File: notest.c

package info (click to toggle)
wmaker 0.96.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 15,332 kB
  • sloc: ansic: 99,482; sh: 7,068; perl: 3,423; makefile: 1,647; lisp: 219; python: 34
file content (122 lines) | stat: -rw-r--r-- 3,042 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/* quick and dirty test application that demonstrates: Notify grabbing
 *
 * TODO: remake
 */

#include <stdio.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/Xproto.h>
#include <WMaker.h>

Display *dpy;
Window leader;
WMAppContext *app;
Atom delete_win;
Atom prots[6];
XWMHints *hints;
WMMenu *menu;

static void quit(void *foo, int item, Time time)
{
	exit(0);
}

static void hide(void *foo, int item, Time time)
{
	WMHideApplication(app);
}

int notify_print(int id, XEvent * event, void *data)
{
	printf("Got notification 0x%x, window 0x%lx, data '%s'\n", id, event->xclient.data.l[1], (char *)data);
	return True;
}

static void newwin(void *foo, int item, Time time)
{
	Window win;
	XClassHint classhint;
	char title[100];

	win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, 200, 100, 0, 0, 0);
	prots[0] = delete_win;
	XSetWMProtocols(dpy, win, prots, 1);
	sprintf(title, "Notify Test Window");
	XStoreName(dpy, win, title);

	/* set class hint */
	classhint.res_name = "notest";
	classhint.res_class = "Notest";
	XSetClassHint(dpy, win, &classhint);

	hints = XAllocWMHints();
	/* set window group leader */
	hints->window_group = leader;
	hints->flags = WindowGroupHint;
	XSetWMHints(dpy, win, hints);

	WMAppAddWindow(app, win);
	XMapWindow(dpy, win);
}

int main(int argc, char **argv)
{
	XClassHint classhint;

	dpy = XOpenDisplay("");
	if (!dpy) {
		puts("could not open display!");
		exit(1);
	}
	delete_win = XInternAtom(dpy, "WM_DELETE_WINDOW", False);

	leader = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 10, 10, 0, 0, 0);
	/* set class hint */
	classhint.res_name = "notest";
	classhint.res_class = "Notest";
	XSetClassHint(dpy, leader, &classhint);

	/* set window group leader to self */
	hints = XAllocWMHints();
	hints->window_group = leader;
	hints->flags = WindowGroupHint;
	XSetWMHints(dpy, leader, hints);

	/* create app context */
	app = WMAppCreateWithMain(dpy, DefaultScreen(dpy), leader);
	menu = WMMenuCreate(app, "Notify Test Menu");
	WMMenuAddItem(menu, "Hide", (WMMenuAction) hide, NULL, NULL, NULL);
	WMMenuAddItem(menu, "Quit", (WMMenuAction) quit, NULL, NULL, NULL);

	WMAppSetMainMenu(app, menu);
	WMRealizeMenus(app);

	/* Get some WindowMaker notifications */
	WMNotifySet(app, WMN_APP_START, notify_print, (void *)"App start");
	WMNotifySet(app, WMN_APP_EXIT, notify_print, (void *)"App end");
	WMNotifySet(app, WMN_WIN_FOCUS, notify_print, (void *)"Focus in");
	WMNotifySet(app, WMN_WIN_UNFOCUS, notify_print, (void *)"Focus out");
	WMNotifySet(app, WMN_NOTIFY_ALL, notify_print, (void *)"Unknown type");
	WMNotifyMaskUpdate(app);	/* Mask isn't actually set till we do this */

	/* set command to use to startup this */
	XSetCommand(dpy, leader, argv, argc);

	/* create first window */
	newwin(NULL, 0, 0);

	XFlush(dpy);
	while (1) {
		XEvent ev;
		XNextEvent(dpy, &ev);
		if (ev.type == ClientMessage) {
			if (ev.xclient.data.l[0] == delete_win) {
				XDestroyWindow(dpy, ev.xclient.window);
				break;
			}
		}
		WMProcessEvent(app, &ev);
	}
	exit(0);
}