1 /* Metacity 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, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include <config.h>
21 #include <glib/gi18n.h>
22 #include <gtk/gtk.h>
23 #include <gdk/gdkx.h>
24 #include <stdlib.h>
25 #include <string.h>
26
27 static void
send_restart(void)28 send_restart (void)
29 {
30 XEvent xev;
31
32 xev.xclient.type = ClientMessage;
33 xev.xclient.serial = 0;
34 xev.xclient.send_event = True;
35 xev.xclient.display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
36 xev.xclient.window = gdk_x11_get_default_root_xwindow ();
37 xev.xclient.message_type = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
38 "_METACITY_RESTART_MESSAGE",
39 False);
40 xev.xclient.format = 32;
41 xev.xclient.data.l[0] = 0;
42 xev.xclient.data.l[1] = 0;
43 xev.xclient.data.l[2] = 0;
44
45 XSendEvent (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
46 gdk_x11_get_default_root_xwindow (),
47 False,
48 SubstructureRedirectMask | SubstructureNotifyMask,
49 &xev);
50
51 XFlush (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()));
52 XSync (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), False);
53 }
54
55 static void
send_reload_theme(void)56 send_reload_theme (void)
57 {
58 XEvent xev;
59
60 xev.xclient.type = ClientMessage;
61 xev.xclient.serial = 0;
62 xev.xclient.send_event = True;
63 xev.xclient.display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
64 xev.xclient.window = gdk_x11_get_default_root_xwindow ();
65 xev.xclient.message_type = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
66 "_METACITY_RELOAD_THEME_MESSAGE",
67 False);
68 xev.xclient.format = 32;
69 xev.xclient.data.l[0] = 0;
70 xev.xclient.data.l[1] = 0;
71 xev.xclient.data.l[2] = 0;
72
73 XSendEvent (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
74 gdk_x11_get_default_root_xwindow (),
75 False,
76 SubstructureRedirectMask | SubstructureNotifyMask,
77 &xev);
78
79 XFlush (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()));
80 XSync (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), False);
81 }
82
83 static void
send_set_keybindings(gboolean enabled)84 send_set_keybindings (gboolean enabled)
85 {
86 XEvent xev;
87
88 xev.xclient.type = ClientMessage;
89 xev.xclient.serial = 0;
90 xev.xclient.send_event = True;
91 xev.xclient.display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
92 xev.xclient.window = gdk_x11_get_default_root_xwindow ();
93 xev.xclient.message_type = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
94 "_METACITY_SET_KEYBINDINGS_MESSAGE",
95 False);
96 xev.xclient.format = 32;
97 xev.xclient.data.l[0] = enabled;
98 xev.xclient.data.l[1] = 0;
99 xev.xclient.data.l[2] = 0;
100
101 XSendEvent (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
102 gdk_x11_get_default_root_xwindow (),
103 False,
104 SubstructureRedirectMask | SubstructureNotifyMask,
105 &xev);
106
107 XFlush (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()));
108 XSync (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), False);
109 }
110
111 static void
send_set_mousemods(gboolean enabled)112 send_set_mousemods (gboolean enabled)
113 {
114 XEvent xev;
115
116 xev.xclient.type = ClientMessage;
117 xev.xclient.serial = 0;
118 xev.xclient.send_event = True;
119 xev.xclient.display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
120 xev.xclient.window = gdk_x11_get_default_root_xwindow ();
121 xev.xclient.message_type = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
122 "_METACITY_SET_MOUSEMODS_MESSAGE",
123 False);
124 xev.xclient.format = 32;
125 xev.xclient.data.l[0] = enabled;
126 xev.xclient.data.l[1] = 0;
127 xev.xclient.data.l[2] = 0;
128
129 XSendEvent (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
130 gdk_x11_get_default_root_xwindow (),
131 False,
132 SubstructureRedirectMask | SubstructureNotifyMask,
133 &xev);
134
135 XFlush (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()));
136 XSync (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), False);
137 }
138
139 static void
send_toggle_verbose(void)140 send_toggle_verbose (void)
141 {
142 XEvent xev;
143
144 xev.xclient.type = ClientMessage;
145 xev.xclient.serial = 0;
146 xev.xclient.send_event = True;
147 xev.xclient.display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
148 xev.xclient.window = gdk_x11_get_default_root_xwindow ();
149 xev.xclient.message_type = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
150 "_METACITY_TOGGLE_VERBOSE",
151 False);
152 xev.xclient.format = 32;
153 xev.xclient.data.l[0] = 0;
154 xev.xclient.data.l[1] = 0;
155 xev.xclient.data.l[2] = 0;
156
157 XSendEvent (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
158 gdk_x11_get_default_root_xwindow (),
159 False,
160 SubstructureRedirectMask | SubstructureNotifyMask,
161 &xev);
162
163 XFlush (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()));
164 XSync (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), False);
165 }
166
167 static void
usage(void)168 usage (void)
169 {
170 g_printerr (_("Usage: %s\n"),
171 "metacity-message (restart|reload-theme|enable-keybindings|disable-keybindings|enable-mouse-button-modifiers|disable-mouse-button-modifiers|toggle-verbose)");
172 exit (1);
173 }
174
175 int
main(int argc,char ** argv)176 main (int argc, char **argv)
177 {
178 bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
179
180 gtk_init (&argc, &argv);
181
182 if (argc < 2)
183 usage ();
184
185 if (strcmp (argv[1], "restart") == 0)
186 send_restart ();
187 else if (strcmp (argv[1], "reload-theme") == 0)
188 send_reload_theme ();
189 else if (strcmp (argv[1], "enable-keybindings") == 0)
190 send_set_keybindings (TRUE);
191 else if (strcmp (argv[1], "disable-keybindings") == 0)
192 send_set_keybindings (FALSE);
193 else if (strcmp (argv[1], "enable-mouse-button-modifiers") == 0)
194 send_set_mousemods (TRUE);
195 else if (strcmp (argv[1], "disable-mouse-button-modifiers") == 0)
196 send_set_mousemods (FALSE);
197 else if (strcmp (argv[1], "toggle-verbose") == 0)
198 send_toggle_verbose ();
199 else
200 usage ();
201
202 return 0;
203 }
204
205