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"
56 #endif // HAVE_STDLIB_H
60 #endif // HAVE_STRING_H
62 #ifdef HAVE_SYS_TYPES_H
63 # include <sys/types.h>
64 #endif // HAVE_SYS_TYPES_H
68 #endif // HAVE_CTYPE_H
72 #endif // HAVE_DIRENT_H
76 #endif // HAVE_LOCALE_H
79 # include <sys/types.h>
81 #endif // HAVE_UNISTD_H
83 #ifdef HAVE_SYS_STAT_H
84 # include <sys/stat.h>
85 #endif // HAVE_SYS_STAT_H
89 #endif // HAVE_STDARG_H
92 # include "bsd-snprintf.h"
93 #endif // !HAVE_SNPRINTF
96 #define MAXPATHLEN 255
99 #ifndef FONT_ELEMENT_SIZE
100 #define FONT_ELEMENT_SIZE 50
101 #endif // FONT_ELEMENT_SIZE
107 static Bool running = True;
109 static int anotherWMRunning(Display *display, XErrorEvent *) {
110 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenAnotherWMRunning,
111 "BScreen::BScreen: an error occured while querying the X server.\n"
112 " another window manager already running on display %s.\n"),
113 DisplayString(display));
121 bool operator()(const char *one, const char *two) const {
122 return (strcmp(one, two) < 0) ? True : False;
126 #ifndef HAVE_STRCASESTR
127 static const char * strcasestr(const char *str, const char *ptn) {
129 for( ; *str; str++) {
130 for(s2=str,p2=ptn; ; s2++,p2++) {
131 if (!*p2) return str;
132 if (toupper(*s2) != toupper(*p2)) break;
137 #endif // HAVE_STRCASESTR
139 static const char *getFontElement(const char *pattern, char *buf, int bufsiz, ...) {
144 va_start(va, bufsiz);
147 while((v = va_arg(va, char *)) != NULL) {
148 p = strcasestr(pattern, v);
150 strncpy(buf, p+1, bufsiz-2);
151 p2 = strchr(buf, '-');
158 strncpy(buf, "*", bufsiz);
162 static const char *getFontSize(const char *pattern, int *size) {
167 for (p=pattern; 1; p++) {
169 if (p2!=NULL && n>1 && n<72) {
170 *size = n; return p2+1;
172 *size = 16; return NULL;
174 } else if (*p=='-') {
175 if (n>1 && n<72 && p2!=NULL) {
180 } else if (*p>='0' && *p<='9' && p2!=NULL) {
190 BScreen::BScreen(Openbox &ob, int scrn, Resource &conf) : ScreenInfo(ob, scrn),
191 openbox(ob), config(conf)
193 event_mask = ColormapChangeMask | EnterWindowMask | PropertyChangeMask |
194 SubstructureRedirectMask | KeyPressMask | KeyReleaseMask |
195 ButtonPressMask | ButtonReleaseMask;
197 XErrorHandler old = XSetErrorHandler((XErrorHandler) anotherWMRunning);
198 XSelectInput(getBaseDisplay().getXDisplay(), getRootWindow(), event_mask);
199 XSync(getBaseDisplay().getXDisplay(), False);
200 XSetErrorHandler((XErrorHandler) old);
203 if (! managed) return;
205 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenManagingScreen,
206 "BScreen::BScreen: managing screen %d "
207 "using visual 0x%lx, depth %d\n"),
208 getScreenNumber(), XVisualIDFromVisual(getVisual()),
213 resource.mstyle.t_fontset = resource.mstyle.f_fontset =
214 resource.tstyle.fontset = resource.wstyle.fontset = NULL;
215 resource.mstyle.t_font = resource.mstyle.f_font = resource.tstyle.font =
216 resource.wstyle.font = NULL;
224 pid_t bpid = getpid();
226 XChangeProperty(getBaseDisplay().getXDisplay(), getRootWindow(),
227 openbox.getOpenboxPidAtom(), XA_CARDINAL,
228 sizeof(pid_t) * 8, PropModeReplace,
229 (unsigned char *) &bpid, 1);
230 #endif // HAVE_GETPID
232 XDefineCursor(getBaseDisplay().getXDisplay(), getRootWindow(),
233 openbox.getSessionCursor());
235 workspaceNames = new LinkedList<char>;
236 workspacesList = new LinkedList<Workspace>;
237 rootmenuList = new LinkedList<Rootmenu>;
238 netizenList = new LinkedList<Netizen>;
239 iconList = new LinkedList<OpenboxWindow>;
242 new BImageControl(openbox, *this, True, openbox.getColorsPerChannel(),
243 openbox.getCacheLife(), openbox.getCacheMax());
244 image_control->installRootColormap();
245 root_colormap_installed = True;
247 load(); // load config options from Resources
251 unsigned long gc_value_mask = GCForeground;
252 if (! i18n->multibyte()) gc_value_mask |= GCFont;
254 gcv.foreground = WhitePixel(getBaseDisplay().getXDisplay(),
256 ^ BlackPixel(getBaseDisplay().getXDisplay(),
258 gcv.function = GXxor;
259 gcv.subwindow_mode = IncludeInferiors;
260 opGC = XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
261 GCForeground | GCFunction | GCSubwindowMode, &gcv);
263 gcv.foreground = resource.wstyle.l_text_focus.getPixel();
264 if (resource.wstyle.font)
265 gcv.font = resource.wstyle.font->fid;
266 resource.wstyle.l_text_focus_gc =
267 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
268 gc_value_mask, &gcv);
270 gcv.foreground = resource.wstyle.l_text_unfocus.getPixel();
271 if (resource.wstyle.font)
272 gcv.font = resource.wstyle.font->fid;
273 resource.wstyle.l_text_unfocus_gc =
274 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
275 gc_value_mask, &gcv);
277 gcv.foreground = resource.wstyle.b_pic_focus.getPixel();
278 resource.wstyle.b_pic_focus_gc =
279 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
282 gcv.foreground = resource.wstyle.b_pic_unfocus.getPixel();
283 resource.wstyle.b_pic_unfocus_gc =
284 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
287 gcv.foreground = resource.mstyle.t_text.getPixel();
288 if (resource.mstyle.t_font)
289 gcv.font = resource.mstyle.t_font->fid;
290 resource.mstyle.t_text_gc =
291 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
292 gc_value_mask, &gcv);
294 gcv.foreground = resource.mstyle.f_text.getPixel();
295 if (resource.mstyle.f_font)
296 gcv.font = resource.mstyle.f_font->fid;
297 resource.mstyle.f_text_gc =
298 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
299 gc_value_mask, &gcv);
301 gcv.foreground = resource.mstyle.h_text.getPixel();
302 resource.mstyle.h_text_gc =
303 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
304 gc_value_mask, &gcv);
306 gcv.foreground = resource.mstyle.d_text.getPixel();
307 resource.mstyle.d_text_gc =
308 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
309 gc_value_mask, &gcv);
311 gcv.foreground = resource.mstyle.hilite.getColor()->getPixel();
312 resource.mstyle.hilite_gc =
313 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
314 gc_value_mask, &gcv);
316 gcv.foreground = resource.tstyle.l_text.getPixel();
317 if (resource.tstyle.font)
318 gcv.font = resource.tstyle.font->fid;
319 resource.tstyle.l_text_gc =
320 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
321 gc_value_mask, &gcv);
323 gcv.foreground = resource.tstyle.w_text.getPixel();
324 resource.tstyle.w_text_gc =
325 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
326 gc_value_mask, &gcv);
328 gcv.foreground = resource.tstyle.c_text.getPixel();
329 resource.tstyle.c_text_gc =
330 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
331 gc_value_mask, &gcv);
333 gcv.foreground = resource.tstyle.b_pic.getPixel();
334 resource.tstyle.b_pic_gc =
335 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
336 gc_value_mask, &gcv);
338 const char *s = i18n->getMessage(ScreenSet, ScreenPositionLength,
339 "0: 0000 x 0: 0000");
342 if (i18n->multibyte()) {
343 XRectangle ink, logical;
344 XmbTextExtents(resource.wstyle.fontset, s, l, &ink, &logical);
345 geom_w = logical.width;
347 geom_h = resource.wstyle.fontset_extents->max_ink_extent.height;
349 geom_h = resource.wstyle.font->ascent +
350 resource.wstyle.font->descent;
352 geom_w = XTextWidth(resource.wstyle.font, s, l);
355 geom_w += (resource.bevel_width * 2);
356 geom_h += (resource.bevel_width * 2);
358 XSetWindowAttributes attrib;
359 unsigned long mask = CWBorderPixel | CWColormap | CWSaveUnder;
360 attrib.border_pixel = getBorderColor()->getPixel();
361 attrib.colormap = getColormap();
362 attrib.save_under = True;
365 XCreateWindow(getBaseDisplay().getXDisplay(), getRootWindow(),
366 0, 0, geom_w, geom_h, resource.border_width, getDepth(),
367 InputOutput, getVisual(), mask, &attrib);
368 geom_visible = False;
370 if (resource.wstyle.l_focus.getTexture() & BImage_ParentRelative) {
371 if (resource.wstyle.t_focus.getTexture() ==
372 (BImage_Flat | BImage_Solid)) {
374 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window,
375 resource.wstyle.t_focus.getColor()->getPixel());
377 geom_pixmap = image_control->renderImage(geom_w, geom_h,
378 &resource.wstyle.t_focus);
379 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
380 geom_window, geom_pixmap);
383 if (resource.wstyle.l_focus.getTexture() ==
384 (BImage_Flat | BImage_Solid)) {
386 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window,
387 resource.wstyle.l_focus.getColor()->getPixel());
389 geom_pixmap = image_control->renderImage(geom_w, geom_h,
390 &resource.wstyle.l_focus);
391 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
392 geom_window, geom_pixmap);
396 workspacemenu = new Workspacemenu(*this);
397 iconmenu = new Iconmenu(*this);
398 configmenu = new Configmenu(*this);
400 Workspace *wkspc = NULL;
401 if (resource.workspaces != 0) {
402 for (int i = 0; i < resource.workspaces; ++i) {
403 wkspc = new Workspace(*this, workspacesList->count());
404 workspacesList->insert(wkspc);
405 saveWorkspaceNames();
406 workspacemenu->insert(wkspc->getName(), wkspc->getMenu());
409 wkspc = new Workspace(*this, workspacesList->count());
410 workspacesList->insert(wkspc);
411 saveWorkspaceNames();
412 workspacemenu->insert(wkspc->getName(), wkspc->getMenu());
415 workspacemenu->insert(i18n->getMessage(IconSet, IconIcons, "Icons"),
417 workspacemenu->update();
419 current_workspace = workspacesList->first();
420 workspacemenu->setItemSelected(2, True);
422 toolbar = new Toolbar(*this, config);
425 slit = new Slit(*this, config);
433 changeWorkspaceID(0);
437 Window r, p, *children;
438 XQueryTree(getBaseDisplay().getXDisplay(), getRootWindow(), &r, &p,
441 // preen the window list of all icon windows... for better dockapp support
442 for (i = 0; i < (int) nchild; i++) {
443 if (children[i] == None) continue;
445 XWMHints *wmhints = XGetWMHints(getBaseDisplay().getXDisplay(),
449 if ((wmhints->flags & IconWindowHint) &&
450 (wmhints->icon_window != children[i]))
451 for (int j = 0; j < (int) nchild; j++)
452 if (children[j] == wmhints->icon_window) {
462 // manage shown windows
463 for (i = 0; i < (int) nchild; ++i) {
464 if (children[i] == None || (! openbox.validateWindow(children[i])))
467 XWindowAttributes attrib;
468 if (XGetWindowAttributes(getBaseDisplay().getXDisplay(), children[i],
470 if (attrib.override_redirect) continue;
472 if (attrib.map_state != IsUnmapped) {
473 new OpenboxWindow(openbox, children[i], this);
475 OpenboxWindow *win = openbox.searchWindow(children[i]);
477 XMapRequestEvent mre;
478 mre.window = children[i];
479 win->restoreAttributes();
480 win->mapRequestEvent(&mre);
486 if (! resource.sloppy_focus)
487 XSetInputFocus(getBaseDisplay().getXDisplay(), toolbar->getWindowID(),
488 RevertToParent, CurrentTime);
491 XFlush(getBaseDisplay().getXDisplay());
495 BScreen::~BScreen(void) {
496 if (! managed) return;
498 if (geom_pixmap != None)
499 image_control->removeImage(geom_pixmap);
501 if (geom_window != None)
502 XDestroyWindow(getBaseDisplay().getXDisplay(), geom_window);
504 removeWorkspaceNames();
506 while (workspacesList->count())
507 delete workspacesList->remove(0);
509 while (rootmenuList->count())
510 rootmenuList->remove(0);
512 while (iconList->count())
513 delete iconList->remove(0);
515 while (netizenList->count())
516 delete netizenList->remove(0);
519 if (resource.strftime_format)
520 delete [] resource.strftime_format;
521 #endif // HAVE_STRFTIME
524 delete workspacemenu;
533 delete image_control;
535 delete workspacesList;
536 delete workspaceNames;
541 if (resource.wstyle.fontset)
542 XFreeFontSet(getBaseDisplay().getXDisplay(), resource.wstyle.fontset);
543 if (resource.mstyle.t_fontset)
544 XFreeFontSet(getBaseDisplay().getXDisplay(), resource.mstyle.t_fontset);
545 if (resource.mstyle.f_fontset)
546 XFreeFontSet(getBaseDisplay().getXDisplay(), resource.mstyle.f_fontset);
547 if (resource.tstyle.fontset)
548 XFreeFontSet(getBaseDisplay().getXDisplay(), resource.tstyle.fontset);
550 if (resource.wstyle.font)
551 XFreeFont(getBaseDisplay().getXDisplay(), resource.wstyle.font);
552 if (resource.mstyle.t_font)
553 XFreeFont(getBaseDisplay().getXDisplay(), resource.mstyle.t_font);
554 if (resource.mstyle.f_font)
555 XFreeFont(getBaseDisplay().getXDisplay(), resource.mstyle.f_font);
556 if (resource.tstyle.font)
557 XFreeFont(getBaseDisplay().getXDisplay(), resource.tstyle.font);
558 if (resource.root_command != NULL)
559 delete [] resource.root_command;
561 XFreeGC(getBaseDisplay().getXDisplay(), opGC);
563 XFreeGC(getBaseDisplay().getXDisplay(),
564 resource.wstyle.l_text_focus_gc);
565 XFreeGC(getBaseDisplay().getXDisplay(),
566 resource.wstyle.l_text_unfocus_gc);
567 XFreeGC(getBaseDisplay().getXDisplay(),
568 resource.wstyle.b_pic_focus_gc);
569 XFreeGC(getBaseDisplay().getXDisplay(),
570 resource.wstyle.b_pic_unfocus_gc);
572 XFreeGC(getBaseDisplay().getXDisplay(),
573 resource.mstyle.t_text_gc);
574 XFreeGC(getBaseDisplay().getXDisplay(),
575 resource.mstyle.f_text_gc);
576 XFreeGC(getBaseDisplay().getXDisplay(),
577 resource.mstyle.h_text_gc);
578 XFreeGC(getBaseDisplay().getXDisplay(),
579 resource.mstyle.d_text_gc);
580 XFreeGC(getBaseDisplay().getXDisplay(),
581 resource.mstyle.hilite_gc);
583 XFreeGC(getBaseDisplay().getXDisplay(),
584 resource.tstyle.l_text_gc);
585 XFreeGC(getBaseDisplay().getXDisplay(),
586 resource.tstyle.w_text_gc);
587 XFreeGC(getBaseDisplay().getXDisplay(),
588 resource.tstyle.c_text_gc);
589 XFreeGC(getBaseDisplay().getXDisplay(),
590 resource.tstyle.b_pic_gc);
594 Rect BScreen::availableArea() const {
595 // the following code is temporary and will be taken care of by Screen in the
596 // future (with the NETWM 'strut')
597 Rect space(0, 0, size().w(), size().h());
598 if (!resource.full_max) {
600 int slit_x = slit->autoHide() ? slit->hiddenOrigin().x() : slit->area().x(),
601 slit_y = slit->autoHide() ? slit->hiddenOrigin().y() : slit->area().y();
602 int tbarh = resource.hide_toolbar ? 0 :
603 toolbar->getExposedHeight() + resource.border_width * 2;
605 switch (toolbar->placement()) {
606 case Toolbar::TopLeft:
607 case Toolbar::TopCenter:
608 case Toolbar::TopRight:
611 case Toolbar::BottomLeft:
612 case Toolbar::BottomCenter:
613 case Toolbar::BottomRight:
617 ASSERT(false); // unhandled placement
619 if ((slit->direction() == Slit::Horizontal &&
620 (slit->placement() == Slit::TopLeft ||
621 slit->placement() == Slit::TopRight)) ||
622 slit->placement() == Slit::TopCenter) {
624 if (tbartop && slit_y + slit->area().h() < tbarh) {
625 space.setY(space.y() + tbarh);
626 space.setH(space.h() - tbarh);
628 space.setY(space.y() + (slit_y + slit->area().h() +
629 resource.border_width * 2));
630 space.setH(space.h() - (slit_y + slit->area().h() +
631 resource.border_width * 2));
633 space.setH(space.h() - tbarh);
635 } else if ((slit->direction() == Slit::Vertical &&
636 (slit->placement() == Slit::TopRight ||
637 slit->placement() == Slit::BottomRight)) ||
638 slit->placement() == Slit::CenterRight) {
640 space.setW(space.w() - (size().w() - slit_x));
642 space.setY(space.y() + tbarh);
643 space.setH(space.h() - tbarh);
644 } else if ((slit->direction() == Slit::Horizontal &&
645 (slit->placement() == Slit::BottomLeft ||
646 slit->placement() == Slit::BottomRight)) ||
647 slit->placement() == Slit::BottomCenter) {
649 if (!tbartop && (size().h() - slit_y) < tbarh) {
650 space.setH(space.h() - tbarh);
652 space.setH(space.h() - (size().h() - slit_y));
654 space.setY(space.y() + tbarh);
655 space.setH(space.h() - tbarh);
658 } else {// if ((slit->direction() == Slit::Vertical &&
659 // (slit->placement() == Slit::TopLeft ||
660 // slit->placement() == Slit::BottomLeft)) ||
661 // slit->placement() == Slit::CenterLeft)
663 space.setX(slit_x + slit->area().w() +
664 resource.border_width * 2);
665 space.setW(space.w() - (slit_x + slit->area().w() +
666 resource.border_width * 2));
668 space.setY(space.y() + tbarh);
669 space.setH(space.h() - tbarh);
672 int tbarh = resource.hide_toolbar() ? 0 :
673 toolbar->getExposedHeight() + resource.border_width * 2;
674 switch (toolbar->placement()) {
675 case Toolbar::TopLeft:
676 case Toolbar::TopCenter:
677 case Toolbar::TopRight:
678 space.setY(toolbar->getExposedHeight());
679 space.setH(space.h() - toolbar->getExposedHeight());
681 case Toolbar::BottomLeft:
682 case Toolbar::BottomCenter:
683 case Toolbar::BottomRight:
684 space.setH(space.h() - tbarh);
687 ASSERT(false); // unhandled placement
695 void BScreen::readDatabaseTexture(const char *rname, const char *rclass,
697 unsigned long default_pixel)
701 if (resource.styleconfig.getValue(rname, rclass, s))
702 image_control->parseTexture(texture, s.c_str());
704 texture->setTexture(BImage_Solid | BImage_Flat);
706 if (texture->getTexture() & BImage_Solid) {
707 int clen = strlen(rclass) + 32, nlen = strlen(rname) + 32;
709 char *colorclass = new char[clen], *colorname = new char[nlen];
711 sprintf(colorclass, "%s.Color", rclass);
712 sprintf(colorname, "%s.color", rname);
714 readDatabaseColor(colorname, colorclass, texture->getColor(),
718 sprintf(colorclass, "%s.ColorTo", rclass);
719 sprintf(colorname, "%s.colorTo", rname);
721 readDatabaseColor(colorname, colorclass, texture->getColorTo(),
725 delete [] colorclass;
728 if ((! texture->getColor()->isAllocated()) ||
729 (texture->getTexture() & BImage_Flat))
734 xcol.red = (unsigned int) (texture->getColor()->getRed() +
735 (texture->getColor()->getRed() >> 1));
736 if (xcol.red >= 0xff) xcol.red = 0xffff;
737 else xcol.red *= 0xff;
738 xcol.green = (unsigned int) (texture->getColor()->getGreen() +
739 (texture->getColor()->getGreen() >> 1));
740 if (xcol.green >= 0xff) xcol.green = 0xffff;
741 else xcol.green *= 0xff;
742 xcol.blue = (unsigned int) (texture->getColor()->getBlue() +
743 (texture->getColor()->getBlue() >> 1));
744 if (xcol.blue >= 0xff) xcol.blue = 0xffff;
745 else xcol.blue *= 0xff;
747 if (! XAllocColor(getBaseDisplay().getXDisplay(),
748 getColormap(), &xcol))
751 texture->getHiColor()->setPixel(xcol.pixel);
754 (unsigned int) ((texture->getColor()->getRed() >> 2) +
755 (texture->getColor()->getRed() >> 1)) * 0xff;
757 (unsigned int) ((texture->getColor()->getGreen() >> 2) +
758 (texture->getColor()->getGreen() >> 1)) * 0xff;
760 (unsigned int) ((texture->getColor()->getBlue() >> 2) +
761 (texture->getColor()->getBlue() >> 1)) * 0xff;
763 if (! XAllocColor(getBaseDisplay().getXDisplay(),
764 getColormap(), &xcol))
767 texture->getLoColor()->setPixel(xcol.pixel);
768 } else if (texture->getTexture() & BImage_Gradient) {
769 int clen = strlen(rclass) + 10, nlen = strlen(rname) + 10;
771 char *colorclass = new char[clen], *colorname = new char[nlen],
772 *colortoclass = new char[clen], *colortoname = new char[nlen];
774 sprintf(colorclass, "%s.Color", rclass);
775 sprintf(colorname, "%s.color", rname);
777 sprintf(colortoclass, "%s.ColorTo", rclass);
778 sprintf(colortoname, "%s.colorTo", rname);
780 readDatabaseColor(colorname, colorclass, texture->getColor(),
782 readDatabaseColor(colortoname, colortoclass, texture->getColorTo(),
785 delete [] colorclass;
787 delete [] colortoclass;
788 delete [] colortoname;
793 void BScreen::readDatabaseColor(const char *rname, const char *rclass,
794 BColor *color, unsigned long default_pixel)
798 if (resource.styleconfig.getValue(rname, rclass, s))
799 image_control->parseColor(color, s.c_str());
801 // parsing with no color string just deallocates the color, if it has
802 // been previously allocated
803 image_control->parseColor(color);
804 color->setPixel(default_pixel);
809 void BScreen::readDatabaseFontSet(const char *rname, const char *rclass,
811 if (! fontset) return;
813 static char *defaultFont = "fixed";
814 bool load_default = false;
818 XFreeFontSet(getBaseDisplay().getXDisplay(), *fontset);
820 if (resource.styleconfig.getValue(rname, rclass, s)) {
821 if (! (*fontset = createFontSet(s.c_str())))
827 *fontset = createFontSet(defaultFont);
830 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenDefaultFontLoadFail,
831 "BScreen::LoadStyle(): couldn't load default font.\n"));
838 void BScreen::readDatabaseFont(const char *rname, const char *rclass,
839 XFontStruct **font) {
842 static char *defaultFont = "fixed";
843 bool load_default = false;
847 XFreeFont(getBaseDisplay().getXDisplay(), *font);
849 if (resource.styleconfig.getValue(rname, rclass, s)) {
850 if ((*font = XLoadQueryFont(getBaseDisplay().getXDisplay(),
851 s.c_str())) == NULL) {
852 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenFontLoadFail,
853 "BScreen::LoadStyle(): couldn't load font '%s'\n"),
861 if ((*font = XLoadQueryFont(getBaseDisplay().getXDisplay(),
862 defaultFont)) == NULL) {
863 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenDefaultFontLoadFail,
864 "BScreen::LoadStyle(): couldn't load default font.\n"));
871 XFontSet BScreen::createFontSet(const char *fontname) {
873 char **missing, *def = "-";
874 int nmissing, pixel_size = 0, buf_size = 0;
875 char weight[FONT_ELEMENT_SIZE], slant[FONT_ELEMENT_SIZE];
877 fs = XCreateFontSet(getBaseDisplay().getXDisplay(),
878 fontname, &missing, &nmissing, &def);
879 if (fs && (! nmissing)) return fs;
881 #ifdef HAVE_SETLOCALE
883 if (nmissing) XFreeStringList(missing);
885 setlocale(LC_CTYPE, "C");
886 fs = XCreateFontSet(getBaseDisplay().getXDisplay(), fontname,
887 &missing, &nmissing, &def);
888 setlocale(LC_CTYPE, "");
890 #endif // HAVE_SETLOCALE
893 XFontStruct **fontstructs;
895 XFontsOfFontSet(fs, &fontstructs, &fontnames);
896 fontname = fontnames[0];
899 getFontElement(fontname, weight, FONT_ELEMENT_SIZE,
900 "-medium-", "-bold-", "-demibold-", "-regular-", NULL);
901 getFontElement(fontname, slant, FONT_ELEMENT_SIZE,
902 "-r-", "-i-", "-o-", "-ri-", "-ro-", NULL);
903 getFontSize(fontname, &pixel_size);
905 if (! strcmp(weight, "*")) strncpy(weight, "medium", FONT_ELEMENT_SIZE);
906 if (! strcmp(slant, "*")) strncpy(slant, "r", FONT_ELEMENT_SIZE);
907 if (pixel_size < 3) pixel_size = 3;
908 else if (pixel_size > 97) pixel_size = 97;
910 buf_size = strlen(fontname) + (FONT_ELEMENT_SIZE * 2) + 64;
911 char *pattern2 = new char[buf_size];
912 snprintf(pattern2, buf_size - 1,
914 "-*-*-%s-%s-*-*-%d-*-*-*-*-*-*-*,"
915 "-*-*-*-*-*-*-%d-*-*-*-*-*-*-*,*",
916 fontname, weight, slant, pixel_size, pixel_size);
919 if (nmissing) XFreeStringList(missing);
920 if (fs) XFreeFontSet(getBaseDisplay().getXDisplay(), fs);
922 fs = XCreateFontSet(getBaseDisplay().getXDisplay(), fontname,
923 &missing, &nmissing, &def);
930 void BScreen::setSloppyFocus(bool b) {
931 resource.sloppy_focus = b;
933 s << "session.screen" << getScreenNumber() << ".focusModel" << ends;
934 config.setValue(s.str(),
935 (resource.sloppy_focus ?
936 (resource.auto_raise ? "AutoRaiseSloppyFocus" : "SloppyFocus")
938 s.rdbuf()->freeze(0);
942 void BScreen::setAutoRaise(bool a) {
943 resource.auto_raise = a;
945 s << "session.screen" << getScreenNumber() << ".focusModel" << ends;
946 config.setValue(s.str(),
947 (resource.sloppy_focus ?
948 (resource.auto_raise ? "AutoRaiseSloppyFocus" : "SloppyFocus")
950 s.rdbuf()->freeze(0);
954 void BScreen::setImageDither(bool d, bool reconfig) {
955 resource.image_dither = d;
956 image_control->setDither(d);
958 s << "session.screen" << getScreenNumber() << ".imageDither" << ends;
959 config.setValue(s.str(), resource.image_dither);
960 s.rdbuf()->freeze(0);
966 void BScreen::setOpaqueMove(bool o) {
967 resource.opaque_move = o;
969 s << "session.screen" << getScreenNumber() << ".opaqueMove" << ends;
970 config.setValue(s.str(), resource.opaque_move);
971 s.rdbuf()->freeze(0);
975 void BScreen::setFullMax(bool f) {
976 resource.full_max = f;
978 s << "session.screen" << getScreenNumber() << ".fullMaximization" << ends;
979 config.setValue(s.str(), resource.full_max);
980 s.rdbuf()->freeze(0);
984 void BScreen::setFocusNew(bool f) {
985 resource.focus_new = f;
987 s << "session.screen" << getScreenNumber() << ".focusNewWindows" << ends;
988 config.setValue(s.str(), resource.focus_new);
989 s.rdbuf()->freeze(0);
993 void BScreen::setFocusLast(bool f) {
994 resource.focus_last = f;
996 s << "session.screen" << getScreenNumber() << ".focusLastWindow" << ends;
997 config.setValue(s.str(), resource.focus_last);
998 s.rdbuf()->freeze(0);
1002 void BScreen::setWindowZones(int z) {
1005 s << "session.screen" << getScreenNumber() << ".windowZones" << ends;
1006 config.setValue(s.str(), resource.zones);
1007 s.rdbuf()->freeze(0);
1011 void BScreen::setWorkspaceCount(int w) {
1012 resource.workspaces = w;
1014 s << "session.screen" << getScreenNumber() << ".workspaces" << ends;
1015 config.setValue(s.str(), resource.workspaces);
1016 s.rdbuf()->freeze(0);
1020 void BScreen::setPlacementPolicy(int p) {
1021 resource.placement_policy = p;
1023 s << "session.screen" << getScreenNumber() << ".windowPlacement" << ends;
1024 const char *placement;
1025 switch (resource.placement_policy) {
1026 case CascadePlacement: placement = "CascadePlacement"; break;
1027 case BestFitPlacement: placement = "BestFitPlacement"; break;
1028 case ColSmartPlacement: placement = "ColSmartPlacement"; break;
1029 case UnderMousePlacement: placement = "UnderMousePlacement"; break;
1030 case ClickMousePlacement: placement = "ClickMousePlacement"; break;
1032 case RowSmartPlacement: placement = "RowSmartPlacement"; break;
1034 config.setValue(s.str(), placement);
1035 s.rdbuf()->freeze(0);
1039 void BScreen::setEdgeSnapThreshold(int t) {
1040 resource.edge_snap_threshold = t;
1042 s << "session.screen" << getScreenNumber() << ".edgeSnapThreshold" << ends;
1043 config.setValue(s.str(), resource.edge_snap_threshold);
1044 s.rdbuf()->freeze(0);
1048 void BScreen::setRowPlacementDirection(int d) {
1049 resource.row_direction = d;
1051 s << "session.screen" << getScreenNumber() << ".rowPlacementDirection" <<
1053 config.setValue(s.str(),
1054 resource.row_direction == LeftRight ?
1055 "LeftToRight" : "RightToLeft");
1056 s.rdbuf()->freeze(0);
1060 void BScreen::setColPlacementDirection(int d) {
1061 resource.col_direction = d;
1063 s << "session.screen" << getScreenNumber() << ".colPlacementDirection" <<
1065 config.setValue(s.str(),
1066 resource.col_direction == TopBottom ?
1067 "TopToBottom" : "BottomToTop");
1068 s.rdbuf()->freeze(0);
1072 void BScreen::setRootCommand(const char *cmd) {
1073 if (resource.root_command != NULL)
1074 delete [] resource.root_command;
1076 resource.root_command = bstrdup(cmd);
1078 resource.root_command = NULL;
1079 // this doesn't save to the Resources config because it can't be changed
1080 // inside Openbox, and this way we dont add an empty command which would over-
1081 // ride the styles command when none has been specified
1085 #ifdef HAVE_STRFTIME
1086 void BScreen::setStrftimeFormat(const char *f) {
1087 if (resource.strftime_format != NULL)
1088 delete [] resource.strftime_format;
1090 resource.strftime_format = bstrdup(f);
1092 s << "session.screen" << getScreenNumber() << ".strftimeFormat" << ends;
1093 config.setValue(s.str(), resource.strftime_format);
1094 s.rdbuf()->freeze(0);
1097 #else // !HAVE_STRFTIME
1098 void BScreen::setDateFormat(int f) {
1099 resource.date_format = f;
1101 s << "session.screen" << getScreenNumber() << ".dateFormat" << ends;
1102 config.setValue(s.str(), resource.date_format == B_EuropeanDate ?
1103 "European" : "American");
1104 s.rdbuf()->freeze(0);
1107 void BScreen::setClock24Hour(Bool c) {
1108 resource.clock24hour = c;
1110 s << "session.screen" << getScreenNumber() << ".clockFormat" << ends;
1111 config.setValue(s.str(), resource.clock24hour ? 24 : 12);
1112 s.rdbuf()->freeze(0);
1114 #endif // HAVE_STRFTIME
1116 void BScreen::setHideToolbar(bool b) {
1117 resource.hide_toolbar = b;
1118 if (resource.hide_toolbar)
1119 getToolbar()->unMapToolbar();
1121 getToolbar()->mapToolbar();
1123 s << "session.screen" << getScreenNumber() << ".hideToolbar" << ends;
1124 config.setValue(s.str(), resource.hide_toolbar ? "True" : "False");
1125 s.rdbuf()->freeze(0);
1128 void BScreen::saveWorkspaceNames() {
1129 std::ostrstream rc, names;
1131 for (int i = 0; i < resource.workspaces; i++) {
1132 Workspace *w = getWorkspace(i);
1134 names << w->getName();
1135 if (i < resource.workspaces-1)
1141 rc << "session.screen" << getScreenNumber() << ".workspaceNames" << ends;
1142 config.setValue(rc.str(), names.str());
1143 rc.rdbuf()->freeze(0);
1144 names.rdbuf()->freeze(0);
1147 void BScreen::save() {
1148 setSloppyFocus(resource.sloppy_focus);
1149 setAutoRaise(resource.auto_raise);
1150 setImageDither(resource.image_dither, false);
1151 setOpaqueMove(resource.opaque_move);
1152 setFullMax(resource.full_max);
1153 setFocusNew(resource.focus_new);
1154 setFocusLast(resource.focus_last);
1155 setWindowZones(resource.zones);
1156 setWorkspaceCount(resource.workspaces);
1157 setPlacementPolicy(resource.placement_policy);
1158 setEdgeSnapThreshold(resource.edge_snap_threshold);
1159 setRowPlacementDirection(resource.row_direction);
1160 setColPlacementDirection(resource.col_direction);
1161 setRootCommand(resource.root_command);
1162 #ifdef HAVE_STRFTIME
1163 // it deletes the current value before setting the new one, so we have to
1164 // duplicate the current value.
1165 std::string s = resource.strftime_format;
1166 setStrftimeFormat(s.c_str());
1167 #else // !HAVE_STRFTIME
1168 setDateFormat(resource.date_format);
1169 setClock24Hour(resource.clock24hour);
1170 #endif // HAVE_STRFTIME
1171 setHideToolbar(resource.hide_toolbar);
1174 void BScreen::load() {
1175 std::ostrstream rscreen, rname, rclass;
1179 rscreen << "session.screen" << getScreenNumber() << '.' << ends;
1181 rname << rscreen.str() << "hideToolbar" << ends;
1182 rclass << rscreen.str() << "HideToolbar" << ends;
1183 if (config.getValue(rname.str(), rclass.str(), b))
1184 resource.hide_toolbar = b;
1186 resource.hide_toolbar = false;
1187 Toolbar *t = getToolbar();
1189 if (resource.hide_toolbar)
1195 rname.seekp(0); rclass.seekp(0);
1196 rname << rscreen.str() << "fullMaximization" << ends;
1197 rclass << rscreen.str() << "FullMaximization" << ends;
1198 if (config.getValue(rname.str(), rclass.str(), b))
1199 resource.full_max = b;
1201 resource.full_max = false;
1203 rname.seekp(0); rclass.seekp(0);
1204 rname << rscreen.str() << "focusNewWindows" << ends;
1205 rclass << rscreen.str() << "FocusNewWindows" << ends;
1206 if (config.getValue(rname.str(), rclass.str(), b))
1207 resource.focus_new = b;
1209 resource.focus_new = false;
1211 rname.seekp(0); rclass.seekp(0);
1212 rname << rscreen.str() << "focusLastWindow" << ends;
1213 rclass << rscreen.str() << "FocusLastWindow" << ends;
1214 if (config.getValue(rname.str(), rclass.str(), b))
1215 resource.focus_last = b;
1217 resource.focus_last = false;
1219 rname.seekp(0); rclass.seekp(0);
1220 rname << rscreen.str() << "rowPlacementDirection" << ends;
1221 rclass << rscreen.str() << "RowPlacementDirection" << ends;
1222 if (config.getValue(rname.str(), rclass.str(), s)) {
1223 if (0 == strncasecmp(s.c_str(), "RightToLeft", s.length()))
1224 resource.row_direction = RightLeft;
1225 else //if (0 == strncasecmp(s.c_str(), "LeftToRight", s.length()))
1226 resource.row_direction = LeftRight;
1228 resource.row_direction = LeftRight;
1230 rname.seekp(0); rclass.seekp(0);
1231 rname << rscreen.str() << "colPlacementDirection" << ends;
1232 rclass << rscreen.str() << "ColPlacementDirection" << ends;
1233 if (config.getValue(rname.str(), rclass.str(), s)) {
1234 if (0 == strncasecmp(s.c_str(), "BottomToTop", s.length()))
1235 resource.col_direction = BottomTop;
1236 else //if (0 == strncasecmp(s.c_str(), "TopToBottom", s.length()))
1237 resource.col_direction = TopBottom;
1239 resource.col_direction = TopBottom;
1241 rname.seekp(0); rclass.seekp(0);
1242 rname << rscreen.str() << "workspaces" << ends;
1243 rclass << rscreen.str() << "Workspaces" << ends;
1244 if (config.getValue(rname.str(), rclass.str(), l))
1245 resource.workspaces = l;
1247 resource.workspaces = 1;
1249 removeWorkspaceNames();
1250 rname.seekp(0); rclass.seekp(0);
1251 rname << rscreen.str() << "workspaceNames" << ends;
1252 rclass << rscreen.str() << "WorkspaceNames" << ends;
1253 if (config.getValue(rname.str(), rclass.str(), s)) {
1254 std::string::const_iterator it = s.begin(), end = s.end();
1256 std::string::const_iterator tmp = it;// current string.begin()
1257 it = std::find(tmp, end, ','); // look for comma between tmp and end
1258 std::string name(tmp, it); // name = s[tmp:it]
1259 addWorkspaceName(name.c_str());
1266 rname.seekp(0); rclass.seekp(0);
1267 rname << rscreen.str() << "focusModel" << ends;
1268 rclass << rscreen.str() << "FocusModel" << ends;
1269 if (config.getValue(rname.str(), rclass.str(), s)) {
1270 if (0 == strncasecmp(s.c_str(), "ClickToFocus", s.length())) {
1271 resource.auto_raise = false;
1272 resource.sloppy_focus = false;
1273 } else if (0 == strncasecmp(s.c_str(), "AutoRaiseSloppyFocus",
1275 resource.sloppy_focus = true;
1276 resource.auto_raise = true;
1277 } else { //if (0 == strncasecmp(s.c_str(), "SloppyFocus", s.length())) {
1278 resource.sloppy_focus = true;
1279 resource.auto_raise = false;
1282 resource.sloppy_focus = true;
1283 resource.auto_raise = false;
1286 rname.seekp(0); rclass.seekp(0);
1287 rname << rscreen.str() << "windowZones" << ends;
1288 rclass << rscreen.str() << "WindowZones" << ends;
1289 if (config.getValue(rname.str(), rclass.str(), l))
1290 resource.zones = (l == 1 || l == 2 || l == 4) ? l : 1;
1294 rname.seekp(0); rclass.seekp(0);
1295 rname << rscreen.str() << "windowPlacement" << ends;
1296 rclass << rscreen.str() << "WindowPlacement" << ends;
1297 if (config.getValue(rname.str(), rclass.str(), s)) {
1298 if (0 == strncasecmp(s.c_str(), "RowSmartPlacement", s.length()))
1299 resource.placement_policy = RowSmartPlacement;
1300 else if (0 == strncasecmp(s.c_str(), "ColSmartPlacement", s.length()))
1301 resource.placement_policy = ColSmartPlacement;
1302 else if (0 == strncasecmp(s.c_str(), "BestFitPlacement", s.length()))
1303 resource.placement_policy = BestFitPlacement;
1304 else if (0 == strncasecmp(s.c_str(), "UnderMousePlacement", s.length()))
1305 resource.placement_policy = UnderMousePlacement;
1306 else if (0 == strncasecmp(s.c_str(), "ClickMousePlacement", s.length()))
1307 resource.placement_policy = ClickMousePlacement;
1308 else //if (0 == strncasecmp(s.c_str(), "CascadePlacement", s.length()))
1309 resource.placement_policy = CascadePlacement;
1311 resource.placement_policy = CascadePlacement;
1313 #ifdef HAVE_STRFTIME
1314 rname.seekp(0); rclass.seekp(0);
1315 rname << rscreen.str() << "strftimeFormat" << ends;
1316 rclass << rscreen.str() << "StrftimeFormat" << ends;
1318 if (resource.strftime_format != NULL)
1319 delete [] resource.strftime_format;
1321 if (config.getValue(rname.str(), rclass.str(), s))
1322 resource.strftime_format = bstrdup(s.c_str());
1324 resource.strftime_format = bstrdup("%I:%M %p");
1325 #else // !HAVE_STRFTIME
1326 rname.seekp(0); rclass.seekp(0);
1327 rname << rscreen.str() << "dateFormat" << ends;
1328 rclass << rscreen.str() << "DateFormat" << ends;
1329 if (config.getValue(rname.str(), rclass.str(), s)) {
1330 if (strncasecmp(s.c_str(), "European", s.length()))
1331 resource.date_format = B_EuropeanDate;
1332 else //if (strncasecmp(s.c_str(), "American", s.length()))
1333 resource.date_format = B_AmericanDate;
1335 resource.date_format = B_AmericanDate;
1337 rname.seekp(0); rclass.seekp(0);
1338 rname << rscreen.str() << "clockFormat" << ends;
1339 rclass << rscreen.str() << "ClockFormat" << ends;
1340 if (config.getValue(rname.str(), rclass.str(), l)) {
1342 resource.clock24hour = true;
1343 else if (clock == 12)
1344 resource.clock24hour = false;
1346 resource.clock24hour = false;
1347 #endif // HAVE_STRFTIME
1349 rname.seekp(0); rclass.seekp(0);
1350 rname << rscreen.str() << "edgeSnapThreshold" << ends;
1351 rclass << rscreen.str() << "EdgeSnapThreshold" << ends;
1352 if (config.getValue(rname.str(), rclass.str(), l))
1353 resource.edge_snap_threshold = l;
1355 resource.edge_snap_threshold = 4;
1357 rname.seekp(0); rclass.seekp(0);
1358 rname << rscreen.str() << "imageDither" << ends;
1359 rclass << rscreen.str() << "ImageDither" << ends;
1360 if (config.getValue(rname.str(), rclass.str(), b))
1361 resource.image_dither = b;
1363 resource.image_dither = true;
1365 rname.seekp(0); rclass.seekp(0);
1366 rname << rscreen.str() << "rootCommand" << ends;
1367 rclass << rscreen.str() << "RootCommand" << ends;
1369 if (resource.root_command != NULL)
1370 delete [] resource.root_command;
1372 if (config.getValue(rname.str(), rclass.str(), s))
1373 resource.root_command = bstrdup(s.c_str());
1375 resource.root_command = NULL;
1377 rname.seekp(0); rclass.seekp(0);
1378 rname << rscreen.str() << "opaqueMove" << ends;
1379 rclass << rscreen.str() << "OpaqueMove" << ends;
1380 if (config.getValue(rname.str(), rclass.str(), b))
1381 resource.opaque_move = b;
1383 resource.opaque_move = false;
1385 rscreen.rdbuf()->freeze(0);
1386 rname.rdbuf()->freeze(0);
1387 rclass.rdbuf()->freeze(0);
1390 void BScreen::reconfigure(void) {
1399 unsigned long gc_value_mask = GCForeground;
1400 if (! i18n->multibyte()) gc_value_mask |= GCFont;
1402 gcv.foreground = WhitePixel(getBaseDisplay().getXDisplay(),
1404 gcv.function = GXinvert;
1405 gcv.subwindow_mode = IncludeInferiors;
1406 XChangeGC(getBaseDisplay().getXDisplay(), opGC,
1407 GCForeground | GCFunction | GCSubwindowMode, &gcv);
1409 gcv.foreground = resource.wstyle.l_text_focus.getPixel();
1410 if (resource.wstyle.font)
1411 gcv.font = resource.wstyle.font->fid;
1412 XChangeGC(getBaseDisplay().getXDisplay(), resource.wstyle.l_text_focus_gc,
1413 gc_value_mask, &gcv);
1415 gcv.foreground = resource.wstyle.l_text_unfocus.getPixel();
1416 XChangeGC(getBaseDisplay().getXDisplay(), resource.wstyle.l_text_unfocus_gc,
1417 gc_value_mask, &gcv);
1419 gcv.foreground = resource.wstyle.b_pic_focus.getPixel();
1420 XChangeGC(getBaseDisplay().getXDisplay(), resource.wstyle.b_pic_focus_gc,
1421 GCForeground, &gcv);
1423 gcv.foreground = resource.wstyle.b_pic_unfocus.getPixel();
1424 XChangeGC(getBaseDisplay().getXDisplay(), resource.wstyle.b_pic_unfocus_gc,
1425 GCForeground, &gcv);
1427 gcv.foreground = resource.mstyle.t_text.getPixel();
1428 if (resource.mstyle.t_font)
1429 gcv.font = resource.mstyle.t_font->fid;
1430 XChangeGC(getBaseDisplay().getXDisplay(), resource.mstyle.t_text_gc,
1431 gc_value_mask, &gcv);
1433 gcv.foreground = resource.mstyle.f_text.getPixel();
1434 if (resource.mstyle.f_font)
1435 gcv.font = resource.mstyle.f_font->fid;
1436 XChangeGC(getBaseDisplay().getXDisplay(), resource.mstyle.f_text_gc,
1437 gc_value_mask, &gcv);
1439 gcv.foreground = resource.mstyle.h_text.getPixel();
1440 XChangeGC(getBaseDisplay().getXDisplay(), resource.mstyle.h_text_gc,
1441 gc_value_mask, &gcv);
1443 gcv.foreground = resource.mstyle.d_text.getPixel();
1444 XChangeGC(getBaseDisplay().getXDisplay(), resource.mstyle.d_text_gc,
1445 gc_value_mask, &gcv);
1447 gcv.foreground = resource.mstyle.hilite.getColor()->getPixel();
1448 XChangeGC(getBaseDisplay().getXDisplay(), resource.mstyle.hilite_gc,
1449 gc_value_mask, &gcv);
1451 gcv.foreground = resource.tstyle.l_text.getPixel();
1452 if (resource.tstyle.font)
1453 gcv.font = resource.tstyle.font->fid;
1454 XChangeGC(getBaseDisplay().getXDisplay(), resource.tstyle.l_text_gc,
1455 gc_value_mask, &gcv);
1457 gcv.foreground = resource.tstyle.w_text.getPixel();
1458 XChangeGC(getBaseDisplay().getXDisplay(), resource.tstyle.w_text_gc,
1459 gc_value_mask, &gcv);
1461 gcv.foreground = resource.tstyle.c_text.getPixel();
1462 XChangeGC(getBaseDisplay().getXDisplay(), resource.tstyle.c_text_gc,
1463 gc_value_mask, &gcv);
1465 gcv.foreground = resource.tstyle.b_pic.getPixel();
1466 XChangeGC(getBaseDisplay().getXDisplay(), resource.tstyle.b_pic_gc,
1467 gc_value_mask, &gcv);
1469 const char *s = i18n->getMessage(ScreenSet, ScreenPositionLength,
1470 "0: 0000 x 0: 0000");
1473 if (i18n->multibyte()) {
1474 XRectangle ink, logical;
1475 XmbTextExtents(resource.wstyle.fontset, s, l, &ink, &logical);
1476 geom_w = logical.width;
1478 geom_h = resource.wstyle.fontset_extents->max_ink_extent.height;
1480 geom_w = XTextWidth(resource.wstyle.font, s, l);
1482 geom_h = resource.wstyle.font->ascent +
1483 resource.wstyle.font->descent;
1486 geom_w += (resource.bevel_width * 2);
1487 geom_h += (resource.bevel_width * 2);
1489 Pixmap tmp = geom_pixmap;
1490 if (resource.wstyle.l_focus.getTexture() & BImage_ParentRelative) {
1491 if (resource.wstyle.t_focus.getTexture() ==
1492 (BImage_Flat | BImage_Solid)) {
1494 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window,
1495 resource.wstyle.t_focus.getColor()->getPixel());
1497 geom_pixmap = image_control->renderImage(geom_w, geom_h,
1498 &resource.wstyle.t_focus);
1499 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
1500 geom_window, geom_pixmap);
1503 if (resource.wstyle.l_focus.getTexture() ==
1504 (BImage_Flat | BImage_Solid)) {
1506 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window,
1507 resource.wstyle.l_focus.getColor()->getPixel());
1509 geom_pixmap = image_control->renderImage(geom_w, geom_h,
1510 &resource.wstyle.l_focus);
1511 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
1512 geom_window, geom_pixmap);
1515 if (tmp) image_control->removeImage(tmp);
1517 XSetWindowBorderWidth(getBaseDisplay().getXDisplay(), geom_window,
1518 resource.border_width);
1519 XSetWindowBorder(getBaseDisplay().getXDisplay(), geom_window,
1520 resource.border_color.getPixel());
1522 workspacemenu->reconfigure();
1523 iconmenu->reconfigure();
1526 int remember_sub = rootmenu->getCurrentSubmenu();
1529 rootmenu->reconfigure();
1530 rootmenu->drawSubmenu(remember_sub);
1533 configmenu->reconfigure();
1535 toolbar->reconfigure();
1538 slit->reconfigure();
1541 LinkedListIterator<Workspace> wit(workspacesList);
1542 for (Workspace *w = wit.current(); w; wit++, w = wit.current())
1545 LinkedListIterator<OpenboxWindow> iit(iconList);
1546 for (OpenboxWindow *bw = iit.current(); bw; iit++, bw = iit.current())
1547 if (bw->validateClient())
1550 image_control->timeout();
1554 void BScreen::rereadMenu(void) {
1558 rootmenu->reconfigure();
1562 void BScreen::removeWorkspaceNames(void) {
1563 while (workspaceNames->count())
1564 delete [] workspaceNames->remove(0);
1568 void BScreen::LoadStyle(void) {
1569 Resource &conf = resource.styleconfig;
1571 const char *sfile = openbox.getStyleFilename();
1572 bool loaded = false;
1573 if (sfile != NULL) {
1574 conf.setFile(sfile);
1575 loaded = conf.load();
1578 conf.setFile(DEFAULTSTYLE);
1580 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenDefaultStyleLoadFail,
1581 "BScreen::LoadStyle(): couldn't load "
1582 "default style.\n"));
1590 // load fonts/fontsets
1592 if (i18n->multibyte()) {
1593 readDatabaseFontSet("window.font", "Window.Font",
1594 &resource.wstyle.fontset);
1595 readDatabaseFontSet("toolbar.font", "Toolbar.Font",
1596 &resource.tstyle.fontset);
1597 readDatabaseFontSet("menu.title.font", "Menu.Title.Font",
1598 &resource.mstyle.t_fontset);
1599 readDatabaseFontSet("menu.frame.font", "Menu.Frame.Font",
1600 &resource.mstyle.f_fontset);
1602 resource.mstyle.t_fontset_extents =
1603 XExtentsOfFontSet(resource.mstyle.t_fontset);
1604 resource.mstyle.f_fontset_extents =
1605 XExtentsOfFontSet(resource.mstyle.f_fontset);
1606 resource.tstyle.fontset_extents =
1607 XExtentsOfFontSet(resource.tstyle.fontset);
1608 resource.wstyle.fontset_extents =
1609 XExtentsOfFontSet(resource.wstyle.fontset);
1611 readDatabaseFont("window.font", "Window.Font",
1612 &resource.wstyle.font);
1613 readDatabaseFont("menu.title.font", "Menu.Title.Font",
1614 &resource.mstyle.t_font);
1615 readDatabaseFont("menu.frame.font", "Menu.Frame.Font",
1616 &resource.mstyle.f_font);
1617 readDatabaseFont("toolbar.font", "Toolbar.Font",
1618 &resource.tstyle.font);
1621 // load window config
1622 readDatabaseTexture("window.title.focus", "Window.Title.Focus",
1623 &resource.wstyle.t_focus,
1624 WhitePixel(getBaseDisplay().getXDisplay(),
1625 getScreenNumber()));
1626 readDatabaseTexture("window.title.unfocus", "Window.Title.Unfocus",
1627 &resource.wstyle.t_unfocus,
1628 BlackPixel(getBaseDisplay().getXDisplay(),
1629 getScreenNumber()));
1630 readDatabaseTexture("window.label.focus", "Window.Label.Focus",
1631 &resource.wstyle.l_focus,
1632 WhitePixel(getBaseDisplay().getXDisplay(),
1633 getScreenNumber()));
1634 readDatabaseTexture("window.label.unfocus", "Window.Label.Unfocus",
1635 &resource.wstyle.l_unfocus,
1636 BlackPixel(getBaseDisplay().getXDisplay(),
1637 getScreenNumber()));
1638 readDatabaseTexture("window.handle.focus", "Window.Handle.Focus",
1639 &resource.wstyle.h_focus,
1640 WhitePixel(getBaseDisplay().getXDisplay(),
1641 getScreenNumber()));
1642 readDatabaseTexture("window.handle.unfocus", "Window.Handle.Unfocus",
1643 &resource.wstyle.h_unfocus,
1644 BlackPixel(getBaseDisplay().getXDisplay(),
1645 getScreenNumber()));
1646 readDatabaseTexture("window.grip.focus", "Window.Grip.Focus",
1647 &resource.wstyle.g_focus,
1648 WhitePixel(getBaseDisplay().getXDisplay(),
1649 getScreenNumber()));
1650 readDatabaseTexture("window.grip.unfocus", "Window.Grip.Unfocus",
1651 &resource.wstyle.g_unfocus,
1652 BlackPixel(getBaseDisplay().getXDisplay(),
1653 getScreenNumber()));
1654 readDatabaseTexture("window.button.focus", "Window.Button.Focus",
1655 &resource.wstyle.b_focus,
1656 WhitePixel(getBaseDisplay().getXDisplay(),
1657 getScreenNumber()));
1658 readDatabaseTexture("window.button.unfocus", "Window.Button.Unfocus",
1659 &resource.wstyle.b_unfocus,
1660 BlackPixel(getBaseDisplay().getXDisplay(),
1661 getScreenNumber()));
1662 readDatabaseTexture("window.button.pressed", "Window.Button.Pressed",
1663 &resource.wstyle.b_pressed,
1664 BlackPixel(getBaseDisplay().getXDisplay(),
1665 getScreenNumber()));
1666 readDatabaseColor("window.frame.focusColor",
1667 "Window.Frame.FocusColor",
1668 &resource.wstyle.f_focus,
1669 WhitePixel(getBaseDisplay().getXDisplay(),
1670 getScreenNumber()));
1671 readDatabaseColor("window.frame.unfocusColor",
1672 "Window.Frame.UnfocusColor",
1673 &resource.wstyle.f_unfocus,
1674 BlackPixel(getBaseDisplay().getXDisplay(),
1675 getScreenNumber()));
1676 readDatabaseColor("window.label.focus.textColor",
1677 "Window.Label.Focus.TextColor",
1678 &resource.wstyle.l_text_focus,
1679 BlackPixel(getBaseDisplay().getXDisplay(),
1680 getScreenNumber()));
1681 readDatabaseColor("window.label.unfocus.textColor",
1682 "Window.Label.Unfocus.TextColor",
1683 &resource.wstyle.l_text_unfocus,
1684 WhitePixel(getBaseDisplay().getXDisplay(),
1685 getScreenNumber()));
1686 readDatabaseColor("window.button.focus.picColor",
1687 "Window.Button.Focus.PicColor",
1688 &resource.wstyle.b_pic_focus,
1689 BlackPixel(getBaseDisplay().getXDisplay(),
1690 getScreenNumber()));
1691 readDatabaseColor("window.button.unfocus.picColor",
1692 "Window.Button.Unfocus.PicColor",
1693 &resource.wstyle.b_pic_unfocus,
1694 WhitePixel(getBaseDisplay().getXDisplay(),
1695 getScreenNumber()));
1697 if (conf.getValue("window.justify", "Window.Justify", s)) {
1698 if (0 == strncasecmp(s.c_str(), "right", s.length()))
1699 resource.wstyle.justify = BScreen::RightJustify;
1700 else if (0 == strncasecmp(s.c_str(), "center", s.length()))
1701 resource.wstyle.justify = BScreen::CenterJustify;
1703 resource.wstyle.justify = BScreen::LeftJustify;
1705 resource.wstyle.justify = BScreen::LeftJustify;
1707 // load toolbar config
1708 readDatabaseTexture("toolbar", "Toolbar",
1709 &resource.tstyle.toolbar,
1710 BlackPixel(getBaseDisplay().getXDisplay(),
1711 getScreenNumber()));
1712 readDatabaseTexture("toolbar.label", "Toolbar.Label",
1713 &resource.tstyle.label,
1714 BlackPixel(getBaseDisplay().getXDisplay(),
1715 getScreenNumber()));
1716 readDatabaseTexture("toolbar.windowLabel", "Toolbar.WindowLabel",
1717 &resource.tstyle.window,
1718 BlackPixel(getBaseDisplay().getXDisplay(),
1719 getScreenNumber()));
1720 readDatabaseTexture("toolbar.button", "Toolbar.Button",
1721 &resource.tstyle.button,
1722 WhitePixel(getBaseDisplay().getXDisplay(),
1723 getScreenNumber()));
1724 readDatabaseTexture("toolbar.button.pressed", "Toolbar.Button.Pressed",
1725 &resource.tstyle.pressed,
1726 BlackPixel(getBaseDisplay().getXDisplay(),
1727 getScreenNumber()));
1728 readDatabaseTexture("toolbar.clock", "Toolbar.Clock",
1729 &resource.tstyle.clock,
1730 BlackPixel(getBaseDisplay().getXDisplay(),
1731 getScreenNumber()));
1732 readDatabaseColor("toolbar.label.textColor", "Toolbar.Label.TextColor",
1733 &resource.tstyle.l_text,
1734 WhitePixel(getBaseDisplay().getXDisplay(),
1735 getScreenNumber()));
1736 readDatabaseColor("toolbar.windowLabel.textColor",
1737 "Toolbar.WindowLabel.TextColor",
1738 &resource.tstyle.w_text,
1739 WhitePixel(getBaseDisplay().getXDisplay(),
1740 getScreenNumber()));
1741 readDatabaseColor("toolbar.clock.textColor", "Toolbar.Clock.TextColor",
1742 &resource.tstyle.c_text,
1743 WhitePixel(getBaseDisplay().getXDisplay(),
1744 getScreenNumber()));
1745 readDatabaseColor("toolbar.button.picColor", "Toolbar.Button.PicColor",
1746 &resource.tstyle.b_pic,
1747 BlackPixel(getBaseDisplay().getXDisplay(),
1748 getScreenNumber()));
1750 if (conf.getValue("toolbar.justify", "Toolbar.Justify", s)) {
1751 if (0 == strncasecmp(s.c_str(), "right", s.length()))
1752 resource.tstyle.justify = BScreen::RightJustify;
1753 else if (0 == strncasecmp(s.c_str(), "center", s.length()))
1754 resource.tstyle.justify = BScreen::CenterJustify;
1756 resource.tstyle.justify = BScreen::LeftJustify;
1758 resource.tstyle.justify = BScreen::LeftJustify;
1761 readDatabaseTexture("menu.title", "Menu.Title",
1762 &resource.mstyle.title,
1763 WhitePixel(getBaseDisplay().getXDisplay(),
1764 getScreenNumber()));
1765 readDatabaseTexture("menu.frame", "Menu.Frame",
1766 &resource.mstyle.frame,
1767 BlackPixel(getBaseDisplay().getXDisplay(),
1768 getScreenNumber()));
1769 readDatabaseTexture("menu.hilite", "Menu.Hilite",
1770 &resource.mstyle.hilite,
1771 WhitePixel(getBaseDisplay().getXDisplay(),
1772 getScreenNumber()));
1773 readDatabaseColor("menu.title.textColor", "Menu.Title.TextColor",
1774 &resource.mstyle.t_text,
1775 BlackPixel(getBaseDisplay().getXDisplay(),
1776 getScreenNumber()));
1777 readDatabaseColor("menu.frame.textColor", "Menu.Frame.TextColor",
1778 &resource.mstyle.f_text,
1779 WhitePixel(getBaseDisplay().getXDisplay(),
1780 getScreenNumber()));
1781 readDatabaseColor("menu.frame.disableColor", "Menu.Frame.DisableColor",
1782 &resource.mstyle.d_text,
1783 BlackPixel(getBaseDisplay().getXDisplay(),
1784 getScreenNumber()));
1785 readDatabaseColor("menu.hilite.textColor", "Menu.Hilite.TextColor",
1786 &resource.mstyle.h_text,
1787 BlackPixel(getBaseDisplay().getXDisplay(),
1788 getScreenNumber()));
1790 if (conf.getValue("menu.title.justify", "Menu.Title.Justify", s)) {
1791 if (0 == strncasecmp(s.c_str(), "right", s.length()))
1792 resource.mstyle.t_justify = BScreen::RightJustify;
1793 else if (0 == strncasecmp(s.c_str(), "center", s.length()))
1794 resource.mstyle.t_justify = BScreen::CenterJustify;
1796 resource.mstyle.t_justify = BScreen::LeftJustify;
1798 resource.mstyle.t_justify = BScreen::LeftJustify;
1800 if (conf.getValue("menu.frame.justify", "Menu.Frame.Justify", s)) {
1801 if (0 == strncasecmp(s.c_str(), "right", s.length()))
1802 resource.mstyle.f_justify = BScreen::RightJustify;
1803 else if (0 == strncasecmp(s.c_str(), "center", s.length()))
1804 resource.mstyle.f_justify = BScreen::CenterJustify;
1806 resource.mstyle.f_justify = BScreen::LeftJustify;
1808 resource.mstyle.f_justify = BScreen::LeftJustify;
1810 if (conf.getValue("menu.bullet", "Menu.Bullet", s)) {
1811 if (0 == strncasecmp(s.c_str(), "empty", s.length()))
1812 resource.mstyle.bullet = Basemenu::Empty;
1813 else if (0 == strncasecmp(s.c_str(), "square", s.length()))
1814 resource.mstyle.bullet = Basemenu::Square;
1815 else if (0 == strncasecmp(s.c_str(), "diamond", s.length()))
1816 resource.mstyle.bullet = Basemenu::Diamond;
1818 resource.mstyle.bullet = Basemenu::Triangle;
1820 resource.mstyle.bullet = Basemenu::Triangle;
1822 if (conf.getValue("menu.bullet.position", "Menu.Bullet.Position", s)) {
1823 if (0 == strncasecmp(s.c_str(), "right", s.length()))
1824 resource.mstyle.bullet_pos = Basemenu::Right;
1826 resource.mstyle.bullet_pos = Basemenu::Left;
1828 resource.mstyle.bullet_pos = Basemenu::Left;
1830 readDatabaseColor("borderColor", "BorderColor", &resource.border_color,
1831 BlackPixel(getBaseDisplay().getXDisplay(),
1832 getScreenNumber()));
1834 // load bevel, border and handle widths
1835 if (conf.getValue("handleWidth", "HandleWidth", l)) {
1836 if (l <= size().w() / 2 && l != 0)
1837 resource.handle_width = l;
1839 resource.handle_width = 6;
1841 resource.handle_width = 6;
1843 if (conf.getValue("borderWidth", "BorderWidth", l))
1844 resource.border_width = l;
1846 resource.border_width = 1;
1848 if (conf.getValue("bevelWidth", "BevelWidth", l)) {
1849 if (l <= size().w() / 2 && l != 0)
1850 resource.bevel_width = l;
1852 resource.bevel_width = 3;
1854 resource.bevel_width = 3;
1856 if (conf.getValue("frameWidth", "FrameWidth", l)) {
1857 if (l <= size().w() / 2)
1858 resource.frame_width = l;
1860 resource.frame_width = resource.bevel_width;
1862 resource.frame_width = resource.bevel_width;
1864 const char *cmd = resource.root_command;
1865 if (cmd != NULL || conf.getValue("rootCommand", "RootCommand", s)) {
1867 cmd = s.c_str(); // not specified by the screen, so use the one from the
1870 char displaystring[MAXPATHLEN];
1871 sprintf(displaystring, "DISPLAY=%s",
1872 DisplayString(getBaseDisplay().getXDisplay()));
1873 sprintf(displaystring + strlen(displaystring) - 1, "%d",
1876 bexec(cmd, displaystring);
1878 spawnlp(P_NOWAIT, "cmd.exe", "cmd.exe", "/c", cmd, NULL);
1884 void BScreen::addIcon(OpenboxWindow *w) {
1887 w->setWorkspace(-1);
1888 w->setWindowNumber(iconList->count());
1890 iconList->insert(w);
1892 iconmenu->insert((const char **) w->getIconTitle());
1897 void BScreen::removeIcon(OpenboxWindow *w) {
1900 iconList->remove(w->getWindowNumber());
1902 iconmenu->remove(w->getWindowNumber());
1905 LinkedListIterator<OpenboxWindow> it(iconList);
1906 OpenboxWindow *bw = it.current();
1907 for (int i = 0; bw; it++, bw = it.current())
1908 bw->setWindowNumber(i++);
1912 OpenboxWindow *BScreen::getIcon(int index) {
1913 if (index >= 0 && index < iconList->count())
1914 return iconList->find(index);
1920 int BScreen::addWorkspace(void) {
1921 Workspace *wkspc = new Workspace(*this, workspacesList->count());
1922 workspacesList->insert(wkspc);
1923 saveWorkspaceNames();
1925 workspacemenu->insert(wkspc->getName(), wkspc->getMenu(),
1926 wkspc->getWorkspaceID() + 2);
1927 workspacemenu->update();
1929 toolbar->reconfigure();
1931 updateNetizenWorkspaceCount();
1933 return workspacesList->count();
1937 int BScreen::removeLastWorkspace(void) {
1938 if (workspacesList->count() == 1)
1941 Workspace *wkspc = workspacesList->last();
1943 if (current_workspace->getWorkspaceID() == wkspc->getWorkspaceID())
1944 changeWorkspaceID(current_workspace->getWorkspaceID() - 1);
1948 workspacemenu->remove(wkspc->getWorkspaceID() + 2);
1949 workspacemenu->update();
1951 workspacesList->remove(wkspc);
1954 toolbar->reconfigure();
1956 updateNetizenWorkspaceCount();
1958 return workspacesList->count();
1962 void BScreen::changeWorkspaceID(int id) {
1963 if (! current_workspace) return;
1965 if (id != current_workspace->getWorkspaceID()) {
1966 current_workspace->hideAll();
1968 workspacemenu->setItemSelected(current_workspace->getWorkspaceID() + 2,
1971 if (openbox.getFocusedWindow() &&
1972 openbox.getFocusedWindow()->getScreen() == this &&
1973 (! openbox.getFocusedWindow()->isStuck())) {
1974 current_workspace->setLastFocusedWindow(openbox.getFocusedWindow());
1975 openbox.setFocusedWindow(NULL);
1978 current_workspace = getWorkspace(id);
1980 workspacemenu->setItemSelected(current_workspace->getWorkspaceID() + 2,
1982 toolbar->redrawWorkspaceLabel(True);
1984 current_workspace->showAll();
1986 if (resource.focus_last && current_workspace->getLastFocusedWindow()) {
1987 XSync(openbox.getXDisplay(), False);
1988 current_workspace->getLastFocusedWindow()->setInputFocus();
1992 updateNetizenCurrentWorkspace();
1996 void BScreen::addNetizen(Netizen *n) {
1997 netizenList->insert(n);
1999 n->sendWorkspaceCount();
2000 n->sendCurrentWorkspace();
2002 LinkedListIterator<Workspace> it(workspacesList);
2003 for (Workspace *w = it.current(); w; it++, w = it.current()) {
2004 for (int i = 0; i < w->getCount(); i++)
2005 n->sendWindowAdd(w->getWindow(i)->getClientWindow(),
2006 w->getWorkspaceID());
2009 Window f = ((openbox.getFocusedWindow()) ?
2010 openbox.getFocusedWindow()->getClientWindow() : None);
2011 n->sendWindowFocus(f);
2015 void BScreen::removeNetizen(Window w) {
2016 LinkedListIterator<Netizen> it(netizenList);
2019 for (Netizen *n = it.current(); n; it++, i++, n = it.current())
2020 if (n->getWindowID() == w) {
2021 Netizen *tmp = netizenList->remove(i);
2029 void BScreen::updateNetizenCurrentWorkspace(void) {
2030 LinkedListIterator<Netizen> it(netizenList);
2031 for (Netizen *n = it.current(); n; it++, n = it.current())
2032 n->sendCurrentWorkspace();
2036 void BScreen::updateNetizenWorkspaceCount(void) {
2037 LinkedListIterator<Netizen> it(netizenList);
2038 for (Netizen *n = it.current(); n; it++, n = it.current())
2039 n->sendWorkspaceCount();
2043 void BScreen::updateNetizenWindowFocus(void) {
2044 Window f = ((openbox.getFocusedWindow()) ?
2045 openbox.getFocusedWindow()->getClientWindow() : None);
2046 LinkedListIterator<Netizen> it(netizenList);
2047 for (Netizen *n = it.current(); n; it++, n = it.current())
2048 n->sendWindowFocus(f);
2052 void BScreen::updateNetizenWindowAdd(Window w, unsigned long p) {
2053 LinkedListIterator<Netizen> it(netizenList);
2054 for (Netizen *n = it.current(); n; it++, n = it.current())
2055 n->sendWindowAdd(w, p);
2059 void BScreen::updateNetizenWindowDel(Window w) {
2060 LinkedListIterator<Netizen> it(netizenList);
2061 for (Netizen *n = it.current(); n; it++, n = it.current())
2062 n->sendWindowDel(w);
2066 void BScreen::updateNetizenWindowRaise(Window w) {
2067 LinkedListIterator<Netizen> it(netizenList);
2068 for (Netizen *n = it.current(); n; it++, n = it.current())
2069 n->sendWindowRaise(w);
2073 void BScreen::updateNetizenWindowLower(Window w) {
2074 LinkedListIterator<Netizen> it(netizenList);
2075 for (Netizen *n = it.current(); n; it++, n = it.current())
2076 n->sendWindowLower(w);
2080 void BScreen::updateNetizenConfigNotify(XEvent *e) {
2081 LinkedListIterator<Netizen> it(netizenList);
2082 for (Netizen *n = it.current(); n; it++, n = it.current())
2083 n->sendConfigNotify(e);
2087 void BScreen::raiseWindows(Window *workspace_stack, int num) {
2088 Window *session_stack = new
2089 Window[(num + workspacesList->count() + rootmenuList->count() + 13)];
2092 XRaiseWindow(getBaseDisplay().getXDisplay(), iconmenu->getWindowID());
2093 *(session_stack + i++) = iconmenu->getWindowID();
2095 LinkedListIterator<Workspace> wit(workspacesList);
2096 for (Workspace *tmp = wit.current(); tmp; wit++, tmp = wit.current())
2097 *(session_stack + i++) = tmp->getMenu()->getWindowID();
2099 *(session_stack + i++) = workspacemenu->getWindowID();
2101 *(session_stack + i++) = configmenu->getFocusmenu()->getWindowID();
2102 *(session_stack + i++) = configmenu->getPlacementmenu()->getWindowID();
2103 *(session_stack + i++) = configmenu->getWindowID();
2106 *(session_stack + i++) = slit->getMenu()->getDirectionmenu()->getWindowID();
2107 *(session_stack + i++) = slit->getMenu()->getPlacementmenu()->getWindowID();
2108 *(session_stack + i++) = slit->getMenu()->getWindowID();
2111 *(session_stack + i++) =
2112 toolbar->getMenu()->getPlacementmenu()->getWindowID();
2113 *(session_stack + i++) = toolbar->getMenu()->getWindowID();
2115 LinkedListIterator<Rootmenu> rit(rootmenuList);
2116 for (Rootmenu *tmp = rit.current(); tmp; rit++, tmp = rit.current())
2117 *(session_stack + i++) = tmp->getWindowID();
2118 *(session_stack + i++) = rootmenu->getWindowID();
2120 if (toolbar->onTop())
2121 *(session_stack + i++) = toolbar->getWindowID();
2125 *(session_stack + i++) = slit->getWindowID();
2129 *(session_stack + i++) = *(workspace_stack + k);
2131 XRestackWindows(getBaseDisplay().getXDisplay(), session_stack, i);
2133 delete [] session_stack;
2137 void BScreen::addWorkspaceName(const char *name) {
2138 workspaceNames->insert(bstrdup(name));
2141 char* BScreen::getNameOfWorkspace(int id) {
2144 if (id >= 0 && id < workspaceNames->count()) {
2145 char *wkspc_name = workspaceNames->find(id);
2154 void BScreen::reassociateWindow(OpenboxWindow *w, int wkspc_id, Bool ignore_sticky) {
2158 wkspc_id = current_workspace->getWorkspaceID();
2160 if (w->getWorkspaceNumber() == wkspc_id)
2163 if (w->isIconic()) {
2165 getWorkspace(wkspc_id)->addWindow(w);
2166 } else if (ignore_sticky || ! w->isStuck()) {
2167 getWorkspace(w->getWorkspaceNumber())->removeWindow(w);
2168 getWorkspace(wkspc_id)->addWindow(w);
2173 void BScreen::nextFocus(void) {
2174 Bool have_focused = False;
2175 int focused_window_number = -1;
2176 OpenboxWindow *next;
2178 if (openbox.getFocusedWindow()) {
2179 if (openbox.getFocusedWindow()->getScreen()->getScreenNumber() ==
2180 getScreenNumber()) {
2181 have_focused = True;
2182 focused_window_number = openbox.getFocusedWindow()->getWindowNumber();
2186 if ((getCurrentWorkspace()->getCount() > 1) && have_focused) {
2187 int next_window_number = focused_window_number;
2189 if ((++next_window_number) >= getCurrentWorkspace()->getCount())
2190 next_window_number = 0;
2192 next = getCurrentWorkspace()->getWindow(next_window_number);
2193 } while ((! next->setInputFocus()) && (next_window_number !=
2194 focused_window_number));
2196 if (next_window_number != focused_window_number)
2197 getCurrentWorkspace()->raiseWindow(next);
2198 } else if (getCurrentWorkspace()->getCount() >= 1) {
2199 next = current_workspace->getWindow(0);
2201 current_workspace->raiseWindow(next);
2202 next->setInputFocus();
2207 void BScreen::prevFocus(void) {
2208 Bool have_focused = False;
2209 int focused_window_number = -1;
2210 OpenboxWindow *prev;
2212 if (openbox.getFocusedWindow()) {
2213 if (openbox.getFocusedWindow()->getScreen()->getScreenNumber() ==
2214 getScreenNumber()) {
2215 have_focused = True;
2216 focused_window_number = openbox.getFocusedWindow()->getWindowNumber();
2220 if ((getCurrentWorkspace()->getCount() > 1) && have_focused) {
2221 int prev_window_number = focused_window_number;
2223 if ((--prev_window_number) < 0)
2224 prev_window_number = getCurrentWorkspace()->getCount() - 1;
2226 prev = getCurrentWorkspace()->getWindow(prev_window_number);
2227 } while ((! prev->setInputFocus()) && (prev_window_number !=
2228 focused_window_number));
2230 if (prev_window_number != focused_window_number)
2231 getCurrentWorkspace()->raiseWindow(prev);
2232 } else if (getCurrentWorkspace()->getCount() >= 1) {
2233 prev = current_workspace->getWindow(0);
2235 current_workspace->raiseWindow(prev);
2236 prev->setInputFocus();
2241 void BScreen::raiseFocus(void) {
2242 Bool have_focused = False;
2243 int focused_window_number = -1;
2245 if (openbox.getFocusedWindow()) {
2246 if (openbox.getFocusedWindow()->getScreen()->getScreenNumber() ==
2247 getScreenNumber()) {
2248 have_focused = True;
2249 focused_window_number = openbox.getFocusedWindow()->getWindowNumber();
2253 if ((getCurrentWorkspace()->getCount() > 1) && have_focused)
2254 getWorkspace(openbox.getFocusedWindow()->getWorkspaceNumber())->
2255 raiseWindow(openbox.getFocusedWindow());
2259 void BScreen::InitMenu(void) {
2261 while (rootmenuList->count())
2262 rootmenuList->remove(0);
2264 while (rootmenu->getCount())
2265 rootmenu->remove(0);
2267 rootmenu = new Rootmenu(*this);
2269 Bool defaultMenu = True;
2271 if (openbox.getMenuFilename()) {
2272 FILE *menu_file = fopen(openbox.getMenuFilename(), "r");
2275 perror(openbox.getMenuFilename());
2277 if (feof(menu_file)) {
2278 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenEmptyMenuFile,
2279 "%s: Empty menu file"),
2280 openbox.getMenuFilename());
2282 char line[1024], label[1024];
2283 memset(line, 0, 1024);
2284 memset(label, 0, 1024);
2286 while (fgets(line, 1024, menu_file) && ! feof(menu_file)) {
2287 if (line[0] != '#') {
2288 int i, key = 0, index = -1, len = strlen(line);
2291 for (i = 0; i < len; i++) {
2292 if (line[i] == '[') index = 0;
2293 else if (line[i] == ']') break;
2294 else if (line[i] != ' ')
2296 key += tolower(line[i]);
2301 for (i = index; i < len; i++) {
2302 if (line[i] == '(') index = 0;
2303 else if (line[i] == ')') break;
2304 else if (index++ >= 0) {
2305 if (line[i] == '\\' && i < len - 1) i++;
2306 label[index - 1] = line[i];
2310 if (index == -1) index = 0;
2311 label[index] = '\0';
2313 rootmenu->setLabel(label);
2314 defaultMenu = parseMenuFile(menu_file, rootmenu);
2325 rootmenu->setInternalMenu();
2326 rootmenu->insert(i18n->getMessage(ScreenSet, Screenxterm, "xterm"),
2328 i18n->getMessage(ScreenSet, Screenxterm, "xterm"));
2329 rootmenu->insert(i18n->getMessage(ScreenSet, ScreenRestart, "Restart"),
2331 rootmenu->insert(i18n->getMessage(ScreenSet, ScreenExit, "Exit"),
2334 openbox.setMenuFilename(openbox.getMenuFilename());
2339 Bool BScreen::parseMenuFile(FILE *file, Rootmenu *menu) {
2340 char line[1024], label[1024], command[1024];
2342 while (! feof(file)) {
2343 memset(line, 0, 1024);
2344 memset(label, 0, 1024);
2345 memset(command, 0, 1024);
2347 if (fgets(line, 1024, file)) {
2348 if (line[0] != '#') {
2349 register int i, key = 0, parse = 0, index = -1,
2350 line_length = strlen(line),
2351 label_length = 0, command_length = 0;
2353 // determine the keyword
2355 for (i = 0; i < line_length; i++) {
2356 if (line[i] == '[') parse = 1;
2357 else if (line[i] == ']') break;
2358 else if (line[i] != ' ')
2360 key += tolower(line[i]);
2363 // get the label enclosed in ()'s
2366 for (i = 0; i < line_length; i++) {
2367 if (line[i] == '(') {
2370 } else if (line[i] == ')') break;
2371 else if (index++ >= 0) {
2372 if (line[i] == '\\' && i < line_length - 1) i++;
2373 label[index - 1] = line[i];
2378 label[index] = '\0';
2379 label_length = index;
2385 // get the command enclosed in {}'s
2388 for (i = 0; i < line_length; i++) {
2389 if (line[i] == '{') {
2392 } else if (line[i] == '}') break;
2393 else if (index++ >= 0) {
2394 if (line[i] == '\\' && i < line_length - 1) i++;
2395 command[index - 1] = line[i];
2400 command[index] = '\0';
2401 command_length = index;
2409 return ((menu->getCount() == 0) ? True : False);
2414 menu->insert(label);
2419 if ((! *label) && (! *command)) {
2420 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenEXECError,
2421 "BScreen::parseMenuFile: [exec] error, "
2422 "no menu label and/or command defined\n"));
2426 menu->insert(label, BScreen::Execute, command);
2432 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenEXITError,
2433 "BScreen::parseMenuFile: [exit] error, "
2434 "no menu label defined\n"));
2438 menu->insert(label, BScreen::Exit);
2444 if ((! *label) || (! *command)) {
2445 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenSTYLEError,
2446 "BScreen::parseMenuFile: [style] error, "
2447 "no menu label and/or filename defined\n"));
2451 char style[MAXPATHLEN];
2453 // perform shell style ~ home directory expansion
2455 int homedir_len = 0;
2456 if (*command == '~' && *(command + 1) == '/') {
2457 homedir = getenv("HOME");
2458 homedir_len = strlen(homedir);
2461 if (homedir && homedir_len != 0) {
2462 strncpy(style, homedir, homedir_len);
2464 strncpy(style + homedir_len, command + 1,
2465 command_length - 1);
2466 *(style + command_length + homedir_len - 1) = '\0';
2468 strncpy(style, command, command_length);
2469 *(style + command_length) = '\0';
2472 menu->insert(label, BScreen::SetStyle, style);
2479 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenCONFIGError,
2480 "BScreen::parseMenufile: [config] error, "
2481 "no label defined"));
2485 menu->insert(label, configmenu);
2489 case 740: // include
2492 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenINCLUDEError,
2493 "BScreen::parseMenuFile: [include] error, "
2494 "no filename defined\n"));
2498 char newfile[MAXPATHLEN];
2500 // perform shell style ~ home directory expansion
2502 int homedir_len = 0;
2503 if (*label == '~' && *(label + 1) == '/') {
2504 homedir = getenv("HOME");
2505 homedir_len = strlen(homedir);
2508 if (homedir && homedir_len != 0) {
2509 strncpy(newfile, homedir, homedir_len);
2511 strncpy(newfile + homedir_len, label + 1,
2513 *(newfile + label_length + homedir_len - 1) = '\0';
2515 strncpy(newfile, label, label_length);
2516 *(newfile + label_length) = '\0';
2520 FILE *submenufile = fopen(newfile, "r");
2524 if (fstat(fileno(submenufile), &buf) ||
2525 (! S_ISREG(buf.st_mode))) {
2527 i18n->getMessage(ScreenSet, ScreenINCLUDEErrorReg,
2528 "BScreen::parseMenuFile: [include] error: "
2529 "'%s' is not a regular file\n"), newfile);
2533 if (! feof(submenufile)) {
2534 if (! parseMenuFile(submenufile, menu))
2535 openbox.setMenuFilename(newfile);
2537 fclose(submenufile);
2546 case 767: // submenu
2549 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenSUBMENUError,
2550 "BScreen::parseMenuFile: [submenu] error, "
2551 "no menu label defined\n"));
2555 Rootmenu *submenu = new Rootmenu(*this);
2558 submenu->setLabel(command);
2560 submenu->setLabel(label);
2562 parseMenuFile(file, submenu);
2564 menu->insert(label, submenu);
2565 rootmenuList->insert(submenu);
2570 case 773: // restart
2573 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenRESTARTError,
2574 "BScreen::parseMenuFile: [restart] error, "
2575 "no menu label defined\n"));
2580 menu->insert(label, BScreen::RestartOther, command);
2582 menu->insert(label, BScreen::Restart);
2587 case 845: // reconfig
2590 fprintf(stderr, i18n->getMessage(ScreenSet, ScreenRECONFIGError,
2591 "BScreen::parseMenuFile: [reconfig] error, "
2592 "no menu label defined\n"));
2596 menu->insert(label, BScreen::Reconfigure);
2601 case 995: // stylesdir
2602 case 1113: // stylesmenu
2604 Bool newmenu = ((key == 1113) ? True : False);
2606 if ((! *label) || ((! *command) && newmenu)) {
2608 i18n->getMessage(ScreenSet, ScreenSTYLESDIRError,
2609 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
2610 " error, no directory defined\n"));
2614 char stylesdir[MAXPATHLEN];
2616 char *directory = ((newmenu) ? command : label);
2617 int directory_length = ((newmenu) ? command_length : label_length);
2619 // perform shell style ~ home directory expansion
2621 int homedir_len = 0;
2623 if (*directory == '~' && *(directory + 1) == '/') {
2624 homedir = getenv("HOME");
2625 homedir_len = strlen(homedir);
2628 if (homedir && homedir_len != 0) {
2629 strncpy(stylesdir, homedir, homedir_len);
2631 strncpy(stylesdir + homedir_len, directory + 1,
2632 directory_length - 1);
2633 *(stylesdir + directory_length + homedir_len - 1) = '\0';
2635 strncpy(stylesdir, directory, directory_length);
2636 *(stylesdir + directory_length) = '\0';
2639 struct stat statbuf;
2641 if (! stat(stylesdir, &statbuf)) {
2642 if (S_ISDIR(statbuf.st_mode)) {
2643 Rootmenu *stylesmenu;
2646 stylesmenu = new Rootmenu(*this);
2650 DIR *d = opendir(stylesdir);
2654 // get the total number of directory entries
2655 while ((p = readdir(d))) entries++;
2658 char **ls = new char* [entries];
2660 while ((p = readdir(d)))
2661 ls[index++] = bstrdup(p->d_name);
2665 std::sort(ls, ls + entries, dcmp());
2667 int n, slen = strlen(stylesdir);
2668 for (n = 0; n < entries; n++) {
2669 if (ls[n][strlen(ls[n])-1] != '~') {
2670 int nlen = strlen(ls[n]);
2671 char style[MAXPATHLEN + 1];
2673 strncpy(style, stylesdir, slen);
2674 *(style + slen) = '/';
2675 strncpy(style + slen + 1, ls[n], nlen + 1);
2677 if ((! stat(style, &statbuf)) && S_ISREG(statbuf.st_mode))
2678 stylesmenu->insert(ls[n], BScreen::SetStyle, style);
2686 stylesmenu->update();
2689 stylesmenu->setLabel(label);
2690 menu->insert(label, stylesmenu);
2691 rootmenuList->insert(stylesmenu);
2694 openbox.setMenuFilename(stylesdir);
2696 fprintf(stderr, i18n->getMessage(ScreenSet,
2697 ScreenSTYLESDIRErrorNotDir,
2698 "BScreen::parseMenuFile:"
2699 " [stylesdir/stylesmenu] error, %s is not a"
2700 " directory\n"), stylesdir);
2704 i18n->getMessage(ScreenSet, ScreenSTYLESDIRErrorNoExist,
2705 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
2706 " error, %s does not exist\n"), stylesdir);
2712 case 1090: // workspaces
2716 i18n->getMessage(ScreenSet, ScreenWORKSPACESError,
2717 "BScreen:parseMenuFile: [workspaces] error, "
2718 "no menu label defined\n"));
2722 menu->insert(label, workspacemenu);
2731 return ((menu->getCount() == 0) ? True : False);
2735 void BScreen::shutdown(void) {
2738 XSelectInput(getBaseDisplay().getXDisplay(), getRootWindow(), NoEventMask);
2739 XSync(getBaseDisplay().getXDisplay(), False);
2741 LinkedListIterator<Workspace> it(workspacesList);
2742 for (Workspace *w = it.current(); w; it++, w = it.current())
2745 while (iconList->count()) {
2746 iconList->first()->restore();
2747 delete iconList->first();
2758 void BScreen::showPosition(int x, int y) {
2759 if (! geom_visible) {
2760 XMoveResizeWindow(getBaseDisplay().getXDisplay(), geom_window,
2761 (size().w() - geom_w) / 2,
2762 (size().h() - geom_h) / 2, geom_w, geom_h);
2763 XMapWindow(getBaseDisplay().getXDisplay(), geom_window);
2764 XRaiseWindow(getBaseDisplay().getXDisplay(), geom_window);
2766 geom_visible = True;
2771 sprintf(label, i18n->getMessage(ScreenSet, ScreenPositionFormat,
2772 "X: %4d x Y: %4d"), x, y);
2774 XClearWindow(getBaseDisplay().getXDisplay(), geom_window);
2776 if (i18n->multibyte()) {
2777 XmbDrawString(getBaseDisplay().getXDisplay(), geom_window,
2778 resource.wstyle.fontset, resource.wstyle.l_text_focus_gc,
2779 resource.bevel_width, resource.bevel_width -
2780 resource.wstyle.fontset_extents->max_ink_extent.y,
2781 label, strlen(label));
2783 XDrawString(getBaseDisplay().getXDisplay(), geom_window,
2784 resource.wstyle.l_text_focus_gc,
2785 resource.bevel_width,
2786 resource.wstyle.font->ascent +
2787 resource.bevel_width, label, strlen(label));
2792 void BScreen::showGeometry(unsigned int gx, unsigned int gy) {
2793 if (! geom_visible) {
2794 XMoveResizeWindow(getBaseDisplay().getXDisplay(), geom_window,
2795 (size().w() - geom_w) / 2,
2796 (size().h() - geom_h) / 2, geom_w, geom_h);
2797 XMapWindow(getBaseDisplay().getXDisplay(), geom_window);
2798 XRaiseWindow(getBaseDisplay().getXDisplay(), geom_window);
2800 geom_visible = True;
2805 sprintf(label, i18n->getMessage(ScreenSet, ScreenGeometryFormat,
2806 "W: %4d x H: %4d"), gx, gy);
2808 XClearWindow(getBaseDisplay().getXDisplay(), geom_window);
2810 if (i18n->multibyte()) {
2811 XmbDrawString(getBaseDisplay().getXDisplay(), geom_window,
2812 resource.wstyle.fontset, resource.wstyle.l_text_focus_gc,
2813 resource.bevel_width, resource.bevel_width -
2814 resource.wstyle.fontset_extents->max_ink_extent.y,
2815 label, strlen(label));
2817 XDrawString(getBaseDisplay().getXDisplay(), geom_window,
2818 resource.wstyle.l_text_focus_gc,
2819 resource.bevel_width,
2820 resource.wstyle.font->ascent +
2821 resource.bevel_width, label, strlen(label));
2825 void BScreen::hideGeometry(void) {
2827 XUnmapWindow(getBaseDisplay().getXDisplay(), geom_window);
2828 geom_visible = False;