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