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
106 static Bool running = True;
108 static int anotherWMRunning(Display *display, XErrorEvent *) {
109 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenAnotherWMRunning,
110 "BScreen::BScreen: an error occured while querying the X server.\n"
111 " another window manager already running on display %s.\n"),
112 DisplayString(display));
120 bool operator()(const char *one, const char *two) const {
121 return (strcmp(one, two) < 0) ? True : False;
125 #ifndef HAVE_STRCASESTR
126 static const char * strcasestr(const char *str, const char *ptn) {
128 for( ; *str; str++) {
129 for(s2=str,p2=ptn; ; s2++,p2++) {
130 if (!*p2) return str;
131 if (toupper(*s2) != toupper(*p2)) break;
136 #endif // HAVE_STRCASESTR
138 static const char *getFontElement(const char *pattern, char *buf, int bufsiz, ...) {
143 va_start(va, bufsiz);
146 while((v = va_arg(va, char *)) != NULL) {
147 p = strcasestr(pattern, v);
149 strncpy(buf, p+1, bufsiz-2);
150 p2 = strchr(buf, '-');
157 strncpy(buf, "*", bufsiz);
161 static const char *getFontSize(const char *pattern, int *size) {
166 for (p=pattern; 1; p++) {
168 if (p2!=NULL && n>1 && n<72) {
169 *size = n; return p2+1;
171 *size = 16; return NULL;
173 } else if (*p=='-') {
174 if (n>1 && n<72 && p2!=NULL) {
179 } else if (*p>='0' && *p<='9' && p2!=NULL) {
189 BScreen::BScreen(Openbox &ob, int scrn, Resource &conf) : ScreenInfo(ob, scrn),
190 openbox(ob), config(conf)
192 event_mask = ColormapChangeMask | EnterWindowMask | PropertyChangeMask |
193 SubstructureRedirectMask | KeyPressMask | KeyReleaseMask |
194 ButtonPressMask | ButtonReleaseMask;
196 XErrorHandler old = XSetErrorHandler((XErrorHandler) anotherWMRunning);
197 XSelectInput(getBaseDisplay().getXDisplay(), getRootWindow(), event_mask);
198 XSync(getBaseDisplay().getXDisplay(), False);
199 XSetErrorHandler((XErrorHandler) old);
202 if (! managed) return;
204 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenManagingScreen,
205 "BScreen::BScreen: managing screen %d "
206 "using visual 0x%lx, depth %d\n"),
207 getScreenNumber(), XVisualIDFromVisual(getVisual()),
212 resource.mstyle.t_fontset = resource.mstyle.f_fontset =
213 resource.tstyle.fontset = resource.wstyle.fontset = NULL;
214 resource.mstyle.t_font = resource.mstyle.f_font = resource.tstyle.font =
215 resource.wstyle.font = NULL;
223 pid_t bpid = getpid();
225 XChangeProperty(getBaseDisplay().getXDisplay(), getRootWindow(),
226 openbox.getOpenboxPidAtom(), XA_CARDINAL,
227 sizeof(pid_t) * 8, PropModeReplace,
228 (unsigned char *) &bpid, 1);
229 #endif // HAVE_GETPID
231 XDefineCursor(getBaseDisplay().getXDisplay(), getRootWindow(),
232 openbox.getSessionCursor());
234 workspaceNames = new LinkedList<char>;
235 workspacesList = new LinkedList<Workspace>;
236 rootmenuList = new LinkedList<Rootmenu>;
237 netizenList = new LinkedList<Netizen>;
238 iconList = new LinkedList<OpenboxWindow>;
241 new BImageControl(openbox, *this, True, openbox.getColorsPerChannel(),
242 openbox.getCacheLife(), openbox.getCacheMax());
243 image_control->installRootColormap();
244 root_colormap_installed = True;
246 image_control->setDither(resource.image_dither);
248 load(); // load config options from Resources
252 unsigned long gc_value_mask = GCForeground;
253 if (! i18n->multibyte()) gc_value_mask |= GCFont;
255 gcv.foreground = WhitePixel(getBaseDisplay().getXDisplay(),
257 ^ BlackPixel(getBaseDisplay().getXDisplay(),
259 gcv.function = GXxor;
260 gcv.subwindow_mode = IncludeInferiors;
261 opGC = XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
262 GCForeground | GCFunction | GCSubwindowMode, &gcv);
264 gcv.foreground = resource.wstyle.l_text_focus.getPixel();
265 if (resource.wstyle.font)
266 gcv.font = resource.wstyle.font->fid;
267 resource.wstyle.l_text_focus_gc =
268 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
269 gc_value_mask, &gcv);
271 gcv.foreground = resource.wstyle.l_text_unfocus.getPixel();
272 if (resource.wstyle.font)
273 gcv.font = resource.wstyle.font->fid;
274 resource.wstyle.l_text_unfocus_gc =
275 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
276 gc_value_mask, &gcv);
278 gcv.foreground = resource.wstyle.b_pic_focus.getPixel();
279 resource.wstyle.b_pic_focus_gc =
280 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
283 gcv.foreground = resource.wstyle.b_pic_unfocus.getPixel();
284 resource.wstyle.b_pic_unfocus_gc =
285 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
288 gcv.foreground = resource.mstyle.t_text.getPixel();
289 if (resource.mstyle.t_font)
290 gcv.font = resource.mstyle.t_font->fid;
291 resource.mstyle.t_text_gc =
292 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
293 gc_value_mask, &gcv);
295 gcv.foreground = resource.mstyle.f_text.getPixel();
296 if (resource.mstyle.f_font)
297 gcv.font = resource.mstyle.f_font->fid;
298 resource.mstyle.f_text_gc =
299 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
300 gc_value_mask, &gcv);
302 gcv.foreground = resource.mstyle.h_text.getPixel();
303 resource.mstyle.h_text_gc =
304 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
305 gc_value_mask, &gcv);
307 gcv.foreground = resource.mstyle.d_text.getPixel();
308 resource.mstyle.d_text_gc =
309 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
310 gc_value_mask, &gcv);
312 gcv.foreground = resource.mstyle.hilite.getColor()->getPixel();
313 resource.mstyle.hilite_gc =
314 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
315 gc_value_mask, &gcv);
317 gcv.foreground = resource.tstyle.l_text.getPixel();
318 if (resource.tstyle.font)
319 gcv.font = resource.tstyle.font->fid;
320 resource.tstyle.l_text_gc =
321 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
322 gc_value_mask, &gcv);
324 gcv.foreground = resource.tstyle.w_text.getPixel();
325 resource.tstyle.w_text_gc =
326 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
327 gc_value_mask, &gcv);
329 gcv.foreground = resource.tstyle.c_text.getPixel();
330 resource.tstyle.c_text_gc =
331 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
332 gc_value_mask, &gcv);
334 gcv.foreground = resource.tstyle.b_pic.getPixel();
335 resource.tstyle.b_pic_gc =
336 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
337 gc_value_mask, &gcv);
339 const char *s = i18n->getMessage(ScreenSet, ScreenPositionLength,
340 "0: 0000 x 0: 0000");
343 if (i18n->multibyte()) {
344 XRectangle ink, logical;
345 XmbTextExtents(resource.wstyle.fontset, s, l, &ink, &logical);
346 geom_w = logical.width;
348 geom_h = resource.wstyle.fontset_extents->max_ink_extent.height;
350 geom_h = resource.wstyle.font->ascent +
351 resource.wstyle.font->descent;
353 geom_w = XTextWidth(resource.wstyle.font, s, l);
356 geom_w += (resource.bevel_width * 2);
357 geom_h += (resource.bevel_width * 2);
359 XSetWindowAttributes attrib;
360 unsigned long mask = CWBorderPixel | CWColormap | CWSaveUnder;
361 attrib.border_pixel = getBorderColor()->getPixel();
362 attrib.colormap = getColormap();
363 attrib.save_under = True;
366 XCreateWindow(getBaseDisplay().getXDisplay(), getRootWindow(),
367 0, 0, geom_w, geom_h, resource.border_width, getDepth(),
368 InputOutput, getVisual(), mask, &attrib);
369 geom_visible = False;
371 if (resource.wstyle.l_focus.getTexture() & BImage_ParentRelative) {
372 if (resource.wstyle.t_focus.getTexture() ==
373 (BImage_Flat | BImage_Solid)) {
375 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window,
376 resource.wstyle.t_focus.getColor()->getPixel());
378 geom_pixmap = image_control->renderImage(geom_w, geom_h,
379 &resource.wstyle.t_focus);
380 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
381 geom_window, geom_pixmap);
384 if (resource.wstyle.l_focus.getTexture() ==
385 (BImage_Flat | BImage_Solid)) {
387 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window,
388 resource.wstyle.l_focus.getColor()->getPixel());
390 geom_pixmap = image_control->renderImage(geom_w, geom_h,
391 &resource.wstyle.l_focus);
392 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
393 geom_window, geom_pixmap);
397 workspacemenu = new Workspacemenu(*this);
398 iconmenu = new Iconmenu(*this);
399 configmenu = new Configmenu(*this);
401 Workspace *wkspc = NULL;
402 if (resource.workspaces != 0) {
403 for (int i = 0; i < resource.workspaces; ++i) {
404 wkspc = new Workspace(*this, workspacesList->count());
405 workspacesList->insert(wkspc);
406 saveWorkspaceNames();
407 workspacemenu->insert(wkspc->getName(), wkspc->getMenu());
410 wkspc = new Workspace(*this, workspacesList->count());
411 workspacesList->insert(wkspc);
412 saveWorkspaceNames();
413 workspacemenu->insert(wkspc->getName(), wkspc->getMenu());
416 workspacemenu->insert(i18n->getMessage(IconSet, IconIcons, "Icons"),
418 workspacemenu->update();
420 current_workspace = workspacesList->first();
421 workspacemenu->setItemSelected(2, True);
423 toolbar = new Toolbar(*this, config);
426 slit = new Slit(*this, config);
434 changeWorkspaceID(0);
438 Window r, p, *children;
439 XQueryTree(getBaseDisplay().getXDisplay(), getRootWindow(), &r, &p,
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;
446 XWMHints *wmhints = XGetWMHints(getBaseDisplay().getXDisplay(),
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) {
463 // manage shown windows
464 for (i = 0; i < (int) nchild; ++i) {
465 if (children[i] == None || (! openbox.validateWindow(children[i])))
468 XWindowAttributes attrib;
469 if (XGetWindowAttributes(getBaseDisplay().getXDisplay(), children[i],
471 if (attrib.override_redirect) continue;
473 if (attrib.map_state != IsUnmapped) {
474 new OpenboxWindow(openbox, children[i], this);
476 OpenboxWindow *win = openbox.searchWindow(children[i]);
478 XMapRequestEvent mre;
479 mre.window = children[i];
480 win->restoreAttributes();
481 win->mapRequestEvent(&mre);
487 if (! resource.sloppy_focus)
488 XSetInputFocus(getBaseDisplay().getXDisplay(), toolbar->getWindowID(),
489 RevertToParent, CurrentTime);
492 XFlush(getBaseDisplay().getXDisplay());
496 BScreen::~BScreen(void) {
497 if (! managed) return;
499 if (geom_pixmap != None)
500 image_control->removeImage(geom_pixmap);
502 if (geom_window != None)
503 XDestroyWindow(getBaseDisplay().getXDisplay(), geom_window);
505 removeWorkspaceNames();
507 while (workspacesList->count())
508 delete workspacesList->remove(0);
510 while (rootmenuList->count())
511 rootmenuList->remove(0);
513 while (iconList->count())
514 delete iconList->remove(0);
516 while (netizenList->count())
517 delete netizenList->remove(0);
520 if (resource.strftime_format)
521 delete [] resource.strftime_format;
522 #endif // HAVE_STRFTIME
525 delete workspacemenu;
534 delete image_control;
536 delete workspacesList;
537 delete workspaceNames;
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);
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;
562 XFreeGC(getBaseDisplay().getXDisplay(), opGC);
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);
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);
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);
594 void BScreen::readDatabaseTexture(const char *rname, const char *rclass,
596 unsigned long default_pixel)
600 if (resource.styleconfig.getValue(rname, rclass, s))
601 image_control->parseTexture(texture, s.c_str());
603 texture->setTexture(BImage_Solid | BImage_Flat);
605 if (texture->getTexture() & BImage_Solid) {
606 int clen = strlen(rclass) + 32, nlen = strlen(rname) + 32;
608 char *colorclass = new char[clen], *colorname = new char[nlen];
610 sprintf(colorclass, "%s.Color", rclass);
611 sprintf(colorname, "%s.color", rname);
613 readDatabaseColor(colorname, colorclass, texture->getColor(),
617 sprintf(colorclass, "%s.ColorTo", rclass);
618 sprintf(colorname, "%s.colorTo", rname);
620 readDatabaseColor(colorname, colorclass, texture->getColorTo(),
624 delete [] colorclass;
627 if ((! texture->getColor()->isAllocated()) ||
628 (texture->getTexture() & BImage_Flat))
633 xcol.red = (unsigned int) (texture->getColor()->getRed() +
634 (texture->getColor()->getRed() >> 1));
635 if (xcol.red >= 0xff) xcol.red = 0xffff;
636 else xcol.red *= 0xff;
637 xcol.green = (unsigned int) (texture->getColor()->getGreen() +
638 (texture->getColor()->getGreen() >> 1));
639 if (xcol.green >= 0xff) xcol.green = 0xffff;
640 else xcol.green *= 0xff;
641 xcol.blue = (unsigned int) (texture->getColor()->getBlue() +
642 (texture->getColor()->getBlue() >> 1));
643 if (xcol.blue >= 0xff) xcol.blue = 0xffff;
644 else xcol.blue *= 0xff;
646 if (! XAllocColor(getBaseDisplay().getXDisplay(),
647 getColormap(), &xcol))
650 texture->getHiColor()->setPixel(xcol.pixel);
653 (unsigned int) ((texture->getColor()->getRed() >> 2) +
654 (texture->getColor()->getRed() >> 1)) * 0xff;
656 (unsigned int) ((texture->getColor()->getGreen() >> 2) +
657 (texture->getColor()->getGreen() >> 1)) * 0xff;
659 (unsigned int) ((texture->getColor()->getBlue() >> 2) +
660 (texture->getColor()->getBlue() >> 1)) * 0xff;
662 if (! XAllocColor(getBaseDisplay().getXDisplay(),
663 getColormap(), &xcol))
666 texture->getLoColor()->setPixel(xcol.pixel);
667 } else if (texture->getTexture() & BImage_Gradient) {
668 int clen = strlen(rclass) + 10, nlen = strlen(rname) + 10;
670 char *colorclass = new char[clen], *colorname = new char[nlen],
671 *colortoclass = new char[clen], *colortoname = new char[nlen];
673 sprintf(colorclass, "%s.Color", rclass);
674 sprintf(colorname, "%s.color", rname);
676 sprintf(colortoclass, "%s.ColorTo", rclass);
677 sprintf(colortoname, "%s.colorTo", rname);
679 readDatabaseColor(colorname, colorclass, texture->getColor(),
681 readDatabaseColor(colortoname, colortoclass, texture->getColorTo(),
684 delete [] colorclass;
686 delete [] colortoclass;
687 delete [] colortoname;
692 void BScreen::readDatabaseColor(const char *rname, const char *rclass,
693 BColor *color, unsigned long default_pixel)
697 if (resource.styleconfig.getValue(rname, rclass, s))
698 image_control->parseColor(color, s.c_str());
700 // parsing with no color string just deallocates the color, if it has
701 // been previously allocated
702 image_control->parseColor(color);
703 color->setPixel(default_pixel);
708 void BScreen::readDatabaseFontSet(const char *rname, const char *rclass,
710 if (! fontset) return;
712 static char *defaultFont = "fixed";
713 bool load_default = false;
717 XFreeFontSet(getBaseDisplay().getXDisplay(), *fontset);
719 if (resource.styleconfig.getValue(rname, rclass, s)) {
720 if (! (*fontset = createFontSet(s.c_str())))
726 *fontset = createFontSet(defaultFont);
729 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenDefaultFontLoadFail,
730 "BScreen::LoadStyle(): couldn't load default font.\n"));
737 void BScreen::readDatabaseFont(const char *rname, const char *rclass,
738 XFontStruct **font) {
741 static char *defaultFont = "fixed";
742 bool load_default = false;
746 XFreeFont(getBaseDisplay().getXDisplay(), *font);
748 if (resource.styleconfig.getValue(rname, rclass, s)) {
749 if ((*font = XLoadQueryFont(getBaseDisplay().getXDisplay(),
750 s.c_str())) == NULL) {
751 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenFontLoadFail,
752 "BScreen::LoadStyle(): couldn't load font '%s'\n"),
760 if ((*font = XLoadQueryFont(getBaseDisplay().getXDisplay(),
761 defaultFont)) == NULL) {
762 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenDefaultFontLoadFail,
763 "BScreen::LoadStyle(): couldn't load default font.\n"));
770 XFontSet BScreen::createFontSet(const char *fontname) {
772 char **missing, *def = "-";
773 int nmissing, pixel_size = 0, buf_size = 0;
774 char weight[FONT_ELEMENT_SIZE], slant[FONT_ELEMENT_SIZE];
776 fs = XCreateFontSet(getBaseDisplay().getXDisplay(),
777 fontname, &missing, &nmissing, &def);
778 if (fs && (! nmissing)) return fs;
780 #ifdef HAVE_SETLOCALE
782 if (nmissing) XFreeStringList(missing);
784 setlocale(LC_CTYPE, "C");
785 fs = XCreateFontSet(getBaseDisplay().getXDisplay(), fontname,
786 &missing, &nmissing, &def);
787 setlocale(LC_CTYPE, "");
789 #endif // HAVE_SETLOCALE
792 XFontStruct **fontstructs;
794 XFontsOfFontSet(fs, &fontstructs, &fontnames);
795 fontname = fontnames[0];
798 getFontElement(fontname, weight, FONT_ELEMENT_SIZE,
799 "-medium-", "-bold-", "-demibold-", "-regular-", NULL);
800 getFontElement(fontname, slant, FONT_ELEMENT_SIZE,
801 "-r-", "-i-", "-o-", "-ri-", "-ro-", NULL);
802 getFontSize(fontname, &pixel_size);
804 if (! strcmp(weight, "*")) strncpy(weight, "medium", FONT_ELEMENT_SIZE);
805 if (! strcmp(slant, "*")) strncpy(slant, "r", FONT_ELEMENT_SIZE);
806 if (pixel_size < 3) pixel_size = 3;
807 else if (pixel_size > 97) pixel_size = 97;
809 buf_size = strlen(fontname) + (FONT_ELEMENT_SIZE * 2) + 64;
810 char *pattern2 = new char[buf_size];
811 snprintf(pattern2, buf_size - 1,
813 "-*-*-%s-%s-*-*-%d-*-*-*-*-*-*-*,"
814 "-*-*-*-*-*-*-%d-*-*-*-*-*-*-*,*",
815 fontname, weight, slant, pixel_size, pixel_size);
818 if (nmissing) XFreeStringList(missing);
819 if (fs) XFreeFontSet(getBaseDisplay().getXDisplay(), fs);
821 fs = XCreateFontSet(getBaseDisplay().getXDisplay(), fontname,
822 &missing, &nmissing, &def);
829 void BScreen::setSloppyFocus(bool b) {
830 resource.sloppy_focus = b;
832 s << "session.screen" << getScreenNumber() << ".focusModel" << ends;
833 config.setValue(s.str(),
834 (resource.sloppy_focus ?
835 (resource.auto_raise ? "AutoRaiseSloppyFocus" : "SloppyFocus")
837 s.rdbuf()->freeze(0);
841 void BScreen::setAutoRaise(bool a) {
842 resource.auto_raise = a;
844 s << "session.screen" << getScreenNumber() << ".focusModel" << ends;
845 config.setValue(s.str(),
846 (resource.sloppy_focus ?
847 (resource.auto_raise ? "AutoRaiseSloppyFocus" : "SloppyFocus")
849 s.rdbuf()->freeze(0);
853 void BScreen::setImageDither(bool d) {
854 resource.image_dither = d;
856 s << "session.screen" << getScreenNumber() << ".imageDither" << ends;
857 config.setValue(s.str(), resource.image_dither);
858 s.rdbuf()->freeze(0);
862 void BScreen::setOpaqueMove(bool o) {
863 resource.opaque_move = o;
865 s << "session.screen" << getScreenNumber() << ".opaqueMove" << ends;
866 config.setValue(s.str(), resource.opaque_move);
867 s.rdbuf()->freeze(0);
871 void BScreen::setFullMax(bool f) {
872 resource.full_max = f;
874 s << "session.screen" << getScreenNumber() << ".fullMaximization" << ends;
875 config.setValue(s.str(), resource.full_max);
876 s.rdbuf()->freeze(0);
880 void BScreen::setFocusNew(bool f) {
881 resource.focus_new = f;
883 s << "session.screen" << getScreenNumber() << ".focusNewWindows" << ends;
884 config.setValue(s.str(), resource.focus_new);
885 s.rdbuf()->freeze(0);
889 void BScreen::setFocusLast(bool f) {
890 resource.focus_last = f;
892 s << "session.screen" << getScreenNumber() << ".focusLastWindow" << ends;
893 config.setValue(s.str(), resource.focus_last);
894 s.rdbuf()->freeze(0);
898 void BScreen::setWindowZones(int z) {
901 s << "session.screen" << getScreenNumber() << ".windowZones" << ends;
902 config.setValue(s.str(), resource.zones);
903 s.rdbuf()->freeze(0);
907 void BScreen::setWorkspaceCount(int w) {
908 resource.workspaces = w;
910 s << "session.screen" << getScreenNumber() << ".workspaces" << ends;
911 config.setValue(s.str(), resource.workspaces);
912 s.rdbuf()->freeze(0);
916 void BScreen::setPlacementPolicy(int p) {
917 resource.placement_policy = p;
919 s << "session.screen" << getScreenNumber() << ".windowPlacement" << ends;
920 const char *placement;
921 switch (resource.placement_policy) {
922 case CascadePlacement: placement = "CascadePlacement"; break;
923 case BestFitPlacement: placement = "BestFitPlacement"; break;
924 case ColSmartPlacement: placement = "ColSmartPlacement"; break;
926 case RowSmartPlacement: placement = "RowSmartPlacement"; break;
928 config.setValue(s.str(), placement);
929 s.rdbuf()->freeze(0);
933 void BScreen::setEdgeSnapThreshold(int t) {
934 resource.edge_snap_threshold = t;
936 s << "session.screen" << getScreenNumber() << ".edgeSnapThreshold" << ends;
937 config.setValue(s.str(), resource.edge_snap_threshold);
938 s.rdbuf()->freeze(0);
942 void BScreen::setRowPlacementDirection(int d) {
943 resource.row_direction = d;
945 s << "session.screen" << getScreenNumber() << ".rowPlacementDirection" <<
947 config.setValue(s.str(),
948 resource.row_direction == LeftRight ?
949 "LeftToRight" : "RightToLeft");
950 s.rdbuf()->freeze(0);
954 void BScreen::setColPlacementDirection(int d) {
955 resource.col_direction = d;
957 s << "session.screen" << getScreenNumber() << ".colPlacementDirection" <<
959 config.setValue(s.str(),
960 resource.col_direction == TopBottom ?
961 "TopToBottom" : "BottomToTop");
962 s.rdbuf()->freeze(0);
966 void BScreen::setRootCommand(const char *cmd) {
967 if (resource.root_command != NULL)
968 delete [] resource.root_command;
970 resource.root_command = bstrdup(cmd);
972 resource.root_command = NULL;
973 // this doesn't save to the Resources config because it can't be changed
974 // inside Openbox, and this way we dont add an empty command which would over-
975 // ride the styles command when none has been specified
980 void BScreen::setStrftimeFormat(const char *f) {
981 if (resource.strftime_format != NULL)
982 delete [] resource.strftime_format;
984 resource.strftime_format = bstrdup(f);
986 s << "session.screen" << getScreenNumber() << ".strftimeFormat" << ends;
987 config.setValue(s.str(), resource.strftime_format);
988 s.rdbuf()->freeze(0);
991 #else // !HAVE_STRFTIME
992 void BScreen::setDateFormat(int f) {
993 resource.date_format = f;
995 s << "session.screen" << getScreenNumber() << ".dateFormat" << ends;
996 config.setValue(s.str(), resource.date_format == B_EuropeanDate ?
997 "European" : "American");
998 s.rdbuf()->freeze(0);
1001 void BScreen::setClock24Hour(Bool c) {
1002 resource.clock24hour = c;
1004 s << "session.screen" << getScreenNumber() << ".clockFormat" << ends;
1005 config.setValue(s.str(), resource.clock24hour ? 24 : 12);
1006 s.rdbuf()->freeze(0);
1008 #endif // HAVE_STRFTIME
1010 void BScreen::setHideToolbar(bool b) {
1011 resource.hide_toolbar = b;
1012 if (resource.hide_toolbar)
1013 getToolbar()->unMapToolbar();
1015 getToolbar()->mapToolbar();
1017 s << "session.screen" << getScreenNumber() << ".hideToolbar" << ends;
1018 config.setValue(s.str(), resource.hide_toolbar ? "True" : "False");
1019 s.rdbuf()->freeze(0);
1022 void BScreen::saveWorkspaceNames() {
1023 ostrstream rc, names;
1025 for (int i = 0; i < resource.workspaces; i++) {
1026 Workspace *w = getWorkspace(i);
1028 names << w->getName();
1029 if (i < resource.workspaces-1)
1035 rc << "session.screen" << getScreenNumber() << ".workspaceNames" << ends;
1036 config.setValue(rc.str(), names.str());
1037 rc.rdbuf()->freeze(0);
1038 names.rdbuf()->freeze(0);
1041 void BScreen::save() {
1042 setSloppyFocus(resource.sloppy_focus);
1043 setAutoRaise(resource.auto_raise);
1044 setImageDither(resource.image_dither);
1045 setOpaqueMove(resource.opaque_move);
1046 setFullMax(resource.full_max);
1047 setFocusNew(resource.focus_new);
1048 setFocusLast(resource.focus_last);
1049 setWindowZones(resource.zones);
1050 setWorkspaceCount(resource.workspaces);
1051 setPlacementPolicy(resource.placement_policy);
1052 setEdgeSnapThreshold(resource.edge_snap_threshold);
1053 setRowPlacementDirection(resource.row_direction);
1054 setColPlacementDirection(resource.col_direction);
1055 setRootCommand(resource.root_command);
1056 #ifdef HAVE_STRFTIME
1057 // it deletes the current value before setting the new one, so we have to
1058 // duplicate the current value.
1059 std::string s = resource.strftime_format;
1060 setStrftimeFormat(s.c_str());
1061 #else // !HAVE_STRFTIME
1062 setDateFormat(resource.date_format);
1063 setClock24Hour(resource.clock24hour);
1064 #endif // HAVE_STRFTIME
1065 setHideToolbar(resource.hide_toolbar);
1068 void BScreen::load() {
1069 std::ostrstream rscreen, rname, rclass;
1073 rscreen << "session.screen" << getScreenNumber() << '.' << ends;
1075 rname << rscreen.str() << "hideToolbar" << ends;
1076 rclass << rscreen.str() << "HideToolbar" << ends;
1077 if (config.getValue(rname.str(), rclass.str(), b))
1078 resource.hide_toolbar = b;
1080 resource.hide_toolbar = false;
1081 Toolbar *t = getToolbar();
1083 if (resource.hide_toolbar)
1089 rname.seekp(0); rclass.seekp(0);
1090 rname << rscreen.str() << "fullMaximization" << ends;
1091 rclass << rscreen.str() << "FullMaximization" << ends;
1092 if (config.getValue(rname.str(), rclass.str(), b))
1093 resource.full_max = b;
1095 resource.full_max = false;
1097 rname.seekp(0); rclass.seekp(0);
1098 rname << rscreen.str() << "focusNewWindows" << ends;
1099 rclass << rscreen.str() << "FocusNewWindows" << ends;
1100 if (config.getValue(rname.str(), rclass.str(), b))
1101 resource.focus_new = b;
1103 resource.focus_new = false;
1105 rname.seekp(0); rclass.seekp(0);
1106 rname << rscreen.str() << "focusLastWindow" << ends;
1107 rclass << rscreen.str() << "FocusLastWindow" << ends;
1108 if (config.getValue(rname.str(), rclass.str(), b))
1109 resource.focus_last = b;
1111 resource.focus_last = false;
1113 rname.seekp(0); rclass.seekp(0);
1114 rname << rscreen.str() << "rowPlacementDirection" << ends;
1115 rclass << rscreen.str() << "RowPlacementDirection" << ends;
1116 if (config.getValue(rname.str(), rclass.str(), s)) {
1117 if (0 == strncasecmp(s.c_str(), "RightToLeft", s.length()))
1118 resource.row_direction = RightLeft;
1119 else if (0 == strncasecmp(s.c_str(), "LeftToRight", s.length()))
1120 resource.row_direction = LeftRight;
1122 resource.row_direction = LeftRight;
1124 rname.seekp(0); rclass.seekp(0);
1125 rname << rscreen.str() << "colPlacementDirection" << ends;
1126 rclass << rscreen.str() << "ColPlacementDirection" << ends;
1127 if (config.getValue(rname.str(), rclass.str(), s)) {
1128 if (0 == strncasecmp(s.c_str(), "BottomToTop", s.length()))
1129 resource.col_direction = BottomTop;
1130 else if (0 == strncasecmp(s.c_str(), "TopToBottom", s.length()))
1131 resource.col_direction = TopBottom;
1133 resource.col_direction = TopBottom;
1135 rname.seekp(0); rclass.seekp(0);
1136 rname << rscreen.str() << "workspaces" << ends;
1137 rclass << rscreen.str() << "Workspaces" << ends;
1138 if (config.getValue(rname.str(), rclass.str(), l))
1139 resource.workspaces = l;
1141 resource.workspaces = 1;
1143 removeWorkspaceNames();
1144 rname.seekp(0); rclass.seekp(0);
1145 rname << rscreen.str() << "workspaceNames" << ends;
1146 rclass << rscreen.str() << "WorkspaceNames" << ends;
1147 if (config.getValue(rname.str(), rclass.str(), s)) {
1148 std::string::const_iterator it = s.begin(), end = s.end();
1150 std::string::const_iterator tmp = it;// current string.begin()
1151 it = std::find(tmp, end, ','); // look for comma between tmp and end
1152 std::string name(tmp, it); // name = s[tmp:it]
1153 addWorkspaceName(name.c_str());
1160 rname.seekp(0); rclass.seekp(0);
1161 rname << rscreen.str() << "focusModel" << ends;
1162 rclass << rscreen.str() << "FocusModel" << ends;
1163 if (config.getValue(rname.str(), rclass.str(), s)) {
1164 if (0 == strncasecmp(s.c_str(), "ClickToFocus", s.length())) {
1165 resource.auto_raise = false;
1166 resource.sloppy_focus = false;
1167 } else if (0 == strncasecmp(s.c_str(), "AutoRaiseSloppyFocus",
1169 resource.sloppy_focus = true;
1170 resource.auto_raise = true;
1171 } else if (0 == strncasecmp(s.c_str(), "SloppyFocus", s.length())) {
1172 resource.sloppy_focus = true;
1173 resource.auto_raise = false;
1176 resource.sloppy_focus = true;
1177 resource.auto_raise = false;
1180 rname.seekp(0); rclass.seekp(0);
1181 rname << rscreen.str() << "windowZones" << ends;
1182 rclass << rscreen.str() << "WindowZones" << ends;
1183 if (config.getValue(rname.str(), rclass.str(), l))
1184 resource.zones = (l == 1 || l == 2 || l == 4) ? l : 1;
1188 rname.seekp(0); rclass.seekp(0);
1189 rname << rscreen.str() << "windowPlacement" << ends;
1190 rclass << rscreen.str() << "WindowPlacement" << ends;
1191 if (config.getValue(rname.str(), rclass.str(), s)) {
1192 if (0 == strncasecmp(s.c_str(), "RowSmartPlacement", s.length()))
1193 resource.placement_policy = RowSmartPlacement;
1194 else if (0 == strncasecmp(s.c_str(), "ColSmartPlacement", s.length()))
1195 resource.placement_policy = ColSmartPlacement;
1196 else if (0 == strncasecmp(s.c_str(), "BestFitPlacement", s.length()))
1197 resource.placement_policy = BestFitPlacement;
1198 else if (0 == strncasecmp(s.c_str(), "CascadePlacement", s.length()))
1199 resource.placement_policy = CascadePlacement;
1201 resource.placement_policy = CascadePlacement;
1203 #ifdef HAVE_STRFTIME
1204 rname.seekp(0); rclass.seekp(0);
1205 rname << rscreen.str() << "strftimeFormat" << ends;
1206 rclass << rscreen.str() << "StrftimeFormat" << ends;
1208 if (resource.strftime_format != NULL)
1209 delete [] resource.strftime_format;
1211 if (config.getValue(rname.str(), rclass.str(), s))
1212 resource.strftime_format = bstrdup(s.c_str());
1214 resource.strftime_format = bstrdup("%I:%M %p");
1215 #else // !HAVE_STRFTIME
1216 rname.seekp(0); rclass.seekp(0);
1217 rname << rscreen.str() << "dateFormat" << ends;
1218 rclass << rscreen.str() << "DateFormat" << ends;
1219 if (config.getValue(rname.str(), rclass.str(), s)) {
1220 if (strncasecmp(s.c_str(), "European", s.length()))
1221 resource.date_format = B_EuropeanDate;
1222 else if (strncasecmp(s.c_str(), "American", s.length()))
1223 resource.date_format = B_AmericanDate;
1225 resource.date_format = B_AmericanDate;
1227 rname.seekp(0); rclass.seekp(0);
1228 rname << rscreen.str() << "clockFormat" << ends;
1229 rclass << rscreen.str() << "ClockFormat" << ends;
1230 if (config.getValue(rname.str(), rclass.str(), l)) {
1232 resource.clock24hour = true;
1233 else if (clock == 12)
1234 resource.clock24hour = false;
1236 resource.clock24hour = false;
1237 #endif // HAVE_STRFTIME
1239 rname.seekp(0); rclass.seekp(0);
1240 rname << rscreen.str() << "edgeSnapThreshold" << ends;
1241 rclass << rscreen.str() << "EdgeSnapThreshold" << ends;
1242 if (config.getValue(rname.str(), rclass.str(), l))
1243 resource.edge_snap_threshold = l;
1245 resource.edge_snap_threshold = 4;
1247 rname.seekp(0); rclass.seekp(0);
1248 rname << rscreen.str() << "imageDither" << ends;
1249 rclass << rscreen.str() << "ImageDither" << ends;
1250 if (config.getValue(rname.str(), rclass.str(), b))
1251 resource.image_dither = b;
1253 resource.image_dither = true;
1255 rname.seekp(0); rclass.seekp(0);
1256 rname << rscreen.str() << "rootCommand" << ends;
1257 rclass << rscreen.str() << "RootCommand" << ends;
1259 if (resource.root_command != NULL)
1260 delete [] resource.root_command;
1262 if (config.getValue(rname.str(), rclass.str(), s))
1263 resource.root_command = bstrdup(s.c_str());
1265 resource.root_command = NULL;
1267 rname.seekp(0); rclass.seekp(0);
1268 rname << rscreen.str() << "opaqueMove" << ends;
1269 rclass << rscreen.str() << "OpaqueMove" << ends;
1270 if (config.getValue(rname.str(), rclass.str(), b))
1271 resource.opaque_move = b;
1273 resource.opaque_move = false;
1275 rscreen.rdbuf()->freeze(0);
1276 rname.rdbuf()->freeze(0);
1277 rclass.rdbuf()->freeze(0);
1280 void BScreen::reconfigure(void) {
1289 unsigned long gc_value_mask = GCForeground;
1290 if (! i18n->multibyte()) gc_value_mask |= GCFont;
1292 gcv.foreground = WhitePixel(getBaseDisplay().getXDisplay(),
1294 gcv.function = GXinvert;
1295 gcv.subwindow_mode = IncludeInferiors;
1296 XChangeGC(getBaseDisplay().getXDisplay(), opGC,
1297 GCForeground | GCFunction | GCSubwindowMode, &gcv);
1299 gcv.foreground = resource.wstyle.l_text_focus.getPixel();
1300 if (resource.wstyle.font)
1301 gcv.font = resource.wstyle.font->fid;
1302 XChangeGC(getBaseDisplay().getXDisplay(), resource.wstyle.l_text_focus_gc,
1303 gc_value_mask, &gcv);
1305 gcv.foreground = resource.wstyle.l_text_unfocus.getPixel();
1306 XChangeGC(getBaseDisplay().getXDisplay(), resource.wstyle.l_text_unfocus_gc,
1307 gc_value_mask, &gcv);
1309 gcv.foreground = resource.wstyle.b_pic_focus.getPixel();
1310 XChangeGC(getBaseDisplay().getXDisplay(), resource.wstyle.b_pic_focus_gc,
1311 GCForeground, &gcv);
1313 gcv.foreground = resource.wstyle.b_pic_unfocus.getPixel();
1314 XChangeGC(getBaseDisplay().getXDisplay(), resource.wstyle.b_pic_unfocus_gc,
1315 GCForeground, &gcv);
1317 gcv.foreground = resource.mstyle.t_text.getPixel();
1318 if (resource.mstyle.t_font)
1319 gcv.font = resource.mstyle.t_font->fid;
1320 XChangeGC(getBaseDisplay().getXDisplay(), resource.mstyle.t_text_gc,
1321 gc_value_mask, &gcv);
1323 gcv.foreground = resource.mstyle.f_text.getPixel();
1324 if (resource.mstyle.f_font)
1325 gcv.font = resource.mstyle.f_font->fid;
1326 XChangeGC(getBaseDisplay().getXDisplay(), resource.mstyle.f_text_gc,
1327 gc_value_mask, &gcv);
1329 gcv.foreground = resource.mstyle.h_text.getPixel();
1330 XChangeGC(getBaseDisplay().getXDisplay(), resource.mstyle.h_text_gc,
1331 gc_value_mask, &gcv);
1333 gcv.foreground = resource.mstyle.d_text.getPixel();
1334 XChangeGC(getBaseDisplay().getXDisplay(), resource.mstyle.d_text_gc,
1335 gc_value_mask, &gcv);
1337 gcv.foreground = resource.mstyle.hilite.getColor()->getPixel();
1338 XChangeGC(getBaseDisplay().getXDisplay(), resource.mstyle.hilite_gc,
1339 gc_value_mask, &gcv);
1341 gcv.foreground = resource.tstyle.l_text.getPixel();
1342 if (resource.tstyle.font)
1343 gcv.font = resource.tstyle.font->fid;
1344 XChangeGC(getBaseDisplay().getXDisplay(), resource.tstyle.l_text_gc,
1345 gc_value_mask, &gcv);
1347 gcv.foreground = resource.tstyle.w_text.getPixel();
1348 XChangeGC(getBaseDisplay().getXDisplay(), resource.tstyle.w_text_gc,
1349 gc_value_mask, &gcv);
1351 gcv.foreground = resource.tstyle.c_text.getPixel();
1352 XChangeGC(getBaseDisplay().getXDisplay(), resource.tstyle.c_text_gc,
1353 gc_value_mask, &gcv);
1355 gcv.foreground = resource.tstyle.b_pic.getPixel();
1356 XChangeGC(getBaseDisplay().getXDisplay(), resource.tstyle.b_pic_gc,
1357 gc_value_mask, &gcv);
1359 const char *s = i18n->getMessage(ScreenSet, ScreenPositionLength,
1360 "0: 0000 x 0: 0000");
1363 if (i18n->multibyte()) {
1364 XRectangle ink, logical;
1365 XmbTextExtents(resource.wstyle.fontset, s, l, &ink, &logical);
1366 geom_w = logical.width;
1368 geom_h = resource.wstyle.fontset_extents->max_ink_extent.height;
1370 geom_w = XTextWidth(resource.wstyle.font, s, l);
1372 geom_h = resource.wstyle.font->ascent +
1373 resource.wstyle.font->descent;
1376 geom_w += (resource.bevel_width * 2);
1377 geom_h += (resource.bevel_width * 2);
1379 Pixmap tmp = geom_pixmap;
1380 if (resource.wstyle.l_focus.getTexture() & BImage_ParentRelative) {
1381 if (resource.wstyle.t_focus.getTexture() ==
1382 (BImage_Flat | BImage_Solid)) {
1384 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window,
1385 resource.wstyle.t_focus.getColor()->getPixel());
1387 geom_pixmap = image_control->renderImage(geom_w, geom_h,
1388 &resource.wstyle.t_focus);
1389 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
1390 geom_window, geom_pixmap);
1393 if (resource.wstyle.l_focus.getTexture() ==
1394 (BImage_Flat | BImage_Solid)) {
1396 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window,
1397 resource.wstyle.l_focus.getColor()->getPixel());
1399 geom_pixmap = image_control->renderImage(geom_w, geom_h,
1400 &resource.wstyle.l_focus);
1401 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
1402 geom_window, geom_pixmap);
1405 if (tmp) image_control->removeImage(tmp);
1407 XSetWindowBorderWidth(getBaseDisplay().getXDisplay(), geom_window,
1408 resource.border_width);
1409 XSetWindowBorder(getBaseDisplay().getXDisplay(), geom_window,
1410 resource.border_color.getPixel());
1412 workspacemenu->reconfigure();
1413 iconmenu->reconfigure();
1416 int remember_sub = rootmenu->getCurrentSubmenu();
1419 rootmenu->reconfigure();
1420 rootmenu->drawSubmenu(remember_sub);
1423 configmenu->reconfigure();
1425 toolbar->reconfigure();
1428 slit->reconfigure();
1431 LinkedListIterator<Workspace> wit(workspacesList);
1432 for (Workspace *w = wit.current(); w; wit++, w = wit.current())
1435 LinkedListIterator<OpenboxWindow> iit(iconList);
1436 for (OpenboxWindow *bw = iit.current(); bw; iit++, bw = iit.current())
1437 if (bw->validateClient())
1440 image_control->timeout();
1444 void BScreen::rereadMenu(void) {
1448 rootmenu->reconfigure();
1452 void BScreen::removeWorkspaceNames(void) {
1453 while (workspaceNames->count())
1454 delete [] workspaceNames->remove(0);
1458 void BScreen::LoadStyle(void) {
1459 Resource &conf = resource.styleconfig;
1461 const char *sfile = openbox.getStyleFilename();
1462 bool loaded = false;
1463 if (sfile != NULL) {
1464 conf.setFile(sfile);
1465 loaded = conf.load();
1468 conf.setFile(DEFAULTSTYLE);
1470 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenDefaultStyleLoadFail,
1471 "BScreen::LoadStyle(): couldn't load "
1472 "default style.\n"));
1480 // load fonts/fontsets
1482 if (i18n->multibyte()) {
1483 readDatabaseFontSet("window.font", "Window.Font",
1484 &resource.wstyle.fontset);
1485 readDatabaseFontSet("toolbar.font", "Toolbar.Font",
1486 &resource.tstyle.fontset);
1487 readDatabaseFontSet("menu.title.font", "Menu.Title.Font",
1488 &resource.mstyle.t_fontset);
1489 readDatabaseFontSet("menu.frame.font", "Menu.Frame.Font",
1490 &resource.mstyle.f_fontset);
1492 resource.mstyle.t_fontset_extents =
1493 XExtentsOfFontSet(resource.mstyle.t_fontset);
1494 resource.mstyle.f_fontset_extents =
1495 XExtentsOfFontSet(resource.mstyle.f_fontset);
1496 resource.tstyle.fontset_extents =
1497 XExtentsOfFontSet(resource.tstyle.fontset);
1498 resource.wstyle.fontset_extents =
1499 XExtentsOfFontSet(resource.wstyle.fontset);
1501 readDatabaseFont("window.font", "Window.Font",
1502 &resource.wstyle.font);
1503 readDatabaseFont("menu.title.font", "Menu.Title.Font",
1504 &resource.mstyle.t_font);
1505 readDatabaseFont("menu.frame.font", "Menu.Frame.Font",
1506 &resource.mstyle.f_font);
1507 readDatabaseFont("toolbar.font", "Toolbar.Font",
1508 &resource.tstyle.font);
1511 // load window config
1512 readDatabaseTexture("window.title.focus", "Window.Title.Focus",
1513 &resource.wstyle.t_focus,
1514 WhitePixel(getBaseDisplay().getXDisplay(),
1515 getScreenNumber()));
1516 readDatabaseTexture("window.title.unfocus", "Window.Title.Unfocus",
1517 &resource.wstyle.t_unfocus,
1518 BlackPixel(getBaseDisplay().getXDisplay(),
1519 getScreenNumber()));
1520 readDatabaseTexture("window.label.focus", "Window.Label.Focus",
1521 &resource.wstyle.l_focus,
1522 WhitePixel(getBaseDisplay().getXDisplay(),
1523 getScreenNumber()));
1524 readDatabaseTexture("window.label.unfocus", "Window.Label.Unfocus",
1525 &resource.wstyle.l_unfocus,
1526 BlackPixel(getBaseDisplay().getXDisplay(),
1527 getScreenNumber()));
1528 readDatabaseTexture("window.handle.focus", "Window.Handle.Focus",
1529 &resource.wstyle.h_focus,
1530 WhitePixel(getBaseDisplay().getXDisplay(),
1531 getScreenNumber()));
1532 readDatabaseTexture("window.handle.unfocus", "Window.Handle.Unfocus",
1533 &resource.wstyle.h_unfocus,
1534 BlackPixel(getBaseDisplay().getXDisplay(),
1535 getScreenNumber()));
1536 readDatabaseTexture("window.grip.focus", "Window.Grip.Focus",
1537 &resource.wstyle.g_focus,
1538 WhitePixel(getBaseDisplay().getXDisplay(),
1539 getScreenNumber()));
1540 readDatabaseTexture("window.grip.unfocus", "Window.Grip.Unfocus",
1541 &resource.wstyle.g_unfocus,
1542 BlackPixel(getBaseDisplay().getXDisplay(),
1543 getScreenNumber()));
1544 readDatabaseTexture("window.button.focus", "Window.Button.Focus",
1545 &resource.wstyle.b_focus,
1546 WhitePixel(getBaseDisplay().getXDisplay(),
1547 getScreenNumber()));
1548 readDatabaseTexture("window.button.unfocus", "Window.Button.Unfocus",
1549 &resource.wstyle.b_unfocus,
1550 BlackPixel(getBaseDisplay().getXDisplay(),
1551 getScreenNumber()));
1552 readDatabaseTexture("window.button.pressed", "Window.Button.Pressed",
1553 &resource.wstyle.b_pressed,
1554 BlackPixel(getBaseDisplay().getXDisplay(),
1555 getScreenNumber()));
1556 readDatabaseColor("window.frame.focusColor",
1557 "Window.Frame.FocusColor",
1558 &resource.wstyle.f_focus,
1559 WhitePixel(getBaseDisplay().getXDisplay(),
1560 getScreenNumber()));
1561 readDatabaseColor("window.frame.unfocusColor",
1562 "Window.Frame.UnfocusColor",
1563 &resource.wstyle.f_unfocus,
1564 BlackPixel(getBaseDisplay().getXDisplay(),
1565 getScreenNumber()));
1566 readDatabaseColor("window.label.focus.textColor",
1567 "Window.Label.Focus.TextColor",
1568 &resource.wstyle.l_text_focus,
1569 BlackPixel(getBaseDisplay().getXDisplay(),
1570 getScreenNumber()));
1571 readDatabaseColor("window.label.unfocus.textColor",
1572 "Window.Label.Unfocus.TextColor",
1573 &resource.wstyle.l_text_unfocus,
1574 WhitePixel(getBaseDisplay().getXDisplay(),
1575 getScreenNumber()));
1576 readDatabaseColor("window.button.focus.picColor",
1577 "Window.Button.Focus.PicColor",
1578 &resource.wstyle.b_pic_focus,
1579 BlackPixel(getBaseDisplay().getXDisplay(),
1580 getScreenNumber()));
1581 readDatabaseColor("window.button.unfocus.picColor",
1582 "Window.Button.Unfocus.PicColor",
1583 &resource.wstyle.b_pic_unfocus,
1584 WhitePixel(getBaseDisplay().getXDisplay(),
1585 getScreenNumber()));
1587 if (conf.getValue("window.justify", "Window.Justify", s)) {
1588 if (0 == strncasecmp(s.c_str(), "right", s.length()))
1589 resource.wstyle.justify = BScreen::RightJustify;
1590 else if (0 == strncasecmp(s.c_str(), "center", s.length()))
1591 resource.wstyle.justify = BScreen::CenterJustify;
1593 resource.wstyle.justify = BScreen::LeftJustify;
1595 resource.wstyle.justify = BScreen::LeftJustify;
1597 // load toolbar config
1598 readDatabaseTexture("toolbar", "Toolbar",
1599 &resource.tstyle.toolbar,
1600 BlackPixel(getBaseDisplay().getXDisplay(),
1601 getScreenNumber()));
1602 readDatabaseTexture("toolbar.label", "Toolbar.Label",
1603 &resource.tstyle.label,
1604 BlackPixel(getBaseDisplay().getXDisplay(),
1605 getScreenNumber()));
1606 readDatabaseTexture("toolbar.windowLabel", "Toolbar.WindowLabel",
1607 &resource.tstyle.window,
1608 BlackPixel(getBaseDisplay().getXDisplay(),
1609 getScreenNumber()));
1610 readDatabaseTexture("toolbar.button", "Toolbar.Button",
1611 &resource.tstyle.button,
1612 WhitePixel(getBaseDisplay().getXDisplay(),
1613 getScreenNumber()));
1614 readDatabaseTexture("toolbar.button.pressed", "Toolbar.Button.Pressed",
1615 &resource.tstyle.pressed,
1616 BlackPixel(getBaseDisplay().getXDisplay(),
1617 getScreenNumber()));
1618 readDatabaseTexture("toolbar.clock", "Toolbar.Clock",
1619 &resource.tstyle.clock,
1620 BlackPixel(getBaseDisplay().getXDisplay(),
1621 getScreenNumber()));
1622 readDatabaseColor("toolbar.label.textColor", "Toolbar.Label.TextColor",
1623 &resource.tstyle.l_text,
1624 WhitePixel(getBaseDisplay().getXDisplay(),
1625 getScreenNumber()));
1626 readDatabaseColor("toolbar.windowLabel.textColor",
1627 "Toolbar.WindowLabel.TextColor",
1628 &resource.tstyle.w_text,
1629 WhitePixel(getBaseDisplay().getXDisplay(),
1630 getScreenNumber()));
1631 readDatabaseColor("toolbar.clock.textColor", "Toolbar.Clock.TextColor",
1632 &resource.tstyle.c_text,
1633 WhitePixel(getBaseDisplay().getXDisplay(),
1634 getScreenNumber()));
1635 readDatabaseColor("toolbar.button.picColor", "Toolbar.Button.PicColor",
1636 &resource.tstyle.b_pic,
1637 BlackPixel(getBaseDisplay().getXDisplay(),
1638 getScreenNumber()));
1640 if (conf.getValue("toolbar.justify", "Toolbar.Justify", s)) {
1641 if (0 == strncasecmp(s.c_str(), "right", s.length()))
1642 resource.tstyle.justify = BScreen::RightJustify;
1643 else if (0 == strncasecmp(s.c_str(), "center", s.length()))
1644 resource.tstyle.justify = BScreen::CenterJustify;
1646 resource.tstyle.justify = BScreen::LeftJustify;
1648 resource.tstyle.justify = BScreen::LeftJustify;
1651 readDatabaseTexture("menu.title", "Menu.Title",
1652 &resource.mstyle.title,
1653 WhitePixel(getBaseDisplay().getXDisplay(),
1654 getScreenNumber()));
1655 readDatabaseTexture("menu.frame", "Menu.Frame",
1656 &resource.mstyle.frame,
1657 BlackPixel(getBaseDisplay().getXDisplay(),
1658 getScreenNumber()));
1659 readDatabaseTexture("menu.hilite", "Menu.Hilite",
1660 &resource.mstyle.hilite,
1661 WhitePixel(getBaseDisplay().getXDisplay(),
1662 getScreenNumber()));
1663 readDatabaseColor("menu.title.textColor", "Menu.Title.TextColor",
1664 &resource.mstyle.t_text,
1665 BlackPixel(getBaseDisplay().getXDisplay(),
1666 getScreenNumber()));
1667 readDatabaseColor("menu.frame.textColor", "Menu.Frame.TextColor",
1668 &resource.mstyle.f_text,
1669 WhitePixel(getBaseDisplay().getXDisplay(),
1670 getScreenNumber()));
1671 readDatabaseColor("menu.frame.disableColor", "Menu.Frame.DisableColor",
1672 &resource.mstyle.d_text,
1673 BlackPixel(getBaseDisplay().getXDisplay(),
1674 getScreenNumber()));
1675 readDatabaseColor("menu.hilite.textColor", "Menu.Hilite.TextColor",
1676 &resource.mstyle.h_text,
1677 BlackPixel(getBaseDisplay().getXDisplay(),
1678 getScreenNumber()));
1680 if (conf.getValue("menu.title.justify", "Menu.Title.Justify", s)) {
1681 if (0 == strncasecmp(s.c_str(), "right", s.length()))
1682 resource.mstyle.t_justify = BScreen::RightJustify;
1683 else if (0 == strncasecmp(s.c_str(), "center", s.length()))
1684 resource.mstyle.t_justify = BScreen::CenterJustify;
1686 resource.mstyle.t_justify = BScreen::LeftJustify;
1688 resource.mstyle.t_justify = BScreen::LeftJustify;
1690 if (conf.getValue("menu.frame.justify", "Menu.Frame.Justify", s)) {
1691 if (0 == strncasecmp(s.c_str(), "right", s.length()))
1692 resource.mstyle.f_justify = BScreen::RightJustify;
1693 else if (0 == strncasecmp(s.c_str(), "center", s.length()))
1694 resource.mstyle.f_justify = BScreen::CenterJustify;
1696 resource.mstyle.f_justify = BScreen::LeftJustify;
1698 resource.mstyle.f_justify = BScreen::LeftJustify;
1700 if (conf.getValue("menu.bullet", "Menu.Bullet", s)) {
1701 if (0 == strncasecmp(s.c_str(), "empty", s.length()))
1702 resource.mstyle.bullet = Basemenu::Empty;
1703 else if (0 == strncasecmp(s.c_str(), "square", s.length()))
1704 resource.mstyle.bullet = Basemenu::Square;
1705 else if (0 == strncasecmp(s.c_str(), "diamond", s.length()))
1706 resource.mstyle.bullet = Basemenu::Diamond;
1708 resource.mstyle.bullet = Basemenu::Triangle;
1710 resource.mstyle.bullet = Basemenu::Triangle;
1712 if (conf.getValue("menu.bullet.position", "Menu.Bullet.Position", s)) {
1713 if (0 == strncasecmp(s.c_str(), "right", s.length()))
1714 resource.mstyle.bullet_pos = Basemenu::Right;
1716 resource.mstyle.bullet_pos = Basemenu::Left;
1718 resource.mstyle.bullet_pos = Basemenu::Left;
1720 readDatabaseColor("borderColor", "BorderColor", &resource.border_color,
1721 BlackPixel(getBaseDisplay().getXDisplay(),
1722 getScreenNumber()));
1724 // load bevel, border and handle widths
1725 if (conf.getValue("handleWidth", "HandleWidth", l)) {
1726 if (l <= size().w() / 2 && l != 0)
1727 resource.handle_width = l;
1729 resource.handle_width = 6;
1731 resource.handle_width = 6;
1733 if (conf.getValue("borderWidth", "BorderWidth", l))
1734 resource.border_width = l;
1736 resource.border_width = 1;
1738 if (conf.getValue("bevelWidth", "BevelWidth", l)) {
1739 if (l <= size().w() / 2 && l != 0)
1740 resource.bevel_width = l;
1742 resource.bevel_width = 3;
1744 resource.bevel_width = 3;
1746 if (conf.getValue("frameWidth", "FrameWidth", l)) {
1747 if (l <= size().w() / 2)
1748 resource.frame_width = l;
1750 resource.frame_width = resource.bevel_width;
1752 resource.frame_width = resource.bevel_width;
1754 const char *cmd = resource.root_command;
1755 if (cmd != NULL || conf.getValue("rootCommand", "RootCommand", s)) {
1757 cmd = s.c_str(); // not specified by the screen, so use the one from the
1760 char displaystring[MAXPATHLEN];
1761 sprintf(displaystring, "DISPLAY=%s",
1762 DisplayString(getBaseDisplay().getXDisplay()));
1763 sprintf(displaystring + strlen(displaystring) - 1, "%d",
1766 bexec(cmd, displaystring);
1768 spawnlp(P_NOWAIT, "cmd.exe", "cmd.exe", "/c", cmd, NULL);
1774 void BScreen::addIcon(OpenboxWindow *w) {
1777 w->setWorkspace(-1);
1778 w->setWindowNumber(iconList->count());
1780 iconList->insert(w);
1782 iconmenu->insert((const char **) w->getIconTitle());
1787 void BScreen::removeIcon(OpenboxWindow *w) {
1790 iconList->remove(w->getWindowNumber());
1792 iconmenu->remove(w->getWindowNumber());
1795 LinkedListIterator<OpenboxWindow> it(iconList);
1796 OpenboxWindow *bw = it.current();
1797 for (int i = 0; bw; it++, bw = it.current())
1798 bw->setWindowNumber(i++);
1802 OpenboxWindow *BScreen::getIcon(int index) {
1803 if (index >= 0 && index < iconList->count())
1804 return iconList->find(index);
1810 int BScreen::addWorkspace(void) {
1811 Workspace *wkspc = new Workspace(*this, workspacesList->count());
1812 workspacesList->insert(wkspc);
1813 saveWorkspaceNames();
1815 workspacemenu->insert(wkspc->getName(), wkspc->getMenu(),
1816 wkspc->getWorkspaceID() + 2);
1817 workspacemenu->update();
1819 toolbar->reconfigure();
1821 updateNetizenWorkspaceCount();
1823 return workspacesList->count();
1827 int BScreen::removeLastWorkspace(void) {
1828 if (workspacesList->count() == 1)
1831 Workspace *wkspc = workspacesList->last();
1833 if (current_workspace->getWorkspaceID() == wkspc->getWorkspaceID())
1834 changeWorkspaceID(current_workspace->getWorkspaceID() - 1);
1838 workspacemenu->remove(wkspc->getWorkspaceID() + 2);
1839 workspacemenu->update();
1841 workspacesList->remove(wkspc);
1844 toolbar->reconfigure();
1846 updateNetizenWorkspaceCount();
1848 return workspacesList->count();
1852 void BScreen::changeWorkspaceID(int id) {
1853 if (! current_workspace) return;
1855 if (id != current_workspace->getWorkspaceID()) {
1856 current_workspace->hideAll();
1858 workspacemenu->setItemSelected(current_workspace->getWorkspaceID() + 2,
1861 if (openbox.getFocusedWindow() &&
1862 openbox.getFocusedWindow()->getScreen() == this &&
1863 (! openbox.getFocusedWindow()->isStuck())) {
1864 current_workspace->setLastFocusedWindow(openbox.getFocusedWindow());
1865 openbox.setFocusedWindow(NULL);
1868 current_workspace = getWorkspace(id);
1870 workspacemenu->setItemSelected(current_workspace->getWorkspaceID() + 2,
1872 toolbar->redrawWorkspaceLabel(True);
1874 current_workspace->showAll();
1876 if (resource.focus_last && current_workspace->getLastFocusedWindow()) {
1877 XSync(openbox.getXDisplay(), False);
1878 current_workspace->getLastFocusedWindow()->setInputFocus();
1882 updateNetizenCurrentWorkspace();
1886 void BScreen::addNetizen(Netizen *n) {
1887 netizenList->insert(n);
1889 n->sendWorkspaceCount();
1890 n->sendCurrentWorkspace();
1892 LinkedListIterator<Workspace> it(workspacesList);
1893 for (Workspace *w = it.current(); w; it++, w = it.current()) {
1894 for (int i = 0; i < w->getCount(); i++)
1895 n->sendWindowAdd(w->getWindow(i)->getClientWindow(),
1896 w->getWorkspaceID());
1899 Window f = ((openbox.getFocusedWindow()) ?
1900 openbox.getFocusedWindow()->getClientWindow() : None);
1901 n->sendWindowFocus(f);
1905 void BScreen::removeNetizen(Window w) {
1906 LinkedListIterator<Netizen> it(netizenList);
1909 for (Netizen *n = it.current(); n; it++, i++, n = it.current())
1910 if (n->getWindowID() == w) {
1911 Netizen *tmp = netizenList->remove(i);
1919 void BScreen::updateNetizenCurrentWorkspace(void) {
1920 LinkedListIterator<Netizen> it(netizenList);
1921 for (Netizen *n = it.current(); n; it++, n = it.current())
1922 n->sendCurrentWorkspace();
1926 void BScreen::updateNetizenWorkspaceCount(void) {
1927 LinkedListIterator<Netizen> it(netizenList);
1928 for (Netizen *n = it.current(); n; it++, n = it.current())
1929 n->sendWorkspaceCount();
1933 void BScreen::updateNetizenWindowFocus(void) {
1934 Window f = ((openbox.getFocusedWindow()) ?
1935 openbox.getFocusedWindow()->getClientWindow() : None);
1936 LinkedListIterator<Netizen> it(netizenList);
1937 for (Netizen *n = it.current(); n; it++, n = it.current())
1938 n->sendWindowFocus(f);
1942 void BScreen::updateNetizenWindowAdd(Window w, unsigned long p) {
1943 LinkedListIterator<Netizen> it(netizenList);
1944 for (Netizen *n = it.current(); n; it++, n = it.current())
1945 n->sendWindowAdd(w, p);
1949 void BScreen::updateNetizenWindowDel(Window w) {
1950 LinkedListIterator<Netizen> it(netizenList);
1951 for (Netizen *n = it.current(); n; it++, n = it.current())
1952 n->sendWindowDel(w);
1956 void BScreen::updateNetizenWindowRaise(Window w) {
1957 LinkedListIterator<Netizen> it(netizenList);
1958 for (Netizen *n = it.current(); n; it++, n = it.current())
1959 n->sendWindowRaise(w);
1963 void BScreen::updateNetizenWindowLower(Window w) {
1964 LinkedListIterator<Netizen> it(netizenList);
1965 for (Netizen *n = it.current(); n; it++, n = it.current())
1966 n->sendWindowLower(w);
1970 void BScreen::updateNetizenConfigNotify(XEvent *e) {
1971 LinkedListIterator<Netizen> it(netizenList);
1972 for (Netizen *n = it.current(); n; it++, n = it.current())
1973 n->sendConfigNotify(e);
1977 void BScreen::raiseWindows(Window *workspace_stack, int num) {
1978 Window *session_stack = new
1979 Window[(num + workspacesList->count() + rootmenuList->count() + 13)];
1982 XRaiseWindow(getBaseDisplay().getXDisplay(), iconmenu->getWindowID());
1983 *(session_stack + i++) = iconmenu->getWindowID();
1985 LinkedListIterator<Workspace> wit(workspacesList);
1986 for (Workspace *tmp = wit.current(); tmp; wit++, tmp = wit.current())
1987 *(session_stack + i++) = tmp->getMenu()->getWindowID();
1989 *(session_stack + i++) = workspacemenu->getWindowID();
1991 *(session_stack + i++) = configmenu->getFocusmenu()->getWindowID();
1992 *(session_stack + i++) = configmenu->getPlacementmenu()->getWindowID();
1993 *(session_stack + i++) = configmenu->getWindowID();
1996 *(session_stack + i++) = slit->getMenu()->getDirectionmenu()->getWindowID();
1997 *(session_stack + i++) = slit->getMenu()->getPlacementmenu()->getWindowID();
1998 *(session_stack + i++) = slit->getMenu()->getWindowID();
2001 *(session_stack + i++) =
2002 toolbar->getMenu()->getPlacementmenu()->getWindowID();
2003 *(session_stack + i++) = toolbar->getMenu()->getWindowID();
2005 LinkedListIterator<Rootmenu> rit(rootmenuList);
2006 for (Rootmenu *tmp = rit.current(); tmp; rit++, tmp = rit.current())
2007 *(session_stack + i++) = tmp->getWindowID();
2008 *(session_stack + i++) = rootmenu->getWindowID();
2010 if (toolbar->onTop())
2011 *(session_stack + i++) = toolbar->getWindowID();
2015 *(session_stack + i++) = slit->getWindowID();
2019 *(session_stack + i++) = *(workspace_stack + k);
2021 XRestackWindows(getBaseDisplay().getXDisplay(), session_stack, i);
2023 delete [] session_stack;
2027 void BScreen::addWorkspaceName(const char *name) {
2028 workspaceNames->insert(bstrdup(name));
2031 char* BScreen::getNameOfWorkspace(int id) {
2034 if (id >= 0 && id < workspaceNames->count()) {
2035 char *wkspc_name = workspaceNames->find(id);
2044 void BScreen::reassociateWindow(OpenboxWindow *w, int wkspc_id, Bool ignore_sticky) {
2048 wkspc_id = current_workspace->getWorkspaceID();
2050 if (w->getWorkspaceNumber() == wkspc_id)
2053 if (w->isIconic()) {
2055 getWorkspace(wkspc_id)->addWindow(w);
2056 } else if (ignore_sticky || ! w->isStuck()) {
2057 getWorkspace(w->getWorkspaceNumber())->removeWindow(w);
2058 getWorkspace(wkspc_id)->addWindow(w);
2063 void BScreen::nextFocus(void) {
2064 Bool have_focused = False;
2065 int focused_window_number = -1;
2066 OpenboxWindow *next;
2068 if (openbox.getFocusedWindow()) {
2069 if (openbox.getFocusedWindow()->getScreen()->getScreenNumber() ==
2070 getScreenNumber()) {
2071 have_focused = True;
2072 focused_window_number = openbox.getFocusedWindow()->getWindowNumber();
2076 if ((getCurrentWorkspace()->getCount() > 1) && have_focused) {
2077 int next_window_number = focused_window_number;
2079 if ((++next_window_number) >= getCurrentWorkspace()->getCount())
2080 next_window_number = 0;
2082 next = getCurrentWorkspace()->getWindow(next_window_number);
2083 } while ((! next->setInputFocus()) && (next_window_number !=
2084 focused_window_number));
2086 if (next_window_number != focused_window_number)
2087 getCurrentWorkspace()->raiseWindow(next);
2088 } else if (getCurrentWorkspace()->getCount() >= 1) {
2089 next = current_workspace->getWindow(0);
2091 current_workspace->raiseWindow(next);
2092 next->setInputFocus();
2097 void BScreen::prevFocus(void) {
2098 Bool have_focused = False;
2099 int focused_window_number = -1;
2100 OpenboxWindow *prev;
2102 if (openbox.getFocusedWindow()) {
2103 if (openbox.getFocusedWindow()->getScreen()->getScreenNumber() ==
2104 getScreenNumber()) {
2105 have_focused = True;
2106 focused_window_number = openbox.getFocusedWindow()->getWindowNumber();
2110 if ((getCurrentWorkspace()->getCount() > 1) && have_focused) {
2111 int prev_window_number = focused_window_number;
2113 if ((--prev_window_number) < 0)
2114 prev_window_number = getCurrentWorkspace()->getCount() - 1;
2116 prev = getCurrentWorkspace()->getWindow(prev_window_number);
2117 } while ((! prev->setInputFocus()) && (prev_window_number !=
2118 focused_window_number));
2120 if (prev_window_number != focused_window_number)
2121 getCurrentWorkspace()->raiseWindow(prev);
2122 } else if (getCurrentWorkspace()->getCount() >= 1) {
2123 prev = current_workspace->getWindow(0);
2125 current_workspace->raiseWindow(prev);
2126 prev->setInputFocus();
2131 void BScreen::raiseFocus(void) {
2132 Bool have_focused = False;
2133 int focused_window_number = -1;
2135 if (openbox.getFocusedWindow()) {
2136 if (openbox.getFocusedWindow()->getScreen()->getScreenNumber() ==
2137 getScreenNumber()) {
2138 have_focused = True;
2139 focused_window_number = openbox.getFocusedWindow()->getWindowNumber();
2143 if ((getCurrentWorkspace()->getCount() > 1) && have_focused)
2144 getWorkspace(openbox.getFocusedWindow()->getWorkspaceNumber())->
2145 raiseWindow(openbox.getFocusedWindow());
2149 void BScreen::InitMenu(void) {
2151 while (rootmenuList->count())
2152 rootmenuList->remove(0);
2154 while (rootmenu->getCount())
2155 rootmenu->remove(0);
2157 rootmenu = new Rootmenu(*this);
2159 Bool defaultMenu = True;
2161 if (openbox.getMenuFilename()) {
2162 FILE *menu_file = fopen(openbox.getMenuFilename(), "r");
2165 perror(openbox.getMenuFilename());
2167 if (feof(menu_file)) {
2168 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenEmptyMenuFile,
2169 "%s: Empty menu file"),
2170 openbox.getMenuFilename());
2172 char line[1024], label[1024];
2173 memset(line, 0, 1024);
2174 memset(label, 0, 1024);
2176 while (fgets(line, 1024, menu_file) && ! feof(menu_file)) {
2177 if (line[0] != '#') {
2178 int i, key = 0, index = -1, len = strlen(line);
2181 for (i = 0; i < len; i++) {
2182 if (line[i] == '[') index = 0;
2183 else if (line[i] == ']') break;
2184 else if (line[i] != ' ')
2186 key += tolower(line[i]);
2191 for (i = index; i < len; i++) {
2192 if (line[i] == '(') index = 0;
2193 else if (line[i] == ')') break;
2194 else if (index++ >= 0) {
2195 if (line[i] == '\\' && i < len - 1) i++;
2196 label[index - 1] = line[i];
2200 if (index == -1) index = 0;
2201 label[index] = '\0';
2203 rootmenu->setLabel(label);
2204 defaultMenu = parseMenuFile(menu_file, rootmenu);
2215 rootmenu->setInternalMenu();
2216 rootmenu->insert(i18n->getMessage(ScreenSet, Screenxterm, "xterm"),
2218 i18n->getMessage(ScreenSet, Screenxterm, "xterm"));
2219 rootmenu->insert(i18n->getMessage(ScreenSet, ScreenRestart, "Restart"),
2221 rootmenu->insert(i18n->getMessage(ScreenSet, ScreenExit, "Exit"),
2224 openbox.setMenuFilename(openbox.getMenuFilename());
2229 Bool BScreen::parseMenuFile(FILE *file, Rootmenu *menu) {
2230 char line[1024], label[1024], command[1024];
2232 while (! feof(file)) {
2233 memset(line, 0, 1024);
2234 memset(label, 0, 1024);
2235 memset(command, 0, 1024);
2237 if (fgets(line, 1024, file)) {
2238 if (line[0] != '#') {
2239 register int i, key = 0, parse = 0, index = -1,
2240 line_length = strlen(line),
2241 label_length = 0, command_length = 0;
2243 // determine the keyword
2245 for (i = 0; i < line_length; i++) {
2246 if (line[i] == '[') parse = 1;
2247 else if (line[i] == ']') break;
2248 else if (line[i] != ' ')
2250 key += tolower(line[i]);
2253 // get the label enclosed in ()'s
2256 for (i = 0; i < line_length; i++) {
2257 if (line[i] == '(') {
2260 } else if (line[i] == ')') break;
2261 else if (index++ >= 0) {
2262 if (line[i] == '\\' && i < line_length - 1) i++;
2263 label[index - 1] = line[i];
2268 label[index] = '\0';
2269 label_length = index;
2275 // get the command enclosed in {}'s
2278 for (i = 0; i < line_length; i++) {
2279 if (line[i] == '{') {
2282 } else if (line[i] == '}') break;
2283 else if (index++ >= 0) {
2284 if (line[i] == '\\' && i < line_length - 1) i++;
2285 command[index - 1] = line[i];
2290 command[index] = '\0';
2291 command_length = index;
2299 return ((menu->getCount() == 0) ? True : False);
2304 menu->insert(label);
2309 if ((! *label) && (! *command)) {
2310 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenEXECError,
2311 "BScreen::parseMenuFile: [exec] error, "
2312 "no menu label and/or command defined\n"));
2316 menu->insert(label, BScreen::Execute, command);
2322 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenEXITError,
2323 "BScreen::parseMenuFile: [exit] error, "
2324 "no menu label defined\n"));
2328 menu->insert(label, BScreen::Exit);
2334 if ((! *label) || (! *command)) {
2335 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenSTYLEError,
2336 "BScreen::parseMenuFile: [style] error, "
2337 "no menu label and/or filename defined\n"));
2341 char style[MAXPATHLEN];
2343 // perform shell style ~ home directory expansion
2345 int homedir_len = 0;
2346 if (*command == '~' && *(command + 1) == '/') {
2347 homedir = getenv("HOME");
2348 homedir_len = strlen(homedir);
2351 if (homedir && homedir_len != 0) {
2352 strncpy(style, homedir, homedir_len);
2354 strncpy(style + homedir_len, command + 1,
2355 command_length - 1);
2356 *(style + command_length + homedir_len - 1) = '\0';
2358 strncpy(style, command, command_length);
2359 *(style + command_length) = '\0';
2362 menu->insert(label, BScreen::SetStyle, style);
2369 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenCONFIGError,
2370 "BScreen::parseMenufile: [config] error, "
2371 "no label defined"));
2375 menu->insert(label, configmenu);
2379 case 740: // include
2382 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenINCLUDEError,
2383 "BScreen::parseMenuFile: [include] error, "
2384 "no filename defined\n"));
2388 char newfile[MAXPATHLEN];
2390 // perform shell style ~ home directory expansion
2392 int homedir_len = 0;
2393 if (*label == '~' && *(label + 1) == '/') {
2394 homedir = getenv("HOME");
2395 homedir_len = strlen(homedir);
2398 if (homedir && homedir_len != 0) {
2399 strncpy(newfile, homedir, homedir_len);
2401 strncpy(newfile + homedir_len, label + 1,
2403 *(newfile + label_length + homedir_len - 1) = '\0';
2405 strncpy(newfile, label, label_length);
2406 *(newfile + label_length) = '\0';
2410 FILE *submenufile = fopen(newfile, "r");
2414 if (fstat(fileno(submenufile), &buf) ||
2415 (! S_ISREG(buf.st_mode))) {
2417 i18n->getMessage(ScreenSet, ScreenINCLUDEErrorReg,
2418 "BScreen::parseMenuFile: [include] error: "
2419 "'%s' is not a regular file\n"), newfile);
2423 if (! feof(submenufile)) {
2424 if (! parseMenuFile(submenufile, menu))
2425 openbox.setMenuFilename(newfile);
2427 fclose(submenufile);
2436 case 767: // submenu
2439 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenSUBMENUError,
2440 "BScreen::parseMenuFile: [submenu] error, "
2441 "no menu label defined\n"));
2445 Rootmenu *submenu = new Rootmenu(*this);
2448 submenu->setLabel(command);
2450 submenu->setLabel(label);
2452 parseMenuFile(file, submenu);
2454 menu->insert(label, submenu);
2455 rootmenuList->insert(submenu);
2460 case 773: // restart
2463 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenRESTARTError,
2464 "BScreen::parseMenuFile: [restart] error, "
2465 "no menu label defined\n"));
2470 menu->insert(label, BScreen::RestartOther, command);
2472 menu->insert(label, BScreen::Restart);
2477 case 845: // reconfig
2480 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenRECONFIGError,
2481 "BScreen::parseMenuFile: [reconfig] error, "
2482 "no menu label defined\n"));
2486 menu->insert(label, BScreen::Reconfigure);
2491 case 995: // stylesdir
2492 case 1113: // stylesmenu
2494 Bool newmenu = ((key == 1113) ? True : False);
2496 if ((! *label) || ((! *command) && newmenu)) {
2498 i18n->getMessage(ScreenSet, ScreenSTYLESDIRError,
2499 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
2500 " error, no directory defined\n"));
2504 char stylesdir[MAXPATHLEN];
2506 char *directory = ((newmenu) ? command : label);
2507 int directory_length = ((newmenu) ? command_length : label_length);
2509 // perform shell style ~ home directory expansion
2511 int homedir_len = 0;
2513 if (*directory == '~' && *(directory + 1) == '/') {
2514 homedir = getenv("HOME");
2515 homedir_len = strlen(homedir);
2518 if (homedir && homedir_len != 0) {
2519 strncpy(stylesdir, homedir, homedir_len);
2521 strncpy(stylesdir + homedir_len, directory + 1,
2522 directory_length - 1);
2523 *(stylesdir + directory_length + homedir_len - 1) = '\0';
2525 strncpy(stylesdir, directory, directory_length);
2526 *(stylesdir + directory_length) = '\0';
2529 struct stat statbuf;
2531 if (! stat(stylesdir, &statbuf)) {
2532 if (S_ISDIR(statbuf.st_mode)) {
2533 Rootmenu *stylesmenu;
2536 stylesmenu = new Rootmenu(*this);
2540 DIR *d = opendir(stylesdir);
2544 // get the total number of directory entries
2545 while ((p = readdir(d))) entries++;
2548 char **ls = new char* [entries];
2550 while ((p = readdir(d)))
2551 ls[index++] = bstrdup(p->d_name);
2555 std::sort(ls, ls + entries, dcmp());
2557 int n, slen = strlen(stylesdir);
2558 for (n = 0; n < entries; n++) {
2559 if (ls[n][strlen(ls[n])-1] != '~') {
2560 int nlen = strlen(ls[n]);
2561 char style[MAXPATHLEN + 1];
2563 strncpy(style, stylesdir, slen);
2564 *(style + slen) = '/';
2565 strncpy(style + slen + 1, ls[n], nlen + 1);
2567 if ((! stat(style, &statbuf)) && S_ISREG(statbuf.st_mode))
2568 stylesmenu->insert(ls[n], BScreen::SetStyle, style);
2576 stylesmenu->update();
2579 stylesmenu->setLabel(label);
2580 menu->insert(label, stylesmenu);
2581 rootmenuList->insert(stylesmenu);
2584 openbox.setMenuFilename(stylesdir);
2586 fprintf(stderr, i18n->getMessage(ScreenSet,
2587 ScreenSTYLESDIRErrorNotDir,
2588 "BScreen::parseMenuFile:"
2589 " [stylesdir/stylesmenu] error, %s is not a"
2590 " directory\n"), stylesdir);
2594 i18n->getMessage(ScreenSet, ScreenSTYLESDIRErrorNoExist,
2595 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
2596 " error, %s does not exist\n"), stylesdir);
2602 case 1090: // workspaces
2606 i18n->getMessage(ScreenSet, ScreenWORKSPACESError,
2607 "BScreen:parseMenuFile: [workspaces] error, "
2608 "no menu label defined\n"));
2612 menu->insert(label, workspacemenu);
2621 return ((menu->getCount() == 0) ? True : False);
2625 void BScreen::shutdown(void) {
2628 XSelectInput(getBaseDisplay().getXDisplay(), getRootWindow(), NoEventMask);
2629 XSync(getBaseDisplay().getXDisplay(), False);
2631 LinkedListIterator<Workspace> it(workspacesList);
2632 for (Workspace *w = it.current(); w; it++, w = it.current())
2635 while (iconList->count()) {
2636 iconList->first()->restore();
2637 delete iconList->first();
2648 void BScreen::showPosition(int x, int y) {
2649 if (! geom_visible) {
2650 XMoveResizeWindow(getBaseDisplay().getXDisplay(), geom_window,
2651 (size().w() - geom_w) / 2,
2652 (size().h() - geom_h) / 2, geom_w, geom_h);
2653 XMapWindow(getBaseDisplay().getXDisplay(), geom_window);
2654 XRaiseWindow(getBaseDisplay().getXDisplay(), geom_window);
2656 geom_visible = True;
2661 sprintf(label, i18n->getMessage(ScreenSet, ScreenPositionFormat,
2662 "X: %4d x Y: %4d"), x, y);
2664 XClearWindow(getBaseDisplay().getXDisplay(), geom_window);
2666 if (i18n->multibyte()) {
2667 XmbDrawString(getBaseDisplay().getXDisplay(), geom_window,
2668 resource.wstyle.fontset, resource.wstyle.l_text_focus_gc,
2669 resource.bevel_width, resource.bevel_width -
2670 resource.wstyle.fontset_extents->max_ink_extent.y,
2671 label, strlen(label));
2673 XDrawString(getBaseDisplay().getXDisplay(), geom_window,
2674 resource.wstyle.l_text_focus_gc,
2675 resource.bevel_width,
2676 resource.wstyle.font->ascent +
2677 resource.bevel_width, label, strlen(label));
2682 void BScreen::showGeometry(unsigned int gx, unsigned int gy) {
2683 if (! geom_visible) {
2684 XMoveResizeWindow(getBaseDisplay().getXDisplay(), geom_window,
2685 (size().w() - geom_w) / 2,
2686 (size().h() - geom_h) / 2, geom_w, geom_h);
2687 XMapWindow(getBaseDisplay().getXDisplay(), geom_window);
2688 XRaiseWindow(getBaseDisplay().getXDisplay(), geom_window);
2690 geom_visible = True;
2695 sprintf(label, i18n->getMessage(ScreenSet, ScreenGeometryFormat,
2696 "W: %4d x H: %4d"), gx, gy);
2698 XClearWindow(getBaseDisplay().getXDisplay(), geom_window);
2700 if (i18n->multibyte()) {
2701 XmbDrawString(getBaseDisplay().getXDisplay(), geom_window,
2702 resource.wstyle.fontset, resource.wstyle.l_text_focus_gc,
2703 resource.bevel_width, resource.bevel_width -
2704 resource.wstyle.fontset_extents->max_ink_extent.y,
2705 label, strlen(label));
2707 XDrawString(getBaseDisplay().getXDisplay(), geom_window,
2708 resource.wstyle.l_text_focus_gc,
2709 resource.bevel_width,
2710 resource.wstyle.font->ascent +
2711 resource.bevel_width, label, strlen(label));
2715 void BScreen::hideGeometry(void) {
2717 XUnmapWindow(getBaseDisplay().getXDisplay(), geom_window);
2718 geom_visible = False;