~profzoom/ubuntu/quantal/wmaker/bug-1079925

« back to all changes in this revision

Viewing changes to test/wtest.c

  • Committer: Bazaar Package Importer
  • Author(s): Marcelo E. Magallon
  • Date: 2004-11-10 14:05:30 UTC
  • Revision ID: james.westby@ubuntu.com-20041110140530-qpd66b5lm38x7apk
Tags: upstream-0.91.0
ImportĀ upstreamĀ versionĀ 0.91.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
5
 *
 
6
 * Note that the windows don't have a window command menu.
 
7
 *
 
8
 * TODO: remake
 
9
 */
 
10
 
 
11
#include <stdio.h>
 
12
#include <stdlib.h>
 
13
#include <X11/Xlib.h>
 
14
#include <X11/Xutil.h>
 
15
#include <X11/Xproto.h>
 
16
#include <WMaker.h>
 
17
 
 
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};
 
21
 
 
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};
 
25
 
 
26
 
 
27
Display *dpy;
 
28
Window leader;
 
29
WMAppContext *app;
 
30
 
 
31
 
 
32
static void
 
33
callback(void *foo, int item, Time time)
 
34
{
 
35
    printf("pushed item %i\n", item);
 
36
}
 
37
 
 
38
static void
 
39
quit(void *foo, int item, Time time)
 
40
{
 
41
    exit(0);
 
42
}
 
43
 
 
44
 
 
45
 
 
46
static void
 
47
hide(void *foo, int item, Time time)
 
48
{
 
49
    WMHideApplication(app);
 
50
}
 
51
 
 
52
 
 
53
Atom delete_win, miniaturize_win;
 
54
Atom prots[6];
 
55
GNUstepWMAttributes attr;
 
56
XWMHints *hints;
 
57
WMMenu *menu;
 
58
WMMenu *submenu;
 
59
int wincount=0;
 
60
 
 
61
static void
 
62
newwin(void *foo, int item, Time time)
 
63
{
 
64
    Window win;
 
65
    XClassHint classhint;
 
66
    char title[100];
 
67
 
 
68
    wincount++;
 
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);
 
76
 
 
77
    /* set class hint */
 
78
    classhint.res_name = "test";
 
79
    classhint.res_class = "Test";
 
80
    XSetClassHint(dpy, win, &classhint);
 
81
 
 
82
    /* set WindowMaker hints */
 
83
    attr.flags = GSMiniaturizePixmapAttr|GSMiniaturizeMaskAttr;
 
84
    attr.miniaturize_pixmap =
 
85
        XCreateBitmapFromData(dpy, DefaultRootWindow(dpy), bits, 10, 10);
 
86
 
 
87
    attr.miniaturize_mask =
 
88
        XCreateBitmapFromData(dpy, DefaultRootWindow(dpy), mbits, 10, 10);
 
89
    /*
 
90
     attr.flags |= GSWindowStyleAttr;
 
91
     attr.window_style = NSTitledWindowMask|NSClosableWindowMask;
 
92
     */
 
93
 
 
94
    WMSetWindowAttributes(dpy, win, &attr);
 
95
 
 
96
    hints = XAllocWMHints();
 
97
    /* set window group leader */
 
98
    hints->window_group = leader;
 
99
    hints->flags = WindowGroupHint;
 
100
    XSetWMHints(dpy, win, hints);
 
101
 
 
102
    WMAppAddWindow(app, win);
 
103
    XMapWindow(dpy, win);
 
104
}
 
105
 
 
106
int main(int argc, char **argv)
 
107
{
 
108
    XClassHint classhint;
 
109
 
 
110
    dpy = XOpenDisplay("");
 
111
    if (!dpy) {
 
112
        puts("could not open display!");
 
113
        exit(1);
 
114
    }
 
115
    delete_win = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
 
116
    miniaturize_win = XInternAtom(dpy, "_GNUSTEP_WM_MINIATURIZE_WINDOW",
 
117
                                  False);
 
118
 
 
119
    leader = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 10, 10, 10, 10,
 
120
                                 0, 0, 0);
 
121
    /* set class hint */
 
122
    classhint.res_name = "test";
 
123
    classhint.res_class = "Test";
 
124
    XSetClassHint(dpy, leader, &classhint);
 
125
 
 
126
    /* set window group leader to self */
 
127
    hints = XAllocWMHints();
 
128
    hints->window_group = leader;
 
129
    hints->flags = WindowGroupHint;
 
130
    XSetWMHints(dpy, leader, hints);
 
131
 
 
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);
 
137
 
 
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);
 
144
 
 
145
    WMAppSetMainMenu(app, menu);
 
146
 
 
147
    WMRealizeMenus(app);
 
148
 
 
149
    /* set command to use to startup this */
 
150
    XSetCommand(dpy, leader, argv, argc);
 
151
 
 
152
    /* create first window */
 
153
    newwin(NULL, 0, 0);
 
154
 
 
155
 
 
156
    XFlush(dpy);
 
157
    puts("Run xprop on the test window to see the properties defined");
 
158
    while (wincount>0) {
 
159
        XEvent ev;
 
160
        XNextEvent(dpy, &ev);
 
161
        if (ev.type==ClientMessage) {
 
162
            if (ev.xclient.data.l[0]==delete_win) {
 
163
                XDestroyWindow(dpy,ev.xclient.window);
 
164
                wincount--;
 
165
            } else if (ev.xclient.data.l[0]==miniaturize_win) {
 
166
                puts("You've pushed the maximize window button");
 
167
            }
 
168
        }
 
169
        WMProcessEvent(app, &ev);
 
170
    }
 
171
    exit(0);
 
172
}
 
173