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.
14 #include <X11/Xutil.h>
15 #include <X11/Xproto.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
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
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
58 WMHideApplication(app
);
61 Atom delete_win
, miniaturize_win
;
63 GNUstepWMAttributes attr
;
69 static void newwin(int item
)
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
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
);
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("");
119 puts("could not open display!");
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);
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
);
155 /* set command to use to startup this */
156 XSetCommand(dpy
, leader
, argv
, argc
);
158 /* create first window */
162 puts("Run xprop on the test window to see the properties defined");
163 while (wincount
> 0) {
165 XNextEvent(dpy
, &ev
);
166 if (ev
.type
== ClientMessage
) {
167 if (ev
.xclient
.data
.l
[0] == delete_win
) {
168 XDestroyWindow(dpy
, ev
.xclient
.window
);
170 } else if (ev
.xclient
.data
.l
[0] == miniaturize_win
) {
171 puts("You've pushed the maximize window button");
174 WMProcessEvent(app
, &ev
);