all repos — openbox @ 4f6908feed54691d4b6e418fccde90c4ddfc1617

openbox fork - make it a bit more like ryudo

tools/gnome-panel-control/gnome-panel-control.c (raw)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include <X11/Xlib.h>
#include <string.h>
#include <stdio.h>
#include <assert.h>

typedef enum
{
    NONE,
    MAIN_MENU,
    RUN_DIALOG
} Action;

int main(int argc, char **argv)
{
    int i;
    Action a = NONE;

    for (i = 1; i < argc; ++i) {
        if (!strcmp(argv[i], "--help")) {
            a = NONE;
            break;
        }
        if (!strcmp(argv[i], "--main-menu")) {
            a = MAIN_MENU;
            break;
        }
        if (!strcmp(argv[i], "--run-dialog")) {
            a = RUN_DIALOG;
            break;
        }
    }

    if (!a) {
        printf("Usage: gnomepanelproxy ACTION\n\n");
        printf("Actions:\n");
        printf("    --help       Display this help and exit\n");
        printf("    --main-menu  Show the main menu\n");
        printf("    --run-dialog Show the run dialog\n\n");
        return 0;
    }

    {
        Display *d;
        Window root;
        XClientMessageEvent ce;
        Atom act_atom;
        Time timestamp;

        d = XOpenDisplay(NULL);
        if (!d) {
            fprintf(stderr,
                    "Unable to open the X display specified by the DISPLAY "
                    "environment variable. Ensure you have permission to "
                    "connect to the display.");
            return 1;
        }
        root = RootWindowOfScreen(DefaultScreenOfDisplay(d));

        switch (a) {
        case MAIN_MENU:
            act_atom = XInternAtom(d, "_GNOME_PANEL_ACTION_MAIN_MENU", False);
            break;
        case RUN_DIALOG:
            act_atom = XInternAtom(d, "_GNOME_PANEL_ACTION_RUN_DIALOG", False);
            break;
        default:
            assert(0);
        }

        /* Generate a timestamp */
        {
            XEvent event;
            Window win;

            win = XCreateSimpleWindow(d, root, 0, 0, 1, 1, 0, 0, 0);

            XSelectInput(d, win, PropertyChangeMask);

            XChangeProperty(d, win, act_atom, act_atom, 8,
                            PropModeAppend, NULL, 0);
            XWindowEvent(d, win, PropertyChangeMask, &event);

            XDestroyWindow(d, win);

            timestamp = event.xproperty.time;
        }

        ce.type = ClientMessage;
        ce.window = root;
        ce.message_type = XInternAtom(d, "_GNOME_PANEL_ACTION", False);
        ce.format = 32;
        ce.data.l[0] = act_atom;
        ce.data.l[1] = timestamp;
        XSendEvent(d, root, False, StructureNotifyMask, (XEvent*) &ce);

        XCloseDisplay(d);
    }

    return 0;
}