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"
55 #endif // HAVE_STDLIB_H
59 #endif // HAVE_STRING_H
61 #ifdef HAVE_SYS_TYPES_H
62 # include <sys/types.h>
63 #endif // HAVE_SYS_TYPES_H
67 #endif // HAVE_CTYPE_H
71 #endif // HAVE_DIRENT_H
75 #endif // HAVE_LOCALE_H
78 # include <sys/types.h>
80 #endif // HAVE_UNISTD_H
82 #ifdef HAVE_SYS_STAT_H
83 # include <sys/stat.h>
84 #endif // HAVE_SYS_STAT_H
88 #endif // HAVE_STDARG_H
91 # include "bsd-snprintf.h"
92 #endif // !HAVE_SNPRINTF
95 #define MAXPATHLEN 255
98 #ifndef FONT_ELEMENT_SIZE
99 #define FONT_ELEMENT_SIZE 50
100 #endif // FONT_ELEMENT_SIZE
106 static Bool running
= True
;
108 static int anotherWMRunning(Display
*display
, XErrorEvent
*) {
109 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenAnotherWMRunning
,
110 "BScreen::BScreen: an error occured while querying the X server.\n"
111 " another window manager already running on display %s.\n"),
112 DisplayString(display
));
120 bool operator()(const char *one
, const char *two
) const {
121 return (strcmp(one
, two
) < 0) ? True
: False
;
125 #ifndef HAVE_STRCASESTR
126 static const char * strcasestr(const char *str
, const char *ptn
) {
128 for( ; *str
; str
++) {
129 for(s2
=str
,p2
=ptn
; ; s2
++,p2
++) {
130 if (!*p2
) return str
;
131 if (toupper(*s2
) != toupper(*p2
)) break;
136 #endif // HAVE_STRCASESTR
138 static const char *getFontElement(const char *pattern
, char *buf
, int bufsiz
, ...) {
143 va_start(va
, bufsiz
);
146 while((v
= va_arg(va
, char *)) != NULL
) {
147 p
= strcasestr(pattern
, v
);
149 strncpy(buf
, p
+1, bufsiz
-2);
150 p2
= strchr(buf
, '-');
157 strncpy(buf
, "*", bufsiz
);
161 static const char *getFontSize(const char *pattern
, int *size
) {
166 for (p
=pattern
; 1; p
++) {
168 if (p2
!=NULL
&& n
>1 && n
<72) {
169 *size
= n
; return p2
+1;
171 *size
= 16; return NULL
;
173 } else if (*p
=='-') {
174 if (n
>1 && n
<72 && p2
!=NULL
) {
179 } else if (*p
>='0' && *p
<='9' && p2
!=NULL
) {
189 BScreen::BScreen(Openbox
&ob
, int scrn
, Resource
&conf
) : ScreenInfo(ob
, scrn
),
190 openbox(ob
), config(conf
)
193 resource
.full_max
= false;
194 resource
.focus_new
= false;
195 resource
.focus_last
= false;
196 resource
.row_direction
= LeftRight
;
197 resource
.col_direction
= TopBottom
;
198 resource
.workspaces
= 1;
199 resource
.sloppy_focus
= true;
200 resource
.auto_raise
= false;
202 resource
.placement_policy
= CascadePlacement
;
204 resource
.strftime_format
= bstrdup("%I:%M %p");
205 #else // !have_strftime
206 resource
.date_format
= B_AmericanDate
;
207 resource
.clock24hour
= false;
208 #endif // HAVE_STRFTIME
209 resource
.edge_snap_threshold
= 4;
210 resource
.image_dither
= true;
211 resource
.root_command
= NULL
;
212 resource
.opaque_move
= false;
214 event_mask
= ColormapChangeMask
| EnterWindowMask
| PropertyChangeMask
|
215 SubstructureRedirectMask
| KeyPressMask
| KeyReleaseMask
|
216 ButtonPressMask
| ButtonReleaseMask
;
218 XErrorHandler old
= XSetErrorHandler((XErrorHandler
) anotherWMRunning
);
219 XSelectInput(getBaseDisplay().getXDisplay(), getRootWindow(), event_mask
);
220 XSync(getBaseDisplay().getXDisplay(), False
);
221 XSetErrorHandler((XErrorHandler
) old
);
224 if (! managed
) return;
226 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenManagingScreen
,
227 "BScreen::BScreen: managing screen %d "
228 "using visual 0x%lx, depth %d\n"),
229 getScreenNumber(), XVisualIDFromVisual(getVisual()),
234 resource
.mstyle
.t_fontset
= resource
.mstyle
.f_fontset
=
235 resource
.tstyle
.fontset
= resource
.wstyle
.fontset
= NULL
;
236 resource
.mstyle
.t_font
= resource
.mstyle
.f_font
= resource
.tstyle
.font
=
237 resource
.wstyle
.font
= NULL
;
245 pid_t bpid
= getpid();
247 XChangeProperty(getBaseDisplay().getXDisplay(), getRootWindow(),
248 openbox
.getOpenboxPidAtom(), XA_CARDINAL
,
249 sizeof(pid_t
) * 8, PropModeReplace
,
250 (unsigned char *) &bpid
, 1);
251 #endif // HAVE_GETPID
253 XDefineCursor(getBaseDisplay().getXDisplay(), getRootWindow(),
254 openbox
.getSessionCursor());
256 workspaceNames
= new LinkedList
<char>;
257 workspacesList
= new LinkedList
<Workspace
>;
258 rootmenuList
= new LinkedList
<Rootmenu
>;
259 netizenList
= new LinkedList
<Netizen
>;
260 iconList
= new LinkedList
<OpenboxWindow
>;
263 new BImageControl(openbox
, *this, True
, openbox
.getColorsPerChannel(),
264 openbox
.getCacheLife(), openbox
.getCacheMax());
265 image_control
->installRootColormap();
266 root_colormap_installed
= True
;
268 image_control
->setDither(resource
.image_dither
);
270 load(); // load config options from Resources
274 unsigned long gc_value_mask
= GCForeground
;
275 if (! i18n
->multibyte()) gc_value_mask
|= GCFont
;
277 gcv
.foreground
= WhitePixel(getBaseDisplay().getXDisplay(),
279 ^ BlackPixel(getBaseDisplay().getXDisplay(),
281 gcv
.function
= GXxor
;
282 gcv
.subwindow_mode
= IncludeInferiors
;
283 opGC
= XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
284 GCForeground
| GCFunction
| GCSubwindowMode
, &gcv
);
286 gcv
.foreground
= resource
.wstyle
.l_text_focus
.getPixel();
287 if (resource
.wstyle
.font
)
288 gcv
.font
= resource
.wstyle
.font
->fid
;
289 resource
.wstyle
.l_text_focus_gc
=
290 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
291 gc_value_mask
, &gcv
);
293 gcv
.foreground
= resource
.wstyle
.l_text_unfocus
.getPixel();
294 if (resource
.wstyle
.font
)
295 gcv
.font
= resource
.wstyle
.font
->fid
;
296 resource
.wstyle
.l_text_unfocus_gc
=
297 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
298 gc_value_mask
, &gcv
);
300 gcv
.foreground
= resource
.wstyle
.b_pic_focus
.getPixel();
301 resource
.wstyle
.b_pic_focus_gc
=
302 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
305 gcv
.foreground
= resource
.wstyle
.b_pic_unfocus
.getPixel();
306 resource
.wstyle
.b_pic_unfocus_gc
=
307 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
310 gcv
.foreground
= resource
.mstyle
.t_text
.getPixel();
311 if (resource
.mstyle
.t_font
)
312 gcv
.font
= resource
.mstyle
.t_font
->fid
;
313 resource
.mstyle
.t_text_gc
=
314 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
315 gc_value_mask
, &gcv
);
317 gcv
.foreground
= resource
.mstyle
.f_text
.getPixel();
318 if (resource
.mstyle
.f_font
)
319 gcv
.font
= resource
.mstyle
.f_font
->fid
;
320 resource
.mstyle
.f_text_gc
=
321 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
322 gc_value_mask
, &gcv
);
324 gcv
.foreground
= resource
.mstyle
.h_text
.getPixel();
325 resource
.mstyle
.h_text_gc
=
326 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
327 gc_value_mask
, &gcv
);
329 gcv
.foreground
= resource
.mstyle
.d_text
.getPixel();
330 resource
.mstyle
.d_text_gc
=
331 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
332 gc_value_mask
, &gcv
);
334 gcv
.foreground
= resource
.mstyle
.hilite
.getColor()->getPixel();
335 resource
.mstyle
.hilite_gc
=
336 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
337 gc_value_mask
, &gcv
);
339 gcv
.foreground
= resource
.tstyle
.l_text
.getPixel();
340 if (resource
.tstyle
.font
)
341 gcv
.font
= resource
.tstyle
.font
->fid
;
342 resource
.tstyle
.l_text_gc
=
343 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
344 gc_value_mask
, &gcv
);
346 gcv
.foreground
= resource
.tstyle
.w_text
.getPixel();
347 resource
.tstyle
.w_text_gc
=
348 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
349 gc_value_mask
, &gcv
);
351 gcv
.foreground
= resource
.tstyle
.c_text
.getPixel();
352 resource
.tstyle
.c_text_gc
=
353 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
354 gc_value_mask
, &gcv
);
356 gcv
.foreground
= resource
.tstyle
.b_pic
.getPixel();
357 resource
.tstyle
.b_pic_gc
=
358 XCreateGC(getBaseDisplay().getXDisplay(), getRootWindow(),
359 gc_value_mask
, &gcv
);
361 const char *s
= i18n
->getMessage(ScreenSet
, ScreenPositionLength
,
362 "0: 0000 x 0: 0000");
365 if (i18n
->multibyte()) {
366 XRectangle ink
, logical
;
367 XmbTextExtents(resource
.wstyle
.fontset
, s
, l
, &ink
, &logical
);
368 geom_w
= logical
.width
;
370 geom_h
= resource
.wstyle
.fontset_extents
->max_ink_extent
.height
;
372 geom_h
= resource
.wstyle
.font
->ascent
+
373 resource
.wstyle
.font
->descent
;
375 geom_w
= XTextWidth(resource
.wstyle
.font
, s
, l
);
378 geom_w
+= (resource
.bevel_width
* 2);
379 geom_h
+= (resource
.bevel_width
* 2);
381 XSetWindowAttributes attrib
;
382 unsigned long mask
= CWBorderPixel
| CWColormap
| CWSaveUnder
;
383 attrib
.border_pixel
= getBorderColor()->getPixel();
384 attrib
.colormap
= getColormap();
385 attrib
.save_under
= True
;
388 XCreateWindow(getBaseDisplay().getXDisplay(), getRootWindow(),
389 0, 0, geom_w
, geom_h
, resource
.border_width
, getDepth(),
390 InputOutput
, getVisual(), mask
, &attrib
);
391 geom_visible
= False
;
393 if (resource
.wstyle
.l_focus
.getTexture() & BImage_ParentRelative
) {
394 if (resource
.wstyle
.t_focus
.getTexture() ==
395 (BImage_Flat
| BImage_Solid
)) {
397 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window
,
398 resource
.wstyle
.t_focus
.getColor()->getPixel());
400 geom_pixmap
= image_control
->renderImage(geom_w
, geom_h
,
401 &resource
.wstyle
.t_focus
);
402 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
403 geom_window
, geom_pixmap
);
406 if (resource
.wstyle
.l_focus
.getTexture() ==
407 (BImage_Flat
| BImage_Solid
)) {
409 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window
,
410 resource
.wstyle
.l_focus
.getColor()->getPixel());
412 geom_pixmap
= image_control
->renderImage(geom_w
, geom_h
,
413 &resource
.wstyle
.l_focus
);
414 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
415 geom_window
, geom_pixmap
);
419 workspacemenu
= new Workspacemenu(*this);
420 iconmenu
= new Iconmenu(*this);
421 configmenu
= new Configmenu(*this);
423 Workspace
*wkspc
= NULL
;
424 if (resource
.workspaces
!= 0) {
425 for (int i
= 0; i
< resource
.workspaces
; ++i
) {
426 wkspc
= new Workspace(*this, workspacesList
->count());
427 workspacesList
->insert(wkspc
);
428 saveWorkspaceNames();
429 workspacemenu
->insert(wkspc
->getName(), wkspc
->getMenu());
432 wkspc
= new Workspace(*this, workspacesList
->count());
433 workspacesList
->insert(wkspc
);
434 saveWorkspaceNames();
435 workspacemenu
->insert(wkspc
->getName(), wkspc
->getMenu());
438 workspacemenu
->insert(i18n
->getMessage(IconSet
, IconIcons
, "Icons"),
440 workspacemenu
->update();
442 current_workspace
= workspacesList
->first();
443 workspacemenu
->setItemSelected(2, True
);
445 toolbar
= new Toolbar(*this, config
);
448 slit
= new Slit(*this, config
);
456 changeWorkspaceID(0);
460 Window r
, p
, *children
;
461 XQueryTree(getBaseDisplay().getXDisplay(), getRootWindow(), &r
, &p
,
464 // preen the window list of all icon windows... for better dockapp support
465 for (i
= 0; i
< (int) nchild
; i
++) {
466 if (children
[i
] == None
) continue;
468 XWMHints
*wmhints
= XGetWMHints(getBaseDisplay().getXDisplay(),
472 if ((wmhints
->flags
& IconWindowHint
) &&
473 (wmhints
->icon_window
!= children
[i
]))
474 for (int j
= 0; j
< (int) nchild
; j
++)
475 if (children
[j
] == wmhints
->icon_window
) {
485 // manage shown windows
486 for (i
= 0; i
< (int) nchild
; ++i
) {
487 if (children
[i
] == None
|| (! openbox
.validateWindow(children
[i
])))
490 XWindowAttributes attrib
;
491 if (XGetWindowAttributes(getBaseDisplay().getXDisplay(), children
[i
],
493 if (attrib
.override_redirect
) continue;
495 if (attrib
.map_state
!= IsUnmapped
) {
496 new OpenboxWindow(openbox
, children
[i
], this);
498 OpenboxWindow
*win
= openbox
.searchWindow(children
[i
]);
500 XMapRequestEvent mre
;
501 mre
.window
= children
[i
];
502 win
->restoreAttributes();
503 win
->mapRequestEvent(&mre
);
509 if (! resource
.sloppy_focus
)
510 XSetInputFocus(getBaseDisplay().getXDisplay(), toolbar
->getWindowID(),
511 RevertToParent
, CurrentTime
);
514 XFlush(getBaseDisplay().getXDisplay());
518 BScreen::~BScreen(void) {
519 if (! managed
) return;
521 if (geom_pixmap
!= None
)
522 image_control
->removeImage(geom_pixmap
);
524 if (geom_window
!= None
)
525 XDestroyWindow(getBaseDisplay().getXDisplay(), geom_window
);
527 removeWorkspaceNames();
529 while (workspacesList
->count())
530 delete workspacesList
->remove(0);
532 while (rootmenuList
->count())
533 rootmenuList
->remove(0);
535 while (iconList
->count())
536 delete iconList
->remove(0);
538 while (netizenList
->count())
539 delete netizenList
->remove(0);
542 if (resource
.strftime_format
)
543 delete [] resource
.strftime_format
;
544 #endif // HAVE_STRFTIME
547 delete workspacemenu
;
556 delete image_control
;
558 delete workspacesList
;
559 delete workspaceNames
;
564 if (resource
.wstyle
.fontset
)
565 XFreeFontSet(getBaseDisplay().getXDisplay(), resource
.wstyle
.fontset
);
566 if (resource
.mstyle
.t_fontset
)
567 XFreeFontSet(getBaseDisplay().getXDisplay(), resource
.mstyle
.t_fontset
);
568 if (resource
.mstyle
.f_fontset
)
569 XFreeFontSet(getBaseDisplay().getXDisplay(), resource
.mstyle
.f_fontset
);
570 if (resource
.tstyle
.fontset
)
571 XFreeFontSet(getBaseDisplay().getXDisplay(), resource
.tstyle
.fontset
);
573 if (resource
.wstyle
.font
)
574 XFreeFont(getBaseDisplay().getXDisplay(), resource
.wstyle
.font
);
575 if (resource
.mstyle
.t_font
)
576 XFreeFont(getBaseDisplay().getXDisplay(), resource
.mstyle
.t_font
);
577 if (resource
.mstyle
.f_font
)
578 XFreeFont(getBaseDisplay().getXDisplay(), resource
.mstyle
.f_font
);
579 if (resource
.tstyle
.font
)
580 XFreeFont(getBaseDisplay().getXDisplay(), resource
.tstyle
.font
);
581 if (resource
.root_command
!= NULL
)
582 delete [] resource
.root_command
;
584 XFreeGC(getBaseDisplay().getXDisplay(), opGC
);
586 XFreeGC(getBaseDisplay().getXDisplay(),
587 resource
.wstyle
.l_text_focus_gc
);
588 XFreeGC(getBaseDisplay().getXDisplay(),
589 resource
.wstyle
.l_text_unfocus_gc
);
590 XFreeGC(getBaseDisplay().getXDisplay(),
591 resource
.wstyle
.b_pic_focus_gc
);
592 XFreeGC(getBaseDisplay().getXDisplay(),
593 resource
.wstyle
.b_pic_unfocus_gc
);
595 XFreeGC(getBaseDisplay().getXDisplay(),
596 resource
.mstyle
.t_text_gc
);
597 XFreeGC(getBaseDisplay().getXDisplay(),
598 resource
.mstyle
.f_text_gc
);
599 XFreeGC(getBaseDisplay().getXDisplay(),
600 resource
.mstyle
.h_text_gc
);
601 XFreeGC(getBaseDisplay().getXDisplay(),
602 resource
.mstyle
.d_text_gc
);
603 XFreeGC(getBaseDisplay().getXDisplay(),
604 resource
.mstyle
.hilite_gc
);
606 XFreeGC(getBaseDisplay().getXDisplay(),
607 resource
.tstyle
.l_text_gc
);
608 XFreeGC(getBaseDisplay().getXDisplay(),
609 resource
.tstyle
.w_text_gc
);
610 XFreeGC(getBaseDisplay().getXDisplay(),
611 resource
.tstyle
.c_text_gc
);
612 XFreeGC(getBaseDisplay().getXDisplay(),
613 resource
.tstyle
.b_pic_gc
);
616 void BScreen::readDatabaseTexture(const char *rname
, const char *rclass
,
618 unsigned long default_pixel
)
622 if (resource
.styleconfig
.getValue(rname
, rclass
, s
))
623 image_control
->parseTexture(texture
, s
.c_str());
625 texture
->setTexture(BImage_Solid
| BImage_Flat
);
627 if (texture
->getTexture() & BImage_Solid
) {
628 int clen
= strlen(rclass
) + 32, nlen
= strlen(rname
) + 32;
630 char *colorclass
= new char[clen
], *colorname
= new char[nlen
];
632 sprintf(colorclass
, "%s.Color", rclass
);
633 sprintf(colorname
, "%s.color", rname
);
635 readDatabaseColor(colorname
, colorclass
, texture
->getColor(),
639 sprintf(colorclass
, "%s.ColorTo", rclass
);
640 sprintf(colorname
, "%s.colorTo", rname
);
642 readDatabaseColor(colorname
, colorclass
, texture
->getColorTo(),
646 delete [] colorclass
;
649 if ((! texture
->getColor()->isAllocated()) ||
650 (texture
->getTexture() & BImage_Flat
))
655 xcol
.red
= (unsigned int) (texture
->getColor()->getRed() +
656 (texture
->getColor()->getRed() >> 1));
657 if (xcol
.red
>= 0xff) xcol
.red
= 0xffff;
658 else xcol
.red
*= 0xff;
659 xcol
.green
= (unsigned int) (texture
->getColor()->getGreen() +
660 (texture
->getColor()->getGreen() >> 1));
661 if (xcol
.green
>= 0xff) xcol
.green
= 0xffff;
662 else xcol
.green
*= 0xff;
663 xcol
.blue
= (unsigned int) (texture
->getColor()->getBlue() +
664 (texture
->getColor()->getBlue() >> 1));
665 if (xcol
.blue
>= 0xff) xcol
.blue
= 0xffff;
666 else xcol
.blue
*= 0xff;
668 if (! XAllocColor(getBaseDisplay().getXDisplay(),
669 getColormap(), &xcol
))
672 texture
->getHiColor()->setPixel(xcol
.pixel
);
675 (unsigned int) ((texture
->getColor()->getRed() >> 2) +
676 (texture
->getColor()->getRed() >> 1)) * 0xff;
678 (unsigned int) ((texture
->getColor()->getGreen() >> 2) +
679 (texture
->getColor()->getGreen() >> 1)) * 0xff;
681 (unsigned int) ((texture
->getColor()->getBlue() >> 2) +
682 (texture
->getColor()->getBlue() >> 1)) * 0xff;
684 if (! XAllocColor(getBaseDisplay().getXDisplay(),
685 getColormap(), &xcol
))
688 texture
->getLoColor()->setPixel(xcol
.pixel
);
689 } else if (texture
->getTexture() & BImage_Gradient
) {
690 int clen
= strlen(rclass
) + 10, nlen
= strlen(rname
) + 10;
692 char *colorclass
= new char[clen
], *colorname
= new char[nlen
],
693 *colortoclass
= new char[clen
], *colortoname
= new char[nlen
];
695 sprintf(colorclass
, "%s.Color", rclass
);
696 sprintf(colorname
, "%s.color", rname
);
698 sprintf(colortoclass
, "%s.ColorTo", rclass
);
699 sprintf(colortoname
, "%s.colorTo", rname
);
701 readDatabaseColor(colorname
, colorclass
, texture
->getColor(),
703 readDatabaseColor(colortoname
, colortoclass
, texture
->getColorTo(),
706 delete [] colorclass
;
708 delete [] colortoclass
;
709 delete [] colortoname
;
714 void BScreen::readDatabaseColor(const char *rname
, const char *rclass
,
715 BColor
*color
, unsigned long default_pixel
)
719 if (resource
.styleconfig
.getValue(rname
, rclass
, s
))
720 image_control
->parseColor(color
, s
.c_str());
722 // parsing with no color string just deallocates the color, if it has
723 // been previously allocated
724 image_control
->parseColor(color
);
725 color
->setPixel(default_pixel
);
730 void BScreen::readDatabaseFontSet(const char *rname
, const char *rclass
,
732 if (! fontset
) return;
734 static char *defaultFont
= "fixed";
735 bool load_default
= false;
739 XFreeFontSet(getBaseDisplay().getXDisplay(), *fontset
);
741 if (resource
.styleconfig
.getValue(rname
, rclass
, s
)) {
742 if (! (*fontset
= createFontSet(s
.c_str())))
748 *fontset
= createFontSet(defaultFont
);
751 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenDefaultFontLoadFail
,
752 "BScreen::LoadStyle(): couldn't load default font.\n"));
759 void BScreen::readDatabaseFont(const char *rname
, const char *rclass
,
760 XFontStruct
**font
) {
763 static char *defaultFont
= "fixed";
764 bool load_default
= false;
768 XFreeFont(getBaseDisplay().getXDisplay(), *font
);
770 if (resource
.styleconfig
.getValue(rname
, rclass
, s
)) {
771 if ((*font
= XLoadQueryFont(getBaseDisplay().getXDisplay(),
772 s
.c_str())) == NULL
) {
773 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenFontLoadFail
,
774 "BScreen::LoadStyle(): couldn't load font '%s'\n"),
782 if ((*font
= XLoadQueryFont(getBaseDisplay().getXDisplay(),
783 defaultFont
)) == NULL
) {
784 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenDefaultFontLoadFail
,
785 "BScreen::LoadStyle(): couldn't load default font.\n"));
792 XFontSet
BScreen::createFontSet(const char *fontname
) {
794 char **missing
, *def
= "-";
795 int nmissing
, pixel_size
= 0, buf_size
= 0;
796 char weight
[FONT_ELEMENT_SIZE
], slant
[FONT_ELEMENT_SIZE
];
798 fs
= XCreateFontSet(getBaseDisplay().getXDisplay(),
799 fontname
, &missing
, &nmissing
, &def
);
800 if (fs
&& (! nmissing
)) return fs
;
802 #ifdef HAVE_SETLOCALE
804 if (nmissing
) XFreeStringList(missing
);
806 setlocale(LC_CTYPE
, "C");
807 fs
= XCreateFontSet(getBaseDisplay().getXDisplay(), fontname
,
808 &missing
, &nmissing
, &def
);
809 setlocale(LC_CTYPE
, "");
811 #endif // HAVE_SETLOCALE
814 XFontStruct
**fontstructs
;
816 XFontsOfFontSet(fs
, &fontstructs
, &fontnames
);
817 fontname
= fontnames
[0];
820 getFontElement(fontname
, weight
, FONT_ELEMENT_SIZE
,
821 "-medium-", "-bold-", "-demibold-", "-regular-", NULL
);
822 getFontElement(fontname
, slant
, FONT_ELEMENT_SIZE
,
823 "-r-", "-i-", "-o-", "-ri-", "-ro-", NULL
);
824 getFontSize(fontname
, &pixel_size
);
826 if (! strcmp(weight
, "*")) strncpy(weight
, "medium", FONT_ELEMENT_SIZE
);
827 if (! strcmp(slant
, "*")) strncpy(slant
, "r", FONT_ELEMENT_SIZE
);
828 if (pixel_size
< 3) pixel_size
= 3;
829 else if (pixel_size
> 97) pixel_size
= 97;
831 buf_size
= strlen(fontname
) + (FONT_ELEMENT_SIZE
* 2) + 64;
832 char *pattern2
= new char[buf_size
];
833 snprintf(pattern2
, buf_size
- 1,
835 "-*-*-%s-%s-*-*-%d-*-*-*-*-*-*-*,"
836 "-*-*-*-*-*-*-%d-*-*-*-*-*-*-*,*",
837 fontname
, weight
, slant
, pixel_size
, pixel_size
);
840 if (nmissing
) XFreeStringList(missing
);
841 if (fs
) XFreeFontSet(getBaseDisplay().getXDisplay(), fs
);
843 fs
= XCreateFontSet(getBaseDisplay().getXDisplay(), fontname
,
844 &missing
, &nmissing
, &def
);
850 void BScreen::setSloppyFocus(bool b
) {
851 resource
.sloppy_focus
= b
;
853 s
<< "session.screen" << getScreenNumber() << ".focusModel" << ends
;
854 config
.setValue(s
.str(),
855 (resource
.sloppy_focus
?
856 (resource
.auto_raise
? "AutoRaiseSloppyFocus" : "SloppyFocus")
858 s
.rdbuf()->freeze(0);
861 void BScreen::setAutoRaise(bool a
) {
862 resource
.auto_raise
= a
;
864 s
<< "session.screen" << getScreenNumber() << ".focusModel" << ends
;
865 config
.setValue(s
.str(),
866 (resource
.sloppy_focus
?
867 (resource
.auto_raise
? "AutoRaiseSloppyFocus" : "SloppyFocus")
869 s
.rdbuf()->freeze(0);
872 void BScreen::setImageDither(bool d
) {
873 resource
.image_dither
= d
;
875 s
<< "session.screen" << getScreenNumber() << ".imageDither" << ends
;
876 config
.setValue(s
.str(), resource
.image_dither
);
877 s
.rdbuf()->freeze(0);
880 void BScreen::setOpaqueMove(bool o
) {
881 resource
.opaque_move
= o
;
883 s
<< "session.screen" << getScreenNumber() << ".opaqueMove" << ends
;
884 config
.setValue(s
.str(), resource
.opaque_move
);
885 s
.rdbuf()->freeze(0);
888 void BScreen::setFullMax(bool f
) {
889 resource
.full_max
= f
;
891 s
<< "session.screen" << getScreenNumber() << ".fullMaximization" << ends
;
892 config
.setValue(s
.str(), resource
.full_max
);
893 s
.rdbuf()->freeze(0);
896 void BScreen::setFocusNew(bool f
) {
897 resource
.focus_new
= f
;
899 s
<< "session.screen" << getScreenNumber() << ".focusNewWindows" << ends
;
900 config
.setValue(s
.str(), resource
.focus_new
);
901 s
.rdbuf()->freeze(0);
904 void BScreen::setFocusLast(bool f
) {
905 resource
.focus_last
= f
;
907 s
<< "session.screen" << getScreenNumber() << ".focusLastWindow" << ends
;
908 config
.setValue(s
.str(), resource
.focus_last
);
909 s
.rdbuf()->freeze(0);
912 void BScreen::setWindowZones(int z
) {
915 s
<< "session.screen" << getScreenNumber() << ".windowZones" << ends
;
916 config
.setValue(s
.str(), resource
.zones
);
917 s
.rdbuf()->freeze(0);
920 void BScreen::setWorkspaceCount(int w
) {
921 resource
.workspaces
= w
;
923 s
<< "session.screen" << getScreenNumber() << ".workspaces" << ends
;
924 config
.setValue(s
.str(), resource
.workspaces
);
925 s
.rdbuf()->freeze(0);
928 void BScreen::setPlacementPolicy(int p
) {
929 resource
.placement_policy
= p
;
931 s
<< "session.screen" << getScreenNumber() << ".windowPlacement" << ends
;
932 const char *placement
;
933 switch (resource
.placement_policy
) {
934 case CascadePlacement
: placement
= "CascadePlacement"; break;
935 case BestFitPlacement
: placement
= "BestFitPlacement"; break;
936 case ColSmartPlacement
: placement
= "ColSmartPlacement"; break;
938 case RowSmartPlacement
: placement
= "RowSmartPlacement"; break;
940 config
.setValue(s
.str(), placement
);
941 s
.rdbuf()->freeze(0);
944 void BScreen::setEdgeSnapThreshold(int t
) {
945 resource
.edge_snap_threshold
= t
;
947 s
<< "session.screen" << getScreenNumber() << ".edgeSnapThreshold" << ends
;
948 config
.setValue(s
.str(), resource
.edge_snap_threshold
);
949 s
.rdbuf()->freeze(0);
952 void BScreen::setRowPlacementDirection(int d
) {
953 resource
.row_direction
= d
;
955 s
<< "session.screen" << getScreenNumber() << ".rowPlacementDirection" <<
957 config
.setValue(s
.str(),
958 resource
.row_direction
== LeftRight
?
959 "LeftToRight" : "RightToLeft");
960 s
.rdbuf()->freeze(0);
963 void BScreen::setColPlacementDirection(int d
) {
964 resource
.col_direction
= d
;
966 s
<< "session.screen" << getScreenNumber() << ".colPlacementDirection" <<
968 config
.setValue(s
.str(),
969 resource
.col_direction
== TopBottom
?
970 "TopToBottom" : "BottomToTop");
971 s
.rdbuf()->freeze(0);
974 void BScreen::setRootCommand(const char *cmd
) {
975 if (resource
.root_command
!= NULL
)
976 delete [] resource
.root_command
;
978 resource
.root_command
= bstrdup(cmd
);
980 resource
.root_command
= NULL
;
981 // this doesn't save to the Resources config because it can't be changed
982 // inside Openbox, and this way we dont add an empty command which would over-
983 // ride the styles commend when none has been specified
986 void BScreen::setStrftimeFormat(const char *f
) {
987 if (resource
.strftime_format
!= NULL
)
988 delete [] resource
.strftime_format
;
990 resource
.strftime_format
= bstrdup(f
);
992 s
<< "session.screen" << getScreenNumber() << ".strftimeFormat" << ends
;
993 config
.setValue(s
.str(), resource
.strftime_format
);
994 s
.rdbuf()->freeze(0);
997 #else // !HAVE_STRFTIME
998 void BScreen::setDateFormat(int f
) {
999 resource
.date_format
= f
;
1001 s
<< "session.screen" << getScreenNumber() << ".dateFormat" << ends
;
1002 config
.setValue(s
.str(), resource
.date_format
== B_EuropeanDate
?
1003 "European" : "American");
1004 s
.rdbuf()->freeze(0);
1007 void BScreen::setClock24Hour(Bool c
) {
1008 resource
.clock24hour
= c
;
1010 s
<< "session.screen" << getScreenNumber() << ".clockFormat" << ends
;
1011 config
.setValue(s
.str(), resource
.clock24hour
? 24 : 12);
1012 s
.rdbuf()->freeze(0);
1014 #endif // HAVE_STRFTIME
1016 void BScreen::setHideToolbar(bool b
) {
1017 resource
.hide_toolbar
= b
;
1018 if (resource
.hide_toolbar
)
1019 getToolbar()->unMapToolbar();
1021 getToolbar()->mapToolbar();
1023 s
<< "session.screen" << getScreenNumber() << ".hideToolbar" << ends
;
1024 config
.setValue(s
.str(), resource
.hide_toolbar
? "True" : "False");
1025 s
.rdbuf()->freeze(0);
1028 void BScreen::saveWorkspaceNames() {
1029 ostrstream rc
, names
;
1031 for (int i
= 0; i
< resource
.workspaces
; i
++) {
1032 Workspace
*w
= getWorkspace(i
);
1034 names
<< w
->getName();
1035 if (i
< resource
.workspaces
-1)
1041 rc
<< "session.screen" << getScreenNumber() << ".workspaceNames" << ends
;
1042 config
.setValue(rc
.str(), names
.str());
1043 rc
.rdbuf()->freeze(0);
1044 names
.rdbuf()->freeze(0);
1047 void BScreen::save() {
1048 setSloppyFocus(resource
.sloppy_focus
);
1049 setAutoRaise(resource
.auto_raise
);
1050 setImageDither(resource
.image_dither
);
1051 setOpaqueMove(resource
.opaque_move
);
1052 setFullMax(resource
.full_max
);
1053 setFocusNew(resource
.focus_new
);
1054 setFocusLast(resource
.focus_last
);
1055 setWindowZones(resource
.zones
);
1056 setWorkspaceCount(resource
.workspaces
);
1057 setPlacementPolicy(resource
.placement_policy
);
1058 setEdgeSnapThreshold(resource
.edge_snap_threshold
);
1059 setRowPlacementDirection(resource
.row_direction
);
1060 setColPlacementDirection(resource
.col_direction
);
1061 setRootCommand(resource
.root_command
);
1062 #ifdef HAVE_STRFTIME
1063 // it deletes the current value before setting the new one, so we have to
1064 // duplicate the current value.
1065 std::string s
= resource
.strftime_format
;
1066 setStrftimeFormat(s
.c_str());
1067 #else // !HAVE_STRFTIME
1068 setDateFormat(resource
.date_format
);
1069 setClock24Hour(resource
.clock24hour
);
1070 #endif // HAVE_STRFTIME
1071 setHideToolbar(resource
.hide_toolbar
);
1074 void BScreen::load() {
1075 std::ostrstream rscreen
, rname
, rclass
;
1079 rscreen
<< "session.screen" << getScreenNumber() << '.' << ends
;
1081 rname
<< rscreen
.str() << "hideToolbar" << ends
;
1082 rclass
<< rscreen
.str() << "HideToolbar" << ends
;
1083 if (config
.getValue(rname
.str(), rclass
.str(), b
))
1084 resource
.hide_toolbar
= b
;
1085 Toolbar
*t
= getToolbar();
1087 if (resource
.hide_toolbar
)
1093 rname
.seekp(0); rclass
.seekp(0);
1094 rname
<< rscreen
.str() << "fullMaximization" << ends
;
1095 rclass
<< rscreen
.str() << "FullMaximization" << ends
;
1096 if (config
.getValue(rname
.str(), rclass
.str(), b
))
1097 resource
.full_max
= b
;
1099 rname
.seekp(0); rclass
.seekp(0);
1100 rname
<< rscreen
.str() << "focusNewWindows" << ends
;
1101 rclass
<< rscreen
.str() << "FocusNewWindows" << ends
;
1102 if (config
.getValue(rname
.str(), rclass
.str(), b
))
1103 resource
.focus_new
= b
;
1105 rname
.seekp(0); rclass
.seekp(0);
1106 rname
<< rscreen
.str() << "focusLastWindow" << ends
;
1107 rclass
<< rscreen
.str() << "FocusLastWindow" << ends
;
1108 if (config
.getValue(rname
.str(), rclass
.str(), b
))
1109 resource
.focus_last
= b
;
1111 rname
.seekp(0); rclass
.seekp(0);
1112 rname
<< rscreen
.str() << "rowPlacementDirection" << ends
;
1113 rclass
<< rscreen
.str() << "RowPlacementDirection" << ends
;
1114 if (config
.getValue(rname
.str(), rclass
.str(), s
)) {
1115 if (0 == strncasecmp(s
.c_str(), "RightToLeft", s
.length()))
1116 resource
.row_direction
= RightLeft
;
1117 else if (0 == strncasecmp(s
.c_str(), "LeftToRight", s
.length()))
1118 resource
.row_direction
= LeftRight
;
1121 rname
.seekp(0); rclass
.seekp(0);
1122 rname
<< rscreen
.str() << "colPlacementDirection" << ends
;
1123 rclass
<< rscreen
.str() << "ColPlacementDirection" << ends
;
1124 if (config
.getValue(rname
.str(), rclass
.str(), s
)) {
1125 if (0 == strncasecmp(s
.c_str(), "BottomToTop", s
.length()))
1126 resource
.col_direction
= BottomTop
;
1127 else if (0 == strncasecmp(s
.c_str(), "TopToBottom", s
.length()))
1128 resource
.col_direction
= TopBottom
;
1131 rname
.seekp(0); rclass
.seekp(0);
1132 rname
<< rscreen
.str() << "workspaces" << ends
;
1133 rclass
<< rscreen
.str() << "Workspaces" << ends
;
1134 if (config
.getValue(rname
.str(), rclass
.str(), l
))
1135 resource
.workspaces
= l
;
1137 removeWorkspaceNames();
1138 rname
.seekp(0); rclass
.seekp(0);
1139 rname
<< rscreen
.str() << "workspaceNames" << ends
;
1140 rclass
<< rscreen
.str() << "WorkspaceNames" << ends
;
1141 if (config
.getValue(rname
.str(), rclass
.str(), s
)) {
1142 std::string::const_iterator it
= s
.begin(), end
= s
.end();
1144 std::string::const_iterator tmp
= it
;// current string.begin()
1145 it
= std::find(tmp
, end
, ','); // look for comma between tmp and end
1146 std::string
name(tmp
, it
); // name = s[tmp:it]
1147 addWorkspaceName(name
.c_str());
1154 rname
.seekp(0); rclass
.seekp(0);
1155 rname
<< rscreen
.str() << "focusModel" << ends
;
1156 rclass
<< rscreen
.str() << "FocusModel" << ends
;
1157 if (config
.getValue(rname
.str(), rclass
.str(), s
)) {
1158 if (0 == strncasecmp(s
.c_str(), "ClickToFocus", s
.length())) {
1159 resource
.auto_raise
= false;
1160 resource
.sloppy_focus
= false;
1161 } else if (0 == strncasecmp(s
.c_str(), "AutoRaiseSloppyFocus",
1163 resource
.sloppy_focus
= true;
1164 resource
.auto_raise
= true;
1165 } else if (0 == strncasecmp(s
.c_str(), "SloppyFocus", s
.length())) {
1166 resource
.sloppy_focus
= true;
1167 resource
.auto_raise
= false;
1171 rname
.seekp(0); rclass
.seekp(0);
1172 rname
<< rscreen
.str() << "windowZones" << ends
;
1173 rclass
<< rscreen
.str() << "WindowZones" << ends
;
1174 if (config
.getValue(rname
.str(), rclass
.str(), l
))
1175 resource
.zones
= (l
== 1 || l
== 2 || l
== 4) ? l
: 1;
1177 rname
.seekp(0); rclass
.seekp(0);
1178 rname
<< rscreen
.str() << "windowPlacement" << ends
;
1179 rclass
<< rscreen
.str() << "WindowPlacement" << ends
;
1180 if (config
.getValue(rname
.str(), rclass
.str(), s
)) {
1181 if (0 == strncasecmp(s
.c_str(), "RowSmartPlacement", s
.length()))
1182 resource
.placement_policy
= RowSmartPlacement
;
1183 else if (0 == strncasecmp(s
.c_str(), "ColSmartPlacement", s
.length()))
1184 resource
.placement_policy
= ColSmartPlacement
;
1185 else if (0 == strncasecmp(s
.c_str(), "BestFitPlacement", s
.length()))
1186 resource
.placement_policy
= BestFitPlacement
;
1187 else if (0 == strncasecmp(s
.c_str(), "CascadePlacement", s
.length()))
1188 resource
.placement_policy
= CascadePlacement
;
1191 #ifdef HAVE_STRFTIME
1192 rname
.seekp(0); rclass
.seekp(0);
1193 rname
<< rscreen
.str() << "strftimeFormat" << ends
;
1194 rclass
<< rscreen
.str() << "StrftimeFormat" << ends
;
1195 if (config
.getValue(rname
.str(), rclass
.str(), s
)) {
1196 if (resource
.strftime_format
!= NULL
)
1197 delete [] resource
.strftime_format
;
1198 resource
.strftime_format
= bstrdup(s
.c_str());
1200 #else // !HAVE_STRFTIME
1201 rname
.seekp(0); rclass
.seekp(0);
1202 rname
<< rscreen
.str() << "dateFormat" << ends
;
1203 rclass
<< rscreen
.str() << "DateFormat" << ends
;
1204 if (config
.getValue(rname
.str(), rclass
.str(), s
)) {
1205 if (strncasecmp(s
.c_str(), "European", s
.length()))
1206 resource
.date_format
= B_EuropeanDate
;
1207 else if (strncasecmp(s
.c_str(), "American", s
.length()))
1208 resource
.date_format
= B_AmericanDate
;
1211 rname
.seekp(0); rclass
.seekp(0);
1212 rname
<< rscreen
.str() << "clockFormat" << ends
;
1213 rclass
<< rscreen
.str() << "ClockFormat" << ends
;
1214 if (config
.getValue(rname
.str(), rclass
.str(), l
)) {
1216 resource
.clock24hour
= true;
1217 else if (clock
== 12)
1218 resource
.clock24hour
= false;
1219 #endif // HAVE_STRFTIME
1221 rname
.seekp(0); rclass
.seekp(0);
1222 rname
<< rscreen
.str() << "edgeSnapThreshold" << ends
;
1223 rclass
<< rscreen
.str() << "EdgeSnapThreshold" << ends
;
1224 if (config
.getValue(rname
.str(), rclass
.str(), l
))
1225 resource
.edge_snap_threshold
= l
;
1227 rname
.seekp(0); rclass
.seekp(0);
1228 rname
<< rscreen
.str() << "imageDither" << ends
;
1229 rclass
<< rscreen
.str() << "ImageDither" << ends
;
1230 if (config
.getValue(rname
.str(), rclass
.str(), b
))
1231 resource
.image_dither
= b
;
1233 rname
.seekp(0); rclass
.seekp(0);
1234 rname
<< rscreen
.str() << "rootCommand" << ends
;
1235 rclass
<< rscreen
.str() << "RootCommand" << ends
;
1236 if (config
.getValue(rname
.str(), rclass
.str(), s
)) {
1237 if (resource
.root_command
!= NULL
)
1238 delete [] resource
.root_command
;
1239 resource
.root_command
= bstrdup(s
.c_str());
1242 rname
.seekp(0); rclass
.seekp(0);
1243 rname
<< rscreen
.str() << "opaqueMove" << ends
;
1244 rclass
<< rscreen
.str() << "OpaqueMove" << ends
;
1245 if (config
.getValue(rname
.str(), rclass
.str(), b
))
1246 resource
.opaque_move
= b
;
1247 rscreen
.rdbuf()->freeze(0);
1248 rname
.rdbuf()->freeze(0);
1249 rclass
.rdbuf()->freeze(0);
1252 void BScreen::reconfigure(void) {
1261 unsigned long gc_value_mask
= GCForeground
;
1262 if (! i18n
->multibyte()) gc_value_mask
|= GCFont
;
1264 gcv
.foreground
= WhitePixel(getBaseDisplay().getXDisplay(),
1266 gcv
.function
= GXinvert
;
1267 gcv
.subwindow_mode
= IncludeInferiors
;
1268 XChangeGC(getBaseDisplay().getXDisplay(), opGC
,
1269 GCForeground
| GCFunction
| GCSubwindowMode
, &gcv
);
1271 gcv
.foreground
= resource
.wstyle
.l_text_focus
.getPixel();
1272 if (resource
.wstyle
.font
)
1273 gcv
.font
= resource
.wstyle
.font
->fid
;
1274 XChangeGC(getBaseDisplay().getXDisplay(), resource
.wstyle
.l_text_focus_gc
,
1275 gc_value_mask
, &gcv
);
1277 gcv
.foreground
= resource
.wstyle
.l_text_unfocus
.getPixel();
1278 XChangeGC(getBaseDisplay().getXDisplay(), resource
.wstyle
.l_text_unfocus_gc
,
1279 gc_value_mask
, &gcv
);
1281 gcv
.foreground
= resource
.wstyle
.b_pic_focus
.getPixel();
1282 XChangeGC(getBaseDisplay().getXDisplay(), resource
.wstyle
.b_pic_focus_gc
,
1283 GCForeground
, &gcv
);
1285 gcv
.foreground
= resource
.wstyle
.b_pic_unfocus
.getPixel();
1286 XChangeGC(getBaseDisplay().getXDisplay(), resource
.wstyle
.b_pic_unfocus_gc
,
1287 GCForeground
, &gcv
);
1289 gcv
.foreground
= resource
.mstyle
.t_text
.getPixel();
1290 if (resource
.mstyle
.t_font
)
1291 gcv
.font
= resource
.mstyle
.t_font
->fid
;
1292 XChangeGC(getBaseDisplay().getXDisplay(), resource
.mstyle
.t_text_gc
,
1293 gc_value_mask
, &gcv
);
1295 gcv
.foreground
= resource
.mstyle
.f_text
.getPixel();
1296 if (resource
.mstyle
.f_font
)
1297 gcv
.font
= resource
.mstyle
.f_font
->fid
;
1298 XChangeGC(getBaseDisplay().getXDisplay(), resource
.mstyle
.f_text_gc
,
1299 gc_value_mask
, &gcv
);
1301 gcv
.foreground
= resource
.mstyle
.h_text
.getPixel();
1302 XChangeGC(getBaseDisplay().getXDisplay(), resource
.mstyle
.h_text_gc
,
1303 gc_value_mask
, &gcv
);
1305 gcv
.foreground
= resource
.mstyle
.d_text
.getPixel();
1306 XChangeGC(getBaseDisplay().getXDisplay(), resource
.mstyle
.d_text_gc
,
1307 gc_value_mask
, &gcv
);
1309 gcv
.foreground
= resource
.mstyle
.hilite
.getColor()->getPixel();
1310 XChangeGC(getBaseDisplay().getXDisplay(), resource
.mstyle
.hilite_gc
,
1311 gc_value_mask
, &gcv
);
1313 gcv
.foreground
= resource
.tstyle
.l_text
.getPixel();
1314 if (resource
.tstyle
.font
)
1315 gcv
.font
= resource
.tstyle
.font
->fid
;
1316 XChangeGC(getBaseDisplay().getXDisplay(), resource
.tstyle
.l_text_gc
,
1317 gc_value_mask
, &gcv
);
1319 gcv
.foreground
= resource
.tstyle
.w_text
.getPixel();
1320 XChangeGC(getBaseDisplay().getXDisplay(), resource
.tstyle
.w_text_gc
,
1321 gc_value_mask
, &gcv
);
1323 gcv
.foreground
= resource
.tstyle
.c_text
.getPixel();
1324 XChangeGC(getBaseDisplay().getXDisplay(), resource
.tstyle
.c_text_gc
,
1325 gc_value_mask
, &gcv
);
1327 gcv
.foreground
= resource
.tstyle
.b_pic
.getPixel();
1328 XChangeGC(getBaseDisplay().getXDisplay(), resource
.tstyle
.b_pic_gc
,
1329 gc_value_mask
, &gcv
);
1331 const char *s
= i18n
->getMessage(ScreenSet
, ScreenPositionLength
,
1332 "0: 0000 x 0: 0000");
1335 if (i18n
->multibyte()) {
1336 XRectangle ink
, logical
;
1337 XmbTextExtents(resource
.wstyle
.fontset
, s
, l
, &ink
, &logical
);
1338 geom_w
= logical
.width
;
1340 geom_h
= resource
.wstyle
.fontset_extents
->max_ink_extent
.height
;
1342 geom_w
= XTextWidth(resource
.wstyle
.font
, s
, l
);
1344 geom_h
= resource
.wstyle
.font
->ascent
+
1345 resource
.wstyle
.font
->descent
;
1348 geom_w
+= (resource
.bevel_width
* 2);
1349 geom_h
+= (resource
.bevel_width
* 2);
1351 Pixmap tmp
= geom_pixmap
;
1352 if (resource
.wstyle
.l_focus
.getTexture() & BImage_ParentRelative
) {
1353 if (resource
.wstyle
.t_focus
.getTexture() ==
1354 (BImage_Flat
| BImage_Solid
)) {
1356 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window
,
1357 resource
.wstyle
.t_focus
.getColor()->getPixel());
1359 geom_pixmap
= image_control
->renderImage(geom_w
, geom_h
,
1360 &resource
.wstyle
.t_focus
);
1361 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
1362 geom_window
, geom_pixmap
);
1365 if (resource
.wstyle
.l_focus
.getTexture() ==
1366 (BImage_Flat
| BImage_Solid
)) {
1368 XSetWindowBackground(getBaseDisplay().getXDisplay(), geom_window
,
1369 resource
.wstyle
.l_focus
.getColor()->getPixel());
1371 geom_pixmap
= image_control
->renderImage(geom_w
, geom_h
,
1372 &resource
.wstyle
.l_focus
);
1373 XSetWindowBackgroundPixmap(getBaseDisplay().getXDisplay(),
1374 geom_window
, geom_pixmap
);
1377 if (tmp
) image_control
->removeImage(tmp
);
1379 XSetWindowBorderWidth(getBaseDisplay().getXDisplay(), geom_window
,
1380 resource
.border_width
);
1381 XSetWindowBorder(getBaseDisplay().getXDisplay(), geom_window
,
1382 resource
.border_color
.getPixel());
1384 workspacemenu
->reconfigure();
1385 iconmenu
->reconfigure();
1388 int remember_sub
= rootmenu
->getCurrentSubmenu();
1391 rootmenu
->reconfigure();
1392 rootmenu
->drawSubmenu(remember_sub
);
1395 configmenu
->reconfigure();
1397 toolbar
->reconfigure();
1400 slit
->reconfigure();
1403 LinkedListIterator
<Workspace
> wit(workspacesList
);
1404 for (Workspace
*w
= wit
.current(); w
; wit
++, w
= wit
.current())
1407 LinkedListIterator
<OpenboxWindow
> iit(iconList
);
1408 for (OpenboxWindow
*bw
= iit
.current(); bw
; iit
++, bw
= iit
.current())
1409 if (bw
->validateClient())
1412 image_control
->timeout();
1416 void BScreen::rereadMenu(void) {
1420 rootmenu
->reconfigure();
1424 void BScreen::removeWorkspaceNames(void) {
1425 while (workspaceNames
->count())
1426 delete [] workspaceNames
->remove(0);
1430 void BScreen::LoadStyle(void) {
1431 Resource
&conf
= resource
.styleconfig
;
1433 const char *sfile
= openbox
.getStyleFilename();
1434 bool loaded
= false;
1435 if (sfile
!= NULL
) {
1436 conf
.setFile(sfile
);
1437 loaded
= conf
.load();
1440 conf
.setFile(DEFAULTSTYLE
);
1442 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenDefaultStyleLoadFail
,
1443 "BScreen::LoadStyle(): couldn't load "
1444 "default style.\n"));
1452 // load fonts/fontsets
1454 if (i18n
->multibyte()) {
1455 readDatabaseFontSet("window.font", "Window.Font",
1456 &resource
.wstyle
.fontset
);
1457 readDatabaseFontSet("toolbar.font", "Toolbar.Font",
1458 &resource
.tstyle
.fontset
);
1459 readDatabaseFontSet("menu.title.font", "Menu.Title.Font",
1460 &resource
.mstyle
.t_fontset
);
1461 readDatabaseFontSet("menu.frame.font", "Menu.Frame.Font",
1462 &resource
.mstyle
.f_fontset
);
1464 resource
.mstyle
.t_fontset_extents
=
1465 XExtentsOfFontSet(resource
.mstyle
.t_fontset
);
1466 resource
.mstyle
.f_fontset_extents
=
1467 XExtentsOfFontSet(resource
.mstyle
.f_fontset
);
1468 resource
.tstyle
.fontset_extents
=
1469 XExtentsOfFontSet(resource
.tstyle
.fontset
);
1470 resource
.wstyle
.fontset_extents
=
1471 XExtentsOfFontSet(resource
.wstyle
.fontset
);
1473 readDatabaseFont("window.font", "Window.Font",
1474 &resource
.wstyle
.font
);
1475 readDatabaseFont("menu.title.font", "Menu.Title.Font",
1476 &resource
.mstyle
.t_font
);
1477 readDatabaseFont("menu.frame.font", "Menu.Frame.Font",
1478 &resource
.mstyle
.f_font
);
1479 readDatabaseFont("toolbar.font", "Toolbar.Font",
1480 &resource
.tstyle
.font
);
1483 // load window config
1484 readDatabaseTexture("window.title.focus", "Window.Title.Focus",
1485 &resource
.wstyle
.t_focus
,
1486 WhitePixel(getBaseDisplay().getXDisplay(),
1487 getScreenNumber()));
1488 readDatabaseTexture("window.title.unfocus", "Window.Title.Unfocus",
1489 &resource
.wstyle
.t_unfocus
,
1490 BlackPixel(getBaseDisplay().getXDisplay(),
1491 getScreenNumber()));
1492 readDatabaseTexture("window.label.focus", "Window.Label.Focus",
1493 &resource
.wstyle
.l_focus
,
1494 WhitePixel(getBaseDisplay().getXDisplay(),
1495 getScreenNumber()));
1496 readDatabaseTexture("window.label.unfocus", "Window.Label.Unfocus",
1497 &resource
.wstyle
.l_unfocus
,
1498 BlackPixel(getBaseDisplay().getXDisplay(),
1499 getScreenNumber()));
1500 readDatabaseTexture("window.handle.focus", "Window.Handle.Focus",
1501 &resource
.wstyle
.h_focus
,
1502 WhitePixel(getBaseDisplay().getXDisplay(),
1503 getScreenNumber()));
1504 readDatabaseTexture("window.handle.unfocus", "Window.Handle.Unfocus",
1505 &resource
.wstyle
.h_unfocus
,
1506 BlackPixel(getBaseDisplay().getXDisplay(),
1507 getScreenNumber()));
1508 readDatabaseTexture("window.grip.focus", "Window.Grip.Focus",
1509 &resource
.wstyle
.g_focus
,
1510 WhitePixel(getBaseDisplay().getXDisplay(),
1511 getScreenNumber()));
1512 readDatabaseTexture("window.grip.unfocus", "Window.Grip.Unfocus",
1513 &resource
.wstyle
.g_unfocus
,
1514 BlackPixel(getBaseDisplay().getXDisplay(),
1515 getScreenNumber()));
1516 readDatabaseTexture("window.button.focus", "Window.Button.Focus",
1517 &resource
.wstyle
.b_focus
,
1518 WhitePixel(getBaseDisplay().getXDisplay(),
1519 getScreenNumber()));
1520 readDatabaseTexture("window.button.unfocus", "Window.Button.Unfocus",
1521 &resource
.wstyle
.b_unfocus
,
1522 BlackPixel(getBaseDisplay().getXDisplay(),
1523 getScreenNumber()));
1524 readDatabaseTexture("window.button.pressed", "Window.Button.Pressed",
1525 &resource
.wstyle
.b_pressed
,
1526 BlackPixel(getBaseDisplay().getXDisplay(),
1527 getScreenNumber()));
1528 readDatabaseColor("window.frame.focusColor",
1529 "Window.Frame.FocusColor",
1530 &resource
.wstyle
.f_focus
,
1531 WhitePixel(getBaseDisplay().getXDisplay(),
1532 getScreenNumber()));
1533 readDatabaseColor("window.frame.unfocusColor",
1534 "Window.Frame.UnfocusColor",
1535 &resource
.wstyle
.f_unfocus
,
1536 BlackPixel(getBaseDisplay().getXDisplay(),
1537 getScreenNumber()));
1538 readDatabaseColor("window.label.focus.textColor",
1539 "Window.Label.Focus.TextColor",
1540 &resource
.wstyle
.l_text_focus
,
1541 BlackPixel(getBaseDisplay().getXDisplay(),
1542 getScreenNumber()));
1543 readDatabaseColor("window.label.unfocus.textColor",
1544 "Window.Label.Unfocus.TextColor",
1545 &resource
.wstyle
.l_text_unfocus
,
1546 WhitePixel(getBaseDisplay().getXDisplay(),
1547 getScreenNumber()));
1548 readDatabaseColor("window.button.focus.picColor",
1549 "Window.Button.Focus.PicColor",
1550 &resource
.wstyle
.b_pic_focus
,
1551 BlackPixel(getBaseDisplay().getXDisplay(),
1552 getScreenNumber()));
1553 readDatabaseColor("window.button.unfocus.picColor",
1554 "Window.Button.Unfocus.PicColor",
1555 &resource
.wstyle
.b_pic_unfocus
,
1556 WhitePixel(getBaseDisplay().getXDisplay(),
1557 getScreenNumber()));
1559 if (conf
.getValue("window.justify", "Window.Justify", s
)) {
1560 if (0 == strncasecmp(s
.c_str(), "right", s
.length()))
1561 resource
.wstyle
.justify
= BScreen::RightJustify
;
1562 else if (0 == strncasecmp(s
.c_str(), "center", s
.length()))
1563 resource
.wstyle
.justify
= BScreen::CenterJustify
;
1565 resource
.wstyle
.justify
= BScreen::LeftJustify
;
1567 resource
.wstyle
.justify
= BScreen::LeftJustify
;
1569 // load toolbar config
1570 readDatabaseTexture("toolbar", "Toolbar",
1571 &resource
.tstyle
.toolbar
,
1572 BlackPixel(getBaseDisplay().getXDisplay(),
1573 getScreenNumber()));
1574 readDatabaseTexture("toolbar.label", "Toolbar.Label",
1575 &resource
.tstyle
.label
,
1576 BlackPixel(getBaseDisplay().getXDisplay(),
1577 getScreenNumber()));
1578 readDatabaseTexture("toolbar.windowLabel", "Toolbar.WindowLabel",
1579 &resource
.tstyle
.window
,
1580 BlackPixel(getBaseDisplay().getXDisplay(),
1581 getScreenNumber()));
1582 readDatabaseTexture("toolbar.button", "Toolbar.Button",
1583 &resource
.tstyle
.button
,
1584 WhitePixel(getBaseDisplay().getXDisplay(),
1585 getScreenNumber()));
1586 readDatabaseTexture("toolbar.button.pressed", "Toolbar.Button.Pressed",
1587 &resource
.tstyle
.pressed
,
1588 BlackPixel(getBaseDisplay().getXDisplay(),
1589 getScreenNumber()));
1590 readDatabaseTexture("toolbar.clock", "Toolbar.Clock",
1591 &resource
.tstyle
.clock
,
1592 BlackPixel(getBaseDisplay().getXDisplay(),
1593 getScreenNumber()));
1594 readDatabaseColor("toolbar.label.textColor", "Toolbar.Label.TextColor",
1595 &resource
.tstyle
.l_text
,
1596 WhitePixel(getBaseDisplay().getXDisplay(),
1597 getScreenNumber()));
1598 readDatabaseColor("toolbar.windowLabel.textColor",
1599 "Toolbar.WindowLabel.TextColor",
1600 &resource
.tstyle
.w_text
,
1601 WhitePixel(getBaseDisplay().getXDisplay(),
1602 getScreenNumber()));
1603 readDatabaseColor("toolbar.clock.textColor", "Toolbar.Clock.TextColor",
1604 &resource
.tstyle
.c_text
,
1605 WhitePixel(getBaseDisplay().getXDisplay(),
1606 getScreenNumber()));
1607 readDatabaseColor("toolbar.button.picColor", "Toolbar.Button.PicColor",
1608 &resource
.tstyle
.b_pic
,
1609 BlackPixel(getBaseDisplay().getXDisplay(),
1610 getScreenNumber()));
1612 if (conf
.getValue("toolbar.justify", "Toolbar.Justify", s
)) {
1613 if (0 == strncasecmp(s
.c_str(), "right", s
.length()))
1614 resource
.tstyle
.justify
= BScreen::RightJustify
;
1615 else if (0 == strncasecmp(s
.c_str(), "center", s
.length()))
1616 resource
.tstyle
.justify
= BScreen::CenterJustify
;
1618 resource
.tstyle
.justify
= BScreen::LeftJustify
;
1620 resource
.tstyle
.justify
= BScreen::LeftJustify
;
1623 readDatabaseTexture("menu.title", "Menu.Title",
1624 &resource
.mstyle
.title
,
1625 WhitePixel(getBaseDisplay().getXDisplay(),
1626 getScreenNumber()));
1627 readDatabaseTexture("menu.frame", "Menu.Frame",
1628 &resource
.mstyle
.frame
,
1629 BlackPixel(getBaseDisplay().getXDisplay(),
1630 getScreenNumber()));
1631 readDatabaseTexture("menu.hilite", "Menu.Hilite",
1632 &resource
.mstyle
.hilite
,
1633 WhitePixel(getBaseDisplay().getXDisplay(),
1634 getScreenNumber()));
1635 readDatabaseColor("menu.title.textColor", "Menu.Title.TextColor",
1636 &resource
.mstyle
.t_text
,
1637 BlackPixel(getBaseDisplay().getXDisplay(),
1638 getScreenNumber()));
1639 readDatabaseColor("menu.frame.textColor", "Menu.Frame.TextColor",
1640 &resource
.mstyle
.f_text
,
1641 WhitePixel(getBaseDisplay().getXDisplay(),
1642 getScreenNumber()));
1643 readDatabaseColor("menu.frame.disableColor", "Menu.Frame.DisableColor",
1644 &resource
.mstyle
.d_text
,
1645 BlackPixel(getBaseDisplay().getXDisplay(),
1646 getScreenNumber()));
1647 readDatabaseColor("menu.hilite.textColor", "Menu.Hilite.TextColor",
1648 &resource
.mstyle
.h_text
,
1649 BlackPixel(getBaseDisplay().getXDisplay(),
1650 getScreenNumber()));
1652 if (conf
.getValue("menu.title.justify", "Menu.Title.Justify", s
)) {
1653 if (0 == strncasecmp(s
.c_str(), "right", s
.length()))
1654 resource
.mstyle
.t_justify
= BScreen::RightJustify
;
1655 else if (0 == strncasecmp(s
.c_str(), "center", s
.length()))
1656 resource
.mstyle
.t_justify
= BScreen::CenterJustify
;
1658 resource
.mstyle
.t_justify
= BScreen::LeftJustify
;
1660 resource
.mstyle
.t_justify
= BScreen::LeftJustify
;
1662 if (conf
.getValue("menu.frame.justify", "Menu.Frame.Justify", s
)) {
1663 if (0 == strncasecmp(s
.c_str(), "right", s
.length()))
1664 resource
.mstyle
.f_justify
= BScreen::RightJustify
;
1665 else if (0 == strncasecmp(s
.c_str(), "center", s
.length()))
1666 resource
.mstyle
.f_justify
= BScreen::CenterJustify
;
1668 resource
.mstyle
.f_justify
= BScreen::LeftJustify
;
1670 resource
.mstyle
.f_justify
= BScreen::LeftJustify
;
1672 if (conf
.getValue("menu.bullet", "Menu.Bullet", s
)) {
1673 if (0 == strncasecmp(s
.c_str(), "empty", s
.length()))
1674 resource
.mstyle
.bullet
= Basemenu::Empty
;
1675 else if (0 == strncasecmp(s
.c_str(), "square", s
.length()))
1676 resource
.mstyle
.bullet
= Basemenu::Square
;
1677 else if (0 == strncasecmp(s
.c_str(), "diamond", s
.length()))
1678 resource
.mstyle
.bullet
= Basemenu::Diamond
;
1680 resource
.mstyle
.bullet
= Basemenu::Triangle
;
1682 resource
.mstyle
.bullet
= Basemenu::Triangle
;
1684 if (conf
.getValue("menu.bullet.position", "Menu.Bullet.Position", s
)) {
1685 if (0 == strncasecmp(s
.c_str(), "right", s
.length()))
1686 resource
.mstyle
.bullet_pos
= Basemenu::Right
;
1688 resource
.mstyle
.bullet_pos
= Basemenu::Left
;
1690 resource
.mstyle
.bullet_pos
= Basemenu::Left
;
1692 readDatabaseColor("borderColor", "BorderColor", &resource
.border_color
,
1693 BlackPixel(getBaseDisplay().getXDisplay(),
1694 getScreenNumber()));
1696 // load bevel, border and handle widths
1697 if (conf
.getValue("handleWidth", "HandleWidth", l
)) {
1698 if (l
<= size().w() / 2 && l
!= 0)
1699 resource
.handle_width
= l
;
1701 resource
.handle_width
= 6;
1703 resource
.handle_width
= 6;
1705 if (conf
.getValue("borderWidth", "BorderWidth", l
))
1706 resource
.border_width
= l
;
1708 resource
.border_width
= 1;
1710 if (conf
.getValue("bevelWidth", "BevelWidth", l
)) {
1711 if (l
<= size().w() / 2 && l
!= 0)
1712 resource
.bevel_width
= l
;
1714 resource
.bevel_width
= 3;
1716 resource
.bevel_width
= 3;
1718 if (conf
.getValue("frameWidth", "FrameWidth", l
)) {
1719 if (l
<= size().w() / 2)
1720 resource
.frame_width
= l
;
1722 resource
.frame_width
= resource
.bevel_width
;
1724 resource
.frame_width
= resource
.bevel_width
;
1726 const char *cmd
= resource
.root_command
;
1727 if (cmd
!= NULL
|| conf
.getValue("rootCommand", "RootCommand", s
)) {
1729 cmd
= s
.c_str(); // not specified by the screen, so use the one from the
1732 char displaystring
[MAXPATHLEN
];
1733 sprintf(displaystring
, "DISPLAY=%s",
1734 DisplayString(getBaseDisplay().getXDisplay()));
1735 sprintf(displaystring
+ strlen(displaystring
) - 1, "%d",
1738 bexec(cmd
, displaystring
);
1740 spawnlp(P_NOWAIT
, "cmd.exe", "cmd.exe", "/c", cmd
, NULL
);
1746 void BScreen::addIcon(OpenboxWindow
*w
) {
1749 w
->setWorkspace(-1);
1750 w
->setWindowNumber(iconList
->count());
1752 iconList
->insert(w
);
1754 iconmenu
->insert((const char **) w
->getIconTitle());
1759 void BScreen::removeIcon(OpenboxWindow
*w
) {
1762 iconList
->remove(w
->getWindowNumber());
1764 iconmenu
->remove(w
->getWindowNumber());
1767 LinkedListIterator
<OpenboxWindow
> it(iconList
);
1768 OpenboxWindow
*bw
= it
.current();
1769 for (int i
= 0; bw
; it
++, bw
= it
.current())
1770 bw
->setWindowNumber(i
++);
1774 OpenboxWindow
*BScreen::getIcon(int index
) {
1775 if (index
>= 0 && index
< iconList
->count())
1776 return iconList
->find(index
);
1782 int BScreen::addWorkspace(void) {
1783 Workspace
*wkspc
= new Workspace(*this, workspacesList
->count());
1784 workspacesList
->insert(wkspc
);
1785 saveWorkspaceNames();
1787 workspacemenu
->insert(wkspc
->getName(), wkspc
->getMenu(),
1788 wkspc
->getWorkspaceID() + 2);
1789 workspacemenu
->update();
1791 toolbar
->reconfigure();
1793 updateNetizenWorkspaceCount();
1795 return workspacesList
->count();
1799 int BScreen::removeLastWorkspace(void) {
1800 if (workspacesList
->count() == 1)
1803 Workspace
*wkspc
= workspacesList
->last();
1805 if (current_workspace
->getWorkspaceID() == wkspc
->getWorkspaceID())
1806 changeWorkspaceID(current_workspace
->getWorkspaceID() - 1);
1810 workspacemenu
->remove(wkspc
->getWorkspaceID() + 2);
1811 workspacemenu
->update();
1813 workspacesList
->remove(wkspc
);
1816 toolbar
->reconfigure();
1818 updateNetizenWorkspaceCount();
1820 return workspacesList
->count();
1824 void BScreen::changeWorkspaceID(int id
) {
1825 if (! current_workspace
) return;
1827 if (id
!= current_workspace
->getWorkspaceID()) {
1828 current_workspace
->hideAll();
1830 workspacemenu
->setItemSelected(current_workspace
->getWorkspaceID() + 2,
1833 if (openbox
.getFocusedWindow() &&
1834 openbox
.getFocusedWindow()->getScreen() == this &&
1835 (! openbox
.getFocusedWindow()->isStuck())) {
1836 current_workspace
->setLastFocusedWindow(openbox
.getFocusedWindow());
1837 openbox
.setFocusedWindow(NULL
);
1840 current_workspace
= getWorkspace(id
);
1842 workspacemenu
->setItemSelected(current_workspace
->getWorkspaceID() + 2,
1844 toolbar
->redrawWorkspaceLabel(True
);
1846 current_workspace
->showAll();
1848 if (resource
.focus_last
&& current_workspace
->getLastFocusedWindow()) {
1849 XSync(openbox
.getXDisplay(), False
);
1850 current_workspace
->getLastFocusedWindow()->setInputFocus();
1854 updateNetizenCurrentWorkspace();
1858 void BScreen::addNetizen(Netizen
*n
) {
1859 netizenList
->insert(n
);
1861 n
->sendWorkspaceCount();
1862 n
->sendCurrentWorkspace();
1864 LinkedListIterator
<Workspace
> it(workspacesList
);
1865 for (Workspace
*w
= it
.current(); w
; it
++, w
= it
.current()) {
1866 for (int i
= 0; i
< w
->getCount(); i
++)
1867 n
->sendWindowAdd(w
->getWindow(i
)->getClientWindow(),
1868 w
->getWorkspaceID());
1871 Window f
= ((openbox
.getFocusedWindow()) ?
1872 openbox
.getFocusedWindow()->getClientWindow() : None
);
1873 n
->sendWindowFocus(f
);
1877 void BScreen::removeNetizen(Window w
) {
1878 LinkedListIterator
<Netizen
> it(netizenList
);
1881 for (Netizen
*n
= it
.current(); n
; it
++, i
++, n
= it
.current())
1882 if (n
->getWindowID() == w
) {
1883 Netizen
*tmp
= netizenList
->remove(i
);
1891 void BScreen::updateNetizenCurrentWorkspace(void) {
1892 LinkedListIterator
<Netizen
> it(netizenList
);
1893 for (Netizen
*n
= it
.current(); n
; it
++, n
= it
.current())
1894 n
->sendCurrentWorkspace();
1898 void BScreen::updateNetizenWorkspaceCount(void) {
1899 LinkedListIterator
<Netizen
> it(netizenList
);
1900 for (Netizen
*n
= it
.current(); n
; it
++, n
= it
.current())
1901 n
->sendWorkspaceCount();
1905 void BScreen::updateNetizenWindowFocus(void) {
1906 Window f
= ((openbox
.getFocusedWindow()) ?
1907 openbox
.getFocusedWindow()->getClientWindow() : None
);
1908 LinkedListIterator
<Netizen
> it(netizenList
);
1909 for (Netizen
*n
= it
.current(); n
; it
++, n
= it
.current())
1910 n
->sendWindowFocus(f
);
1914 void BScreen::updateNetizenWindowAdd(Window w
, unsigned long p
) {
1915 LinkedListIterator
<Netizen
> it(netizenList
);
1916 for (Netizen
*n
= it
.current(); n
; it
++, n
= it
.current())
1917 n
->sendWindowAdd(w
, p
);
1921 void BScreen::updateNetizenWindowDel(Window w
) {
1922 LinkedListIterator
<Netizen
> it(netizenList
);
1923 for (Netizen
*n
= it
.current(); n
; it
++, n
= it
.current())
1924 n
->sendWindowDel(w
);
1928 void BScreen::updateNetizenWindowRaise(Window w
) {
1929 LinkedListIterator
<Netizen
> it(netizenList
);
1930 for (Netizen
*n
= it
.current(); n
; it
++, n
= it
.current())
1931 n
->sendWindowRaise(w
);
1935 void BScreen::updateNetizenWindowLower(Window w
) {
1936 LinkedListIterator
<Netizen
> it(netizenList
);
1937 for (Netizen
*n
= it
.current(); n
; it
++, n
= it
.current())
1938 n
->sendWindowLower(w
);
1942 void BScreen::updateNetizenConfigNotify(XEvent
*e
) {
1943 LinkedListIterator
<Netizen
> it(netizenList
);
1944 for (Netizen
*n
= it
.current(); n
; it
++, n
= it
.current())
1945 n
->sendConfigNotify(e
);
1949 void BScreen::raiseWindows(Window
*workspace_stack
, int num
) {
1950 Window
*session_stack
= new
1951 Window
[(num
+ workspacesList
->count() + rootmenuList
->count() + 13)];
1954 XRaiseWindow(getBaseDisplay().getXDisplay(), iconmenu
->getWindowID());
1955 *(session_stack
+ i
++) = iconmenu
->getWindowID();
1957 LinkedListIterator
<Workspace
> wit(workspacesList
);
1958 for (Workspace
*tmp
= wit
.current(); tmp
; wit
++, tmp
= wit
.current())
1959 *(session_stack
+ i
++) = tmp
->getMenu()->getWindowID();
1961 *(session_stack
+ i
++) = workspacemenu
->getWindowID();
1963 *(session_stack
+ i
++) = configmenu
->getFocusmenu()->getWindowID();
1964 *(session_stack
+ i
++) = configmenu
->getPlacementmenu()->getWindowID();
1965 *(session_stack
+ i
++) = configmenu
->getWindowID();
1968 *(session_stack
+ i
++) = slit
->getMenu()->getDirectionmenu()->getWindowID();
1969 *(session_stack
+ i
++) = slit
->getMenu()->getPlacementmenu()->getWindowID();
1970 *(session_stack
+ i
++) = slit
->getMenu()->getWindowID();
1973 *(session_stack
+ i
++) =
1974 toolbar
->getMenu()->getPlacementmenu()->getWindowID();
1975 *(session_stack
+ i
++) = toolbar
->getMenu()->getWindowID();
1977 LinkedListIterator
<Rootmenu
> rit(rootmenuList
);
1978 for (Rootmenu
*tmp
= rit
.current(); tmp
; rit
++, tmp
= rit
.current())
1979 *(session_stack
+ i
++) = tmp
->getWindowID();
1980 *(session_stack
+ i
++) = rootmenu
->getWindowID();
1982 if (toolbar
->onTop())
1983 *(session_stack
+ i
++) = toolbar
->getWindowID();
1987 *(session_stack
+ i
++) = slit
->getWindowID();
1991 *(session_stack
+ i
++) = *(workspace_stack
+ k
);
1993 XRestackWindows(getBaseDisplay().getXDisplay(), session_stack
, i
);
1995 delete [] session_stack
;
1999 void BScreen::addWorkspaceName(const char *name
) {
2000 workspaceNames
->insert(bstrdup(name
));
2003 char* BScreen::getNameOfWorkspace(int id
) {
2006 if (id
>= 0 && id
< workspaceNames
->count()) {
2007 char *wkspc_name
= workspaceNames
->find(id
);
2016 void BScreen::reassociateWindow(OpenboxWindow
*w
, int wkspc_id
, Bool ignore_sticky
) {
2020 wkspc_id
= current_workspace
->getWorkspaceID();
2022 if (w
->getWorkspaceNumber() == wkspc_id
)
2025 if (w
->isIconic()) {
2027 getWorkspace(wkspc_id
)->addWindow(w
);
2028 } else if (ignore_sticky
|| ! w
->isStuck()) {
2029 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
2030 getWorkspace(wkspc_id
)->addWindow(w
);
2035 void BScreen::nextFocus(void) {
2036 Bool have_focused
= False
;
2037 int focused_window_number
= -1;
2038 OpenboxWindow
*next
;
2040 if (openbox
.getFocusedWindow()) {
2041 if (openbox
.getFocusedWindow()->getScreen()->getScreenNumber() ==
2042 getScreenNumber()) {
2043 have_focused
= True
;
2044 focused_window_number
= openbox
.getFocusedWindow()->getWindowNumber();
2048 if ((getCurrentWorkspace()->getCount() > 1) && have_focused
) {
2049 int next_window_number
= focused_window_number
;
2051 if ((++next_window_number
) >= getCurrentWorkspace()->getCount())
2052 next_window_number
= 0;
2054 next
= getCurrentWorkspace()->getWindow(next_window_number
);
2055 } while ((! next
->setInputFocus()) && (next_window_number
!=
2056 focused_window_number
));
2058 if (next_window_number
!= focused_window_number
)
2059 getCurrentWorkspace()->raiseWindow(next
);
2060 } else if (getCurrentWorkspace()->getCount() >= 1) {
2061 next
= current_workspace
->getWindow(0);
2063 current_workspace
->raiseWindow(next
);
2064 next
->setInputFocus();
2069 void BScreen::prevFocus(void) {
2070 Bool have_focused
= False
;
2071 int focused_window_number
= -1;
2072 OpenboxWindow
*prev
;
2074 if (openbox
.getFocusedWindow()) {
2075 if (openbox
.getFocusedWindow()->getScreen()->getScreenNumber() ==
2076 getScreenNumber()) {
2077 have_focused
= True
;
2078 focused_window_number
= openbox
.getFocusedWindow()->getWindowNumber();
2082 if ((getCurrentWorkspace()->getCount() > 1) && have_focused
) {
2083 int prev_window_number
= focused_window_number
;
2085 if ((--prev_window_number
) < 0)
2086 prev_window_number
= getCurrentWorkspace()->getCount() - 1;
2088 prev
= getCurrentWorkspace()->getWindow(prev_window_number
);
2089 } while ((! prev
->setInputFocus()) && (prev_window_number
!=
2090 focused_window_number
));
2092 if (prev_window_number
!= focused_window_number
)
2093 getCurrentWorkspace()->raiseWindow(prev
);
2094 } else if (getCurrentWorkspace()->getCount() >= 1) {
2095 prev
= current_workspace
->getWindow(0);
2097 current_workspace
->raiseWindow(prev
);
2098 prev
->setInputFocus();
2103 void BScreen::raiseFocus(void) {
2104 Bool have_focused
= False
;
2105 int focused_window_number
= -1;
2107 if (openbox
.getFocusedWindow()) {
2108 if (openbox
.getFocusedWindow()->getScreen()->getScreenNumber() ==
2109 getScreenNumber()) {
2110 have_focused
= True
;
2111 focused_window_number
= openbox
.getFocusedWindow()->getWindowNumber();
2115 if ((getCurrentWorkspace()->getCount() > 1) && have_focused
)
2116 getWorkspace(openbox
.getFocusedWindow()->getWorkspaceNumber())->
2117 raiseWindow(openbox
.getFocusedWindow());
2121 void BScreen::InitMenu(void) {
2123 while (rootmenuList
->count())
2124 rootmenuList
->remove(0);
2126 while (rootmenu
->getCount())
2127 rootmenu
->remove(0);
2129 rootmenu
= new Rootmenu(*this);
2131 Bool defaultMenu
= True
;
2133 if (openbox
.getMenuFilename()) {
2134 FILE *menu_file
= fopen(openbox
.getMenuFilename(), "r");
2137 perror(openbox
.getMenuFilename());
2139 if (feof(menu_file
)) {
2140 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenEmptyMenuFile
,
2141 "%s: Empty menu file"),
2142 openbox
.getMenuFilename());
2144 char line
[1024], label
[1024];
2145 memset(line
, 0, 1024);
2146 memset(label
, 0, 1024);
2148 while (fgets(line
, 1024, menu_file
) && ! feof(menu_file
)) {
2149 if (line
[0] != '#') {
2150 int i
, key
= 0, index
= -1, len
= strlen(line
);
2153 for (i
= 0; i
< len
; i
++) {
2154 if (line
[i
] == '[') index
= 0;
2155 else if (line
[i
] == ']') break;
2156 else if (line
[i
] != ' ')
2158 key
+= tolower(line
[i
]);
2163 for (i
= index
; i
< len
; i
++) {
2164 if (line
[i
] == '(') index
= 0;
2165 else if (line
[i
] == ')') break;
2166 else if (index
++ >= 0) {
2167 if (line
[i
] == '\\' && i
< len
- 1) i
++;
2168 label
[index
- 1] = line
[i
];
2172 if (index
== -1) index
= 0;
2173 label
[index
] = '\0';
2175 rootmenu
->setLabel(label
);
2176 defaultMenu
= parseMenuFile(menu_file
, rootmenu
);
2187 rootmenu
->setInternalMenu();
2188 rootmenu
->insert(i18n
->getMessage(ScreenSet
, Screenxterm
, "xterm"),
2190 i18n
->getMessage(ScreenSet
, Screenxterm
, "xterm"));
2191 rootmenu
->insert(i18n
->getMessage(ScreenSet
, ScreenRestart
, "Restart"),
2193 rootmenu
->insert(i18n
->getMessage(ScreenSet
, ScreenExit
, "Exit"),
2196 openbox
.setMenuFilename(openbox
.getMenuFilename());
2201 Bool
BScreen::parseMenuFile(FILE *file
, Rootmenu
*menu
) {
2202 char line
[1024], label
[1024], command
[1024];
2204 while (! feof(file
)) {
2205 memset(line
, 0, 1024);
2206 memset(label
, 0, 1024);
2207 memset(command
, 0, 1024);
2209 if (fgets(line
, 1024, file
)) {
2210 if (line
[0] != '#') {
2211 register int i
, key
= 0, parse
= 0, index
= -1,
2212 line_length
= strlen(line
),
2213 label_length
= 0, command_length
= 0;
2215 // determine the keyword
2217 for (i
= 0; i
< line_length
; i
++) {
2218 if (line
[i
] == '[') parse
= 1;
2219 else if (line
[i
] == ']') break;
2220 else if (line
[i
] != ' ')
2222 key
+= tolower(line
[i
]);
2225 // get the label enclosed in ()'s
2228 for (i
= 0; i
< line_length
; i
++) {
2229 if (line
[i
] == '(') {
2232 } else if (line
[i
] == ')') break;
2233 else if (index
++ >= 0) {
2234 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
2235 label
[index
- 1] = line
[i
];
2240 label
[index
] = '\0';
2241 label_length
= index
;
2247 // get the command enclosed in {}'s
2250 for (i
= 0; i
< line_length
; i
++) {
2251 if (line
[i
] == '{') {
2254 } else if (line
[i
] == '}') break;
2255 else if (index
++ >= 0) {
2256 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
2257 command
[index
- 1] = line
[i
];
2262 command
[index
] = '\0';
2263 command_length
= index
;
2271 return ((menu
->getCount() == 0) ? True
: False
);
2276 menu
->insert(label
);
2281 if ((! *label
) && (! *command
)) {
2282 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenEXECError
,
2283 "BScreen::parseMenuFile: [exec] error, "
2284 "no menu label and/or command defined\n"));
2288 menu
->insert(label
, BScreen::Execute
, command
);
2294 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenEXITError
,
2295 "BScreen::parseMenuFile: [exit] error, "
2296 "no menu label defined\n"));
2300 menu
->insert(label
, BScreen::Exit
);
2306 if ((! *label
) || (! *command
)) {
2307 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenSTYLEError
,
2308 "BScreen::parseMenuFile: [style] error, "
2309 "no menu label and/or filename defined\n"));
2313 char style
[MAXPATHLEN
];
2315 // perform shell style ~ home directory expansion
2317 int homedir_len
= 0;
2318 if (*command
== '~' && *(command
+ 1) == '/') {
2319 homedir
= getenv("HOME");
2320 homedir_len
= strlen(homedir
);
2323 if (homedir
&& homedir_len
!= 0) {
2324 strncpy(style
, homedir
, homedir_len
);
2326 strncpy(style
+ homedir_len
, command
+ 1,
2327 command_length
- 1);
2328 *(style
+ command_length
+ homedir_len
- 1) = '\0';
2330 strncpy(style
, command
, command_length
);
2331 *(style
+ command_length
) = '\0';
2334 menu
->insert(label
, BScreen::SetStyle
, style
);
2341 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenCONFIGError
,
2342 "BScreen::parseMenufile: [config] error, "
2343 "no label defined"));
2347 menu
->insert(label
, configmenu
);
2351 case 740: // include
2354 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenINCLUDEError
,
2355 "BScreen::parseMenuFile: [include] error, "
2356 "no filename defined\n"));
2360 char newfile
[MAXPATHLEN
];
2362 // perform shell style ~ home directory expansion
2364 int homedir_len
= 0;
2365 if (*label
== '~' && *(label
+ 1) == '/') {
2366 homedir
= getenv("HOME");
2367 homedir_len
= strlen(homedir
);
2370 if (homedir
&& homedir_len
!= 0) {
2371 strncpy(newfile
, homedir
, homedir_len
);
2373 strncpy(newfile
+ homedir_len
, label
+ 1,
2375 *(newfile
+ label_length
+ homedir_len
- 1) = '\0';
2377 strncpy(newfile
, label
, label_length
);
2378 *(newfile
+ label_length
) = '\0';
2382 FILE *submenufile
= fopen(newfile
, "r");
2386 if (fstat(fileno(submenufile
), &buf
) ||
2387 (! S_ISREG(buf
.st_mode
))) {
2389 i18n
->getMessage(ScreenSet
, ScreenINCLUDEErrorReg
,
2390 "BScreen::parseMenuFile: [include] error: "
2391 "'%s' is not a regular file\n"), newfile
);
2395 if (! feof(submenufile
)) {
2396 if (! parseMenuFile(submenufile
, menu
))
2397 openbox
.setMenuFilename(newfile
);
2399 fclose(submenufile
);
2408 case 767: // submenu
2411 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenSUBMENUError
,
2412 "BScreen::parseMenuFile: [submenu] error, "
2413 "no menu label defined\n"));
2417 Rootmenu
*submenu
= new Rootmenu(*this);
2420 submenu
->setLabel(command
);
2422 submenu
->setLabel(label
);
2424 parseMenuFile(file
, submenu
);
2426 menu
->insert(label
, submenu
);
2427 rootmenuList
->insert(submenu
);
2432 case 773: // restart
2435 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenRESTARTError
,
2436 "BScreen::parseMenuFile: [restart] error, "
2437 "no menu label defined\n"));
2442 menu
->insert(label
, BScreen::RestartOther
, command
);
2444 menu
->insert(label
, BScreen::Restart
);
2449 case 845: // reconfig
2452 fprintf(stderr
, i18n
->getMessage(ScreenSet
, ScreenRECONFIGError
,
2453 "BScreen::parseMenuFile: [reconfig] error, "
2454 "no menu label defined\n"));
2458 menu
->insert(label
, BScreen::Reconfigure
);
2463 case 995: // stylesdir
2464 case 1113: // stylesmenu
2466 Bool newmenu
= ((key
== 1113) ? True
: False
);
2468 if ((! *label
) || ((! *command
) && newmenu
)) {
2470 i18n
->getMessage(ScreenSet
, ScreenSTYLESDIRError
,
2471 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
2472 " error, no directory defined\n"));
2476 char stylesdir
[MAXPATHLEN
];
2478 char *directory
= ((newmenu
) ? command
: label
);
2479 int directory_length
= ((newmenu
) ? command_length
: label_length
);
2481 // perform shell style ~ home directory expansion
2483 int homedir_len
= 0;
2485 if (*directory
== '~' && *(directory
+ 1) == '/') {
2486 homedir
= getenv("HOME");
2487 homedir_len
= strlen(homedir
);
2490 if (homedir
&& homedir_len
!= 0) {
2491 strncpy(stylesdir
, homedir
, homedir_len
);
2493 strncpy(stylesdir
+ homedir_len
, directory
+ 1,
2494 directory_length
- 1);
2495 *(stylesdir
+ directory_length
+ homedir_len
- 1) = '\0';
2497 strncpy(stylesdir
, directory
, directory_length
);
2498 *(stylesdir
+ directory_length
) = '\0';
2501 struct stat statbuf
;
2503 if (! stat(stylesdir
, &statbuf
)) {
2504 if (S_ISDIR(statbuf
.st_mode
)) {
2505 Rootmenu
*stylesmenu
;
2508 stylesmenu
= new Rootmenu(*this);
2512 DIR *d
= opendir(stylesdir
);
2516 // get the total number of directory entries
2517 while ((p
= readdir(d
))) entries
++;
2520 char **ls
= new char* [entries
];
2522 while ((p
= readdir(d
)))
2523 ls
[index
++] = bstrdup(p
->d_name
);
2527 std::sort(ls
, ls
+ entries
, dcmp());
2529 int n
, slen
= strlen(stylesdir
);
2530 for (n
= 0; n
< entries
; n
++) {
2531 if (ls
[n
][strlen(ls
[n
])-1] != '~') {
2532 int nlen
= strlen(ls
[n
]);
2533 char style
[MAXPATHLEN
+ 1];
2535 strncpy(style
, stylesdir
, slen
);
2536 *(style
+ slen
) = '/';
2537 strncpy(style
+ slen
+ 1, ls
[n
], nlen
+ 1);
2539 if ((! stat(style
, &statbuf
)) && S_ISREG(statbuf
.st_mode
))
2540 stylesmenu
->insert(ls
[n
], BScreen::SetStyle
, style
);
2548 stylesmenu
->update();
2551 stylesmenu
->setLabel(label
);
2552 menu
->insert(label
, stylesmenu
);
2553 rootmenuList
->insert(stylesmenu
);
2556 openbox
.setMenuFilename(stylesdir
);
2558 fprintf(stderr
, i18n
->getMessage(ScreenSet
,
2559 ScreenSTYLESDIRErrorNotDir
,
2560 "BScreen::parseMenuFile:"
2561 " [stylesdir/stylesmenu] error, %s is not a"
2562 " directory\n"), stylesdir
);
2566 i18n
->getMessage(ScreenSet
, ScreenSTYLESDIRErrorNoExist
,
2567 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
2568 " error, %s does not exist\n"), stylesdir
);
2574 case 1090: // workspaces
2578 i18n
->getMessage(ScreenSet
, ScreenWORKSPACESError
,
2579 "BScreen:parseMenuFile: [workspaces] error, "
2580 "no menu label defined\n"));
2584 menu
->insert(label
, workspacemenu
);
2593 return ((menu
->getCount() == 0) ? True
: False
);
2597 void BScreen::shutdown(void) {
2600 XSelectInput(getBaseDisplay().getXDisplay(), getRootWindow(), NoEventMask
);
2601 XSync(getBaseDisplay().getXDisplay(), False
);
2603 LinkedListIterator
<Workspace
> it(workspacesList
);
2604 for (Workspace
*w
= it
.current(); w
; it
++, w
= it
.current())
2607 while (iconList
->count()) {
2608 iconList
->first()->restore();
2609 delete iconList
->first();
2620 void BScreen::showPosition(int x
, int y
) {
2621 if (! geom_visible
) {
2622 XMoveResizeWindow(getBaseDisplay().getXDisplay(), geom_window
,
2623 (size().w() - geom_w
) / 2,
2624 (size().h() - geom_h
) / 2, geom_w
, geom_h
);
2625 XMapWindow(getBaseDisplay().getXDisplay(), geom_window
);
2626 XRaiseWindow(getBaseDisplay().getXDisplay(), geom_window
);
2628 geom_visible
= True
;
2633 sprintf(label
, i18n
->getMessage(ScreenSet
, ScreenPositionFormat
,
2634 "X: %4d x Y: %4d"), x
, y
);
2636 XClearWindow(getBaseDisplay().getXDisplay(), geom_window
);
2638 if (i18n
->multibyte()) {
2639 XmbDrawString(getBaseDisplay().getXDisplay(), geom_window
,
2640 resource
.wstyle
.fontset
, resource
.wstyle
.l_text_focus_gc
,
2641 resource
.bevel_width
, resource
.bevel_width
-
2642 resource
.wstyle
.fontset_extents
->max_ink_extent
.y
,
2643 label
, strlen(label
));
2645 XDrawString(getBaseDisplay().getXDisplay(), geom_window
,
2646 resource
.wstyle
.l_text_focus_gc
,
2647 resource
.bevel_width
,
2648 resource
.wstyle
.font
->ascent
+
2649 resource
.bevel_width
, label
, strlen(label
));
2654 void BScreen::showGeometry(unsigned int gx
, unsigned int gy
) {
2655 if (! geom_visible
) {
2656 XMoveResizeWindow(getBaseDisplay().getXDisplay(), geom_window
,
2657 (size().w() - geom_w
) / 2,
2658 (size().h() - geom_h
) / 2, geom_w
, geom_h
);
2659 XMapWindow(getBaseDisplay().getXDisplay(), geom_window
);
2660 XRaiseWindow(getBaseDisplay().getXDisplay(), geom_window
);
2662 geom_visible
= True
;
2667 sprintf(label
, i18n
->getMessage(ScreenSet
, ScreenGeometryFormat
,
2668 "W: %4d x H: %4d"), gx
, gy
);
2670 XClearWindow(getBaseDisplay().getXDisplay(), geom_window
);
2672 if (i18n
->multibyte()) {
2673 XmbDrawString(getBaseDisplay().getXDisplay(), geom_window
,
2674 resource
.wstyle
.fontset
, resource
.wstyle
.l_text_focus_gc
,
2675 resource
.bevel_width
, resource
.bevel_width
-
2676 resource
.wstyle
.fontset_extents
->max_ink_extent
.y
,
2677 label
, strlen(label
));
2679 XDrawString(getBaseDisplay().getXDisplay(), geom_window
,
2680 resource
.wstyle
.l_text_focus_gc
,
2681 resource
.bevel_width
,
2682 resource
.wstyle
.font
->ascent
+
2683 resource
.bevel_width
, label
, strlen(label
));
2687 void BScreen::hideGeometry(void) {
2689 XUnmapWindow(getBaseDisplay().getXDisplay(), geom_window
);
2690 geom_visible
= False
;