1 /* quick and dirty test application that demonstrates: Notify grabbing
9 #include <X11/Xproto.h>
23 quit(void *foo
, int item
, Time time
)
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
);
45 newwin(void *foo
, int item
, Time time
)
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
);
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
);
73 int main(int argc
, char **argv
)
77 dpy
= XOpenDisplay("");
79 puts("could not open display!");
82 delete_win
= XInternAtom(dpy
, "WM_DELETE_WINDOW", False
);
84 leader
= XCreateSimpleWindow(dpy
, DefaultRootWindow(dpy
), 10, 10, 10, 10,
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
);
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 */
124 XNextEvent(dpy
, &ev
);
125 if (ev
.type
==ClientMessage
) {
126 if (ev
.xclient
.data
.l
[0]==delete_win
) {
127 XDestroyWindow(dpy
,ev
.xclient
.window
);
131 WMProcessEvent(app
, &ev
);