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