]> icculus.org git repositories - dana/openbox.git/blob - tools/gnome-panel-control/gnome-panel-control.c
rename gnomepanelproxy to gnome-panel-control
[dana/openbox.git] / tools / gnome-panel-control / gnome-panel-control.c
1 #include <X11/Xlib.h>
2 #include <string.h>
3 #include <stdio.h>
4 #include <assert.h>
5
6 typedef enum
7 {
8     NONE,
9     MAIN_MENU,
10     RUN_DIALOG
11 } Action;
12
13 int main(int argc, char **argv)
14 {
15     int i;
16     Action a = NONE;
17
18     for (i = 1; i < argc; ++i) {
19         if (!strcmp(argv[i], "--help")) {
20             a = NONE;
21             break;
22         }
23         if (!strcmp(argv[i], "--main-menu")) {
24             a = MAIN_MENU;
25             break;
26         }
27         if (!strcmp(argv[i], "--run-dialog")) {
28             a = RUN_DIALOG;
29             break;
30         }
31     }
32
33     if (!a) {
34         printf("Usage: gnome-panel-control ACTION\n\n");
35         printf("Actions:\n");
36         printf("    --help       Display this help and exit\n");
37         printf("    --main-menu  Show the main menu\n");
38         printf("    --run-dialog Show the run dialog\n\n");
39         return 0;
40     }
41
42     {
43         Display *d;
44         Window root;
45         XClientMessageEvent ce;
46         Atom act_atom;
47         Time timestamp;
48
49         d = XOpenDisplay(NULL);
50         if (!d) {
51             fprintf(stderr,
52                     "Unable to open the X display specified by the DISPLAY "
53                     "environment variable. Ensure you have permission to "
54                     "connect to the display.");
55             return 1;
56         }
57         root = RootWindowOfScreen(DefaultScreenOfDisplay(d));
58
59         switch (a) {
60         case MAIN_MENU:
61             act_atom = XInternAtom(d, "_GNOME_PANEL_ACTION_MAIN_MENU", False);
62             break;
63         case RUN_DIALOG:
64             act_atom = XInternAtom(d, "_GNOME_PANEL_ACTION_RUN_DIALOG", False);
65             break;
66         default:
67             assert(0);
68         }
69
70         /* Generate a timestamp */
71         {
72             XEvent event;
73             Window win;
74
75             win = XCreateSimpleWindow(d, root, 0, 0, 1, 1, 0, 0, 0);
76
77             XSelectInput(d, win, PropertyChangeMask);
78
79             XChangeProperty(d, win, act_atom, act_atom, 8,
80                             PropModeAppend, NULL, 0);
81             XWindowEvent(d, win, PropertyChangeMask, &event);
82
83             XDestroyWindow(d, win);
84
85             timestamp = event.xproperty.time;
86         }
87
88         ce.type = ClientMessage;
89         ce.window = root;
90         ce.message_type = XInternAtom(d, "_GNOME_PANEL_ACTION", False);
91         ce.format = 32;
92         ce.data.l[0] = act_atom;
93         ce.data.l[1] = timestamp;
94         XSendEvent(d, root, False, StructureNotifyMask, (XEvent*) &ce);
95
96         XCloseDisplay(d);
97     }
98
99     return 0;
100 }