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>
32 #endif // HAVE_STDLIB_H
36 #endif // HAVE_STRING_H
40 #endif // HAVE_CTYPE_H
43 # include <sys/types.h>
45 #endif // HAVE_UNISTD_H
49 #endif // HAVE_DIRENT_H
53 #endif // HAVE_LOCALE_H
55 #ifdef HAVE_SYS_STAT_H
56 # include <sys/stat.h>
57 #endif // HAVE_SYS_STAT_H
61 #endif // HAVE_STDARG_H
72 #include "blackbox.hh"
73 #include "Clientmenu.hh"
76 #include "Iconmenu.hh"
80 #include "Rootmenu.hh"
84 #include "Workspace.hh"
85 #include "Workspacemenu.hh"
88 #ifndef FONT_ELEMENT_SIZE
89 #define FONT_ELEMENT_SIZE 50
90 #endif // FONT_ELEMENT_SIZE
93 static bool running
= True
;
95 static int anotherWMRunning(Display
*display
, XErrorEvent
*) {
96 fprintf(stderr
, i18n(ScreenSet
, ScreenAnotherWMRunning
,
97 "BScreen::BScreen: an error occured while querying the X server.\n"
98 " another window manager already running on display %s.\n"),
99 DisplayString(display
));
107 BScreen::BScreen(Blackbox
*bb
, unsigned int scrn
) : ScreenInfo(bb
, scrn
) {
109 screenstr
= (string
)"session.screen" + itostring(scrn
) + '.';
110 config
= blackbox
->getConfig();
111 xatom
= blackbox
->getXAtom();
113 event_mask
= ColormapChangeMask
| EnterWindowMask
| PropertyChangeMask
|
114 SubstructureRedirectMask
| ButtonPressMask
| ButtonReleaseMask
;
116 XErrorHandler old
= XSetErrorHandler((XErrorHandler
) anotherWMRunning
);
117 XSelectInput(getBaseDisplay()->getXDisplay(), getRootWindow(), event_mask
);
118 XSync(getBaseDisplay()->getXDisplay(), False
);
119 XSetErrorHandler((XErrorHandler
) old
);
122 if (! managed
) return;
124 fprintf(stderr
, i18n(ScreenSet
, ScreenManagingScreen
,
125 "BScreen::BScreen: managing screen %d "
126 "using visual 0x%lx, depth %d\n"),
127 getScreenNumber(), XVisualIDFromVisual(getVisual()),
132 resource
.mstyle
.t_font
= resource
.mstyle
.f_font
= resource
.tstyle
.font
=
133 resource
.wstyle
.font
= (BFont
*) 0;
135 xatom
->setSupported(this); // set-up netwm support
137 xatom
->setValue(getRootWindow(), XAtom::blackbox_pid
, XAtom::cardinal
,
138 (unsigned long) getpid());
139 #endif // HAVE_GETPID
140 unsigned long geometry
[] = { getWidth(),
142 xatom
->setValue(getRootWindow(), XAtom::net_desktop_geometry
,
143 XAtom::cardinal
, geometry
, 2);
144 unsigned long viewport
[] = {0,0};
145 xatom
->setValue(getRootWindow(), XAtom::net_desktop_viewport
,
146 XAtom::cardinal
, viewport
, 2);
149 XDefineCursor(blackbox
->getXDisplay(), getRootWindow(),
150 blackbox
->getSessionCursor());
152 // start off full screen, top left.
153 usableArea
.setSize(getWidth(), getHeight());
156 new BImageControl(blackbox
, this, True
, blackbox
->getColorsPerChannel(),
157 blackbox
->getCacheLife(), blackbox
->getCacheMax());
158 image_control
->installRootColormap();
159 root_colormap_installed
= True
;
165 gcv
.foreground
= WhitePixel(blackbox
->getXDisplay(), getScreenNumber())
166 ^ BlackPixel(blackbox
->getXDisplay(), getScreenNumber());
167 gcv
.function
= GXxor
;
168 gcv
.subwindow_mode
= IncludeInferiors
;
169 opGC
= XCreateGC(blackbox
->getXDisplay(), getRootWindow(),
170 GCForeground
| GCFunction
| GCSubwindowMode
, &gcv
);
172 const char *s
= i18n(ScreenSet
, ScreenPositionLength
,
173 "0: 0000 x 0: 0000");
174 geom_w
= resource
.wstyle
.font
->measureString(s
) + resource
.bevel_width
* 2;
175 geom_h
= resource
.wstyle
.font
->height() + resource
.bevel_width
* 2;
177 XSetWindowAttributes attrib
;
178 unsigned long mask
= CWBorderPixel
| CWColormap
| CWSaveUnder
;
179 attrib
.border_pixel
= getBorderColor()->pixel();
180 attrib
.colormap
= getColormap();
181 attrib
.save_under
= True
;
183 geom_window
= XCreateWindow(blackbox
->getXDisplay(), getRootWindow(),
184 0, 0, geom_w
, geom_h
, resource
.border_width
,
185 getDepth(), InputOutput
, getVisual(),
187 geom_visible
= False
;
189 BTexture
* texture
= &(resource
.wstyle
.l_focus
);
190 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
191 if (geom_pixmap
== ParentRelative
) {
192 texture
= &(resource
.wstyle
.t_focus
);
193 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
196 XSetWindowBackground(blackbox
->getXDisplay(), geom_window
,
197 texture
->color().pixel());
199 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
200 geom_window
, geom_pixmap
);
202 workspacemenu
= new Workspacemenu(this);
203 iconmenu
= new Iconmenu(this);
204 configmenu
= new Configmenu(this);
206 Workspace
*wkspc
= (Workspace
*) 0;
207 if (resource
.workspaces
!= 0) {
208 for (unsigned int i
= 0; i
< resource
.workspaces
; ++i
) {
209 wkspc
= new Workspace(this, workspacesList
.size());
210 workspacesList
.push_back(wkspc
);
211 workspacemenu
->insert(wkspc
->getName(), wkspc
->getMenu());
214 wkspc
= new Workspace(this, workspacesList
.size());
215 workspacesList
.push_back(wkspc
);
216 workspacemenu
->insert(wkspc
->getName(), wkspc
->getMenu());
218 saveWorkspaceNames();
220 updateNetizenWorkspaceCount();
222 workspacemenu
->insert(i18n(IconSet
, IconIcons
, "Icons"), iconmenu
);
223 workspacemenu
->update();
225 current_workspace
= workspacesList
.front();
227 xatom
->setValue(getRootWindow(), XAtom::net_current_desktop
,
228 XAtom::cardinal
, 0); //first workspace
230 workspacemenu
->setItemSelected(2, True
);
232 toolbar
= new Toolbar(this);
234 slit
= new Slit(this);
238 raiseWindows(0, 0); // this also initializes the empty stacking list
241 updateClientList(); // initialize the client list, which will be empty
242 updateAvailableArea();
244 changeWorkspaceID(0);
246 unsigned int i
, j
, nchild
;
247 Window r
, p
, *children
;
248 XQueryTree(blackbox
->getXDisplay(), getRootWindow(), &r
, &p
,
251 // preen the window list of all icon windows... for better dockapp support
252 for (i
= 0; i
< nchild
; i
++) {
253 if (children
[i
] == None
) continue;
255 XWMHints
*wmhints
= XGetWMHints(blackbox
->getXDisplay(),
259 if ((wmhints
->flags
& IconWindowHint
) &&
260 (wmhints
->icon_window
!= children
[i
])) {
261 for (j
= 0; j
< nchild
; j
++) {
262 if (children
[j
] == wmhints
->icon_window
) {
273 // manage shown windows
274 for (i
= 0; i
< nchild
; ++i
) {
275 if (children
[i
] == None
|| (! blackbox
->validateWindow(children
[i
])))
278 XWindowAttributes attrib
;
279 if (XGetWindowAttributes(blackbox
->getXDisplay(), children
[i
], &attrib
)) {
280 if (attrib
.override_redirect
) continue;
282 if (attrib
.map_state
!= IsUnmapped
) {
283 manageWindow(children
[i
]);
290 // call this again just in case a window we found updates the Strut list
291 updateAvailableArea();
295 BScreen::~BScreen(void) {
296 if (! managed
) return;
298 if (geom_pixmap
!= None
)
299 image_control
->removeImage(geom_pixmap
);
301 if (geom_window
!= None
)
302 XDestroyWindow(blackbox
->getXDisplay(), geom_window
);
304 std::for_each(workspacesList
.begin(), workspacesList
.end(),
307 std::for_each(iconList
.begin(), iconList
.end(), PointerAssassin());
309 std::for_each(netizenList
.begin(), netizenList
.end(), PointerAssassin());
312 delete workspacemenu
;
317 delete image_control
;
319 if (resource
.wstyle
.font
)
320 delete resource
.wstyle
.font
;
321 if (resource
.mstyle
.t_font
)
322 delete resource
.mstyle
.t_font
;
323 if (resource
.mstyle
.f_font
)
324 delete resource
.mstyle
.f_font
;
325 if (resource
.tstyle
.font
)
326 delete resource
.tstyle
.font
;
328 XFreeGC(blackbox
->getXDisplay(), opGC
);
332 void BScreen::saveSloppyFocus(bool s
) {
333 resource
.sloppy_focus
= s
;
336 if (resource
.sloppy_focus
) {
337 fmodel
= "SloppyFocus";
338 if (resource
.auto_raise
) fmodel
+= " AutoRaise";
339 if (resource
.click_raise
) fmodel
+= " ClickRaise";
341 fmodel
= "ClickToFocus";
343 config
->setValue(screenstr
+ "focusModel", fmodel
);
347 void BScreen::saveAutoRaise(bool a
) {
348 resource
.auto_raise
= a
;
349 saveSloppyFocus(resource
.sloppy_focus
);
353 void BScreen::saveClickRaise(bool c
) {
354 resource
.click_raise
= c
;
355 saveSloppyFocus(resource
.sloppy_focus
);
359 void BScreen::saveImageDither(bool d
) {
360 image_control
->setDither(d
);
361 config
->setValue(screenstr
+ "imageDither", doImageDither());
365 void BScreen::saveOpaqueMove(bool o
) {
366 resource
.opaque_move
= o
;
367 config
->setValue(screenstr
+ "opaqueMove", resource
.opaque_move
);
371 void BScreen::saveFullMax(bool f
) {
372 resource
.full_max
= f
;
373 config
->setValue(screenstr
+ "fullMaximization", resource
.full_max
);
377 void BScreen::saveFocusNew(bool f
) {
378 resource
.focus_new
= f
;
379 config
->setValue(screenstr
+ "focusNewWindows", resource
.focus_new
);
383 void BScreen::saveFocusLast(bool f
) {
384 resource
.focus_last
= f
;
385 config
->setValue(screenstr
+ "focusLastWindow", resource
.focus_last
);
389 void BScreen::saveHideToolbar(bool h
) {
390 resource
.hide_toolbar
= h
;
391 if (resource
.hide_toolbar
)
392 toolbar
->unmapToolbar();
394 toolbar
->mapToolbar();
395 config
->setValue(screenstr
+ "hideToolbar", resource
.hide_toolbar
);
399 void BScreen::saveWindowToWindowSnap(bool s
) {
400 resource
.window_to_window_snap
= s
;
401 config
->setValue(screenstr
+ "windowToWindowSnap",
402 resource
.window_to_window_snap
);
406 void BScreen::saveWindowCornerSnap(bool s
) {
407 resource
.window_corner_snap
= s
;
408 config
->setValue(screenstr
+ "windowCornerSnap",
409 resource
.window_corner_snap
);
413 void BScreen::saveWorkspaces(unsigned int w
) {
414 resource
.workspaces
= w
;
415 config
->setValue(screenstr
+ "workspaces", resource
.workspaces
);
419 void BScreen::savePlacementPolicy(int p
) {
420 resource
.placement_policy
= p
;
421 const char *placement
;
422 switch (resource
.placement_policy
) {
423 case CascadePlacement
: placement
= "CascadePlacement"; break;
424 case ColSmartPlacement
: placement
= "ColSmartPlacement"; break;
425 case RowSmartPlacement
: default: placement
= "RowSmartPlacement"; break;
427 config
->setValue(screenstr
+ "windowPlacement", placement
);
431 void BScreen::saveEdgeSnapThreshold(int t
) {
432 resource
.edge_snap_threshold
= t
;
433 config
->setValue(screenstr
+ "edgeSnapThreshold",
434 resource
.edge_snap_threshold
);
438 void BScreen::saveRowPlacementDirection(int d
) {
439 resource
.row_direction
= d
;
440 config
->setValue(screenstr
+ "rowPlacementDirection",
441 resource
.row_direction
== LeftRight
?
442 "LeftToRight" : "RightToLeft");
446 void BScreen::saveColPlacementDirection(int d
) {
447 resource
.col_direction
= d
;
448 config
->setValue(screenstr
+ "colPlacementDirection",
449 resource
.col_direction
== TopBottom
?
450 "TopToBottom" : "BottomToTop");
455 void BScreen::saveStrftimeFormat(const std::string
& format
) {
456 resource
.strftime_format
= format
;
457 config
->setValue(screenstr
+ "strftimeFormat", resource
.strftime_format
);
460 #else // !HAVE_STRFTIME
462 void BScreen::saveDateFormat(int f
) {
463 resource
.date_format
= f
;
464 config
->setValue(screenstr
+ "dateFormat",
465 resource
.date_format
== B_EuropeanDate
?
466 "European" : "American");
470 void BScreen::saveClock24Hour(Bool c
) {
471 resource
.clock24hour
= c
;
472 config
->setValue(screenstr
+ "clockFormat", resource
.clock24hour
? 24 : 12);
474 #endif // HAVE_STRFTIME
477 void BScreen::saveWorkspaceNames() {
478 XAtom::StringVect nameList
;
479 unsigned long numnames
= (unsigned) -1;
483 xatom
->getValue(getRootWindow(), XAtom::net_desktop_names
, XAtom::utf8
,
484 numnames
, nameList
)) {
485 for (unsigned int i
= 0; i
< nameList
.size(); ++i
) {
486 if (i
> 0) names
+= ",";
487 names
+= nameList
[i
];
490 config
->setValue(screenstr
+ "workspaceNames", names
);
494 void BScreen::save_rc(void) {
495 saveSloppyFocus(resource
.sloppy_focus
);
496 saveAutoRaise(resource
.auto_raise
);
497 saveImageDither(doImageDither());
498 saveOpaqueMove(resource
.opaque_move
);
499 saveFullMax(resource
.full_max
);
500 saveFocusNew(resource
.focus_new
);
501 saveFocusLast(resource
.focus_last
);
502 saveHideToolbar(resource
.hide_toolbar
);
503 saveWindowToWindowSnap(resource
.window_to_window_snap
);
504 saveWindowCornerSnap(resource
.window_corner_snap
);
505 saveWorkspaces(resource
.workspaces
);
506 savePlacementPolicy(resource
.placement_policy
);
507 saveEdgeSnapThreshold(resource
.edge_snap_threshold
);
508 saveRowPlacementDirection(resource
.row_direction
);
509 saveColPlacementDirection(resource
.col_direction
);
511 saveStrftimeFormat(resource
.strftime_format
);
512 #else // !HAVE_STRFTIME
513 saveDateFormat(resource
.date_format
);
514 savwClock24Hour(resource
.clock24hour
);
515 #endif // HAVE_STRFTIME
522 void BScreen::load_rc(void) {
526 if (! config
->getValue(screenstr
+ "fullMaximization", resource
.full_max
))
527 resource
.full_max
= false;
529 if (! config
->getValue(screenstr
+ "focusNewWindows", resource
.focus_new
))
530 resource
.focus_new
= false;
532 if (! config
->getValue(screenstr
+ "focusLastWindow", resource
.focus_last
))
533 resource
.focus_last
= false;
535 if (! config
->getValue(screenstr
+ "workspaces", resource
.workspaces
))
536 resource
.workspaces
= 1;
538 if (! config
->getValue(screenstr
+ "opaqueMove", resource
.opaque_move
))
539 resource
.opaque_move
= false;
541 if (! config
->getValue(screenstr
+ "hideToolbar", resource
.hide_toolbar
))
542 resource
.hide_toolbar
= false;
544 if (! config
->getValue(screenstr
+ "windowToWindowSnap",
545 resource
.window_to_window_snap
))
546 resource
.window_to_window_snap
= true;
548 if (! config
->getValue(screenstr
+ "windowCornerSnap",
549 resource
.window_corner_snap
))
550 resource
.window_corner_snap
= true;
552 if (! config
->getValue(screenstr
+ "imageDither", b
))
554 image_control
->setDither(b
);
556 if (! config
->getValue(screenstr
+ "edgeSnapThreshold",
557 resource
.edge_snap_threshold
))
558 resource
.edge_snap_threshold
= 4;
560 if (config
->getValue(screenstr
+ "rowPlacementDirection", s
) &&
562 resource
.row_direction
= RightLeft
;
564 resource
.row_direction
= LeftRight
;
566 if (config
->getValue(screenstr
+ "colPlacementDirection", s
) &&
568 resource
.col_direction
= BottomTop
;
570 resource
.col_direction
= TopBottom
;
572 XAtom::StringVect workspaceNames
;
573 if (config
->getValue(screenstr
+ "workspaceNames", s
)) {
574 string::const_iterator it
= s
.begin(), end
= s
.end();
576 string::const_iterator tmp
= it
; // current string.begin()
577 it
= std::find(tmp
, end
, ','); // look for comma between tmp and end
578 workspaceNames
.push_back(string(tmp
, it
)); // s[tmp:it]
584 xatom
->setValue(getRootWindow(), XAtom::net_desktop_names
, XAtom::utf8
,
587 resource
.sloppy_focus
= true;
588 resource
.auto_raise
= false;
589 resource
.click_raise
= false;
590 if (config
->getValue(screenstr
+ "focusModel", s
)) {
591 if (s
.find("ClickToFocus") != string::npos
) {
592 resource
.sloppy_focus
= false;
595 if (s
.find("AutoRaise") != string::npos
)
596 resource
.auto_raise
= true;
597 if (s
.find("ClickRaise") != string::npos
)
598 resource
.click_raise
= true;
602 if (config
->getValue(screenstr
+ "windowPlacement", s
)) {
603 if (s
== "CascadePlacement")
604 resource
.placement_policy
= CascadePlacement
;
605 else if (s
== "ColSmartPlacement")
606 resource
.placement_policy
= ColSmartPlacement
;
607 else //if (s == "RowSmartPlacement")
608 resource
.placement_policy
= RowSmartPlacement
;
610 resource
.placement_policy
= RowSmartPlacement
;
613 if (config
->getValue(screenstr
+ "strftimeFormat", s
))
614 resource
.strftime_format
= s
;
616 resource
.strftime_format
= "%I:%M %p";
617 #else // !HAVE_STRFTIME
620 if (config
->getValue(screenstr
+ "dateFormat", s
) && s
== "European")
621 resource
.date_format
= B_EuropeanDate
;
623 resource
.date_format
= B_AmericanDate
;
625 if (! config
->getValue(screenstr
+ "clockFormat", l
))
627 resource
.clock24hour
= l
== 24;
628 #endif // HAVE_STRFTIME
632 void BScreen::reconfigure(void) {
639 gcv
.foreground
= WhitePixel(blackbox
->getXDisplay(),
641 gcv
.function
= GXinvert
;
642 gcv
.subwindow_mode
= IncludeInferiors
;
643 XChangeGC(blackbox
->getXDisplay(), opGC
,
644 GCForeground
| GCFunction
| GCSubwindowMode
, &gcv
);
646 const char *s
= i18n(ScreenSet
, ScreenPositionLength
,
647 "0: 0000 x 0: 0000");
649 geom_w
= resource
.wstyle
.font
->measureString(s
) + resource
.bevel_width
* 2;
650 geom_h
= resource
.wstyle
.font
->height() + resource
.bevel_width
* 2;
652 BTexture
* texture
= &(resource
.wstyle
.l_focus
);
653 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
654 if (geom_pixmap
== ParentRelative
) {
655 texture
= &(resource
.wstyle
.t_focus
);
656 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
659 XSetWindowBackground(blackbox
->getXDisplay(), geom_window
,
660 texture
->color().pixel());
662 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
663 geom_window
, geom_pixmap
);
665 XSetWindowBorderWidth(blackbox
->getXDisplay(), geom_window
,
666 resource
.border_width
);
667 XSetWindowBorder(blackbox
->getXDisplay(), geom_window
,
668 resource
.border_color
.pixel());
670 workspacemenu
->reconfigure();
671 iconmenu
->reconfigure();
673 typedef std::vector
<int> SubList
;
674 SubList remember_subs
;
676 // save the current open menus
677 Basemenu
*menu
= rootmenu
;
679 while ((submenu
= menu
->getCurrentSubmenu()) >= 0) {
680 remember_subs
.push_back(submenu
);
681 menu
= menu
->find(submenu
)->submenu();
687 rootmenu
->reconfigure();
689 // reopen the saved menus
691 const SubList::iterator subs_end
= remember_subs
.end();
692 for (SubList::iterator it
= remember_subs
.begin(); it
!= subs_end
; ++it
) {
693 menu
->drawSubmenu(*it
);
694 menu
= menu
->find(*it
)->submenu();
699 configmenu
->reconfigure();
701 toolbar
->reconfigure();
705 std::for_each(workspacesList
.begin(), workspacesList
.end(),
706 std::mem_fun(&Workspace::reconfigure
));
708 BlackboxWindowList::iterator iit
= iconList
.begin();
709 for (; iit
!= iconList
.end(); ++iit
) {
710 BlackboxWindow
*bw
= *iit
;
711 if (bw
->validateClient())
715 image_control
->timeout();
719 void BScreen::rereadMenu(void) {
723 rootmenu
->reconfigure();
727 void BScreen::LoadStyle(void) {
730 const char *sfile
= blackbox
->getStyleFilename();
732 style
.setFile(sfile
);
733 if (! style
.load()) {
734 style
.setFile(DEFAULTSTYLE
);
736 style
.create(); // hardcoded default values will be used.
742 // load fonts/fontsets
743 if (resource
.wstyle
.font
)
744 delete resource
.wstyle
.font
;
745 if (resource
.tstyle
.font
)
746 delete resource
.tstyle
.font
;
747 if (resource
.mstyle
.f_font
)
748 delete resource
.mstyle
.f_font
;
749 if (resource
.mstyle
.t_font
)
750 delete resource
.mstyle
.t_font
;
751 resource
.wstyle
.font
= resource
.tstyle
.font
= resource
.mstyle
.f_font
=
752 resource
.mstyle
.t_font
= (BFont
*) 0;
754 resource
.wstyle
.font
= readDatabaseFont("window.font", style
);
755 resource
.tstyle
.font
= readDatabaseFont("toolbar.font", style
);
756 resource
.mstyle
.t_font
= readDatabaseFont("menu.title.font", style
);
757 resource
.mstyle
.f_font
= readDatabaseFont("menu.frame.font", style
);
759 // load window config
760 resource
.wstyle
.t_focus
=
761 readDatabaseTexture("window.title.focus", "white", style
);
762 resource
.wstyle
.t_unfocus
=
763 readDatabaseTexture("window.title.unfocus", "black", style
);
764 resource
.wstyle
.l_focus
=
765 readDatabaseTexture("window.label.focus", "white", style
);
766 resource
.wstyle
.l_unfocus
=
767 readDatabaseTexture("window.label.unfocus", "black", style
);
768 resource
.wstyle
.h_focus
=
769 readDatabaseTexture("window.handle.focus", "white", style
);
770 resource
.wstyle
.h_unfocus
=
771 readDatabaseTexture("window.handle.unfocus", "black", style
);
772 resource
.wstyle
.g_focus
=
773 readDatabaseTexture("window.grip.focus", "white", style
);
774 resource
.wstyle
.g_unfocus
=
775 readDatabaseTexture("window.grip.unfocus", "black", style
);
776 resource
.wstyle
.b_focus
=
777 readDatabaseTexture("window.button.focus", "white", style
);
778 resource
.wstyle
.b_unfocus
=
779 readDatabaseTexture("window.button.unfocus", "black", style
);
780 resource
.wstyle
.b_pressed
=
781 readDatabaseTexture("window.button.pressed", "black", style
);
782 resource
.wstyle
.f_focus
=
783 readDatabaseColor("window.frame.focusColor", "white", style
);
784 resource
.wstyle
.f_unfocus
=
785 readDatabaseColor("window.frame.unfocusColor", "black", style
);
786 resource
.wstyle
.l_text_focus
=
787 readDatabaseColor("window.label.focus.textColor", "black", style
);
788 resource
.wstyle
.l_text_unfocus
=
789 readDatabaseColor("window.label.unfocus.textColor", "white", style
);
790 resource
.wstyle
.b_pic_focus
=
791 readDatabaseColor("window.button.focus.picColor", "black", style
);
792 resource
.wstyle
.b_pic_unfocus
=
793 readDatabaseColor("window.button.unfocus.picColor", "white", style
);
795 resource
.wstyle
.justify
= LeftJustify
;
796 if (style
.getValue("window.justify", s
)) {
797 if (s
== "right" || s
== "Right")
798 resource
.wstyle
.justify
= RightJustify
;
799 else if (s
== "center" || s
== "Center")
800 resource
.wstyle
.justify
= CenterJustify
;
803 // load toolbar config
804 resource
.tstyle
.toolbar
=
805 readDatabaseTexture("toolbar", "black", style
);
806 resource
.tstyle
.label
=
807 readDatabaseTexture("toolbar.label", "black", style
);
808 resource
.tstyle
.window
=
809 readDatabaseTexture("toolbar.windowLabel", "black", style
);
810 resource
.tstyle
.button
=
811 readDatabaseTexture("toolbar.button", "white", style
);
812 resource
.tstyle
.pressed
=
813 readDatabaseTexture("toolbar.button.pressed", "black", style
);
814 resource
.tstyle
.clock
=
815 readDatabaseTexture("toolbar.clock", "black", style
);
816 resource
.tstyle
.l_text
=
817 readDatabaseColor("toolbar.label.textColor", "white", style
);
818 resource
.tstyle
.w_text
=
819 readDatabaseColor("toolbar.windowLabel.textColor", "white", style
);
820 resource
.tstyle
.c_text
=
821 readDatabaseColor("toolbar.clock.textColor", "white", style
);
822 resource
.tstyle
.b_pic
=
823 readDatabaseColor("toolbar.button.picColor", "black", style
);
825 resource
.tstyle
.justify
= LeftJustify
;
826 if (style
.getValue("toolbar.justify", s
)) {
827 if (s
== "right" || s
== "Right")
828 resource
.tstyle
.justify
= RightJustify
;
829 else if (s
== "center" || s
== "Center")
830 resource
.tstyle
.justify
= CenterJustify
;
834 resource
.mstyle
.title
=
835 readDatabaseTexture("menu.title", "white", style
);
836 resource
.mstyle
.frame
=
837 readDatabaseTexture("menu.frame", "black", style
);
838 resource
.mstyle
.hilite
=
839 readDatabaseTexture("menu.hilite", "white", style
);
840 resource
.mstyle
.t_text
=
841 readDatabaseColor("menu.title.textColor", "black", style
);
842 resource
.mstyle
.f_text
=
843 readDatabaseColor("menu.frame.textColor", "white", style
);
844 resource
.mstyle
.d_text
=
845 readDatabaseColor("menu.frame.disableColor", "black", style
);
846 resource
.mstyle
.h_text
=
847 readDatabaseColor("menu.hilite.textColor", "black", style
);
849 resource
.mstyle
.t_justify
= LeftJustify
;
850 if (style
.getValue("menu.title.justify", s
)) {
851 if (s
== "right" || s
== "Right")
852 resource
.mstyle
.t_justify
= RightJustify
;
853 else if (s
== "center" || s
== "Center")
854 resource
.mstyle
.t_justify
= CenterJustify
;
857 resource
.mstyle
.f_justify
= LeftJustify
;
858 if (style
.getValue("menu.frame.justify", s
)) {
859 if (s
== "right" || s
== "Right")
860 resource
.mstyle
.f_justify
= RightJustify
;
861 else if (s
== "center" || s
== "Center")
862 resource
.mstyle
.f_justify
= CenterJustify
;
865 resource
.mstyle
.bullet
= Basemenu::Triangle
;
866 if (style
.getValue("menu.bullet", s
)) {
867 if (s
== "empty" || s
== "Empty")
868 resource
.mstyle
.bullet
= Basemenu::Empty
;
869 else if (s
== "square" || s
== "Square")
870 resource
.mstyle
.bullet
= Basemenu::Square
;
871 else if (s
== "diamond" || s
== "Diamond")
872 resource
.mstyle
.bullet
= Basemenu::Diamond
;
875 resource
.mstyle
.bullet_pos
= Basemenu::Left
;
876 if (style
.getValue("menu.bullet.position", s
)) {
877 if (s
== "right" || s
== "Right")
878 resource
.mstyle
.bullet_pos
= Basemenu::Right
;
881 resource
.border_color
=
882 readDatabaseColor("borderColor", "black", style
);
884 // load bevel, border and handle widths
885 if (! style
.getValue("handleWidth", resource
.handle_width
) ||
886 resource
.handle_width
> (getWidth() / 2) || resource
.handle_width
== 0)
887 resource
.handle_width
= 6;
889 if (! style
.getValue("borderWidth", resource
.border_width
))
890 resource
.border_width
= 1;
892 if (! style
.getValue("bevelWidth", resource
.bevel_width
) ||
893 resource
.bevel_width
> (getWidth() / 2) || resource
.bevel_width
== 0)
894 resource
.bevel_width
= 3;
896 if (! style
.getValue("frameWidth", resource
.frame_width
) ||
897 resource
.frame_width
> (getWidth() / 2))
898 resource
.frame_width
= resource
.bevel_width
;
900 if (style
.getValue("rootCommand", s
))
901 bexec(s
, displayString());
905 void BScreen::addIcon(BlackboxWindow
*w
) {
908 w
->setWorkspace(BSENTINEL
);
909 w
->setWindowNumber(iconList
.size());
911 iconList
.push_back(w
);
913 const char* title
= w
->getIconTitle();
914 iconmenu
->insert(title
);
919 void BScreen::removeIcon(BlackboxWindow
*w
) {
924 iconmenu
->remove(w
->getWindowNumber());
927 BlackboxWindowList::iterator it
= iconList
.begin(),
928 end
= iconList
.end();
929 for (int i
= 0; it
!= end
; ++it
)
930 (*it
)->setWindowNumber(i
++);
934 BlackboxWindow
*BScreen::getIcon(unsigned int index
) {
935 if (index
< iconList
.size()) {
936 BlackboxWindowList::iterator it
= iconList
.begin();
937 for (; index
> 0; --index
, ++it
) ; /* increment to index */
941 return (BlackboxWindow
*) 0;
945 unsigned int BScreen::addWorkspace(void) {
946 Workspace
*wkspc
= new Workspace(this, workspacesList
.size());
947 workspacesList
.push_back(wkspc
);
948 saveWorkspaces(getWorkspaceCount());
950 workspacemenu
->insert(wkspc
->getName(), wkspc
->getMenu(),
952 workspacemenu
->update();
954 toolbar
->reconfigure();
956 updateNetizenWorkspaceCount();
958 return workspacesList
.size();
962 unsigned int BScreen::removeLastWorkspace(void) {
963 if (workspacesList
.size() == 1)
966 Workspace
*wkspc
= workspacesList
.back();
968 if (current_workspace
->getID() == wkspc
->getID())
969 changeWorkspaceID(current_workspace
->getID() - 1);
973 workspacemenu
->remove(wkspc
->getID() + 2);
974 workspacemenu
->update();
976 workspacesList
.pop_back();
979 saveWorkspaces(getWorkspaceCount());
981 toolbar
->reconfigure();
983 updateNetizenWorkspaceCount();
985 return workspacesList
.size();
989 void BScreen::changeWorkspaceID(unsigned int id
) {
990 if (! current_workspace
) return;
992 if (id
!= current_workspace
->getID()) {
993 BlackboxWindow
*focused
= blackbox
->getFocusedWindow();
994 if (focused
&& focused
->getScreen() == this && ! focused
->isStuck()) {
995 if (focused
->getWorkspaceNumber() != current_workspace
->getID()) {
996 fprintf(stderr
, "%s is on the wrong workspace, aborting\n",
997 focused
->getTitle());
1000 current_workspace
->setLastFocusedWindow(focused
);
1002 // if no window had focus, no need to store a last focus
1003 current_workspace
->setLastFocusedWindow((BlackboxWindow
*) 0);
1005 // when we switch workspaces, unfocus whatever was focused
1006 blackbox
->setFocusedWindow((BlackboxWindow
*) 0);
1008 current_workspace
->hideAll();
1009 workspacemenu
->setItemSelected(current_workspace
->getID() + 2, False
);
1011 current_workspace
= getWorkspace(id
);
1013 xatom
->setValue(getRootWindow(), XAtom::net_current_desktop
,
1014 XAtom::cardinal
, id
);
1016 workspacemenu
->setItemSelected(current_workspace
->getID() + 2, True
);
1017 toolbar
->redrawWorkspaceLabel(True
);
1019 current_workspace
->showAll();
1021 if (resource
.focus_last
&& current_workspace
->getLastFocusedWindow()) {
1022 XSync(blackbox
->getXDisplay(), False
);
1023 current_workspace
->getLastFocusedWindow()->setInputFocus();
1027 updateNetizenCurrentWorkspace();
1032 * Set the _NET_CLIENT_LIST root window property.
1034 void BScreen::updateClientList(void) {
1035 if (windowList
.size() > 0) {
1036 Window
*windows
= new Window
[windowList
.size()];
1037 Window
*win_it
= windows
;
1038 BlackboxWindowList::iterator it
= windowList
.begin();
1039 const BlackboxWindowList::iterator end
= windowList
.end();
1040 for (; it
!= end
; ++it
, ++win_it
)
1041 *win_it
= (*it
)->getClientWindow();
1042 xatom
->setValue(getRootWindow(), XAtom::net_client_list
, XAtom::window
,
1043 windows
, windowList
.size());
1046 xatom
->setValue(getRootWindow(), XAtom::net_client_list
, XAtom::window
,
1052 * Set the _NET_CLIENT_LIST_STACKING root window property.
1054 void BScreen::updateStackingList(void) {
1056 BlackboxWindowList stack_order
;
1059 * Get the atacking order from all of the workspaces.
1060 * We start with the current workspace so that the sticky windows will be
1061 * in the right order on the current workspace.
1062 * XXX: Do we need to have sticky windows in the list once for each workspace?
1064 getCurrentWorkspace()->appendStackOrder(stack_order
);
1065 for (unsigned int i
= 0; i
< getWorkspaceCount(); ++i
)
1066 if (i
!= getCurrentWorkspaceID())
1067 getWorkspace(i
)->appendStackOrder(stack_order
);
1069 if (stack_order
.size() > 0) {
1070 // set the client list atoms
1071 Window
*windows
= new Window
[stack_order
.size()];
1072 Window
*win_it
= windows
;
1073 BlackboxWindowList::iterator it
= stack_order
.begin();
1074 const BlackboxWindowList::iterator end
= stack_order
.end();
1075 for (; it
!= end
; ++it
, ++win_it
)
1076 *win_it
= (*it
)->getClientWindow();
1077 xatom
->setValue(getRootWindow(), XAtom::net_client_list_stacking
,
1078 XAtom::window
, windows
, stack_order
.size());
1081 xatom
->setValue(getRootWindow(), XAtom::net_client_list_stacking
,
1082 XAtom::window
, 0, 0);
1086 void BScreen::addSystrayWindow(Window window
) {
1087 systrayWindowList
.push_back(window
);
1088 xatom
->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows
,
1090 &systrayWindowList
[0], systrayWindowList
.size());
1091 blackbox
->saveSystrayWindowSearch(window
, this);
1095 void BScreen::removeSystrayWindow(Window window
) {
1096 WindowList::iterator it
= systrayWindowList
.begin();
1097 const WindowList::iterator end
= systrayWindowList
.end();
1098 for (; it
!= end
; ++it
)
1099 if (*it
== window
) {
1100 systrayWindowList
.erase(it
);
1101 xatom
->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows
,
1103 &systrayWindowList
[0], systrayWindowList
.size());
1104 blackbox
->removeSystrayWindowSearch(window
);
1110 void BScreen::addDesktopWindow(Window window
) {
1111 desktopWindowList
.push_back(window
);
1112 XLowerWindow(blackbox
->getXDisplay(), window
);
1113 XSelectInput(blackbox
->getXDisplay(), window
, StructureNotifyMask
);
1114 blackbox
->saveDesktopWindowSearch(window
, this);
1118 void BScreen::removeDesktopWindow(Window window
) {
1119 WindowList::iterator it
= desktopWindowList
.begin();
1120 const WindowList::iterator end
= desktopWindowList
.end();
1121 for (; it
!= end
; ++it
)
1122 if (*it
== window
) {
1123 desktopWindowList
.erase(it
);
1124 XSelectInput(blackbox
->getXDisplay(), window
, None
);
1125 blackbox
->removeDesktopWindowSearch(window
);
1131 void BScreen::manageWindow(Window w
) {
1132 new BlackboxWindow(blackbox
, w
, this);
1134 BlackboxWindow
*win
= blackbox
->searchWindow(w
);
1137 if (win
->isDesktop()) {
1138 // desktop windows cant do anything, so we remove all the normal window
1139 // stuff from them, they are only kept around so that we can keep them on
1140 // the bottom of the z-order
1142 addDesktopWindow(win
->getClientWindow());
1147 windowList
.push_back(win
);
1150 XMapRequestEvent mre
;
1152 if (blackbox
->isStartup()) win
->restoreAttributes();
1153 win
->mapRequestEvent(&mre
);
1157 void BScreen::unmanageWindow(BlackboxWindow
*w
, bool remap
) {
1160 if (w
->getWorkspaceNumber() != BSENTINEL
&&
1161 w
->getWindowNumber() != BSENTINEL
)
1162 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
1163 else if (w
->isIconic())
1166 windowList
.remove(w
);
1169 if (blackbox
->getFocusedWindow() == w
)
1170 blackbox
->setFocusedWindow((BlackboxWindow
*) 0);
1172 removeNetizen(w
->getClientWindow());
1175 some managed windows can also be window group controllers. when
1176 unmanaging such windows, we should also delete the window group.
1178 BWindowGroup
*group
= blackbox
->searchGroup(w
->getClientWindow());
1185 void BScreen::addNetizen(Netizen
*n
) {
1186 netizenList
.push_back(n
);
1188 n
->sendWorkspaceCount();
1189 n
->sendCurrentWorkspace();
1191 WorkspaceList::iterator it
= workspacesList
.begin();
1192 const WorkspaceList::iterator end
= workspacesList
.end();
1193 for (; it
!= end
; ++it
)
1194 (*it
)->sendWindowList(*n
);
1196 Window f
= ((blackbox
->getFocusedWindow()) ?
1197 blackbox
->getFocusedWindow()->getClientWindow() : None
);
1198 n
->sendWindowFocus(f
);
1202 void BScreen::removeNetizen(Window w
) {
1203 NetizenList::iterator it
= netizenList
.begin();
1204 for (; it
!= netizenList
.end(); ++it
) {
1205 if ((*it
)->getWindowID() == w
) {
1207 netizenList
.erase(it
);
1214 void BScreen::updateWorkArea(void) {
1215 if (workspacesList
.size() > 0) {
1216 unsigned long *dims
= new unsigned long[4 * workspacesList
.size()];
1217 for (unsigned int i
= 0, m
= workspacesList
.size(); i
< m
; ++i
) {
1218 // XXX: this could be different for each workspace
1219 const Rect
&area
= availableArea();
1220 dims
[(i
* 4) + 0] = area
.x();
1221 dims
[(i
* 4) + 1] = area
.y();
1222 dims
[(i
* 4) + 2] = area
.width();
1223 dims
[(i
* 4) + 3] = area
.height();
1225 xatom
->setValue(getRootWindow(), XAtom::net_workarea
, XAtom::cardinal
,
1226 dims
, 4 * workspacesList
.size());
1229 xatom
->setValue(getRootWindow(), XAtom::net_workarea
, XAtom::cardinal
,
1234 void BScreen::updateNetizenCurrentWorkspace(void) {
1235 std::for_each(netizenList
.begin(), netizenList
.end(),
1236 std::mem_fun(&Netizen::sendCurrentWorkspace
));
1240 void BScreen::updateNetizenWorkspaceCount(void) {
1241 xatom
->setValue(getRootWindow(), XAtom::net_number_of_desktops
,
1242 XAtom::cardinal
, workspacesList
.size());
1246 std::for_each(netizenList
.begin(), netizenList
.end(),
1247 std::mem_fun(&Netizen::sendWorkspaceCount
));
1251 void BScreen::updateNetizenWindowFocus(void) {
1252 Window f
= ((blackbox
->getFocusedWindow()) ?
1253 blackbox
->getFocusedWindow()->getClientWindow() : None
);
1255 xatom
->setValue(getRootWindow(), XAtom::net_active_window
,
1258 NetizenList::iterator it
= netizenList
.begin();
1259 for (; it
!= netizenList
.end(); ++it
)
1260 (*it
)->sendWindowFocus(f
);
1264 void BScreen::updateNetizenWindowAdd(Window w
, unsigned long p
) {
1265 NetizenList::iterator it
= netizenList
.begin();
1266 for (; it
!= netizenList
.end(); ++it
) {
1267 (*it
)->sendWindowAdd(w
, p
);
1272 void BScreen::updateNetizenWindowDel(Window w
) {
1273 NetizenList::iterator it
= netizenList
.begin();
1274 for (; it
!= netizenList
.end(); ++it
)
1275 (*it
)->sendWindowDel(w
);
1279 void BScreen::updateNetizenWindowRaise(Window w
) {
1280 NetizenList::iterator it
= netizenList
.begin();
1281 for (; it
!= netizenList
.end(); ++it
)
1282 (*it
)->sendWindowRaise(w
);
1286 void BScreen::updateNetizenWindowLower(Window w
) {
1287 NetizenList::iterator it
= netizenList
.begin();
1288 for (; it
!= netizenList
.end(); ++it
)
1289 (*it
)->sendWindowLower(w
);
1293 void BScreen::updateNetizenConfigNotify(XEvent
*e
) {
1294 NetizenList::iterator it
= netizenList
.begin();
1295 for (; it
!= netizenList
.end(); ++it
)
1296 (*it
)->sendConfigNotify(e
);
1300 void BScreen::raiseWindows(Window
*workspace_stack
, unsigned int num
) {
1301 // the 13 represents the number of blackbox windows such as menus
1302 Window
*session_stack
= new
1303 Window
[(num
+ workspacesList
.size() + rootmenuList
.size() + 13)];
1304 unsigned int i
= 0, k
= num
;
1306 XRaiseWindow(blackbox
->getXDisplay(), iconmenu
->getWindowID());
1307 *(session_stack
+ i
++) = iconmenu
->getWindowID();
1309 WorkspaceList::iterator wit
= workspacesList
.begin();
1310 const WorkspaceList::iterator w_end
= workspacesList
.end();
1311 for (; wit
!= w_end
; ++wit
)
1312 *(session_stack
+ i
++) = (*wit
)->getMenu()->getWindowID();
1314 *(session_stack
+ i
++) = workspacemenu
->getWindowID();
1316 *(session_stack
+ i
++) = configmenu
->getFocusmenu()->getWindowID();
1317 *(session_stack
+ i
++) = configmenu
->getPlacementmenu()->getWindowID();
1318 *(session_stack
+ i
++) = configmenu
->getWindowID();
1320 *(session_stack
+ i
++) = slit
->getMenu()->getDirectionmenu()->getWindowID();
1321 *(session_stack
+ i
++) = slit
->getMenu()->getPlacementmenu()->getWindowID();
1322 *(session_stack
+ i
++) = slit
->getMenu()->getWindowID();
1324 *(session_stack
+ i
++) =
1325 toolbar
->getMenu()->getPlacementmenu()->getWindowID();
1326 *(session_stack
+ i
++) = toolbar
->getMenu()->getWindowID();
1328 RootmenuList::iterator rit
= rootmenuList
.begin();
1329 for (; rit
!= rootmenuList
.end(); ++rit
)
1330 *(session_stack
+ i
++) = (*rit
)->getWindowID();
1331 *(session_stack
+ i
++) = rootmenu
->getWindowID();
1333 if (toolbar
->isOnTop())
1334 *(session_stack
+ i
++) = toolbar
->getWindowID();
1336 if (slit
->isOnTop())
1337 *(session_stack
+ i
++) = slit
->getWindowID();
1340 *(session_stack
+ i
++) = *(workspace_stack
+ k
);
1342 XRestackWindows(blackbox
->getXDisplay(), session_stack
, i
);
1344 delete [] session_stack
;
1346 updateStackingList();
1350 void BScreen::lowerDesktops(void) {
1351 if (desktopWindowList
.empty()) return;
1353 XLowerWindow(blackbox
->getXDisplay(), desktopWindowList
[0]);
1354 if (desktopWindowList
.size() > 1)
1355 XRestackWindows(blackbox
->getXDisplay(), &desktopWindowList
[0],
1356 desktopWindowList
.size());
1360 void BScreen::reassociateWindow(BlackboxWindow
*w
, unsigned int wkspc_id
,
1361 bool ignore_sticky
) {
1364 if (wkspc_id
== BSENTINEL
)
1365 wkspc_id
= current_workspace
->getID();
1367 if (w
->getWorkspaceNumber() == wkspc_id
)
1370 if (w
->isIconic()) {
1372 getWorkspace(wkspc_id
)->addWindow(w
);
1373 } else if (ignore_sticky
|| ! w
->isStuck()) {
1374 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
1375 getWorkspace(wkspc_id
)->addWindow(w
);
1380 void BScreen::propagateWindowName(const BlackboxWindow
*bw
) {
1381 if (bw
->isIconic()) {
1382 iconmenu
->changeItemLabel(bw
->getWindowNumber(), bw
->getIconTitle());
1386 Clientmenu
*clientmenu
= getWorkspace(bw
->getWorkspaceNumber())->getMenu();
1387 clientmenu
->changeItemLabel(bw
->getWindowNumber(), bw
->getTitle());
1388 clientmenu
->update();
1390 if (blackbox
->getFocusedWindow() == bw
)
1391 toolbar
->redrawWindowLabel(True
);
1396 void BScreen::nextFocus(void) {
1397 BlackboxWindow
*focused
= blackbox
->getFocusedWindow(),
1401 // if window is not on this screen, ignore it
1402 if (focused
->getScreen()->getScreenNumber() != getScreenNumber())
1403 focused
= (BlackboxWindow
*) 0;
1406 if (focused
&& current_workspace
->getCount() > 1) {
1407 // next is the next window to recieve focus, current is a place holder
1408 BlackboxWindow
*current
;
1411 next
= current_workspace
->getNextWindowInList(current
);
1412 } while(! next
->setInputFocus() && next
!= focused
);
1414 if (next
!= focused
)
1415 current_workspace
->raiseWindow(next
);
1416 } else if (current_workspace
->getCount() >= 1) {
1417 next
= current_workspace
->getTopWindowOnStack();
1419 current_workspace
->raiseWindow(next
);
1420 next
->setInputFocus();
1425 void BScreen::prevFocus(void) {
1426 BlackboxWindow
*focused
= blackbox
->getFocusedWindow(),
1430 // if window is not on this screen, ignore it
1431 if (focused
->getScreen()->getScreenNumber() != getScreenNumber())
1432 focused
= (BlackboxWindow
*) 0;
1435 if (focused
&& current_workspace
->getCount() > 1) {
1436 // next is the next window to recieve focus, current is a place holder
1437 BlackboxWindow
*current
;
1440 next
= current_workspace
->getPrevWindowInList(current
);
1441 } while(! next
->setInputFocus() && next
!= focused
);
1443 if (next
!= focused
)
1444 current_workspace
->raiseWindow(next
);
1445 } else if (current_workspace
->getCount() >= 1) {
1446 next
= current_workspace
->getTopWindowOnStack();
1448 current_workspace
->raiseWindow(next
);
1449 next
->setInputFocus();
1454 void BScreen::raiseFocus(void) {
1455 BlackboxWindow
*focused
= blackbox
->getFocusedWindow();
1459 // if on this Screen, raise it
1460 if (focused
->getScreen()->getScreenNumber() == getScreenNumber()) {
1461 Workspace
*workspace
= getWorkspace(focused
->getWorkspaceNumber());
1462 workspace
->raiseWindow(focused
);
1467 void BScreen::InitMenu(void) {
1469 rootmenuList
.clear();
1471 while (rootmenu
->getCount())
1472 rootmenu
->remove(0);
1474 rootmenu
= new Rootmenu(this);
1476 bool defaultMenu
= True
;
1478 FILE *menu_file
= (FILE *) 0;
1479 const char *menu_filename
= blackbox
->getMenuFilename();
1482 if (! (menu_file
= fopen(menu_filename
, "r")))
1483 perror(menu_filename
);
1484 if (! menu_file
) { // opening the menu file failed, try the default menu
1485 menu_filename
= DEFAULTMENU
;
1486 if (! (menu_file
= fopen(menu_filename
, "r")))
1487 perror(menu_filename
);
1491 if (feof(menu_file
)) {
1492 fprintf(stderr
, i18n(ScreenSet
, ScreenEmptyMenuFile
,
1493 "%s: Empty menu file"),
1496 char line
[1024], label
[1024];
1497 memset(line
, 0, 1024);
1498 memset(label
, 0, 1024);
1500 while (fgets(line
, 1024, menu_file
) && ! feof(menu_file
)) {
1501 if (line
[0] != '#') {
1502 int i
, key
= 0, index
= -1, len
= strlen(line
);
1504 for (i
= 0; i
< len
; i
++) {
1505 if (line
[i
] == '[') index
= 0;
1506 else if (line
[i
] == ']') break;
1507 else if (line
[i
] != ' ')
1509 key
+= tolower(line
[i
]);
1512 if (key
== 517) { // [begin]
1514 for (i
= index
; i
< len
; i
++) {
1515 if (line
[i
] == '(') index
= 0;
1516 else if (line
[i
] == ')') break;
1517 else if (index
++ >= 0) {
1518 if (line
[i
] == '\\' && i
< len
- 1) i
++;
1519 label
[index
- 1] = line
[i
];
1523 if (index
== -1) index
= 0;
1524 label
[index
] = '\0';
1526 rootmenu
->setLabel(label
);
1527 defaultMenu
= parseMenuFile(menu_file
, rootmenu
);
1529 blackbox
->addMenuTimestamp(menu_filename
);
1539 rootmenu
->setInternalMenu();
1540 rootmenu
->insert(i18n(ScreenSet
, Screenxterm
, "xterm"),
1542 i18n(ScreenSet
, Screenxterm
, "xterm"));
1543 rootmenu
->insert(i18n(ScreenSet
, ScreenRestart
, "Restart"),
1545 rootmenu
->insert(i18n(ScreenSet
, ScreenExit
, "Exit"),
1547 rootmenu
->setLabel(i18n(BasemenuSet
, BasemenuBlackboxMenu
,
1553 bool BScreen::parseMenuFile(FILE *file
, Rootmenu
*menu
) {
1554 char line
[1024], label
[1024], command
[1024];
1556 while (! feof(file
)) {
1557 memset(line
, 0, 1024);
1558 memset(label
, 0, 1024);
1559 memset(command
, 0, 1024);
1561 if (fgets(line
, 1024, file
)) {
1562 if (line
[0] != '#') {
1563 int i
, key
= 0, parse
= 0, index
= -1, line_length
= strlen(line
);
1565 // determine the keyword
1566 for (i
= 0; i
< line_length
; i
++) {
1567 if (line
[i
] == '[') parse
= 1;
1568 else if (line
[i
] == ']') break;
1569 else if (line
[i
] != ' ')
1571 key
+= tolower(line
[i
]);
1574 // get the label enclosed in ()'s
1577 for (i
= 0; i
< line_length
; i
++) {
1578 if (line
[i
] == '(') {
1581 } else if (line
[i
] == ')') break;
1582 else if (index
++ >= 0) {
1583 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
1584 label
[index
- 1] = line
[i
];
1589 label
[index
] = '\0';
1594 // get the command enclosed in {}'s
1597 for (i
= 0; i
< line_length
; i
++) {
1598 if (line
[i
] == '{') {
1601 } else if (line
[i
] == '}') break;
1602 else if (index
++ >= 0) {
1603 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
1604 command
[index
- 1] = line
[i
];
1609 command
[index
] = '\0';
1616 return ((menu
->getCount() == 0) ? True
: False
);
1623 menu
->insert(label
);
1628 if ((! *label
) && (! *command
)) {
1629 fprintf(stderr
, i18n(ScreenSet
, ScreenEXECError
,
1630 "BScreen::parseMenuFile: [exec] error, "
1631 "no menu label and/or command defined\n"));
1635 menu
->insert(label
, BScreen::Execute
, command
);
1641 fprintf(stderr
, i18n(ScreenSet
, ScreenEXITError
,
1642 "BScreen::parseMenuFile: [exit] error, "
1643 "no menu label defined\n"));
1647 menu
->insert(label
, BScreen::Exit
);
1653 if ((! *label
) || (! *command
)) {
1655 i18n(ScreenSet
, ScreenSTYLEError
,
1656 "BScreen::parseMenuFile: [style] error, "
1657 "no menu label and/or filename defined\n"));
1661 string style
= expandTilde(command
);
1663 menu
->insert(label
, BScreen::SetStyle
, style
.c_str());
1670 fprintf(stderr
, i18n(ScreenSet
, ScreenCONFIGError
,
1671 "BScreen::parseMenufile: [config] error, "
1672 "no label defined"));
1676 menu
->insert(label
, configmenu
);
1680 case 740: // include
1683 fprintf(stderr
, i18n(ScreenSet
, ScreenINCLUDEError
,
1684 "BScreen::parseMenuFile: [include] error, "
1685 "no filename defined\n"));
1689 string newfile
= expandTilde(label
);
1690 FILE *submenufile
= fopen(newfile
.c_str(), "r");
1694 if (fstat(fileno(submenufile
), &buf
) ||
1695 (! S_ISREG(buf
.st_mode
))) {
1697 i18n(ScreenSet
, ScreenINCLUDEErrorReg
,
1698 "BScreen::parseMenuFile: [include] error: "
1699 "'%s' is not a regular file\n"), newfile
.c_str());
1703 if (! feof(submenufile
)) {
1704 if (! parseMenuFile(submenufile
, menu
))
1705 blackbox
->addMenuTimestamp(newfile
);
1707 fclose(submenufile
);
1710 perror(newfile
.c_str());
1716 case 767: // submenu
1719 fprintf(stderr
, i18n(ScreenSet
, ScreenSUBMENUError
,
1720 "BScreen::parseMenuFile: [submenu] error, "
1721 "no menu label defined\n"));
1725 Rootmenu
*submenu
= new Rootmenu(this);
1728 submenu
->setLabel(command
);
1730 submenu
->setLabel(label
);
1732 parseMenuFile(file
, submenu
);
1734 menu
->insert(label
, submenu
);
1735 rootmenuList
.push_back(submenu
);
1740 case 773: // restart
1743 fprintf(stderr
, i18n(ScreenSet
, ScreenRESTARTError
,
1744 "BScreen::parseMenuFile: [restart] error, "
1745 "no menu label defined\n"));
1750 menu
->insert(label
, BScreen::RestartOther
, command
);
1752 menu
->insert(label
, BScreen::Restart
);
1757 case 845: // reconfig
1761 i18n(ScreenSet
, ScreenRECONFIGError
,
1762 "BScreen::parseMenuFile: [reconfig] error, "
1763 "no menu label defined\n"));
1767 menu
->insert(label
, BScreen::Reconfigure
);
1772 case 995: // stylesdir
1773 case 1113: // stylesmenu
1775 bool newmenu
= ((key
== 1113) ? True
: False
);
1777 if ((! *label
) || ((! *command
) && newmenu
)) {
1779 i18n(ScreenSet
, ScreenSTYLESDIRError
,
1780 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1781 " error, no directory defined\n"));
1785 char *directory
= ((newmenu
) ? command
: label
);
1787 string stylesdir
= expandTilde(directory
);
1789 struct stat statbuf
;
1791 if (! stat(stylesdir
.c_str(), &statbuf
)) {
1792 if (S_ISDIR(statbuf
.st_mode
)) {
1793 Rootmenu
*stylesmenu
;
1796 stylesmenu
= new Rootmenu(this);
1800 DIR *d
= opendir(stylesdir
.c_str());
1802 std::vector
<string
> ls
;
1804 while((p
= readdir(d
)))
1805 ls
.push_back(p
->d_name
);
1809 std::sort(ls
.begin(), ls
.end());
1811 std::vector
<string
>::iterator it
= ls
.begin(),
1813 for (; it
!= end
; ++it
) {
1814 const string
& fname
= *it
;
1816 if (fname
[fname
.size()-1] == '~')
1819 string style
= stylesdir
;
1823 if ((! stat(style
.c_str(), &statbuf
)) &&
1824 S_ISREG(statbuf
.st_mode
))
1825 stylesmenu
->insert(fname
, BScreen::SetStyle
, style
);
1828 stylesmenu
->update();
1831 stylesmenu
->setLabel(label
);
1832 menu
->insert(label
, stylesmenu
);
1833 rootmenuList
.push_back(stylesmenu
);
1836 blackbox
->addMenuTimestamp(stylesdir
);
1839 i18n(ScreenSet
, ScreenSTYLESDIRErrorNotDir
,
1840 "BScreen::parseMenuFile:"
1841 " [stylesdir/stylesmenu] error, %s is not a"
1842 " directory\n"), stylesdir
.c_str());
1846 i18n(ScreenSet
, ScreenSTYLESDIRErrorNoExist
,
1847 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1848 " error, %s does not exist\n"), stylesdir
.c_str());
1853 case 1090: // workspaces
1857 i18n(ScreenSet
, ScreenWORKSPACESError
,
1858 "BScreen:parseMenuFile: [workspaces] error, "
1859 "no menu label defined\n"));
1863 menu
->insert(label
, workspacemenu
);
1872 return ((menu
->getCount() == 0) ? True
: False
);
1876 void BScreen::shutdown(void) {
1877 XSelectInput(blackbox
->getXDisplay(), getRootWindow(), NoEventMask
);
1878 XSync(blackbox
->getXDisplay(), False
);
1880 while(! windowList
.empty())
1881 unmanageWindow(windowList
.front(), True
);
1887 void BScreen::showPosition(int x
, int y
) {
1888 if (! geom_visible
) {
1889 XMoveResizeWindow(blackbox
->getXDisplay(), geom_window
,
1890 (getWidth() - geom_w
) / 2,
1891 (getHeight() - geom_h
) / 2, geom_w
, geom_h
);
1892 XMapWindow(blackbox
->getXDisplay(), geom_window
);
1893 XRaiseWindow(blackbox
->getXDisplay(), geom_window
);
1895 geom_visible
= True
;
1900 sprintf(label
, i18n(ScreenSet
, ScreenPositionFormat
,
1901 "X: %4d x Y: %4d"), x
, y
);
1903 XClearWindow(blackbox
->getXDisplay(), geom_window
);
1905 resource
.wstyle
.font
->drawString(geom_window
,
1906 resource
.bevel_width
, resource
.bevel_width
,
1907 resource
.wstyle
.l_text_focus
,
1912 void BScreen::showGeometry(unsigned int gx
, unsigned int gy
) {
1913 if (! geom_visible
) {
1914 XMoveResizeWindow(blackbox
->getXDisplay(), geom_window
,
1915 (getWidth() - geom_w
) / 2,
1916 (getHeight() - geom_h
) / 2, geom_w
, geom_h
);
1917 XMapWindow(blackbox
->getXDisplay(), geom_window
);
1918 XRaiseWindow(blackbox
->getXDisplay(), geom_window
);
1920 geom_visible
= True
;
1925 sprintf(label
, i18n(ScreenSet
, ScreenGeometryFormat
,
1926 "W: %4d x H: %4d"), gx
, gy
);
1928 XClearWindow(blackbox
->getXDisplay(), geom_window
);
1930 resource
.wstyle
.font
->drawString(geom_window
,
1931 resource
.bevel_width
, resource
.bevel_width
,
1932 resource
.wstyle
.l_text_focus
,
1937 void BScreen::hideGeometry(void) {
1939 XUnmapWindow(blackbox
->getXDisplay(), geom_window
);
1940 geom_visible
= False
;
1945 void BScreen::addStrut(Strut
*strut
) {
1946 strutList
.push_back(strut
);
1950 void BScreen::removeStrut(Strut
*strut
) {
1951 strutList
.remove(strut
);
1955 const Rect
& BScreen::availableArea(void) const {
1957 return getRect(); // return the full screen
1962 void BScreen::updateAvailableArea(void) {
1963 Rect old_area
= usableArea
;
1964 usableArea
= getRect(); // reset to full screen
1966 /* these values represent offsets from the screen edge
1967 * we look for the biggest offset on each edge and then apply them
1969 * do not be confused by the similarity to the names of Rect's members
1971 unsigned int current_left
= 0, current_right
= 0, current_top
= 0,
1974 StrutList::const_iterator it
= strutList
.begin(), end
= strutList
.end();
1976 for(; it
!= end
; ++it
) {
1978 if (strut
->left
> current_left
)
1979 current_left
= strut
->left
;
1980 if (strut
->top
> current_top
)
1981 current_top
= strut
->top
;
1982 if (strut
->right
> current_right
)
1983 current_right
= strut
->right
;
1984 if (strut
->bottom
> current_bottom
)
1985 current_bottom
= strut
->bottom
;
1988 usableArea
.setPos(current_left
, current_top
);
1989 usableArea
.setSize(usableArea
.width() - (current_left
+ current_right
),
1990 usableArea
.height() - (current_top
+ current_bottom
));
1992 if (old_area
!= usableArea
) {
1993 BlackboxWindowList::iterator it
= windowList
.begin(),
1994 end
= windowList
.end();
1995 for (; it
!= end
; ++it
)
1996 if ((*it
)->isMaximized()) (*it
)->remaximize();
2003 Workspace
* BScreen::getWorkspace(unsigned int index
) {
2004 assert(index
< workspacesList
.size());
2005 return workspacesList
[index
];
2009 void BScreen::buttonPressEvent(XButtonEvent
*xbutton
) {
2010 if (xbutton
->button
== 1) {
2011 if (! isRootColormapInstalled())
2012 image_control
->installRootColormap();
2014 if (workspacemenu
->isVisible())
2015 workspacemenu
->hide();
2017 if (rootmenu
->isVisible())
2019 } else if (xbutton
->button
== 2) {
2020 int mx
= xbutton
->x_root
- (workspacemenu
->getWidth() / 2);
2021 int my
= xbutton
->y_root
- (workspacemenu
->getTitleHeight() / 2);
2026 if (mx
+ workspacemenu
->getWidth() > getWidth())
2027 mx
= getWidth() - workspacemenu
->getWidth() - getBorderWidth();
2029 if (my
+ workspacemenu
->getHeight() > getHeight())
2030 my
= getHeight() - workspacemenu
->getHeight() - getBorderWidth();
2032 workspacemenu
->move(mx
, my
);
2034 if (! workspacemenu
->isVisible()) {
2035 workspacemenu
->removeParent();
2036 workspacemenu
->show();
2038 } else if (xbutton
->button
== 3) {
2039 int mx
= xbutton
->x_root
- (rootmenu
->getWidth() / 2);
2040 int my
= xbutton
->y_root
- (rootmenu
->getTitleHeight() / 2);
2045 if (mx
+ rootmenu
->getWidth() > getWidth())
2046 mx
= getWidth() - rootmenu
->getWidth() - getBorderWidth();
2048 if (my
+ rootmenu
->getHeight() > getHeight())
2049 my
= getHeight() - rootmenu
->getHeight() - getBorderWidth();
2051 rootmenu
->move(mx
, my
);
2053 if (! rootmenu
->isVisible()) {
2054 blackbox
->checkMenu();
2058 } else if (xbutton
->button
== 4) {
2059 if (getCurrentWorkspaceID() >= getWorkspaceCount() - 1)
2060 changeWorkspaceID(0);
2062 changeWorkspaceID(getCurrentWorkspaceID() + 1);
2064 } else if (xbutton
->button
== 5) {
2065 if (getCurrentWorkspaceID() == 0)
2066 changeWorkspaceID(getWorkspaceCount() - 1);
2068 changeWorkspaceID(getCurrentWorkspaceID() - 1);
2073 void BScreen::toggleFocusModel(FocusModel model
) {
2074 if (model
== SloppyFocus
) {
2075 saveSloppyFocus(True
);
2077 // we're cheating here to save writing the config file 3 times
2078 resource
.auto_raise
= False
;
2079 resource
.click_raise
= False
;
2080 saveSloppyFocus(False
);
2087 void BScreen::updateFocusModel()
2089 std::for_each(workspacesList
.begin(), workspacesList
.end(),
2090 std::mem_fun(&Workspace::updateFocusModel
));
2094 BTexture
BScreen::readDatabaseTexture(const string
&rname
,
2095 const string
&default_color
,
2096 const Configuration
&style
) {
2100 if (style
.getValue(rname
, s
))
2101 texture
= BTexture(s
);
2103 texture
.setTexture(BTexture::Solid
| BTexture::Flat
);
2105 // associate this texture with this screen
2106 texture
.setDisplay(getBaseDisplay(), getScreenNumber());
2107 texture
.setImageControl(image_control
);
2109 if (texture
.texture() & BTexture::Solid
) {
2110 texture
.setColor(readDatabaseColor(rname
+ ".color",
2111 default_color
, style
));
2112 texture
.setColorTo(readDatabaseColor(rname
+ ".colorTo",
2113 default_color
, style
));
2114 } else if (texture
.texture() & BTexture::Gradient
) {
2115 texture
.setColor(readDatabaseColor(rname
+ ".color",
2116 default_color
, style
));
2117 texture
.setColorTo(readDatabaseColor(rname
+ ".colorTo",
2118 default_color
, style
));
2125 BColor
BScreen::readDatabaseColor(const string
&rname
,
2126 const string
&default_color
,
2127 const Configuration
&style
) {
2130 if (style
.getValue(rname
, s
))
2131 color
= BColor(s
, getBaseDisplay(), getScreenNumber());
2133 color
= BColor(default_color
, getBaseDisplay(), getScreenNumber());
2138 BFont
*BScreen::readDatabaseFont(const string
&rname
,
2139 const Configuration
&style
) {
2143 style
.getValue(rname
, s
); // if this fails, a blank string will be used,
2144 // which will cause the fallback font to load.
2146 BFont
*b
= new BFont(blackbox
->getXDisplay(), this, s
);
2148 exit(2); // can't continue without a font