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
= "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;
137 xatom
->setSupported(this); // set-up netwm support
139 xatom
->setValue(getRootWindow(), XAtom::blackbox_pid
, XAtom::cardinal
,
140 (unsigned long) getpid());
141 #endif // HAVE_GETPID
142 unsigned long geometry
[] = { getWidth(),
144 xatom
->setValue(getRootWindow(), XAtom::net_desktop_geometry
,
145 XAtom::cardinal
, geometry
, 2);
146 unsigned long viewport
[] = {0,0};
147 xatom
->setValue(getRootWindow(), XAtom::net_desktop_viewport
,
148 XAtom::cardinal
, viewport
, 2);
151 XDefineCursor(blackbox
->getXDisplay(), getRootWindow(),
152 blackbox
->getSessionCursor());
154 // start off full screen, top left.
155 usableArea
.setSize(getWidth(), getHeight());
158 new BImageControl(blackbox
, this, True
, blackbox
->getColorsPerChannel(),
159 blackbox
->getCacheLife(), blackbox
->getCacheMax());
160 image_control
->installRootColormap();
161 root_colormap_installed
= True
;
167 gcv
.foreground
= WhitePixel(blackbox
->getXDisplay(), getScreenNumber())
168 ^ BlackPixel(blackbox
->getXDisplay(), getScreenNumber());
169 gcv
.function
= GXxor
;
170 gcv
.subwindow_mode
= IncludeInferiors
;
171 opGC
= XCreateGC(blackbox
->getXDisplay(), getRootWindow(),
172 GCForeground
| GCFunction
| GCSubwindowMode
, &gcv
);
174 const char *s
= i18n(ScreenSet
, ScreenPositionLength
,
175 "0: 0000 x 0: 0000");
176 geom_w
= resource
.wstyle
.font
->measureString(s
) + resource
.bevel_width
* 2;
177 geom_h
= resource
.wstyle
.font
->height() + resource
.bevel_width
* 2;
179 XSetWindowAttributes attrib
;
180 unsigned long mask
= CWBorderPixel
| CWColormap
| CWSaveUnder
;
181 attrib
.border_pixel
= getBorderColor()->pixel();
182 attrib
.colormap
= getColormap();
183 attrib
.save_under
= True
;
185 geom_window
= XCreateWindow(blackbox
->getXDisplay(), getRootWindow(),
186 0, 0, geom_w
, geom_h
, resource
.border_width
,
187 getDepth(), InputOutput
, getVisual(),
189 geom_visible
= False
;
191 BTexture
* texture
= &(resource
.wstyle
.l_focus
);
192 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
193 if (geom_pixmap
== ParentRelative
) {
194 texture
= &(resource
.wstyle
.t_focus
);
195 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
198 XSetWindowBackground(blackbox
->getXDisplay(), geom_window
,
199 texture
->color().pixel());
201 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
202 geom_window
, geom_pixmap
);
204 workspacemenu
= new Workspacemenu(this);
205 iconmenu
= new Iconmenu(this);
206 configmenu
= new Configmenu(this);
208 if (resource
.workspaces
!= 0) {
209 for (unsigned int i
= 0; i
< resource
.workspaces
; ++i
) {
210 Workspace
*wkspc
= new Workspace(this, workspacesList
.size());
211 workspacesList
.push_back(wkspc
);
212 workspacemenu
->insertWorkspace(wkspc
);
213 workspacemenu
->update();
217 Workspace
*wkspc
= new Workspace(this, workspacesList
.size());
218 workspacesList
.push_back(wkspc
);
219 workspacemenu
->insertWorkspace(wkspc
);
220 workspacemenu
->update();
222 saveWorkspaceNames();
224 updateNetizenWorkspaceCount();
226 workspacemenu
->insert(i18n(IconSet
, IconIcons
, "Icons"), iconmenu
);
227 workspacemenu
->update();
229 current_workspace
= workspacesList
.front();
231 xatom
->setValue(getRootWindow(), XAtom::net_current_desktop
,
232 XAtom::cardinal
, 0); //first workspace
234 workspacemenu
->setItemSelected(2, True
);
236 toolbar
= new Toolbar(this);
238 slit
= new Slit(this);
242 raiseWindows(0, 0); // this also initializes the empty stacking list
245 updateClientList(); // initialize the client lists, which will be empty
246 updateAvailableArea();
248 changeWorkspaceID(0);
250 unsigned int i
, j
, nchild
;
251 Window r
, p
, *children
;
252 XQueryTree(blackbox
->getXDisplay(), getRootWindow(), &r
, &p
,
255 // preen the window list of all icon windows... for better dockapp support
256 for (i
= 0; i
< nchild
; i
++) {
257 if (children
[i
] == None
) continue;
259 XWMHints
*wmhints
= XGetWMHints(blackbox
->getXDisplay(),
263 if ((wmhints
->flags
& IconWindowHint
) &&
264 (wmhints
->icon_window
!= children
[i
])) {
265 for (j
= 0; j
< nchild
; j
++) {
266 if (children
[j
] == wmhints
->icon_window
) {
277 // manage shown windows
278 for (i
= 0; i
< nchild
; ++i
) {
279 if (children
[i
] == None
|| (! blackbox
->validateWindow(children
[i
])))
282 XWindowAttributes attrib
;
283 if (XGetWindowAttributes(blackbox
->getXDisplay(), children
[i
], &attrib
)) {
284 if (attrib
.override_redirect
) continue;
286 if (attrib
.map_state
!= IsUnmapped
) {
287 manageWindow(children
[i
]);
294 // call this again just in case a window we found updates the Strut list
295 updateAvailableArea();
299 BScreen::~BScreen(void) {
300 if (! managed
) return;
302 if (geom_pixmap
!= None
)
303 image_control
->removeImage(geom_pixmap
);
305 if (geom_window
!= None
)
306 XDestroyWindow(blackbox
->getXDisplay(), geom_window
);
308 std::for_each(workspacesList
.begin(), workspacesList
.end(),
311 std::for_each(iconList
.begin(), iconList
.end(), PointerAssassin());
313 std::for_each(netizenList
.begin(), netizenList
.end(), PointerAssassin());
315 while (! desktopWindowList
.empty())
316 removeDesktopWindow(desktopWindowList
[0]);
318 while (! systrayWindowList
.empty())
319 removeSystrayWindow(systrayWindowList
[0]);
322 delete workspacemenu
;
327 delete image_control
;
329 if (resource
.wstyle
.font
)
330 delete resource
.wstyle
.font
;
331 if (resource
.mstyle
.t_font
)
332 delete resource
.mstyle
.t_font
;
333 if (resource
.mstyle
.f_font
)
334 delete resource
.mstyle
.f_font
;
335 if (resource
.tstyle
.font
)
336 delete resource
.tstyle
.font
;
338 XFreeGC(blackbox
->getXDisplay(), opGC
);
342 void BScreen::saveSloppyFocus(bool s
) {
343 resource
.sloppy_focus
= s
;
346 if (resource
.sloppy_focus
) {
347 fmodel
= "SloppyFocus";
348 if (resource
.auto_raise
) fmodel
+= " AutoRaise";
349 if (resource
.click_raise
) fmodel
+= " ClickRaise";
351 fmodel
= "ClickToFocus";
353 config
->setValue(screenstr
+ "focusModel", fmodel
);
357 void BScreen::saveAutoRaise(bool a
) {
358 resource
.auto_raise
= a
;
359 saveSloppyFocus(resource
.sloppy_focus
);
363 void BScreen::saveClickRaise(bool c
) {
364 resource
.click_raise
= c
;
365 saveSloppyFocus(resource
.sloppy_focus
);
369 void BScreen::saveImageDither(bool d
) {
370 image_control
->setDither(d
);
371 config
->setValue(screenstr
+ "imageDither", doImageDither());
375 void BScreen::saveOpaqueMove(bool o
) {
376 resource
.opaque_move
= o
;
377 config
->setValue(screenstr
+ "opaqueMove", resource
.opaque_move
);
381 void BScreen::saveFullMax(bool f
) {
382 resource
.full_max
= f
;
383 config
->setValue(screenstr
+ "fullMaximization", resource
.full_max
);
387 void BScreen::saveFocusNew(bool f
) {
388 resource
.focus_new
= f
;
389 config
->setValue(screenstr
+ "focusNewWindows", resource
.focus_new
);
393 void BScreen::saveFocusLast(bool f
) {
394 resource
.focus_last
= f
;
395 config
->setValue(screenstr
+ "focusLastWindow", resource
.focus_last
);
399 void BScreen::saveAAFonts(bool f
) {
400 resource
.aa_fonts
= f
;
402 config
->setValue(screenstr
+ "antialiasFonts", resource
.aa_fonts
);
406 void BScreen::saveHideToolbar(bool h
) {
407 resource
.hide_toolbar
= h
;
408 if (resource
.hide_toolbar
)
409 toolbar
->unmapToolbar();
411 toolbar
->mapToolbar();
412 config
->setValue(screenstr
+ "hideToolbar", resource
.hide_toolbar
);
416 void BScreen::saveWindowToWindowSnap(bool s
) {
417 resource
.window_to_window_snap
= s
;
418 config
->setValue(screenstr
+ "windowToWindowSnap",
419 resource
.window_to_window_snap
);
423 void BScreen::saveResizeZones(unsigned int z
) {
424 resource
.resize_zones
= z
;
425 config
->setValue(screenstr
+ "resizeZones", resource
.resize_zones
);
429 void BScreen::saveWindowCornerSnap(bool s
) {
430 resource
.window_corner_snap
= s
;
431 config
->setValue(screenstr
+ "windowCornerSnap",
432 resource
.window_corner_snap
);
436 void BScreen::saveWorkspaces(unsigned int w
) {
437 resource
.workspaces
= w
;
438 config
->setValue(screenstr
+ "workspaces", resource
.workspaces
);
442 void BScreen::savePlacementPolicy(int p
) {
443 resource
.placement_policy
= p
;
444 const char *placement
;
445 switch (resource
.placement_policy
) {
446 case CascadePlacement
: placement
= "CascadePlacement"; break;
447 case ColSmartPlacement
: placement
= "ColSmartPlacement"; break;
448 case RowSmartPlacement
: default: placement
= "RowSmartPlacement"; break;
450 config
->setValue(screenstr
+ "windowPlacement", placement
);
454 void BScreen::saveEdgeSnapThreshold(int t
) {
455 resource
.edge_snap_threshold
= t
;
456 config
->setValue(screenstr
+ "edgeSnapThreshold",
457 resource
.edge_snap_threshold
);
461 void BScreen::saveRowPlacementDirection(int d
) {
462 resource
.row_direction
= d
;
463 config
->setValue(screenstr
+ "rowPlacementDirection",
464 resource
.row_direction
== LeftRight
?
465 "LeftToRight" : "RightToLeft");
469 void BScreen::saveColPlacementDirection(int d
) {
470 resource
.col_direction
= d
;
471 config
->setValue(screenstr
+ "colPlacementDirection",
472 resource
.col_direction
== TopBottom
?
473 "TopToBottom" : "BottomToTop");
478 void BScreen::saveStrftimeFormat(const std::string
& format
) {
479 resource
.strftime_format
= format
;
480 config
->setValue(screenstr
+ "strftimeFormat", resource
.strftime_format
);
483 #else // !HAVE_STRFTIME
485 void BScreen::saveDateFormat(int f
) {
486 resource
.date_format
= f
;
487 config
->setValue(screenstr
+ "dateFormat",
488 resource
.date_format
== B_EuropeanDate
?
489 "European" : "American");
493 void BScreen::saveClock24Hour(Bool c
) {
494 resource
.clock24hour
= c
;
495 config
->setValue(screenstr
+ "clockFormat", resource
.clock24hour
? 24 : 12);
497 #endif // HAVE_STRFTIME
500 void BScreen::saveWorkspaceNames() {
503 for (unsigned int i
= 0; i
< workspacesList
.size(); ++i
) {
504 names
+= workspacesList
[i
]->getName();
505 if (i
< workspacesList
.size() - 1)
509 config
->setValue(screenstr
+ "workspaceNames", names
);
513 void BScreen::save_rc(void) {
514 saveSloppyFocus(resource
.sloppy_focus
);
515 saveAutoRaise(resource
.auto_raise
);
516 saveImageDither(doImageDither());
517 saveAAFonts(resource
.aa_fonts
);
518 saveResizeZones(resource
.resize_zones
);
519 saveOpaqueMove(resource
.opaque_move
);
520 saveFullMax(resource
.full_max
);
521 saveFocusNew(resource
.focus_new
);
522 saveFocusLast(resource
.focus_last
);
523 saveHideToolbar(resource
.hide_toolbar
);
524 saveWindowToWindowSnap(resource
.window_to_window_snap
);
525 saveWindowCornerSnap(resource
.window_corner_snap
);
526 saveWorkspaces(resource
.workspaces
);
527 savePlacementPolicy(resource
.placement_policy
);
528 saveEdgeSnapThreshold(resource
.edge_snap_threshold
);
529 saveRowPlacementDirection(resource
.row_direction
);
530 saveColPlacementDirection(resource
.col_direction
);
532 saveStrftimeFormat(resource
.strftime_format
);
533 #else // !HAVE_STRFTIME
534 saveDateFormat(resource
.date_format
);
535 savwClock24Hour(resource
.clock24hour
);
536 #endif // HAVE_STRFTIME
543 void BScreen::load_rc(void) {
547 if (! config
->getValue(screenstr
+ "fullMaximization", resource
.full_max
))
548 resource
.full_max
= false;
550 if (! config
->getValue(screenstr
+ "focusNewWindows", resource
.focus_new
))
551 resource
.focus_new
= false;
553 if (! config
->getValue(screenstr
+ "focusLastWindow", resource
.focus_last
))
554 resource
.focus_last
= false;
556 if (! config
->getValue(screenstr
+ "workspaces", resource
.workspaces
))
557 resource
.workspaces
= 1;
559 if (! config
->getValue(screenstr
+ "opaqueMove", resource
.opaque_move
))
560 resource
.opaque_move
= false;
562 if (! config
->getValue(screenstr
+ "antialiasFonts", resource
.aa_fonts
))
563 resource
.aa_fonts
= true;
565 if (! config
->getValue(screenstr
+ "resizeZones", resource
.resize_zones
) ||
566 (resource
.resize_zones
!= 1 && resource
.resize_zones
!= 2 &&
567 resource
.resize_zones
!= 4))
568 resource
.resize_zones
= 4;
570 if (! config
->getValue(screenstr
+ "hideToolbar", resource
.hide_toolbar
))
571 resource
.hide_toolbar
= false;
573 if (! config
->getValue(screenstr
+ "windowToWindowSnap",
574 resource
.window_to_window_snap
))
575 resource
.window_to_window_snap
= true;
577 if (! config
->getValue(screenstr
+ "windowCornerSnap",
578 resource
.window_corner_snap
))
579 resource
.window_corner_snap
= true;
581 if (! config
->getValue(screenstr
+ "imageDither", b
))
583 image_control
->setDither(b
);
585 if (! config
->getValue(screenstr
+ "edgeSnapThreshold",
586 resource
.edge_snap_threshold
))
587 resource
.edge_snap_threshold
= 4;
589 if (config
->getValue(screenstr
+ "rowPlacementDirection", s
) &&
591 resource
.row_direction
= RightLeft
;
593 resource
.row_direction
= LeftRight
;
595 if (config
->getValue(screenstr
+ "colPlacementDirection", s
) &&
597 resource
.col_direction
= BottomTop
;
599 resource
.col_direction
= TopBottom
;
601 XAtom::StringVect workspaceNames
;
602 if (config
->getValue(screenstr
+ "workspaceNames", s
)) {
603 string::const_iterator it
= s
.begin(), end
= s
.end();
605 string::const_iterator tmp
= it
; // current string.begin()
606 it
= std::find(tmp
, end
, ','); // look for comma between tmp and end
607 workspaceNames
.push_back(string(tmp
, it
)); // s[tmp:it]
613 xatom
->setValue(getRootWindow(), XAtom::net_desktop_names
, XAtom::utf8
,
616 resource
.sloppy_focus
= true;
617 resource
.auto_raise
= false;
618 resource
.click_raise
= false;
619 if (config
->getValue(screenstr
+ "focusModel", s
)) {
620 if (s
.find("ClickToFocus") != string::npos
) {
621 resource
.sloppy_focus
= false;
624 if (s
.find("AutoRaise") != string::npos
)
625 resource
.auto_raise
= true;
626 if (s
.find("ClickRaise") != string::npos
)
627 resource
.click_raise
= true;
631 if (config
->getValue(screenstr
+ "windowPlacement", s
)) {
632 if (s
== "CascadePlacement")
633 resource
.placement_policy
= CascadePlacement
;
634 else if (s
== "ColSmartPlacement")
635 resource
.placement_policy
= ColSmartPlacement
;
636 else //if (s == "RowSmartPlacement")
637 resource
.placement_policy
= RowSmartPlacement
;
639 resource
.placement_policy
= RowSmartPlacement
;
642 if (config
->getValue(screenstr
+ "strftimeFormat", s
))
643 resource
.strftime_format
= s
;
645 resource
.strftime_format
= "%I:%M %p";
646 #else // !HAVE_STRFTIME
649 if (config
->getValue(screenstr
+ "dateFormat", s
) && s
== "European")
650 resource
.date_format
= B_EuropeanDate
;
652 resource
.date_format
= B_AmericanDate
;
654 if (! config
->getValue(screenstr
+ "clockFormat", l
))
656 resource
.clock24hour
= l
== 24;
657 #endif // HAVE_STRFTIME
661 void BScreen::reconfigure(void) {
668 gcv
.foreground
= WhitePixel(blackbox
->getXDisplay(),
670 gcv
.function
= GXinvert
;
671 gcv
.subwindow_mode
= IncludeInferiors
;
672 XChangeGC(blackbox
->getXDisplay(), opGC
,
673 GCForeground
| GCFunction
| GCSubwindowMode
, &gcv
);
675 const char *s
= i18n(ScreenSet
, ScreenPositionLength
,
676 "0: 0000 x 0: 0000");
678 geom_w
= resource
.wstyle
.font
->measureString(s
) + resource
.bevel_width
* 2;
679 geom_h
= resource
.wstyle
.font
->height() + resource
.bevel_width
* 2;
681 BTexture
* texture
= &(resource
.wstyle
.l_focus
);
682 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
683 if (geom_pixmap
== ParentRelative
) {
684 texture
= &(resource
.wstyle
.t_focus
);
685 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
688 XSetWindowBackground(blackbox
->getXDisplay(), geom_window
,
689 texture
->color().pixel());
691 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
692 geom_window
, geom_pixmap
);
694 XSetWindowBorderWidth(blackbox
->getXDisplay(), geom_window
,
695 resource
.border_width
);
696 XSetWindowBorder(blackbox
->getXDisplay(), geom_window
,
697 resource
.border_color
.pixel());
699 workspacemenu
->reconfigure();
700 iconmenu
->reconfigure();
702 typedef std::vector
<int> SubList
;
703 SubList remember_subs
;
705 // save the current open menus
706 Basemenu
*menu
= rootmenu
;
708 while ((submenu
= menu
->getCurrentSubmenu()) >= 0) {
709 remember_subs
.push_back(submenu
);
710 menu
= menu
->find(submenu
)->submenu();
716 rootmenu
->reconfigure();
718 // reopen the saved menus
720 const SubList::iterator subs_end
= remember_subs
.end();
721 for (SubList::iterator it
= remember_subs
.begin(); it
!= subs_end
; ++it
) {
722 menu
->drawSubmenu(*it
);
723 menu
= menu
->find(*it
)->submenu();
728 configmenu
->reconfigure();
730 toolbar
->reconfigure();
734 std::for_each(workspacesList
.begin(), workspacesList
.end(),
735 std::mem_fun(&Workspace::reconfigure
));
737 BlackboxWindowList::iterator iit
= iconList
.begin();
738 for (; iit
!= iconList
.end(); ++iit
) {
739 BlackboxWindow
*bw
= *iit
;
740 if (bw
->validateClient())
744 image_control
->timeout();
748 void BScreen::rereadMenu(void) {
752 rootmenu
->reconfigure();
756 void BScreen::LoadStyle(void) {
757 Configuration
style(False
);
759 const char *sfile
= blackbox
->getStyleFilename();
761 style
.setFile(sfile
);
762 if (! style
.load()) {
763 style
.setFile(DEFAULTSTYLE
);
765 style
.create(); // hardcoded default values will be used.
769 // merge in the rc file
770 style
.merge(config
->file(), True
);
774 // load fonts/fontsets
775 if (resource
.wstyle
.font
)
776 delete resource
.wstyle
.font
;
777 if (resource
.tstyle
.font
)
778 delete resource
.tstyle
.font
;
779 if (resource
.mstyle
.f_font
)
780 delete resource
.mstyle
.f_font
;
781 if (resource
.mstyle
.t_font
)
782 delete resource
.mstyle
.t_font
;
783 resource
.wstyle
.font
= resource
.tstyle
.font
= resource
.mstyle
.f_font
=
784 resource
.mstyle
.t_font
= (BFont
*) 0;
786 resource
.wstyle
.font
= readDatabaseFont("window.", style
);
787 resource
.tstyle
.font
= readDatabaseFont("toolbar.", style
);
788 resource
.mstyle
.t_font
= readDatabaseFont("menu.title.", style
);
789 resource
.mstyle
.f_font
= readDatabaseFont("menu.frame.", style
);
791 // load window config
792 resource
.wstyle
.t_focus
=
793 readDatabaseTexture("window.title.focus", "white", style
);
794 resource
.wstyle
.t_unfocus
=
795 readDatabaseTexture("window.title.unfocus", "black", style
);
796 resource
.wstyle
.l_focus
=
797 readDatabaseTexture("window.label.focus", "white", style
);
798 resource
.wstyle
.l_unfocus
=
799 readDatabaseTexture("window.label.unfocus", "black", style
);
800 resource
.wstyle
.h_focus
=
801 readDatabaseTexture("window.handle.focus", "white", style
);
802 resource
.wstyle
.h_unfocus
=
803 readDatabaseTexture("window.handle.unfocus", "black", style
);
804 resource
.wstyle
.g_focus
=
805 readDatabaseTexture("window.grip.focus", "white", style
);
806 resource
.wstyle
.g_unfocus
=
807 readDatabaseTexture("window.grip.unfocus", "black", style
);
808 resource
.wstyle
.b_focus
=
809 readDatabaseTexture("window.button.focus", "white", style
);
810 resource
.wstyle
.b_unfocus
=
811 readDatabaseTexture("window.button.unfocus", "black", style
);
812 resource
.wstyle
.b_pressed
=
813 readDatabaseTexture("window.button.pressed", "black", style
);
814 resource
.wstyle
.f_focus
=
815 readDatabaseColor("window.frame.focusColor", "white", style
);
816 resource
.wstyle
.f_unfocus
=
817 readDatabaseColor("window.frame.unfocusColor", "black", style
);
818 resource
.wstyle
.l_text_focus
=
819 readDatabaseColor("window.label.focus.textColor", "black", style
);
820 resource
.wstyle
.l_text_unfocus
=
821 readDatabaseColor("window.label.unfocus.textColor", "white", style
);
822 resource
.wstyle
.b_pic_focus
=
823 readDatabaseColor("window.button.focus.picColor", "black", style
);
824 resource
.wstyle
.b_pic_unfocus
=
825 readDatabaseColor("window.button.unfocus.picColor", "white", style
);
827 resource
.wstyle
.justify
= LeftJustify
;
828 if (style
.getValue("window.justify", s
)) {
829 if (s
== "right" || s
== "Right")
830 resource
.wstyle
.justify
= RightJustify
;
831 else if (s
== "center" || s
== "Center")
832 resource
.wstyle
.justify
= CenterJustify
;
835 // load toolbar config
836 resource
.tstyle
.toolbar
=
837 readDatabaseTexture("toolbar", "black", style
);
838 resource
.tstyle
.label
=
839 readDatabaseTexture("toolbar.label", "black", style
);
840 resource
.tstyle
.window
=
841 readDatabaseTexture("toolbar.windowLabel", "black", style
);
842 resource
.tstyle
.button
=
843 readDatabaseTexture("toolbar.button", "white", style
);
844 resource
.tstyle
.pressed
=
845 readDatabaseTexture("toolbar.button.pressed", "black", style
);
846 resource
.tstyle
.clock
=
847 readDatabaseTexture("toolbar.clock", "black", style
);
848 resource
.tstyle
.l_text
=
849 readDatabaseColor("toolbar.label.textColor", "white", style
);
850 resource
.tstyle
.w_text
=
851 readDatabaseColor("toolbar.windowLabel.textColor", "white", style
);
852 resource
.tstyle
.c_text
=
853 readDatabaseColor("toolbar.clock.textColor", "white", style
);
854 resource
.tstyle
.b_pic
=
855 readDatabaseColor("toolbar.button.picColor", "black", style
);
857 resource
.tstyle
.justify
= LeftJustify
;
858 if (style
.getValue("toolbar.justify", s
)) {
859 if (s
== "right" || s
== "Right")
860 resource
.tstyle
.justify
= RightJustify
;
861 else if (s
== "center" || s
== "Center")
862 resource
.tstyle
.justify
= CenterJustify
;
866 resource
.mstyle
.title
=
867 readDatabaseTexture("menu.title", "white", style
);
868 resource
.mstyle
.frame
=
869 readDatabaseTexture("menu.frame", "black", style
);
870 resource
.mstyle
.hilite
=
871 readDatabaseTexture("menu.hilite", "white", style
);
872 resource
.mstyle
.t_text
=
873 readDatabaseColor("menu.title.textColor", "black", style
);
874 resource
.mstyle
.f_text
=
875 readDatabaseColor("menu.frame.textColor", "white", style
);
876 resource
.mstyle
.d_text
=
877 readDatabaseColor("menu.frame.disableColor", "black", style
);
878 resource
.mstyle
.h_text
=
879 readDatabaseColor("menu.hilite.textColor", "black", style
);
881 resource
.mstyle
.t_justify
= LeftJustify
;
882 if (style
.getValue("menu.title.justify", s
)) {
883 if (s
== "right" || s
== "Right")
884 resource
.mstyle
.t_justify
= RightJustify
;
885 else if (s
== "center" || s
== "Center")
886 resource
.mstyle
.t_justify
= CenterJustify
;
889 resource
.mstyle
.f_justify
= LeftJustify
;
890 if (style
.getValue("menu.frame.justify", s
)) {
891 if (s
== "right" || s
== "Right")
892 resource
.mstyle
.f_justify
= RightJustify
;
893 else if (s
== "center" || s
== "Center")
894 resource
.mstyle
.f_justify
= CenterJustify
;
897 resource
.mstyle
.bullet
= Basemenu::Triangle
;
898 if (style
.getValue("menu.bullet", s
)) {
899 if (s
== "empty" || s
== "Empty")
900 resource
.mstyle
.bullet
= Basemenu::Empty
;
901 else if (s
== "square" || s
== "Square")
902 resource
.mstyle
.bullet
= Basemenu::Square
;
903 else if (s
== "diamond" || s
== "Diamond")
904 resource
.mstyle
.bullet
= Basemenu::Diamond
;
907 resource
.mstyle
.bullet_pos
= Basemenu::Left
;
908 if (style
.getValue("menu.bullet.position", s
)) {
909 if (s
== "right" || s
== "Right")
910 resource
.mstyle
.bullet_pos
= Basemenu::Right
;
913 resource
.border_color
=
914 readDatabaseColor("borderColor", "black", style
);
916 // load bevel, border and handle widths
917 if (! style
.getValue("handleWidth", resource
.handle_width
) ||
918 resource
.handle_width
> (getWidth() / 2) || resource
.handle_width
== 0)
919 resource
.handle_width
= 6;
921 if (! style
.getValue("borderWidth", resource
.border_width
))
922 resource
.border_width
= 1;
924 if (! style
.getValue("bevelWidth", resource
.bevel_width
) ||
925 resource
.bevel_width
> (getWidth() / 2) || resource
.bevel_width
== 0)
926 resource
.bevel_width
= 3;
928 if (! style
.getValue("frameWidth", resource
.frame_width
) ||
929 resource
.frame_width
> (getWidth() / 2))
930 resource
.frame_width
= resource
.bevel_width
;
932 if (style
.getValue("rootCommand", s
))
933 bexec(s
, displayString());
937 void BScreen::addIcon(BlackboxWindow
*w
) {
940 w
->setWorkspace(BSENTINEL
);
941 w
->setWindowNumber(iconList
.size());
943 iconList
.push_back(w
);
945 const char* title
= w
->getIconTitle();
946 iconmenu
->insert(title
);
951 void BScreen::removeIcon(BlackboxWindow
*w
) {
956 iconmenu
->remove(w
->getWindowNumber());
959 BlackboxWindowList::iterator it
= iconList
.begin(),
960 end
= iconList
.end();
961 for (int i
= 0; it
!= end
; ++it
)
962 (*it
)->setWindowNumber(i
++);
966 BlackboxWindow
*BScreen::getIcon(unsigned int index
) {
967 if (index
< iconList
.size()) {
968 BlackboxWindowList::iterator it
= iconList
.begin();
969 for (; index
> 0; --index
, ++it
) ; /* increment to index */
973 return (BlackboxWindow
*) 0;
977 unsigned int BScreen::addWorkspace(void) {
978 Workspace
*wkspc
= new Workspace(this, workspacesList
.size());
979 workspacesList
.push_back(wkspc
);
980 saveWorkspaces(getWorkspaceCount());
981 saveWorkspaceNames();
983 workspacemenu
->insertWorkspace(wkspc
);
984 workspacemenu
->update();
986 toolbar
->reconfigure();
988 updateNetizenWorkspaceCount();
990 return workspacesList
.size();
994 unsigned int BScreen::removeLastWorkspace(void) {
995 if (workspacesList
.size() == 1)
998 Workspace
*wkspc
= workspacesList
.back();
1000 if (current_workspace
->getID() == wkspc
->getID())
1001 changeWorkspaceID(current_workspace
->getID() - 1);
1005 workspacemenu
->removeWorkspace(wkspc
);
1006 workspacemenu
->update();
1008 workspacesList
.pop_back();
1011 saveWorkspaces(getWorkspaceCount());
1012 saveWorkspaceNames();
1014 toolbar
->reconfigure();
1016 updateNetizenWorkspaceCount();
1018 return workspacesList
.size();
1022 void BScreen::changeWorkspaceID(unsigned int id
) {
1023 if (! current_workspace
|| id
== current_workspace
->getID()) return;
1025 BlackboxWindow
*focused
= blackbox
->getFocusedWindow();
1026 if (focused
&& focused
->getScreen() == this) {
1027 assert(focused
->isStuck() ||
1028 focused
->getWorkspaceNumber() == current_workspace
->getID());
1030 current_workspace
->setLastFocusedWindow(focused
);
1032 // if no window had focus, no need to store a last focus
1033 current_workspace
->setLastFocusedWindow((BlackboxWindow
*) 0);
1036 // when we switch workspaces, unfocus whatever was focused
1037 blackbox
->setFocusedWindow((BlackboxWindow
*) 0);
1039 current_workspace
->hideAll();
1040 workspacemenu
->setItemSelected(current_workspace
->getID() + 2, False
);
1042 current_workspace
= getWorkspace(id
);
1044 xatom
->setValue(getRootWindow(), XAtom::net_current_desktop
,
1045 XAtom::cardinal
, id
);
1047 workspacemenu
->setItemSelected(current_workspace
->getID() + 2, True
);
1048 toolbar
->redrawWorkspaceLabel(True
);
1050 current_workspace
->showAll();
1052 if (resource
.focus_last
&& current_workspace
->getLastFocusedWindow()) {
1053 XSync(blackbox
->getXDisplay(), False
);
1054 current_workspace
->getLastFocusedWindow()->setInputFocus();
1057 updateNetizenCurrentWorkspace();
1062 * Set the _NET_CLIENT_LIST root window property.
1064 void BScreen::updateClientList(void) {
1065 if (windowList
.size() > 0) {
1066 Window
*windows
= new Window
[windowList
.size()];
1067 Window
*win_it
= windows
;
1068 BlackboxWindowList::iterator it
= windowList
.begin();
1069 const BlackboxWindowList::iterator end
= windowList
.end();
1070 for (; it
!= end
; ++it
, ++win_it
)
1071 *win_it
= (*it
)->getClientWindow();
1072 xatom
->setValue(getRootWindow(), XAtom::net_client_list
, XAtom::window
,
1073 windows
, windowList
.size());
1076 xatom
->setValue(getRootWindow(), XAtom::net_client_list
, XAtom::window
,
1079 updateStackingList();
1084 * Set the _NET_CLIENT_LIST_STACKING root window property.
1086 void BScreen::updateStackingList(void) {
1088 BlackboxWindowList stack_order
;
1091 * Get the stacking order from all of the workspaces.
1092 * We start with the current workspace so that the sticky windows will be
1093 * in the right order on the current workspace.
1094 * XXX: Do we need to have sticky windows in the list once for each workspace?
1096 getCurrentWorkspace()->appendStackOrder(stack_order
);
1097 for (unsigned int i
= 0; i
< getWorkspaceCount(); ++i
)
1098 if (i
!= getCurrentWorkspaceID())
1099 getWorkspace(i
)->appendStackOrder(stack_order
);
1101 if (stack_order
.size() > 0) {
1102 // set the client list atoms
1103 Window
*windows
= new Window
[stack_order
.size()];
1104 Window
*win_it
= windows
;
1105 BlackboxWindowList::iterator it
= stack_order
.begin(),
1106 end
= stack_order
.end();
1107 for (; it
!= end
; ++it
, ++win_it
)
1108 *win_it
= (*it
)->getClientWindow();
1109 xatom
->setValue(getRootWindow(), XAtom::net_client_list_stacking
,
1110 XAtom::window
, windows
, stack_order
.size());
1113 xatom
->setValue(getRootWindow(), XAtom::net_client_list_stacking
,
1114 XAtom::window
, 0, 0);
1118 void BScreen::addSystrayWindow(Window window
) {
1119 systrayWindowList
.push_back(window
);
1120 xatom
->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows
,
1122 &systrayWindowList
[0], systrayWindowList
.size());
1123 blackbox
->saveSystrayWindowSearch(window
, this);
1127 void BScreen::removeSystrayWindow(Window window
) {
1128 WindowList::iterator it
= systrayWindowList
.begin();
1129 const WindowList::iterator end
= systrayWindowList
.end();
1130 for (; it
!= end
; ++it
)
1131 if (*it
== window
) {
1132 systrayWindowList
.erase(it
);
1133 xatom
->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows
,
1135 &systrayWindowList
[0], systrayWindowList
.size());
1136 blackbox
->removeSystrayWindowSearch(window
);
1142 void BScreen::addDesktopWindow(Window window
) {
1143 desktopWindowList
.push_back(window
);
1144 XLowerWindow(blackbox
->getXDisplay(), window
);
1145 XSelectInput(blackbox
->getXDisplay(), window
, StructureNotifyMask
);
1146 blackbox
->saveDesktopWindowSearch(window
, this);
1150 void BScreen::removeDesktopWindow(Window window
) {
1151 WindowList::iterator it
= desktopWindowList
.begin();
1152 const WindowList::iterator end
= desktopWindowList
.end();
1153 for (; it
!= end
; ++it
)
1154 if (*it
== window
) {
1155 desktopWindowList
.erase(it
);
1156 XSelectInput(blackbox
->getXDisplay(), window
, None
);
1157 blackbox
->removeDesktopWindowSearch(window
);
1163 void BScreen::manageWindow(Window w
) {
1164 new BlackboxWindow(blackbox
, w
, this);
1166 BlackboxWindow
*win
= blackbox
->searchWindow(w
);
1169 if (win
->isDesktop()) {
1170 // desktop windows cant do anything, so we remove all the normal window
1171 // stuff from them, they are only kept around so that we can keep them on
1172 // the bottom of the z-order
1174 addDesktopWindow(win
->getClientWindow());
1179 windowList
.push_back(win
);
1182 XMapRequestEvent mre
;
1184 if (blackbox
->isStartup()) win
->restoreAttributes();
1185 win
->mapRequestEvent(&mre
);
1189 void BScreen::unmanageWindow(BlackboxWindow
*w
, bool remap
) {
1192 if (w
->getWorkspaceNumber() != BSENTINEL
&&
1193 w
->getWindowNumber() != BSENTINEL
)
1194 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
1195 else if (w
->isIconic())
1198 windowList
.remove(w
);
1201 if (blackbox
->getFocusedWindow() == w
)
1202 blackbox
->setFocusedWindow((BlackboxWindow
*) 0);
1204 removeNetizen(w
->getClientWindow());
1207 some managed windows can also be window group controllers. when
1208 unmanaging such windows, we should also delete the window group.
1210 BWindowGroup
*group
= blackbox
->searchGroup(w
->getClientWindow());
1217 void BScreen::addNetizen(Netizen
*n
) {
1218 netizenList
.push_back(n
);
1220 n
->sendWorkspaceCount();
1221 n
->sendCurrentWorkspace();
1223 WorkspaceList::iterator it
= workspacesList
.begin();
1224 const WorkspaceList::iterator end
= workspacesList
.end();
1225 for (; it
!= end
; ++it
)
1226 (*it
)->sendWindowList(*n
);
1228 Window f
= ((blackbox
->getFocusedWindow()) ?
1229 blackbox
->getFocusedWindow()->getClientWindow() : None
);
1230 n
->sendWindowFocus(f
);
1234 void BScreen::removeNetizen(Window w
) {
1235 NetizenList::iterator it
= netizenList
.begin();
1236 for (; it
!= netizenList
.end(); ++it
) {
1237 if ((*it
)->getWindowID() == w
) {
1239 netizenList
.erase(it
);
1246 void BScreen::updateWorkArea(void) {
1247 if (workspacesList
.size() > 0) {
1248 unsigned long *dims
= new unsigned long[4 * workspacesList
.size()];
1249 for (unsigned int i
= 0, m
= workspacesList
.size(); i
< m
; ++i
) {
1250 // XXX: this could be different for each workspace
1251 const Rect
&area
= availableArea();
1252 dims
[(i
* 4) + 0] = area
.x();
1253 dims
[(i
* 4) + 1] = area
.y();
1254 dims
[(i
* 4) + 2] = area
.width();
1255 dims
[(i
* 4) + 3] = area
.height();
1257 xatom
->setValue(getRootWindow(), XAtom::net_workarea
, XAtom::cardinal
,
1258 dims
, 4 * workspacesList
.size());
1261 xatom
->setValue(getRootWindow(), XAtom::net_workarea
, XAtom::cardinal
,
1266 void BScreen::updateNetizenCurrentWorkspace(void) {
1267 std::for_each(netizenList
.begin(), netizenList
.end(),
1268 std::mem_fun(&Netizen::sendCurrentWorkspace
));
1272 void BScreen::updateNetizenWorkspaceCount(void) {
1273 xatom
->setValue(getRootWindow(), XAtom::net_number_of_desktops
,
1274 XAtom::cardinal
, workspacesList
.size());
1278 std::for_each(netizenList
.begin(), netizenList
.end(),
1279 std::mem_fun(&Netizen::sendWorkspaceCount
));
1283 void BScreen::updateNetizenWindowFocus(void) {
1284 Window f
= ((blackbox
->getFocusedWindow()) ?
1285 blackbox
->getFocusedWindow()->getClientWindow() : None
);
1287 xatom
->setValue(getRootWindow(), XAtom::net_active_window
,
1290 NetizenList::iterator it
= netizenList
.begin();
1291 for (; it
!= netizenList
.end(); ++it
)
1292 (*it
)->sendWindowFocus(f
);
1296 void BScreen::updateNetizenWindowAdd(Window w
, unsigned long p
) {
1297 NetizenList::iterator it
= netizenList
.begin();
1298 for (; it
!= netizenList
.end(); ++it
) {
1299 (*it
)->sendWindowAdd(w
, p
);
1304 void BScreen::updateNetizenWindowDel(Window w
) {
1305 NetizenList::iterator it
= netizenList
.begin();
1306 for (; it
!= netizenList
.end(); ++it
)
1307 (*it
)->sendWindowDel(w
);
1311 void BScreen::updateNetizenWindowRaise(Window w
) {
1312 NetizenList::iterator it
= netizenList
.begin();
1313 for (; it
!= netizenList
.end(); ++it
)
1314 (*it
)->sendWindowRaise(w
);
1318 void BScreen::updateNetizenWindowLower(Window w
) {
1319 NetizenList::iterator it
= netizenList
.begin();
1320 for (; it
!= netizenList
.end(); ++it
)
1321 (*it
)->sendWindowLower(w
);
1325 void BScreen::updateNetizenConfigNotify(XEvent
*e
) {
1326 NetizenList::iterator it
= netizenList
.begin();
1327 for (; it
!= netizenList
.end(); ++it
)
1328 (*it
)->sendConfigNotify(e
);
1332 void BScreen::raiseWindows(Window
*workspace_stack
, unsigned int num
) {
1333 // the 13 represents the number of blackbox windows such as menus
1334 Window
*session_stack
= new
1335 Window
[(num
+ workspacesList
.size() + rootmenuList
.size() + 13)];
1336 unsigned int i
= 0, k
= num
;
1338 XRaiseWindow(blackbox
->getXDisplay(), iconmenu
->getWindowID());
1339 *(session_stack
+ i
++) = iconmenu
->getWindowID();
1341 WorkspaceList::iterator wit
= workspacesList
.begin();
1342 const WorkspaceList::iterator w_end
= workspacesList
.end();
1343 for (; wit
!= w_end
; ++wit
)
1344 *(session_stack
+ i
++) = (*wit
)->getMenu()->getWindowID();
1346 *(session_stack
+ i
++) = workspacemenu
->getWindowID();
1348 *(session_stack
+ i
++) = configmenu
->getFocusmenu()->getWindowID();
1349 *(session_stack
+ i
++) = configmenu
->getPlacementmenu()->getWindowID();
1350 *(session_stack
+ i
++) = configmenu
->getWindowID();
1352 *(session_stack
+ i
++) = slit
->getMenu()->getDirectionmenu()->getWindowID();
1353 *(session_stack
+ i
++) = slit
->getMenu()->getPlacementmenu()->getWindowID();
1354 *(session_stack
+ i
++) = slit
->getMenu()->getWindowID();
1356 *(session_stack
+ i
++) =
1357 toolbar
->getMenu()->getPlacementmenu()->getWindowID();
1358 *(session_stack
+ i
++) = toolbar
->getMenu()->getWindowID();
1360 RootmenuList::iterator rit
= rootmenuList
.begin();
1361 for (; rit
!= rootmenuList
.end(); ++rit
)
1362 *(session_stack
+ i
++) = (*rit
)->getWindowID();
1363 *(session_stack
+ i
++) = rootmenu
->getWindowID();
1365 if (toolbar
->isOnTop())
1366 *(session_stack
+ i
++) = toolbar
->getWindowID();
1368 if (slit
->isOnTop())
1369 *(session_stack
+ i
++) = slit
->getWindowID();
1372 *(session_stack
+ i
++) = *(workspace_stack
+ k
);
1374 XRestackWindows(blackbox
->getXDisplay(), session_stack
, i
);
1376 delete [] session_stack
;
1378 updateStackingList();
1382 void BScreen::lowerWindows(Window
*workspace_stack
, unsigned int num
) {
1383 assert(num
> 0); // this would cause trouble in the XRaiseWindow call
1385 Window
*session_stack
= new Window
[(num
+ desktopWindowList
.size())];
1386 unsigned int i
= 0, k
= num
;
1388 XLowerWindow(blackbox
->getXDisplay(), workspace_stack
[0]);
1391 *(session_stack
+ i
++) = *(workspace_stack
+ k
);
1393 WindowList::iterator dit
= desktopWindowList
.begin();
1394 const WindowList::iterator d_end
= desktopWindowList
.end();
1395 for (; dit
!= d_end
; ++dit
)
1396 *(session_stack
+ i
++) = *dit
;
1398 XRestackWindows(blackbox
->getXDisplay(), session_stack
, i
);
1400 delete [] session_stack
;
1402 updateStackingList();
1406 void BScreen::reassociateWindow(BlackboxWindow
*w
, unsigned int wkspc_id
,
1407 bool ignore_sticky
) {
1410 if (wkspc_id
== BSENTINEL
)
1411 wkspc_id
= current_workspace
->getID();
1413 if (w
->getWorkspaceNumber() == wkspc_id
)
1416 if (w
->isIconic()) {
1418 getWorkspace(wkspc_id
)->addWindow(w
);
1419 } else if (ignore_sticky
|| ! w
->isStuck()) {
1420 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
1421 getWorkspace(wkspc_id
)->addWindow(w
);
1423 updateStackingList();
1427 void BScreen::propagateWindowName(const BlackboxWindow
*bw
) {
1428 if (bw
->isIconic()) {
1429 iconmenu
->changeItemLabel(bw
->getWindowNumber(), bw
->getIconTitle());
1433 Clientmenu
*clientmenu
= getWorkspace(bw
->getWorkspaceNumber())->getMenu();
1434 clientmenu
->changeItemLabel(bw
->getWindowNumber(), bw
->getTitle());
1435 clientmenu
->update();
1437 if (blackbox
->getFocusedWindow() == bw
)
1438 toolbar
->redrawWindowLabel(True
);
1443 void BScreen::nextFocus(void) {
1444 BlackboxWindow
*focused
= blackbox
->getFocusedWindow(),
1448 // if window is not on this screen, ignore it
1449 if (focused
->getScreen()->getScreenNumber() != getScreenNumber())
1450 focused
= (BlackboxWindow
*) 0;
1453 if (focused
&& current_workspace
->getCount() > 1) {
1454 // next is the next window to recieve focus, current is a place holder
1455 BlackboxWindow
*current
;
1458 next
= current_workspace
->getNextWindowInList(current
);
1459 } while(! next
->setInputFocus() && next
!= focused
);
1461 if (next
!= focused
)
1462 current_workspace
->raiseWindow(next
);
1463 } else if (current_workspace
->getCount() >= 1) {
1464 next
= current_workspace
->getTopWindowOnStack();
1466 current_workspace
->raiseWindow(next
);
1467 next
->setInputFocus();
1472 void BScreen::prevFocus(void) {
1473 BlackboxWindow
*focused
= blackbox
->getFocusedWindow(),
1477 // if window is not on this screen, ignore it
1478 if (focused
->getScreen()->getScreenNumber() != getScreenNumber())
1479 focused
= (BlackboxWindow
*) 0;
1482 if (focused
&& current_workspace
->getCount() > 1) {
1483 // next is the next window to recieve focus, current is a place holder
1484 BlackboxWindow
*current
;
1487 next
= current_workspace
->getPrevWindowInList(current
);
1488 } while(! next
->setInputFocus() && next
!= focused
);
1490 if (next
!= focused
)
1491 current_workspace
->raiseWindow(next
);
1492 } else if (current_workspace
->getCount() >= 1) {
1493 next
= current_workspace
->getTopWindowOnStack();
1495 current_workspace
->raiseWindow(next
);
1496 next
->setInputFocus();
1501 void BScreen::raiseFocus(void) {
1502 BlackboxWindow
*focused
= blackbox
->getFocusedWindow();
1506 // if on this Screen, raise it
1507 if (focused
->getScreen()->getScreenNumber() == getScreenNumber()) {
1508 Workspace
*workspace
= getWorkspace(focused
->getWorkspaceNumber());
1509 workspace
->raiseWindow(focused
);
1514 void BScreen::InitMenu(void) {
1516 rootmenuList
.clear();
1518 while (rootmenu
->getCount())
1519 rootmenu
->remove(0);
1521 rootmenu
= new Rootmenu(this);
1523 bool defaultMenu
= True
;
1525 FILE *menu_file
= (FILE *) 0;
1526 const char *menu_filename
= blackbox
->getMenuFilename();
1529 if (! (menu_file
= fopen(menu_filename
, "r")))
1530 perror(menu_filename
);
1531 if (! menu_file
) { // opening the menu file failed, try the default menu
1532 menu_filename
= DEFAULTMENU
;
1533 if (! (menu_file
= fopen(menu_filename
, "r")))
1534 perror(menu_filename
);
1538 if (feof(menu_file
)) {
1539 fprintf(stderr
, i18n(ScreenSet
, ScreenEmptyMenuFile
,
1540 "%s: Empty menu file"),
1543 char line
[1024], label
[1024];
1544 memset(line
, 0, 1024);
1545 memset(label
, 0, 1024);
1547 while (fgets(line
, 1024, menu_file
) && ! feof(menu_file
)) {
1548 if (line
[0] != '#') {
1549 int i
, key
= 0, index
= -1, len
= strlen(line
);
1551 for (i
= 0; i
< len
; i
++) {
1552 if (line
[i
] == '[') index
= 0;
1553 else if (line
[i
] == ']') break;
1554 else if (line
[i
] != ' ')
1556 key
+= tolower(line
[i
]);
1559 if (key
== 517) { // [begin]
1561 for (i
= index
; i
< len
; i
++) {
1562 if (line
[i
] == '(') index
= 0;
1563 else if (line
[i
] == ')') break;
1564 else if (index
++ >= 0) {
1565 if (line
[i
] == '\\' && i
< len
- 1) i
++;
1566 label
[index
- 1] = line
[i
];
1570 if (index
== -1) index
= 0;
1571 label
[index
] = '\0';
1573 rootmenu
->setLabel(label
);
1574 defaultMenu
= parseMenuFile(menu_file
, rootmenu
);
1576 blackbox
->addMenuTimestamp(menu_filename
);
1586 rootmenu
->setInternalMenu();
1587 rootmenu
->insert(i18n(ScreenSet
, Screenxterm
, "xterm"),
1589 i18n(ScreenSet
, Screenxterm
, "xterm"));
1590 rootmenu
->insert(i18n(ScreenSet
, ScreenRestart
, "Restart"),
1592 rootmenu
->insert(i18n(ScreenSet
, ScreenExit
, "Exit"),
1594 rootmenu
->setLabel(i18n(BasemenuSet
, BasemenuBlackboxMenu
,
1600 bool BScreen::parseMenuFile(FILE *file
, Rootmenu
*menu
) {
1601 char line
[1024], label
[1024], command
[1024];
1603 while (! feof(file
)) {
1604 memset(line
, 0, 1024);
1605 memset(label
, 0, 1024);
1606 memset(command
, 0, 1024);
1608 if (fgets(line
, 1024, file
)) {
1609 if (line
[0] != '#') {
1610 int i
, key
= 0, parse
= 0, index
= -1, line_length
= strlen(line
);
1612 // determine the keyword
1613 for (i
= 0; i
< line_length
; i
++) {
1614 if (line
[i
] == '[') parse
= 1;
1615 else if (line
[i
] == ']') break;
1616 else if (line
[i
] != ' ')
1618 key
+= tolower(line
[i
]);
1621 // get the label enclosed in ()'s
1624 for (i
= 0; i
< line_length
; i
++) {
1625 if (line
[i
] == '(') {
1628 } else if (line
[i
] == ')') break;
1629 else if (index
++ >= 0) {
1630 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
1631 label
[index
- 1] = line
[i
];
1636 label
[index
] = '\0';
1641 // get the command enclosed in {}'s
1644 for (i
= 0; i
< line_length
; i
++) {
1645 if (line
[i
] == '{') {
1648 } else if (line
[i
] == '}') break;
1649 else if (index
++ >= 0) {
1650 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
1651 command
[index
- 1] = line
[i
];
1656 command
[index
] = '\0';
1663 return ((menu
->getCount() == 0) ? True
: False
);
1670 menu
->insert(label
);
1675 if ((! *label
) && (! *command
)) {
1676 fprintf(stderr
, i18n(ScreenSet
, ScreenEXECError
,
1677 "BScreen::parseMenuFile: [exec] error, "
1678 "no menu label and/or command defined\n"));
1682 menu
->insert(label
, BScreen::Execute
, command
);
1688 fprintf(stderr
, i18n(ScreenSet
, ScreenEXITError
,
1689 "BScreen::parseMenuFile: [exit] error, "
1690 "no menu label defined\n"));
1694 menu
->insert(label
, BScreen::Exit
);
1700 if ((! *label
) || (! *command
)) {
1702 i18n(ScreenSet
, ScreenSTYLEError
,
1703 "BScreen::parseMenuFile: [style] error, "
1704 "no menu label and/or filename defined\n"));
1708 string style
= expandTilde(command
);
1710 menu
->insert(label
, BScreen::SetStyle
, style
.c_str());
1717 fprintf(stderr
, i18n(ScreenSet
, ScreenCONFIGError
,
1718 "BScreen::parseMenufile: [config] error, "
1719 "no label defined"));
1723 menu
->insert(label
, configmenu
);
1727 case 740: // include
1730 fprintf(stderr
, i18n(ScreenSet
, ScreenINCLUDEError
,
1731 "BScreen::parseMenuFile: [include] error, "
1732 "no filename defined\n"));
1736 string newfile
= expandTilde(label
);
1737 FILE *submenufile
= fopen(newfile
.c_str(), "r");
1741 if (fstat(fileno(submenufile
), &buf
) ||
1742 (! S_ISREG(buf
.st_mode
))) {
1744 i18n(ScreenSet
, ScreenINCLUDEErrorReg
,
1745 "BScreen::parseMenuFile: [include] error: "
1746 "'%s' is not a regular file\n"), newfile
.c_str());
1750 if (! feof(submenufile
)) {
1751 if (! parseMenuFile(submenufile
, menu
))
1752 blackbox
->addMenuTimestamp(newfile
);
1754 fclose(submenufile
);
1757 perror(newfile
.c_str());
1763 case 767: // submenu
1766 fprintf(stderr
, i18n(ScreenSet
, ScreenSUBMENUError
,
1767 "BScreen::parseMenuFile: [submenu] error, "
1768 "no menu label defined\n"));
1772 Rootmenu
*submenu
= new Rootmenu(this);
1775 submenu
->setLabel(command
);
1777 submenu
->setLabel(label
);
1779 parseMenuFile(file
, submenu
);
1781 menu
->insert(label
, submenu
);
1782 rootmenuList
.push_back(submenu
);
1787 case 773: // restart
1790 fprintf(stderr
, i18n(ScreenSet
, ScreenRESTARTError
,
1791 "BScreen::parseMenuFile: [restart] error, "
1792 "no menu label defined\n"));
1797 menu
->insert(label
, BScreen::RestartOther
, command
);
1799 menu
->insert(label
, BScreen::Restart
);
1804 case 845: // reconfig
1808 i18n(ScreenSet
, ScreenRECONFIGError
,
1809 "BScreen::parseMenuFile: [reconfig] error, "
1810 "no menu label defined\n"));
1814 menu
->insert(label
, BScreen::Reconfigure
);
1819 case 995: // stylesdir
1820 case 1113: // stylesmenu
1822 bool newmenu
= ((key
== 1113) ? True
: False
);
1824 if ((! *label
) || ((! *command
) && newmenu
)) {
1826 i18n(ScreenSet
, ScreenSTYLESDIRError
,
1827 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1828 " error, no directory defined\n"));
1832 char *directory
= ((newmenu
) ? command
: label
);
1834 string stylesdir
= expandTilde(directory
);
1836 struct stat statbuf
;
1838 if (! stat(stylesdir
.c_str(), &statbuf
)) {
1839 if (S_ISDIR(statbuf
.st_mode
)) {
1840 Rootmenu
*stylesmenu
;
1843 stylesmenu
= new Rootmenu(this);
1847 DIR *d
= opendir(stylesdir
.c_str());
1849 std::vector
<string
> ls
;
1851 while((p
= readdir(d
)))
1852 ls
.push_back(p
->d_name
);
1856 std::sort(ls
.begin(), ls
.end());
1858 std::vector
<string
>::iterator it
= ls
.begin(),
1860 for (; it
!= end
; ++it
) {
1861 const string
& fname
= *it
;
1863 if (fname
[fname
.size()-1] == '~')
1866 string style
= stylesdir
;
1870 if ((! stat(style
.c_str(), &statbuf
)) &&
1871 S_ISREG(statbuf
.st_mode
))
1872 stylesmenu
->insert(fname
, BScreen::SetStyle
, style
);
1875 stylesmenu
->update();
1878 stylesmenu
->setLabel(label
);
1879 menu
->insert(label
, stylesmenu
);
1880 rootmenuList
.push_back(stylesmenu
);
1883 blackbox
->addMenuTimestamp(stylesdir
);
1886 i18n(ScreenSet
, ScreenSTYLESDIRErrorNotDir
,
1887 "BScreen::parseMenuFile:"
1888 " [stylesdir/stylesmenu] error, %s is not a"
1889 " directory\n"), stylesdir
.c_str());
1893 i18n(ScreenSet
, ScreenSTYLESDIRErrorNoExist
,
1894 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1895 " error, %s does not exist\n"), stylesdir
.c_str());
1900 case 1090: // workspaces
1904 i18n(ScreenSet
, ScreenWORKSPACESError
,
1905 "BScreen:parseMenuFile: [workspaces] error, "
1906 "no menu label defined\n"));
1910 menu
->insert(label
, workspacemenu
);
1919 return ((menu
->getCount() == 0) ? True
: False
);
1923 void BScreen::shutdown(void) {
1924 XSelectInput(blackbox
->getXDisplay(), getRootWindow(), NoEventMask
);
1925 XSync(blackbox
->getXDisplay(), False
);
1927 while(! windowList
.empty())
1928 unmanageWindow(windowList
.front(), True
);
1934 void BScreen::showPosition(int x
, int y
) {
1935 if (! geom_visible
) {
1936 XMoveResizeWindow(blackbox
->getXDisplay(), geom_window
,
1937 (getWidth() - geom_w
) / 2,
1938 (getHeight() - geom_h
) / 2, geom_w
, geom_h
);
1939 XMapWindow(blackbox
->getXDisplay(), geom_window
);
1940 XRaiseWindow(blackbox
->getXDisplay(), geom_window
);
1942 geom_visible
= True
;
1947 sprintf(label
, i18n(ScreenSet
, ScreenPositionFormat
,
1948 "X: %4d x Y: %4d"), x
, y
);
1950 XClearWindow(blackbox
->getXDisplay(), geom_window
);
1952 resource
.wstyle
.font
->drawString(geom_window
,
1953 resource
.bevel_width
, resource
.bevel_width
,
1954 resource
.wstyle
.l_text_focus
,
1959 void BScreen::showGeometry(unsigned int gx
, unsigned int gy
) {
1960 if (! geom_visible
) {
1961 XMoveResizeWindow(blackbox
->getXDisplay(), geom_window
,
1962 (getWidth() - geom_w
) / 2,
1963 (getHeight() - geom_h
) / 2, geom_w
, geom_h
);
1964 XMapWindow(blackbox
->getXDisplay(), geom_window
);
1965 XRaiseWindow(blackbox
->getXDisplay(), geom_window
);
1967 geom_visible
= True
;
1972 sprintf(label
, i18n(ScreenSet
, ScreenGeometryFormat
,
1973 "W: %4d x H: %4d"), gx
, gy
);
1975 XClearWindow(blackbox
->getXDisplay(), geom_window
);
1977 resource
.wstyle
.font
->drawString(geom_window
,
1978 resource
.bevel_width
, resource
.bevel_width
,
1979 resource
.wstyle
.l_text_focus
,
1984 void BScreen::hideGeometry(void) {
1986 XUnmapWindow(blackbox
->getXDisplay(), geom_window
);
1987 geom_visible
= False
;
1992 void BScreen::addStrut(Strut
*strut
) {
1993 strutList
.push_back(strut
);
1997 void BScreen::removeStrut(Strut
*strut
) {
1998 strutList
.remove(strut
);
2002 const Rect
& BScreen::availableArea(void) const {
2004 return getRect(); // return the full screen
2009 void BScreen::updateAvailableArea(void) {
2010 Rect old_area
= usableArea
;
2011 usableArea
= getRect(); // reset to full screen
2013 /* these values represent offsets from the screen edge
2014 * we look for the biggest offset on each edge and then apply them
2016 * do not be confused by the similarity to the names of Rect's members
2018 unsigned int current_left
= 0, current_right
= 0, current_top
= 0,
2021 StrutList::const_iterator it
= strutList
.begin(), end
= strutList
.end();
2023 for(; it
!= end
; ++it
) {
2025 if (strut
->left
> current_left
)
2026 current_left
= strut
->left
;
2027 if (strut
->top
> current_top
)
2028 current_top
= strut
->top
;
2029 if (strut
->right
> current_right
)
2030 current_right
= strut
->right
;
2031 if (strut
->bottom
> current_bottom
)
2032 current_bottom
= strut
->bottom
;
2035 usableArea
.setPos(current_left
, current_top
);
2036 usableArea
.setSize(usableArea
.width() - (current_left
+ current_right
),
2037 usableArea
.height() - (current_top
+ current_bottom
));
2039 if (old_area
!= usableArea
) {
2040 BlackboxWindowList::iterator it
= windowList
.begin(),
2041 end
= windowList
.end();
2042 for (; it
!= end
; ++it
)
2043 if ((*it
)->isMaximized()) (*it
)->remaximize();
2050 Workspace
* BScreen::getWorkspace(unsigned int index
) {
2051 assert(index
< workspacesList
.size());
2052 return workspacesList
[index
];
2056 void BScreen::buttonPressEvent(const XButtonEvent
*xbutton
) {
2057 if (xbutton
->button
== 1) {
2058 if (! isRootColormapInstalled())
2059 image_control
->installRootColormap();
2061 if (workspacemenu
->isVisible())
2062 workspacemenu
->hide();
2064 if (rootmenu
->isVisible())
2066 } else if (xbutton
->button
== 2) {
2067 int mx
= xbutton
->x_root
- (workspacemenu
->getWidth() / 2);
2068 int my
= xbutton
->y_root
- (workspacemenu
->getTitleHeight() / 2);
2073 if (mx
+ workspacemenu
->getWidth() > getWidth())
2074 mx
= getWidth() - workspacemenu
->getWidth() - getBorderWidth();
2076 if (my
+ workspacemenu
->getHeight() > getHeight())
2077 my
= getHeight() - workspacemenu
->getHeight() - getBorderWidth();
2079 workspacemenu
->move(mx
, my
);
2081 if (! workspacemenu
->isVisible()) {
2082 workspacemenu
->removeParent();
2083 workspacemenu
->show();
2085 } else if (xbutton
->button
== 3) {
2086 int mx
= xbutton
->x_root
- (rootmenu
->getWidth() / 2);
2087 int my
= xbutton
->y_root
- (rootmenu
->getTitleHeight() / 2);
2092 if (mx
+ rootmenu
->getWidth() > getWidth())
2093 mx
= getWidth() - rootmenu
->getWidth() - getBorderWidth();
2095 if (my
+ rootmenu
->getHeight() > getHeight())
2096 my
= getHeight() - rootmenu
->getHeight() - getBorderWidth();
2098 rootmenu
->move(mx
, my
);
2100 if (! rootmenu
->isVisible()) {
2101 blackbox
->checkMenu();
2105 } else if (xbutton
->button
== 4) {
2106 if (getCurrentWorkspaceID() >= getWorkspaceCount() - 1)
2107 changeWorkspaceID(0);
2109 changeWorkspaceID(getCurrentWorkspaceID() + 1);
2111 } else if (xbutton
->button
== 5) {
2112 if (getCurrentWorkspaceID() == 0)
2113 changeWorkspaceID(getWorkspaceCount() - 1);
2115 changeWorkspaceID(getCurrentWorkspaceID() - 1);
2120 void BScreen::propertyNotifyEvent(const XPropertyEvent
*pe
) {
2121 if (pe
->atom
== xatom
->getAtom(XAtom::net_desktop_names
)) {
2122 // _NET_WM_DESKTOP_NAMES
2123 fprintf(stderr
, "UPDATING WORKSPACE NAMES\n");
2124 WorkspaceList::iterator it
= workspacesList
.begin();
2125 const WorkspaceList::iterator end
= workspacesList
.end();
2126 for (; it
!= end
; ++it
) {
2127 (*it
)->readName(); // re-read its name from the window property
2128 workspacemenu
->changeWorkspaceLabel((*it
)->getID(), (*it
)->getName());
2130 workspacemenu
->update();
2131 toolbar
->reconfigure();
2132 saveWorkspaceNames();
2137 void BScreen::toggleFocusModel(FocusModel model
) {
2138 std::for_each(windowList
.begin(), windowList
.end(),
2139 std::mem_fun(&BlackboxWindow::ungrabButtons
));
2141 if (model
== SloppyFocus
) {
2142 saveSloppyFocus(True
);
2144 // we're cheating here to save writing the config file 3 times
2145 resource
.auto_raise
= False
;
2146 resource
.click_raise
= False
;
2147 saveSloppyFocus(False
);
2150 std::for_each(windowList
.begin(), windowList
.end(),
2151 std::mem_fun(&BlackboxWindow::grabButtons
));
2155 BTexture
BScreen::readDatabaseTexture(const string
&rname
,
2156 const string
&default_color
,
2157 const Configuration
&style
) {
2161 if (style
.getValue(rname
, s
))
2162 texture
= BTexture(s
);
2164 texture
.setTexture(BTexture::Solid
| BTexture::Flat
);
2166 // associate this texture with this screen
2167 texture
.setDisplay(getBaseDisplay(), getScreenNumber());
2168 texture
.setImageControl(image_control
);
2170 if (texture
.texture() & BTexture::Solid
) {
2171 texture
.setColor(readDatabaseColor(rname
+ ".color",
2172 default_color
, style
));
2173 texture
.setColorTo(readDatabaseColor(rname
+ ".colorTo",
2174 default_color
, style
));
2175 } else if (texture
.texture() & BTexture::Gradient
) {
2176 texture
.setColor(readDatabaseColor(rname
+ ".color",
2177 default_color
, style
));
2178 texture
.setColorTo(readDatabaseColor(rname
+ ".colorTo",
2179 default_color
, style
));
2186 BColor
BScreen::readDatabaseColor(const string
&rname
,
2187 const string
&default_color
,
2188 const Configuration
&style
) {
2191 if (style
.getValue(rname
, s
))
2192 color
= BColor(s
, getBaseDisplay(), getScreenNumber());
2194 color
= BColor(default_color
, getBaseDisplay(), getScreenNumber());
2199 BFont
*BScreen::readDatabaseFont(const string
&rbasename
,
2200 const Configuration
&style
) {
2207 if (style
.getValue(rbasename
+ "xft.font", s
) &&
2208 style
.getValue(rbasename
+ "xft.size", i
)) {
2211 bool italic
= False
;
2212 if (style
.getValue(rbasename
+ "xft.flags", s
)) {
2213 if (s
.find("bold") != string::npos
)
2215 if (s
.find("italic") != string::npos
)
2219 BFont
*b
= new BFont(blackbox
->getXDisplay(), this, family
, i
, bold
,
2220 italic
, resource
.aa_fonts
);
2224 delete b
; // fall back to the normal X font stuff
2228 style
.getValue(rbasename
+ "font", s
);
2229 // if this fails, a blank string will be used, which will cause the fallback
2232 BFont
*b
= new BFont(blackbox
->getXDisplay(), this, s
);
2234 exit(2); // can't continue without a font