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 unsigned char bits
[] = {
19 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
20 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
22 static unsigned char mbits
[] = {
23 0xff, 0x03, 0xff, 0x01, 0xff, 0x00, 0x7f, 0x00, 0x3f, 0x00, 0x1f, 0x00,
24 0x0f, 0x00, 0x07, 0x00, 0x03, 0x00, 0x01, 0x00};
33 callback(void *foo
, int item
, Time time
)
35 printf("pushed item %i\n", item
);
39 quit(void *foo
, int item
, Time time
)
47 hide(void *foo
, int item
, Time time
)
49 WMHideApplication(app
);
53 Atom delete_win
, miniaturize_win
;
55 GNUstepWMAttributes attr
;
62 newwin(void *foo
, int item
, Time time
)
69 win
= XCreateSimpleWindow(dpy
, DefaultRootWindow(dpy
),
70 10*wincount
, 10*wincount
, 200, 100, 0, 0, 0);
71 prots
[0] = delete_win
;
72 prots
[1] = miniaturize_win
;
73 XSetWMProtocols(dpy
, win
, prots
, 2);
74 sprintf(title
, "Test Window %i", wincount
);
75 XStoreName(dpy
, win
, title
);
78 classhint
.res_name
= "test";
79 classhint
.res_class
= "Test";
80 XSetClassHint(dpy
, win
, &classhint
);
82 /* set WindowMaker hints */
83 attr
.flags
= GSMiniaturizePixmapAttr
|GSMiniaturizeMaskAttr
;
84 attr
.miniaturize_pixmap
=
85 XCreateBitmapFromData(dpy
, DefaultRootWindow(dpy
), bits
, 10, 10);
87 attr
.miniaturize_mask
=
88 XCreateBitmapFromData(dpy
, DefaultRootWindow(dpy
), mbits
, 10, 10);
90 attr.flags |= GSWindowStyleAttr;
91 attr.window_style = NSTitledWindowMask|NSClosableWindowMask;
94 WMSetWindowAttributes(dpy
, win
, &attr
);
96 hints
= XAllocWMHints();
97 /* set window group leader */
98 hints
->window_group
= leader
;
99 hints
->flags
= WindowGroupHint
;
100 XSetWMHints(dpy
, win
, hints
);
102 WMAppAddWindow(app
, win
);
103 XMapWindow(dpy
, win
);
106 int main(int argc
, char **argv
)
108 XClassHint classhint
;
110 dpy
= XOpenDisplay("");
112 puts("could not open display!");
115 delete_win
= XInternAtom(dpy
, "WM_DELETE_WINDOW", False
);
116 miniaturize_win
= XInternAtom(dpy
, "_GNUSTEP_WM_MINIATURIZE_WINDOW",
119 leader
= XCreateSimpleWindow(dpy
, DefaultRootWindow(dpy
), 10, 10, 10, 10,
122 classhint
.res_name
= "test";
123 classhint
.res_class
= "Test";
124 XSetClassHint(dpy
, leader
, &classhint
);
126 /* set window group leader to self */
127 hints
= XAllocWMHints();
128 hints
->window_group
= leader
;
129 hints
->flags
= WindowGroupHint
;
130 XSetWMHints(dpy
, leader
, hints
);
132 /* create app context */
133 app
= WMAppCreateWithMain(dpy
, DefaultScreen(dpy
), leader
);
134 menu
= WMMenuCreate(app
, "Test Menu");
135 submenu
= WMMenuCreate(app
, "File");
136 WMMenuAddSubmenu(menu
, "File", submenu
);
138 WMMenuAddItem(menu
, "Hide", (WMMenuAction
)hide
, NULL
, NULL
, NULL
);
139 WMMenuAddItem(menu
, "Quit", (WMMenuAction
)quit
, NULL
, NULL
, NULL
);
140 WMMenuAddItem(submenu
, "New", (WMMenuAction
)newwin
, NULL
, NULL
, NULL
);
141 WMMenuAddItem(submenu
, "Open", (WMMenuAction
)callback
, NULL
, NULL
, NULL
);
142 WMMenuAddItem(submenu
, "Save", (WMMenuAction
)callback
, NULL
, NULL
, NULL
);
143 WMMenuAddItem(submenu
, "Save As...", (WMMenuAction
)callback
, NULL
, NULL
, NULL
);
145 WMAppSetMainMenu(app
, menu
);
149 /* set command to use to startup this */
150 XSetCommand(dpy
, leader
, argv
, argc
);
152 /* create first window */
157 puts("Run xprop on the test window to see the properties defined");
160 XNextEvent(dpy
, &ev
);
161 if (ev
.type
==ClientMessage
) {
162 if (ev
.xclient
.data
.l
[0]==delete_win
) {
163 XDestroyWindow(dpy
,ev
.xclient
.window
);
165 } else if (ev
.xclient
.data
.l
[0]==miniaturize_win
) {
166 puts("You've pushed the maximize window button");
169 WMProcessEvent(app
, &ev
);