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