Update Serbian translation from master branch
[wmaker-crm.git] / test / wtest.c
blob00b125098c920ec7edc7fceedc475cf4395f651a
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 "config.h"
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <X11/Xlib.h>
16 #include <X11/Xutil.h>
17 #include <X11/Xproto.h>
18 #include <WMaker.h>
20 #ifdef HAVE_STDNORETURN
21 #include <stdnoreturn.h>
22 #endif
25 static char bits[] = {
26 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
27 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
30 static char mbits[] = {
31 0xff, 0x03, 0xff, 0x01, 0xff, 0x00, 0x7f, 0x00, 0x3f, 0x00, 0x1f, 0x00,
32 0x0f, 0x00, 0x07, 0x00, 0x03, 0x00, 0x01, 0x00
35 Display *dpy;
36 Window leader;
37 WMAppContext *app;
39 static void callback(int item)
41 printf("pushed item %i\n", item);
44 static noreturn void quit(int item)
47 * This parameter is not used, but because we're a call-back we have a fixed
48 * prototype, so we tell the compiler it is ok to avoid a spurious unused
49 * variable warning
51 (void) item;
53 exit(0);
56 static void hide(int item)
59 * This parameter is not used, but because we're a call-back we have a fixed
60 * prototype, so we tell the compiler it is ok to avoid a spurious unused
61 * variable warning
63 (void) item;
65 WMHideApplication(app);
68 Atom delete_win, miniaturize_win;
69 Atom prots[6];
70 GNUstepWMAttributes attr;
71 XWMHints *hints;
72 WMMenu *menu;
73 WMMenu *submenu;
74 int wincount = 0;
76 static void newwin(int item)
78 Window win;
79 XClassHint classhint;
80 char title[100];
83 * This parameter is not used, but because we're a call-back we have a fixed
84 * prototype, so we tell the compiler it is ok to avoid a spurious unused
85 * variable warning
87 (void) item;
89 wincount++;
90 win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10 * wincount, 10 * wincount, 200, 100, 0, 0, 0);
91 prots[0] = delete_win;
92 prots[1] = miniaturize_win;
93 XSetWMProtocols(dpy, win, prots, 2);
94 sprintf(title, "Test Window %i", wincount);
95 XStoreName(dpy, win, title);
97 /* set class hint */
98 classhint.res_name = "test";
99 classhint.res_class = "Test";
100 XSetClassHint(dpy, win, &classhint);
102 /* set WindowMaker hints */
103 attr.flags = GSMiniaturizePixmapAttr | GSMiniaturizeMaskAttr;
104 attr.miniaturize_pixmap = XCreateBitmapFromData(dpy, DefaultRootWindow(dpy), bits, 10, 10);
106 attr.miniaturize_mask = XCreateBitmapFromData(dpy, DefaultRootWindow(dpy), mbits, 10, 10);
108 WMSetWindowAttributes(dpy, win, &attr);
110 hints = XAllocWMHints();
111 /* set window group leader */
112 hints->window_group = leader;
113 hints->flags = WindowGroupHint;
114 XSetWMHints(dpy, win, hints);
116 WMAppAddWindow(app, win);
117 XMapWindow(dpy, win);
120 int main(int argc, char **argv)
122 XClassHint classhint;
124 dpy = XOpenDisplay("");
125 if (!dpy) {
126 puts("could not open display!");
127 exit(1);
129 delete_win = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
130 miniaturize_win = XInternAtom(dpy, "_GNUSTEP_WM_MINIATURIZE_WINDOW", False);
132 leader = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 10, 10, 0, 0, 0);
134 /* set class hint */
135 classhint.res_name = "test";
136 classhint.res_class = "Test";
137 XSetClassHint(dpy, leader, &classhint);
139 /* set window group leader to self */
140 hints = XAllocWMHints();
141 hints->window_group = leader;
142 hints->flags = WindowGroupHint;
143 XSetWMHints(dpy, leader, hints);
145 /* create app context */
146 app = WMAppCreateWithMain(dpy, DefaultScreen(dpy), leader);
147 menu = WMMenuCreate(app, "Test Menu");
148 submenu = WMMenuCreate(app, "File");
149 WMMenuAddSubmenu(menu, "File", submenu);
151 WMMenuAddItem(menu, "Hide", (WMMenuAction) hide, NULL, NULL, NULL);
152 WMMenuAddItem(menu, "Quit", (WMMenuAction) quit, NULL, NULL, NULL);
153 WMMenuAddItem(submenu, "New", (WMMenuAction) newwin, NULL, NULL, NULL);
154 WMMenuAddItem(submenu, "Open", (WMMenuAction) callback, NULL, NULL, NULL);
155 WMMenuAddItem(submenu, "Save", (WMMenuAction) callback, NULL, NULL, NULL);
156 WMMenuAddItem(submenu, "Save As...", (WMMenuAction) callback, NULL, NULL, NULL);
158 WMAppSetMainMenu(app, menu);
160 WMRealizeMenus(app);
162 /* set command to use to startup this */
163 XSetCommand(dpy, leader, argv, argc);
165 /* create first window */
166 newwin(0);
168 XFlush(dpy);
169 puts("Run xprop on the test window to see the properties defined");
170 while (wincount > 0) {
171 XEvent ev;
172 XNextEvent(dpy, &ev);
173 if (ev.type == ClientMessage) {
174 if (ev.xclient.data.l[0] == delete_win) {
175 XDestroyWindow(dpy, ev.xclient.window);
176 wincount--;
177 } else if (ev.xclient.data.l[0] == miniaturize_win) {
178 puts("You've pushed the maximize window button");
181 WMProcessEvent(app, &ev);
183 exit(0);