wmaker: Added 'const' attribute to function 'wDefaultsInitDomain'
[wmaker-crm.git] / test / wtest.c
blob8490e9ca2ae3a593fed44d0d6e3c4f86a97410bf
1 /* quick and dirty test application that demonstrates: application hiding,
2 * application defined titlebar button images, application defined
3 * titlebar button actions, application menus, docking and
4 * window manager commands
6 * Note that the windows don't have a window command menu.
8 * TODO: remake
9 */
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <X11/Xlib.h>
14 #include <X11/Xutil.h>
15 #include <X11/Xproto.h>
16 #include <WMaker.h>
18 static char bits[] = {
19 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
20 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
23 static char mbits[] = {
24 0xff, 0x03, 0xff, 0x01, 0xff, 0x00, 0x7f, 0x00, 0x3f, 0x00, 0x1f, 0x00,
25 0x0f, 0x00, 0x07, 0x00, 0x03, 0x00, 0x01, 0x00
28 Display *dpy;
29 Window leader;
30 WMAppContext *app;
32 static void callback(void *foo, int item, Time time)
34 printf("pushed item %i\n", item);
37 static void quit(void *foo, int item, Time time)
39 exit(0);
42 static void hide(void *foo, int item, Time time)
44 WMHideApplication(app);
47 Atom delete_win, miniaturize_win;
48 Atom prots[6];
49 GNUstepWMAttributes attr;
50 XWMHints *hints;
51 WMMenu *menu;
52 WMMenu *submenu;
53 int wincount = 0;
55 static void newwin(void *foo, int item, Time time)
57 Window win;
58 XClassHint classhint;
59 char title[100];
61 wincount++;
62 win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10 * wincount, 10 * wincount, 200, 100, 0, 0, 0);
63 prots[0] = delete_win;
64 prots[1] = miniaturize_win;
65 XSetWMProtocols(dpy, win, prots, 2);
66 sprintf(title, "Test Window %i", wincount);
67 XStoreName(dpy, win, title);
69 /* set class hint */
70 classhint.res_name = "test";
71 classhint.res_class = "Test";
72 XSetClassHint(dpy, win, &classhint);
74 /* set WindowMaker hints */
75 attr.flags = GSMiniaturizePixmapAttr | GSMiniaturizeMaskAttr;
76 attr.miniaturize_pixmap = XCreateBitmapFromData(dpy, DefaultRootWindow(dpy), bits, 10, 10);
78 attr.miniaturize_mask = XCreateBitmapFromData(dpy, DefaultRootWindow(dpy), mbits, 10, 10);
80 attr.flags |= GSWindowStyleAttr;
81 attr.window_style = NSTitledWindowMask|NSClosableWindowMask;
84 WMSetWindowAttributes(dpy, win, &attr);
86 hints = XAllocWMHints();
87 /* set window group leader */
88 hints->window_group = leader;
89 hints->flags = WindowGroupHint;
90 XSetWMHints(dpy, win, hints);
92 WMAppAddWindow(app, win);
93 XMapWindow(dpy, win);
96 int main(int argc, char **argv)
98 XClassHint classhint;
100 dpy = XOpenDisplay("");
101 if (!dpy) {
102 puts("could not open display!");
103 exit(1);
105 delete_win = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
106 miniaturize_win = XInternAtom(dpy, "_GNUSTEP_WM_MINIATURIZE_WINDOW", False);
108 leader = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 10, 10, 0, 0, 0);
109 /* set class hint */
110 classhint.res_name = "test";
111 classhint.res_class = "Test";
112 XSetClassHint(dpy, leader, &classhint);
114 /* set window group leader to self */
115 hints = XAllocWMHints();
116 hints->window_group = leader;
117 hints->flags = WindowGroupHint;
118 XSetWMHints(dpy, leader, hints);
120 /* create app context */
121 app = WMAppCreateWithMain(dpy, DefaultScreen(dpy), leader);
122 menu = WMMenuCreate(app, "Test Menu");
123 submenu = WMMenuCreate(app, "File");
124 WMMenuAddSubmenu(menu, "File", submenu);
126 WMMenuAddItem(menu, "Hide", (WMMenuAction) hide, NULL, NULL, NULL);
127 WMMenuAddItem(menu, "Quit", (WMMenuAction) quit, NULL, NULL, NULL);
128 WMMenuAddItem(submenu, "New", (WMMenuAction) newwin, NULL, NULL, NULL);
129 WMMenuAddItem(submenu, "Open", (WMMenuAction) callback, NULL, NULL, NULL);
130 WMMenuAddItem(submenu, "Save", (WMMenuAction) callback, NULL, NULL, NULL);
131 WMMenuAddItem(submenu, "Save As...", (WMMenuAction) callback, NULL, NULL, NULL);
133 WMAppSetMainMenu(app, menu);
135 WMRealizeMenus(app);
137 /* set command to use to startup this */
138 XSetCommand(dpy, leader, argv, argc);
140 /* create first window */
141 newwin(NULL, 0, 0);
143 XFlush(dpy);
144 puts("Run xprop on the test window to see the properties defined");
145 while (wincount > 0) {
146 XEvent ev;
147 XNextEvent(dpy, &ev);
148 if (ev.type == ClientMessage) {
149 if (ev.xclient.data.l[0] == delete_win) {
150 XDestroyWindow(dpy, ev.xclient.window);
151 wincount--;
152 } else if (ev.xclient.data.l[0] == miniaturize_win) {
153 puts("You've pushed the maximize window button");
156 WMProcessEvent(app, &ev);
158 exit(0);