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 load(); // load config options from Resources
250 unsigned long gc_value_mask = GCForeground;
251 if (! i18n->multibyte()) gc_value_mask |= GCFont;
253 gcv.foreground = WhitePixel(getBaseDisplay().getXDisplay(),
255 ^ BlackPixel(getBaseDisplay().getXDisplay(),
257 gcv.function = GXxor;
258 gcv.subwindow_mode = IncludeInferiors;
259 opGC = XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
260 GCForeground | GCFunction | GCSubwindowMode, &gcv);
262 gcv.foreground = resource.wstyle.l_text_focus.getPixel();
263 if (resource.wstyle.font)
264 gcv.font = resource.wstyle.font->fid;
265 resource.wstyle.l_text_focus_gc =
266 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
267 gc_value_mask, &gcv);
269 gcv.foreground = resource.wstyle.l_text_unfocus.getPixel();
270 if (resource.wstyle.font)
271 gcv.font = resource.wstyle.font->fid;
272 resource.wstyle.l_text_unfocus_gc =
273 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
274 gc_value_mask, &gcv);
276 gcv.foreground = resource.wstyle.b_pic_focus.getPixel();
277 resource.wstyle.b_pic_focus_gc =
278 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
281 gcv.foreground = resource.wstyle.b_pic_unfocus.getPixel();
282 resource.wstyle.b_pic_unfocus_gc =
283 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
286 gcv.foreground = resource.mstyle.t_text.getPixel();
287 if (resource.mstyle.t_font)
288 gcv.font = resource.mstyle.t_font->fid;
289 resource.mstyle.t_text_gc =
290 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
291 gc_value_mask, &gcv);
293 gcv.foreground = resource.mstyle.f_text.getPixel();
294 if (resource.mstyle.f_font)
295 gcv.font = resource.mstyle.f_font->fid;
296 resource.mstyle.f_text_gc =
297 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
298 gc_value_mask, &gcv);
300 gcv.foreground = resource.mstyle.h_text.getPixel();
301 resource.mstyle.h_text_gc =
302 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
303 gc_value_mask, &gcv);
305 gcv.foreground = resource.mstyle.d_text.getPixel();
306 resource.mstyle.d_text_gc =
307 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
308 gc_value_mask, &gcv);
310 gcv.foreground = resource.mstyle.hilite.getColor()->getPixel();
311 resource.mstyle.hilite_gc =
312 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
313 gc_value_mask, &gcv);
315 gcv.foreground = resource.tstyle.l_text.getPixel();
316 if (resource.tstyle.font)
317 gcv.font = resource.tstyle.font->fid;
318 resource.tstyle.l_text_gc =
319 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
320 gc_value_mask, &gcv);
322 gcv.foreground = resource.tstyle.w_text.getPixel();
323 resource.tstyle.w_text_gc =
324 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
325 gc_value_mask, &gcv);
327 gcv.foreground = resource.tstyle.c_text.getPixel();
328 resource.tstyle.c_text_gc =
329 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
330 gc_value_mask, &gcv);
332 gcv.foreground = resource.tstyle.b_pic.getPixel();
333 resource.tstyle.b_pic_gc =
334 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
335 gc_value_mask, &gcv);
337 const char *s = i18n->getMessage(ScreenSet, ScreenPositionLength,
338 "0: 0000 x 0: 0000");
341 if (i18n->multibyte()) {
342 XRectangle ink, logical;
343 XmbTextExtents(resource.wstyle.fontset, s, l, &ink, &logical);
344 geom_w = logical.width;
346 geom_h = resource.wstyle.fontset_extents->max_ink_extent.height;
348 geom_h = resource.wstyle.font->ascent +
349 resource.wstyle.font->descent;
351 geom_w = XTextWidth(resource.wstyle.font, s, l);
354 geom_w += (resource.bevel_width * 2);
355 geom_h += (resource.bevel_width * 2);
357 XSetWindowAttributes attrib;
358 unsigned long mask = CWBorderPixel | CWColormap | CWSaveUnder;
359 attrib.border_pixel = getBorderColor()->getPixel();
360 attrib.colormap = getColormap();
361 attrib.save_under = True;
364 XCreateWindow(getBaseDisplay().getXDisplay(), getRootWindow(),
365 0, 0, geom_w, geom_h, resource.border_width, getDepth(),
366 InputOutput, getVisual(), mask, &attrib);
367 geom_visible = False;
369 if (resource.wstyle.l_focus.getTexture() & BImage_ParentRelative) {
370 if (resource.wstyle.t_focus.getTexture() ==
371 (BImage_Flat | BImage_Solid)) {
373 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window,
374 resource.wstyle.t_focus.getColor()->getPixel());
376 geom_pixmap = image_control->renderImage(geom_w, geom_h,
377 &resource.wstyle.t_focus);
378 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
379 geom_window, geom_pixmap);
382 if (resource.wstyle.l_focus.getTexture() ==
383 (BImage_Flat | BImage_Solid)) {
385 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window,
386 resource.wstyle.l_focus.getColor()->getPixel());
388 geom_pixmap = image_control->renderImage(geom_w, geom_h,
389 &resource.wstyle.l_focus);
390 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
391 geom_window, geom_pixmap);
395 workspacemenu = new Workspacemenu(*this);
396 iconmenu = new Iconmenu(*this);
397 configmenu = new Configmenu(*this);
399 Workspace *wkspc = NULL;
400 if (resource.workspaces != 0) {
401 for (int i = 0; i < resource.workspaces; ++i) {
402 wkspc = new Workspace(*this, workspacesList->count());
403 workspacesList->insert(wkspc);
404 saveWorkspaceNames();
405 workspacemenu->insert(wkspc->getName(), wkspc->getMenu());
408 wkspc = new Workspace(*this, workspacesList->count());
409 workspacesList->insert(wkspc);
410 saveWorkspaceNames();
411 workspacemenu->insert(wkspc->getName(), wkspc->getMenu());
414 workspacemenu->insert(i18n->getMessage(IconSet, IconIcons, "Icons"),
416 workspacemenu->update();
418 current_workspace = workspacesList->first();
419 workspacemenu->setItemSelected(2, True);
421 toolbar = new Toolbar(*this, config);
424 slit = new Slit(*this, config);
432 changeWorkspaceID(0);
436 Window r, p, *children;
437 XQueryTree(getBaseDisplay().getXDisplay(), getRootWindow(), &r, &p,
440 // preen the window list of all icon windows... for better dockapp support
441 for (i = 0; i < (int) nchild; i++) {
442 if (children[i] == None) continue;
444 XWMHints *wmhints = XGetWMHints(getBaseDisplay().getXDisplay(),
448 if ((wmhints->flags & IconWindowHint) &&
449 (wmhints->icon_window != children[i]))
450 for (int j = 0; j < (int) nchild; j++)
451 if (children[j] == wmhints->icon_window) {
461 // manage shown windows
462 for (i = 0; i < (int) nchild; ++i) {
463 if (children[i] == None || (! openbox.validateWindow(children[i])))
466 XWindowAttributes attrib;
467 if (XGetWindowAttributes(getBaseDisplay().getXDisplay(), children[i],
469 if (attrib.override_redirect) continue;
471 if (attrib.map_state != IsUnmapped) {
472 new OpenboxWindow(openbox, children[i], this);
474 OpenboxWindow *win = openbox.searchWindow(children[i]);
476 XMapRequestEvent mre;
477 mre.window = children[i];
478 win->restoreAttributes();
479 win->mapRequestEvent(&mre);
485 if (! resource.sloppy_focus)
486 XSetInputFocus(getBaseDisplay().getXDisplay(), toolbar->getWindowID(),
487 RevertToParent, CurrentTime);
490 XFlush(getBaseDisplay().getXDisplay());
494 BScreen::~BScreen(void) {
495 if (! managed) return;
497 if (geom_pixmap != None)
498 image_control->removeImage(geom_pixmap);
500 if (geom_window != None)
501 XDestroyWindow(getBaseDisplay().getXDisplay(), geom_window);
503 removeWorkspaceNames();
505 while (workspacesList->count())
506 delete workspacesList->remove(0);
508 while (rootmenuList->count())
509 rootmenuList->remove(0);
511 while (iconList->count())
512 delete iconList->remove(0);
514 while (netizenList->count())
515 delete netizenList->remove(0);
518 if (resource.strftime_format)
519 delete [] resource.strftime_format;
520 #endif // HAVE_STRFTIME
523 delete workspacemenu;
532 delete image_control;
534 delete workspacesList;
535 delete workspaceNames;
540 if (resource.wstyle.fontset)
541 XFreeFontSet(getBaseDisplay().getXDisplay(), resource.wstyle.fontset);
542 if (resource.mstyle.t_fontset)
543 XFreeFontSet(getBaseDisplay().getXDisplay(), resource.mstyle.t_fontset);
544 if (resource.mstyle.f_fontset)
545 XFreeFontSet(getBaseDisplay().getXDisplay(), resource.mstyle.f_fontset);
546 if (resource.tstyle.fontset)
547 XFreeFontSet(getBaseDisplay().getXDisplay(), resource.tstyle.fontset);
549 if (resource.wstyle.font)
550 XFreeFont(getBaseDisplay().getXDisplay(), resource.wstyle.font);
551 if (resource.mstyle.t_font)
552 XFreeFont(getBaseDisplay().getXDisplay(), resource.mstyle.t_font);
553 if (resource.mstyle.f_font)
554 XFreeFont(getBaseDisplay().getXDisplay(), resource.mstyle.f_font);
555 if (resource.tstyle.font)
556 XFreeFont(getBaseDisplay().getXDisplay(), resource.tstyle.font);
557 if (resource.root_command != NULL)
558 delete [] resource.root_command;
560 XFreeGC(getBaseDisplay().getXDisplay(), opGC);
562 XFreeGC(getBaseDisplay().getXDisplay(),
563 resource.wstyle.l_text_focus_gc);
564 XFreeGC(getBaseDisplay().getXDisplay(),
565 resource.wstyle.l_text_unfocus_gc);
566 XFreeGC(getBaseDisplay().getXDisplay(),
567 resource.wstyle.b_pic_focus_gc);
568 XFreeGC(getBaseDisplay().getXDisplay(),
569 resource.wstyle.b_pic_unfocus_gc);
571 XFreeGC(getBaseDisplay().getXDisplay(),
572 resource.mstyle.t_text_gc);
573 XFreeGC(getBaseDisplay().getXDisplay(),
574 resource.mstyle.f_text_gc);
575 XFreeGC(getBaseDisplay().getXDisplay(),
576 resource.mstyle.h_text_gc);
577 XFreeGC(getBaseDisplay().getXDisplay(),
578 resource.mstyle.d_text_gc);
579 XFreeGC(getBaseDisplay().getXDisplay(),
580 resource.mstyle.hilite_gc);
582 XFreeGC(getBaseDisplay().getXDisplay(),
583 resource.tstyle.l_text_gc);
584 XFreeGC(getBaseDisplay().getXDisplay(),
585 resource.tstyle.w_text_gc);
586 XFreeGC(getBaseDisplay().getXDisplay(),
587 resource.tstyle.c_text_gc);
588 XFreeGC(getBaseDisplay().getXDisplay(),
589 resource.tstyle.b_pic_gc);
592 void BScreen::readDatabaseTexture(const char *rname, const char *rclass,
594 unsigned long default_pixel)
598 if (resource.styleconfig.getValue(rname, rclass, s))
599 image_control->parseTexture(texture, s.c_str());
601 texture->setTexture(BImage_Solid | BImage_Flat);
603 if (texture->getTexture() & BImage_Solid) {
604 int clen = strlen(rclass) + 32, nlen = strlen(rname) + 32;
606 char *colorclass = new char[clen], *colorname = new char[nlen];
608 sprintf(colorclass, "%s.Color", rclass);
609 sprintf(colorname, "%s.color", rname);
611 readDatabaseColor(colorname, colorclass, texture->getColor(),
615 sprintf(colorclass, "%s.ColorTo", rclass);
616 sprintf(colorname, "%s.colorTo", rname);
618 readDatabaseColor(colorname, colorclass, texture->getColorTo(),
622 delete [] colorclass;
625 if ((! texture->getColor()->isAllocated()) ||
626 (texture->getTexture() & BImage_Flat))
631 xcol.red = (unsigned int) (texture->getColor()->getRed() +
632 (texture->getColor()->getRed() >> 1));
633 if (xcol.red >= 0xff) xcol.red = 0xffff;
634 else xcol.red *= 0xff;
635 xcol.green = (unsigned int) (texture->getColor()->getGreen() +
636 (texture->getColor()->getGreen() >> 1));
637 if (xcol.green >= 0xff) xcol.green = 0xffff;
638 else xcol.green *= 0xff;
639 xcol.blue = (unsigned int) (texture->getColor()->getBlue() +
640 (texture->getColor()->getBlue() >> 1));
641 if (xcol.blue >= 0xff) xcol.blue = 0xffff;
642 else xcol.blue *= 0xff;
644 if (! XAllocColor(getBaseDisplay().getXDisplay(),
645 getColormap(), &xcol))
648 texture->getHiColor()->setPixel(xcol.pixel);
651 (unsigned int) ((texture->getColor()->getRed() >> 2) +
652 (texture->getColor()->getRed() >> 1)) * 0xff;
654 (unsigned int) ((texture->getColor()->getGreen() >> 2) +
655 (texture->getColor()->getGreen() >> 1)) * 0xff;
657 (unsigned int) ((texture->getColor()->getBlue() >> 2) +
658 (texture->getColor()->getBlue() >> 1)) * 0xff;
660 if (! XAllocColor(getBaseDisplay().getXDisplay(),
661 getColormap(), &xcol))
664 texture->getLoColor()->setPixel(xcol.pixel);
665 } else if (texture->getTexture() & BImage_Gradient) {
666 int clen = strlen(rclass) + 10, nlen = strlen(rname) + 10;
668 char *colorclass = new char[clen], *colorname = new char[nlen],
669 *colortoclass = new char[clen], *colortoname = new char[nlen];
671 sprintf(colorclass, "%s.Color", rclass);
672 sprintf(colorname, "%s.color", rname);
674 sprintf(colortoclass, "%s.ColorTo", rclass);
675 sprintf(colortoname, "%s.colorTo", rname);
677 readDatabaseColor(colorname, colorclass, texture->getColor(),
679 readDatabaseColor(colortoname, colortoclass, texture->getColorTo(),
682 delete [] colorclass;
684 delete [] colortoclass;
685 delete [] colortoname;
690 void BScreen::readDatabaseColor(const char *rname, const char *rclass,
691 BColor *color, unsigned long default_pixel)
695 if (resource.styleconfig.getValue(rname, rclass, s))
696 image_control->parseColor(color, s.c_str());
698 // parsing with no color string just deallocates the color, if it has
699 // been previously allocated
700 image_control->parseColor(color);
701 color->setPixel(default_pixel);
706 void BScreen::readDatabaseFontSet(const char *rname, const char *rclass,
708 if (! fontset) return;
710 static char *defaultFont = "fixed";
711 bool load_default = false;
715 XFreeFontSet(getBaseDisplay().getXDisplay(), *fontset);
717 if (resource.styleconfig.getValue(rname, rclass, s)) {
718 if (! (*fontset = createFontSet(s.c_str())))
724 *fontset = createFontSet(defaultFont);
727 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenDefaultFontLoadFail,
728 "BScreen::LoadStyle(): couldn't load default font.\n"));
735 void BScreen::readDatabaseFont(const char *rname, const char *rclass,
736 XFontStruct **font) {
739 static char *defaultFont = "fixed";
740 bool load_default = false;
744 XFreeFont(getBaseDisplay().getXDisplay(), *font);
746 if (resource.styleconfig.getValue(rname, rclass, s)) {
747 if ((*font = XLoadQueryFont(getBaseDisplay().getXDisplay(),
748 s.c_str())) == NULL) {
749 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenFontLoadFail,
750 "BScreen::LoadStyle(): couldn't load font '%s'\n"),
758 if ((*font = XLoadQueryFont(getBaseDisplay().getXDisplay(),
759 defaultFont)) == NULL) {
760 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenDefaultFontLoadFail,
761 "BScreen::LoadStyle(): couldn't load default font.\n"));
768 XFontSet BScreen::createFontSet(const char *fontname) {
770 char **missing, *def = "-";
771 int nmissing, pixel_size = 0, buf_size = 0;
772 char weight[FONT_ELEMENT_SIZE], slant[FONT_ELEMENT_SIZE];
774 fs = XCreateFontSet(getBaseDisplay().getXDisplay(),
775 fontname, &missing, &nmissing, &def);
776 if (fs && (! nmissing)) return fs;
778 #ifdef HAVE_SETLOCALE
780 if (nmissing) XFreeStringList(missing);
782 setlocale(LC_CTYPE, "C");
783 fs = XCreateFontSet(getBaseDisplay().getXDisplay(), fontname,
784 &missing, &nmissing, &def);
785 setlocale(LC_CTYPE, "");
787 #endif // HAVE_SETLOCALE
790 XFontStruct **fontstructs;
792 XFontsOfFontSet(fs, &fontstructs, &fontnames);
793 fontname = fontnames[0];
796 getFontElement(fontname, weight, FONT_ELEMENT_SIZE,
797 "-medium-", "-bold-", "-demibold-", "-regular-", NULL);
798 getFontElement(fontname, slant, FONT_ELEMENT_SIZE,
799 "-r-", "-i-", "-o-", "-ri-", "-ro-", NULL);
800 getFontSize(fontname, &pixel_size);
802 if (! strcmp(weight, "*")) strncpy(weight, "medium", FONT_ELEMENT_SIZE);
803 if (! strcmp(slant, "*")) strncpy(slant, "r", FONT_ELEMENT_SIZE);
804 if (pixel_size < 3) pixel_size = 3;
805 else if (pixel_size > 97) pixel_size = 97;
807 buf_size = strlen(fontname) + (FONT_ELEMENT_SIZE * 2) + 64;
808 char *pattern2 = new char[buf_size];
809 snprintf(pattern2, buf_size - 1,
811 "-*-*-%s-%s-*-*-%d-*-*-*-*-*-*-*,"
812 "-*-*-*-*-*-*-%d-*-*-*-*-*-*-*,*",
813 fontname, weight, slant, pixel_size, pixel_size);
816 if (nmissing) XFreeStringList(missing);
817 if (fs) XFreeFontSet(getBaseDisplay().getXDisplay(), fs);
819 fs = XCreateFontSet(getBaseDisplay().getXDisplay(), fontname,
820 &missing, &nmissing, &def);
827 void BScreen::setSloppyFocus(bool b) {
828 resource.sloppy_focus = b;
830 s << "session.screen" << getScreenNumber() << ".focusModel" << ends;
831 config.setValue(s.str(),
832 (resource.sloppy_focus ?
833 (resource.auto_raise ? "AutoRaiseSloppyFocus" : "SloppyFocus")
835 s.rdbuf()->freeze(0);
839 void BScreen::setAutoRaise(bool a) {
840 resource.auto_raise = a;
842 s << "session.screen" << getScreenNumber() << ".focusModel" << ends;
843 config.setValue(s.str(),
844 (resource.sloppy_focus ?
845 (resource.auto_raise ? "AutoRaiseSloppyFocus" : "SloppyFocus")
847 s.rdbuf()->freeze(0);
851 void BScreen::setImageDither(bool d, bool reconfig) {
852 resource.image_dither = d;
853 image_control->setDither(d);
855 s << "session.screen" << getScreenNumber() << ".imageDither" << ends;
856 config.setValue(s.str(), resource.image_dither);
857 s.rdbuf()->freeze(0);
863 void BScreen::setOpaqueMove(bool o) {
864 resource.opaque_move = o;
866 s << "session.screen" << getScreenNumber() << ".opaqueMove" << ends;
867 config.setValue(s.str(), resource.opaque_move);
868 s.rdbuf()->freeze(0);
872 void BScreen::setFullMax(bool f) {
873 resource.full_max = f;
875 s << "session.screen" << getScreenNumber() << ".fullMaximization" << ends;
876 config.setValue(s.str(), resource.full_max);
877 s.rdbuf()->freeze(0);
881 void BScreen::setFocusNew(bool f) {
882 resource.focus_new = f;
884 s << "session.screen" << getScreenNumber() << ".focusNewWindows" << ends;
885 config.setValue(s.str(), resource.focus_new);
886 s.rdbuf()->freeze(0);
890 void BScreen::setFocusLast(bool f) {
891 resource.focus_last = f;
893 s << "session.screen" << getScreenNumber() << ".focusLastWindow" << ends;
894 config.setValue(s.str(), resource.focus_last);
895 s.rdbuf()->freeze(0);
899 void BScreen::setWindowZones(int z) {
902 s << "session.screen" << getScreenNumber() << ".windowZones" << ends;
903 config.setValue(s.str(), resource.zones);
904 s.rdbuf()->freeze(0);
908 void BScreen::setWorkspaceCount(int w) {
909 resource.workspaces = w;
911 s << "session.screen" << getScreenNumber() << ".workspaces" << ends;
912 config.setValue(s.str(), resource.workspaces);
913 s.rdbuf()->freeze(0);
917 void BScreen::setPlacementPolicy(int p) {
918 resource.placement_policy = p;
920 s << "session.screen" << getScreenNumber() << ".windowPlacement" << ends;
921 const char *placement;
922 switch (resource.placement_policy) {
923 case CascadePlacement: placement = "CascadePlacement"; break;
924 case BestFitPlacement: placement = "BestFitPlacement"; break;
925 case ColSmartPlacement: placement = "ColSmartPlacement"; break;
927 case RowSmartPlacement: placement = "RowSmartPlacement"; break;
929 config.setValue(s.str(), placement);
930 s.rdbuf()->freeze(0);
934 void BScreen::setEdgeSnapThreshold(int t) {
935 resource.edge_snap_threshold = t;
937 s << "session.screen" << getScreenNumber() << ".edgeSnapThreshold" << ends;
938 config.setValue(s.str(), resource.edge_snap_threshold);
939 s.rdbuf()->freeze(0);
943 void BScreen::setRowPlacementDirection(int d) {
944 resource.row_direction = d;
946 s << "session.screen" << getScreenNumber() << ".rowPlacementDirection" <<
948 config.setValue(s.str(),
949 resource.row_direction == LeftRight ?
950 "LeftToRight" : "RightToLeft");
951 s.rdbuf()->freeze(0);
955 void BScreen::setColPlacementDirection(int d) {
956 resource.col_direction = d;
958 s << "session.screen" << getScreenNumber() << ".colPlacementDirection" <<
960 config.setValue(s.str(),
961 resource.col_direction == TopBottom ?
962 "TopToBottom" : "BottomToTop");
963 s.rdbuf()->freeze(0);
967 void BScreen::setRootCommand(const char *cmd) {
968 if (resource.root_command != NULL)
969 delete [] resource.root_command;
971 resource.root_command = bstrdup(cmd);
973 resource.root_command = NULL;
974 // this doesn't save to the Resources config because it can't be changed
975 // inside Openbox, and this way we dont add an empty command which would over-
976 // ride the styles command when none has been specified
981 void BScreen::setStrftimeFormat(const char *f) {
982 if (resource.strftime_format != NULL)
983 delete [] resource.strftime_format;
985 resource.strftime_format = bstrdup(f);
987 s << "session.screen" << getScreenNumber() << ".strftimeFormat" << ends;
988 config.setValue(s.str(), resource.strftime_format);
989 s.rdbuf()->freeze(0);
992 #else // !HAVE_STRFTIME
993 void BScreen::setDateFormat(int f) {
994 resource.date_format = f;
996 s << "session.screen" << getScreenNumber() << ".dateFormat" << ends;
997 config.setValue(s.str(), resource.date_format == B_EuropeanDate ?
998 "European" : "American");
999 s.rdbuf()->freeze(0);
1002 void BScreen::setClock24Hour(Bool c) {
1003 resource.clock24hour = c;
1005 s << "session.screen" << getScreenNumber() << ".clockFormat" << ends;
1006 config.setValue(s.str(), resource.clock24hour ? 24 : 12);
1007 s.rdbuf()->freeze(0);
1009 #endif // HAVE_STRFTIME
1011 void BScreen::setHideToolbar(bool b) {
1012 resource.hide_toolbar = b;
1013 if (resource.hide_toolbar)
1014 getToolbar()->unMapToolbar();
1016 getToolbar()->mapToolbar();
1018 s << "session.screen" << getScreenNumber() << ".hideToolbar" << ends;
1019 config.setValue(s.str(), resource.hide_toolbar ? "True" : "False");
1020 s.rdbuf()->freeze(0);
1023 void BScreen::saveWorkspaceNames() {
1024 std::ostrstream rc, names;
1026 for (int i = 0; i < resource.workspaces; i++) {
1027 Workspace *w = getWorkspace(i);
1029 names << w->getName();
1030 if (i < resource.workspaces-1)
1036 rc << "session.screen" << getScreenNumber() << ".workspaceNames" << ends;
1037 config.setValue(rc.str(), names.str());
1038 rc.rdbuf()->freeze(0);
1039 names.rdbuf()->freeze(0);
1042 void BScreen::save() {
1043 setSloppyFocus(resource.sloppy_focus);
1044 setAutoRaise(resource.auto_raise);
1045 setImageDither(resource.image_dither, false);
1046 setOpaqueMove(resource.opaque_move);
1047 setFullMax(resource.full_max);
1048 setFocusNew(resource.focus_new);
1049 setFocusLast(resource.focus_last);
1050 setWindowZones(resource.zones);
1051 setWorkspaceCount(resource.workspaces);
1052 setPlacementPolicy(resource.placement_policy);
1053 setEdgeSnapThreshold(resource.edge_snap_threshold);
1054 setRowPlacementDirection(resource.row_direction);
1055 setColPlacementDirection(resource.col_direction);
1056 setRootCommand(resource.root_command);
1057 #ifdef HAVE_STRFTIME
1058 // it deletes the current value before setting the new one, so we have to
1059 // duplicate the current value.
1060 std::string s = resource.strftime_format;
1061 setStrftimeFormat(s.c_str());
1062 #else // !HAVE_STRFTIME
1063 setDateFormat(resource.date_format);
1064 setClock24Hour(resource.clock24hour);
1065 #endif // HAVE_STRFTIME
1066 setHideToolbar(resource.hide_toolbar);
1069 void BScreen::load() {
1070 std::ostrstream rscreen, rname, rclass;
1074 rscreen << "session.screen" << getScreenNumber() << '.' << ends;
1076 rname << rscreen.str() << "hideToolbar" << ends;
1077 rclass << rscreen.str() << "HideToolbar" << ends;
1078 if (config.getValue(rname.str(), rclass.str(), b))
1079 resource.hide_toolbar = b;
1081 resource.hide_toolbar = false;
1082 Toolbar *t = getToolbar();
1084 if (resource.hide_toolbar)
1090 rname.seekp(0); rclass.seekp(0);
1091 rname << rscreen.str() << "fullMaximization" << ends;
1092 rclass << rscreen.str() << "FullMaximization" << ends;
1093 if (config.getValue(rname.str(), rclass.str(), b))
1094 resource.full_max = b;
1096 resource.full_max = false;
1098 rname.seekp(0); rclass.seekp(0);
1099 rname << rscreen.str() << "focusNewWindows" << ends;
1100 rclass << rscreen.str() << "FocusNewWindows" << ends;
1101 if (config.getValue(rname.str(), rclass.str(), b))
1102 resource.focus_new = b;
1104 resource.focus_new = false;
1106 rname.seekp(0); rclass.seekp(0);
1107 rname << rscreen.str() << "focusLastWindow" << ends;
1108 rclass << rscreen.str() << "FocusLastWindow" << ends;
1109 if (config.getValue(rname.str(), rclass.str(), b))
1110 resource.focus_last = b;
1112 resource.focus_last = false;
1114 rname.seekp(0); rclass.seekp(0);
1115 rname << rscreen.str() << "rowPlacementDirection" << ends;
1116 rclass << rscreen.str() << "RowPlacementDirection" << ends;
1117 if (config.getValue(rname.str(), rclass.str(), s)) {
1118 if (0 == strncasecmp(s.c_str(), "RightToLeft", s.length()))
1119 resource.row_direction = RightLeft;
1120 else if (0 == strncasecmp(s.c_str(), "LeftToRight", s.length()))
1121 resource.row_direction = LeftRight;
1123 resource.row_direction = LeftRight;
1125 rname.seekp(0); rclass.seekp(0);
1126 rname << rscreen.str() << "colPlacementDirection" << ends;
1127 rclass << rscreen.str() << "ColPlacementDirection" << ends;
1128 if (config.getValue(rname.str(), rclass.str(), s)) {
1129 if (0 == strncasecmp(s.c_str(), "BottomToTop", s.length()))
1130 resource.col_direction = BottomTop;
1131 else if (0 == strncasecmp(s.c_str(), "TopToBottom", s.length()))
1132 resource.col_direction = TopBottom;
1134 resource.col_direction = TopBottom;
1136 rname.seekp(0); rclass.seekp(0);
1137 rname << rscreen.str() << "workspaces" << ends;
1138 rclass << rscreen.str() << "Workspaces" << ends;
1139 if (config.getValue(rname.str(), rclass.str(), l))
1140 resource.workspaces = l;
1142 resource.workspaces = 1;
1144 removeWorkspaceNames();
1145 rname.seekp(0); rclass.seekp(0);
1146 rname << rscreen.str() << "workspaceNames" << ends;
1147 rclass << rscreen.str() << "WorkspaceNames" << ends;
1148 if (config.getValue(rname.str(), rclass.str(), s)) {
1149 std::string::const_iterator it = s.begin(), end = s.end();
1151 std::string::const_iterator tmp = it;// current string.begin()
1152 it = std::find(tmp, end, ','); // look for comma between tmp and end
1153 std::string name(tmp, it); // name = s[tmp:it]
1154 addWorkspaceName(name.c_str());
1161 rname.seekp(0); rclass.seekp(0);
1162 rname << rscreen.str() << "focusModel" << ends;
1163 rclass << rscreen.str() << "FocusModel" << ends;
1164 if (config.getValue(rname.str(), rclass.str(), s)) {
1165 if (0 == strncasecmp(s.c_str(), "ClickToFocus", s.length())) {
1166 resource.auto_raise = false;
1167 resource.sloppy_focus = false;
1168 } else if (0 == strncasecmp(s.c_str(), "AutoRaiseSloppyFocus",
1170 resource.sloppy_focus = true;
1171 resource.auto_raise = true;
1172 } else if (0 == strncasecmp(s.c_str(), "SloppyFocus", s.length())) {
1173 resource.sloppy_focus = true;
1174 resource.auto_raise = false;
1177 resource.sloppy_focus = true;
1178 resource.auto_raise = false;
1181 rname.seekp(0); rclass.seekp(0);
1182 rname << rscreen.str() << "windowZones" << ends;
1183 rclass << rscreen.str() << "WindowZones" << ends;
1184 if (config.getValue(rname.str(), rclass.str(), l))
1185 resource.zones = (l == 1 || l == 2 || l == 4) ? l : 1;
1189 rname.seekp(0); rclass.seekp(0);
1190 rname << rscreen.str() << "windowPlacement" << ends;
1191 rclass << rscreen.str() << "WindowPlacement" << ends;
1192 if (config.getValue(rname.str(), rclass.str(), s)) {
1193 if (0 == strncasecmp(s.c_str(), "RowSmartPlacement", s.length()))
1194 resource.placement_policy = RowSmartPlacement;
1195 else if (0 == strncasecmp(s.c_str(), "ColSmartPlacement", s.length()))
1196 resource.placement_policy = ColSmartPlacement;
1197 else if (0 == strncasecmp(s.c_str(), "BestFitPlacement", s.length()))
1198 resource.placement_policy = BestFitPlacement;
1199 else if (0 == strncasecmp(s.c_str(), "CascadePlacement", s.length()))
1200 resource.placement_policy = CascadePlacement;
1202 resource.placement_policy = CascadePlacement;
1204 #ifdef HAVE_STRFTIME
1205 rname.seekp(0); rclass.seekp(0);
1206 rname << rscreen.str() << "strftimeFormat" << ends;
1207 rclass << rscreen.str() << "StrftimeFormat" << ends;
1209 if (resource.strftime_format != NULL)
1210 delete [] resource.strftime_format;
1212 if (config.getValue(rname.str(), rclass.str(), s))
1213 resource.strftime_format = bstrdup(s.c_str());
1215 resource.strftime_format = bstrdup("%I:%M %p");
1216 #else // !HAVE_STRFTIME
1217 rname.seekp(0); rclass.seekp(0);
1218 rname << rscreen.str() << "dateFormat" << ends;
1219 rclass << rscreen.str() << "DateFormat" << ends;
1220 if (config.getValue(rname.str(), rclass.str(), s)) {
1221 if (strncasecmp(s.c_str(), "European", s.length()))
1222 resource.date_format = B_EuropeanDate;
1223 else if (strncasecmp(s.c_str(), "American", s.length()))
1224 resource.date_format = B_AmericanDate;
1226 resource.date_format = B_AmericanDate;
1228 rname.seekp(0); rclass.seekp(0);
1229 rname << rscreen.str() << "clockFormat" << ends;
1230 rclass << rscreen.str() << "ClockFormat" << ends;
1231 if (config.getValue(rname.str(), rclass.str(), l)) {
1233 resource.clock24hour = true;
1234 else if (clock == 12)
1235 resource.clock24hour = false;
1237 resource.clock24hour = false;
1238 #endif // HAVE_STRFTIME
1240 rname.seekp(0); rclass.seekp(0);
1241 rname << rscreen.str() << "edgeSnapThreshold" << ends;
1242 rclass << rscreen.str() << "EdgeSnapThreshold" << ends;
1243 if (config.getValue(rname.str(), rclass.str(), l))
1244 resource.edge_snap_threshold = l;
1246 resource.edge_snap_threshold = 4;
1248 rname.seekp(0); rclass.seekp(0);
1249 rname << rscreen.str() << "imageDither" << ends;
1250 rclass << rscreen.str() << "ImageDither" << ends;
1251 if (config.getValue(rname.str(), rclass.str(), b))
1252 resource.image_dither = b;
1254 resource.image_dither = true;
1256 rname.seekp(0); rclass.seekp(0);
1257 rname << rscreen.str() << "rootCommand" << ends;
1258 rclass << rscreen.str() << "RootCommand" << ends;
1260 if (resource.root_command != NULL)
1261 delete [] resource.root_command;
1263 if (config.getValue(rname.str(), rclass.str(), s))
1264 resource.root_command = bstrdup(s.c_str());
1266 resource.root_command = NULL;
1268 rname.seekp(0); rclass.seekp(0);
1269 rname << rscreen.str() << "opaqueMove" << ends;
1270 rclass << rscreen.str() << "OpaqueMove" << ends;
1271 if (config.getValue(rname.str(), rclass.str(), b))
1272 resource.opaque_move = b;
1274 resource.opaque_move = false;
1276 rscreen.rdbuf()->freeze(0);
1277 rname.rdbuf()->freeze(0);
1278 rclass.rdbuf()->freeze(0);
1281 void BScreen::reconfigure(void) {
1290 unsigned long gc_value_mask = GCForeground;
1291 if (! i18n->multibyte()) gc_value_mask |= GCFont;
1293 gcv.foreground = WhitePixel(getBaseDisplay().getXDisplay(),
1295 gcv.function = GXinvert;
1296 gcv.subwindow_mode = IncludeInferiors;
1297 XChangeGC(getBaseDisplay().getXDisplay(), opGC,
1298 GCForeground | GCFunction | GCSubwindowMode, &gcv);
1300 gcv.foreground = resource.wstyle.l_text_focus.getPixel();
1301 if (resource.wstyle.font)
1302 gcv.font = resource.wstyle.font->fid;
1303 XChangeGC(getBaseDisplay().getXDisplay(), resource.wstyle.l_text_focus_gc,
1304 gc_value_mask, &gcv);
1306 gcv.foreground = resource.wstyle.l_text_unfocus.getPixel();
1307 XChangeGC(getBaseDisplay().getXDisplay(), resource.wstyle.l_text_unfocus_gc,
1308 gc_value_mask, &gcv);
1310 gcv.foreground = resource.wstyle.b_pic_focus.getPixel();
1311 XChangeGC(getBaseDisplay().getXDisplay(), resource.wstyle.b_pic_focus_gc,
1312 GCForeground, &gcv);
1314 gcv.foreground = resource.wstyle.b_pic_unfocus.getPixel();
1315 XChangeGC(getBaseDisplay().getXDisplay(), resource.wstyle.b_pic_unfocus_gc,
1316 GCForeground, &gcv);
1318 gcv.foreground = resource.mstyle.t_text.getPixel();
1319 if (resource.mstyle.t_font)
1320 gcv.font = resource.mstyle.t_font->fid;
1321 XChangeGC(getBaseDisplay().getXDisplay(), resource.mstyle.t_text_gc,
1322 gc_value_mask, &gcv);
1324 gcv.foreground = resource.mstyle.f_text.getPixel();
1325 if (resource.mstyle.f_font)
1326 gcv.font = resource.mstyle.f_font->fid;
1327 XChangeGC(getBaseDisplay().getXDisplay(), resource.mstyle.f_text_gc,
1328 gc_value_mask, &gcv);
1330 gcv.foreground = resource.mstyle.h_text.getPixel();
1331 XChangeGC(getBaseDisplay().getXDisplay(), resource.mstyle.h_text_gc,
1332 gc_value_mask, &gcv);
1334 gcv.foreground = resource.mstyle.d_text.getPixel();
1335 XChangeGC(getBaseDisplay().getXDisplay(), resource.mstyle.d_text_gc,
1336 gc_value_mask, &gcv);
1338 gcv.foreground = resource.mstyle.hilite.getColor()->getPixel();
1339 XChangeGC(getBaseDisplay().getXDisplay(), resource.mstyle.hilite_gc,
1340 gc_value_mask, &gcv);
1342 gcv.foreground = resource.tstyle.l_text.getPixel();
1343 if (resource.tstyle.font)
1344 gcv.font = resource.tstyle.font->fid;
1345 XChangeGC(getBaseDisplay().getXDisplay(), resource.tstyle.l_text_gc,
1346 gc_value_mask, &gcv);
1348 gcv.foreground = resource.tstyle.w_text.getPixel();
1349 XChangeGC(getBaseDisplay().getXDisplay(), resource.tstyle.w_text_gc,
1350 gc_value_mask, &gcv);
1352 gcv.foreground = resource.tstyle.c_text.getPixel();
1353 XChangeGC(getBaseDisplay().getXDisplay(), resource.tstyle.c_text_gc,
1354 gc_value_mask, &gcv);
1356 gcv.foreground = resource.tstyle.b_pic.getPixel();
1357 XChangeGC(getBaseDisplay().getXDisplay(), resource.tstyle.b_pic_gc,
1358 gc_value_mask, &gcv);
1360 const char *s = i18n->getMessage(ScreenSet, ScreenPositionLength,
1361 "0: 0000 x 0: 0000");
1364 if (i18n->multibyte()) {
1365 XRectangle ink, logical;
1366 XmbTextExtents(resource.wstyle.fontset, s, l, &ink, &logical);
1367 geom_w = logical.width;
1369 geom_h = resource.wstyle.fontset_extents->max_ink_extent.height;
1371 geom_w = XTextWidth(resource.wstyle.font, s, l);
1373 geom_h = resource.wstyle.font->ascent +
1374 resource.wstyle.font->descent;
1377 geom_w += (resource.bevel_width * 2);
1378 geom_h += (resource.bevel_width * 2);
1380 Pixmap tmp = geom_pixmap;
1381 if (resource.wstyle.l_focus.getTexture() & BImage_ParentRelative) {
1382 if (resource.wstyle.t_focus.getTexture() ==
1383 (BImage_Flat | BImage_Solid)) {
1385 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window,
1386 resource.wstyle.t_focus.getColor()->getPixel());
1388 geom_pixmap = image_control->renderImage(geom_w, geom_h,
1389 &resource.wstyle.t_focus);
1390 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
1391 geom_window, geom_pixmap);
1394 if (resource.wstyle.l_focus.getTexture() ==
1395 (BImage_Flat | BImage_Solid)) {
1397 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window,
1398 resource.wstyle.l_focus.getColor()->getPixel());
1400 geom_pixmap = image_control->renderImage(geom_w, geom_h,
1401 &resource.wstyle.l_focus);
1402 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
1403 geom_window, geom_pixmap);
1406 if (tmp) image_control->removeImage(tmp);
1408 XSetWindowBorderWidth(getBaseDisplay().getXDisplay(), geom_window,
1409 resource.border_width);
1410 XSetWindowBorder(getBaseDisplay().getXDisplay(), geom_window,
1411 resource.border_color.getPixel());
1413 workspacemenu->reconfigure();
1414 iconmenu->reconfigure();
1417 int remember_sub = rootmenu->getCurrentSubmenu();
1420 rootmenu->reconfigure();
1421 rootmenu->drawSubmenu(remember_sub);
1424 configmenu->reconfigure();
1426 toolbar->reconfigure();
1429 slit->reconfigure();
1432 LinkedListIterator<Workspace> wit(workspacesList);
1433 for (Workspace *w = wit.current(); w; wit++, w = wit.current())
1436 LinkedListIterator<OpenboxWindow> iit(iconList);
1437 for (OpenboxWindow *bw = iit.current(); bw; iit++, bw = iit.current())
1438 if (bw->validateClient())
1441 image_control->timeout();
1445 void BScreen::rereadMenu(void) {
1449 rootmenu->reconfigure();
1453 void BScreen::removeWorkspaceNames(void) {
1454 while (workspaceNames->count())
1455 delete [] workspaceNames->remove(0);
1459 void BScreen::LoadStyle(void) {
1460 Resource &conf = resource.styleconfig;
1462 const char *sfile = openbox.getStyleFilename();
1463 bool loaded = false;
1464 if (sfile != NULL) {
1465 conf.setFile(sfile);
1466 loaded = conf.load();
1469 conf.setFile(DEFAULTSTYLE);
1471 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenDefaultStyleLoadFail,
1472 "BScreen::LoadStyle(): couldn't load "
1473 "default style.\n"));
1481 // load fonts/fontsets
1483 if (i18n->multibyte()) {
1484 readDatabaseFontSet("window.font", "Window.Font",
1485 &resource.wstyle.fontset);
1486 readDatabaseFontSet("toolbar.font", "Toolbar.Font",
1487 &resource.tstyle.fontset);
1488 readDatabaseFontSet("menu.title.font", "Menu.Title.Font",
1489 &resource.mstyle.t_fontset);
1490 readDatabaseFontSet("menu.frame.font", "Menu.Frame.Font",
1491 &resource.mstyle.f_fontset);
1493 resource.mstyle.t_fontset_extents =
1494 XExtentsOfFontSet(resource.mstyle.t_fontset);
1495 resource.mstyle.f_fontset_extents =
1496 XExtentsOfFontSet(resource.mstyle.f_fontset);
1497 resource.tstyle.fontset_extents =
1498 XExtentsOfFontSet(resource.tstyle.fontset);
1499 resource.wstyle.fontset_extents =
1500 XExtentsOfFontSet(resource.wstyle.fontset);
1502 readDatabaseFont("window.font", "Window.Font",
1503 &resource.wstyle.font);
1504 readDatabaseFont("menu.title.font", "Menu.Title.Font",
1505 &resource.mstyle.t_font);
1506 readDatabaseFont("menu.frame.font", "Menu.Frame.Font",
1507 &resource.mstyle.f_font);
1508 readDatabaseFont("toolbar.font", "Toolbar.Font",
1509 &resource.tstyle.font);
1512 // load window config
1513 readDatabaseTexture("window.title.focus", "Window.Title.Focus",
1514 &resource.wstyle.t_focus,
1515 WhitePixel(getBaseDisplay().getXDisplay(),
1516 getScreenNumber()));
1517 readDatabaseTexture("window.title.unfocus", "Window.Title.Unfocus",
1518 &resource.wstyle.t_unfocus,
1519 BlackPixel(getBaseDisplay().getXDisplay(),
1520 getScreenNumber()));
1521 readDatabaseTexture("window.label.focus", "Window.Label.Focus",
1522 &resource.wstyle.l_focus,
1523 WhitePixel(getBaseDisplay().getXDisplay(),
1524 getScreenNumber()));
1525 readDatabaseTexture("window.label.unfocus", "Window.Label.Unfocus",
1526 &resource.wstyle.l_unfocus,
1527 BlackPixel(getBaseDisplay().getXDisplay(),
1528 getScreenNumber()));
1529 readDatabaseTexture("window.handle.focus", "Window.Handle.Focus",
1530 &resource.wstyle.h_focus,
1531 WhitePixel(getBaseDisplay().getXDisplay(),
1532 getScreenNumber()));
1533 readDatabaseTexture("window.handle.unfocus", "Window.Handle.Unfocus",
1534 &resource.wstyle.h_unfocus,
1535 BlackPixel(getBaseDisplay().getXDisplay(),
1536 getScreenNumber()));
1537 readDatabaseTexture("window.grip.focus", "Window.Grip.Focus",
1538 &resource.wstyle.g_focus,
1539 WhitePixel(getBaseDisplay().getXDisplay(),
1540 getScreenNumber()));
1541 readDatabaseTexture("window.grip.unfocus", "Window.Grip.Unfocus",
1542 &resource.wstyle.g_unfocus,
1543 BlackPixel(getBaseDisplay().getXDisplay(),
1544 getScreenNumber()));
1545 readDatabaseTexture("window.button.focus", "Window.Button.Focus",
1546 &resource.wstyle.b_focus,
1547 WhitePixel(getBaseDisplay().getXDisplay(),
1548 getScreenNumber()));
1549 readDatabaseTexture("window.button.unfocus", "Window.Button.Unfocus",
1550 &resource.wstyle.b_unfocus,
1551 BlackPixel(getBaseDisplay().getXDisplay(),
1552 getScreenNumber()));
1553 readDatabaseTexture("window.button.pressed", "Window.Button.Pressed",
1554 &resource.wstyle.b_pressed,
1555 BlackPixel(getBaseDisplay().getXDisplay(),
1556 getScreenNumber()));
1557 readDatabaseColor("window.frame.focusColor",
1558 "Window.Frame.FocusColor",
1559 &resource.wstyle.f_focus,
1560 WhitePixel(getBaseDisplay().getXDisplay(),
1561 getScreenNumber()));
1562 readDatabaseColor("window.frame.unfocusColor",
1563 "Window.Frame.UnfocusColor",
1564 &resource.wstyle.f_unfocus,
1565 BlackPixel(getBaseDisplay().getXDisplay(),
1566 getScreenNumber()));
1567 readDatabaseColor("window.label.focus.textColor",
1568 "Window.Label.Focus.TextColor",
1569 &resource.wstyle.l_text_focus,
1570 BlackPixel(getBaseDisplay().getXDisplay(),
1571 getScreenNumber()));
1572 readDatabaseColor("window.label.unfocus.textColor",
1573 "Window.Label.Unfocus.TextColor",
1574 &resource.wstyle.l_text_unfocus,
1575 WhitePixel(getBaseDisplay().getXDisplay(),
1576 getScreenNumber()));
1577 readDatabaseColor("window.button.focus.picColor",
1578 "Window.Button.Focus.PicColor",
1579 &resource.wstyle.b_pic_focus,
1580 BlackPixel(getBaseDisplay().getXDisplay(),
1581 getScreenNumber()));
1582 readDatabaseColor("window.button.unfocus.picColor",
1583 "Window.Button.Unfocus.PicColor",
1584 &resource.wstyle.b_pic_unfocus,
1585 WhitePixel(getBaseDisplay().getXDisplay(),
1586 getScreenNumber()));
1588 if (conf.getValue("window.justify", "Window.Justify", s)) {
1589 if (0 == strncasecmp(s.c_str(), "right", s.length()))
1590 resource.wstyle.justify = BScreen::RightJustify;
1591 else if (0 == strncasecmp(s.c_str(), "center", s.length()))
1592 resource.wstyle.justify = BScreen::CenterJustify;
1594 resource.wstyle.justify = BScreen::LeftJustify;
1596 resource.wstyle.justify = BScreen::LeftJustify;
1598 // load toolbar config
1599 readDatabaseTexture("toolbar", "Toolbar",
1600 &resource.tstyle.toolbar,
1601 BlackPixel(getBaseDisplay().getXDisplay(),
1602 getScreenNumber()));
1603 readDatabaseTexture("toolbar.label", "Toolbar.Label",
1604 &resource.tstyle.label,
1605 BlackPixel(getBaseDisplay().getXDisplay(),
1606 getScreenNumber()));
1607 readDatabaseTexture("toolbar.windowLabel", "Toolbar.WindowLabel",
1608 &resource.tstyle.window,
1609 BlackPixel(getBaseDisplay().getXDisplay(),
1610 getScreenNumber()));
1611 readDatabaseTexture("toolbar.button", "Toolbar.Button",
1612 &resource.tstyle.button,
1613 WhitePixel(getBaseDisplay().getXDisplay(),
1614 getScreenNumber()));
1615 readDatabaseTexture("toolbar.button.pressed", "Toolbar.Button.Pressed",
1616 &resource.tstyle.pressed,
1617 BlackPixel(getBaseDisplay().getXDisplay(),
1618 getScreenNumber()));
1619 readDatabaseTexture("toolbar.clock", "Toolbar.Clock",
1620 &resource.tstyle.clock,
1621 BlackPixel(getBaseDisplay().getXDisplay(),
1622 getScreenNumber()));
1623 readDatabaseColor("toolbar.label.textColor", "Toolbar.Label.TextColor",
1624 &resource.tstyle.l_text,
1625 WhitePixel(getBaseDisplay().getXDisplay(),
1626 getScreenNumber()));
1627 readDatabaseColor("toolbar.windowLabel.textColor",
1628 "Toolbar.WindowLabel.TextColor",
1629 &resource.tstyle.w_text,
1630 WhitePixel(getBaseDisplay().getXDisplay(),
1631 getScreenNumber()));
1632 readDatabaseColor("toolbar.clock.textColor", "Toolbar.Clock.TextColor",
1633 &resource.tstyle.c_text,
1634 WhitePixel(getBaseDisplay().getXDisplay(),
1635 getScreenNumber()));
1636 readDatabaseColor("toolbar.button.picColor", "Toolbar.Button.PicColor",
1637 &resource.tstyle.b_pic,
1638 BlackPixel(getBaseDisplay().getXDisplay(),
1639 getScreenNumber()));
1641 if (conf.getValue("toolbar.justify", "Toolbar.Justify", s)) {
1642 if (0 == strncasecmp(s.c_str(), "right", s.length()))
1643 resource.tstyle.justify = BScreen::RightJustify;
1644 else if (0 == strncasecmp(s.c_str(), "center", s.length()))
1645 resource.tstyle.justify = BScreen::CenterJustify;
1647 resource.tstyle.justify = BScreen::LeftJustify;
1649 resource.tstyle.justify = BScreen::LeftJustify;
1652 readDatabaseTexture("menu.title", "Menu.Title",
1653 &resource.mstyle.title,
1654 WhitePixel(getBaseDisplay().getXDisplay(),
1655 getScreenNumber()));
1656 readDatabaseTexture("menu.frame", "Menu.Frame",
1657 &resource.mstyle.frame,
1658 BlackPixel(getBaseDisplay().getXDisplay(),
1659 getScreenNumber()));
1660 readDatabaseTexture("menu.hilite", "Menu.Hilite",
1661 &resource.mstyle.hilite,
1662 WhitePixel(getBaseDisplay().getXDisplay(),
1663 getScreenNumber()));
1664 readDatabaseColor("menu.title.textColor", "Menu.Title.TextColor",
1665 &resource.mstyle.t_text,
1666 BlackPixel(getBaseDisplay().getXDisplay(),
1667 getScreenNumber()));
1668 readDatabaseColor("menu.frame.textColor", "Menu.Frame.TextColor",
1669 &resource.mstyle.f_text,
1670 WhitePixel(getBaseDisplay().getXDisplay(),
1671 getScreenNumber()));
1672 readDatabaseColor("menu.frame.disableColor", "Menu.Frame.DisableColor",
1673 &resource.mstyle.d_text,
1674 BlackPixel(getBaseDisplay().getXDisplay(),
1675 getScreenNumber()));
1676 readDatabaseColor("menu.hilite.textColor", "Menu.Hilite.TextColor",
1677 &resource.mstyle.h_text,
1678 BlackPixel(getBaseDisplay().getXDisplay(),
1679 getScreenNumber()));
1681 if (conf.getValue("menu.title.justify", "Menu.Title.Justify", s)) {
1682 if (0 == strncasecmp(s.c_str(), "right", s.length()))
1683 resource.mstyle.t_justify = BScreen::RightJustify;
1684 else if (0 == strncasecmp(s.c_str(), "center", s.length()))
1685 resource.mstyle.t_justify = BScreen::CenterJustify;
1687 resource.mstyle.t_justify = BScreen::LeftJustify;
1689 resource.mstyle.t_justify = BScreen::LeftJustify;
1691 if (conf.getValue("menu.frame.justify", "Menu.Frame.Justify", s)) {
1692 if (0 == strncasecmp(s.c_str(), "right", s.length()))
1693 resource.mstyle.f_justify = BScreen::RightJustify;
1694 else if (0 == strncasecmp(s.c_str(), "center", s.length()))
1695 resource.mstyle.f_justify = BScreen::CenterJustify;
1697 resource.mstyle.f_justify = BScreen::LeftJustify;
1699 resource.mstyle.f_justify = BScreen::LeftJustify;
1701 if (conf.getValue("menu.bullet", "Menu.Bullet", s)) {
1702 if (0 == strncasecmp(s.c_str(), "empty", s.length()))
1703 resource.mstyle.bullet = Basemenu::Empty;
1704 else if (0 == strncasecmp(s.c_str(), "square", s.length()))
1705 resource.mstyle.bullet = Basemenu::Square;
1706 else if (0 == strncasecmp(s.c_str(), "diamond", s.length()))
1707 resource.mstyle.bullet = Basemenu::Diamond;
1709 resource.mstyle.bullet = Basemenu::Triangle;
1711 resource.mstyle.bullet = Basemenu::Triangle;
1713 if (conf.getValue("menu.bullet.position", "Menu.Bullet.Position", s)) {
1714 if (0 == strncasecmp(s.c_str(), "right", s.length()))
1715 resource.mstyle.bullet_pos = Basemenu::Right;
1717 resource.mstyle.bullet_pos = Basemenu::Left;
1719 resource.mstyle.bullet_pos = Basemenu::Left;
1721 readDatabaseColor("borderColor", "BorderColor", &resource.border_color,
1722 BlackPixel(getBaseDisplay().getXDisplay(),
1723 getScreenNumber()));
1725 // load bevel, border and handle widths
1726 if (conf.getValue("handleWidth", "HandleWidth", l)) {
1727 if (l <= size().w() / 2 && l != 0)
1728 resource.handle_width = l;
1730 resource.handle_width = 6;
1732 resource.handle_width = 6;
1734 if (conf.getValue("borderWidth", "BorderWidth", l))
1735 resource.border_width = l;
1737 resource.border_width = 1;
1739 if (conf.getValue("bevelWidth", "BevelWidth", l)) {
1740 if (l <= size().w() / 2 && l != 0)
1741 resource.bevel_width = l;
1743 resource.bevel_width = 3;
1745 resource.bevel_width = 3;
1747 if (conf.getValue("frameWidth", "FrameWidth", l)) {
1748 if (l <= size().w() / 2)
1749 resource.frame_width = l;
1751 resource.frame_width = resource.bevel_width;
1753 resource.frame_width = resource.bevel_width;
1755 const char *cmd = resource.root_command;
1756 if (cmd != NULL || conf.getValue("rootCommand", "RootCommand", s)) {
1758 cmd = s.c_str(); // not specified by the screen, so use the one from the
1761 char displaystring[MAXPATHLEN];
1762 sprintf(displaystring, "DISPLAY=%s",
1763 DisplayString(getBaseDisplay().getXDisplay()));
1764 sprintf(displaystring + strlen(displaystring) - 1, "%d",
1767 bexec(cmd, displaystring);
1769 spawnlp(P_NOWAIT, "cmd.exe", "cmd.exe", "/c", cmd, NULL);
1775 void BScreen::addIcon(OpenboxWindow *w) {
1778 w->setWorkspace(-1);
1779 w->setWindowNumber(iconList->count());
1781 iconList->insert(w);
1783 iconmenu->insert((const char **) w->getIconTitle());
1788 void BScreen::removeIcon(OpenboxWindow *w) {
1791 iconList->remove(w->getWindowNumber());
1793 iconmenu->remove(w->getWindowNumber());
1796 LinkedListIterator<OpenboxWindow> it(iconList);
1797 OpenboxWindow *bw = it.current();
1798 for (int i = 0; bw; it++, bw = it.current())
1799 bw->setWindowNumber(i++);
1803 OpenboxWindow *BScreen::getIcon(int index) {
1804 if (index >= 0 && index < iconList->count())
1805 return iconList->find(index);
1811 int BScreen::addWorkspace(void) {
1812 Workspace *wkspc = new Workspace(*this, workspacesList->count());
1813 workspacesList->insert(wkspc);
1814 saveWorkspaceNames();
1816 workspacemenu->insert(wkspc->getName(), wkspc->getMenu(),
1817 wkspc->getWorkspaceID() + 2);
1818 workspacemenu->update();
1820 toolbar->reconfigure();
1822 updateNetizenWorkspaceCount();
1824 return workspacesList->count();
1828 int BScreen::removeLastWorkspace(void) {
1829 if (workspacesList->count() == 1)
1832 Workspace *wkspc = workspacesList->last();
1834 if (current_workspace->getWorkspaceID() == wkspc->getWorkspaceID())
1835 changeWorkspaceID(current_workspace->getWorkspaceID() - 1);
1839 workspacemenu->remove(wkspc->getWorkspaceID() + 2);
1840 workspacemenu->update();
1842 workspacesList->remove(wkspc);
1845 toolbar->reconfigure();
1847 updateNetizenWorkspaceCount();
1849 return workspacesList->count();
1853 void BScreen::changeWorkspaceID(int id) {
1854 if (! current_workspace) return;
1856 if (id != current_workspace->getWorkspaceID()) {
1857 current_workspace->hideAll();
1859 workspacemenu->setItemSelected(current_workspace->getWorkspaceID() + 2,
1862 if (openbox.getFocusedWindow() &&
1863 openbox.getFocusedWindow()->getScreen() == this &&
1864 (! openbox.getFocusedWindow()->isStuck())) {
1865 current_workspace->setLastFocusedWindow(openbox.getFocusedWindow());
1866 openbox.setFocusedWindow(NULL);
1869 current_workspace = getWorkspace(id);
1871 workspacemenu->setItemSelected(current_workspace->getWorkspaceID() + 2,
1873 toolbar->redrawWorkspaceLabel(True);
1875 current_workspace->showAll();
1877 if (resource.focus_last && current_workspace->getLastFocusedWindow()) {
1878 XSync(openbox.getXDisplay(), False);
1879 current_workspace->getLastFocusedWindow()->setInputFocus();
1883 updateNetizenCurrentWorkspace();
1887 void BScreen::addNetizen(Netizen *n) {
1888 netizenList->insert(n);
1890 n->sendWorkspaceCount();
1891 n->sendCurrentWorkspace();
1893 LinkedListIterator<Workspace> it(workspacesList);
1894 for (Workspace *w = it.current(); w; it++, w = it.current()) {
1895 for (int i = 0; i < w->getCount(); i++)
1896 n->sendWindowAdd(w->getWindow(i)->getClientWindow(),
1897 w->getWorkspaceID());
1900 Window f = ((openbox.getFocusedWindow()) ?
1901 openbox.getFocusedWindow()->getClientWindow() : None);
1902 n->sendWindowFocus(f);
1906 void BScreen::removeNetizen(Window w) {
1907 LinkedListIterator<Netizen> it(netizenList);
1910 for (Netizen *n = it.current(); n; it++, i++, n = it.current())
1911 if (n->getWindowID() == w) {
1912 Netizen *tmp = netizenList->remove(i);
1920 void BScreen::updateNetizenCurrentWorkspace(void) {
1921 LinkedListIterator<Netizen> it(netizenList);
1922 for (Netizen *n = it.current(); n; it++, n = it.current())
1923 n->sendCurrentWorkspace();
1927 void BScreen::updateNetizenWorkspaceCount(void) {
1928 LinkedListIterator<Netizen> it(netizenList);
1929 for (Netizen *n = it.current(); n; it++, n = it.current())
1930 n->sendWorkspaceCount();
1934 void BScreen::updateNetizenWindowFocus(void) {
1935 Window f = ((openbox.getFocusedWindow()) ?
1936 openbox.getFocusedWindow()->getClientWindow() : None);
1937 LinkedListIterator<Netizen> it(netizenList);
1938 for (Netizen *n = it.current(); n; it++, n = it.current())
1939 n->sendWindowFocus(f);
1943 void BScreen::updateNetizenWindowAdd(Window w, unsigned long p) {
1944 LinkedListIterator<Netizen> it(netizenList);
1945 for (Netizen *n = it.current(); n; it++, n = it.current())
1946 n->sendWindowAdd(w, p);
1950 void BScreen::updateNetizenWindowDel(Window w) {
1951 LinkedListIterator<Netizen> it(netizenList);
1952 for (Netizen *n = it.current(); n; it++, n = it.current())
1953 n->sendWindowDel(w);
1957 void BScreen::updateNetizenWindowRaise(Window w) {
1958 LinkedListIterator<Netizen> it(netizenList);
1959 for (Netizen *n = it.current(); n; it++, n = it.current())
1960 n->sendWindowRaise(w);
1964 void BScreen::updateNetizenWindowLower(Window w) {
1965 LinkedListIterator<Netizen> it(netizenList);
1966 for (Netizen *n = it.current(); n; it++, n = it.current())
1967 n->sendWindowLower(w);
1971 void BScreen::updateNetizenConfigNotify(XEvent *e) {
1972 LinkedListIterator<Netizen> it(netizenList);
1973 for (Netizen *n = it.current(); n; it++, n = it.current())
1974 n->sendConfigNotify(e);
1978 void BScreen::raiseWindows(Window *workspace_stack, int num) {
1979 Window *session_stack = new
1980 Window[(num + workspacesList->count() + rootmenuList->count() + 13)];
1983 XRaiseWindow(getBaseDisplay().getXDisplay(), iconmenu->getWindowID());
1984 *(session_stack + i++) = iconmenu->getWindowID();
1986 LinkedListIterator<Workspace> wit(workspacesList);
1987 for (Workspace *tmp = wit.current(); tmp; wit++, tmp = wit.current())
1988 *(session_stack + i++) = tmp->getMenu()->getWindowID();
1990 *(session_stack + i++) = workspacemenu->getWindowID();
1992 *(session_stack + i++) = configmenu->getFocusmenu()->getWindowID();
1993 *(session_stack + i++) = configmenu->getPlacementmenu()->getWindowID();
1994 *(session_stack + i++) = configmenu->getWindowID();
1997 *(session_stack + i++) = slit->getMenu()->getDirectionmenu()->getWindowID();
1998 *(session_stack + i++) = slit->getMenu()->getPlacementmenu()->getWindowID();
1999 *(session_stack + i++) = slit->getMenu()->getWindowID();
2002 *(session_stack + i++) =
2003 toolbar->getMenu()->getPlacementmenu()->getWindowID();
2004 *(session_stack + i++) = toolbar->getMenu()->getWindowID();
2006 LinkedListIterator<Rootmenu> rit(rootmenuList);
2007 for (Rootmenu *tmp = rit.current(); tmp; rit++, tmp = rit.current())
2008 *(session_stack + i++) = tmp->getWindowID();
2009 *(session_stack + i++) = rootmenu->getWindowID();
2011 if (toolbar->onTop())
2012 *(session_stack + i++) = toolbar->getWindowID();
2016 *(session_stack + i++) = slit->getWindowID();
2020 *(session_stack + i++) = *(workspace_stack + k);
2022 XRestackWindows(getBaseDisplay().getXDisplay(), session_stack, i);
2024 delete [] session_stack;
2028 void BScreen::addWorkspaceName(const char *name) {
2029 workspaceNames->insert(bstrdup(name));
2032 char* BScreen::getNameOfWorkspace(int id) {
2035 if (id >= 0 && id < workspaceNames->count()) {
2036 char *wkspc_name = workspaceNames->find(id);
2045 void BScreen::reassociateWindow(OpenboxWindow *w, int wkspc_id, Bool ignore_sticky) {
2049 wkspc_id = current_workspace->getWorkspaceID();
2051 if (w->getWorkspaceNumber() == wkspc_id)
2054 if (w->isIconic()) {
2056 getWorkspace(wkspc_id)->addWindow(w);
2057 } else if (ignore_sticky || ! w->isStuck()) {
2058 getWorkspace(w->getWorkspaceNumber())->removeWindow(w);
2059 getWorkspace(wkspc_id)->addWindow(w);
2064 void BScreen::nextFocus(void) {
2065 Bool have_focused = False;
2066 int focused_window_number = -1;
2067 OpenboxWindow *next;
2069 if (openbox.getFocusedWindow()) {
2070 if (openbox.getFocusedWindow()->getScreen()->getScreenNumber() ==
2071 getScreenNumber()) {
2072 have_focused = True;
2073 focused_window_number = openbox.getFocusedWindow()->getWindowNumber();
2077 if ((getCurrentWorkspace()->getCount() > 1) && have_focused) {
2078 int next_window_number = focused_window_number;
2080 if ((++next_window_number) >= getCurrentWorkspace()->getCount())
2081 next_window_number = 0;
2083 next = getCurrentWorkspace()->getWindow(next_window_number);
2084 } while ((! next->setInputFocus()) && (next_window_number !=
2085 focused_window_number));
2087 if (next_window_number != focused_window_number)
2088 getCurrentWorkspace()->raiseWindow(next);
2089 } else if (getCurrentWorkspace()->getCount() >= 1) {
2090 next = current_workspace->getWindow(0);
2092 current_workspace->raiseWindow(next);
2093 next->setInputFocus();
2098 void BScreen::prevFocus(void) {
2099 Bool have_focused = False;
2100 int focused_window_number = -1;
2101 OpenboxWindow *prev;
2103 if (openbox.getFocusedWindow()) {
2104 if (openbox.getFocusedWindow()->getScreen()->getScreenNumber() ==
2105 getScreenNumber()) {
2106 have_focused = True;
2107 focused_window_number = openbox.getFocusedWindow()->getWindowNumber();
2111 if ((getCurrentWorkspace()->getCount() > 1) && have_focused) {
2112 int prev_window_number = focused_window_number;
2114 if ((--prev_window_number) < 0)
2115 prev_window_number = getCurrentWorkspace()->getCount() - 1;
2117 prev = getCurrentWorkspace()->getWindow(prev_window_number);
2118 } while ((! prev->setInputFocus()) && (prev_window_number !=
2119 focused_window_number));
2121 if (prev_window_number != focused_window_number)
2122 getCurrentWorkspace()->raiseWindow(prev);
2123 } else if (getCurrentWorkspace()->getCount() >= 1) {
2124 prev = current_workspace->getWindow(0);
2126 current_workspace->raiseWindow(prev);
2127 prev->setInputFocus();
2132 void BScreen::raiseFocus(void) {
2133 Bool have_focused = False;
2134 int focused_window_number = -1;
2136 if (openbox.getFocusedWindow()) {
2137 if (openbox.getFocusedWindow()->getScreen()->getScreenNumber() ==
2138 getScreenNumber()) {
2139 have_focused = True;
2140 focused_window_number = openbox.getFocusedWindow()->getWindowNumber();
2144 if ((getCurrentWorkspace()->getCount() > 1) && have_focused)
2145 getWorkspace(openbox.getFocusedWindow()->getWorkspaceNumber())->
2146 raiseWindow(openbox.getFocusedWindow());
2150 void BScreen::InitMenu(void) {
2152 while (rootmenuList->count())
2153 rootmenuList->remove(0);
2155 while (rootmenu->getCount())
2156 rootmenu->remove(0);
2158 rootmenu = new Rootmenu(*this);
2160 Bool defaultMenu = True;
2162 if (openbox.getMenuFilename()) {
2163 FILE *menu_file = fopen(openbox.getMenuFilename(), "r");
2166 perror(openbox.getMenuFilename());
2168 if (feof(menu_file)) {
2169 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenEmptyMenuFile,
2170 "%s: Empty menu file"),
2171 openbox.getMenuFilename());
2173 char line[1024], label[1024];
2174 memset(line, 0, 1024);
2175 memset(label, 0, 1024);
2177 while (fgets(line, 1024, menu_file) && ! feof(menu_file)) {
2178 if (line[0] != '#') {
2179 int i, key = 0, index = -1, len = strlen(line);
2182 for (i = 0; i < len; i++) {
2183 if (line[i] == '[') index = 0;
2184 else if (line[i] == ']') break;
2185 else if (line[i] != ' ')
2187 key += tolower(line[i]);
2192 for (i = index; i < len; i++) {
2193 if (line[i] == '(') index = 0;
2194 else if (line[i] == ')') break;
2195 else if (index++ >= 0) {
2196 if (line[i] == '\\' && i < len - 1) i++;
2197 label[index - 1] = line[i];
2201 if (index == -1) index = 0;
2202 label[index] = '\0';
2204 rootmenu->setLabel(label);
2205 defaultMenu = parseMenuFile(menu_file, rootmenu);
2216 rootmenu->setInternalMenu();
2217 rootmenu->insert(i18n->getMessage(ScreenSet, Screenxterm, "xterm"),
2219 i18n->getMessage(ScreenSet, Screenxterm, "xterm"));
2220 rootmenu->insert(i18n->getMessage(ScreenSet, ScreenRestart, "Restart"),
2222 rootmenu->insert(i18n->getMessage(ScreenSet, ScreenExit, "Exit"),
2225 openbox.setMenuFilename(openbox.getMenuFilename());
2230 Bool BScreen::parseMenuFile(FILE *file, Rootmenu *menu) {
2231 char line[1024], label[1024], command[1024];
2233 while (! feof(file)) {
2234 memset(line, 0, 1024);
2235 memset(label, 0, 1024);
2236 memset(command, 0, 1024);
2238 if (fgets(line, 1024, file)) {
2239 if (line[0] != '#') {
2240 register int i, key = 0, parse = 0, index = -1,
2241 line_length = strlen(line),
2242 label_length = 0, command_length = 0;
2244 // determine the keyword
2246 for (i = 0; i < line_length; i++) {
2247 if (line[i] == '[') parse = 1;
2248 else if (line[i] == ']') break;
2249 else if (line[i] != ' ')
2251 key += tolower(line[i]);
2254 // get the label enclosed in ()'s
2257 for (i = 0; i < line_length; i++) {
2258 if (line[i] == '(') {
2261 } else if (line[i] == ')') break;
2262 else if (index++ >= 0) {
2263 if (line[i] == '\\' && i < line_length - 1) i++;
2264 label[index - 1] = line[i];
2269 label[index] = '\0';
2270 label_length = index;
2276 // get the command enclosed in {}'s
2279 for (i = 0; i < line_length; i++) {
2280 if (line[i] == '{') {
2283 } else if (line[i] == '}') break;
2284 else if (index++ >= 0) {
2285 if (line[i] == '\\' && i < line_length - 1) i++;
2286 command[index - 1] = line[i];
2291 command[index] = '\0';
2292 command_length = index;
2300 return ((menu->getCount() == 0) ? True : False);
2305 menu->insert(label);
2310 if ((! *label) && (! *command)) {
2311 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenEXECError,
2312 "BScreen::parseMenuFile: [exec] error, "
2313 "no menu label and/or command defined\n"));
2317 menu->insert(label, BScreen::Execute, command);
2323 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenEXITError,
2324 "BScreen::parseMenuFile: [exit] error, "
2325 "no menu label defined\n"));
2329 menu->insert(label, BScreen::Exit);
2335 if ((! *label) || (! *command)) {
2336 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenSTYLEError,
2337 "BScreen::parseMenuFile: [style] error, "
2338 "no menu label and/or filename defined\n"));
2342 char style[MAXPATHLEN];
2344 // perform shell style ~ home directory expansion
2346 int homedir_len = 0;
2347 if (*command == '~' && *(command + 1) == '/') {
2348 homedir = getenv("HOME");
2349 homedir_len = strlen(homedir);
2352 if (homedir && homedir_len != 0) {
2353 strncpy(style, homedir, homedir_len);
2355 strncpy(style + homedir_len, command + 1,
2356 command_length - 1);
2357 *(style + command_length + homedir_len - 1) = '\0';
2359 strncpy(style, command, command_length);
2360 *(style + command_length) = '\0';
2363 menu->insert(label, BScreen::SetStyle, style);
2370 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenCONFIGError,
2371 "BScreen::parseMenufile: [config] error, "
2372 "no label defined"));
2376 menu->insert(label, configmenu);
2380 case 740: // include
2383 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenINCLUDEError,
2384 "BScreen::parseMenuFile: [include] error, "
2385 "no filename defined\n"));
2389 char newfile[MAXPATHLEN];
2391 // perform shell style ~ home directory expansion
2393 int homedir_len = 0;
2394 if (*label == '~' && *(label + 1) == '/') {
2395 homedir = getenv("HOME");
2396 homedir_len = strlen(homedir);
2399 if (homedir && homedir_len != 0) {
2400 strncpy(newfile, homedir, homedir_len);
2402 strncpy(newfile + homedir_len, label + 1,
2404 *(newfile + label_length + homedir_len - 1) = '\0';
2406 strncpy(newfile, label, label_length);
2407 *(newfile + label_length) = '\0';
2411 FILE *submenufile = fopen(newfile, "r");
2415 if (fstat(fileno(submenufile), &buf) ||
2416 (! S_ISREG(buf.st_mode))) {
2418 i18n->getMessage(ScreenSet, ScreenINCLUDEErrorReg,
2419 "BScreen::parseMenuFile: [include] error: "
2420 "'%s' is not a regular file\n"), newfile);
2424 if (! feof(submenufile)) {
2425 if (! parseMenuFile(submenufile, menu))
2426 openbox.setMenuFilename(newfile);
2428 fclose(submenufile);
2437 case 767: // submenu
2440 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenSUBMENUError,
2441 "BScreen::parseMenuFile: [submenu] error, "
2442 "no menu label defined\n"));
2446 Rootmenu *submenu = new Rootmenu(*this);
2449 submenu->setLabel(command);
2451 submenu->setLabel(label);
2453 parseMenuFile(file, submenu);
2455 menu->insert(label, submenu);
2456 rootmenuList->insert(submenu);
2461 case 773: // restart
2464 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenRESTARTError,
2465 "BScreen::parseMenuFile: [restart] error, "
2466 "no menu label defined\n"));
2471 menu->insert(label, BScreen::RestartOther, command);
2473 menu->insert(label, BScreen::Restart);
2478 case 845: // reconfig
2481 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenRECONFIGError,
2482 "BScreen::parseMenuFile: [reconfig] error, "
2483 "no menu label defined\n"));
2487 menu->insert(label, BScreen::Reconfigure);
2492 case 995: // stylesdir
2493 case 1113: // stylesmenu
2495 Bool newmenu = ((key == 1113) ? True : False);
2497 if ((! *label) || ((! *command) && newmenu)) {
2499 i18n->getMessage(ScreenSet, ScreenSTYLESDIRError,
2500 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
2501 " error, no directory defined\n"));
2505 char stylesdir[MAXPATHLEN];
2507 char *directory = ((newmenu) ? command : label);
2508 int directory_length = ((newmenu) ? command_length : label_length);
2510 // perform shell style ~ home directory expansion
2512 int homedir_len = 0;
2514 if (*directory == '~' && *(directory + 1) == '/') {
2515 homedir = getenv("HOME");
2516 homedir_len = strlen(homedir);
2519 if (homedir && homedir_len != 0) {
2520 strncpy(stylesdir, homedir, homedir_len);
2522 strncpy(stylesdir + homedir_len, directory + 1,
2523 directory_length - 1);
2524 *(stylesdir + directory_length + homedir_len - 1) = '\0';
2526 strncpy(stylesdir, directory, directory_length);
2527 *(stylesdir + directory_length) = '\0';
2530 struct stat statbuf;
2532 if (! stat(stylesdir, &statbuf)) {
2533 if (S_ISDIR(statbuf.st_mode)) {
2534 Rootmenu *stylesmenu;
2537 stylesmenu = new Rootmenu(*this);
2541 DIR *d = opendir(stylesdir);
2545 // get the total number of directory entries
2546 while ((p = readdir(d))) entries++;
2549 char **ls = new char* [entries];
2551 while ((p = readdir(d)))
2552 ls[index++] = bstrdup(p->d_name);
2556 std::sort(ls, ls + entries, dcmp());
2558 int n, slen = strlen(stylesdir);
2559 for (n = 0; n < entries; n++) {
2560 if (ls[n][strlen(ls[n])-1] != '~') {
2561 int nlen = strlen(ls[n]);
2562 char style[MAXPATHLEN + 1];
2564 strncpy(style, stylesdir, slen);
2565 *(style + slen) = '/';
2566 strncpy(style + slen + 1, ls[n], nlen + 1);
2568 if ((! stat(style, &statbuf)) && S_ISREG(statbuf.st_mode))
2569 stylesmenu->insert(ls[n], BScreen::SetStyle, style);
2577 stylesmenu->update();
2580 stylesmenu->setLabel(label);
2581 menu->insert(label, stylesmenu);
2582 rootmenuList->insert(stylesmenu);
2585 openbox.setMenuFilename(stylesdir);
2587 fprintf(stderr, i18n->getMessage(ScreenSet,
2588 ScreenSTYLESDIRErrorNotDir,
2589 "BScreen::parseMenuFile:"
2590 " [stylesdir/stylesmenu] error, %s is not a"
2591 " directory\n"), stylesdir);
2595 i18n->getMessage(ScreenSet, ScreenSTYLESDIRErrorNoExist,
2596 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
2597 " error, %s does not exist\n"), stylesdir);
2603 case 1090: // workspaces
2607 i18n->getMessage(ScreenSet, ScreenWORKSPACESError,
2608 "BScreen:parseMenuFile: [workspaces] error, "
2609 "no menu label defined\n"));
2613 menu->insert(label, workspacemenu);
2622 return ((menu->getCount() == 0) ? True : False);
2626 void BScreen::shutdown(void) {
2629 XSelectInput(getBaseDisplay().getXDisplay(), getRootWindow(), NoEventMask);
2630 XSync(getBaseDisplay().getXDisplay(), False);
2632 LinkedListIterator<Workspace> it(workspacesList);
2633 for (Workspace *w = it.current(); w; it++, w = it.current())
2636 while (iconList->count()) {
2637 iconList->first()->restore();
2638 delete iconList->first();
2649 void BScreen::showPosition(int x, int y) {
2650 if (! geom_visible) {
2651 XMoveResizeWindow(getBaseDisplay().getXDisplay(), geom_window,
2652 (size().w() - geom_w) / 2,
2653 (size().h() - geom_h) / 2, geom_w, geom_h);
2654 XMapWindow(getBaseDisplay().getXDisplay(), geom_window);
2655 XRaiseWindow(getBaseDisplay().getXDisplay(), geom_window);
2657 geom_visible = True;
2662 sprintf(label, i18n->getMessage(ScreenSet, ScreenPositionFormat,
2663 "X: %4d x Y: %4d"), x, y);
2665 XClearWindow(getBaseDisplay().getXDisplay(), geom_window);
2667 if (i18n->multibyte()) {
2668 XmbDrawString(getBaseDisplay().getXDisplay(), geom_window,
2669 resource.wstyle.fontset, resource.wstyle.l_text_focus_gc,
2670 resource.bevel_width, resource.bevel_width -
2671 resource.wstyle.fontset_extents->max_ink_extent.y,
2672 label, strlen(label));
2674 XDrawString(getBaseDisplay().getXDisplay(), geom_window,
2675 resource.wstyle.l_text_focus_gc,
2676 resource.bevel_width,
2677 resource.wstyle.font->ascent +
2678 resource.bevel_width, label, strlen(label));
2683 void BScreen::showGeometry(unsigned int gx, unsigned int gy) {
2684 if (! geom_visible) {
2685 XMoveResizeWindow(getBaseDisplay().getXDisplay(), geom_window,
2686 (size().w() - geom_w) / 2,
2687 (size().h() - geom_h) / 2, geom_w, geom_h);
2688 XMapWindow(getBaseDisplay().getXDisplay(), geom_window);
2689 XRaiseWindow(getBaseDisplay().getXDisplay(), geom_window);
2691 geom_visible = True;
2696 sprintf(label, i18n->getMessage(ScreenSet, ScreenGeometryFormat,
2697 "W: %4d x H: %4d"), gx, gy);
2699 XClearWindow(getBaseDisplay().getXDisplay(), geom_window);
2701 if (i18n->multibyte()) {
2702 XmbDrawString(getBaseDisplay().getXDisplay(), geom_window,
2703 resource.wstyle.fontset, resource.wstyle.l_text_focus_gc,
2704 resource.bevel_width, resource.bevel_width -
2705 resource.wstyle.fontset_extents->max_ink_extent.y,
2706 label, strlen(label));
2708 XDrawString(getBaseDisplay().getXDisplay(), geom_window,
2709 resource.wstyle.l_text_focus_gc,
2710 resource.bevel_width,
2711 resource.wstyle.font->ascent +
2712 resource.bevel_width, label, strlen(label));
2716 void BScreen::hideGeometry(void) {
2718 XUnmapWindow(getBaseDisplay().getXDisplay(), geom_window);
2719 geom_visible = False;