]> Dogcows Code - chaz/openbox/blob - src/Screen.cc
251faadd429464f1ad5f960109df48830ff6f31d
[chaz/openbox] / src / Screen.cc
1 // Screen.cc for Openbox
2 // Copyright (c) 2001 Sean 'Shaleh' Perry <shaleh@debian.org>
3 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a
6 // copy of this software and associated documentation files (the "Software"),
7 // to deal in the Software without restriction, including without limitation
8 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 // and/or sell copies of the Software, and to permit persons to whom the
10 // Software is furnished to do so, subject to the following conditions:
11 //
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
14 //
15 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
21 // DEALINGS IN THE SOFTWARE.
22
23 // stupid macros needed to access some functions in version 2 of the GNU C
24 // library
25 #ifndef _GNU_SOURCE
26 #define _GNU_SOURCE
27 #endif // _GNU_SOURCE
28
29 #ifdef HAVE_CONFIG_H
30 # include "../config.h"
31 #endif // HAVE_CONFIG_H
32
33 #include <X11/Xatom.h>
34 #include <X11/keysym.h>
35
36 #include "i18n.h"
37 #include "openbox.h"
38 #include "Clientmenu.h"
39 #include "Iconmenu.h"
40 #include "Image.h"
41 #include "Screen.h"
42
43 #ifdef SLIT
44 #include "Slit.h"
45 #endif // SLIT
46
47 #include "Rootmenu.h"
48 #include "Toolbar.h"
49 #include "Window.h"
50 #include "Workspace.h"
51 #include "Workspacemenu.h"
52
53 #ifdef HAVE_STDLIB_H
54 # include <stdlib.h>
55 #endif // HAVE_STDLIB_H
56
57 #ifdef HAVE_STRING_H
58 # include <string.h>
59 #endif // HAVE_STRING_H
60
61 #ifdef HAVE_SYS_TYPES_H
62 # include <sys/types.h>
63 #endif // HAVE_SYS_TYPES_H
64
65 #ifdef HAVE_CTYPE_H
66 # include <ctype.h>
67 #endif // HAVE_CTYPE_H
68
69 #ifdef HAVE_DIRENT_H
70 # include <dirent.h>
71 #endif // HAVE_DIRENT_H
72
73 #ifdef HAVE_LOCALE_H
74 # include <locale.h>
75 #endif // HAVE_LOCALE_H
76
77 #ifdef HAVE_UNISTD_H
78 # include <sys/types.h>
79 # include <unistd.h>
80 #endif // HAVE_UNISTD_H
81
82 #ifdef HAVE_SYS_STAT_H
83 # include <sys/stat.h>
84 #endif // HAVE_SYS_STAT_H
85
86 #ifdef HAVE_STDARG_H
87 # include <stdarg.h>
88 #endif // HAVE_STDARG_H
89
90 #ifndef HAVE_SNPRINTF
91 # include "bsd-snprintf.h"
92 #endif // !HAVE_SNPRINTF
93
94 #ifndef MAXPATHLEN
95 #define MAXPATHLEN 255
96 #endif // MAXPATHLEN
97
98 #ifndef FONT_ELEMENT_SIZE
99 #define FONT_ELEMENT_SIZE 50
100 #endif // FONT_ELEMENT_SIZE
101
102 #include <strstream>
103 #include <string>
104 #include <algorithm>
105
106 static Bool running = True;
107
108 static int anotherWMRunning(Display *display, XErrorEvent *) {
109 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenAnotherWMRunning,
110 "BScreen::BScreen: an error occured while querying the X server.\n"
111 " another window manager already running on display %s.\n"),
112 DisplayString(display));
113
114 running = False;
115
116 return(-1);
117 }
118
119 struct dcmp {
120 bool operator()(const char *one, const char *two) const {
121 return (strcmp(one, two) < 0) ? True : False;
122 }
123 };
124
125 #ifndef HAVE_STRCASESTR
126 static const char * strcasestr(const char *str, const char *ptn) {
127 const char *s2, *p2;
128 for( ; *str; str++) {
129 for(s2=str,p2=ptn; ; s2++,p2++) {
130 if (!*p2) return str;
131 if (toupper(*s2) != toupper(*p2)) break;
132 }
133 }
134 return NULL;
135 }
136 #endif // HAVE_STRCASESTR
137
138 static const char *getFontElement(const char *pattern, char *buf, int bufsiz, ...) {
139 const char *p, *v;
140 char *p2;
141 va_list va;
142
143 va_start(va, bufsiz);
144 buf[bufsiz-1] = 0;
145 buf[bufsiz-2] = '*';
146 while((v = va_arg(va, char *)) != NULL) {
147 p = strcasestr(pattern, v);
148 if (p) {
149 strncpy(buf, p+1, bufsiz-2);
150 p2 = strchr(buf, '-');
151 if (p2) *p2=0;
152 va_end(va);
153 return p;
154 }
155 }
156 va_end(va);
157 strncpy(buf, "*", bufsiz);
158 return NULL;
159 }
160
161 static const char *getFontSize(const char *pattern, int *size) {
162 const char *p;
163 const char *p2=NULL;
164 int n=0;
165
166 for (p=pattern; 1; p++) {
167 if (!*p) {
168 if (p2!=NULL && n>1 && n<72) {
169 *size = n; return p2+1;
170 } else {
171 *size = 16; return NULL;
172 }
173 } else if (*p=='-') {
174 if (n>1 && n<72 && p2!=NULL) {
175 *size = n;
176 return p2+1;
177 }
178 p2=p; n=0;
179 } else if (*p>='0' && *p<='9' && p2!=NULL) {
180 n *= 10;
181 n += *p-'0';
182 } else {
183 p2=NULL; n=0;
184 }
185 }
186 }
187
188
189 BScreen::BScreen(Openbox &ob, int scrn, Resource &conf) : ScreenInfo(ob, scrn),
190 openbox(ob), config(conf)
191 {
192 // default values
193 resource.full_max = false;
194 resource.focus_new = false;
195 resource.focus_last = false;
196 resource.row_direction = LeftRight;
197 resource.col_direction = TopBottom;
198 resource.workspaces = 1;
199 resource.sloppy_focus = true;
200 resource.auto_raise = false;
201 resource.zones = 1;
202 resource.placement_policy = CascadePlacement;
203 #ifdef HAVE_STRFTIME
204 resource.strftime_format = bstrdup("%I:%M %p");
205 #else // !have_strftime
206 resource.date_format = B_AmericanDate;
207 resource.clock24hour = false;
208 #endif // HAVE_STRFTIME
209 resource.edge_snap_threshold = 4;
210 resource.image_dither = true;
211 resource.root_command = NULL;
212 resource.opaque_move = false;
213
214 event_mask = ColormapChangeMask | EnterWindowMask | PropertyChangeMask |
215 SubstructureRedirectMask | KeyPressMask | KeyReleaseMask |
216 ButtonPressMask | ButtonReleaseMask;
217
218 XErrorHandler old = XSetErrorHandler((XErrorHandler) anotherWMRunning);
219 XSelectInput(getBaseDisplay().getXDisplay(), getRootWindow(), event_mask);
220 XSync(getBaseDisplay().getXDisplay(), False);
221 XSetErrorHandler((XErrorHandler) old);
222
223 managed = running;
224 if (! managed) return;
225
226 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenManagingScreen,
227 "BScreen::BScreen: managing screen %d "
228 "using visual 0x%lx, depth %d\n"),
229 getScreenNumber(), XVisualIDFromVisual(getVisual()),
230 getDepth());
231
232 rootmenu = 0;
233
234 resource.mstyle.t_fontset = resource.mstyle.f_fontset =
235 resource.tstyle.fontset = resource.wstyle.fontset = (XFontSet) 0;
236 resource.mstyle.t_font = resource.mstyle.f_font = resource.tstyle.font =
237 resource.wstyle.font = (XFontStruct *) 0;
238
239 #ifdef HAVE_GETPID
240 pid_t bpid = getpid();
241
242 XChangeProperty(getBaseDisplay().getXDisplay(), getRootWindow(),
243 openbox.getOpenboxPidAtom(), XA_CARDINAL,
244 sizeof(pid_t) * 8, PropModeReplace,
245 (unsigned char *) &bpid, 1);
246 #endif // HAVE_GETPID
247
248 XDefineCursor(getBaseDisplay().getXDisplay(), getRootWindow(),
249 openbox.getSessionCursor());
250
251 workspaceNames = new LinkedList<char>;
252
253 load(); // load config options from Resources
254
255 workspacesList = new LinkedList<Workspace>;
256 rootmenuList = new LinkedList<Rootmenu>;
257 netizenList = new LinkedList<Netizen>;
258 iconList = new LinkedList<OpenboxWindow>;
259
260 image_control =
261 new BImageControl(openbox, *this, True, openbox.getColorsPerChannel(),
262 openbox.getCacheLife(), openbox.getCacheMax());
263 image_control->installRootColormap();
264 root_colormap_installed = True;
265
266 image_control->setDither(resource.image_dither);
267
268 LoadStyle();
269
270 XGCValues gcv;
271 unsigned long gc_value_mask = GCForeground;
272 if (! i18n->multibyte()) gc_value_mask |= GCFont;
273
274 gcv.foreground = WhitePixel(getBaseDisplay().getXDisplay(),
275 getScreenNumber())
276 ^ BlackPixel(getBaseDisplay().getXDisplay(),
277 getScreenNumber());
278 gcv.function = GXxor;
279 gcv.subwindow_mode = IncludeInferiors;
280 opGC = XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
281 GCForeground | GCFunction | GCSubwindowMode, &gcv);
282
283 gcv.foreground = resource.wstyle.l_text_focus.getPixel();
284 if (resource.wstyle.font)
285 gcv.font = resource.wstyle.font->fid;
286 resource.wstyle.l_text_focus_gc =
287 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
288 gc_value_mask, &gcv);
289
290 gcv.foreground = resource.wstyle.l_text_unfocus.getPixel();
291 if (resource.wstyle.font)
292 gcv.font = resource.wstyle.font->fid;
293 resource.wstyle.l_text_unfocus_gc =
294 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
295 gc_value_mask, &gcv);
296
297 gcv.foreground = resource.wstyle.b_pic_focus.getPixel();
298 resource.wstyle.b_pic_focus_gc =
299 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
300 GCForeground, &gcv);
301
302 gcv.foreground = resource.wstyle.b_pic_unfocus.getPixel();
303 resource.wstyle.b_pic_unfocus_gc =
304 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
305 GCForeground, &gcv);
306
307 gcv.foreground = resource.mstyle.t_text.getPixel();
308 if (resource.mstyle.t_font)
309 gcv.font = resource.mstyle.t_font->fid;
310 resource.mstyle.t_text_gc =
311 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
312 gc_value_mask, &gcv);
313
314 gcv.foreground = resource.mstyle.f_text.getPixel();
315 if (resource.mstyle.f_font)
316 gcv.font = resource.mstyle.f_font->fid;
317 resource.mstyle.f_text_gc =
318 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
319 gc_value_mask, &gcv);
320
321 gcv.foreground = resource.mstyle.h_text.getPixel();
322 resource.mstyle.h_text_gc =
323 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
324 gc_value_mask, &gcv);
325
326 gcv.foreground = resource.mstyle.d_text.getPixel();
327 resource.mstyle.d_text_gc =
328 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
329 gc_value_mask, &gcv);
330
331 gcv.foreground = resource.mstyle.hilite.getColor()->getPixel();
332 resource.mstyle.hilite_gc =
333 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
334 gc_value_mask, &gcv);
335
336 gcv.foreground = resource.tstyle.l_text.getPixel();
337 if (resource.tstyle.font)
338 gcv.font = resource.tstyle.font->fid;
339 resource.tstyle.l_text_gc =
340 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
341 gc_value_mask, &gcv);
342
343 gcv.foreground = resource.tstyle.w_text.getPixel();
344 resource.tstyle.w_text_gc =
345 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
346 gc_value_mask, &gcv);
347
348 gcv.foreground = resource.tstyle.c_text.getPixel();
349 resource.tstyle.c_text_gc =
350 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
351 gc_value_mask, &gcv);
352
353 gcv.foreground = resource.tstyle.b_pic.getPixel();
354 resource.tstyle.b_pic_gc =
355 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
356 gc_value_mask, &gcv);
357
358 const char *s = i18n->getMessage(ScreenSet, ScreenPositionLength,
359 "0: 0000 x 0: 0000");
360 int l = strlen(s);
361
362 if (i18n->multibyte()) {
363 XRectangle ink, logical;
364 XmbTextExtents(resource.wstyle.fontset, s, l, &ink, &logical);
365 geom_w = logical.width;
366
367 geom_h = resource.wstyle.fontset_extents->max_ink_extent.height;
368 } else {
369 geom_h = resource.wstyle.font->ascent +
370 resource.wstyle.font->descent;
371
372 geom_w = XTextWidth(resource.wstyle.font, s, l);
373 }
374
375 geom_w += (resource.bevel_width * 2);
376 geom_h += (resource.bevel_width * 2);
377
378 XSetWindowAttributes attrib;
379 unsigned long mask = CWBorderPixel | CWColormap | CWSaveUnder;
380 attrib.border_pixel = getBorderColor()->getPixel();
381 attrib.colormap = getColormap();
382 attrib.save_under = True;
383
384 geom_window =
385 XCreateWindow(getBaseDisplay().getXDisplay(), getRootWindow(),
386 0, 0, geom_w, geom_h, resource.border_width, getDepth(),
387 InputOutput, getVisual(), mask, &attrib);
388 geom_visible = False;
389
390 if (resource.wstyle.l_focus.getTexture() & BImage_ParentRelative) {
391 if (resource.wstyle.t_focus.getTexture() ==
392 (BImage_Flat | BImage_Solid)) {
393 geom_pixmap = None;
394 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window,
395 resource.wstyle.t_focus.getColor()->getPixel());
396 } else {
397 geom_pixmap = image_control->renderImage(geom_w, geom_h,
398 &resource.wstyle.t_focus);
399 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
400 geom_window, geom_pixmap);
401 }
402 } else {
403 if (resource.wstyle.l_focus.getTexture() ==
404 (BImage_Flat | BImage_Solid)) {
405 geom_pixmap = None;
406 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window,
407 resource.wstyle.l_focus.getColor()->getPixel());
408 } else {
409 geom_pixmap = image_control->renderImage(geom_w, geom_h,
410 &resource.wstyle.l_focus);
411 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
412 geom_window, geom_pixmap);
413 }
414 }
415
416 workspacemenu = new Workspacemenu(*this);
417 iconmenu = new Iconmenu(*this);
418 configmenu = new Configmenu(*this);
419
420 Workspace *wkspc = (Workspace *) 0;
421 if (resource.workspaces != 0) {
422 for (int i = 0; i < resource.workspaces; ++i) {
423 wkspc = new Workspace(*this, workspacesList->count());
424 workspacesList->insert(wkspc);
425 saveWorkspaceNames();
426 workspacemenu->insert(wkspc->getName(), wkspc->getMenu());
427 }
428 } else {
429 wkspc = new Workspace(*this, workspacesList->count());
430 workspacesList->insert(wkspc);
431 saveWorkspaceNames();
432 workspacemenu->insert(wkspc->getName(), wkspc->getMenu());
433 }
434
435 workspacemenu->insert(i18n->getMessage(IconSet, IconIcons, "Icons"),
436 iconmenu);
437 workspacemenu->update();
438
439 current_workspace = workspacesList->first();
440 workspacemenu->setItemSelected(2, True);
441
442 toolbar = new Toolbar(*this, config);
443
444 #ifdef SLIT
445 slit = new Slit(*this, config);
446 #endif // SLIT
447
448 InitMenu();
449
450 raiseWindows(0, 0);
451 rootmenu->update();
452
453 changeWorkspaceID(0);
454
455 int i;
456 unsigned int nchild;
457 Window r, p, *children;
458 XQueryTree(getBaseDisplay().getXDisplay(), getRootWindow(), &r, &p,
459 &children, &nchild);
460
461 // preen the window list of all icon windows... for better dockapp support
462 for (i = 0; i < (int) nchild; i++) {
463 if (children[i] == None) continue;
464
465 XWMHints *wmhints = XGetWMHints(getBaseDisplay().getXDisplay(),
466 children[i]);
467
468 if (wmhints) {
469 if ((wmhints->flags & IconWindowHint) &&
470 (wmhints->icon_window != children[i]))
471 for (int j = 0; j < (int) nchild; j++)
472 if (children[j] == wmhints->icon_window) {
473 children[j] = None;
474
475 break;
476 }
477
478 XFree(wmhints);
479 }
480 }
481
482 // manage shown windows
483 for (i = 0; i < (int) nchild; ++i) {
484 if (children[i] == None || (! openbox.validateWindow(children[i])))
485 continue;
486
487 XWindowAttributes attrib;
488 if (XGetWindowAttributes(getBaseDisplay().getXDisplay(), children[i],
489 &attrib)) {
490 if (attrib.override_redirect) continue;
491
492 if (attrib.map_state != IsUnmapped) {
493 new OpenboxWindow(openbox, children[i], this);
494
495 OpenboxWindow *win = openbox.searchWindow(children[i]);
496 if (win) {
497 XMapRequestEvent mre;
498 mre.window = children[i];
499 win->restoreAttributes();
500 win->mapRequestEvent(&mre);
501 }
502 }
503 }
504 }
505
506 if (! resource.sloppy_focus)
507 XSetInputFocus(getBaseDisplay().getXDisplay(), toolbar->getWindowID(),
508 RevertToParent, CurrentTime);
509
510 XFree(children);
511 XFlush(getBaseDisplay().getXDisplay());
512 }
513
514
515 BScreen::~BScreen(void) {
516 if (! managed) return;
517
518 if (geom_pixmap != None)
519 image_control->removeImage(geom_pixmap);
520
521 if (geom_window != None)
522 XDestroyWindow(getBaseDisplay().getXDisplay(), geom_window);
523
524 removeWorkspaceNames();
525
526 while (workspacesList->count())
527 delete workspacesList->remove(0);
528
529 while (rootmenuList->count())
530 rootmenuList->remove(0);
531
532 while (iconList->count())
533 delete iconList->remove(0);
534
535 while (netizenList->count())
536 delete netizenList->remove(0);
537
538 #ifdef HAVE_STRFTIME
539 if (resource.strftime_format)
540 delete [] resource.strftime_format;
541 #endif // HAVE_STRFTIME
542
543 delete rootmenu;
544 delete workspacemenu;
545 delete iconmenu;
546 delete configmenu;
547
548 #ifdef SLIT
549 delete slit;
550 #endif // SLIT
551
552 delete toolbar;
553 delete image_control;
554
555 delete workspacesList;
556 delete workspaceNames;
557 delete rootmenuList;
558 delete iconList;
559 delete netizenList;
560
561 if (resource.wstyle.fontset)
562 XFreeFontSet(getBaseDisplay().getXDisplay(), resource.wstyle.fontset);
563 if (resource.mstyle.t_fontset)
564 XFreeFontSet(getBaseDisplay().getXDisplay(), resource.mstyle.t_fontset);
565 if (resource.mstyle.f_fontset)
566 XFreeFontSet(getBaseDisplay().getXDisplay(), resource.mstyle.f_fontset);
567 if (resource.tstyle.fontset)
568 XFreeFontSet(getBaseDisplay().getXDisplay(), resource.tstyle.fontset);
569
570 if (resource.wstyle.font)
571 XFreeFont(getBaseDisplay().getXDisplay(), resource.wstyle.font);
572 if (resource.mstyle.t_font)
573 XFreeFont(getBaseDisplay().getXDisplay(), resource.mstyle.t_font);
574 if (resource.mstyle.f_font)
575 XFreeFont(getBaseDisplay().getXDisplay(), resource.mstyle.f_font);
576 if (resource.tstyle.font)
577 XFreeFont(getBaseDisplay().getXDisplay(), resource.tstyle.font);
578 if (resource.root_command != NULL)
579 delete [] resource.root_command;
580
581 XFreeGC(getBaseDisplay().getXDisplay(), opGC);
582
583 XFreeGC(getBaseDisplay().getXDisplay(),
584 resource.wstyle.l_text_focus_gc);
585 XFreeGC(getBaseDisplay().getXDisplay(),
586 resource.wstyle.l_text_unfocus_gc);
587 XFreeGC(getBaseDisplay().getXDisplay(),
588 resource.wstyle.b_pic_focus_gc);
589 XFreeGC(getBaseDisplay().getXDisplay(),
590 resource.wstyle.b_pic_unfocus_gc);
591
592 XFreeGC(getBaseDisplay().getXDisplay(),
593 resource.mstyle.t_text_gc);
594 XFreeGC(getBaseDisplay().getXDisplay(),
595 resource.mstyle.f_text_gc);
596 XFreeGC(getBaseDisplay().getXDisplay(),
597 resource.mstyle.h_text_gc);
598 XFreeGC(getBaseDisplay().getXDisplay(),
599 resource.mstyle.d_text_gc);
600 XFreeGC(getBaseDisplay().getXDisplay(),
601 resource.mstyle.hilite_gc);
602
603 XFreeGC(getBaseDisplay().getXDisplay(),
604 resource.tstyle.l_text_gc);
605 XFreeGC(getBaseDisplay().getXDisplay(),
606 resource.tstyle.w_text_gc);
607 XFreeGC(getBaseDisplay().getXDisplay(),
608 resource.tstyle.c_text_gc);
609 XFreeGC(getBaseDisplay().getXDisplay(),
610 resource.tstyle.b_pic_gc);
611 }
612
613 void BScreen::readDatabaseTexture(const char *rname, const char *rclass,
614 BTexture *texture,
615 unsigned long default_pixel)
616 {
617 std::string s;
618
619 if (resource.styleconfig.getValue(rname, rclass, s))
620 image_control->parseTexture(texture, s.c_str());
621 else
622 texture->setTexture(BImage_Solid | BImage_Flat);
623
624 if (texture->getTexture() & BImage_Solid) {
625 int clen = strlen(rclass) + 32, nlen = strlen(rname) + 32;
626
627 char *colorclass = new char[clen], *colorname = new char[nlen];
628
629 sprintf(colorclass, "%s.Color", rclass);
630 sprintf(colorname, "%s.color", rname);
631
632 readDatabaseColor(colorname, colorclass, texture->getColor(),
633 default_pixel);
634
635 #ifdef INTERLACE
636 sprintf(colorclass, "%s.ColorTo", rclass);
637 sprintf(colorname, "%s.colorTo", rname);
638
639 readDatabaseColor(colorname, colorclass, texture->getColorTo(),
640 default_pixel);
641 #endif // INTERLACE
642
643 delete [] colorclass;
644 delete [] colorname;
645
646 if ((! texture->getColor()->isAllocated()) ||
647 (texture->getTexture() & BImage_Flat))
648 return;
649
650 XColor xcol;
651
652 xcol.red = (unsigned int) (texture->getColor()->getRed() +
653 (texture->getColor()->getRed() >> 1));
654 if (xcol.red >= 0xff) xcol.red = 0xffff;
655 else xcol.red *= 0xff;
656 xcol.green = (unsigned int) (texture->getColor()->getGreen() +
657 (texture->getColor()->getGreen() >> 1));
658 if (xcol.green >= 0xff) xcol.green = 0xffff;
659 else xcol.green *= 0xff;
660 xcol.blue = (unsigned int) (texture->getColor()->getBlue() +
661 (texture->getColor()->getBlue() >> 1));
662 if (xcol.blue >= 0xff) xcol.blue = 0xffff;
663 else xcol.blue *= 0xff;
664
665 if (! XAllocColor(getBaseDisplay().getXDisplay(),
666 getColormap(), &xcol))
667 xcol.pixel = 0;
668
669 texture->getHiColor()->setPixel(xcol.pixel);
670
671 xcol.red =
672 (unsigned int) ((texture->getColor()->getRed() >> 2) +
673 (texture->getColor()->getRed() >> 1)) * 0xff;
674 xcol.green =
675 (unsigned int) ((texture->getColor()->getGreen() >> 2) +
676 (texture->getColor()->getGreen() >> 1)) * 0xff;
677 xcol.blue =
678 (unsigned int) ((texture->getColor()->getBlue() >> 2) +
679 (texture->getColor()->getBlue() >> 1)) * 0xff;
680
681 if (! XAllocColor(getBaseDisplay().getXDisplay(),
682 getColormap(), &xcol))
683 xcol.pixel = 0;
684
685 texture->getLoColor()->setPixel(xcol.pixel);
686 } else if (texture->getTexture() & BImage_Gradient) {
687 int clen = strlen(rclass) + 10, nlen = strlen(rname) + 10;
688
689 char *colorclass = new char[clen], *colorname = new char[nlen],
690 *colortoclass = new char[clen], *colortoname = new char[nlen];
691
692 sprintf(colorclass, "%s.Color", rclass);
693 sprintf(colorname, "%s.color", rname);
694
695 sprintf(colortoclass, "%s.ColorTo", rclass);
696 sprintf(colortoname, "%s.colorTo", rname);
697
698 readDatabaseColor(colorname, colorclass, texture->getColor(),
699 default_pixel);
700 readDatabaseColor(colortoname, colortoclass, texture->getColorTo(),
701 default_pixel);
702
703 delete [] colorclass;
704 delete [] colorname;
705 delete [] colortoclass;
706 delete [] colortoname;
707 }
708 }
709
710
711 void BScreen::readDatabaseColor(const char *rname, const char *rclass,
712 BColor *color, unsigned long default_pixel)
713 {
714 std::string s;
715
716 if (resource.styleconfig.getValue(rname, rclass, s))
717 image_control->parseColor(color, s.c_str());
718 else {
719 // parsing with no color string just deallocates the color, if it has
720 // been previously allocated
721 image_control->parseColor(color);
722 color->setPixel(default_pixel);
723 }
724 }
725
726
727 void BScreen::readDatabaseFontSet(const char *rname, const char *rclass,
728 XFontSet *fontset) {
729 if (! fontset) return;
730
731 static char *defaultFont = "fixed";
732 bool load_default = false;
733 std::string s;
734
735 if (*fontset)
736 XFreeFontSet(getBaseDisplay().getXDisplay(), *fontset);
737
738 if (resource.styleconfig.getValue(rname, rclass, s)) {
739 if (! (*fontset = createFontSet(s.c_str())))
740 load_default = true;
741 } else
742 load_default = true;
743
744 if (load_default) {
745 *fontset = createFontSet(defaultFont);
746
747 if (! *fontset) {
748 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenDefaultFontLoadFail,
749 "BScreen::LoadStyle(): couldn't load default font.\n"));
750 exit(2);
751 }
752 }
753 }
754
755
756 void BScreen::readDatabaseFont(const char *rname, const char *rclass,
757 XFontStruct **font) {
758 if (! font) return;
759
760 static char *defaultFont = "fixed";
761 bool load_default = false;
762 std::string s;
763
764 if (*font)
765 XFreeFont(getBaseDisplay().getXDisplay(), *font);
766
767 if (resource.styleconfig.getValue(rname, rclass, s)) {
768 if ((*font = XLoadQueryFont(getBaseDisplay().getXDisplay(),
769 s.c_str())) == NULL) {
770 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenFontLoadFail,
771 "BScreen::LoadStyle(): couldn't load font '%s'\n"),
772 s.c_str());
773 load_default = true;
774 }
775 } else
776 load_default = true;
777
778 if (load_default) {
779 if ((*font = XLoadQueryFont(getBaseDisplay().getXDisplay(),
780 defaultFont)) == NULL) {
781 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenDefaultFontLoadFail,
782 "BScreen::LoadStyle(): couldn't load default font.\n"));
783 exit(2);
784 }
785 }
786 }
787
788
789 XFontSet BScreen::createFontSet(const char *fontname) {
790 XFontSet fs;
791 char **missing, *def = "-";
792 int nmissing, pixel_size = 0, buf_size = 0;
793 char weight[FONT_ELEMENT_SIZE], slant[FONT_ELEMENT_SIZE];
794
795 fs = XCreateFontSet(getBaseDisplay().getXDisplay(),
796 fontname, &missing, &nmissing, &def);
797 if (fs && (! nmissing)) return fs;
798
799 #ifdef HAVE_SETLOCALE
800 if (! fs) {
801 if (nmissing) XFreeStringList(missing);
802
803 setlocale(LC_CTYPE, "C");
804 fs = XCreateFontSet(getBaseDisplay().getXDisplay(), fontname,
805 &missing, &nmissing, &def);
806 setlocale(LC_CTYPE, "");
807 }
808 #endif // HAVE_SETLOCALE
809
810 if (fs) {
811 XFontStruct **fontstructs;
812 char **fontnames;
813 XFontsOfFontSet(fs, &fontstructs, &fontnames);
814 fontname = fontnames[0];
815 }
816
817 getFontElement(fontname, weight, FONT_ELEMENT_SIZE,
818 "-medium-", "-bold-", "-demibold-", "-regular-", NULL);
819 getFontElement(fontname, slant, FONT_ELEMENT_SIZE,
820 "-r-", "-i-", "-o-", "-ri-", "-ro-", NULL);
821 getFontSize(fontname, &pixel_size);
822
823 if (! strcmp(weight, "*")) strncpy(weight, "medium", FONT_ELEMENT_SIZE);
824 if (! strcmp(slant, "*")) strncpy(slant, "r", FONT_ELEMENT_SIZE);
825 if (pixel_size < 3) pixel_size = 3;
826 else if (pixel_size > 97) pixel_size = 97;
827
828 buf_size = strlen(fontname) + (FONT_ELEMENT_SIZE * 2) + 64;
829 char *pattern2 = new char[buf_size];
830 snprintf(pattern2, buf_size - 1,
831 "%s,"
832 "-*-*-%s-%s-*-*-%d-*-*-*-*-*-*-*,"
833 "-*-*-*-*-*-*-%d-*-*-*-*-*-*-*,*",
834 fontname, weight, slant, pixel_size, pixel_size);
835 fontname = pattern2;
836
837 if (nmissing) XFreeStringList(missing);
838 if (fs) XFreeFontSet(getBaseDisplay().getXDisplay(), fs);
839
840 fs = XCreateFontSet(getBaseDisplay().getXDisplay(), fontname,
841 &missing, &nmissing, &def);
842 delete [] pattern2;
843
844 return fs;
845 }
846
847 void BScreen::setSloppyFocus(bool b) {
848 resource.sloppy_focus = b;
849 ostrstream s;
850 s << "session.screen" << getScreenNumber() << ".focusModel" << ends;
851 config.setValue(s.str(),
852 (resource.sloppy_focus ?
853 (resource.auto_raise ? "AutoRaiseSloppyFocus" : "SloppyFocus")
854 : "ClickToFocus"));
855 }
856
857 void BScreen::setAutoRaise(bool a) {
858 resource.auto_raise = a;
859 ostrstream s;
860 s << "session.screen" << getScreenNumber() << ".focusModel" << ends;
861 config.setValue(s.str(),
862 (resource.sloppy_focus ?
863 (resource.auto_raise ? "AutoRaiseSloppyFocus" : "SloppyFocus")
864 : "ClickToFocus"));
865 }
866
867 void BScreen::setImageDither(bool d) {
868 resource.image_dither = d;
869 ostrstream s;
870 s << "session.screen" << getScreenNumber() << ".imageDither" << ends;
871 config.setValue(s.str(), resource.image_dither);
872 }
873
874 void BScreen::setOpaqueMove(bool o) {
875 resource.opaque_move = o;
876 ostrstream s;
877 s << "session.screen" << getScreenNumber() << ".opaqueMove" << ends;
878 config.setValue(s.str(), resource.opaque_move);
879 }
880
881 void BScreen::setFullMax(bool f) {
882 resource.full_max = f;
883 ostrstream s;
884 s << "session.screen" << getScreenNumber() << ".fullMaximization" << ends;
885 config.setValue(s.str(), resource.full_max);
886 }
887
888 void BScreen::setFocusNew(bool f) {
889 resource.focus_new = f;
890 ostrstream s;
891 s << "session.screen" << getScreenNumber() << ".focusNewWindows" << ends;
892 config.setValue(s.str(), resource.focus_new);
893 }
894
895 void BScreen::setFocusLast(bool f) {
896 resource.focus_last = f;
897 ostrstream s;
898 s << "session.screen" << getScreenNumber() << ".focusLastWindow" << ends;
899 config.setValue(s.str(), resource.focus_last);
900 }
901
902 void BScreen::setWindowZones(int z) {
903 resource.zones = z;
904 ostrstream s;
905 s << "session.screen" << getScreenNumber() << ".windowZones" << ends;
906 config.setValue(s.str(), resource.zones);
907 }
908
909 void BScreen::setWorkspaceCount(int w) {
910 resource.workspaces = w;
911 ostrstream s;
912 s << "session.screen" << getScreenNumber() << ".workspaces" << ends;
913 config.setValue(s.str(), resource.workspaces);
914 }
915
916 void BScreen::setPlacementPolicy(int p) {
917 resource.placement_policy = p;
918 ostrstream s;
919 s << "session.screen" << getScreenNumber() << ".windowPlacement" << ends;
920 const char *placement;
921 switch (resource.placement_policy) {
922 case CascadePlacement: placement = "CascadePlacement"; break;
923 case BestFitPlacement: placement = "BestFitPlacement"; break;
924 case ColSmartPlacement: placement = "ColSmartPlacement"; break;
925 default:
926 case RowSmartPlacement: placement = "RowSmartPlacement"; break;
927 }
928 config.setValue(s.str(), placement);
929 }
930
931 void BScreen::setEdgeSnapThreshold(int t) {
932 resource.edge_snap_threshold = t;
933 ostrstream s;
934 s << "session.screen" << getScreenNumber() << ".edgeSnapThreshold" << ends;
935 config.setValue(s.str(), resource.edge_snap_threshold);
936 }
937
938 void BScreen::setRowPlacementDirection(int d) {
939 resource.row_direction = d;
940 ostrstream s;
941 s << "session.screen" << getScreenNumber() << ".rowPlacementDirection" <<
942 ends;
943 config.setValue(s.str(),
944 resource.row_direction == LeftRight ?
945 "LeftToRight" : "RightToLeft");
946 }
947
948 void BScreen::setColPlacementDirection(int d) {
949 resource.col_direction = d;
950 ostrstream s;
951 s << "session.screen" << getScreenNumber() << ".colPlacementDirection" <<
952 ends;
953 config.setValue(s.str(),
954 resource.col_direction == TopBottom ?
955 "TopToBottom" : "BottomToTop");
956 }
957
958 void BScreen::setRootCommand(const char *cmd) {
959 if (resource.root_command != NULL)
960 delete [] resource.root_command;
961 if (cmd != NULL)
962 resource.root_command = bstrdup(cmd);
963 else
964 resource.root_command = NULL;
965 // this doesn't save to the Resources config because it can't be changed
966 // inside Openbox, and this way we dont add an empty command which would over-
967 // ride the styles commend when none has been specified
968 }
969 #ifdef HAVE_STRFTIME
970 void BScreen::setStrftimeFormat(const char *f) {
971 if (resource.strftime_format != NULL)
972 delete [] resource.strftime_format;
973
974 resource.strftime_format = bstrdup(f);
975 ostrstream s;
976 s << "session.screen" << getScreenNumber() << ".strftimeFormat" << ends;
977 config.setValue(s.str(), resource.strftime_format);
978 }
979
980 #else // !HAVE_STRFTIME
981 void BScreen::setDateFormat(int f) {
982 resource.date_format = f;
983 ostrstream s;
984 s << "session.screen" << getScreenNumber() << ".dateFormat" << ends;
985 config.setValue(s.str(), resource.date_format == B_EuropeanDate ?
986 "European" : "American");
987 }
988
989 void BScreen::setClock24Hour(Bool c) {
990 resource.clock24hour = c;
991 ostrstream s;
992 s << "session.screen" << getScreenNumber() << ".clockFormat" << ends;
993 config.setValue(s.str(), resource.clock24hour ? 24 : 12);
994 }
995 #endif // HAVE_STRFTIME
996
997 void BScreen::setHideToolbar(bool b) {
998 resource.hide_toolbar = b;
999 if (resource.hide_toolbar)
1000 getToolbar()->unMapToolbar();
1001 else
1002 getToolbar()->mapToolbar();
1003 ostrstream s;
1004 s << "session.screen" << getScreenNumber() << ".hideToolbar" << ends;
1005 config.setValue(s.str(), resource.hide_toolbar ? "True" : "False");
1006 }
1007
1008 void BScreen::saveWorkspaceNames() {
1009 ostrstream rc, names;
1010
1011 for (int i = 0; i < resource.workspaces; i++) {
1012 Workspace *w = getWorkspace(i);
1013 if (w != NULL) {
1014 names << w->getName();
1015 if (i < resource.workspaces-1)
1016 names << ',';
1017 }
1018 }
1019 names << ends;
1020
1021 rc << "session.screen" << getScreenNumber() << ".workspaceNames" << ends;
1022 config.setValue(rc.str(), names.str());
1023 }
1024
1025 void BScreen::save() {
1026 setSloppyFocus(resource.sloppy_focus);
1027 setAutoRaise(resource.auto_raise);
1028 setImageDither(resource.image_dither);
1029 setOpaqueMove(resource.opaque_move);
1030 setFullMax(resource.full_max);
1031 setFocusNew(resource.focus_new);
1032 setFocusLast(resource.focus_last);
1033 setWindowZones(resource.zones);
1034 setWorkspaceCount(resource.workspaces);
1035 setPlacementPolicy(resource.placement_policy);
1036 setEdgeSnapThreshold(resource.edge_snap_threshold);
1037 setRowPlacementDirection(resource.row_direction);
1038 setColPlacementDirection(resource.col_direction);
1039 setRootCommand(resource.root_command);
1040 #ifdef HAVE_STRFTIME
1041 // it deletes the current value before setting the new one, so we have to
1042 // duplicate the current value.
1043 setStrftimeFormat(bstrdup(resource.strftime_format));
1044 #else // !HAVE_STRFTIME
1045 setDateFormat(resource.date_format);
1046 setClock24Hour(resource.clock24hour);
1047 #endif // HAVE_STRFTIME
1048 setHideToolbar(resource.hide_toolbar);
1049 }
1050
1051 void BScreen::load() {
1052 std::ostrstream rscreen, rname, rclass;
1053 std::string s;
1054 bool b;
1055 long l;
1056 rscreen << "session.screen" << getScreenNumber() << '.' << ends;
1057
1058 rname << rscreen.str() << "hideToolbar" << ends;
1059 rclass << rscreen.str() << "HideToolbar" << ends;
1060 if (config.getValue(rname.str(), rclass.str(), b))
1061 resource.hide_toolbar = b;
1062
1063 rname.seekp(0); rclass.seekp(0);
1064 rname << rscreen.str() << "fullMaximization" << ends;
1065 rclass << rscreen.str() << "FullMaximization" << ends;
1066 if (config.getValue(rname.str(), rclass.str(), b))
1067 resource.full_max = b;
1068
1069 rname.seekp(0); rclass.seekp(0);
1070 rname << rscreen.str() << "focusNewWindows" << ends;
1071 rclass << rscreen.str() << "FocusNewWindows" << ends;
1072 if (config.getValue(rname.str(), rclass.str(), b))
1073 resource.focus_new = b;
1074
1075 rname.seekp(0); rclass.seekp(0);
1076 rname << rscreen.str() << "focusLastWindow" << ends;
1077 rclass << rscreen.str() << "FocusLastWindow" << ends;
1078 if (config.getValue(rname.str(), rclass.str(), b))
1079 resource.focus_last = b;
1080
1081 rname.seekp(0); rclass.seekp(0);
1082 rname << rscreen.str() << "rowPlacementDirection" << ends;
1083 rclass << rscreen.str() << "RowPlacementDirection" << ends;
1084 if (config.getValue(rname.str(), rclass.str(), s)) {
1085 if (0 == strncasecmp(s.c_str(), "RightToLeft", s.length()))
1086 resource.row_direction = RightLeft;
1087 else if (0 == strncasecmp(s.c_str(), "LeftToRight", s.length()))
1088 resource.row_direction = LeftRight;
1089 }
1090
1091 rname.seekp(0); rclass.seekp(0);
1092 rname << rscreen.str() << "colPlacementDirection" << ends;
1093 rclass << rscreen.str() << "ColPlacementDirection" << ends;
1094 if (config.getValue(rname.str(), rclass.str(), s)) {
1095 if (0 == strncasecmp(s.c_str(), "BottomToTop", s.length()))
1096 resource.col_direction = BottomTop;
1097 else if (0 == strncasecmp(s.c_str(), "TopToBottom", s.length()))
1098 resource.col_direction = TopBottom;
1099 }
1100
1101 rname.seekp(0); rclass.seekp(0);
1102 rname << rscreen.str() << "workspaces" << ends;
1103 rclass << rscreen.str() << "Workspaces" << ends;
1104 if (config.getValue(rname.str(), rclass.str(), l))
1105 resource.workspaces = l;
1106
1107 removeWorkspaceNames();
1108 rname.seekp(0); rclass.seekp(0);
1109 rname << rscreen.str() << "workspaceNames" << ends;
1110 rclass << rscreen.str() << "WorkspaceNames" << ends;
1111 if (config.getValue(rname.str(), rclass.str(), s)) {
1112 std::string::const_iterator it = s.begin(), end = s.end();
1113 while(1) {
1114 std::string::const_iterator tmp = it;// current string.begin()
1115 it = std::find(tmp, end, ','); // look for comma between tmp and end
1116 std::string name(tmp, it); // name = s[tmp:it]
1117 addWorkspaceName(name.c_str());
1118 if (it == end)
1119 break;
1120 ++it;
1121 }
1122 }
1123
1124 rname.seekp(0); rclass.seekp(0);
1125 rname << rscreen.str() << "focusModel" << ends;
1126 rclass << rscreen.str() << "FocusModel" << ends;
1127 if (config.getValue(rname.str(), rclass.str(), s)) {
1128 if (0 == strncasecmp(s.c_str(), "ClickToFocus", s.length())) {
1129 resource.auto_raise = false;
1130 resource.sloppy_focus = false;
1131 } else if (0 == strncasecmp(s.c_str(), "AutoRaiseSloppyFocus",
1132 s.length())) {
1133 resource.sloppy_focus = true;
1134 resource.auto_raise = true;
1135 } else if (0 == strncasecmp(s.c_str(), "SloppyFocus", s.length())) {
1136 resource.sloppy_focus = true;
1137 resource.auto_raise = false;
1138 }
1139 }
1140
1141 rname.seekp(0); rclass.seekp(0);
1142 rname << rscreen.str() << "windowZones" << ends;
1143 rclass << rscreen.str() << "WindowZones" << ends;
1144 if (config.getValue(rname.str(), rclass.str(), l))
1145 resource.zones = (l == 1 || l == 2 || l == 4) ? l : 1;
1146
1147 rname.seekp(0); rclass.seekp(0);
1148 rname << rscreen.str() << "windowPlacement" << ends;
1149 rclass << rscreen.str() << "WindowPlacement" << ends;
1150 if (config.getValue(rname.str(), rclass.str(), s)) {
1151 if (0 == strncasecmp(s.c_str(), "RowSmartPlacement", s.length()))
1152 resource.placement_policy = RowSmartPlacement;
1153 else if (0 == strncasecmp(s.c_str(), "ColSmartPlacement", s.length()))
1154 resource.placement_policy = ColSmartPlacement;
1155 else if (0 == strncasecmp(s.c_str(), "BestFitPlacement", s.length()))
1156 resource.placement_policy = BestFitPlacement;
1157 else if (0 == strncasecmp(s.c_str(), "CascadePlacement", s.length()))
1158 resource.placement_policy = CascadePlacement;
1159 }
1160
1161 #ifdef HAVE_STRFTIME
1162 rname.seekp(0); rclass.seekp(0);
1163 rname << rscreen.str() << "strftimeFormat" << ends;
1164 rclass << rscreen.str() << "StrftimeFormat" << ends;
1165 if (config.getValue(rname.str(), rclass.str(), s))
1166 resource.strftime_format = bstrdup(s.c_str());
1167 #else // !HAVE_STRFTIME
1168 rname.seekp(0); rclass.seekp(0);
1169 rname << rscreen.str() << "dateFormat" << ends;
1170 rclass << rscreen.str() << "DateFormat" << ends;
1171 if (config.getValue(rname.str(), rclass.str(), s)) {
1172 if (strncasecmp(s.c_str(), "European", s.length()))
1173 resource.date_format = B_EuropeanDate;
1174 else if (strncasecmp(s.c_str(), "American", s.length()))
1175 resource.date_format = B_AmericanDate;
1176 }
1177
1178 rname.seekp(0); rclass.seekp(0);
1179 rname << rscreen.str() << "clockFormat" << ends;
1180 rclass << rscreen.str() << "ClockFormat" << ends;
1181 if (config.getValue(rname.str(), rclass.str(), l)) {
1182 if (clock == 24)
1183 resource.clock24hour = true;
1184 else if (clock == 12)
1185 resource.clock24hour = false;
1186 #endif // HAVE_STRFTIME
1187
1188 rname.seekp(0); rclass.seekp(0);
1189 rname << rscreen.str() << "edgeSnapThreshold" << ends;
1190 rclass << rscreen.str() << "EdgeSnapThreshold" << ends;
1191 if (config.getValue(rname.str(), rclass.str(), l))
1192 resource.edge_snap_threshold = l;
1193
1194 rname.seekp(0); rclass.seekp(0);
1195 rname << rscreen.str() << "imageDither" << ends;
1196 rclass << rscreen.str() << "ImageDither" << ends;
1197 if (config.getValue(rname.str(), rclass.str(), b))
1198 resource.image_dither = b;
1199
1200 rname.seekp(0); rclass.seekp(0);
1201 rname << rscreen.str() << "rootCommand" << ends;
1202 rclass << rscreen.str() << "RootCommand" << ends;
1203 if (config.getValue(rname.str(), rclass.str(), s))
1204 resource.root_command = bstrdup(s.c_str());
1205
1206 rname.seekp(0); rclass.seekp(0);
1207 rname << rscreen.str() << "opaqueMove" << ends;
1208 rclass << rscreen.str() << "OpaqueMove" << ends;
1209 resource.opaque_move = b;
1210 }
1211
1212 void BScreen::reconfigure(void) {
1213 load();
1214 LoadStyle();
1215
1216 XGCValues gcv;
1217 unsigned long gc_value_mask = GCForeground;
1218 if (! i18n->multibyte()) gc_value_mask |= GCFont;
1219
1220 gcv.foreground = WhitePixel(getBaseDisplay().getXDisplay(),
1221 getScreenNumber());
1222 gcv.function = GXinvert;
1223 gcv.subwindow_mode = IncludeInferiors;
1224 XChangeGC(getBaseDisplay().getXDisplay(), opGC,
1225 GCForeground | GCFunction | GCSubwindowMode, &gcv);
1226
1227 gcv.foreground = resource.wstyle.l_text_focus.getPixel();
1228 if (resource.wstyle.font)
1229 gcv.font = resource.wstyle.font->fid;
1230 XChangeGC(getBaseDisplay().getXDisplay(), resource.wstyle.l_text_focus_gc,
1231 gc_value_mask, &gcv);
1232
1233 gcv.foreground = resource.wstyle.l_text_unfocus.getPixel();
1234 XChangeGC(getBaseDisplay().getXDisplay(), resource.wstyle.l_text_unfocus_gc,
1235 gc_value_mask, &gcv);
1236
1237 gcv.foreground = resource.wstyle.b_pic_focus.getPixel();
1238 XChangeGC(getBaseDisplay().getXDisplay(), resource.wstyle.b_pic_focus_gc,
1239 GCForeground, &gcv);
1240
1241 gcv.foreground = resource.wstyle.b_pic_unfocus.getPixel();
1242 XChangeGC(getBaseDisplay().getXDisplay(), resource.wstyle.b_pic_unfocus_gc,
1243 GCForeground, &gcv);
1244
1245 gcv.foreground = resource.mstyle.t_text.getPixel();
1246 if (resource.mstyle.t_font)
1247 gcv.font = resource.mstyle.t_font->fid;
1248 XChangeGC(getBaseDisplay().getXDisplay(), resource.mstyle.t_text_gc,
1249 gc_value_mask, &gcv);
1250
1251 gcv.foreground = resource.mstyle.f_text.getPixel();
1252 if (resource.mstyle.f_font)
1253 gcv.font = resource.mstyle.f_font->fid;
1254 XChangeGC(getBaseDisplay().getXDisplay(), resource.mstyle.f_text_gc,
1255 gc_value_mask, &gcv);
1256
1257 gcv.foreground = resource.mstyle.h_text.getPixel();
1258 XChangeGC(getBaseDisplay().getXDisplay(), resource.mstyle.h_text_gc,
1259 gc_value_mask, &gcv);
1260
1261 gcv.foreground = resource.mstyle.d_text.getPixel();
1262 XChangeGC(getBaseDisplay().getXDisplay(), resource.mstyle.d_text_gc,
1263 gc_value_mask, &gcv);
1264
1265 gcv.foreground = resource.mstyle.hilite.getColor()->getPixel();
1266 XChangeGC(getBaseDisplay().getXDisplay(), resource.mstyle.hilite_gc,
1267 gc_value_mask, &gcv);
1268
1269 gcv.foreground = resource.tstyle.l_text.getPixel();
1270 if (resource.tstyle.font)
1271 gcv.font = resource.tstyle.font->fid;
1272 XChangeGC(getBaseDisplay().getXDisplay(), resource.tstyle.l_text_gc,
1273 gc_value_mask, &gcv);
1274
1275 gcv.foreground = resource.tstyle.w_text.getPixel();
1276 XChangeGC(getBaseDisplay().getXDisplay(), resource.tstyle.w_text_gc,
1277 gc_value_mask, &gcv);
1278
1279 gcv.foreground = resource.tstyle.c_text.getPixel();
1280 XChangeGC(getBaseDisplay().getXDisplay(), resource.tstyle.c_text_gc,
1281 gc_value_mask, &gcv);
1282
1283 gcv.foreground = resource.tstyle.b_pic.getPixel();
1284 XChangeGC(getBaseDisplay().getXDisplay(), resource.tstyle.b_pic_gc,
1285 gc_value_mask, &gcv);
1286
1287 const char *s = i18n->getMessage(ScreenSet, ScreenPositionLength,
1288 "0: 0000 x 0: 0000");
1289 int l = strlen(s);
1290
1291 if (i18n->multibyte()) {
1292 XRectangle ink, logical;
1293 XmbTextExtents(resource.wstyle.fontset, s, l, &ink, &logical);
1294 geom_w = logical.width;
1295
1296 geom_h = resource.wstyle.fontset_extents->max_ink_extent.height;
1297 } else {
1298 geom_w = XTextWidth(resource.wstyle.font, s, l);
1299
1300 geom_h = resource.wstyle.font->ascent +
1301 resource.wstyle.font->descent;
1302 }
1303
1304 geom_w += (resource.bevel_width * 2);
1305 geom_h += (resource.bevel_width * 2);
1306
1307 Pixmap tmp = geom_pixmap;
1308 if (resource.wstyle.l_focus.getTexture() & BImage_ParentRelative) {
1309 if (resource.wstyle.t_focus.getTexture() ==
1310 (BImage_Flat | BImage_Solid)) {
1311 geom_pixmap = None;
1312 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window,
1313 resource.wstyle.t_focus.getColor()->getPixel());
1314 } else {
1315 geom_pixmap = image_control->renderImage(geom_w, geom_h,
1316 &resource.wstyle.t_focus);
1317 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
1318 geom_window, geom_pixmap);
1319 }
1320 } else {
1321 if (resource.wstyle.l_focus.getTexture() ==
1322 (BImage_Flat | BImage_Solid)) {
1323 geom_pixmap = None;
1324 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window,
1325 resource.wstyle.l_focus.getColor()->getPixel());
1326 } else {
1327 geom_pixmap = image_control->renderImage(geom_w, geom_h,
1328 &resource.wstyle.l_focus);
1329 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
1330 geom_window, geom_pixmap);
1331 }
1332 }
1333 if (tmp) image_control->removeImage(tmp);
1334
1335 XSetWindowBorderWidth(getBaseDisplay().getXDisplay(), geom_window,
1336 resource.border_width);
1337 XSetWindowBorder(getBaseDisplay().getXDisplay(), geom_window,
1338 resource.border_color.getPixel());
1339
1340 workspacemenu->reconfigure();
1341 iconmenu->reconfigure();
1342
1343 {
1344 int remember_sub = rootmenu->getCurrentSubmenu();
1345 InitMenu();
1346 raiseWindows(0, 0);
1347 rootmenu->reconfigure();
1348 rootmenu->drawSubmenu(remember_sub);
1349 }
1350
1351 configmenu->reconfigure();
1352
1353 toolbar->reconfigure();
1354
1355 #ifdef SLIT
1356 slit->reconfigure();
1357 #endif // SLIT
1358
1359 LinkedListIterator<Workspace> wit(workspacesList);
1360 for (Workspace *w = wit.current(); w; wit++, w = wit.current())
1361 w->reconfigure();
1362
1363 LinkedListIterator<OpenboxWindow> iit(iconList);
1364 for (OpenboxWindow *bw = iit.current(); bw; iit++, bw = iit.current())
1365 if (bw->validateClient())
1366 bw->reconfigure();
1367
1368 image_control->timeout();
1369 }
1370
1371
1372 void BScreen::rereadMenu(void) {
1373 InitMenu();
1374 raiseWindows(0, 0);
1375
1376 rootmenu->reconfigure();
1377 }
1378
1379
1380 void BScreen::removeWorkspaceNames(void) {
1381 while (workspaceNames->count())
1382 delete [] workspaceNames->remove(0);
1383 }
1384
1385
1386 void BScreen::LoadStyle(void) {
1387 Resource &conf = resource.styleconfig;
1388
1389 conf.setFile(openbox.getStyleFilename());
1390 if (!conf.load()) {
1391 conf.setFile(DEFAULTSTYLE);
1392 if (!conf.load()) {
1393 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenDefaultStyleLoadFail,
1394 "BScreen::LoadStyle(): couldn't load "
1395 "default style.\n"));
1396 exit(2);
1397 }
1398 }
1399
1400 std::string s;
1401 long l;
1402
1403 // load fonts/fontsets
1404
1405 if (i18n->multibyte()) {
1406 readDatabaseFontSet("window.font", "Window.Font",
1407 &resource.wstyle.fontset);
1408 readDatabaseFontSet("toolbar.font", "Toolbar.Font",
1409 &resource.tstyle.fontset);
1410 readDatabaseFontSet("menu.title.font", "Menu.Title.Font",
1411 &resource.mstyle.t_fontset);
1412 readDatabaseFontSet("menu.frame.font", "Menu.Frame.Font",
1413 &resource.mstyle.f_fontset);
1414
1415 resource.mstyle.t_fontset_extents =
1416 XExtentsOfFontSet(resource.mstyle.t_fontset);
1417 resource.mstyle.f_fontset_extents =
1418 XExtentsOfFontSet(resource.mstyle.f_fontset);
1419 resource.tstyle.fontset_extents =
1420 XExtentsOfFontSet(resource.tstyle.fontset);
1421 resource.wstyle.fontset_extents =
1422 XExtentsOfFontSet(resource.wstyle.fontset);
1423 } else {
1424 readDatabaseFont("window.font", "Window.Font",
1425 &resource.wstyle.font);
1426 readDatabaseFont("menu.title.font", "Menu.Title.Font",
1427 &resource.mstyle.t_font);
1428 readDatabaseFont("menu.frame.font", "Menu.Frame.Font",
1429 &resource.mstyle.f_font);
1430 readDatabaseFont("toolbar.font", "Toolbar.Font",
1431 &resource.tstyle.font);
1432 }
1433
1434 // load window config
1435 readDatabaseTexture("window.title.focus", "Window.Title.Focus",
1436 &resource.wstyle.t_focus,
1437 WhitePixel(getBaseDisplay().getXDisplay(),
1438 getScreenNumber()));
1439 readDatabaseTexture("window.title.unfocus", "Window.Title.Unfocus",
1440 &resource.wstyle.t_unfocus,
1441 BlackPixel(getBaseDisplay().getXDisplay(),
1442 getScreenNumber()));
1443 readDatabaseTexture("window.label.focus", "Window.Label.Focus",
1444 &resource.wstyle.l_focus,
1445 WhitePixel(getBaseDisplay().getXDisplay(),
1446 getScreenNumber()));
1447 readDatabaseTexture("window.label.unfocus", "Window.Label.Unfocus",
1448 &resource.wstyle.l_unfocus,
1449 BlackPixel(getBaseDisplay().getXDisplay(),
1450 getScreenNumber()));
1451 readDatabaseTexture("window.handle.focus", "Window.Handle.Focus",
1452 &resource.wstyle.h_focus,
1453 WhitePixel(getBaseDisplay().getXDisplay(),
1454 getScreenNumber()));
1455 readDatabaseTexture("window.handle.unfocus", "Window.Handle.Unfocus",
1456 &resource.wstyle.h_unfocus,
1457 BlackPixel(getBaseDisplay().getXDisplay(),
1458 getScreenNumber()));
1459 readDatabaseTexture("window.grip.focus", "Window.Grip.Focus",
1460 &resource.wstyle.g_focus,
1461 WhitePixel(getBaseDisplay().getXDisplay(),
1462 getScreenNumber()));
1463 readDatabaseTexture("window.grip.unfocus", "Window.Grip.Unfocus",
1464 &resource.wstyle.g_unfocus,
1465 BlackPixel(getBaseDisplay().getXDisplay(),
1466 getScreenNumber()));
1467 readDatabaseTexture("window.button.focus", "Window.Button.Focus",
1468 &resource.wstyle.b_focus,
1469 WhitePixel(getBaseDisplay().getXDisplay(),
1470 getScreenNumber()));
1471 readDatabaseTexture("window.button.unfocus", "Window.Button.Unfocus",
1472 &resource.wstyle.b_unfocus,
1473 BlackPixel(getBaseDisplay().getXDisplay(),
1474 getScreenNumber()));
1475 readDatabaseTexture("window.button.pressed", "Window.Button.Pressed",
1476 &resource.wstyle.b_pressed,
1477 BlackPixel(getBaseDisplay().getXDisplay(),
1478 getScreenNumber()));
1479 readDatabaseColor("window.frame.focusColor",
1480 "Window.Frame.FocusColor",
1481 &resource.wstyle.f_focus,
1482 WhitePixel(getBaseDisplay().getXDisplay(),
1483 getScreenNumber()));
1484 readDatabaseColor("window.frame.unfocusColor",
1485 "Window.Frame.UnfocusColor",
1486 &resource.wstyle.f_unfocus,
1487 BlackPixel(getBaseDisplay().getXDisplay(),
1488 getScreenNumber()));
1489 readDatabaseColor("window.label.focus.textColor",
1490 "Window.Label.Focus.TextColor",
1491 &resource.wstyle.l_text_focus,
1492 BlackPixel(getBaseDisplay().getXDisplay(),
1493 getScreenNumber()));
1494 readDatabaseColor("window.label.unfocus.textColor",
1495 "Window.Label.Unfocus.TextColor",
1496 &resource.wstyle.l_text_unfocus,
1497 WhitePixel(getBaseDisplay().getXDisplay(),
1498 getScreenNumber()));
1499 readDatabaseColor("window.button.focus.picColor",
1500 "Window.Button.Focus.PicColor",
1501 &resource.wstyle.b_pic_focus,
1502 BlackPixel(getBaseDisplay().getXDisplay(),
1503 getScreenNumber()));
1504 readDatabaseColor("window.button.unfocus.picColor",
1505 "Window.Button.Unfocus.PicColor",
1506 &resource.wstyle.b_pic_unfocus,
1507 WhitePixel(getBaseDisplay().getXDisplay(),
1508 getScreenNumber()));
1509
1510 if (conf.getValue("window.justify", "Window.Justify", s)) {
1511 if (0 == strncasecmp(s.c_str(), "right", s.length()))
1512 resource.wstyle.justify = BScreen::RightJustify;
1513 else if (0 == strncasecmp(s.c_str(), "center", s.length()))
1514 resource.wstyle.justify = BScreen::CenterJustify;
1515 else
1516 resource.wstyle.justify = BScreen::LeftJustify;
1517 } else
1518 resource.wstyle.justify = BScreen::LeftJustify;
1519
1520 // load toolbar config
1521 readDatabaseTexture("toolbar", "Toolbar",
1522 &resource.tstyle.toolbar,
1523 BlackPixel(getBaseDisplay().getXDisplay(),
1524 getScreenNumber()));
1525 readDatabaseTexture("toolbar.label", "Toolbar.Label",
1526 &resource.tstyle.label,
1527 BlackPixel(getBaseDisplay().getXDisplay(),
1528 getScreenNumber()));
1529 readDatabaseTexture("toolbar.windowLabel", "Toolbar.WindowLabel",
1530 &resource.tstyle.window,
1531 BlackPixel(getBaseDisplay().getXDisplay(),
1532 getScreenNumber()));
1533 readDatabaseTexture("toolbar.button", "Toolbar.Button",
1534 &resource.tstyle.button,
1535 WhitePixel(getBaseDisplay().getXDisplay(),
1536 getScreenNumber()));
1537 readDatabaseTexture("toolbar.button.pressed", "Toolbar.Button.Pressed",
1538 &resource.tstyle.pressed,
1539 BlackPixel(getBaseDisplay().getXDisplay(),
1540 getScreenNumber()));
1541 readDatabaseTexture("toolbar.clock", "Toolbar.Clock",
1542 &resource.tstyle.clock,
1543 BlackPixel(getBaseDisplay().getXDisplay(),
1544 getScreenNumber()));
1545 readDatabaseColor("toolbar.label.textColor", "Toolbar.Label.TextColor",
1546 &resource.tstyle.l_text,
1547 WhitePixel(getBaseDisplay().getXDisplay(),
1548 getScreenNumber()));
1549 readDatabaseColor("toolbar.windowLabel.textColor",
1550 "Toolbar.WindowLabel.TextColor",
1551 &resource.tstyle.w_text,
1552 WhitePixel(getBaseDisplay().getXDisplay(),
1553 getScreenNumber()));
1554 readDatabaseColor("toolbar.clock.textColor", "Toolbar.Clock.TextColor",
1555 &resource.tstyle.c_text,
1556 WhitePixel(getBaseDisplay().getXDisplay(),
1557 getScreenNumber()));
1558 readDatabaseColor("toolbar.button.picColor", "Toolbar.Button.PicColor",
1559 &resource.tstyle.b_pic,
1560 BlackPixel(getBaseDisplay().getXDisplay(),
1561 getScreenNumber()));
1562
1563 if (conf.getValue("toolbar.justify", "Toolbar.Justify", s)) {
1564 if (0 == strncasecmp(s.c_str(), "right", s.length()))
1565 resource.tstyle.justify = BScreen::RightJustify;
1566 else if (0 == strncasecmp(s.c_str(), "center", s.length()))
1567 resource.tstyle.justify = BScreen::CenterJustify;
1568 else
1569 resource.tstyle.justify = BScreen::LeftJustify;
1570 } else
1571 resource.tstyle.justify = BScreen::LeftJustify;
1572
1573 // load menu config
1574 readDatabaseTexture("menu.title", "Menu.Title",
1575 &resource.mstyle.title,
1576 WhitePixel(getBaseDisplay().getXDisplay(),
1577 getScreenNumber()));
1578 readDatabaseTexture("menu.frame", "Menu.Frame",
1579 &resource.mstyle.frame,
1580 BlackPixel(getBaseDisplay().getXDisplay(),
1581 getScreenNumber()));
1582 readDatabaseTexture("menu.hilite", "Menu.Hilite",
1583 &resource.mstyle.hilite,
1584 WhitePixel(getBaseDisplay().getXDisplay(),
1585 getScreenNumber()));
1586 readDatabaseColor("menu.title.textColor", "Menu.Title.TextColor",
1587 &resource.mstyle.t_text,
1588 BlackPixel(getBaseDisplay().getXDisplay(),
1589 getScreenNumber()));
1590 readDatabaseColor("menu.frame.textColor", "Menu.Frame.TextColor",
1591 &resource.mstyle.f_text,
1592 WhitePixel(getBaseDisplay().getXDisplay(),
1593 getScreenNumber()));
1594 readDatabaseColor("menu.frame.disableColor", "Menu.Frame.DisableColor",
1595 &resource.mstyle.d_text,
1596 BlackPixel(getBaseDisplay().getXDisplay(),
1597 getScreenNumber()));
1598 readDatabaseColor("menu.hilite.textColor", "Menu.Hilite.TextColor",
1599 &resource.mstyle.h_text,
1600 BlackPixel(getBaseDisplay().getXDisplay(),
1601 getScreenNumber()));
1602
1603 if (conf.getValue("menu.title.justify", "Menu.Title.Justify", s)) {
1604 if (0 == strncasecmp(s.c_str(), "right", s.length()))
1605 resource.mstyle.t_justify = BScreen::RightJustify;
1606 else if (0 == strncasecmp(s.c_str(), "center", s.length()))
1607 resource.mstyle.t_justify = BScreen::CenterJustify;
1608 else
1609 resource.mstyle.t_justify = BScreen::LeftJustify;
1610 } else
1611 resource.mstyle.t_justify = BScreen::LeftJustify;
1612
1613 if (conf.getValue("menu.frame.justify", "Menu.Frame.Justify", s)) {
1614 if (0 == strncasecmp(s.c_str(), "right", s.length()))
1615 resource.mstyle.f_justify = BScreen::RightJustify;
1616 else if (0 == strncasecmp(s.c_str(), "center", s.length()))
1617 resource.mstyle.f_justify = BScreen::CenterJustify;
1618 else
1619 resource.mstyle.f_justify = BScreen::LeftJustify;
1620 } else
1621 resource.mstyle.f_justify = BScreen::LeftJustify;
1622
1623 if (conf.getValue("menu.bullet", "Menu.Bullet", s)) {
1624 if (0 == strncasecmp(s.c_str(), "empty", s.length()))
1625 resource.mstyle.bullet = Basemenu::Empty;
1626 else if (0 == strncasecmp(s.c_str(), "square", s.length()))
1627 resource.mstyle.bullet = Basemenu::Square;
1628 else if (0 == strncasecmp(s.c_str(), "diamond", s.length()))
1629 resource.mstyle.bullet = Basemenu::Diamond;
1630 else
1631 resource.mstyle.bullet = Basemenu::Triangle;
1632 } else
1633 resource.mstyle.bullet = Basemenu::Triangle;
1634
1635 if (conf.getValue("menu.bullet.position", "Menu.Bullet.Position", s)) {
1636 if (0 == strncasecmp(s.c_str(), "right", s.length()))
1637 resource.mstyle.bullet_pos = Basemenu::Right;
1638 else
1639 resource.mstyle.bullet_pos = Basemenu::Left;
1640 } else
1641 resource.mstyle.bullet_pos = Basemenu::Left;
1642
1643 readDatabaseColor("borderColor", "BorderColor", &resource.border_color,
1644 BlackPixel(getBaseDisplay().getXDisplay(),
1645 getScreenNumber()));
1646
1647 // load bevel, border and handle widths
1648 if (conf.getValue("handleWidth", "HandleWidth", l)) {
1649 if (l <= size().w() / 2 && l != 0)
1650 resource.handle_width = l;
1651 else
1652 resource.handle_width = 6;
1653 } else
1654 resource.handle_width = 6;
1655
1656 if (conf.getValue("borderWidth", "BorderWidth", l))
1657 resource.border_width = l;
1658 else
1659 resource.border_width = 1;
1660
1661 if (conf.getValue("bevelWidth", "BevelWidth", l)) {
1662 if (l <= size().w() / 2 && l != 0)
1663 resource.bevel_width = l;
1664 else
1665 resource.bevel_width = 3;
1666 } else
1667 resource.bevel_width = 3;
1668
1669 if (conf.getValue("frameWidth", "FrameWidth", l)) {
1670 if (l <= size().w() / 2)
1671 resource.frame_width = l;
1672 else
1673 resource.frame_width = resource.bevel_width;
1674 } else
1675 resource.frame_width = resource.bevel_width;
1676
1677 const char *cmd = resource.root_command;
1678 if (cmd != NULL || conf.getValue("rootCommand", "RootCommand", s)) {
1679 if (cmd == NULL)
1680 cmd = s.c_str(); // not specified by the screen, so use the one from the
1681 // style file
1682 #ifndef __EMX__
1683 char displaystring[MAXPATHLEN];
1684 sprintf(displaystring, "DISPLAY=%s",
1685 DisplayString(getBaseDisplay().getXDisplay()));
1686 sprintf(displaystring + strlen(displaystring) - 1, "%d",
1687 getScreenNumber());
1688
1689 bexec(cmd, displaystring);
1690 #else // __EMX__
1691 spawnlp(P_NOWAIT, "cmd.exe", "cmd.exe", "/c", cmd, NULL);
1692 #endif // !__EMX__
1693 }
1694 }
1695
1696
1697 void BScreen::addIcon(OpenboxWindow *w) {
1698 if (! w) return;
1699
1700 w->setWorkspace(-1);
1701 w->setWindowNumber(iconList->count());
1702
1703 iconList->insert(w);
1704
1705 iconmenu->insert((const char **) w->getIconTitle());
1706 iconmenu->update();
1707 }
1708
1709
1710 void BScreen::removeIcon(OpenboxWindow *w) {
1711 if (! w) return;
1712
1713 iconList->remove(w->getWindowNumber());
1714
1715 iconmenu->remove(w->getWindowNumber());
1716 iconmenu->update();
1717
1718 LinkedListIterator<OpenboxWindow> it(iconList);
1719 OpenboxWindow *bw = it.current();
1720 for (int i = 0; bw; it++, bw = it.current())
1721 bw->setWindowNumber(i++);
1722 }
1723
1724
1725 OpenboxWindow *BScreen::getIcon(int index) {
1726 if (index >= 0 && index < iconList->count())
1727 return iconList->find(index);
1728
1729 return (OpenboxWindow *) 0;
1730 }
1731
1732
1733 int BScreen::addWorkspace(void) {
1734 Workspace *wkspc = new Workspace(*this, workspacesList->count());
1735 workspacesList->insert(wkspc);
1736 saveWorkspaceNames();
1737
1738 workspacemenu->insert(wkspc->getName(), wkspc->getMenu(),
1739 wkspc->getWorkspaceID() + 2);
1740 workspacemenu->update();
1741
1742 toolbar->reconfigure();
1743
1744 updateNetizenWorkspaceCount();
1745
1746 return workspacesList->count();
1747 }
1748
1749
1750 int BScreen::removeLastWorkspace(void) {
1751 if (workspacesList->count() == 1)
1752 return 0;
1753
1754 Workspace *wkspc = workspacesList->last();
1755
1756 if (current_workspace->getWorkspaceID() == wkspc->getWorkspaceID())
1757 changeWorkspaceID(current_workspace->getWorkspaceID() - 1);
1758
1759 wkspc->removeAll();
1760
1761 workspacemenu->remove(wkspc->getWorkspaceID() + 2);
1762 workspacemenu->update();
1763
1764 workspacesList->remove(wkspc);
1765 delete wkspc;
1766
1767 toolbar->reconfigure();
1768
1769 updateNetizenWorkspaceCount();
1770
1771 return workspacesList->count();
1772 }
1773
1774
1775 void BScreen::changeWorkspaceID(int id) {
1776 if (! current_workspace) return;
1777
1778 if (id != current_workspace->getWorkspaceID()) {
1779 current_workspace->hideAll();
1780
1781 workspacemenu->setItemSelected(current_workspace->getWorkspaceID() + 2,
1782 False);
1783
1784 if (openbox.getFocusedWindow() &&
1785 openbox.getFocusedWindow()->getScreen() == this &&
1786 (! openbox.getFocusedWindow()->isStuck())) {
1787 current_workspace->setLastFocusedWindow(openbox.getFocusedWindow());
1788 openbox.setFocusedWindow((OpenboxWindow *) 0);
1789 }
1790
1791 current_workspace = getWorkspace(id);
1792
1793 workspacemenu->setItemSelected(current_workspace->getWorkspaceID() + 2,
1794 True);
1795 toolbar->redrawWorkspaceLabel(True);
1796
1797 current_workspace->showAll();
1798
1799 if (resource.focus_last && current_workspace->getLastFocusedWindow()) {
1800 XSync(openbox.getXDisplay(), False);
1801 current_workspace->getLastFocusedWindow()->setInputFocus();
1802 }
1803 }
1804
1805 updateNetizenCurrentWorkspace();
1806 }
1807
1808
1809 void BScreen::addNetizen(Netizen *n) {
1810 netizenList->insert(n);
1811
1812 n->sendWorkspaceCount();
1813 n->sendCurrentWorkspace();
1814
1815 LinkedListIterator<Workspace> it(workspacesList);
1816 for (Workspace *w = it.current(); w; it++, w = it.current()) {
1817 for (int i = 0; i < w->getCount(); i++)
1818 n->sendWindowAdd(w->getWindow(i)->getClientWindow(),
1819 w->getWorkspaceID());
1820 }
1821
1822 Window f = ((openbox.getFocusedWindow()) ?
1823 openbox.getFocusedWindow()->getClientWindow() : None);
1824 n->sendWindowFocus(f);
1825 }
1826
1827
1828 void BScreen::removeNetizen(Window w) {
1829 LinkedListIterator<Netizen> it(netizenList);
1830 int i = 0;
1831
1832 for (Netizen *n = it.current(); n; it++, i++, n = it.current())
1833 if (n->getWindowID() == w) {
1834 Netizen *tmp = netizenList->remove(i);
1835 delete tmp;
1836
1837 break;
1838 }
1839 }
1840
1841
1842 void BScreen::updateNetizenCurrentWorkspace(void) {
1843 LinkedListIterator<Netizen> it(netizenList);
1844 for (Netizen *n = it.current(); n; it++, n = it.current())
1845 n->sendCurrentWorkspace();
1846 }
1847
1848
1849 void BScreen::updateNetizenWorkspaceCount(void) {
1850 LinkedListIterator<Netizen> it(netizenList);
1851 for (Netizen *n = it.current(); n; it++, n = it.current())
1852 n->sendWorkspaceCount();
1853 }
1854
1855
1856 void BScreen::updateNetizenWindowFocus(void) {
1857 Window f = ((openbox.getFocusedWindow()) ?
1858 openbox.getFocusedWindow()->getClientWindow() : None);
1859 LinkedListIterator<Netizen> it(netizenList);
1860 for (Netizen *n = it.current(); n; it++, n = it.current())
1861 n->sendWindowFocus(f);
1862 }
1863
1864
1865 void BScreen::updateNetizenWindowAdd(Window w, unsigned long p) {
1866 LinkedListIterator<Netizen> it(netizenList);
1867 for (Netizen *n = it.current(); n; it++, n = it.current())
1868 n->sendWindowAdd(w, p);
1869 }
1870
1871
1872 void BScreen::updateNetizenWindowDel(Window w) {
1873 LinkedListIterator<Netizen> it(netizenList);
1874 for (Netizen *n = it.current(); n; it++, n = it.current())
1875 n->sendWindowDel(w);
1876 }
1877
1878
1879 void BScreen::updateNetizenWindowRaise(Window w) {
1880 LinkedListIterator<Netizen> it(netizenList);
1881 for (Netizen *n = it.current(); n; it++, n = it.current())
1882 n->sendWindowRaise(w);
1883 }
1884
1885
1886 void BScreen::updateNetizenWindowLower(Window w) {
1887 LinkedListIterator<Netizen> it(netizenList);
1888 for (Netizen *n = it.current(); n; it++, n = it.current())
1889 n->sendWindowLower(w);
1890 }
1891
1892
1893 void BScreen::updateNetizenConfigNotify(XEvent *e) {
1894 LinkedListIterator<Netizen> it(netizenList);
1895 for (Netizen *n = it.current(); n; it++, n = it.current())
1896 n->sendConfigNotify(e);
1897 }
1898
1899
1900 void BScreen::raiseWindows(Window *workspace_stack, int num) {
1901 Window *session_stack = new
1902 Window[(num + workspacesList->count() + rootmenuList->count() + 13)];
1903 int i = 0, k = num;
1904
1905 XRaiseWindow(getBaseDisplay().getXDisplay(), iconmenu->getWindowID());
1906 *(session_stack + i++) = iconmenu->getWindowID();
1907
1908 LinkedListIterator<Workspace> wit(workspacesList);
1909 for (Workspace *tmp = wit.current(); tmp; wit++, tmp = wit.current())
1910 *(session_stack + i++) = tmp->getMenu()->getWindowID();
1911
1912 *(session_stack + i++) = workspacemenu->getWindowID();
1913
1914 *(session_stack + i++) = configmenu->getFocusmenu()->getWindowID();
1915 *(session_stack + i++) = configmenu->getPlacementmenu()->getWindowID();
1916 *(session_stack + i++) = configmenu->getWindowID();
1917
1918 #ifdef SLIT
1919 *(session_stack + i++) = slit->getMenu()->getDirectionmenu()->getWindowID();
1920 *(session_stack + i++) = slit->getMenu()->getPlacementmenu()->getWindowID();
1921 *(session_stack + i++) = slit->getMenu()->getWindowID();
1922 #endif // SLIT
1923
1924 *(session_stack + i++) =
1925 toolbar->getMenu()->getPlacementmenu()->getWindowID();
1926 *(session_stack + i++) = toolbar->getMenu()->getWindowID();
1927
1928 LinkedListIterator<Rootmenu> rit(rootmenuList);
1929 for (Rootmenu *tmp = rit.current(); tmp; rit++, tmp = rit.current())
1930 *(session_stack + i++) = tmp->getWindowID();
1931 *(session_stack + i++) = rootmenu->getWindowID();
1932
1933 if (toolbar->onTop())
1934 *(session_stack + i++) = toolbar->getWindowID();
1935
1936 #ifdef SLIT
1937 if (slit->onTop())
1938 *(session_stack + i++) = slit->getWindowID();
1939 #endif // SLIT
1940
1941 while (k--)
1942 *(session_stack + i++) = *(workspace_stack + k);
1943
1944 XRestackWindows(getBaseDisplay().getXDisplay(), session_stack, i);
1945
1946 delete [] session_stack;
1947 }
1948
1949
1950 void BScreen::addWorkspaceName(const char *name) {
1951 workspaceNames->insert(bstrdup(name));
1952 }
1953
1954 char* BScreen::getNameOfWorkspace(int id) {
1955 char *name = (char *) 0;
1956
1957 if (id >= 0 && id < workspaceNames->count()) {
1958 char *wkspc_name = workspaceNames->find(id);
1959
1960 if (wkspc_name)
1961 name = wkspc_name;
1962 }
1963 return name;
1964 }
1965
1966
1967 void BScreen::reassociateWindow(OpenboxWindow *w, int wkspc_id, Bool ignore_sticky) {
1968 if (! w) return;
1969
1970 if (wkspc_id == -1)
1971 wkspc_id = current_workspace->getWorkspaceID();
1972
1973 if (w->getWorkspaceNumber() == wkspc_id)
1974 return;
1975
1976 if (w->isIconic()) {
1977 removeIcon(w);
1978 getWorkspace(wkspc_id)->addWindow(w);
1979 } else if (ignore_sticky || ! w->isStuck()) {
1980 getWorkspace(w->getWorkspaceNumber())->removeWindow(w);
1981 getWorkspace(wkspc_id)->addWindow(w);
1982 }
1983 }
1984
1985
1986 void BScreen::nextFocus(void) {
1987 Bool have_focused = False;
1988 int focused_window_number = -1;
1989 OpenboxWindow *next;
1990
1991 if (openbox.getFocusedWindow()) {
1992 if (openbox.getFocusedWindow()->getScreen()->getScreenNumber() ==
1993 getScreenNumber()) {
1994 have_focused = True;
1995 focused_window_number = openbox.getFocusedWindow()->getWindowNumber();
1996 }
1997 }
1998
1999 if ((getCurrentWorkspace()->getCount() > 1) && have_focused) {
2000 int next_window_number = focused_window_number;
2001 do {
2002 if ((++next_window_number) >= getCurrentWorkspace()->getCount())
2003 next_window_number = 0;
2004
2005 next = getCurrentWorkspace()->getWindow(next_window_number);
2006 } while ((! next->setInputFocus()) && (next_window_number !=
2007 focused_window_number));
2008
2009 if (next_window_number != focused_window_number)
2010 getCurrentWorkspace()->raiseWindow(next);
2011 } else if (getCurrentWorkspace()->getCount() >= 1) {
2012 next = current_workspace->getWindow(0);
2013
2014 current_workspace->raiseWindow(next);
2015 next->setInputFocus();
2016 }
2017 }
2018
2019
2020 void BScreen::prevFocus(void) {
2021 Bool have_focused = False;
2022 int focused_window_number = -1;
2023 OpenboxWindow *prev;
2024
2025 if (openbox.getFocusedWindow()) {
2026 if (openbox.getFocusedWindow()->getScreen()->getScreenNumber() ==
2027 getScreenNumber()) {
2028 have_focused = True;
2029 focused_window_number = openbox.getFocusedWindow()->getWindowNumber();
2030 }
2031 }
2032
2033 if ((getCurrentWorkspace()->getCount() > 1) && have_focused) {
2034 int prev_window_number = focused_window_number;
2035 do {
2036 if ((--prev_window_number) < 0)
2037 prev_window_number = getCurrentWorkspace()->getCount() - 1;
2038
2039 prev = getCurrentWorkspace()->getWindow(prev_window_number);
2040 } while ((! prev->setInputFocus()) && (prev_window_number !=
2041 focused_window_number));
2042
2043 if (prev_window_number != focused_window_number)
2044 getCurrentWorkspace()->raiseWindow(prev);
2045 } else if (getCurrentWorkspace()->getCount() >= 1) {
2046 prev = current_workspace->getWindow(0);
2047
2048 current_workspace->raiseWindow(prev);
2049 prev->setInputFocus();
2050 }
2051 }
2052
2053
2054 void BScreen::raiseFocus(void) {
2055 Bool have_focused = False;
2056 int focused_window_number = -1;
2057
2058 if (openbox.getFocusedWindow()) {
2059 if (openbox.getFocusedWindow()->getScreen()->getScreenNumber() ==
2060 getScreenNumber()) {
2061 have_focused = True;
2062 focused_window_number = openbox.getFocusedWindow()->getWindowNumber();
2063 }
2064 }
2065
2066 if ((getCurrentWorkspace()->getCount() > 1) && have_focused)
2067 getWorkspace(openbox.getFocusedWindow()->getWorkspaceNumber())->
2068 raiseWindow(openbox.getFocusedWindow());
2069 }
2070
2071
2072 void BScreen::InitMenu(void) {
2073 if (rootmenu) {
2074 while (rootmenuList->count())
2075 rootmenuList->remove(0);
2076
2077 while (rootmenu->getCount())
2078 rootmenu->remove(0);
2079 } else {
2080 rootmenu = new Rootmenu(*this);
2081 }
2082 Bool defaultMenu = True;
2083
2084 if (openbox.getMenuFilename()) {
2085 FILE *menu_file = fopen(openbox.getMenuFilename(), "r");
2086
2087 if (!menu_file) {
2088 perror(openbox.getMenuFilename());
2089 } else {
2090 if (feof(menu_file)) {
2091 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenEmptyMenuFile,
2092 "%s: Empty menu file"),
2093 openbox.getMenuFilename());
2094 } else {
2095 char line[1024], label[1024];
2096 memset(line, 0, 1024);
2097 memset(label, 0, 1024);
2098
2099 while (fgets(line, 1024, menu_file) && ! feof(menu_file)) {
2100 if (line[0] != '#') {
2101 int i, key = 0, index = -1, len = strlen(line);
2102
2103 key = 0;
2104 for (i = 0; i < len; i++) {
2105 if (line[i] == '[') index = 0;
2106 else if (line[i] == ']') break;
2107 else if (line[i] != ' ')
2108 if (index++ >= 0)
2109 key += tolower(line[i]);
2110 }
2111
2112 if (key == 517) {
2113 index = -1;
2114 for (i = index; i < len; i++) {
2115 if (line[i] == '(') index = 0;
2116 else if (line[i] == ')') break;
2117 else if (index++ >= 0) {
2118 if (line[i] == '\\' && i < len - 1) i++;
2119 label[index - 1] = line[i];
2120 }
2121 }
2122
2123 if (index == -1) index = 0;
2124 label[index] = '\0';
2125
2126 rootmenu->setLabel(label);
2127 defaultMenu = parseMenuFile(menu_file, rootmenu);
2128 break;
2129 }
2130 }
2131 }
2132 }
2133 fclose(menu_file);
2134 }
2135 }
2136
2137 if (defaultMenu) {
2138 rootmenu->setInternalMenu();
2139 rootmenu->insert(i18n->getMessage(ScreenSet, Screenxterm, "xterm"),
2140 BScreen::Execute,
2141 i18n->getMessage(ScreenSet, Screenxterm, "xterm"));
2142 rootmenu->insert(i18n->getMessage(ScreenSet, ScreenRestart, "Restart"),
2143 BScreen::Restart);
2144 rootmenu->insert(i18n->getMessage(ScreenSet, ScreenExit, "Exit"),
2145 BScreen::Exit);
2146 } else {
2147 openbox.saveMenuFilename(openbox.getMenuFilename());
2148 }
2149 }
2150
2151
2152 Bool BScreen::parseMenuFile(FILE *file, Rootmenu *menu) {
2153 char line[1024], label[1024], command[1024];
2154
2155 while (! feof(file)) {
2156 memset(line, 0, 1024);
2157 memset(label, 0, 1024);
2158 memset(command, 0, 1024);
2159
2160 if (fgets(line, 1024, file)) {
2161 if (line[0] != '#') {
2162 register int i, key = 0, parse = 0, index = -1,
2163 line_length = strlen(line),
2164 label_length = 0, command_length = 0;
2165
2166 // determine the keyword
2167 key = 0;
2168 for (i = 0; i < line_length; i++) {
2169 if (line[i] == '[') parse = 1;
2170 else if (line[i] == ']') break;
2171 else if (line[i] != ' ')
2172 if (parse)
2173 key += tolower(line[i]);
2174 }
2175
2176 // get the label enclosed in ()'s
2177 parse = 0;
2178
2179 for (i = 0; i < line_length; i++) {
2180 if (line[i] == '(') {
2181 index = 0;
2182 parse = 1;
2183 } else if (line[i] == ')') break;
2184 else if (index++ >= 0) {
2185 if (line[i] == '\\' && i < line_length - 1) i++;
2186 label[index - 1] = line[i];
2187 }
2188 }
2189
2190 if (parse) {
2191 label[index] = '\0';
2192 label_length = index;
2193 } else {
2194 label[0] = '\0';
2195 label_length = 0;
2196 }
2197
2198 // get the command enclosed in {}'s
2199 parse = 0;
2200 index = -1;
2201 for (i = 0; i < line_length; i++) {
2202 if (line[i] == '{') {
2203 index = 0;
2204 parse = 1;
2205 } else if (line[i] == '}') break;
2206 else if (index++ >= 0) {
2207 if (line[i] == '\\' && i < line_length - 1) i++;
2208 command[index - 1] = line[i];
2209 }
2210 }
2211
2212 if (parse) {
2213 command[index] = '\0';
2214 command_length = index;
2215 } else {
2216 command[0] = '\0';
2217 command_length = 0;
2218 }
2219
2220 switch (key) {
2221 case 311: //end
2222 return ((menu->getCount() == 0) ? True : False);
2223
2224 break;
2225
2226 case 333: // nop
2227 menu->insert(label);
2228
2229 break;
2230
2231 case 421: // exec
2232 if ((! *label) && (! *command)) {
2233 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenEXECError,
2234 "BScreen::parseMenuFile: [exec] error, "
2235 "no menu label and/or command defined\n"));
2236 continue;
2237 }
2238
2239 menu->insert(label, BScreen::Execute, command);
2240
2241 break;
2242
2243 case 442: // exit
2244 if (! *label) {
2245 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenEXITError,
2246 "BScreen::parseMenuFile: [exit] error, "
2247 "no menu label defined\n"));
2248 continue;
2249 }
2250
2251 menu->insert(label, BScreen::Exit);
2252
2253 break;
2254
2255 case 561: // style
2256 {
2257 if ((! *label) || (! *command)) {
2258 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenSTYLEError,
2259 "BScreen::parseMenuFile: [style] error, "
2260 "no menu label and/or filename defined\n"));
2261 continue;
2262 }
2263
2264 char style[MAXPATHLEN];
2265
2266 // perform shell style ~ home directory expansion
2267 char *homedir = 0;
2268 int homedir_len = 0;
2269 if (*command == '~' && *(command + 1) == '/') {
2270 homedir = getenv("HOME");
2271 homedir_len = strlen(homedir);
2272 }
2273
2274 if (homedir && homedir_len != 0) {
2275 strncpy(style, homedir, homedir_len);
2276
2277 strncpy(style + homedir_len, command + 1,
2278 command_length - 1);
2279 *(style + command_length + homedir_len - 1) = '\0';
2280 } else {
2281 strncpy(style, command, command_length);
2282 *(style + command_length) = '\0';
2283 }
2284
2285 menu->insert(label, BScreen::SetStyle, style);
2286 }
2287
2288 break;
2289
2290 case 630: // config
2291 if (! *label) {
2292 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenCONFIGError,
2293 "BScreen::parseMenufile: [config] error, "
2294 "no label defined"));
2295 continue;
2296 }
2297
2298 menu->insert(label, configmenu);
2299
2300 break;
2301
2302 case 740: // include
2303 {
2304 if (! *label) {
2305 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenINCLUDEError,
2306 "BScreen::parseMenuFile: [include] error, "
2307 "no filename defined\n"));
2308 continue;
2309 }
2310
2311 char newfile[MAXPATHLEN];
2312
2313 // perform shell style ~ home directory expansion
2314 char *homedir = 0;
2315 int homedir_len = 0;
2316 if (*label == '~' && *(label + 1) == '/') {
2317 homedir = getenv("HOME");
2318 homedir_len = strlen(homedir);
2319 }
2320
2321 if (homedir && homedir_len != 0) {
2322 strncpy(newfile, homedir, homedir_len);
2323
2324 strncpy(newfile + homedir_len, label + 1,
2325 label_length - 1);
2326 *(newfile + label_length + homedir_len - 1) = '\0';
2327 } else {
2328 strncpy(newfile, label, label_length);
2329 *(newfile + label_length) = '\0';
2330 }
2331
2332 if (newfile) {
2333 FILE *submenufile = fopen(newfile, "r");
2334
2335 if (submenufile) {
2336 struct stat buf;
2337 if (fstat(fileno(submenufile), &buf) ||
2338 (! S_ISREG(buf.st_mode))) {
2339 fprintf(stderr,
2340 i18n->getMessage(ScreenSet, ScreenINCLUDEErrorReg,
2341 "BScreen::parseMenuFile: [include] error: "
2342 "'%s' is not a regular file\n"), newfile);
2343 break;
2344 }
2345
2346 if (! feof(submenufile)) {
2347 if (! parseMenuFile(submenufile, menu))
2348 openbox.saveMenuFilename(newfile);
2349
2350 fclose(submenufile);
2351 }
2352 } else
2353 perror(newfile);
2354 }
2355 }
2356
2357 break;
2358
2359 case 767: // submenu
2360 {
2361 if (! *label) {
2362 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenSUBMENUError,
2363 "BScreen::parseMenuFile: [submenu] error, "
2364 "no menu label defined\n"));
2365 continue;
2366 }
2367
2368 Rootmenu *submenu = new Rootmenu(*this);
2369
2370 if (*command)
2371 submenu->setLabel(command);
2372 else
2373 submenu->setLabel(label);
2374
2375 parseMenuFile(file, submenu);
2376 submenu->update();
2377 menu->insert(label, submenu);
2378 rootmenuList->insert(submenu);
2379 }
2380
2381 break;
2382
2383 case 773: // restart
2384 {
2385 if (! *label) {
2386 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenRESTARTError,
2387 "BScreen::parseMenuFile: [restart] error, "
2388 "no menu label defined\n"));
2389 continue;
2390 }
2391
2392 if (*command)
2393 menu->insert(label, BScreen::RestartOther, command);
2394 else
2395 menu->insert(label, BScreen::Restart);
2396 }
2397
2398 break;
2399
2400 case 845: // reconfig
2401 {
2402 if (! *label) {
2403 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenRECONFIGError,
2404 "BScreen::parseMenuFile: [reconfig] error, "
2405 "no menu label defined\n"));
2406 continue;
2407 }
2408
2409 menu->insert(label, BScreen::Reconfigure);
2410 }
2411
2412 break;
2413
2414 case 995: // stylesdir
2415 case 1113: // stylesmenu
2416 {
2417 Bool newmenu = ((key == 1113) ? True : False);
2418
2419 if ((! *label) || ((! *command) && newmenu)) {
2420 fprintf(stderr,
2421 i18n->getMessage(ScreenSet, ScreenSTYLESDIRError,
2422 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
2423 " error, no directory defined\n"));
2424 continue;
2425 }
2426
2427 char stylesdir[MAXPATHLEN];
2428
2429 char *directory = ((newmenu) ? command : label);
2430 int directory_length = ((newmenu) ? command_length : label_length);
2431
2432 // perform shell style ~ home directory expansion
2433 char *homedir = 0;
2434 int homedir_len = 0;
2435
2436 if (*directory == '~' && *(directory + 1) == '/') {
2437 homedir = getenv("HOME");
2438 homedir_len = strlen(homedir);
2439 }
2440
2441 if (homedir && homedir_len != 0) {
2442 strncpy(stylesdir, homedir, homedir_len);
2443
2444 strncpy(stylesdir + homedir_len, directory + 1,
2445 directory_length - 1);
2446 *(stylesdir + directory_length + homedir_len - 1) = '\0';
2447 } else {
2448 strncpy(stylesdir, directory, directory_length);
2449 *(stylesdir + directory_length) = '\0';
2450 }
2451
2452 struct stat statbuf;
2453
2454 if (! stat(stylesdir, &statbuf)) {
2455 if (S_ISDIR(statbuf.st_mode)) {
2456 Rootmenu *stylesmenu;
2457
2458 if (newmenu)
2459 stylesmenu = new Rootmenu(*this);
2460 else
2461 stylesmenu = menu;
2462
2463 DIR *d = opendir(stylesdir);
2464 int entries = 0;
2465 struct dirent *p;
2466
2467 // get the total number of directory entries
2468 while ((p = readdir(d))) entries++;
2469 rewinddir(d);
2470
2471 char **ls = new char* [entries];
2472 int index = 0;
2473 while ((p = readdir(d)))
2474 ls[index++] = bstrdup(p->d_name);
2475
2476 closedir(d);
2477
2478 std::sort(ls, ls + entries, dcmp());
2479
2480 int n, slen = strlen(stylesdir);
2481 for (n = 0; n < entries; n++) {
2482 if (ls[n][strlen(ls[n])-1] != '~') {
2483 int nlen = strlen(ls[n]);
2484 char style[MAXPATHLEN + 1];
2485
2486 strncpy(style, stylesdir, slen);
2487 *(style + slen) = '/';
2488 strncpy(style + slen + 1, ls[n], nlen + 1);
2489
2490 if ((! stat(style, &statbuf)) && S_ISREG(statbuf.st_mode))
2491 stylesmenu->insert(ls[n], BScreen::SetStyle, style);
2492 }
2493
2494 delete [] ls[n];
2495 }
2496
2497 delete [] ls;
2498
2499 stylesmenu->update();
2500
2501 if (newmenu) {
2502 stylesmenu->setLabel(label);
2503 menu->insert(label, stylesmenu);
2504 rootmenuList->insert(stylesmenu);
2505 }
2506
2507 openbox.saveMenuFilename(stylesdir);
2508 } else {
2509 fprintf(stderr, i18n->getMessage(ScreenSet,
2510 ScreenSTYLESDIRErrorNotDir,
2511 "BScreen::parseMenuFile:"
2512 " [stylesdir/stylesmenu] error, %s is not a"
2513 " directory\n"), stylesdir);
2514 }
2515 } else {
2516 fprintf(stderr,
2517 i18n->getMessage(ScreenSet, ScreenSTYLESDIRErrorNoExist,
2518 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
2519 " error, %s does not exist\n"), stylesdir);
2520 }
2521
2522 break;
2523 }
2524
2525 case 1090: // workspaces
2526 {
2527 if (! *label) {
2528 fprintf(stderr,
2529 i18n->getMessage(ScreenSet, ScreenWORKSPACESError,
2530 "BScreen:parseMenuFile: [workspaces] error, "
2531 "no menu label defined\n"));
2532 continue;
2533 }
2534
2535 menu->insert(label, workspacemenu);
2536
2537 break;
2538 }
2539 }
2540 }
2541 }
2542 }
2543
2544 return ((menu->getCount() == 0) ? True : False);
2545 }
2546
2547
2548 void BScreen::shutdown(void) {
2549 openbox.grab();
2550
2551 XSelectInput(getBaseDisplay().getXDisplay(), getRootWindow(), NoEventMask);
2552 XSync(getBaseDisplay().getXDisplay(), False);
2553
2554 LinkedListIterator<Workspace> it(workspacesList);
2555 for (Workspace *w = it.current(); w; it++, w = it.current())
2556 w->shutdown();
2557
2558 while (iconList->count()) {
2559 iconList->first()->restore();
2560 delete iconList->first();
2561 }
2562
2563 #ifdef SLIT
2564 slit->shutdown();
2565 #endif // SLIT
2566
2567 openbox.ungrab();
2568 }
2569
2570
2571 void BScreen::showPosition(int x, int y) {
2572 if (! geom_visible) {
2573 XMoveResizeWindow(getBaseDisplay().getXDisplay(), geom_window,
2574 (size().w() - geom_w) / 2,
2575 (size().h() - geom_h) / 2, geom_w, geom_h);
2576 XMapWindow(getBaseDisplay().getXDisplay(), geom_window);
2577 XRaiseWindow(getBaseDisplay().getXDisplay(), geom_window);
2578
2579 geom_visible = True;
2580 }
2581
2582 char label[1024];
2583
2584 sprintf(label, i18n->getMessage(ScreenSet, ScreenPositionFormat,
2585 "X: %4d x Y: %4d"), x, y);
2586
2587 XClearWindow(getBaseDisplay().getXDisplay(), geom_window);
2588
2589 if (i18n->multibyte()) {
2590 XmbDrawString(getBaseDisplay().getXDisplay(), geom_window,
2591 resource.wstyle.fontset, resource.wstyle.l_text_focus_gc,
2592 resource.bevel_width, resource.bevel_width -
2593 resource.wstyle.fontset_extents->max_ink_extent.y,
2594 label, strlen(label));
2595 } else {
2596 XDrawString(getBaseDisplay().getXDisplay(), geom_window,
2597 resource.wstyle.l_text_focus_gc,
2598 resource.bevel_width,
2599 resource.wstyle.font->ascent +
2600 resource.bevel_width, label, strlen(label));
2601 }
2602 }
2603
2604
2605 void BScreen::showGeometry(unsigned int gx, unsigned int gy) {
2606 if (! geom_visible) {
2607 XMoveResizeWindow(getBaseDisplay().getXDisplay(), geom_window,
2608 (size().w() - geom_w) / 2,
2609 (size().h() - geom_h) / 2, geom_w, geom_h);
2610 XMapWindow(getBaseDisplay().getXDisplay(), geom_window);
2611 XRaiseWindow(getBaseDisplay().getXDisplay(), geom_window);
2612
2613 geom_visible = True;
2614 }
2615
2616 char label[1024];
2617
2618 sprintf(label, i18n->getMessage(ScreenSet, ScreenGeometryFormat,
2619 "W: %4d x H: %4d"), gx, gy);
2620
2621 XClearWindow(getBaseDisplay().getXDisplay(), geom_window);
2622
2623 if (i18n->multibyte()) {
2624 XmbDrawString(getBaseDisplay().getXDisplay(), geom_window,
2625 resource.wstyle.fontset, resource.wstyle.l_text_focus_gc,
2626 resource.bevel_width, resource.bevel_width -
2627 resource.wstyle.fontset_extents->max_ink_extent.y,
2628 label, strlen(label));
2629 } else {
2630 XDrawString(getBaseDisplay().getXDisplay(), geom_window,
2631 resource.wstyle.l_text_focus_gc,
2632 resource.bevel_width,
2633 resource.wstyle.font->ascent +
2634 resource.bevel_width, label, strlen(label));
2635 }
2636 }
2637
2638 void BScreen::hideGeometry(void) {
2639 if (geom_visible) {
2640 XUnmapWindow(getBaseDisplay().getXDisplay(), geom_window);
2641 geom_visible = False;
2642 }
2643 }
This page took 0.170326 seconds and 4 git commands to generate.