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