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)
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:
12 // The above copyright notice and this permission notice shall be included in
13 // all copies or substantial portions of the Software.
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.
23 // stupid macros needed to access some functions in version 2 of the GNU C
30 # include "../config.h"
31 #endif // HAVE_CONFIG_H
33 #include <X11/Xatom.h>
34 #include <X11/keysym.h>
38 #include "Clientmenu.h"
50 #include "Workspace.h"
51 #include "Workspacemenu.h"
55 #endif // HAVE_STDLIB_H
59 #endif // HAVE_STRING_H
61 #ifdef HAVE_SYS_TYPES_H
62 # include <sys/types.h>
63 #endif // HAVE_SYS_TYPES_H
67 #endif // HAVE_CTYPE_H
71 #endif // HAVE_DIRENT_H
75 #endif // HAVE_LOCALE_H
78 # include <sys/types.h>
80 #endif // HAVE_UNISTD_H
82 #ifdef HAVE_SYS_STAT_H
83 # include <sys/stat.h>
84 #endif // HAVE_SYS_STAT_H
88 #endif // HAVE_STDARG_H
91 # include "bsd-snprintf.h"
92 #endif // !HAVE_SNPRINTF
95 #define MAXPATHLEN 255
98 #ifndef FONT_ELEMENT_SIZE
99 #define FONT_ELEMENT_SIZE 50
100 #endif // FONT_ELEMENT_SIZE
104 #endif // HAVE_SSTREAM
108 static Bool running = True;
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));
122 bool operator()(const char *one, const char *two) const {
123 return (strcmp(one, two) < 0) ? True : False;
127 #ifndef HAVE_STRCASESTR
128 static const char * strcasestr(const char *str, const char *ptn) {
130 for( ; *str; str++) {
131 for(s2=str,p2=ptn; ; s2++,p2++) {
132 if (!*p2) return str;
133 if (toupper(*s2) != toupper(*p2)) break;
138 #endif // HAVE_STRCASESTR
140 static const char *getFontElement(const char *pattern, char *buf, int bufsiz, ...) {
145 va_start(va, bufsiz);
148 while((v = va_arg(va, char *)) != NULL) {
149 p = strcasestr(pattern, v);
151 strncpy(buf, p+1, bufsiz-2);
152 p2 = strchr(buf, '-');
159 strncpy(buf, "*", bufsiz);
163 static const char *getFontSize(const char *pattern, int *size) {
168 for (p=pattern; 1; p++) {
170 if (p2!=NULL && n>1 && n<72) {
171 *size = n; return p2+1;
173 *size = 16; return NULL;
175 } else if (*p=='-') {
176 if (n>1 && n<72 && p2!=NULL) {
181 } else if (*p>='0' && *p<='9' && p2!=NULL) {
191 BScreen::BScreen(Openbox &ob, int scrn, Resource &conf) : ScreenInfo(ob, scrn),
192 openbox(ob), config(conf)
194 event_mask = ColormapChangeMask | EnterWindowMask | PropertyChangeMask |
195 SubstructureRedirectMask | KeyPressMask | KeyReleaseMask |
196 ButtonPressMask | ButtonReleaseMask;
198 XErrorHandler old = XSetErrorHandler((XErrorHandler) anotherWMRunning);
199 XSelectInput(getBaseDisplay().getXDisplay(), getRootWindow(), event_mask);
200 XSync(getBaseDisplay().getXDisplay(), False);
201 XSetErrorHandler((XErrorHandler) old);
204 if (! managed) return;
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()),
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;
225 pid_t bpid = getpid();
227 XChangeProperty(getBaseDisplay().getXDisplay(), getRootWindow(),
228 openbox.getOpenboxPidAtom(), XA_CARDINAL,
229 sizeof(pid_t) * 8, PropModeReplace,
230 (unsigned char *) &bpid, 1);
231 #endif // HAVE_GETPID
233 XDefineCursor(getBaseDisplay().getXDisplay(), getRootWindow(),
234 openbox.getSessionCursor());
236 workspaceNames = new LinkedList<char>;
237 workspacesList = new LinkedList<Workspace>;
238 rootmenuList = new LinkedList<Rootmenu>;
239 netizenList = new LinkedList<Netizen>;
240 iconList = new LinkedList<OpenboxWindow>;
243 new BImageControl(openbox, *this, True, openbox.getColorsPerChannel(),
244 openbox.getCacheLife(), openbox.getCacheMax());
245 image_control->installRootColormap();
246 root_colormap_installed = True;
248 image_control->setDither(resource.image_dither);
250 load(); // load config options from Resources
254 unsigned long gc_value_mask = GCForeground;
255 if (! i18n->multibyte()) gc_value_mask |= GCFont;
257 gcv.foreground = WhitePixel(getBaseDisplay().getXDisplay(),
259 ^ BlackPixel(getBaseDisplay().getXDisplay(),
261 gcv.function = GXxor;
262 gcv.subwindow_mode = IncludeInferiors;
263 opGC = XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
264 GCForeground | GCFunction | GCSubwindowMode, &gcv);
266 gcv.foreground = resource.wstyle.l_text_focus.getPixel();
267 if (resource.wstyle.font)
268 gcv.font = resource.wstyle.font->fid;
269 resource.wstyle.l_text_focus_gc =
270 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
271 gc_value_mask, &gcv);
273 gcv.foreground = resource.wstyle.l_text_unfocus.getPixel();
274 if (resource.wstyle.font)
275 gcv.font = resource.wstyle.font->fid;
276 resource.wstyle.l_text_unfocus_gc =
277 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
278 gc_value_mask, &gcv);
280 gcv.foreground = resource.wstyle.b_pic_focus.getPixel();
281 resource.wstyle.b_pic_focus_gc =
282 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
285 gcv.foreground = resource.wstyle.b_pic_unfocus.getPixel();
286 resource.wstyle.b_pic_unfocus_gc =
287 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
290 gcv.foreground = resource.mstyle.t_text.getPixel();
291 if (resource.mstyle.t_font)
292 gcv.font = resource.mstyle.t_font->fid;
293 resource.mstyle.t_text_gc =
294 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
295 gc_value_mask, &gcv);
297 gcv.foreground = resource.mstyle.f_text.getPixel();
298 if (resource.mstyle.f_font)
299 gcv.font = resource.mstyle.f_font->fid;
300 resource.mstyle.f_text_gc =
301 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
302 gc_value_mask, &gcv);
304 gcv.foreground = resource.mstyle.h_text.getPixel();
305 resource.mstyle.h_text_gc =
306 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
307 gc_value_mask, &gcv);
309 gcv.foreground = resource.mstyle.d_text.getPixel();
310 resource.mstyle.d_text_gc =
311 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
312 gc_value_mask, &gcv);
314 gcv.foreground = resource.mstyle.hilite.getColor()->getPixel();
315 resource.mstyle.hilite_gc =
316 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
317 gc_value_mask, &gcv);
319 gcv.foreground = resource.tstyle.l_text.getPixel();
320 if (resource.tstyle.font)
321 gcv.font = resource.tstyle.font->fid;
322 resource.tstyle.l_text_gc =
323 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
324 gc_value_mask, &gcv);
326 gcv.foreground = resource.tstyle.w_text.getPixel();
327 resource.tstyle.w_text_gc =
328 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
329 gc_value_mask, &gcv);
331 gcv.foreground = resource.tstyle.c_text.getPixel();
332 resource.tstyle.c_text_gc =
333 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
334 gc_value_mask, &gcv);
336 gcv.foreground = resource.tstyle.b_pic.getPixel();
337 resource.tstyle.b_pic_gc =
338 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
339 gc_value_mask, &gcv);
341 const char *s = i18n->getMessage(ScreenSet, ScreenPositionLength,
342 "0: 0000 x 0: 0000");
345 if (i18n->multibyte()) {
346 XRectangle ink, logical;
347 XmbTextExtents(resource.wstyle.fontset, s, l, &ink, &logical);
348 geom_w = logical.width;
350 geom_h = resource.wstyle.fontset_extents->max_ink_extent.height;
352 geom_h = resource.wstyle.font->ascent +
353 resource.wstyle.font->descent;
355 geom_w = XTextWidth(resource.wstyle.font, s, l);
358 geom_w += (resource.bevel_width * 2);
359 geom_h += (resource.bevel_width * 2);
361 XSetWindowAttributes attrib;
362 unsigned long mask = CWBorderPixel | CWColormap | CWSaveUnder;
363 attrib.border_pixel = getBorderColor()->getPixel();
364 attrib.colormap = getColormap();
365 attrib.save_under = True;
368 XCreateWindow(getBaseDisplay().getXDisplay(), getRootWindow(),
369 0, 0, geom_w, geom_h, resource.border_width, getDepth(),
370 InputOutput, getVisual(), mask, &attrib);
371 geom_visible = False;
373 if (resource.wstyle.l_focus.getTexture() & BImage_ParentRelative) {
374 if (resource.wstyle.t_focus.getTexture() ==
375 (BImage_Flat | BImage_Solid)) {
377 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window,
378 resource.wstyle.t_focus.getColor()->getPixel());
380 geom_pixmap = image_control->renderImage(geom_w, geom_h,
381 &resource.wstyle.t_focus);
382 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
383 geom_window, geom_pixmap);
386 if (resource.wstyle.l_focus.getTexture() ==
387 (BImage_Flat | BImage_Solid)) {
389 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window,
390 resource.wstyle.l_focus.getColor()->getPixel());
392 geom_pixmap = image_control->renderImage(geom_w, geom_h,
393 &resource.wstyle.l_focus);
394 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
395 geom_window, geom_pixmap);
399 workspacemenu = new Workspacemenu(*this);
400 iconmenu = new Iconmenu(*this);
401 configmenu = new Configmenu(*this);
403 Workspace *wkspc = NULL;
404 if (resource.workspaces != 0) {
405 for (int i = 0; i < resource.workspaces; ++i) {
406 wkspc = new Workspace(*this, workspacesList->count());
407 workspacesList->insert(wkspc);
408 saveWorkspaceNames();
409 workspacemenu->insert(wkspc->getName(), wkspc->getMenu());
412 wkspc = new Workspace(*this, workspacesList->count());
413 workspacesList->insert(wkspc);
414 saveWorkspaceNames();
415 workspacemenu->insert(wkspc->getName(), wkspc->getMenu());
418 workspacemenu->insert(i18n->getMessage(IconSet, IconIcons, "Icons"),
420 workspacemenu->update();
422 current_workspace = workspacesList->first();
423 workspacemenu->setItemSelected(2, True);
425 toolbar = new Toolbar(*this, config);
428 slit = new Slit(*this, config);
436 changeWorkspaceID(0);
440 Window r, p, *children;
441 XQueryTree(getBaseDisplay().getXDisplay(), getRootWindow(), &r, &p,
444 // preen the window list of all icon windows... for better dockapp support
445 for (i = 0; i < (int) nchild; i++) {
446 if (children[i] == None) continue;
448 XWMHints *wmhints = XGetWMHints(getBaseDisplay().getXDisplay(),
452 if ((wmhints->flags & IconWindowHint) &&
453 (wmhints->icon_window != children[i]))
454 for (int j = 0; j < (int) nchild; j++)
455 if (children[j] == wmhints->icon_window) {
465 // manage shown windows
466 for (i = 0; i < (int) nchild; ++i) {
467 if (children[i] == None || (! openbox.validateWindow(children[i])))
470 XWindowAttributes attrib;
471 if (XGetWindowAttributes(getBaseDisplay().getXDisplay(), children[i],
473 if (attrib.override_redirect) continue;
475 if (attrib.map_state != IsUnmapped) {
476 new OpenboxWindow(openbox, children[i], this);
478 OpenboxWindow *win = openbox.searchWindow(children[i]);
480 XMapRequestEvent mre;
481 mre.window = children[i];
482 win->restoreAttributes();
483 win->mapRequestEvent(&mre);
489 if (! resource.sloppy_focus)
490 XSetInputFocus(getBaseDisplay().getXDisplay(), toolbar->getWindowID(),
491 RevertToParent, CurrentTime);
494 XFlush(getBaseDisplay().getXDisplay());
498 BScreen::~BScreen(void) {
499 if (! managed) return;
501 if (geom_pixmap != None)
502 image_control->removeImage(geom_pixmap);
504 if (geom_window != None)
505 XDestroyWindow(getBaseDisplay().getXDisplay(), geom_window);
507 removeWorkspaceNames();
509 while (workspacesList->count())
510 delete workspacesList->remove(0);
512 while (rootmenuList->count())
513 rootmenuList->remove(0);
515 while (iconList->count())
516 delete iconList->remove(0);
518 while (netizenList->count())
519 delete netizenList->remove(0);
522 if (resource.strftime_format)
523 delete [] resource.strftime_format;
524 #endif // HAVE_STRFTIME
527 delete workspacemenu;
536 delete image_control;
538 delete workspacesList;
539 delete workspaceNames;
544 if (resource.wstyle.fontset)
545 XFreeFontSet(getBaseDisplay().getXDisplay(), resource.wstyle.fontset);
546 if (resource.mstyle.t_fontset)
547 XFreeFontSet(getBaseDisplay().getXDisplay(), resource.mstyle.t_fontset);
548 if (resource.mstyle.f_fontset)
549 XFreeFontSet(getBaseDisplay().getXDisplay(), resource.mstyle.f_fontset);
550 if (resource.tstyle.fontset)
551 XFreeFontSet(getBaseDisplay().getXDisplay(), resource.tstyle.fontset);
553 if (resource.wstyle.font)
554 XFreeFont(getBaseDisplay().getXDisplay(), resource.wstyle.font);
555 if (resource.mstyle.t_font)
556 XFreeFont(getBaseDisplay().getXDisplay(), resource.mstyle.t_font);
557 if (resource.mstyle.f_font)
558 XFreeFont(getBaseDisplay().getXDisplay(), resource.mstyle.f_font);
559 if (resource.tstyle.font)
560 XFreeFont(getBaseDisplay().getXDisplay(), resource.tstyle.font);
561 if (resource.root_command != NULL)
562 delete [] resource.root_command;
564 XFreeGC(getBaseDisplay().getXDisplay(), opGC);
566 XFreeGC(getBaseDisplay().getXDisplay(),
567 resource.wstyle.l_text_focus_gc);
568 XFreeGC(getBaseDisplay().getXDisplay(),
569 resource.wstyle.l_text_unfocus_gc);
570 XFreeGC(getBaseDisplay().getXDisplay(),
571 resource.wstyle.b_pic_focus_gc);
572 XFreeGC(getBaseDisplay().getXDisplay(),
573 resource.wstyle.b_pic_unfocus_gc);
575 XFreeGC(getBaseDisplay().getXDisplay(),
576 resource.mstyle.t_text_gc);
577 XFreeGC(getBaseDisplay().getXDisplay(),
578 resource.mstyle.f_text_gc);
579 XFreeGC(getBaseDisplay().getXDisplay(),
580 resource.mstyle.h_text_gc);
581 XFreeGC(getBaseDisplay().getXDisplay(),
582 resource.mstyle.d_text_gc);
583 XFreeGC(getBaseDisplay().getXDisplay(),
584 resource.mstyle.hilite_gc);
586 XFreeGC(getBaseDisplay().getXDisplay(),
587 resource.tstyle.l_text_gc);
588 XFreeGC(getBaseDisplay().getXDisplay(),
589 resource.tstyle.w_text_gc);
590 XFreeGC(getBaseDisplay().getXDisplay(),
591 resource.tstyle.c_text_gc);
592 XFreeGC(getBaseDisplay().getXDisplay(),
593 resource.tstyle.b_pic_gc);
596 void BScreen::readDatabaseTexture(const char *rname, const char *rclass,
598 unsigned long default_pixel)
602 if (resource.styleconfig.getValue(rname, rclass, s))
603 image_control->parseTexture(texture, s.c_str());
605 texture->setTexture(BImage_Solid | BImage_Flat);
607 if (texture->getTexture() & BImage_Solid) {
608 int clen = strlen(rclass) + 32, nlen = strlen(rname) + 32;
610 char *colorclass = new char[clen], *colorname = new char[nlen];
612 sprintf(colorclass, "%s.Color", rclass);
613 sprintf(colorname, "%s.color", rname);
615 readDatabaseColor(colorname, colorclass, texture->getColor(),
619 sprintf(colorclass, "%s.ColorTo", rclass);
620 sprintf(colorname, "%s.colorTo", rname);
622 readDatabaseColor(colorname, colorclass, texture->getColorTo(),
626 delete [] colorclass;
629 if ((! texture->getColor()->isAllocated()) ||
630 (texture->getTexture() & BImage_Flat))
635 xcol.red = (unsigned int) (texture->getColor()->getRed() +
636 (texture->getColor()->getRed() >> 1));
637 if (xcol.red >= 0xff) xcol.red = 0xffff;
638 else xcol.red *= 0xff;
639 xcol.green = (unsigned int) (texture->getColor()->getGreen() +
640 (texture->getColor()->getGreen() >> 1));
641 if (xcol.green >= 0xff) xcol.green = 0xffff;
642 else xcol.green *= 0xff;
643 xcol.blue = (unsigned int) (texture->getColor()->getBlue() +
644 (texture->getColor()->getBlue() >> 1));
645 if (xcol.blue >= 0xff) xcol.blue = 0xffff;
646 else xcol.blue *= 0xff;
648 if (! XAllocColor(getBaseDisplay().getXDisplay(),
649 getColormap(), &xcol))
652 texture->getHiColor()->setPixel(xcol.pixel);
655 (unsigned int) ((texture->getColor()->getRed() >> 2) +
656 (texture->getColor()->getRed() >> 1)) * 0xff;
658 (unsigned int) ((texture->getColor()->getGreen() >> 2) +
659 (texture->getColor()->getGreen() >> 1)) * 0xff;
661 (unsigned int) ((texture->getColor()->getBlue() >> 2) +
662 (texture->getColor()->getBlue() >> 1)) * 0xff;
664 if (! XAllocColor(getBaseDisplay().getXDisplay(),
665 getColormap(), &xcol))
668 texture->getLoColor()->setPixel(xcol.pixel);
669 } else if (texture->getTexture() & BImage_Gradient) {
670 int clen = strlen(rclass) + 10, nlen = strlen(rname) + 10;
672 char *colorclass = new char[clen], *colorname = new char[nlen],
673 *colortoclass = new char[clen], *colortoname = new char[nlen];
675 sprintf(colorclass, "%s.Color", rclass);
676 sprintf(colorname, "%s.color", rname);
678 sprintf(colortoclass, "%s.ColorTo", rclass);
679 sprintf(colortoname, "%s.colorTo", rname);
681 readDatabaseColor(colorname, colorclass, texture->getColor(),
683 readDatabaseColor(colortoname, colortoclass, texture->getColorTo(),
686 delete [] colorclass;
688 delete [] colortoclass;
689 delete [] colortoname;
694 void BScreen::readDatabaseColor(const char *rname, const char *rclass,
695 BColor *color, unsigned long default_pixel)
699 if (resource.styleconfig.getValue(rname, rclass, s))
700 image_control->parseColor(color, s.c_str());
702 // parsing with no color string just deallocates the color, if it has
703 // been previously allocated
704 image_control->parseColor(color);
705 color->setPixel(default_pixel);
710 void BScreen::readDatabaseFontSet(const char *rname, const char *rclass,
712 if (! fontset) return;
714 static char *defaultFont = "fixed";
715 bool load_default = false;
719 XFreeFontSet(getBaseDisplay().getXDisplay(), *fontset);
721 if (resource.styleconfig.getValue(rname, rclass, s)) {
722 if (! (*fontset = createFontSet(s.c_str())))
728 *fontset = createFontSet(defaultFont);
731 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenDefaultFontLoadFail,
732 "BScreen::LoadStyle(): couldn't load default font.\n"));
739 void BScreen::readDatabaseFont(const char *rname, const char *rclass,
740 XFontStruct **font) {
743 static char *defaultFont = "fixed";
744 bool load_default = false;
748 XFreeFont(getBaseDisplay().getXDisplay(), *font);
750 if (resource.styleconfig.getValue(rname, rclass, s)) {
751 if ((*font = XLoadQueryFont(getBaseDisplay().getXDisplay(),
752 s.c_str())) == NULL) {
753 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenFontLoadFail,
754 "BScreen::LoadStyle(): couldn't load font '%s'\n"),
762 if ((*font = XLoadQueryFont(getBaseDisplay().getXDisplay(),
763 defaultFont)) == NULL) {
764 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenDefaultFontLoadFail,
765 "BScreen::LoadStyle(): couldn't load default font.\n"));
772 XFontSet BScreen::createFontSet(const char *fontname) {
774 char **missing, *def = "-";
775 int nmissing, pixel_size = 0, buf_size = 0;
776 char weight[FONT_ELEMENT_SIZE], slant[FONT_ELEMENT_SIZE];
778 fs = XCreateFontSet(getBaseDisplay().getXDisplay(),
779 fontname, &missing, &nmissing, &def);
780 if (fs && (! nmissing)) return fs;
782 #ifdef HAVE_SETLOCALE
784 if (nmissing) XFreeStringList(missing);
786 setlocale(LC_CTYPE, "C");
787 fs = XCreateFontSet(getBaseDisplay().getXDisplay(), fontname,
788 &missing, &nmissing, &def);
789 setlocale(LC_CTYPE, "");
791 #endif // HAVE_SETLOCALE
794 XFontStruct **fontstructs;
796 XFontsOfFontSet(fs, &fontstructs, &fontnames);
797 fontname = fontnames[0];
800 getFontElement(fontname, weight, FONT_ELEMENT_SIZE,
801 "-medium-", "-bold-", "-demibold-", "-regular-", NULL);
802 getFontElement(fontname, slant, FONT_ELEMENT_SIZE,
803 "-r-", "-i-", "-o-", "-ri-", "-ro-", NULL);
804 getFontSize(fontname, &pixel_size);
806 if (! strcmp(weight, "*")) strncpy(weight, "medium", FONT_ELEMENT_SIZE);
807 if (! strcmp(slant, "*")) strncpy(slant, "r", FONT_ELEMENT_SIZE);
808 if (pixel_size < 3) pixel_size = 3;
809 else if (pixel_size > 97) pixel_size = 97;
811 buf_size = strlen(fontname) + (FONT_ELEMENT_SIZE * 2) + 64;
812 char *pattern2 = new char[buf_size];
813 snprintf(pattern2, buf_size - 1,
815 "-*-*-%s-%s-*-*-%d-*-*-*-*-*-*-*,"
816 "-*-*-*-*-*-*-%d-*-*-*-*-*-*-*,*",
817 fontname, weight, slant, pixel_size, pixel_size);
820 if (nmissing) XFreeStringList(missing);
821 if (fs) XFreeFontSet(getBaseDisplay().getXDisplay(), fs);
823 fs = XCreateFontSet(getBaseDisplay().getXDisplay(), fontname,
824 &missing, &nmissing, &def);
831 void BScreen::setSloppyFocus(bool b) {
832 resource.sloppy_focus = b;
833 std::ostringstream s;
834 s << "session.screen" << getScreenNumber() << ".focusModel";
835 config.setValue(s.str(),
836 (resource.sloppy_focus ?
837 (resource.auto_raise ? "AutoRaiseSloppyFocus" : "SloppyFocus")
842 void BScreen::setAutoRaise(bool a) {
843 resource.auto_raise = a;
844 std::ostringstream s;
845 s << "session.screen" << getScreenNumber() << ".focusModel";
846 config.setValue(s.str(),
847 (resource.sloppy_focus ?
848 (resource.auto_raise ? "AutoRaiseSloppyFocus" : "SloppyFocus")
853 void BScreen::setImageDither(bool d) {
854 resource.image_dither = d;
855 std::ostringstream s;
856 s << "session.screen" << getScreenNumber() << ".imageDither";
857 config.setValue(s.str(), resource.image_dither);
861 void BScreen::setOpaqueMove(bool o) {
862 resource.opaque_move = o;
863 std::ostringstream s;
864 s << "session.screen" << getScreenNumber() << ".opaqueMove";
865 config.setValue(s.str(), resource.opaque_move);
869 void BScreen::setFullMax(bool f) {
870 resource.full_max = f;
871 std::ostringstream s;
872 s << "session.screen" << getScreenNumber() << ".fullMaximization";
873 config.setValue(s.str(), resource.full_max);
875 s.rdbuf()->freeze(0);
876 #endif // HAVE_SSTREAM
880 void BScreen::setFocusNew(bool f) {
881 resource.focus_new = f;
882 std::ostringstream s;
883 s << "session.screen" << getScreenNumber() << ".focusNewWindows";
884 config.setValue(s.str(), resource.focus_new);
888 void BScreen::setFocusLast(bool f) {
889 resource.focus_last = f;
890 std::ostringstream s;
891 s << "session.screen" << getScreenNumber() << ".focusLastWindow";
892 config.setValue(s.str(), resource.focus_last);
896 void BScreen::setWindowZones(int z) {
898 std::ostringstream s;
899 s << "session.screen" << getScreenNumber() << ".windowZones";
900 config.setValue(s.str(), resource.zones);
904 void BScreen::setWorkspaceCount(int w) {
905 resource.workspaces = w;
906 std::ostringstream s;
907 s << "session.screen" << getScreenNumber() << ".workspaces";
908 config.setValue(s.str(), resource.workspaces);
912 void BScreen::setPlacementPolicy(int p) {
913 resource.placement_policy = p;
914 std::ostringstream s;
915 s << "session.screen" << getScreenNumber() << ".windowPlacement";
916 const char *placement;
917 switch (resource.placement_policy) {
918 case CascadePlacement: placement = "CascadePlacement"; break;
919 case BestFitPlacement: placement = "BestFitPlacement"; break;
920 case ColSmartPlacement: placement = "ColSmartPlacement"; break;
922 case RowSmartPlacement: placement = "RowSmartPlacement"; break;
924 config.setValue(s.str(), placement);
928 void BScreen::setEdgeSnapThreshold(int t) {
929 resource.edge_snap_threshold = t;
930 std::ostringstream s;
931 s << "session.screen" << getScreenNumber() << ".edgeSnapThreshold";
932 config.setValue(s.str(), resource.edge_snap_threshold);
936 void BScreen::setRowPlacementDirection(int d) {
937 resource.row_direction = d;
938 std::ostringstream s;
939 s << "session.screen" << getScreenNumber() << ".rowPlacementDirection";
940 config.setValue(s.str(),
941 resource.row_direction == LeftRight ?
942 "LeftToRight" : "RightToLeft");
946 void BScreen::setColPlacementDirection(int d) {
947 resource.col_direction = d;
948 std::ostringstream s;
949 s << "session.screen" << getScreenNumber() << ".colPlacementDirection";
950 config.setValue(s.str(),
951 resource.col_direction == TopBottom ?
952 "TopToBottom" : "BottomToTop");
956 void BScreen::setRootCommand(const char *cmd) {
957 if (resource.root_command != NULL)
958 delete [] resource.root_command;
960 resource.root_command = bstrdup(cmd);
962 resource.root_command = NULL;
963 // this doesn't save to the Resources config because it can't be changed
964 // inside Openbox, and this way we dont add an empty command which would over-
965 // ride the styles command when none has been specified
970 void BScreen::setStrftimeFormat(const char *f) {
971 if (resource.strftime_format != NULL)
972 delete [] resource.strftime_format;
974 resource.strftime_format = bstrdup(f);
975 std::ostringstream s;
976 s << "session.screen" << getScreenNumber() << ".strftimeFormat";
977 config.setValue(s.str(), resource.strftime_format);
980 #else // !HAVE_STRFTIME
981 void BScreen::setDateFormat(int f) {
982 resource.date_format = f;
983 std::ostringstream s;
984 s << "session.screen" << getScreenNumber() << ".dateFormat";
985 config.setValue(s.str(), resource.date_format == B_EuropeanDate ?
986 "European" : "American");
989 void BScreen::setClock24Hour(Bool c) {
990 resource.clock24hour = c;
991 std::ostringstream s;
992 s << "session.screen" << getScreenNumber() << ".clockFormat";
993 config.setValue(s.str(), resource.clock24hour ? 24 : 12);
995 #endif // HAVE_STRFTIME
997 void BScreen::setHideToolbar(bool b) {
998 resource.hide_toolbar = b;
999 if (resource.hide_toolbar)
1000 getToolbar()->unMapToolbar();
1002 getToolbar()->mapToolbar();
1003 std::ostringstream s;
1004 s << "session.screen" << getScreenNumber() << ".hideToolbar";
1005 config.setValue(s.str(), resource.hide_toolbar ? "True" : "False");
1008 void BScreen::saveWorkspaceNames() {
1009 std::ostringstream rc, names;
1011 for (int i = 0; i < resource.workspaces; i++) {
1012 Workspace *w = getWorkspace(i);
1014 names << w->getName();
1015 if (i < resource.workspaces-1)
1021 rc << "session.screen" << getScreenNumber() << ".workspaceNames";
1022 config.setValue(rc.str(), names.str());
1025 void BScreen::save() {
1026 setSloppyFocus(resource.sloppy_focus);
1027 setAutoRaise(resource.auto_raise);
1028 setImageDither(resource.image_dither);
1029 setOpaqueMove(resource.opaque_move);
1030 setFullMax(resource.full_max);
1031 setFocusNew(resource.focus_new);
1032 setFocusLast(resource.focus_last);
1033 setWindowZones(resource.zones);
1034 setWorkspaceCount(resource.workspaces);
1035 setPlacementPolicy(resource.placement_policy);
1036 setEdgeSnapThreshold(resource.edge_snap_threshold);
1037 setRowPlacementDirection(resource.row_direction);
1038 setColPlacementDirection(resource.col_direction);
1039 setRootCommand(resource.root_command);
1040 #ifdef HAVE_STRFTIME
1041 // it deletes the current value before setting the new one, so we have to
1042 // duplicate the current value.
1043 std::string s = resource.strftime_format;
1044 setStrftimeFormat(s.c_str());
1045 #else // !HAVE_STRFTIME
1046 setDateFormat(resource.date_format);
1047 setClock24Hour(resource.clock24hour);
1048 #endif // HAVE_STRFTIME
1049 setHideToolbar(resource.hide_toolbar);
1052 void BScreen::load() {
1053 std::ostringstream rscreen, rname, rclass;
1057 rscreen << "session.screen" << getScreenNumber() << '.';
1059 rname << rscreen.str() << "hideToolbar";
1060 rclass << rscreen.str() << "HideToolbar";
1061 if (config.getValue(rname.str(), rclass.str(), b))
1062 resource.hide_toolbar = b;
1064 resource.hide_toolbar = false;
1065 Toolbar *t = getToolbar();
1067 if (resource.hide_toolbar)
1073 rname.seekp(0); rclass.seekp(0);
1074 rname << rscreen.str() << "fullMaximization";
1075 rclass << rscreen.str() << "FullMaximization";
1076 if (config.getValue(rname.str(), rclass.str(), b))
1077 resource.full_max = b;
1079 resource.full_max = false;
1081 rname.seekp(0); rclass.seekp(0);
1082 rname << rscreen.str() << "focusNewWindows";
1083 rclass << rscreen.str() << "FocusNewWindows";
1084 if (config.getValue(rname.str(), rclass.str(), b))
1085 resource.focus_new = b;
1087 resource.focus_new = false;
1089 rname.seekp(0); rclass.seekp(0);
1090 rname << rscreen.str() << "focusLastWindow";
1091 rclass << rscreen.str() << "FocusLastWindow";
1092 if (config.getValue(rname.str(), rclass.str(), b))
1093 resource.focus_last = b;
1095 resource.focus_last = false;
1097 rname.seekp(0); rclass.seekp(0);
1098 rname << rscreen.str() << "rowPlacementDirection";
1099 rclass << rscreen.str() << "RowPlacementDirection";
1100 if (config.getValue(rname.str(), rclass.str(), s)) {
1101 if (0 == strncasecmp(s.c_str(), "RightToLeft", s.length()))
1102 resource.row_direction = RightLeft;
1103 else if (0 == strncasecmp(s.c_str(), "LeftToRight", s.length()))
1104 resource.row_direction = LeftRight;
1106 resource.row_direction = LeftRight;
1108 rname.seekp(0); rclass.seekp(0);
1109 rname << rscreen.str() << "colPlacementDirection";
1110 rclass << rscreen.str() << "ColPlacementDirection";
1111 if (config.getValue(rname.str(), rclass.str(), s)) {
1112 if (0 == strncasecmp(s.c_str(), "BottomToTop", s.length()))
1113 resource.col_direction = BottomTop;
1114 else if (0 == strncasecmp(s.c_str(), "TopToBottom", s.length()))
1115 resource.col_direction = TopBottom;
1117 resource.col_direction = TopBottom;
1119 rname.seekp(0); rclass.seekp(0);
1120 rname << rscreen.str() << "workspaces";
1121 rclass << rscreen.str() << "Workspaces";
1122 if (config.getValue(rname.str(), rclass.str(), l))
1123 resource.workspaces = l;
1125 resource.workspaces = 1;
1127 removeWorkspaceNames();
1128 rname.seekp(0); rclass.seekp(0);
1129 rname << rscreen.str() << "workspaceNames";
1130 rclass << rscreen.str() << "WorkspaceNames";
1131 if (config.getValue(rname.str(), rclass.str(), s)) {
1132 std::string::const_iterator it = s.begin(), end = s.end();
1134 std::string::const_iterator tmp = it;// current string.begin()
1135 it = std::find(tmp, end, ','); // look for comma between tmp and end
1136 std::string name(tmp, it); // name = s[tmp:it]
1137 addWorkspaceName(name.c_str());
1144 rname.seekp(0); rclass.seekp(0);
1145 rname << rscreen.str() << "focusModel";
1146 rclass << rscreen.str() << "FocusModel";
1147 if (config.getValue(rname.str(), rclass.str(), s)) {
1148 if (0 == strncasecmp(s.c_str(), "ClickToFocus", s.length())) {
1149 resource.auto_raise = false;
1150 resource.sloppy_focus = false;
1151 } else if (0 == strncasecmp(s.c_str(), "AutoRaiseSloppyFocus",
1153 resource.sloppy_focus = true;
1154 resource.auto_raise = true;
1155 } else if (0 == strncasecmp(s.c_str(), "SloppyFocus", s.length())) {
1156 resource.sloppy_focus = true;
1157 resource.auto_raise = false;
1160 resource.sloppy_focus = true;
1161 resource.auto_raise = false;
1164 rname.seekp(0); rclass.seekp(0);
1165 rname << rscreen.str() << "windowZones";
1166 rclass << rscreen.str() << "WindowZones";
1167 if (config.getValue(rname.str(), rclass.str(), l))
1168 resource.zones = (l == 1 || l == 2 || l == 4) ? l : 1;
1172 rname.seekp(0); rclass.seekp(0);
1173 rname << rscreen.str() << "windowPlacement";
1174 rclass << rscreen.str() << "WindowPlacement";
1175 if (config.getValue(rname.str(), rclass.str(), s)) {
1176 if (0 == strncasecmp(s.c_str(), "RowSmartPlacement", s.length()))
1177 resource.placement_policy = RowSmartPlacement;
1178 else if (0 == strncasecmp(s.c_str(), "ColSmartPlacement", s.length()))
1179 resource.placement_policy = ColSmartPlacement;
1180 else if (0 == strncasecmp(s.c_str(), "BestFitPlacement", s.length()))
1181 resource.placement_policy = BestFitPlacement;
1182 else if (0 == strncasecmp(s.c_str(), "CascadePlacement", s.length()))
1183 resource.placement_policy = CascadePlacement;
1185 resource.placement_policy = CascadePlacement;
1187 #ifdef HAVE_STRFTIME
1188 rname.seekp(0); rclass.seekp(0);
1189 rname << rscreen.str() << "strftimeFormat";
1190 rclass << rscreen.str() << "StrftimeFormat";
1192 if (resource.strftime_format != NULL)
1193 delete [] resource.strftime_format;
1195 if (config.getValue(rname.str(), rclass.str(), s))
1196 resource.strftime_format = bstrdup(s.c_str());
1198 resource.strftime_format = bstrdup("%I:%M %p");
1199 #else // !HAVE_STRFTIME
1200 rname.seekp(0); rclass.seekp(0);
1201 rname << rscreen.str() << "dateFormat";
1202 rclass << rscreen.str() << "DateFormat";
1203 if (config.getValue(rname.str(), rclass.str(), s)) {
1204 if (strncasecmp(s.c_str(), "European", s.length()))
1205 resource.date_format = B_EuropeanDate;
1206 else if (strncasecmp(s.c_str(), "American", s.length()))
1207 resource.date_format = B_AmericanDate;
1209 resource.date_format = B_AmericanDate;
1211 rname.seekp(0); rclass.seekp(0);
1212 rname << rscreen.str() << "clockFormat";
1213 rclass << rscreen.str() << "ClockFormat";
1214 if (config.getValue(rname.str(), rclass.str(), l)) {
1216 resource.clock24hour = true;
1217 else if (clock == 12)
1218 resource.clock24hour = false;
1220 resource.clock24hour = false;
1221 #endif // HAVE_STRFTIME
1223 rname.seekp(0); rclass.seekp(0);
1224 rname << rscreen.str() << "edgeSnapThreshold";
1225 rclass << rscreen.str() << "EdgeSnapThreshold";
1226 if (config.getValue(rname.str(), rclass.str(), l))
1227 resource.edge_snap_threshold = l;
1229 resource.edge_snap_threshold = 4;
1231 rname.seekp(0); rclass.seekp(0);
1232 rname << rscreen.str() << "imageDither";
1233 rclass << rscreen.str() << "ImageDither";
1234 if (config.getValue(rname.str(), rclass.str(), b))
1235 resource.image_dither = b;
1237 resource.image_dither = true;
1239 rname.seekp(0); rclass.seekp(0);
1240 rname << rscreen.str() << "rootCommand";
1241 rclass << rscreen.str() << "RootCommand";
1243 if (resource.root_command != NULL)
1244 delete [] resource.root_command;
1246 if (config.getValue(rname.str(), rclass.str(), s))
1247 resource.root_command = bstrdup(s.c_str());
1249 resource.root_command = NULL;
1251 rname.seekp(0); rclass.seekp(0);
1252 rname << rscreen.str() << "opaqueMove";
1253 rclass << rscreen.str() << "OpaqueMove";
1254 if (config.getValue(rname.str(), rclass.str(), b))
1255 resource.opaque_move = b;
1257 resource.opaque_move = false;
1260 void BScreen::reconfigure(void) {
1269 unsigned long gc_value_mask = GCForeground;
1270 if (! i18n->multibyte()) gc_value_mask |= GCFont;
1272 gcv.foreground = WhitePixel(getBaseDisplay().getXDisplay(),
1274 gcv.function = GXinvert;
1275 gcv.subwindow_mode = IncludeInferiors;
1276 XChangeGC(getBaseDisplay().getXDisplay(), opGC,
1277 GCForeground | GCFunction | GCSubwindowMode, &gcv);
1279 gcv.foreground = resource.wstyle.l_text_focus.getPixel();
1280 if (resource.wstyle.font)
1281 gcv.font = resource.wstyle.font->fid;
1282 XChangeGC(getBaseDisplay().getXDisplay(), resource.wstyle.l_text_focus_gc,
1283 gc_value_mask, &gcv);
1285 gcv.foreground = resource.wstyle.l_text_unfocus.getPixel();
1286 XChangeGC(getBaseDisplay().getXDisplay(), resource.wstyle.l_text_unfocus_gc,
1287 gc_value_mask, &gcv);
1289 gcv.foreground = resource.wstyle.b_pic_focus.getPixel();
1290 XChangeGC(getBaseDisplay().getXDisplay(), resource.wstyle.b_pic_focus_gc,
1291 GCForeground, &gcv);
1293 gcv.foreground = resource.wstyle.b_pic_unfocus.getPixel();
1294 XChangeGC(getBaseDisplay().getXDisplay(), resource.wstyle.b_pic_unfocus_gc,
1295 GCForeground, &gcv);
1297 gcv.foreground = resource.mstyle.t_text.getPixel();
1298 if (resource.mstyle.t_font)
1299 gcv.font = resource.mstyle.t_font->fid;
1300 XChangeGC(getBaseDisplay().getXDisplay(), resource.mstyle.t_text_gc,
1301 gc_value_mask, &gcv);
1303 gcv.foreground = resource.mstyle.f_text.getPixel();
1304 if (resource.mstyle.f_font)
1305 gcv.font = resource.mstyle.f_font->fid;
1306 XChangeGC(getBaseDisplay().getXDisplay(), resource.mstyle.f_text_gc,
1307 gc_value_mask, &gcv);
1309 gcv.foreground = resource.mstyle.h_text.getPixel();
1310 XChangeGC(getBaseDisplay().getXDisplay(), resource.mstyle.h_text_gc,
1311 gc_value_mask, &gcv);
1313 gcv.foreground = resource.mstyle.d_text.getPixel();
1314 XChangeGC(getBaseDisplay().getXDisplay(), resource.mstyle.d_text_gc,
1315 gc_value_mask, &gcv);
1317 gcv.foreground = resource.mstyle.hilite.getColor()->getPixel();
1318 XChangeGC(getBaseDisplay().getXDisplay(), resource.mstyle.hilite_gc,
1319 gc_value_mask, &gcv);
1321 gcv.foreground = resource.tstyle.l_text.getPixel();
1322 if (resource.tstyle.font)
1323 gcv.font = resource.tstyle.font->fid;
1324 XChangeGC(getBaseDisplay().getXDisplay(), resource.tstyle.l_text_gc,
1325 gc_value_mask, &gcv);
1327 gcv.foreground = resource.tstyle.w_text.getPixel();
1328 XChangeGC(getBaseDisplay().getXDisplay(), resource.tstyle.w_text_gc,
1329 gc_value_mask, &gcv);
1331 gcv.foreground = resource.tstyle.c_text.getPixel();
1332 XChangeGC(getBaseDisplay().getXDisplay(), resource.tstyle.c_text_gc,
1333 gc_value_mask, &gcv);
1335 gcv.foreground = resource.tstyle.b_pic.getPixel();
1336 XChangeGC(getBaseDisplay().getXDisplay(), resource.tstyle.b_pic_gc,
1337 gc_value_mask, &gcv);
1339 const char *s = i18n->getMessage(ScreenSet, ScreenPositionLength,
1340 "0: 0000 x 0: 0000");
1343 if (i18n->multibyte()) {
1344 XRectangle ink, logical;
1345 XmbTextExtents(resource.wstyle.fontset, s, l, &ink, &logical);
1346 geom_w = logical.width;
1348 geom_h = resource.wstyle.fontset_extents->max_ink_extent.height;
1350 geom_w = XTextWidth(resource.wstyle.font, s, l);
1352 geom_h = resource.wstyle.font->ascent +
1353 resource.wstyle.font->descent;
1356 geom_w += (resource.bevel_width * 2);
1357 geom_h += (resource.bevel_width * 2);
1359 Pixmap tmp = geom_pixmap;
1360 if (resource.wstyle.l_focus.getTexture() & BImage_ParentRelative) {
1361 if (resource.wstyle.t_focus.getTexture() ==
1362 (BImage_Flat | BImage_Solid)) {
1364 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window,
1365 resource.wstyle.t_focus.getColor()->getPixel());
1367 geom_pixmap = image_control->renderImage(geom_w, geom_h,
1368 &resource.wstyle.t_focus);
1369 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
1370 geom_window, geom_pixmap);
1373 if (resource.wstyle.l_focus.getTexture() ==
1374 (BImage_Flat | BImage_Solid)) {
1376 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window,
1377 resource.wstyle.l_focus.getColor()->getPixel());
1379 geom_pixmap = image_control->renderImage(geom_w, geom_h,
1380 &resource.wstyle.l_focus);
1381 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
1382 geom_window, geom_pixmap);
1385 if (tmp) image_control->removeImage(tmp);
1387 XSetWindowBorderWidth(getBaseDisplay().getXDisplay(), geom_window,
1388 resource.border_width);
1389 XSetWindowBorder(getBaseDisplay().getXDisplay(), geom_window,
1390 resource.border_color.getPixel());
1392 workspacemenu->reconfigure();
1393 iconmenu->reconfigure();
1396 int remember_sub = rootmenu->getCurrentSubmenu();
1399 rootmenu->reconfigure();
1400 rootmenu->drawSubmenu(remember_sub);
1403 configmenu->reconfigure();
1405 toolbar->reconfigure();
1408 slit->reconfigure();
1411 LinkedListIterator<Workspace> wit(workspacesList);
1412 for (Workspace *w = wit.current(); w; wit++, w = wit.current())
1415 LinkedListIterator<OpenboxWindow> iit(iconList);
1416 for (OpenboxWindow *bw = iit.current(); bw; iit++, bw = iit.current())
1417 if (bw->validateClient())
1420 image_control->timeout();
1424 void BScreen::rereadMenu(void) {
1428 rootmenu->reconfigure();
1432 void BScreen::removeWorkspaceNames(void) {
1433 while (workspaceNames->count())
1434 delete [] workspaceNames->remove(0);
1438 void BScreen::LoadStyle(void) {
1439 Resource &conf = resource.styleconfig;
1441 const char *sfile = openbox.getStyleFilename();
1442 bool loaded = false;
1443 if (sfile != NULL) {
1444 conf.setFile(sfile);
1445 loaded = conf.load();
1448 conf.setFile(DEFAULTSTYLE);
1450 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenDefaultStyleLoadFail,
1451 "BScreen::LoadStyle(): couldn't load "
1452 "default style.\n"));
1460 // load fonts/fontsets
1462 if (i18n->multibyte()) {
1463 readDatabaseFontSet("window.font", "Window.Font",
1464 &resource.wstyle.fontset);
1465 readDatabaseFontSet("toolbar.font", "Toolbar.Font",
1466 &resource.tstyle.fontset);
1467 readDatabaseFontSet("menu.title.font", "Menu.Title.Font",
1468 &resource.mstyle.t_fontset);
1469 readDatabaseFontSet("menu.frame.font", "Menu.Frame.Font",
1470 &resource.mstyle.f_fontset);
1472 resource.mstyle.t_fontset_extents =
1473 XExtentsOfFontSet(resource.mstyle.t_fontset);
1474 resource.mstyle.f_fontset_extents =
1475 XExtentsOfFontSet(resource.mstyle.f_fontset);
1476 resource.tstyle.fontset_extents =
1477 XExtentsOfFontSet(resource.tstyle.fontset);
1478 resource.wstyle.fontset_extents =
1479 XExtentsOfFontSet(resource.wstyle.fontset);
1481 readDatabaseFont("window.font", "Window.Font",
1482 &resource.wstyle.font);
1483 readDatabaseFont("menu.title.font", "Menu.Title.Font",
1484 &resource.mstyle.t_font);
1485 readDatabaseFont("menu.frame.font", "Menu.Frame.Font",
1486 &resource.mstyle.f_font);
1487 readDatabaseFont("toolbar.font", "Toolbar.Font",
1488 &resource.tstyle.font);
1491 // load window config
1492 readDatabaseTexture("window.title.focus", "Window.Title.Focus",
1493 &resource.wstyle.t_focus,
1494 WhitePixel(getBaseDisplay().getXDisplay(),
1495 getScreenNumber()));
1496 readDatabaseTexture("window.title.unfocus", "Window.Title.Unfocus",
1497 &resource.wstyle.t_unfocus,
1498 BlackPixel(getBaseDisplay().getXDisplay(),
1499 getScreenNumber()));
1500 readDatabaseTexture("window.label.focus", "Window.Label.Focus",
1501 &resource.wstyle.l_focus,
1502 WhitePixel(getBaseDisplay().getXDisplay(),
1503 getScreenNumber()));
1504 readDatabaseTexture("window.label.unfocus", "Window.Label.Unfocus",
1505 &resource.wstyle.l_unfocus,
1506 BlackPixel(getBaseDisplay().getXDisplay(),
1507 getScreenNumber()));
1508 readDatabaseTexture("window.handle.focus", "Window.Handle.Focus",
1509 &resource.wstyle.h_focus,
1510 WhitePixel(getBaseDisplay().getXDisplay(),
1511 getScreenNumber()));
1512 readDatabaseTexture("window.handle.unfocus", "Window.Handle.Unfocus",
1513 &resource.wstyle.h_unfocus,
1514 BlackPixel(getBaseDisplay().getXDisplay(),
1515 getScreenNumber()));
1516 readDatabaseTexture("window.grip.focus", "Window.Grip.Focus",
1517 &resource.wstyle.g_focus,
1518 WhitePixel(getBaseDisplay().getXDisplay(),
1519 getScreenNumber()));
1520 readDatabaseTexture("window.grip.unfocus", "Window.Grip.Unfocus",
1521 &resource.wstyle.g_unfocus,
1522 BlackPixel(getBaseDisplay().getXDisplay(),
1523 getScreenNumber()));
1524 readDatabaseTexture("window.button.focus", "Window.Button.Focus",
1525 &resource.wstyle.b_focus,
1526 WhitePixel(getBaseDisplay().getXDisplay(),
1527 getScreenNumber()));
1528 readDatabaseTexture("window.button.unfocus", "Window.Button.Unfocus",
1529 &resource.wstyle.b_unfocus,
1530 BlackPixel(getBaseDisplay().getXDisplay(),
1531 getScreenNumber()));
1532 readDatabaseTexture("window.button.pressed", "Window.Button.Pressed",
1533 &resource.wstyle.b_pressed,
1534 BlackPixel(getBaseDisplay().getXDisplay(),
1535 getScreenNumber()));
1536 readDatabaseColor("window.frame.focusColor",
1537 "Window.Frame.FocusColor",
1538 &resource.wstyle.f_focus,
1539 WhitePixel(getBaseDisplay().getXDisplay(),
1540 getScreenNumber()));
1541 readDatabaseColor("window.frame.unfocusColor",
1542 "Window.Frame.UnfocusColor",
1543 &resource.wstyle.f_unfocus,
1544 BlackPixel(getBaseDisplay().getXDisplay(),
1545 getScreenNumber()));
1546 readDatabaseColor("window.label.focus.textColor",
1547 "Window.Label.Focus.TextColor",
1548 &resource.wstyle.l_text_focus,
1549 BlackPixel(getBaseDisplay().getXDisplay(),
1550 getScreenNumber()));
1551 readDatabaseColor("window.label.unfocus.textColor",
1552 "Window.Label.Unfocus.TextColor",
1553 &resource.wstyle.l_text_unfocus,
1554 WhitePixel(getBaseDisplay().getXDisplay(),
1555 getScreenNumber()));
1556 readDatabaseColor("window.button.focus.picColor",
1557 "Window.Button.Focus.PicColor",
1558 &resource.wstyle.b_pic_focus,
1559 BlackPixel(getBaseDisplay().getXDisplay(),
1560 getScreenNumber()));
1561 readDatabaseColor("window.button.unfocus.picColor",
1562 "Window.Button.Unfocus.PicColor",
1563 &resource.wstyle.b_pic_unfocus,
1564 WhitePixel(getBaseDisplay().getXDisplay(),
1565 getScreenNumber()));
1567 if (conf.getValue("window.justify", "Window.Justify", s)) {
1568 if (0 == strncasecmp(s.c_str(), "right", s.length()))
1569 resource.wstyle.justify = BScreen::RightJustify;
1570 else if (0 == strncasecmp(s.c_str(), "center", s.length()))
1571 resource.wstyle.justify = BScreen::CenterJustify;
1573 resource.wstyle.justify = BScreen::LeftJustify;
1575 resource.wstyle.justify = BScreen::LeftJustify;
1577 // load toolbar config
1578 readDatabaseTexture("toolbar", "Toolbar",
1579 &resource.tstyle.toolbar,
1580 BlackPixel(getBaseDisplay().getXDisplay(),
1581 getScreenNumber()));
1582 readDatabaseTexture("toolbar.label", "Toolbar.Label",
1583 &resource.tstyle.label,
1584 BlackPixel(getBaseDisplay().getXDisplay(),
1585 getScreenNumber()));
1586 readDatabaseTexture("toolbar.windowLabel", "Toolbar.WindowLabel",
1587 &resource.tstyle.window,
1588 BlackPixel(getBaseDisplay().getXDisplay(),
1589 getScreenNumber()));
1590 readDatabaseTexture("toolbar.button", "Toolbar.Button",
1591 &resource.tstyle.button,
1592 WhitePixel(getBaseDisplay().getXDisplay(),
1593 getScreenNumber()));
1594 readDatabaseTexture("toolbar.button.pressed", "Toolbar.Button.Pressed",
1595 &resource.tstyle.pressed,
1596 BlackPixel(getBaseDisplay().getXDisplay(),
1597 getScreenNumber()));
1598 readDatabaseTexture("toolbar.clock", "Toolbar.Clock",
1599 &resource.tstyle.clock,
1600 BlackPixel(getBaseDisplay().getXDisplay(),
1601 getScreenNumber()));
1602 readDatabaseColor("toolbar.label.textColor", "Toolbar.Label.TextColor",
1603 &resource.tstyle.l_text,
1604 WhitePixel(getBaseDisplay().getXDisplay(),
1605 getScreenNumber()));
1606 readDatabaseColor("toolbar.windowLabel.textColor",
1607 "Toolbar.WindowLabel.TextColor",
1608 &resource.tstyle.w_text,
1609 WhitePixel(getBaseDisplay().getXDisplay(),
1610 getScreenNumber()));
1611 readDatabaseColor("toolbar.clock.textColor", "Toolbar.Clock.TextColor",
1612 &resource.tstyle.c_text,
1613 WhitePixel(getBaseDisplay().getXDisplay(),
1614 getScreenNumber()));
1615 readDatabaseColor("toolbar.button.picColor", "Toolbar.Button.PicColor",
1616 &resource.tstyle.b_pic,
1617 BlackPixel(getBaseDisplay().getXDisplay(),
1618 getScreenNumber()));
1620 if (conf.getValue("toolbar.justify", "Toolbar.Justify", s)) {
1621 if (0 == strncasecmp(s.c_str(), "right", s.length()))
1622 resource.tstyle.justify = BScreen::RightJustify;
1623 else if (0 == strncasecmp(s.c_str(), "center", s.length()))
1624 resource.tstyle.justify = BScreen::CenterJustify;
1626 resource.tstyle.justify = BScreen::LeftJustify;
1628 resource.tstyle.justify = BScreen::LeftJustify;
1631 readDatabaseTexture("menu.title", "Menu.Title",
1632 &resource.mstyle.title,
1633 WhitePixel(getBaseDisplay().getXDisplay(),
1634 getScreenNumber()));
1635 readDatabaseTexture("menu.frame", "Menu.Frame",
1636 &resource.mstyle.frame,
1637 BlackPixel(getBaseDisplay().getXDisplay(),
1638 getScreenNumber()));
1639 readDatabaseTexture("menu.hilite", "Menu.Hilite",
1640 &resource.mstyle.hilite,
1641 WhitePixel(getBaseDisplay().getXDisplay(),
1642 getScreenNumber()));
1643 readDatabaseColor("menu.title.textColor", "Menu.Title.TextColor",
1644 &resource.mstyle.t_text,
1645 BlackPixel(getBaseDisplay().getXDisplay(),
1646 getScreenNumber()));
1647 readDatabaseColor("menu.frame.textColor", "Menu.Frame.TextColor",
1648 &resource.mstyle.f_text,
1649 WhitePixel(getBaseDisplay().getXDisplay(),
1650 getScreenNumber()));
1651 readDatabaseColor("menu.frame.disableColor", "Menu.Frame.DisableColor",
1652 &resource.mstyle.d_text,
1653 BlackPixel(getBaseDisplay().getXDisplay(),
1654 getScreenNumber()));
1655 readDatabaseColor("menu.hilite.textColor", "Menu.Hilite.TextColor",
1656 &resource.mstyle.h_text,
1657 BlackPixel(getBaseDisplay().getXDisplay(),
1658 getScreenNumber()));
1660 if (conf.getValue("menu.title.justify", "Menu.Title.Justify", s)) {
1661 if (0 == strncasecmp(s.c_str(), "right", s.length()))
1662 resource.mstyle.t_justify = BScreen::RightJustify;
1663 else if (0 == strncasecmp(s.c_str(), "center", s.length()))
1664 resource.mstyle.t_justify = BScreen::CenterJustify;
1666 resource.mstyle.t_justify = BScreen::LeftJustify;
1668 resource.mstyle.t_justify = BScreen::LeftJustify;
1670 if (conf.getValue("menu.frame.justify", "Menu.Frame.Justify", s)) {
1671 if (0 == strncasecmp(s.c_str(), "right", s.length()))
1672 resource.mstyle.f_justify = BScreen::RightJustify;
1673 else if (0 == strncasecmp(s.c_str(), "center", s.length()))
1674 resource.mstyle.f_justify = BScreen::CenterJustify;
1676 resource.mstyle.f_justify = BScreen::LeftJustify;
1678 resource.mstyle.f_justify = BScreen::LeftJustify;
1680 if (conf.getValue("menu.bullet", "Menu.Bullet", s)) {
1681 if (0 == strncasecmp(s.c_str(), "empty", s.length()))
1682 resource.mstyle.bullet = Basemenu::Empty;
1683 else if (0 == strncasecmp(s.c_str(), "square", s.length()))
1684 resource.mstyle.bullet = Basemenu::Square;
1685 else if (0 == strncasecmp(s.c_str(), "diamond", s.length()))
1686 resource.mstyle.bullet = Basemenu::Diamond;
1688 resource.mstyle.bullet = Basemenu::Triangle;
1690 resource.mstyle.bullet = Basemenu::Triangle;
1692 if (conf.getValue("menu.bullet.position", "Menu.Bullet.Position", s)) {
1693 if (0 == strncasecmp(s.c_str(), "right", s.length()))
1694 resource.mstyle.bullet_pos = Basemenu::Right;
1696 resource.mstyle.bullet_pos = Basemenu::Left;
1698 resource.mstyle.bullet_pos = Basemenu::Left;
1700 readDatabaseColor("borderColor", "BorderColor", &resource.border_color,
1701 BlackPixel(getBaseDisplay().getXDisplay(),
1702 getScreenNumber()));
1704 // load bevel, border and handle widths
1705 if (conf.getValue("handleWidth", "HandleWidth", l)) {
1706 if (l <= size().w() / 2 && l != 0)
1707 resource.handle_width = l;
1709 resource.handle_width = 6;
1711 resource.handle_width = 6;
1713 if (conf.getValue("borderWidth", "BorderWidth", l))
1714 resource.border_width = l;
1716 resource.border_width = 1;
1718 if (conf.getValue("bevelWidth", "BevelWidth", l)) {
1719 if (l <= size().w() / 2 && l != 0)
1720 resource.bevel_width = l;
1722 resource.bevel_width = 3;
1724 resource.bevel_width = 3;
1726 if (conf.getValue("frameWidth", "FrameWidth", l)) {
1727 if (l <= size().w() / 2)
1728 resource.frame_width = l;
1730 resource.frame_width = resource.bevel_width;
1732 resource.frame_width = resource.bevel_width;
1734 const char *cmd = resource.root_command;
1735 if (cmd != NULL || conf.getValue("rootCommand", "RootCommand", s)) {
1737 cmd = s.c_str(); // not specified by the screen, so use the one from the
1740 char displaystring[MAXPATHLEN];
1741 sprintf(displaystring, "DISPLAY=%s",
1742 DisplayString(getBaseDisplay().getXDisplay()));
1743 sprintf(displaystring + strlen(displaystring) - 1, "%d",
1746 bexec(cmd, displaystring);
1748 spawnlp(P_NOWAIT, "cmd.exe", "cmd.exe", "/c", cmd, NULL);
1754 void BScreen::addIcon(OpenboxWindow *w) {
1757 w->setWorkspace(-1);
1758 w->setWindowNumber(iconList->count());
1760 iconList->insert(w);
1762 iconmenu->insert((const char **) w->getIconTitle());
1767 void BScreen::removeIcon(OpenboxWindow *w) {
1770 iconList->remove(w->getWindowNumber());
1772 iconmenu->remove(w->getWindowNumber());
1775 LinkedListIterator<OpenboxWindow> it(iconList);
1776 OpenboxWindow *bw = it.current();
1777 for (int i = 0; bw; it++, bw = it.current())
1778 bw->setWindowNumber(i++);
1782 OpenboxWindow *BScreen::getIcon(int index) {
1783 if (index >= 0 && index < iconList->count())
1784 return iconList->find(index);
1790 int BScreen::addWorkspace(void) {
1791 Workspace *wkspc = new Workspace(*this, workspacesList->count());
1792 workspacesList->insert(wkspc);
1793 saveWorkspaceNames();
1795 workspacemenu->insert(wkspc->getName(), wkspc->getMenu(),
1796 wkspc->getWorkspaceID() + 2);
1797 workspacemenu->update();
1799 toolbar->reconfigure();
1801 updateNetizenWorkspaceCount();
1803 return workspacesList->count();
1807 int BScreen::removeLastWorkspace(void) {
1808 if (workspacesList->count() == 1)
1811 Workspace *wkspc = workspacesList->last();
1813 if (current_workspace->getWorkspaceID() == wkspc->getWorkspaceID())
1814 changeWorkspaceID(current_workspace->getWorkspaceID() - 1);
1818 workspacemenu->remove(wkspc->getWorkspaceID() + 2);
1819 workspacemenu->update();
1821 workspacesList->remove(wkspc);
1824 toolbar->reconfigure();
1826 updateNetizenWorkspaceCount();
1828 return workspacesList->count();
1832 void BScreen::changeWorkspaceID(int id) {
1833 if (! current_workspace) return;
1835 if (id != current_workspace->getWorkspaceID()) {
1836 current_workspace->hideAll();
1838 workspacemenu->setItemSelected(current_workspace->getWorkspaceID() + 2,
1841 if (openbox.getFocusedWindow() &&
1842 openbox.getFocusedWindow()->getScreen() == this &&
1843 (! openbox.getFocusedWindow()->isStuck())) {
1844 current_workspace->setLastFocusedWindow(openbox.getFocusedWindow());
1845 openbox.setFocusedWindow(NULL);
1848 current_workspace = getWorkspace(id);
1850 workspacemenu->setItemSelected(current_workspace->getWorkspaceID() + 2,
1852 toolbar->redrawWorkspaceLabel(True);
1854 current_workspace->showAll();
1856 if (resource.focus_last && current_workspace->getLastFocusedWindow()) {
1857 XSync(openbox.getXDisplay(), False);
1858 current_workspace->getLastFocusedWindow()->setInputFocus();
1862 updateNetizenCurrentWorkspace();
1866 void BScreen::addNetizen(Netizen *n) {
1867 netizenList->insert(n);
1869 n->sendWorkspaceCount();
1870 n->sendCurrentWorkspace();
1872 LinkedListIterator<Workspace> it(workspacesList);
1873 for (Workspace *w = it.current(); w; it++, w = it.current()) {
1874 for (int i = 0; i < w->getCount(); i++)
1875 n->sendWindowAdd(w->getWindow(i)->getClientWindow(),
1876 w->getWorkspaceID());
1879 Window f = ((openbox.getFocusedWindow()) ?
1880 openbox.getFocusedWindow()->getClientWindow() : None);
1881 n->sendWindowFocus(f);
1885 void BScreen::removeNetizen(Window w) {
1886 LinkedListIterator<Netizen> it(netizenList);
1889 for (Netizen *n = it.current(); n; it++, i++, n = it.current())
1890 if (n->getWindowID() == w) {
1891 Netizen *tmp = netizenList->remove(i);
1899 void BScreen::updateNetizenCurrentWorkspace(void) {
1900 LinkedListIterator<Netizen> it(netizenList);
1901 for (Netizen *n = it.current(); n; it++, n = it.current())
1902 n->sendCurrentWorkspace();
1906 void BScreen::updateNetizenWorkspaceCount(void) {
1907 LinkedListIterator<Netizen> it(netizenList);
1908 for (Netizen *n = it.current(); n; it++, n = it.current())
1909 n->sendWorkspaceCount();
1913 void BScreen::updateNetizenWindowFocus(void) {
1914 Window f = ((openbox.getFocusedWindow()) ?
1915 openbox.getFocusedWindow()->getClientWindow() : None);
1916 LinkedListIterator<Netizen> it(netizenList);
1917 for (Netizen *n = it.current(); n; it++, n = it.current())
1918 n->sendWindowFocus(f);
1922 void BScreen::updateNetizenWindowAdd(Window w, unsigned long p) {
1923 LinkedListIterator<Netizen> it(netizenList);
1924 for (Netizen *n = it.current(); n; it++, n = it.current())
1925 n->sendWindowAdd(w, p);
1929 void BScreen::updateNetizenWindowDel(Window w) {
1930 LinkedListIterator<Netizen> it(netizenList);
1931 for (Netizen *n = it.current(); n; it++, n = it.current())
1932 n->sendWindowDel(w);
1936 void BScreen::updateNetizenWindowRaise(Window w) {
1937 LinkedListIterator<Netizen> it(netizenList);
1938 for (Netizen *n = it.current(); n; it++, n = it.current())
1939 n->sendWindowRaise(w);
1943 void BScreen::updateNetizenWindowLower(Window w) {
1944 LinkedListIterator<Netizen> it(netizenList);
1945 for (Netizen *n = it.current(); n; it++, n = it.current())
1946 n->sendWindowLower(w);
1950 void BScreen::updateNetizenConfigNotify(XEvent *e) {
1951 LinkedListIterator<Netizen> it(netizenList);
1952 for (Netizen *n = it.current(); n; it++, n = it.current())
1953 n->sendConfigNotify(e);
1957 void BScreen::raiseWindows(Window *workspace_stack, int num) {
1958 Window *session_stack = new
1959 Window[(num + workspacesList->count() + rootmenuList->count() + 13)];
1962 XRaiseWindow(getBaseDisplay().getXDisplay(), iconmenu->getWindowID());
1963 *(session_stack + i++) = iconmenu->getWindowID();
1965 LinkedListIterator<Workspace> wit(workspacesList);
1966 for (Workspace *tmp = wit.current(); tmp; wit++, tmp = wit.current())
1967 *(session_stack + i++) = tmp->getMenu()->getWindowID();
1969 *(session_stack + i++) = workspacemenu->getWindowID();
1971 *(session_stack + i++) = configmenu->getFocusmenu()->getWindowID();
1972 *(session_stack + i++) = configmenu->getPlacementmenu()->getWindowID();
1973 *(session_stack + i++) = configmenu->getWindowID();
1976 *(session_stack + i++) = slit->getMenu()->getDirectionmenu()->getWindowID();
1977 *(session_stack + i++) = slit->getMenu()->getPlacementmenu()->getWindowID();
1978 *(session_stack + i++) = slit->getMenu()->getWindowID();
1981 *(session_stack + i++) =
1982 toolbar->getMenu()->getPlacementmenu()->getWindowID();
1983 *(session_stack + i++) = toolbar->getMenu()->getWindowID();
1985 LinkedListIterator<Rootmenu> rit(rootmenuList);
1986 for (Rootmenu *tmp = rit.current(); tmp; rit++, tmp = rit.current())
1987 *(session_stack + i++) = tmp->getWindowID();
1988 *(session_stack + i++) = rootmenu->getWindowID();
1990 if (toolbar->onTop())
1991 *(session_stack + i++) = toolbar->getWindowID();
1995 *(session_stack + i++) = slit->getWindowID();
1999 *(session_stack + i++) = *(workspace_stack + k);
2001 XRestackWindows(getBaseDisplay().getXDisplay(), session_stack, i);
2003 delete [] session_stack;
2007 void BScreen::addWorkspaceName(const char *name) {
2008 workspaceNames->insert(bstrdup(name));
2011 char* BScreen::getNameOfWorkspace(int id) {
2014 if (id >= 0 && id < workspaceNames->count()) {
2015 char *wkspc_name = workspaceNames->find(id);
2024 void BScreen::reassociateWindow(OpenboxWindow *w, int wkspc_id, Bool ignore_sticky) {
2028 wkspc_id = current_workspace->getWorkspaceID();
2030 if (w->getWorkspaceNumber() == wkspc_id)
2033 if (w->isIconic()) {
2035 getWorkspace(wkspc_id)->addWindow(w);
2036 } else if (ignore_sticky || ! w->isStuck()) {
2037 getWorkspace(w->getWorkspaceNumber())->removeWindow(w);
2038 getWorkspace(wkspc_id)->addWindow(w);
2043 void BScreen::nextFocus(void) {
2044 Bool have_focused = False;
2045 int focused_window_number = -1;
2046 OpenboxWindow *next;
2048 if (openbox.getFocusedWindow()) {
2049 if (openbox.getFocusedWindow()->getScreen()->getScreenNumber() ==
2050 getScreenNumber()) {
2051 have_focused = True;
2052 focused_window_number = openbox.getFocusedWindow()->getWindowNumber();
2056 if ((getCurrentWorkspace()->getCount() > 1) && have_focused) {
2057 int next_window_number = focused_window_number;
2059 if ((++next_window_number) >= getCurrentWorkspace()->getCount())
2060 next_window_number = 0;
2062 next = getCurrentWorkspace()->getWindow(next_window_number);
2063 } while ((! next->setInputFocus()) && (next_window_number !=
2064 focused_window_number));
2066 if (next_window_number != focused_window_number)
2067 getCurrentWorkspace()->raiseWindow(next);
2068 } else if (getCurrentWorkspace()->getCount() >= 1) {
2069 next = current_workspace->getWindow(0);
2071 current_workspace->raiseWindow(next);
2072 next->setInputFocus();
2077 void BScreen::prevFocus(void) {
2078 Bool have_focused = False;
2079 int focused_window_number = -1;
2080 OpenboxWindow *prev;
2082 if (openbox.getFocusedWindow()) {
2083 if (openbox.getFocusedWindow()->getScreen()->getScreenNumber() ==
2084 getScreenNumber()) {
2085 have_focused = True;
2086 focused_window_number = openbox.getFocusedWindow()->getWindowNumber();
2090 if ((getCurrentWorkspace()->getCount() > 1) && have_focused) {
2091 int prev_window_number = focused_window_number;
2093 if ((--prev_window_number) < 0)
2094 prev_window_number = getCurrentWorkspace()->getCount() - 1;
2096 prev = getCurrentWorkspace()->getWindow(prev_window_number);
2097 } while ((! prev->setInputFocus()) && (prev_window_number !=
2098 focused_window_number));
2100 if (prev_window_number != focused_window_number)
2101 getCurrentWorkspace()->raiseWindow(prev);
2102 } else if (getCurrentWorkspace()->getCount() >= 1) {
2103 prev = current_workspace->getWindow(0);
2105 current_workspace->raiseWindow(prev);
2106 prev->setInputFocus();
2111 void BScreen::raiseFocus(void) {
2112 Bool have_focused = False;
2113 int focused_window_number = -1;
2115 if (openbox.getFocusedWindow()) {
2116 if (openbox.getFocusedWindow()->getScreen()->getScreenNumber() ==
2117 getScreenNumber()) {
2118 have_focused = True;
2119 focused_window_number = openbox.getFocusedWindow()->getWindowNumber();
2123 if ((getCurrentWorkspace()->getCount() > 1) && have_focused)
2124 getWorkspace(openbox.getFocusedWindow()->getWorkspaceNumber())->
2125 raiseWindow(openbox.getFocusedWindow());
2129 void BScreen::InitMenu(void) {
2131 while (rootmenuList->count())
2132 rootmenuList->remove(0);
2134 while (rootmenu->getCount())
2135 rootmenu->remove(0);
2137 rootmenu = new Rootmenu(*this);
2139 Bool defaultMenu = True;
2141 if (openbox.getMenuFilename()) {
2142 FILE *menu_file = fopen(openbox.getMenuFilename(), "r");
2145 perror(openbox.getMenuFilename());
2147 if (feof(menu_file)) {
2148 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenEmptyMenuFile,
2149 "%s: Empty menu file"),
2150 openbox.getMenuFilename());
2152 char line[1024], label[1024];
2153 memset(line, 0, 1024);
2154 memset(label, 0, 1024);
2156 while (fgets(line, 1024, menu_file) && ! feof(menu_file)) {
2157 if (line[0] != '#') {
2158 int i, key = 0, index = -1, len = strlen(line);
2161 for (i = 0; i < len; i++) {
2162 if (line[i] == '[') index = 0;
2163 else if (line[i] == ']') break;
2164 else if (line[i] != ' ')
2166 key += tolower(line[i]);
2171 for (i = index; i < len; i++) {
2172 if (line[i] == '(') index = 0;
2173 else if (line[i] == ')') break;
2174 else if (index++ >= 0) {
2175 if (line[i] == '\\' && i < len - 1) i++;
2176 label[index - 1] = line[i];
2180 if (index == -1) index = 0;
2181 label[index] = '\0';
2183 rootmenu->setLabel(label);
2184 defaultMenu = parseMenuFile(menu_file, rootmenu);
2195 rootmenu->setInternalMenu();
2196 rootmenu->insert(i18n->getMessage(ScreenSet, Screenxterm, "xterm"),
2198 i18n->getMessage(ScreenSet, Screenxterm, "xterm"));
2199 rootmenu->insert(i18n->getMessage(ScreenSet, ScreenRestart, "Restart"),
2201 rootmenu->insert(i18n->getMessage(ScreenSet, ScreenExit, "Exit"),
2204 openbox.setMenuFilename(openbox.getMenuFilename());
2209 Bool BScreen::parseMenuFile(FILE *file, Rootmenu *menu) {
2210 char line[1024], label[1024], command[1024];
2212 while (! feof(file)) {
2213 memset(line, 0, 1024);
2214 memset(label, 0, 1024);
2215 memset(command, 0, 1024);
2217 if (fgets(line, 1024, file)) {
2218 if (line[0] != '#') {
2219 register int i, key = 0, parse = 0, index = -1,
2220 line_length = strlen(line),
2221 label_length = 0, command_length = 0;
2223 // determine the keyword
2225 for (i = 0; i < line_length; i++) {
2226 if (line[i] == '[') parse = 1;
2227 else if (line[i] == ']') break;
2228 else if (line[i] != ' ')
2230 key += tolower(line[i]);
2233 // get the label enclosed in ()'s
2236 for (i = 0; i < line_length; i++) {
2237 if (line[i] == '(') {
2240 } else if (line[i] == ')') break;
2241 else if (index++ >= 0) {
2242 if (line[i] == '\\' && i < line_length - 1) i++;
2243 label[index - 1] = line[i];
2248 label[index] = '\0';
2249 label_length = index;
2255 // get the command enclosed in {}'s
2258 for (i = 0; i < line_length; i++) {
2259 if (line[i] == '{') {
2262 } else if (line[i] == '}') break;
2263 else if (index++ >= 0) {
2264 if (line[i] == '\\' && i < line_length - 1) i++;
2265 command[index - 1] = line[i];
2270 command[index] = '\0';
2271 command_length = index;
2279 return ((menu->getCount() == 0) ? True : False);
2284 menu->insert(label);
2289 if ((! *label) && (! *command)) {
2290 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenEXECError,
2291 "BScreen::parseMenuFile: [exec] error, "
2292 "no menu label and/or command defined\n"));
2296 menu->insert(label, BScreen::Execute, command);
2302 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenEXITError,
2303 "BScreen::parseMenuFile: [exit] error, "
2304 "no menu label defined\n"));
2308 menu->insert(label, BScreen::Exit);
2314 if ((! *label) || (! *command)) {
2315 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenSTYLEError,
2316 "BScreen::parseMenuFile: [style] error, "
2317 "no menu label and/or filename defined\n"));
2321 char style[MAXPATHLEN];
2323 // perform shell style ~ home directory expansion
2325 int homedir_len = 0;
2326 if (*command == '~' && *(command + 1) == '/') {
2327 homedir = getenv("HOME");
2328 homedir_len = strlen(homedir);
2331 if (homedir && homedir_len != 0) {
2332 strncpy(style, homedir, homedir_len);
2334 strncpy(style + homedir_len, command + 1,
2335 command_length - 1);
2336 *(style + command_length + homedir_len - 1) = '\0';
2338 strncpy(style, command, command_length);
2339 *(style + command_length) = '\0';
2342 menu->insert(label, BScreen::SetStyle, style);
2349 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenCONFIGError,
2350 "BScreen::parseMenufile: [config] error, "
2351 "no label defined"));
2355 menu->insert(label, configmenu);
2359 case 740: // include
2362 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenINCLUDEError,
2363 "BScreen::parseMenuFile: [include] error, "
2364 "no filename defined\n"));
2368 char newfile[MAXPATHLEN];
2370 // perform shell style ~ home directory expansion
2372 int homedir_len = 0;
2373 if (*label == '~' && *(label + 1) == '/') {
2374 homedir = getenv("HOME");
2375 homedir_len = strlen(homedir);
2378 if (homedir && homedir_len != 0) {
2379 strncpy(newfile, homedir, homedir_len);
2381 strncpy(newfile + homedir_len, label + 1,
2383 *(newfile + label_length + homedir_len - 1) = '\0';
2385 strncpy(newfile, label, label_length);
2386 *(newfile + label_length) = '\0';
2390 FILE *submenufile = fopen(newfile, "r");
2394 if (fstat(fileno(submenufile), &buf) ||
2395 (! S_ISREG(buf.st_mode))) {
2397 i18n->getMessage(ScreenSet, ScreenINCLUDEErrorReg,
2398 "BScreen::parseMenuFile: [include] error: "
2399 "'%s' is not a regular file\n"), newfile);
2403 if (! feof(submenufile)) {
2404 if (! parseMenuFile(submenufile, menu))
2405 openbox.setMenuFilename(newfile);
2407 fclose(submenufile);
2416 case 767: // submenu
2419 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenSUBMENUError,
2420 "BScreen::parseMenuFile: [submenu] error, "
2421 "no menu label defined\n"));
2425 Rootmenu *submenu = new Rootmenu(*this);
2428 submenu->setLabel(command);
2430 submenu->setLabel(label);
2432 parseMenuFile(file, submenu);
2434 menu->insert(label, submenu);
2435 rootmenuList->insert(submenu);
2440 case 773: // restart
2443 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenRESTARTError,
2444 "BScreen::parseMenuFile: [restart] error, "
2445 "no menu label defined\n"));
2450 menu->insert(label, BScreen::RestartOther, command);
2452 menu->insert(label, BScreen::Restart);
2457 case 845: // reconfig
2460 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenRECONFIGError,
2461 "BScreen::parseMenuFile: [reconfig] error, "
2462 "no menu label defined\n"));
2466 menu->insert(label, BScreen::Reconfigure);
2471 case 995: // stylesdir
2472 case 1113: // stylesmenu
2474 Bool newmenu = ((key == 1113) ? True : False);
2476 if ((! *label) || ((! *command) && newmenu)) {
2478 i18n->getMessage(ScreenSet, ScreenSTYLESDIRError,
2479 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
2480 " error, no directory defined\n"));
2484 char stylesdir[MAXPATHLEN];
2486 char *directory = ((newmenu) ? command : label);
2487 int directory_length = ((newmenu) ? command_length : label_length);
2489 // perform shell style ~ home directory expansion
2491 int homedir_len = 0;
2493 if (*directory == '~' && *(directory + 1) == '/') {
2494 homedir = getenv("HOME");
2495 homedir_len = strlen(homedir);
2498 if (homedir && homedir_len != 0) {
2499 strncpy(stylesdir, homedir, homedir_len);
2501 strncpy(stylesdir + homedir_len, directory + 1,
2502 directory_length - 1);
2503 *(stylesdir + directory_length + homedir_len - 1) = '\0';
2505 strncpy(stylesdir, directory, directory_length);
2506 *(stylesdir + directory_length) = '\0';
2509 struct stat statbuf;
2511 if (! stat(stylesdir, &statbuf)) {
2512 if (S_ISDIR(statbuf.st_mode)) {
2513 Rootmenu *stylesmenu;
2516 stylesmenu = new Rootmenu(*this);
2520 DIR *d = opendir(stylesdir);
2524 // get the total number of directory entries
2525 while ((p = readdir(d))) entries++;
2528 char **ls = new char* [entries];
2530 while ((p = readdir(d)))
2531 ls[index++] = bstrdup(p->d_name);
2535 std::sort(ls, ls + entries, dcmp());
2537 int n, slen = strlen(stylesdir);
2538 for (n = 0; n < entries; n++) {
2539 if (ls[n][strlen(ls[n])-1] != '~') {
2540 int nlen = strlen(ls[n]);
2541 char style[MAXPATHLEN + 1];
2543 strncpy(style, stylesdir, slen);
2544 *(style + slen) = '/';
2545 strncpy(style + slen + 1, ls[n], nlen + 1);
2547 if ((! stat(style, &statbuf)) && S_ISREG(statbuf.st_mode))
2548 stylesmenu->insert(ls[n], BScreen::SetStyle, style);
2556 stylesmenu->update();
2559 stylesmenu->setLabel(label);
2560 menu->insert(label, stylesmenu);
2561 rootmenuList->insert(stylesmenu);
2564 openbox.setMenuFilename(stylesdir);
2566 fprintf(stderr, i18n->getMessage(ScreenSet,
2567 ScreenSTYLESDIRErrorNotDir,
2568 "BScreen::parseMenuFile:"
2569 " [stylesdir/stylesmenu] error, %s is not a"
2570 " directory\n"), stylesdir);
2574 i18n->getMessage(ScreenSet, ScreenSTYLESDIRErrorNoExist,
2575 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
2576 " error, %s does not exist\n"), stylesdir);
2582 case 1090: // workspaces
2586 i18n->getMessage(ScreenSet, ScreenWORKSPACESError,
2587 "BScreen:parseMenuFile: [workspaces] error, "
2588 "no menu label defined\n"));
2592 menu->insert(label, workspacemenu);
2601 return ((menu->getCount() == 0) ? True : False);
2605 void BScreen::shutdown(void) {
2608 XSelectInput(getBaseDisplay().getXDisplay(), getRootWindow(), NoEventMask);
2609 XSync(getBaseDisplay().getXDisplay(), False);
2611 LinkedListIterator<Workspace> it(workspacesList);
2612 for (Workspace *w = it.current(); w; it++, w = it.current())
2615 while (iconList->count()) {
2616 iconList->first()->restore();
2617 delete iconList->first();
2628 void BScreen::showPosition(int x, int y) {
2629 if (! geom_visible) {
2630 XMoveResizeWindow(getBaseDisplay().getXDisplay(), geom_window,
2631 (size().w() - geom_w) / 2,
2632 (size().h() - geom_h) / 2, geom_w, geom_h);
2633 XMapWindow(getBaseDisplay().getXDisplay(), geom_window);
2634 XRaiseWindow(getBaseDisplay().getXDisplay(), geom_window);
2636 geom_visible = True;
2641 sprintf(label, i18n->getMessage(ScreenSet, ScreenPositionFormat,
2642 "X: %4d x Y: %4d"), x, y);
2644 XClearWindow(getBaseDisplay().getXDisplay(), geom_window);
2646 if (i18n->multibyte()) {
2647 XmbDrawString(getBaseDisplay().getXDisplay(), geom_window,
2648 resource.wstyle.fontset, resource.wstyle.l_text_focus_gc,
2649 resource.bevel_width, resource.bevel_width -
2650 resource.wstyle.fontset_extents->max_ink_extent.y,
2651 label, strlen(label));
2653 XDrawString(getBaseDisplay().getXDisplay(), geom_window,
2654 resource.wstyle.l_text_focus_gc,
2655 resource.bevel_width,
2656 resource.wstyle.font->ascent +
2657 resource.bevel_width, label, strlen(label));
2662 void BScreen::showGeometry(unsigned int gx, unsigned int gy) {
2663 if (! geom_visible) {
2664 XMoveResizeWindow(getBaseDisplay().getXDisplay(), geom_window,
2665 (size().w() - geom_w) / 2,
2666 (size().h() - geom_h) / 2, geom_w, geom_h);
2667 XMapWindow(getBaseDisplay().getXDisplay(), geom_window);
2668 XRaiseWindow(getBaseDisplay().getXDisplay(), geom_window);
2670 geom_visible = True;
2675 sprintf(label, i18n->getMessage(ScreenSet, ScreenGeometryFormat,
2676 "W: %4d x H: %4d"), gx, gy);
2678 XClearWindow(getBaseDisplay().getXDisplay(), geom_window);
2680 if (i18n->multibyte()) {
2681 XmbDrawString(getBaseDisplay().getXDisplay(), geom_window,
2682 resource.wstyle.fontset, resource.wstyle.l_text_focus_gc,
2683 resource.bevel_width, resource.bevel_width -
2684 resource.wstyle.fontset_extents->max_ink_extent.y,
2685 label, strlen(label));
2687 XDrawString(getBaseDisplay().getXDisplay(), geom_window,
2688 resource.wstyle.l_text_focus_gc,
2689 resource.bevel_width,
2690 resource.wstyle.font->ascent +
2691 resource.bevel_width, label, strlen(label));
2695 void BScreen::hideGeometry(void) {
2697 XUnmapWindow(getBaseDisplay().getXDisplay(), geom_window);
2698 geom_visible = False;