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.
13 #include <X11/Xutil.h>
14 #include <X11/Xproto.h>
17 static unsigned char bits
[] = {
18 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
19 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
21 static unsigned char mbits
[] = {
22 0xff, 0x03, 0xff, 0x01, 0xff, 0x00, 0x7f, 0x00, 0x3f, 0x00, 0x1f, 0x00,
23 0x0f, 0x00, 0x07, 0x00, 0x03, 0x00, 0x01, 0x00};
32 callback(void *foo
, int item
, Time time
)
34 printf("pushed item %i\n", item
);
38 quit(void *foo
, int item
, Time time
)
46 hide(void *foo
, int item
, Time time
)
48 WMHideApplication(app
);
52 Atom delete_win
, miniaturize_win
;
54 GNUstepWMAttributes attr
;
61 newwin(void *foo
, int item
, Time time
)
68 win
= XCreateSimpleWindow(dpy
, DefaultRootWindow(dpy
),
69 10*wincount
, 10*wincount
, 200, 100, 0, 0, 0);
70 prots
[0] = delete_win
;
71 prots
[1] = miniaturize_win
;
72 XSetWMProtocols(dpy
, win
, prots
, 2);
73 sprintf(title
, "Test Window %i", wincount
);
74 XStoreName(dpy
, win
, title
);
77 classhint
.res_name
= "test";
78 classhint
.res_class
= "Test";
79 XSetClassHint(dpy
, win
, &classhint
);
81 /* set WindowMaker hints */
82 attr
.flags
= GSMiniaturizePixmapAttr
|GSMiniaturizeMaskAttr
;
83 attr
.miniaturize_pixmap
=
84 XCreateBitmapFromData(dpy
, DefaultRootWindow(dpy
), bits
, 10, 10);
86 attr
.miniaturize_mask
=
87 XCreateBitmapFromData(dpy
, DefaultRootWindow(dpy
), mbits
, 10, 10);
89 attr.flags |= GSWindowStyleAttr;
90 attr.window_style = NSTitledWindowMask|NSClosableWindowMask;
93 WMSetWindowAttributes(dpy
, win
, &attr
);
95 hints
= XAllocWMHints();
96 /* set window group leader */
97 hints
->window_group
= leader
;
98 hints
->flags
= WindowGroupHint
;
99 XSetWMHints(dpy
, win
, hints
);
101 WMAppAddWindow(app
, win
);
102 XMapWindow(dpy
, win
);
105 int main(int argc
, char **argv
)
107 XClassHint classhint
;
109 dpy
= XOpenDisplay("");
111 puts("could not open display!");
114 delete_win
= XInternAtom(dpy
, "WM_DELETE_WINDOW", False
);
115 miniaturize_win
= XInternAtom(dpy
, "_GNUSTEP_WM_MINIATURIZE_WINDOW",
118 leader
= XCreateSimpleWindow(dpy
, DefaultRootWindow(dpy
), 10, 10, 10, 10,
121 classhint
.res_name
= "test";
122 classhint
.res_class
= "Test";
123 XSetClassHint(dpy
, leader
, &classhint
);
125 /* set window group leader to self */
126 hints
= XAllocWMHints();
127 hints
->window_group
= leader
;
128 hints
->flags
= WindowGroupHint
;
129 XSetWMHints(dpy
, leader
, hints
);
131 /* create app context */
132 app
= WMAppCreateWithMain(dpy
, DefaultScreen(dpy
), leader
);
133 menu
= WMMenuCreate(app
, "Test Menu");
134 submenu
= WMMenuCreate(app
, "File");
135 WMMenuAddSubmenu(menu
, "File", submenu
);
137 WMMenuAddItem(menu
, "Hide", (WMMenuAction
)hide
, NULL
, NULL
, NULL
);
138 WMMenuAddItem(menu
, "Quit", (WMMenuAction
)quit
, NULL
, NULL
, NULL
);
139 WMMenuAddItem(submenu
, "New", (WMMenuAction
)newwin
, NULL
, NULL
, NULL
);
140 WMMenuAddItem(submenu
, "Open", (WMMenuAction
)callback
, NULL
, NULL
, NULL
);
141 WMMenuAddItem(submenu
, "Save", (WMMenuAction
)callback
, NULL
, NULL
, NULL
);
142 WMMenuAddItem(submenu
, "Save As...", (WMMenuAction
)callback
, NULL
, NULL
, NULL
);
144 WMAppSetMainMenu(app
, menu
);
148 /* set command to use to startup this */
149 XSetCommand(dpy
, leader
, argv
, argc
);
151 /* create first window */
156 puts("Run xprop on the test window to see the properties defined");
159 XNextEvent(dpy
, &ev
);
160 if (ev
.type
==ClientMessage
) {
161 if (ev
.xclient
.data
.l
[0]==delete_win
) {
162 XDestroyWindow(dpy
,ev
.xclient
.window
);
164 } else if (ev
.xclient
.data
.l
[0]==miniaturize_win
) {
165 puts("You've pushed the maximize window button");
168 WMProcessEvent(app
, &ev
);