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