1 /* quick and dirty test application that demonstrates: Notify grabbing
9 #include <X11/Xproto.h>
20 static void quit(void *foo, int item, Time time)
25 static void hide(void *foo, int item, Time time)
27 WMHideApplication(app);
30 int notify_print(int id, XEvent * event, void *data)
32 printf("Got notification 0x%x, window 0x%lx, data '%s'\n", id, event->xclient.data.l[1], (char *)data);
36 static void newwin(void *foo, int item, Time time)
42 win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, 200, 100, 0, 0, 0);
43 prots[0] = delete_win;
44 XSetWMProtocols(dpy, win, prots, 1);
45 sprintf(title, "Notify Test Window");
46 XStoreName(dpy, win, title);
49 classhint.res_name = "notest";
50 classhint.res_class = "Notest";
51 XSetClassHint(dpy, win, &classhint);
53 hints = XAllocWMHints();
54 /* set window group leader */
55 hints->window_group = leader;
56 hints->flags = WindowGroupHint;
57 XSetWMHints(dpy, win, hints);
59 WMAppAddWindow(app, win);
63 int main(int argc, char **argv)
67 dpy = XOpenDisplay("");
69 puts("could not open display!");
72 delete_win = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
74 leader = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 10, 10, 0, 0, 0);
76 classhint.res_name = "notest";
77 classhint.res_class = "Notest";
78 XSetClassHint(dpy, leader, &classhint);
80 /* set window group leader to self */
81 hints = XAllocWMHints();
82 hints->window_group = leader;
83 hints->flags = WindowGroupHint;
84 XSetWMHints(dpy, leader, hints);
86 /* create app context */
87 app = WMAppCreateWithMain(dpy, DefaultScreen(dpy), leader);
88 menu = WMMenuCreate(app, "Notify Test Menu");
89 WMMenuAddItem(menu, "Hide", (WMMenuAction) hide, NULL, NULL, NULL);
90 WMMenuAddItem(menu, "Quit", (WMMenuAction) quit, NULL, NULL, NULL);
92 WMAppSetMainMenu(app, menu);
95 /* Get some WindowMaker notifications */
96 WMNotifySet(app, WMN_APP_START, notify_print, (void *)"App start");
97 WMNotifySet(app, WMN_APP_EXIT, notify_print, (void *)"App end");
98 WMNotifySet(app, WMN_WIN_FOCUS, notify_print, (void *)"Focus in");
99 WMNotifySet(app, WMN_WIN_UNFOCUS, notify_print, (void *)"Focus out");
100 WMNotifySet(app, WMN_NOTIFY_ALL, notify_print, (void *)"Unknown type");
101 WMNotifyMaskUpdate(app); /* Mask isn't actually set till we do this */
103 /* set command to use to startup this */
104 XSetCommand(dpy, leader, argv, argc);
106 /* create first window */
112 XNextEvent(dpy, &ev);
113 if (ev.type == ClientMessage) {
114 if (ev.xclient.data.l[0] == delete_win) {
115 XDestroyWindow(dpy, ev.xclient.window);
119 WMProcessEvent(app, &ev);