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(void *foo
, int item
, Time time
)
34 printf("pushed item %i\n", item
);
37 static void quit(void *foo
, int item
, Time time
)
42 static void hide(void *foo
, int item
, Time time
)
44 WMHideApplication(app
);
47 Atom delete_win
, miniaturize_win
;
49 GNUstepWMAttributes attr
;
55 static void newwin(void *foo
, int item
, Time time
)
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
);
70 classhint
.res_name
= "test";
71 classhint
.res_class
= "Test";
72 XSetClassHint(dpy
, win
, &classhint
);
74 /* set WindowMaker hints */
75 attr
.flags
= GSMiniaturizePixmapAttr
| GSMiniaturizeMaskAttr
;
76 attr
.miniaturize_pixmap
= XCreateBitmapFromData(dpy
, DefaultRootWindow(dpy
), bits
, 10, 10);
78 attr
.miniaturize_mask
= XCreateBitmapFromData(dpy
, DefaultRootWindow(dpy
), mbits
, 10, 10);
80 attr.flags |= GSWindowStyleAttr;
81 attr.window_style = NSTitledWindowMask|NSClosableWindowMask;
84 WMSetWindowAttributes(dpy
, win
, &attr
);
86 hints
= XAllocWMHints();
87 /* set window group leader */
88 hints
->window_group
= leader
;
89 hints
->flags
= WindowGroupHint
;
90 XSetWMHints(dpy
, win
, hints
);
92 WMAppAddWindow(app
, win
);
96 int main(int argc
, char **argv
)
100 dpy
= XOpenDisplay("");
102 puts("could not open display!");
105 delete_win
= XInternAtom(dpy
, "WM_DELETE_WINDOW", False
);
106 miniaturize_win
= XInternAtom(dpy
, "_GNUSTEP_WM_MINIATURIZE_WINDOW", False
);
108 leader
= XCreateSimpleWindow(dpy
, DefaultRootWindow(dpy
), 10, 10, 10, 10, 0, 0, 0);
110 classhint
.res_name
= "test";
111 classhint
.res_class
= "Test";
112 XSetClassHint(dpy
, leader
, &classhint
);
114 /* set window group leader to self */
115 hints
= XAllocWMHints();
116 hints
->window_group
= leader
;
117 hints
->flags
= WindowGroupHint
;
118 XSetWMHints(dpy
, leader
, hints
);
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
);
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
);
133 WMAppSetMainMenu(app
, menu
);
137 /* set command to use to startup this */
138 XSetCommand(dpy
, leader
, argv
, argc
);
140 /* create first window */
144 puts("Run xprop on the test window to see the properties defined");
145 while (wincount
> 0) {
147 XNextEvent(dpy
, &ev
);
148 if (ev
.type
== ClientMessage
) {
149 if (ev
.xclient
.data
.l
[0] == delete_win
) {
150 XDestroyWindow(dpy
, ev
.xclient
.window
);
152 } else if (ev
.xclient
.data
.l
[0] == miniaturize_win
) {
153 puts("You've pushed the maximize window button");
156 WMProcessEvent(app
, &ev
);