1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 // Screen.cc for Blackbox - an X11 Window manager
3 // Copyright (c) 2001 - 2002 Sean 'Shaleh' Perry <shaleh@debian.org>
4 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
6 // Permission is hereby granted, free of charge, to any person obtaining a
7 // copy of this software and associated documentation files (the "Software"),
8 // to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 // and/or sell copies of the Software, and to permit persons to whom the
11 // Software is furnished to do so, subject to the following conditions:
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 // DEALINGS IN THE SOFTWARE.
24 #include "../config.h"
27 #include <X11/Xatom.h>
28 #include <X11/keysym.h>
37 #endif // HAVE_STDLIB_H
41 #endif // HAVE_STRING_H
45 #endif // HAVE_CTYPE_H
48 # include <sys/types.h>
50 #endif // HAVE_UNISTD_H
54 #endif // HAVE_DIRENT_H
58 #endif // HAVE_LOCALE_H
60 #ifdef HAVE_SYS_STAT_H
61 # include <sys/stat.h>
62 #endif // HAVE_SYS_STAT_H
66 #endif // HAVE_STDARG_H
77 #include "blackbox.hh"
78 #include "Clientmenu.hh"
80 #include "Iconmenu.hh"
84 #include "Rootmenu.hh"
88 #include "Workspace.hh"
89 #include "Workspacemenu.hh"
92 #ifndef FONT_ELEMENT_SIZE
93 #define FONT_ELEMENT_SIZE 50
94 #endif // FONT_ELEMENT_SIZE
97 static bool running
= True
;
99 static int anotherWMRunning(Display
*display
, XErrorEvent
*) {
100 fprintf(stderr
, i18n(ScreenSet
, ScreenAnotherWMRunning
,
101 "BScreen::BScreen: an error occured while querying the X server.\n"
102 " another window manager already running on display %s.\n"),
103 DisplayString(display
));
111 BScreen::BScreen(Blackbox
*bb
, unsigned int scrn
) : ScreenInfo(bb
, scrn
) {
113 screenstr
= (string
)"session.screen" + itostring(scrn
) + '.';
114 config
= blackbox
->getConfig();
115 xatom
= blackbox
->getXAtom();
117 event_mask
= ColormapChangeMask
| EnterWindowMask
| PropertyChangeMask
|
118 SubstructureRedirectMask
| ButtonPressMask
| ButtonReleaseMask
;
120 XErrorHandler old
= XSetErrorHandler((XErrorHandler
) anotherWMRunning
);
121 XSelectInput(getBaseDisplay()->getXDisplay(), getRootWindow(), event_mask
);
122 XSync(getBaseDisplay()->getXDisplay(), False
);
123 XSetErrorHandler((XErrorHandler
) old
);
126 if (! managed
) return;
128 fprintf(stderr
, i18n(ScreenSet
, ScreenManagingScreen
,
129 "BScreen::BScreen: managing screen %d "
130 "using visual 0x%lx, depth %d\n"),
131 getScreenNumber(), XVisualIDFromVisual(getVisual()),
136 resource
.mstyle
.t_fontset
= resource
.mstyle
.f_fontset
=
137 resource
.tstyle
.fontset
= resource
.wstyle
.fontset
= (XFontSet
) 0;
138 resource
.mstyle
.t_font
= resource
.mstyle
.f_font
= resource
.tstyle
.font
=
139 resource
.wstyle
.font
= (XFontStruct
*) 0;
141 xatom
->setSupported(this); // set-up netwm support
143 xatom
->setValue(getRootWindow(), XAtom::blackbox_pid
, XAtom::cardinal
,
144 (unsigned long) getpid());
145 #endif // HAVE_GETPID
146 unsigned long geometry
[] = { getWidth(),
148 xatom
->setValue(getRootWindow(), XAtom::net_desktop_geometry
,
149 XAtom::cardinal
, geometry
, 2);
150 unsigned long viewport
[] = {0,0};
151 xatom
->setValue(getRootWindow(), XAtom::net_desktop_viewport
,
152 XAtom::cardinal
, viewport
, 2);
155 XDefineCursor(blackbox
->getXDisplay(), getRootWindow(),
156 blackbox
->getSessionCursor());
158 // start off full screen, top left.
159 usableArea
.setSize(getWidth(), getHeight());
162 new BImageControl(blackbox
, this, True
, blackbox
->getColorsPerChannel(),
163 blackbox
->getCacheLife(), blackbox
->getCacheMax());
164 image_control
->installRootColormap();
165 root_colormap_installed
= True
;
171 unsigned long gc_value_mask
= GCForeground
;
172 if (! i18n
.multibyte()) gc_value_mask
|= GCFont
;
174 gcv
.foreground
= WhitePixel(blackbox
->getXDisplay(), getScreenNumber())
175 ^ BlackPixel(blackbox
->getXDisplay(), getScreenNumber());
176 gcv
.function
= GXxor
;
177 gcv
.subwindow_mode
= IncludeInferiors
;
178 opGC
= XCreateGC(blackbox
->getXDisplay(), getRootWindow(),
179 GCForeground
| GCFunction
| GCSubwindowMode
, &gcv
);
181 const char *s
= i18n(ScreenSet
, ScreenPositionLength
,
182 "0: 0000 x 0: 0000");
185 if (i18n
.multibyte()) {
186 XRectangle ink
, logical
;
187 XmbTextExtents(resource
.wstyle
.fontset
, s
, l
, &ink
, &logical
);
188 geom_w
= logical
.width
;
190 geom_h
= resource
.wstyle
.fontset_extents
->max_ink_extent
.height
;
192 geom_h
= resource
.wstyle
.font
->ascent
+
193 resource
.wstyle
.font
->descent
;
195 geom_w
= XTextWidth(resource
.wstyle
.font
, s
, l
);
198 geom_w
+= (resource
.bevel_width
* 2);
199 geom_h
+= (resource
.bevel_width
* 2);
201 XSetWindowAttributes attrib
;
202 unsigned long mask
= CWBorderPixel
| CWColormap
| CWSaveUnder
;
203 attrib
.border_pixel
= getBorderColor()->pixel();
204 attrib
.colormap
= getColormap();
205 attrib
.save_under
= True
;
207 geom_window
= XCreateWindow(blackbox
->getXDisplay(), getRootWindow(),
208 0, 0, geom_w
, geom_h
, resource
.border_width
,
209 getDepth(), InputOutput
, getVisual(),
211 geom_visible
= False
;
213 BTexture
* texture
= &(resource
.wstyle
.l_focus
);
214 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
215 if (geom_pixmap
== ParentRelative
) {
216 texture
= &(resource
.wstyle
.t_focus
);
217 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
220 XSetWindowBackground(blackbox
->getXDisplay(), geom_window
,
221 texture
->color().pixel());
223 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
224 geom_window
, geom_pixmap
);
226 workspacemenu
= new Workspacemenu(this);
227 iconmenu
= new Iconmenu(this);
228 configmenu
= new Configmenu(this);
230 Workspace
*wkspc
= (Workspace
*) 0;
231 if (resource
.workspaces
!= 0) {
232 for (unsigned int i
= 0; i
< resource
.workspaces
; ++i
) {
233 wkspc
= new Workspace(this, workspacesList
.size());
234 workspacesList
.push_back(wkspc
);
235 workspacemenu
->insert(wkspc
->getName(), wkspc
->getMenu());
238 wkspc
= new Workspace(this, workspacesList
.size());
239 workspacesList
.push_back(wkspc
);
240 workspacemenu
->insert(wkspc
->getName(), wkspc
->getMenu());
242 saveWorkspaceNames();
244 updateNetizenWorkspaceCount();
246 workspacemenu
->insert(i18n(IconSet
, IconIcons
, "Icons"), iconmenu
);
247 workspacemenu
->update();
249 current_workspace
= workspacesList
.front();
251 xatom
->setValue(getRootWindow(), XAtom::net_current_desktop
,
252 XAtom::cardinal
, 0); //first workspace
254 workspacemenu
->setItemSelected(2, True
);
256 toolbar
= new Toolbar(this);
258 slit
= new Slit(this);
262 raiseWindows(0, 0); // this also initializes the empty stacking list
265 updateClientList(); // initialize the client list, which will be empty
266 updateAvailableArea();
268 changeWorkspaceID(0);
270 unsigned int i
, j
, nchild
;
271 Window r
, p
, *children
;
272 XQueryTree(blackbox
->getXDisplay(), getRootWindow(), &r
, &p
,
275 // preen the window list of all icon windows... for better dockapp support
276 for (i
= 0; i
< nchild
; i
++) {
277 if (children
[i
] == None
) continue;
279 XWMHints
*wmhints
= XGetWMHints(blackbox
->getXDisplay(),
283 if ((wmhints
->flags
& IconWindowHint
) &&
284 (wmhints
->icon_window
!= children
[i
])) {
285 for (j
= 0; j
< nchild
; j
++) {
286 if (children
[j
] == wmhints
->icon_window
) {
297 // manage shown windows
298 for (i
= 0; i
< nchild
; ++i
) {
299 if (children
[i
] == None
|| (! blackbox
->validateWindow(children
[i
])))
302 XWindowAttributes attrib
;
303 if (XGetWindowAttributes(blackbox
->getXDisplay(), children
[i
], &attrib
)) {
304 if (attrib
.override_redirect
) continue;
306 if (attrib
.map_state
!= IsUnmapped
) {
307 manageWindow(children
[i
]);
314 // call this again just in case a window we found updates the Strut list
315 updateAvailableArea();
319 BScreen::~BScreen(void) {
320 if (! managed
) return;
322 if (geom_pixmap
!= None
)
323 image_control
->removeImage(geom_pixmap
);
325 if (geom_window
!= None
)
326 XDestroyWindow(blackbox
->getXDisplay(), geom_window
);
328 std::for_each(workspacesList
.begin(), workspacesList
.end(),
331 std::for_each(iconList
.begin(), iconList
.end(), PointerAssassin());
333 std::for_each(netizenList
.begin(), netizenList
.end(), PointerAssassin());
336 delete workspacemenu
;
341 delete image_control
;
343 if (resource
.wstyle
.fontset
)
344 XFreeFontSet(blackbox
->getXDisplay(), resource
.wstyle
.fontset
);
345 if (resource
.mstyle
.t_fontset
)
346 XFreeFontSet(blackbox
->getXDisplay(), resource
.mstyle
.t_fontset
);
347 if (resource
.mstyle
.f_fontset
)
348 XFreeFontSet(blackbox
->getXDisplay(), resource
.mstyle
.f_fontset
);
349 if (resource
.tstyle
.fontset
)
350 XFreeFontSet(blackbox
->getXDisplay(), resource
.tstyle
.fontset
);
352 if (resource
.wstyle
.font
)
353 XFreeFont(blackbox
->getXDisplay(), resource
.wstyle
.font
);
354 if (resource
.mstyle
.t_font
)
355 XFreeFont(blackbox
->getXDisplay(), resource
.mstyle
.t_font
);
356 if (resource
.mstyle
.f_font
)
357 XFreeFont(blackbox
->getXDisplay(), resource
.mstyle
.f_font
);
358 if (resource
.tstyle
.font
)
359 XFreeFont(blackbox
->getXDisplay(), resource
.tstyle
.font
);
361 XFreeGC(blackbox
->getXDisplay(), opGC
);
365 void BScreen::saveSloppyFocus(bool s
) {
366 resource
.sloppy_focus
= s
;
369 if (resource
.sloppy_focus
) {
370 fmodel
= "SloppyFocus";
371 if (resource
.auto_raise
) fmodel
+= " AutoRaise";
372 if (resource
.click_raise
) fmodel
+= " ClickRaise";
374 fmodel
= "ClickToFocus";
376 config
->setValue(screenstr
+ "focusModel", fmodel
);
380 void BScreen::saveAutoRaise(bool a
) {
381 resource
.auto_raise
= a
;
382 saveSloppyFocus(resource
.sloppy_focus
);
386 void BScreen::saveClickRaise(bool c
) {
387 resource
.click_raise
= c
;
388 saveSloppyFocus(resource
.sloppy_focus
);
392 void BScreen::saveImageDither(bool d
) {
393 image_control
->setDither(d
);
394 config
->setValue(screenstr
+ "imageDither", doImageDither());
398 void BScreen::saveOpaqueMove(bool o
) {
399 resource
.opaque_move
= o
;
400 config
->setValue(screenstr
+ "opaqueMove", resource
.opaque_move
);
404 void BScreen::saveFullMax(bool f
) {
405 resource
.full_max
= f
;
406 config
->setValue(screenstr
+ "fullMaximization", resource
.full_max
);
410 void BScreen::saveFocusNew(bool f
) {
411 resource
.focus_new
= f
;
412 config
->setValue(screenstr
+ "focusNewWindows", resource
.focus_new
);
416 void BScreen::saveFocusLast(bool f
) {
417 resource
.focus_last
= f
;
418 config
->setValue(screenstr
+ "focusLastWindow", resource
.focus_last
);
422 void BScreen::saveHideToolbar(bool h
) {
423 resource
.hide_toolbar
= h
;
424 if (resource
.hide_toolbar
)
425 toolbar
->unmapToolbar();
427 toolbar
->mapToolbar();
428 config
->setValue(screenstr
+ "hideToolbar", resource
.hide_toolbar
);
432 void BScreen::saveWindowToWindowSnap(bool s
) {
433 resource
.window_to_window_snap
= s
;
434 config
->setValue(screenstr
+ "windowToWindowSnap",
435 resource
.window_to_window_snap
);
439 void BScreen::saveWindowCornerSnap(bool s
) {
440 resource
.window_corner_snap
= s
;
441 config
->setValue(screenstr
+ "windowCornerSnap",
442 resource
.window_corner_snap
);
446 void BScreen::saveWorkspaces(unsigned int w
) {
447 resource
.workspaces
= w
;
448 config
->setValue(screenstr
+ "workspaces", resource
.workspaces
);
452 void BScreen::savePlacementPolicy(int p
) {
453 resource
.placement_policy
= p
;
454 const char *placement
;
455 switch (resource
.placement_policy
) {
456 case CascadePlacement
: placement
= "CascadePlacement"; break;
457 case ColSmartPlacement
: placement
= "ColSmartPlacement"; break;
458 case RowSmartPlacement
: default: placement
= "RowSmartPlacement"; break;
460 config
->setValue(screenstr
+ "windowPlacement", placement
);
464 void BScreen::saveEdgeSnapThreshold(int t
) {
465 resource
.edge_snap_threshold
= t
;
466 config
->setValue(screenstr
+ "edgeSnapThreshold",
467 resource
.edge_snap_threshold
);
471 void BScreen::saveRowPlacementDirection(int d
) {
472 resource
.row_direction
= d
;
473 config
->setValue(screenstr
+ "rowPlacementDirection",
474 resource
.row_direction
== LeftRight
?
475 "LeftToRight" : "RightToLeft");
479 void BScreen::saveColPlacementDirection(int d
) {
480 resource
.col_direction
= d
;
481 config
->setValue(screenstr
+ "colPlacementDirection",
482 resource
.col_direction
== TopBottom
?
483 "TopToBottom" : "BottomToTop");
488 void BScreen::saveStrftimeFormat(const std::string
& format
) {
489 resource
.strftime_format
= format
;
490 config
->setValue(screenstr
+ "strftimeFormat", resource
.strftime_format
);
493 #else // !HAVE_STRFTIME
495 void BScreen::saveDateFormat(int f
) {
496 resource
.date_format
= f
;
497 config
->setValue(screenstr
+ "dateFormat",
498 resource
.date_format
== B_EuropeanDate
?
499 "European" : "American");
503 void BScreen::saveClock24Hour(Bool c
) {
504 resource
.clock24hour
= c
;
505 config
->setValue(screenstr
+ "clockFormat", resource
.clock24hour
? 24 : 12);
507 #endif // HAVE_STRFTIME
510 void BScreen::saveWorkspaceNames() {
511 XAtom::StringVect nameList
;
512 unsigned long numnames
= (unsigned) -1;
516 xatom
->getValue(getRootWindow(), XAtom::net_desktop_names
, XAtom::utf8
,
517 numnames
, nameList
)) {
518 for (unsigned int i
= 0; i
< nameList
.size(); ++i
) {
519 if (i
> 0) names
+= ",";
520 names
+= nameList
[i
];
523 config
->setValue(screenstr
+ "workspaceNames", names
);
527 void BScreen::save_rc(void) {
528 saveSloppyFocus(resource
.sloppy_focus
);
529 saveAutoRaise(resource
.auto_raise
);
530 saveImageDither(doImageDither());
531 saveOpaqueMove(resource
.opaque_move
);
532 saveFullMax(resource
.full_max
);
533 saveFocusNew(resource
.focus_new
);
534 saveFocusLast(resource
.focus_last
);
535 saveHideToolbar(resource
.hide_toolbar
);
536 saveWindowToWindowSnap(resource
.window_to_window_snap
);
537 saveWindowCornerSnap(resource
.window_corner_snap
);
538 saveWorkspaces(resource
.workspaces
);
539 savePlacementPolicy(resource
.placement_policy
);
540 saveEdgeSnapThreshold(resource
.edge_snap_threshold
);
541 saveRowPlacementDirection(resource
.row_direction
);
542 saveColPlacementDirection(resource
.col_direction
);
544 saveStrftimeFormat(resource
.strftime_format
);
545 #else // !HAVE_STRFTIME
546 saveDateFormat(resource
.date_format
);
547 savwClock24Hour(resource
.clock24hour
);
548 #endif // HAVE_STRFTIME
555 void BScreen::load_rc(void) {
559 if (! config
->getValue(screenstr
+ "fullMaximization", resource
.full_max
))
560 resource
.full_max
= false;
562 if (! config
->getValue(screenstr
+ "focusNewWindows", resource
.focus_new
))
563 resource
.focus_new
= false;
565 if (! config
->getValue(screenstr
+ "focusLastWindow", resource
.focus_last
))
566 resource
.focus_last
= false;
568 if (! config
->getValue(screenstr
+ "workspaces", resource
.workspaces
))
569 resource
.workspaces
= 1;
571 if (! config
->getValue(screenstr
+ "opaqueMove", resource
.opaque_move
))
572 resource
.opaque_move
= false;
574 if (! config
->getValue(screenstr
+ "hideToolbar", resource
.hide_toolbar
))
575 resource
.hide_toolbar
= false;
577 if (! config
->getValue(screenstr
+ "windowToWindowSnap",
578 resource
.window_to_window_snap
))
579 resource
.window_to_window_snap
= true;
581 if (! config
->getValue(screenstr
+ "windowCornerSnap",
582 resource
.window_corner_snap
))
583 resource
.window_corner_snap
= true;
585 if (! config
->getValue(screenstr
+ "imageDither", b
))
587 image_control
->setDither(b
);
589 if (! config
->getValue(screenstr
+ "edgeSnapThreshold",
590 resource
.edge_snap_threshold
))
591 resource
.edge_snap_threshold
= 4;
593 if (config
->getValue(screenstr
+ "rowPlacementDirection", s
) &&
595 resource
.row_direction
= RightLeft
;
597 resource
.row_direction
= LeftRight
;
599 if (config
->getValue(screenstr
+ "colPlacementDirection", s
) &&
601 resource
.col_direction
= BottomTop
;
603 resource
.col_direction
= TopBottom
;
605 XAtom::StringVect workspaceNames
;
606 if (config
->getValue(screenstr
+ "workspaceNames", s
)) {
607 string::const_iterator it
= s
.begin(), end
= s
.end();
609 string::const_iterator tmp
= it
; // current string.begin()
610 it
= std::find(tmp
, end
, ','); // look for comma between tmp and end
611 workspaceNames
.push_back(string(tmp
, it
)); // s[tmp:it]
617 xatom
->setValue(getRootWindow(), XAtom::net_desktop_names
, XAtom::utf8
,
620 resource
.sloppy_focus
= true;
621 resource
.auto_raise
= false;
622 resource
.click_raise
= false;
623 if (config
->getValue(screenstr
+ "focusModel", s
)) {
624 if (s
.find("ClickToFocus") != string::npos
) {
625 resource
.sloppy_focus
= false;
628 if (s
.find("AutoRaise") != string::npos
)
629 resource
.auto_raise
= true;
630 if (s
.find("ClickRaise") != string::npos
)
631 resource
.click_raise
= true;
635 if (config
->getValue(screenstr
+ "windowPlacement", s
)) {
636 if (s
== "CascadePlacement")
637 resource
.placement_policy
= CascadePlacement
;
638 else if (s
== "ColSmartPlacement")
639 resource
.placement_policy
= ColSmartPlacement
;
640 else //if (s == "RowSmartPlacement")
641 resource
.placement_policy
= RowSmartPlacement
;
643 resource
.placement_policy
= RowSmartPlacement
;
646 if (config
->getValue(screenstr
+ "strftimeFormat", s
))
647 resource
.strftime_format
= s
;
649 resource
.strftime_format
= "%I:%M %p";
650 #else // !HAVE_STRFTIME
653 if (config
->getValue(screenstr
+ "dateFormat", s
) && s
== "European")
654 resource
.date_format
= B_EuropeanDate
;
656 resource
.date_format
= B_AmericanDate
;
658 if (! config
->getValue(screenstr
+ "clockFormat", l
))
660 resource
.clock24hour
= l
== 24;
661 #endif // HAVE_STRFTIME
665 void BScreen::reconfigure(void) {
672 unsigned long gc_value_mask
= GCForeground
;
673 if (! i18n
.multibyte()) gc_value_mask
|= GCFont
;
675 gcv
.foreground
= WhitePixel(blackbox
->getXDisplay(),
677 gcv
.function
= GXinvert
;
678 gcv
.subwindow_mode
= IncludeInferiors
;
679 XChangeGC(blackbox
->getXDisplay(), opGC
,
680 GCForeground
| GCFunction
| GCSubwindowMode
, &gcv
);
682 const char *s
= i18n(ScreenSet
, ScreenPositionLength
,
683 "0: 0000 x 0: 0000");
686 if (i18n
.multibyte()) {
687 XRectangle ink
, logical
;
688 XmbTextExtents(resource
.wstyle
.fontset
, s
, l
, &ink
, &logical
);
689 geom_w
= logical
.width
;
691 geom_h
= resource
.wstyle
.fontset_extents
->max_ink_extent
.height
;
693 geom_w
= XTextWidth(resource
.wstyle
.font
, s
, l
);
695 geom_h
= resource
.wstyle
.font
->ascent
+ resource
.wstyle
.font
->descent
;
698 geom_w
+= (resource
.bevel_width
* 2);
699 geom_h
+= (resource
.bevel_width
* 2);
701 BTexture
* texture
= &(resource
.wstyle
.l_focus
);
702 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
703 if (geom_pixmap
== ParentRelative
) {
704 texture
= &(resource
.wstyle
.t_focus
);
705 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
708 XSetWindowBackground(blackbox
->getXDisplay(), geom_window
,
709 texture
->color().pixel());
711 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
712 geom_window
, geom_pixmap
);
714 XSetWindowBorderWidth(blackbox
->getXDisplay(), geom_window
,
715 resource
.border_width
);
716 XSetWindowBorder(blackbox
->getXDisplay(), geom_window
,
717 resource
.border_color
.pixel());
719 workspacemenu
->reconfigure();
720 iconmenu
->reconfigure();
722 typedef std::vector
<int> SubList
;
723 SubList remember_subs
;
725 // save the current open menus
726 Basemenu
*menu
= rootmenu
;
728 while ((submenu
= menu
->getCurrentSubmenu()) >= 0) {
729 remember_subs
.push_back(submenu
);
730 menu
= menu
->find(submenu
)->submenu();
736 rootmenu
->reconfigure();
738 // reopen the saved menus
740 const SubList::iterator subs_end
= remember_subs
.end();
741 for (SubList::iterator it
= remember_subs
.begin(); it
!= subs_end
; ++it
) {
742 menu
->drawSubmenu(*it
);
743 menu
= menu
->find(*it
)->submenu();
748 configmenu
->reconfigure();
750 toolbar
->reconfigure();
754 std::for_each(workspacesList
.begin(), workspacesList
.end(),
755 std::mem_fun(&Workspace::reconfigure
));
757 BlackboxWindowList::iterator iit
= iconList
.begin();
758 for (; iit
!= iconList
.end(); ++iit
) {
759 BlackboxWindow
*bw
= *iit
;
760 if (bw
->validateClient())
764 image_control
->timeout();
768 void BScreen::rereadMenu(void) {
772 rootmenu
->reconfigure();
776 void BScreen::LoadStyle(void) {
779 const char *sfile
= blackbox
->getStyleFilename();
781 style
.setFile(sfile
);
782 if (! style
.load()) {
783 style
.setFile(DEFAULTSTYLE
);
785 style
.create(); // hardcoded default values will be used.
791 // load fonts/fontsets
792 if (resource
.wstyle
.fontset
)
793 XFreeFontSet(blackbox
->getXDisplay(), resource
.wstyle
.fontset
);
794 if (resource
.tstyle
.fontset
)
795 XFreeFontSet(blackbox
->getXDisplay(), resource
.tstyle
.fontset
);
796 if (resource
.mstyle
.f_fontset
)
797 XFreeFontSet(blackbox
->getXDisplay(), resource
.mstyle
.f_fontset
);
798 if (resource
.mstyle
.t_fontset
)
799 XFreeFontSet(blackbox
->getXDisplay(), resource
.mstyle
.t_fontset
);
800 resource
.wstyle
.fontset
= 0;
801 resource
.tstyle
.fontset
= 0;
802 resource
.mstyle
.f_fontset
= 0;
803 resource
.mstyle
.t_fontset
= 0;
804 if (resource
.wstyle
.font
)
805 XFreeFont(blackbox
->getXDisplay(), resource
.wstyle
.font
);
806 if (resource
.tstyle
.font
)
807 XFreeFont(blackbox
->getXDisplay(), resource
.tstyle
.font
);
808 if (resource
.mstyle
.f_font
)
809 XFreeFont(blackbox
->getXDisplay(), resource
.mstyle
.f_font
);
810 if (resource
.mstyle
.t_font
)
811 XFreeFont(blackbox
->getXDisplay(), resource
.mstyle
.t_font
);
812 resource
.wstyle
.font
= 0;
813 resource
.tstyle
.font
= 0;
814 resource
.mstyle
.f_font
= 0;
815 resource
.mstyle
.t_font
= 0;
817 if (i18n
.multibyte()) {
818 resource
.wstyle
.fontset
= readDatabaseFontSet("window.font", style
);
819 resource
.tstyle
.fontset
= readDatabaseFontSet("toolbar.font", style
);
820 resource
.mstyle
.t_fontset
= readDatabaseFontSet("menu.title.font", style
);
821 resource
.mstyle
.f_fontset
= readDatabaseFontSet("menu.frame.font", style
);
823 resource
.mstyle
.t_fontset_extents
=
824 XExtentsOfFontSet(resource
.mstyle
.t_fontset
);
825 resource
.mstyle
.f_fontset_extents
=
826 XExtentsOfFontSet(resource
.mstyle
.f_fontset
);
827 resource
.tstyle
.fontset_extents
=
828 XExtentsOfFontSet(resource
.tstyle
.fontset
);
829 resource
.wstyle
.fontset_extents
=
830 XExtentsOfFontSet(resource
.wstyle
.fontset
);
832 resource
.wstyle
.font
= readDatabaseFont("window.font", style
);
833 resource
.tstyle
.font
= readDatabaseFont("toolbar.font", style
);
834 resource
.mstyle
.t_font
= readDatabaseFont("menu.title.font", style
);
835 resource
.mstyle
.f_font
= readDatabaseFont("menu.frame.font", style
);
838 // load window config
839 resource
.wstyle
.t_focus
=
840 readDatabaseTexture("window.title.focus", "white", style
);
841 resource
.wstyle
.t_unfocus
=
842 readDatabaseTexture("window.title.unfocus", "black", style
);
843 resource
.wstyle
.l_focus
=
844 readDatabaseTexture("window.label.focus", "white", style
);
845 resource
.wstyle
.l_unfocus
=
846 readDatabaseTexture("window.label.unfocus", "black", style
);
847 resource
.wstyle
.h_focus
=
848 readDatabaseTexture("window.handle.focus", "white", style
);
849 resource
.wstyle
.h_unfocus
=
850 readDatabaseTexture("window.handle.unfocus", "black", style
);
851 resource
.wstyle
.g_focus
=
852 readDatabaseTexture("window.grip.focus", "white", style
);
853 resource
.wstyle
.g_unfocus
=
854 readDatabaseTexture("window.grip.unfocus", "black", style
);
855 resource
.wstyle
.b_focus
=
856 readDatabaseTexture("window.button.focus", "white", style
);
857 resource
.wstyle
.b_unfocus
=
858 readDatabaseTexture("window.button.unfocus", "black", style
);
859 resource
.wstyle
.b_pressed
=
860 readDatabaseTexture("window.button.pressed", "black", style
);
861 resource
.wstyle
.f_focus
=
862 readDatabaseColor("window.frame.focusColor", "white", style
);
863 resource
.wstyle
.f_unfocus
=
864 readDatabaseColor("window.frame.unfocusColor", "black", style
);
865 resource
.wstyle
.l_text_focus
=
866 readDatabaseColor("window.label.focus.textColor", "black", style
);
867 resource
.wstyle
.l_text_unfocus
=
868 readDatabaseColor("window.label.unfocus.textColor", "white", style
);
869 resource
.wstyle
.b_pic_focus
=
870 readDatabaseColor("window.button.focus.picColor", "black", style
);
871 resource
.wstyle
.b_pic_unfocus
=
872 readDatabaseColor("window.button.unfocus.picColor", "white", style
);
874 resource
.wstyle
.justify
= LeftJustify
;
875 if (style
.getValue("window.justify", s
)) {
876 if (s
== "right" || s
== "Right")
877 resource
.wstyle
.justify
= RightJustify
;
878 else if (s
== "center" || s
== "Center")
879 resource
.wstyle
.justify
= CenterJustify
;
882 // load toolbar config
883 resource
.tstyle
.toolbar
=
884 readDatabaseTexture("toolbar", "black", style
);
885 resource
.tstyle
.label
=
886 readDatabaseTexture("toolbar.label", "black", style
);
887 resource
.tstyle
.window
=
888 readDatabaseTexture("toolbar.windowLabel", "black", style
);
889 resource
.tstyle
.button
=
890 readDatabaseTexture("toolbar.button", "white", style
);
891 resource
.tstyle
.pressed
=
892 readDatabaseTexture("toolbar.button.pressed", "black", style
);
893 resource
.tstyle
.clock
=
894 readDatabaseTexture("toolbar.clock", "black", style
);
895 resource
.tstyle
.l_text
=
896 readDatabaseColor("toolbar.label.textColor", "white", style
);
897 resource
.tstyle
.w_text
=
898 readDatabaseColor("toolbar.windowLabel.textColor", "white", style
);
899 resource
.tstyle
.c_text
=
900 readDatabaseColor("toolbar.clock.textColor", "white", style
);
901 resource
.tstyle
.b_pic
=
902 readDatabaseColor("toolbar.button.picColor", "black", style
);
904 resource
.tstyle
.justify
= LeftJustify
;
905 if (style
.getValue("toolbar.justify", s
)) {
906 if (s
== "right" || s
== "Right")
907 resource
.tstyle
.justify
= RightJustify
;
908 else if (s
== "center" || s
== "Center")
909 resource
.tstyle
.justify
= CenterJustify
;
913 resource
.mstyle
.title
=
914 readDatabaseTexture("menu.title", "white", style
);
915 resource
.mstyle
.frame
=
916 readDatabaseTexture("menu.frame", "black", style
);
917 resource
.mstyle
.hilite
=
918 readDatabaseTexture("menu.hilite", "white", style
);
919 resource
.mstyle
.t_text
=
920 readDatabaseColor("menu.title.textColor", "black", style
);
921 resource
.mstyle
.f_text
=
922 readDatabaseColor("menu.frame.textColor", "white", style
);
923 resource
.mstyle
.d_text
=
924 readDatabaseColor("menu.frame.disableColor", "black", style
);
925 resource
.mstyle
.h_text
=
926 readDatabaseColor("menu.hilite.textColor", "black", style
);
928 resource
.mstyle
.t_justify
= LeftJustify
;
929 if (style
.getValue("menu.title.justify", s
)) {
930 if (s
== "right" || s
== "Right")
931 resource
.mstyle
.t_justify
= RightJustify
;
932 else if (s
== "center" || s
== "Center")
933 resource
.mstyle
.t_justify
= CenterJustify
;
936 resource
.mstyle
.f_justify
= LeftJustify
;
937 if (style
.getValue("menu.frame.justify", s
)) {
938 if (s
== "right" || s
== "Right")
939 resource
.mstyle
.f_justify
= RightJustify
;
940 else if (s
== "center" || s
== "Center")
941 resource
.mstyle
.f_justify
= CenterJustify
;
944 resource
.mstyle
.bullet
= Basemenu::Triangle
;
945 if (style
.getValue("menu.bullet", s
)) {
946 if (s
== "empty" || s
== "Empty")
947 resource
.mstyle
.bullet
= Basemenu::Empty
;
948 else if (s
== "square" || s
== "Square")
949 resource
.mstyle
.bullet
= Basemenu::Square
;
950 else if (s
== "diamond" || s
== "Diamond")
951 resource
.mstyle
.bullet
= Basemenu::Diamond
;
954 resource
.mstyle
.bullet_pos
= Basemenu::Left
;
955 if (style
.getValue("menu.bullet.position", s
)) {
956 if (s
== "right" || s
== "Right")
957 resource
.mstyle
.bullet_pos
= Basemenu::Right
;
960 resource
.border_color
=
961 readDatabaseColor("borderColor", "black", style
);
963 // load bevel, border and handle widths
964 if (! style
.getValue("handleWidth", resource
.handle_width
) ||
965 resource
.handle_width
> (getWidth() / 2) || resource
.handle_width
== 0)
966 resource
.handle_width
= 6;
968 if (! style
.getValue("borderWidth", resource
.border_width
))
969 resource
.border_width
= 1;
971 if (! style
.getValue("bevelWidth", resource
.bevel_width
) ||
972 resource
.bevel_width
> (getWidth() / 2) || resource
.bevel_width
== 0)
973 resource
.bevel_width
= 3;
975 if (! style
.getValue("frameWidth", resource
.frame_width
) ||
976 resource
.frame_width
> (getWidth() / 2))
977 resource
.frame_width
= resource
.bevel_width
;
979 if (style
.getValue("rootCommand", s
))
980 bexec(s
, displayString());
984 void BScreen::addIcon(BlackboxWindow
*w
) {
987 w
->setWorkspace(BSENTINEL
);
988 w
->setWindowNumber(iconList
.size());
990 iconList
.push_back(w
);
992 const char* title
= w
->getIconTitle();
993 iconmenu
->insert(title
);
998 void BScreen::removeIcon(BlackboxWindow
*w
) {
1003 iconmenu
->remove(w
->getWindowNumber());
1006 BlackboxWindowList::iterator it
= iconList
.begin(),
1007 end
= iconList
.end();
1008 for (int i
= 0; it
!= end
; ++it
)
1009 (*it
)->setWindowNumber(i
++);
1013 BlackboxWindow
*BScreen::getIcon(unsigned int index
) {
1014 if (index
< iconList
.size()) {
1015 BlackboxWindowList::iterator it
= iconList
.begin();
1016 for (; index
> 0; --index
, ++it
) ; /* increment to index */
1020 return (BlackboxWindow
*) 0;
1024 unsigned int BScreen::addWorkspace(void) {
1025 Workspace
*wkspc
= new Workspace(this, workspacesList
.size());
1026 workspacesList
.push_back(wkspc
);
1027 saveWorkspaces(getWorkspaceCount());
1029 workspacemenu
->insert(wkspc
->getName(), wkspc
->getMenu(),
1030 wkspc
->getID() + 2);
1031 workspacemenu
->update();
1033 toolbar
->reconfigure();
1035 updateNetizenWorkspaceCount();
1037 return workspacesList
.size();
1041 unsigned int BScreen::removeLastWorkspace(void) {
1042 if (workspacesList
.size() == 1)
1045 Workspace
*wkspc
= workspacesList
.back();
1047 if (current_workspace
->getID() == wkspc
->getID())
1048 changeWorkspaceID(current_workspace
->getID() - 1);
1052 workspacemenu
->remove(wkspc
->getID() + 2);
1053 workspacemenu
->update();
1055 workspacesList
.pop_back();
1058 saveWorkspaces(getWorkspaceCount());
1060 toolbar
->reconfigure();
1062 updateNetizenWorkspaceCount();
1064 return workspacesList
.size();
1068 void BScreen::changeWorkspaceID(unsigned int id
) {
1069 if (! current_workspace
) return;
1071 if (id
!= current_workspace
->getID()) {
1072 BlackboxWindow
*focused
= blackbox
->getFocusedWindow();
1073 if (focused
&& focused
->getScreen() == this && ! focused
->isStuck()) {
1074 if (focused
->getWorkspaceNumber() != current_workspace
->getID()) {
1075 fprintf(stderr
, "%s is on the wrong workspace, aborting\n",
1076 focused
->getTitle());
1079 current_workspace
->setLastFocusedWindow(focused
);
1081 // if no window had focus, no need to store a last focus
1082 current_workspace
->setLastFocusedWindow((BlackboxWindow
*) 0);
1084 // when we switch workspaces, unfocus whatever was focused
1085 blackbox
->setFocusedWindow((BlackboxWindow
*) 0);
1087 current_workspace
->hideAll();
1088 workspacemenu
->setItemSelected(current_workspace
->getID() + 2, False
);
1090 current_workspace
= getWorkspace(id
);
1092 xatom
->setValue(getRootWindow(), XAtom::net_current_desktop
,
1093 XAtom::cardinal
, id
);
1095 workspacemenu
->setItemSelected(current_workspace
->getID() + 2, True
);
1096 toolbar
->redrawWorkspaceLabel(True
);
1098 current_workspace
->showAll();
1100 if (resource
.focus_last
&& current_workspace
->getLastFocusedWindow()) {
1101 XSync(blackbox
->getXDisplay(), False
);
1102 current_workspace
->getLastFocusedWindow()->setInputFocus();
1106 updateNetizenCurrentWorkspace();
1111 * Set the _NET_CLIENT_LIST root window property.
1113 void BScreen::updateClientList(void) {
1114 if (windowList
.size() > 0) {
1115 Window
*windows
= new Window
[windowList
.size()];
1116 Window
*win_it
= windows
;
1117 BlackboxWindowList::iterator it
= windowList
.begin();
1118 const BlackboxWindowList::iterator end
= windowList
.end();
1119 for (; it
!= end
; ++it
, ++win_it
)
1120 *win_it
= (*it
)->getClientWindow();
1121 xatom
->setValue(getRootWindow(), XAtom::net_client_list
, XAtom::window
,
1122 windows
, windowList
.size());
1125 xatom
->setValue(getRootWindow(), XAtom::net_client_list
, XAtom::window
,
1131 * Set the _NET_CLIENT_LIST_STACKING root window property.
1133 void BScreen::updateStackingList(void) {
1135 BlackboxWindowList stack_order
;
1138 * Get the atacking order from all of the workspaces.
1139 * We start with the current workspace so that the sticky windows will be
1140 * in the right order on the current workspace.
1141 * XXX: Do we need to have sticky windows in the list once for each workspace?
1143 getCurrentWorkspace()->appendStackOrder(stack_order
);
1144 for (unsigned int i
= 0; i
< getWorkspaceCount(); ++i
)
1145 if (i
!= getCurrentWorkspaceID())
1146 getWorkspace(i
)->appendStackOrder(stack_order
);
1148 if (stack_order
.size() > 0) {
1149 // set the client list atoms
1150 Window
*windows
= new Window
[stack_order
.size()];
1151 Window
*win_it
= windows
;
1152 BlackboxWindowList::iterator it
= stack_order
.begin();
1153 const BlackboxWindowList::iterator end
= stack_order
.end();
1154 for (; it
!= end
; ++it
, ++win_it
)
1155 *win_it
= (*it
)->getClientWindow();
1156 xatom
->setValue(getRootWindow(), XAtom::net_client_list_stacking
,
1157 XAtom::window
, windows
, stack_order
.size());
1160 xatom
->setValue(getRootWindow(), XAtom::net_client_list_stacking
,
1161 XAtom::window
, 0, 0);
1165 void BScreen::addSystrayWindow(Window window
) {
1166 systrayWindowList
.push_back(window
);
1167 xatom
->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows
,
1169 &systrayWindowList
[0], systrayWindowList
.size());
1170 blackbox
->saveSystrayWindowSearch(window
, this);
1174 void BScreen::removeSystrayWindow(Window window
) {
1175 WindowList::iterator it
= systrayWindowList
.begin();
1176 const WindowList::iterator end
= systrayWindowList
.end();
1177 for (; it
!= end
; ++it
)
1178 if (*it
== window
) {
1179 systrayWindowList
.erase(it
);
1180 xatom
->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows
,
1182 &systrayWindowList
[0], systrayWindowList
.size());
1183 blackbox
->removeSystrayWindowSearch(window
);
1189 void BScreen::addDesktopWindow(Window window
) {
1190 desktopWindowList
.push_back(window
);
1191 XLowerWindow(blackbox
->getXDisplay(), window
);
1192 XSelectInput(blackbox
->getXDisplay(), window
, StructureNotifyMask
);
1193 blackbox
->saveDesktopWindowSearch(window
, this);
1197 void BScreen::removeDesktopWindow(Window window
) {
1198 WindowList::iterator it
= desktopWindowList
.begin();
1199 const WindowList::iterator end
= desktopWindowList
.end();
1200 for (; it
!= end
; ++it
)
1201 if (*it
== window
) {
1202 desktopWindowList
.erase(it
);
1203 XSelectInput(blackbox
->getXDisplay(), window
, None
);
1204 blackbox
->removeDesktopWindowSearch(window
);
1210 void BScreen::manageWindow(Window w
) {
1211 new BlackboxWindow(blackbox
, w
, this);
1213 BlackboxWindow
*win
= blackbox
->searchWindow(w
);
1216 if (win
->isDesktop()) {
1217 // desktop windows cant do anything, so we remove all the normal window
1218 // stuff from them, they are only kept around so that we can keep them on
1219 // the bottom of the z-order
1221 addDesktopWindow(win
->getClientWindow());
1226 windowList
.push_back(win
);
1229 XMapRequestEvent mre
;
1231 if (blackbox
->isStartup()) win
->restoreAttributes();
1232 win
->mapRequestEvent(&mre
);
1236 void BScreen::unmanageWindow(BlackboxWindow
*w
, bool remap
) {
1239 if (w
->getWorkspaceNumber() != BSENTINEL
&&
1240 w
->getWindowNumber() != BSENTINEL
)
1241 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
1242 else if (w
->isIconic())
1245 windowList
.remove(w
);
1248 if (blackbox
->getFocusedWindow() == w
)
1249 blackbox
->setFocusedWindow((BlackboxWindow
*) 0);
1251 removeNetizen(w
->getClientWindow());
1254 some managed windows can also be window group controllers. when
1255 unmanaging such windows, we should also delete the window group.
1257 BWindowGroup
*group
= blackbox
->searchGroup(w
->getClientWindow());
1264 void BScreen::addNetizen(Netizen
*n
) {
1265 netizenList
.push_back(n
);
1267 n
->sendWorkspaceCount();
1268 n
->sendCurrentWorkspace();
1270 WorkspaceList::iterator it
= workspacesList
.begin();
1271 const WorkspaceList::iterator end
= workspacesList
.end();
1272 for (; it
!= end
; ++it
)
1273 (*it
)->sendWindowList(*n
);
1275 Window f
= ((blackbox
->getFocusedWindow()) ?
1276 blackbox
->getFocusedWindow()->getClientWindow() : None
);
1277 n
->sendWindowFocus(f
);
1281 void BScreen::removeNetizen(Window w
) {
1282 NetizenList::iterator it
= netizenList
.begin();
1283 for (; it
!= netizenList
.end(); ++it
) {
1284 if ((*it
)->getWindowID() == w
) {
1286 netizenList
.erase(it
);
1293 void BScreen::updateWorkArea(void) {
1294 if (workspacesList
.size() > 0) {
1295 unsigned long *dims
= new unsigned long[4 * workspacesList
.size()];
1296 for (unsigned int i
= 0, m
= workspacesList
.size(); i
< m
; ++i
) {
1297 // XXX: this could be different for each workspace
1298 const Rect
&area
= availableArea();
1299 dims
[(i
* 4) + 0] = area
.x();
1300 dims
[(i
* 4) + 1] = area
.y();
1301 dims
[(i
* 4) + 2] = area
.width();
1302 dims
[(i
* 4) + 3] = area
.height();
1304 xatom
->setValue(getRootWindow(), XAtom::net_workarea
, XAtom::cardinal
,
1305 dims
, 4 * workspacesList
.size());
1307 xatom
->setValue(getRootWindow(), XAtom::net_workarea
, XAtom::cardinal
,
1312 void BScreen::updateNetizenCurrentWorkspace(void) {
1313 std::for_each(netizenList
.begin(), netizenList
.end(),
1314 std::mem_fun(&Netizen::sendCurrentWorkspace
));
1318 void BScreen::updateNetizenWorkspaceCount(void) {
1319 xatom
->setValue(getRootWindow(), XAtom::net_number_of_desktops
,
1320 XAtom::cardinal
, workspacesList
.size());
1324 std::for_each(netizenList
.begin(), netizenList
.end(),
1325 std::mem_fun(&Netizen::sendWorkspaceCount
));
1329 void BScreen::updateNetizenWindowFocus(void) {
1330 Window f
= ((blackbox
->getFocusedWindow()) ?
1331 blackbox
->getFocusedWindow()->getClientWindow() : None
);
1333 xatom
->setValue(getRootWindow(), XAtom::net_active_window
,
1336 NetizenList::iterator it
= netizenList
.begin();
1337 for (; it
!= netizenList
.end(); ++it
)
1338 (*it
)->sendWindowFocus(f
);
1342 void BScreen::updateNetizenWindowAdd(Window w
, unsigned long p
) {
1343 NetizenList::iterator it
= netizenList
.begin();
1344 for (; it
!= netizenList
.end(); ++it
) {
1345 (*it
)->sendWindowAdd(w
, p
);
1350 void BScreen::updateNetizenWindowDel(Window w
) {
1351 NetizenList::iterator it
= netizenList
.begin();
1352 for (; it
!= netizenList
.end(); ++it
)
1353 (*it
)->sendWindowDel(w
);
1357 void BScreen::updateNetizenWindowRaise(Window w
) {
1358 NetizenList::iterator it
= netizenList
.begin();
1359 for (; it
!= netizenList
.end(); ++it
)
1360 (*it
)->sendWindowRaise(w
);
1364 void BScreen::updateNetizenWindowLower(Window w
) {
1365 NetizenList::iterator it
= netizenList
.begin();
1366 for (; it
!= netizenList
.end(); ++it
)
1367 (*it
)->sendWindowLower(w
);
1371 void BScreen::updateNetizenConfigNotify(XEvent
*e
) {
1372 NetizenList::iterator it
= netizenList
.begin();
1373 for (; it
!= netizenList
.end(); ++it
)
1374 (*it
)->sendConfigNotify(e
);
1378 void BScreen::raiseWindows(Window
*workspace_stack
, unsigned int num
) {
1379 // the 13 represents the number of blackbox windows such as menus
1380 Window
*session_stack
= new
1381 Window
[(num
+ workspacesList
.size() + rootmenuList
.size() + 13)];
1382 unsigned int i
= 0, k
= num
;
1384 XRaiseWindow(blackbox
->getXDisplay(), iconmenu
->getWindowID());
1385 *(session_stack
+ i
++) = iconmenu
->getWindowID();
1387 WorkspaceList::iterator wit
= workspacesList
.begin();
1388 const WorkspaceList::iterator w_end
= workspacesList
.end();
1389 for (; wit
!= w_end
; ++wit
)
1390 *(session_stack
+ i
++) = (*wit
)->getMenu()->getWindowID();
1392 *(session_stack
+ i
++) = workspacemenu
->getWindowID();
1394 *(session_stack
+ i
++) = configmenu
->getFocusmenu()->getWindowID();
1395 *(session_stack
+ i
++) = configmenu
->getPlacementmenu()->getWindowID();
1396 *(session_stack
+ i
++) = configmenu
->getWindowID();
1398 *(session_stack
+ i
++) = slit
->getMenu()->getDirectionmenu()->getWindowID();
1399 *(session_stack
+ i
++) = slit
->getMenu()->getPlacementmenu()->getWindowID();
1400 *(session_stack
+ i
++) = slit
->getMenu()->getWindowID();
1402 *(session_stack
+ i
++) =
1403 toolbar
->getMenu()->getPlacementmenu()->getWindowID();
1404 *(session_stack
+ i
++) = toolbar
->getMenu()->getWindowID();
1406 RootmenuList::iterator rit
= rootmenuList
.begin();
1407 for (; rit
!= rootmenuList
.end(); ++rit
)
1408 *(session_stack
+ i
++) = (*rit
)->getWindowID();
1409 *(session_stack
+ i
++) = rootmenu
->getWindowID();
1411 if (toolbar
->isOnTop())
1412 *(session_stack
+ i
++) = toolbar
->getWindowID();
1414 if (slit
->isOnTop())
1415 *(session_stack
+ i
++) = slit
->getWindowID();
1418 *(session_stack
+ i
++) = *(workspace_stack
+ k
);
1420 XRestackWindows(blackbox
->getXDisplay(), session_stack
, i
);
1422 delete [] session_stack
;
1424 updateStackingList();
1428 void BScreen::lowerDesktops(void) {
1429 if (desktopWindowList
.empty()) return;
1431 XLowerWindow(blackbox
->getXDisplay(), desktopWindowList
[0]);
1432 if (desktopWindowList
.size() > 1)
1433 XRestackWindows(blackbox
->getXDisplay(), &desktopWindowList
[0],
1434 desktopWindowList
.size());
1438 void BScreen::reassociateWindow(BlackboxWindow
*w
, unsigned int wkspc_id
,
1439 bool ignore_sticky
) {
1442 if (wkspc_id
== BSENTINEL
)
1443 wkspc_id
= current_workspace
->getID();
1445 if (w
->getWorkspaceNumber() == wkspc_id
)
1448 if (w
->isIconic()) {
1450 getWorkspace(wkspc_id
)->addWindow(w
);
1451 } else if (ignore_sticky
|| ! w
->isStuck()) {
1452 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
1453 getWorkspace(wkspc_id
)->addWindow(w
);
1458 void BScreen::propagateWindowName(const BlackboxWindow
*bw
) {
1459 if (bw
->isIconic()) {
1460 iconmenu
->changeItemLabel(bw
->getWindowNumber(), bw
->getIconTitle());
1464 Clientmenu
*clientmenu
= getWorkspace(bw
->getWorkspaceNumber())->getMenu();
1465 clientmenu
->changeItemLabel(bw
->getWindowNumber(), bw
->getTitle());
1466 clientmenu
->update();
1468 if (blackbox
->getFocusedWindow() == bw
)
1469 toolbar
->redrawWindowLabel(True
);
1474 void BScreen::nextFocus(void) {
1475 BlackboxWindow
*focused
= blackbox
->getFocusedWindow(),
1479 // if window is not on this screen, ignore it
1480 if (focused
->getScreen()->getScreenNumber() != getScreenNumber())
1481 focused
= (BlackboxWindow
*) 0;
1484 if (focused
&& current_workspace
->getCount() > 1) {
1485 // next is the next window to recieve focus, current is a place holder
1486 BlackboxWindow
*current
;
1489 next
= current_workspace
->getNextWindowInList(current
);
1490 } while(! next
->setInputFocus() && next
!= focused
);
1492 if (next
!= focused
)
1493 current_workspace
->raiseWindow(next
);
1494 } else if (current_workspace
->getCount() >= 1) {
1495 next
= current_workspace
->getTopWindowOnStack();
1497 current_workspace
->raiseWindow(next
);
1498 next
->setInputFocus();
1503 void BScreen::prevFocus(void) {
1504 BlackboxWindow
*focused
= blackbox
->getFocusedWindow(),
1508 // if window is not on this screen, ignore it
1509 if (focused
->getScreen()->getScreenNumber() != getScreenNumber())
1510 focused
= (BlackboxWindow
*) 0;
1513 if (focused
&& current_workspace
->getCount() > 1) {
1514 // next is the next window to recieve focus, current is a place holder
1515 BlackboxWindow
*current
;
1518 next
= current_workspace
->getPrevWindowInList(current
);
1519 } while(! next
->setInputFocus() && next
!= focused
);
1521 if (next
!= focused
)
1522 current_workspace
->raiseWindow(next
);
1523 } else if (current_workspace
->getCount() >= 1) {
1524 next
= current_workspace
->getTopWindowOnStack();
1526 current_workspace
->raiseWindow(next
);
1527 next
->setInputFocus();
1532 void BScreen::raiseFocus(void) {
1533 BlackboxWindow
*focused
= blackbox
->getFocusedWindow();
1537 // if on this Screen, raise it
1538 if (focused
->getScreen()->getScreenNumber() == getScreenNumber()) {
1539 Workspace
*workspace
= getWorkspace(focused
->getWorkspaceNumber());
1540 workspace
->raiseWindow(focused
);
1545 void BScreen::InitMenu(void) {
1547 rootmenuList
.clear();
1549 while (rootmenu
->getCount())
1550 rootmenu
->remove(0);
1552 rootmenu
= new Rootmenu(this);
1554 bool defaultMenu
= True
;
1556 FILE *menu_file
= (FILE *) 0;
1557 const char *menu_filename
= blackbox
->getMenuFilename();
1560 if (! (menu_file
= fopen(menu_filename
, "r")))
1561 perror(menu_filename
);
1562 if (! menu_file
) { // opening the menu file failed, try the default menu
1563 menu_filename
= DEFAULTMENU
;
1564 if (! (menu_file
= fopen(menu_filename
, "r")))
1565 perror(menu_filename
);
1569 if (feof(menu_file
)) {
1570 fprintf(stderr
, i18n(ScreenSet
, ScreenEmptyMenuFile
,
1571 "%s: Empty menu file"),
1574 char line
[1024], label
[1024];
1575 memset(line
, 0, 1024);
1576 memset(label
, 0, 1024);
1578 while (fgets(line
, 1024, menu_file
) && ! feof(menu_file
)) {
1579 if (line
[0] != '#') {
1580 int i
, key
= 0, index
= -1, len
= strlen(line
);
1582 for (i
= 0; i
< len
; i
++) {
1583 if (line
[i
] == '[') index
= 0;
1584 else if (line
[i
] == ']') break;
1585 else if (line
[i
] != ' ')
1587 key
+= tolower(line
[i
]);
1590 if (key
== 517) { // [begin]
1592 for (i
= index
; i
< len
; i
++) {
1593 if (line
[i
] == '(') index
= 0;
1594 else if (line
[i
] == ')') break;
1595 else if (index
++ >= 0) {
1596 if (line
[i
] == '\\' && i
< len
- 1) i
++;
1597 label
[index
- 1] = line
[i
];
1601 if (index
== -1) index
= 0;
1602 label
[index
] = '\0';
1604 rootmenu
->setLabel(label
);
1605 defaultMenu
= parseMenuFile(menu_file
, rootmenu
);
1607 blackbox
->addMenuTimestamp(menu_filename
);
1617 rootmenu
->setInternalMenu();
1618 rootmenu
->insert(i18n(ScreenSet
, Screenxterm
, "xterm"),
1620 i18n(ScreenSet
, Screenxterm
, "xterm"));
1621 rootmenu
->insert(i18n(ScreenSet
, ScreenRestart
, "Restart"),
1623 rootmenu
->insert(i18n(ScreenSet
, ScreenExit
, "Exit"),
1625 rootmenu
->setLabel(i18n(BasemenuSet
, BasemenuBlackboxMenu
,
1631 bool BScreen::parseMenuFile(FILE *file
, Rootmenu
*menu
) {
1632 char line
[1024], label
[1024], command
[1024];
1634 while (! feof(file
)) {
1635 memset(line
, 0, 1024);
1636 memset(label
, 0, 1024);
1637 memset(command
, 0, 1024);
1639 if (fgets(line
, 1024, file
)) {
1640 if (line
[0] != '#') {
1641 int i
, key
= 0, parse
= 0, index
= -1, line_length
= strlen(line
);
1643 // determine the keyword
1644 for (i
= 0; i
< line_length
; i
++) {
1645 if (line
[i
] == '[') parse
= 1;
1646 else if (line
[i
] == ']') break;
1647 else if (line
[i
] != ' ')
1649 key
+= tolower(line
[i
]);
1652 // get the label enclosed in ()'s
1655 for (i
= 0; i
< line_length
; i
++) {
1656 if (line
[i
] == '(') {
1659 } else if (line
[i
] == ')') break;
1660 else if (index
++ >= 0) {
1661 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
1662 label
[index
- 1] = line
[i
];
1667 label
[index
] = '\0';
1672 // get the command enclosed in {}'s
1675 for (i
= 0; i
< line_length
; i
++) {
1676 if (line
[i
] == '{') {
1679 } else if (line
[i
] == '}') break;
1680 else if (index
++ >= 0) {
1681 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
1682 command
[index
- 1] = line
[i
];
1687 command
[index
] = '\0';
1694 return ((menu
->getCount() == 0) ? True
: False
);
1701 menu
->insert(label
);
1706 if ((! *label
) && (! *command
)) {
1707 fprintf(stderr
, i18n(ScreenSet
, ScreenEXECError
,
1708 "BScreen::parseMenuFile: [exec] error, "
1709 "no menu label and/or command defined\n"));
1713 menu
->insert(label
, BScreen::Execute
, command
);
1719 fprintf(stderr
, i18n(ScreenSet
, ScreenEXITError
,
1720 "BScreen::parseMenuFile: [exit] error, "
1721 "no menu label defined\n"));
1725 menu
->insert(label
, BScreen::Exit
);
1731 if ((! *label
) || (! *command
)) {
1733 i18n(ScreenSet
, ScreenSTYLEError
,
1734 "BScreen::parseMenuFile: [style] error, "
1735 "no menu label and/or filename defined\n"));
1739 string style
= expandTilde(command
);
1741 menu
->insert(label
, BScreen::SetStyle
, style
.c_str());
1748 fprintf(stderr
, i18n(ScreenSet
, ScreenCONFIGError
,
1749 "BScreen::parseMenufile: [config] error, "
1750 "no label defined"));
1754 menu
->insert(label
, configmenu
);
1758 case 740: // include
1761 fprintf(stderr
, i18n(ScreenSet
, ScreenINCLUDEError
,
1762 "BScreen::parseMenuFile: [include] error, "
1763 "no filename defined\n"));
1767 string newfile
= expandTilde(label
);
1768 FILE *submenufile
= fopen(newfile
.c_str(), "r");
1772 if (fstat(fileno(submenufile
), &buf
) ||
1773 (! S_ISREG(buf
.st_mode
))) {
1775 i18n(ScreenSet
, ScreenINCLUDEErrorReg
,
1776 "BScreen::parseMenuFile: [include] error: "
1777 "'%s' is not a regular file\n"), newfile
.c_str());
1781 if (! feof(submenufile
)) {
1782 if (! parseMenuFile(submenufile
, menu
))
1783 blackbox
->addMenuTimestamp(newfile
);
1785 fclose(submenufile
);
1788 perror(newfile
.c_str());
1794 case 767: // submenu
1797 fprintf(stderr
, i18n(ScreenSet
, ScreenSUBMENUError
,
1798 "BScreen::parseMenuFile: [submenu] error, "
1799 "no menu label defined\n"));
1803 Rootmenu
*submenu
= new Rootmenu(this);
1806 submenu
->setLabel(command
);
1808 submenu
->setLabel(label
);
1810 parseMenuFile(file
, submenu
);
1812 menu
->insert(label
, submenu
);
1813 rootmenuList
.push_back(submenu
);
1818 case 773: // restart
1821 fprintf(stderr
, i18n(ScreenSet
, ScreenRESTARTError
,
1822 "BScreen::parseMenuFile: [restart] error, "
1823 "no menu label defined\n"));
1828 menu
->insert(label
, BScreen::RestartOther
, command
);
1830 menu
->insert(label
, BScreen::Restart
);
1835 case 845: // reconfig
1839 i18n(ScreenSet
, ScreenRECONFIGError
,
1840 "BScreen::parseMenuFile: [reconfig] error, "
1841 "no menu label defined\n"));
1845 menu
->insert(label
, BScreen::Reconfigure
);
1850 case 995: // stylesdir
1851 case 1113: // stylesmenu
1853 bool newmenu
= ((key
== 1113) ? True
: False
);
1855 if ((! *label
) || ((! *command
) && newmenu
)) {
1857 i18n(ScreenSet
, ScreenSTYLESDIRError
,
1858 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1859 " error, no directory defined\n"));
1863 char *directory
= ((newmenu
) ? command
: label
);
1865 string stylesdir
= expandTilde(directory
);
1867 struct stat statbuf
;
1869 if (! stat(stylesdir
.c_str(), &statbuf
)) {
1870 if (S_ISDIR(statbuf
.st_mode
)) {
1871 Rootmenu
*stylesmenu
;
1874 stylesmenu
= new Rootmenu(this);
1878 DIR *d
= opendir(stylesdir
.c_str());
1880 std::vector
<string
> ls
;
1882 while((p
= readdir(d
)))
1883 ls
.push_back(p
->d_name
);
1887 std::sort(ls
.begin(), ls
.end());
1889 std::vector
<string
>::iterator it
= ls
.begin(),
1891 for (; it
!= end
; ++it
) {
1892 const string
& fname
= *it
;
1894 if (fname
[fname
.size()-1] == '~')
1897 string style
= stylesdir
;
1901 if ((! stat(style
.c_str(), &statbuf
)) &&
1902 S_ISREG(statbuf
.st_mode
))
1903 stylesmenu
->insert(fname
, BScreen::SetStyle
, style
);
1906 stylesmenu
->update();
1909 stylesmenu
->setLabel(label
);
1910 menu
->insert(label
, stylesmenu
);
1911 rootmenuList
.push_back(stylesmenu
);
1914 blackbox
->addMenuTimestamp(stylesdir
);
1917 i18n(ScreenSet
, ScreenSTYLESDIRErrorNotDir
,
1918 "BScreen::parseMenuFile:"
1919 " [stylesdir/stylesmenu] error, %s is not a"
1920 " directory\n"), stylesdir
.c_str());
1924 i18n(ScreenSet
, ScreenSTYLESDIRErrorNoExist
,
1925 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1926 " error, %s does not exist\n"), stylesdir
.c_str());
1931 case 1090: // workspaces
1935 i18n(ScreenSet
, ScreenWORKSPACESError
,
1936 "BScreen:parseMenuFile: [workspaces] error, "
1937 "no menu label defined\n"));
1941 menu
->insert(label
, workspacemenu
);
1950 return ((menu
->getCount() == 0) ? True
: False
);
1954 void BScreen::shutdown(void) {
1955 XSelectInput(blackbox
->getXDisplay(), getRootWindow(), NoEventMask
);
1956 XSync(blackbox
->getXDisplay(), False
);
1958 while(! windowList
.empty())
1959 unmanageWindow(windowList
.front(), True
);
1965 void BScreen::showPosition(int x
, int y
) {
1966 if (! geom_visible
) {
1967 XMoveResizeWindow(blackbox
->getXDisplay(), geom_window
,
1968 (getWidth() - geom_w
) / 2,
1969 (getHeight() - geom_h
) / 2, geom_w
, geom_h
);
1970 XMapWindow(blackbox
->getXDisplay(), geom_window
);
1971 XRaiseWindow(blackbox
->getXDisplay(), geom_window
);
1973 geom_visible
= True
;
1978 sprintf(label
, i18n(ScreenSet
, ScreenPositionFormat
,
1979 "X: %4d x Y: %4d"), x
, y
);
1981 XClearWindow(blackbox
->getXDisplay(), geom_window
);
1983 BPen
pen(resource
.wstyle
.l_text_focus
, resource
.wstyle
.font
);
1984 if (i18n
.multibyte()) {
1985 XmbDrawString(blackbox
->getXDisplay(), geom_window
,
1986 resource
.wstyle
.fontset
, pen
.gc(),
1987 resource
.bevel_width
, resource
.bevel_width
-
1988 resource
.wstyle
.fontset_extents
->max_ink_extent
.y
,
1989 label
, strlen(label
));
1991 XDrawString(blackbox
->getXDisplay(), geom_window
,
1992 pen
.gc(), resource
.bevel_width
,
1993 resource
.wstyle
.font
->ascent
+ resource
.bevel_width
,
1994 label
, strlen(label
));
1999 void BScreen::showGeometry(unsigned int gx
, unsigned int gy
) {
2000 if (! geom_visible
) {
2001 XMoveResizeWindow(blackbox
->getXDisplay(), geom_window
,
2002 (getWidth() - geom_w
) / 2,
2003 (getHeight() - geom_h
) / 2, geom_w
, geom_h
);
2004 XMapWindow(blackbox
->getXDisplay(), geom_window
);
2005 XRaiseWindow(blackbox
->getXDisplay(), geom_window
);
2007 geom_visible
= True
;
2012 sprintf(label
, i18n(ScreenSet
, ScreenGeometryFormat
,
2013 "W: %4d x H: %4d"), gx
, gy
);
2015 XClearWindow(blackbox
->getXDisplay(), geom_window
);
2017 BPen
pen(resource
.wstyle
.l_text_focus
, resource
.wstyle
.font
);
2018 if (i18n
.multibyte()) {
2019 XmbDrawString(blackbox
->getXDisplay(), geom_window
,
2020 resource
.wstyle
.fontset
, pen
.gc(),
2021 resource
.bevel_width
, resource
.bevel_width
-
2022 resource
.wstyle
.fontset_extents
->max_ink_extent
.y
,
2023 label
, strlen(label
));
2025 XDrawString(blackbox
->getXDisplay(), geom_window
,
2026 pen
.gc(), resource
.bevel_width
,
2027 resource
.wstyle
.font
->ascent
+
2028 resource
.bevel_width
, label
, strlen(label
));
2033 void BScreen::hideGeometry(void) {
2035 XUnmapWindow(blackbox
->getXDisplay(), geom_window
);
2036 geom_visible
= False
;
2041 void BScreen::addStrut(Strut
*strut
) {
2042 strutList
.push_back(strut
);
2046 void BScreen::removeStrut(Strut
*strut
) {
2047 strutList
.remove(strut
);
2051 const Rect
& BScreen::availableArea(void) const {
2053 return getRect(); // return the full screen
2058 void BScreen::updateAvailableArea(void) {
2059 Rect old_area
= usableArea
;
2060 usableArea
= getRect(); // reset to full screen
2062 /* these values represent offsets from the screen edge
2063 * we look for the biggest offset on each edge and then apply them
2065 * do not be confused by the similarity to the names of Rect's members
2067 unsigned int current_left
= 0, current_right
= 0, current_top
= 0,
2070 StrutList::const_iterator it
= strutList
.begin(), end
= strutList
.end();
2072 for(; it
!= end
; ++it
) {
2074 if (strut
->left
> current_left
)
2075 current_left
= strut
->left
;
2076 if (strut
->top
> current_top
)
2077 current_top
= strut
->top
;
2078 if (strut
->right
> current_right
)
2079 current_right
= strut
->right
;
2080 if (strut
->bottom
> current_bottom
)
2081 current_bottom
= strut
->bottom
;
2084 usableArea
.setPos(current_left
, current_top
);
2085 usableArea
.setSize(usableArea
.width() - (current_left
+ current_right
),
2086 usableArea
.height() - (current_top
+ current_bottom
));
2088 if (old_area
!= usableArea
) {
2089 BlackboxWindowList::iterator it
= windowList
.begin(),
2090 end
= windowList
.end();
2091 for (; it
!= end
; ++it
)
2092 if ((*it
)->isMaximized()) (*it
)->remaximize();
2099 Workspace
* BScreen::getWorkspace(unsigned int index
) {
2100 assert(index
< workspacesList
.size());
2101 return workspacesList
[index
];
2105 void BScreen::buttonPressEvent(XButtonEvent
*xbutton
) {
2106 if (xbutton
->button
== 1) {
2107 if (! isRootColormapInstalled())
2108 image_control
->installRootColormap();
2110 if (workspacemenu
->isVisible())
2111 workspacemenu
->hide();
2113 if (rootmenu
->isVisible())
2115 } else if (xbutton
->button
== 2) {
2116 int mx
= xbutton
->x_root
- (workspacemenu
->getWidth() / 2);
2117 int my
= xbutton
->y_root
- (workspacemenu
->getTitleHeight() / 2);
2122 if (mx
+ workspacemenu
->getWidth() > getWidth())
2123 mx
= getWidth() - workspacemenu
->getWidth() - getBorderWidth();
2125 if (my
+ workspacemenu
->getHeight() > getHeight())
2126 my
= getHeight() - workspacemenu
->getHeight() - getBorderWidth();
2128 workspacemenu
->move(mx
, my
);
2130 if (! workspacemenu
->isVisible()) {
2131 workspacemenu
->removeParent();
2132 workspacemenu
->show();
2134 } else if (xbutton
->button
== 3) {
2135 int mx
= xbutton
->x_root
- (rootmenu
->getWidth() / 2);
2136 int my
= xbutton
->y_root
- (rootmenu
->getTitleHeight() / 2);
2141 if (mx
+ rootmenu
->getWidth() > getWidth())
2142 mx
= getWidth() - rootmenu
->getWidth() - getBorderWidth();
2144 if (my
+ rootmenu
->getHeight() > getHeight())
2145 my
= getHeight() - rootmenu
->getHeight() - getBorderWidth();
2147 rootmenu
->move(mx
, my
);
2149 if (! rootmenu
->isVisible()) {
2150 blackbox
->checkMenu();
2154 } else if (xbutton
->button
== 4) {
2155 if (getCurrentWorkspaceID() >= getWorkspaceCount() - 1)
2156 changeWorkspaceID(0);
2158 changeWorkspaceID(getCurrentWorkspaceID() + 1);
2160 } else if (xbutton
->button
== 5) {
2161 if (getCurrentWorkspaceID() == 0)
2162 changeWorkspaceID(getWorkspaceCount() - 1);
2164 changeWorkspaceID(getCurrentWorkspaceID() - 1);
2169 void BScreen::toggleFocusModel(FocusModel model
) {
2170 if (model
== SloppyFocus
) {
2171 saveSloppyFocus(True
);
2173 // we're cheating here to save writing the config file 3 times
2174 resource
.auto_raise
= False
;
2175 resource
.click_raise
= False
;
2176 saveSloppyFocus(False
);
2183 void BScreen::updateFocusModel()
2185 std::for_each(workspacesList
.begin(), workspacesList
.end(),
2186 std::mem_fun(&Workspace::updateFocusModel
));
2190 BTexture
BScreen::readDatabaseTexture(const string
&rname
,
2191 const string
&default_color
,
2192 Configuration
&style
) {
2196 if (style
.getValue(rname
, s
))
2197 texture
= BTexture(s
);
2199 texture
.setTexture(BTexture::Solid
| BTexture::Flat
);
2201 // associate this texture with this screen
2202 texture
.setDisplay(getBaseDisplay(), getScreenNumber());
2203 texture
.setImageControl(image_control
);
2205 if (texture
.texture() & BTexture::Solid
) {
2206 texture
.setColor(readDatabaseColor(rname
+ ".color",
2207 default_color
, style
));
2208 texture
.setColorTo(readDatabaseColor(rname
+ ".colorTo",
2209 default_color
, style
));
2210 } else if (texture
.texture() & BTexture::Gradient
) {
2211 texture
.setColor(readDatabaseColor(rname
+ ".color",
2212 default_color
, style
));
2213 texture
.setColorTo(readDatabaseColor(rname
+ ".colorTo",
2214 default_color
, style
));
2221 BColor
BScreen::readDatabaseColor(const string
&rname
,
2222 const string
&default_color
,
2223 Configuration
&style
) {
2226 if (style
.getValue(rname
, s
))
2227 color
= BColor(s
, getBaseDisplay(), getScreenNumber());
2229 color
= BColor(default_color
, getBaseDisplay(), getScreenNumber());
2234 XFontSet
BScreen::readDatabaseFontSet(const string
&rname
,
2235 Configuration
&style
) {
2236 char *defaultFont
= "fixed";
2238 bool load_default
= True
;
2240 XFontSet fontset
= 0;
2241 if (style
.getValue(rname
, s
) && (fontset
= createFontSet(s
)))
2242 load_default
= False
;
2245 fontset
= createFontSet(defaultFont
);
2249 i18n(ScreenSet
, ScreenDefaultFontLoadFail
,
2250 "BScreen::setCurrentStyle(): couldn't load default font.\n"));
2259 XFontStruct
*BScreen::readDatabaseFont(const string
&rname
,
2260 Configuration
&style
) {
2261 char *defaultFont
= "fixed";
2263 bool load_default
= False
;
2265 XFontStruct
*font
= 0;
2266 if (style
.getValue(rname
, s
)) {
2267 if ((font
= XLoadQueryFont(blackbox
->getXDisplay(), s
.c_str())) == NULL
) {
2269 i18n(ScreenSet
, ScreenFontLoadFail
,
2270 "BScreen::setCurrentStyle(): couldn't load font '%s'\n"),
2273 load_default
= True
;
2276 load_default
= True
;
2280 font
= XLoadQueryFont(blackbox
->getXDisplay(), defaultFont
);
2283 i18n(ScreenSet
, ScreenDefaultFontLoadFail
,
2284 "BScreen::setCurrentStyle(): couldn't load default font.\n"));
2293 #ifndef HAVE_STRCASESTR
2294 static const char * strcasestr(const char *str
, const char *ptn
) {
2295 const char *s2
, *p2
;
2296 for(; *str
; str
++) {
2297 for(s2
=str
,p2
=ptn
; ; s2
++,p2
++) {
2298 if (! *p2
) return str
;
2299 if (toupper(*s2
) != toupper(*p2
)) break;
2304 #endif // HAVE_STRCASESTR
2307 static const char *getFontElement(const char *pattern
, char *buf
,
2313 va_start(va
, bufsiz
);
2315 buf
[bufsiz
-2] = '*';
2316 while((v
= va_arg(va
, char *)) != NULL
) {
2317 p
= strcasestr(pattern
, v
);
2319 strncpy(buf
, p
+1, bufsiz
-2);
2320 p2
= strchr(buf
, '-');
2327 strncpy(buf
, "*", bufsiz
);
2332 static const char *getFontSize(const char *pattern
, int *size
) {
2334 const char *p2
=NULL
;
2337 for (p
=pattern
; 1; p
++) {
2339 if (p2
!=NULL
&& n
>1 && n
<72) {
2340 *size
= n
; return p2
+1;
2342 *size
= 16; return NULL
;
2344 } else if (*p
=='-') {
2345 if (n
>1 && n
<72 && p2
!=NULL
) {
2350 } else if (*p
>='0' && *p
<='9' && p2
!=NULL
) {
2360 XFontSet
BScreen::createFontSet(const string
&fontname
) {
2362 char **missing
, *def
= "-";
2363 int nmissing
, pixel_size
= 0, buf_size
= 0;
2364 char weight
[FONT_ELEMENT_SIZE
], slant
[FONT_ELEMENT_SIZE
];
2366 fs
= XCreateFontSet(blackbox
->getXDisplay(),
2367 fontname
.c_str(), &missing
, &nmissing
, &def
);
2368 if (fs
&& (! nmissing
))
2371 const char *nfontname
= fontname
.c_str();
2372 #ifdef HAVE_SETLOCALE
2374 if (nmissing
) XFreeStringList(missing
);
2376 setlocale(LC_CTYPE
, "C");
2377 fs
= XCreateFontSet(blackbox
->getXDisplay(), fontname
.c_str(),
2378 &missing
, &nmissing
, &def
);
2379 setlocale(LC_CTYPE
, "");
2381 #endif // HAVE_SETLOCALE
2384 XFontStruct
**fontstructs
;
2386 XFontsOfFontSet(fs
, &fontstructs
, &fontnames
);
2387 nfontname
= fontnames
[0];
2390 getFontElement(nfontname
, weight
, FONT_ELEMENT_SIZE
,
2391 "-medium-", "-bold-", "-demibold-", "-regular-", NULL
);
2392 getFontElement(nfontname
, slant
, FONT_ELEMENT_SIZE
,
2393 "-r-", "-i-", "-o-", "-ri-", "-ro-", NULL
);
2394 getFontSize(nfontname
, &pixel_size
);
2396 if (! strcmp(weight
, "*"))
2397 strncpy(weight
, "medium", FONT_ELEMENT_SIZE
);
2398 if (! strcmp(slant
, "*"))
2399 strncpy(slant
, "r", FONT_ELEMENT_SIZE
);
2402 else if (pixel_size
> 97)
2405 buf_size
= strlen(nfontname
) + (FONT_ELEMENT_SIZE
* 2) + 64;
2406 char *pattern2
= new char[buf_size
];
2409 "-*-*-%s-%s-*-*-%d-*-*-*-*-*-*-*,"
2410 "-*-*-*-*-*-*-%d-*-*-*-*-*-*-*,*",
2411 nfontname
, weight
, slant
, pixel_size
, pixel_size
);
2412 nfontname
= pattern2
;
2415 XFreeStringList(missing
);
2417 XFreeFontSet(blackbox
->getXDisplay(), fs
);
2419 fs
= XCreateFontSet(blackbox
->getXDisplay(), nfontname
, &missing
,