13
extern Cursor wm_curs;
14
extern XFontStruct *labelfont;
15
extern char *progname;
16
extern XContext screen_context, client_context, vroot_context;
18
extern void createmenubar();
19
extern void reparent(Client *);
21
Scrn *front = NULL, *scr = NULL;
23
static Scrn *getvroot(Window root)
26
if(!XFindContext(dpy, root, vroot_context, (XPointer *)&s))
31
static void setvroot(Window root, Scrn *s)
33
XSaveContext(dpy, root, vroot_context, (XPointer)s);
36
void setvirtualroot(Scrn *s)
39
Scrn *old_vroot = getvroot(s->root);
41
if(s==old_vroot) return;
43
XDeleteProperty(dpy, old_vroot->back, swm_vroot);
45
XChangeProperty(dpy, s->back, swm_vroot, XA_WINDOW, 32, PropModeReplace,
46
(unsigned char *)&(s->back), 1);
50
Scrn *getscreenbyroot(Window w);
52
void screentoback(void)
55
if((!scr)||(scr->back==scr->root)) return;
57
XLowerWindow(dpy, scr->back);
59
} else if(scr==getscreenbyroot(scr->root)) {
60
XLowerWindow(dpy, scr->back);
61
scr->upfront->behind=scr->behind;
62
scr->behind->upfront=scr->upfront;
63
scr->upfront=front->upfront;
65
front->upfront->behind=scr;
67
} else if(scr->behind==front) {
68
XRaiseWindow(dpy, scr->back);
71
XRaiseWindow(dpy, scr->back);
72
scr->upfront->behind=scr->behind;
73
scr->behind->upfront=scr->upfront;
74
scr->upfront=front->upfront;
76
front->upfront->behind=scr;
80
if((f = getscreenbyroot(scr->root))) {
81
init_dri(&f->dri, dpy, f->root, f->cmap, True);
86
void assimilate(Window w, int x, int y)
88
#ifdef ASSIMILATE_WINDOWS
89
XSetWindowAttributes xsa;
91
XAddToSaveSet(dpy, w);
92
XReparentWindow(dpy, w, scr->back, x, (y<scr->y? 0:y-scr->y));
93
XSaveContext(dpy, w, screen_context, (XPointer)scr);
94
xsa.override_redirect = False;
95
XChangeWindowAttributes(dpy, w, CWOverrideRedirect, &xsa);
99
static void scanwins()
101
unsigned int i, nwins;
103
Window dw1, dw2, *wins;
104
XWindowAttributes *pattr=NULL;
108
XQueryTree(dpy, scr->root, &dw1, &dw2, &wins, &nwins);
109
if(nwins && (pattr=calloc(nwins, sizeof(XWindowAttributes)))) {
110
for (i = 0; i < nwins; i++)
111
XGetWindowAttributes(dpy, wins[i], pattr+i);
112
for (i = 0; i < nwins; i++) {
113
if (!XFindContext(dpy, wins[i], client_context, &dummy))
115
if (pattr[i].override_redirect) {
116
if(scr->back!=scr->root && XFindContext(dpy, wins[i], screen_context, &dummy))
117
assimilate(wins[i], pattr[i].x, pattr[i].y);
120
c = createclient(wins[i]);
121
if (c != 0 && c->window == wins[i]) {
122
if (pattr[i].map_state == IsViewable) {
123
c->state=NormalState;
126
if(c->state==IconicState) {
129
XMapWindow(dpy, c->icon->window);
130
if(c->icon->labelwidth)
131
XMapWindow(dpy, c->icon->labelwin);
133
} else if(c->state==NormalState)
134
XMapRaised(dpy, c->parent);
136
XRaiseWindow(dpy, c->parent);
144
XFree((void *) wins);
148
Scrn *openscreen(char *deftitle, Window root)
151
XWindowAttributes attr;
152
XSetWindowAttributes swa;
154
extern char *label_font_name;
157
root = DefaultRootWindow(dpy);
159
XGetWindowAttributes(dpy, root, &attr);
161
s = (Scrn *)calloc(1, sizeof(Scrn));
163
s->cmap = attr.colormap;
164
s->depth = attr.depth;
165
s->visual = attr.visual;
166
s->number = XScreenNumberOfScreen(attr.screen);
168
init_dri(&s->dri, dpy, s->root, s->cmap, True);
170
swa.background_pixel = s->dri.dri_Pens[BACKGROUNDPEN];
171
swa.override_redirect = True;
172
swa.colormap = attr.colormap;
173
swa.cursor = wm_curs;
174
swa.border_pixel = BlackPixel(dpy, DefaultScreen(dpy));
176
s->back = XCreateWindow(dpy, root,
177
-prefs.borderwidth, (s->y=0)-prefs.borderwidth,
178
s->width = attr.width, s->height = attr.height,
179
s->bw=prefs.borderwidth, CopyFromParent,
180
InputOutput, CopyFromParent,
181
CWBackPixel|CWOverrideRedirect|CWColormap|CWCursor|
185
XSaveContext(dpy, s->back, screen_context, (XPointer)s);
187
gcv.background = s->dri.dri_Pens[BACKGROUNDPEN];
188
gcv.font = s->dri.dri_Font->fid;
190
s->gc = XCreateGC(dpy, s->back, GCBackground|GCFont, &gcv);
193
if(!(labelfont = XLoadQueryFont(dpy, label_font_name))) {
194
fprintf(stderr, "%s: cannot open font %s\n", progname, label_font_name);
195
labelfont = s->dri.dri_Font;
198
gcv.font = labelfont->fid;
199
gcv.foreground = s->dri.dri_Pens[TEXTPEN];
201
s->icongc = XCreateGC(dpy, s->back, GCForeground|GCBackground|GCFont, &gcv);
203
gcv.function = GXinvert;
204
gcv.subwindow_mode = IncludeInferiors;
206
s->rubbergc = XCreateGC(dpy, s->back, GCFunction|GCSubwindowMode, &gcv);
208
s->title = s->deftitle = deftitle;
210
s->default_tool_pm = None;
211
s->default_tool_pm2 = None;
212
s->default_tool_pm_w=0;
213
s->default_tool_pm_h=0;
214
s->lh = labelfont->ascent+labelfont->descent;
218
s->upfront=front->upfront;
219
front->upfront->behind=s;
222
s->behind = s->upfront = s;
231
void realizescreens(void)
236
scr->fh = scr->dri.dri_Font->ascent+scr->dri.dri_Font->descent;
238
scr->h2=(2*scr->bh)/10; scr->h3=(3*scr->bh)/10;
239
scr->h4=(4*scr->bh)/10; scr->h5=(5*scr->bh)/10;
240
scr->h6=(6*scr->bh)/10; scr->h7=(7*scr->bh)/10;
241
scr->h8=(8*scr->bh)/10;
243
createdefaulticons();
245
XSelectInput(dpy, scr->root,
246
SubstructureNotifyMask|SubstructureRedirectMask|
247
KeyPressMask|KeyReleaseMask|
248
ButtonPressMask|ButtonReleaseMask);
249
if(scr->back != scr->root)
250
XSelectInput(dpy, scr->back,
251
SubstructureNotifyMask|SubstructureRedirectMask|
252
KeyPressMask|KeyReleaseMask|
253
ButtonPressMask|ButtonReleaseMask);
255
XStoreName(dpy, scr->back, scr->title);
256
XLowerWindow(dpy, scr->back);
257
XMapWindow(dpy, scr->back);
263
if(!getvroot(scr->root)) {
264
init_dri(&scr->dri, dpy, scr->root, scr->cmap, True);
271
Scrn *getscreen(Window w)
276
if(s->back == w || s->root == w)
283
Scrn *getscreenbyroot(Window w)