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