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