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