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.
16 #include <X11/Xutil.h>
17 #include <X11/Xproto.h>
20 #ifdef HAVE_STDNORETURN
21 #include <stdnoreturn.h>
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
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
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
65 WMHideApplication(app
);
68 Atom delete_win
, miniaturize_win
;
70 GNUstepWMAttributes attr
;
76 static void newwin(int item
)
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
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
);
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("");
126 puts("could not open display!");
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);
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
);
162 /* set command to use to startup this */
163 XSetCommand(dpy
, leader
, argv
, argc
);
165 /* create first window */
169 puts("Run xprop on the test window to see the properties defined");
170 while (wincount
> 0) {
172 XNextEvent(dpy
, &ev
);
173 if (ev
.type
== ClientMessage
) {
174 if (ev
.xclient
.data
.l
[0] == delete_win
) {
175 XDestroyWindow(dpy
, ev
.xclient
.window
);
177 } else if (ev
.xclient
.data
.l
[0] == miniaturize_win
) {
178 puts("You've pushed the maximize window button");
181 WMProcessEvent(app
, &ev
);