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
;
226 pid_t bpid
= getpid();
228 XChangeProperty(getBaseDisplay().getXDisplay(), getRootWindow(),
229 openbox
.getOpenboxPidAtom(), XA_CARDINAL
,
230 sizeof(pid_t
) * 8, PropModeReplace
,
231 (unsigned char *) &bpid
, 1);
232 #endif // HAVE_GETPID
234 XDefineCursor(getBaseDisplay().getXDisplay(), getRootWindow(),
235 openbox
.getSessionCursor());
237 workspaceNames
= new LinkedList
<char>;
238 workspacesList
= new LinkedList
<Workspace
>;
239 iconList
= new LinkedList
<OpenboxWindow
>;
242 new BImageControl(openbox
, *this, True
, openbox
.getColorsPerChannel(),
243 openbox
.getCacheLife(), openbox
.getCacheMax());
244 image_control
->installRootColormap();
245 root_colormap_installed
= True
;
247 load(); // load config options from Resources
251 unsigned long gc_value_mask
= GCForeground
;
252 if (! i18n
->multibyte()) gc_value_mask
|= GCFont
;
254 gcv
.foreground
= WhitePixel(getBaseDisplay().getXDisplay(),
256 ^ BlackPixel(getBaseDisplay().getXDisplay(),
258 gcv
.function
= GXxor
;
259 gcv
.subwindow_mode
= IncludeInferiors
;
260 opGC
= XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
261 GCForeground
| GCFunction
| GCSubwindowMode
, &gcv
);
263 gcv
.foreground
= resource
.wstyle
.l_text_focus
.getPixel();
264 if (resource
.wstyle
.font
)
265 gcv
.font
= resource
.wstyle
.font
->fid
;
266 resource
.wstyle
.l_text_focus_gc
=
267 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
268 gc_value_mask
, &gcv
);
270 gcv
.foreground
= resource
.wstyle
.l_text_unfocus
.getPixel();
271 if (resource
.wstyle
.font
)
272 gcv
.font
= resource
.wstyle
.font
->fid
;
273 resource
.wstyle
.l_text_unfocus_gc
=
274 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
275 gc_value_mask
, &gcv
);
277 gcv
.foreground
= resource
.wstyle
.b_pic_focus
.getPixel();
278 resource
.wstyle
.b_pic_focus_gc
=
279 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
282 gcv
.foreground
= resource
.wstyle
.b_pic_unfocus
.getPixel();
283 resource
.wstyle
.b_pic_unfocus_gc
=
284 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
287 gcv
.foreground
= resource
.mstyle
.t_text
.getPixel();
288 if (resource
.mstyle
.t_font
)
289 gcv
.font
= resource
.mstyle
.t_font
->fid
;
290 resource
.mstyle
.t_text_gc
=
291 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
292 gc_value_mask
, &gcv
);
294 gcv
.foreground
= resource
.mstyle
.f_text
.getPixel();
295 if (resource
.mstyle
.f_font
)
296 gcv
.font
= resource
.mstyle
.f_font
->fid
;
297 resource
.mstyle
.f_text_gc
=
298 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
299 gc_value_mask
, &gcv
);
301 gcv
.foreground
= resource
.mstyle
.h_text
.getPixel();
302 resource
.mstyle
.h_text_gc
=
303 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
304 gc_value_mask
, &gcv
);
306 gcv
.foreground
= resource
.mstyle
.d_text
.getPixel();
307 resource
.mstyle
.d_text_gc
=
308 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
309 gc_value_mask
, &gcv
);
311 gcv
.foreground
= resource
.mstyle
.hilite
.getColor()->getPixel();
312 resource
.mstyle
.hilite_gc
=
313 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
314 gc_value_mask
, &gcv
);
316 gcv
.foreground
= resource
.tstyle
.l_text
.getPixel();
317 if (resource
.tstyle
.font
)
318 gcv
.font
= resource
.tstyle
.font
->fid
;
319 resource
.tstyle
.l_text_gc
=
320 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
321 gc_value_mask
, &gcv
);
323 gcv
.foreground
= resource
.tstyle
.w_text
.getPixel();
324 resource
.tstyle
.w_text_gc
=
325 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
326 gc_value_mask
, &gcv
);
328 gcv
.foreground
= resource
.tstyle
.c_text
.getPixel();
329 resource
.tstyle
.c_text_gc
=
330 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
331 gc_value_mask
, &gcv
);
333 gcv
.foreground
= resource
.tstyle
.b_pic
.getPixel();
334 resource
.tstyle
.b_pic_gc
=
335 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
336 gc_value_mask
, &gcv
);
338 const char *s
= i18n
->getMessage(ScreenSet
, ScreenPositionLength
,
339 "0: 0000 x 0: 0000");
342 if (i18n
->multibyte()) {
343 XRectangle ink
, logical
;
344 XmbTextExtents(resource
.wstyle
.fontset
, s
, l
, &ink
, &logical
);
345 geom_w
= logical
.width
;
347 geom_h
= resource
.wstyle
.fontset_extents
->max_ink_extent
.height
;
349 geom_h
= resource
.wstyle
.font
->ascent
+
350 resource
.wstyle
.font
->descent
;
352 geom_w
= XTextWidth(resource
.wstyle
.font
, s
, l
);
355 geom_w
+= (resource
.bevel_width
* 2);
356 geom_h
+= (resource
.bevel_width
* 2);
358 XSetWindowAttributes attrib
;
359 unsigned long mask
= CWBorderPixel
| CWColormap
| CWSaveUnder
;
360 attrib
.border_pixel
= getBorderColor()->getPixel();
361 attrib
.colormap
= getColormap();
362 attrib
.save_under
= True
;
365 XCreateWindow(getBaseDisplay().getXDisplay(), getRootWindow(),
366 0, 0, geom_w
, geom_h
, resource
.border_width
, getDepth(),
367 InputOutput
, getVisual(), mask
, &attrib
);
368 geom_visible
= False
;
370 if (resource
.wstyle
.l_focus
.getTexture() & BImage_ParentRelative
) {
371 if (resource
.wstyle
.t_focus
.getTexture() ==
372 (BImage_Flat
| BImage_Solid
)) {
374 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window
,
375 resource
.wstyle
.t_focus
.getColor()->getPixel());
377 geom_pixmap
= image_control
->renderImage(geom_w
, geom_h
,
378 &resource
.wstyle
.t_focus
);
379 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
380 geom_window
, geom_pixmap
);
383 if (resource
.wstyle
.l_focus
.getTexture() ==
384 (BImage_Flat
| BImage_Solid
)) {
386 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window
,
387 resource
.wstyle
.l_focus
.getColor()->getPixel());
389 geom_pixmap
= image_control
->renderImage(geom_w
, geom_h
,
390 &resource
.wstyle
.l_focus
);
391 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
392 geom_window
, geom_pixmap
);
396 workspacemenu
= new Workspacemenu(*this);
397 iconmenu
= new Iconmenu(*this);
398 configmenu
= new Configmenu(*this);
400 Workspace
*wkspc
= NULL
;
401 if (resource
.workspaces
!= 0) {
402 for (int i
= 0; i
< resource
.workspaces
; ++i
) {
403 wkspc
= new Workspace(*this, workspacesList
->count());
404 workspacesList
->insert(wkspc
);
405 workspacemenu
->insert(wkspc
->getName(), wkspc
->getMenu());
408 wkspc
= new Workspace(*this, workspacesList
->count());
409 workspacesList
->insert(wkspc
);
410 workspacemenu
->insert(wkspc
->getName(), wkspc
->getMenu());
412 saveWorkspaceNames();
414 workspacemenu
->insert(i18n
->getMessage(IconSet
, IconIcons
, "Icons"),
416 workspacemenu
->update();
418 current_workspace
= workspacesList
->first();
419 workspacemenu
->setItemSelected(2, True
);
421 toolbar
= new Toolbar(*this, config
);
424 slit
= new Slit(*this, config
);
432 changeWorkspaceID(0);
436 Window r
, p
, *children
;
437 XQueryTree(getBaseDisplay().getXDisplay(), getRootWindow(), &r
, &p
,
440 // preen the window list of all icon windows... for better dockapp support
441 for (i
= 0; i
< (int) nchild
; i
++) {
442 if (children
[i
] == None
) continue;
444 XWMHints
*wmhints
= XGetWMHints(getBaseDisplay().getXDisplay(),
448 if ((wmhints
->flags
& IconWindowHint
) &&
449 (wmhints
->icon_window
!= children
[i
]))
450 for (int j
= 0; j
< (int) nchild
; j
++)
451 if (children
[j
] == wmhints
->icon_window
) {
461 // manage shown windows
462 for (i
= 0; i
< (int) nchild
; ++i
) {
463 if (children
[i
] == None
|| (! openbox
.validateWindow(children
[i
])))
466 XWindowAttributes attrib
;
467 if (XGetWindowAttributes(getBaseDisplay().getXDisplay(), children
[i
],
469 if (attrib
.override_redirect
) continue;
471 if (attrib
.map_state
!= IsUnmapped
) {
472 new OpenboxWindow(openbox
, children
[i
], this);
474 OpenboxWindow
*win
= openbox
.searchWindow(children
[i
]);
476 XMapRequestEvent mre
;
477 mre
.window
= children
[i
];
478 win
->restoreAttributes();
479 win
->mapRequestEvent(&mre
);
485 XSetInputFocus(getBaseDisplay().getXDisplay(),
486 PointerRoot
, None
, CurrentTime
);
489 XFlush(getBaseDisplay().getXDisplay());
493 BScreen::~BScreen(void) {
494 if (! managed
) return;
496 if (geom_pixmap
!= None
)
497 image_control
->removeImage(geom_pixmap
);
499 if (geom_window
!= None
)
500 XDestroyWindow(getBaseDisplay().getXDisplay(), geom_window
);
502 removeWorkspaceNames();
504 while (workspacesList
->count())
505 delete workspacesList
->remove(0);
507 while (!rootmenuList
.empty())
508 rootmenuList
.erase(rootmenuList
.begin());
510 while (iconList
->count())
511 delete iconList
->remove(0);
513 while (!netizenList
.empty())
514 netizenList
.erase(netizenList
.begin());
517 if (resource
.strftime_format
)
518 delete [] resource
.strftime_format
;
519 #endif // HAVE_STRFTIME
522 delete workspacemenu
;
531 delete image_control
;
533 delete workspacesList
;
534 delete workspaceNames
;
537 if (resource
.wstyle
.fontset
)
538 XFreeFontSet(getBaseDisplay().getXDisplay(), resource
.wstyle
.fontset
);
539 if (resource
.mstyle
.t_fontset
)
540 XFreeFontSet(getBaseDisplay().getXDisplay(), resource
.mstyle
.t_fontset
);
541 if (resource
.mstyle
.f_fontset
)
542 XFreeFontSet(getBaseDisplay().getXDisplay(), resource
.mstyle
.f_fontset
);
543 if (resource
.tstyle
.fontset
)
544 XFreeFontSet(getBaseDisplay().getXDisplay(), resource
.tstyle
.fontset
);
546 if (resource
.wstyle
.font
)
547 XFreeFont(getBaseDisplay().getXDisplay(), resource
.wstyle
.font
);
548 if (resource
.mstyle
.t_font
)
549 XFreeFont(getBaseDisplay().getXDisplay(), resource
.mstyle
.t_font
);
550 if (resource
.mstyle
.f_font
)
551 XFreeFont(getBaseDisplay().getXDisplay(), resource
.mstyle
.f_font
);
552 if (resource
.tstyle
.font
)
553 XFreeFont(getBaseDisplay().getXDisplay(), resource
.tstyle
.font
);
554 if (resource
.root_command
!= NULL
)
555 delete [] resource
.root_command
;
557 XFreeGC(getBaseDisplay().getXDisplay(), opGC
);
559 XFreeGC(getBaseDisplay().getXDisplay(),
560 resource
.wstyle
.l_text_focus_gc
);
561 XFreeGC(getBaseDisplay().getXDisplay(),
562 resource
.wstyle
.l_text_unfocus_gc
);
563 XFreeGC(getBaseDisplay().getXDisplay(),
564 resource
.wstyle
.b_pic_focus_gc
);
565 XFreeGC(getBaseDisplay().getXDisplay(),
566 resource
.wstyle
.b_pic_unfocus_gc
);
568 XFreeGC(getBaseDisplay().getXDisplay(),
569 resource
.mstyle
.t_text_gc
);
570 XFreeGC(getBaseDisplay().getXDisplay(),
571 resource
.mstyle
.f_text_gc
);
572 XFreeGC(getBaseDisplay().getXDisplay(),
573 resource
.mstyle
.h_text_gc
);
574 XFreeGC(getBaseDisplay().getXDisplay(),
575 resource
.mstyle
.d_text_gc
);
576 XFreeGC(getBaseDisplay().getXDisplay(),
577 resource
.mstyle
.hilite_gc
);
579 XFreeGC(getBaseDisplay().getXDisplay(),
580 resource
.tstyle
.l_text_gc
);
581 XFreeGC(getBaseDisplay().getXDisplay(),
582 resource
.tstyle
.w_text_gc
);
583 XFreeGC(getBaseDisplay().getXDisplay(),
584 resource
.tstyle
.c_text_gc
);
585 XFreeGC(getBaseDisplay().getXDisplay(),
586 resource
.tstyle
.b_pic_gc
);
590 Rect
BScreen::availableArea() const {
591 // the following code is temporary and will be taken care of by Screen in the
592 // future (with the NETWM 'strut')
593 Rect
space(0, 0, size().w(), size().h());
594 if (!resource
.full_max
) {
596 int slit_x
= slit
->autoHide() ? slit
->hiddenOrigin().x() : slit
->area().x(),
597 slit_y
= slit
->autoHide() ? slit
->hiddenOrigin().y() : slit
->area().y();
598 int tbarh
= resource
.hide_toolbar
? 0 :
599 toolbar
->getExposedHeight() + resource
.border_width
* 2;
601 switch (toolbar
->placement()) {
602 case Toolbar::TopLeft
:
603 case Toolbar::TopCenter
:
604 case Toolbar::TopRight
:
607 case Toolbar::BottomLeft
:
608 case Toolbar::BottomCenter
:
609 case Toolbar::BottomRight
:
613 ASSERT(false); // unhandled placement
615 if ((slit
->direction() == Slit::Horizontal
&&
616 (slit
->placement() == Slit::TopLeft
||
617 slit
->placement() == Slit::TopRight
)) ||
618 slit
->placement() == Slit::TopCenter
) {
620 if (tbartop
&& slit_y
+ slit
->area().h() < tbarh
) {
621 space
.setY(space
.y() + tbarh
);
622 space
.setH(space
.h() - tbarh
);
624 space
.setY(space
.y() + (slit_y
+ slit
->area().h() +
625 resource
.border_width
* 2));
626 space
.setH(space
.h() - (slit_y
+ slit
->area().h() +
627 resource
.border_width
* 2));
629 space
.setH(space
.h() - tbarh
);
631 } else if ((slit
->direction() == Slit::Vertical
&&
632 (slit
->placement() == Slit::TopRight
||
633 slit
->placement() == Slit::BottomRight
)) ||
634 slit
->placement() == Slit::CenterRight
) {
636 space
.setW(space
.w() - (size().w() - slit_x
));
638 space
.setY(space
.y() + tbarh
);
639 space
.setH(space
.h() - tbarh
);
640 } else if ((slit
->direction() == Slit::Horizontal
&&
641 (slit
->placement() == Slit::BottomLeft
||
642 slit
->placement() == Slit::BottomRight
)) ||
643 slit
->placement() == Slit::BottomCenter
) {
645 if (!tbartop
&& (size().h() - slit_y
) < tbarh
) {
646 space
.setH(space
.h() - tbarh
);
648 space
.setH(space
.h() - (size().h() - slit_y
));
650 space
.setY(space
.y() + tbarh
);
651 space
.setH(space
.h() - tbarh
);
654 } else {// if ((slit->direction() == Slit::Vertical &&
655 // (slit->placement() == Slit::TopLeft ||
656 // slit->placement() == Slit::BottomLeft)) ||
657 // slit->placement() == Slit::CenterLeft)
659 space
.setX(slit_x
+ slit
->area().w() +
660 resource
.border_width
* 2);
661 space
.setW(space
.w() - (slit_x
+ slit
->area().w() +
662 resource
.border_width
* 2));
664 space
.setY(space
.y() + tbarh
);
665 space
.setH(space
.h() - tbarh
);
668 int tbarh
= resource
.hide_toolbar() ? 0 :
669 toolbar
->getExposedHeight() + resource
.border_width
* 2;
670 switch (toolbar
->placement()) {
671 case Toolbar::TopLeft
:
672 case Toolbar::TopCenter
:
673 case Toolbar::TopRight
:
674 space
.setY(toolbar
->getExposedHeight());
675 space
.setH(space
.h() - toolbar
->getExposedHeight());
677 case Toolbar::BottomLeft
:
678 case Toolbar::BottomCenter
:
679 case Toolbar::BottomRight
:
680 space
.setH(space
.h() - tbarh
);
683 ASSERT(false); // unhandled placement
691 void BScreen::readDatabaseTexture(const char *rname
, const char *rclass
,
693 unsigned long default_pixel
)
697 if (resource
.styleconfig
.getValue(rname
, rclass
, s
))
698 image_control
->parseTexture(texture
, s
.c_str());
700 texture
->setTexture(BImage_Solid
| BImage_Flat
);
702 if (texture
->getTexture() & BImage_Solid
) {
703 int clen
= strlen(rclass
) + 32, nlen
= strlen(rname
) + 32;
705 char *colorclass
= new char[clen
], *colorname
= new char[nlen
];
707 sprintf(colorclass
, "%s.Color", rclass
);
708 sprintf(colorname
, "%s.color", rname
);
710 readDatabaseColor(colorname
, colorclass
, texture
->getColor(),
714 sprintf(colorclass
, "%s.ColorTo", rclass
);
715 sprintf(colorname
, "%s.colorTo", rname
);
717 readDatabaseColor(colorname
, colorclass
, texture
->getColorTo(),
721 delete [] colorclass
;
724 if ((! texture
->getColor()->isAllocated()) ||
725 (texture
->getTexture() & BImage_Flat
))
730 xcol
.red
= (unsigned int) (texture
->getColor()->getRed() +
731 (texture
->getColor()->getRed() >> 1));
732 if (xcol
.red
>= 0xff) xcol
.red
= 0xffff;
733 else xcol
.red
*= 0xff;
734 xcol
.green
= (unsigned int) (texture
->getColor()->getGreen() +
735 (texture
->getColor()->getGreen() >> 1));
736 if (xcol
.green
>= 0xff) xcol
.green
= 0xffff;
737 else xcol
.green
*= 0xff;
738 xcol
.blue
= (unsigned int) (texture
->getColor()->getBlue() +
739 (texture
->getColor()->getBlue() >> 1));
740 if (xcol
.blue
>= 0xff) xcol
.blue
= 0xffff;
741 else xcol
.blue
*= 0xff;
743 if (! XAllocColor(getBaseDisplay().getXDisplay(),
744 getColormap(), &xcol
))
747 texture
->getHiColor()->setPixel(xcol
.pixel
);
750 (unsigned int) ((texture
->getColor()->getRed() >> 2) +
751 (texture
->getColor()->getRed() >> 1)) * 0xff;
753 (unsigned int) ((texture
->getColor()->getGreen() >> 2) +
754 (texture
->getColor()->getGreen() >> 1)) * 0xff;
756 (unsigned int) ((texture
->getColor()->getBlue() >> 2) +
757 (texture
->getColor()->getBlue() >> 1)) * 0xff;
759 if (! XAllocColor(getBaseDisplay().getXDisplay(),
760 getColormap(), &xcol
))
763 texture
->getLoColor()->setPixel(xcol
.pixel
);
764 } else if (texture
->getTexture() & BImage_Gradient
) {
765 int clen
= strlen(rclass
) + 10, nlen
= strlen(rname
) + 10;
767 char *colorclass
= new char[clen
], *colorname
= new char[nlen
],
768 *colortoclass
= new char[clen
], *colortoname
= new char[nlen
];
770 sprintf(colorclass
, "%s.Color", rclass
);
771 sprintf(colorname
, "%s.color", rname
);
773 sprintf(colortoclass
, "%s.ColorTo", rclass
);
774 sprintf(colortoname
, "%s.colorTo", rname
);
776 readDatabaseColor(colorname
, colorclass
, texture
->getColor(),
778 readDatabaseColor(colortoname
, colortoclass
, texture
->getColorTo(),
781 delete [] colorclass
;
783 delete [] colortoclass
;
784 delete [] colortoname
;
789 void BScreen::readDatabaseColor(const char *rname
, const char *rclass
,
790 BColor
*color
, unsigned long default_pixel
)
794 if (resource
.styleconfig
.getValue(rname
, rclass
, s
))
795 image_control
->parseColor(color
, s
.c_str());
797 // parsing with no color std::string just deallocates the color, if it has
798 // been previously allocated
799 image_control
->parseColor(color
);
800 color
->setPixel(default_pixel
);
805 void BScreen::readDatabaseFontSet(const char *rname
, const char *rclass
,
807 if (! fontset
) return;
809 static char *defaultFont
= "fixed";
810 bool load_default
= false;
814 XFreeFontSet(getBaseDisplay().getXDisplay(), *fontset
);
816 if (resource
.styleconfig
.getValue(rname
, rclass
, s
)) {
817 if (! (*fontset
= createFontSet(s
.c_str())))
823 *fontset
= createFontSet(defaultFont
);
826 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenDefaultFontLoadFail
,
827 "BScreen::LoadStyle(): couldn't load default font.\n"));
834 void BScreen::readDatabaseFont(const char *rname
, const char *rclass
,
835 XFontStruct
**font
) {
838 static char *defaultFont
= "fixed";
839 bool load_default
= false;
843 XFreeFont(getBaseDisplay().getXDisplay(), *font
);
845 if (resource
.styleconfig
.getValue(rname
, rclass
, s
)) {
846 if ((*font
= XLoadQueryFont(getBaseDisplay().getXDisplay(),
847 s
.c_str())) == NULL
) {
848 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenFontLoadFail
,
849 "BScreen::LoadStyle(): couldn't load font '%s'\n"),
857 if ((*font
= XLoadQueryFont(getBaseDisplay().getXDisplay(),
858 defaultFont
)) == NULL
) {
859 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenDefaultFontLoadFail
,
860 "BScreen::LoadStyle(): couldn't load default font.\n"));
867 XFontSet
BScreen::createFontSet(const char *fontname
) {
869 char **missing
, *def
= "-";
870 int nmissing
, pixel_size
= 0, buf_size
= 0;
871 char weight
[FONT_ELEMENT_SIZE
], slant
[FONT_ELEMENT_SIZE
];
873 fs
= XCreateFontSet(getBaseDisplay().getXDisplay(),
874 fontname
, &missing
, &nmissing
, &def
);
875 if (fs
&& (! nmissing
)) return fs
;
877 #ifdef HAVE_SETLOCALE
879 if (nmissing
) XFreeStringList(missing
);
881 setlocale(LC_CTYPE
, "C");
882 fs
= XCreateFontSet(getBaseDisplay().getXDisplay(), fontname
,
883 &missing
, &nmissing
, &def
);
884 setlocale(LC_CTYPE
, "");
886 #endif // HAVE_SETLOCALE
889 XFontStruct
**fontstructs
;
891 XFontsOfFontSet(fs
, &fontstructs
, &fontnames
);
892 fontname
= fontnames
[0];
895 getFontElement(fontname
, weight
, FONT_ELEMENT_SIZE
,
896 "-medium-", "-bold-", "-demibold-", "-regular-", NULL
);
897 getFontElement(fontname
, slant
, FONT_ELEMENT_SIZE
,
898 "-r-", "-i-", "-o-", "-ri-", "-ro-", NULL
);
899 getFontSize(fontname
, &pixel_size
);
901 if (! strcmp(weight
, "*")) strncpy(weight
, "medium", FONT_ELEMENT_SIZE
);
902 if (! strcmp(slant
, "*")) strncpy(slant
, "r", FONT_ELEMENT_SIZE
);
903 if (pixel_size
< 3) pixel_size
= 3;
904 else if (pixel_size
> 97) pixel_size
= 97;
906 buf_size
= strlen(fontname
) + (FONT_ELEMENT_SIZE
* 2) + 64;
907 char *pattern2
= new char[buf_size
];
908 snprintf(pattern2
, buf_size
- 1,
910 "-*-*-%s-%s-*-*-%d-*-*-*-*-*-*-*,"
911 "-*-*-*-*-*-*-%d-*-*-*-*-*-*-*,*",
912 fontname
, weight
, slant
, pixel_size
, pixel_size
);
915 if (nmissing
) XFreeStringList(missing
);
916 if (fs
) XFreeFontSet(getBaseDisplay().getXDisplay(), fs
);
918 fs
= XCreateFontSet(getBaseDisplay().getXDisplay(), fontname
,
919 &missing
, &nmissing
, &def
);
926 void BScreen::setSloppyFocus(bool b
) {
927 resource
.sloppy_focus
= b
;
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::setAutoRaise(bool a
) {
939 resource
.auto_raise
= a
;
941 s
<< "session.screen" << getScreenNumber() << ".focusModel" << ends
;
942 config
.setValue(s
.str(),
943 (resource
.sloppy_focus
?
944 (resource
.auto_raise
? "AutoRaiseSloppyFocus" : "SloppyFocus")
946 s
.rdbuf()->freeze(0);
950 void BScreen::setImageDither(bool d
, bool reconfig
) {
951 image_control
->setDither(d
);
953 s
<< "session.screen" << getScreenNumber() << ".imageDither" << ends
;
954 config
.setValue(s
.str(), imageDither());
957 s
.rdbuf()->freeze(0);
961 void BScreen::setOpaqueMove(bool o
) {
962 resource
.opaque_move
= o
;
964 s
<< "session.screen" << getScreenNumber() << ".opaqueMove" << ends
;
965 config
.setValue(s
.str(), resource
.opaque_move
);
966 s
.rdbuf()->freeze(0);
970 void BScreen::setFullMax(bool f
) {
971 resource
.full_max
= f
;
973 s
<< "session.screen" << getScreenNumber() << ".fullMaximization" << ends
;
974 config
.setValue(s
.str(), resource
.full_max
);
975 s
.rdbuf()->freeze(0);
979 void BScreen::setFocusNew(bool f
) {
980 resource
.focus_new
= f
;
982 s
<< "session.screen" << getScreenNumber() << ".focusNewWindows" << ends
;
983 config
.setValue(s
.str(), resource
.focus_new
);
984 s
.rdbuf()->freeze(0);
988 void BScreen::setFocusLast(bool f
) {
989 resource
.focus_last
= f
;
991 s
<< "session.screen" << getScreenNumber() << ".focusLastWindow" << ends
;
992 config
.setValue(s
.str(), resource
.focus_last
);
993 s
.rdbuf()->freeze(0);
997 void BScreen::setWindowZones(int z
) {
1000 s
<< "session.screen" << getScreenNumber() << ".windowZones" << ends
;
1001 config
.setValue(s
.str(), resource
.zones
);
1002 s
.rdbuf()->freeze(0);
1006 void BScreen::setWorkspaceCount(int w
) {
1007 resource
.workspaces
= w
;
1009 s
<< "session.screen" << getScreenNumber() << ".workspaces" << ends
;
1010 config
.setValue(s
.str(), resource
.workspaces
);
1011 s
.rdbuf()->freeze(0);
1015 void BScreen::setPlacementPolicy(int p
) {
1016 resource
.placement_policy
= p
;
1018 s
<< "session.screen" << getScreenNumber() << ".windowPlacement" << ends
;
1019 const char *placement
;
1020 switch (resource
.placement_policy
) {
1021 case CascadePlacement
: placement
= "CascadePlacement"; break;
1022 case BestFitPlacement
: placement
= "BestFitPlacement"; break;
1023 case ColSmartPlacement
: placement
= "ColSmartPlacement"; break;
1024 case UnderMousePlacement
: placement
= "UnderMousePlacement"; break;
1025 case ClickMousePlacement
: placement
= "ClickMousePlacement"; break;
1027 case RowSmartPlacement
: placement
= "RowSmartPlacement"; break;
1029 config
.setValue(s
.str(), placement
);
1030 s
.rdbuf()->freeze(0);
1034 void BScreen::setEdgeSnapThreshold(int t
) {
1035 resource
.edge_snap_threshold
= t
;
1037 s
<< "session.screen" << getScreenNumber() << ".edgeSnapThreshold" << ends
;
1038 config
.setValue(s
.str(), resource
.edge_snap_threshold
);
1039 s
.rdbuf()->freeze(0);
1043 void BScreen::setRowPlacementDirection(int d
) {
1044 resource
.row_direction
= d
;
1046 s
<< "session.screen" << getScreenNumber() << ".rowPlacementDirection" << ends
;
1047 config
.setValue(s
.str(),
1048 resource
.row_direction
== LeftRight
?
1049 "LeftToRight" : "RightToLeft");
1050 s
.rdbuf()->freeze(0);
1054 void BScreen::setColPlacementDirection(int d
) {
1055 resource
.col_direction
= d
;
1057 s
<< "session.screen" << getScreenNumber() << ".colPlacementDirection" << ends
;
1058 config
.setValue(s
.str(),
1059 resource
.col_direction
== TopBottom
?
1060 "TopToBottom" : "BottomToTop");
1061 s
.rdbuf()->freeze(0);
1065 void BScreen::setRootCommand(const char *cmd
) {
1066 if (resource
.root_command
!= NULL
)
1067 delete [] resource
.root_command
;
1069 resource
.root_command
= bstrdup(cmd
);
1071 resource
.root_command
= NULL
;
1072 // this doesn't save to the Resources config because it can't be changed
1073 // inside Openbox, and this way we dont add an empty command which would over-
1074 // ride the styles command when none has been specified
1078 #ifdef HAVE_STRFTIME
1079 void BScreen::setStrftimeFormat(const char *f
) {
1080 if (resource
.strftime_format
!= NULL
)
1081 delete [] resource
.strftime_format
;
1083 resource
.strftime_format
= bstrdup(f
);
1085 s
<< "session.screen" << getScreenNumber() << ".strftimeFormat" << ends
;
1086 config
.setValue(s
.str(), resource
.strftime_format
);
1087 s
.rdbuf()->freeze(0);
1090 #else // !HAVE_STRFTIME
1091 void BScreen::setDateFormat(int f
) {
1092 resource
.date_format
= f
;
1094 s
<< "session.screen" << getScreenNumber() << ".dateFormat" << ends
;
1095 config
.setValue(s
.str(), resource
.date_format
== B_EuropeanDate
?
1096 "European" : "American");
1097 s
.rdbuf()->freeze(0);
1100 void BScreen::setClock24Hour(Bool c
) {
1101 resource
.clock24hour
= c
;
1103 s
<< "session.screen" << getScreenNumber() << ".clockFormat" << ends
;
1104 config
.setValue(s
.str(), resource
.clock24hour
? 24 : 12);
1105 s
.rdbuf()->freeze(0);
1107 #endif // HAVE_STRFTIME
1109 void BScreen::setHideToolbar(bool b
) {
1110 resource
.hide_toolbar
= b
;
1111 if (resource
.hide_toolbar
)
1112 getToolbar()->unMapToolbar();
1114 getToolbar()->mapToolbar();
1116 s
<< "session.screen" << getScreenNumber() << ".hideToolbar" << ends
;
1117 config
.setValue(s
.str(), resource
.hide_toolbar
? "True" : "False");
1118 s
.rdbuf()->freeze(0);
1121 void BScreen::saveWorkspaceNames() {
1122 ostrstream rc
, names
;
1124 for (int i
= 0; i
< resource
.workspaces
; i
++) {
1125 Workspace
*w
= getWorkspace(i
);
1127 names
<< w
->getName();
1128 if (i
< resource
.workspaces
-1)
1134 rc
<< "session.screen" << getScreenNumber() << ".workspaceNames" << ends
;
1135 config
.setValue(rc
.str(), names
.str());
1136 rc
.rdbuf()->freeze(0);
1137 names
.rdbuf()->freeze(0);
1140 void BScreen::save() {
1141 setSloppyFocus(resource
.sloppy_focus
);
1142 setAutoRaise(resource
.auto_raise
);
1143 setImageDither(imageDither(), false);
1144 setOpaqueMove(resource
.opaque_move
);
1145 setFullMax(resource
.full_max
);
1146 setFocusNew(resource
.focus_new
);
1147 setFocusLast(resource
.focus_last
);
1148 setWindowZones(resource
.zones
);
1149 setWorkspaceCount(resource
.workspaces
);
1150 setPlacementPolicy(resource
.placement_policy
);
1151 setEdgeSnapThreshold(resource
.edge_snap_threshold
);
1152 setRowPlacementDirection(resource
.row_direction
);
1153 setColPlacementDirection(resource
.col_direction
);
1154 setRootCommand(resource
.root_command
);
1155 #ifdef HAVE_STRFTIME
1156 // it deletes the current value before setting the new one, so we have to
1157 // duplicate the current value.
1158 std::string s
= resource
.strftime_format
;
1159 setStrftimeFormat(s
.c_str());
1160 #else // !HAVE_STRFTIME
1161 setDateFormat(resource
.date_format
);
1162 setClock24Hour(resource
.clock24hour
);
1163 #endif // HAVE_STRFTIME
1164 setHideToolbar(resource
.hide_toolbar
);
1168 void BScreen::load() {
1169 ostrstream rscreen
, rname
, rclass
;
1173 rscreen
<< "session.screen" << getScreenNumber() << '.' << ends
;
1175 rname
<< rscreen
.str() << "hideToolbar" << ends
;
1176 rclass
<< rscreen
.str() << "HideToolbar" << ends
;
1177 if (config
.getValue(rname
.str(), rclass
.str(), b
))
1178 resource
.hide_toolbar
= b
;
1180 resource
.hide_toolbar
= false;
1181 Toolbar
*t
= getToolbar();
1183 if (resource
.hide_toolbar
)
1189 rname
.seekp(0); rclass
.seekp(0);
1190 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1191 rname
<< rscreen
.str() << "fullMaximization" << ends
;
1192 rclass
<< rscreen
.str() << "FullMaximization" << ends
;
1193 if (config
.getValue(rname
.str(), rclass
.str(), b
))
1194 resource
.full_max
= b
;
1196 resource
.full_max
= false;
1198 rname
.seekp(0); rclass
.seekp(0);
1199 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1200 rname
<< rscreen
.str() << "focusNewWindows" << ends
;
1201 rclass
<< rscreen
.str() << "FocusNewWindows" << ends
;
1202 if (config
.getValue(rname
.str(), rclass
.str(), b
))
1203 resource
.focus_new
= b
;
1205 resource
.focus_new
= false;
1207 rname
.seekp(0); rclass
.seekp(0);
1208 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1209 rname
<< rscreen
.str() << "focusLastWindow" << ends
;
1210 rclass
<< rscreen
.str() << "FocusLastWindow" << ends
;
1211 if (config
.getValue(rname
.str(), rclass
.str(), b
))
1212 resource
.focus_last
= b
;
1214 resource
.focus_last
= false;
1216 rname
.seekp(0); rclass
.seekp(0);
1217 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1218 rname
<< rscreen
.str() << "rowPlacementDirection" << ends
;
1219 rclass
<< rscreen
.str() << "RowPlacementDirection" << ends
;
1220 if (config
.getValue(rname
.str(), rclass
.str(), s
)) {
1221 if (0 == strncasecmp(s
.c_str(), "RightToLeft", s
.length()))
1222 resource
.row_direction
= RightLeft
;
1223 else //if (0 == strncasecmp(s.c_str(), "LeftToRight", s.length()))
1224 resource
.row_direction
= LeftRight
;
1226 resource
.row_direction
= LeftRight
;
1228 rname
.seekp(0); rclass
.seekp(0);
1229 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1230 rname
<< rscreen
.str() << "colPlacementDirection" << ends
;
1231 rclass
<< rscreen
.str() << "ColPlacementDirection" << ends
;
1232 if (config
.getValue(rname
.str(), rclass
.str(), s
)) {
1233 if (0 == strncasecmp(s
.c_str(), "BottomToTop", s
.length()))
1234 resource
.col_direction
= BottomTop
;
1235 else //if (0 == strncasecmp(s.c_str(), "TopToBottom", s.length()))
1236 resource
.col_direction
= TopBottom
;
1238 resource
.col_direction
= TopBottom
;
1240 rname
.seekp(0); rclass
.seekp(0);
1241 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1242 rname
<< rscreen
.str() << "workspaces" << ends
;
1243 rclass
<< rscreen
.str() << "Workspaces" << ends
;
1244 if (config
.getValue(rname
.str(), rclass
.str(), l
)) {
1245 resource
.workspaces
= l
;
1247 resource
.workspaces
= 1;
1249 removeWorkspaceNames();
1250 rname
.seekp(0); rclass
.seekp(0);
1251 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1252 rname
<< rscreen
.str() << "workspaceNames" << ends
;
1253 rclass
<< rscreen
.str() << "WorkspaceNames" << ends
;
1254 if (config
.getValue(rname
.str(), rclass
.str(), s
)) {
1255 string::const_iterator it
= s
.begin(), end
= s
.end();
1257 string::const_iterator tmp
= it
;// current string.begin()
1258 it
= std::find(tmp
, end
, ','); // look for comma between tmp and end
1259 std::string
name(tmp
, it
); // name = s[tmp:it]
1260 addWorkspaceName(name
.c_str());
1267 rname
.seekp(0); rclass
.seekp(0);
1268 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1269 rname
<< rscreen
.str() << "focusModel" << ends
;
1270 rclass
<< rscreen
.str() << "FocusModel" << ends
;
1271 if (config
.getValue(rname
.str(), rclass
.str(), s
)) {
1272 if (0 == strncasecmp(s
.c_str(), "ClickToFocus", s
.length())) {
1273 resource
.auto_raise
= false;
1274 resource
.sloppy_focus
= false;
1275 } else if (0 == strncasecmp(s
.c_str(), "AutoRaiseSloppyFocus",
1277 resource
.sloppy_focus
= true;
1278 resource
.auto_raise
= true;
1279 } else { //if (0 == strncasecmp(s.c_str(), "SloppyFocus", s.length())) {
1280 resource
.sloppy_focus
= true;
1281 resource
.auto_raise
= false;
1284 resource
.sloppy_focus
= true;
1285 resource
.auto_raise
= false;
1288 rname
.seekp(0); rclass
.seekp(0);
1289 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1290 rname
<< rscreen
.str() << "windowZones" << ends
;
1291 rclass
<< rscreen
.str() << "WindowZones" << ends
;
1292 if (config
.getValue(rname
.str(), rclass
.str(), l
))
1293 resource
.zones
= (l
== 1 || l
== 2 || l
== 4) ? l
: 1;
1297 rname
.seekp(0); rclass
.seekp(0);
1298 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1299 rname
<< rscreen
.str() << "windowPlacement" << ends
;
1300 rclass
<< rscreen
.str() << "WindowPlacement" << ends
;
1301 if (config
.getValue(rname
.str(), rclass
.str(), s
)) {
1302 if (0 == strncasecmp(s
.c_str(), "RowSmartPlacement", s
.length()))
1303 resource
.placement_policy
= RowSmartPlacement
;
1304 else if (0 == strncasecmp(s
.c_str(), "ColSmartPlacement", s
.length()))
1305 resource
.placement_policy
= ColSmartPlacement
;
1306 else if (0 == strncasecmp(s
.c_str(), "BestFitPlacement", s
.length()))
1307 resource
.placement_policy
= BestFitPlacement
;
1308 else if (0 == strncasecmp(s
.c_str(), "UnderMousePlacement", s
.length()))
1309 resource
.placement_policy
= UnderMousePlacement
;
1310 else if (0 == strncasecmp(s
.c_str(), "ClickMousePlacement", s
.length()))
1311 resource
.placement_policy
= ClickMousePlacement
;
1312 else //if (0 == strncasecmp(s.c_str(), "CascadePlacement", s.length()))
1313 resource
.placement_policy
= CascadePlacement
;
1315 resource
.placement_policy
= CascadePlacement
;
1317 #ifdef HAVE_STRFTIME
1318 rname
.seekp(0); rclass
.seekp(0);
1319 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1320 rname
<< rscreen
.str() << "strftimeFormat" << ends
;
1321 rclass
<< rscreen
.str() << "StrftimeFormat" << ends
;
1323 if (resource
.strftime_format
!= NULL
)
1324 delete [] resource
.strftime_format
;
1326 if (config
.getValue(rname
.str(), rclass
.str(), s
))
1327 resource
.strftime_format
= bstrdup(s
.c_str());
1329 resource
.strftime_format
= bstrdup("%I:%M %p");
1330 #else // !HAVE_STRFTIME
1331 rname
.seekp(0); rclass
.seekp(0);
1332 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1333 rname
<< rscreen
.str() << "dateFormat" << ends
;
1334 rclass
<< rscreen
.str() << "DateFormat" << ends
;
1335 if (config
.getValue(rname
.str(), rclass
.str(), s
)) {
1336 if (strncasecmp(s
.c_str(), "European", s
.length()))
1337 resource
.date_format
= B_EuropeanDate
;
1338 else //if (strncasecmp(s.c_str(), "American", s.length()))
1339 resource
.date_format
= B_AmericanDate
;
1341 resource
.date_format
= B_AmericanDate
;
1343 rname
.seekp(0); rclass
.seekp(0);
1344 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1345 rname
<< rscreen
.str() << "clockFormat" << ends
;
1346 rclass
<< rscreen
.str() << "ClockFormat" << ends
;
1347 if (config
.getValue(rname
.str(), rclass
.str(), l
)) {
1349 resource
.clock24hour
= true;
1350 else if (clock
== 12)
1351 resource
.clock24hour
= false;
1353 resource
.clock24hour
= false;
1354 #endif // HAVE_STRFTIME
1356 rname
.seekp(0); rclass
.seekp(0);
1357 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1358 rname
<< rscreen
.str() << "edgeSnapThreshold" << ends
;
1359 rclass
<< rscreen
.str() << "EdgeSnapThreshold" << ends
;
1360 if (config
.getValue(rname
.str(), rclass
.str(), l
))
1361 resource
.edge_snap_threshold
= l
;
1363 resource
.edge_snap_threshold
= 4;
1365 rname
.seekp(0); rclass
.seekp(0);
1366 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1367 rname
<< rscreen
.str() << "imageDither" << ends
;
1368 rclass
<< rscreen
.str() << "ImageDither" << ends
;
1369 if (config
.getValue(rname
.str(), rclass
.str(), b
))
1370 image_control
->setDither(b
);
1372 image_control
->setDither(true);
1374 rname
.seekp(0); rclass
.seekp(0);
1375 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1376 rname
<< rscreen
.str() << "rootCommand" << ends
;
1377 rclass
<< rscreen
.str() << "RootCommand" << ends
;
1379 if (resource
.root_command
!= NULL
)
1380 delete [] resource
.root_command
;
1382 if (config
.getValue(rname
.str(), rclass
.str(), s
))
1383 resource
.root_command
= bstrdup(s
.c_str());
1385 resource
.root_command
= NULL
;
1387 rname
.seekp(0); rclass
.seekp(0);
1388 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1389 rname
<< rscreen
.str() << "opaqueMove" << ends
;
1390 rclass
<< rscreen
.str() << "OpaqueMove" << ends
;
1391 if (config
.getValue(rname
.str(), rclass
.str(), b
))
1392 resource
.opaque_move
= b
;
1394 resource
.opaque_move
= false;
1396 rscreen
.rdbuf()->freeze(0);
1397 rname
.rdbuf()->freeze(0); rclass
.rdbuf()->freeze(0);
1400 void BScreen::reconfigure(void) {
1409 unsigned long gc_value_mask
= GCForeground
;
1410 if (! i18n
->multibyte()) gc_value_mask
|= GCFont
;
1412 gcv
.foreground
= WhitePixel(getBaseDisplay().getXDisplay(),
1414 gcv
.function
= GXinvert
;
1415 gcv
.subwindow_mode
= IncludeInferiors
;
1416 XChangeGC(getBaseDisplay().getXDisplay(), opGC
,
1417 GCForeground
| GCFunction
| GCSubwindowMode
, &gcv
);
1419 gcv
.foreground
= resource
.wstyle
.l_text_focus
.getPixel();
1420 if (resource
.wstyle
.font
)
1421 gcv
.font
= resource
.wstyle
.font
->fid
;
1422 XChangeGC(getBaseDisplay().getXDisplay(), resource
.wstyle
.l_text_focus_gc
,
1423 gc_value_mask
, &gcv
);
1425 gcv
.foreground
= resource
.wstyle
.l_text_unfocus
.getPixel();
1426 XChangeGC(getBaseDisplay().getXDisplay(), resource
.wstyle
.l_text_unfocus_gc
,
1427 gc_value_mask
, &gcv
);
1429 gcv
.foreground
= resource
.wstyle
.b_pic_focus
.getPixel();
1430 XChangeGC(getBaseDisplay().getXDisplay(), resource
.wstyle
.b_pic_focus_gc
,
1431 GCForeground
, &gcv
);
1433 gcv
.foreground
= resource
.wstyle
.b_pic_unfocus
.getPixel();
1434 XChangeGC(getBaseDisplay().getXDisplay(), resource
.wstyle
.b_pic_unfocus_gc
,
1435 GCForeground
, &gcv
);
1437 gcv
.foreground
= resource
.mstyle
.t_text
.getPixel();
1438 if (resource
.mstyle
.t_font
)
1439 gcv
.font
= resource
.mstyle
.t_font
->fid
;
1440 XChangeGC(getBaseDisplay().getXDisplay(), resource
.mstyle
.t_text_gc
,
1441 gc_value_mask
, &gcv
);
1443 gcv
.foreground
= resource
.mstyle
.f_text
.getPixel();
1444 if (resource
.mstyle
.f_font
)
1445 gcv
.font
= resource
.mstyle
.f_font
->fid
;
1446 XChangeGC(getBaseDisplay().getXDisplay(), resource
.mstyle
.f_text_gc
,
1447 gc_value_mask
, &gcv
);
1449 gcv
.foreground
= resource
.mstyle
.h_text
.getPixel();
1450 XChangeGC(getBaseDisplay().getXDisplay(), resource
.mstyle
.h_text_gc
,
1451 gc_value_mask
, &gcv
);
1453 gcv
.foreground
= resource
.mstyle
.d_text
.getPixel();
1454 XChangeGC(getBaseDisplay().getXDisplay(), resource
.mstyle
.d_text_gc
,
1455 gc_value_mask
, &gcv
);
1457 gcv
.foreground
= resource
.mstyle
.hilite
.getColor()->getPixel();
1458 XChangeGC(getBaseDisplay().getXDisplay(), resource
.mstyle
.hilite_gc
,
1459 gc_value_mask
, &gcv
);
1461 gcv
.foreground
= resource
.tstyle
.l_text
.getPixel();
1462 if (resource
.tstyle
.font
)
1463 gcv
.font
= resource
.tstyle
.font
->fid
;
1464 XChangeGC(getBaseDisplay().getXDisplay(), resource
.tstyle
.l_text_gc
,
1465 gc_value_mask
, &gcv
);
1467 gcv
.foreground
= resource
.tstyle
.w_text
.getPixel();
1468 XChangeGC(getBaseDisplay().getXDisplay(), resource
.tstyle
.w_text_gc
,
1469 gc_value_mask
, &gcv
);
1471 gcv
.foreground
= resource
.tstyle
.c_text
.getPixel();
1472 XChangeGC(getBaseDisplay().getXDisplay(), resource
.tstyle
.c_text_gc
,
1473 gc_value_mask
, &gcv
);
1475 gcv
.foreground
= resource
.tstyle
.b_pic
.getPixel();
1476 XChangeGC(getBaseDisplay().getXDisplay(), resource
.tstyle
.b_pic_gc
,
1477 gc_value_mask
, &gcv
);
1479 const char *s
= i18n
->getMessage(ScreenSet
, ScreenPositionLength
,
1480 "0: 0000 x 0: 0000");
1483 if (i18n
->multibyte()) {
1484 XRectangle ink
, logical
;
1485 XmbTextExtents(resource
.wstyle
.fontset
, s
, l
, &ink
, &logical
);
1486 geom_w
= logical
.width
;
1488 geom_h
= resource
.wstyle
.fontset_extents
->max_ink_extent
.height
;
1490 geom_w
= XTextWidth(resource
.wstyle
.font
, s
, l
);
1492 geom_h
= resource
.wstyle
.font
->ascent
+
1493 resource
.wstyle
.font
->descent
;
1496 geom_w
+= (resource
.bevel_width
* 2);
1497 geom_h
+= (resource
.bevel_width
* 2);
1499 Pixmap tmp
= geom_pixmap
;
1500 if (resource
.wstyle
.l_focus
.getTexture() & BImage_ParentRelative
) {
1501 if (resource
.wstyle
.t_focus
.getTexture() ==
1502 (BImage_Flat
| BImage_Solid
)) {
1504 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window
,
1505 resource
.wstyle
.t_focus
.getColor()->getPixel());
1507 geom_pixmap
= image_control
->renderImage(geom_w
, geom_h
,
1508 &resource
.wstyle
.t_focus
);
1509 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
1510 geom_window
, geom_pixmap
);
1513 if (resource
.wstyle
.l_focus
.getTexture() ==
1514 (BImage_Flat
| BImage_Solid
)) {
1516 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window
,
1517 resource
.wstyle
.l_focus
.getColor()->getPixel());
1519 geom_pixmap
= image_control
->renderImage(geom_w
, geom_h
,
1520 &resource
.wstyle
.l_focus
);
1521 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
1522 geom_window
, geom_pixmap
);
1525 if (tmp
) image_control
->removeImage(tmp
);
1527 XSetWindowBorderWidth(getBaseDisplay().getXDisplay(), geom_window
,
1528 resource
.border_width
);
1529 XSetWindowBorder(getBaseDisplay().getXDisplay(), geom_window
,
1530 resource
.border_color
.getPixel());
1532 workspacemenu
->reconfigure();
1533 iconmenu
->reconfigure();
1536 int remember_sub
= rootmenu
->getCurrentSubmenu();
1539 rootmenu
->reconfigure();
1540 rootmenu
->drawSubmenu(remember_sub
);
1543 configmenu
->reconfigure();
1545 toolbar
->reconfigure();
1548 slit
->reconfigure();
1551 LinkedListIterator
<Workspace
> wit(workspacesList
);
1552 for (Workspace
*w
= wit
.current(); w
; wit
++, w
= wit
.current())
1555 LinkedListIterator
<OpenboxWindow
> iit(iconList
);
1556 for (OpenboxWindow
*bw
= iit
.current(); bw
; iit
++, bw
= iit
.current())
1557 if (bw
->validateClient())
1560 image_control
->timeout();
1564 void BScreen::rereadMenu(void) {
1568 rootmenu
->reconfigure();
1572 void BScreen::removeWorkspaceNames(void) {
1573 while (workspaceNames
->count())
1574 delete [] workspaceNames
->remove(0);
1578 void BScreen::LoadStyle(void) {
1579 Resource
&conf
= resource
.styleconfig
;
1581 const char *sfile
= openbox
.getStyleFilename();
1582 bool loaded
= false;
1583 if (sfile
!= NULL
) {
1584 conf
.setFile(sfile
);
1585 loaded
= conf
.load();
1588 conf
.setFile(DEFAULTSTYLE
);
1590 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenDefaultStyleLoadFail
,
1591 "BScreen::LoadStyle(): couldn't load "
1592 "default style.\n"));
1600 // load fonts/fontsets
1602 if (i18n
->multibyte()) {
1603 readDatabaseFontSet("window.font", "Window.Font",
1604 &resource
.wstyle
.fontset
);
1605 readDatabaseFontSet("toolbar.font", "Toolbar.Font",
1606 &resource
.tstyle
.fontset
);
1607 readDatabaseFontSet("menu.title.font", "Menu.Title.Font",
1608 &resource
.mstyle
.t_fontset
);
1609 readDatabaseFontSet("menu.frame.font", "Menu.Frame.Font",
1610 &resource
.mstyle
.f_fontset
);
1612 resource
.mstyle
.t_fontset_extents
=
1613 XExtentsOfFontSet(resource
.mstyle
.t_fontset
);
1614 resource
.mstyle
.f_fontset_extents
=
1615 XExtentsOfFontSet(resource
.mstyle
.f_fontset
);
1616 resource
.tstyle
.fontset_extents
=
1617 XExtentsOfFontSet(resource
.tstyle
.fontset
);
1618 resource
.wstyle
.fontset_extents
=
1619 XExtentsOfFontSet(resource
.wstyle
.fontset
);
1621 readDatabaseFont("window.font", "Window.Font",
1622 &resource
.wstyle
.font
);
1623 readDatabaseFont("menu.title.font", "Menu.Title.Font",
1624 &resource
.mstyle
.t_font
);
1625 readDatabaseFont("menu.frame.font", "Menu.Frame.Font",
1626 &resource
.mstyle
.f_font
);
1627 readDatabaseFont("toolbar.font", "Toolbar.Font",
1628 &resource
.tstyle
.font
);
1631 // load window config
1632 readDatabaseTexture("window.title.focus", "Window.Title.Focus",
1633 &resource
.wstyle
.t_focus
,
1634 WhitePixel(getBaseDisplay().getXDisplay(),
1635 getScreenNumber()));
1636 readDatabaseTexture("window.title.unfocus", "Window.Title.Unfocus",
1637 &resource
.wstyle
.t_unfocus
,
1638 BlackPixel(getBaseDisplay().getXDisplay(),
1639 getScreenNumber()));
1640 readDatabaseTexture("window.label.focus", "Window.Label.Focus",
1641 &resource
.wstyle
.l_focus
,
1642 WhitePixel(getBaseDisplay().getXDisplay(),
1643 getScreenNumber()));
1644 readDatabaseTexture("window.label.unfocus", "Window.Label.Unfocus",
1645 &resource
.wstyle
.l_unfocus
,
1646 BlackPixel(getBaseDisplay().getXDisplay(),
1647 getScreenNumber()));
1648 readDatabaseTexture("window.handle.focus", "Window.Handle.Focus",
1649 &resource
.wstyle
.h_focus
,
1650 WhitePixel(getBaseDisplay().getXDisplay(),
1651 getScreenNumber()));
1652 readDatabaseTexture("window.handle.unfocus", "Window.Handle.Unfocus",
1653 &resource
.wstyle
.h_unfocus
,
1654 BlackPixel(getBaseDisplay().getXDisplay(),
1655 getScreenNumber()));
1656 readDatabaseTexture("window.grip.focus", "Window.Grip.Focus",
1657 &resource
.wstyle
.g_focus
,
1658 WhitePixel(getBaseDisplay().getXDisplay(),
1659 getScreenNumber()));
1660 readDatabaseTexture("window.grip.unfocus", "Window.Grip.Unfocus",
1661 &resource
.wstyle
.g_unfocus
,
1662 BlackPixel(getBaseDisplay().getXDisplay(),
1663 getScreenNumber()));
1664 readDatabaseTexture("window.button.focus", "Window.Button.Focus",
1665 &resource
.wstyle
.b_focus
,
1666 WhitePixel(getBaseDisplay().getXDisplay(),
1667 getScreenNumber()));
1668 readDatabaseTexture("window.button.unfocus", "Window.Button.Unfocus",
1669 &resource
.wstyle
.b_unfocus
,
1670 BlackPixel(getBaseDisplay().getXDisplay(),
1671 getScreenNumber()));
1672 readDatabaseTexture("window.button.pressed", "Window.Button.Pressed",
1673 &resource
.wstyle
.b_pressed
,
1674 BlackPixel(getBaseDisplay().getXDisplay(),
1675 getScreenNumber()));
1676 readDatabaseColor("window.frame.focusColor",
1677 "Window.Frame.FocusColor",
1678 &resource
.wstyle
.f_focus
,
1679 WhitePixel(getBaseDisplay().getXDisplay(),
1680 getScreenNumber()));
1681 readDatabaseColor("window.frame.unfocusColor",
1682 "Window.Frame.UnfocusColor",
1683 &resource
.wstyle
.f_unfocus
,
1684 BlackPixel(getBaseDisplay().getXDisplay(),
1685 getScreenNumber()));
1686 readDatabaseColor("window.label.focus.textColor",
1687 "Window.Label.Focus.TextColor",
1688 &resource
.wstyle
.l_text_focus
,
1689 BlackPixel(getBaseDisplay().getXDisplay(),
1690 getScreenNumber()));
1691 readDatabaseColor("window.label.unfocus.textColor",
1692 "Window.Label.Unfocus.TextColor",
1693 &resource
.wstyle
.l_text_unfocus
,
1694 WhitePixel(getBaseDisplay().getXDisplay(),
1695 getScreenNumber()));
1696 readDatabaseColor("window.button.focus.picColor",
1697 "Window.Button.Focus.PicColor",
1698 &resource
.wstyle
.b_pic_focus
,
1699 BlackPixel(getBaseDisplay().getXDisplay(),
1700 getScreenNumber()));
1701 readDatabaseColor("window.button.unfocus.picColor",
1702 "Window.Button.Unfocus.PicColor",
1703 &resource
.wstyle
.b_pic_unfocus
,
1704 WhitePixel(getBaseDisplay().getXDisplay(),
1705 getScreenNumber()));
1707 if (conf
.getValue("window.justify", "Window.Justify", s
)) {
1708 if (0 == strncasecmp(s
.c_str(), "right", s
.length()))
1709 resource
.wstyle
.justify
= BScreen::RightJustify
;
1710 else if (0 == strncasecmp(s
.c_str(), "center", s
.length()))
1711 resource
.wstyle
.justify
= BScreen::CenterJustify
;
1713 resource
.wstyle
.justify
= BScreen::LeftJustify
;
1715 resource
.wstyle
.justify
= BScreen::LeftJustify
;
1717 // load toolbar config
1718 readDatabaseTexture("toolbar", "Toolbar",
1719 &resource
.tstyle
.toolbar
,
1720 BlackPixel(getBaseDisplay().getXDisplay(),
1721 getScreenNumber()));
1722 readDatabaseTexture("toolbar.label", "Toolbar.Label",
1723 &resource
.tstyle
.label
,
1724 BlackPixel(getBaseDisplay().getXDisplay(),
1725 getScreenNumber()));
1726 readDatabaseTexture("toolbar.windowLabel", "Toolbar.WindowLabel",
1727 &resource
.tstyle
.window
,
1728 BlackPixel(getBaseDisplay().getXDisplay(),
1729 getScreenNumber()));
1730 readDatabaseTexture("toolbar.button", "Toolbar.Button",
1731 &resource
.tstyle
.button
,
1732 WhitePixel(getBaseDisplay().getXDisplay(),
1733 getScreenNumber()));
1734 readDatabaseTexture("toolbar.button.pressed", "Toolbar.Button.Pressed",
1735 &resource
.tstyle
.pressed
,
1736 BlackPixel(getBaseDisplay().getXDisplay(),
1737 getScreenNumber()));
1738 readDatabaseTexture("toolbar.clock", "Toolbar.Clock",
1739 &resource
.tstyle
.clock
,
1740 BlackPixel(getBaseDisplay().getXDisplay(),
1741 getScreenNumber()));
1742 readDatabaseColor("toolbar.label.textColor", "Toolbar.Label.TextColor",
1743 &resource
.tstyle
.l_text
,
1744 WhitePixel(getBaseDisplay().getXDisplay(),
1745 getScreenNumber()));
1746 readDatabaseColor("toolbar.windowLabel.textColor",
1747 "Toolbar.WindowLabel.TextColor",
1748 &resource
.tstyle
.w_text
,
1749 WhitePixel(getBaseDisplay().getXDisplay(),
1750 getScreenNumber()));
1751 readDatabaseColor("toolbar.clock.textColor", "Toolbar.Clock.TextColor",
1752 &resource
.tstyle
.c_text
,
1753 WhitePixel(getBaseDisplay().getXDisplay(),
1754 getScreenNumber()));
1755 readDatabaseColor("toolbar.button.picColor", "Toolbar.Button.PicColor",
1756 &resource
.tstyle
.b_pic
,
1757 BlackPixel(getBaseDisplay().getXDisplay(),
1758 getScreenNumber()));
1760 if (conf
.getValue("toolbar.justify", "Toolbar.Justify", s
)) {
1761 if (0 == strncasecmp(s
.c_str(), "right", s
.length()))
1762 resource
.tstyle
.justify
= BScreen::RightJustify
;
1763 else if (0 == strncasecmp(s
.c_str(), "center", s
.length()))
1764 resource
.tstyle
.justify
= BScreen::CenterJustify
;
1766 resource
.tstyle
.justify
= BScreen::LeftJustify
;
1768 resource
.tstyle
.justify
= BScreen::LeftJustify
;
1771 readDatabaseTexture("menu.title", "Menu.Title",
1772 &resource
.mstyle
.title
,
1773 WhitePixel(getBaseDisplay().getXDisplay(),
1774 getScreenNumber()));
1775 readDatabaseTexture("menu.frame", "Menu.Frame",
1776 &resource
.mstyle
.frame
,
1777 BlackPixel(getBaseDisplay().getXDisplay(),
1778 getScreenNumber()));
1779 readDatabaseTexture("menu.hilite", "Menu.Hilite",
1780 &resource
.mstyle
.hilite
,
1781 WhitePixel(getBaseDisplay().getXDisplay(),
1782 getScreenNumber()));
1783 readDatabaseColor("menu.title.textColor", "Menu.Title.TextColor",
1784 &resource
.mstyle
.t_text
,
1785 BlackPixel(getBaseDisplay().getXDisplay(),
1786 getScreenNumber()));
1787 readDatabaseColor("menu.frame.textColor", "Menu.Frame.TextColor",
1788 &resource
.mstyle
.f_text
,
1789 WhitePixel(getBaseDisplay().getXDisplay(),
1790 getScreenNumber()));
1791 readDatabaseColor("menu.frame.disableColor", "Menu.Frame.DisableColor",
1792 &resource
.mstyle
.d_text
,
1793 BlackPixel(getBaseDisplay().getXDisplay(),
1794 getScreenNumber()));
1795 readDatabaseColor("menu.hilite.textColor", "Menu.Hilite.TextColor",
1796 &resource
.mstyle
.h_text
,
1797 BlackPixel(getBaseDisplay().getXDisplay(),
1798 getScreenNumber()));
1800 if (conf
.getValue("menu.title.justify", "Menu.Title.Justify", s
)) {
1801 if (0 == strncasecmp(s
.c_str(), "right", s
.length()))
1802 resource
.mstyle
.t_justify
= BScreen::RightJustify
;
1803 else if (0 == strncasecmp(s
.c_str(), "center", s
.length()))
1804 resource
.mstyle
.t_justify
= BScreen::CenterJustify
;
1806 resource
.mstyle
.t_justify
= BScreen::LeftJustify
;
1808 resource
.mstyle
.t_justify
= BScreen::LeftJustify
;
1810 if (conf
.getValue("menu.frame.justify", "Menu.Frame.Justify", s
)) {
1811 if (0 == strncasecmp(s
.c_str(), "right", s
.length()))
1812 resource
.mstyle
.f_justify
= BScreen::RightJustify
;
1813 else if (0 == strncasecmp(s
.c_str(), "center", s
.length()))
1814 resource
.mstyle
.f_justify
= BScreen::CenterJustify
;
1816 resource
.mstyle
.f_justify
= BScreen::LeftJustify
;
1818 resource
.mstyle
.f_justify
= BScreen::LeftJustify
;
1820 if (conf
.getValue("menu.bullet", "Menu.Bullet", s
)) {
1821 if (0 == strncasecmp(s
.c_str(), "empty", s
.length()))
1822 resource
.mstyle
.bullet
= Basemenu::Empty
;
1823 else if (0 == strncasecmp(s
.c_str(), "square", s
.length()))
1824 resource
.mstyle
.bullet
= Basemenu::Square
;
1825 else if (0 == strncasecmp(s
.c_str(), "diamond", s
.length()))
1826 resource
.mstyle
.bullet
= Basemenu::Diamond
;
1828 resource
.mstyle
.bullet
= Basemenu::Triangle
;
1830 resource
.mstyle
.bullet
= Basemenu::Triangle
;
1832 if (conf
.getValue("menu.bullet.position", "Menu.Bullet.Position", s
)) {
1833 if (0 == strncasecmp(s
.c_str(), "right", s
.length()))
1834 resource
.mstyle
.bullet_pos
= Basemenu::Right
;
1836 resource
.mstyle
.bullet_pos
= Basemenu::Left
;
1838 resource
.mstyle
.bullet_pos
= Basemenu::Left
;
1840 readDatabaseColor("borderColor", "BorderColor", &resource
.border_color
,
1841 BlackPixel(getBaseDisplay().getXDisplay(),
1842 getScreenNumber()));
1844 // load bevel, border and handle widths
1845 if (conf
.getValue("handleWidth", "HandleWidth", l
)) {
1846 if (l
<= size().w() / 2 && l
!= 0)
1847 resource
.handle_width
= l
;
1849 resource
.handle_width
= 6;
1851 resource
.handle_width
= 6;
1853 if (conf
.getValue("borderWidth", "BorderWidth", l
))
1854 resource
.border_width
= l
;
1856 resource
.border_width
= 1;
1858 if (conf
.getValue("bevelWidth", "BevelWidth", l
)) {
1859 if (l
<= size().w() / 2 && l
!= 0)
1860 resource
.bevel_width
= l
;
1862 resource
.bevel_width
= 3;
1864 resource
.bevel_width
= 3;
1866 if (conf
.getValue("frameWidth", "FrameWidth", l
)) {
1867 if (l
<= size().w() / 2)
1868 resource
.frame_width
= l
;
1870 resource
.frame_width
= resource
.bevel_width
;
1872 resource
.frame_width
= resource
.bevel_width
;
1874 const char *cmd
= resource
.root_command
;
1875 if (cmd
!= NULL
|| conf
.getValue("rootCommand", "RootCommand", s
)) {
1877 cmd
= s
.c_str(); // not specified by the screen, so use the one from the
1880 char displaystring
[MAXPATHLEN
];
1881 sprintf(displaystring
, "DISPLAY=%s",
1882 DisplayString(getBaseDisplay().getXDisplay()));
1883 sprintf(displaystring
+ strlen(displaystring
) - 1, "%d",
1886 bexec(cmd
, displaystring
);
1888 spawnlp(P_NOWAIT
, "cmd.exe", "cmd.exe", "/c", cmd
, NULL
);
1894 void BScreen::addIcon(OpenboxWindow
*w
) {
1897 w
->setWorkspace(-1);
1898 w
->setWindowNumber(iconList
->count());
1900 iconList
->insert(w
);
1902 iconmenu
->insert((const char **) w
->getIconTitle());
1907 void BScreen::removeIcon(OpenboxWindow
*w
) {
1910 iconList
->remove(w
->getWindowNumber());
1912 iconmenu
->remove(w
->getWindowNumber());
1915 LinkedListIterator
<OpenboxWindow
> it(iconList
);
1916 OpenboxWindow
*bw
= it
.current();
1917 for (int i
= 0; bw
; it
++, bw
= it
.current())
1918 bw
->setWindowNumber(i
++);
1922 OpenboxWindow
*BScreen::getIcon(int index
) {
1923 if (index
>= 0 && index
< iconList
->count())
1924 return iconList
->find(index
);
1930 int BScreen::addWorkspace(void) {
1931 Workspace
*wkspc
= new Workspace(*this, workspacesList
->count());
1932 workspacesList
->insert(wkspc
);
1933 setWorkspaceCount(workspaceCount()+1);
1934 saveWorkspaceNames();
1936 workspacemenu
->insert(wkspc
->getName(), wkspc
->getMenu(),
1937 wkspc
->getWorkspaceID() + 2);
1938 workspacemenu
->update();
1940 toolbar
->reconfigure();
1942 updateNetizenWorkspaceCount();
1944 return workspacesList
->count();
1948 int BScreen::removeLastWorkspace(void) {
1949 if (workspacesList
->count() == 1)
1952 Workspace
*wkspc
= workspacesList
->last();
1954 if (current_workspace
->getWorkspaceID() == wkspc
->getWorkspaceID())
1955 changeWorkspaceID(current_workspace
->getWorkspaceID() - 1);
1959 workspacemenu
->remove(wkspc
->getWorkspaceID() + 2);
1960 workspacemenu
->update();
1962 workspacesList
->remove(wkspc
);
1964 setWorkspaceCount(workspaceCount()-1);
1965 saveWorkspaceNames();
1967 toolbar
->reconfigure();
1969 updateNetizenWorkspaceCount();
1971 return workspacesList
->count();
1975 void BScreen::changeWorkspaceID(int id
) {
1976 if (! current_workspace
) return;
1978 if (id
!= current_workspace
->getWorkspaceID()) {
1979 current_workspace
->hideAll();
1981 workspacemenu
->setItemSelected(current_workspace
->getWorkspaceID() + 2,
1984 if (openbox
.focusedWindow() &&
1985 openbox
.focusedWindow()->getScreen() == this &&
1986 (! openbox
.focusedWindow()->isStuck())) {
1987 current_workspace
->setLastFocusedWindow(openbox
.focusedWindow());
1988 openbox
.focusWindow((OpenboxWindow
*) 0);
1991 current_workspace
= getWorkspace(id
);
1993 workspacemenu
->setItemSelected(current_workspace
->getWorkspaceID() + 2,
1995 toolbar
->redrawWorkspaceLabel(True
);
1997 current_workspace
->showAll();
1999 if (resource
.focus_last
&& current_workspace
->getLastFocusedWindow()) {
2000 XSync(openbox
.getXDisplay(), False
);
2001 current_workspace
->getLastFocusedWindow()->setInputFocus();
2005 updateNetizenCurrentWorkspace();
2009 void BScreen::addNetizen(Netizen
*n
) {
2010 netizenList
.push_back(n
);
2012 n
->sendWorkspaceCount();
2013 n
->sendCurrentWorkspace();
2015 LinkedListIterator
<Workspace
> it(workspacesList
);
2016 for (Workspace
*w
= it
.current(); w
; it
++, w
= it
.current()) {
2017 for (int i
= 0; i
< w
->getCount(); i
++)
2018 n
->sendWindowAdd(w
->getWindow(i
)->getClientWindow(),
2019 w
->getWorkspaceID());
2022 Window f
= ((openbox
.focusedWindow()) ?
2023 openbox
.focusedWindow()->getClientWindow() : None
);
2024 n
->sendWindowFocus(f
);
2028 void BScreen::removeNetizen(Window w
) {
2029 netList::iterator it
;
2032 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2033 if ((*it
)->getWindowID() == w
) {
2035 netizenList
.erase(it
);
2042 void BScreen::updateNetizenCurrentWorkspace(void) {
2043 netList::iterator it
;
2044 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2045 (*it
)->sendCurrentWorkspace();
2049 void BScreen::updateNetizenWorkspaceCount(void) {
2050 netList::iterator it
;
2051 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2052 (*it
)->sendWorkspaceCount();
2056 void BScreen::updateNetizenWindowFocus(void) {
2057 Window f
= ((openbox
.focusedWindow()) ?
2058 openbox
.focusedWindow()->getClientWindow() : None
);
2059 netList::iterator it
;
2060 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2061 (*it
)->sendWindowFocus(f
);
2064 void BScreen::updateNetizenWindowAdd(Window w
, unsigned long p
) {
2065 netList::iterator it
;
2066 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2067 (*it
)->sendWindowAdd(w
, p
);
2071 void BScreen::updateNetizenWindowDel(Window w
) {
2072 netList::iterator it
;
2073 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2074 (*it
)->sendWindowDel(w
);
2078 void BScreen::updateNetizenWindowRaise(Window w
) {
2079 netList::iterator it
;
2080 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2081 (*it
)->sendWindowRaise(w
);
2085 void BScreen::updateNetizenWindowLower(Window w
) {
2086 netList::iterator it
;
2087 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2088 (*it
)->sendWindowLower(w
);
2092 void BScreen::updateNetizenConfigNotify(XEvent
*e
) {
2093 netList::iterator it
;
2094 for (it
= netizenList
.begin(); it
!= netizenList
.end(); ++it
)
2095 (*it
)->sendConfigNotify(e
);
2099 void BScreen::raiseWindows(Window
*workspace_stack
, int num
) {
2100 Window
*session_stack
= new
2101 Window
[(num
+ workspacesList
->count() + rootmenuList
.size() + 13)];
2104 XRaiseWindow(getBaseDisplay().getXDisplay(), iconmenu
->getWindowID());
2105 *(session_stack
+ i
++) = iconmenu
->getWindowID();
2107 LinkedListIterator
<Workspace
> wit(workspacesList
);
2108 for (Workspace
*tmp
= wit
.current(); tmp
; wit
++, tmp
= wit
.current())
2109 *(session_stack
+ i
++) = tmp
->getMenu()->getWindowID();
2111 *(session_stack
+ i
++) = workspacemenu
->getWindowID();
2113 *(session_stack
+ i
++) = configmenu
->getFocusmenu()->getWindowID();
2114 *(session_stack
+ i
++) = configmenu
->getPlacementmenu()->getWindowID();
2115 *(session_stack
+ i
++) = configmenu
->getWindowID();
2118 *(session_stack
+ i
++) = slit
->getMenu()->getDirectionmenu()->getWindowID();
2119 *(session_stack
+ i
++) = slit
->getMenu()->getPlacementmenu()->getWindowID();
2120 *(session_stack
+ i
++) = slit
->getMenu()->getWindowID();
2123 *(session_stack
+ i
++) =
2124 toolbar
->getMenu()->getPlacementmenu()->getWindowID();
2125 *(session_stack
+ i
++) = toolbar
->getMenu()->getWindowID();
2127 menuList::iterator rit
;
2128 for (rit
= rootmenuList
.begin(); rit
!= rootmenuList
.end(); ++rit
)
2129 *(session_stack
+ i
++) = (*rit
)->getWindowID();
2130 *(session_stack
+ i
++) = rootmenu
->getWindowID();
2132 if (toolbar
->onTop())
2133 *(session_stack
+ i
++) = toolbar
->getWindowID();
2137 *(session_stack
+ i
++) = slit
->getWindowID();
2141 *(session_stack
+ i
++) = *(workspace_stack
+ k
);
2143 XRestackWindows(getBaseDisplay().getXDisplay(), session_stack
, i
);
2145 delete [] session_stack
;
2149 void BScreen::addWorkspaceName(const char *name
) {
2150 workspaceNames
->insert(bstrdup(name
));
2153 char* BScreen::getNameOfWorkspace(int id
) {
2156 if (id
>= 0 && id
< workspaceNames
->count()) {
2157 char *wkspc_name
= workspaceNames
->find(id
);
2166 void BScreen::reassociateWindow(OpenboxWindow
*w
, int wkspc_id
, Bool ignore_sticky
) {
2170 wkspc_id
= current_workspace
->getWorkspaceID();
2172 if (w
->getWorkspaceNumber() == wkspc_id
)
2175 if (w
->isIconic()) {
2177 getWorkspace(wkspc_id
)->addWindow(w
);
2178 } else if (ignore_sticky
|| ! w
->isStuck()) {
2179 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
2180 getWorkspace(wkspc_id
)->addWindow(w
);
2185 void BScreen::nextFocus(void) {
2186 Bool have_focused
= False
;
2187 int focused_window_number
= -1;
2188 OpenboxWindow
*next
;
2190 if (openbox
.focusedWindow()) {
2191 if (openbox
.focusedWindow()->getScreen()->getScreenNumber() ==
2192 getScreenNumber()) {
2193 have_focused
= True
;
2194 focused_window_number
= openbox
.focusedWindow()->getWindowNumber();
2198 if ((getCurrentWorkspace()->getCount() > 1) && have_focused
) {
2199 int next_window_number
= focused_window_number
;
2201 if ((++next_window_number
) >= getCurrentWorkspace()->getCount())
2202 next_window_number
= 0;
2204 next
= getCurrentWorkspace()->getWindow(next_window_number
);
2205 } while ((! next
->setInputFocus()) && (next_window_number
!=
2206 focused_window_number
));
2208 if (next_window_number
!= focused_window_number
)
2209 getCurrentWorkspace()->raiseWindow(next
);
2210 } else if (getCurrentWorkspace()->getCount() >= 1) {
2211 next
= current_workspace
->getWindow(0);
2213 current_workspace
->raiseWindow(next
);
2214 next
->setInputFocus();
2219 void BScreen::prevFocus(void) {
2220 Bool have_focused
= False
;
2221 int focused_window_number
= -1;
2222 OpenboxWindow
*prev
;
2224 if (openbox
.focusedWindow()) {
2225 if (openbox
.focusedWindow()->getScreen()->getScreenNumber() ==
2226 getScreenNumber()) {
2227 have_focused
= True
;
2228 focused_window_number
= openbox
.focusedWindow()->getWindowNumber();
2232 if ((getCurrentWorkspace()->getCount() > 1) && have_focused
) {
2233 int prev_window_number
= focused_window_number
;
2235 if ((--prev_window_number
) < 0)
2236 prev_window_number
= getCurrentWorkspace()->getCount() - 1;
2238 prev
= getCurrentWorkspace()->getWindow(prev_window_number
);
2239 } while ((! prev
->setInputFocus()) && (prev_window_number
!=
2240 focused_window_number
));
2242 if (prev_window_number
!= focused_window_number
)
2243 getCurrentWorkspace()->raiseWindow(prev
);
2244 } else if (getCurrentWorkspace()->getCount() >= 1) {
2245 prev
= current_workspace
->getWindow(0);
2247 current_workspace
->raiseWindow(prev
);
2248 prev
->setInputFocus();
2253 void BScreen::raiseFocus(void) {
2254 Bool have_focused
= False
;
2255 int focused_window_number
= -1;
2257 if (openbox
.focusedWindow()) {
2258 if (openbox
.focusedWindow()->getScreen()->getScreenNumber() ==
2259 getScreenNumber()) {
2260 have_focused
= True
;
2261 focused_window_number
= openbox
.focusedWindow()->getWindowNumber();
2265 if ((getCurrentWorkspace()->getCount() > 1) && have_focused
)
2266 getWorkspace(openbox
.focusedWindow()->getWorkspaceNumber())->
2267 raiseWindow(openbox
.focusedWindow());
2271 void BScreen::InitMenu(void) {
2273 while (!rootmenuList
.empty())
2274 rootmenuList
.erase(rootmenuList
.begin());
2276 while (rootmenu
->getCount())
2277 rootmenu
->remove(0);
2279 rootmenu
= new Rootmenu(*this);
2281 Bool defaultMenu
= True
;
2283 if (openbox
.getMenuFilename()) {
2284 FILE *menu_file
= fopen(openbox
.getMenuFilename(), "r");
2287 perror(openbox
.getMenuFilename());
2289 if (feof(menu_file
)) {
2290 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenEmptyMenuFile
,
2291 "%s: Empty menu file"),
2292 openbox
.getMenuFilename());
2294 char line
[1024], label
[1024];
2295 memset(line
, 0, 1024);
2296 memset(label
, 0, 1024);
2298 while (fgets(line
, 1024, menu_file
) && ! feof(menu_file
)) {
2299 if (line
[0] != '#') {
2300 int i
, key
= 0, index
= -1, len
= strlen(line
);
2303 for (i
= 0; i
< len
; i
++) {
2304 if (line
[i
] == '[') index
= 0;
2305 else if (line
[i
] == ']') break;
2306 else if (line
[i
] != ' ')
2308 key
+= tolower(line
[i
]);
2313 for (i
= index
; i
< len
; i
++) {
2314 if (line
[i
] == '(') index
= 0;
2315 else if (line
[i
] == ')') break;
2316 else if (index
++ >= 0) {
2317 if (line
[i
] == '\\' && i
< len
- 1) i
++;
2318 label
[index
- 1] = line
[i
];
2322 if (index
== -1) index
= 0;
2323 label
[index
] = '\0';
2325 rootmenu
->setLabel(label
);
2326 defaultMenu
= parseMenuFile(menu_file
, rootmenu
);
2337 rootmenu
->setInternalMenu();
2338 rootmenu
->insert(i18n
->getMessage(ScreenSet
, Screenxterm
, "xterm"),
2340 i18n
->getMessage(ScreenSet
, Screenxterm
, "xterm"));
2341 rootmenu
->insert(i18n
->getMessage(ScreenSet
, ScreenRestart
, "Restart"),
2343 rootmenu
->insert(i18n
->getMessage(ScreenSet
, ScreenExit
, "Exit"),
2346 openbox
.setMenuFilename(openbox
.getMenuFilename());
2351 Bool
BScreen::parseMenuFile(FILE *file
, Rootmenu
*menu
) {
2352 char line
[1024], label
[1024], command
[1024];
2354 while (! feof(file
)) {
2355 memset(line
, 0, 1024);
2356 memset(label
, 0, 1024);
2357 memset(command
, 0, 1024);
2359 if (fgets(line
, 1024, file
)) {
2360 if (line
[0] != '#') {
2361 register int i
, key
= 0, parse
= 0, index
= -1,
2362 line_length
= strlen(line
),
2363 label_length
= 0, command_length
= 0;
2365 // determine the keyword
2367 for (i
= 0; i
< line_length
; i
++) {
2368 if (line
[i
] == '[') parse
= 1;
2369 else if (line
[i
] == ']') break;
2370 else if (line
[i
] != ' ')
2372 key
+= tolower(line
[i
]);
2375 // get the label enclosed in ()'s
2378 for (i
= 0; i
< line_length
; i
++) {
2379 if (line
[i
] == '(') {
2382 } else if (line
[i
] == ')') break;
2383 else if (index
++ >= 0) {
2384 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
2385 label
[index
- 1] = line
[i
];
2390 label
[index
] = '\0';
2391 label_length
= index
;
2397 // get the command enclosed in {}'s
2400 for (i
= 0; i
< line_length
; i
++) {
2401 if (line
[i
] == '{') {
2404 } else if (line
[i
] == '}') break;
2405 else if (index
++ >= 0) {
2406 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
2407 command
[index
- 1] = line
[i
];
2412 command
[index
] = '\0';
2413 command_length
= index
;
2421 return ((menu
->getCount() == 0) ? True
: False
);
2426 menu
->insert(label
);
2431 if ((! *label
) && (! *command
)) {
2432 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenEXECError
,
2433 "BScreen::parseMenuFile: [exec] error, "
2434 "no menu label and/or command defined\n"));
2438 menu
->insert(label
, BScreen::Execute
, command
);
2444 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenEXITError
,
2445 "BScreen::parseMenuFile: [exit] error, "
2446 "no menu label defined\n"));
2450 menu
->insert(label
, BScreen::Exit
);
2456 if ((! *label
) || (! *command
)) {
2457 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenSTYLEError
,
2458 "BScreen::parseMenuFile: [style] error, "
2459 "no menu label and/or filename defined\n"));
2463 char style
[MAXPATHLEN
];
2465 // perform shell style ~ home directory expansion
2467 int homedir_len
= 0;
2468 if (*command
== '~' && *(command
+ 1) == '/') {
2469 homedir
= getenv("HOME");
2470 homedir_len
= strlen(homedir
);
2473 if (homedir
&& homedir_len
!= 0) {
2474 strncpy(style
, homedir
, homedir_len
);
2476 strncpy(style
+ homedir_len
, command
+ 1,
2477 command_length
- 1);
2478 *(style
+ command_length
+ homedir_len
- 1) = '\0';
2480 strncpy(style
, command
, command_length
);
2481 *(style
+ command_length
) = '\0';
2484 menu
->insert(label
, BScreen::SetStyle
, style
);
2491 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenCONFIGError
,
2492 "BScreen::parseMenufile: [config] error, "
2493 "no label defined"));
2497 menu
->insert(label
, configmenu
);
2501 case 740: // include
2504 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenINCLUDEError
,
2505 "BScreen::parseMenuFile: [include] error, "
2506 "no filename defined\n"));
2510 char newfile
[MAXPATHLEN
];
2512 // perform shell style ~ home directory expansion
2514 int homedir_len
= 0;
2515 if (*label
== '~' && *(label
+ 1) == '/') {
2516 homedir
= getenv("HOME");
2517 homedir_len
= strlen(homedir
);
2520 if (homedir
&& homedir_len
!= 0) {
2521 strncpy(newfile
, homedir
, homedir_len
);
2523 strncpy(newfile
+ homedir_len
, label
+ 1,
2525 *(newfile
+ label_length
+ homedir_len
- 1) = '\0';
2527 strncpy(newfile
, label
, label_length
);
2528 *(newfile
+ label_length
) = '\0';
2532 FILE *submenufile
= fopen(newfile
, "r");
2536 if (fstat(fileno(submenufile
), &buf
) ||
2537 (! S_ISREG(buf
.st_mode
))) {
2539 i18n
->getMessage(ScreenSet
, ScreenINCLUDEErrorReg
,
2540 "BScreen::parseMenuFile: [include] error: "
2541 "'%s' is not a regular file\n"), newfile
);
2545 if (! feof(submenufile
)) {
2546 if (! parseMenuFile(submenufile
, menu
))
2547 openbox
.setMenuFilename(newfile
);
2549 fclose(submenufile
);
2558 case 767: // submenu
2561 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenSUBMENUError
,
2562 "BScreen::parseMenuFile: [submenu] error, "
2563 "no menu label defined\n"));
2567 Rootmenu
*submenu
= new Rootmenu(*this);
2570 submenu
->setLabel(command
);
2572 submenu
->setLabel(label
);
2574 parseMenuFile(file
, submenu
);
2576 menu
->insert(label
, submenu
);
2577 rootmenuList
.push_back(submenu
);
2582 case 773: // restart
2585 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenRESTARTError
,
2586 "BScreen::parseMenuFile: [restart] error, "
2587 "no menu label defined\n"));
2592 menu
->insert(label
, BScreen::RestartOther
, command
);
2594 menu
->insert(label
, BScreen::Restart
);
2599 case 845: // reconfig
2602 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenRECONFIGError
,
2603 "BScreen::parseMenuFile: [reconfig] error, "
2604 "no menu label defined\n"));
2608 menu
->insert(label
, BScreen::Reconfigure
);
2613 case 995: // stylesdir
2614 case 1113: // stylesmenu
2616 Bool newmenu
= ((key
== 1113) ? True
: False
);
2618 if ((! *label
) || ((! *command
) && newmenu
)) {
2620 i18n
->getMessage(ScreenSet
, ScreenSTYLESDIRError
,
2621 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
2622 " error, no directory defined\n"));
2626 char stylesdir
[MAXPATHLEN
];
2628 char *directory
= ((newmenu
) ? command
: label
);
2629 int directory_length
= ((newmenu
) ? command_length
: label_length
);
2631 // perform shell style ~ home directory expansion
2633 int homedir_len
= 0;
2635 if (*directory
== '~' && *(directory
+ 1) == '/') {
2636 homedir
= getenv("HOME");
2637 homedir_len
= strlen(homedir
);
2640 if (homedir
&& homedir_len
!= 0) {
2641 strncpy(stylesdir
, homedir
, homedir_len
);
2643 strncpy(stylesdir
+ homedir_len
, directory
+ 1,
2644 directory_length
- 1);
2645 *(stylesdir
+ directory_length
+ homedir_len
- 1) = '\0';
2647 strncpy(stylesdir
, directory
, directory_length
);
2648 *(stylesdir
+ directory_length
) = '\0';
2651 struct stat statbuf
;
2653 if (! stat(stylesdir
, &statbuf
)) {
2654 if (S_ISDIR(statbuf
.st_mode
)) {
2655 Rootmenu
*stylesmenu
;
2658 stylesmenu
= new Rootmenu(*this);
2662 DIR *d
= opendir(stylesdir
);
2666 // get the total number of directory entries
2667 while ((p
= readdir(d
))) entries
++;
2670 char **ls
= new char* [entries
];
2672 while ((p
= readdir(d
)))
2673 ls
[index
++] = bstrdup(p
->d_name
);
2677 std::sort(ls
, ls
+ entries
, dcmp());
2679 int n
, slen
= strlen(stylesdir
);
2680 for (n
= 0; n
< entries
; n
++) {
2681 if (ls
[n
][strlen(ls
[n
])-1] != '~') {
2682 int nlen
= strlen(ls
[n
]);
2683 char style
[MAXPATHLEN
+ 1];
2685 strncpy(style
, stylesdir
, slen
);
2686 *(style
+ slen
) = '/';
2687 strncpy(style
+ slen
+ 1, ls
[n
], nlen
+ 1);
2689 if ((! stat(style
, &statbuf
)) && S_ISREG(statbuf
.st_mode
))
2690 stylesmenu
->insert(ls
[n
], BScreen::SetStyle
, style
);
2698 stylesmenu
->update();
2701 stylesmenu
->setLabel(label
);
2702 menu
->insert(label
, stylesmenu
);
2703 rootmenuList
.push_back(stylesmenu
);
2706 openbox
.setMenuFilename(stylesdir
);
2708 fprintf(stderr
, i18n
->getMessage(ScreenSet
,
2709 ScreenSTYLESDIRErrorNotDir
,
2710 "BScreen::parseMenuFile:"
2711 " [stylesdir/stylesmenu] error, %s is not a"
2712 " directory\n"), stylesdir
);
2716 i18n
->getMessage(ScreenSet
, ScreenSTYLESDIRErrorNoExist
,
2717 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
2718 " error, %s does not exist\n"), stylesdir
);
2724 case 1090: // workspaces
2728 i18n
->getMessage(ScreenSet
, ScreenWORKSPACESError
,
2729 "BScreen:parseMenuFile: [workspaces] error, "
2730 "no menu label defined\n"));
2734 menu
->insert(label
, workspacemenu
);
2743 return ((menu
->getCount() == 0) ? True
: False
);
2747 void BScreen::shutdown(void) {
2750 XSelectInput(getBaseDisplay().getXDisplay(), getRootWindow(), NoEventMask
);
2751 XSync(getBaseDisplay().getXDisplay(), False
);
2753 LinkedListIterator
<Workspace
> it(workspacesList
);
2754 for (Workspace
*w
= it
.current(); w
; it
++, w
= it
.current())
2757 while (iconList
->count()) {
2758 iconList
->first()->restore();
2759 delete iconList
->first();
2770 void BScreen::showPosition(int x
, int y
) {
2771 if (! geom_visible
) {
2772 XMoveResizeWindow(getBaseDisplay().getXDisplay(), geom_window
,
2773 (size().w() - geom_w
) / 2,
2774 (size().h() - geom_h
) / 2, geom_w
, geom_h
);
2775 XMapWindow(getBaseDisplay().getXDisplay(), geom_window
);
2776 XRaiseWindow(getBaseDisplay().getXDisplay(), geom_window
);
2778 geom_visible
= True
;
2783 sprintf(label
, i18n
->getMessage(ScreenSet
, ScreenPositionFormat
,
2784 "X: %4d x Y: %4d"), x
, y
);
2786 XClearWindow(getBaseDisplay().getXDisplay(), geom_window
);
2788 if (i18n
->multibyte()) {
2789 XmbDrawString(getBaseDisplay().getXDisplay(), geom_window
,
2790 resource
.wstyle
.fontset
, resource
.wstyle
.l_text_focus_gc
,
2791 resource
.bevel_width
, resource
.bevel_width
-
2792 resource
.wstyle
.fontset_extents
->max_ink_extent
.y
,
2793 label
, strlen(label
));
2795 XDrawString(getBaseDisplay().getXDisplay(), geom_window
,
2796 resource
.wstyle
.l_text_focus_gc
,
2797 resource
.bevel_width
,
2798 resource
.wstyle
.font
->ascent
+
2799 resource
.bevel_width
, label
, strlen(label
));
2804 void BScreen::showGeometry(unsigned int gx
, unsigned int gy
) {
2805 if (! geom_visible
) {
2806 XMoveResizeWindow(getBaseDisplay().getXDisplay(), geom_window
,
2807 (size().w() - geom_w
) / 2,
2808 (size().h() - geom_h
) / 2, geom_w
, geom_h
);
2809 XMapWindow(getBaseDisplay().getXDisplay(), geom_window
);
2810 XRaiseWindow(getBaseDisplay().getXDisplay(), geom_window
);
2812 geom_visible
= True
;
2817 sprintf(label
, i18n
->getMessage(ScreenSet
, ScreenGeometryFormat
,
2818 "W: %4d x H: %4d"), gx
, gy
);
2820 XClearWindow(getBaseDisplay().getXDisplay(), geom_window
);
2822 if (i18n
->multibyte()) {
2823 XmbDrawString(getBaseDisplay().getXDisplay(), geom_window
,
2824 resource
.wstyle
.fontset
, resource
.wstyle
.l_text_focus_gc
,
2825 resource
.bevel_width
, resource
.bevel_width
-
2826 resource
.wstyle
.fontset_extents
->max_ink_extent
.y
,
2827 label
, strlen(label
));
2829 XDrawString(getBaseDisplay().getXDisplay(), geom_window
,
2830 resource
.wstyle
.l_text_focus_gc
,
2831 resource
.bevel_width
,
2832 resource
.wstyle
.font
->ascent
+
2833 resource
.bevel_width
, label
, strlen(label
));
2837 void BScreen::hideGeometry(void) {
2839 XUnmapWindow(getBaseDisplay().getXDisplay(), geom_window
);
2840 geom_visible
= False
;