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
);
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
);
46 newwin(void *foo
, int item
, Time time
)
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
);
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
);
74 int main(int argc
, char **argv
)
78 dpy
= XOpenDisplay("");
80 puts("could not open display!");
83 delete_win
= XInternAtom(dpy
, "WM_DELETE_WINDOW", False
);
85 leader
= XCreateSimpleWindow(dpy
, DefaultRootWindow(dpy
), 10, 10, 10, 10,
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
);
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 */
125 XNextEvent(dpy
, &ev
);
126 if (ev
.type
==ClientMessage
) {
127 if (ev
.xclient
.data
.l
[0]==delete_win
) {
128 XDestroyWindow(dpy
,ev
.xclient
.window
);
132 WMProcessEvent(app
, &ev
);