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(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(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
228 current_workspace
= (Workspace
*) 0;
231 pid_t bpid
= getpid();
233 XChangeProperty(getBaseDisplay().getXDisplay(), getRootWindow(),
234 openbox
.getOpenboxPidAtom(), XA_CARDINAL
,
235 sizeof(pid_t
) * 8, PropModeReplace
,
236 (unsigned char *) &bpid
, 1);
237 #endif // HAVE_GETPID
239 XDefineCursor(getBaseDisplay().getXDisplay(), getRootWindow(),
240 openbox
.getSessionCursor());
243 new BImageControl(openbox
, *this, True
, openbox
.getColorsPerChannel(),
244 openbox
.getCacheLife(), openbox
.getCacheMax());
245 image_control
->installRootColormap();
246 root_colormap_installed
= True
;
248 load(); // load config options from Resources
252 unsigned long gc_value_mask
= GCForeground
;
253 if (! i18n
.multibyte()) gc_value_mask
|= GCFont
;
255 gcv
.foreground
= WhitePixel(getBaseDisplay().getXDisplay(),
257 ^ BlackPixel(getBaseDisplay().getXDisplay(),
259 gcv
.function
= GXxor
;
260 gcv
.subwindow_mode
= IncludeInferiors
;
261 opGC
= XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
262 GCForeground
| GCFunction
| GCSubwindowMode
, &gcv
);
264 gcv
.foreground
= resource
.wstyle
.l_text_focus
.getPixel();
265 if (resource
.wstyle
.font
)
266 gcv
.font
= resource
.wstyle
.font
->fid
;
267 resource
.wstyle
.l_text_focus_gc
=
268 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
269 gc_value_mask
, &gcv
);
271 gcv
.foreground
= resource
.wstyle
.l_text_unfocus
.getPixel();
272 if (resource
.wstyle
.font
)
273 gcv
.font
= resource
.wstyle
.font
->fid
;
274 resource
.wstyle
.l_text_unfocus_gc
=
275 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
276 gc_value_mask
, &gcv
);
278 gcv
.foreground
= resource
.wstyle
.b_pic_focus
.getPixel();
279 resource
.wstyle
.b_pic_focus_gc
=
280 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
283 gcv
.foreground
= resource
.wstyle
.b_pic_unfocus
.getPixel();
284 resource
.wstyle
.b_pic_unfocus_gc
=
285 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
288 gcv
.foreground
= resource
.mstyle
.t_text
.getPixel();
289 if (resource
.mstyle
.t_font
)
290 gcv
.font
= resource
.mstyle
.t_font
->fid
;
291 resource
.mstyle
.t_text_gc
=
292 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
293 gc_value_mask
, &gcv
);
295 gcv
.foreground
= resource
.mstyle
.f_text
.getPixel();
296 if (resource
.mstyle
.f_font
)
297 gcv
.font
= resource
.mstyle
.f_font
->fid
;
298 resource
.mstyle
.f_text_gc
=
299 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
300 gc_value_mask
, &gcv
);
302 gcv
.foreground
= resource
.mstyle
.h_text
.getPixel();
303 resource
.mstyle
.h_text_gc
=
304 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
305 gc_value_mask
, &gcv
);
307 gcv
.foreground
= resource
.mstyle
.d_text
.getPixel();
308 resource
.mstyle
.d_text_gc
=
309 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
310 gc_value_mask
, &gcv
);
312 gcv
.foreground
= resource
.mstyle
.hilite
.getColor()->getPixel();
313 resource
.mstyle
.hilite_gc
=
314 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
315 gc_value_mask
, &gcv
);
317 gcv
.foreground
= resource
.tstyle
.l_text
.getPixel();
318 if (resource
.tstyle
.font
)
319 gcv
.font
= resource
.tstyle
.font
->fid
;
320 resource
.tstyle
.l_text_gc
=
321 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
322 gc_value_mask
, &gcv
);
324 gcv
.foreground
= resource
.tstyle
.w_text
.getPixel();
325 resource
.tstyle
.w_text_gc
=
326 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
327 gc_value_mask
, &gcv
);
329 gcv
.foreground
= resource
.tstyle
.c_text
.getPixel();
330 resource
.tstyle
.c_text_gc
=
331 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
332 gc_value_mask
, &gcv
);
334 gcv
.foreground
= resource
.tstyle
.b_pic
.getPixel();
335 resource
.tstyle
.b_pic_gc
=
336 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
337 gc_value_mask
, &gcv
);
339 const char *s
= i18n(ScreenSet
, ScreenPositionLength
,
340 "0: 0000 x 0: 0000");
343 if (i18n
.multibyte()) {
344 XRectangle ink
, logical
;
345 XmbTextExtents(resource
.wstyle
.fontset
, s
, l
, &ink
, &logical
);
346 geom_w
= logical
.width
;
348 geom_h
= resource
.wstyle
.fontset_extents
->max_ink_extent
.height
;
350 geom_h
= resource
.wstyle
.font
->ascent
+
351 resource
.wstyle
.font
->descent
;
353 geom_w
= XTextWidth(resource
.wstyle
.font
, s
, l
);
356 geom_w
+= (resource
.bevel_width
* 2);
357 geom_h
+= (resource
.bevel_width
* 2);
359 XSetWindowAttributes attrib
;
360 unsigned long mask
= CWBorderPixel
| CWColormap
| CWSaveUnder
;
361 attrib
.border_pixel
= getBorderColor()->getPixel();
362 attrib
.colormap
= getColormap();
363 attrib
.save_under
= True
;
366 XCreateWindow(getBaseDisplay().getXDisplay(), getRootWindow(),
367 0, 0, geom_w
, geom_h
, resource
.border_width
, getDepth(),
368 InputOutput
, getVisual(), mask
, &attrib
);
369 geom_visible
= False
;
371 if (resource
.wstyle
.l_focus
.getTexture() & BImage_ParentRelative
) {
372 if (resource
.wstyle
.t_focus
.getTexture() ==
373 (BImage_Flat
| BImage_Solid
)) {
375 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window
,
376 resource
.wstyle
.t_focus
.getColor()->getPixel());
378 geom_pixmap
= image_control
->renderImage(geom_w
, geom_h
,
379 &resource
.wstyle
.t_focus
);
380 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
381 geom_window
, geom_pixmap
);
384 if (resource
.wstyle
.l_focus
.getTexture() ==
385 (BImage_Flat
| BImage_Solid
)) {
387 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window
,
388 resource
.wstyle
.l_focus
.getColor()->getPixel());
390 geom_pixmap
= image_control
->renderImage(geom_w
, geom_h
,
391 &resource
.wstyle
.l_focus
);
392 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
393 geom_window
, geom_pixmap
);
397 workspacemenu
= new Workspacemenu(*this);
398 iconmenu
= new Iconmenu(*this);
399 configmenu
= new Configmenu(*this);
401 Workspace
*wkspc
= NULL
;
402 if (resource
.workspaces
!= 0) {
403 for (int i
= 0; i
< resource
.workspaces
; ++i
) {
404 wkspc
= new Workspace(*this, workspacesList
.size());
405 workspacesList
.push_back(wkspc
);
406 workspacemenu
->insert(wkspc
->getName(), wkspc
->getMenu());
409 setWorkspaceCount(1);
410 wkspc
= new Workspace(*this, workspacesList
.size());
411 workspacesList
.push_back(wkspc
);
412 workspacemenu
->insert(wkspc
->getName(), wkspc
->getMenu());
414 saveWorkspaceNames();
416 workspacemenu
->insert(i18n(IconSet
, IconIcons
, "Icons"),
418 workspacemenu
->update();
420 current_workspace
= workspacesList
.front();
421 workspacemenu
->setItemSelected(2, True
);
423 toolbar
= new Toolbar(*this, config
);
426 slit
= new Slit(*this, config
);
434 changeWorkspaceID(0);
438 Window r
, p
, *children
;
439 XQueryTree(getBaseDisplay().getXDisplay(), getRootWindow(), &r
, &p
,
442 // preen the window list of all icon windows... for better dockapp support
443 for (i
= 0; i
< (int) nchild
; i
++) {
444 if (children
[i
] == None
) continue;
446 XWMHints
*wmhints
= XGetWMHints(getBaseDisplay().getXDisplay(),
450 if ((wmhints
->flags
& IconWindowHint
) &&
451 (wmhints
->icon_window
!= children
[i
]))
452 for (int j
= 0; j
< (int) nchild
; j
++)
453 if (children
[j
] == wmhints
->icon_window
) {
463 // manage shown windows
464 for (i
= 0; i
< (int) nchild
; ++i
) {
465 if (children
[i
] == None
|| (! openbox
.validateWindow(children
[i
])))
468 XWindowAttributes attrib
;
469 if (XGetWindowAttributes(getBaseDisplay().getXDisplay(), children
[i
],
471 if (attrib
.override_redirect
) continue;
473 if (attrib
.map_state
!= IsUnmapped
) {
474 new OpenboxWindow(openbox
, children
[i
], this);
476 OpenboxWindow
*win
= openbox
.searchWindow(children
[i
]);
478 XMapRequestEvent mre
;
479 mre
.window
= children
[i
];
480 win
->restoreAttributes();
481 win
->mapRequestEvent(&mre
);
488 XFlush(getBaseDisplay().getXDisplay());
492 BScreen::~BScreen(void) {
493 if (! managed
) return;
495 if (geom_pixmap
!= None
)
496 image_control
->removeImage(geom_pixmap
);
498 if (geom_window
!= None
)
499 XDestroyWindow(getBaseDisplay().getXDisplay(), geom_window
);
501 removeWorkspaceNames();
503 std::for_each(workspacesList
.begin(), workspacesList
.end(),
505 std::for_each(iconList
.begin(), iconList
.end(), PointerAssassin());
506 std::for_each(netizenList
.begin(), netizenList
.end(), PointerAssassin());
509 if (resource
.strftime_format
)
510 delete [] resource
.strftime_format
;
511 #endif // HAVE_STRFTIME
514 delete workspacemenu
;
523 delete image_control
;
525 if (resource
.wstyle
.fontset
)
526 XFreeFontSet(getBaseDisplay().getXDisplay(), resource
.wstyle
.fontset
);
527 if (resource
.mstyle
.t_fontset
)
528 XFreeFontSet(getBaseDisplay().getXDisplay(), resource
.mstyle
.t_fontset
);
529 if (resource
.mstyle
.f_fontset
)
530 XFreeFontSet(getBaseDisplay().getXDisplay(), resource
.mstyle
.f_fontset
);
531 if (resource
.tstyle
.fontset
)
532 XFreeFontSet(getBaseDisplay().getXDisplay(), resource
.tstyle
.fontset
);
534 if (resource
.wstyle
.font
)
535 XFreeFont(getBaseDisplay().getXDisplay(), resource
.wstyle
.font
);
536 if (resource
.mstyle
.t_font
)
537 XFreeFont(getBaseDisplay().getXDisplay(), resource
.mstyle
.t_font
);
538 if (resource
.mstyle
.f_font
)
539 XFreeFont(getBaseDisplay().getXDisplay(), resource
.mstyle
.f_font
);
540 if (resource
.tstyle
.font
)
541 XFreeFont(getBaseDisplay().getXDisplay(), resource
.tstyle
.font
);
542 if (resource
.root_command
!= NULL
)
543 delete [] resource
.root_command
;
545 XFreeGC(getBaseDisplay().getXDisplay(), opGC
);
547 XFreeGC(getBaseDisplay().getXDisplay(),
548 resource
.wstyle
.l_text_focus_gc
);
549 XFreeGC(getBaseDisplay().getXDisplay(),
550 resource
.wstyle
.l_text_unfocus_gc
);
551 XFreeGC(getBaseDisplay().getXDisplay(),
552 resource
.wstyle
.b_pic_focus_gc
);
553 XFreeGC(getBaseDisplay().getXDisplay(),
554 resource
.wstyle
.b_pic_unfocus_gc
);
556 XFreeGC(getBaseDisplay().getXDisplay(),
557 resource
.mstyle
.t_text_gc
);
558 XFreeGC(getBaseDisplay().getXDisplay(),
559 resource
.mstyle
.f_text_gc
);
560 XFreeGC(getBaseDisplay().getXDisplay(),
561 resource
.mstyle
.h_text_gc
);
562 XFreeGC(getBaseDisplay().getXDisplay(),
563 resource
.mstyle
.d_text_gc
);
564 XFreeGC(getBaseDisplay().getXDisplay(),
565 resource
.mstyle
.hilite_gc
);
567 XFreeGC(getBaseDisplay().getXDisplay(),
568 resource
.tstyle
.l_text_gc
);
569 XFreeGC(getBaseDisplay().getXDisplay(),
570 resource
.tstyle
.w_text_gc
);
571 XFreeGC(getBaseDisplay().getXDisplay(),
572 resource
.tstyle
.c_text_gc
);
573 XFreeGC(getBaseDisplay().getXDisplay(),
574 resource
.tstyle
.b_pic_gc
);
578 Rect
BScreen::availableArea() const {
579 // the following code is temporary and will be taken care of by Screen in the
580 // future (with the NETWM 'strut')
581 Rect
space(0, 0, size().w(), size().h());
582 if (!resource
.full_max
) {
584 int slit_x
= slit
->autoHide() ? slit
->hiddenOrigin().x() : slit
->area().x(),
585 slit_y
= slit
->autoHide() ? slit
->hiddenOrigin().y() : slit
->area().y();
586 unsigned int tbarh
= resource
.hide_toolbar
? 0 :
587 toolbar
->getExposedHeight() + resource
.border_width
* 2;
589 switch (toolbar
->placement()) {
590 case Toolbar::TopLeft
:
591 case Toolbar::TopCenter
:
592 case Toolbar::TopRight
:
595 case Toolbar::BottomLeft
:
596 case Toolbar::BottomCenter
:
597 case Toolbar::BottomRight
:
601 ASSERT(false); // unhandled placement
603 if ((slit
->direction() == Slit::Horizontal
&&
604 (slit
->placement() == Slit::TopLeft
||
605 slit
->placement() == Slit::TopRight
)) ||
606 slit
->placement() == Slit::TopCenter
) {
608 if (tbartop
&& slit_y
+ slit
->area().h() < tbarh
) {
609 space
.setY(space
.y() + tbarh
);
610 space
.setH(space
.h() - tbarh
);
612 space
.setY(space
.y() + (slit_y
+ slit
->area().h() +
613 resource
.border_width
* 2));
614 space
.setH(space
.h() - (slit_y
+ slit
->area().h() +
615 resource
.border_width
* 2));
617 space
.setH(space
.h() - tbarh
);
619 } else if ((slit
->direction() == Slit::Vertical
&&
620 (slit
->placement() == Slit::TopRight
||
621 slit
->placement() == Slit::BottomRight
)) ||
622 slit
->placement() == Slit::CenterRight
) {
624 space
.setW(space
.w() - (size().w() - slit_x
));
626 space
.setY(space
.y() + tbarh
);
627 space
.setH(space
.h() - tbarh
);
628 } else if ((slit
->direction() == Slit::Horizontal
&&
629 (slit
->placement() == Slit::BottomLeft
||
630 slit
->placement() == Slit::BottomRight
)) ||
631 slit
->placement() == Slit::BottomCenter
) {
633 if (!tbartop
&& (size().h() - slit_y
) < tbarh
) {
634 space
.setH(space
.h() - tbarh
);
636 space
.setH(space
.h() - (size().h() - slit_y
));
638 space
.setY(space
.y() + tbarh
);
639 space
.setH(space
.h() - tbarh
);
642 } else {// if ((slit->direction() == Slit::Vertical &&
643 // (slit->placement() == Slit::TopLeft ||
644 // slit->placement() == Slit::BottomLeft)) ||
645 // slit->placement() == Slit::CenterLeft)
647 space
.setX(slit_x
+ slit
->area().w() +
648 resource
.border_width
* 2);
649 space
.setW(space
.w() - (slit_x
+ slit
->area().w() +
650 resource
.border_width
* 2));
652 space
.setY(space
.y() + tbarh
);
653 space
.setH(space
.h() - tbarh
);
656 int tbarh
= resource
.hide_toolbar
? 0 :
657 toolbar
->getExposedHeight() + resource
.border_width
* 2;
658 switch (toolbar
->placement()) {
659 case Toolbar::TopLeft
:
660 case Toolbar::TopCenter
:
661 case Toolbar::TopRight
:
662 space
.setY(toolbar
->getExposedHeight());
663 space
.setH(space
.h() - toolbar
->getExposedHeight());
665 case Toolbar::BottomLeft
:
666 case Toolbar::BottomCenter
:
667 case Toolbar::BottomRight
:
668 space
.setH(space
.h() - tbarh
);
671 ASSERT(false); // unhandled placement
679 void BScreen::readDatabaseTexture(const char *rname
, const char *rclass
,
681 unsigned long default_pixel
)
685 if (resource
.styleconfig
.getValue(rname
, rclass
, s
))
686 image_control
->parseTexture(texture
, s
.c_str());
688 texture
->setTexture(BImage_Solid
| BImage_Flat
);
690 if (texture
->getTexture() & BImage_Solid
) {
691 int clen
= strlen(rclass
) + 32, nlen
= strlen(rname
) + 32;
693 char *colorclass
= new char[clen
], *colorname
= new char[nlen
];
695 sprintf(colorclass
, "%s.Color", rclass
);
696 sprintf(colorname
, "%s.color", rname
);
698 readDatabaseColor(colorname
, colorclass
, texture
->getColor(),
702 sprintf(colorclass
, "%s.ColorTo", rclass
);
703 sprintf(colorname
, "%s.colorTo", rname
);
705 readDatabaseColor(colorname
, colorclass
, texture
->getColorTo(),
709 delete [] colorclass
;
712 if ((! texture
->getColor()->isAllocated()) ||
713 (texture
->getTexture() & BImage_Flat
))
718 xcol
.red
= (unsigned int) (texture
->getColor()->getRed() +
719 (texture
->getColor()->getRed() >> 1));
720 if (xcol
.red
>= 0xff) xcol
.red
= 0xffff;
721 else xcol
.red
*= 0xff;
722 xcol
.green
= (unsigned int) (texture
->getColor()->getGreen() +
723 (texture
->getColor()->getGreen() >> 1));
724 if (xcol
.green
>= 0xff) xcol
.green
= 0xffff;
725 else xcol
.green
*= 0xff;
726 xcol
.blue
= (unsigned int) (texture
->getColor()->getBlue() +
727 (texture
->getColor()->getBlue() >> 1));
728 if (xcol
.blue
>= 0xff) xcol
.blue
= 0xffff;
729 else xcol
.blue
*= 0xff;
731 if (! XAllocColor(getBaseDisplay().getXDisplay(),
732 getColormap(), &xcol
))
735 texture
->getHiColor()->setPixel(xcol
.pixel
);
738 (unsigned int) ((texture
->getColor()->getRed() >> 2) +
739 (texture
->getColor()->getRed() >> 1)) * 0xff;
741 (unsigned int) ((texture
->getColor()->getGreen() >> 2) +
742 (texture
->getColor()->getGreen() >> 1)) * 0xff;
744 (unsigned int) ((texture
->getColor()->getBlue() >> 2) +
745 (texture
->getColor()->getBlue() >> 1)) * 0xff;
747 if (! XAllocColor(getBaseDisplay().getXDisplay(),
748 getColormap(), &xcol
))
751 texture
->getLoColor()->setPixel(xcol
.pixel
);
752 } else if (texture
->getTexture() & BImage_Gradient
) {
753 int clen
= strlen(rclass
) + 10, nlen
= strlen(rname
) + 10;
755 char *colorclass
= new char[clen
], *colorname
= new char[nlen
],
756 *colortoclass
= new char[clen
], *colortoname
= new char[nlen
];
758 sprintf(colorclass
, "%s.Color", rclass
);
759 sprintf(colorname
, "%s.color", rname
);
761 sprintf(colortoclass
, "%s.ColorTo", rclass
);
762 sprintf(colortoname
, "%s.colorTo", rname
);
764 readDatabaseColor(colorname
, colorclass
, texture
->getColor(),
766 readDatabaseColor(colortoname
, colortoclass
, texture
->getColorTo(),
769 delete [] colorclass
;
771 delete [] colortoclass
;
772 delete [] colortoname
;
777 void BScreen::readDatabaseColor(const char *rname
, const char *rclass
,
778 BColor
*color
, unsigned long default_pixel
)
782 if (resource
.styleconfig
.getValue(rname
, rclass
, s
))
783 image_control
->parseColor(color
, s
.c_str());
785 // parsing with no color std::string just deallocates the color, if it has
786 // been previously allocated
787 image_control
->parseColor(color
);
788 color
->setPixel(default_pixel
);
793 void BScreen::readDatabaseFontSet(const char *rname
, const char *rclass
,
795 if (! fontset
) return;
797 static char *defaultFont
= "fixed";
798 bool load_default
= false;
802 XFreeFontSet(getBaseDisplay().getXDisplay(), *fontset
);
804 if (resource
.styleconfig
.getValue(rname
, rclass
, s
)) {
805 if (! (*fontset
= createFontSet(s
.c_str())))
811 *fontset
= createFontSet(defaultFont
);
814 fprintf(stderr
, i18n(ScreenSet
, ScreenDefaultFontLoadFail
,
815 "BScreen::LoadStyle(): couldn't load default font.\n"));
822 void BScreen::readDatabaseFont(const char *rname
, const char *rclass
,
823 XFontStruct
**font
) {
826 static char *defaultFont
= "fixed";
827 bool load_default
= false;
831 XFreeFont(getBaseDisplay().getXDisplay(), *font
);
833 if (resource
.styleconfig
.getValue(rname
, rclass
, s
)) {
834 if ((*font
= XLoadQueryFont(getBaseDisplay().getXDisplay(),
835 s
.c_str())) == NULL
) {
836 fprintf(stderr
, i18n(ScreenSet
, ScreenFontLoadFail
,
837 "BScreen::LoadStyle(): couldn't load font '%s'\n"),
845 if ((*font
= XLoadQueryFont(getBaseDisplay().getXDisplay(),
846 defaultFont
)) == NULL
) {
847 fprintf(stderr
, i18n(ScreenSet
, ScreenDefaultFontLoadFail
,
848 "BScreen::LoadStyle(): couldn't load default font.\n"));
855 XFontSet
BScreen::createFontSet(const char *fontname
) {
857 char **missing
, *def
= "-";
858 int nmissing
, pixel_size
= 0, buf_size
= 0;
859 char weight
[FONT_ELEMENT_SIZE
], slant
[FONT_ELEMENT_SIZE
];
861 fs
= XCreateFontSet(getBaseDisplay().getXDisplay(),
862 fontname
, &missing
, &nmissing
, &def
);
863 if (fs
&& (! nmissing
)) return fs
;
865 #ifdef HAVE_SETLOCALE
867 if (nmissing
) XFreeStringList(missing
);
869 setlocale(LC_CTYPE
, "C");
870 fs
= XCreateFontSet(getBaseDisplay().getXDisplay(), fontname
,
871 &missing
, &nmissing
, &def
);
872 setlocale(LC_CTYPE
, "");
874 #endif // HAVE_SETLOCALE
877 XFontStruct
**fontstructs
;
879 XFontsOfFontSet(fs
, &fontstructs
, &fontnames
);
880 fontname
= fontnames
[0];
883 getFontElement(fontname
, weight
, FONT_ELEMENT_SIZE
,
884 "-medium-", "-bold-", "-demibold-", "-regular-", NULL
);
885 getFontElement(fontname
, slant
, FONT_ELEMENT_SIZE
,
886 "-r-", "-i-", "-o-", "-ri-", "-ro-", NULL
);
887 getFontSize(fontname
, &pixel_size
);
889 if (! strcmp(weight
, "*")) strncpy(weight
, "medium", FONT_ELEMENT_SIZE
);
890 if (! strcmp(slant
, "*")) strncpy(slant
, "r", FONT_ELEMENT_SIZE
);
891 if (pixel_size
< 3) pixel_size
= 3;
892 else if (pixel_size
> 97) pixel_size
= 97;
894 buf_size
= strlen(fontname
) + (FONT_ELEMENT_SIZE
* 2) + 64;
895 char *pattern2
= new char[buf_size
];
896 snprintf(pattern2
, buf_size
- 1,
898 "-*-*-%s-%s-*-*-%d-*-*-*-*-*-*-*,"
899 "-*-*-*-*-*-*-%d-*-*-*-*-*-*-*,*",
900 fontname
, weight
, slant
, pixel_size
, pixel_size
);
903 if (nmissing
) XFreeStringList(missing
);
904 if (fs
) XFreeFontSet(getBaseDisplay().getXDisplay(), fs
);
906 fs
= XCreateFontSet(getBaseDisplay().getXDisplay(), fontname
,
907 &missing
, &nmissing
, &def
);
914 void BScreen::setSloppyFocus(bool b
) {
915 resource
.sloppy_focus
= b
;
917 s
<< "session.screen" << getScreenNumber() << ".focusModel" << ends
;
918 config
.setValue(s
.str(),
919 (resource
.sloppy_focus
?
920 (resource
.auto_raise
? "AutoRaiseSloppyFocus" : "SloppyFocus")
922 s
.rdbuf()->freeze(0);
926 void BScreen::setAutoRaise(bool a
) {
927 resource
.auto_raise
= a
;
929 s
<< "session.screen" << getScreenNumber() << ".focusModel" << ends
;
930 config
.setValue(s
.str(),
931 (resource
.sloppy_focus
?
932 (resource
.auto_raise
? "AutoRaiseSloppyFocus" : "SloppyFocus")
934 s
.rdbuf()->freeze(0);
938 void BScreen::setImageDither(bool d
, bool reconfig
) {
939 image_control
->setDither(d
);
941 s
<< "session.screen" << getScreenNumber() << ".imageDither" << ends
;
942 config
.setValue(s
.str(), imageDither());
945 s
.rdbuf()->freeze(0);
949 void BScreen::setOpaqueMove(bool o
) {
950 resource
.opaque_move
= o
;
952 s
<< "session.screen" << getScreenNumber() << ".opaqueMove" << ends
;
953 config
.setValue(s
.str(), resource
.opaque_move
);
954 s
.rdbuf()->freeze(0);
958 void BScreen::setFullMax(bool f
) {
959 resource
.full_max
= f
;
961 s
<< "session.screen" << getScreenNumber() << ".fullMaximization" << ends
;
962 config
.setValue(s
.str(), resource
.full_max
);
963 s
.rdbuf()->freeze(0);
967 void BScreen::setFocusNew(bool f
) {
968 resource
.focus_new
= f
;
970 s
<< "session.screen" << getScreenNumber() << ".focusNewWindows" << ends
;
971 config
.setValue(s
.str(), resource
.focus_new
);
972 s
.rdbuf()->freeze(0);
976 void BScreen::setFocusLast(bool f
) {
977 resource
.focus_last
= f
;
979 s
<< "session.screen" << getScreenNumber() << ".focusLastWindow" << ends
;
980 config
.setValue(s
.str(), resource
.focus_last
);
981 s
.rdbuf()->freeze(0);
985 void BScreen::setWindowZones(int z
) {
988 s
<< "session.screen" << getScreenNumber() << ".windowZones" << ends
;
989 config
.setValue(s
.str(), resource
.zones
);
990 s
.rdbuf()->freeze(0);
994 void BScreen::setWorkspaceCount(int w
) {
995 resource
.workspaces
= w
;
997 s
<< "session.screen" << getScreenNumber() << ".workspaces" << ends
;
998 config
.setValue(s
.str(), resource
.workspaces
);
999 s
.rdbuf()->freeze(0);
1003 void BScreen::setPlacementPolicy(int p
) {
1004 resource
.placement_policy
= p
;
1006 s
<< "session.screen" << getScreenNumber() << ".windowPlacement" << ends
;
1007 const char *placement
;
1008 switch (resource
.placement_policy
) {
1009 case CascadePlacement
: placement
= "CascadePlacement"; break;
1010 case BestFitPlacement
: placement
= "BestFitPlacement"; break;
1011 case ColSmartPlacement
: placement
= "ColSmartPlacement"; break;
1012 case UnderMousePlacement
: placement
= "UnderMousePlacement"; break;
1013 case ClickMousePlacement
: placement
= "ClickMousePlacement"; break;
1015 case RowSmartPlacement
: placement
= "RowSmartPlacement"; break;
1017 config
.setValue(s
.str(), placement
);
1018 s
.rdbuf()->freeze(0);
1022 void BScreen::setEdgeSnapThreshold(int t
) {
1023 resource
.edge_snap_threshold
= t
;
1025 s
<< "session.screen" << getScreenNumber() << ".edgeSnapThreshold" << ends
;
1026 config
.setValue(s
.str(), resource
.edge_snap_threshold
);
1027 s
.rdbuf()->freeze(0);
1031 void BScreen::setRowPlacementDirection(int d
) {
1032 resource
.row_direction
= d
;
1034 s
<< "session.screen" << getScreenNumber() << ".rowPlacementDirection" << ends
;
1035 config
.setValue(s
.str(),
1036 resource
.row_direction
== LeftRight
?
1037 "LeftToRight" : "RightToLeft");
1038 s
.rdbuf()->freeze(0);
1042 void BScreen::setColPlacementDirection(int d
) {
1043 resource
.col_direction
= d
;
1045 s
<< "session.screen" << getScreenNumber() << ".colPlacementDirection" << ends
;
1046 config
.setValue(s
.str(),
1047 resource
.col_direction
== TopBottom
?
1048 "TopToBottom" : "BottomToTop");
1049 s
.rdbuf()->freeze(0);
1053 void BScreen::setRootCommand(const char *cmd
) {
1054 if (resource
.root_command
!= NULL
)
1055 delete [] resource
.root_command
;
1057 resource
.root_command
= bstrdup(cmd
);
1059 resource
.root_command
= NULL
;
1060 // this doesn't save to the Resources config because it can't be changed
1061 // inside Openbox, and this way we dont add an empty command which would over-
1062 // ride the styles command when none has been specified
1066 #ifdef HAVE_STRFTIME
1067 void BScreen::setStrftimeFormat(const char *f
) {
1068 if (resource
.strftime_format
!= NULL
)
1069 delete [] resource
.strftime_format
;
1071 resource
.strftime_format
= bstrdup(f
);
1073 s
<< "session.screen" << getScreenNumber() << ".strftimeFormat" << ends
;
1074 config
.setValue(s
.str(), resource
.strftime_format
);
1075 s
.rdbuf()->freeze(0);
1078 #else // !HAVE_STRFTIME
1080 void BScreen::setDateFormat(int f
) {
1081 resource
.date_format
= f
;
1083 s
<< "session.screen" << getScreenNumber() << ".dateFormat" << ends
;
1084 config
.setValue(s
.str(), resource
.date_format
== B_EuropeanDate
?
1085 "European" : "American");
1086 s
.rdbuf()->freeze(0);
1090 void BScreen::setClock24Hour(Bool c
) {
1091 resource
.clock24hour
= c
;
1093 s
<< "session.screen" << getScreenNumber() << ".clockFormat" << ends
;
1094 config
.setValue(s
.str(), resource
.clock24hour
? 24 : 12);
1095 s
.rdbuf()->freeze(0);
1097 #endif // HAVE_STRFTIME
1100 void BScreen::setHideToolbar(bool b
) {
1101 resource
.hide_toolbar
= b
;
1102 if (resource
.hide_toolbar
)
1103 getToolbar()->unMapToolbar();
1105 getToolbar()->mapToolbar();
1107 s
<< "session.screen" << getScreenNumber() << ".hideToolbar" << ends
;
1108 config
.setValue(s
.str(), resource
.hide_toolbar
? "True" : "False");
1109 s
.rdbuf()->freeze(0);
1113 void BScreen::saveWorkspaceNames() {
1114 std::ostrstream rc
, names
;
1116 wkspList::iterator it
;
1117 wkspList::iterator last
= workspacesList
.end() - 1;
1118 for (it
= workspacesList
.begin(); it
!= workspacesList
.end(); ++it
) {
1119 names
<< (*it
)->getName();
1125 rc
<< "session.screen" << getScreenNumber() << ".workspaceNames" << ends
;
1126 config
.setValue(rc
.str(), names
.str());
1127 rc
.rdbuf()->freeze(0);
1128 names
.rdbuf()->freeze(0);
1131 void BScreen::save() {
1132 setSloppyFocus(resource
.sloppy_focus
);
1133 setAutoRaise(resource
.auto_raise
);
1134 setImageDither(imageDither(), false);
1135 setOpaqueMove(resource
.opaque_move
);
1136 setFullMax(resource
.full_max
);
1137 setFocusNew(resource
.focus_new
);
1138 setFocusLast(resource
.focus_last
);
1139 setWindowZones(resource
.zones
);
1140 setWorkspaceCount(resource
.workspaces
);
1141 setPlacementPolicy(resource
.placement_policy
);
1142 setEdgeSnapThreshold(resource
.edge_snap_threshold
);
1143 setRowPlacementDirection(resource
.row_direction
);
1144 setColPlacementDirection(resource
.col_direction
);
1145 setRootCommand(resource
.root_command
);
1146 #ifdef HAVE_STRFTIME
1147 // it deletes the current value before setting the new one, so we have to
1148 // duplicate the current value.
1149 std::string s
= resource
.strftime_format
;
1150 setStrftimeFormat(s
.c_str());
1151 #else // !HAVE_STRFTIME
1152 setDateFormat(resource
.date_format
);
1153 setClock24Hour(resource
.clock24hour
);
1154 #endif // HAVE_STRFTIME
1155 setHideToolbar(resource
.hide_toolbar
);
1164 void BScreen::load() {
1165 std::ostrstream rscreen
, rname
, rclass
;
1169 rscreen
<< "session.screen" << getScreenNumber() << '.' << ends
;
1171 rname
<< rscreen
.str() << "hideToolbar" << ends
;
1172 rclass
<< rscreen
.str() << "HideToolbar" << ends
;
1173 if (config
.getValue(rname
.str(), rclass
.str(), b
))
1174 resource
.hide_toolbar
= b
;
1176 resource
.hide_toolbar
= false;
1177 Toolbar
*t
= getToolbar();
1179 if (resource
.hide_toolbar
)
1185 rname
.seekp(0); rclass
.seekp(0);
1186 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1187 rname
<< rscreen
.str() << "fullMaximization" << ends
;
1188 rclass
<< rscreen
.str() << "FullMaximization" << ends
;
1189 if (config
.getValue(rname
.str(), rclass
.str(), b
))
1190 resource
.full_max
= b
;
1192 resource
.full_max
= false;
1194 rname
.seekp(0); rclass
.seekp(0);
1195 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1196 rname
<< rscreen
.str() << "focusNewWindows" << ends
;
1197 rclass
<< rscreen
.str() << "FocusNewWindows" << ends
;
1198 if (config
.getValue(rname
.str(), rclass
.str(), b
))
1199 resource
.focus_new
= b
;
1201 resource
.focus_new
= false;
1203 rname
.seekp(0); rclass
.seekp(0);
1204 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1205 rname
<< rscreen
.str() << "focusLastWindow" << ends
;
1206 rclass
<< rscreen
.str() << "FocusLastWindow" << ends
;
1207 if (config
.getValue(rname
.str(), rclass
.str(), b
))
1208 resource
.focus_last
= b
;
1210 resource
.focus_last
= false;
1212 rname
.seekp(0); rclass
.seekp(0);
1213 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1214 rname
<< rscreen
.str() << "rowPlacementDirection" << ends
;
1215 rclass
<< rscreen
.str() << "RowPlacementDirection" << ends
;
1216 if (config
.getValue(rname
.str(), rclass
.str(), s
)) {
1217 if (0 == strncasecmp(s
.c_str(), "RightToLeft", s
.length()))
1218 resource
.row_direction
= RightLeft
;
1219 else //if (0 == strncasecmp(s.c_str(), "LeftToRight", s.length()))
1220 resource
.row_direction
= LeftRight
;
1222 resource
.row_direction
= LeftRight
;
1224 rname
.seekp(0); rclass
.seekp(0);
1225 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1226 rname
<< rscreen
.str() << "colPlacementDirection" << ends
;
1227 rclass
<< rscreen
.str() << "ColPlacementDirection" << ends
;
1228 if (config
.getValue(rname
.str(), rclass
.str(), s
)) {
1229 if (0 == strncasecmp(s
.c_str(), "BottomToTop", s
.length()))
1230 resource
.col_direction
= BottomTop
;
1231 else //if (0 == strncasecmp(s.c_str(), "TopToBottom", s.length()))
1232 resource
.col_direction
= TopBottom
;
1234 resource
.col_direction
= TopBottom
;
1236 rname
.seekp(0); rclass
.seekp(0);
1237 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1238 rname
<< rscreen
.str() << "workspaces" << ends
;
1239 rclass
<< rscreen
.str() << "Workspaces" << ends
;
1240 if (config
.getValue(rname
.str(), rclass
.str(), l
)) {
1241 resource
.workspaces
= l
;
1243 resource
.workspaces
= 1;
1245 removeWorkspaceNames();
1246 rname
.seekp(0); rclass
.seekp(0);
1247 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1248 rname
<< rscreen
.str() << "workspaceNames" << ends
;
1249 rclass
<< rscreen
.str() << "WorkspaceNames" << ends
;
1250 if (config
.getValue(rname
.str(), rclass
.str(), s
)) {
1251 std::string::const_iterator it
= s
.begin(), end
= s
.end();
1253 std::string::const_iterator tmp
= it
;// current string.begin()
1254 it
= std::find(tmp
, end
, ','); // look for comma between tmp and end
1255 std::string
name(tmp
, it
); // name = s[tmp:it]
1256 addWorkspaceName(name
.c_str());
1263 rname
.seekp(0); rclass
.seekp(0);
1264 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1265 rname
<< rscreen
.str() << "focusModel" << ends
;
1266 rclass
<< rscreen
.str() << "FocusModel" << ends
;
1267 if (config
.getValue(rname
.str(), rclass
.str(), s
)) {
1268 if (0 == strncasecmp(s
.c_str(), "ClickToFocus", s
.length())) {
1269 resource
.auto_raise
= false;
1270 resource
.sloppy_focus
= false;
1271 } else if (0 == strncasecmp(s
.c_str(), "AutoRaiseSloppyFocus",
1273 resource
.sloppy_focus
= true;
1274 resource
.auto_raise
= true;
1275 } else { //if (0 == strncasecmp(s.c_str(), "SloppyFocus", s.length())) {
1276 resource
.sloppy_focus
= true;
1277 resource
.auto_raise
= false;
1280 resource
.sloppy_focus
= true;
1281 resource
.auto_raise
= false;
1284 rname
.seekp(0); rclass
.seekp(0);
1285 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1286 rname
<< rscreen
.str() << "windowZones" << ends
;
1287 rclass
<< rscreen
.str() << "WindowZones" << ends
;
1288 if (config
.getValue(rname
.str(), rclass
.str(), l
))
1289 resource
.zones
= (l
== 1 || l
== 2 || l
== 4) ? l
: 1;
1293 rname
.seekp(0); rclass
.seekp(0);
1294 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1295 rname
<< rscreen
.str() << "windowPlacement" << ends
;
1296 rclass
<< rscreen
.str() << "WindowPlacement" << ends
;
1297 if (config
.getValue(rname
.str(), rclass
.str(), s
)) {
1298 if (0 == strncasecmp(s
.c_str(), "RowSmartPlacement", s
.length()))
1299 resource
.placement_policy
= RowSmartPlacement
;
1300 else if (0 == strncasecmp(s
.c_str(), "ColSmartPlacement", s
.length()))
1301 resource
.placement_policy
= ColSmartPlacement
;
1302 else if (0 == strncasecmp(s
.c_str(), "BestFitPlacement", s
.length()))
1303 resource
.placement_policy
= BestFitPlacement
;
1304 else if (0 == strncasecmp(s
.c_str(), "UnderMousePlacement", s
.length()))
1305 resource
.placement_policy
= UnderMousePlacement
;
1306 else if (0 == strncasecmp(s
.c_str(), "ClickMousePlacement", s
.length()))
1307 resource
.placement_policy
= ClickMousePlacement
;
1308 else //if (0 == strncasecmp(s.c_str(), "CascadePlacement", s.length()))
1309 resource
.placement_policy
= CascadePlacement
;
1311 resource
.placement_policy
= CascadePlacement
;
1313 #ifdef HAVE_STRFTIME
1314 rname
.seekp(0); rclass
.seekp(0);
1315 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1316 rname
<< rscreen
.str() << "strftimeFormat" << ends
;
1317 rclass
<< rscreen
.str() << "StrftimeFormat" << ends
;
1319 if (resource
.strftime_format
!= NULL
)
1320 delete [] resource
.strftime_format
;
1322 if (config
.getValue(rname
.str(), rclass
.str(), s
))
1323 resource
.strftime_format
= bstrdup(s
.c_str());
1325 resource
.strftime_format
= bstrdup("%I:%M %p");
1326 #else // !HAVE_STRFTIME
1327 rname
.seekp(0); rclass
.seekp(0);
1328 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1329 rname
<< rscreen
.str() << "dateFormat" << ends
;
1330 rclass
<< rscreen
.str() << "DateFormat" << ends
;
1331 if (config
.getValue(rname
.str(), rclass
.str(), s
)) {
1332 if (strncasecmp(s
.c_str(), "European", s
.length()))
1333 resource
.date_format
= B_EuropeanDate
;
1334 else //if (strncasecmp(s.c_str(), "American", s.length()))
1335 resource
.date_format
= B_AmericanDate
;
1337 resource
.date_format
= B_AmericanDate
;
1339 rname
.seekp(0); rclass
.seekp(0);
1340 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1341 rname
<< rscreen
.str() << "clockFormat" << ends
;
1342 rclass
<< rscreen
.str() << "ClockFormat" << ends
;
1343 if (config
.getValue(rname
.str(), rclass
.str(), l
)) {
1345 resource
.clock24hour
= true;
1346 else if (clock
== 12)
1347 resource
.clock24hour
= false;
1349 resource
.clock24hour
= false;
1350 #endif // HAVE_STRFTIME
1352 rname
.seekp(0); rclass
.seekp(0);
1353 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1354 rname
<< rscreen
.str() << "edgeSnapThreshold" << ends
;
1355 rclass
<< rscreen
.str() << "EdgeSnapThreshold" << ends
;
1356 if (config
.getValue(rname
.str(), rclass
.str(), l
))
1357 resource
.edge_snap_threshold
= l
;
1359 resource
.edge_snap_threshold
= 4;
1361 rname
.seekp(0); rclass
.seekp(0);
1362 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1363 rname
<< rscreen
.str() << "imageDither" << ends
;
1364 rclass
<< rscreen
.str() << "ImageDither" << ends
;
1365 if (config
.getValue(rname
.str(), rclass
.str(), b
))
1366 image_control
->setDither(b
);
1368 image_control
->setDither(true);
1370 rname
.seekp(0); rclass
.seekp(0);
1371 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1372 rname
<< rscreen
.str() << "rootCommand" << ends
;
1373 rclass
<< rscreen
.str() << "RootCommand" << ends
;
1375 if (resource
.root_command
!= NULL
)
1376 delete [] resource
.root_command
;
1378 if (config
.getValue(rname
.str(), rclass
.str(), s
))
1379 resource
.root_command
= bstrdup(s
.c_str());
1381 resource
.root_command
= NULL
;
1383 rname
.seekp(0); rclass
.seekp(0);
1384 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1385 rname
<< rscreen
.str() << "opaqueMove" << ends
;
1386 rclass
<< rscreen
.str() << "OpaqueMove" << ends
;
1387 if (config
.getValue(rname
.str(), rclass
.str(), b
))
1388 resource
.opaque_move
= b
;
1390 resource
.opaque_move
= false;
1392 rscreen
.rdbuf()->freeze(0);
1393 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1396 void BScreen::reconfigure(void) {
1405 unsigned long gc_value_mask
= GCForeground
;
1406 if (! i18n
.multibyte()) gc_value_mask
|= GCFont
;
1408 gcv
.foreground
= WhitePixel(getBaseDisplay().getXDisplay(),
1410 gcv
.function
= GXinvert
;
1411 gcv
.subwindow_mode
= IncludeInferiors
;
1412 XChangeGC(getBaseDisplay().getXDisplay(), opGC
,
1413 GCForeground
| GCFunction
| GCSubwindowMode
, &gcv
);
1415 gcv
.foreground
= resource
.wstyle
.l_text_focus
.getPixel();
1416 if (resource
.wstyle
.font
)
1417 gcv
.font
= resource
.wstyle
.font
->fid
;
1418 XChangeGC(getBaseDisplay().getXDisplay(), resource
.wstyle
.l_text_focus_gc
,
1419 gc_value_mask
, &gcv
);
1421 gcv
.foreground
= resource
.wstyle
.l_text_unfocus
.getPixel();
1422 XChangeGC(getBaseDisplay().getXDisplay(), resource
.wstyle
.l_text_unfocus_gc
,
1423 gc_value_mask
, &gcv
);
1425 gcv
.foreground
= resource
.wstyle
.b_pic_focus
.getPixel();
1426 XChangeGC(getBaseDisplay().getXDisplay(), resource
.wstyle
.b_pic_focus_gc
,
1427 GCForeground
, &gcv
);
1429 gcv
.foreground
= resource
.wstyle
.b_pic_unfocus
.getPixel();
1430 XChangeGC(getBaseDisplay().getXDisplay(), resource
.wstyle
.b_pic_unfocus_gc
,
1431 GCForeground
, &gcv
);
1433 gcv
.foreground
= resource
.mstyle
.t_text
.getPixel();
1434 if (resource
.mstyle
.t_font
)
1435 gcv
.font
= resource
.mstyle
.t_font
->fid
;
1436 XChangeGC(getBaseDisplay().getXDisplay(), resource
.mstyle
.t_text_gc
,
1437 gc_value_mask
, &gcv
);
1439 gcv
.foreground
= resource
.mstyle
.f_text
.getPixel();
1440 if (resource
.mstyle
.f_font
)
1441 gcv
.font
= resource
.mstyle
.f_font
->fid
;
1442 XChangeGC(getBaseDisplay().getXDisplay(), resource
.mstyle
.f_text_gc
,
1443 gc_value_mask
, &gcv
);
1445 gcv
.foreground
= resource
.mstyle
.h_text
.getPixel();
1446 XChangeGC(getBaseDisplay().getXDisplay(), resource
.mstyle
.h_text_gc
,
1447 gc_value_mask
, &gcv
);
1449 gcv
.foreground
= resource
.mstyle
.d_text
.getPixel();
1450 XChangeGC(getBaseDisplay().getXDisplay(), resource
.mstyle
.d_text_gc
,
1451 gc_value_mask
, &gcv
);
1453 gcv
.foreground
= resource
.mstyle
.hilite
.getColor()->getPixel();
1454 XChangeGC(getBaseDisplay().getXDisplay(), resource
.mstyle
.hilite_gc
,
1455 gc_value_mask
, &gcv
);
1457 gcv
.foreground
= resource
.tstyle
.l_text
.getPixel();
1458 if (resource
.tstyle
.font
)
1459 gcv
.font
= resource
.tstyle
.font
->fid
;
1460 XChangeGC(getBaseDisplay().getXDisplay(), resource
.tstyle
.l_text_gc
,
1461 gc_value_mask
, &gcv
);
1463 gcv
.foreground
= resource
.tstyle
.w_text
.getPixel();
1464 XChangeGC(getBaseDisplay().getXDisplay(), resource
.tstyle
.w_text_gc
,
1465 gc_value_mask
, &gcv
);
1467 gcv
.foreground
= resource
.tstyle
.c_text
.getPixel();
1468 XChangeGC(getBaseDisplay().getXDisplay(), resource
.tstyle
.c_text_gc
,
1469 gc_value_mask
, &gcv
);
1471 gcv
.foreground
= resource
.tstyle
.b_pic
.getPixel();
1472 XChangeGC(getBaseDisplay().getXDisplay(), resource
.tstyle
.b_pic_gc
,
1473 gc_value_mask
, &gcv
);
1475 const char *s
= i18n(ScreenSet
, ScreenPositionLength
,
1476 "0: 0000 x 0: 0000");
1479 if (i18n
.multibyte()) {
1480 XRectangle ink
, logical
;
1481 XmbTextExtents(resource
.wstyle
.fontset
, s
, l
, &ink
, &logical
);
1482 geom_w
= logical
.width
;
1484 geom_h
= resource
.wstyle
.fontset_extents
->max_ink_extent
.height
;
1486 geom_w
= XTextWidth(resource
.wstyle
.font
, s
, l
);
1488 geom_h
= resource
.wstyle
.font
->ascent
+
1489 resource
.wstyle
.font
->descent
;
1492 geom_w
+= (resource
.bevel_width
* 2);
1493 geom_h
+= (resource
.bevel_width
* 2);
1495 Pixmap tmp
= geom_pixmap
;
1496 if (resource
.wstyle
.l_focus
.getTexture() & BImage_ParentRelative
) {
1497 if (resource
.wstyle
.t_focus
.getTexture() ==
1498 (BImage_Flat
| BImage_Solid
)) {
1500 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window
,
1501 resource
.wstyle
.t_focus
.getColor()->getPixel());
1503 geom_pixmap
= image_control
->renderImage(geom_w
, geom_h
,
1504 &resource
.wstyle
.t_focus
);
1505 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
1506 geom_window
, geom_pixmap
);
1509 if (resource
.wstyle
.l_focus
.getTexture() ==
1510 (BImage_Flat
| BImage_Solid
)) {
1512 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window
,
1513 resource
.wstyle
.l_focus
.getColor()->getPixel());
1515 geom_pixmap
= image_control
->renderImage(geom_w
, geom_h
,
1516 &resource
.wstyle
.l_focus
);
1517 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
1518 geom_window
, geom_pixmap
);
1521 if (tmp
) image_control
->removeImage(tmp
);
1523 XSetWindowBorderWidth(getBaseDisplay().getXDisplay(), geom_window
,
1524 resource
.border_width
);
1525 XSetWindowBorder(getBaseDisplay().getXDisplay(), geom_window
,
1526 resource
.border_color
.getPixel());
1528 workspacemenu
->reconfigure();
1529 iconmenu
->reconfigure();
1532 int remember_sub
= rootmenu
->getCurrentSubmenu();
1535 rootmenu
->reconfigure();
1536 rootmenu
->drawSubmenu(remember_sub
);
1539 configmenu
->reconfigure();
1541 toolbar
->reconfigure();
1544 slit
->reconfigure();
1547 std::for_each(workspacesList
.begin(), workspacesList
.end(),
1548 std::mem_fun(&Workspace::reconfigure
));
1550 for (winList::iterator it
= iconList
.begin(); it
!= iconList
.end(); ++it
)
1551 if ((*it
)->validateClient())
1552 (*it
)->reconfigure();
1554 image_control
->timeout();
1558 void BScreen::rereadMenu(void) {
1562 rootmenu
->reconfigure();
1566 void BScreen::removeWorkspaceNames(void) {
1567 workspaceNames
.clear();
1571 void BScreen::LoadStyle(void) {
1572 Resource
&conf
= resource
.styleconfig
;
1574 const char *sfile
= openbox
.getStyleFilename();
1575 bool loaded
= false;
1576 if (sfile
!= NULL
) {
1577 conf
.setFile(sfile
);
1578 loaded
= conf
.load();
1581 conf
.setFile(DEFAULTSTYLE
);
1583 fprintf(stderr
, i18n(ScreenSet
, ScreenDefaultStyleLoadFail
,
1584 "BScreen::LoadStyle(): couldn't load "
1585 "default style.\n"));
1593 // load fonts/fontsets
1595 if (i18n
.multibyte()) {
1596 readDatabaseFontSet("window.font", "Window.Font",
1597 &resource
.wstyle
.fontset
);
1598 readDatabaseFontSet("toolbar.font", "Toolbar.Font",
1599 &resource
.tstyle
.fontset
);
1600 readDatabaseFontSet("menu.title.font", "Menu.Title.Font",
1601 &resource
.mstyle
.t_fontset
);
1602 readDatabaseFontSet("menu.frame.font", "Menu.Frame.Font",
1603 &resource
.mstyle
.f_fontset
);
1605 resource
.mstyle
.t_fontset_extents
=
1606 XExtentsOfFontSet(resource
.mstyle
.t_fontset
);
1607 resource
.mstyle
.f_fontset_extents
=
1608 XExtentsOfFontSet(resource
.mstyle
.f_fontset
);
1609 resource
.tstyle
.fontset_extents
=
1610 XExtentsOfFontSet(resource
.tstyle
.fontset
);
1611 resource
.wstyle
.fontset_extents
=
1612 XExtentsOfFontSet(resource
.wstyle
.fontset
);
1614 readDatabaseFont("window.font", "Window.Font",
1615 &resource
.wstyle
.font
);
1616 readDatabaseFont("menu.title.font", "Menu.Title.Font",
1617 &resource
.mstyle
.t_font
);
1618 readDatabaseFont("menu.frame.font", "Menu.Frame.Font",
1619 &resource
.mstyle
.f_font
);
1620 readDatabaseFont("toolbar.font", "Toolbar.Font",
1621 &resource
.tstyle
.font
);
1624 // load window config
1625 readDatabaseTexture("window.title.focus", "Window.Title.Focus",
1626 &resource
.wstyle
.t_focus
,
1627 WhitePixel(getBaseDisplay().getXDisplay(),
1628 getScreenNumber()));
1629 readDatabaseTexture("window.title.unfocus", "Window.Title.Unfocus",
1630 &resource
.wstyle
.t_unfocus
,
1631 BlackPixel(getBaseDisplay().getXDisplay(),
1632 getScreenNumber()));
1633 readDatabaseTexture("window.label.focus", "Window.Label.Focus",
1634 &resource
.wstyle
.l_focus
,
1635 WhitePixel(getBaseDisplay().getXDisplay(),
1636 getScreenNumber()));
1637 readDatabaseTexture("window.label.unfocus", "Window.Label.Unfocus",
1638 &resource
.wstyle
.l_unfocus
,
1639 BlackPixel(getBaseDisplay().getXDisplay(),
1640 getScreenNumber()));
1641 readDatabaseTexture("window.handle.focus", "Window.Handle.Focus",
1642 &resource
.wstyle
.h_focus
,
1643 WhitePixel(getBaseDisplay().getXDisplay(),
1644 getScreenNumber()));
1645 readDatabaseTexture("window.handle.unfocus", "Window.Handle.Unfocus",
1646 &resource
.wstyle
.h_unfocus
,
1647 BlackPixel(getBaseDisplay().getXDisplay(),
1648 getScreenNumber()));
1649 readDatabaseTexture("window.grip.focus", "Window.Grip.Focus",
1650 &resource
.wstyle
.g_focus
,
1651 WhitePixel(getBaseDisplay().getXDisplay(),
1652 getScreenNumber()));
1653 readDatabaseTexture("window.grip.unfocus", "Window.Grip.Unfocus",
1654 &resource
.wstyle
.g_unfocus
,
1655 BlackPixel(getBaseDisplay().getXDisplay(),
1656 getScreenNumber()));
1657 readDatabaseTexture("window.button.focus", "Window.Button.Focus",
1658 &resource
.wstyle
.b_focus
,
1659 WhitePixel(getBaseDisplay().getXDisplay(),
1660 getScreenNumber()));
1661 readDatabaseTexture("window.button.unfocus", "Window.Button.Unfocus",
1662 &resource
.wstyle
.b_unfocus
,
1663 BlackPixel(getBaseDisplay().getXDisplay(),
1664 getScreenNumber()));
1665 readDatabaseTexture("window.button.pressed", "Window.Button.Pressed",
1666 &resource
.wstyle
.b_pressed
,
1667 BlackPixel(getBaseDisplay().getXDisplay(),
1668 getScreenNumber()));
1669 readDatabaseColor("window.frame.focusColor",
1670 "Window.Frame.FocusColor",
1671 &resource
.wstyle
.f_focus
,
1672 WhitePixel(getBaseDisplay().getXDisplay(),
1673 getScreenNumber()));
1674 readDatabaseColor("window.frame.unfocusColor",
1675 "Window.Frame.UnfocusColor",
1676 &resource
.wstyle
.f_unfocus
,
1677 BlackPixel(getBaseDisplay().getXDisplay(),
1678 getScreenNumber()));
1679 readDatabaseColor("window.label.focus.textColor",
1680 "Window.Label.Focus.TextColor",
1681 &resource
.wstyle
.l_text_focus
,
1682 BlackPixel(getBaseDisplay().getXDisplay(),
1683 getScreenNumber()));
1684 readDatabaseColor("window.label.unfocus.textColor",
1685 "Window.Label.Unfocus.TextColor",
1686 &resource
.wstyle
.l_text_unfocus
,
1687 WhitePixel(getBaseDisplay().getXDisplay(),
1688 getScreenNumber()));
1689 readDatabaseColor("window.button.focus.picColor",
1690 "Window.Button.Focus.PicColor",
1691 &resource
.wstyle
.b_pic_focus
,
1692 BlackPixel(getBaseDisplay().getXDisplay(),
1693 getScreenNumber()));
1694 readDatabaseColor("window.button.unfocus.picColor",
1695 "Window.Button.Unfocus.PicColor",
1696 &resource
.wstyle
.b_pic_unfocus
,
1697 WhitePixel(getBaseDisplay().getXDisplay(),
1698 getScreenNumber()));
1700 if (conf
.getValue("window.justify", "Window.Justify", s
)) {
1701 if (0 == strncasecmp(s
.c_str(), "right", s
.length()))
1702 resource
.wstyle
.justify
= BScreen::RightJustify
;
1703 else if (0 == strncasecmp(s
.c_str(), "center", s
.length()))
1704 resource
.wstyle
.justify
= BScreen::CenterJustify
;
1706 resource
.wstyle
.justify
= BScreen::LeftJustify
;
1708 resource
.wstyle
.justify
= BScreen::LeftJustify
;
1710 // load toolbar config
1711 readDatabaseTexture("toolbar", "Toolbar",
1712 &resource
.tstyle
.toolbar
,
1713 BlackPixel(getBaseDisplay().getXDisplay(),
1714 getScreenNumber()));
1715 readDatabaseTexture("toolbar.label", "Toolbar.Label",
1716 &resource
.tstyle
.label
,
1717 BlackPixel(getBaseDisplay().getXDisplay(),
1718 getScreenNumber()));
1719 readDatabaseTexture("toolbar.windowLabel", "Toolbar.WindowLabel",
1720 &resource
.tstyle
.window
,
1721 BlackPixel(getBaseDisplay().getXDisplay(),
1722 getScreenNumber()));
1723 readDatabaseTexture("toolbar.button", "Toolbar.Button",
1724 &resource
.tstyle
.button
,
1725 WhitePixel(getBaseDisplay().getXDisplay(),
1726 getScreenNumber()));
1727 readDatabaseTexture("toolbar.button.pressed", "Toolbar.Button.Pressed",
1728 &resource
.tstyle
.pressed
,
1729 BlackPixel(getBaseDisplay().getXDisplay(),
1730 getScreenNumber()));
1731 readDatabaseTexture("toolbar.clock", "Toolbar.Clock",
1732 &resource
.tstyle
.clock
,
1733 BlackPixel(getBaseDisplay().getXDisplay(),
1734 getScreenNumber()));
1735 readDatabaseColor("toolbar.label.textColor", "Toolbar.Label.TextColor",
1736 &resource
.tstyle
.l_text
,
1737 WhitePixel(getBaseDisplay().getXDisplay(),
1738 getScreenNumber()));
1739 readDatabaseColor("toolbar.windowLabel.textColor",
1740 "Toolbar.WindowLabel.TextColor",
1741 &resource
.tstyle
.w_text
,
1742 WhitePixel(getBaseDisplay().getXDisplay(),
1743 getScreenNumber()));
1744 readDatabaseColor("toolbar.clock.textColor", "Toolbar.Clock.TextColor",
1745 &resource
.tstyle
.c_text
,
1746 WhitePixel(getBaseDisplay().getXDisplay(),
1747 getScreenNumber()));
1748 readDatabaseColor("toolbar.button.picColor", "Toolbar.Button.PicColor",
1749 &resource
.tstyle
.b_pic
,
1750 BlackPixel(getBaseDisplay().getXDisplay(),
1751 getScreenNumber()));
1753 if (conf
.getValue("toolbar.justify", "Toolbar.Justify", s
)) {
1754 if (0 == strncasecmp(s
.c_str(), "right", s
.length()))
1755 resource
.tstyle
.justify
= BScreen::RightJustify
;
1756 else if (0 == strncasecmp(s
.c_str(), "center", s
.length()))
1757 resource
.tstyle
.justify
= BScreen::CenterJustify
;
1759 resource
.tstyle
.justify
= BScreen::LeftJustify
;
1761 resource
.tstyle
.justify
= BScreen::LeftJustify
;
1764 readDatabaseTexture("menu.title", "Menu.Title",
1765 &resource
.mstyle
.title
,
1766 WhitePixel(getBaseDisplay().getXDisplay(),
1767 getScreenNumber()));
1768 readDatabaseTexture("menu.frame", "Menu.Frame",
1769 &resource
.mstyle
.frame
,
1770 BlackPixel(getBaseDisplay().getXDisplay(),
1771 getScreenNumber()));
1772 readDatabaseTexture("menu.hilite", "Menu.Hilite",
1773 &resource
.mstyle
.hilite
,
1774 WhitePixel(getBaseDisplay().getXDisplay(),
1775 getScreenNumber()));
1776 readDatabaseColor("menu.title.textColor", "Menu.Title.TextColor",
1777 &resource
.mstyle
.t_text
,
1778 BlackPixel(getBaseDisplay().getXDisplay(),
1779 getScreenNumber()));
1780 readDatabaseColor("menu.frame.textColor", "Menu.Frame.TextColor",
1781 &resource
.mstyle
.f_text
,
1782 WhitePixel(getBaseDisplay().getXDisplay(),
1783 getScreenNumber()));
1784 readDatabaseColor("menu.frame.disableColor", "Menu.Frame.DisableColor",
1785 &resource
.mstyle
.d_text
,
1786 BlackPixel(getBaseDisplay().getXDisplay(),
1787 getScreenNumber()));
1788 readDatabaseColor("menu.hilite.textColor", "Menu.Hilite.TextColor",
1789 &resource
.mstyle
.h_text
,
1790 BlackPixel(getBaseDisplay().getXDisplay(),
1791 getScreenNumber()));
1793 if (conf
.getValue("menu.title.justify", "Menu.Title.Justify", s
)) {
1794 if (0 == strncasecmp(s
.c_str(), "right", s
.length()))
1795 resource
.mstyle
.t_justify
= BScreen::RightJustify
;
1796 else if (0 == strncasecmp(s
.c_str(), "center", s
.length()))
1797 resource
.mstyle
.t_justify
= BScreen::CenterJustify
;
1799 resource
.mstyle
.t_justify
= BScreen::LeftJustify
;
1801 resource
.mstyle
.t_justify
= BScreen::LeftJustify
;
1803 if (conf
.getValue("menu.frame.justify", "Menu.Frame.Justify", s
)) {
1804 if (0 == strncasecmp(s
.c_str(), "right", s
.length()))
1805 resource
.mstyle
.f_justify
= BScreen::RightJustify
;
1806 else if (0 == strncasecmp(s
.c_str(), "center", s
.length()))
1807 resource
.mstyle
.f_justify
= BScreen::CenterJustify
;
1809 resource
.mstyle
.f_justify
= BScreen::LeftJustify
;
1811 resource
.mstyle
.f_justify
= BScreen::LeftJustify
;
1813 if (conf
.getValue("menu.bullet", "Menu.Bullet", s
)) {
1814 if (0 == strncasecmp(s
.c_str(), "empty", s
.length()))
1815 resource
.mstyle
.bullet
= Basemenu::Empty
;
1816 else if (0 == strncasecmp(s
.c_str(), "square", s
.length()))
1817 resource
.mstyle
.bullet
= Basemenu::Square
;
1818 else if (0 == strncasecmp(s
.c_str(), "diamond", s
.length()))
1819 resource
.mstyle
.bullet
= Basemenu::Diamond
;
1821 resource
.mstyle
.bullet
= Basemenu::Triangle
;
1823 resource
.mstyle
.bullet
= Basemenu::Triangle
;
1825 if (conf
.getValue("menu.bullet.position", "Menu.Bullet.Position", s
)) {
1826 if (0 == strncasecmp(s
.c_str(), "right", s
.length()))
1827 resource
.mstyle
.bullet_pos
= Basemenu::Right
;
1829 resource
.mstyle
.bullet_pos
= Basemenu::Left
;
1831 resource
.mstyle
.bullet_pos
= Basemenu::Left
;
1833 readDatabaseColor("borderColor", "BorderColor", &resource
.border_color
,
1834 BlackPixel(getBaseDisplay().getXDisplay(),
1835 getScreenNumber()));
1837 // load bevel, border and handle widths
1838 if (conf
.getValue("handleWidth", "HandleWidth", l
)) {
1839 if (l
<= (signed)size().w() / 2 && l
!= 0)
1840 resource
.handle_width
= l
;
1842 resource
.handle_width
= 6;
1844 resource
.handle_width
= 6;
1846 if (conf
.getValue("borderWidth", "BorderWidth", l
))
1847 resource
.border_width
= l
;
1849 resource
.border_width
= 1;
1851 if (conf
.getValue("bevelWidth", "BevelWidth", l
)) {
1852 if (l
<= (signed)size().w() / 2 && l
!= 0)
1853 resource
.bevel_width
= l
;
1855 resource
.bevel_width
= 3;
1857 resource
.bevel_width
= 3;
1859 if (conf
.getValue("frameWidth", "FrameWidth", l
)) {
1860 if (l
<= (signed)size().w() / 2)
1861 resource
.frame_width
= l
;
1863 resource
.frame_width
= resource
.bevel_width
;
1865 resource
.frame_width
= resource
.bevel_width
;
1867 const char *cmd
= resource
.root_command
;
1868 if (cmd
!= NULL
|| conf
.getValue("rootCommand", "RootCommand", s
)) {
1870 cmd
= s
.c_str(); // not specified by the screen, so use the one from the
1873 char displaystring
[MAXPATHLEN
];
1874 sprintf(displaystring
, "DISPLAY=%s",
1875 DisplayString(getBaseDisplay().getXDisplay()));
1876 sprintf(displaystring
+ strlen(displaystring
) - 1, "%d",
1879 bexec(cmd
, displaystring
);
1881 spawnlp(P_NOWAIT
, "cmd.exe", "cmd.exe", "/c", cmd
, NULL
);
1887 void BScreen::addIcon(OpenboxWindow
*w
) {
1890 w
->setWorkspace(-1);
1891 w
->setWindowNumber(iconList
.size());
1893 iconList
.push_back(w
);
1895 iconmenu
->insert((const char **) w
->getIconTitle());
1900 void BScreen::removeIcon(OpenboxWindow
*w
) {
1905 iconmenu
->remove(w
->getWindowNumber());
1908 winList::iterator it
= iconList
.begin();
1909 for (int i
= 0; it
!= iconList
.end(); ++it
, ++i
)
1910 (*it
)->setWindowNumber(i
);
1914 OpenboxWindow
*BScreen::getIcon(int index
) {
1915 if (index
< 0 || index
>= (signed)iconList
.size())
1916 return (OpenboxWindow
*) 0;
1918 winList::iterator it
= iconList
.begin();
1919 for (; index
> 0; --index
, ++it
); // increment to index
1924 int BScreen::addWorkspace(void) {
1925 Workspace
*wkspc
= new Workspace(*this, workspacesList
.size());
1926 workspacesList
.push_back(wkspc
);
1927 setWorkspaceCount(workspaceCount()+1);
1928 saveWorkspaceNames();
1930 workspacemenu
->insert(wkspc
->getName(), wkspc
->getMenu(),
1931 wkspc
->getWorkspaceID() + 2);
1932 workspacemenu
->update();
1934 toolbar
->reconfigure();
1936 updateNetizenWorkspaceCount();
1938 return workspacesList
.size();
1942 int BScreen::removeLastWorkspace(void) {
1943 if (workspacesList
.size() == 1)
1946 Workspace
*wkspc
= workspacesList
.back();
1948 if (current_workspace
->getWorkspaceID() == wkspc
->getWorkspaceID())
1949 changeWorkspaceID(current_workspace
->getWorkspaceID() - 1);
1953 workspacemenu
->remove(wkspc
->getWorkspaceID() + 2);
1954 workspacemenu
->update();
1956 workspacesList
.pop_back();
1959 setWorkspaceCount(workspaceCount()-1);
1960 saveWorkspaceNames();
1962 toolbar
->reconfigure();
1964 updateNetizenWorkspaceCount();
1966 return workspacesList
.size();
1970 void BScreen::changeWorkspaceID(int id
) {
1971 if (! current_workspace
) return;
1973 if (id
!= current_workspace
->getWorkspaceID()) {
1974 current_workspace
->hideAll();
1976 workspacemenu
->setItemSelected(current_workspace
->getWorkspaceID() + 2,
1979 OpenboxWindow
*fw
= openbox
.focusedWindow();
1980 if (fw
&& fw
->getScreen() == this)
1981 openbox
.focusWindow(0);
1983 current_workspace
= getWorkspace(id
);
1985 workspacemenu
->setItemSelected(current_workspace
->getWorkspaceID() + 2,
1987 toolbar
->redrawWorkspaceLabel(True
);
1989 current_workspace
->showAll();
1991 if (resource
.focus_last
&& current_workspace
->lastFocusedWindow()) {
1992 XSync(openbox
.getXDisplay(), False
);
1993 current_workspace
->lastFocusedWindow()->setInputFocus();
1997 updateNetizenCurrentWorkspace();
2001 void BScreen::addNetizen(Netizen
*n
) {
2002 netizenList
.push_back(n
);
2004 n
->sendWorkspaceCount();
2005 n
->sendCurrentWorkspace();
2007 wkspList::iterator it
;
2008 for (it
= workspacesList
.begin(); it
!= workspacesList
.end(); ++it
) {
2009 for (int i
= 0; i
< (*it
)->getCount(); i
++)
2010 n
->sendWindowAdd((*it
)->getWindow(i
)->getClientWindow(),
2011 (*it
)->getWorkspaceID());
2014 Window f
= ((openbox
.focusedWindow()) ?
2015 openbox
.focusedWindow()->getClientWindow() : None
);
2016 n
->sendWindowFocus(f
);
2020 void BScreen::removeNetizen(Window w
) {
2021 netList::iterator it
;
2023 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2024 if ((*it
)->getWindowID() == w
) {
2026 netizenList
.erase(it
);
2033 void BScreen::updateNetizenCurrentWorkspace(void) {
2034 netList::iterator it
;
2035 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2036 (*it
)->sendCurrentWorkspace();
2040 void BScreen::updateNetizenWorkspaceCount(void) {
2041 netList::iterator it
;
2042 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2043 (*it
)->sendWorkspaceCount();
2047 void BScreen::updateNetizenWindowFocus(void) {
2048 Window f
= ((openbox
.focusedWindow()) ?
2049 openbox
.focusedWindow()->getClientWindow() : None
);
2050 netList::iterator it
;
2051 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2052 (*it
)->sendWindowFocus(f
);
2056 void BScreen::updateNetizenWindowAdd(Window w
, unsigned long p
) {
2057 netList::iterator it
;
2058 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2059 (*it
)->sendWindowAdd(w
, p
);
2063 void BScreen::updateNetizenWindowDel(Window w
) {
2064 netList::iterator it
;
2065 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2066 (*it
)->sendWindowDel(w
);
2070 void BScreen::updateNetizenWindowRaise(Window w
) {
2071 netList::iterator it
;
2072 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2073 (*it
)->sendWindowRaise(w
);
2077 void BScreen::updateNetizenWindowLower(Window w
) {
2078 netList::iterator it
;
2079 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2080 (*it
)->sendWindowLower(w
);
2084 void BScreen::updateNetizenConfigNotify(XEvent
*e
) {
2085 netList::iterator it
;
2086 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2087 (*it
)->sendConfigNotify(e
);
2091 void BScreen::raiseWindows(Window
*workspace_stack
, int num
) {
2092 Window
*session_stack
= new
2093 Window
[(num
+ workspacesList
.size() + rootmenuList
.size() + 13)];
2096 XRaiseWindow(getBaseDisplay().getXDisplay(), iconmenu
->getWindowID());
2097 *(session_stack
+ i
++) = iconmenu
->getWindowID();
2099 wkspList::iterator it
;
2100 for (it
= workspacesList
.begin(); it
!= workspacesList
.end(); ++it
)
2101 *(session_stack
+ i
++) = (*it
)->getMenu()->getWindowID();
2103 *(session_stack
+ i
++) = workspacemenu
->getWindowID();
2105 *(session_stack
+ i
++) = configmenu
->getFocusmenu()->getWindowID();
2106 *(session_stack
+ i
++) = configmenu
->getPlacementmenu()->getWindowID();
2107 *(session_stack
+ i
++) = configmenu
->getWindowID();
2110 *(session_stack
+ i
++) = slit
->getMenu()->getDirectionmenu()->getWindowID();
2111 *(session_stack
+ i
++) = slit
->getMenu()->getPlacementmenu()->getWindowID();
2112 *(session_stack
+ i
++) = slit
->getMenu()->getWindowID();
2115 *(session_stack
+ i
++) =
2116 toolbar
->getMenu()->getPlacementmenu()->getWindowID();
2117 *(session_stack
+ i
++) = toolbar
->getMenu()->getWindowID();
2119 menuList::iterator rit
;
2120 for (rit
= rootmenuList
.begin(); rit
!= rootmenuList
.end(); ++rit
)
2121 *(session_stack
+ i
++) = (*rit
)->getWindowID();
2122 *(session_stack
+ i
++) = rootmenu
->getWindowID();
2124 if (toolbar
->onTop())
2125 *(session_stack
+ i
++) = toolbar
->getWindowID();
2129 *(session_stack
+ i
++) = slit
->getWindowID();
2133 *(session_stack
+ i
++) = *(workspace_stack
+ k
);
2135 XRestackWindows(getBaseDisplay().getXDisplay(), session_stack
, i
);
2137 delete [] session_stack
;
2141 void BScreen::addWorkspaceName(const char *name
) {
2142 workspaceNames
.push_back(name
);
2146 const char *BScreen::getNameOfWorkspace(int id
) {
2147 if (id
< 0 || id
>= (signed)workspaceNames
.size())
2148 return (const char *) 0;
2149 return workspaceNames
[id
].c_str();
2153 void BScreen::reassociateWindow(OpenboxWindow
*w
, int wkspc_id
, Bool ignore_sticky
) {
2157 wkspc_id
= current_workspace
->getWorkspaceID();
2159 if (w
->getWorkspaceNumber() == wkspc_id
)
2162 if (w
->isIconic()) {
2164 getWorkspace(wkspc_id
)->addWindow(w
);
2165 } else if (ignore_sticky
|| ! w
->isStuck()) {
2166 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
2167 getWorkspace(wkspc_id
)->addWindow(w
);
2172 void BScreen::nextFocus(void) {
2173 Bool have_focused
= False
;
2174 int focused_window_number
= -1;
2175 OpenboxWindow
*next
;
2177 if (openbox
.focusedWindow()) {
2178 if (openbox
.focusedWindow()->getScreen()->getScreenNumber() ==
2179 getScreenNumber()) {
2180 have_focused
= True
;
2181 focused_window_number
= openbox
.focusedWindow()->getWindowNumber();
2185 if ((getCurrentWorkspace()->getCount() > 1) && have_focused
) {
2186 int next_window_number
= focused_window_number
;
2188 if ((++next_window_number
) >= getCurrentWorkspace()->getCount())
2189 next_window_number
= 0;
2191 next
= getCurrentWorkspace()->getWindow(next_window_number
);
2192 } while ((! next
->setInputFocus()) && (next_window_number
!=
2193 focused_window_number
));
2195 if (next_window_number
!= focused_window_number
)
2196 getCurrentWorkspace()->raiseWindow(next
);
2197 } else if (getCurrentWorkspace()->getCount() >= 1) {
2198 next
= current_workspace
->getWindow(0);
2200 current_workspace
->raiseWindow(next
);
2201 next
->setInputFocus();
2206 void BScreen::prevFocus(void) {
2207 Bool have_focused
= False
;
2208 int focused_window_number
= -1;
2209 OpenboxWindow
*prev
;
2211 if (openbox
.focusedWindow()) {
2212 if (openbox
.focusedWindow()->getScreen()->getScreenNumber() ==
2213 getScreenNumber()) {
2214 have_focused
= True
;
2215 focused_window_number
= openbox
.focusedWindow()->getWindowNumber();
2219 if ((getCurrentWorkspace()->getCount() > 1) && have_focused
) {
2220 int prev_window_number
= focused_window_number
;
2222 if ((--prev_window_number
) < 0)
2223 prev_window_number
= getCurrentWorkspace()->getCount() - 1;
2225 prev
= getCurrentWorkspace()->getWindow(prev_window_number
);
2226 } while ((! prev
->setInputFocus()) && (prev_window_number
!=
2227 focused_window_number
));
2229 if (prev_window_number
!= focused_window_number
)
2230 getCurrentWorkspace()->raiseWindow(prev
);
2231 } else if (getCurrentWorkspace()->getCount() >= 1) {
2232 prev
= current_workspace
->getWindow(0);
2234 current_workspace
->raiseWindow(prev
);
2235 prev
->setInputFocus();
2240 void BScreen::raiseFocus(void) {
2241 Bool have_focused
= False
;
2242 int focused_window_number
= -1;
2244 if (openbox
.focusedWindow()) {
2245 if (openbox
.focusedWindow()->getScreen()->getScreenNumber() ==
2246 getScreenNumber()) {
2247 have_focused
= True
;
2248 focused_window_number
= openbox
.focusedWindow()->getWindowNumber();
2252 if ((getCurrentWorkspace()->getCount() > 1) && have_focused
)
2253 getWorkspace(openbox
.focusedWindow()->getWorkspaceNumber())->
2254 raiseWindow(openbox
.focusedWindow());
2258 void BScreen::InitMenu(void) {
2260 rootmenuList
.clear();
2261 while (rootmenu
->getCount())
2262 rootmenu
->remove(0);
2264 rootmenu
= new Rootmenu(*this);
2266 bool defaultMenu
= true;
2269 const char *menu_filename
= openbox
.getMenuFilename();
2271 if (!(menu_file
= fopen(menu_filename
, "r"))) {
2272 perror(menu_filename
);
2273 menu_filename
= (char *) 0;
2275 if (menu_filename
== (char *) 0) {
2276 // opening the menu file failed, try the DEFAULTMENU
2277 menu_filename
= DEFAULTMENU
;
2278 if (!(menu_file
= fopen(menu_filename
, "r"))) {
2279 perror(menu_filename
);
2280 menu_filename
= (char *) 0;
2284 if (menu_filename
) {
2285 if (feof(menu_file
)) {
2286 fprintf(stderr
, i18n(ScreenSet
, ScreenEmptyMenuFile
,
2287 "%s: Empty menu file"), menu_filename
);
2288 menu_filename
= (char *) 0;
2290 // successsfully opened a menu file
2291 char line
[1024], label
[1024];
2292 memset(line
, 0, 1024);
2293 memset(label
, 0, 1024);
2295 while (fgets(line
, 1024, menu_file
) && ! feof(menu_file
)) {
2296 if (line
[0] != '#') {
2297 int i
, key
= 0, index
= -1, len
= strlen(line
);
2300 for (i
= 0; i
< len
; i
++) {
2301 if (line
[i
] == '[') index
= 0;
2302 else if (line
[i
] == ']') break;
2303 else if (line
[i
] != ' ')
2305 key
+= tolower(line
[i
]);
2310 for (i
= index
; i
< len
; i
++) {
2311 if (line
[i
] == '(') index
= 0;
2312 else if (line
[i
] == ')') break;
2313 else if (index
++ >= 0) {
2314 if (line
[i
] == '\\' && i
< len
- 1) i
++;
2315 label
[index
- 1] = line
[i
];
2319 if (index
== -1) index
= 0;
2320 label
[index
] = '\0';
2322 rootmenu
->setLabel(label
);
2323 defaultMenu
= parseMenuFile(menu_file
, rootmenu
);
2325 openbox
.addMenuTimestamp(menu_filename
);
2335 rootmenu
->setInternalMenu();
2336 rootmenu
->insert(i18n(ScreenSet
, Screenxterm
, "xterm"),
2338 i18n(ScreenSet
, Screenxterm
, "xterm"));
2339 rootmenu
->insert(i18n(ScreenSet
, ScreenRestart
, "Restart"),
2341 rootmenu
->insert(i18n(ScreenSet
, ScreenExit
, "Exit"),
2347 Bool
BScreen::parseMenuFile(FILE *file
, Rootmenu
*menu
) {
2348 char line
[1024], label
[1024], command
[1024];
2350 while (! feof(file
)) {
2351 memset(line
, 0, 1024);
2352 memset(label
, 0, 1024);
2353 memset(command
, 0, 1024);
2355 if (fgets(line
, 1024, file
)) {
2356 if (line
[0] != '#') {
2357 register int i
, key
= 0, parse
= 0, index
= -1,
2358 line_length
= strlen(line
),
2359 label_length
= 0, command_length
= 0;
2361 // determine the keyword
2363 for (i
= 0; i
< line_length
; i
++) {
2364 if (line
[i
] == '[') parse
= 1;
2365 else if (line
[i
] == ']') break;
2366 else if (line
[i
] != ' ')
2368 key
+= tolower(line
[i
]);
2371 // get the label enclosed in ()'s
2374 for (i
= 0; i
< line_length
; i
++) {
2375 if (line
[i
] == '(') {
2378 } else if (line
[i
] == ')') break;
2379 else if (index
++ >= 0) {
2380 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
2381 label
[index
- 1] = line
[i
];
2386 label
[index
] = '\0';
2387 label_length
= index
;
2393 // get the command enclosed in {}'s
2396 for (i
= 0; i
< line_length
; i
++) {
2397 if (line
[i
] == '{') {
2400 } else if (line
[i
] == '}') break;
2401 else if (index
++ >= 0) {
2402 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
2403 command
[index
- 1] = line
[i
];
2408 command
[index
] = '\0';
2409 command_length
= index
;
2417 return ((menu
->getCount() == 0) ? True
: False
);
2422 menu
->insert(label
);
2427 if ((! *label
) && (! *command
)) {
2428 fprintf(stderr
, i18n(ScreenSet
, ScreenEXECError
,
2429 "BScreen::parseMenuFile: [exec] error, "
2430 "no menu label and/or command defined\n"));
2434 menu
->insert(label
, BScreen::Execute
, command
);
2440 fprintf(stderr
, i18n(ScreenSet
, ScreenEXITError
,
2441 "BScreen::parseMenuFile: [exit] error, "
2442 "no menu label defined\n"));
2446 menu
->insert(label
, BScreen::Exit
);
2452 if ((! *label
) || (! *command
)) {
2453 fprintf(stderr
, i18n(ScreenSet
, ScreenSTYLEError
,
2454 "BScreen::parseMenuFile: [style] error, "
2455 "no menu label and/or filename defined\n"));
2459 char style
[MAXPATHLEN
];
2461 // perform shell style ~ home directory expansion
2463 int homedir_len
= 0;
2464 if (*command
== '~' && *(command
+ 1) == '/') {
2465 homedir
= getenv("HOME");
2466 homedir_len
= strlen(homedir
);
2469 if (homedir
&& homedir_len
!= 0) {
2470 strncpy(style
, homedir
, homedir_len
);
2472 strncpy(style
+ homedir_len
, command
+ 1,
2473 command_length
- 1);
2474 *(style
+ command_length
+ homedir_len
- 1) = '\0';
2476 strncpy(style
, command
, command_length
);
2477 *(style
+ command_length
) = '\0';
2480 menu
->insert(label
, BScreen::SetStyle
, style
);
2487 fprintf(stderr
, i18n(ScreenSet
, ScreenCONFIGError
,
2488 "BScreen::parseMenufile: [config] error, "
2489 "no label defined"));
2493 menu
->insert(label
, configmenu
);
2497 case 740: // include
2500 fprintf(stderr
, i18n(ScreenSet
, ScreenINCLUDEError
,
2501 "BScreen::parseMenuFile: [include] error, "
2502 "no filename defined\n"));
2506 char newfile
[MAXPATHLEN
];
2508 // perform shell style ~ home directory expansion
2510 int homedir_len
= 0;
2511 if (*label
== '~' && *(label
+ 1) == '/') {
2512 homedir
= getenv("HOME");
2513 homedir_len
= strlen(homedir
);
2516 if (homedir
&& homedir_len
!= 0) {
2517 strncpy(newfile
, homedir
, homedir_len
);
2519 strncpy(newfile
+ homedir_len
, label
+ 1,
2521 *(newfile
+ label_length
+ homedir_len
- 1) = '\0';
2523 strncpy(newfile
, label
, label_length
);
2524 *(newfile
+ label_length
) = '\0';
2528 FILE *submenufile
= fopen(newfile
, "r");
2532 if (fstat(fileno(submenufile
), &buf
) ||
2533 (! S_ISREG(buf
.st_mode
))) {
2535 i18n(ScreenSet
, ScreenINCLUDEErrorReg
,
2536 "BScreen::parseMenuFile: [include] error: "
2537 "'%s' is not a regular file\n"), newfile
);
2541 if (! feof(submenufile
)) {
2542 if (!parseMenuFile(submenufile
, menu
))
2543 openbox
.addMenuTimestamp(newfile
);
2544 fclose(submenufile
);
2553 case 767: // submenu
2556 fprintf(stderr
, i18n(ScreenSet
, ScreenSUBMENUError
,
2557 "BScreen::parseMenuFile: [submenu] error, "
2558 "no menu label defined\n"));
2562 Rootmenu
*submenu
= new Rootmenu(*this);
2565 submenu
->setLabel(command
);
2567 submenu
->setLabel(label
);
2569 parseMenuFile(file
, submenu
);
2571 menu
->insert(label
, submenu
);
2572 rootmenuList
.push_back(submenu
);
2577 case 773: // restart
2580 fprintf(stderr
, i18n(ScreenSet
, ScreenRESTARTError
,
2581 "BScreen::parseMenuFile: [restart] error, "
2582 "no menu label defined\n"));
2587 menu
->insert(label
, BScreen::RestartOther
, command
);
2589 menu
->insert(label
, BScreen::Restart
);
2594 case 845: // reconfig
2597 fprintf(stderr
, i18n(ScreenSet
, ScreenRECONFIGError
,
2598 "BScreen::parseMenuFile: [reconfig] error, "
2599 "no menu label defined\n"));
2603 menu
->insert(label
, BScreen::Reconfigure
);
2608 case 995: // stylesdir
2609 case 1113: // stylesmenu
2611 Bool newmenu
= ((key
== 1113) ? True
: False
);
2613 if ((! *label
) || ((! *command
) && newmenu
)) {
2615 i18n(ScreenSet
, ScreenSTYLESDIRError
,
2616 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
2617 " error, no directory defined\n"));
2621 char stylesdir
[MAXPATHLEN
];
2623 char *directory
= ((newmenu
) ? command
: label
);
2624 int directory_length
= ((newmenu
) ? command_length
: label_length
);
2626 // perform shell style ~ home directory expansion
2628 int homedir_len
= 0;
2630 if (*directory
== '~' && *(directory
+ 1) == '/') {
2631 homedir
= getenv("HOME");
2632 homedir_len
= strlen(homedir
);
2635 if (homedir
&& homedir_len
!= 0) {
2636 strncpy(stylesdir
, homedir
, homedir_len
);
2638 strncpy(stylesdir
+ homedir_len
, directory
+ 1,
2639 directory_length
- 1);
2640 *(stylesdir
+ directory_length
+ homedir_len
- 1) = '\0';
2642 strncpy(stylesdir
, directory
, directory_length
);
2643 *(stylesdir
+ directory_length
) = '\0';
2646 struct stat statbuf
;
2648 if (! stat(stylesdir
, &statbuf
)) {
2649 if (S_ISDIR(statbuf
.st_mode
)) {
2650 Rootmenu
*stylesmenu
;
2653 stylesmenu
= new Rootmenu(*this);
2657 DIR *d
= opendir(stylesdir
);
2661 // get the total number of directory entries
2662 while ((p
= readdir(d
))) entries
++;
2665 char **ls
= new char* [entries
];
2667 while ((p
= readdir(d
)))
2668 ls
[index
++] = bstrdup(p
->d_name
);
2672 std::sort(ls
, ls
+ entries
, dcmp());
2674 int n
, slen
= strlen(stylesdir
);
2675 for (n
= 0; n
< entries
; n
++) {
2676 if (ls
[n
][strlen(ls
[n
])-1] != '~') {
2677 int nlen
= strlen(ls
[n
]);
2678 char style
[MAXPATHLEN
+ 1];
2680 strncpy(style
, stylesdir
, slen
);
2681 *(style
+ slen
) = '/';
2682 strncpy(style
+ slen
+ 1, ls
[n
], nlen
+ 1);
2684 if ((! stat(style
, &statbuf
)) && S_ISREG(statbuf
.st_mode
))
2685 stylesmenu
->insert(ls
[n
], BScreen::SetStyle
, style
);
2693 stylesmenu
->update();
2696 stylesmenu
->setLabel(label
);
2697 menu
->insert(label
, stylesmenu
);
2698 rootmenuList
.push_back(stylesmenu
);
2700 openbox
.addMenuTimestamp(stylesdir
);
2702 fprintf(stderr
, i18n(ScreenSet
,
2703 ScreenSTYLESDIRErrorNotDir
,
2704 "BScreen::parseMenuFile:"
2705 " [stylesdir/stylesmenu] error, %s is not a"
2706 " directory\n"), stylesdir
);
2710 i18n(ScreenSet
, ScreenSTYLESDIRErrorNoExist
,
2711 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
2712 " error, %s does not exist\n"), stylesdir
);
2718 case 1090: // workspaces
2722 i18n(ScreenSet
, ScreenWORKSPACESError
,
2723 "BScreen:parseMenuFile: [workspaces] error, "
2724 "no menu label defined\n"));
2728 menu
->insert(label
, workspacemenu
);
2737 return ((menu
->getCount() == 0) ? True
: False
);
2741 void BScreen::shutdown(void) {
2744 XSelectInput(getBaseDisplay().getXDisplay(), getRootWindow(), NoEventMask
);
2745 XSync(getBaseDisplay().getXDisplay(), False
);
2747 std::for_each(workspacesList
.begin(), workspacesList
.end(),
2748 std::mem_fun(&Workspace::shutdown
));
2750 while (!iconList
.empty())
2751 iconList
.front()->restore();
2761 void BScreen::showPosition(int x
, int y
) {
2762 if (! geom_visible
) {
2763 XMoveResizeWindow(getBaseDisplay().getXDisplay(), geom_window
,
2764 (size().w() - geom_w
) / 2,
2765 (size().h() - geom_h
) / 2, geom_w
, geom_h
);
2766 XMapWindow(getBaseDisplay().getXDisplay(), geom_window
);
2767 XRaiseWindow(getBaseDisplay().getXDisplay(), geom_window
);
2769 geom_visible
= True
;
2774 sprintf(label
, i18n(ScreenSet
, ScreenPositionFormat
,
2775 "X: %4d x Y: %4d"), x
, y
);
2777 XClearWindow(getBaseDisplay().getXDisplay(), geom_window
);
2779 if (i18n
.multibyte()) {
2780 XmbDrawString(getBaseDisplay().getXDisplay(), geom_window
,
2781 resource
.wstyle
.fontset
, resource
.wstyle
.l_text_focus_gc
,
2782 resource
.bevel_width
, resource
.bevel_width
-
2783 resource
.wstyle
.fontset_extents
->max_ink_extent
.y
,
2784 label
, strlen(label
));
2786 XDrawString(getBaseDisplay().getXDisplay(), geom_window
,
2787 resource
.wstyle
.l_text_focus_gc
,
2788 resource
.bevel_width
,
2789 resource
.wstyle
.font
->ascent
+
2790 resource
.bevel_width
, label
, strlen(label
));
2795 void BScreen::showGeometry(unsigned int gx
, unsigned int gy
) {
2796 if (! geom_visible
) {
2797 XMoveResizeWindow(getBaseDisplay().getXDisplay(), geom_window
,
2798 (size().w() - geom_w
) / 2,
2799 (size().h() - geom_h
) / 2, geom_w
, geom_h
);
2800 XMapWindow(getBaseDisplay().getXDisplay(), geom_window
);
2801 XRaiseWindow(getBaseDisplay().getXDisplay(), geom_window
);
2803 geom_visible
= True
;
2808 sprintf(label
, i18n(ScreenSet
, ScreenGeometryFormat
,
2809 "W: %4d x H: %4d"), gx
, gy
);
2811 XClearWindow(getBaseDisplay().getXDisplay(), geom_window
);
2813 if (i18n
.multibyte()) {
2814 XmbDrawString(getBaseDisplay().getXDisplay(), geom_window
,
2815 resource
.wstyle
.fontset
, resource
.wstyle
.l_text_focus_gc
,
2816 resource
.bevel_width
, resource
.bevel_width
-
2817 resource
.wstyle
.fontset_extents
->max_ink_extent
.y
,
2818 label
, strlen(label
));
2820 XDrawString(getBaseDisplay().getXDisplay(), geom_window
,
2821 resource
.wstyle
.l_text_focus_gc
,
2822 resource
.bevel_width
,
2823 resource
.wstyle
.font
->ascent
+
2824 resource
.bevel_width
, label
, strlen(label
));
2828 void BScreen::hideGeometry(void) {
2830 XUnmapWindow(getBaseDisplay().getXDisplay(), geom_window
);
2831 geom_visible
= False
;