wrlib: moved 'RShutdown' from 'load.c' to 'misc.c' for consistency
[wmaker-crm.git] / test / wtest.c
blob37f285d98569edf26375b77a24d10e975fb88aa2
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(int item)
34 printf("pushed item %i\n", item);
37 static void quit(int item)
40 * This parameter is not used, but because we're a call-back we have a fixed
41 * prototype, so we tell the compiler it is ok to avoid a spurious unused
42 * variable warning
44 (void) item;
46 exit(0);
49 static void hide(int item)
52 * This parameter is not used, but because we're a call-back we have a fixed
53 * prototype, so we tell the compiler it is ok to avoid a spurious unused
54 * variable warning
56 (void) item;
58 WMHideApplication(app);
61 Atom delete_win, miniaturize_win;
62 Atom prots[6];
63 GNUstepWMAttributes attr;
64 XWMHints *hints;
65 WMMenu *menu;
66 WMMenu *submenu;
67 int wincount = 0;
69 static void newwin(int item)
71 Window win;
72 XClassHint classhint;
73 char title[100];
76 * This parameter is not used, but because we're a call-back we have a fixed
77 * prototype, so we tell the compiler it is ok to avoid a spurious unused
78 * variable warning
80 (void) item;
82 wincount++;
83 win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10 * wincount, 10 * wincount, 200, 100, 0, 0, 0);
84 prots[0] = delete_win;
85 prots[1] = miniaturize_win;
86 XSetWMProtocols(dpy, win, prots, 2);
87 sprintf(title, "Test Window %i", wincount);
88 XStoreName(dpy, win, title);
90 /* set class hint */
91 classhint.res_name = "test";
92 classhint.res_class = "Test";
93 XSetClassHint(dpy, win, &classhint);
95 /* set WindowMaker hints */
96 attr.flags = GSMiniaturizePixmapAttr | GSMiniaturizeMaskAttr;
97 attr.miniaturize_pixmap = XCreateBitmapFromData(dpy, DefaultRootWindow(dpy), bits, 10, 10);
99 attr.miniaturize_mask = XCreateBitmapFromData(dpy, DefaultRootWindow(dpy), mbits, 10, 10);
101 WMSetWindowAttributes(dpy, win, &attr);
103 hints = XAllocWMHints();
104 /* set window group leader */
105 hints->window_group = leader;
106 hints->flags = WindowGroupHint;
107 XSetWMHints(dpy, win, hints);
109 WMAppAddWindow(app, win);
110 XMapWindow(dpy, win);
113 int main(int argc, char **argv)
115 XClassHint classhint;
117 dpy = XOpenDisplay("");
118 if (!dpy) {
119 puts("could not open display!");
120 exit(1);
122 delete_win = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
123 miniaturize_win = XInternAtom(dpy, "_GNUSTEP_WM_MINIATURIZE_WINDOW", False);
125 leader = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 10, 10, 0, 0, 0);
127 /* set class hint */
128 classhint.res_name = "test";
129 classhint.res_class = "Test";
130 XSetClassHint(dpy, leader, &classhint);
132 /* set window group leader to self */
133 hints = XAllocWMHints();
134 hints->window_group = leader;
135 hints->flags = WindowGroupHint;
136 XSetWMHints(dpy, leader, hints);
138 /* create app context */
139 app = WMAppCreateWithMain(dpy, DefaultScreen(dpy), leader);
140 menu = WMMenuCreate(app, "Test Menu");
141 submenu = WMMenuCreate(app, "File");
142 WMMenuAddSubmenu(menu, "File", submenu);
144 WMMenuAddItem(menu, "Hide", (WMMenuAction) hide, NULL, NULL, NULL);
145 WMMenuAddItem(menu, "Quit", (WMMenuAction) quit, NULL, NULL, NULL);
146 WMMenuAddItem(submenu, "New", (WMMenuAction) newwin, NULL, NULL, NULL);
147 WMMenuAddItem(submenu, "Open", (WMMenuAction) callback, NULL, NULL, NULL);
148 WMMenuAddItem(submenu, "Save", (WMMenuAction) callback, NULL, NULL, NULL);
149 WMMenuAddItem(submenu, "Save As...", (WMMenuAction) callback, NULL, NULL, NULL);
151 WMAppSetMainMenu(app, menu);
153 WMRealizeMenus(app);
155 /* set command to use to startup this */
156 XSetCommand(dpy, leader, argv, argc);
158 /* create first window */
159 newwin(0);
161 XFlush(dpy);
162 puts("Run xprop on the test window to see the properties defined");
163 while (wincount > 0) {
164 XEvent ev;
165 XNextEvent(dpy, &ev);
166 if (ev.type == ClientMessage) {
167 if (ev.xclient.data.l[0] == delete_win) {
168 XDestroyWindow(dpy, ev.xclient.window);
169 wincount--;
170 } else if (ev.xclient.data.l[0] == miniaturize_win) {
171 puts("You've pushed the maximize window button");
174 WMProcessEvent(app, &ev);
176 exit(0);