~ubuntu-branches/ubuntu/saucy/amiwm/saucy

« back to all changes in this revision

Viewing changes to screen.c

  • Committer: Bazaar Package Importer
  • Author(s): Jorgen Schaefer
  • Date: 2001-08-31 13:23:27 UTC
  • Revision ID: james.westby@ubuntu.com-20010831132327-n08nr7qqfhcgpsqp
Tags: upstream-0.20.48
ImportĀ upstreamĀ versionĀ 0.20.48

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <X11/Xlib.h>
 
2
#include <stdio.h>
 
3
#include <stdlib.h>
 
4
 
 
5
#include "drawinfo.h"
 
6
#include "screen.h"
 
7
#include "icon.h"
 
8
#include "client.h"
 
9
#include "prefs.h"
 
10
#include "icc.h"
 
11
 
 
12
extern Display *dpy;
 
13
extern Cursor wm_curs;
 
14
extern XFontStruct *labelfont;
 
15
extern char *progname;
 
16
extern XContext screen_context, client_context, vroot_context;
 
17
 
 
18
extern void createmenubar();
 
19
extern void reparent(Client *);
 
20
 
 
21
Scrn *front = NULL, *scr = NULL;
 
22
 
 
23
static Scrn *getvroot(Window root)
 
24
{
 
25
  Scrn *s;
 
26
  if(!XFindContext(dpy, root, vroot_context, (XPointer *)&s))
 
27
    return s;
 
28
  return NULL;
 
29
}
 
30
 
 
31
static void setvroot(Window root, Scrn *s)
 
32
{
 
33
  XSaveContext(dpy, root, vroot_context, (XPointer)s);
 
34
}
 
35
 
 
36
void setvirtualroot(Scrn *s)
 
37
{
 
38
  if(s) {
 
39
    Scrn *old_vroot = getvroot(s->root);
 
40
 
 
41
    if(s==old_vroot) return;
 
42
    if(old_vroot)
 
43
      XDeleteProperty(dpy, old_vroot->back, swm_vroot);
 
44
    setvroot(s->root, s);
 
45
    XChangeProperty(dpy, s->back, swm_vroot, XA_WINDOW, 32, PropModeReplace,
 
46
                    (unsigned char *)&(s->back), 1);
 
47
  }
 
48
}
 
49
 
 
50
Scrn *getscreenbyroot(Window w);
 
51
 
 
52
void screentoback(void)
 
53
{
 
54
  Scrn *f;
 
55
  if((!scr)||(scr->back==scr->root)) return;
 
56
  if(scr==front) {
 
57
    XLowerWindow(dpy, scr->back);
 
58
    front=scr->behind;
 
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;
 
64
    scr->behind=front;
 
65
    front->upfront->behind=scr;
 
66
    front->upfront=scr;
 
67
  } else if(scr->behind==front) {
 
68
    XRaiseWindow(dpy, scr->back);
 
69
    front=scr;
 
70
  } else {
 
71
    XRaiseWindow(dpy, scr->back);
 
72
    scr->upfront->behind=scr->behind;
 
73
    scr->behind->upfront=scr->upfront;
 
74
    scr->upfront=front->upfront;
 
75
    scr->behind=front;
 
76
    front->upfront->behind=scr;
 
77
    front->upfront=scr;
 
78
    front=scr;
 
79
  }
 
80
  if((f = getscreenbyroot(scr->root))) {
 
81
    init_dri(&f->dri, dpy, f->root, f->cmap, True);
 
82
    setvirtualroot(f);
 
83
  }
 
84
}
 
85
 
 
86
void assimilate(Window w, int x, int y)
 
87
{
 
88
#ifdef ASSIMILATE_WINDOWS
 
89
  XSetWindowAttributes xsa;
 
90
 
 
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);
 
96
#endif
 
97
}
 
98
 
 
99
static void scanwins()
 
100
{
 
101
  unsigned int i, nwins;
 
102
  Client *c;
 
103
  Window dw1, dw2, *wins;
 
104
  XWindowAttributes *pattr=NULL;
 
105
  XPointer dummy;
 
106
  Scrn *s=scr;
 
107
 
 
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))
 
114
        continue;
 
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);
 
118
        continue;
 
119
      }
 
120
      c = createclient(wins[i]);
 
121
      if (c != 0 && c->window == wins[i]) {
 
122
        if (pattr[i].map_state == IsViewable) {
 
123
          c->state=NormalState;
 
124
          getstate(c);
 
125
          reparent(c);
 
126
          if(c->state==IconicState) {
 
127
            createicon(c);
 
128
            adjusticon(c->icon);
 
129
            XMapWindow(dpy, c->icon->window);
 
130
            if(c->icon->labelwidth)
 
131
              XMapWindow(dpy, c->icon->labelwin);
 
132
            c->icon->mapped=1;
 
133
          } else if(c->state==NormalState)
 
134
            XMapRaised(dpy, c->parent);
 
135
          else
 
136
            XRaiseWindow(dpy, c->parent);
 
137
          c->reparenting=1;
 
138
          scr=s;
 
139
        }
 
140
      }
 
