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