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
);
487 XFlush(getBaseDisplay().getXDisplay());
491 BScreen::~BScreen(void) {
492 if (! managed
) return;
494 if (geom_pixmap
!= None
)
495 image_control
->removeImage(geom_pixmap
);
497 if (geom_window
!= None
)
498 XDestroyWindow(getBaseDisplay().getXDisplay(), geom_window
);
500 removeWorkspaceNames();
502 std::for_each(workspacesList
.begin(), workspacesList
.end(),
504 std::for_each(iconList
.begin(), iconList
.end(), PointerAssassin());
505 std::for_each(netizenList
.begin(), netizenList
.end(), PointerAssassin());
508 if (resource
.strftime_format
)
509 delete [] resource
.strftime_format
;
510 #endif // HAVE_STRFTIME
513 delete workspacemenu
;
522 delete image_control
;
524 if (resource
.wstyle
.fontset
)
525 XFreeFontSet(getBaseDisplay().getXDisplay(), resource
.wstyle
.fontset
);
526 if (resource
.mstyle
.t_fontset
)
527 XFreeFontSet(getBaseDisplay().getXDisplay(), resource
.mstyle
.t_fontset
);
528 if (resource
.mstyle
.f_fontset
)
529 XFreeFontSet(getBaseDisplay().getXDisplay(), resource
.mstyle
.f_fontset
);
530 if (resource
.tstyle
.fontset
)
531 XFreeFontSet(getBaseDisplay().getXDisplay(), resource
.tstyle
.fontset
);
533 if (resource
.wstyle
.font
)
534 XFreeFont(getBaseDisplay().getXDisplay(), resource
.wstyle
.font
);
535 if (resource
.mstyle
.t_font
)
536 XFreeFont(getBaseDisplay().getXDisplay(), resource
.mstyle
.t_font
);
537 if (resource
.mstyle
.f_font
)
538 XFreeFont(getBaseDisplay().getXDisplay(), resource
.mstyle
.f_font
);
539 if (resource
.tstyle
.font
)
540 XFreeFont(getBaseDisplay().getXDisplay(), resource
.tstyle
.font
);
541 if (resource
.root_command
!= NULL
)
542 delete [] resource
.root_command
;
544 XFreeGC(getBaseDisplay().getXDisplay(), opGC
);
546 XFreeGC(getBaseDisplay().getXDisplay(),
547 resource
.wstyle
.l_text_focus_gc
);
548 XFreeGC(getBaseDisplay().getXDisplay(),
549 resource
.wstyle
.l_text_unfocus_gc
);
550 XFreeGC(getBaseDisplay().getXDisplay(),
551 resource
.wstyle
.b_pic_focus_gc
);
552 XFreeGC(getBaseDisplay().getXDisplay(),
553 resource
.wstyle
.b_pic_unfocus_gc
);
555 XFreeGC(getBaseDisplay().getXDisplay(),
556 resource
.mstyle
.t_text_gc
);
557 XFreeGC(getBaseDisplay().getXDisplay(),
558 resource
.mstyle
.f_text_gc
);
559 XFreeGC(getBaseDisplay().getXDisplay(),
560 resource
.mstyle
.h_text_gc
);
561 XFreeGC(getBaseDisplay().getXDisplay(),
562 resource
.mstyle
.d_text_gc
);
563 XFreeGC(getBaseDisplay().getXDisplay(),
564 resource
.mstyle
.hilite_gc
);
566 XFreeGC(getBaseDisplay().getXDisplay(),
567 resource
.tstyle
.l_text_gc
);
568 XFreeGC(getBaseDisplay().getXDisplay(),
569 resource
.tstyle
.w_text_gc
);
570 XFreeGC(getBaseDisplay().getXDisplay(),
571 resource
.tstyle
.c_text_gc
);
572 XFreeGC(getBaseDisplay().getXDisplay(),
573 resource
.tstyle
.b_pic_gc
);
577 Rect
BScreen::availableArea() const {
578 // the following code is temporary and will be taken care of by Screen in the
579 // future (with the NETWM 'strut')
580 Rect
space(0, 0, size().w(), size().h());
581 if (!resource
.full_max
) {
583 int slit_x
= slit
->autoHide() ? slit
->hiddenOrigin().x() : slit
->area().x(),
584 slit_y
= slit
->autoHide() ? slit
->hiddenOrigin().y() : slit
->area().y();
585 int tbarh
= resource
.hide_toolbar
? 0 :
586 toolbar
->getExposedHeight() + resource
.border_width
* 2;
588 switch (toolbar
->placement()) {
589 case Toolbar::TopLeft
:
590 case Toolbar::TopCenter
:
591 case Toolbar::TopRight
:
594 case Toolbar::BottomLeft
:
595 case Toolbar::BottomCenter
:
596 case Toolbar::BottomRight
:
600 ASSERT(false); // unhandled placement
602 if ((slit
->direction() == Slit::Horizontal
&&
603 (slit
->placement() == Slit::TopLeft
||
604 slit
->placement() == Slit::TopRight
)) ||
605 slit
->placement() == Slit::TopCenter
) {
607 if (tbartop
&& slit_y
+ slit
->area().h() < tbarh
) {
608 space
.setY(space
.y() + tbarh
);
609 space
.setH(space
.h() - tbarh
);
611 space
.setY(space
.y() + (slit_y
+ slit
->area().h() +
612 resource
.border_width
* 2));
613 space
.setH(space
.h() - (slit_y
+ slit
->area().h() +
614 resource
.border_width
* 2));
616 space
.setH(space
.h() - tbarh
);
618 } else if ((slit
->direction() == Slit::Vertical
&&
619 (slit
->placement() == Slit::TopRight
||
620 slit
->placement() == Slit::BottomRight
)) ||
621 slit
->placement() == Slit::CenterRight
) {
623 space
.setW(space
.w() - (size().w() - slit_x
));
625 space
.setY(space
.y() + tbarh
);
626 space
.setH(space
.h() - tbarh
);
627 } else if ((slit
->direction() == Slit::Horizontal
&&
628 (slit
->placement() == Slit::BottomLeft
||
629 slit
->placement() == Slit::BottomRight
)) ||
630 slit
->placement() == Slit::BottomCenter
) {
632 if (!tbartop
&& (size().h() - slit_y
) < tbarh
) {
633 space
.setH(space
.h() - tbarh
);
635 space
.setH(space
.h() - (size().h() - slit_y
));
637 space
.setY(space
.y() + tbarh
);
638 space
.setH(space
.h() - tbarh
);
641 } else {// if ((slit->direction() == Slit::Vertical &&
642 // (slit->placement() == Slit::TopLeft ||
643 // slit->placement() == Slit::BottomLeft)) ||
644 // slit->placement() == Slit::CenterLeft)
646 space
.setX(slit_x
+ slit
->area().w() +
647 resource
.border_width
* 2);
648 space
.setW(space
.w() - (slit_x
+ slit
->area().w() +
649 resource
.border_width
* 2));
651 space
.setY(space
.y() + tbarh
);
652 space
.setH(space
.h() - tbarh
);
655 int tbarh
= resource
.hide_toolbar() ? 0 :
656 toolbar
->getExposedHeight() + resource
.border_width
* 2;
657 switch (toolbar
->placement()) {
658 case Toolbar::TopLeft
:
659 case Toolbar::TopCenter
:
660 case Toolbar::TopRight
:
661 space
.setY(toolbar
->getExposedHeight());
662 space
.setH(space
.h() - toolbar
->getExposedHeight());
664 case Toolbar::BottomLeft
:
665 case Toolbar::BottomCenter
:
666 case Toolbar::BottomRight
:
667 space
.setH(space
.h() - tbarh
);
670 ASSERT(false); // unhandled placement
678 void BScreen::readDatabaseTexture(const char *rname
, const char *rclass
,
680 unsigned long default_pixel
)
684 if (resource
.styleconfig
.getValue(rname
, rclass
, s
))
685 image_control
->parseTexture(texture
, s
.c_str());
687 texture
->setTexture(BImage_Solid
| BImage_Flat
);
689 if (texture
->getTexture() & BImage_Solid
) {
690 int clen
= strlen(rclass
) + 32, nlen
= strlen(rname
) + 32;
692 char *colorclass
= new char[clen
], *colorname
= new char[nlen
];
694 sprintf(colorclass
, "%s.Color", rclass
);
695 sprintf(colorname
, "%s.color", rname
);
697 readDatabaseColor(colorname
, colorclass
, texture
->getColor(),
701 sprintf(colorclass
, "%s.ColorTo", rclass
);
702 sprintf(colorname
, "%s.colorTo", rname
);
704 readDatabaseColor(colorname
, colorclass
, texture
->getColorTo(),
708 delete [] colorclass
;
711 if ((! texture
->getColor()->isAllocated()) ||
712 (texture
->getTexture() & BImage_Flat
))
717 xcol
.red
= (unsigned int) (texture
->getColor()->getRed() +
718 (texture
->getColor()->getRed() >> 1));
719 if (xcol
.red
>= 0xff) xcol
.red
= 0xffff;
720 else xcol
.red
*= 0xff;
721 xcol
.green
= (unsigned int) (texture
->getColor()->getGreen() +
722 (texture
->getColor()->getGreen() >> 1));
723 if (xcol
.green
>= 0xff) xcol
.green
= 0xffff;
724 else xcol
.green
*= 0xff;
725 xcol
.blue
= (unsigned int) (texture
->getColor()->getBlue() +
726 (texture
->getColor()->getBlue() >> 1));
727 if (xcol
.blue
>= 0xff) xcol
.blue
= 0xffff;
728 else xcol
.blue
*= 0xff;
730 if (! XAllocColor(getBaseDisplay().getXDisplay(),
731 getColormap(), &xcol
))
734 texture
->getHiColor()->setPixel(xcol
.pixel
);
737 (unsigned int) ((texture
->getColor()->getRed() >> 2) +
738 (texture
->getColor()->getRed() >> 1)) * 0xff;
740 (unsigned int) ((texture
->getColor()->getGreen() >> 2) +
741 (texture
->getColor()->getGreen() >> 1)) * 0xff;
743 (unsigned int) ((texture
->getColor()->getBlue() >> 2) +
744 (texture
->getColor()->getBlue() >> 1)) * 0xff;
746 if (! XAllocColor(getBaseDisplay().getXDisplay(),
747 getColormap(), &xcol
))
750 texture
->getLoColor()->setPixel(xcol
.pixel
);
751 } else if (texture
->getTexture() & BImage_Gradient
) {
752 int clen
= strlen(rclass
) + 10, nlen
= strlen(rname
) + 10;
754 char *colorclass
= new char[clen
], *colorname
= new char[nlen
],
755 *colortoclass
= new char[clen
], *colortoname
= new char[nlen
];
757 sprintf(colorclass
, "%s.Color", rclass
);
758 sprintf(colorname
, "%s.color", rname
);
760 sprintf(colortoclass
, "%s.ColorTo", rclass
);
761 sprintf(colortoname
, "%s.colorTo", rname
);
763 readDatabaseColor(colorname
, colorclass
, texture
->getColor(),
765 readDatabaseColor(colortoname
, colortoclass
, texture
->getColorTo(),
768 delete [] colorclass
;
770 delete [] colortoclass
;
771 delete [] colortoname
;
776 void BScreen::readDatabaseColor(const char *rname
, const char *rclass
,
777 BColor
*color
, unsigned long default_pixel
)
781 if (resource
.styleconfig
.getValue(rname
, rclass
, s
))
782 image_control
->parseColor(color
, s
.c_str());
784 // parsing with no color std::string just deallocates the color, if it has
785 // been previously allocated
786 image_control
->parseColor(color
);
787 color
->setPixel(default_pixel
);
792 void BScreen::readDatabaseFontSet(const char *rname
, const char *rclass
,
794 if (! fontset
) return;
796 static char *defaultFont
= "fixed";
797 bool load_default
= false;
801 XFreeFontSet(getBaseDisplay().getXDisplay(), *fontset
);
803 if (resource
.styleconfig
.getValue(rname
, rclass
, s
)) {
804 if (! (*fontset
= createFontSet(s
.c_str())))
810 *fontset
= createFontSet(defaultFont
);
813 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenDefaultFontLoadFail
,
814 "BScreen::LoadStyle(): couldn't load default font.\n"));
821 void BScreen::readDatabaseFont(const char *rname
, const char *rclass
,
822 XFontStruct
**font
) {
825 static char *defaultFont
= "fixed";
826 bool load_default
= false;
830 XFreeFont(getBaseDisplay().getXDisplay(), *font
);
832 if (resource
.styleconfig
.getValue(rname
, rclass
, s
)) {
833 if ((*font
= XLoadQueryFont(getBaseDisplay().getXDisplay(),
834 s
.c_str())) == NULL
) {
835 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenFontLoadFail
,
836 "BScreen::LoadStyle(): couldn't load font '%s'\n"),
844 if ((*font
= XLoadQueryFont(getBaseDisplay().getXDisplay(),
845 defaultFont
)) == NULL
) {
846 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenDefaultFontLoadFail
,
847 "BScreen::LoadStyle(): couldn't load default font.\n"));
854 XFontSet
BScreen::createFontSet(const char *fontname
) {
856 char **missing
, *def
= "-";
857 int nmissing
, pixel_size
= 0, buf_size
= 0;
858 char weight
[FONT_ELEMENT_SIZE
], slant
[FONT_ELEMENT_SIZE
];
860 fs
= XCreateFontSet(getBaseDisplay().getXDisplay(),
861 fontname
, &missing
, &nmissing
, &def
);
862 if (fs
&& (! nmissing
)) return fs
;
864 #ifdef HAVE_SETLOCALE
866 if (nmissing
) XFreeStringList(missing
);
868 setlocale(LC_CTYPE
, "C");
869 fs
= XCreateFontSet(getBaseDisplay().getXDisplay(), fontname
,
870 &missing
, &nmissing
, &def
);
871 setlocale(LC_CTYPE
, "");
873 #endif // HAVE_SETLOCALE
876 XFontStruct
**fontstructs
;
878 XFontsOfFontSet(fs
, &fontstructs
, &fontnames
);
879 fontname
= fontnames
[0];
882 getFontElement(fontname
, weight
, FONT_ELEMENT_SIZE
,
883 "-medium-", "-bold-", "-demibold-", "-regular-", NULL
);
884 getFontElement(fontname
, slant
, FONT_ELEMENT_SIZE
,
885 "-r-", "-i-", "-o-", "-ri-", "-ro-", NULL
);
886 getFontSize(fontname
, &pixel_size
);
888 if (! strcmp(weight
, "*")) strncpy(weight
, "medium", FONT_ELEMENT_SIZE
);
889 if (! strcmp(slant
, "*")) strncpy(slant
, "r", FONT_ELEMENT_SIZE
);
890 if (pixel_size
< 3) pixel_size
= 3;
891 else if (pixel_size
> 97) pixel_size
= 97;
893 buf_size
= strlen(fontname
) + (FONT_ELEMENT_SIZE
* 2) + 64;
894 char *pattern2
= new char[buf_size
];
895 snprintf(pattern2
, buf_size
- 1,
897 "-*-*-%s-%s-*-*-%d-*-*-*-*-*-*-*,"
898 "-*-*-*-*-*-*-%d-*-*-*-*-*-*-*,*",
899 fontname
, weight
, slant
, pixel_size
, pixel_size
);
902 if (nmissing
) XFreeStringList(missing
);
903 if (fs
) XFreeFontSet(getBaseDisplay().getXDisplay(), fs
);
905 fs
= XCreateFontSet(getBaseDisplay().getXDisplay(), fontname
,
906 &missing
, &nmissing
, &def
);
913 void BScreen::setSloppyFocus(bool b
) {
914 resource
.sloppy_focus
= b
;
916 s
<< "session.screen" << getScreenNumber() << ".focusModel" << ends
;
917 config
.setValue(s
.str(),
918 (resource
.sloppy_focus
?
919 (resource
.auto_raise
? "AutoRaiseSloppyFocus" : "SloppyFocus")
921 s
.rdbuf()->freeze(0);
925 void BScreen::setAutoRaise(bool a
) {
926 resource
.auto_raise
= a
;
928 s
<< "session.screen" << getScreenNumber() << ".focusModel" << ends
;
929 config
.setValue(s
.str(),
930 (resource
.sloppy_focus
?
931 (resource
.auto_raise
? "AutoRaiseSloppyFocus" : "SloppyFocus")
933 s
.rdbuf()->freeze(0);
937 void BScreen::setImageDither(bool d
, bool reconfig
) {
938 image_control
->setDither(d
);
940 s
<< "session.screen" << getScreenNumber() << ".imageDither" << ends
;
941 config
.setValue(s
.str(), imageDither());
944 s
.rdbuf()->freeze(0);
948 void BScreen::setOpaqueMove(bool o
) {
949 resource
.opaque_move
= o
;
951 s
<< "session.screen" << getScreenNumber() << ".opaqueMove" << ends
;
952 config
.setValue(s
.str(), resource
.opaque_move
);
953 s
.rdbuf()->freeze(0);
957 void BScreen::setFullMax(bool f
) {
958 resource
.full_max
= f
;
960 s
<< "session.screen" << getScreenNumber() << ".fullMaximization" << ends
;
961 config
.setValue(s
.str(), resource
.full_max
);
962 s
.rdbuf()->freeze(0);
966 void BScreen::setFocusNew(bool f
) {
967 resource
.focus_new
= f
;
969 s
<< "session.screen" << getScreenNumber() << ".focusNewWindows" << ends
;
970 config
.setValue(s
.str(), resource
.focus_new
);
971 s
.rdbuf()->freeze(0);
975 void BScreen::setFocusLast(bool f
) {
976 resource
.focus_last
= f
;
978 s
<< "session.screen" << getScreenNumber() << ".focusLastWindow" << ends
;
979 config
.setValue(s
.str(), resource
.focus_last
);
980 s
.rdbuf()->freeze(0);
984 void BScreen::setWindowZones(int z
) {
987 s
<< "session.screen" << getScreenNumber() << ".windowZones" << ends
;
988 config
.setValue(s
.str(), resource
.zones
);
989 s
.rdbuf()->freeze(0);
993 void BScreen::setWorkspaceCount(int w
) {
994 resource
.workspaces
= w
;
996 s
<< "session.screen" << getScreenNumber() << ".workspaces" << ends
;
997 config
.setValue(s
.str(), resource
.workspaces
);
998 s
.rdbuf()->freeze(0);
1002 void BScreen::setPlacementPolicy(int p
) {
1003 resource
.placement_policy
= p
;
1005 s
<< "session.screen" << getScreenNumber() << ".windowPlacement" << ends
;
1006 const char *placement
;
1007 switch (resource
.placement_policy
) {
1008 case CascadePlacement
: placement
= "CascadePlacement"; break;
1009 case BestFitPlacement
: placement
= "BestFitPlacement"; break;
1010 case ColSmartPlacement
: placement
= "ColSmartPlacement"; break;
1011 case UnderMousePlacement
: placement
= "UnderMousePlacement"; break;
1012 case ClickMousePlacement
: placement
= "ClickMousePlacement"; break;
1014 case RowSmartPlacement
: placement
= "RowSmartPlacement"; break;
1016 config
.setValue(s
.str(), placement
);
1017 s
.rdbuf()->freeze(0);
1021 void BScreen::setEdgeSnapThreshold(int t
) {
1022 resource
.edge_snap_threshold
= t
;
1024 s
<< "session.screen" << getScreenNumber() << ".edgeSnapThreshold" << ends
;
1025 config
.setValue(s
.str(), resource
.edge_snap_threshold
);
1026 s
.rdbuf()->freeze(0);
1030 void BScreen::setRowPlacementDirection(int d
) {
1031 resource
.row_direction
= d
;
1033 s
<< "session.screen" << getScreenNumber() << ".rowPlacementDirection" << ends
;
1034 config
.setValue(s
.str(),
1035 resource
.row_direction
== LeftRight
?
1036 "LeftToRight" : "RightToLeft");
1037 s
.rdbuf()->freeze(0);
1041 void BScreen::setColPlacementDirection(int d
) {
1042 resource
.col_direction
= d
;
1044 s
<< "session.screen" << getScreenNumber() << ".colPlacementDirection" << ends
;
1045 config
.setValue(s
.str(),
1046 resource
.col_direction
== TopBottom
?
1047 "TopToBottom" : "BottomToTop");
1048 s
.rdbuf()->freeze(0);
1052 void BScreen::setRootCommand(const char *cmd
) {
1053 if (resource
.root_command
!= NULL
)
1054 delete [] resource
.root_command
;
1056 resource
.root_command
= bstrdup(cmd
);
1058 resource
.root_command
= NULL
;
1059 // this doesn't save to the Resources config because it can't be changed
1060 // inside Openbox, and this way we dont add an empty command which would over-
1061 // ride the styles command when none has been specified
1065 #ifdef HAVE_STRFTIME
1066 void BScreen::setStrftimeFormat(const char *f
) {
1067 if (resource
.strftime_format
!= NULL
)
1068 delete [] resource
.strftime_format
;
1070 resource
.strftime_format
= bstrdup(f
);
1072 s
<< "session.screen" << getScreenNumber() << ".strftimeFormat" << ends
;
1073 config
.setValue(s
.str(), resource
.strftime_format
);
1074 s
.rdbuf()->freeze(0);
1077 #else // !HAVE_STRFTIME
1079 void BScreen::setDateFormat(int f
) {
1080 resource
.date_format
= f
;
1082 s
<< "session.screen" << getScreenNumber() << ".dateFormat" << ends
;
1083 config
.setValue(s
.str(), resource
.date_format
== B_EuropeanDate
?
1084 "European" : "American");
1085 s
.rdbuf()->freeze(0);
1089 void BScreen::setClock24Hour(Bool c
) {
1090 resource
.clock24hour
= c
;
1092 s
<< "session.screen" << getScreenNumber() << ".clockFormat" << ends
;
1093 config
.setValue(s
.str(), resource
.clock24hour
? 24 : 12);
1094 s
.rdbuf()->freeze(0);
1096 #endif // HAVE_STRFTIME
1099 void BScreen::setHideToolbar(bool b
) {
1100 resource
.hide_toolbar
= b
;
1101 if (resource
.hide_toolbar
)
1102 getToolbar()->unMapToolbar();
1104 getToolbar()->mapToolbar();
1106 s
<< "session.screen" << getScreenNumber() << ".hideToolbar" << ends
;
1107 config
.setValue(s
.str(), resource
.hide_toolbar
? "True" : "False");
1108 s
.rdbuf()->freeze(0);
1112 void BScreen::saveWorkspaceNames() {
1113 std::ostrstream rc
, names
;
1115 wkspList::iterator it
;
1116 wkspList::iterator last
= workspacesList
.end() - 1;
1117 for (it
= workspacesList
.begin(); it
!= workspacesList
.end(); ++it
) {
1118 names
<< (*it
)->getName();
1124 rc
<< "session.screen" << getScreenNumber() << ".workspaceNames" << ends
;
1125 config
.setValue(rc
.str(), names
.str());
1126 rc
.rdbuf()->freeze(0);
1127 names
.rdbuf()->freeze(0);
1130 void BScreen::save() {
1131 setSloppyFocus(resource
.sloppy_focus
);
1132 setAutoRaise(resource
.auto_raise
);
1133 setImageDither(imageDither(), false);
1134 setOpaqueMove(resource
.opaque_move
);
1135 setFullMax(resource
.full_max
);
1136 setFocusNew(resource
.focus_new
);
1137 setFocusLast(resource
.focus_last
);
1138 setWindowZones(resource
.zones
);
1139 setWorkspaceCount(resource
.workspaces
);
1140 setPlacementPolicy(resource
.placement_policy
);
1141 setEdgeSnapThreshold(resource
.edge_snap_threshold
);
1142 setRowPlacementDirection(resource
.row_direction
);
1143 setColPlacementDirection(resource
.col_direction
);
1144 setRootCommand(resource
.root_command
);
1145 #ifdef HAVE_STRFTIME
1146 // it deletes the current value before setting the new one, so we have to
1147 // duplicate the current value.
1148 std::string s
= resource
.strftime_format
;
1149 setStrftimeFormat(s
.c_str());
1150 #else // !HAVE_STRFTIME
1151 setDateFormat(resource
.date_format
);
1152 setClock24Hour(resource
.clock24hour
);
1153 #endif // HAVE_STRFTIME
1154 setHideToolbar(resource
.hide_toolbar
);
1163 void BScreen::load() {
1164 std::ostrstream rscreen
, rname
, rclass
;
1168 rscreen
<< "session.screen" << getScreenNumber() << '.' << ends
;
1170 rname
<< rscreen
.str() << "hideToolbar" << ends
;
1171 rclass
<< rscreen
.str() << "HideToolbar" << ends
;
1172 if (config
.getValue(rname
.str(), rclass
.str(), b
))
1173 resource
.hide_toolbar
= b
;
1175 resource
.hide_toolbar
= false;
1176 Toolbar
*t
= getToolbar();
1178 if (resource
.hide_toolbar
)
1184 rname
.seekp(0); rclass
.seekp(0);
1185 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1186 rname
<< rscreen
.str() << "fullMaximization" << ends
;
1187 rclass
<< rscreen
.str() << "FullMaximization" << ends
;
1188 if (config
.getValue(rname
.str(), rclass
.str(), b
))
1189 resource
.full_max
= b
;
1191 resource
.full_max
= false;
1193 rname
.seekp(0); rclass
.seekp(0);
1194 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1195 rname
<< rscreen
.str() << "focusNewWindows" << ends
;
1196 rclass
<< rscreen
.str() << "FocusNewWindows" << ends
;
1197 if (config
.getValue(rname
.str(), rclass
.str(), b
))
1198 resource
.focus_new
= b
;
1200 resource
.focus_new
= false;
1202 rname
.seekp(0); rclass
.seekp(0);
1203 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1204 rname
<< rscreen
.str() << "focusLastWindow" << ends
;
1205 rclass
<< rscreen
.str() << "FocusLastWindow" << ends
;
1206 if (config
.getValue(rname
.str(), rclass
.str(), b
))
1207 resource
.focus_last
= b
;
1209 resource
.focus_last
= false;
1211 rname
.seekp(0); rclass
.seekp(0);
1212 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1213 rname
<< rscreen
.str() << "rowPlacementDirection" << ends
;
1214 rclass
<< rscreen
.str() << "RowPlacementDirection" << ends
;
1215 if (config
.getValue(rname
.str(), rclass
.str(), s
)) {
1216 if (0 == strncasecmp(s
.c_str(), "RightToLeft", s
.length()))
1217 resource
.row_direction
= RightLeft
;
1218 else //if (0 == strncasecmp(s.c_str(), "LeftToRight", s.length()))
1219 resource
.row_direction
= LeftRight
;
1221 resource
.row_direction
= LeftRight
;
1223 rname
.seekp(0); rclass
.seekp(0);
1224 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1225 rname
<< rscreen
.str() << "colPlacementDirection" << ends
;
1226 rclass
<< rscreen
.str() << "ColPlacementDirection" << ends
;
1227 if (config
.getValue(rname
.str(), rclass
.str(), s
)) {
1228 if (0 == strncasecmp(s
.c_str(), "BottomToTop", s
.length()))
1229 resource
.col_direction
= BottomTop
;
1230 else //if (0 == strncasecmp(s.c_str(), "TopToBottom", s.length()))
1231 resource
.col_direction
= TopBottom
;
1233 resource
.col_direction
= TopBottom
;
1235 rname
.seekp(0); rclass
.seekp(0);
1236 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1237 rname
<< rscreen
.str() << "workspaces" << ends
;
1238 rclass
<< rscreen
.str() << "Workspaces" << ends
;
1239 if (config
.getValue(rname
.str(), rclass
.str(), l
)) {
1240 resource
.workspaces
= l
;
1242 resource
.workspaces
= 1;
1244 removeWorkspaceNames();
1245 rname
.seekp(0); rclass
.seekp(0);
1246 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1247 rname
<< rscreen
.str() << "workspaceNames" << ends
;
1248 rclass
<< rscreen
.str() << "WorkspaceNames" << ends
;
1249 if (config
.getValue(rname
.str(), rclass
.str(), s
)) {
1250 std::string::const_iterator it
= s
.begin(), end
= s
.end();
1252 std::string::const_iterator tmp
= it
;// current string.begin()
1253 it
= std::find(tmp
, end
, ','); // look for comma between tmp and end
1254 std::string
name(tmp
, it
); // name = s[tmp:it]
1255 addWorkspaceName(name
.c_str());
1262 rname
.seekp(0); rclass
.seekp(0);
1263 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1264 rname
<< rscreen
.str() << "focusModel" << ends
;
1265 rclass
<< rscreen
.str() << "FocusModel" << ends
;
1266 if (config
.getValue(rname
.str(), rclass
.str(), s
)) {
1267 if (0 == strncasecmp(s
.c_str(), "ClickToFocus", s
.length())) {
1268 resource
.auto_raise
= false;
1269 resource
.sloppy_focus
= false;
1270 } else if (0 == strncasecmp(s
.c_str(), "AutoRaiseSloppyFocus",
1272 resource
.sloppy_focus
= true;
1273 resource
.auto_raise
= true;
1274 } else { //if (0 == strncasecmp(s.c_str(), "SloppyFocus", s.length())) {
1275 resource
.sloppy_focus
= true;
1276 resource
.auto_raise
= false;
1279 resource
.sloppy_focus
= true;
1280 resource
.auto_raise
= false;
1283 rname
.seekp(0); rclass
.seekp(0);
1284 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1285 rname
<< rscreen
.str() << "windowZones" << ends
;
1286 rclass
<< rscreen
.str() << "WindowZones" << ends
;
1287 if (config
.getValue(rname
.str(), rclass
.str(), l
))
1288 resource
.zones
= (l
== 1 || l
== 2 || l
== 4) ? l
: 1;
1292 rname
.seekp(0); rclass
.seekp(0);
1293 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1294 rname
<< rscreen
.str() << "windowPlacement" << ends
;
1295 rclass
<< rscreen
.str() << "WindowPlacement" << ends
;
1296 if (config
.getValue(rname
.str(), rclass
.str(), s
)) {
1297 if (0 == strncasecmp(s
.c_str(), "RowSmartPlacement", s
.length()))
1298 resource
.placement_policy
= RowSmartPlacement
;
1299 else if (0 == strncasecmp(s
.c_str(), "ColSmartPlacement", s
.length()))
1300 resource
.placement_policy
= ColSmartPlacement
;
1301 else if (0 == strncasecmp(s
.c_str(), "BestFitPlacement", s
.length()))
1302 resource
.placement_policy
= BestFitPlacement
;
1303 else if (0 == strncasecmp(s
.c_str(), "UnderMousePlacement", s
.length()))
1304 resource
.placement_policy
= UnderMousePlacement
;
1305 else if (0 == strncasecmp(s
.c_str(), "ClickMousePlacement", s
.length()))
1306 resource
.placement_policy
= ClickMousePlacement
;
1307 else //if (0 == strncasecmp(s.c_str(), "CascadePlacement", s.length()))
1308 resource
.placement_policy
= CascadePlacement
;
1310 resource
.placement_policy
= CascadePlacement
;
1312 #ifdef HAVE_STRFTIME
1313 rname
.seekp(0); rclass
.seekp(0);
1314 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(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
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1328 rname
<< rscreen
.str() << "dateFormat" << ends
;
1329 rclass
<< rscreen
.str() << "DateFormat" << ends
;
1330 if (config
.getValue(rname
.str(), rclass
.str(), s
)) {
1331 if (strncasecmp(s
.c_str(), "European", s
.length()))
1332 resource
.date_format
= B_EuropeanDate
;
1333 else //if (strncasecmp(s.c_str(), "American", s.length()))
1334 resource
.date_format
= B_AmericanDate
;
1336 resource
.date_format
= B_AmericanDate
;
1338 rname
.seekp(0); rclass
.seekp(0);
1339 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1340 rname
<< rscreen
.str() << "clockFormat" << ends
;
1341 rclass
<< rscreen
.str() << "ClockFormat" << ends
;
1342 if (config
.getValue(rname
.str(), rclass
.str(), l
)) {
1344 resource
.clock24hour
= true;
1345 else if (clock
== 12)
1346 resource
.clock24hour
= false;
1348 resource
.clock24hour
= false;
1349 #endif // HAVE_STRFTIME
1351 rname
.seekp(0); rclass
.seekp(0);
1352 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1353 rname
<< rscreen
.str() << "edgeSnapThreshold" << ends
;
1354 rclass
<< rscreen
.str() << "EdgeSnapThreshold" << ends
;
1355 if (config
.getValue(rname
.str(), rclass
.str(), l
))
1356 resource
.edge_snap_threshold
= l
;
1358 resource
.edge_snap_threshold
= 4;
1360 rname
.seekp(0); rclass
.seekp(0);
1361 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1362 rname
<< rscreen
.str() << "imageDither" << ends
;
1363 rclass
<< rscreen
.str() << "ImageDither" << ends
;
1364 if (config
.getValue(rname
.str(), rclass
.str(), b
))
1365 image_control
->setDither(b
);
1367 image_control
->setDither(true);
1369 rname
.seekp(0); rclass
.seekp(0);
1370 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1371 rname
<< rscreen
.str() << "rootCommand" << ends
;
1372 rclass
<< rscreen
.str() << "RootCommand" << ends
;
1374 if (resource
.root_command
!= NULL
)
1375 delete [] resource
.root_command
;
1377 if (config
.getValue(rname
.str(), rclass
.str(), s
))
1378 resource
.root_command
= bstrdup(s
.c_str());
1380 resource
.root_command
= NULL
;
1382 rname
.seekp(0); rclass
.seekp(0);
1383 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1384 rname
<< rscreen
.str() << "opaqueMove" << ends
;
1385 rclass
<< rscreen
.str() << "OpaqueMove" << ends
;
1386 if (config
.getValue(rname
.str(), rclass
.str(), b
))
1387 resource
.opaque_move
= b
;
1389 resource
.opaque_move
= false;
1391 rscreen
.rdbuf()->freeze(0);
1392 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1395 void BScreen::reconfigure(void) {
1404 unsigned long gc_value_mask
= GCForeground
;
1405 if (! i18n
->multibyte()) gc_value_mask
|= GCFont
;
1407 gcv
.foreground
= WhitePixel(getBaseDisplay().getXDisplay(),
1409 gcv
.function
= GXinvert
;
1410 gcv
.subwindow_mode
= IncludeInferiors
;
1411 XChangeGC(getBaseDisplay().getXDisplay(), opGC
,
1412 GCForeground
| GCFunction
| GCSubwindowMode
, &gcv
);
1414 gcv
.foreground
= resource
.wstyle
.l_text_focus
.getPixel();
1415 if (resource
.wstyle
.font
)
1416 gcv
.font
= resource
.wstyle
.font
->fid
;
1417 XChangeGC(getBaseDisplay().getXDisplay(), resource
.wstyle
.l_text_focus_gc
,
1418 gc_value_mask
, &gcv
);
1420 gcv
.foreground
= resource
.wstyle
.l_text_unfocus
.getPixel();
1421 XChangeGC(getBaseDisplay().getXDisplay(), resource
.wstyle
.l_text_unfocus_gc
,
1422 gc_value_mask
, &gcv
);
1424 gcv
.foreground
= resource
.wstyle
.b_pic_focus
.getPixel();
1425 XChangeGC(getBaseDisplay().getXDisplay(), resource
.wstyle
.b_pic_focus_gc
,
1426 GCForeground
, &gcv
);
1428 gcv
.foreground
= resource
.wstyle
.b_pic_unfocus
.getPixel();
1429 XChangeGC(getBaseDisplay().getXDisplay(), resource
.wstyle
.b_pic_unfocus_gc
,
1430 GCForeground
, &gcv
);
1432 gcv
.foreground
= resource
.mstyle
.t_text
.getPixel();
1433 if (resource
.mstyle
.t_font
)
1434 gcv
.font
= resource
.mstyle
.t_font
->fid
;
1435 XChangeGC(getBaseDisplay().getXDisplay(), resource
.mstyle
.t_text_gc
,
1436 gc_value_mask
, &gcv
);
1438 gcv
.foreground
= resource
.mstyle
.f_text
.getPixel();
1439 if (resource
.mstyle
.f_font
)
1440 gcv
.font
= resource
.mstyle
.f_font
->fid
;
1441 XChangeGC(getBaseDisplay().getXDisplay(), resource
.mstyle
.f_text_gc
,
1442 gc_value_mask
, &gcv
);
1444 gcv
.foreground
= resource
.mstyle
.h_text
.getPixel();
1445 XChangeGC(getBaseDisplay().getXDisplay(), resource
.mstyle
.h_text_gc
,
1446 gc_value_mask
, &gcv
);
1448 gcv
.foreground
= resource
.mstyle
.d_text
.getPixel();
1449 XChangeGC(getBaseDisplay().getXDisplay(), resource
.mstyle
.d_text_gc
,
1450 gc_value_mask
, &gcv
);
1452 gcv
.foreground
= resource
.mstyle
.hilite
.getColor()->getPixel();
1453 XChangeGC(getBaseDisplay().getXDisplay(), resource
.mstyle
.hilite_gc
,
1454 gc_value_mask
, &gcv
);
1456 gcv
.foreground
= resource
.tstyle
.l_text
.getPixel();
1457 if (resource
.tstyle
.font
)
1458 gcv
.font
= resource
.tstyle
.font
->fid
;
1459 XChangeGC(getBaseDisplay().getXDisplay(), resource
.tstyle
.l_text_gc
,
1460 gc_value_mask
, &gcv
);
1462 gcv
.foreground
= resource
.tstyle
.w_text
.getPixel();
1463 XChangeGC(getBaseDisplay().getXDisplay(), resource
.tstyle
.w_text_gc
,
1464 gc_value_mask
, &gcv
);
1466 gcv
.foreground
= resource
.tstyle
.c_text
.getPixel();
1467 XChangeGC(getBaseDisplay().getXDisplay(), resource
.tstyle
.c_text_gc
,
1468 gc_value_mask
, &gcv
);
1470 gcv
.foreground
= resource
.tstyle
.b_pic
.getPixel();
1471 XChangeGC(getBaseDisplay().getXDisplay(), resource
.tstyle
.b_pic_gc
,
1472 gc_value_mask
, &gcv
);
1474 const char *s
= i18n
->getMessage(ScreenSet
, ScreenPositionLength
,
1475 "0: 0000 x 0: 0000");
1478 if (i18n
->multibyte()) {
1479 XRectangle ink
, logical
;
1480 XmbTextExtents(resource
.wstyle
.fontset
, s
, l
, &ink
, &logical
);
1481 geom_w
= logical
.width
;
1483 geom_h
= resource
.wstyle
.fontset_extents
->max_ink_extent
.height
;
1485 geom_w
= XTextWidth(resource
.wstyle
.font
, s
, l
);
1487 geom_h
= resource
.wstyle
.font
->ascent
+
1488 resource
.wstyle
.font
->descent
;
1491 geom_w
+= (resource
.bevel_width
* 2);
1492 geom_h
+= (resource
.bevel_width
* 2);
1494 Pixmap tmp
= geom_pixmap
;
1495 if (resource
.wstyle
.l_focus
.getTexture() & BImage_ParentRelative
) {
1496 if (resource
.wstyle
.t_focus
.getTexture() ==
1497 (BImage_Flat
| BImage_Solid
)) {
1499 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window
,
1500 resource
.wstyle
.t_focus
.getColor()->getPixel());
1502 geom_pixmap
= image_control
->renderImage(geom_w
, geom_h
,
1503 &resource
.wstyle
.t_focus
);
1504 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
1505 geom_window
, geom_pixmap
);
1508 if (resource
.wstyle
.l_focus
.getTexture() ==
1509 (BImage_Flat
| BImage_Solid
)) {
1511 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window
,
1512 resource
.wstyle
.l_focus
.getColor()->getPixel());
1514 geom_pixmap
= image_control
->renderImage(geom_w
, geom_h
,
1515 &resource
.wstyle
.l_focus
);
1516 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
1517 geom_window
, geom_pixmap
);
1520 if (tmp
) image_control
->removeImage(tmp
);
1522 XSetWindowBorderWidth(getBaseDisplay().getXDisplay(), geom_window
,
1523 resource
.border_width
);
1524 XSetWindowBorder(getBaseDisplay().getXDisplay(), geom_window
,
1525 resource
.border_color
.getPixel());
1527 workspacemenu
->reconfigure();
1528 iconmenu
->reconfigure();
1531 int remember_sub
= rootmenu
->getCurrentSubmenu();
1534 rootmenu
->reconfigure();
1535 rootmenu
->drawSubmenu(remember_sub
);
1538 configmenu
->reconfigure();
1540 toolbar
->reconfigure();
1543 slit
->reconfigure();
1546 std::for_each(workspacesList
.begin(), workspacesList
.end(),
1547 std::mem_fun(&Workspace::reconfigure
));
1549 for (winList::iterator it
= iconList
.begin(); it
!= iconList
.end(); ++it
)
1550 if ((*it
)->validateClient())
1551 (*it
)->reconfigure();
1553 image_control
->timeout();
1557 void BScreen::rereadMenu(void) {
1561 rootmenu
->reconfigure();
1565 void BScreen::removeWorkspaceNames(void) {
1566 workspaceNames
.clear();
1570 void BScreen::LoadStyle(void) {
1571 Resource
&conf
= resource
.styleconfig
;
1573 const char *sfile
= openbox
.getStyleFilename();
1574 bool loaded
= false;
1575 if (sfile
!= NULL
) {
1576 conf
.setFile(sfile
);
1577 loaded
= conf
.load();
1580 conf
.setFile(DEFAULTSTYLE
);
1582 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenDefaultStyleLoadFail
,
1583 "BScreen::LoadStyle(): couldn't load "
1584 "default style.\n"));
1592 // load fonts/fontsets
1594 if (i18n
->multibyte()) {
1595 readDatabaseFontSet("window.font", "Window.Font",
1596 &resource
.wstyle
.fontset
);
1597 readDatabaseFontSet("toolbar.font", "Toolbar.Font",
1598 &resource
.tstyle
.fontset
);
1599 readDatabaseFontSet("menu.title.font", "Menu.Title.Font",
1600 &resource
.mstyle
.t_fontset
);
1601 readDatabaseFontSet("menu.frame.font", "Menu.Frame.Font",
1602 &resource
.mstyle
.f_fontset
);
1604 resource
.mstyle
.t_fontset_extents
=
1605 XExtentsOfFontSet(resource
.mstyle
.t_fontset
);
1606 resource
.mstyle
.f_fontset_extents
=
1607 XExtentsOfFontSet(resource
.mstyle
.f_fontset
);
1608 resource
.tstyle
.fontset_extents
=
1609 XExtentsOfFontSet(resource
.tstyle
.fontset
);
1610 resource
.wstyle
.fontset_extents
=
1611 XExtentsOfFontSet(resource
.wstyle
.fontset
);
1613 readDatabaseFont("window.font", "Window.Font",
1614 &resource
.wstyle
.font
);
1615 readDatabaseFont("menu.title.font", "Menu.Title.Font",
1616 &resource
.mstyle
.t_font
);
1617 readDatabaseFont("menu.frame.font", "Menu.Frame.Font",
1618 &resource
.mstyle
.f_font
);
1619 readDatabaseFont("toolbar.font", "Toolbar.Font",
1620 &resource
.tstyle
.font
);
1623 // load window config
1624 readDatabaseTexture("window.title.focus", "Window.Title.Focus",
1625 &resource
.wstyle
.t_focus
,
1626 WhitePixel(getBaseDisplay().getXDisplay(),
1627 getScreenNumber()));
1628 readDatabaseTexture("window.title.unfocus", "Window.Title.Unfocus",
1629 &resource
.wstyle
.t_unfocus
,
1630 BlackPixel(getBaseDisplay().getXDisplay(),
1631 getScreenNumber()));
1632 readDatabaseTexture("window.label.focus", "Window.Label.Focus",
1633 &resource
.wstyle
.l_focus
,
1634 WhitePixel(getBaseDisplay().getXDisplay(),
1635 getScreenNumber()));
1636 readDatabaseTexture("window.label.unfocus", "Window.Label.Unfocus",
1637 &resource
.wstyle
.l_unfocus
,
1638 BlackPixel(getBaseDisplay().getXDisplay(),
1639 getScreenNumber()));
1640 readDatabaseTexture("window.handle.focus", "Window.Handle.Focus",
1641 &resource
.wstyle
.h_focus
,
1642 WhitePixel(getBaseDisplay().getXDisplay(),
1643 getScreenNumber()));
1644 readDatabaseTexture("window.handle.unfocus", "Window.Handle.Unfocus",
1645 &resource
.wstyle
.h_unfocus
,
1646 BlackPixel(getBaseDisplay().getXDisplay(),
1647 getScreenNumber()));
1648 readDatabaseTexture("window.grip.focus", "Window.Grip.Focus",
1649 &resource
.wstyle
.g_focus
,
1650 WhitePixel(getBaseDisplay().getXDisplay(),
1651 getScreenNumber()));
1652 readDatabaseTexture("window.grip.unfocus", "Window.Grip.Unfocus",
1653 &resource
.wstyle
.g_unfocus
,
1654 BlackPixel(getBaseDisplay().getXDisplay(),
1655 getScreenNumber()));
1656 readDatabaseTexture("window.button.focus", "Window.Button.Focus",
1657 &resource
.wstyle
.b_focus
,
1658 WhitePixel(getBaseDisplay().getXDisplay(),
1659 getScreenNumber()));
1660 readDatabaseTexture("window.button.unfocus", "Window.Button.Unfocus",
1661 &resource
.wstyle
.b_unfocus
,
1662 BlackPixel(getBaseDisplay().getXDisplay(),
1663 getScreenNumber()));
1664 readDatabaseTexture("window.button.pressed", "Window.Button.Pressed",
1665 &resource
.wstyle
.b_pressed
,
1666 BlackPixel(getBaseDisplay().getXDisplay(),
1667 getScreenNumber()));
1668 readDatabaseColor("window.frame.focusColor",
1669 "Window.Frame.FocusColor",
1670 &resource
.wstyle
.f_focus
,
1671 WhitePixel(getBaseDisplay().getXDisplay(),
1672 getScreenNumber()));
1673 readDatabaseColor("window.frame.unfocusColor",
1674 "Window.Frame.UnfocusColor",
1675 &resource
.wstyle
.f_unfocus
,
1676 BlackPixel(getBaseDisplay().getXDisplay(),
1677 getScreenNumber()));
1678 readDatabaseColor("window.label.focus.textColor",
1679 "Window.Label.Focus.TextColor",
1680 &resource
.wstyle
.l_text_focus
,
1681 BlackPixel(getBaseDisplay().getXDisplay(),
1682 getScreenNumber()));
1683 readDatabaseColor("window.label.unfocus.textColor",
1684 "Window.Label.Unfocus.TextColor",
1685 &resource
.wstyle
.l_text_unfocus
,
1686 WhitePixel(getBaseDisplay().getXDisplay(),
1687 getScreenNumber()));
1688 readDatabaseColor("window.button.focus.picColor",
1689 "Window.Button.Focus.PicColor",
1690 &resource
.wstyle
.b_pic_focus
,
1691 BlackPixel(getBaseDisplay().getXDisplay(),
1692 getScreenNumber()));
1693 readDatabaseColor("window.button.unfocus.picColor",
1694 "Window.Button.Unfocus.PicColor",
1695 &resource
.wstyle
.b_pic_unfocus
,
1696 WhitePixel(getBaseDisplay().getXDisplay(),
1697 getScreenNumber()));
1699 if (conf
.getValue("window.justify", "Window.Justify", s
)) {
1700 if (0 == strncasecmp(s
.c_str(), "right", s
.length()))
1701 resource
.wstyle
.justify
= BScreen::RightJustify
;
1702 else if (0 == strncasecmp(s
.c_str(), "center", s
.length()))
1703 resource
.wstyle
.justify
= BScreen::CenterJustify
;
1705 resource
.wstyle
.justify
= BScreen::LeftJustify
;
1707 resource
.wstyle
.justify
= BScreen::LeftJustify
;
1709 // load toolbar config
1710 readDatabaseTexture("toolbar", "Toolbar",
1711 &resource
.tstyle
.toolbar
,
1712 BlackPixel(getBaseDisplay().getXDisplay(),
1713 getScreenNumber()));
1714 readDatabaseTexture("toolbar.label", "Toolbar.Label",
1715 &resource
.tstyle
.label
,
1716 BlackPixel(getBaseDisplay().getXDisplay(),
1717 getScreenNumber()));
1718 readDatabaseTexture("toolbar.windowLabel", "Toolbar.WindowLabel",
1719 &resource
.tstyle
.window
,
1720 BlackPixel(getBaseDisplay().getXDisplay(),
1721 getScreenNumber()));
1722 readDatabaseTexture("toolbar.button", "Toolbar.Button",
1723 &resource
.tstyle
.button
,
1724 WhitePixel(getBaseDisplay().getXDisplay(),
1725 getScreenNumber()));
1726 readDatabaseTexture("toolbar.button.pressed", "Toolbar.Button.Pressed",
1727 &resource
.tstyle
.pressed
,
1728 BlackPixel(getBaseDisplay().getXDisplay(),
1729 getScreenNumber()));
1730 readDatabaseTexture("toolbar.clock", "Toolbar.Clock",
1731 &resource
.tstyle
.clock
,
1732 BlackPixel(getBaseDisplay().getXDisplay(),
1733 getScreenNumber()));
1734 readDatabaseColor("toolbar.label.textColor", "Toolbar.Label.TextColor",
1735 &resource
.tstyle
.l_text
,
1736 WhitePixel(getBaseDisplay().getXDisplay(),
1737 getScreenNumber()));
1738 readDatabaseColor("toolbar.windowLabel.textColor",
1739 "Toolbar.WindowLabel.TextColor",
1740 &resource
.tstyle
.w_text
,
1741 WhitePixel(getBaseDisplay().getXDisplay(),
1742 getScreenNumber()));
1743 readDatabaseColor("toolbar.clock.textColor", "Toolbar.Clock.TextColor",
1744 &resource
.tstyle
.c_text
,
1745 WhitePixel(getBaseDisplay().getXDisplay(),
1746 getScreenNumber()));
1747 readDatabaseColor("toolbar.button.picColor", "Toolbar.Button.PicColor",
1748 &resource
.tstyle
.b_pic
,
1749 BlackPixel(getBaseDisplay().getXDisplay(),
1750 getScreenNumber()));
1752 if (conf
.getValue("toolbar.justify", "Toolbar.Justify", s
)) {
1753 if (0 == strncasecmp(s
.c_str(), "right", s
.length()))
1754 resource
.tstyle
.justify
= BScreen::RightJustify
;
1755 else if (0 == strncasecmp(s
.c_str(), "center", s
.length()))
1756 resource
.tstyle
.justify
= BScreen::CenterJustify
;
1758 resource
.tstyle
.justify
= BScreen::LeftJustify
;
1760 resource
.tstyle
.justify
= BScreen::LeftJustify
;
1763 readDatabaseTexture("menu.title", "Menu.Title",
1764 &resource
.mstyle
.title
,
1765 WhitePixel(getBaseDisplay().getXDisplay(),
1766 getScreenNumber()));
1767 readDatabaseTexture("menu.frame", "Menu.Frame",
1768 &resource
.mstyle
.frame
,
1769 BlackPixel(getBaseDisplay().getXDisplay(),
1770 getScreenNumber()));
1771 readDatabaseTexture("menu.hilite", "Menu.Hilite",
1772 &resource
.mstyle
.hilite
,
1773 WhitePixel(getBaseDisplay().getXDisplay(),
1774 getScreenNumber()));
1775 readDatabaseColor("menu.title.textColor", "Menu.Title.TextColor",
1776 &resource
.mstyle
.t_text
,
1777 BlackPixel(getBaseDisplay().getXDisplay(),
1778 getScreenNumber()));
1779 readDatabaseColor("menu.frame.textColor", "Menu.Frame.TextColor",
1780 &resource
.mstyle
.f_text
,
1781 WhitePixel(getBaseDisplay().getXDisplay(),
1782 getScreenNumber()));
1783 readDatabaseColor("menu.frame.disableColor", "Menu.Frame.DisableColor",
1784 &resource
.mstyle
.d_text
,
1785 BlackPixel(getBaseDisplay().getXDisplay(),
1786 getScreenNumber()));
1787 readDatabaseColor("menu.hilite.textColor", "Menu.Hilite.TextColor",
1788 &resource
.mstyle
.h_text
,
1789 BlackPixel(getBaseDisplay().getXDisplay(),
1790 getScreenNumber()));
1792 if (conf
.getValue("menu.title.justify", "Menu.Title.Justify", s
)) {
1793 if (0 == strncasecmp(s
.c_str(), "right", s
.length()))
1794 resource
.mstyle
.t_justify
= BScreen::RightJustify
;
1795 else if (0 == strncasecmp(s
.c_str(), "center", s
.length()))
1796 resource
.mstyle
.t_justify
= BScreen::CenterJustify
;
1798 resource
.mstyle
.t_justify
= BScreen::LeftJustify
;
1800 resource
.mstyle
.t_justify
= BScreen::LeftJustify
;
1802 if (conf
.getValue("menu.frame.justify", "Menu.Frame.Justify", s
)) {
1803 if (0 == strncasecmp(s
.c_str(), "right", s
.length()))
1804 resource
.mstyle
.f_justify
= BScreen::RightJustify
;
1805 else if (0 == strncasecmp(s
.c_str(), "center", s
.length()))
1806 resource
.mstyle
.f_justify
= BScreen::CenterJustify
;
1808 resource
.mstyle
.f_justify
= BScreen::LeftJustify
;
1810 resource
.mstyle
.f_justify
= BScreen::LeftJustify
;
1812 if (conf
.getValue("menu.bullet", "Menu.Bullet", s
)) {
1813 if (0 == strncasecmp(s
.c_str(), "empty", s
.length()))
1814 resource
.mstyle
.bullet
= Basemenu::Empty
;
1815 else if (0 == strncasecmp(s
.c_str(), "square", s
.length()))
1816 resource
.mstyle
.bullet
= Basemenu::Square
;
1817 else if (0 == strncasecmp(s
.c_str(), "diamond", s
.length()))
1818 resource
.mstyle
.bullet
= Basemenu::Diamond
;
1820 resource
.mstyle
.bullet
= Basemenu::Triangle
;
1822 resource
.mstyle
.bullet
= Basemenu::Triangle
;
1824 if (conf
.getValue("menu.bullet.position", "Menu.Bullet.Position", s
)) {
1825 if (0 == strncasecmp(s
.c_str(), "right", s
.length()))
1826 resource
.mstyle
.bullet_pos
= Basemenu::Right
;
1828 resource
.mstyle
.bullet_pos
= Basemenu::Left
;
1830 resource
.mstyle
.bullet_pos
= Basemenu::Left
;
1832 readDatabaseColor("borderColor", "BorderColor", &resource
.border_color
,
1833 BlackPixel(getBaseDisplay().getXDisplay(),
1834 getScreenNumber()));
1836 // load bevel, border and handle widths
1837 if (conf
.getValue("handleWidth", "HandleWidth", l
)) {
1838 if (l
<= size().w() / 2 && l
!= 0)
1839 resource
.handle_width
= l
;
1841 resource
.handle_width
= 6;
1843 resource
.handle_width
= 6;
1845 if (conf
.getValue("borderWidth", "BorderWidth", l
))
1846 resource
.border_width
= l
;
1848 resource
.border_width
= 1;
1850 if (conf
.getValue("bevelWidth", "BevelWidth", l
)) {
1851 if (l
<= size().w() / 2 && l
!= 0)
1852 resource
.bevel_width
= l
;
1854 resource
.bevel_width
= 3;
1856 resource
.bevel_width
= 3;
1858 if (conf
.getValue("frameWidth", "FrameWidth", l
)) {
1859 if (l
<= size().w() / 2)
1860 resource
.frame_width
= l
;
1862 resource
.frame_width
= resource
.bevel_width
;
1864 resource
.frame_width
= resource
.bevel_width
;
1866 const char *cmd
= resource
.root_command
;
1867 if (cmd
!= NULL
|| conf
.getValue("rootCommand", "RootCommand", s
)) {
1869 cmd
= s
.c_str(); // not specified by the screen, so use the one from the
1872 char displaystring
[MAXPATHLEN
];
1873 sprintf(displaystring
, "DISPLAY=%s",
1874 DisplayString(getBaseDisplay().getXDisplay()));
1875 sprintf(displaystring
+ strlen(displaystring
) - 1, "%d",
1878 bexec(cmd
, displaystring
);
1880 spawnlp(P_NOWAIT
, "cmd.exe", "cmd.exe", "/c", cmd
, NULL
);
1886 void BScreen::addIcon(OpenboxWindow
*w
) {
1889 w
->setWorkspace(-1);
1890 w
->setWindowNumber(iconList
.size());
1892 iconList
.push_back(w
);
1894 iconmenu
->insert((const char **) w
->getIconTitle());
1899 void BScreen::removeIcon(OpenboxWindow
*w
) {
1904 iconmenu
->remove(w
->getWindowNumber());
1907 winList::iterator it
= iconList
.begin();
1908 for (int i
= 0; it
!= iconList
.end(); ++it
, ++i
)
1909 (*it
)->setWindowNumber(i
);
1913 OpenboxWindow
*BScreen::getIcon(int index
) {
1914 if (index
< 0 || index
>= iconList
.size())
1915 return (OpenboxWindow
*) 0;
1917 winList::iterator it
= iconList
.begin();
1918 for (; index
> 0; --index
, ++it
); // increment to index
1923 int BScreen::addWorkspace(void) {
1924 Workspace
*wkspc
= new Workspace(*this, workspacesList
.size());
1925 workspacesList
.push_back(wkspc
);
1926 setWorkspaceCount(workspaceCount()+1);
1927 saveWorkspaceNames();
1929 workspacemenu
->insert(wkspc
->getName(), wkspc
->getMenu(),
1930 wkspc
->getWorkspaceID() + 2);
1931 workspacemenu
->update();
1933 toolbar
->reconfigure();
1935 updateNetizenWorkspaceCount();
1937 return workspacesList
.size();
1941 int BScreen::removeLastWorkspace(void) {
1942 if (workspacesList
.size() == 1)
1945 Workspace
*wkspc
= workspacesList
.back();
1947 if (current_workspace
->getWorkspaceID() == wkspc
->getWorkspaceID())
1948 changeWorkspaceID(current_workspace
->getWorkspaceID() - 1);
1952 workspacemenu
->remove(wkspc
->getWorkspaceID() + 2);
1953 workspacemenu
->update();
1955 workspacesList
.pop_back();
1958 setWorkspaceCount(workspaceCount()-1);
1959 saveWorkspaceNames();
1961 toolbar
->reconfigure();
1963 updateNetizenWorkspaceCount();
1965 return workspacesList
.size();
1969 void BScreen::changeWorkspaceID(int id
) {
1970 if (! current_workspace
) return;
1972 if (id
!= current_workspace
->getWorkspaceID()) {
1973 current_workspace
->hideAll();
1975 workspacemenu
->setItemSelected(current_workspace
->getWorkspaceID() + 2,
1978 if (openbox
.focusedWindow() &&
1979 openbox
.focusedWindow()->getScreen() == this &&
1980 (! openbox
.focusedWindow()->isStuck())) {
1981 current_workspace
->setLastFocusedWindow(openbox
.focusedWindow());
1982 openbox
.focusWindow((OpenboxWindow
*) 0);
1985 current_workspace
= getWorkspace(id
);
1987 workspacemenu
->setItemSelected(current_workspace
->getWorkspaceID() + 2,
1989 toolbar
->redrawWorkspaceLabel(True
);
1991 current_workspace
->showAll();
1993 if (resource
.focus_last
&& current_workspace
->getLastFocusedWindow()) {
1994 XSync(openbox
.getXDisplay(), False
);
1995 current_workspace
->getLastFocusedWindow()->setInputFocus();
1999 updateNetizenCurrentWorkspace();
2003 void BScreen::addNetizen(Netizen
*n
) {
2004 netizenList
.push_back(n
);
2006 n
->sendWorkspaceCount();
2007 n
->sendCurrentWorkspace();
2009 wkspList::iterator it
;
2010 for (it
= workspacesList
.begin(); it
!= workspacesList
.end(); ++it
) {
2011 for (int i
= 0; i
< (*it
)->getCount(); i
++)
2012 n
->sendWindowAdd((*it
)->getWindow(i
)->getClientWindow(),
2013 (*it
)->getWorkspaceID());
2016 Window f
= ((openbox
.focusedWindow()) ?
2017 openbox
.focusedWindow()->getClientWindow() : None
);
2018 n
->sendWindowFocus(f
);
2022 void BScreen::removeNetizen(Window w
) {
2023 netList::iterator it
;
2026 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2027 if ((*it
)->getWindowID() == w
) {
2029 netizenList
.erase(it
);
2036 void BScreen::updateNetizenCurrentWorkspace(void) {
2037 netList::iterator it
;
2038 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2039 (*it
)->sendCurrentWorkspace();
2043 void BScreen::updateNetizenWorkspaceCount(void) {
2044 netList::iterator it
;
2045 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2046 (*it
)->sendWorkspaceCount();
2050 void BScreen::updateNetizenWindowFocus(void) {
2051 Window f
= ((openbox
.focusedWindow()) ?
2052 openbox
.focusedWindow()->getClientWindow() : None
);
2053 netList::iterator it
;
2054 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2055 (*it
)->sendWindowFocus(f
);
2059 void BScreen::updateNetizenWindowAdd(Window w
, unsigned long p
) {
2060 netList::iterator it
;
2061 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2062 (*it
)->sendWindowAdd(w
, p
);
2066 void BScreen::updateNetizenWindowDel(Window w
) {
2067 netList::iterator it
;
2068 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2069 (*it
)->sendWindowDel(w
);
2073 void BScreen::updateNetizenWindowRaise(Window w
) {
2074 netList::iterator it
;
2075 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2076 (*it
)->sendWindowRaise(w
);
2080 void BScreen::updateNetizenWindowLower(Window w
) {
2081 netList::iterator it
;
2082 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2083 (*it
)->sendWindowLower(w
);
2087 void BScreen::updateNetizenConfigNotify(XEvent
*e
) {
2088 netList::iterator it
;
2089 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2090 (*it
)->sendConfigNotify(e
);
2094 void BScreen::raiseWindows(Window
*workspace_stack
, int num
) {
2095 Window
*session_stack
= new
2096 Window
[(num
+ workspacesList
.size() + rootmenuList
.size() + 13)];
2099 XRaiseWindow(getBaseDisplay().getXDisplay(), iconmenu
->getWindowID());
2100 *(session_stack
+ i
++) = iconmenu
->getWindowID();
2102 wkspList::iterator it
;
2103 for (it
= workspacesList
.begin(); it
!= workspacesList
.end(); ++it
)
2104 *(session_stack
+ i
++) = (*it
)->getMenu()->getWindowID();
2106 *(session_stack
+ i
++) = workspacemenu
->getWindowID();
2108 *(session_stack
+ i
++) = configmenu
->getFocusmenu()->getWindowID();
2109 *(session_stack
+ i
++) = configmenu
->getPlacementmenu()->getWindowID();
2110 *(session_stack
+ i
++) = configmenu
->getWindowID();
2113 *(session_stack
+ i
++) = slit
->getMenu()->getDirectionmenu()->getWindowID();
2114 *(session_stack
+ i
++) = slit
->getMenu()->getPlacementmenu()->getWindowID();
2115 *(session_stack
+ i
++) = slit
->getMenu()->getWindowID();
2118 *(session_stack
+ i
++) =
2119 toolbar
->getMenu()->getPlacementmenu()->getWindowID();
2120 *(session_stack
+ i
++) = toolbar
->getMenu()->getWindowID();
2122 menuList::iterator rit
;
2123 for (rit
= rootmenuList
.begin(); rit
!= rootmenuList
.end(); ++rit
)
2124 *(session_stack
+ i
++) = (*rit
)->getWindowID();
2125 *(session_stack
+ i
++) = rootmenu
->getWindowID();
2127 if (toolbar
->onTop())
2128 *(session_stack
+ i
++) = toolbar
->getWindowID();
2132 *(session_stack
+ i
++) = slit
->getWindowID();
2136 *(session_stack
+ i
++) = *(workspace_stack
+ k
);
2138 XRestackWindows(getBaseDisplay().getXDisplay(), session_stack
, i
);
2140 delete [] session_stack
;
2144 void BScreen::addWorkspaceName(const char *name
) {
2145 workspaceNames
.push_back(name
);
2149 const char *BScreen::getNameOfWorkspace(int id
) {
2150 if (id
< 0 || id
>= workspaceNames
.size())
2151 return (const char *) 0;
2152 return workspaceNames
[id
].c_str();
2156 void BScreen::reassociateWindow(OpenboxWindow
*w
, int wkspc_id
, Bool ignore_sticky
) {
2160 wkspc_id
= current_workspace
->getWorkspaceID();
2162 if (w
->getWorkspaceNumber() == wkspc_id
)
2165 if (w
->isIconic()) {
2167 getWorkspace(wkspc_id
)->addWindow(w
);
2168 } else if (ignore_sticky
|| ! w
->isStuck()) {
2169 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
2170 getWorkspace(wkspc_id
)->addWindow(w
);
2175 void BScreen::nextFocus(void) {
2176 Bool have_focused
= False
;
2177 int focused_window_number
= -1;
2178 OpenboxWindow
*next
;
2180 if (openbox
.focusedWindow()) {
2181 if (openbox
.focusedWindow()->getScreen()->getScreenNumber() ==
2182 getScreenNumber()) {
2183 have_focused
= True
;
2184 focused_window_number
= openbox
.focusedWindow()->getWindowNumber();
2188 if ((getCurrentWorkspace()->getCount() > 1) && have_focused
) {
2189 int next_window_number
= focused_window_number
;
2191 if ((++next_window_number
) >= getCurrentWorkspace()->getCount())
2192 next_window_number
= 0;
2194 next
= getCurrentWorkspace()->getWindow(next_window_number
);
2195 } while ((! next
->setInputFocus()) && (next_window_number
!=
2196 focused_window_number
));
2198 if (next_window_number
!= focused_window_number
)
2199 getCurrentWorkspace()->raiseWindow(next
);
2200 } else if (getCurrentWorkspace()->getCount() >= 1) {
2201 next
= current_workspace
->getWindow(0);
2203 current_workspace
->raiseWindow(next
);
2204 next
->setInputFocus();
2209 void BScreen::prevFocus(void) {
2210 Bool have_focused
= False
;
2211 int focused_window_number
= -1;
2212 OpenboxWindow
*prev
;
2214 if (openbox
.focusedWindow()) {
2215 if (openbox
.focusedWindow()->getScreen()->getScreenNumber() ==
2216 getScreenNumber()) {
2217 have_focused
= True
;
2218 focused_window_number
= openbox
.focusedWindow()->getWindowNumber();
2222 if ((getCurrentWorkspace()->getCount() > 1) && have_focused
) {
2223 int prev_window_number
= focused_window_number
;
2225 if ((--prev_window_number
) < 0)
2226 prev_window_number
= getCurrentWorkspace()->getCount() - 1;
2228 prev
= getCurrentWorkspace()->getWindow(prev_window_number
);
2229 } while ((! prev
->setInputFocus()) && (prev_window_number
!=
2230 focused_window_number
));
2232 if (prev_window_number
!= focused_window_number
)
2233 getCurrentWorkspace()->raiseWindow(prev
);
2234 } else if (getCurrentWorkspace()->getCount() >= 1) {
2235 prev
= current_workspace
->getWindow(0);
2237 current_workspace
->raiseWindow(prev
);
2238 prev
->setInputFocus();
2243 void BScreen::raiseFocus(void) {
2244 Bool have_focused
= False
;
2245 int focused_window_number
= -1;
2247 if (openbox
.focusedWindow()) {
2248 if (openbox
.focusedWindow()->getScreen()->getScreenNumber() ==
2249 getScreenNumber()) {
2250 have_focused
= True
;
2251 focused_window_number
= openbox
.focusedWindow()->getWindowNumber();
2255 if ((getCurrentWorkspace()->getCount() > 1) && have_focused
)
2256 getWorkspace(openbox
.focusedWindow()->getWorkspaceNumber())->
2257 raiseWindow(openbox
.focusedWindow());
2261 void BScreen::InitMenu(void) {
2263 rootmenuList
.clear();
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
.push_back(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
.push_back(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 std::for_each(workspacesList
.begin(), workspacesList
.end(),
2742 std::mem_fun(&Workspace::shutdown
));
2744 while (!iconList
.empty())
2745 iconList
.front()->restore();
2755 void BScreen::showPosition(int x
, int y
) {
2756 if (! geom_visible
) {
2757 XMoveResizeWindow(getBaseDisplay().getXDisplay(), geom_window
,
2758 (size().w() - geom_w
) / 2,
2759 (size().h() - geom_h
) / 2, geom_w
, geom_h
);
2760 XMapWindow(getBaseDisplay().getXDisplay(), geom_window
);
2761 XRaiseWindow(getBaseDisplay().getXDisplay(), geom_window
);
2763 geom_visible
= True
;
2768 sprintf(label
, i18n
->getMessage(ScreenSet
, ScreenPositionFormat
,
2769 "X: %4d x Y: %4d"), x
, y
);
2771 XClearWindow(getBaseDisplay().getXDisplay(), geom_window
);
2773 if (i18n
->multibyte()) {
2774 XmbDrawString(getBaseDisplay().getXDisplay(), geom_window
,
2775 resource
.wstyle
.fontset
, resource
.wstyle
.l_text_focus_gc
,
2776 resource
.bevel_width
, resource
.bevel_width
-
2777 resource
.wstyle
.fontset_extents
->max_ink_extent
.y
,
2778 label
, strlen(label
));
2780 XDrawString(getBaseDisplay().getXDisplay(), geom_window
,
2781 resource
.wstyle
.l_text_focus_gc
,
2782 resource
.bevel_width
,
2783 resource
.wstyle
.font
->ascent
+
2784 resource
.bevel_width
, label
, strlen(label
));
2789 void BScreen::showGeometry(unsigned int gx
, unsigned int gy
) {
2790 if (! geom_visible
) {
2791 XMoveResizeWindow(getBaseDisplay().getXDisplay(), geom_window
,
2792 (size().w() - geom_w
) / 2,
2793 (size().h() - geom_h
) / 2, geom_w
, geom_h
);
2794 XMapWindow(getBaseDisplay().getXDisplay(), geom_window
);
2795 XRaiseWindow(getBaseDisplay().getXDisplay(), geom_window
);
2797 geom_visible
= True
;
2802 sprintf(label
, i18n
->getMessage(ScreenSet
, ScreenGeometryFormat
,
2803 "W: %4d x H: %4d"), gx
, gy
);
2805 XClearWindow(getBaseDisplay().getXDisplay(), geom_window
);
2807 if (i18n
->multibyte()) {
2808 XmbDrawString(getBaseDisplay().getXDisplay(), geom_window
,
2809 resource
.wstyle
.fontset
, resource
.wstyle
.l_text_focus_gc
,
2810 resource
.bevel_width
, resource
.bevel_width
-
2811 resource
.wstyle
.fontset_extents
->max_ink_extent
.y
,
2812 label
, strlen(label
));
2814 XDrawString(getBaseDisplay().getXDisplay(), geom_window
,
2815 resource
.wstyle
.l_text_focus_gc
,
2816 resource
.bevel_width
,
2817 resource
.wstyle
.font
->ascent
+
2818 resource
.bevel_width
, label
, strlen(label
));
2822 void BScreen::hideGeometry(void) {
2824 XUnmapWindow(getBaseDisplay().getXDisplay(), geom_window
);
2825 geom_visible
= False
;