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
106 #include <functional>
109 static Bool running
= True
;
111 static int anotherWMRunning(Display
*display
, XErrorEvent
*) {
112 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenAnotherWMRunning
,
113 "BScreen::BScreen: an error occured while querying the X server.\n"
114 " another window manager already running on display %s.\n"),
115 DisplayString(display
));
123 bool operator()(const char *one
, const char *two
) const {
124 return (strcmp(one
, two
) < 0) ? True
: False
;
128 #ifndef HAVE_STRCASESTR
129 static const char * strcasestr(const char *str
, const char *ptn
) {
131 for( ; *str
; str
++) {
132 for(s2
=str
,p2
=ptn
; ; s2
++,p2
++) {
133 if (!*p2
) return str
;
134 if (toupper(*s2
) != toupper(*p2
)) break;
139 #endif // HAVE_STRCASESTR
141 static const char *getFontElement(const char *pattern
, char *buf
, int bufsiz
, ...) {
146 va_start(va
, bufsiz
);
149 while((v
= va_arg(va
, char *)) != NULL
) {
150 p
= strcasestr(pattern
, v
);
152 strncpy(buf
, p
+1, bufsiz
-2);
153 p2
= strchr(buf
, '-');
160 strncpy(buf
, "*", bufsiz
);
164 static const char *getFontSize(const char *pattern
, int *size
) {
169 for (p
=pattern
; 1; p
++) {
171 if (p2
!=NULL
&& n
>1 && n
<72) {
172 *size
= n
; return p2
+1;
174 *size
= 16; return NULL
;
176 } else if (*p
=='-') {
177 if (n
>1 && n
<72 && p2
!=NULL
) {
182 } else if (*p
>='0' && *p
<='9' && p2
!=NULL
) {
192 BScreen::BScreen(Openbox
&ob
, int scrn
, Resource
&conf
) : ScreenInfo(ob
, scrn
),
193 openbox(ob
), config(conf
)
195 event_mask
= ColormapChangeMask
| EnterWindowMask
| PropertyChangeMask
|
196 SubstructureRedirectMask
| KeyPressMask
| KeyReleaseMask
|
197 ButtonPressMask
| ButtonReleaseMask
;
199 XErrorHandler old
= XSetErrorHandler((XErrorHandler
) anotherWMRunning
);
200 XSelectInput(getBaseDisplay().getXDisplay(), getRootWindow(), event_mask
);
201 XSync(getBaseDisplay().getXDisplay(), False
);
202 XSetErrorHandler((XErrorHandler
) old
);
205 if (! managed
) return;
207 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenManagingScreen
,
208 "BScreen::BScreen: managing screen %d "
209 "using visual 0x%lx, depth %d\n"),
210 getScreenNumber(), XVisualIDFromVisual(getVisual()),
215 resource
.mstyle
.t_fontset
= resource
.mstyle
.f_fontset
=
216 resource
.tstyle
.fontset
= resource
.wstyle
.fontset
= NULL
;
217 resource
.mstyle
.t_font
= resource
.mstyle
.f_font
= resource
.tstyle
.font
=
218 resource
.wstyle
.font
= NULL
;
219 resource
.root_command
= NULL
;
221 resource
.strftime_format
= NULL
;
222 #endif // HAVE_STRFTIME
230 pid_t bpid
= getpid();
232 XChangeProperty(getBaseDisplay().getXDisplay(), getRootWindow(),
233 openbox
.getOpenboxPidAtom(), XA_CARDINAL
,
234 sizeof(pid_t
) * 8, PropModeReplace
,
235 (unsigned char *) &bpid
, 1);
236 #endif // HAVE_GETPID
238 XDefineCursor(getBaseDisplay().getXDisplay(), getRootWindow(),
239 openbox
.getSessionCursor());
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
.size());
404 workspacesList
.push_back(wkspc
);
405 workspacemenu
->insert(wkspc
->getName(), wkspc
->getMenu());
408 setWorkspaceCount(1);
409 wkspc
= new Workspace(*this, workspacesList
.size());
410 workspacesList
.push_back(wkspc
);
411 workspacemenu
->insert(wkspc
->getName(), wkspc
->getMenu());
413 saveWorkspaceNames();
415 workspacemenu
->insert(i18n
->getMessage(IconSet
, IconIcons
, "Icons"),
417 workspacemenu
->update();
419 current_workspace
= workspacesList
.front();
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 XSetInputFocus(getBaseDisplay().getXDisplay(),
487 PointerRoot
, None
, 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 std::for_each(workspacesList
.begin(), workspacesList
.end(),
507 std::for_each(iconList
.begin(), iconList
.end(), PointerAssassin());
508 std::for_each(netizenList
.begin(), netizenList
.end(), PointerAssassin());
511 if (resource
.strftime_format
)
512 delete [] resource
.strftime_format
;
513 #endif // HAVE_STRFTIME
516 delete workspacemenu
;
525 delete image_control
;
527 if (resource
.wstyle
.fontset
)
528 XFreeFontSet(getBaseDisplay().getXDisplay(), resource
.wstyle
.fontset
);
529 if (resource
.mstyle
.t_fontset
)
530 XFreeFontSet(getBaseDisplay().getXDisplay(), resource
.mstyle
.t_fontset
);
531 if (resource
.mstyle
.f_fontset
)
532 XFreeFontSet(getBaseDisplay().getXDisplay(), resource
.mstyle
.f_fontset
);
533 if (resource
.tstyle
.fontset
)
534 XFreeFontSet(getBaseDisplay().getXDisplay(), resource
.tstyle
.fontset
);
536 if (resource
.wstyle
.font
)
537 XFreeFont(getBaseDisplay().getXDisplay(), resource
.wstyle
.font
);
538 if (resource
.mstyle
.t_font
)
539 XFreeFont(getBaseDisplay().getXDisplay(), resource
.mstyle
.t_font
);
540 if (resource
.mstyle
.f_font
)
541 XFreeFont(getBaseDisplay().getXDisplay(), resource
.mstyle
.f_font
);
542 if (resource
.tstyle
.font
)
543 XFreeFont(getBaseDisplay().getXDisplay(), resource
.tstyle
.font
);
544 if (resource
.root_command
!= NULL
)
545 delete [] resource
.root_command
;
547 XFreeGC(getBaseDisplay().getXDisplay(), opGC
);
549 XFreeGC(getBaseDisplay().getXDisplay(),
550 resource
.wstyle
.l_text_focus_gc
);
551 XFreeGC(getBaseDisplay().getXDisplay(),
552 resource
.wstyle
.l_text_unfocus_gc
);
553 XFreeGC(getBaseDisplay().getXDisplay(),
554 resource
.wstyle
.b_pic_focus_gc
);
555 XFreeGC(getBaseDisplay().getXDisplay(),
556 resource
.wstyle
.b_pic_unfocus_gc
);
558 XFreeGC(getBaseDisplay().getXDisplay(),
559 resource
.mstyle
.t_text_gc
);
560 XFreeGC(getBaseDisplay().getXDisplay(),
561 resource
.mstyle
.f_text_gc
);
562 XFreeGC(getBaseDisplay().getXDisplay(),
563 resource
.mstyle
.h_text_gc
);
564 XFreeGC(getBaseDisplay().getXDisplay(),
565 resource
.mstyle
.d_text_gc
);
566 XFreeGC(getBaseDisplay().getXDisplay(),
567 resource
.mstyle
.hilite_gc
);
569 XFreeGC(getBaseDisplay().getXDisplay(),
570 resource
.tstyle
.l_text_gc
);
571 XFreeGC(getBaseDisplay().getXDisplay(),
572 resource
.tstyle
.w_text_gc
);
573 XFreeGC(getBaseDisplay().getXDisplay(),
574 resource
.tstyle
.c_text_gc
);
575 XFreeGC(getBaseDisplay().getXDisplay(),
576 resource
.tstyle
.b_pic_gc
);
580 Rect
BScreen::availableArea() const {
581 // the following code is temporary and will be taken care of by Screen in the
582 // future (with the NETWM 'strut')
583 Rect
space(0, 0, size().w(), size().h());
584 if (!resource
.full_max
) {
586 int slit_x
= slit
->autoHide() ? slit
->hiddenOrigin().x() : slit
->area().x(),
587 slit_y
= slit
->autoHide() ? slit
->hiddenOrigin().y() : slit
->area().y();
588 int tbarh
= resource
.hide_toolbar
? 0 :
589 toolbar
->getExposedHeight() + resource
.border_width
* 2;
591 switch (toolbar
->placement()) {
592 case Toolbar::TopLeft
:
593 case Toolbar::TopCenter
:
594 case Toolbar::TopRight
:
597 case Toolbar::BottomLeft
:
598 case Toolbar::BottomCenter
:
599 case Toolbar::BottomRight
:
603 ASSERT(false); // unhandled placement
605 if ((slit
->direction() == Slit::Horizontal
&&
606 (slit
->placement() == Slit::TopLeft
||
607 slit
->placement() == Slit::TopRight
)) ||
608 slit
->placement() == Slit::TopCenter
) {
610 if (tbartop
&& slit_y
+ slit
->area().h() < tbarh
) {
611 space
.setY(space
.y() + tbarh
);
612 space
.setH(space
.h() - tbarh
);
614 space
.setY(space
.y() + (slit_y
+ slit
->area().h() +
615 resource
.border_width
* 2));
616 space
.setH(space
.h() - (slit_y
+ slit
->area().h() +
617 resource
.border_width
* 2));
619 space
.setH(space
.h() - tbarh
);
621 } else if ((slit
->direction() == Slit::Vertical
&&
622 (slit
->placement() == Slit::TopRight
||
623 slit
->placement() == Slit::BottomRight
)) ||
624 slit
->placement() == Slit::CenterRight
) {
626 space
.setW(space
.w() - (size().w() - slit_x
));
628 space
.setY(space
.y() + tbarh
);
629 space
.setH(space
.h() - tbarh
);
630 } else if ((slit
->direction() == Slit::Horizontal
&&
631 (slit
->placement() == Slit::BottomLeft
||
632 slit
->placement() == Slit::BottomRight
)) ||
633 slit
->placement() == Slit::BottomCenter
) {
635 if (!tbartop
&& (size().h() - slit_y
) < tbarh
) {
636 space
.setH(space
.h() - tbarh
);
638 space
.setH(space
.h() - (size().h() - slit_y
));
640 space
.setY(space
.y() + tbarh
);
641 space
.setH(space
.h() - tbarh
);
644 } else {// if ((slit->direction() == Slit::Vertical &&
645 // (slit->placement() == Slit::TopLeft ||
646 // slit->placement() == Slit::BottomLeft)) ||
647 // slit->placement() == Slit::CenterLeft)
649 space
.setX(slit_x
+ slit
->area().w() +
650 resource
.border_width
* 2);
651 space
.setW(space
.w() - (slit_x
+ slit
->area().w() +
652 resource
.border_width
* 2));
654 space
.setY(space
.y() + tbarh
);
655 space
.setH(space
.h() - tbarh
);
658 int tbarh
= resource
.hide_toolbar() ? 0 :
659 toolbar
->getExposedHeight() + resource
.border_width
* 2;
660 switch (toolbar
->placement()) {
661 case Toolbar::TopLeft
:
662 case Toolbar::TopCenter
:
663 case Toolbar::TopRight
:
664 space
.setY(toolbar
->getExposedHeight());
665 space
.setH(space
.h() - toolbar
->getExposedHeight());
667 case Toolbar::BottomLeft
:
668 case Toolbar::BottomCenter
:
669 case Toolbar::BottomRight
:
670 space
.setH(space
.h() - tbarh
);
673 ASSERT(false); // unhandled placement
681 void BScreen::readDatabaseTexture(const char *rname
, const char *rclass
,
683 unsigned long default_pixel
)
687 if (resource
.styleconfig
.getValue(rname
, rclass
, s
))
688 image_control
->parseTexture(texture
, s
.c_str());
690 texture
->setTexture(BImage_Solid
| BImage_Flat
);
692 if (texture
->getTexture() & BImage_Solid
) {
693 int clen
= strlen(rclass
) + 32, nlen
= strlen(rname
) + 32;
695 char *colorclass
= new char[clen
], *colorname
= new char[nlen
];
697 sprintf(colorclass
, "%s.Color", rclass
);
698 sprintf(colorname
, "%s.color", rname
);
700 readDatabaseColor(colorname
, colorclass
, texture
->getColor(),
704 sprintf(colorclass
, "%s.ColorTo", rclass
);
705 sprintf(colorname
, "%s.colorTo", rname
);
707 readDatabaseColor(colorname
, colorclass
, texture
->getColorTo(),
711 delete [] colorclass
;
714 if ((! texture
->getColor()->isAllocated()) ||
715 (texture
->getTexture() & BImage_Flat
))
720 xcol
.red
= (unsigned int) (texture
->getColor()->getRed() +
721 (texture
->getColor()->getRed() >> 1));
722 if (xcol
.red
>= 0xff) xcol
.red
= 0xffff;
723 else xcol
.red
*= 0xff;
724 xcol
.green
= (unsigned int) (texture
->getColor()->getGreen() +
725 (texture
->getColor()->getGreen() >> 1));
726 if (xcol
.green
>= 0xff) xcol
.green
= 0xffff;
727 else xcol
.green
*= 0xff;
728 xcol
.blue
= (unsigned int) (texture
->getColor()->getBlue() +
729 (texture
->getColor()->getBlue() >> 1));
730 if (xcol
.blue
>= 0xff) xcol
.blue
= 0xffff;
731 else xcol
.blue
*= 0xff;
733 if (! XAllocColor(getBaseDisplay().getXDisplay(),
734 getColormap(), &xcol
))
737 texture
->getHiColor()->setPixel(xcol
.pixel
);
740 (unsigned int) ((texture
->getColor()->getRed() >> 2) +
741 (texture
->getColor()->getRed() >> 1)) * 0xff;
743 (unsigned int) ((texture
->getColor()->getGreen() >> 2) +
744 (texture
->getColor()->getGreen() >> 1)) * 0xff;
746 (unsigned int) ((texture
->getColor()->getBlue() >> 2) +
747 (texture
->getColor()->getBlue() >> 1)) * 0xff;
749 if (! XAllocColor(getBaseDisplay().getXDisplay(),
750 getColormap(), &xcol
))
753 texture
->getLoColor()->setPixel(xcol
.pixel
);
754 } else if (texture
->getTexture() & BImage_Gradient
) {
755 int clen
= strlen(rclass
) + 10, nlen
= strlen(rname
) + 10;
757 char *colorclass
= new char[clen
], *colorname
= new char[nlen
],
758 *colortoclass
= new char[clen
], *colortoname
= new char[nlen
];
760 sprintf(colorclass
, "%s.Color", rclass
);
761 sprintf(colorname
, "%s.color", rname
);
763 sprintf(colortoclass
, "%s.ColorTo", rclass
);
764 sprintf(colortoname
, "%s.colorTo", rname
);
766 readDatabaseColor(colorname
, colorclass
, texture
->getColor(),
768 readDatabaseColor(colortoname
, colortoclass
, texture
->getColorTo(),
771 delete [] colorclass
;
773 delete [] colortoclass
;
774 delete [] colortoname
;
779 void BScreen::readDatabaseColor(const char *rname
, const char *rclass
,
780 BColor
*color
, unsigned long default_pixel
)
784 if (resource
.styleconfig
.getValue(rname
, rclass
, s
))
785 image_control
->parseColor(color
, s
.c_str());
787 // parsing with no color std::string just deallocates the color, if it has
788 // been previously allocated
789 image_control
->parseColor(color
);
790 color
->setPixel(default_pixel
);
795 void BScreen::readDatabaseFontSet(const char *rname
, const char *rclass
,
797 if (! fontset
) return;
799 static char *defaultFont
= "fixed";
800 bool load_default
= false;
804 XFreeFontSet(getBaseDisplay().getXDisplay(), *fontset
);
806 if (resource
.styleconfig
.getValue(rname
, rclass
, s
)) {
807 if (! (*fontset
= createFontSet(s
.c_str())))
813 *fontset
= createFontSet(defaultFont
);
816 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenDefaultFontLoadFail
,
817 "BScreen::LoadStyle(): couldn't load default font.\n"));
824 void BScreen::readDatabaseFont(const char *rname
, const char *rclass
,
825 XFontStruct
**font
) {
828 static char *defaultFont
= "fixed";
829 bool load_default
= false;
833 XFreeFont(getBaseDisplay().getXDisplay(), *font
);
835 if (resource
.styleconfig
.getValue(rname
, rclass
, s
)) {
836 if ((*font
= XLoadQueryFont(getBaseDisplay().getXDisplay(),
837 s
.c_str())) == NULL
) {
838 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenFontLoadFail
,
839 "BScreen::LoadStyle(): couldn't load font '%s'\n"),
847 if ((*font
= XLoadQueryFont(getBaseDisplay().getXDisplay(),
848 defaultFont
)) == NULL
) {
849 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenDefaultFontLoadFail
,
850 "BScreen::LoadStyle(): couldn't load default font.\n"));
857 XFontSet
BScreen::createFontSet(const char *fontname
) {
859 char **missing
, *def
= "-";
860 int nmissing
, pixel_size
= 0, buf_size
= 0;
861 char weight
[FONT_ELEMENT_SIZE
], slant
[FONT_ELEMENT_SIZE
];
863 fs
= XCreateFontSet(getBaseDisplay().getXDisplay(),
864 fontname
, &missing
, &nmissing
, &def
);
865 if (fs
&& (! nmissing
)) return fs
;
867 #ifdef HAVE_SETLOCALE
869 if (nmissing
) XFreeStringList(missing
);
871 setlocale(LC_CTYPE
, "C");
872 fs
= XCreateFontSet(getBaseDisplay().getXDisplay(), fontname
,
873 &missing
, &nmissing
, &def
);
874 setlocale(LC_CTYPE
, "");
876 #endif // HAVE_SETLOCALE
879 XFontStruct
**fontstructs
;
881 XFontsOfFontSet(fs
, &fontstructs
, &fontnames
);
882 fontname
= fontnames
[0];
885 getFontElement(fontname
, weight
, FONT_ELEMENT_SIZE
,
886 "-medium-", "-bold-", "-demibold-", "-regular-", NULL
);
887 getFontElement(fontname
, slant
, FONT_ELEMENT_SIZE
,
888 "-r-", "-i-", "-o-", "-ri-", "-ro-", NULL
);
889 getFontSize(fontname
, &pixel_size
);
891 if (! strcmp(weight
, "*")) strncpy(weight
, "medium", FONT_ELEMENT_SIZE
);
892 if (! strcmp(slant
, "*")) strncpy(slant
, "r", FONT_ELEMENT_SIZE
);
893 if (pixel_size
< 3) pixel_size
= 3;
894 else if (pixel_size
> 97) pixel_size
= 97;
896 buf_size
= strlen(fontname
) + (FONT_ELEMENT_SIZE
* 2) + 64;
897 char *pattern2
= new char[buf_size
];
898 snprintf(pattern2
, buf_size
- 1,
900 "-*-*-%s-%s-*-*-%d-*-*-*-*-*-*-*,"
901 "-*-*-*-*-*-*-%d-*-*-*-*-*-*-*,*",
902 fontname
, weight
, slant
, pixel_size
, pixel_size
);
905 if (nmissing
) XFreeStringList(missing
);
906 if (fs
) XFreeFontSet(getBaseDisplay().getXDisplay(), fs
);
908 fs
= XCreateFontSet(getBaseDisplay().getXDisplay(), fontname
,
909 &missing
, &nmissing
, &def
);
916 void BScreen::setSloppyFocus(bool b
) {
917 resource
.sloppy_focus
= b
;
919 s
<< "session.screen" << getScreenNumber() << ".focusModel" << ends
;
920 config
.setValue(s
.str(),
921 (resource
.sloppy_focus
?
922 (resource
.auto_raise
? "AutoRaiseSloppyFocus" : "SloppyFocus")
924 s
.rdbuf()->freeze(0);
928 void BScreen::setAutoRaise(bool a
) {
929 resource
.auto_raise
= a
;
931 s
<< "session.screen" << getScreenNumber() << ".focusModel" << ends
;
932 config
.setValue(s
.str(),
933 (resource
.sloppy_focus
?
934 (resource
.auto_raise
? "AutoRaiseSloppyFocus" : "SloppyFocus")
936 s
.rdbuf()->freeze(0);
940 void BScreen::setImageDither(bool d
, bool reconfig
) {
941 image_control
->setDither(d
);
943 s
<< "session.screen" << getScreenNumber() << ".imageDither" << ends
;
944 config
.setValue(s
.str(), imageDither());
947 s
.rdbuf()->freeze(0);
951 void BScreen::setOpaqueMove(bool o
) {
952 resource
.opaque_move
= o
;
954 s
<< "session.screen" << getScreenNumber() << ".opaqueMove" << ends
;
955 config
.setValue(s
.str(), resource
.opaque_move
);
956 s
.rdbuf()->freeze(0);
960 void BScreen::setFullMax(bool f
) {
961 resource
.full_max
= f
;
963 s
<< "session.screen" << getScreenNumber() << ".fullMaximization" << ends
;
964 config
.setValue(s
.str(), resource
.full_max
);
965 s
.rdbuf()->freeze(0);
969 void BScreen::setFocusNew(bool f
) {
970 resource
.focus_new
= f
;
972 s
<< "session.screen" << getScreenNumber() << ".focusNewWindows" << ends
;
973 config
.setValue(s
.str(), resource
.focus_new
);
974 s
.rdbuf()->freeze(0);
978 void BScreen::setFocusLast(bool f
) {
979 resource
.focus_last
= f
;
981 s
<< "session.screen" << getScreenNumber() << ".focusLastWindow" << ends
;
982 config
.setValue(s
.str(), resource
.focus_last
);
983 s
.rdbuf()->freeze(0);
987 void BScreen::setWindowZones(int z
) {
990 s
<< "session.screen" << getScreenNumber() << ".windowZones" << ends
;
991 config
.setValue(s
.str(), resource
.zones
);
992 s
.rdbuf()->freeze(0);
996 void BScreen::setWorkspaceCount(int w
) {
997 resource
.workspaces
= w
;
999 s
<< "session.screen" << getScreenNumber() << ".workspaces" << ends
;
1000 config
.setValue(s
.str(), resource
.workspaces
);
1001 s
.rdbuf()->freeze(0);
1005 void BScreen::setPlacementPolicy(int p
) {
1006 resource
.placement_policy
= p
;
1008 s
<< "session.screen" << getScreenNumber() << ".windowPlacement" << ends
;
1009 const char *placement
;
1010 switch (resource
.placement_policy
) {
1011 case CascadePlacement
: placement
= "CascadePlacement"; break;
1012 case BestFitPlacement
: placement
= "BestFitPlacement"; break;
1013 case ColSmartPlacement
: placement
= "ColSmartPlacement"; break;
1014 case UnderMousePlacement
: placement
= "UnderMousePlacement"; break;
1015 case ClickMousePlacement
: placement
= "ClickMousePlacement"; break;
1017 case RowSmartPlacement
: placement
= "RowSmartPlacement"; break;
1019 config
.setValue(s
.str(), placement
);
1020 s
.rdbuf()->freeze(0);
1024 void BScreen::setEdgeSnapThreshold(int t
) {
1025 resource
.edge_snap_threshold
= t
;
1027 s
<< "session.screen" << getScreenNumber() << ".edgeSnapThreshold" << ends
;
1028 config
.setValue(s
.str(), resource
.edge_snap_threshold
);
1029 s
.rdbuf()->freeze(0);
1033 void BScreen::setRowPlacementDirection(int d
) {
1034 resource
.row_direction
= d
;
1036 s
<< "session.screen" << getScreenNumber() << ".rowPlacementDirection" << ends
;
1037 config
.setValue(s
.str(),
1038 resource
.row_direction
== LeftRight
?
1039 "LeftToRight" : "RightToLeft");
1040 s
.rdbuf()->freeze(0);
1044 void BScreen::setColPlacementDirection(int d
) {
1045 resource
.col_direction
= d
;
1047 s
<< "session.screen" << getScreenNumber() << ".colPlacementDirection" << ends
;
1048 config
.setValue(s
.str(),
1049 resource
.col_direction
== TopBottom
?
1050 "TopToBottom" : "BottomToTop");
1051 s
.rdbuf()->freeze(0);
1055 void BScreen::setRootCommand(const char *cmd
) {
1056 if (resource
.root_command
!= NULL
)
1057 delete [] resource
.root_command
;
1059 resource
.root_command
= bstrdup(cmd
);
1061 resource
.root_command
= NULL
;
1062 // this doesn't save to the Resources config because it can't be changed
1063 // inside Openbox, and this way we dont add an empty command which would over-
1064 // ride the styles command when none has been specified
1068 #ifdef HAVE_STRFTIME
1069 void BScreen::setStrftimeFormat(const char *f
) {
1070 if (resource
.strftime_format
!= NULL
)
1071 delete [] resource
.strftime_format
;
1073 resource
.strftime_format
= bstrdup(f
);
1075 s
<< "session.screen" << getScreenNumber() << ".strftimeFormat" << ends
;
1076 config
.setValue(s
.str(), resource
.strftime_format
);
1077 s
.rdbuf()->freeze(0);
1080 #else // !HAVE_STRFTIME
1082 void BScreen::setDateFormat(int f
) {
1083 resource
.date_format
= f
;
1085 s
<< "session.screen" << getScreenNumber() << ".dateFormat" << ends
;
1086 config
.setValue(s
.str(), resource
.date_format
== B_EuropeanDate
?
1087 "European" : "American");
1088 s
.rdbuf()->freeze(0);
1092 void BScreen::setClock24Hour(Bool c
) {
1093 resource
.clock24hour
= c
;
1095 s
<< "session.screen" << getScreenNumber() << ".clockFormat" << ends
;
1096 config
.setValue(s
.str(), resource
.clock24hour
? 24 : 12);
1097 s
.rdbuf()->freeze(0);
1099 #endif // HAVE_STRFTIME
1102 void BScreen::setHideToolbar(bool b
) {
1103 resource
.hide_toolbar
= b
;
1104 if (resource
.hide_toolbar
)
1105 getToolbar()->unMapToolbar();
1107 getToolbar()->mapToolbar();
1109 s
<< "session.screen" << getScreenNumber() << ".hideToolbar" << ends
;
1110 config
.setValue(s
.str(), resource
.hide_toolbar
? "True" : "False");
1111 s
.rdbuf()->freeze(0);
1115 void BScreen::saveWorkspaceNames() {
1116 std::ostrstream rc
, names
;
1118 wkspList::iterator it
;
1119 wkspList::iterator last
= workspacesList
.end() - 1;
1120 for (it
= workspacesList
.begin(); it
!= workspacesList
.end(); ++it
) {
1121 names
<< (*it
)->getName();
1127 rc
<< "session.screen" << getScreenNumber() << ".workspaceNames" << ends
;
1128 config
.setValue(rc
.str(), names
.str());
1129 rc
.rdbuf()->freeze(0);
1130 names
.rdbuf()->freeze(0);
1133 void BScreen::save() {
1134 setSloppyFocus(resource
.sloppy_focus
);
1135 setAutoRaise(resource
.auto_raise
);
1136 setImageDither(imageDither(), false);
1137 setOpaqueMove(resource
.opaque_move
);
1138 setFullMax(resource
.full_max
);
1139 setFocusNew(resource
.focus_new
);
1140 setFocusLast(resource
.focus_last
);
1141 setWindowZones(resource
.zones
);
1142 setWorkspaceCount(resource
.workspaces
);
1143 setPlacementPolicy(resource
.placement_policy
);
1144 setEdgeSnapThreshold(resource
.edge_snap_threshold
);
1145 setRowPlacementDirection(resource
.row_direction
);
1146 setColPlacementDirection(resource
.col_direction
);
1147 setRootCommand(resource
.root_command
);
1148 #ifdef HAVE_STRFTIME
1149 // it deletes the current value before setting the new one, so we have to
1150 // duplicate the current value.
1151 std::string s
= resource
.strftime_format
;
1152 setStrftimeFormat(s
.c_str());
1153 #else // !HAVE_STRFTIME
1154 setDateFormat(resource
.date_format
);
1155 setClock24Hour(resource
.clock24hour
);
1156 #endif // HAVE_STRFTIME
1157 setHideToolbar(resource
.hide_toolbar
);
1166 void BScreen::load() {
1167 std::ostrstream rscreen
, rname
, rclass
;
1171 rscreen
<< "session.screen" << getScreenNumber() << '.' << ends
;
1173 rname
<< rscreen
.str() << "hideToolbar" << ends
;
1174 rclass
<< rscreen
.str() << "HideToolbar" << ends
;
1175 if (config
.getValue(rname
.str(), rclass
.str(), b
))
1176 resource
.hide_toolbar
= b
;
1178 resource
.hide_toolbar
= false;
1179 Toolbar
*t
= getToolbar();
1181 if (resource
.hide_toolbar
)
1187 rname
.seekp(0); rclass
.seekp(0);
1188 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1189 rname
<< rscreen
.str() << "fullMaximization" << ends
;
1190 rclass
<< rscreen
.str() << "FullMaximization" << ends
;
1191 if (config
.getValue(rname
.str(), rclass
.str(), b
))
1192 resource
.full_max
= b
;
1194 resource
.full_max
= false;
1196 rname
.seekp(0); rclass
.seekp(0);
1197 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1198 rname
<< rscreen
.str() << "focusNewWindows" << ends
;
1199 rclass
<< rscreen
.str() << "FocusNewWindows" << ends
;
1200 if (config
.getValue(rname
.str(), rclass
.str(), b
))
1201 resource
.focus_new
= b
;
1203 resource
.focus_new
= false;
1205 rname
.seekp(0); rclass
.seekp(0);
1206 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1207 rname
<< rscreen
.str() << "focusLastWindow" << ends
;
1208 rclass
<< rscreen
.str() << "FocusLastWindow" << ends
;
1209 if (config
.getValue(rname
.str(), rclass
.str(), b
))
1210 resource
.focus_last
= b
;
1212 resource
.focus_last
= false;
1214 rname
.seekp(0); rclass
.seekp(0);
1215 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1216 rname
<< rscreen
.str() << "rowPlacementDirection" << ends
;
1217 rclass
<< rscreen
.str() << "RowPlacementDirection" << ends
;
1218 if (config
.getValue(rname
.str(), rclass
.str(), s
)) {
1219 if (0 == strncasecmp(s
.c_str(), "RightToLeft", s
.length()))
1220 resource
.row_direction
= RightLeft
;
1221 else //if (0 == strncasecmp(s.c_str(), "LeftToRight", s.length()))
1222 resource
.row_direction
= LeftRight
;
1224 resource
.row_direction
= LeftRight
;
1226 rname
.seekp(0); rclass
.seekp(0);
1227 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1228 rname
<< rscreen
.str() << "colPlacementDirection" << ends
;
1229 rclass
<< rscreen
.str() << "ColPlacementDirection" << ends
;
1230 if (config
.getValue(rname
.str(), rclass
.str(), s
)) {
1231 if (0 == strncasecmp(s
.c_str(), "BottomToTop", s
.length()))
1232 resource
.col_direction
= BottomTop
;
1233 else //if (0 == strncasecmp(s.c_str(), "TopToBottom", s.length()))
1234 resource
.col_direction
= TopBottom
;
1236 resource
.col_direction
= TopBottom
;
1238 rname
.seekp(0); rclass
.seekp(0);
1239 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1240 rname
<< rscreen
.str() << "workspaces" << ends
;
1241 rclass
<< rscreen
.str() << "Workspaces" << ends
;
1242 if (config
.getValue(rname
.str(), rclass
.str(), l
)) {
1243 resource
.workspaces
= l
;
1245 resource
.workspaces
= 1;
1247 removeWorkspaceNames();
1248 rname
.seekp(0); rclass
.seekp(0);
1249 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1250 rname
<< rscreen
.str() << "workspaceNames" << ends
;
1251 rclass
<< rscreen
.str() << "WorkspaceNames" << ends
;
1252 if (config
.getValue(rname
.str(), rclass
.str(), s
)) {
1253 std::string::const_iterator it
= s
.begin(), end
= s
.end();
1255 std::string::const_iterator tmp
= it
;// current string.begin()
1256 it
= std::find(tmp
, end
, ','); // look for comma between tmp and end
1257 std::string
name(tmp
, it
); // name = s[tmp:it]
1258 addWorkspaceName(name
.c_str());
1265 rname
.seekp(0); rclass
.seekp(0);
1266 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(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
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1288 rname
<< rscreen
.str() << "windowZones" << ends
;
1289 rclass
<< rscreen
.str() << "WindowZones" << ends
;
1290 if (config
.getValue(rname
.str(), rclass
.str(), l
))
1291 resource
.zones
= (l
== 1 || l
== 2 || l
== 4) ? l
: 1;
1295 rname
.seekp(0); rclass
.seekp(0);
1296 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1297 rname
<< rscreen
.str() << "windowPlacement" << ends
;
1298 rclass
<< rscreen
.str() << "WindowPlacement" << ends
;
1299 if (config
.getValue(rname
.str(), rclass
.str(), s
)) {
1300 if (0 == strncasecmp(s
.c_str(), "RowSmartPlacement", s
.length()))
1301 resource
.placement_policy
= RowSmartPlacement
;
1302 else if (0 == strncasecmp(s
.c_str(), "ColSmartPlacement", s
.length()))
1303 resource
.placement_policy
= ColSmartPlacement
;
1304 else if (0 == strncasecmp(s
.c_str(), "BestFitPlacement", s
.length()))
1305 resource
.placement_policy
= BestFitPlacement
;
1306 else if (0 == strncasecmp(s
.c_str(), "UnderMousePlacement", s
.length()))
1307 resource
.placement_policy
= UnderMousePlacement
;
1308 else if (0 == strncasecmp(s
.c_str(), "ClickMousePlacement", s
.length()))
1309 resource
.placement_policy
= ClickMousePlacement
;
1310 else //if (0 == strncasecmp(s.c_str(), "CascadePlacement", s.length()))
1311 resource
.placement_policy
= CascadePlacement
;
1313 resource
.placement_policy
= CascadePlacement
;
1315 #ifdef HAVE_STRFTIME
1316 rname
.seekp(0); rclass
.seekp(0);
1317 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1318 rname
<< rscreen
.str() << "strftimeFormat" << ends
;
1319 rclass
<< rscreen
.str() << "StrftimeFormat" << ends
;
1321 if (resource
.strftime_format
!= NULL
)
1322 delete [] resource
.strftime_format
;
1324 if (config
.getValue(rname
.str(), rclass
.str(), s
))
1325 resource
.strftime_format
= bstrdup(s
.c_str());
1327 resource
.strftime_format
= bstrdup("%I:%M %p");
1328 #else // !HAVE_STRFTIME
1329 rname
.seekp(0); rclass
.seekp(0);
1330 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1331 rname
<< rscreen
.str() << "dateFormat" << ends
;
1332 rclass
<< rscreen
.str() << "DateFormat" << ends
;
1333 if (config
.getValue(rname
.str(), rclass
.str(), s
)) {
1334 if (strncasecmp(s
.c_str(), "European", s
.length()))
1335 resource
.date_format
= B_EuropeanDate
;
1336 else //if (strncasecmp(s.c_str(), "American", s.length()))
1337 resource
.date_format
= B_AmericanDate
;
1339 resource
.date_format
= B_AmericanDate
;
1341 rname
.seekp(0); rclass
.seekp(0);
1342 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1343 rname
<< rscreen
.str() << "clockFormat" << ends
;
1344 rclass
<< rscreen
.str() << "ClockFormat" << ends
;
1345 if (config
.getValue(rname
.str(), rclass
.str(), l
)) {
1347 resource
.clock24hour
= true;
1348 else if (clock
== 12)
1349 resource
.clock24hour
= false;
1351 resource
.clock24hour
= false;
1352 #endif // HAVE_STRFTIME
1354 rname
.seekp(0); rclass
.seekp(0);
1355 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1356 rname
<< rscreen
.str() << "edgeSnapThreshold" << ends
;
1357 rclass
<< rscreen
.str() << "EdgeSnapThreshold" << ends
;
1358 if (config
.getValue(rname
.str(), rclass
.str(), l
))
1359 resource
.edge_snap_threshold
= l
;
1361 resource
.edge_snap_threshold
= 4;
1363 rname
.seekp(0); rclass
.seekp(0);
1364 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1365 rname
<< rscreen
.str() << "imageDither" << ends
;
1366 rclass
<< rscreen
.str() << "ImageDither" << ends
;
1367 if (config
.getValue(rname
.str(), rclass
.str(), b
))
1368 image_control
->setDither(b
);
1370 image_control
->setDither(true);
1372 rname
.seekp(0); rclass
.seekp(0);
1373 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1374 rname
<< rscreen
.str() << "rootCommand" << ends
;
1375 rclass
<< rscreen
.str() << "RootCommand" << ends
;
1377 if (resource
.root_command
!= NULL
)
1378 delete [] resource
.root_command
;
1380 if (config
.getValue(rname
.str(), rclass
.str(), s
))
1381 resource
.root_command
= bstrdup(s
.c_str());
1383 resource
.root_command
= NULL
;
1385 rname
.seekp(0); rclass
.seekp(0);
1386 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1387 rname
<< rscreen
.str() << "opaqueMove" << ends
;
1388 rclass
<< rscreen
.str() << "OpaqueMove" << ends
;
1389 if (config
.getValue(rname
.str(), rclass
.str(), b
))
1390 resource
.opaque_move
= b
;
1392 resource
.opaque_move
= false;
1394 rscreen
.rdbuf()->freeze(0);
1395 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1398 void BScreen::reconfigure(void) {
1407 unsigned long gc_value_mask
= GCForeground
;
1408 if (! i18n
->multibyte()) gc_value_mask
|= GCFont
;
1410 gcv
.foreground
= WhitePixel(getBaseDisplay().getXDisplay(),
1412 gcv
.function
= GXinvert
;
1413 gcv
.subwindow_mode
= IncludeInferiors
;
1414 XChangeGC(getBaseDisplay().getXDisplay(), opGC
,
1415 GCForeground
| GCFunction
| GCSubwindowMode
, &gcv
);
1417 gcv
.foreground
= resource
.wstyle
.l_text_focus
.getPixel();
1418 if (resource
.wstyle
.font
)
1419 gcv
.font
= resource
.wstyle
.font
->fid
;
1420 XChangeGC(getBaseDisplay().getXDisplay(), resource
.wstyle
.l_text_focus_gc
,
1421 gc_value_mask
, &gcv
);
1423 gcv
.foreground
= resource
.wstyle
.l_text_unfocus
.getPixel();
1424 XChangeGC(getBaseDisplay().getXDisplay(), resource
.wstyle
.l_text_unfocus_gc
,
1425 gc_value_mask
, &gcv
);
1427 gcv
.foreground
= resource
.wstyle
.b_pic_focus
.getPixel();
1428 XChangeGC(getBaseDisplay().getXDisplay(), resource
.wstyle
.b_pic_focus_gc
,
1429 GCForeground
, &gcv
);
1431 gcv
.foreground
= resource
.wstyle
.b_pic_unfocus
.getPixel();
1432 XChangeGC(getBaseDisplay().getXDisplay(), resource
.wstyle
.b_pic_unfocus_gc
,
1433 GCForeground
, &gcv
);
1435 gcv
.foreground
= resource
.mstyle
.t_text
.getPixel();
1436 if (resource
.mstyle
.t_font
)
1437 gcv
.font
= resource
.mstyle
.t_font
->fid
;
1438 XChangeGC(getBaseDisplay().getXDisplay(), resource
.mstyle
.t_text_gc
,
1439 gc_value_mask
, &gcv
);
1441 gcv
.foreground
= resource
.mstyle
.f_text
.getPixel();
1442 if (resource
.mstyle
.f_font
)
1443 gcv
.font
= resource
.mstyle
.f_font
->fid
;
1444 XChangeGC(getBaseDisplay().getXDisplay(), resource
.mstyle
.f_text_gc
,
1445 gc_value_mask
, &gcv
);
1447 gcv
.foreground
= resource
.mstyle
.h_text
.getPixel();
1448 XChangeGC(getBaseDisplay().getXDisplay(), resource
.mstyle
.h_text_gc
,
1449 gc_value_mask
, &gcv
);
1451 gcv
.foreground
= resource
.mstyle
.d_text
.getPixel();
1452 XChangeGC(getBaseDisplay().getXDisplay(), resource
.mstyle
.d_text_gc
,
1453 gc_value_mask
, &gcv
);
1455 gcv
.foreground
= resource
.mstyle
.hilite
.getColor()->getPixel();
1456 XChangeGC(getBaseDisplay().getXDisplay(), resource
.mstyle
.hilite_gc
,
1457 gc_value_mask
, &gcv
);
1459 gcv
.foreground
= resource
.tstyle
.l_text
.getPixel();
1460 if (resource
.tstyle
.font
)
1461 gcv
.font
= resource
.tstyle
.font
->fid
;
1462 XChangeGC(getBaseDisplay().getXDisplay(), resource
.tstyle
.l_text_gc
,
1463 gc_value_mask
, &gcv
);
1465 gcv
.foreground
= resource
.tstyle
.w_text
.getPixel();
1466 XChangeGC(getBaseDisplay().getXDisplay(), resource
.tstyle
.w_text_gc
,
1467 gc_value_mask
, &gcv
);
1469 gcv
.foreground
= resource
.tstyle
.c_text
.getPixel();
1470 XChangeGC(getBaseDisplay().getXDisplay(), resource
.tstyle
.c_text_gc
,
1471 gc_value_mask
, &gcv
);
1473 gcv
.foreground
= resource
.tstyle
.b_pic
.getPixel();
1474 XChangeGC(getBaseDisplay().getXDisplay(), resource
.tstyle
.b_pic_gc
,
1475 gc_value_mask
, &gcv
);
1477 const char *s
= i18n
->getMessage(ScreenSet
, ScreenPositionLength
,
1478 "0: 0000 x 0: 0000");
1481 if (i18n
->multibyte()) {
1482 XRectangle ink
, logical
;
1483 XmbTextExtents(resource
.wstyle
.fontset
, s
, l
, &ink
, &logical
);
1484 geom_w
= logical
.width
;
1486 geom_h
= resource
.wstyle
.fontset_extents
->max_ink_extent
.height
;
1488 geom_w
= XTextWidth(resource
.wstyle
.font
, s
, l
);
1490 geom_h
= resource
.wstyle
.font
->ascent
+
1491 resource
.wstyle
.font
->descent
;
1494 geom_w
+= (resource
.bevel_width
* 2);
1495 geom_h
+= (resource
.bevel_width
* 2);
1497 Pixmap tmp
= geom_pixmap
;
1498 if (resource
.wstyle
.l_focus
.getTexture() & BImage_ParentRelative
) {
1499 if (resource
.wstyle
.t_focus
.getTexture() ==
1500 (BImage_Flat
| BImage_Solid
)) {
1502 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window
,
1503 resource
.wstyle
.t_focus
.getColor()->getPixel());
1505 geom_pixmap
= image_control
->renderImage(geom_w
, geom_h
,
1506 &resource
.wstyle
.t_focus
);
1507 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
1508 geom_window
, geom_pixmap
);
1511 if (resource
.wstyle
.l_focus
.getTexture() ==
1512 (BImage_Flat
| BImage_Solid
)) {
1514 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window
,
1515 resource
.wstyle
.l_focus
.getColor()->getPixel());
1517 geom_pixmap
= image_control
->renderImage(geom_w
, geom_h
,
1518 &resource
.wstyle
.l_focus
);
1519 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
1520 geom_window
, geom_pixmap
);
1523 if (tmp
) image_control
->removeImage(tmp
);
1525 XSetWindowBorderWidth(getBaseDisplay().getXDisplay(), geom_window
,
1526 resource
.border_width
);
1527 XSetWindowBorder(getBaseDisplay().getXDisplay(), geom_window
,
1528 resource
.border_color
.getPixel());
1530 workspacemenu
->reconfigure();
1531 iconmenu
->reconfigure();
1534 int remember_sub
= rootmenu
->getCurrentSubmenu();
1537 rootmenu
->reconfigure();
1538 rootmenu
->drawSubmenu(remember_sub
);
1541 configmenu
->reconfigure();
1543 toolbar
->reconfigure();
1546 slit
->reconfigure();
1549 std::for_each(workspacesList
.begin(), workspacesList
.end(),
1550 std::mem_fun(&Workspace::reconfigure
));
1552 for (winList::iterator it
= iconList
.begin(); it
!= iconList
.end(); ++it
)
1553 if ((*it
)->validateClient())
1554 (*it
)->reconfigure();
1556 image_control
->timeout();
1560 void BScreen::rereadMenu(void) {
1564 rootmenu
->reconfigure();
1568 void BScreen::removeWorkspaceNames(void) {
1569 workspaceNames
.clear();
1573 void BScreen::LoadStyle(void) {
1574 Resource
&conf
= resource
.styleconfig
;
1576 const char *sfile
= openbox
.getStyleFilename();
1577 bool loaded
= false;
1578 if (sfile
!= NULL
) {
1579 conf
.setFile(sfile
);
1580 loaded
= conf
.load();
1583 conf
.setFile(DEFAULTSTYLE
);
1585 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenDefaultStyleLoadFail
,
1586 "BScreen::LoadStyle(): couldn't load "
1587 "default style.\n"));
1595 // load fonts/fontsets
1597 if (i18n
->multibyte()) {
1598 readDatabaseFontSet("window.font", "Window.Font",
1599 &resource
.wstyle
.fontset
);
1600 readDatabaseFontSet("toolbar.font", "Toolbar.Font",
1601 &resource
.tstyle
.fontset
);
1602 readDatabaseFontSet("menu.title.font", "Menu.Title.Font",
1603 &resource
.mstyle
.t_fontset
);
1604 readDatabaseFontSet("menu.frame.font", "Menu.Frame.Font",
1605 &resource
.mstyle
.f_fontset
);
1607 resource
.mstyle
.t_fontset_extents
=
1608 XExtentsOfFontSet(resource
.mstyle
.t_fontset
);
1609 resource
.mstyle
.f_fontset_extents
=
1610 XExtentsOfFontSet(resource
.mstyle
.f_fontset
);
1611 resource
.tstyle
.fontset_extents
=
1612 XExtentsOfFontSet(resource
.tstyle
.fontset
);
1613 resource
.wstyle
.fontset_extents
=
1614 XExtentsOfFontSet(resource
.wstyle
.fontset
);
1616 readDatabaseFont("window.font", "Window.Font",
1617 &resource
.wstyle
.font
);
1618 readDatabaseFont("menu.title.font", "Menu.Title.Font",
1619 &resource
.mstyle
.t_font
);
1620 readDatabaseFont("menu.frame.font", "Menu.Frame.Font",
1621 &resource
.mstyle
.f_font
);
1622 readDatabaseFont("toolbar.font", "Toolbar.Font",
1623 &resource
.tstyle
.font
);
1626 // load window config
1627 readDatabaseTexture("window.title.focus", "Window.Title.Focus",
1628 &resource
.wstyle
.t_focus
,
1629 WhitePixel(getBaseDisplay().getXDisplay(),
1630 getScreenNumber()));
1631 readDatabaseTexture("window.title.unfocus", "Window.Title.Unfocus",
1632 &resource
.wstyle
.t_unfocus
,
1633 BlackPixel(getBaseDisplay().getXDisplay(),
1634 getScreenNumber()));
1635 readDatabaseTexture("window.label.focus", "Window.Label.Focus",
1636 &resource
.wstyle
.l_focus
,
1637 WhitePixel(getBaseDisplay().getXDisplay(),
1638 getScreenNumber()));
1639 readDatabaseTexture("window.label.unfocus", "Window.Label.Unfocus",
1640 &resource
.wstyle
.l_unfocus
,
1641 BlackPixel(getBaseDisplay().getXDisplay(),
1642 getScreenNumber()));
1643 readDatabaseTexture("window.handle.focus", "Window.Handle.Focus",
1644 &resource
.wstyle
.h_focus
,
1645 WhitePixel(getBaseDisplay().getXDisplay(),
1646 getScreenNumber()));
1647 readDatabaseTexture("window.handle.unfocus", "Window.Handle.Unfocus",
1648 &resource
.wstyle
.h_unfocus
,
1649 BlackPixel(getBaseDisplay().getXDisplay(),
1650 getScreenNumber()));
1651 readDatabaseTexture("window.grip.focus", "Window.Grip.Focus",
1652 &resource
.wstyle
.g_focus
,
1653 WhitePixel(getBaseDisplay().getXDisplay(),
1654 getScreenNumber()));
1655 readDatabaseTexture("window.grip.unfocus", "Window.Grip.Unfocus",
1656 &resource
.wstyle
.g_unfocus
,
1657 BlackPixel(getBaseDisplay().getXDisplay(),
1658 getScreenNumber()));
1659 readDatabaseTexture("window.button.focus", "Window.Button.Focus",
1660 &resource
.wstyle
.b_focus
,
1661 WhitePixel(getBaseDisplay().getXDisplay(),
1662 getScreenNumber()));
1663 readDatabaseTexture("window.button.unfocus", "Window.Button.Unfocus",
1664 &resource
.wstyle
.b_unfocus
,
1665 BlackPixel(getBaseDisplay().getXDisplay(),
1666 getScreenNumber()));
1667 readDatabaseTexture("window.button.pressed", "Window.Button.Pressed",
1668 &resource
.wstyle
.b_pressed
,
1669 BlackPixel(getBaseDisplay().getXDisplay(),
1670 getScreenNumber()));
1671 readDatabaseColor("window.frame.focusColor",
1672 "Window.Frame.FocusColor",
1673 &resource
.wstyle
.f_focus
,
1674 WhitePixel(getBaseDisplay().getXDisplay(),
1675 getScreenNumber()));
1676 readDatabaseColor("window.frame.unfocusColor",
1677 "Window.Frame.UnfocusColor",
1678 &resource
.wstyle
.f_unfocus
,
1679 BlackPixel(getBaseDisplay().getXDisplay(),
1680 getScreenNumber()));
1681 readDatabaseColor("window.label.focus.textColor",
1682 "Window.Label.Focus.TextColor",
1683 &resource
.wstyle
.l_text_focus
,
1684 BlackPixel(getBaseDisplay().getXDisplay(),
1685 getScreenNumber()));
1686 readDatabaseColor("window.label.unfocus.textColor",
1687 "Window.Label.Unfocus.TextColor",
1688 &resource
.wstyle
.l_text_unfocus
,
1689 WhitePixel(getBaseDisplay().getXDisplay(),
1690 getScreenNumber()));
1691 readDatabaseColor("window.button.focus.picColor",
1692 "Window.Button.Focus.PicColor",
1693 &resource
.wstyle
.b_pic_focus
,
1694 BlackPixel(getBaseDisplay().getXDisplay(),
1695 getScreenNumber()));
1696 readDatabaseColor("window.button.unfocus.picColor",
1697 "Window.Button.Unfocus.PicColor",
1698 &resource
.wstyle
.b_pic_unfocus
,
1699 WhitePixel(getBaseDisplay().getXDisplay(),
1700 getScreenNumber()));
1702 if (conf
.getValue("window.justify", "Window.Justify", s
)) {
1703 if (0 == strncasecmp(s
.c_str(), "right", s
.length()))
1704 resource
.wstyle
.justify
= BScreen::RightJustify
;
1705 else if (0 == strncasecmp(s
.c_str(), "center", s
.length()))
1706 resource
.wstyle
.justify
= BScreen::CenterJustify
;
1708 resource
.wstyle
.justify
= BScreen::LeftJustify
;
1710 resource
.wstyle
.justify
= BScreen::LeftJustify
;
1712 // load toolbar config
1713 readDatabaseTexture("toolbar", "Toolbar",
1714 &resource
.tstyle
.toolbar
,
1715 BlackPixel(getBaseDisplay().getXDisplay(),
1716 getScreenNumber()));
1717 readDatabaseTexture("toolbar.label", "Toolbar.Label",
1718 &resource
.tstyle
.label
,
1719 BlackPixel(getBaseDisplay().getXDisplay(),
1720 getScreenNumber()));
1721 readDatabaseTexture("toolbar.windowLabel", "Toolbar.WindowLabel",
1722 &resource
.tstyle
.window
,
1723 BlackPixel(getBaseDisplay().getXDisplay(),
1724 getScreenNumber()));
1725 readDatabaseTexture("toolbar.button", "Toolbar.Button",
1726 &resource
.tstyle
.button
,
1727 WhitePixel(getBaseDisplay().getXDisplay(),
1728 getScreenNumber()));
1729 readDatabaseTexture("toolbar.button.pressed", "Toolbar.Button.Pressed",
1730 &resource
.tstyle
.pressed
,
1731 BlackPixel(getBaseDisplay().getXDisplay(),
1732 getScreenNumber()));
1733 readDatabaseTexture("toolbar.clock", "Toolbar.Clock",
1734 &resource
.tstyle
.clock
,
1735 BlackPixel(getBaseDisplay().getXDisplay(),
1736 getScreenNumber()));
1737 readDatabaseColor("toolbar.label.textColor", "Toolbar.Label.TextColor",
1738 &resource
.tstyle
.l_text
,
1739 WhitePixel(getBaseDisplay().getXDisplay(),
1740 getScreenNumber()));
1741 readDatabaseColor("toolbar.windowLabel.textColor",
1742 "Toolbar.WindowLabel.TextColor",
1743 &resource
.tstyle
.w_text
,
1744 WhitePixel(getBaseDisplay().getXDisplay(),
1745 getScreenNumber()));
1746 readDatabaseColor("toolbar.clock.textColor", "Toolbar.Clock.TextColor",
1747 &resource
.tstyle
.c_text
,
1748 WhitePixel(getBaseDisplay().getXDisplay(),
1749 getScreenNumber()));
1750 readDatabaseColor("toolbar.button.picColor", "Toolbar.Button.PicColor",
1751 &resource
.tstyle
.b_pic
,
1752 BlackPixel(getBaseDisplay().getXDisplay(),
1753 getScreenNumber()));
1755 if (conf
.getValue("toolbar.justify", "Toolbar.Justify", s
)) {
1756 if (0 == strncasecmp(s
.c_str(), "right", s
.length()))
1757 resource
.tstyle
.justify
= BScreen::RightJustify
;
1758 else if (0 == strncasecmp(s
.c_str(), "center", s
.length()))
1759 resource
.tstyle
.justify
= BScreen::CenterJustify
;
1761 resource
.tstyle
.justify
= BScreen::LeftJustify
;
1763 resource
.tstyle
.justify
= BScreen::LeftJustify
;
1766 readDatabaseTexture("menu.title", "Menu.Title",
1767 &resource
.mstyle
.title
,
1768 WhitePixel(getBaseDisplay().getXDisplay(),
1769 getScreenNumber()));
1770 readDatabaseTexture("menu.frame", "Menu.Frame",
1771 &resource
.mstyle
.frame
,
1772 BlackPixel(getBaseDisplay().getXDisplay(),
1773 getScreenNumber()));
1774 readDatabaseTexture("menu.hilite", "Menu.Hilite",
1775 &resource
.mstyle
.hilite
,
1776 WhitePixel(getBaseDisplay().getXDisplay(),
1777 getScreenNumber()));
1778 readDatabaseColor("menu.title.textColor", "Menu.Title.TextColor",
1779 &resource
.mstyle
.t_text
,
1780 BlackPixel(getBaseDisplay().getXDisplay(),
1781 getScreenNumber()));
1782 readDatabaseColor("menu.frame.textColor", "Menu.Frame.TextColor",
1783 &resource
.mstyle
.f_text
,
1784 WhitePixel(getBaseDisplay().getXDisplay(),
1785 getScreenNumber()));
1786 readDatabaseColor("menu.frame.disableColor", "Menu.Frame.DisableColor",
1787 &resource
.mstyle
.d_text
,
1788 BlackPixel(getBaseDisplay().getXDisplay(),
1789 getScreenNumber()));
1790 readDatabaseColor("menu.hilite.textColor", "Menu.Hilite.TextColor",
1791 &resource
.mstyle
.h_text
,
1792 BlackPixel(getBaseDisplay().getXDisplay(),
1793 getScreenNumber()));
1795 if (conf
.getValue("menu.title.justify", "Menu.Title.Justify", s
)) {
1796 if (0 == strncasecmp(s
.c_str(), "right", s
.length()))
1797 resource
.mstyle
.t_justify
= BScreen::RightJustify
;
1798 else if (0 == strncasecmp(s
.c_str(), "center", s
.length()))
1799 resource
.mstyle
.t_justify
= BScreen::CenterJustify
;
1801 resource
.mstyle
.t_justify
= BScreen::LeftJustify
;
1803 resource
.mstyle
.t_justify
= BScreen::LeftJustify
;
1805 if (conf
.getValue("menu.frame.justify", "Menu.Frame.Justify", s
)) {
1806 if (0 == strncasecmp(s
.c_str(), "right", s
.length()))
1807 resource
.mstyle
.f_justify
= BScreen::RightJustify
;
1808 else if (0 == strncasecmp(s
.c_str(), "center", s
.length()))
1809 resource
.mstyle
.f_justify
= BScreen::CenterJustify
;
1811 resource
.mstyle
.f_justify
= BScreen::LeftJustify
;
1813 resource
.mstyle
.f_justify
= BScreen::LeftJustify
;
1815 if (conf
.getValue("menu.bullet", "Menu.Bullet", s
)) {
1816 if (0 == strncasecmp(s
.c_str(), "empty", s
.length()))
1817 resource
.mstyle
.bullet
= Basemenu::Empty
;
1818 else if (0 == strncasecmp(s
.c_str(), "square", s
.length()))
1819 resource
.mstyle
.bullet
= Basemenu::Square
;
1820 else if (0 == strncasecmp(s
.c_str(), "diamond", s
.length()))
1821 resource
.mstyle
.bullet
= Basemenu::Diamond
;
1823 resource
.mstyle
.bullet
= Basemenu::Triangle
;
1825 resource
.mstyle
.bullet
= Basemenu::Triangle
;
1827 if (conf
.getValue("menu.bullet.position", "Menu.Bullet.Position", s
)) {
1828 if (0 == strncasecmp(s
.c_str(), "right", s
.length()))
1829 resource
.mstyle
.bullet_pos
= Basemenu::Right
;
1831 resource
.mstyle
.bullet_pos
= Basemenu::Left
;
1833 resource
.mstyle
.bullet_pos
= Basemenu::Left
;
1835 readDatabaseColor("borderColor", "BorderColor", &resource
.border_color
,
1836 BlackPixel(getBaseDisplay().getXDisplay(),
1837 getScreenNumber()));
1839 // load bevel, border and handle widths
1840 if (conf
.getValue("handleWidth", "HandleWidth", l
)) {
1841 if (l
<= size().w() / 2 && l
!= 0)
1842 resource
.handle_width
= l
;
1844 resource
.handle_width
= 6;
1846 resource
.handle_width
= 6;
1848 if (conf
.getValue("borderWidth", "BorderWidth", l
))
1849 resource
.border_width
= l
;
1851 resource
.border_width
= 1;
1853 if (conf
.getValue("bevelWidth", "BevelWidth", l
)) {
1854 if (l
<= size().w() / 2 && l
!= 0)
1855 resource
.bevel_width
= l
;
1857 resource
.bevel_width
= 3;
1859 resource
.bevel_width
= 3;
1861 if (conf
.getValue("frameWidth", "FrameWidth", l
)) {
1862 if (l
<= size().w() / 2)
1863 resource
.frame_width
= l
;
1865 resource
.frame_width
= resource
.bevel_width
;
1867 resource
.frame_width
= resource
.bevel_width
;
1869 const char *cmd
= resource
.root_command
;
1870 if (cmd
!= NULL
|| conf
.getValue("rootCommand", "RootCommand", s
)) {
1872 cmd
= s
.c_str(); // not specified by the screen, so use the one from the
1875 char displaystring
[MAXPATHLEN
];
1876 sprintf(displaystring
, "DISPLAY=%s",
1877 DisplayString(getBaseDisplay().getXDisplay()));
1878 sprintf(displaystring
+ strlen(displaystring
) - 1, "%d",
1881 bexec(cmd
, displaystring
);
1883 spawnlp(P_NOWAIT
, "cmd.exe", "cmd.exe", "/c", cmd
, NULL
);
1889 void BScreen::addIcon(OpenboxWindow
*w
) {
1892 w
->setWorkspace(-1);
1893 w
->setWindowNumber(iconList
.size());
1895 iconList
.push_back(w
);
1897 iconmenu
->insert((const char **) w
->getIconTitle());
1902 void BScreen::removeIcon(OpenboxWindow
*w
) {
1907 iconmenu
->remove(w
->getWindowNumber());
1910 winList::iterator it
= iconList
.begin();
1911 for (int i
= 0; it
!= iconList
.end(); ++it
, ++i
)
1912 (*it
)->setWindowNumber(i
);
1916 OpenboxWindow
*BScreen::getIcon(int index
) {
1917 if (index
< 0 || index
>= iconList
.size())
1918 return (OpenboxWindow
*) 0;
1920 winList::iterator it
= iconList
.begin();
1921 for (; index
> 0; --index
, ++it
); // increment to index
1926 int BScreen::addWorkspace(void) {
1927 Workspace
*wkspc
= new Workspace(*this, workspacesList
.size());
1928 workspacesList
.push_back(wkspc
);
1929 setWorkspaceCount(workspaceCount()+1);
1930 saveWorkspaceNames();
1932 workspacemenu
->insert(wkspc
->getName(), wkspc
->getMenu(),
1933 wkspc
->getWorkspaceID() + 2);
1934 workspacemenu
->update();
1936 toolbar
->reconfigure();
1938 updateNetizenWorkspaceCount();
1940 return workspacesList
.size();
1944 int BScreen::removeLastWorkspace(void) {
1945 if (workspacesList
.size() == 1)
1948 Workspace
*wkspc
= workspacesList
.back();
1950 if (current_workspace
->getWorkspaceID() == wkspc
->getWorkspaceID())
1951 changeWorkspaceID(current_workspace
->getWorkspaceID() - 1);
1955 workspacemenu
->remove(wkspc
->getWorkspaceID() + 2);
1956 workspacemenu
->update();
1958 workspacesList
.pop_back();
1961 setWorkspaceCount(workspaceCount()-1);
1962 saveWorkspaceNames();
1964 toolbar
->reconfigure();
1966 updateNetizenWorkspaceCount();
1968 return workspacesList
.size();
1972 void BScreen::changeWorkspaceID(int id
) {
1973 if (! current_workspace
) return;
1975 if (id
!= current_workspace
->getWorkspaceID()) {
1976 current_workspace
->hideAll();
1978 workspacemenu
->setItemSelected(current_workspace
->getWorkspaceID() + 2,
1981 if (openbox
.focusedWindow() &&
1982 openbox
.focusedWindow()->getScreen() == this &&
1983 (! openbox
.focusedWindow()->isStuck())) {
1984 current_workspace
->setLastFocusedWindow(openbox
.focusedWindow());
1985 openbox
.focusWindow((OpenboxWindow
*) 0);
1988 current_workspace
= getWorkspace(id
);
1990 workspacemenu
->setItemSelected(current_workspace
->getWorkspaceID() + 2,
1992 toolbar
->redrawWorkspaceLabel(True
);
1994 current_workspace
->showAll();
1996 if (resource
.focus_last
&& current_workspace
->getLastFocusedWindow()) {
1997 XSync(openbox
.getXDisplay(), False
);
1998 current_workspace
->getLastFocusedWindow()->setInputFocus();
2002 updateNetizenCurrentWorkspace();
2006 void BScreen::addNetizen(Netizen
*n
) {
2007 netizenList
.push_back(n
);
2009 n
->sendWorkspaceCount();
2010 n
->sendCurrentWorkspace();
2012 wkspList::iterator it
;
2013 for (it
= workspacesList
.begin(); it
!= workspacesList
.end(); ++it
) {
2014 for (int i
= 0; i
< (*it
)->getCount(); i
++)
2015 n
->sendWindowAdd((*it
)->getWindow(i
)->getClientWindow(),
2016 (*it
)->getWorkspaceID());
2019 Window f
= ((openbox
.focusedWindow()) ?
2020 openbox
.focusedWindow()->getClientWindow() : None
);
2021 n
->sendWindowFocus(f
);
2025 void BScreen::removeNetizen(Window w
) {
2026 netList::iterator it
;
2029 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2030 if ((*it
)->getWindowID() == w
) {
2032 netizenList
.erase(it
);
2039 void BScreen::updateNetizenCurrentWorkspace(void) {
2040 netList::iterator it
;
2041 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2042 (*it
)->sendCurrentWorkspace();
2046 void BScreen::updateNetizenWorkspaceCount(void) {
2047 netList::iterator it
;
2048 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2049 (*it
)->sendWorkspaceCount();
2053 void BScreen::updateNetizenWindowFocus(void) {
2054 Window f
= ((openbox
.focusedWindow()) ?
2055 openbox
.focusedWindow()->getClientWindow() : None
);
2056 netList::iterator it
;
2057 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2058 (*it
)->sendWindowFocus(f
);
2062 void BScreen::updateNetizenWindowAdd(Window w
, unsigned long p
) {
2063 netList::iterator it
;
2064 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2065 (*it
)->sendWindowAdd(w
, p
);
2069 void BScreen::updateNetizenWindowDel(Window w
) {
2070 netList::iterator it
;
2071 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2072 (*it
)->sendWindowDel(w
);
2076 void BScreen::updateNetizenWindowRaise(Window w
) {
2077 netList::iterator it
;
2078 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2079 (*it
)->sendWindowRaise(w
);
2083 void BScreen::updateNetizenWindowLower(Window w
) {
2084 netList::iterator it
;
2085 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2086 (*it
)->sendWindowLower(w
);
2090 void BScreen::updateNetizenConfigNotify(XEvent
*e
) {
2091 netList::iterator it
;
2092 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2093 (*it
)->sendConfigNotify(e
);
2097 void BScreen::raiseWindows(Window
*workspace_stack
, int num
) {
2098 Window
*session_stack
= new
2099 Window
[(num
+ workspacesList
.size() + rootmenuList
.size() + 13)];
2102 XRaiseWindow(getBaseDisplay().getXDisplay(), iconmenu
->getWindowID());
2103 *(session_stack
+ i
++) = iconmenu
->getWindowID();
2105 wkspList::iterator it
;
2106 for (it
= workspacesList
.begin(); it
!= workspacesList
.end(); ++it
)
2107 *(session_stack
+ i
++) = (*it
)->getMenu()->getWindowID();
2109 *(session_stack
+ i
++) = workspacemenu
->getWindowID();
2111 *(session_stack
+ i
++) = configmenu
->getFocusmenu()->getWindowID();
2112 *(session_stack
+ i
++) = configmenu
->getPlacementmenu()->getWindowID();
2113 *(session_stack
+ i
++) = configmenu
->getWindowID();
2116 *(session_stack
+ i
++) = slit
->getMenu()->getDirectionmenu()->getWindowID();
2117 *(session_stack
+ i
++) = slit
->getMenu()->getPlacementmenu()->getWindowID();
2118 *(session_stack
+ i
++) = slit
->getMenu()->getWindowID();
2121 *(session_stack
+ i
++) =
2122 toolbar
->getMenu()->getPlacementmenu()->getWindowID();
2123 *(session_stack
+ i
++) = toolbar
->getMenu()->getWindowID();
2125 menuList::iterator rit
;
2126 for (rit
= rootmenuList
.begin(); rit
!= rootmenuList
.end(); ++rit
)
2127 *(session_stack
+ i
++) = (*rit
)->getWindowID();
2128 *(session_stack
+ i
++) = rootmenu
->getWindowID();
2130 if (toolbar
->onTop())
2131 *(session_stack
+ i
++) = toolbar
->getWindowID();
2135 *(session_stack
+ i
++) = slit
->getWindowID();
2139 *(session_stack
+ i
++) = *(workspace_stack
+ k
);
2141 XRestackWindows(getBaseDisplay().getXDisplay(), session_stack
, i
);
2143 delete [] session_stack
;
2147 void BScreen::addWorkspaceName(const char *name
) {
2148 workspaceNames
.push_back(name
);
2152 const char *BScreen::getNameOfWorkspace(int id
) {
2153 if (id
< 0 || id
>= workspaceNames
.size())
2154 return (const char *) 0;
2155 return workspaceNames
[id
].c_str();
2159 void BScreen::reassociateWindow(OpenboxWindow
*w
, int wkspc_id
, Bool ignore_sticky
) {
2163 wkspc_id
= current_workspace
->getWorkspaceID();
2165 if (w
->getWorkspaceNumber() == wkspc_id
)
2168 if (w
->isIconic()) {
2170 getWorkspace(wkspc_id
)->addWindow(w
);
2171 } else if (ignore_sticky
|| ! w
->isStuck()) {
2172 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
2173 getWorkspace(wkspc_id
)->addWindow(w
);
2178 void BScreen::nextFocus(void) {
2179 Bool have_focused
= False
;
2180 int focused_window_number
= -1;
2181 OpenboxWindow
*next
;
2183 if (openbox
.focusedWindow()) {
2184 if (openbox
.focusedWindow()->getScreen()->getScreenNumber() ==
2185 getScreenNumber()) {
2186 have_focused
= True
;
2187 focused_window_number
= openbox
.focusedWindow()->getWindowNumber();
2191 if ((getCurrentWorkspace()->getCount() > 1) && have_focused
) {
2192 int next_window_number
= focused_window_number
;
2194 if ((++next_window_number
) >= getCurrentWorkspace()->getCount())
2195 next_window_number
= 0;
2197 next
= getCurrentWorkspace()->getWindow(next_window_number
);
2198 } while ((! next
->setInputFocus()) && (next_window_number
!=
2199 focused_window_number
));
2201 if (next_window_number
!= focused_window_number
)
2202 getCurrentWorkspace()->raiseWindow(next
);
2203 } else if (getCurrentWorkspace()->getCount() >= 1) {
2204 next
= current_workspace
->getWindow(0);
2206 current_workspace
->raiseWindow(next
);
2207 next
->setInputFocus();
2212 void BScreen::prevFocus(void) {
2213 Bool have_focused
= False
;
2214 int focused_window_number
= -1;
2215 OpenboxWindow
*prev
;
2217 if (openbox
.focusedWindow()) {
2218 if (openbox
.focusedWindow()->getScreen()->getScreenNumber() ==
2219 getScreenNumber()) {
2220 have_focused
= True
;
2221 focused_window_number
= openbox
.focusedWindow()->getWindowNumber();
2225 if ((getCurrentWorkspace()->getCount() > 1) && have_focused
) {
2226 int prev_window_number
= focused_window_number
;
2228 if ((--prev_window_number
) < 0)
2229 prev_window_number
= getCurrentWorkspace()->getCount() - 1;
2231 prev
= getCurrentWorkspace()->getWindow(prev_window_number
);
2232 } while ((! prev
->setInputFocus()) && (prev_window_number
!=
2233 focused_window_number
));
2235 if (prev_window_number
!= focused_window_number
)
2236 getCurrentWorkspace()->raiseWindow(prev
);
2237 } else if (getCurrentWorkspace()->getCount() >= 1) {
2238 prev
= current_workspace
->getWindow(0);
2240 current_workspace
->raiseWindow(prev
);
2241 prev
->setInputFocus();
2246 void BScreen::raiseFocus(void) {
2247 Bool have_focused
= False
;
2248 int focused_window_number
= -1;
2250 if (openbox
.focusedWindow()) {
2251 if (openbox
.focusedWindow()->getScreen()->getScreenNumber() ==
2252 getScreenNumber()) {
2253 have_focused
= True
;
2254 focused_window_number
= openbox
.focusedWindow()->getWindowNumber();
2258 if ((getCurrentWorkspace()->getCount() > 1) && have_focused
)
2259 getWorkspace(openbox
.focusedWindow()->getWorkspaceNumber())->
2260 raiseWindow(openbox
.focusedWindow());
2264 void BScreen::InitMenu(void) {
2266 rootmenuList
.clear();
2267 while (rootmenu
->getCount())
2268 rootmenu
->remove(0);
2270 rootmenu
= new Rootmenu(*this);
2272 Bool defaultMenu
= True
;
2274 if (openbox
.getMenuFilename()) {
2275 FILE *menu_file
= fopen(openbox
.getMenuFilename(), "r");
2278 perror(openbox
.getMenuFilename());
2280 if (feof(menu_file
)) {
2281 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenEmptyMenuFile
,
2282 "%s: Empty menu file"),
2283 openbox
.getMenuFilename());
2285 char line
[1024], label
[1024];
2286 memset(line
, 0, 1024);
2287 memset(label
, 0, 1024);
2289 while (fgets(line
, 1024, menu_file
) && ! feof(menu_file
)) {
2290 if (line
[0] != '#') {
2291 int i
, key
= 0, index
= -1, len
= strlen(line
);
2294 for (i
= 0; i
< len
; i
++) {
2295 if (line
[i
] == '[') index
= 0;
2296 else if (line
[i
] == ']') break;
2297 else if (line
[i
] != ' ')
2299 key
+= tolower(line
[i
]);
2304 for (i
= index
; i
< len
; i
++) {
2305 if (line
[i
] == '(') index
= 0;
2306 else if (line
[i
] == ')') break;
2307 else if (index
++ >= 0) {
2308 if (line
[i
] == '\\' && i
< len
- 1) i
++;
2309 label
[index
- 1] = line
[i
];
2313 if (index
== -1) index
= 0;
2314 label
[index
] = '\0';
2316 rootmenu
->setLabel(label
);
2317 defaultMenu
= parseMenuFile(menu_file
, rootmenu
);
2328 rootmenu
->setInternalMenu();
2329 rootmenu
->insert(i18n
->getMessage(ScreenSet
, Screenxterm
, "xterm"),
2331 i18n
->getMessage(ScreenSet
, Screenxterm
, "xterm"));
2332 rootmenu
->insert(i18n
->getMessage(ScreenSet
, ScreenRestart
, "Restart"),
2334 rootmenu
->insert(i18n
->getMessage(ScreenSet
, ScreenExit
, "Exit"),
2337 openbox
.setMenuFilename(openbox
.getMenuFilename());
2342 Bool
BScreen::parseMenuFile(FILE *file
, Rootmenu
*menu
) {
2343 char line
[1024], label
[1024], command
[1024];
2345 while (! feof(file
)) {
2346 memset(line
, 0, 1024);
2347 memset(label
, 0, 1024);
2348 memset(command
, 0, 1024);
2350 if (fgets(line
, 1024, file
)) {
2351 if (line
[0] != '#') {
2352 register int i
, key
= 0, parse
= 0, index
= -1,
2353 line_length
= strlen(line
),
2354 label_length
= 0, command_length
= 0;
2356 // determine the keyword
2358 for (i
= 0; i
< line_length
; i
++) {
2359 if (line
[i
] == '[') parse
= 1;
2360 else if (line
[i
] == ']') break;
2361 else if (line
[i
] != ' ')
2363 key
+= tolower(line
[i
]);
2366 // get the label enclosed in ()'s
2369 for (i
= 0; i
< line_length
; i
++) {
2370 if (line
[i
] == '(') {
2373 } else if (line
[i
] == ')') break;
2374 else if (index
++ >= 0) {
2375 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
2376 label
[index
- 1] = line
[i
];
2381 label
[index
] = '\0';
2382 label_length
= index
;
2388 // get the command enclosed in {}'s
2391 for (i
= 0; i
< line_length
; i
++) {
2392 if (line
[i
] == '{') {
2395 } else if (line
[i
] == '}') break;
2396 else if (index
++ >= 0) {
2397 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
2398 command
[index
- 1] = line
[i
];
2403 command
[index
] = '\0';
2404 command_length
= index
;
2412 return ((menu
->getCount() == 0) ? True
: False
);
2417 menu
->insert(label
);
2422 if ((! *label
) && (! *command
)) {
2423 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenEXECError
,
2424 "BScreen::parseMenuFile: [exec] error, "
2425 "no menu label and/or command defined\n"));
2429 menu
->insert(label
, BScreen::Execute
, command
);
2435 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenEXITError
,
2436 "BScreen::parseMenuFile: [exit] error, "
2437 "no menu label defined\n"));
2441 menu
->insert(label
, BScreen::Exit
);
2447 if ((! *label
) || (! *command
)) {
2448 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenSTYLEError
,
2449 "BScreen::parseMenuFile: [style] error, "
2450 "no menu label and/or filename defined\n"));
2454 char style
[MAXPATHLEN
];
2456 // perform shell style ~ home directory expansion
2458 int homedir_len
= 0;
2459 if (*command
== '~' && *(command
+ 1) == '/') {
2460 homedir
= getenv("HOME");
2461 homedir_len
= strlen(homedir
);
2464 if (homedir
&& homedir_len
!= 0) {
2465 strncpy(style
, homedir
, homedir_len
);
2467 strncpy(style
+ homedir_len
, command
+ 1,
2468 command_length
- 1);
2469 *(style
+ command_length
+ homedir_len
- 1) = '\0';
2471 strncpy(style
, command
, command_length
);
2472 *(style
+ command_length
) = '\0';
2475 menu
->insert(label
, BScreen::SetStyle
, style
);
2482 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenCONFIGError
,
2483 "BScreen::parseMenufile: [config] error, "
2484 "no label defined"));
2488 menu
->insert(label
, configmenu
);
2492 case 740: // include
2495 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenINCLUDEError
,
2496 "BScreen::parseMenuFile: [include] error, "
2497 "no filename defined\n"));
2501 char newfile
[MAXPATHLEN
];
2503 // perform shell style ~ home directory expansion
2505 int homedir_len
= 0;
2506 if (*label
== '~' && *(label
+ 1) == '/') {
2507 homedir
= getenv("HOME");
2508 homedir_len
= strlen(homedir
);
2511 if (homedir
&& homedir_len
!= 0) {
2512 strncpy(newfile
, homedir
, homedir_len
);
2514 strncpy(newfile
+ homedir_len
, label
+ 1,
2516 *(newfile
+ label_length
+ homedir_len
- 1) = '\0';
2518 strncpy(newfile
, label
, label_length
);
2519 *(newfile
+ label_length
) = '\0';
2523 FILE *submenufile
= fopen(newfile
, "r");
2527 if (fstat(fileno(submenufile
), &buf
) ||
2528 (! S_ISREG(buf
.st_mode
))) {
2530 i18n
->getMessage(ScreenSet
, ScreenINCLUDEErrorReg
,
2531 "BScreen::parseMenuFile: [include] error: "
2532 "'%s' is not a regular file\n"), newfile
);
2536 if (! feof(submenufile
)) {
2537 if (! parseMenuFile(submenufile
, menu
))
2538 openbox
.setMenuFilename(newfile
);
2540 fclose(submenufile
);
2549 case 767: // submenu
2552 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenSUBMENUError
,
2553 "BScreen::parseMenuFile: [submenu] error, "
2554 "no menu label defined\n"));
2558 Rootmenu
*submenu
= new Rootmenu(*this);
2561 submenu
->setLabel(command
);
2563 submenu
->setLabel(label
);
2565 parseMenuFile(file
, submenu
);
2567 menu
->insert(label
, submenu
);
2568 rootmenuList
.push_back(submenu
);
2573 case 773: // restart
2576 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenRESTARTError
,
2577 "BScreen::parseMenuFile: [restart] error, "
2578 "no menu label defined\n"));
2583 menu
->insert(label
, BScreen::RestartOther
, command
);
2585 menu
->insert(label
, BScreen::Restart
);
2590 case 845: // reconfig
2593 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenRECONFIGError
,
2594 "BScreen::parseMenuFile: [reconfig] error, "
2595 "no menu label defined\n"));
2599 menu
->insert(label
, BScreen::Reconfigure
);
2604 case 995: // stylesdir
2605 case 1113: // stylesmenu
2607 Bool newmenu
= ((key
== 1113) ? True
: False
);
2609 if ((! *label
) || ((! *command
) && newmenu
)) {
2611 i18n
->getMessage(ScreenSet
, ScreenSTYLESDIRError
,
2612 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
2613 " error, no directory defined\n"));
2617 char stylesdir
[MAXPATHLEN
];
2619 char *directory
= ((newmenu
) ? command
: label
);
2620 int directory_length
= ((newmenu
) ? command_length
: label_length
);
2622 // perform shell style ~ home directory expansion
2624 int homedir_len
= 0;
2626 if (*directory
== '~' && *(directory
+ 1) == '/') {
2627 homedir
= getenv("HOME");
2628 homedir_len
= strlen(homedir
);
2631 if (homedir
&& homedir_len
!= 0) {
2632 strncpy(stylesdir
, homedir
, homedir_len
);
2634 strncpy(stylesdir
+ homedir_len
, directory
+ 1,
2635 directory_length
- 1);
2636 *(stylesdir
+ directory_length
+ homedir_len
- 1) = '\0';
2638 strncpy(stylesdir
, directory
, directory_length
);
2639 *(stylesdir
+ directory_length
) = '\0';
2642 struct stat statbuf
;
2644 if (! stat(stylesdir
, &statbuf
)) {
2645 if (S_ISDIR(statbuf
.st_mode
)) {
2646 Rootmenu
*stylesmenu
;
2649 stylesmenu
= new Rootmenu(*this);
2653 DIR *d
= opendir(stylesdir
);
2657 // get the total number of directory entries
2658 while ((p
= readdir(d
))) entries
++;
2661 char **ls
= new char* [entries
];
2663 while ((p
= readdir(d
)))
2664 ls
[index
++] = bstrdup(p
->d_name
);
2668 std::sort(ls
, ls
+ entries
, dcmp());
2670 int n
, slen
= strlen(stylesdir
);
2671 for (n
= 0; n
< entries
; n
++) {
2672 if (ls
[n
][strlen(ls
[n
])-1] != '~') {
2673 int nlen
= strlen(ls
[n
]);
2674 char style
[MAXPATHLEN
+ 1];
2676 strncpy(style
, stylesdir
, slen
);
2677 *(style
+ slen
) = '/';
2678 strncpy(style
+ slen
+ 1, ls
[n
], nlen
+ 1);
2680 if ((! stat(style
, &statbuf
)) && S_ISREG(statbuf
.st_mode
))
2681 stylesmenu
->insert(ls
[n
], BScreen::SetStyle
, style
);
2689 stylesmenu
->update();
2692 stylesmenu
->setLabel(label
);
2693 menu
->insert(label
, stylesmenu
);
2694 rootmenuList
.push_back(stylesmenu
);
2697 openbox
.setMenuFilename(stylesdir
);
2699 fprintf(stderr
, i18n
->getMessage(ScreenSet
,
2700 ScreenSTYLESDIRErrorNotDir
,
2701 "BScreen::parseMenuFile:"
2702 " [stylesdir/stylesmenu] error, %s is not a"
2703 " directory\n"), stylesdir
);
2707 i18n
->getMessage(ScreenSet
, ScreenSTYLESDIRErrorNoExist
,
2708 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
2709 " error, %s does not exist\n"), stylesdir
);
2715 case 1090: // workspaces
2719 i18n
->getMessage(ScreenSet
, ScreenWORKSPACESError
,
2720 "BScreen:parseMenuFile: [workspaces] error, "
2721 "no menu label defined\n"));
2725 menu
->insert(label
, workspacemenu
);
2734 return ((menu
->getCount() == 0) ? True
: False
);
2738 void BScreen::shutdown(void) {
2741 XSelectInput(getBaseDisplay().getXDisplay(), getRootWindow(), NoEventMask
);
2742 XSync(getBaseDisplay().getXDisplay(), False
);
2744 std::for_each(workspacesList
.begin(), workspacesList
.end(),
2745 std::mem_fun(&Workspace::shutdown
));
2747 while (!iconList
.empty())
2748 iconList
.front()->restore();
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
;