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 updateDesktopNames();
245 updateNetizenWorkspaceCount();
247 workspacemenu
->insert(i18n(IconSet
, IconIcons
, "Icons"), iconmenu
);
248 workspacemenu
->update();
250 current_workspace
= workspacesList
.front();
252 xatom
->setValue(getRootWindow(), XAtom::net_current_desktop
,
253 XAtom::cardinal
, 0); //first workspace
255 workspacemenu
->setItemSelected(2, True
);
257 removeWorkspaceNames(); // do not need them any longer
259 toolbar
= new Toolbar(this);
261 slit
= new Slit(this);
265 raiseWindows(0, 0); // this also initializes the empty stacking list
268 updateClientList(); // initialize the client list, which will be empty
269 updateAvailableArea();
271 changeWorkspaceID(0);
273 unsigned int i
, j
, nchild
;
274 Window r
, p
, *children
;
275 XQueryTree(blackbox
->getXDisplay(), getRootWindow(), &r
, &p
,
278 // preen the window list of all icon windows... for better dockapp support
279 for (i
= 0; i
< nchild
; i
++) {
280 if (children
[i
] == None
) continue;
282 XWMHints
*wmhints
= XGetWMHints(blackbox
->getXDisplay(),
286 if ((wmhints
->flags
& IconWindowHint
) &&
287 (wmhints
->icon_window
!= children
[i
])) {
288 for (j
= 0; j
< nchild
; j
++) {
289 if (children
[j
] == wmhints
->icon_window
) {
300 // manage shown windows
301 for (i
= 0; i
< nchild
; ++i
) {
302 if (children
[i
] == None
|| (! blackbox
->validateWindow(children
[i
])))
305 XWindowAttributes attrib
;
306 if (XGetWindowAttributes(blackbox
->getXDisplay(), children
[i
], &attrib
)) {
307 if (attrib
.override_redirect
) continue;
309 if (attrib
.map_state
!= IsUnmapped
) {
310 manageWindow(children
[i
]);
317 // call this again just in case a window we found updates the Strut list
318 updateAvailableArea();
322 BScreen::~BScreen(void) {
323 if (! managed
) return;
325 if (geom_pixmap
!= None
)
326 image_control
->removeImage(geom_pixmap
);
328 if (geom_window
!= None
)
329 XDestroyWindow(blackbox
->getXDisplay(), geom_window
);
331 std::for_each(workspacesList
.begin(), workspacesList
.end(),
334 std::for_each(iconList
.begin(), iconList
.end(), PointerAssassin());
336 std::for_each(netizenList
.begin(), netizenList
.end(), PointerAssassin());
339 delete workspacemenu
;
344 delete image_control
;
346 if (resource
.wstyle
.fontset
)
347 XFreeFontSet(blackbox
->getXDisplay(), resource
.wstyle
.fontset
);
348 if (resource
.mstyle
.t_fontset
)
349 XFreeFontSet(blackbox
->getXDisplay(), resource
.mstyle
.t_fontset
);
350 if (resource
.mstyle
.f_fontset
)
351 XFreeFontSet(blackbox
->getXDisplay(), resource
.mstyle
.f_fontset
);
352 if (resource
.tstyle
.fontset
)
353 XFreeFontSet(blackbox
->getXDisplay(), resource
.tstyle
.fontset
);
355 if (resource
.wstyle
.font
)
356 XFreeFont(blackbox
->getXDisplay(), resource
.wstyle
.font
);
357 if (resource
.mstyle
.t_font
)
358 XFreeFont(blackbox
->getXDisplay(), resource
.mstyle
.t_font
);
359 if (resource
.mstyle
.f_font
)
360 XFreeFont(blackbox
->getXDisplay(), resource
.mstyle
.f_font
);
361 if (resource
.tstyle
.font
)
362 XFreeFont(blackbox
->getXDisplay(), resource
.tstyle
.font
);
364 XFreeGC(blackbox
->getXDisplay(), opGC
);
368 void BScreen::removeWorkspaceNames(void) {
369 workspaceNames
.clear();
372 void BScreen::saveSloppyFocus(bool s
) {
373 resource
.sloppy_focus
= s
;
376 if (resource
.sloppy_focus
) {
377 fmodel
= "SloppyFocus";
378 if (resource
.auto_raise
) fmodel
+= " AutoRaise";
379 if (resource
.click_raise
) fmodel
+= " ClickRaise";
381 fmodel
= "ClickToFocus";
383 config
->setValue(screenstr
+ "focusModel", fmodel
);
387 void BScreen::saveAutoRaise(bool a
) {
388 resource
.auto_raise
= a
;
389 saveSloppyFocus(resource
.sloppy_focus
);
393 void BScreen::saveClickRaise(bool c
) {
394 resource
.click_raise
= c
;
395 saveSloppyFocus(resource
.sloppy_focus
);
399 void BScreen::saveImageDither(bool d
) {
400 image_control
->setDither(d
);
401 config
->setValue(screenstr
+ "imageDither", doImageDither());
405 void BScreen::saveOpaqueMove(bool o
) {
406 resource
.opaque_move
= o
;
407 config
->setValue(screenstr
+ "opaqueMove", resource
.opaque_move
);
411 void BScreen::saveFullMax(bool f
) {
412 resource
.full_max
= f
;
413 config
->setValue(screenstr
+ "fullMaximization", resource
.full_max
);
417 void BScreen::saveFocusNew(bool f
) {
418 resource
.focus_new
= f
;
419 config
->setValue(screenstr
+ "focusNewWindows", resource
.focus_new
);
423 void BScreen::saveFocusLast(bool f
) {
424 resource
.focus_last
= f
;
425 config
->setValue(screenstr
+ "focusLastWindow", resource
.focus_last
);
429 void BScreen::saveHideToolbar(bool h
) {
430 resource
.hide_toolbar
= h
;
431 if (resource
.hide_toolbar
)
432 toolbar
->unmapToolbar();
434 toolbar
->mapToolbar();
435 config
->setValue(screenstr
+ "hideToolbar", resource
.hide_toolbar
);
439 void BScreen::saveWindowToWindowSnap(bool s
) {
440 resource
.window_to_window_snap
= s
;
441 config
->setValue(screenstr
+ "windowToWindowSnap",
442 resource
.window_to_window_snap
);
446 void BScreen::saveWindowCornerSnap(bool s
) {
447 resource
.window_corner_snap
= s
;
448 config
->setValue(screenstr
+ "windowCornerSnap",
449 resource
.window_corner_snap
);
453 void BScreen::saveWorkspaces(unsigned int w
) {
454 resource
.workspaces
= w
;
455 config
->setValue(screenstr
+ "workspaces", resource
.workspaces
);
459 void BScreen::savePlacementPolicy(int p
) {
460 resource
.placement_policy
= p
;
461 const char *placement
;
462 switch (resource
.placement_policy
) {
463 case CascadePlacement
: placement
= "CascadePlacement"; break;
464 case ColSmartPlacement
: placement
= "ColSmartPlacement"; break;
465 case RowSmartPlacement
: default: placement
= "RowSmartPlacement"; break;
467 config
->setValue(screenstr
+ "windowPlacement", placement
);
471 void BScreen::saveEdgeSnapThreshold(int t
) {
472 resource
.edge_snap_threshold
= t
;
473 config
->setValue(screenstr
+ "edgeSnapThreshold",
474 resource
.edge_snap_threshold
);
478 void BScreen::saveRowPlacementDirection(int d
) {
479 resource
.row_direction
= d
;
480 config
->setValue(screenstr
+ "rowPlacementDirection",
481 resource
.row_direction
== LeftRight
?
482 "LeftToRight" : "RightToLeft");
486 void BScreen::saveColPlacementDirection(int d
) {
487 resource
.col_direction
= d
;
488 config
->setValue(screenstr
+ "colPlacementDirection",
489 resource
.col_direction
== TopBottom
?
490 "TopToBottom" : "BottomToTop");
495 void BScreen::saveStrftimeFormat(const std::string
& format
) {
496 resource
.strftime_format
= format
;
497 config
->setValue(screenstr
+ "strftimeFormat", resource
.strftime_format
);
500 #else // !HAVE_STRFTIME
502 void BScreen::saveDateFormat(int f
) {
503 resource
.date_format
= f
;
504 config
->setValue(screenstr
+ "dateFormat",
505 resource
.date_format
== B_EuropeanDate
?
506 "European" : "American");
510 void BScreen::saveClock24Hour(Bool c
) {
511 resource
.clock24hour
= c
;
512 config
->setValue(screenstr
+ "clockFormat", resource
.clock24hour
? 24 : 12);
514 #endif // HAVE_STRFTIME
517 void BScreen::saveWorkspaceNames() {
519 WorkspaceList::iterator it
= workspacesList
.begin();
520 const WorkspaceList::iterator last
= workspacesList
.end() - 1;
521 const WorkspaceList::iterator end
= workspacesList
.end();
522 for (; it
!= end
; ++it
) {
523 names
+= (*it
)->getName();
527 config
->setValue(screenstr
+ "workspaceNames", names
);
531 void BScreen::save_rc(void) {
532 saveSloppyFocus(resource
.sloppy_focus
);
533 saveAutoRaise(resource
.auto_raise
);
534 saveImageDither(doImageDither());
535 saveOpaqueMove(resource
.opaque_move
);
536 saveFullMax(resource
.full_max
);
537 saveFocusNew(resource
.focus_new
);
538 saveFocusLast(resource
.focus_last
);
539 saveHideToolbar(resource
.hide_toolbar
);
540 saveWindowToWindowSnap(resource
.window_to_window_snap
);
541 saveWindowCornerSnap(resource
.window_corner_snap
);
542 saveWorkspaces(resource
.workspaces
);
543 savePlacementPolicy(resource
.placement_policy
);
544 saveEdgeSnapThreshold(resource
.edge_snap_threshold
);
545 saveRowPlacementDirection(resource
.row_direction
);
546 saveColPlacementDirection(resource
.col_direction
);
548 saveStrftimeFormat(resource
.strftime_format
);
549 #else // !HAVE_STRFTIME
550 saveDateFormat(resource
.date_format
);
551 savwClock24Hour(resource
.clock24hour
);
552 #endif // HAVE_STRFTIME
559 void BScreen::load_rc(void) {
563 if (! config
->getValue(screenstr
+ "fullMaximization", resource
.full_max
))
564 resource
.full_max
= false;
566 if (! config
->getValue(screenstr
+ "focusNewWindows", resource
.focus_new
))
567 resource
.focus_new
= false;
569 if (! config
->getValue(screenstr
+ "focusLastWindow", resource
.focus_last
))
570 resource
.focus_last
= false;
572 if (! config
->getValue(screenstr
+ "workspaces", resource
.workspaces
))
573 resource
.workspaces
= 1;
575 if (! config
->getValue(screenstr
+ "opaqueMove", resource
.opaque_move
))
576 resource
.opaque_move
= false;
578 if (! config
->getValue(screenstr
+ "hideToolbar", resource
.hide_toolbar
))
579 resource
.hide_toolbar
= false;
581 if (! config
->getValue(screenstr
+ "windowToWindowSnap",
582 resource
.window_to_window_snap
))
583 resource
.window_to_window_snap
= true;
585 if (! config
->getValue(screenstr
+ "windowCornerSnap",
586 resource
.window_corner_snap
))
587 resource
.window_corner_snap
= true;
589 if (! config
->getValue(screenstr
+ "imageDither", b
))
591 image_control
->setDither(b
);
593 if (! config
->getValue(screenstr
+ "edgeSnapThreshold",
594 resource
.edge_snap_threshold
))
595 resource
.edge_snap_threshold
= 4;
597 if (config
->getValue(screenstr
+ "rowPlacementDirection", s
) &&
599 resource
.row_direction
= RightLeft
;
601 resource
.row_direction
= LeftRight
;
603 if (config
->getValue(screenstr
+ "colPlacementDirection", s
) &&
605 resource
.col_direction
= BottomTop
;
607 resource
.col_direction
= TopBottom
;
609 if (config
->getValue(screenstr
+ "workspaceNames", s
)) {
610 string::const_iterator it
= s
.begin(), end
= s
.end();
612 string::const_iterator tmp
= it
; // current string.begin()
613 it
= std::find(tmp
, end
, ','); // look for comma between tmp and end
614 addWorkspaceName(string(tmp
, it
)); // s[tmp:it]
621 resource
.sloppy_focus
= true;
622 resource
.auto_raise
= false;
623 resource
.click_raise
= false;
624 if (config
->getValue(screenstr
+ "focusModel", s
)) {
625 if (s
.find("ClickToFocus") != string::npos
) {
626 resource
.sloppy_focus
= false;
629 if (s
.find("AutoRaise") != string::npos
)
630 resource
.auto_raise
= true;
631 if (s
.find("ClickRaise") != string::npos
)
632 resource
.click_raise
= true;
636 if (config
->getValue(screenstr
+ "windowPlacement", s
)) {
637 if (s
== "CascadePlacement")
638 resource
.placement_policy
= CascadePlacement
;
639 else if (s
== "ColSmartPlacement")
640 resource
.placement_policy
= ColSmartPlacement
;
641 else //if (s == "RowSmartPlacement")
642 resource
.placement_policy
= RowSmartPlacement
;
644 resource
.placement_policy
= RowSmartPlacement
;
647 if (config
->getValue(screenstr
+ "strftimeFormat", s
))
648 resource
.strftime_format
= s
;
650 resource
.strftime_format
= "%I:%M %p";
651 #else // !HAVE_STRFTIME
654 if (config
->getValue(screenstr
+ "dateFormat", s
) && s
== "European")
655 resource
.date_format
= B_EuropeanDate
;
657 resource
.date_format
= B_AmericanDate
;
659 if (! config
->getValue(screenstr
+ "clockFormat", l
))
661 resource
.clock24hour
= l
== 24;
662 #endif // HAVE_STRFTIME
666 void BScreen::reconfigure(void) {
673 unsigned long gc_value_mask
= GCForeground
;
674 if (! i18n
.multibyte()) gc_value_mask
|= GCFont
;
676 gcv
.foreground
= WhitePixel(blackbox
->getXDisplay(),
678 gcv
.function
= GXinvert
;
679 gcv
.subwindow_mode
= IncludeInferiors
;
680 XChangeGC(blackbox
->getXDisplay(), opGC
,
681 GCForeground
| GCFunction
| GCSubwindowMode
, &gcv
);
683 const char *s
= i18n(ScreenSet
, ScreenPositionLength
,
684 "0: 0000 x 0: 0000");
687 if (i18n
.multibyte()) {
688 XRectangle ink
, logical
;
689 XmbTextExtents(resource
.wstyle
.fontset
, s
, l
, &ink
, &logical
);
690 geom_w
= logical
.width
;
692 geom_h
= resource
.wstyle
.fontset_extents
->max_ink_extent
.height
;
694 geom_w
= XTextWidth(resource
.wstyle
.font
, s
, l
);
696 geom_h
= resource
.wstyle
.font
->ascent
+ resource
.wstyle
.font
->descent
;
699 geom_w
+= (resource
.bevel_width
* 2);
700 geom_h
+= (resource
.bevel_width
* 2);
702 BTexture
* texture
= &(resource
.wstyle
.l_focus
);
703 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
704 if (geom_pixmap
== ParentRelative
) {
705 texture
= &(resource
.wstyle
.t_focus
);
706 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
709 XSetWindowBackground(blackbox
->getXDisplay(), geom_window
,
710 texture
->color().pixel());
712 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
713 geom_window
, geom_pixmap
);
715 XSetWindowBorderWidth(blackbox
->getXDisplay(), geom_window
,
716 resource
.border_width
);
717 XSetWindowBorder(blackbox
->getXDisplay(), geom_window
,
718 resource
.border_color
.pixel());
720 workspacemenu
->reconfigure();
721 iconmenu
->reconfigure();
723 typedef std::vector
<int> SubList
;
724 SubList remember_subs
;
726 // save the current open menus
727 Basemenu
*menu
= rootmenu
;
729 while ((submenu
= menu
->getCurrentSubmenu()) >= 0) {
730 remember_subs
.push_back(submenu
);
731 menu
= menu
->find(submenu
)->submenu();
737 rootmenu
->reconfigure();
739 // reopen the saved menus
741 const SubList::iterator subs_end
= remember_subs
.end();
742 for (SubList::iterator it
= remember_subs
.begin(); it
!= subs_end
; ++it
) {
743 menu
->drawSubmenu(*it
);
744 menu
= menu
->find(*it
)->submenu();
749 configmenu
->reconfigure();
751 toolbar
->reconfigure();
755 std::for_each(workspacesList
.begin(), workspacesList
.end(),
756 std::mem_fun(&Workspace::reconfigure
));
758 BlackboxWindowList::iterator iit
= iconList
.begin();
759 for (; iit
!= iconList
.end(); ++iit
) {
760 BlackboxWindow
*bw
= *iit
;
761 if (bw
->validateClient())
765 image_control
->timeout();
769 void BScreen::rereadMenu(void) {
773 rootmenu
->reconfigure();
777 void BScreen::LoadStyle(void) {
780 const char *sfile
= blackbox
->getStyleFilename();
782 style
.setFile(sfile
);
783 if (! style
.load()) {
784 style
.setFile(DEFAULTSTYLE
);
786 style
.create(); // hardcoded default values will be used.
792 // load fonts/fontsets
793 if (resource
.wstyle
.fontset
)
794 XFreeFontSet(blackbox
->getXDisplay(), resource
.wstyle
.fontset
);
795 if (resource
.tstyle
.fontset
)
796 XFreeFontSet(blackbox
->getXDisplay(), resource
.tstyle
.fontset
);
797 if (resource
.mstyle
.f_fontset
)
798 XFreeFontSet(blackbox
->getXDisplay(), resource
.mstyle
.f_fontset
);
799 if (resource
.mstyle
.t_fontset
)
800 XFreeFontSet(blackbox
->getXDisplay(), resource
.mstyle
.t_fontset
);
801 resource
.wstyle
.fontset
= 0;
802 resource
.tstyle
.fontset
= 0;
803 resource
.mstyle
.f_fontset
= 0;
804 resource
.mstyle
.t_fontset
= 0;
805 if (resource
.wstyle
.font
)
806 XFreeFont(blackbox
->getXDisplay(), resource
.wstyle
.font
);
807 if (resource
.tstyle
.font
)
808 XFreeFont(blackbox
->getXDisplay(), resource
.tstyle
.font
);
809 if (resource
.mstyle
.f_font
)
810 XFreeFont(blackbox
->getXDisplay(), resource
.mstyle
.f_font
);
811 if (resource
.mstyle
.t_font
)
812 XFreeFont(blackbox
->getXDisplay(), resource
.mstyle
.t_font
);
813 resource
.wstyle
.font
= 0;
814 resource
.tstyle
.font
= 0;
815 resource
.mstyle
.f_font
= 0;
816 resource
.mstyle
.t_font
= 0;
818 if (i18n
.multibyte()) {
819 resource
.wstyle
.fontset
= readDatabaseFontSet("window.font", style
);
820 resource
.tstyle
.fontset
= readDatabaseFontSet("toolbar.font", style
);
821 resource
.mstyle
.t_fontset
= readDatabaseFontSet("menu.title.font", style
);
822 resource
.mstyle
.f_fontset
= readDatabaseFontSet("menu.frame.font", style
);
824 resource
.mstyle
.t_fontset_extents
=
825 XExtentsOfFontSet(resource
.mstyle
.t_fontset
);
826 resource
.mstyle
.f_fontset_extents
=
827 XExtentsOfFontSet(resource
.mstyle
.f_fontset
);
828 resource
.tstyle
.fontset_extents
=
829 XExtentsOfFontSet(resource
.tstyle
.fontset
);
830 resource
.wstyle
.fontset_extents
=
831 XExtentsOfFontSet(resource
.wstyle
.fontset
);
833 resource
.wstyle
.font
= readDatabaseFont("window.font", style
);
834 resource
.tstyle
.font
= readDatabaseFont("toolbar.font", style
);
835 resource
.mstyle
.t_font
= readDatabaseFont("menu.title.font", style
);
836 resource
.mstyle
.f_font
= readDatabaseFont("menu.frame.font", style
);
839 // load window config
840 resource
.wstyle
.t_focus
=
841 readDatabaseTexture("window.title.focus", "white", style
);
842 resource
.wstyle
.t_unfocus
=
843 readDatabaseTexture("window.title.unfocus", "black", style
);
844 resource
.wstyle
.l_focus
=
845 readDatabaseTexture("window.label.focus", "white", style
);
846 resource
.wstyle
.l_unfocus
=
847 readDatabaseTexture("window.label.unfocus", "black", style
);
848 resource
.wstyle
.h_focus
=
849 readDatabaseTexture("window.handle.focus", "white", style
);
850 resource
.wstyle
.h_unfocus
=
851 readDatabaseTexture("window.handle.unfocus", "black", style
);
852 resource
.wstyle
.g_focus
=
853 readDatabaseTexture("window.grip.focus", "white", style
);
854 resource
.wstyle
.g_unfocus
=
855 readDatabaseTexture("window.grip.unfocus", "black", style
);
856 resource
.wstyle
.b_focus
=
857 readDatabaseTexture("window.button.focus", "white", style
);
858 resource
.wstyle
.b_unfocus
=
859 readDatabaseTexture("window.button.unfocus", "black", style
);
860 resource
.wstyle
.b_pressed
=
861 readDatabaseTexture("window.button.pressed", "black", style
);
862 resource
.wstyle
.f_focus
=
863 readDatabaseColor("window.frame.focusColor", "white", style
);
864 resource
.wstyle
.f_unfocus
=
865 readDatabaseColor("window.frame.unfocusColor", "black", style
);
866 resource
.wstyle
.l_text_focus
=
867 readDatabaseColor("window.label.focus.textColor", "black", style
);
868 resource
.wstyle
.l_text_unfocus
=
869 readDatabaseColor("window.label.unfocus.textColor", "white", style
);
870 resource
.wstyle
.b_pic_focus
=
871 readDatabaseColor("window.button.focus.picColor", "black", style
);
872 resource
.wstyle
.b_pic_unfocus
=
873 readDatabaseColor("window.button.unfocus.picColor", "white", style
);
875 resource
.wstyle
.justify
= LeftJustify
;
876 if (style
.getValue("window.justify", s
)) {
877 if (s
== "right" || s
== "Right")
878 resource
.wstyle
.justify
= RightJustify
;
879 else if (s
== "center" || s
== "Center")
880 resource
.wstyle
.justify
= CenterJustify
;
883 // load toolbar config
884 resource
.tstyle
.toolbar
=
885 readDatabaseTexture("toolbar", "black", style
);
886 resource
.tstyle
.label
=
887 readDatabaseTexture("toolbar.label", "black", style
);
888 resource
.tstyle
.window
=
889 readDatabaseTexture("toolbar.windowLabel", "black", style
);
890 resource
.tstyle
.button
=
891 readDatabaseTexture("toolbar.button", "white", style
);
892 resource
.tstyle
.pressed
=
893 readDatabaseTexture("toolbar.button.pressed", "black", style
);
894 resource
.tstyle
.clock
=
895 readDatabaseTexture("toolbar.clock", "black", style
);
896 resource
.tstyle
.l_text
=
897 readDatabaseColor("toolbar.label.textColor", "white", style
);
898 resource
.tstyle
.w_text
=
899 readDatabaseColor("toolbar.windowLabel.textColor", "white", style
);
900 resource
.tstyle
.c_text
=
901 readDatabaseColor("toolbar.clock.textColor", "white", style
);
902 resource
.tstyle
.b_pic
=
903 readDatabaseColor("toolbar.button.picColor", "black", style
);
905 resource
.tstyle
.justify
= LeftJustify
;
906 if (style
.getValue("toolbar.justify", s
)) {
907 if (s
== "right" || s
== "Right")
908 resource
.tstyle
.justify
= RightJustify
;
909 else if (s
== "center" || s
== "Center")
910 resource
.tstyle
.justify
= CenterJustify
;
914 resource
.mstyle
.title
=
915 readDatabaseTexture("menu.title", "white", style
);
916 resource
.mstyle
.frame
=
917 readDatabaseTexture("menu.frame", "black", style
);
918 resource
.mstyle
.hilite
=
919 readDatabaseTexture("menu.hilite", "white", style
);
920 resource
.mstyle
.t_text
=
921 readDatabaseColor("menu.title.textColor", "black", style
);
922 resource
.mstyle
.f_text
=
923 readDatabaseColor("menu.frame.textColor", "white", style
);
924 resource
.mstyle
.d_text
=
925 readDatabaseColor("menu.frame.disableColor", "black", style
);
926 resource
.mstyle
.h_text
=
927 readDatabaseColor("menu.hilite.textColor", "black", style
);
929 resource
.mstyle
.t_justify
= LeftJustify
;
930 if (style
.getValue("menu.title.justify", s
)) {
931 if (s
== "right" || s
== "Right")
932 resource
.mstyle
.t_justify
= RightJustify
;
933 else if (s
== "center" || s
== "Center")
934 resource
.mstyle
.t_justify
= CenterJustify
;
937 resource
.mstyle
.f_justify
= LeftJustify
;
938 if (style
.getValue("menu.frame.justify", s
)) {
939 if (s
== "right" || s
== "Right")
940 resource
.mstyle
.f_justify
= RightJustify
;
941 else if (s
== "center" || s
== "Center")
942 resource
.mstyle
.f_justify
= CenterJustify
;
945 resource
.mstyle
.bullet
= Basemenu::Triangle
;
946 if (style
.getValue("menu.bullet", s
)) {
947 if (s
== "empty" || s
== "Empty")
948 resource
.mstyle
.bullet
= Basemenu::Empty
;
949 else if (s
== "square" || s
== "Square")
950 resource
.mstyle
.bullet
= Basemenu::Square
;
951 else if (s
== "diamond" || s
== "Diamond")
952 resource
.mstyle
.bullet
= Basemenu::Diamond
;
955 resource
.mstyle
.bullet_pos
= Basemenu::Left
;
956 if (style
.getValue("menu.bullet.position", s
)) {
957 if (s
== "right" || s
== "Right")
958 resource
.mstyle
.bullet_pos
= Basemenu::Right
;
961 resource
.border_color
=
962 readDatabaseColor("borderColor", "black", style
);
964 // load bevel, border and handle widths
965 if (! style
.getValue("handleWidth", resource
.handle_width
) ||
966 resource
.handle_width
> (getWidth() / 2) || resource
.handle_width
== 0)
967 resource
.handle_width
= 6;
969 if (! style
.getValue("borderWidth", resource
.border_width
))
970 resource
.border_width
= 1;
972 if (! style
.getValue("bevelWidth", resource
.bevel_width
) ||
973 resource
.bevel_width
> (getWidth() / 2) || resource
.bevel_width
== 0)
974 resource
.bevel_width
= 3;
976 if (! style
.getValue("frameWidth", resource
.frame_width
) ||
977 resource
.frame_width
> (getWidth() / 2))
978 resource
.frame_width
= resource
.bevel_width
;
980 if (style
.getValue("rootCommand", s
))
981 bexec(s
, displayString());
985 void BScreen::addIcon(BlackboxWindow
*w
) {
988 w
->setWorkspace(BSENTINEL
);
989 w
->setWindowNumber(iconList
.size());
991 iconList
.push_back(w
);
993 const char* title
= w
->getIconTitle();
994 iconmenu
->insert(title
);
999 void BScreen::removeIcon(BlackboxWindow
*w
) {
1004 iconmenu
->remove(w
->getWindowNumber());
1007 BlackboxWindowList::iterator it
= iconList
.begin(),
1008 end
= iconList
.end();
1009 for (int i
= 0; it
!= end
; ++it
)
1010 (*it
)->setWindowNumber(i
++);
1014 BlackboxWindow
*BScreen::getIcon(unsigned int index
) {
1015 if (index
< iconList
.size()) {
1016 BlackboxWindowList::iterator it
= iconList
.begin();
1017 for (; index
> 0; --index
, ++it
) ; /* increment to index */
1021 return (BlackboxWindow
*) 0;
1025 unsigned int BScreen::addWorkspace(void) {
1026 Workspace
*wkspc
= new Workspace(this, workspacesList
.size());
1027 workspacesList
.push_back(wkspc
);
1028 saveWorkspaces(getWorkspaceCount());
1029 saveWorkspaceNames();
1031 workspacemenu
->insert(wkspc
->getName(), wkspc
->getMenu(),
1032 wkspc
->getID() + 2);
1033 workspacemenu
->update();
1035 toolbar
->reconfigure();
1037 updateDesktopNames();
1038 updateNetizenWorkspaceCount();
1040 return workspacesList
.size();
1044 unsigned int BScreen::removeLastWorkspace(void) {
1045 if (workspacesList
.size() == 1)
1048 Workspace
*wkspc
= workspacesList
.back();
1050 if (current_workspace
->getID() == wkspc
->getID())
1051 changeWorkspaceID(current_workspace
->getID() - 1);
1055 workspacemenu
->remove(wkspc
->getID() + 2);
1056 workspacemenu
->update();
1058 workspacesList
.pop_back();
1061 saveWorkspaces(getWorkspaceCount());
1062 saveWorkspaceNames();
1063 updateDesktopNames();
1065 toolbar
->reconfigure();
1067 updateNetizenWorkspaceCount();
1069 return workspacesList
.size();
1073 void BScreen::changeWorkspaceID(unsigned int id
) {
1074 if (! current_workspace
) return;
1076 if (id
!= current_workspace
->getID()) {
1077 BlackboxWindow
*focused
= blackbox
->getFocusedWindow();
1078 if (focused
&& focused
->getScreen() == this && ! focused
->isStuck()) {
1079 if (focused
->getWorkspaceNumber() != current_workspace
->getID()) {
1080 fprintf(stderr
, "%s is on the wrong workspace, aborting\n",
1081 focused
->getTitle());
1084 current_workspace
->setLastFocusedWindow(focused
);
1086 // if no window had focus, no need to store a last focus
1087 current_workspace
->setLastFocusedWindow((BlackboxWindow
*) 0);
1089 // when we switch workspaces, unfocus whatever was focused
1090 blackbox
->setFocusedWindow((BlackboxWindow
*) 0);
1092 current_workspace
->hideAll();
1093 workspacemenu
->setItemSelected(current_workspace
->getID() + 2, False
);
1095 current_workspace
= getWorkspace(id
);
1097 xatom
->setValue(getRootWindow(), XAtom::net_current_desktop
,
1098 XAtom::cardinal
, id
);
1100 workspacemenu
->setItemSelected(current_workspace
->getID() + 2, True
);
1101 toolbar
->redrawWorkspaceLabel(True
);
1103 current_workspace
->showAll();
1105 if (resource
.focus_last
&& current_workspace
->getLastFocusedWindow()) {
1106 XSync(blackbox
->getXDisplay(), False
);
1107 current_workspace
->getLastFocusedWindow()->setInputFocus();
1111 updateNetizenCurrentWorkspace();
1116 * Set the _NET_CLIENT_LIST root window property.
1118 void BScreen::updateClientList(void) {
1119 if (windowList
.size() > 0) {
1120 Window
*windows
= new Window
[windowList
.size()];
1121 Window
*win_it
= windows
;
1122 BlackboxWindowList::iterator it
= windowList
.begin();
1123 const BlackboxWindowList::iterator end
= windowList
.end();
1124 for (; it
!= end
; ++it
, ++win_it
)
1125 *win_it
= (*it
)->getClientWindow();
1126 xatom
->setValue(getRootWindow(), XAtom::net_client_list
, XAtom::window
,
1127 windows
, windowList
.size());
1130 xatom
->setValue(getRootWindow(), XAtom::net_client_list
, XAtom::window
,
1136 * Set the _NET_CLIENT_LIST_STACKING root window property.
1138 void BScreen::updateStackingList(void) {
1140 BlackboxWindowList stack_order
;
1143 * Get the atacking order from all of the workspaces.
1144 * We start with the current workspace so that the sticky windows will be
1145 * in the right order on the current workspace.
1146 * XXX: Do we need to have sticky windows in the list once for each workspace?
1148 getCurrentWorkspace()->appendStackOrder(stack_order
);
1149 for (unsigned int i
= 0; i
< getWorkspaceCount(); ++i
)
1150 if (i
!= getCurrentWorkspaceID())
1151 getWorkspace(i
)->appendStackOrder(stack_order
);
1153 if (stack_order
.size() > 0) {
1154 // set the client list atoms
1155 Window
*windows
= new Window
[stack_order
.size()];
1156 Window
*win_it
= windows
;
1157 BlackboxWindowList::iterator it
= stack_order
.begin();
1158 const BlackboxWindowList::iterator end
= stack_order
.end();
1159 for (; it
!= end
; ++it
, ++win_it
)
1160 *win_it
= (*it
)->getClientWindow();
1161 xatom
->setValue(getRootWindow(), XAtom::net_client_list_stacking
,
1162 XAtom::window
, windows
, stack_order
.size());
1165 xatom
->setValue(getRootWindow(), XAtom::net_client_list_stacking
,
1166 XAtom::window
, 0, 0);
1170 void BScreen::addSystrayWindow(Window window
) {
1171 systrayWindowList
.push_back(window
);
1172 xatom
->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows
,
1174 &systrayWindowList
[0], systrayWindowList
.size());
1175 blackbox
->saveSystrayWindowSearch(window
, this);
1179 void BScreen::removeSystrayWindow(Window window
) {
1180 WindowList::iterator it
= systrayWindowList
.begin();
1181 const WindowList::iterator end
= systrayWindowList
.end();
1182 for (; it
!= end
; ++it
)
1183 if (*it
== window
) {
1184 systrayWindowList
.erase(it
);
1185 xatom
->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows
,
1187 &systrayWindowList
[0], systrayWindowList
.size());
1188 blackbox
->removeSystrayWindowSearch(window
);
1194 void BScreen::addDesktopWindow(Window window
) {
1195 desktopWindowList
.push_back(window
);
1196 XLowerWindow(blackbox
->getXDisplay(), window
);
1197 XSelectInput(blackbox
->getXDisplay(), window
, StructureNotifyMask
);
1198 blackbox
->saveDesktopWindowSearch(window
, this);
1202 void BScreen::removeDesktopWindow(Window window
) {
1203 WindowList::iterator it
= desktopWindowList
.begin();
1204 const WindowList::iterator end
= desktopWindowList
.end();
1205 for (; it
!= end
; ++it
)
1206 if (*it
== window
) {
1207 desktopWindowList
.erase(it
);
1208 XSelectInput(blackbox
->getXDisplay(), window
, None
);
1209 blackbox
->removeDesktopWindowSearch(window
);
1215 void BScreen::manageWindow(Window w
) {
1216 new BlackboxWindow(blackbox
, w
, this);
1218 BlackboxWindow
*win
= blackbox
->searchWindow(w
);
1221 if (win
->isDesktop()) {
1222 // desktop windows cant do anything, so we remove all the normal window
1223 // stuff from them, they are only kept around so that we can keep them on
1224 // the bottom of the z-order
1225 addDesktopWindow(win
->getClientWindow());
1231 windowList
.push_back(win
);
1234 XMapRequestEvent mre
;
1236 if (blackbox
->isStartup()) win
->restoreAttributes();
1237 win
->mapRequestEvent(&mre
);
1241 void BScreen::unmanageWindow(BlackboxWindow
*w
, bool remap
) {
1244 if (w
->getWorkspaceNumber() != BSENTINEL
&&
1245 w
->getWindowNumber() != BSENTINEL
)
1246 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
1247 else if (w
->isIconic())
1250 windowList
.remove(w
);
1253 if (blackbox
->getFocusedWindow() == w
)
1254 blackbox
->setFocusedWindow((BlackboxWindow
*) 0);
1256 removeNetizen(w
->getClientWindow());
1259 some managed windows can also be window group controllers. when
1260 unmanaging such windows, we should also delete the window group.
1262 BWindowGroup
*group
= blackbox
->searchGroup(w
->getClientWindow());
1269 void BScreen::addNetizen(Netizen
*n
) {
1270 netizenList
.push_back(n
);
1272 n
->sendWorkspaceCount();
1273 n
->sendCurrentWorkspace();
1275 WorkspaceList::iterator it
= workspacesList
.begin();
1276 const WorkspaceList::iterator end
= workspacesList
.end();
1277 for (; it
!= end
; ++it
)
1278 (*it
)->sendWindowList(*n
);
1280 Window f
= ((blackbox
->getFocusedWindow()) ?
1281 blackbox
->getFocusedWindow()->getClientWindow() : None
);
1282 n
->sendWindowFocus(f
);
1286 void BScreen::removeNetizen(Window w
) {
1287 NetizenList::iterator it
= netizenList
.begin();
1288 for (; it
!= netizenList
.end(); ++it
) {
1289 if ((*it
)->getWindowID() == w
) {
1291 netizenList
.erase(it
);
1298 void BScreen::updateWorkArea(void) {
1299 if (workspacesList
.size() > 0) {
1300 unsigned long *dims
= new unsigned long[4 * workspacesList
.size()];
1301 for (unsigned int i
= 0, m
= workspacesList
.size(); i
< m
; ++i
) {
1302 // XXX: this could be different for each workspace
1303 const Rect
&area
= availableArea();
1304 dims
[(i
* 4) + 0] = area
.x();
1305 dims
[(i
* 4) + 1] = area
.y();
1306 dims
[(i
* 4) + 2] = area
.width();
1307 dims
[(i
* 4) + 3] = area
.height();
1309 xatom
->setValue(getRootWindow(), XAtom::net_workarea
, XAtom::cardinal
,
1310 dims
, 4 * workspacesList
.size());
1312 xatom
->setValue(getRootWindow(), XAtom::net_workarea
, XAtom::cardinal
,
1317 void BScreen::updateNetizenCurrentWorkspace(void) {
1318 std::for_each(netizenList
.begin(), netizenList
.end(),
1319 std::mem_fun(&Netizen::sendCurrentWorkspace
));
1323 void BScreen::updateNetizenWorkspaceCount(void) {
1324 xatom
->setValue(getRootWindow(), XAtom::net_number_of_desktops
,
1325 XAtom::cardinal
, workspacesList
.size());
1329 std::for_each(netizenList
.begin(), netizenList
.end(),
1330 std::mem_fun(&Netizen::sendWorkspaceCount
));
1334 void BScreen::updateNetizenWindowFocus(void) {
1335 Window f
= ((blackbox
->getFocusedWindow()) ?
1336 blackbox
->getFocusedWindow()->getClientWindow() : None
);
1338 xatom
->setValue(getRootWindow(), XAtom::net_active_window
,
1341 NetizenList::iterator it
= netizenList
.begin();
1342 for (; it
!= netizenList
.end(); ++it
)
1343 (*it
)->sendWindowFocus(f
);
1347 void BScreen::updateNetizenWindowAdd(Window w
, unsigned long p
) {
1348 NetizenList::iterator it
= netizenList
.begin();
1349 for (; it
!= netizenList
.end(); ++it
) {
1350 (*it
)->sendWindowAdd(w
, p
);
1355 void BScreen::updateNetizenWindowDel(Window w
) {
1356 NetizenList::iterator it
= netizenList
.begin();
1357 for (; it
!= netizenList
.end(); ++it
)
1358 (*it
)->sendWindowDel(w
);
1362 void BScreen::updateNetizenWindowRaise(Window w
) {
1363 NetizenList::iterator it
= netizenList
.begin();
1364 for (; it
!= netizenList
.end(); ++it
)
1365 (*it
)->sendWindowRaise(w
);
1369 void BScreen::updateNetizenWindowLower(Window w
) {
1370 NetizenList::iterator it
= netizenList
.begin();
1371 for (; it
!= netizenList
.end(); ++it
)
1372 (*it
)->sendWindowLower(w
);
1376 void BScreen::updateNetizenConfigNotify(XEvent
*e
) {
1377 NetizenList::iterator it
= netizenList
.begin();
1378 for (; it
!= netizenList
.end(); ++it
)
1379 (*it
)->sendConfigNotify(e
);
1383 void BScreen::raiseWindows(Window
*workspace_stack
, unsigned int num
) {
1384 // the 13 represents the number of blackbox windows such as menus
1385 Window
*session_stack
= new
1386 Window
[(num
+ workspacesList
.size() + rootmenuList
.size() + 13)];
1387 unsigned int i
= 0, k
= num
;
1389 XRaiseWindow(blackbox
->getXDisplay(), iconmenu
->getWindowID());
1390 *(session_stack
+ i
++) = iconmenu
->getWindowID();
1392 WorkspaceList::iterator wit
= workspacesList
.begin();
1393 const WorkspaceList::iterator w_end
= workspacesList
.end();
1394 for (; wit
!= w_end
; ++wit
)
1395 *(session_stack
+ i
++) = (*wit
)->getMenu()->getWindowID();
1397 *(session_stack
+ i
++) = workspacemenu
->getWindowID();
1399 *(session_stack
+ i
++) = configmenu
->getFocusmenu()->getWindowID();
1400 *(session_stack
+ i
++) = configmenu
->getPlacementmenu()->getWindowID();
1401 *(session_stack
+ i
++) = configmenu
->getWindowID();
1403 *(session_stack
+ i
++) = slit
->getMenu()->getDirectionmenu()->getWindowID();
1404 *(session_stack
+ i
++) = slit
->getMenu()->getPlacementmenu()->getWindowID();
1405 *(session_stack
+ i
++) = slit
->getMenu()->getWindowID();
1407 *(session_stack
+ i
++) =
1408 toolbar
->getMenu()->getPlacementmenu()->getWindowID();
1409 *(session_stack
+ i
++) = toolbar
->getMenu()->getWindowID();
1411 RootmenuList::iterator rit
= rootmenuList
.begin();
1412 for (; rit
!= rootmenuList
.end(); ++rit
)
1413 *(session_stack
+ i
++) = (*rit
)->getWindowID();
1414 *(session_stack
+ i
++) = rootmenu
->getWindowID();
1416 if (toolbar
->isOnTop())
1417 *(session_stack
+ i
++) = toolbar
->getWindowID();
1419 if (slit
->isOnTop())
1420 *(session_stack
+ i
++) = slit
->getWindowID();
1423 *(session_stack
+ i
++) = *(workspace_stack
+ k
);
1425 XRestackWindows(blackbox
->getXDisplay(), session_stack
, i
);
1427 delete [] session_stack
;
1429 updateStackingList();
1433 void BScreen::lowerDesktops(void) {
1434 XLowerWindow(blackbox
->getXDisplay(), desktopWindowList
[0]);
1435 if (desktopWindowList
.size() > 1)
1436 XRestackWindows(blackbox
->getXDisplay(), &desktopWindowList
[0],
1437 desktopWindowList
.size());
1441 void BScreen::addWorkspaceName(const string
& name
) {
1442 workspaceNames
.push_back(name
);
1443 updateDesktopNames();
1447 void BScreen::updateDesktopNames(){
1448 XAtom::StringVect names
;
1450 WorkspaceList::iterator it
= workspacesList
.begin();
1451 const WorkspaceList::iterator end
= workspacesList
.end();
1452 for (; it
!= end
; ++it
)
1453 names
.push_back((*it
)->getName());
1455 xatom
->setValue(getRootWindow(), XAtom::net_desktop_names
,
1456 XAtom::utf8
, names
);
1461 * I would love to kill this function and the accompanying workspaceNames
1462 * list. However, we have a chicken and egg situation. The names are read
1463 * in during load_rc() which happens before the workspaces are created.
1464 * The current solution is to read the names into a list, then use the list
1465 * later for constructing the workspaces. It is only used during initial
1468 const string
BScreen::getNameOfWorkspace(unsigned int id
) {
1469 if (id
< workspaceNames
.size())
1470 return workspaceNames
[id
];
1475 void BScreen::reassociateWindow(BlackboxWindow
*w
, unsigned int wkspc_id
,
1476 bool ignore_sticky
) {
1479 if (wkspc_id
== BSENTINEL
)
1480 wkspc_id
= current_workspace
->getID();
1482 if (w
->getWorkspaceNumber() == wkspc_id
)
1485 if (w
->isIconic()) {
1487 getWorkspace(wkspc_id
)->addWindow(w
);
1488 } else if (ignore_sticky
|| ! w
->isStuck()) {
1489 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
1490 getWorkspace(wkspc_id
)->addWindow(w
);
1495 void BScreen::propagateWindowName(const BlackboxWindow
*bw
) {
1496 if (bw
->isIconic()) {
1497 iconmenu
->changeItemLabel(bw
->getWindowNumber(), bw
->getIconTitle());
1501 Clientmenu
*clientmenu
= getWorkspace(bw
->getWorkspaceNumber())->getMenu();
1502 clientmenu
->changeItemLabel(bw
->getWindowNumber(), bw
->getTitle());
1503 clientmenu
->update();
1505 if (blackbox
->getFocusedWindow() == bw
)
1506 toolbar
->redrawWindowLabel(True
);
1511 void BScreen::nextFocus(void) {
1512 BlackboxWindow
*focused
= blackbox
->getFocusedWindow(),
1516 // if window is not on this screen, ignore it
1517 if (focused
->getScreen()->getScreenNumber() != getScreenNumber())
1518 focused
= (BlackboxWindow
*) 0;
1521 if (focused
&& current_workspace
->getCount() > 1) {
1522 // next is the next window to recieve focus, current is a place holder
1523 BlackboxWindow
*current
;
1526 next
= current_workspace
->getNextWindowInList(current
);
1527 } while(! next
->setInputFocus() && next
!= focused
);
1529 if (next
!= focused
)
1530 current_workspace
->raiseWindow(next
);
1531 } else if (current_workspace
->getCount() >= 1) {
1532 next
= current_workspace
->getTopWindowOnStack();
1534 current_workspace
->raiseWindow(next
);
1535 next
->setInputFocus();
1540 void BScreen::prevFocus(void) {
1541 BlackboxWindow
*focused
= blackbox
->getFocusedWindow(),
1545 // if window is not on this screen, ignore it
1546 if (focused
->getScreen()->getScreenNumber() != getScreenNumber())
1547 focused
= (BlackboxWindow
*) 0;
1550 if (focused
&& current_workspace
->getCount() > 1) {
1551 // next is the next window to recieve focus, current is a place holder
1552 BlackboxWindow
*current
;
1555 next
= current_workspace
->getPrevWindowInList(current
);
1556 } while(! next
->setInputFocus() && next
!= focused
);
1558 if (next
!= focused
)
1559 current_workspace
->raiseWindow(next
);
1560 } else if (current_workspace
->getCount() >= 1) {
1561 next
= current_workspace
->getTopWindowOnStack();
1563 current_workspace
->raiseWindow(next
);
1564 next
->setInputFocus();
1569 void BScreen::raiseFocus(void) {
1570 BlackboxWindow
*focused
= blackbox
->getFocusedWindow();
1574 // if on this Screen, raise it
1575 if (focused
->getScreen()->getScreenNumber() == getScreenNumber()) {
1576 Workspace
*workspace
= getWorkspace(focused
->getWorkspaceNumber());
1577 workspace
->raiseWindow(focused
);
1582 void BScreen::InitMenu(void) {
1584 rootmenuList
.clear();
1586 while (rootmenu
->getCount())
1587 rootmenu
->remove(0);
1589 rootmenu
= new Rootmenu(this);
1591 bool defaultMenu
= True
;
1593 FILE *menu_file
= (FILE *) 0;
1594 const char *menu_filename
= blackbox
->getMenuFilename();
1597 if (! (menu_file
= fopen(menu_filename
, "r")))
1598 perror(menu_filename
);
1599 if (! menu_file
) { // opening the menu file failed, try the default menu
1600 menu_filename
= DEFAULTMENU
;
1601 if (! (menu_file
= fopen(menu_filename
, "r")))
1602 perror(menu_filename
);
1606 if (feof(menu_file
)) {
1607 fprintf(stderr
, i18n(ScreenSet
, ScreenEmptyMenuFile
,
1608 "%s: Empty menu file"),
1611 char line
[1024], label
[1024];
1612 memset(line
, 0, 1024);
1613 memset(label
, 0, 1024);
1615 while (fgets(line
, 1024, menu_file
) && ! feof(menu_file
)) {
1616 if (line
[0] != '#') {
1617 int i
, key
= 0, index
= -1, len
= strlen(line
);
1619 for (i
= 0; i
< len
; i
++) {
1620 if (line
[i
] == '[') index
= 0;
1621 else if (line
[i
] == ']') break;
1622 else if (line
[i
] != ' ')
1624 key
+= tolower(line
[i
]);
1627 if (key
== 517) { // [begin]
1629 for (i
= index
; i
< len
; i
++) {
1630 if (line
[i
] == '(') index
= 0;
1631 else if (line
[i
] == ')') break;
1632 else if (index
++ >= 0) {
1633 if (line
[i
] == '\\' && i
< len
- 1) i
++;
1634 label
[index
- 1] = line
[i
];
1638 if (index
== -1) index
= 0;
1639 label
[index
] = '\0';
1641 rootmenu
->setLabel(label
);
1642 defaultMenu
= parseMenuFile(menu_file
, rootmenu
);
1644 blackbox
->addMenuTimestamp(menu_filename
);
1654 rootmenu
->setInternalMenu();
1655 rootmenu
->insert(i18n(ScreenSet
, Screenxterm
, "xterm"),
1657 i18n(ScreenSet
, Screenxterm
, "xterm"));
1658 rootmenu
->insert(i18n(ScreenSet
, ScreenRestart
, "Restart"),
1660 rootmenu
->insert(i18n(ScreenSet
, ScreenExit
, "Exit"),
1662 rootmenu
->setLabel(i18n(BasemenuSet
, BasemenuBlackboxMenu
,
1668 bool BScreen::parseMenuFile(FILE *file
, Rootmenu
*menu
) {
1669 char line
[1024], label
[1024], command
[1024];
1671 while (! feof(file
)) {
1672 memset(line
, 0, 1024);
1673 memset(label
, 0, 1024);
1674 memset(command
, 0, 1024);
1676 if (fgets(line
, 1024, file
)) {
1677 if (line
[0] != '#') {
1678 int i
, key
= 0, parse
= 0, index
= -1, line_length
= strlen(line
);
1680 // determine the keyword
1681 for (i
= 0; i
< line_length
; i
++) {
1682 if (line
[i
] == '[') parse
= 1;
1683 else if (line
[i
] == ']') break;
1684 else if (line
[i
] != ' ')
1686 key
+= tolower(line
[i
]);
1689 // get the label enclosed in ()'s
1692 for (i
= 0; i
< line_length
; i
++) {
1693 if (line
[i
] == '(') {
1696 } else if (line
[i
] == ')') break;
1697 else if (index
++ >= 0) {
1698 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
1699 label
[index
- 1] = line
[i
];
1704 label
[index
] = '\0';
1709 // get the command enclosed in {}'s
1712 for (i
= 0; i
< line_length
; i
++) {
1713 if (line
[i
] == '{') {
1716 } else if (line
[i
] == '}') break;
1717 else if (index
++ >= 0) {
1718 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
1719 command
[index
- 1] = line
[i
];
1724 command
[index
] = '\0';
1731 return ((menu
->getCount() == 0) ? True
: False
);
1738 menu
->insert(label
);
1743 if ((! *label
) && (! *command
)) {
1744 fprintf(stderr
, i18n(ScreenSet
, ScreenEXECError
,
1745 "BScreen::parseMenuFile: [exec] error, "
1746 "no menu label and/or command defined\n"));
1750 menu
->insert(label
, BScreen::Execute
, command
);
1756 fprintf(stderr
, i18n(ScreenSet
, ScreenEXITError
,
1757 "BScreen::parseMenuFile: [exit] error, "
1758 "no menu label defined\n"));
1762 menu
->insert(label
, BScreen::Exit
);
1768 if ((! *label
) || (! *command
)) {
1770 i18n(ScreenSet
, ScreenSTYLEError
,
1771 "BScreen::parseMenuFile: [style] error, "
1772 "no menu label and/or filename defined\n"));
1776 string style
= expandTilde(command
);
1778 menu
->insert(label
, BScreen::SetStyle
, style
.c_str());
1785 fprintf(stderr
, i18n(ScreenSet
, ScreenCONFIGError
,
1786 "BScreen::parseMenufile: [config] error, "
1787 "no label defined"));
1791 menu
->insert(label
, configmenu
);
1795 case 740: // include
1798 fprintf(stderr
, i18n(ScreenSet
, ScreenINCLUDEError
,
1799 "BScreen::parseMenuFile: [include] error, "
1800 "no filename defined\n"));
1804 string newfile
= expandTilde(label
);
1805 FILE *submenufile
= fopen(newfile
.c_str(), "r");
1809 if (fstat(fileno(submenufile
), &buf
) ||
1810 (! S_ISREG(buf
.st_mode
))) {
1812 i18n(ScreenSet
, ScreenINCLUDEErrorReg
,
1813 "BScreen::parseMenuFile: [include] error: "
1814 "'%s' is not a regular file\n"), newfile
.c_str());
1818 if (! feof(submenufile
)) {
1819 if (! parseMenuFile(submenufile
, menu
))
1820 blackbox
->addMenuTimestamp(newfile
);
1822 fclose(submenufile
);
1825 perror(newfile
.c_str());
1831 case 767: // submenu
1834 fprintf(stderr
, i18n(ScreenSet
, ScreenSUBMENUError
,
1835 "BScreen::parseMenuFile: [submenu] error, "
1836 "no menu label defined\n"));
1840 Rootmenu
*submenu
= new Rootmenu(this);
1843 submenu
->setLabel(command
);
1845 submenu
->setLabel(label
);
1847 parseMenuFile(file
, submenu
);
1849 menu
->insert(label
, submenu
);
1850 rootmenuList
.push_back(submenu
);
1855 case 773: // restart
1858 fprintf(stderr
, i18n(ScreenSet
, ScreenRESTARTError
,
1859 "BScreen::parseMenuFile: [restart] error, "
1860 "no menu label defined\n"));
1865 menu
->insert(label
, BScreen::RestartOther
, command
);
1867 menu
->insert(label
, BScreen::Restart
);
1872 case 845: // reconfig
1876 i18n(ScreenSet
, ScreenRECONFIGError
,
1877 "BScreen::parseMenuFile: [reconfig] error, "
1878 "no menu label defined\n"));
1882 menu
->insert(label
, BScreen::Reconfigure
);
1887 case 995: // stylesdir
1888 case 1113: // stylesmenu
1890 bool newmenu
= ((key
== 1113) ? True
: False
);
1892 if ((! *label
) || ((! *command
) && newmenu
)) {
1894 i18n(ScreenSet
, ScreenSTYLESDIRError
,
1895 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1896 " error, no directory defined\n"));
1900 char *directory
= ((newmenu
) ? command
: label
);
1902 string stylesdir
= expandTilde(directory
);
1904 struct stat statbuf
;
1906 if (! stat(stylesdir
.c_str(), &statbuf
)) {
1907 if (S_ISDIR(statbuf
.st_mode
)) {
1908 Rootmenu
*stylesmenu
;
1911 stylesmenu
= new Rootmenu(this);
1915 DIR *d
= opendir(stylesdir
.c_str());
1917 std::vector
<string
> ls
;
1919 while((p
= readdir(d
)))
1920 ls
.push_back(p
->d_name
);
1924 std::sort(ls
.begin(), ls
.end());
1926 std::vector
<string
>::iterator it
= ls
.begin(),
1928 for (; it
!= end
; ++it
) {
1929 const string
& fname
= *it
;
1931 if (fname
[fname
.size()-1] == '~')
1934 string style
= stylesdir
;
1938 if ((! stat(style
.c_str(), &statbuf
)) &&
1939 S_ISREG(statbuf
.st_mode
))
1940 stylesmenu
->insert(fname
, BScreen::SetStyle
, style
);
1943 stylesmenu
->update();
1946 stylesmenu
->setLabel(label
);
1947 menu
->insert(label
, stylesmenu
);
1948 rootmenuList
.push_back(stylesmenu
);
1951 blackbox
->addMenuTimestamp(stylesdir
);
1954 i18n(ScreenSet
, ScreenSTYLESDIRErrorNotDir
,
1955 "BScreen::parseMenuFile:"
1956 " [stylesdir/stylesmenu] error, %s is not a"
1957 " directory\n"), stylesdir
.c_str());
1961 i18n(ScreenSet
, ScreenSTYLESDIRErrorNoExist
,
1962 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1963 " error, %s does not exist\n"), stylesdir
.c_str());
1968 case 1090: // workspaces
1972 i18n(ScreenSet
, ScreenWORKSPACESError
,
1973 "BScreen:parseMenuFile: [workspaces] error, "
1974 "no menu label defined\n"));
1978 menu
->insert(label
, workspacemenu
);
1987 return ((menu
->getCount() == 0) ? True
: False
);
1991 void BScreen::shutdown(void) {
1992 XSelectInput(blackbox
->getXDisplay(), getRootWindow(), NoEventMask
);
1993 XSync(blackbox
->getXDisplay(), False
);
1995 while(! windowList
.empty())
1996 unmanageWindow(windowList
.front(), True
);
2002 void BScreen::showPosition(int x
, int y
) {
2003 if (! geom_visible
) {
2004 XMoveResizeWindow(blackbox
->getXDisplay(), geom_window
,
2005 (getWidth() - geom_w
) / 2,
2006 (getHeight() - geom_h
) / 2, geom_w
, geom_h
);
2007 XMapWindow(blackbox
->getXDisplay(), geom_window
);
2008 XRaiseWindow(blackbox
->getXDisplay(), geom_window
);
2010 geom_visible
= True
;
2015 sprintf(label
, i18n(ScreenSet
, ScreenPositionFormat
,
2016 "X: %4d x Y: %4d"), x
, y
);
2018 XClearWindow(blackbox
->getXDisplay(), geom_window
);
2020 BPen
pen(resource
.wstyle
.l_text_focus
, resource
.wstyle
.font
);
2021 if (i18n
.multibyte()) {
2022 XmbDrawString(blackbox
->getXDisplay(), geom_window
,
2023 resource
.wstyle
.fontset
, pen
.gc(),
2024 resource
.bevel_width
, resource
.bevel_width
-
2025 resource
.wstyle
.fontset_extents
->max_ink_extent
.y
,
2026 label
, strlen(label
));
2028 XDrawString(blackbox
->getXDisplay(), geom_window
,
2029 pen
.gc(), resource
.bevel_width
,
2030 resource
.wstyle
.font
->ascent
+ resource
.bevel_width
,
2031 label
, strlen(label
));
2036 void BScreen::showGeometry(unsigned int gx
, unsigned int gy
) {
2037 if (! geom_visible
) {
2038 XMoveResizeWindow(blackbox
->getXDisplay(), geom_window
,
2039 (getWidth() - geom_w
) / 2,
2040 (getHeight() - geom_h
) / 2, geom_w
, geom_h
);
2041 XMapWindow(blackbox
->getXDisplay(), geom_window
);
2042 XRaiseWindow(blackbox
->getXDisplay(), geom_window
);
2044 geom_visible
= True
;
2049 sprintf(label
, i18n(ScreenSet
, ScreenGeometryFormat
,
2050 "W: %4d x H: %4d"), gx
, gy
);
2052 XClearWindow(blackbox
->getXDisplay(), geom_window
);
2054 BPen
pen(resource
.wstyle
.l_text_focus
, resource
.wstyle
.font
);
2055 if (i18n
.multibyte()) {
2056 XmbDrawString(blackbox
->getXDisplay(), geom_window
,
2057 resource
.wstyle
.fontset
, pen
.gc(),
2058 resource
.bevel_width
, resource
.bevel_width
-
2059 resource
.wstyle
.fontset_extents
->max_ink_extent
.y
,
2060 label
, strlen(label
));
2062 XDrawString(blackbox
->getXDisplay(), geom_window
,
2063 pen
.gc(), resource
.bevel_width
,
2064 resource
.wstyle
.font
->ascent
+
2065 resource
.bevel_width
, label
, strlen(label
));
2070 void BScreen::hideGeometry(void) {
2072 XUnmapWindow(blackbox
->getXDisplay(), geom_window
);
2073 geom_visible
= False
;
2078 void BScreen::addStrut(Strut
*strut
) {
2079 strutList
.push_back(strut
);
2083 void BScreen::removeStrut(Strut
*strut
) {
2084 strutList
.remove(strut
);
2088 const Rect
& BScreen::availableArea(void) const {
2090 return getRect(); // return the full screen
2095 void BScreen::updateAvailableArea(void) {
2096 Rect old_area
= usableArea
;
2097 usableArea
= getRect(); // reset to full screen
2099 /* these values represent offsets from the screen edge
2100 * we look for the biggest offset on each edge and then apply them
2102 * do not be confused by the similarity to the names of Rect's members
2104 unsigned int current_left
= 0, current_right
= 0, current_top
= 0,
2107 StrutList::const_iterator it
= strutList
.begin(), end
= strutList
.end();
2109 for(; it
!= end
; ++it
) {
2111 if (strut
->left
> current_left
)
2112 current_left
= strut
->left
;
2113 if (strut
->top
> current_top
)
2114 current_top
= strut
->top
;
2115 if (strut
->right
> current_right
)
2116 current_right
= strut
->right
;
2117 if (strut
->bottom
> current_bottom
)
2118 current_bottom
= strut
->bottom
;
2121 usableArea
.setPos(current_left
, current_top
);
2122 usableArea
.setSize(usableArea
.width() - (current_left
+ current_right
),
2123 usableArea
.height() - (current_top
+ current_bottom
));
2125 if (old_area
!= usableArea
) {
2126 BlackboxWindowList::iterator it
= windowList
.begin(),
2127 end
= windowList
.end();
2128 for (; it
!= end
; ++it
)
2129 if ((*it
)->isMaximized()) (*it
)->remaximize();
2136 Workspace
* BScreen::getWorkspace(unsigned int index
) {
2137 assert(index
< workspacesList
.size());
2138 return workspacesList
[index
];
2142 void BScreen::buttonPressEvent(XButtonEvent
*xbutton
) {
2143 if (xbutton
->button
== 1) {
2144 if (! isRootColormapInstalled())
2145 image_control
->installRootColormap();
2147 if (workspacemenu
->isVisible())
2148 workspacemenu
->hide();
2150 if (rootmenu
->isVisible())
2152 } else if (xbutton
->button
== 2) {
2153 int mx
= xbutton
->x_root
- (workspacemenu
->getWidth() / 2);
2154 int my
= xbutton
->y_root
- (workspacemenu
->getTitleHeight() / 2);
2159 if (mx
+ workspacemenu
->getWidth() > getWidth())
2160 mx
= getWidth() - workspacemenu
->getWidth() - getBorderWidth();
2162 if (my
+ workspacemenu
->getHeight() > getHeight())
2163 my
= getHeight() - workspacemenu
->getHeight() - getBorderWidth();
2165 workspacemenu
->move(mx
, my
);
2167 if (! workspacemenu
->isVisible()) {
2168 workspacemenu
->removeParent();
2169 workspacemenu
->show();
2171 } else if (xbutton
->button
== 3) {
2172 int mx
= xbutton
->x_root
- (rootmenu
->getWidth() / 2);
2173 int my
= xbutton
->y_root
- (rootmenu
->getTitleHeight() / 2);
2178 if (mx
+ rootmenu
->getWidth() > getWidth())
2179 mx
= getWidth() - rootmenu
->getWidth() - getBorderWidth();
2181 if (my
+ rootmenu
->getHeight() > getHeight())
2182 my
= getHeight() - rootmenu
->getHeight() - getBorderWidth();
2184 rootmenu
->move(mx
, my
);
2186 if (! rootmenu
->isVisible()) {
2187 blackbox
->checkMenu();
2191 } else if (xbutton
->button
== 4) {
2192 if (getCurrentWorkspaceID() >= getWorkspaceCount() - 1)
2193 changeWorkspaceID(0);
2195 changeWorkspaceID(getCurrentWorkspaceID() + 1);
2197 } else if (xbutton
->button
== 5) {
2198 if (getCurrentWorkspaceID() == 0)
2199 changeWorkspaceID(getWorkspaceCount() - 1);
2201 changeWorkspaceID(getCurrentWorkspaceID() - 1);
2206 void BScreen::toggleFocusModel(FocusModel model
) {
2207 if (model
== SloppyFocus
) {
2208 saveSloppyFocus(True
);
2210 saveSloppyFocus(False
);
2211 saveAutoRaise(False
);
2212 saveClickRaise(False
);
2219 void BScreen::updateFocusModel()
2221 std::for_each(workspacesList
.begin(), workspacesList
.end(),
2222 std::mem_fun(&Workspace::updateFocusModel
));
2226 BTexture
BScreen::readDatabaseTexture(const string
&rname
,
2227 const string
&default_color
,
2228 Configuration
&style
) {
2232 if (style
.getValue(rname
, s
))
2233 texture
= BTexture(s
);
2235 texture
.setTexture(BTexture::Solid
| BTexture::Flat
);
2237 // associate this texture with this screen
2238 texture
.setDisplay(getBaseDisplay(), getScreenNumber());
2239 texture
.setImageControl(image_control
);
2241 if (texture
.texture() & BTexture::Solid
) {
2242 texture
.setColor(readDatabaseColor(rname
+ ".color",
2243 default_color
, style
));
2244 texture
.setColorTo(readDatabaseColor(rname
+ ".colorTo",
2245 default_color
, style
));
2246 } else if (texture
.texture() & BTexture::Gradient
) {
2247 texture
.setColor(readDatabaseColor(rname
+ ".color",
2248 default_color
, style
));
2249 texture
.setColorTo(readDatabaseColor(rname
+ ".colorTo",
2250 default_color
, style
));
2257 BColor
BScreen::readDatabaseColor(const string
&rname
,
2258 const string
&default_color
,
2259 Configuration
&style
) {
2262 if (style
.getValue(rname
, s
))
2263 color
= BColor(s
, getBaseDisplay(), getScreenNumber());
2265 color
= BColor(default_color
, getBaseDisplay(), getScreenNumber());
2270 XFontSet
BScreen::readDatabaseFontSet(const string
&rname
,
2271 Configuration
&style
) {
2272 char *defaultFont
= "fixed";
2274 bool load_default
= True
;
2276 XFontSet fontset
= 0;
2277 if (style
.getValue(rname
, s
) && (fontset
= createFontSet(s
)))
2278 load_default
= False
;
2281 fontset
= createFontSet(defaultFont
);
2285 i18n(ScreenSet
, ScreenDefaultFontLoadFail
,
2286 "BScreen::setCurrentStyle(): couldn't load default font.\n"));
2295 XFontStruct
*BScreen::readDatabaseFont(const string
&rname
,
2296 Configuration
&style
) {
2297 char *defaultFont
= "fixed";
2299 bool load_default
= False
;
2301 XFontStruct
*font
= 0;
2302 if (style
.getValue(rname
, s
)) {
2303 if ((font
= XLoadQueryFont(blackbox
->getXDisplay(), s
.c_str())) == NULL
) {
2305 i18n(ScreenSet
, ScreenFontLoadFail
,
2306 "BScreen::setCurrentStyle(): couldn't load font '%s'\n"),
2309 load_default
= True
;
2312 load_default
= True
;
2316 font
= XLoadQueryFont(blackbox
->getXDisplay(), defaultFont
);
2319 i18n(ScreenSet
, ScreenDefaultFontLoadFail
,
2320 "BScreen::setCurrentStyle(): couldn't load default font.\n"));
2329 #ifndef HAVE_STRCASESTR
2330 static const char * strcasestr(const char *str
, const char *ptn
) {
2331 const char *s2
, *p2
;
2332 for(; *str
; str
++) {
2333 for(s2
=str
,p2
=ptn
; ; s2
++,p2
++) {
2334 if (! *p2
) return str
;
2335 if (toupper(*s2
) != toupper(*p2
)) break;
2340 #endif // HAVE_STRCASESTR
2343 static const char *getFontElement(const char *pattern
, char *buf
,
2349 va_start(va
, bufsiz
);
2351 buf
[bufsiz
-2] = '*';
2352 while((v
= va_arg(va
, char *)) != NULL
) {
2353 p
= strcasestr(pattern
, v
);
2355 strncpy(buf
, p
+1, bufsiz
-2);
2356 p2
= strchr(buf
, '-');
2363 strncpy(buf
, "*", bufsiz
);
2368 static const char *getFontSize(const char *pattern
, int *size
) {
2370 const char *p2
=NULL
;
2373 for (p
=pattern
; 1; p
++) {
2375 if (p2
!=NULL
&& n
>1 && n
<72) {
2376 *size
= n
; return p2
+1;
2378 *size
= 16; return NULL
;
2380 } else if (*p
=='-') {
2381 if (n
>1 && n
<72 && p2
!=NULL
) {
2386 } else if (*p
>='0' && *p
<='9' && p2
!=NULL
) {
2396 XFontSet
BScreen::createFontSet(const string
&fontname
) {
2398 char **missing
, *def
= "-";
2399 int nmissing
, pixel_size
= 0, buf_size
= 0;
2400 char weight
[FONT_ELEMENT_SIZE
], slant
[FONT_ELEMENT_SIZE
];
2402 fs
= XCreateFontSet(blackbox
->getXDisplay(),
2403 fontname
.c_str(), &missing
, &nmissing
, &def
);
2404 if (fs
&& (! nmissing
))
2407 const char *nfontname
= fontname
.c_str();
2408 #ifdef HAVE_SETLOCALE
2410 if (nmissing
) XFreeStringList(missing
);
2412 setlocale(LC_CTYPE
, "C");
2413 fs
= XCreateFontSet(blackbox
->getXDisplay(), fontname
.c_str(),
2414 &missing
, &nmissing
, &def
);
2415 setlocale(LC_CTYPE
, "");
2417 #endif // HAVE_SETLOCALE
2420 XFontStruct
**fontstructs
;
2422 XFontsOfFontSet(fs
, &fontstructs
, &fontnames
);
2423 nfontname
= fontnames
[0];
2426 getFontElement(nfontname
, weight
, FONT_ELEMENT_SIZE
,
2427 "-medium-", "-bold-", "-demibold-", "-regular-", NULL
);
2428 getFontElement(nfontname
, slant
, FONT_ELEMENT_SIZE
,
2429 "-r-", "-i-", "-o-", "-ri-", "-ro-", NULL
);
2430 getFontSize(nfontname
, &pixel_size
);
2432 if (! strcmp(weight
, "*"))
2433 strncpy(weight
, "medium", FONT_ELEMENT_SIZE
);
2434 if (! strcmp(slant
, "*"))
2435 strncpy(slant
, "r", FONT_ELEMENT_SIZE
);
2438 else if (pixel_size
> 97)
2441 buf_size
= strlen(nfontname
) + (FONT_ELEMENT_SIZE
* 2) + 64;
2442 char *pattern2
= new char[buf_size
];
2445 "-*-*-%s-%s-*-*-%d-*-*-*-*-*-*-*,"
2446 "-*-*-*-*-*-*-%d-*-*-*-*-*-*-*,*",
2447 nfontname
, weight
, slant
, pixel_size
, pixel_size
);
2448 nfontname
= pattern2
;
2451 XFreeStringList(missing
);
2453 XFreeFontSet(blackbox
->getXDisplay(), fs
);
2455 fs
= XCreateFontSet(blackbox
->getXDisplay(), nfontname
, &missing
,