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