Change to the linux kernel coding style
[wmaker-crm.git] / test / wtest.c
Commit [+]AuthorDateLineData
9d2e6ef9 scottc1998-09-29 22:36:29 +00001/* 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
6830b057 dan2004-10-12 21:28:27 +00004 * window manager commands
5 *
9d2e6ef9 scottc1998-09-29 22:36:29 +00006 * Note that the windows don't have a window command menu.
7 *
8 * TODO: remake
9 */
10
11#include <stdio.h>
9aca0d5f dan2004-10-12 01:34:32 +000012#include <stdlib.h>
9d2e6ef9 scottc1998-09-29 22:36:29 +000013#include <X11/Xlib.h>
14#include <X11/Xutil.h>
15#include <X11/Xproto.h>
16#include <WMaker.h>
17
c0317dda dan2005-08-22 23:58:19 +000018static char bits[] = {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020019 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
20 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff
21};
9d2e6ef9 scottc1998-09-29 22:36:29 +000022
c0317dda dan2005-08-22 23:58:19 +000023static char mbits[] = {
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020024 0xff, 0x03, 0xff, 0x01, 0xff, 0x00, 0x7f, 0x00, 0x3f, 0x00, 0x1f, 0x00,
25 0x0f, 0x00, 0x07, 0x00, 0x03, 0x00, 0x01, 0x00
26};
9d2e6ef9 scottc1998-09-29 22:36:29 +000027
28Display *dpy;
29Window leader;
30WMAppContext *app;
31
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020032static void callback(void *foo, int item, Time time)
9d2e6ef9 scottc1998-09-29 22:36:29 +000033{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020034 printf("pushed item %i\n", item);
9d2e6ef9 scottc1998-09-29 22:36:29 +000035}
36
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020037static void quit(void *foo, int item, Time time)
9d2e6ef9 scottc1998-09-29 22:36:29 +000038{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020039 exit(0);
9d2e6ef9 scottc1998-09-29 22:36:29 +000040}
41
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020042static void hide(void *foo, int item, Time time)
9d2e6ef9 scottc1998-09-29 22:36:29 +000043{
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020044 WMHideApplication(app);
9d2e6ef9 scottc1998-09-29 22:36:29 +000045}
46
9d2e6ef9 scottc1998-09-29 22:36:29 +000047Atom delete_win, miniaturize_win;
48Atom prots[6];
49GNUstepWMAttributes attr;
50XWMHints *hints;
51WMMenu *menu;
52WMMenu *submenu;
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020053int wincount = 0;
9d2e6ef9 scottc1998-09-29 22:36:29 +000054
688a56e8 Carlos R. Mafra2009-08-20 00:59:40 +020055static void newwin(void *foo, int item, Time time)
9d2e6ef9 scottc1998-09-29 22:36:29 +000056{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020057 Window win;
58 XClassHint classhint;
59 char title[100];
60
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);
68
69 /* set class hint */
70 classhint.res_name = "test";
71 classhint.res_class = "Test";
72 XSetClassHint(dpy, win, &classhint);
73
74 /* set WindowMaker hints */
75 attr.flags = GSMiniaturizePixmapAttr | GSMiniaturizeMaskAttr;
76 attr.miniaturize_pixmap = XCreateBitmapFromData(dpy, DefaultRootWindow(dpy), bits, 10, 10);
77
78 attr.miniaturize_mask = XCreateBitmapFromData(dpy, DefaultRootWindow(dpy), mbits, 10, 10);
79 /*
80 attr.flags |= GSWindowStyleAttr;
81 attr.window_style = NSTitledWindowMask|NSClosableWindowMask;
82 */
83
84 WMSetWindowAttributes(dpy, win, &attr);
85
86 hints = XAllocWMHints();
87 /* set window group leader */
88 hints->window_group = leader;
89 hints->flags = WindowGroupHint;
90 XSetWMHints(dpy, win, hints);
91
92 WMAppAddWindow(app, win);
93 XMapWindow(dpy, win);
9d2e6ef9 scottc1998-09-29 22:36:29 +000094}
95
96int main(int argc, char **argv)
6830b057 dan2004-10-12 21:28:27 +000097{
688a56e8
CM
Carlos R. Mafra2009-08-20 00:59:40 +020098 XClassHint classhint;
99
100 dpy = XOpenDisplay("");
101 if (!dpy) {
102 puts("could not open display!");
103 exit(1);
104 }
105 delete_win = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
106 miniaturize_win = XInternAtom(dpy, "_GNUSTEP_WM_MINIATURIZE_WINDOW", False);
107
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);
113
114 /* set window group leader to self */
115 hints = XAllocWMHints();
116 hints->window_group = leader;
117 hints->flags = WindowGroupHint;
118 XSetWMHints(dpy, leader, hints);
119
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);
125
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);
132
133 WMAppSetMainMenu(app, menu);
134
135 WMRealizeMenus(app);
136
137 /* set command to use to startup this */
138 XSetCommand(dpy, leader, argv, argc);
139
140 /* create first window */
141 newwin(NULL, 0, 0);
142
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");
154 }
155 }
156 WMProcessEvent(app, &ev);
157 }
158 exit(0);
9d2e6ef9 scottc1998-09-29 22:36:29 +0000159}