changed indentation to use spaces only
[wmaker-crm.git] / test / notest.c
blobf517313cf727c25d67d4f0bb9bc6177aad637e29
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>
13 Display *dpy;
14 Window leader;
15 WMAppContext *app;
16 Atom delete_win;
17 Atom prots[6];
18 XWMHints *hints;
19 WMMenu *menu;
22 static void
23 quit(void *foo, int item, Time time)
25 exit(0);
29 static void
30 hide(void *foo, int item, Time time)
32 WMHideApplication(app);
36 int
37 notify_print( int id, XEvent *event, void *data )
39 printf( "Got notification 0x%x, window 0x%lx, data '%s'\n",
40 id, event->xclient.data.l[1], (char *) data );
41 return True;
45 static void
46 newwin(void *foo, int item, Time time)
48 Window win;
49 XClassHint classhint;
50 char title[100];
52 win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy),
53 0, 0, 200, 100, 0, 0, 0);
54 prots[0] = delete_win;
55 XSetWMProtocols(dpy, win, prots, 1);
56 sprintf(title, "Notify Test Window");
57 XStoreName(dpy, win, title);
59 /* set class hint */
60 classhint.res_name = "notest";
61 classhint.res_class = "Notest";
62 XSetClassHint(dpy, win, &classhint);
64 hints = XAllocWMHints();
65 /* set window group leader */
66 hints->window_group = leader;
67 hints->flags = WindowGroupHint;
68 XSetWMHints(dpy, win, hints);
70 WMAppAddWindow(app, win);
71 XMapWindow(dpy, win);
74 int main(int argc, char **argv)
76 XClassHint classhint;
78 dpy = XOpenDisplay("");
79 if (!dpy) {
80 puts("could not open display!");
81 exit(1);
83 delete_win = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
85 leader = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 10, 10,
86 0, 0, 0);
87 /* set class hint */
88 classhint.res_name = "notest";
89 classhint.res_class = "Notest";
90 XSetClassHint(dpy, leader, &classhint);
92 /* set window group leader to self */
93 hints = XAllocWMHints();
94 hints->window_group = leader;
95 hints->flags = WindowGroupHint;
96 XSetWMHints(dpy, leader, hints);
98 /* create app context */
99 app = WMAppCreateWithMain(dpy, DefaultScreen(dpy), leader);
100 menu = WMMenuCreate(app, "Notify Test Menu");
101 WMMenuAddItem(menu, "Hide", (WMMenuAction)hide, NULL, NULL, NULL);
102 WMMenuAddItem(menu, "Quit", (WMMenuAction)quit, NULL, NULL, NULL);
104 WMAppSetMainMenu(app, menu);
105 WMRealizeMenus(app);
107 /* Get some WindowMaker notifications */
108 WMNotifySet( app, WMN_APP_START, notify_print, (void *) "App start" );
109 WMNotifySet( app, WMN_APP_EXIT, notify_print, (void *) "App end" );
110 WMNotifySet( app, WMN_WIN_FOCUS, notify_print, (void *) "Focus in" );
111 WMNotifySet( app, WMN_WIN_UNFOCUS, notify_print, (void *) "Focus out" );
112 WMNotifySet( app, WMN_NOTIFY_ALL, notify_print, (void *) "Unknown type" );
113 WMNotifyMaskUpdate( app ); /* Mask isn't actually set till we do this */
115 /* set command to use to startup this */
116 XSetCommand(dpy, leader, argv, argc);
118 /* create first window */
119 newwin(NULL, 0, 0);
122 XFlush(dpy);
123 while( 1 ) {
124 XEvent ev;
125 XNextEvent(dpy, &ev);
126 if (ev.type==ClientMessage) {
127 if (ev.xclient.data.l[0]==delete_win) {
128 XDestroyWindow(dpy,ev.xclient.window);
129 break;
132 WMProcessEvent(app, &ev);
134 exit(0);