Add support for monitors "All" to span panel over all monitors.
[lxde/lxpanel.git] / src / lxpanelctl.c
1 /**
2 * Copyright (c) 2006 LxDE Developers, see the file AUTHORS for details.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 */
18
19 /* Remote controller of lxpanel */
20
21 #include "lxpanelctl.h"
22 #include <X11/Xlib.h>
23 #include <X11/Xutil.h>
24 #include <X11/Xatom.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <string.h>
28
29 static Display* dpy;
30
31 static const char usage[] =
32 "\nlxpanelctl - LXPanel Controller\n"
33 "Usage: lxpanelctl <command>\n\n"
34 "Available commands:\n"
35 "menu\tshow system menu\n"
36 "run\tshow run dialog\n"
37 "config\tshow configuration dialog\n"
38 "restart\trestart lxpanel\n"
39 "exit\texit lxpanel\n\n";
40
41 static int get_cmd( const char* cmd )
42 {
43 if( ! strcmp( cmd, "menu") )
44 return LXPANEL_CMD_SYS_MENU;
45 else if( ! strcmp( cmd, "run") )
46 return LXPANEL_CMD_RUN;
47 else if( ! strcmp( cmd, "config") )
48 return LXPANEL_CMD_CONFIG;
49 else if( ! strcmp( cmd, "restart") )
50 return LXPANEL_CMD_RESTART;
51 else if( ! strcmp( cmd, "exit") )
52 return LXPANEL_CMD_EXIT;
53 return -1;
54 }
55
56 int main( int argc, char** argv )
57 {
58 char *display_name = (char *)getenv("DISPLAY");
59 XEvent ev;
60 Window root;
61 Atom cmd_atom;
62 int cmd;
63 /* int restart; */
64
65 if( argc < 2 )
66 {
67 printf( usage );
68 return 1;
69 }
70
71 /*
72 if( restart = !strcmp( argv[1], "restart" ) )
73 argv[1] = "exit";
74 */
75
76 if( ( cmd = get_cmd( argv[1] ) ) == -1 )
77 return 1;
78
79 dpy = XOpenDisplay(display_name);
80 if (dpy == NULL) {
81 printf("Cant connect to display: %s\n", display_name);
82 exit(1);
83 }
84 root = DefaultRootWindow(dpy);
85 cmd_atom = XInternAtom(dpy, "_LXPANEL_CMD", False);
86 memset(&ev, '\0', sizeof ev);
87 ev.xclient.type = ClientMessage;
88 ev.xclient.window = root;
89 ev.xclient.message_type = cmd_atom;
90 ev.xclient.format = 8;
91
92 ev.xclient.data.b[0] = cmd;
93
94 XSendEvent(dpy, root, False,
95 SubstructureRedirectMask|SubstructureNotifyMask, &ev);
96 XSync(dpy, False);
97 XCloseDisplay(dpy);
98
99 /*
100 if( restart ) {
101 system( PACKAGE_BIN_DIR "/lxpanel &" );
102 }
103 */
104 return 0;
105 }
106