Change to the linux kernel coding style
[wmaker-crm.git] / test / notest.c
blobe3fdc1667fb9f6eb98f17a9b586aea79587b6a7b
1 /* quick and dirty test application that demonstrates: Notify grabbing
3 * TODO: remake
4 */
6 #include <stdio.h>
7 #include <X11/Xlib.h>
8 #include <X11/Xutil.h>
9 #include <X11/Xproto.h>
10 #include <WMaker.h>
12 Display *dpy;
13 Window leader;
14 WMAppContext *app;
15 Atom delete_win;
16 Atom prots[6];
17 XWMHints *hints;
18 WMMenu *menu;
20 static void quit(void *foo, int item, Time time)
22 exit(0);
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);
33 return True;
36 static void newwin(void *foo, int item, Time time)
38 Window win;
39 XClassHint classhint;
40 char title[100];
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);
48 /* set class hint */
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);
60 XMapWindow(dpy, win);
63 int main(int argc, char **argv)
65 XClassHint classhint;
67 dpy = XOpenDisplay("");
68 if (!dpy) {
69 puts("could not open display!");
70 exit(1);
72 delete_win = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
74 leader = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 10, 10, 0, 0, 0);
75 /* set class hint */
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);
93 WMRealizeMenus(app);
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 */
107 newwin(NULL, 0, 0);
109 XFlush(dpy);
110 while (1) {
111 XEvent ev;
112 XNextEvent(dpy, &ev);
113 if (ev.type == ClientMessage) {
114 if (ev.xclient.data.l[0] == delete_win) {
115 XDestroyWindow(dpy, ev.xclient.window);
116 break;
119 WMProcessEvent(app, &ev);
121 exit(0);