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
108 static Bool running
= True
;
110 static int anotherWMRunning(Display
*display
, XErrorEvent
*) {
111 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenAnotherWMRunning
,
112 "BScreen::BScreen: an error occured while querying the X server.\n"
113 " another window manager already running on display %s.\n"),
114 DisplayString(display
));
122 bool operator()(const char *one
, const char *two
) const {
123 return (strcmp(one
, two
) < 0) ? True
: False
;
127 #ifndef HAVE_STRCASESTR
128 static const char * strcasestr(const char *str
, const char *ptn
) {
130 for( ; *str
; str
++) {
131 for(s2
=str
,p2
=ptn
; ; s2
++,p2
++) {
132 if (!*p2
) return str
;
133 if (toupper(*s2
) != toupper(*p2
)) break;
138 #endif // HAVE_STRCASESTR
140 static const char *getFontElement(const char *pattern
, char *buf
, int bufsiz
, ...) {
145 va_start(va
, bufsiz
);
148 while((v
= va_arg(va
, char *)) != NULL
) {
149 p
= strcasestr(pattern
, v
);
151 strncpy(buf
, p
+1, bufsiz
-2);
152 p2
= strchr(buf
, '-');
159 strncpy(buf
, "*", bufsiz
);
163 static const char *getFontSize(const char *pattern
, int *size
) {
168 for (p
=pattern
; 1; p
++) {
170 if (p2
!=NULL
&& n
>1 && n
<72) {
171 *size
= n
; return p2
+1;
173 *size
= 16; return NULL
;
175 } else if (*p
=='-') {
176 if (n
>1 && n
<72 && p2
!=NULL
) {
181 } else if (*p
>='0' && *p
<='9' && p2
!=NULL
) {
191 BScreen::BScreen(Openbox
&ob
, int scrn
, Resource
&conf
) : ScreenInfo(ob
, scrn
),
192 openbox(ob
), config(conf
)
194 event_mask
= ColormapChangeMask
| EnterWindowMask
| PropertyChangeMask
|
195 SubstructureRedirectMask
| KeyPressMask
| KeyReleaseMask
|
196 ButtonPressMask
| ButtonReleaseMask
;
198 XErrorHandler old
= XSetErrorHandler((XErrorHandler
) anotherWMRunning
);
199 XSelectInput(getBaseDisplay().getXDisplay(), getRootWindow(), event_mask
);
200 XSync(getBaseDisplay().getXDisplay(), False
);
201 XSetErrorHandler((XErrorHandler
) old
);
204 if (! managed
) return;
206 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenManagingScreen
,
207 "BScreen::BScreen: managing screen %d "
208 "using visual 0x%lx, depth %d\n"),
209 getScreenNumber(), XVisualIDFromVisual(getVisual()),
214 resource
.mstyle
.t_fontset
= resource
.mstyle
.f_fontset
=
215 resource
.tstyle
.fontset
= resource
.wstyle
.fontset
= NULL
;
216 resource
.mstyle
.t_font
= resource
.mstyle
.f_font
= resource
.tstyle
.font
=
217 resource
.wstyle
.font
= NULL
;
218 resource
.root_command
= NULL
;
220 resource
.strftime_format
= NULL
;
221 #endif // HAVE_STRFTIME
229 pid_t bpid
= getpid();
231 XChangeProperty(getBaseDisplay().getXDisplay(), getRootWindow(),
232 openbox
.getOpenboxPidAtom(), XA_CARDINAL
,
233 sizeof(pid_t
) * 8, PropModeReplace
,
234 (unsigned char *) &bpid
, 1);
235 #endif // HAVE_GETPID
237 XDefineCursor(getBaseDisplay().getXDisplay(), getRootWindow(),
238 openbox
.getSessionCursor());
240 workspaceNames
= new LinkedList
<char>;
241 workspacesList
= new LinkedList
<Workspace
>;
242 iconList
= new LinkedList
<OpenboxWindow
>;
245 new BImageControl(openbox
, *this, True
, openbox
.getColorsPerChannel(),
246 openbox
.getCacheLife(), openbox
.getCacheMax());
247 image_control
->installRootColormap();
248 root_colormap_installed
= True
;
250 load(); // load config options from Resources
254 unsigned long gc_value_mask
= GCForeground
;
255 if (! i18n
->multibyte()) gc_value_mask
|= GCFont
;
257 gcv
.foreground
= WhitePixel(getBaseDisplay().getXDisplay(),
259 ^ BlackPixel(getBaseDisplay().getXDisplay(),
261 gcv
.function
= GXxor
;
262 gcv
.subwindow_mode
= IncludeInferiors
;
263 opGC
= XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
264 GCForeground
| GCFunction
| GCSubwindowMode
, &gcv
);
266 gcv
.foreground
= resource
.wstyle
.l_text_focus
.getPixel();
267 if (resource
.wstyle
.font
)
268 gcv
.font
= resource
.wstyle
.font
->fid
;
269 resource
.wstyle
.l_text_focus_gc
=
270 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
271 gc_value_mask
, &gcv
);
273 gcv
.foreground
= resource
.wstyle
.l_text_unfocus
.getPixel();
274 if (resource
.wstyle
.font
)
275 gcv
.font
= resource
.wstyle
.font
->fid
;
276 resource
.wstyle
.l_text_unfocus_gc
=
277 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
278 gc_value_mask
, &gcv
);
280 gcv
.foreground
= resource
.wstyle
.b_pic_focus
.getPixel();
281 resource
.wstyle
.b_pic_focus_gc
=
282 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
285 gcv
.foreground
= resource
.wstyle
.b_pic_unfocus
.getPixel();
286 resource
.wstyle
.b_pic_unfocus_gc
=
287 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
290 gcv
.foreground
= resource
.mstyle
.t_text
.getPixel();
291 if (resource
.mstyle
.t_font
)
292 gcv
.font
= resource
.mstyle
.t_font
->fid
;
293 resource
.mstyle
.t_text_gc
=
294 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
295 gc_value_mask
, &gcv
);
297 gcv
.foreground
= resource
.mstyle
.f_text
.getPixel();
298 if (resource
.mstyle
.f_font
)
299 gcv
.font
= resource
.mstyle
.f_font
->fid
;
300 resource
.mstyle
.f_text_gc
=
301 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
302 gc_value_mask
, &gcv
);
304 gcv
.foreground
= resource
.mstyle
.h_text
.getPixel();
305 resource
.mstyle
.h_text_gc
=
306 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
307 gc_value_mask
, &gcv
);
309 gcv
.foreground
= resource
.mstyle
.d_text
.getPixel();
310 resource
.mstyle
.d_text_gc
=
311 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
312 gc_value_mask
, &gcv
);
314 gcv
.foreground
= resource
.mstyle
.hilite
.getColor()->getPixel();
315 resource
.mstyle
.hilite_gc
=
316 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
317 gc_value_mask
, &gcv
);
319 gcv
.foreground
= resource
.tstyle
.l_text
.getPixel();
320 if (resource
.tstyle
.font
)
321 gcv
.font
= resource
.tstyle
.font
->fid
;
322 resource
.tstyle
.l_text_gc
=
323 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
324 gc_value_mask
, &gcv
);
326 gcv
.foreground
= resource
.tstyle
.w_text
.getPixel();
327 resource
.tstyle
.w_text_gc
=
328 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
329 gc_value_mask
, &gcv
);
331 gcv
.foreground
= resource
.tstyle
.c_text
.getPixel();
332 resource
.tstyle
.c_text_gc
=
333 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
334 gc_value_mask
, &gcv
);
336 gcv
.foreground
= resource
.tstyle
.b_pic
.getPixel();
337 resource
.tstyle
.b_pic_gc
=
338 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
339 gc_value_mask
, &gcv
);
341 const char *s
= i18n
->getMessage(ScreenSet
, ScreenPositionLength
,
342 "0: 0000 x 0: 0000");
345 if (i18n
->multibyte()) {
346 XRectangle ink
, logical
;
347 XmbTextExtents(resource
.wstyle
.fontset
, s
, l
, &ink
, &logical
);
348 geom_w
= logical
.width
;
350 geom_h
= resource
.wstyle
.fontset_extents
->max_ink_extent
.height
;
352 geom_h
= resource
.wstyle
.font
->ascent
+
353 resource
.wstyle
.font
->descent
;
355 geom_w
= XTextWidth(resource
.wstyle
.font
, s
, l
);
358 geom_w
+= (resource
.bevel_width
* 2);
359 geom_h
+= (resource
.bevel_width
* 2);
361 XSetWindowAttributes attrib
;
362 unsigned long mask
= CWBorderPixel
| CWColormap
| CWSaveUnder
;
363 attrib
.border_pixel
= getBorderColor()->getPixel();
364 attrib
.colormap
= getColormap();
365 attrib
.save_under
= True
;
368 XCreateWindow(getBaseDisplay().getXDisplay(), getRootWindow(),
369 0, 0, geom_w
, geom_h
, resource
.border_width
, getDepth(),
370 InputOutput
, getVisual(), mask
, &attrib
);
371 geom_visible
= False
;
373 if (resource
.wstyle
.l_focus
.getTexture() & BImage_ParentRelative
) {
374 if (resource
.wstyle
.t_focus
.getTexture() ==
375 (BImage_Flat
| BImage_Solid
)) {
377 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window
,
378 resource
.wstyle
.t_focus
.getColor()->getPixel());
380 geom_pixmap
= image_control
->renderImage(geom_w
, geom_h
,
381 &resource
.wstyle
.t_focus
);
382 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
383 geom_window
, geom_pixmap
);
386 if (resource
.wstyle
.l_focus
.getTexture() ==
387 (BImage_Flat
| BImage_Solid
)) {
389 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window
,
390 resource
.wstyle
.l_focus
.getColor()->getPixel());
392 geom_pixmap
= image_control
->renderImage(geom_w
, geom_h
,
393 &resource
.wstyle
.l_focus
);
394 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
395 geom_window
, geom_pixmap
);
399 workspacemenu
= new Workspacemenu(*this);
400 iconmenu
= new Iconmenu(*this);
401 configmenu
= new Configmenu(*this);
403 Workspace
*wkspc
= NULL
;
404 if (resource
.workspaces
!= 0) {
405 for (int i
= 0; i
< resource
.workspaces
; ++i
) {
406 wkspc
= new Workspace(*this, workspacesList
->count());
407 workspacesList
->insert(wkspc
);
408 workspacemenu
->insert(wkspc
->getName(), wkspc
->getMenu());
411 wkspc
= new Workspace(*this, workspacesList
->count());
412 workspacesList
->insert(wkspc
);
413 workspacemenu
->insert(wkspc
->getName(), wkspc
->getMenu());
415 saveWorkspaceNames();
417 workspacemenu
->insert(i18n
->getMessage(IconSet
, IconIcons
, "Icons"),
419 workspacemenu
->update();
421 current_workspace
= workspacesList
->first();
422 workspacemenu
->setItemSelected(2, True
);
424 toolbar
= new Toolbar(*this, config
);
427 slit
= new Slit(*this, config
);
435 changeWorkspaceID(0);
439 Window r
, p
, *children
;
440 XQueryTree(getBaseDisplay().getXDisplay(), getRootWindow(), &r
, &p
,
443 // preen the window list of all icon windows... for better dockapp support
444 for (i
= 0; i
< (int) nchild
; i
++) {
445 if (children
[i
] == None
) continue;
447 XWMHints
*wmhints
= XGetWMHints(getBaseDisplay().getXDisplay(),
451 if ((wmhints
->flags
& IconWindowHint
) &&
452 (wmhints
->icon_window
!= children
[i
]))
453 for (int j
= 0; j
< (int) nchild
; j
++)
454 if (children
[j
] == wmhints
->icon_window
) {
464 // manage shown windows
465 for (i
= 0; i
< (int) nchild
; ++i
) {
466 if (children
[i
] == None
|| (! openbox
.validateWindow(children
[i
])))
469 XWindowAttributes attrib
;
470 if (XGetWindowAttributes(getBaseDisplay().getXDisplay(), children
[i
],
472 if (attrib
.override_redirect
) continue;
474 if (attrib
.map_state
!= IsUnmapped
) {
475 new OpenboxWindow(openbox
, children
[i
], this);
477 OpenboxWindow
*win
= openbox
.searchWindow(children
[i
]);
479 XMapRequestEvent mre
;
480 mre
.window
= children
[i
];
481 win
->restoreAttributes();
482 win
->mapRequestEvent(&mre
);
488 XSetInputFocus(getBaseDisplay().getXDisplay(),
489 PointerRoot
, None
, CurrentTime
);
492 XFlush(getBaseDisplay().getXDisplay());
496 BScreen::~BScreen(void) {
497 if (! managed
) return;
499 if (geom_pixmap
!= None
)
500 image_control
->removeImage(geom_pixmap
);
502 if (geom_window
!= None
)
503 XDestroyWindow(getBaseDisplay().getXDisplay(), geom_window
);
505 removeWorkspaceNames();
507 while (workspacesList
->count())
508 delete workspacesList
->remove(0);
510 while (!rootmenuList
.empty())
511 rootmenuList
.erase(rootmenuList
.begin());
513 while (iconList
->count())
514 delete iconList
->remove(0);
516 while (!netizenList
.empty())
517 netizenList
.erase(netizenList
.begin());
520 if (resource
.strftime_format
)
521 delete [] resource
.strftime_format
;
522 #endif // HAVE_STRFTIME
525 delete workspacemenu
;
534 delete image_control
;
536 delete workspacesList
;
537 delete workspaceNames
;
540 if (resource
.wstyle
.fontset
)
541 XFreeFontSet(getBaseDisplay().getXDisplay(), resource
.wstyle
.fontset
);
542 if (resource
.mstyle
.t_fontset
)
543 XFreeFontSet(getBaseDisplay().getXDisplay(), resource
.mstyle
.t_fontset
);
544 if (resource
.mstyle
.f_fontset
)
545 XFreeFontSet(getBaseDisplay().getXDisplay(), resource
.mstyle
.f_fontset
);
546 if (resource
.tstyle
.fontset
)
547 XFreeFontSet(getBaseDisplay().getXDisplay(), resource
.tstyle
.fontset
);
549 if (resource
.wstyle
.font
)
550 XFreeFont(getBaseDisplay().getXDisplay(), resource
.wstyle
.font
);
551 if (resource
.mstyle
.t_font
)
552 XFreeFont(getBaseDisplay().getXDisplay(), resource
.mstyle
.t_font
);
553 if (resource
.mstyle
.f_font
)
554 XFreeFont(getBaseDisplay().getXDisplay(), resource
.mstyle
.f_font
);
555 if (resource
.tstyle
.font
)
556 XFreeFont(getBaseDisplay().getXDisplay(), resource
.tstyle
.font
);
557 if (resource
.root_command
!= NULL
)
558 delete [] resource
.root_command
;
560 XFreeGC(getBaseDisplay().getXDisplay(), opGC
);
562 XFreeGC(getBaseDisplay().getXDisplay(),
563 resource
.wstyle
.l_text_focus_gc
);
564 XFreeGC(getBaseDisplay().getXDisplay(),
565 resource
.wstyle
.l_text_unfocus_gc
);
566 XFreeGC(getBaseDisplay().getXDisplay(),
567 resource
.wstyle
.b_pic_focus_gc
);
568 XFreeGC(getBaseDisplay().getXDisplay(),
569 resource
.wstyle
.b_pic_unfocus_gc
);
571 XFreeGC(getBaseDisplay().getXDisplay(),
572 resource
.mstyle
.t_text_gc
);
573 XFreeGC(getBaseDisplay().getXDisplay(),
574 resource
.mstyle
.f_text_gc
);
575 XFreeGC(getBaseDisplay().getXDisplay(),
576 resource
.mstyle
.h_text_gc
);
577 XFreeGC(getBaseDisplay().getXDisplay(),
578 resource
.mstyle
.d_text_gc
);
579 XFreeGC(getBaseDisplay().getXDisplay(),
580 resource
.mstyle
.hilite_gc
);
582 XFreeGC(getBaseDisplay().getXDisplay(),
583 resource
.tstyle
.l_text_gc
);
584 XFreeGC(getBaseDisplay().getXDisplay(),
585 resource
.tstyle
.w_text_gc
);
586 XFreeGC(getBaseDisplay().getXDisplay(),
587 resource
.tstyle
.c_text_gc
);
588 XFreeGC(getBaseDisplay().getXDisplay(),
589 resource
.tstyle
.b_pic_gc
);
593 Rect
BScreen::availableArea() const {
594 // the following code is temporary and will be taken care of by Screen in the
595 // future (with the NETWM 'strut')
596 Rect
space(0, 0, size().w(), size().h());
597 if (!resource
.full_max
) {
599 int slit_x
= slit
->autoHide() ? slit
->hiddenOrigin().x() : slit
->area().x(),
600 slit_y
= slit
->autoHide() ? slit
->hiddenOrigin().y() : slit
->area().y();
601 int tbarh
= resource
.hide_toolbar
? 0 :
602 toolbar
->getExposedHeight() + resource
.border_width
* 2;
604 switch (toolbar
->placement()) {
605 case Toolbar::TopLeft
:
606 case Toolbar::TopCenter
:
607 case Toolbar::TopRight
:
610 case Toolbar::BottomLeft
:
611 case Toolbar::BottomCenter
:
612 case Toolbar::BottomRight
:
616 ASSERT(false); // unhandled placement
618 if ((slit
->direction() == Slit::Horizontal
&&
619 (slit
->placement() == Slit::TopLeft
||
620 slit
->placement() == Slit::TopRight
)) ||
621 slit
->placement() == Slit::TopCenter
) {
623 if (tbartop
&& slit_y
+ slit
->area().h() < tbarh
) {
624 space
.setY(space
.y() + tbarh
);
625 space
.setH(space
.h() - tbarh
);
627 space
.setY(space
.y() + (slit_y
+ slit
->area().h() +
628 resource
.border_width
* 2));
629 space
.setH(space
.h() - (slit_y
+ slit
->area().h() +
630 resource
.border_width
* 2));
632 space
.setH(space
.h() - tbarh
);
634 } else if ((slit
->direction() == Slit::Vertical
&&
635 (slit
->placement() == Slit::TopRight
||
636 slit
->placement() == Slit::BottomRight
)) ||
637 slit
->placement() == Slit::CenterRight
) {
639 space
.setW(space
.w() - (size().w() - slit_x
));
641 space
.setY(space
.y() + tbarh
);
642 space
.setH(space
.h() - tbarh
);
643 } else if ((slit
->direction() == Slit::Horizontal
&&
644 (slit
->placement() == Slit::BottomLeft
||
645 slit
->placement() == Slit::BottomRight
)) ||
646 slit
->placement() == Slit::BottomCenter
) {
648 if (!tbartop
&& (size().h() - slit_y
) < tbarh
) {
649 space
.setH(space
.h() - tbarh
);
651 space
.setH(space
.h() - (size().h() - slit_y
));
653 space
.setY(space
.y() + tbarh
);
654 space
.setH(space
.h() - tbarh
);
657 } else {// if ((slit->direction() == Slit::Vertical &&
658 // (slit->placement() == Slit::TopLeft ||
659 // slit->placement() == Slit::BottomLeft)) ||
660 // slit->placement() == Slit::CenterLeft)
662 space
.setX(slit_x
+ slit
->area().w() +
663 resource
.border_width
* 2);
664 space
.setW(space
.w() - (slit_x
+ slit
->area().w() +
665 resource
.border_width
* 2));
667 space
.setY(space
.y() + tbarh
);
668 space
.setH(space
.h() - tbarh
);
671 int tbarh
= resource
.hide_toolbar() ? 0 :
672 toolbar
->getExposedHeight() + resource
.border_width
* 2;
673 switch (toolbar
->placement()) {
674 case Toolbar::TopLeft
:
675 case Toolbar::TopCenter
:
676 case Toolbar::TopRight
:
677 space
.setY(toolbar
->getExposedHeight());
678 space
.setH(space
.h() - toolbar
->getExposedHeight());
680 case Toolbar::BottomLeft
:
681 case Toolbar::BottomCenter
:
682 case Toolbar::BottomRight
:
683 space
.setH(space
.h() - tbarh
);
686 ASSERT(false); // unhandled placement
694 void BScreen::readDatabaseTexture(const char *rname
, const char *rclass
,
696 unsigned long default_pixel
)
700 if (resource
.styleconfig
.getValue(rname
, rclass
, s
))
701 image_control
->parseTexture(texture
, s
.c_str());
703 texture
->setTexture(BImage_Solid
| BImage_Flat
);
705 if (texture
->getTexture() & BImage_Solid
) {
706 int clen
= strlen(rclass
) + 32, nlen
= strlen(rname
) + 32;
708 char *colorclass
= new char[clen
], *colorname
= new char[nlen
];
710 sprintf(colorclass
, "%s.Color", rclass
);
711 sprintf(colorname
, "%s.color", rname
);
713 readDatabaseColor(colorname
, colorclass
, texture
->getColor(),
717 sprintf(colorclass
, "%s.ColorTo", rclass
);
718 sprintf(colorname
, "%s.colorTo", rname
);
720 readDatabaseColor(colorname
, colorclass
, texture
->getColorTo(),
724 delete [] colorclass
;
727 if ((! texture
->getColor()->isAllocated()) ||
728 (texture
->getTexture() & BImage_Flat
))
733 xcol
.red
= (unsigned int) (texture
->getColor()->getRed() +
734 (texture
->getColor()->getRed() >> 1));
735 if (xcol
.red
>= 0xff) xcol
.red
= 0xffff;
736 else xcol
.red
*= 0xff;
737 xcol
.green
= (unsigned int) (texture
->getColor()->getGreen() +
738 (texture
->getColor()->getGreen() >> 1));
739 if (xcol
.green
>= 0xff) xcol
.green
= 0xffff;
740 else xcol
.green
*= 0xff;
741 xcol
.blue
= (unsigned int) (texture
->getColor()->getBlue() +
742 (texture
->getColor()->getBlue() >> 1));
743 if (xcol
.blue
>= 0xff) xcol
.blue
= 0xffff;
744 else xcol
.blue
*= 0xff;
746 if (! XAllocColor(getBaseDisplay().getXDisplay(),
747 getColormap(), &xcol
))
750 texture
->getHiColor()->setPixel(xcol
.pixel
);
753 (unsigned int) ((texture
->getColor()->getRed() >> 2) +
754 (texture
->getColor()->getRed() >> 1)) * 0xff;
756 (unsigned int) ((texture
->getColor()->getGreen() >> 2) +
757 (texture
->getColor()->getGreen() >> 1)) * 0xff;
759 (unsigned int) ((texture
->getColor()->getBlue() >> 2) +
760 (texture
->getColor()->getBlue() >> 1)) * 0xff;
762 if (! XAllocColor(getBaseDisplay().getXDisplay(),
763 getColormap(), &xcol
))
766 texture
->getLoColor()->setPixel(xcol
.pixel
);
767 } else if (texture
->getTexture() & BImage_Gradient
) {
768 int clen
= strlen(rclass
) + 10, nlen
= strlen(rname
) + 10;
770 char *colorclass
= new char[clen
], *colorname
= new char[nlen
],
771 *colortoclass
= new char[clen
], *colortoname
= new char[nlen
];
773 sprintf(colorclass
, "%s.Color", rclass
);
774 sprintf(colorname
, "%s.color", rname
);
776 sprintf(colortoclass
, "%s.ColorTo", rclass
);
777 sprintf(colortoname
, "%s.colorTo", rname
);
779 readDatabaseColor(colorname
, colorclass
, texture
->getColor(),
781 readDatabaseColor(colortoname
, colortoclass
, texture
->getColorTo(),
784 delete [] colorclass
;
786 delete [] colortoclass
;
787 delete [] colortoname
;
792 void BScreen::readDatabaseColor(const char *rname
, const char *rclass
,
793 BColor
*color
, unsigned long default_pixel
)
797 if (resource
.styleconfig
.getValue(rname
, rclass
, s
))
798 image_control
->parseColor(color
, s
.c_str());
800 // parsing with no color std::string just deallocates the color, if it has
801 // been previously allocated
802 image_control
->parseColor(color
);
803 color
->setPixel(default_pixel
);
808 void BScreen::readDatabaseFontSet(const char *rname
, const char *rclass
,
810 if (! fontset
) return;
812 static char *defaultFont
= "fixed";
813 bool load_default
= false;
817 XFreeFontSet(getBaseDisplay().getXDisplay(), *fontset
);
819 if (resource
.styleconfig
.getValue(rname
, rclass
, s
)) {
820 if (! (*fontset
= createFontSet(s
.c_str())))
826 *fontset
= createFontSet(defaultFont
);
829 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenDefaultFontLoadFail
,
830 "BScreen::LoadStyle(): couldn't load default font.\n"));
837 void BScreen::readDatabaseFont(const char *rname
, const char *rclass
,
838 XFontStruct
**font
) {
841 static char *defaultFont
= "fixed";
842 bool load_default
= false;
846 XFreeFont(getBaseDisplay().getXDisplay(), *font
);
848 if (resource
.styleconfig
.getValue(rname
, rclass
, s
)) {
849 if ((*font
= XLoadQueryFont(getBaseDisplay().getXDisplay(),
850 s
.c_str())) == NULL
) {
851 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenFontLoadFail
,
852 "BScreen::LoadStyle(): couldn't load font '%s'\n"),
860 if ((*font
= XLoadQueryFont(getBaseDisplay().getXDisplay(),
861 defaultFont
)) == NULL
) {
862 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenDefaultFontLoadFail
,
863 "BScreen::LoadStyle(): couldn't load default font.\n"));
870 XFontSet
BScreen::createFontSet(const char *fontname
) {
872 char **missing
, *def
= "-";
873 int nmissing
, pixel_size
= 0, buf_size
= 0;
874 char weight
[FONT_ELEMENT_SIZE
], slant
[FONT_ELEMENT_SIZE
];
876 fs
= XCreateFontSet(getBaseDisplay().getXDisplay(),
877 fontname
, &missing
, &nmissing
, &def
);
878 if (fs
&& (! nmissing
)) return fs
;
880 #ifdef HAVE_SETLOCALE
882 if (nmissing
) XFreeStringList(missing
);
884 setlocale(LC_CTYPE
, "C");
885 fs
= XCreateFontSet(getBaseDisplay().getXDisplay(), fontname
,
886 &missing
, &nmissing
, &def
);
887 setlocale(LC_CTYPE
, "");
889 #endif // HAVE_SETLOCALE
892 XFontStruct
**fontstructs
;
894 XFontsOfFontSet(fs
, &fontstructs
, &fontnames
);
895 fontname
= fontnames
[0];
898 getFontElement(fontname
, weight
, FONT_ELEMENT_SIZE
,
899 "-medium-", "-bold-", "-demibold-", "-regular-", NULL
);
900 getFontElement(fontname
, slant
, FONT_ELEMENT_SIZE
,
901 "-r-", "-i-", "-o-", "-ri-", "-ro-", NULL
);
902 getFontSize(fontname
, &pixel_size
);
904 if (! strcmp(weight
, "*")) strncpy(weight
, "medium", FONT_ELEMENT_SIZE
);
905 if (! strcmp(slant
, "*")) strncpy(slant
, "r", FONT_ELEMENT_SIZE
);
906 if (pixel_size
< 3) pixel_size
= 3;
907 else if (pixel_size
> 97) pixel_size
= 97;
909 buf_size
= strlen(fontname
) + (FONT_ELEMENT_SIZE
* 2) + 64;
910 char *pattern2
= new char[buf_size
];
911 snprintf(pattern2
, buf_size
- 1,
913 "-*-*-%s-%s-*-*-%d-*-*-*-*-*-*-*,"
914 "-*-*-*-*-*-*-%d-*-*-*-*-*-*-*,*",
915 fontname
, weight
, slant
, pixel_size
, pixel_size
);
918 if (nmissing
) XFreeStringList(missing
);
919 if (fs
) XFreeFontSet(getBaseDisplay().getXDisplay(), fs
);
921 fs
= XCreateFontSet(getBaseDisplay().getXDisplay(), fontname
,
922 &missing
, &nmissing
, &def
);
929 void BScreen::setSloppyFocus(bool b
) {
930 resource
.sloppy_focus
= b
;
932 s
<< "session.screen" << getScreenNumber() << ".focusModel" << ends
;
933 config
.setValue(s
.str(),
934 (resource
.sloppy_focus
?
935 (resource
.auto_raise
? "AutoRaiseSloppyFocus" : "SloppyFocus")
937 s
.rdbuf()->freeze(0);
941 void BScreen::setAutoRaise(bool a
) {
942 resource
.auto_raise
= a
;
944 s
<< "session.screen" << getScreenNumber() << ".focusModel" << ends
;
945 config
.setValue(s
.str(),
946 (resource
.sloppy_focus
?
947 (resource
.auto_raise
? "AutoRaiseSloppyFocus" : "SloppyFocus")
949 s
.rdbuf()->freeze(0);
953 void BScreen::setImageDither(bool d
, bool reconfig
) {
954 image_control
->setDither(d
);
956 s
<< "session.screen" << getScreenNumber() << ".imageDither" << ends
;
957 config
.setValue(s
.str(), imageDither());
960 s
.rdbuf()->freeze(0);
964 void BScreen::setOpaqueMove(bool o
) {
965 resource
.opaque_move
= o
;
967 s
<< "session.screen" << getScreenNumber() << ".opaqueMove" << ends
;
968 config
.setValue(s
.str(), resource
.opaque_move
);
969 s
.rdbuf()->freeze(0);
973 void BScreen::setFullMax(bool f
) {
974 resource
.full_max
= f
;
976 s
<< "session.screen" << getScreenNumber() << ".fullMaximization" << ends
;
977 config
.setValue(s
.str(), resource
.full_max
);
978 s
.rdbuf()->freeze(0);
982 void BScreen::setFocusNew(bool f
) {
983 resource
.focus_new
= f
;
985 s
<< "session.screen" << getScreenNumber() << ".focusNewWindows" << ends
;
986 config
.setValue(s
.str(), resource
.focus_new
);
987 s
.rdbuf()->freeze(0);
991 void BScreen::setFocusLast(bool f
) {
992 resource
.focus_last
= f
;
994 s
<< "session.screen" << getScreenNumber() << ".focusLastWindow" << ends
;
995 config
.setValue(s
.str(), resource
.focus_last
);
996 s
.rdbuf()->freeze(0);
1000 void BScreen::setWindowZones(int z
) {
1003 s
<< "session.screen" << getScreenNumber() << ".windowZones" << ends
;
1004 config
.setValue(s
.str(), resource
.zones
);
1005 s
.rdbuf()->freeze(0);
1009 void BScreen::setWorkspaceCount(int w
) {
1010 resource
.workspaces
= w
;
1012 s
<< "session.screen" << getScreenNumber() << ".workspaces" << ends
;
1013 config
.setValue(s
.str(), resource
.workspaces
);
1014 s
.rdbuf()->freeze(0);
1018 void BScreen::setPlacementPolicy(int p
) {
1019 resource
.placement_policy
= p
;
1021 s
<< "session.screen" << getScreenNumber() << ".windowPlacement" << ends
;
1022 const char *placement
;
1023 switch (resource
.placement_policy
) {
1024 case CascadePlacement
: placement
= "CascadePlacement"; break;
1025 case BestFitPlacement
: placement
= "BestFitPlacement"; break;
1026 case ColSmartPlacement
: placement
= "ColSmartPlacement"; break;
1027 case UnderMousePlacement
: placement
= "UnderMousePlacement"; break;
1028 case ClickMousePlacement
: placement
= "ClickMousePlacement"; break;
1030 case RowSmartPlacement
: placement
= "RowSmartPlacement"; break;
1032 config
.setValue(s
.str(), placement
);
1033 s
.rdbuf()->freeze(0);
1037 void BScreen::setEdgeSnapThreshold(int t
) {
1038 resource
.edge_snap_threshold
= t
;
1040 s
<< "session.screen" << getScreenNumber() << ".edgeSnapThreshold" << ends
;
1041 config
.setValue(s
.str(), resource
.edge_snap_threshold
);
1042 s
.rdbuf()->freeze(0);
1046 void BScreen::setRowPlacementDirection(int d
) {
1047 resource
.row_direction
= d
;
1049 s
<< "session.screen" << getScreenNumber() << ".rowPlacementDirection" << ends
;
1050 config
.setValue(s
.str(),
1051 resource
.row_direction
== LeftRight
?
1052 "LeftToRight" : "RightToLeft");
1053 s
.rdbuf()->freeze(0);
1057 void BScreen::setColPlacementDirection(int d
) {
1058 resource
.col_direction
= d
;
1060 s
<< "session.screen" << getScreenNumber() << ".colPlacementDirection" << ends
;
1061 config
.setValue(s
.str(),
1062 resource
.col_direction
== TopBottom
?
1063 "TopToBottom" : "BottomToTop");
1064 s
.rdbuf()->freeze(0);
1068 void BScreen::setRootCommand(const char *cmd
) {
1069 if (resource
.root_command
!= NULL
)
1070 delete [] resource
.root_command
;
1072 resource
.root_command
= bstrdup(cmd
);
1074 resource
.root_command
= NULL
;
1075 // this doesn't save to the Resources config because it can't be changed
1076 // inside Openbox, and this way we dont add an empty command which would over-
1077 // ride the styles command when none has been specified
1081 #ifdef HAVE_STRFTIME
1082 void BScreen::setStrftimeFormat(const char *f
) {
1083 if (resource
.strftime_format
!= NULL
)
1084 delete [] resource
.strftime_format
;
1086 resource
.strftime_format
= bstrdup(f
);
1088 s
<< "session.screen" << getScreenNumber() << ".strftimeFormat" << ends
;
1089 config
.setValue(s
.str(), resource
.strftime_format
);
1090 s
.rdbuf()->freeze(0);
1093 #else // !HAVE_STRFTIME
1094 void BScreen::setDateFormat(int f
) {
1095 resource
.date_format
= f
;
1097 s
<< "session.screen" << getScreenNumber() << ".dateFormat" << ends
;
1098 config
.setValue(s
.str(), resource
.date_format
== B_EuropeanDate
?
1099 "European" : "American");
1100 s
.rdbuf()->freeze(0);
1103 void BScreen::setClock24Hour(Bool c
) {
1104 resource
.clock24hour
= c
;
1106 s
<< "session.screen" << getScreenNumber() << ".clockFormat" << ends
;
1107 config
.setValue(s
.str(), resource
.clock24hour
? 24 : 12);
1108 s
.rdbuf()->freeze(0);
1110 #endif // HAVE_STRFTIME
1112 void BScreen::setHideToolbar(bool b
) {
1113 resource
.hide_toolbar
= b
;
1114 if (resource
.hide_toolbar
)
1115 getToolbar()->unMapToolbar();
1117 getToolbar()->mapToolbar();
1119 s
<< "session.screen" << getScreenNumber() << ".hideToolbar" << ends
;
1120 config
.setValue(s
.str(), resource
.hide_toolbar
? "True" : "False");
1121 s
.rdbuf()->freeze(0);
1124 void BScreen::saveWorkspaceNames() {
1125 ostrstream rc
, names
;
1127 for (int i
= 0; i
< resource
.workspaces
; i
++) {
1128 Workspace
*w
= getWorkspace(i
);
1130 names
<< w
->getName();
1131 if (i
< resource
.workspaces
-1)
1137 rc
<< "session.screen" << getScreenNumber() << ".workspaceNames" << ends
;
1138 config
.setValue(rc
.str(), names
.str());
1139 rc
.rdbuf()->freeze(0);
1140 names
.rdbuf()->freeze(0);
1143 void BScreen::save() {
1144 setSloppyFocus(resource
.sloppy_focus
);
1145 setAutoRaise(resource
.auto_raise
);
1146 setImageDither(imageDither(), false);
1147 setOpaqueMove(resource
.opaque_move
);
1148 setFullMax(resource
.full_max
);
1149 setFocusNew(resource
.focus_new
);
1150 setFocusLast(resource
.focus_last
);
1151 setWindowZones(resource
.zones
);
1152 setWorkspaceCount(resource
.workspaces
);
1153 setPlacementPolicy(resource
.placement_policy
);
1154 setEdgeSnapThreshold(resource
.edge_snap_threshold
);
1155 setRowPlacementDirection(resource
.row_direction
);
1156 setColPlacementDirection(resource
.col_direction
);
1157 setRootCommand(resource
.root_command
);
1158 #ifdef HAVE_STRFTIME
1159 // it deletes the current value before setting the new one, so we have to
1160 // duplicate the current value.
1161 std::string s
= resource
.strftime_format
;
1162 setStrftimeFormat(s
.c_str());
1163 #else // !HAVE_STRFTIME
1164 setDateFormat(resource
.date_format
);
1165 setClock24Hour(resource
.clock24hour
);
1166 #endif // HAVE_STRFTIME
1167 setHideToolbar(resource
.hide_toolbar
);
1171 void BScreen::load() {
1172 ostrstream rscreen
, rname
, rclass
;
1176 rscreen
<< "session.screen" << getScreenNumber() << '.' << ends
;
1178 rname
<< rscreen
.str() << "hideToolbar" << ends
;
1179 rclass
<< rscreen
.str() << "HideToolbar" << ends
;
1180 if (config
.getValue(rname
.str(), rclass
.str(), b
))
1181 resource
.hide_toolbar
= b
;
1183 resource
.hide_toolbar
= false;
1184 Toolbar
*t
= getToolbar();
1186 if (resource
.hide_toolbar
)
1192 rname
.seekp(0); rclass
.seekp(0);
1193 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1194 rname
<< rscreen
.str() << "fullMaximization" << ends
;
1195 rclass
<< rscreen
.str() << "FullMaximization" << ends
;
1196 if (config
.getValue(rname
.str(), rclass
.str(), b
))
1197 resource
.full_max
= b
;
1199 resource
.full_max
= false;
1201 rname
.seekp(0); rclass
.seekp(0);
1202 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1203 rname
<< rscreen
.str() << "focusNewWindows" << ends
;
1204 rclass
<< rscreen
.str() << "FocusNewWindows" << ends
;
1205 if (config
.getValue(rname
.str(), rclass
.str(), b
))
1206 resource
.focus_new
= b
;
1208 resource
.focus_new
= false;
1210 rname
.seekp(0); rclass
.seekp(0);
1211 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1212 rname
<< rscreen
.str() << "focusLastWindow" << ends
;
1213 rclass
<< rscreen
.str() << "FocusLastWindow" << ends
;
1214 if (config
.getValue(rname
.str(), rclass
.str(), b
))
1215 resource
.focus_last
= b
;
1217 resource
.focus_last
= false;
1219 rname
.seekp(0); rclass
.seekp(0);
1220 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1221 rname
<< rscreen
.str() << "rowPlacementDirection" << ends
;
1222 rclass
<< rscreen
.str() << "RowPlacementDirection" << ends
;
1223 if (config
.getValue(rname
.str(), rclass
.str(), s
)) {
1224 if (0 == strncasecmp(s
.c_str(), "RightToLeft", s
.length()))
1225 resource
.row_direction
= RightLeft
;
1226 else //if (0 == strncasecmp(s.c_str(), "LeftToRight", s.length()))
1227 resource
.row_direction
= LeftRight
;
1229 resource
.row_direction
= LeftRight
;
1231 rname
.seekp(0); rclass
.seekp(0);
1232 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1233 rname
<< rscreen
.str() << "colPlacementDirection" << ends
;
1234 rclass
<< rscreen
.str() << "ColPlacementDirection" << ends
;
1235 if (config
.getValue(rname
.str(), rclass
.str(), s
)) {
1236 if (0 == strncasecmp(s
.c_str(), "BottomToTop", s
.length()))
1237 resource
.col_direction
= BottomTop
;
1238 else //if (0 == strncasecmp(s.c_str(), "TopToBottom", s.length()))
1239 resource
.col_direction
= TopBottom
;
1241 resource
.col_direction
= TopBottom
;
1243 rname
.seekp(0); rclass
.seekp(0);
1244 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1245 rname
<< rscreen
.str() << "workspaces" << ends
;
1246 rclass
<< rscreen
.str() << "Workspaces" << ends
;
1247 if (config
.getValue(rname
.str(), rclass
.str(), l
)) {
1248 resource
.workspaces
= l
;
1250 resource
.workspaces
= 1;
1252 removeWorkspaceNames();
1253 rname
.seekp(0); rclass
.seekp(0);
1254 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1255 rname
<< rscreen
.str() << "workspaceNames" << ends
;
1256 rclass
<< rscreen
.str() << "WorkspaceNames" << ends
;
1257 if (config
.getValue(rname
.str(), rclass
.str(), s
)) {
1258 string::const_iterator it
= s
.begin(), end
= s
.end();
1260 string::const_iterator tmp
= it
;// current string.begin()
1261 it
= std::find(tmp
, end
, ','); // look for comma between tmp and end
1262 std::string
name(tmp
, it
); // name = s[tmp:it]
1263 addWorkspaceName(name
.c_str());
1270 rname
.seekp(0); rclass
.seekp(0);
1271 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1272 rname
<< rscreen
.str() << "focusModel" << ends
;
1273 rclass
<< rscreen
.str() << "FocusModel" << ends
;
1274 if (config
.getValue(rname
.str(), rclass
.str(), s
)) {
1275 if (0 == strncasecmp(s
.c_str(), "ClickToFocus", s
.length())) {
1276 resource
.auto_raise
= false;
1277 resource
.sloppy_focus
= false;
1278 } else if (0 == strncasecmp(s
.c_str(), "AutoRaiseSloppyFocus",
1280 resource
.sloppy_focus
= true;
1281 resource
.auto_raise
= true;
1282 } else { //if (0 == strncasecmp(s.c_str(), "SloppyFocus", s.length())) {
1283 resource
.sloppy_focus
= true;
1284 resource
.auto_raise
= false;
1287 resource
.sloppy_focus
= true;
1288 resource
.auto_raise
= false;
1291 rname
.seekp(0); rclass
.seekp(0);
1292 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1293 rname
<< rscreen
.str() << "windowZones" << ends
;
1294 rclass
<< rscreen
.str() << "WindowZones" << ends
;
1295 if (config
.getValue(rname
.str(), rclass
.str(), l
))
1296 resource
.zones
= (l
== 1 || l
== 2 || l
== 4) ? l
: 1;
1300 rname
.seekp(0); rclass
.seekp(0);
1301 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1302 rname
<< rscreen
.str() << "windowPlacement" << ends
;
1303 rclass
<< rscreen
.str() << "WindowPlacement" << ends
;
1304 if (config
.getValue(rname
.str(), rclass
.str(), s
)) {
1305 if (0 == strncasecmp(s
.c_str(), "RowSmartPlacement", s
.length()))
1306 resource
.placement_policy
= RowSmartPlacement
;
1307 else if (0 == strncasecmp(s
.c_str(), "ColSmartPlacement", s
.length()))
1308 resource
.placement_policy
= ColSmartPlacement
;
1309 else if (0 == strncasecmp(s
.c_str(), "BestFitPlacement", s
.length()))
1310 resource
.placement_policy
= BestFitPlacement
;
1311 else if (0 == strncasecmp(s
.c_str(), "UnderMousePlacement", s
.length()))
1312 resource
.placement_policy
= UnderMousePlacement
;
1313 else if (0 == strncasecmp(s
.c_str(), "ClickMousePlacement", s
.length()))
1314 resource
.placement_policy
= ClickMousePlacement
;
1315 else //if (0 == strncasecmp(s.c_str(), "CascadePlacement", s.length()))
1316 resource
.placement_policy
= CascadePlacement
;
1318 resource
.placement_policy
= CascadePlacement
;
1320 #ifdef HAVE_STRFTIME
1321 rname
.seekp(0); rclass
.seekp(0);
1322 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1323 rname
<< rscreen
.str() << "strftimeFormat" << ends
;
1324 rclass
<< rscreen
.str() << "StrftimeFormat" << ends
;
1326 if (resource
.strftime_format
!= NULL
)
1327 delete [] resource
.strftime_format
;
1329 if (config
.getValue(rname
.str(), rclass
.str(), s
))
1330 resource
.strftime_format
= bstrdup(s
.c_str());
1332 resource
.strftime_format
= bstrdup("%I:%M %p");
1333 #else // !HAVE_STRFTIME
1334 rname
.seekp(0); rclass
.seekp(0);
1335 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1336 rname
<< rscreen
.str() << "dateFormat" << ends
;
1337 rclass
<< rscreen
.str() << "DateFormat" << ends
;
1338 if (config
.getValue(rname
.str(), rclass
.str(), s
)) {
1339 if (strncasecmp(s
.c_str(), "European", s
.length()))
1340 resource
.date_format
= B_EuropeanDate
;
1341 else //if (strncasecmp(s.c_str(), "American", s.length()))
1342 resource
.date_format
= B_AmericanDate
;
1344 resource
.date_format
= B_AmericanDate
;
1346 rname
.seekp(0); rclass
.seekp(0);
1347 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1348 rname
<< rscreen
.str() << "clockFormat" << ends
;
1349 rclass
<< rscreen
.str() << "ClockFormat" << ends
;
1350 if (config
.getValue(rname
.str(), rclass
.str(), l
)) {
1352 resource
.clock24hour
= true;
1353 else if (clock
== 12)
1354 resource
.clock24hour
= false;
1356 resource
.clock24hour
= false;
1357 #endif // HAVE_STRFTIME
1359 rname
.seekp(0); rclass
.seekp(0);
1360 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1361 rname
<< rscreen
.str() << "edgeSnapThreshold" << ends
;
1362 rclass
<< rscreen
.str() << "EdgeSnapThreshold" << ends
;
1363 if (config
.getValue(rname
.str(), rclass
.str(), l
))
1364 resource
.edge_snap_threshold
= l
;
1366 resource
.edge_snap_threshold
= 4;
1368 rname
.seekp(0); rclass
.seekp(0);
1369 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1370 rname
<< rscreen
.str() << "imageDither" << ends
;
1371 rclass
<< rscreen
.str() << "ImageDither" << ends
;
1372 if (config
.getValue(rname
.str(), rclass
.str(), b
))
1373 image_control
->setDither(b
);
1375 image_control
->setDither(true);
1377 rname
.seekp(0); rclass
.seekp(0);
1378 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1379 rname
<< rscreen
.str() << "rootCommand" << ends
;
1380 rclass
<< rscreen
.str() << "RootCommand" << ends
;
1382 if (resource
.root_command
!= NULL
)
1383 delete [] resource
.root_command
;
1385 if (config
.getValue(rname
.str(), rclass
.str(), s
))
1386 resource
.root_command
= bstrdup(s
.c_str());
1388 resource
.root_command
= NULL
;
1390 rname
.seekp(0); rclass
.seekp(0);
1391 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1392 rname
<< rscreen
.str() << "opaqueMove" << ends
;
1393 rclass
<< rscreen
.str() << "OpaqueMove" << ends
;
1394 if (config
.getValue(rname
.str(), rclass
.str(), b
))
1395 resource
.opaque_move
= b
;
1397 resource
.opaque_move
= false;
1399 rscreen
.rdbuf()->freeze(0);
1400 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1403 void BScreen::reconfigure(void) {
1412 unsigned long gc_value_mask
= GCForeground
;
1413 if (! i18n
->multibyte()) gc_value_mask
|= GCFont
;
1415 gcv
.foreground
= WhitePixel(getBaseDisplay().getXDisplay(),
1417 gcv
.function
= GXinvert
;
1418 gcv
.subwindow_mode
= IncludeInferiors
;
1419 XChangeGC(getBaseDisplay().getXDisplay(), opGC
,
1420 GCForeground
| GCFunction
| GCSubwindowMode
, &gcv
);
1422 gcv
.foreground
= resource
.wstyle
.l_text_focus
.getPixel();
1423 if (resource
.wstyle
.font
)
1424 gcv
.font
= resource
.wstyle
.font
->fid
;
1425 XChangeGC(getBaseDisplay().getXDisplay(), resource
.wstyle
.l_text_focus_gc
,
1426 gc_value_mask
, &gcv
);
1428 gcv
.foreground
= resource
.wstyle
.l_text_unfocus
.getPixel();
1429 XChangeGC(getBaseDisplay().getXDisplay(), resource
.wstyle
.l_text_unfocus_gc
,
1430 gc_value_mask
, &gcv
);
1432 gcv
.foreground
= resource
.wstyle
.b_pic_focus
.getPixel();
1433 XChangeGC(getBaseDisplay().getXDisplay(), resource
.wstyle
.b_pic_focus_gc
,
1434 GCForeground
, &gcv
);
1436 gcv
.foreground
= resource
.wstyle
.b_pic_unfocus
.getPixel();
1437 XChangeGC(getBaseDisplay().getXDisplay(), resource
.wstyle
.b_pic_unfocus_gc
,
1438 GCForeground
, &gcv
);
1440 gcv
.foreground
= resource
.mstyle
.t_text
.getPixel();
1441 if (resource
.mstyle
.t_font
)
1442 gcv
.font
= resource
.mstyle
.t_font
->fid
;
1443 XChangeGC(getBaseDisplay().getXDisplay(), resource
.mstyle
.t_text_gc
,
1444 gc_value_mask
, &gcv
);
1446 gcv
.foreground
= resource
.mstyle
.f_text
.getPixel();
1447 if (resource
.mstyle
.f_font
)
1448 gcv
.font
= resource
.mstyle
.f_font
->fid
;
1449 XChangeGC(getBaseDisplay().getXDisplay(), resource
.mstyle
.f_text_gc
,
1450 gc_value_mask
, &gcv
);
1452 gcv
.foreground
= resource
.mstyle
.h_text
.getPixel();
1453 XChangeGC(getBaseDisplay().getXDisplay(), resource
.mstyle
.h_text_gc
,
1454 gc_value_mask
, &gcv
);
1456 gcv
.foreground
= resource
.mstyle
.d_text
.getPixel();
1457 XChangeGC(getBaseDisplay().getXDisplay(), resource
.mstyle
.d_text_gc
,
1458 gc_value_mask
, &gcv
);
1460 gcv
.foreground
= resource
.mstyle
.hilite
.getColor()->getPixel();
1461 XChangeGC(getBaseDisplay().getXDisplay(), resource
.mstyle
.hilite_gc
,
1462 gc_value_mask
, &gcv
);
1464 gcv
.foreground
= resource
.tstyle
.l_text
.getPixel();
1465 if (resource
.tstyle
.font
)
1466 gcv
.font
= resource
.tstyle
.font
->fid
;
1467 XChangeGC(getBaseDisplay().getXDisplay(), resource
.tstyle
.l_text_gc
,
1468 gc_value_mask
, &gcv
);
1470 gcv
.foreground
= resource
.tstyle
.w_text
.getPixel();
1471 XChangeGC(getBaseDisplay().getXDisplay(), resource
.tstyle
.w_text_gc
,
1472 gc_value_mask
, &gcv
);
1474 gcv
.foreground
= resource
.tstyle
.c_text
.getPixel();
1475 XChangeGC(getBaseDisplay().getXDisplay(), resource
.tstyle
.c_text_gc
,
1476 gc_value_mask
, &gcv
);
1478 gcv
.foreground
= resource
.tstyle
.b_pic
.getPixel();
1479 XChangeGC(getBaseDisplay().getXDisplay(), resource
.tstyle
.b_pic_gc
,
1480 gc_value_mask
, &gcv
);
1482 const char *s
= i18n
->getMessage(ScreenSet
, ScreenPositionLength
,
1483 "0: 0000 x 0: 0000");
1486 if (i18n
->multibyte()) {
1487 XRectangle ink
, logical
;
1488 XmbTextExtents(resource
.wstyle
.fontset
, s
, l
, &ink
, &logical
);
1489 geom_w
= logical
.width
;
1491 geom_h
= resource
.wstyle
.fontset_extents
->max_ink_extent
.height
;
1493 geom_w
= XTextWidth(resource
.wstyle
.font
, s
, l
);
1495 geom_h
= resource
.wstyle
.font
->ascent
+
1496 resource
.wstyle
.font
->descent
;
1499 geom_w
+= (resource
.bevel_width
* 2);
1500 geom_h
+= (resource
.bevel_width
* 2);
1502 Pixmap tmp
= geom_pixmap
;
1503 if (resource
.wstyle
.l_focus
.getTexture() & BImage_ParentRelative
) {
1504 if (resource
.wstyle
.t_focus
.getTexture() ==
1505 (BImage_Flat
| BImage_Solid
)) {
1507 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window
,
1508 resource
.wstyle
.t_focus
.getColor()->getPixel());
1510 geom_pixmap
= image_control
->renderImage(geom_w
, geom_h
,
1511 &resource
.wstyle
.t_focus
);
1512 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
1513 geom_window
, geom_pixmap
);
1516 if (resource
.wstyle
.l_focus
.getTexture() ==
1517 (BImage_Flat
| BImage_Solid
)) {
1519 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window
,
1520 resource
.wstyle
.l_focus
.getColor()->getPixel());
1522 geom_pixmap
= image_control
->renderImage(geom_w
, geom_h
,
1523 &resource
.wstyle
.l_focus
);
1524 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
1525 geom_window
, geom_pixmap
);
1528 if (tmp
) image_control
->removeImage(tmp
);
1530 XSetWindowBorderWidth(getBaseDisplay().getXDisplay(), geom_window
,
1531 resource
.border_width
);
1532 XSetWindowBorder(getBaseDisplay().getXDisplay(), geom_window
,
1533 resource
.border_color
.getPixel());
1535 workspacemenu
->reconfigure();
1536 iconmenu
->reconfigure();
1539 int remember_sub
= rootmenu
->getCurrentSubmenu();
1542 rootmenu
->reconfigure();
1543 rootmenu
->drawSubmenu(remember_sub
);
1546 configmenu
->reconfigure();
1548 toolbar
->reconfigure();
1551 slit
->reconfigure();
1554 LinkedListIterator
<Workspace
> wit(workspacesList
);
1555 for (Workspace
*w
= wit
.current(); w
; wit
++, w
= wit
.current())
1558 LinkedListIterator
<OpenboxWindow
> iit(iconList
);
1559 for (OpenboxWindow
*bw
= iit
.current(); bw
; iit
++, bw
= iit
.current())
1560 if (bw
->validateClient())
1563 image_control
->timeout();
1567 void BScreen::rereadMenu(void) {
1571 rootmenu
->reconfigure();
1575 void BScreen::removeWorkspaceNames(void) {
1576 while (workspaceNames
->count())
1577 delete [] workspaceNames
->remove(0);
1581 void BScreen::LoadStyle(void) {
1582 Resource
&conf
= resource
.styleconfig
;
1584 const char *sfile
= openbox
.getStyleFilename();
1585 bool loaded
= false;
1586 if (sfile
!= NULL
) {
1587 conf
.setFile(sfile
);
1588 loaded
= conf
.load();
1591 conf
.setFile(DEFAULTSTYLE
);
1593 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenDefaultStyleLoadFail
,
1594 "BScreen::LoadStyle(): couldn't load "
1595 "default style.\n"));
1603 // load fonts/fontsets
1605 if (i18n
->multibyte()) {
1606 readDatabaseFontSet("window.font", "Window.Font",
1607 &resource
.wstyle
.fontset
);
1608 readDatabaseFontSet("toolbar.font", "Toolbar.Font",
1609 &resource
.tstyle
.fontset
);
1610 readDatabaseFontSet("menu.title.font", "Menu.Title.Font",
1611 &resource
.mstyle
.t_fontset
);
1612 readDatabaseFontSet("menu.frame.font", "Menu.Frame.Font",
1613 &resource
.mstyle
.f_fontset
);
1615 resource
.mstyle
.t_fontset_extents
=
1616 XExtentsOfFontSet(resource
.mstyle
.t_fontset
);
1617 resource
.mstyle
.f_fontset_extents
=
1618 XExtentsOfFontSet(resource
.mstyle
.f_fontset
);
1619 resource
.tstyle
.fontset_extents
=
1620 XExtentsOfFontSet(resource
.tstyle
.fontset
);
1621 resource
.wstyle
.fontset_extents
=
1622 XExtentsOfFontSet(resource
.wstyle
.fontset
);
1624 readDatabaseFont("window.font", "Window.Font",
1625 &resource
.wstyle
.font
);
1626 readDatabaseFont("menu.title.font", "Menu.Title.Font",
1627 &resource
.mstyle
.t_font
);
1628 readDatabaseFont("menu.frame.font", "Menu.Frame.Font",
1629 &resource
.mstyle
.f_font
);
1630 readDatabaseFont("toolbar.font", "Toolbar.Font",
1631 &resource
.tstyle
.font
);
1634 // load window config
1635 readDatabaseTexture("window.title.focus", "Window.Title.Focus",
1636 &resource
.wstyle
.t_focus
,
1637 WhitePixel(getBaseDisplay().getXDisplay(),
1638 getScreenNumber()));
1639 readDatabaseTexture("window.title.unfocus", "Window.Title.Unfocus",
1640 &resource
.wstyle
.t_unfocus
,
1641 BlackPixel(getBaseDisplay().getXDisplay(),
1642 getScreenNumber()));
1643 readDatabaseTexture("window.label.focus", "Window.Label.Focus",
1644 &resource
.wstyle
.l_focus
,
1645 WhitePixel(getBaseDisplay().getXDisplay(),
1646 getScreenNumber()));
1647 readDatabaseTexture("window.label.unfocus", "Window.Label.Unfocus",
1648 &resource
.wstyle
.l_unfocus
,
1649 BlackPixel(getBaseDisplay().getXDisplay(),
1650 getScreenNumber()));
1651 readDatabaseTexture("window.handle.focus", "Window.Handle.Focus",
1652 &resource
.wstyle
.h_focus
,
1653 WhitePixel(getBaseDisplay().getXDisplay(),
1654 getScreenNumber()));
1655 readDatabaseTexture("window.handle.unfocus", "Window.Handle.Unfocus",
1656 &resource
.wstyle
.h_unfocus
,
1657 BlackPixel(getBaseDisplay().getXDisplay(),
1658 getScreenNumber()));
1659 readDatabaseTexture("window.grip.focus", "Window.Grip.Focus",
1660 &resource
.wstyle
.g_focus
,
1661 WhitePixel(getBaseDisplay().getXDisplay(),
1662 getScreenNumber()));
1663 readDatabaseTexture("window.grip.unfocus", "Window.Grip.Unfocus",
1664 &resource
.wstyle
.g_unfocus
,
1665 BlackPixel(getBaseDisplay().getXDisplay(),
1666 getScreenNumber()));
1667 readDatabaseTexture("window.button.focus", "Window.Button.Focus",
1668 &resource
.wstyle
.b_focus
,
1669 WhitePixel(getBaseDisplay().getXDisplay(),
1670 getScreenNumber()));
1671 readDatabaseTexture("window.button.unfocus", "Window.Button.Unfocus",
1672 &resource
.wstyle
.b_unfocus
,
1673 BlackPixel(getBaseDisplay().getXDisplay(),
1674 getScreenNumber()));
1675 readDatabaseTexture("window.button.pressed", "Window.Button.Pressed",
1676 &resource
.wstyle
.b_pressed
,
1677 BlackPixel(getBaseDisplay().getXDisplay(),
1678 getScreenNumber()));
1679 readDatabaseColor("window.frame.focusColor",
1680 "Window.Frame.FocusColor",
1681 &resource
.wstyle
.f_focus
,
1682 WhitePixel(getBaseDisplay().getXDisplay(),
1683 getScreenNumber()));
1684 readDatabaseColor("window.frame.unfocusColor",
1685 "Window.Frame.UnfocusColor",
1686 &resource
.wstyle
.f_unfocus
,
1687 BlackPixel(getBaseDisplay().getXDisplay(),
1688 getScreenNumber()));
1689 readDatabaseColor("window.label.focus.textColor",
1690 "Window.Label.Focus.TextColor",
1691 &resource
.wstyle
.l_text_focus
,
1692 BlackPixel(getBaseDisplay().getXDisplay(),
1693 getScreenNumber()));
1694 readDatabaseColor("window.label.unfocus.textColor",
1695 "Window.Label.Unfocus.TextColor",
1696 &resource
.wstyle
.l_text_unfocus
,
1697 WhitePixel(getBaseDisplay().getXDisplay(),
1698 getScreenNumber()));
1699 readDatabaseColor("window.button.focus.picColor",
1700 "Window.Button.Focus.PicColor",
1701 &resource
.wstyle
.b_pic_focus
,
1702 BlackPixel(getBaseDisplay().getXDisplay(),
1703 getScreenNumber()));
1704 readDatabaseColor("window.button.unfocus.picColor",
1705 "Window.Button.Unfocus.PicColor",
1706 &resource
.wstyle
.b_pic_unfocus
,
1707 WhitePixel(getBaseDisplay().getXDisplay(),
1708 getScreenNumber()));
1710 if (conf
.getValue("window.justify", "Window.Justify", s
)) {
1711 if (0 == strncasecmp(s
.c_str(), "right", s
.length()))
1712 resource
.wstyle
.justify
= BScreen::RightJustify
;
1713 else if (0 == strncasecmp(s
.c_str(), "center", s
.length()))
1714 resource
.wstyle
.justify
= BScreen::CenterJustify
;
1716 resource
.wstyle
.justify
= BScreen::LeftJustify
;
1718 resource
.wstyle
.justify
= BScreen::LeftJustify
;
1720 // load toolbar config
1721 readDatabaseTexture("toolbar", "Toolbar",
1722 &resource
.tstyle
.toolbar
,
1723 BlackPixel(getBaseDisplay().getXDisplay(),
1724 getScreenNumber()));
1725 readDatabaseTexture("toolbar.label", "Toolbar.Label",
1726 &resource
.tstyle
.label
,
1727 BlackPixel(getBaseDisplay().getXDisplay(),
1728 getScreenNumber()));
1729 readDatabaseTexture("toolbar.windowLabel", "Toolbar.WindowLabel",
1730 &resource
.tstyle
.window
,
1731 BlackPixel(getBaseDisplay().getXDisplay(),
1732 getScreenNumber()));
1733 readDatabaseTexture("toolbar.button", "Toolbar.Button",
1734 &resource
.tstyle
.button
,
1735 WhitePixel(getBaseDisplay().getXDisplay(),
1736 getScreenNumber()));
1737 readDatabaseTexture("toolbar.button.pressed", "Toolbar.Button.Pressed",
1738 &resource
.tstyle
.pressed
,
1739 BlackPixel(getBaseDisplay().getXDisplay(),
1740 getScreenNumber()));
1741 readDatabaseTexture("toolbar.clock", "Toolbar.Clock",
1742 &resource
.tstyle
.clock
,
1743 BlackPixel(getBaseDisplay().getXDisplay(),
1744 getScreenNumber()));
1745 readDatabaseColor("toolbar.label.textColor", "Toolbar.Label.TextColor",
1746 &resource
.tstyle
.l_text
,
1747 WhitePixel(getBaseDisplay().getXDisplay(),
1748 getScreenNumber()));
1749 readDatabaseColor("toolbar.windowLabel.textColor",
1750 "Toolbar.WindowLabel.TextColor",
1751 &resource
.tstyle
.w_text
,
1752 WhitePixel(getBaseDisplay().getXDisplay(),
1753 getScreenNumber()));
1754 readDatabaseColor("toolbar.clock.textColor", "Toolbar.Clock.TextColor",
1755 &resource
.tstyle
.c_text
,
1756 WhitePixel(getBaseDisplay().getXDisplay(),
1757 getScreenNumber()));
1758 readDatabaseColor("toolbar.button.picColor", "Toolbar.Button.PicColor",
1759 &resource
.tstyle
.b_pic
,
1760 BlackPixel(getBaseDisplay().getXDisplay(),
1761 getScreenNumber()));
1763 if (conf
.getValue("toolbar.justify", "Toolbar.Justify", s
)) {
1764 if (0 == strncasecmp(s
.c_str(), "right", s
.length()))
1765 resource
.tstyle
.justify
= BScreen::RightJustify
;
1766 else if (0 == strncasecmp(s
.c_str(), "center", s
.length()))
1767 resource
.tstyle
.justify
= BScreen::CenterJustify
;
1769 resource
.tstyle
.justify
= BScreen::LeftJustify
;
1771 resource
.tstyle
.justify
= BScreen::LeftJustify
;
1774 readDatabaseTexture("menu.title", "Menu.Title",
1775 &resource
.mstyle
.title
,
1776 WhitePixel(getBaseDisplay().getXDisplay(),
1777 getScreenNumber()));
1778 readDatabaseTexture("menu.frame", "Menu.Frame",
1779 &resource
.mstyle
.frame
,
1780 BlackPixel(getBaseDisplay().getXDisplay(),
1781 getScreenNumber()));
1782 readDatabaseTexture("menu.hilite", "Menu.Hilite",
1783 &resource
.mstyle
.hilite
,
1784 WhitePixel(getBaseDisplay().getXDisplay(),
1785 getScreenNumber()));
1786 readDatabaseColor("menu.title.textColor", "Menu.Title.TextColor",
1787 &resource
.mstyle
.t_text
,
1788 BlackPixel(getBaseDisplay().getXDisplay(),
1789 getScreenNumber()));
1790 readDatabaseColor("menu.frame.textColor", "Menu.Frame.TextColor",
1791 &resource
.mstyle
.f_text
,
1792 WhitePixel(getBaseDisplay().getXDisplay(),
1793 getScreenNumber()));
1794 readDatabaseColor("menu.frame.disableColor", "Menu.Frame.DisableColor",
1795 &resource
.mstyle
.d_text
,
1796 BlackPixel(getBaseDisplay().getXDisplay(),
1797 getScreenNumber()));
1798 readDatabaseColor("menu.hilite.textColor", "Menu.Hilite.TextColor",
1799 &resource
.mstyle
.h_text
,
1800 BlackPixel(getBaseDisplay().getXDisplay(),
1801 getScreenNumber()));
1803 if (conf
.getValue("menu.title.justify", "Menu.Title.Justify", s
)) {
1804 if (0 == strncasecmp(s
.c_str(), "right", s
.length()))
1805 resource
.mstyle
.t_justify
= BScreen::RightJustify
;
1806 else if (0 == strncasecmp(s
.c_str(), "center", s
.length()))
1807 resource
.mstyle
.t_justify
= BScreen::CenterJustify
;
1809 resource
.mstyle
.t_justify
= BScreen::LeftJustify
;
1811 resource
.mstyle
.t_justify
= BScreen::LeftJustify
;
1813 if (conf
.getValue("menu.frame.justify", "Menu.Frame.Justify", s
)) {
1814 if (0 == strncasecmp(s
.c_str(), "right", s
.length()))
1815 resource
.mstyle
.f_justify
= BScreen::RightJustify
;
1816 else if (0 == strncasecmp(s
.c_str(), "center", s
.length()))
1817 resource
.mstyle
.f_justify
= BScreen::CenterJustify
;
1819 resource
.mstyle
.f_justify
= BScreen::LeftJustify
;
1821 resource
.mstyle
.f_justify
= BScreen::LeftJustify
;
1823 if (conf
.getValue("menu.bullet", "Menu.Bullet", s
)) {
1824 if (0 == strncasecmp(s
.c_str(), "empty", s
.length()))
1825 resource
.mstyle
.bullet
= Basemenu::Empty
;
1826 else if (0 == strncasecmp(s
.c_str(), "square", s
.length()))
1827 resource
.mstyle
.bullet
= Basemenu::Square
;
1828 else if (0 == strncasecmp(s
.c_str(), "diamond", s
.length()))
1829 resource
.mstyle
.bullet
= Basemenu::Diamond
;
1831 resource
.mstyle
.bullet
= Basemenu::Triangle
;
1833 resource
.mstyle
.bullet
= Basemenu::Triangle
;
1835 if (conf
.getValue("menu.bullet.position", "Menu.Bullet.Position", s
)) {
1836 if (0 == strncasecmp(s
.c_str(), "right", s
.length()))
1837 resource
.mstyle
.bullet_pos
= Basemenu::Right
;
1839 resource
.mstyle
.bullet_pos
= Basemenu::Left
;
1841 resource
.mstyle
.bullet_pos
= Basemenu::Left
;
1843 readDatabaseColor("borderColor", "BorderColor", &resource
.border_color
,
1844 BlackPixel(getBaseDisplay().getXDisplay(),
1845 getScreenNumber()));
1847 // load bevel, border and handle widths
1848 if (conf
.getValue("handleWidth", "HandleWidth", l
)) {
1849 if (l
<= size().w() / 2 && l
!= 0)
1850 resource
.handle_width
= l
;
1852 resource
.handle_width
= 6;
1854 resource
.handle_width
= 6;
1856 if (conf
.getValue("borderWidth", "BorderWidth", l
))
1857 resource
.border_width
= l
;
1859 resource
.border_width
= 1;
1861 if (conf
.getValue("bevelWidth", "BevelWidth", l
)) {
1862 if (l
<= size().w() / 2 && l
!= 0)
1863 resource
.bevel_width
= l
;
1865 resource
.bevel_width
= 3;
1867 resource
.bevel_width
= 3;
1869 if (conf
.getValue("frameWidth", "FrameWidth", l
)) {
1870 if (l
<= size().w() / 2)
1871 resource
.frame_width
= l
;
1873 resource
.frame_width
= resource
.bevel_width
;
1875 resource
.frame_width
= resource
.bevel_width
;
1877 const char *cmd
= resource
.root_command
;
1878 if (cmd
!= NULL
|| conf
.getValue("rootCommand", "RootCommand", s
)) {
1880 cmd
= s
.c_str(); // not specified by the screen, so use the one from the
1883 char displaystring
[MAXPATHLEN
];
1884 sprintf(displaystring
, "DISPLAY=%s",
1885 DisplayString(getBaseDisplay().getXDisplay()));
1886 sprintf(displaystring
+ strlen(displaystring
) - 1, "%d",
1889 bexec(cmd
, displaystring
);
1891 spawnlp(P_NOWAIT
, "cmd.exe", "cmd.exe", "/c", cmd
, NULL
);
1897 void BScreen::addIcon(OpenboxWindow
*w
) {
1900 w
->setWorkspace(-1);
1901 w
->setWindowNumber(iconList
->count());
1903 iconList
->insert(w
);
1905 iconmenu
->insert((const char **) w
->getIconTitle());
1910 void BScreen::removeIcon(OpenboxWindow
*w
) {
1913 iconList
->remove(w
->getWindowNumber());
1915 iconmenu
->remove(w
->getWindowNumber());
1918 LinkedListIterator
<OpenboxWindow
> it(iconList
);
1919 OpenboxWindow
*bw
= it
.current();
1920 for (int i
= 0; bw
; it
++, bw
= it
.current())
1921 bw
->setWindowNumber(i
++);
1925 OpenboxWindow
*BScreen::getIcon(int index
) {
1926 if (index
>= 0 && index
< iconList
->count())
1927 return iconList
->find(index
);
1933 int BScreen::addWorkspace(void) {
1934 Workspace
*wkspc
= new Workspace(*this, workspacesList
->count());
1935 workspacesList
->insert(wkspc
);
1936 setWorkspaceCount(workspaceCount()+1);
1937 saveWorkspaceNames();
1939 workspacemenu
->insert(wkspc
->getName(), wkspc
->getMenu(),
1940 wkspc
->getWorkspaceID() + 2);
1941 workspacemenu
->update();
1943 toolbar
->reconfigure();
1945 updateNetizenWorkspaceCount();
1947 return workspacesList
->count();
1951 int BScreen::removeLastWorkspace(void) {
1952 if (workspacesList
->count() == 1)
1955 Workspace
*wkspc
= workspacesList
->last();
1957 if (current_workspace
->getWorkspaceID() == wkspc
->getWorkspaceID())
1958 changeWorkspaceID(current_workspace
->getWorkspaceID() - 1);
1962 workspacemenu
->remove(wkspc
->getWorkspaceID() + 2);
1963 workspacemenu
->update();
1965 workspacesList
->remove(wkspc
);
1967 setWorkspaceCount(workspaceCount()-1);
1968 saveWorkspaceNames();
1970 toolbar
->reconfigure();
1972 updateNetizenWorkspaceCount();
1974 return workspacesList
->count();
1978 void BScreen::changeWorkspaceID(int id
) {
1979 if (! current_workspace
) return;
1981 if (id
!= current_workspace
->getWorkspaceID()) {
1982 current_workspace
->hideAll();
1984 workspacemenu
->setItemSelected(current_workspace
->getWorkspaceID() + 2,
1987 if (openbox
.focusedWindow() &&
1988 openbox
.focusedWindow()->getScreen() == this &&
1989 (! openbox
.focusedWindow()->isStuck())) {
1990 current_workspace
->setLastFocusedWindow(openbox
.focusedWindow());
1991 openbox
.focusWindow((OpenboxWindow
*) 0);
1994 current_workspace
= getWorkspace(id
);
1996 workspacemenu
->setItemSelected(current_workspace
->getWorkspaceID() + 2,
1998 toolbar
->redrawWorkspaceLabel(True
);
2000 current_workspace
->showAll();
2002 if (resource
.focus_last
&& current_workspace
->getLastFocusedWindow()) {
2003 XSync(openbox
.getXDisplay(), False
);
2004 current_workspace
->getLastFocusedWindow()->setInputFocus();
2008 updateNetizenCurrentWorkspace();
2012 void BScreen::addNetizen(Netizen
*n
) {
2013 netizenList
.push_back(n
);
2015 n
->sendWorkspaceCount();
2016 n
->sendCurrentWorkspace();
2018 LinkedListIterator
<Workspace
> it(workspacesList
);
2019 for (Workspace
*w
= it
.current(); w
; it
++, w
= it
.current()) {
2020 for (int i
= 0; i
< w
->getCount(); i
++)
2021 n
->sendWindowAdd(w
->getWindow(i
)->getClientWindow(),
2022 w
->getWorkspaceID());
2025 Window f
= ((openbox
.focusedWindow()) ?
2026 openbox
.focusedWindow()->getClientWindow() : None
);
2027 n
->sendWindowFocus(f
);
2031 void BScreen::removeNetizen(Window w
) {
2032 netList::iterator it
;
2035 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2036 if ((*it
)->getWindowID() == w
) {
2038 netizenList
.erase(it
);
2045 void BScreen::updateNetizenCurrentWorkspace(void) {
2046 netList::iterator it
;
2047 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2048 (*it
)->sendCurrentWorkspace();
2052 void BScreen::updateNetizenWorkspaceCount(void) {
2053 netList::iterator it
;
2054 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2055 (*it
)->sendWorkspaceCount();
2059 void BScreen::updateNetizenWindowFocus(void) {
2060 Window f
= ((openbox
.focusedWindow()) ?
2061 openbox
.focusedWindow()->getClientWindow() : None
);
2062 netList::iterator it
;
2063 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2064 (*it
)->sendWindowFocus(f
);
2067 void BScreen::updateNetizenWindowAdd(Window w
, unsigned long p
) {
2068 netList::iterator it
;
2069 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2070 (*it
)->sendWindowAdd(w
, p
);
2074 void BScreen::updateNetizenWindowDel(Window w
) {
2075 netList::iterator it
;
2076 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2077 (*it
)->sendWindowDel(w
);
2081 void BScreen::updateNetizenWindowRaise(Window w
) {
2082 netList::iterator it
;
2083 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2084 (*it
)->sendWindowRaise(w
);
2088 void BScreen::updateNetizenWindowLower(Window w
) {
2089 netList::iterator it
;
2090 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2091 (*it
)->sendWindowLower(w
);
2095 void BScreen::updateNetizenConfigNotify(XEvent
*e
) {
2096 netList::iterator it
;
2097 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2098 (*it
)->sendConfigNotify(e
);
2102 void BScreen::raiseWindows(Window
*workspace_stack
, int num
) {
2103 Window
*session_stack
= new
2104 Window
[(num
+ workspacesList
->count() + rootmenuList
.size() + 13)];
2107 XRaiseWindow(getBaseDisplay().getXDisplay(), iconmenu
->getWindowID());
2108 *(session_stack
+ i
++) = iconmenu
->getWindowID();
2110 LinkedListIterator
<Workspace
> wit(workspacesList
);
2111 for (Workspace
*tmp
= wit
.current(); tmp
; wit
++, tmp
= wit
.current())
2112 *(session_stack
+ i
++) = tmp
->getMenu()->getWindowID();
2114 *(session_stack
+ i
++) = workspacemenu
->getWindowID();
2116 *(session_stack
+ i
++) = configmenu
->getFocusmenu()->getWindowID();
2117 *(session_stack
+ i
++) = configmenu
->getPlacementmenu()->getWindowID();
2118 *(session_stack
+ i
++) = configmenu
->getWindowID();
2121 *(session_stack
+ i
++) = slit
->getMenu()->getDirectionmenu()->getWindowID();
2122 *(session_stack
+ i
++) = slit
->getMenu()->getPlacementmenu()->getWindowID();
2123 *(session_stack
+ i
++) = slit
->getMenu()->getWindowID();
2126 *(session_stack
+ i
++) =
2127 toolbar
->getMenu()->getPlacementmenu()->getWindowID();
2128 *(session_stack
+ i
++) = toolbar
->getMenu()->getWindowID();
2130 menuList::iterator rit
;
2131 for (rit
= rootmenuList
.begin(); rit
!= rootmenuList
.end(); ++rit
)
2132 *(session_stack
+ i
++) = (*rit
)->getWindowID();
2133 *(session_stack
+ i
++) = rootmenu
->getWindowID();
2135 if (toolbar
->onTop())
2136 *(session_stack
+ i
++) = toolbar
->getWindowID();
2140 *(session_stack
+ i
++) = slit
->getWindowID();
2144 *(session_stack
+ i
++) = *(workspace_stack
+ k
);
2146 XRestackWindows(getBaseDisplay().getXDisplay(), session_stack
, i
);
2148 delete [] session_stack
;
2152 void BScreen::addWorkspaceName(const char *name
) {
2153 workspaceNames
->insert(bstrdup(name
));
2156 char* BScreen::getNameOfWorkspace(int id
) {
2159 if (id
>= 0 && id
< workspaceNames
->count()) {
2160 char *wkspc_name
= workspaceNames
->find(id
);
2169 void BScreen::reassociateWindow(OpenboxWindow
*w
, int wkspc_id
, Bool ignore_sticky
) {
2173 wkspc_id
= current_workspace
->getWorkspaceID();
2175 if (w
->getWorkspaceNumber() == wkspc_id
)
2178 if (w
->isIconic()) {
2180 getWorkspace(wkspc_id
)->addWindow(w
);
2181 } else if (ignore_sticky
|| ! w
->isStuck()) {
2182 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
2183 getWorkspace(wkspc_id
)->addWindow(w
);
2188 void BScreen::nextFocus(void) {
2189 Bool have_focused
= False
;
2190 int focused_window_number
= -1;
2191 OpenboxWindow
*next
;
2193 if (openbox
.focusedWindow()) {
2194 if (openbox
.focusedWindow()->getScreen()->getScreenNumber() ==
2195 getScreenNumber()) {
2196 have_focused
= True
;
2197 focused_window_number
= openbox
.focusedWindow()->getWindowNumber();
2201 if ((getCurrentWorkspace()->getCount() > 1) && have_focused
) {
2202 int next_window_number
= focused_window_number
;
2204 if ((++next_window_number
) >= getCurrentWorkspace()->getCount())
2205 next_window_number
= 0;
2207 next
= getCurrentWorkspace()->getWindow(next_window_number
);
2208 } while ((! next
->setInputFocus()) && (next_window_number
!=
2209 focused_window_number
));
2211 if (next_window_number
!= focused_window_number
)
2212 getCurrentWorkspace()->raiseWindow(next
);
2213 } else if (getCurrentWorkspace()->getCount() >= 1) {
2214 next
= current_workspace
->getWindow(0);
2216 current_workspace
->raiseWindow(next
);
2217 next
->setInputFocus();
2222 void BScreen::prevFocus(void) {
2223 Bool have_focused
= False
;
2224 int focused_window_number
= -1;
2225 OpenboxWindow
*prev
;
2227 if (openbox
.focusedWindow()) {
2228 if (openbox
.focusedWindow()->getScreen()->getScreenNumber() ==
2229 getScreenNumber()) {
2230 have_focused
= True
;
2231 focused_window_number
= openbox
.focusedWindow()->getWindowNumber();
2235 if ((getCurrentWorkspace()->getCount() > 1) && have_focused
) {
2236 int prev_window_number
= focused_window_number
;
2238 if ((--prev_window_number
) < 0)
2239 prev_window_number
= getCurrentWorkspace()->getCount() - 1;
2241 prev
= getCurrentWorkspace()->getWindow(prev_window_number
);
2242 } while ((! prev
->setInputFocus()) && (prev_window_number
!=
2243 focused_window_number
));
2245 if (prev_window_number
!= focused_window_number
)
2246 getCurrentWorkspace()->raiseWindow(prev
);
2247 } else if (getCurrentWorkspace()->getCount() >= 1) {
2248 prev
= current_workspace
->getWindow(0);
2250 current_workspace
->raiseWindow(prev
);
2251 prev
->setInputFocus();
2256 void BScreen::raiseFocus(void) {
2257 Bool have_focused
= False
;
2258 int focused_window_number
= -1;
2260 if (openbox
.focusedWindow()) {
2261 if (openbox
.focusedWindow()->getScreen()->getScreenNumber() ==
2262 getScreenNumber()) {
2263 have_focused
= True
;
2264 focused_window_number
= openbox
.focusedWindow()->getWindowNumber();
2268 if ((getCurrentWorkspace()->getCount() > 1) && have_focused
)
2269 getWorkspace(openbox
.focusedWindow()->getWorkspaceNumber())->
2270 raiseWindow(openbox
.focusedWindow());
2274 void BScreen::InitMenu(void) {
2276 while (!rootmenuList
.empty())
2277 rootmenuList
.erase(rootmenuList
.begin());
2279 while (rootmenu
->getCount())
2280 rootmenu
->remove(0);
2282 rootmenu
= new Rootmenu(*this);
2284 Bool defaultMenu
= True
;
2286 if (openbox
.getMenuFilename()) {
2287 FILE *menu_file
= fopen(openbox
.getMenuFilename(), "r");
2290 perror(openbox
.getMenuFilename());
2292 if (feof(menu_file
)) {
2293 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenEmptyMenuFile
,
2294 "%s: Empty menu file"),
2295 openbox
.getMenuFilename());
2297 char line
[1024], label
[1024];
2298 memset(line
, 0, 1024);
2299 memset(label
, 0, 1024);
2301 while (fgets(line
, 1024, menu_file
) && ! feof(menu_file
)) {
2302 if (line
[0] != '#') {
2303 int i
, key
= 0, index
= -1, len
= strlen(line
);
2306 for (i
= 0; i
< len
; i
++) {
2307 if (line
[i
] == '[') index
= 0;
2308 else if (line
[i
] == ']') break;
2309 else if (line
[i
] != ' ')
2311 key
+= tolower(line
[i
]);
2316 for (i
= index
; i
< len
; i
++) {
2317 if (line
[i
] == '(') index
= 0;
2318 else if (line
[i
] == ')') break;
2319 else if (index
++ >= 0) {
2320 if (line
[i
] == '\\' && i
< len
- 1) i
++;
2321 label
[index
- 1] = line
[i
];
2325 if (index
== -1) index
= 0;
2326 label
[index
] = '\0';
2328 rootmenu
->setLabel(label
);
2329 defaultMenu
= parseMenuFile(menu_file
, rootmenu
);
2340 rootmenu
->setInternalMenu();
2341 rootmenu
->insert(i18n
->getMessage(ScreenSet
, Screenxterm
, "xterm"),
2343 i18n
->getMessage(ScreenSet
, Screenxterm
, "xterm"));
2344 rootmenu
->insert(i18n
->getMessage(ScreenSet
, ScreenRestart
, "Restart"),
2346 rootmenu
->insert(i18n
->getMessage(ScreenSet
, ScreenExit
, "Exit"),
2349 openbox
.setMenuFilename(openbox
.getMenuFilename());
2354 Bool
BScreen::parseMenuFile(FILE *file
, Rootmenu
*menu
) {
2355 char line
[1024], label
[1024], command
[1024];
2357 while (! feof(file
)) {
2358 memset(line
, 0, 1024);
2359 memset(label
, 0, 1024);
2360 memset(command
, 0, 1024);
2362 if (fgets(line
, 1024, file
)) {
2363 if (line
[0] != '#') {
2364 register int i
, key
= 0, parse
= 0, index
= -1,
2365 line_length
= strlen(line
),
2366 label_length
= 0, command_length
= 0;
2368 // determine the keyword
2370 for (i
= 0; i
< line_length
; i
++) {
2371 if (line
[i
] == '[') parse
= 1;
2372 else if (line
[i
] == ']') break;
2373 else if (line
[i
] != ' ')
2375 key
+= tolower(line
[i
]);
2378 // get the label enclosed in ()'s
2381 for (i
= 0; i
< line_length
; i
++) {
2382 if (line
[i
] == '(') {
2385 } else if (line
[i
] == ')') break;
2386 else if (index
++ >= 0) {
2387 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
2388 label
[index
- 1] = line
[i
];
2393 label
[index
] = '\0';
2394 label_length
= index
;
2400 // get the command enclosed in {}'s
2403 for (i
= 0; i
< line_length
; i
++) {
2404 if (line
[i
] == '{') {
2407 } else if (line
[i
] == '}') break;
2408 else if (index
++ >= 0) {
2409 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
2410 command
[index
- 1] = line
[i
];
2415 command
[index
] = '\0';
2416 command_length
= index
;
2424 return ((menu
->getCount() == 0) ? True
: False
);
2429 menu
->insert(label
);
2434 if ((! *label
) && (! *command
)) {
2435 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenEXECError
,
2436 "BScreen::parseMenuFile: [exec] error, "
2437 "no menu label and/or command defined\n"));
2441 menu
->insert(label
, BScreen::Execute
, command
);
2447 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenEXITError
,
2448 "BScreen::parseMenuFile: [exit] error, "
2449 "no menu label defined\n"));
2453 menu
->insert(label
, BScreen::Exit
);
2459 if ((! *label
) || (! *command
)) {
2460 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenSTYLEError
,
2461 "BScreen::parseMenuFile: [style] error, "
2462 "no menu label and/or filename defined\n"));
2466 char style
[MAXPATHLEN
];
2468 // perform shell style ~ home directory expansion
2470 int homedir_len
= 0;
2471 if (*command
== '~' && *(command
+ 1) == '/') {
2472 homedir
= getenv("HOME");
2473 homedir_len
= strlen(homedir
);
2476 if (homedir
&& homedir_len
!= 0) {
2477 strncpy(style
, homedir
, homedir_len
);
2479 strncpy(style
+ homedir_len
, command
+ 1,
2480 command_length
- 1);
2481 *(style
+ command_length
+ homedir_len
- 1) = '\0';
2483 strncpy(style
, command
, command_length
);
2484 *(style
+ command_length
) = '\0';
2487 menu
->insert(label
, BScreen::SetStyle
, style
);
2494 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenCONFIGError
,
2495 "BScreen::parseMenufile: [config] error, "
2496 "no label defined"));
2500 menu
->insert(label
, configmenu
);
2504 case 740: // include
2507 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenINCLUDEError
,
2508 "BScreen::parseMenuFile: [include] error, "
2509 "no filename defined\n"));
2513 char newfile
[MAXPATHLEN
];
2515 // perform shell style ~ home directory expansion
2517 int homedir_len
= 0;
2518 if (*label
== '~' && *(label
+ 1) == '/') {
2519 homedir
= getenv("HOME");
2520 homedir_len
= strlen(homedir
);
2523 if (homedir
&& homedir_len
!= 0) {
2524 strncpy(newfile
, homedir
, homedir_len
);
2526 strncpy(newfile
+ homedir_len
, label
+ 1,
2528 *(newfile
+ label_length
+ homedir_len
- 1) = '\0';
2530 strncpy(newfile
, label
, label_length
);
2531 *(newfile
+ label_length
) = '\0';
2535 FILE *submenufile
= fopen(newfile
, "r");
2539 if (fstat(fileno(submenufile
), &buf
) ||
2540 (! S_ISREG(buf
.st_mode
))) {
2542 i18n
->getMessage(ScreenSet
, ScreenINCLUDEErrorReg
,
2543 "BScreen::parseMenuFile: [include] error: "
2544 "'%s' is not a regular file\n"), newfile
);
2548 if (! feof(submenufile
)) {
2549 if (! parseMenuFile(submenufile
, menu
))
2550 openbox
.setMenuFilename(newfile
);
2552 fclose(submenufile
);
2561 case 767: // submenu
2564 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenSUBMENUError
,
2565 "BScreen::parseMenuFile: [submenu] error, "
2566 "no menu label defined\n"));
2570 Rootmenu
*submenu
= new Rootmenu(*this);
2573 submenu
->setLabel(command
);
2575 submenu
->setLabel(label
);
2577 parseMenuFile(file
, submenu
);
2579 menu
->insert(label
, submenu
);
2580 rootmenuList
.push_back(submenu
);
2585 case 773: // restart
2588 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenRESTARTError
,
2589 "BScreen::parseMenuFile: [restart] error, "
2590 "no menu label defined\n"));
2595 menu
->insert(label
, BScreen::RestartOther
, command
);
2597 menu
->insert(label
, BScreen::Restart
);
2602 case 845: // reconfig
2605 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenRECONFIGError
,
2606 "BScreen::parseMenuFile: [reconfig] error, "
2607 "no menu label defined\n"));
2611 menu
->insert(label
, BScreen::Reconfigure
);
2616 case 995: // stylesdir
2617 case 1113: // stylesmenu
2619 Bool newmenu
= ((key
== 1113) ? True
: False
);
2621 if ((! *label
) || ((! *command
) && newmenu
)) {
2623 i18n
->getMessage(ScreenSet
, ScreenSTYLESDIRError
,
2624 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
2625 " error, no directory defined\n"));
2629 char stylesdir
[MAXPATHLEN
];
2631 char *directory
= ((newmenu
) ? command
: label
);
2632 int directory_length
= ((newmenu
) ? command_length
: label_length
);
2634 // perform shell style ~ home directory expansion
2636 int homedir_len
= 0;
2638 if (*directory
== '~' && *(directory
+ 1) == '/') {
2639 homedir
= getenv("HOME");
2640 homedir_len
= strlen(homedir
);
2643 if (homedir
&& homedir_len
!= 0) {
2644 strncpy(stylesdir
, homedir
, homedir_len
);
2646 strncpy(stylesdir
+ homedir_len
, directory
+ 1,
2647 directory_length
- 1);
2648 *(stylesdir
+ directory_length
+ homedir_len
- 1) = '\0';
2650 strncpy(stylesdir
, directory
, directory_length
);
2651 *(stylesdir
+ directory_length
) = '\0';
2654 struct stat statbuf
;
2656 if (! stat(stylesdir
, &statbuf
)) {
2657 if (S_ISDIR(statbuf
.st_mode
)) {
2658 Rootmenu
*stylesmenu
;
2661 stylesmenu
= new Rootmenu(*this);
2665 DIR *d
= opendir(stylesdir
);
2669 // get the total number of directory entries
2670 while ((p
= readdir(d
))) entries
++;
2673 char **ls
= new char* [entries
];
2675 while ((p
= readdir(d
)))
2676 ls
[index
++] = bstrdup(p
->d_name
);
2680 std::sort(ls
, ls
+ entries
, dcmp());
2682 int n
, slen
= strlen(stylesdir
);
2683 for (n
= 0; n
< entries
; n
++) {
2684 if (ls
[n
][strlen(ls
[n
])-1] != '~') {
2685 int nlen
= strlen(ls
[n
]);
2686 char style
[MAXPATHLEN
+ 1];
2688 strncpy(style
, stylesdir
, slen
);
2689 *(style
+ slen
) = '/';
2690 strncpy(style
+ slen
+ 1, ls
[n
], nlen
+ 1);
2692 if ((! stat(style
, &statbuf
)) && S_ISREG(statbuf
.st_mode
))
2693 stylesmenu
->insert(ls
[n
], BScreen::SetStyle
, style
);
2701 stylesmenu
->update();
2704 stylesmenu
->setLabel(label
);
2705 menu
->insert(label
, stylesmenu
);
2706 rootmenuList
.push_back(stylesmenu
);
2709 openbox
.setMenuFilename(stylesdir
);
2711 fprintf(stderr
, i18n
->getMessage(ScreenSet
,
2712 ScreenSTYLESDIRErrorNotDir
,
2713 "BScreen::parseMenuFile:"
2714 " [stylesdir/stylesmenu] error, %s is not a"
2715 " directory\n"), stylesdir
);
2719 i18n
->getMessage(ScreenSet
, ScreenSTYLESDIRErrorNoExist
,
2720 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
2721 " error, %s does not exist\n"), stylesdir
);
2727 case 1090: // workspaces
2731 i18n
->getMessage(ScreenSet
, ScreenWORKSPACESError
,
2732 "BScreen:parseMenuFile: [workspaces] error, "
2733 "no menu label defined\n"));
2737 menu
->insert(label
, workspacemenu
);
2746 return ((menu
->getCount() == 0) ? True
: False
);
2750 void BScreen::shutdown(void) {
2753 XSelectInput(getBaseDisplay().getXDisplay(), getRootWindow(), NoEventMask
);
2754 XSync(getBaseDisplay().getXDisplay(), False
);
2756 LinkedListIterator
<Workspace
> it(workspacesList
);
2757 for (Workspace
*w
= it
.current(); w
; it
++, w
= it
.current())
2760 while (iconList
->count()) {
2761 iconList
->first()->restore();
2762 delete iconList
->first();
2773 void BScreen::showPosition(int x
, int y
) {
2774 if (! geom_visible
) {
2775 XMoveResizeWindow(getBaseDisplay().getXDisplay(), geom_window
,
2776 (size().w() - geom_w
) / 2,
2777 (size().h() - geom_h
) / 2, geom_w
, geom_h
);
2778 XMapWindow(getBaseDisplay().getXDisplay(), geom_window
);
2779 XRaiseWindow(getBaseDisplay().getXDisplay(), geom_window
);
2781 geom_visible
= True
;
2786 sprintf(label
, i18n
->getMessage(ScreenSet
, ScreenPositionFormat
,
2787 "X: %4d x Y: %4d"), x
, y
);
2789 XClearWindow(getBaseDisplay().getXDisplay(), geom_window
);
2791 if (i18n
->multibyte()) {
2792 XmbDrawString(getBaseDisplay().getXDisplay(), geom_window
,
2793 resource
.wstyle
.fontset
, resource
.wstyle
.l_text_focus_gc
,
2794 resource
.bevel_width
, resource
.bevel_width
-
2795 resource
.wstyle
.fontset_extents
->max_ink_extent
.y
,
2796 label
, strlen(label
));
2798 XDrawString(getBaseDisplay().getXDisplay(), geom_window
,
2799 resource
.wstyle
.l_text_focus_gc
,
2800 resource
.bevel_width
,
2801 resource
.wstyle
.font
->ascent
+
2802 resource
.bevel_width
, label
, strlen(label
));
2807 void BScreen::showGeometry(unsigned int gx
, unsigned int gy
) {
2808 if (! geom_visible
) {
2809 XMoveResizeWindow(getBaseDisplay().getXDisplay(), geom_window
,
2810 (size().w() - geom_w
) / 2,
2811 (size().h() - geom_h
) / 2, geom_w
, geom_h
);
2812 XMapWindow(getBaseDisplay().getXDisplay(), geom_window
);
2813 XRaiseWindow(getBaseDisplay().getXDisplay(), geom_window
);
2815 geom_visible
= True
;
2820 sprintf(label
, i18n
->getMessage(ScreenSet
, ScreenGeometryFormat
,
2821 "W: %4d x H: %4d"), gx
, gy
);
2823 XClearWindow(getBaseDisplay().getXDisplay(), geom_window
);
2825 if (i18n
->multibyte()) {
2826 XmbDrawString(getBaseDisplay().getXDisplay(), geom_window
,
2827 resource
.wstyle
.fontset
, resource
.wstyle
.l_text_focus_gc
,
2828 resource
.bevel_width
, resource
.bevel_width
-
2829 resource
.wstyle
.fontset_extents
->max_ink_extent
.y
,
2830 label
, strlen(label
));
2832 XDrawString(getBaseDisplay().getXDisplay(), geom_window
,
2833 resource
.wstyle
.l_text_focus_gc
,
2834 resource
.bevel_width
,
2835 resource
.wstyle
.font
->ascent
+
2836 resource
.bevel_width
, label
, strlen(label
));
2840 void BScreen::hideGeometry(void) {
2842 XUnmapWindow(getBaseDisplay().getXDisplay(), geom_window
);
2843 geom_visible
= False
;