metacity-message.c

Go to the documentation of this file.
00001 /* Metacity send-magic-messages app */
00002 
00003 /*
00004  * Copyright (C) 2002 Havoc Pennington
00005  *
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License as
00008  * published by the Free Software Foundation; either version 2 of the
00009  * License, or (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful, but
00012  * WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  * General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
00019  * 02111-1307, USA.
00020  */
00021 
00022 #include <config.h>
00023 #include <gtk/gtk.h>
00024 #include <gdk/gdkx.h>
00025 #include <stdlib.h>
00026 #include <string.h>
00027 
00028 #include <libintl.h>
00029 #define _(x) dgettext (GETTEXT_PACKAGE, x)
00030 #define N_(x) x
00031 
00032 
00033 static void
00034 send_restart (void)
00035 {
00036   XEvent xev;
00037 
00038   xev.xclient.type = ClientMessage;
00039   xev.xclient.serial = 0;
00040   xev.xclient.send_event = True;
00041   xev.xclient.display = gdk_display;
00042   xev.xclient.window = gdk_x11_get_default_root_xwindow ();
00043   xev.xclient.message_type = XInternAtom (gdk_display,
00044                                           "_METACITY_RESTART_MESSAGE",
00045                                           False);
00046   xev.xclient.format = 32;
00047   xev.xclient.data.l[0] = 0;
00048   xev.xclient.data.l[1] = 0;
00049   xev.xclient.data.l[2] = 0;
00050 
00051   XSendEvent (gdk_display,
00052               gdk_x11_get_default_root_xwindow (),
00053               False,
00054               SubstructureRedirectMask | SubstructureNotifyMask,
00055               &xev);
00056 
00057   XFlush (gdk_display);
00058   XSync (gdk_display, False);
00059 }
00060 
00061 static void
00062 send_reload_theme (void)
00063 {
00064   XEvent xev;
00065 
00066   xev.xclient.type = ClientMessage;
00067   xev.xclient.serial = 0;
00068   xev.xclient.send_event = True;
00069   xev.xclient.display = gdk_display;
00070   xev.xclient.window = gdk_x11_get_default_root_xwindow ();
00071   xev.xclient.message_type = XInternAtom (gdk_display,
00072                                           "_METACITY_RELOAD_THEME_MESSAGE",
00073                                           False);
00074   xev.xclient.format = 32;
00075   xev.xclient.data.l[0] = 0;
00076   xev.xclient.data.l[1] = 0;
00077   xev.xclient.data.l[2] = 0;
00078 
00079   XSendEvent (gdk_display,
00080               gdk_x11_get_default_root_xwindow (),
00081               False,
00082               SubstructureRedirectMask | SubstructureNotifyMask,
00083               &xev);
00084 
00085   XFlush (gdk_display);
00086   XSync (gdk_display, False);
00087 }
00088 
00089 static void
00090 send_set_keybindings (gboolean enabled)
00091 {
00092   XEvent xev;
00093 
00094   xev.xclient.type = ClientMessage;
00095   xev.xclient.serial = 0;
00096   xev.xclient.send_event = True;
00097   xev.xclient.display = gdk_display;
00098   xev.xclient.window = gdk_x11_get_default_root_xwindow ();
00099   xev.xclient.message_type = XInternAtom (gdk_display,
00100                                           "_METACITY_SET_KEYBINDINGS_MESSAGE",
00101                                           False);
00102   xev.xclient.format = 32;
00103   xev.xclient.data.l[0] = enabled;
00104   xev.xclient.data.l[1] = 0;
00105   xev.xclient.data.l[2] = 0;
00106 
00107   XSendEvent (gdk_display,
00108               gdk_x11_get_default_root_xwindow (),
00109               False,
00110               SubstructureRedirectMask | SubstructureNotifyMask,
00111               &xev);
00112 
00113   XFlush (gdk_display);
00114   XSync (gdk_display, False);
00115 }
00116 
00117 #ifdef WITH_VERBOSE_MODE
00118 static void
00119 send_toggle_verbose (void)
00120 {
00121   XEvent xev;
00122 
00123   xev.xclient.type = ClientMessage;
00124   xev.xclient.serial = 0;
00125   xev.xclient.send_event = True;
00126   xev.xclient.display = gdk_display;
00127   xev.xclient.window = gdk_x11_get_default_root_xwindow ();
00128   xev.xclient.message_type = XInternAtom (gdk_display,
00129                                           "_METACITY_TOGGLE_VERBOSE",
00130                                           False);
00131   xev.xclient.format = 32;
00132   xev.xclient.data.l[0] = 0;
00133   xev.xclient.data.l[1] = 0;
00134   xev.xclient.data.l[2] = 0;
00135 
00136   XSendEvent (gdk_display,
00137               gdk_x11_get_default_root_xwindow (),
00138               False,
00139               SubstructureRedirectMask | SubstructureNotifyMask,
00140               &xev);
00141 
00142   XFlush (gdk_display);
00143   XSync (gdk_display, False);
00144 }
00145 #endif
00146 
00147 static void
00148 usage (void)
00149 {
00150   g_printerr (_("Usage: %s\n"),
00151               "metacity-message (restart|reload-theme|enable-keybindings|disable-keybindings|toggle-verbose)");
00152   exit (1);
00153 }
00154 
00155 int
00156 main (int argc, char **argv)
00157 {
00158   bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
00159   
00160   gtk_init (&argc, &argv);
00161 
00162   if (argc < 2)
00163     usage ();
00164 
00165   if (strcmp (argv[1], "restart") == 0)
00166     send_restart ();
00167   else if (strcmp (argv[1], "reload-theme") == 0)
00168     send_reload_theme ();
00169   else if (strcmp (argv[1], "enable-keybindings") == 0)
00170     send_set_keybindings (TRUE);
00171   else if (strcmp (argv[1], "disable-keybindings") == 0)
00172     send_set_keybindings (FALSE);
00173   else if (strcmp (argv[1], "toggle-verbose") == 0)
00174     {
00175 #ifndef WITH_VERBOSE_MODE
00176       g_printerr (_("Metacity was compiled without support for verbose mode\n"));
00177       return 1;
00178 #else      
00179       send_toggle_verbose ();
00180 #endif
00181     }
00182   else
00183     usage ();
00184   
00185   return 0;
00186 }
00187 

Generated on Sat Aug 23 22:04:18 2008 for metacity by  doxygen 1.5.5