141
    }
 
142
    free(pattr);
 
143
  }
 
144
  XFree((void *) wins);
 
145
  cleanupicons();
 
146
}
 
147
 
 
148
Scrn *openscreen(char *deftitle, Window root)
 
149
{
 
150
  Scrn *s;
 
151
  XWindowAttributes attr;
 
152
  XSetWindowAttributes swa;
 
153
  XGCValues gcv;
 
154
  extern char *label_font_name;
 
155
 
 
156
  if(!root)
 
157
    root = DefaultRootWindow(dpy);
 
158
 
 
159
  XGetWindowAttributes(dpy, root, &attr);
 
160
 
 
161
  s = (Scrn *)calloc(1, sizeof(Scrn));
 
162
  s->root = root;
 
163
  s->cmap = attr.colormap;
 
164
  s->depth = attr.depth;
 
165
  s->visual = attr.visual;
 
166
  s->number = XScreenNumberOfScreen(attr.screen);
 
167
 
 
168
  init_dri(&s->dri, dpy, s->root, s->cmap, True);
 
169
 
 
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));
 
175
 
 
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|
 
182
                          CWBorderPixel,
 
183
                          &swa);
 
184
 
 
185
  XSaveContext(dpy, s->back, screen_context, (XPointer)s);
 
186
 
 
187
  gcv.background = s->dri.dri_Pens[BACKGROUNDPEN];
 
188
  gcv.font = s->dri.dri_Font->fid;
 
189
 
 
190
  s->gc = XCreateGC(dpy, s->back, GCBackground|GCFont, &gcv);
 
191
  
 
192
  if(!labelfont)
 
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;
 
196
    }
 
197
 
 
198
  gcv.font = labelfont->fid;
 
199
  gcv.foreground = s->dri.dri_Pens[TEXTPEN];
 
200
 
 
201
  s->icongc = XCreateGC(dpy, s->back, GCForeground|GCBackground|GCFont, &gcv);
 
202
 
 
203
  gcv.function = GXinvert;
 
204
  gcv.subwindow_mode = IncludeInferiors;
 
205
 
 
206
  s->rubbergc = XCreateGC(dpy, s->back, GCFunction|GCSubwindowMode, &gcv);
 
207
 
 
208
  s->title = s->deftitle = deftitle;
 
209
 
 
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;
 
215
 
 
216
  if(front) {
 
217
    s->behind=front;
 
218
    s->upfront=front->upfront;
 
219
    front->upfront->behind=s;
 
220
    front->upfront=s;
 
221
  } else {
 
222
    s->behind = s->upfront = s;
 
223
    front = s;
 
224
  }
 
225
 
 
226
  scr=s;
 
227
 
 
228
  return s;
 
229
}
 
230
 
 
231
void realizescreens(void)
 
232
{
 
233
  scr = front;
 
234
 
 
235
  do {
 
236
    scr->fh = scr->dri.dri_Font->ascent+scr->dri.dri_Font->descent;
 
237
    scr->bh=scr->fh+3;
 
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;
 
242
    createmenubar();
 
243
    createdefaulticons();
 
244
 
 
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);
 
254
 
 
255
    XStoreName(dpy, scr->back, scr->title);
 
256
    XLowerWindow(dpy, scr->back);
 
257
    XMapWindow(dpy, scr->back);
 
258
 
 
259
    scr=scr->behind;
 
260
  } while(scr!=front);
 
261
  do {  
 
262
    scanwins();
 
263
    if(!getvroot(scr->root)) {
 
264
      init_dri(&scr->dri, dpy, scr->root, scr->cmap, True);
 
265
      setvirtualroot(scr);
 
266
    }
 
267
    scr=scr->behind;
 
268
  } while(scr!=front);
 
269
}
 
270
 
 
271
Scrn *getscreen(Window w)
 
272
{
 
273
  Scrn *s=front;
 
274
  if(w && s)
 
275
    do {
 
276
      if(s->back == w || s->root == w)
 
277
        return s;
 
278
      s=s->behind;
 
279
    } while(s!=front);
 
280
  return front;
 
281
}
 
282
 
 
283
Scrn *getscreenbyroot(Window w)
 
284
{
 
285
  Scrn *s=front;
 
286
  if(s)
 
287
    do {
 
288
      if(s->root == w)
 
289
        return s;
 
290
      s=s->behind;
 
291
    } while(s!=front);
 
292
  return NULL;
 
293
}