Debian Codegraph @

keyboard-indicator/src/applet-notifications.c

raw
1 /**
2 * This file is a part of the Cairo-Dock project
3 *
4 * Copyright : (C) see the 'copyright' file.
5 * E-mail : see the 'copyright' file.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 3
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include <stdlib.h>
21 #include <string.h>
22 #include <libxklavier/xklavier.h>
23 #include <gdk/gdkx.h>
24
25 #include "applet-struct.h"
26 #include "applet-xklavier.h"
27 #include "applet-notifications.h"
28
29
30 //\___________ Define here the action to be taken when the user left-clicks on your icon or on its subdock or your desklet. The icon and the container that were clicked are available through the macros CD_APPLET_CLICKED_ICON and CD_APPLET_CLICKED_CONTAINER. CD_APPLET_CLICKED_ICON may be NULL if the user clicked in the container but out of icons.
31 CD_APPLET_ON_CLICK_BEGIN
32 cd_xkbd_set_prev_next_group (+1);
33 CD_APPLET_ON_CLICK_END
34
35
36 //\___________ Define here the entries you want to add to the menu when the user right-clicks on your icon or on its subdock or your desklet. The icon and the container that were clicked are available through the macros CD_APPLET_CLICKED_ICON and CD_APPLET_CLICKED_CONTAINER. CD_APPLET_CLICKED_ICON may be NULL if the user clicked in the container but out of icons. The menu where you can add your entries is available throught the macro CD_APPLET_MY_MENU; you can add sub-menu to it if you want.
37 static void _select_group (GtkMenuItem *menu_item, gpointer data)
38 {
39 CD_APPLET_ENTER;
40 int iNumGroup = GPOINTER_TO_INT (data);
41 cd_xkbd_set_group (iNumGroup);
42 CD_APPLET_LEAVE ();
43 }
44 static void _open_keyboard_properties (GtkMenuItem *menu_item, gpointer data)
45 {
46 const gchar *cCommand = NULL;
47 gchar *cResult = cairo_dock_launch_command_sync ("which gnome-control-center"); // Gnome3
48 if (cResult != NULL && *cResult == '/')
49 {
50 cCommand = "gnome-control-center region";
51 }
52 else
53 {
54 g_free (cResult);
55 cResult = cairo_dock_launch_command_sync ("which gnome-keyboard-properties"); // Gnome2
56 if (cResult != NULL && *cResult == '/')
57 cCommand = "gnome-keyboard-properties";
58 } /// TODO: handle other DE ...
59 g_free (cResult);
60
61 if (cCommand)
62 {
63 cairo_dock_launch_command (cCommand);
64 }
65 }
66 CD_APPLET_ON_BUILD_MENU_BEGIN
67 XklEngine *pEngine = xkl_engine_get_instance (gdk_x11_get_default_xdisplay ()); // singleton.
68 const gchar **pGroupNames = xkl_engine_get_groups_names (pEngine);
69 int i;
70 for (i = 0; pGroupNames[i] != NULL && *pGroupNames[i] != '-'; i ++)
71 {
72 CD_APPLET_ADD_IN_MENU_WITH_DATA (pGroupNames[i], _select_group, CD_APPLET_MY_MENU, GINT_TO_POINTER (i));
73 }
74
75 if (g_iDesktopEnv == CAIRO_DOCK_GNOME)
76 {
77 CD_APPLET_ADD_SEPARATOR_IN_MENU (CD_APPLET_MY_MENU);
78 CD_APPLET_ADD_IN_MENU_WITH_STOCK (D_("Keyboard preferences"), GLDI_ICON_NAME_PROPERTIES, _open_keyboard_properties, CD_APPLET_MY_MENU);
79 }
80 CD_APPLET_ON_BUILD_MENU_END
81
82
83 CD_APPLET_ON_SCROLL_BEGIN
84 cd_xkbd_set_prev_next_group (CD_APPLET_SCROLL_UP ? +1 : -1);
85 CD_APPLET_ON_SCROLL_END
86
87
88 void cd_xkbd_on_keybinding_pull (const gchar *keystring, gpointer user_data)
89 {
90 cd_xkbd_set_prev_next_group (+1);
91 }