~ubuntu-branches/debian/jessie/mate-control-center/jessie

« back to all changes in this revision

Viewing changes to typing-break/main.c

  • Committer: Package Import Robot
  • Author(s): Mike Gabriel
  • Date: 2014-05-02 23:20:06 UTC
  • Revision ID: package-import@ubuntu.com-20140502232006-9626h14ggaz2hc9h
Tags: upstream-1.8.1+dfsg1
ImportĀ upstreamĀ versionĀ 1.8.1+dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
 
2
/*
 
3
 * Copyright (C) 2002 CodeFactory AB
 
4
 * Copyright (C) 2002-2003 Richard Hult <richard@imendio.com>
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU General Public License as
 
8
 * published by the Free Software Foundation; either version 2 of the
 
9
 * License, or (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
14
 * General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public
 
17
 * License along with this program; if not, write to the
 
18
 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 
19
 * Boston, MA 02110-1301, USA.
 
20
 */
 
21
 
 
22
#include <config.h>
 
23
#include <string.h>
 
24
#include <stdlib.h>
 
25
#include <glib/gi18n.h>
 
26
#include <gdk/gdkx.h>
 
27
#include <gtk/gtk.h>
 
28
 
 
29
#include "drw-selection.h"
 
30
#include "drwright.h"
 
31
 
 
32
gboolean debug = FALSE;
 
33
 
 
34
#ifndef HAVE_APP_INDICATOR
 
35
static gboolean
 
36
have_tray (void)
 
37
{
 
38
#if GTK_CHECK_VERSION (3, 0, 0)
 
39
        Screen *xscreen = DefaultScreenOfDisplay (gdk_x11_display_get_xdisplay(gdk_display_get_default()));
 
40
#else
 
41
        Screen *xscreen = DefaultScreenOfDisplay (gdk_display);
 
42
#endif
 
43
        Atom    selection_atom;
 
44
        char   *selection_atom_name;
 
45
        
 
46
        selection_atom_name = g_strdup_printf ("_NET_SYSTEM_TRAY_S%d",
 
47
                                               XScreenNumberOfScreen (xscreen));
 
48
        selection_atom = XInternAtom (DisplayOfScreen (xscreen), selection_atom_name, False);
 
49
        g_free (selection_atom_name);
 
50
        
 
51
        if (XGetSelectionOwner (DisplayOfScreen (xscreen), selection_atom)) {
 
52
                return TRUE;
 
53
        } else {
 
54
                return FALSE;
 
55
        }
 
56
}
 
57
#endif /* HAVE_APP_INDICATOR */
 
58
 
 
59
int
 
60
main (int argc, char *argv[])
 
61
{
 
62
        DrWright     *drwright;
 
63
        DrwSelection *selection;
 
64
        gboolean      no_check = FALSE;
 
65
        const GOptionEntry options[] = {
 
66
          { "debug", 'd', 0, G_OPTION_ARG_NONE, &debug,
 
67
            N_("Enable debugging code"), NULL },
 
68
          { "no-check", 'n', 0, G_OPTION_ARG_NONE, &no_check,
 
69
            N_("Don't check whether the notification area exists"), NULL },
 
70
          { NULL }
 
71
        };
 
72
        GOptionContext *option_context;
 
73
        GError *error = NULL;
 
74
        gboolean retval;
 
75
 
 
76
        bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);  
 
77
        bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
 
78
        textdomain (GETTEXT_PACKAGE);
 
79
 
 
80
        option_context = g_option_context_new (NULL);
 
81
#if GLIB_CHECK_VERSION (2, 12, 0)
 
82
        g_option_context_set_translation_domain (option_context, GETTEXT_PACKAGE);
 
83
#endif
 
84
        g_option_context_add_main_entries (option_context, options, GETTEXT_PACKAGE);
 
85
        g_option_context_add_group (option_context, gtk_get_option_group (TRUE));
 
86
 
 
87
        retval = g_option_context_parse (option_context, &argc, &argv, &error);
 
88
        g_option_context_free (option_context);
 
89
        if (!retval) {
 
90
                g_print ("%s\n", error->message);
 
91
                g_error_free (error);
 
92
                exit (1);
 
93
        }
 
94
 
 
95
        g_set_application_name (_("Typing Monitor"));
 
96
        gtk_window_set_default_icon_name ("mate-typing-monitor");
 
97
 
 
98
        selection = drw_selection_start ();
 
99
        if (!drw_selection_is_master (selection)) {
 
100
                g_message ("The typing monitor is already running, exiting.");
 
101
                return 0;
 
102
        }
 
103
 
 
104
#ifndef HAVE_APP_INDICATOR
 
105
        if (!no_check && !have_tray ()) {
 
106
                GtkWidget *dialog;
 
107
 
 
108
                dialog = gtk_message_dialog_new (
 
109
                        NULL, 0,
 
110
                        GTK_MESSAGE_INFO,
 
111
                        GTK_BUTTONS_CLOSE,
 
112
                        _("The typing monitor uses the notification area to display "
 
113
                          "information. You don't seem to have a notification area "
 
114
                          "on your panel. You can add it by right-clicking on your "
 
115
                          "panel and choosing 'Add to panel', selecting 'Notification "
 
116
                          "area' and clicking 'Add'."));
 
117
                
 
118
                gtk_dialog_run (GTK_DIALOG (dialog));
 
119
 
 
120
                gtk_widget_destroy (dialog);
 
121
        }
 
122
#endif /* HAVE_APP_INDICATOR */
 
123
        
 
124
        drwright = drwright_new ();
 
125
 
 
126
        gtk_main ();
 
127
 
 
128
        return 0;
 
129
}