- Made scrolling of text in dialog panel smoother
[wmaker-crm.git] / test / wtest.c
blob563dbe852a772e0596f2bf2f6202927a6514a3e5
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
5 *
6 * Note that the windows don't have a window command menu.
8 * TODO: remake
9 */
11 #include <stdio.h>
12 #include <X11/Xlib.h>
13 #include <X11/Xutil.h>
14 #include <X11/Xproto.h>
15 #include <WMaker.h>
17 static unsigned char bits[] = {
18 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
19 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
21 static unsigned char mbits[] = {
22 0xff, 0x03, 0xff, 0x01, 0xff, 0x00, 0x7f, 0x00, 0x3f, 0x00, 0x1f, 0x00,
23 0x0f, 0x00, 0x07, 0x00, 0x03, 0x00, 0x01, 0x00};
26 Display *dpy;
27 Window leader;
28 WMAppContext *app;
31 static void
32 callback(void *foo, int item, Time time)
34 printf("pushed item %i\n", item);
37 static void
38 quit(void *foo, int item, Time time)
40 exit(0);
45 static void
46 hide(void *foo, int item, Time time)
48 WMHideApplication(app);
52 Atom delete_win, miniaturize_win;
53 Atom prots[6];
54 GNUstepWMAttributes attr;
55 XWMHints *hints;
56 WMMenu *menu;
57 WMMenu *submenu;
58 int wincount=0;
60 static void
61 newwin(void *foo, int item, Time time)
63 Window win;
64 XClassHint classhint;
65 char title[100];
67 wincount++;
68 win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy),
69 10*wincount, 10*wincount, 200, 100, 0, 0, 0);
70 prots[0] = delete_win;
71 prots[1] = miniaturize_win;
72 XSetWMProtocols(dpy, win, prots, 2);
73 sprintf(title, "Test Window %i", wincount);
74 XStoreName(dpy, win, title);
76 /* set class hint */
77 classhint.res_name = "test";
78 classhint.res_class = "Test";
79 XSetClassHint(dpy, win, &classhint);
81 /* set WindowMaker hints */
82 attr.flags = GSMiniaturizePixmapAttr|GSMiniaturizeMaskAttr;
83 attr.miniaturize_pixmap =
84 XCreateBitmapFromData(dpy, DefaultRootWindow(dpy), bits, 10, 10);
86 attr.miniaturize_mask =
87 XCreateBitmapFromData(dpy, DefaultRootWindow(dpy), mbits, 10, 10);
88 /*
89 attr.flags |= GSWindowStyleAttr;
90 attr.window_style = NSTitledWindowMask|NSClosableWindowMask;
93 WMSetWindowAttributes(dpy, win, &attr);
95 hints = XAllocWMHints();
96 /* set window group leader */
97 hints->window_group = leader;
98 hints->flags = WindowGroupHint;
99 XSetWMHints(dpy, win, hints);
101 WMAppAddWindow(app, win);
102 XMapWindow(dpy, win);
105 int main(int argc, char **argv)
107 XClassHint classhint;
109 dpy = XOpenDisplay("");
110 if (!dpy) {
111 puts("could not open display!");
112 exit(1);
114 delete_win = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
115 miniaturize_win = XInternAtom(dpy, "_GNUSTEP_WM_MINIATURIZE_WINDOW",
116 False);
118 leader = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 10, 10,
119 0, 0, 0);
120 /* set class hint */
121 classhint.res_name = "test";
122 classhint.res_class = "Test";
123 XSetClassHint(dpy, leader, &classhint);
125 /* set window group leader to self */
126 hints = XAllocWMHints();
127 hints->window_group = leader;
128 hints->flags = WindowGroupHint;
129 XSetWMHints(dpy, leader, hints);
131 /* create app context */
132 app = WMAppCreateWithMain(dpy, DefaultScreen(dpy), leader);
133 menu = WMMenuCreate(app, "Test Menu");
134 submenu = WMMenuCreate(app, "File");
135 WMMenuAddSubmenu(menu, "File", submenu);
137 WMMenuAddItem(menu, "Hide", (WMMenuAction)hide, NULL, NULL, NULL);
138 WMMenuAddItem(menu, "Quit", (WMMenuAction)quit, NULL, NULL, NULL);
139 WMMenuAddItem(submenu, "New", (WMMenuAction)newwin, NULL, NULL, NULL);
140 WMMenuAddItem(submenu, "Open", (WMMenuAction)callback, NULL, NULL, NULL);
141 WMMenuAddItem(submenu, "Save", (WMMenuAction)callback, NULL, NULL, NULL);
142 WMMenuAddItem(submenu, "Save As...", (WMMenuAction)callback, NULL, NULL, NULL);
144 WMAppSetMainMenu(app, menu);
146 WMRealizeMenus(app);
148 /* set command to use to startup this */
149 XSetCommand(dpy, leader, argv, argc);
151 /* create first window */
152 newwin(NULL, 0, 0);
155 XFlush(dpy);
156 puts("Run xprop on the test window to see the properties defined");
157 while (wincount>0) {
158 XEvent ev;
159 XNextEvent(dpy, &ev);
160 if (ev.type==ClientMessage) {
161 if (ev.xclient.data.l[0]==delete_win) {
162 XDestroyWindow(dpy,ev.xclient.window);
163 wincount--;
164 } else if (ev.xclient.data.l[0]==miniaturize_win) {
165 puts("You've pushed the maximize window button");
168 WMProcessEvent(app, &ev);
170 exit(0);