Initial revision
[wmaker-crm.git] / test / notest.c
blob174691a87b94ce415622b9bd8ff536ad86df628d
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 notify_print( int id, XEvent *event, void *data )
38 printf( "Got notification 0x%x, window 0x%lx, data '%s'\n",
39 id, event->xclient.data.l[1], (char *) data );
40 return True;
44 static void
45 newwin(void *foo, int item, Time time)
47 Window win;
48 XClassHint classhint;
49 char title[100];
51 win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy),
52 0, 0, 200, 100, 0, 0, 0);
53 prots[0] = delete_win;
54 XSetWMProtocols(dpy, win, prots, 1);
55 sprintf(title, "Notify Test Window");
56 XStoreName(dpy, win, title);
58 /* set class hint */
59 classhint.res_name = "notest";
60 classhint.res_class = "Notest";
61 XSetClassHint(dpy, win, &classhint);
63 hints = XAllocWMHints();
64 /* set window group leader */
65 hints->window_group = leader;
66 hints->flags = WindowGroupHint;
67 XSetWMHints(dpy, win, hints);
69 WMAppAddWindow(app, win);
70 XMapWindow(dpy, win);
73 int main(int argc, char **argv)
75 XClassHint classhint;
77 dpy = XOpenDisplay("");
78 if (!dpy) {
79 puts("could not open display!");
80 exit(1);
82 delete_win = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
84 leader = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 10, 10,
85 0, 0, 0);
86 /* set class hint */
87 classhint.res_name = "notest";
88 classhint.res_class = "Notest";
89 XSetClassHint(dpy, leader, &classhint);
91 /* set window group leader to self */
92 hints = XAllocWMHints();
93 hints->window_group = leader;
94 hints->flags = WindowGroupHint;
95 XSetWMHints(dpy, leader, hints);
97 /* create app context */
98 app = WMAppCreateWithMain(dpy, DefaultScreen(dpy), leader);
99 menu = WMMenuCreate(app, "Notify Test Menu");
100 WMMenuAddItem(menu, "Hide", (WMMenuAction)hide, NULL, NULL, NULL);
101 WMMenuAddItem(menu, "Quit", (WMMenuAction)quit, NULL, NULL, NULL);
103 WMAppSetMainMenu(app, menu);
104 WMRealizeMenus(app);
106 /* Get some WindowMaker notifications */
107 WMNotifySet( app, WMN_APP_START, notify_print, (void *) "App start" );
108 WMNotifySet( app, WMN_APP_EXIT, notify_print, (void *) "App end" );
109 WMNotifySet( app, WMN_WIN_FOCUS, notify_print, (void *) "Focus in" );
110 WMNotifySet( app, WMN_WIN_UNFOCUS, notify_print, (void *) "Focus out" );
111 WMNotifySet( app, WMN_NOTIFY_ALL, notify_print, (void *) "Unknown type" );
112 WMNotifyMaskUpdate( app ); /* Mask isn't actually set till we do this */
114 /* set command to use to startup this */
115 XSetCommand(dpy, leader, argv, argc);
117 /* create first window */
118 newwin(NULL, 0, 0);
121 XFlush(dpy);
122 while( 1 ) {
123 XEvent ev;
124 XNextEvent(dpy, &ev);
125 if (ev.type==ClientMessage) {
126 if (ev.xclient.data.l[0]==delete_win) {
127 XDestroyWindow(dpy,ev.xclient.window);
128 break;
131 WMProcessEvent(app, &ev);
133 exit(0);