1 /* Marco send-magic-messages app */
2
3 /*
4 * Copyright (C) 2002 Havoc Pennington
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, but
12 * 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 License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 * 02110-1301, USA.
20 */
21
22 #include <config.h>
23 #include <glib/gi18n.h>
24 #include <gtk/gtk.h>
25 #include <gdk/gdkx.h>
26 #include <stdlib.h>
27 #include <string.h>
28
29 static void
send_restart(void)30 send_restart (void)
31 {
32 XEvent xev;
33
34 xev.xclient.type = ClientMessage;
35 xev.xclient.serial = 0;
36 xev.xclient.send_event = True;
37 xev.xclient.display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
38 xev.xclient.window = gdk_x11_get_default_root_xwindow ();
39 xev.xclient.message_type = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
40 "_MARCO_RESTART_MESSAGE",
41 False);
42 xev.xclient.format = 32;
43 xev.xclient.data.l[0] = 0;
44 xev.xclient.data.l[1] = 0;
45 xev.xclient.data.l[2] = 0;
46
47 XSendEvent (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
48 gdk_x11_get_default_root_xwindow (),
49 False,
50 SubstructureRedirectMask | SubstructureNotifyMask,
51 &xev);
52
53 XFlush (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()));
54 XSync (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), False);
55 }
56
57 static void
send_reload_theme(void)58 send_reload_theme (void)
59 {
60 XEvent xev;
61
62 xev.xclient.type = ClientMessage;
63 xev.xclient.serial = 0;
64 xev.xclient.send_event = True;
65 xev.xclient.display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
66 xev.xclient.window = gdk_x11_get_default_root_xwindow ();
67 xev.xclient.message_type = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
68 "_MARCO_RELOAD_THEME_MESSAGE",
69 False);
70 xev.xclient.format = 32;
71 xev.xclient.data.l[0] = 0;
72 xev.xclient.data.l[1] = 0;
73 xev.xclient.data.l[2] = 0;
74
75 XSendEvent (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
76 gdk_x11_get_default_root_xwindow (),
77 False,
78 SubstructureRedirectMask | SubstructureNotifyMask,
79 &xev);
80
81 XFlush (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()));
82 XSync (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), False);
83 }
84
85 static void
send_set_keybindings(gboolean enabled)86 send_set_keybindings (gboolean enabled)
87 {
88 XEvent xev;
89
90 xev.xclient.type = ClientMessage;
91 xev.xclient.serial = 0;
92 xev.xclient.send_event = True;
93 xev.xclient.display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
94 xev.xclient.window = gdk_x11_get_default_root_xwindow ();
95 xev.xclient.message_type = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
96 "_MARCO_SET_KEYBINDINGS_MESSAGE",
97 False);
98 xev.xclient.format = 32;
99 xev.xclient.data.l[0] = enabled;
100 xev.xclient.data.l[1] = 0;
101 xev.xclient.data.l[2] = 0;
102
103 XSendEvent (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
104 gdk_x11_get_default_root_xwindow (),
105 False,
106 SubstructureRedirectMask | SubstructureNotifyMask,
107 &xev);
108
109 XFlush (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()));
110 XSync (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), False);
111 }
112
113 #ifdef WITH_VERBOSE_MODE
114 static void
send_toggle_verbose(void)115 send_toggle_verbose (void)
116 {
117 XEvent xev;
118
119 xev.xclient.type = ClientMessage;
120 xev.xclient.serial = 0;
121 xev.xclient.send_event = True;
122 xev.xclient.display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
123 xev.xclient.window = gdk_x11_get_default_root_xwindow ();
124 xev.xclient.message_type = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
125 "_MARCO_TOGGLE_VERBOSE",
126 False);
127 xev.xclient.format = 32;
128 xev.xclient.data.l[0] = 0;
129 xev.xclient.data.l[1] = 0;
130 xev.xclient.data.l[2] = 0;
131
132 XSendEvent (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
133 gdk_x11_get_default_root_xwindow (),
134 False,
135 SubstructureRedirectMask | SubstructureNotifyMask,
136 &xev);
137
138 XFlush (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()));
139 XSync (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), False);
140 }
141 #endif
142
143 static void
usage(void)144 usage (void)
145 {
146 g_printerr (_("Usage: %s\n"),
147 "marco-message (restart|reload-theme|enable-keybindings|disable-keybindings|toggle-verbose)");
148 exit (1);
149 }
150
151 int
main(int argc,char ** argv)152 main (int argc, char **argv)
153 {
154 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
155
156 gtk_init (&argc, &argv);
157
158 if (argc < 2)
159 usage ();
160
161 if (strcmp (argv[1], "restart") == 0)
162 send_restart ();
163 else if (strcmp (argv[1], "reload-theme") == 0)
164 send_reload_theme ();
165 else if (strcmp (argv[1], "enable-keybindings") == 0)
166 send_set_keybindings (TRUE);
167 else if (strcmp (argv[1], "disable-keybindings") == 0)
168 send_set_keybindings (FALSE);
169 else if (strcmp (argv[1], "toggle-verbose") == 0)
170 {
171 #ifndef WITH_VERBOSE_MODE
172 g_printerr (_("Marco was compiled without support for verbose mode\n"));
173 return 1;
174 #else
175 send_toggle_verbose ();
176 #endif
177 }
178 else
179 usage ();
180
181 return 0;
182 }
183
184