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.
25 #include "../config.h"
26 #endif // HAVE_CONFIG_H
29 #include <X11/Xatom.h>
30 #include <X11/keysym.h>
33 # include <X11/Xlib.h>
34 # include <X11/extensions/Xinerama.h>
39 #endif // HAVE_STDLIB_H
43 #endif // HAVE_STRING_H
47 #endif // HAVE_CTYPE_H
50 # include <sys/types.h>
52 #endif // HAVE_UNISTD_H
56 #endif // HAVE_DIRENT_H
60 #endif // HAVE_LOCALE_H
62 #ifdef HAVE_SYS_STAT_H
63 # include <sys/stat.h>
64 #endif // HAVE_SYS_STAT_H
68 #endif // HAVE_STDARG_H
79 #include "blackbox.hh"
80 #include "Clientmenu.hh"
83 #include "Iconmenu.hh"
87 #include "Rootmenu.hh"
91 #include "Workspace.hh"
92 #include "Workspacemenu.hh"
96 #ifndef FONT_ELEMENT_SIZE
97 #define FONT_ELEMENT_SIZE 50
98 #endif // FONT_ELEMENT_SIZE
101 static bool running
= True
;
103 static int anotherWMRunning(Display
*display
, XErrorEvent
*) {
104 fprintf(stderr
, i18n(ScreenSet
, ScreenAnotherWMRunning
,
105 "BScreen::BScreen: an error occured while querying the X server.\n"
106 " another window manager already running on display %s.\n"),
107 DisplayString(display
));
115 BScreen::BScreen(Blackbox
*bb
, unsigned int scrn
) : ScreenInfo(bb
, scrn
) {
117 screenstr
= "session.screen" + itostring(scrn
) + '.';
118 config
= blackbox
->getConfig();
119 xatom
= blackbox
->getXAtom();
121 event_mask
= ColormapChangeMask
| EnterWindowMask
| PropertyChangeMask
|
122 SubstructureRedirectMask
| ButtonPressMask
| ButtonReleaseMask
;
124 XErrorHandler old
= XSetErrorHandler((XErrorHandler
) anotherWMRunning
);
125 XSelectInput(getBaseDisplay()->getXDisplay(), getRootWindow(), event_mask
);
126 XSync(getBaseDisplay()->getXDisplay(), False
);
127 XSetErrorHandler((XErrorHandler
) old
);
130 if (! managed
) return;
132 fprintf(stderr
, i18n(ScreenSet
, ScreenManagingScreen
,
133 "BScreen::BScreen: managing screen %d "
134 "using visual 0x%lx, depth %d\n"),
135 getScreenNumber(), XVisualIDFromVisual(getVisual()),
140 resource
.mstyle
.t_font
= resource
.mstyle
.f_font
= resource
.tstyle
.font
=
141 resource
.wstyle
.font
= (BFont
*) 0;
145 xatom
->setSupported(this); // set-up netwm support
147 xatom
->setValue(getRootWindow(), XAtom::blackbox_pid
, XAtom::cardinal
,
148 (unsigned long) getpid());
149 #endif // HAVE_GETPID
150 unsigned long geometry
[] = { getWidth(),
152 xatom
->setValue(getRootWindow(), XAtom::net_desktop_geometry
,
153 XAtom::cardinal
, geometry
, 2);
154 unsigned long viewport
[] = {0,0};
155 xatom
->setValue(getRootWindow(), XAtom::net_desktop_viewport
,
156 XAtom::cardinal
, viewport
, 2);
159 XDefineCursor(blackbox
->getXDisplay(), getRootWindow(),
160 blackbox
->getSessionCursor());
162 updateAvailableArea();
165 new BImageControl(blackbox
, this, True
, blackbox
->getColorsPerChannel(),
166 blackbox
->getCacheLife(), blackbox
->getCacheMax());
167 image_control
->installRootColormap();
168 root_colormap_installed
= True
;
174 gcv
.foreground
= WhitePixel(blackbox
->getXDisplay(), getScreenNumber())
175 ^ BlackPixel(blackbox
->getXDisplay(), getScreenNumber());
176 gcv
.function
= GXxor
;
177 gcv
.subwindow_mode
= IncludeInferiors
;
178 opGC
= XCreateGC(blackbox
->getXDisplay(), getRootWindow(),
179 GCForeground
| GCFunction
| GCSubwindowMode
, &gcv
);
181 const char *s
= i18n(ScreenSet
, ScreenPositionLength
,
182 "0: 0000 x 0: 0000");
183 geom_w
= resource
.wstyle
.font
->measureString(s
) + resource
.bevel_width
* 2;
184 geom_h
= resource
.wstyle
.font
->height() + resource
.bevel_width
* 2;
186 XSetWindowAttributes attrib
;
187 unsigned long mask
= CWBorderPixel
| CWColormap
| CWSaveUnder
;
188 attrib
.border_pixel
= getBorderColor()->pixel();
189 attrib
.colormap
= getColormap();
190 attrib
.save_under
= True
;
192 geom_window
= XCreateWindow(blackbox
->getXDisplay(), getRootWindow(),
193 0, 0, geom_w
, geom_h
, resource
.border_width
,
194 getDepth(), InputOutput
, getVisual(),
196 geom_visible
= False
;
198 BTexture
* texture
= &(resource
.wstyle
.l_focus
);
199 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
200 if (geom_pixmap
== ParentRelative
) {
201 texture
= &(resource
.wstyle
.t_focus
);
202 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
205 XSetWindowBackground(blackbox
->getXDisplay(), geom_window
,
206 texture
->color().pixel());
208 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
209 geom_window
, geom_pixmap
);
211 workspacemenu
= new Workspacemenu(this);
212 iconmenu
= new Iconmenu(this);
213 configmenu
= new Configmenu(this);
215 if (resource
.workspaces
> 0) {
216 for (unsigned int i
= 0; i
< resource
.workspaces
; ++i
) {
217 Workspace
*wkspc
= new Workspace(this, workspacesList
.size());
218 workspacesList
.push_back(wkspc
);
219 workspacemenu
->insertWorkspace(wkspc
);
220 workspacemenu
->update();
224 Workspace
*wkspc
= new Workspace(this, workspacesList
.size());
225 workspacesList
.push_back(wkspc
);
226 workspacemenu
->insertWorkspace(wkspc
);
227 workspacemenu
->update();
229 saveWorkspaceNames();
231 updateNetizenWorkspaceCount();
233 workspacemenu
->insert(i18n(IconSet
, IconIcons
, "Icons"), iconmenu
);
234 workspacemenu
->update();
236 current_workspace
= workspacesList
.front();
238 xatom
->setValue(getRootWindow(), XAtom::net_current_desktop
,
239 XAtom::cardinal
, 0); //first workspace
241 workspacemenu
->setItemSelected(2, True
);
243 toolbar
= new Toolbar(this);
245 slit
= new Slit(this);
249 raiseWindows(0, 0); // this also initializes the empty stacking list
252 updateClientList(); // initialize the client lists, which will be empty
253 updateAvailableArea();
255 changeWorkspaceID(0);
257 unsigned int i
, j
, nchild
;
258 Window r
, p
, *children
;
259 XQueryTree(blackbox
->getXDisplay(), getRootWindow(), &r
, &p
,
262 // preen the window list of all icon windows... for better dockapp support
263 for (i
= 0; i
< nchild
; i
++) {
264 if (children
[i
] == None
) continue;
266 XWMHints
*wmhints
= XGetWMHints(blackbox
->getXDisplay(),
270 if ((wmhints
->flags
& IconWindowHint
) &&
271 (wmhints
->icon_window
!= children
[i
])) {
272 for (j
= 0; j
< nchild
; j
++) {
273 if (children
[j
] == wmhints
->icon_window
) {
284 // manage shown windows
285 for (i
= 0; i
< nchild
; ++i
) {
286 if (children
[i
] == None
|| ! blackbox
->validateWindow(children
[i
]))
289 XWindowAttributes attrib
;
290 if (XGetWindowAttributes(blackbox
->getXDisplay(), children
[i
], &attrib
)) {
291 if (attrib
.override_redirect
) continue;
293 if (attrib
.map_state
!= IsUnmapped
) {
294 manageWindow(children
[i
]);
301 // call this again just in case a window we found updates the Strut list
302 updateAvailableArea();
306 BScreen::~BScreen(void) {
307 if (! managed
) return;
309 if (geom_pixmap
!= None
)
310 image_control
->removeImage(geom_pixmap
);
312 if (geom_window
!= None
)
313 XDestroyWindow(blackbox
->getXDisplay(), geom_window
);
315 std::for_each(workspacesList
.begin(), workspacesList
.end(),
318 std::for_each(iconList
.begin(), iconList
.end(), PointerAssassin());
320 std::for_each(netizenList
.begin(), netizenList
.end(), PointerAssassin());
322 while (! systrayWindowList
.empty())
323 removeSystrayWindow(systrayWindowList
[0]);
326 delete workspacemenu
;
331 delete image_control
;
333 if (resource
.wstyle
.font
)
334 delete resource
.wstyle
.font
;
335 if (resource
.mstyle
.t_font
)
336 delete resource
.mstyle
.t_font
;
337 if (resource
.mstyle
.f_font
)
338 delete resource
.mstyle
.f_font
;
339 if (resource
.tstyle
.font
)
340 delete resource
.tstyle
.font
;
342 XFreeGC(blackbox
->getXDisplay(), opGC
);
346 void BScreen::saveSloppyFocus(bool s
) {
347 resource
.sloppy_focus
= s
;
350 if (resource
.sloppy_focus
) {
351 fmodel
= "SloppyFocus";
352 if (resource
.auto_raise
) fmodel
+= " AutoRaise";
353 if (resource
.click_raise
) fmodel
+= " ClickRaise";
355 fmodel
= "ClickToFocus";
357 config
->setValue(screenstr
+ "focusModel", fmodel
);
361 void BScreen::saveAutoRaise(bool a
) {
362 resource
.auto_raise
= a
;
363 saveSloppyFocus(resource
.sloppy_focus
);
367 void BScreen::saveClickRaise(bool c
) {
368 resource
.click_raise
= c
;
369 saveSloppyFocus(resource
.sloppy_focus
);
373 void BScreen::saveImageDither(bool d
) {
374 image_control
->setDither(d
);
375 config
->setValue(screenstr
+ "imageDither", doImageDither());
379 void BScreen::saveOpaqueMove(bool o
) {
380 resource
.opaque_move
= o
;
381 config
->setValue(screenstr
+ "opaqueMove", resource
.opaque_move
);
385 void BScreen::saveFullMax(bool f
) {
386 resource
.full_max
= f
;
387 config
->setValue(screenstr
+ "fullMaximization", resource
.full_max
);
391 void BScreen::saveFocusNew(bool f
) {
392 resource
.focus_new
= f
;
393 config
->setValue(screenstr
+ "focusNewWindows", resource
.focus_new
);
397 void BScreen::saveFocusLast(bool f
) {
398 resource
.focus_last
= f
;
399 config
->setValue(screenstr
+ "focusLastWindow", resource
.focus_last
);
403 void BScreen::saveAAFonts(bool f
) {
404 resource
.aa_fonts
= f
;
406 config
->setValue(screenstr
+ "antialiasFonts", resource
.aa_fonts
);
410 void BScreen::saveHideToolbar(bool h
) {
411 resource
.hide_toolbar
= h
;
412 if (resource
.hide_toolbar
)
413 toolbar
->unmapToolbar();
415 toolbar
->mapToolbar();
416 config
->setValue(screenstr
+ "hideToolbar", resource
.hide_toolbar
);
420 void BScreen::saveWindowToEdgeSnap(int s
) {
421 resource
.snap_to_edges
= s
;
424 switch (resource
.snap_to_edges
) {
425 case WindowNoSnap
: snap
= "NoSnap"; break;
426 case WindowResistance
: snap
= "Resistance"; break;
427 case WindowSnap
: default: snap
= "Snap"; break;
429 config
->setValue(screenstr
+ "windowToEdgeSnap", snap
);
433 void BScreen::saveWindowToWindowSnap(int s
) {
434 resource
.snap_to_windows
= s
;
437 switch (resource
.snap_to_windows
) {
438 case WindowNoSnap
: snap
= "NoSnap"; break;
439 case WindowResistance
: snap
= "Resistance"; break;
440 case WindowSnap
: default: snap
= "Snap"; break;
442 config
->setValue(screenstr
+ "windowToWindowSnap", snap
);
446 void BScreen::saveResizeZones(unsigned int z
) {
447 resource
.resize_zones
= z
;
448 config
->setValue(screenstr
+ "resizeZones", resource
.resize_zones
);
452 void BScreen::saveWindowCornerSnap(bool s
) {
453 resource
.window_corner_snap
= s
;
454 config
->setValue(screenstr
+ "windowCornerSnap",
455 resource
.window_corner_snap
);
459 void BScreen::saveWorkspaces(unsigned int w
) {
460 resource
.workspaces
= w
;
461 config
->setValue(screenstr
+ "workspaces", resource
.workspaces
);
465 void BScreen::savePlacementPolicy(int p
) {
466 resource
.placement_policy
= p
;
467 const char *placement
;
468 switch (resource
.placement_policy
) {
469 case CascadePlacement
: placement
= "CascadePlacement"; break;
470 case UnderMousePlacement
: placement
= "UnderMousePlacement"; break;
471 case ClickMousePlacement
: placement
= "ClickMousePlacement"; break;
472 case ColSmartPlacement
: placement
= "ColSmartPlacement"; break;
473 case RowSmartPlacement
: default: placement
= "RowSmartPlacement"; break;
475 config
->setValue(screenstr
+ "windowPlacement", placement
);
479 void BScreen::saveResistanceSize(int s
) {
480 resource
.resistance_size
= s
;
481 config
->setValue(screenstr
+ "resistanceSize",
482 resource
.resistance_size
);
486 void BScreen::saveSnapThreshold(int t
) {
487 resource
.snap_threshold
= t
;
488 config
->setValue(screenstr
+ "edgeSnapThreshold",
489 resource
.snap_threshold
);
493 void BScreen::saveSnapOffset(int t
) {
494 resource
.snap_offset
= t
;
495 config
->setValue(screenstr
+ "edgeSnapOffset",
496 resource
.snap_offset
);
500 void BScreen::saveRowPlacementDirection(int d
) {
501 resource
.row_direction
= d
;
502 config
->setValue(screenstr
+ "rowPlacementDirection",
503 resource
.row_direction
== LeftRight
?
504 "LeftToRight" : "RightToLeft");
508 void BScreen::saveColPlacementDirection(int d
) {
509 resource
.col_direction
= d
;
510 config
->setValue(screenstr
+ "colPlacementDirection",
511 resource
.col_direction
== TopBottom
?
512 "TopToBottom" : "BottomToTop");
517 void BScreen::saveStrftimeFormat(const std::string
& format
) {
518 resource
.strftime_format
= format
;
519 config
->setValue(screenstr
+ "strftimeFormat", resource
.strftime_format
);
522 #else // !HAVE_STRFTIME
524 void BScreen::saveDateFormat(int f
) {
525 resource
.date_format
= f
;
526 config
->setValue(screenstr
+ "dateFormat",
527 resource
.date_format
== B_EuropeanDate
?
528 "European" : "American");
532 void BScreen::saveClock24Hour(bool c
) {
533 resource
.clock24hour
= c
;
534 config
->setValue(screenstr
+ "clockFormat", resource
.clock24hour
? 24 : 12);
536 #endif // HAVE_STRFTIME
539 void BScreen::saveWorkspaceNames() {
542 for (unsigned int i
= 0; i
< workspacesList
.size(); ++i
) {
543 names
+= workspacesList
[i
]->getName();
544 if (i
< workspacesList
.size() - 1)
548 config
->setValue(screenstr
+ "workspaceNames", names
);
552 void BScreen::savePlaceIgnoreShaded(bool i
) {
553 resource
.ignore_shaded
= i
;
554 config
->setValue(screenstr
+ "placementIgnoreShaded",
555 resource
.ignore_shaded
);
559 void BScreen::savePlaceIgnoreMaximized(bool i
) {
560 resource
.ignore_maximized
= i
;
561 config
->setValue(screenstr
+ "placementIgnoreMaximized",
562 resource
.ignore_maximized
);
566 void BScreen::saveAllowScrollLock(bool a
) {
567 resource
.allow_scroll_lock
= a
;
568 config
->setValue(screenstr
+ "disableBindingsWithScrollLock",
569 resource
.allow_scroll_lock
);
573 void BScreen::saveWorkspaceWarping(bool w
) {
574 resource
.workspace_warping
= w
;
575 config
->setValue(screenstr
+ "workspaceWarping",
576 resource
.workspace_warping
);
580 void BScreen::saveRootScrollDirection(int d
) {
581 resource
.root_scroll
= d
;
583 switch (resource
.root_scroll
) {
584 case NoScroll
: dir
= "None"; break;
585 case ReverseScroll
: dir
= "Reverse"; break;
586 case NormalScroll
: default: dir
= "Normal"; break;
588 config
->setValue(screenstr
+ "rootScrollDirection", dir
);
592 void BScreen::save_rc(void) {
593 saveSloppyFocus(resource
.sloppy_focus
);
594 saveAutoRaise(resource
.auto_raise
);
595 saveImageDither(doImageDither());
596 saveAAFonts(resource
.aa_fonts
);
597 saveResizeZones(resource
.resize_zones
);
598 saveOpaqueMove(resource
.opaque_move
);
599 saveFullMax(resource
.full_max
);
600 saveFocusNew(resource
.focus_new
);
601 saveFocusLast(resource
.focus_last
);
602 saveHideToolbar(resource
.hide_toolbar
);
603 saveWindowToWindowSnap(resource
.snap_to_windows
);
604 saveWindowToEdgeSnap(resource
.snap_to_edges
);
605 saveWindowCornerSnap(resource
.window_corner_snap
);
606 saveWorkspaces(resource
.workspaces
);
607 savePlacementPolicy(resource
.placement_policy
);
608 saveSnapThreshold(resource
.snap_threshold
);
609 saveSnapOffset(resource
.snap_offset
);
610 saveResistanceSize(resource
.resistance_size
);
611 saveRowPlacementDirection(resource
.row_direction
);
612 saveColPlacementDirection(resource
.col_direction
);
614 saveStrftimeFormat(resource
.strftime_format
);
615 #else // !HAVE_STRFTIME
616 saveDateFormat(resource
.date_format
);
617 savwClock24Hour(resource
.clock24hour
);
618 #endif // HAVE_STRFTIME
619 savePlaceIgnoreShaded(resource
.ignore_shaded
);
620 savePlaceIgnoreMaximized(resource
.ignore_maximized
);
621 saveAllowScrollLock(resource
.allow_scroll_lock
);
622 saveWorkspaceWarping(resource
.workspace_warping
);
623 saveRootScrollDirection(resource
.root_scroll
);
630 void BScreen::load_rc(void) {
634 if (! config
->getValue(screenstr
+ "fullMaximization", resource
.full_max
))
635 resource
.full_max
= false;
637 if (! config
->getValue(screenstr
+ "focusNewWindows", resource
.focus_new
))
638 resource
.focus_new
= false;
640 if (! config
->getValue(screenstr
+ "focusLastWindow", resource
.focus_last
))
641 resource
.focus_last
= false;
643 if (! config
->getValue(screenstr
+ "workspaces", resource
.workspaces
))
644 resource
.workspaces
= 1;
646 if (! config
->getValue(screenstr
+ "opaqueMove", resource
.opaque_move
))
647 resource
.opaque_move
= false;
649 if (! config
->getValue(screenstr
+ "antialiasFonts", resource
.aa_fonts
))
650 resource
.aa_fonts
= true;
652 if (! config
->getValue(screenstr
+ "resizeZones", resource
.resize_zones
) ||
653 (resource
.resize_zones
!= 1 && resource
.resize_zones
!= 2 &&
654 resource
.resize_zones
!= 4))
655 resource
.resize_zones
= 4;
657 if (! config
->getValue(screenstr
+ "hideToolbar", resource
.hide_toolbar
))
658 resource
.hide_toolbar
= false;
660 resource
.snap_to_windows
= WindowResistance
;
661 if (config
->getValue(screenstr
+ "windowToWindowSnap", s
)) {
663 resource
.snap_to_windows
= WindowNoSnap
;
664 else if (s
== "Snap")
665 resource
.snap_to_windows
= WindowSnap
;
668 resource
.snap_to_edges
= WindowResistance
;
669 if (config
->getValue(screenstr
+ "windowToEdgeSnap", s
)) {
671 resource
.snap_to_edges
= WindowNoSnap
;
672 else if (s
== "Snap")
673 resource
.snap_to_edges
= WindowSnap
;
676 if (! config
->getValue(screenstr
+ "windowCornerSnap",
677 resource
.window_corner_snap
))
678 resource
.window_corner_snap
= true;
680 if (! config
->getValue(screenstr
+ "imageDither", b
))
682 image_control
->setDither(b
);
684 if (! config
->getValue(screenstr
+ "edgeSnapOffset",
685 resource
.snap_offset
))
686 resource
.snap_offset
= 0;
687 if (resource
.snap_offset
> 50) // sanity check, setting this huge would
688 resource
.snap_offset
= 50; // seriously suck.
690 if (! config
->getValue(screenstr
+ "edgeSnapThreshold",
691 resource
.snap_threshold
))
692 resource
.snap_threshold
= 4;
694 if (! config
->getValue(screenstr
+ "resistanceSize",
695 resource
.resistance_size
))
696 resource
.resistance_size
= 18;
698 if (config
->getValue(screenstr
+ "rowPlacementDirection", s
) &&
700 resource
.row_direction
= RightLeft
;
702 resource
.row_direction
= LeftRight
;
704 if (config
->getValue(screenstr
+ "colPlacementDirection", s
) &&
706 resource
.col_direction
= BottomTop
;
708 resource
.col_direction
= TopBottom
;
710 if (config
->getValue(screenstr
+ "workspaceNames", s
)) {
711 XAtom::StringVect workspaceNames
;
713 string::const_iterator it
= s
.begin(), end
= s
.end();
715 string::const_iterator tmp
= it
; // current string.begin()
716 it
= std::find(tmp
, end
, ','); // look for comma between tmp and end
717 workspaceNames
.push_back(string(tmp
, it
)); // s[tmp:it]
723 xatom
->setValue(getRootWindow(), XAtom::net_desktop_names
, XAtom::utf8
,
727 resource
.sloppy_focus
= true;
728 resource
.auto_raise
= false;
729 resource
.click_raise
= false;
730 if (config
->getValue(screenstr
+ "focusModel", s
)) {
731 if (s
.find("ClickToFocus") != string::npos
) {
732 resource
.sloppy_focus
= false;
735 if (s
.find("AutoRaise") != string::npos
)
736 resource
.auto_raise
= true;
737 if (s
.find("ClickRaise") != string::npos
)
738 resource
.click_raise
= true;
742 if (config
->getValue(screenstr
+ "windowPlacement", s
)) {
743 if (s
== "CascadePlacement")
744 resource
.placement_policy
= CascadePlacement
;
745 else if (s
== "UnderMousePlacement")
746 resource
.placement_policy
= UnderMousePlacement
;
747 else if (s
== "ClickMousePlacement")
748 resource
.placement_policy
= ClickMousePlacement
;
749 else if (s
== "ColSmartPlacement")
750 resource
.placement_policy
= ColSmartPlacement
;
751 else //if (s == "RowSmartPlacement")
752 resource
.placement_policy
= RowSmartPlacement
;
754 resource
.placement_policy
= RowSmartPlacement
;
757 if (! config
->getValue(screenstr
+ "strftimeFormat",
758 resource
.strftime_format
))
759 resource
.strftime_format
= "%I:%M %p";
760 #else // !HAVE_STRFTIME
763 if (config
->getValue(screenstr
+ "dateFormat", s
) && s
== "European")
764 resource
.date_format
= B_EuropeanDate
;
766 resource
.date_format
= B_AmericanDate
;
768 if (! config
->getValue(screenstr
+ "clockFormat", l
))
770 resource
.clock24hour
= l
== 24;
771 #endif // HAVE_STRFTIME
773 if (! config
->getValue(screenstr
+ "placementIgnoreShaded",
774 resource
.ignore_shaded
))
775 resource
.ignore_shaded
= true;
777 if (! config
->getValue(screenstr
+ "placementIgnoreMaximized",
778 resource
.ignore_maximized
))
779 resource
.ignore_maximized
= true;
781 if (! config
->getValue(screenstr
+ "disableBindingsWithScrollLock",
782 resource
.allow_scroll_lock
))
783 resource
.allow_scroll_lock
= false;
785 if (! config
->getValue(screenstr
+ "workspaceWarping",
786 resource
.workspace_warping
))
787 resource
.workspace_warping
= false;
789 resource
.root_scroll
= NormalScroll
;
790 if (config
->getValue(screenstr
+ "rootScrollDirection", s
)) {
792 resource
.root_scroll
= NoScroll
;
793 else if (s
== "Reverse")
794 resource
.root_scroll
= ReverseScroll
;
799 void BScreen::changeWorkspaceCount(unsigned int new_count
) {
800 assert(new_count
> 0);
802 if (new_count
< workspacesList
.size()) {
804 for (unsigned int i
= workspacesList
.size(); i
> new_count
; --i
)
805 removeLastWorkspace();
806 // removeLast already sets the current workspace to the
807 // last available one.
808 } else if (new_count
> workspacesList
.size()) {
810 for(unsigned int i
= workspacesList
.size(); i
< new_count
; ++i
)
816 void BScreen::reconfigure(void) {
817 // don't reconfigure while saving the initial rc file, it's a waste and it
818 // breaks somethings (workspace names)
819 if (blackbox
->isStartup()) return;
826 // we need to do this explicitly, because just loading this value from the rc
828 changeWorkspaceCount(resource
.workspaces
);
831 gcv
.foreground
= WhitePixel(blackbox
->getXDisplay(),
833 gcv
.function
= GXinvert
;
834 gcv
.subwindow_mode
= IncludeInferiors
;
835 XChangeGC(blackbox
->getXDisplay(), opGC
,
836 GCForeground
| GCFunction
| GCSubwindowMode
, &gcv
);
838 const char *s
= i18n(ScreenSet
, ScreenPositionLength
,
839 "0: 0000 x 0: 0000");
841 geom_w
= resource
.wstyle
.font
->measureString(s
) + resource
.bevel_width
* 2;
842 geom_h
= resource
.wstyle
.font
->height() + resource
.bevel_width
* 2;
844 BTexture
* texture
= &(resource
.wstyle
.l_focus
);
845 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
846 if (geom_pixmap
== ParentRelative
) {
847 texture
= &(resource
.wstyle
.t_focus
);
848 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
851 XSetWindowBackground(blackbox
->getXDisplay(), geom_window
,
852 texture
->color().pixel());
854 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
855 geom_window
, geom_pixmap
);
857 XSetWindowBorderWidth(blackbox
->getXDisplay(), geom_window
,
858 resource
.border_width
);
859 XSetWindowBorder(blackbox
->getXDisplay(), geom_window
,
860 resource
.border_color
.pixel());
862 workspacemenu
->reconfigure();
863 iconmenu
->reconfigure();
865 typedef std::vector
<int> SubList
;
866 SubList remember_subs
;
868 // save the current open menus
869 Basemenu
*menu
= rootmenu
;
871 while ((submenu
= menu
->getCurrentSubmenu()) >= 0) {
872 remember_subs
.push_back(submenu
);
873 menu
= menu
->find(submenu
)->submenu();
879 rootmenu
->reconfigure();
881 // reopen the saved menus
883 const SubList::iterator subs_end
= remember_subs
.end();
884 for (SubList::iterator it
= remember_subs
.begin(); it
!= subs_end
; ++it
) {
885 menu
->drawSubmenu(*it
);
886 menu
= menu
->find(*it
)->submenu();
891 configmenu
->reconfigure();
893 toolbar
->reconfigure();
897 std::for_each(workspacesList
.begin(), workspacesList
.end(),
898 std::mem_fun(&Workspace::reconfigure
));
900 BlackboxWindowList::iterator iit
= iconList
.begin();
901 for (; iit
!= iconList
.end(); ++iit
) {
902 BlackboxWindow
*bw
= *iit
;
903 if (bw
->validateClient())
907 image_control
->timeout();
911 void BScreen::rereadMenu(void) {
915 rootmenu
->reconfigure();
919 void BScreen::LoadStyle(void) {
920 Configuration
style(False
);
922 const char *sfile
= blackbox
->getStyleFilename();
924 style
.setFile(sfile
);
925 if (! style
.load()) {
926 style
.setFile(DEFAULTSTYLE
);
928 style
.create(); // hardcoded default values will be used.
932 // merge in the rc file
933 style
.merge(config
->file(), True
);
937 // load fonts/fontsets
938 if (resource
.wstyle
.font
)
939 delete resource
.wstyle
.font
;
940 if (resource
.tstyle
.font
)
941 delete resource
.tstyle
.font
;
942 if (resource
.mstyle
.f_font
)
943 delete resource
.mstyle
.f_font
;
944 if (resource
.mstyle
.t_font
)
945 delete resource
.mstyle
.t_font
;
946 resource
.wstyle
.font
= resource
.tstyle
.font
= resource
.mstyle
.f_font
=
947 resource
.mstyle
.t_font
= (BFont
*) 0;
949 resource
.wstyle
.font
= readDatabaseFont("window.", style
);
950 resource
.tstyle
.font
= readDatabaseFont("toolbar.", style
);
951 resource
.mstyle
.t_font
= readDatabaseFont("menu.title.", style
);
952 resource
.mstyle
.f_font
= readDatabaseFont("menu.frame.", style
);
954 // load window config
955 resource
.wstyle
.t_focus
=
956 readDatabaseTexture("window.title.focus", "white", style
);
957 resource
.wstyle
.t_unfocus
=
958 readDatabaseTexture("window.title.unfocus", "black", style
);
959 resource
.wstyle
.l_focus
=
960 readDatabaseTexture("window.label.focus", "white", style
);
961 resource
.wstyle
.l_unfocus
=
962 readDatabaseTexture("window.label.unfocus", "black", style
);
963 resource
.wstyle
.h_focus
=
964 readDatabaseTexture("window.handle.focus", "white", style
);
965 resource
.wstyle
.h_unfocus
=
966 readDatabaseTexture("window.handle.unfocus", "black", style
);
967 resource
.wstyle
.g_focus
=
968 readDatabaseTexture("window.grip.focus", "white", style
);
969 resource
.wstyle
.g_unfocus
=
970 readDatabaseTexture("window.grip.unfocus", "black", style
);
971 resource
.wstyle
.b_focus
=
972 readDatabaseTexture("window.button.focus", "white", style
);
973 resource
.wstyle
.b_unfocus
=
974 readDatabaseTexture("window.button.unfocus", "black", style
);
975 resource
.wstyle
.b_pressed
=
976 readDatabaseTexture("window.button.pressed", "black", style
);
978 // we create the window.frame texture by hand because it exists only to
979 // make the code cleaner and is not actually used for display
980 BColor color
= readDatabaseColor("window.frame.focusColor", "white", style
);
981 resource
.wstyle
.f_focus
= BTexture("solid flat", getBaseDisplay(),
982 getScreenNumber(), image_control
);
983 resource
.wstyle
.f_focus
.setColor(color
);
985 color
= readDatabaseColor("window.frame.unfocusColor", "white", style
);
986 resource
.wstyle
.f_unfocus
= BTexture("solid flat", getBaseDisplay(),
987 getScreenNumber(), image_control
);
988 resource
.wstyle
.f_unfocus
.setColor(color
);
990 resource
.wstyle
.l_text_focus
=
991 readDatabaseColor("window.label.focus.textColor", "black", style
);
992 resource
.wstyle
.l_text_unfocus
=
993 readDatabaseColor("window.label.unfocus.textColor", "white", style
);
994 resource
.wstyle
.b_pic_focus
=
995 readDatabaseColor("window.button.focus.picColor", "black", style
);
996 resource
.wstyle
.b_pic_unfocus
=
997 readDatabaseColor("window.button.unfocus.picColor", "white", style
);
999 resource
.wstyle
.justify
= LeftJustify
;
1000 if (style
.getValue("window.justify", s
)) {
1001 if (s
== "right" || s
== "Right")
1002 resource
.wstyle
.justify
= RightJustify
;
1003 else if (s
== "center" || s
== "Center")
1004 resource
.wstyle
.justify
= CenterJustify
;
1008 if (resource
.wstyle
.t_focus
.texture() == BTexture::Parent_Relative
)
1009 resource
.wstyle
.t_focus
= resource
.wstyle
.f_focus
;
1010 if (resource
.wstyle
.t_unfocus
.texture() == BTexture::Parent_Relative
)
1011 resource
.wstyle
.t_unfocus
= resource
.wstyle
.f_unfocus
;
1012 if (resource
.wstyle
.h_focus
.texture() == BTexture::Parent_Relative
)
1013 resource
.wstyle
.h_focus
= resource
.wstyle
.f_focus
;
1014 if (resource
.wstyle
.h_unfocus
.texture() == BTexture::Parent_Relative
)
1015 resource
.wstyle
.h_unfocus
= resource
.wstyle
.f_unfocus
;
1017 // load toolbar config
1018 resource
.tstyle
.toolbar
=
1019 readDatabaseTexture("toolbar", "black", style
);
1020 resource
.tstyle
.label
=
1021 readDatabaseTexture("toolbar.label", "black", style
);
1022 resource
.tstyle
.window
=
1023 readDatabaseTexture("toolbar.windowLabel", "black", style
);
1024 resource
.tstyle
.button
=
1025 readDatabaseTexture("toolbar.button", "white", style
);
1026 resource
.tstyle
.pressed
=
1027 readDatabaseTexture("toolbar.button.pressed", "black", style
);
1028 resource
.tstyle
.clock
=
1029 readDatabaseTexture("toolbar.clock", "black", style
);
1030 resource
.tstyle
.l_text
=
1031 readDatabaseColor("toolbar.label.textColor", "white", style
);
1032 resource
.tstyle
.w_text
=
1033 readDatabaseColor("toolbar.windowLabel.textColor", "white", style
);
1034 resource
.tstyle
.c_text
=
1035 readDatabaseColor("toolbar.clock.textColor", "white", style
);
1036 resource
.tstyle
.b_pic
=
1037 readDatabaseColor("toolbar.button.picColor", "black", style
);
1039 resource
.tstyle
.justify
= LeftJustify
;
1040 if (style
.getValue("toolbar.justify", s
)) {
1041 if (s
== "right" || s
== "Right")
1042 resource
.tstyle
.justify
= RightJustify
;
1043 else if (s
== "center" || s
== "Center")
1044 resource
.tstyle
.justify
= CenterJustify
;
1048 if (resource
.tstyle
.toolbar
.texture() == BTexture::Parent_Relative
) {
1049 resource
.tstyle
.toolbar
= BTexture("solid flat", getBaseDisplay(),
1050 getScreenNumber(), image_control
);
1051 resource
.tstyle
.toolbar
.setColor(BColor("black", getBaseDisplay(),
1052 getScreenNumber()));
1056 resource
.mstyle
.title
=
1057 readDatabaseTexture("menu.title", "white", style
);
1058 resource
.mstyle
.frame
=
1059 readDatabaseTexture("menu.frame", "black", style
);
1060 resource
.mstyle
.hilite
=
1061 readDatabaseTexture("menu.hilite", "white", style
);
1062 resource
.mstyle
.t_text
=
1063 readDatabaseColor("menu.title.textColor", "black", style
);
1064 resource
.mstyle
.f_text
=
1065 readDatabaseColor("menu.frame.textColor", "white", style
);
1066 resource
.mstyle
.d_text
=
1067 readDatabaseColor("menu.frame.disableColor", "black", style
);
1068 resource
.mstyle
.h_text
=
1069 readDatabaseColor("menu.hilite.textColor", "black", style
);
1071 resource
.mstyle
.t_justify
= LeftJustify
;
1072 if (style
.getValue("menu.title.justify", s
)) {
1073 if (s
== "right" || s
== "Right")
1074 resource
.mstyle
.t_justify
= RightJustify
;
1075 else if (s
== "center" || s
== "Center")
1076 resource
.mstyle
.t_justify
= CenterJustify
;
1079 resource
.mstyle
.f_justify
= LeftJustify
;
1080 if (style
.getValue("menu.frame.justify", s
)) {
1081 if (s
== "right" || s
== "Right")
1082 resource
.mstyle
.f_justify
= RightJustify
;
1083 else if (s
== "center" || s
== "Center")
1084 resource
.mstyle
.f_justify
= CenterJustify
;
1087 resource
.mstyle
.bullet
= Basemenu::Triangle
;
1088 if (style
.getValue("menu.bullet", s
)) {
1089 if (s
== "empty" || s
== "Empty")
1090 resource
.mstyle
.bullet
= Basemenu::Empty
;
1091 else if (s
== "square" || s
== "Square")
1092 resource
.mstyle
.bullet
= Basemenu::Square
;
1093 else if (s
== "diamond" || s
== "Diamond")
1094 resource
.mstyle
.bullet
= Basemenu::Diamond
;
1097 resource
.mstyle
.bullet_pos
= Basemenu::Left
;
1098 if (style
.getValue("menu.bullet.position", s
)) {
1099 if (s
== "right" || s
== "Right")
1100 resource
.mstyle
.bullet_pos
= Basemenu::Right
;
1104 if (resource
.mstyle
.frame
.texture() == BTexture::Parent_Relative
) {
1105 resource
.mstyle
.frame
= BTexture("solid flat", getBaseDisplay(),
1106 getScreenNumber(), image_control
);
1107 resource
.mstyle
.frame
.setColor(BColor("black", getBaseDisplay(),
1108 getScreenNumber()));
1111 resource
.border_color
=
1112 readDatabaseColor("borderColor", "black", style
);
1114 // load bevel, border and handle widths
1115 if (! style
.getValue("handleWidth", resource
.handle_width
) ||
1116 resource
.handle_width
> (getWidth() / 2) || resource
.handle_width
== 0)
1117 resource
.handle_width
= 6;
1119 if (! style
.getValue("borderWidth", resource
.border_width
))
1120 resource
.border_width
= 1;
1122 if (! style
.getValue("bevelWidth", resource
.bevel_width
) ||
1123 resource
.bevel_width
> (getWidth() / 2) || resource
.bevel_width
== 0)
1124 resource
.bevel_width
= 3;
1126 if (! style
.getValue("frameWidth", resource
.frame_width
) ||
1127 resource
.frame_width
> (getWidth() / 2))
1128 resource
.frame_width
= resource
.bevel_width
;
1130 if (style
.getValue("rootCommand", s
))
1131 bexec(s
, displayString());
1135 void BScreen::addIcon(BlackboxWindow
*w
) {
1138 w
->setWorkspace(BSENTINEL
);
1139 w
->setWindowNumber(iconList
.size());
1141 iconList
.push_back(w
);
1143 const char* title
= w
->getIconTitle();
1144 iconmenu
->insert(title
);
1149 void BScreen::removeIcon(BlackboxWindow
*w
) {
1154 iconmenu
->remove(w
->getWindowNumber());
1157 BlackboxWindowList::iterator it
= iconList
.begin(),
1158 end
= iconList
.end();
1159 for (int i
= 0; it
!= end
; ++it
)
1160 (*it
)->setWindowNumber(i
++);
1164 BlackboxWindow
*BScreen::getIcon(unsigned int index
) {
1165 if (index
< iconList
.size()) {
1166 BlackboxWindowList::iterator it
= iconList
.begin();
1167 while (index
-- > 0) // increment to index
1172 return (BlackboxWindow
*) 0;
1176 unsigned int BScreen::addWorkspace(void) {
1177 Workspace
*wkspc
= new Workspace(this, workspacesList
.size());
1178 workspacesList
.push_back(wkspc
);
1179 saveWorkspaces(getWorkspaceCount());
1180 saveWorkspaceNames();
1182 workspacemenu
->insertWorkspace(wkspc
);
1183 workspacemenu
->update();
1185 toolbar
->reconfigure();
1187 updateNetizenWorkspaceCount();
1189 return workspacesList
.size();
1193 unsigned int BScreen::removeLastWorkspace(void) {
1194 if (workspacesList
.size() == 1)
1197 Workspace
*wkspc
= workspacesList
.back();
1199 if (current_workspace
->getID() == wkspc
->getID())
1200 changeWorkspaceID(current_workspace
->getID() - 1);
1204 workspacemenu
->removeWorkspace(wkspc
);
1205 workspacemenu
->update();
1207 workspacesList
.pop_back();
1210 saveWorkspaces(getWorkspaceCount());
1211 saveWorkspaceNames();
1213 toolbar
->reconfigure();
1215 updateNetizenWorkspaceCount();
1217 return workspacesList
.size();
1221 void BScreen::changeWorkspaceID(unsigned int id
) {
1222 if (! current_workspace
|| id
== current_workspace
->getID()) return;
1224 BlackboxWindow
*focused
= blackbox
->getFocusedWindow();
1225 if (focused
&& focused
->getScreen() == this) {
1226 assert(focused
->isStuck() ||
1227 focused
->getWorkspaceNumber() == current_workspace
->getID());
1229 current_workspace
->setLastFocusedWindow(focused
);
1231 // if no window had focus, no need to store a last focus
1232 current_workspace
->setLastFocusedWindow((BlackboxWindow
*) 0);
1235 // when we switch workspaces, unfocus whatever was focused if it is going
1237 if (focused
&& ! focused
->isStuck())
1238 blackbox
->setFocusedWindow((BlackboxWindow
*) 0);
1240 current_workspace
->hideAll();
1241 workspacemenu
->setItemSelected(current_workspace
->getID() + 2, False
);
1243 current_workspace
= getWorkspace(id
);
1245 xatom
->setValue(getRootWindow(), XAtom::net_current_desktop
,
1246 XAtom::cardinal
, id
);
1248 workspacemenu
->setItemSelected(current_workspace
->getID() + 2, True
);
1249 toolbar
->redrawWorkspaceLabel(True
);
1251 current_workspace
->showAll();
1256 BlackboxWindow
*win
= (BlackboxWindow
*) 0;
1259 XSync(blackbox
->getXDisplay(), False
);
1261 // If sloppy focus and we can find the client window under the pointer,
1263 if (resource
.sloppy_focus
&&
1264 XQueryPointer(blackbox
->getXDisplay(), getRootWindow(), &r
, &c
,
1265 &rx
, &ry
, &x
, &y
, &m
) &&
1267 if ( (win
= blackbox
->searchWindow(c
)) ) {
1268 f
= win
->setInputFocus();
1269 blackbox
->setFocusedWindow(win
);
1273 // If that fails, and we're doing focus_last, try to focus the last window.
1274 if (! f
&& resource
.focus_last
&&
1275 (win
= current_workspace
->getLastFocusedWindow())) {
1276 f
= win
->setInputFocus();
1277 blackbox
->setFocusedWindow(win
);
1280 // If that fails, then set focus to nothing.
1281 if (! f
) blackbox
->setFocusedWindow((BlackboxWindow
*) 0);
1283 updateNetizenCurrentWorkspace();
1288 * Set the _NET_CLIENT_LIST root window property.
1290 void BScreen::updateClientList(void) {
1291 if (windowList
.size() > 0) {
1292 Window
*windows
= new Window
[windowList
.size()];
1293 Window
*win_it
= windows
;
1294 BlackboxWindowList::iterator it
= windowList
.begin();
1295 const BlackboxWindowList::iterator end
= windowList
.end();
1296 for (; it
!= end
; ++it
, ++win_it
)
1297 *win_it
= (*it
)->getClientWindow();
1298 xatom
->setValue(getRootWindow(), XAtom::net_client_list
, XAtom::window
,
1299 windows
, windowList
.size());
1302 xatom
->setValue(getRootWindow(), XAtom::net_client_list
, XAtom::window
,
1305 updateStackingList();
1310 * Set the _NET_CLIENT_LIST_STACKING root window property.
1312 void BScreen::updateStackingList(void) {
1314 BlackboxWindowList stack_order
;
1317 * Get the stacking order from all of the workspaces.
1318 * We start with the current workspace so that the sticky windows will be
1319 * in the right order on the current workspace.
1320 * XXX: Do we need to have sticky windows in the list once for each workspace?
1322 getCurrentWorkspace()->appendStackOrder(stack_order
);
1323 for (unsigned int i
= 0; i
< getWorkspaceCount(); ++i
)
1324 if (i
!= getCurrentWorkspaceID())
1325 getWorkspace(i
)->appendStackOrder(stack_order
);
1327 if (stack_order
.size() > 0) {
1328 // set the client list atoms
1329 Window
*windows
= new Window
[stack_order
.size()];
1330 Window
*win_it
= windows
;
1331 BlackboxWindowList::iterator it
= stack_order
.begin(),
1332 end
= stack_order
.end();
1333 for (; it
!= end
; ++it
, ++win_it
)
1334 *win_it
= (*it
)->getClientWindow();
1335 xatom
->setValue(getRootWindow(), XAtom::net_client_list_stacking
,
1336 XAtom::window
, windows
, stack_order
.size());
1339 xatom
->setValue(getRootWindow(), XAtom::net_client_list_stacking
,
1340 XAtom::window
, 0, 0);
1344 void BScreen::addSystrayWindow(Window window
) {
1345 XGrabServer(blackbox
->getXDisplay());
1347 XSelectInput(blackbox
->getXDisplay(), window
, SubstructureRedirectMask
);
1348 systrayWindowList
.push_back(window
);
1349 xatom
->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows
,
1351 &systrayWindowList
[0], systrayWindowList
.size());
1352 blackbox
->saveSystrayWindowSearch(window
, this);
1354 XUngrabServer(blackbox
->getXDisplay());
1358 void BScreen::removeSystrayWindow(Window window
) {
1359 XGrabServer(blackbox
->getXDisplay());
1361 WindowList::iterator it
= systrayWindowList
.begin();
1362 const WindowList::iterator end
= systrayWindowList
.end();
1363 for (; it
!= end
; ++it
)
1364 if (*it
== window
) {
1365 systrayWindowList
.erase(it
);
1366 xatom
->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows
,
1368 &systrayWindowList
[0], systrayWindowList
.size());
1369 blackbox
->removeSystrayWindowSearch(window
);
1370 XSelectInput(blackbox
->getXDisplay(), window
, NoEventMask
);
1374 assert(it
!= end
); // not a systray window
1376 XUngrabServer(blackbox
->getXDisplay());
1380 void BScreen::manageWindow(Window w
) {
1381 // is the window a KDE systray window?
1383 if (xatom
->getValue(w
, XAtom::kde_net_wm_system_tray_window_for
,
1384 XAtom::window
, systray
) && systray
!= None
) {
1385 addSystrayWindow(w
);
1389 // is the window a docking app
1390 XWMHints
*wmhint
= XGetWMHints(blackbox
->getXDisplay(), w
);
1391 if (wmhint
&& (wmhint
->flags
& StateHint
) &&
1392 wmhint
->initial_state
== WithdrawnState
) {
1397 new BlackboxWindow(blackbox
, w
, this);
1399 BlackboxWindow
*win
= blackbox
->searchWindow(w
);
1403 if (win
->isDesktop()) {
1404 desktopWindowList
.push_back(win
->getFrameWindow());
1405 } else { // if (win->isNormal()) {
1406 // don't list desktop windows as managed windows
1407 windowList
.push_back(win
);
1410 if (win
->isTopmost())
1411 specialWindowList
.push_back(win
->getFrameWindow());
1414 XMapRequestEvent mre
;
1416 if (blackbox
->isStartup() && win
->isNormal()) win
->restoreAttributes();
1417 win
->mapRequestEvent(&mre
);
1421 void BScreen::unmanageWindow(BlackboxWindow
*w
, bool remap
) {
1422 // is the window a KDE systray window?
1424 if (xatom
->getValue(w
->getClientWindow(),
1425 XAtom::kde_net_wm_system_tray_window_for
,
1426 XAtom::window
, systray
) && systray
!= None
) {
1427 removeSystrayWindow(w
->getClientWindow());
1433 // Remove the modality so that its parent won't try to re-focus the window
1434 if (w
->isModal()) w
->setModal(False
);
1436 if (w
->getWorkspaceNumber() != BSENTINEL
&&
1437 w
->getWindowNumber() != BSENTINEL
) {
1438 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
1440 for (unsigned int i
= 0; i
< getNumberOfWorkspaces(); ++i
)
1441 if (i
!= w
->getWorkspaceNumber())
1442 getWorkspace(i
)->removeWindow(w
, True
);
1444 } else if (w
->isIconic())
1447 if (w
->isDesktop()) {
1448 WindowList::iterator it
= desktopWindowList
.begin();
1449 const WindowList::iterator end
= desktopWindowList
.end();
1450 for (; it
!= end
; ++it
)
1451 if (*it
== w
->getFrameWindow()) {
1452 desktopWindowList
.erase(it
);
1455 assert(it
!= end
); // the window wasnt a desktop window?
1456 } else { // if (w->isNormal()) {
1457 // we don't list desktop windows as managed windows
1458 windowList
.remove(w
);
1461 if (w
->isTopmost()) {
1462 WindowList::iterator it
= specialWindowList
.begin();
1463 const WindowList::iterator end
= specialWindowList
.end();
1464 for (; it
!= end
; ++it
)
1465 if (*it
== w
->getFrameWindow()) {
1466 specialWindowList
.erase(it
);
1469 assert(it
!= end
); // the window wasnt a special window?
1473 if (blackbox
->getFocusedWindow() == w
)
1474 blackbox
->setFocusedWindow((BlackboxWindow
*) 0);
1476 removeNetizen(w
->getClientWindow());
1479 some managed windows can also be window group controllers. when
1480 unmanaging such windows, we should also delete the window group.
1482 BWindowGroup
*group
= blackbox
->searchGroup(w
->getClientWindow());
1489 void BScreen::addNetizen(Netizen
*n
) {
1490 netizenList
.push_back(n
);
1492 n
->sendWorkspaceCount();
1493 n
->sendCurrentWorkspace();
1495 WorkspaceList::iterator it
= workspacesList
.begin();
1496 const WorkspaceList::iterator end
= workspacesList
.end();
1497 for (; it
!= end
; ++it
)
1498 (*it
)->sendWindowList(*n
);
1500 Window f
= ((blackbox
->getFocusedWindow()) ?
1501 blackbox
->getFocusedWindow()->getClientWindow() : None
);
1502 n
->sendWindowFocus(f
);
1506 void BScreen::removeNetizen(Window w
) {
1507 NetizenList::iterator it
= netizenList
.begin();
1508 for (; it
!= netizenList
.end(); ++it
) {
1509 if ((*it
)->getWindowID() == w
) {
1511 netizenList
.erase(it
);
1518 void BScreen::updateWorkArea(void) {
1519 if (workspacesList
.size() > 0) {
1520 unsigned long *dims
= new unsigned long[4 * workspacesList
.size()];
1521 for (unsigned int i
= 0, m
= workspacesList
.size(); i
< m
; ++i
) {
1522 // XXX: this could be different for each workspace
1523 const Rect
&area
= availableArea();
1524 dims
[(i
* 4) + 0] = area
.x();
1525 dims
[(i
* 4) + 1] = area
.y();
1526 dims
[(i
* 4) + 2] = area
.width();
1527 dims
[(i
* 4) + 3] = area
.height();
1529 xatom
->setValue(getRootWindow(), XAtom::net_workarea
, XAtom::cardinal
,
1530 dims
, 4 * workspacesList
.size());
1533 xatom
->setValue(getRootWindow(), XAtom::net_workarea
, XAtom::cardinal
,
1538 void BScreen::updateNetizenCurrentWorkspace(void) {
1539 std::for_each(netizenList
.begin(), netizenList
.end(),
1540 std::mem_fun(&Netizen::sendCurrentWorkspace
));
1544 void BScreen::updateNetizenWorkspaceCount(void) {
1545 xatom
->setValue(getRootWindow(), XAtom::net_number_of_desktops
,
1546 XAtom::cardinal
, workspacesList
.size());
1550 std::for_each(netizenList
.begin(), netizenList
.end(),
1551 std::mem_fun(&Netizen::sendWorkspaceCount
));
1555 void BScreen::updateNetizenWindowFocus(void) {
1556 Window f
= ((blackbox
->getFocusedWindow()) ?
1557 blackbox
->getFocusedWindow()->getClientWindow() : None
);
1559 xatom
->setValue(getRootWindow(), XAtom::net_active_window
,
1562 NetizenList::iterator it
= netizenList
.begin();
1563 for (; it
!= netizenList
.end(); ++it
)
1564 (*it
)->sendWindowFocus(f
);
1568 void BScreen::updateNetizenWindowAdd(Window w
, unsigned long p
) {
1569 NetizenList::iterator it
= netizenList
.begin();
1570 for (; it
!= netizenList
.end(); ++it
) {
1571 (*it
)->sendWindowAdd(w
, p
);
1576 void BScreen::updateNetizenWindowDel(Window w
) {
1577 NetizenList::iterator it
= netizenList
.begin();
1578 for (; it
!= netizenList
.end(); ++it
)
1579 (*it
)->sendWindowDel(w
);
1583 void BScreen::updateNetizenWindowRaise(Window w
) {
1584 NetizenList::iterator it
= netizenList
.begin();
1585 for (; it
!= netizenList
.end(); ++it
)
1586 (*it
)->sendWindowRaise(w
);
1590 void BScreen::updateNetizenWindowLower(Window w
) {
1591 NetizenList::iterator it
= netizenList
.begin();
1592 for (; it
!= netizenList
.end(); ++it
)
1593 (*it
)->sendWindowLower(w
);
1597 void BScreen::updateNetizenConfigNotify(XEvent
*e
) {
1598 NetizenList::iterator it
= netizenList
.begin();
1599 for (; it
!= netizenList
.end(); ++it
)
1600 (*it
)->sendConfigNotify(e
);
1604 void BScreen::raiseWindows(Window
*workspace_stack
, unsigned int num
) {
1605 // the 13 represents the number of blackbox windows such as menus
1611 Window
*session_stack
= new
1612 Window
[(num
+ workspacesList
.size() + rootmenuList
.size() +
1613 specialWindowList
.size() + bbwins
)];
1614 unsigned int i
= 0, k
= num
;
1616 XRaiseWindow(blackbox
->getXDisplay(), iconmenu
->getWindowID());
1617 *(session_stack
+ i
++) = iconmenu
->getWindowID();
1619 WorkspaceList::iterator wit
= workspacesList
.begin();
1620 const WorkspaceList::iterator w_end
= workspacesList
.end();
1621 for (; wit
!= w_end
; ++wit
)
1622 *(session_stack
+ i
++) = (*wit
)->getMenu()->getWindowID();
1624 *(session_stack
+ i
++) = workspacemenu
->getWindowID();
1626 *(session_stack
+ i
++) = configmenu
->getFocusmenu()->getWindowID();
1627 *(session_stack
+ i
++) = configmenu
->getPlacementmenu()->getWindowID();
1628 *(session_stack
+ i
++) = configmenu
->getWindowSnapmenu()->getWindowID();
1629 *(session_stack
+ i
++) = configmenu
->getEdgeSnapmenu()->getWindowID();
1631 *(session_stack
+ i
++) = configmenu
->getXineramamenu()->getWindowID();
1633 *(session_stack
+ i
++) = configmenu
->getWindowID();
1635 *(session_stack
+ i
++) = slit
->getMenu()->getDirectionmenu()->getWindowID();
1636 *(session_stack
+ i
++) = slit
->getMenu()->getPlacementmenu()->getWindowID();
1637 *(session_stack
+ i
++) = slit
->getMenu()->getWindowID();
1639 *(session_stack
+ i
++) =
1640 toolbar
->getMenu()->getPlacementmenu()->getWindowID();
1641 *(session_stack
+ i
++) = toolbar
->getMenu()->getWindowID();
1643 RootmenuList::iterator rit
= rootmenuList
.begin();
1644 for (; rit
!= rootmenuList
.end(); ++rit
)
1645 *(session_stack
+ i
++) = (*rit
)->getWindowID();
1646 *(session_stack
+ i
++) = rootmenu
->getWindowID();
1648 if (toolbar
->isOnTop())
1649 *(session_stack
+ i
++) = toolbar
->getWindowID();
1651 if (slit
->isOnTop())
1652 *(session_stack
+ i
++) = slit
->getWindowID();
1654 WindowList::iterator sit
, send
= specialWindowList
.end();
1655 for (sit
= specialWindowList
.begin(); sit
!= send
; ++sit
)
1656 *(session_stack
+ i
++) = *sit
;
1659 *(session_stack
+ i
++) = *(workspace_stack
+ k
);
1661 XRestackWindows(blackbox
->getXDisplay(), session_stack
, i
);
1663 delete [] session_stack
;
1665 updateStackingList();
1669 void BScreen::lowerWindows(Window
*workspace_stack
, unsigned int num
) {
1670 assert(num
> 0); // this would cause trouble in the XRaiseWindow call
1672 Window
*session_stack
= new Window
[(num
+ desktopWindowList
.size())];
1673 unsigned int i
= 0, k
= num
;
1675 XLowerWindow(blackbox
->getXDisplay(), workspace_stack
[0]);
1678 *(session_stack
+ i
++) = *(workspace_stack
+ k
);
1680 WindowList::iterator dit
= desktopWindowList
.begin();
1681 const WindowList::iterator d_end
= desktopWindowList
.end();
1682 for (; dit
!= d_end
; ++dit
)
1683 *(session_stack
+ i
++) = *dit
;
1685 XRestackWindows(blackbox
->getXDisplay(), session_stack
, i
);
1687 delete [] session_stack
;
1689 updateStackingList();
1693 void BScreen::reassociateWindow(BlackboxWindow
*w
, unsigned int wkspc_id
,
1694 bool ignore_sticky
) {
1697 if (wkspc_id
== BSENTINEL
)
1698 wkspc_id
= current_workspace
->getID();
1700 if (w
->getWorkspaceNumber() == wkspc_id
)
1703 if (w
->isIconic()) {
1705 getWorkspace(wkspc_id
)->addWindow(w
);
1707 for (unsigned int i
= 0; i
< getNumberOfWorkspaces(); ++i
)
1708 if (i
!= w
->getWorkspaceNumber())
1709 getWorkspace(i
)->addWindow(w
, True
);
1710 } else if (ignore_sticky
|| ! w
->isStuck()) {
1713 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
1714 getWorkspace(wkspc_id
)->addWindow(w
);
1716 updateStackingList();
1720 void BScreen::propagateWindowName(const BlackboxWindow
*bw
) {
1721 if (bw
->isIconic()) {
1722 iconmenu
->changeItemLabel(bw
->getWindowNumber(), bw
->getIconTitle());
1726 Clientmenu
*clientmenu
= getWorkspace(bw
->getWorkspaceNumber())->getMenu();
1727 clientmenu
->changeItemLabel(bw
->getWindowNumber(), bw
->getTitle());
1728 clientmenu
->update();
1730 if (blackbox
->getFocusedWindow() == bw
)
1731 toolbar
->redrawWindowLabel(True
);
1736 void BScreen::nextFocus(void) {
1737 BlackboxWindow
*focused
= blackbox
->getFocusedWindow(),
1741 // if window is not on this screen, ignore it
1742 if (focused
->getScreen()->getScreenNumber() != getScreenNumber())
1743 focused
= (BlackboxWindow
*) 0;
1746 if (focused
&& current_workspace
->getCount() > 1) {
1747 // next is the next window to recieve focus, current is a place holder
1748 BlackboxWindow
*current
;
1751 next
= current_workspace
->getNextWindowInList(current
);
1752 } while(! next
->setInputFocus() && next
!= focused
);
1754 if (next
!= focused
)
1755 current_workspace
->raiseWindow(next
);
1756 } else if (current_workspace
->getCount() >= 1) {
1757 next
= current_workspace
->getTopWindowOnStack();
1759 current_workspace
->raiseWindow(next
);
1760 next
->setInputFocus();
1765 void BScreen::prevFocus(void) {
1766 BlackboxWindow
*focused
= blackbox
->getFocusedWindow(),
1770 // if window is not on this screen, ignore it
1771 if (focused
->getScreen()->getScreenNumber() != getScreenNumber())
1772 focused
= (BlackboxWindow
*) 0;
1775 if (focused
&& current_workspace
->getCount() > 1) {
1776 // next is the next window to recieve focus, current is a place holder
1777 BlackboxWindow
*current
;
1780 next
= current_workspace
->getPrevWindowInList(current
);
1781 } while(! next
->setInputFocus() && next
!= focused
);
1783 if (next
!= focused
)
1784 current_workspace
->raiseWindow(next
);
1785 } else if (current_workspace
->getCount() >= 1) {
1786 next
= current_workspace
->getTopWindowOnStack();
1788 current_workspace
->raiseWindow(next
);
1789 next
->setInputFocus();
1794 void BScreen::raiseFocus(void) {
1795 BlackboxWindow
*focused
= blackbox
->getFocusedWindow();
1799 // if on this Screen, raise it
1800 if (focused
->getScreen()->getScreenNumber() == getScreenNumber()) {
1801 Workspace
*workspace
= getWorkspace(focused
->getWorkspaceNumber());
1802 workspace
->raiseWindow(focused
);
1807 void BScreen::InitMenu(void) {
1809 rootmenuList
.clear();
1811 while (rootmenu
->getCount())
1812 rootmenu
->remove(0);
1814 rootmenu
= new Rootmenu(this);
1816 bool defaultMenu
= True
;
1818 FILE *menu_file
= (FILE *) 0;
1819 const char *menu_filename
= blackbox
->getMenuFilename();
1822 if (! (menu_file
= fopen(menu_filename
, "r")))
1823 perror(menu_filename
);
1824 if (! menu_file
) { // opening the menu file failed, try the default menu
1825 menu_filename
= DEFAULTMENU
;
1826 if (! (menu_file
= fopen(menu_filename
, "r")))
1827 perror(menu_filename
);
1831 if (feof(menu_file
)) {
1832 fprintf(stderr
, i18n(ScreenSet
, ScreenEmptyMenuFile
,
1833 "%s: Empty menu file"),
1836 char line
[1024], label
[1024];
1837 memset(line
, 0, 1024);
1838 memset(label
, 0, 1024);
1840 while (fgets(line
, 1024, menu_file
) && ! feof(menu_file
)) {
1844 int i
, key
= 0, index
= -1, len
= strlen(line
);
1846 for (i
= 0; i
< len
; i
++) {
1847 if (line
[i
] == '[') index
= 0;
1848 else if (line
[i
] == ']') break;
1849 else if (line
[i
] != ' ')
1851 key
+= tolower(line
[i
]);
1854 if (key
== 517) { // [begin]
1856 for (i
= index
; i
< len
; i
++) {
1857 if (line
[i
] == '(') index
= 0;
1858 else if (line
[i
] == ')') break;
1859 else if (index
++ >= 0) {
1860 if (line
[i
] == '\\' && i
< len
- 1) i
++;
1861 label
[index
- 1] = line
[i
];
1865 if (index
== -1) index
= 0;
1866 label
[index
] = '\0';
1868 rootmenu
->setLabel(label
);
1869 defaultMenu
= parseMenuFile(menu_file
, rootmenu
);
1871 blackbox
->addMenuTimestamp(menu_filename
);
1880 rootmenu
->setInternalMenu();
1881 rootmenu
->insert(i18n(ScreenSet
, Screenxterm
, "xterm"),
1883 i18n(ScreenSet
, Screenxterm
, "xterm"));
1884 rootmenu
->insert(i18n(ScreenSet
, ScreenRestart
, "Restart"),
1886 rootmenu
->insert(i18n(ScreenSet
, ScreenExit
, "Exit"),
1888 rootmenu
->setLabel(i18n(BasemenuSet
, BasemenuBlackboxMenu
,
1895 size_t string_within(char begin
, char end
,
1896 const char *input
, size_t start_at
, size_t length
,
1900 size_t i
= start_at
;
1901 for (; i
< length
; ++i
) {
1902 if (input
[i
] == begin
) {
1904 } else if (input
[i
] == end
) {
1907 if (input
[i
] == '\\' && i
< length
- 1) i
++;
1908 output
[index
++] = input
[i
];
1913 output
[index
] = '\0';
1921 bool BScreen::parseMenuFile(FILE *file
, Rootmenu
*menu
) {
1922 char line
[1024], keyword
[1024], label
[1024], command
[1024];
1925 while (! (done
|| feof(file
))) {
1926 memset(line
, 0, 1024);
1927 memset(label
, 0, 1024);
1928 memset(command
, 0, 1024);
1930 if (! fgets(line
, 1024, file
))
1933 if (line
[0] == '#') // comment, skip it
1936 size_t line_length
= strlen(line
);
1937 unsigned int key
= 0;
1939 // get the keyword enclosed in []'s
1940 size_t pos
= string_within('[', ']', line
, 0, line_length
, keyword
);
1942 if (keyword
[0] == '\0') { // no keyword, no menu entry
1945 size_t len
= strlen(keyword
);
1946 for (size_t i
= 0; i
< len
; ++i
) {
1947 if (keyword
[i
] != ' ')
1948 key
+= tolower(keyword
[i
]);
1952 // get the label enclosed in ()'s
1953 pos
= string_within('(', ')', line
, pos
, line_length
, label
);
1955 // get the command enclosed in {}'s
1956 pos
= string_within('{', '}', line
, pos
, line_length
, command
);
1967 menu
->insert(label
);
1972 if (! (*label
&& *command
)) {
1973 fprintf(stderr
, i18n(ScreenSet
, ScreenEXECError
,
1974 "BScreen::parseMenuFile: [exec] error, "
1975 "no menu label and/or command defined\n"));
1979 menu
->insert(label
, BScreen::Execute
, command
);
1985 fprintf(stderr
, i18n(ScreenSet
, ScreenEXITError
,
1986 "BScreen::parseMenuFile: [exit] error, "
1987 "no menu label defined\n"));
1991 menu
->insert(label
, BScreen::Exit
);
1995 case 561: { // style
1996 if (! (*label
&& *command
)) {
1998 i18n(ScreenSet
, ScreenSTYLEError
,
1999 "BScreen::parseMenuFile: [style] error, "
2000 "no menu label and/or filename defined\n"));
2004 string style
= expandTilde(command
);
2006 menu
->insert(label
, BScreen::SetStyle
, style
.c_str());
2012 fprintf(stderr
, i18n(ScreenSet
, ScreenCONFIGError
,
2013 "BScreen::parseMenufile: [config] error, "
2014 "no label defined"));
2018 menu
->insert(label
, configmenu
);
2022 case 740: { // include
2024 fprintf(stderr
, i18n(ScreenSet
, ScreenINCLUDEError
,
2025 "BScreen::parseMenuFile: [include] error, "
2026 "no filename defined\n"));
2030 string newfile
= expandTilde(label
);
2031 FILE *submenufile
= fopen(newfile
.c_str(), "r");
2033 if (! submenufile
) {
2034 perror(newfile
.c_str());
2039 if (fstat(fileno(submenufile
), &buf
) ||
2040 ! S_ISREG(buf
.st_mode
)) {
2042 i18n(ScreenSet
, ScreenINCLUDEErrorReg
,
2043 "BScreen::parseMenuFile: [include] error: "
2044 "'%s' is not a regular file\n"), newfile
.c_str());
2048 if (! feof(submenufile
)) {
2049 if (! parseMenuFile(submenufile
, menu
))
2050 blackbox
->addMenuTimestamp(newfile
);
2052 fclose(submenufile
);
2058 case 767: { // submenu
2060 fprintf(stderr
, i18n(ScreenSet
, ScreenSUBMENUError
,
2061 "BScreen::parseMenuFile: [submenu] error, "
2062 "no menu label defined\n"));
2066 Rootmenu
*submenu
= new Rootmenu(this);
2069 submenu
->setLabel(command
);
2071 submenu
->setLabel(label
);
2073 parseMenuFile(file
, submenu
);
2075 menu
->insert(label
, submenu
);
2076 rootmenuList
.push_back(submenu
);
2081 case 773: { // restart
2083 fprintf(stderr
, i18n(ScreenSet
, ScreenRESTARTError
,
2084 "BScreen::parseMenuFile: [restart] error, "
2085 "no menu label defined\n"));
2090 menu
->insert(label
, BScreen::RestartOther
, command
);
2092 menu
->insert(label
, BScreen::Restart
);
2097 case 845: { // reconfig
2100 i18n(ScreenSet
, ScreenRECONFIGError
,
2101 "BScreen::parseMenuFile: [reconfig] error, "
2102 "no menu label defined\n"));
2106 menu
->insert(label
, BScreen::Reconfigure
);
2111 case 995: // stylesdir
2112 case 1113: { // stylesmenu
2113 bool newmenu
= ((key
== 1113) ? True
: False
);
2115 if (! *label
|| (! *command
&& newmenu
)) {
2117 i18n(ScreenSet
, ScreenSTYLESDIRError
,
2118 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
2119 " error, no directory defined\n"));
2123 char *directory
= ((newmenu
) ? command
: label
);
2125 string stylesdir
= expandTilde(directory
);
2127 struct stat statbuf
;
2129 if (stat(stylesdir
.c_str(), &statbuf
) == -1) {
2131 i18n(ScreenSet
, ScreenSTYLESDIRErrorNoExist
,
2132 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
2133 " error, %s does not exist\n"), stylesdir
.c_str());
2136 if (! S_ISDIR(statbuf
.st_mode
)) {
2138 i18n(ScreenSet
, ScreenSTYLESDIRErrorNotDir
,
2139 "BScreen::parseMenuFile:"
2140 " [stylesdir/stylesmenu] error, %s is not a"
2141 " directory\n"), stylesdir
.c_str());
2145 Rootmenu
*stylesmenu
;
2148 stylesmenu
= new Rootmenu(this);
2152 DIR *d
= opendir(stylesdir
.c_str());
2154 std::vector
<string
> ls
;
2156 while((p
= readdir(d
)))
2157 ls
.push_back(p
->d_name
);
2161 std::sort(ls
.begin(), ls
.end());
2163 std::vector
<string
>::iterator it
= ls
.begin(),
2165 for (; it
!= end
; ++it
) {
2166 const string
& fname
= *it
;
2168 if (fname
[fname
.size()-1] == '~')
2171 string style
= stylesdir
;
2175 if (! stat(style
.c_str(), &statbuf
) && S_ISREG(statbuf
.st_mode
))
2176 stylesmenu
->insert(fname
, BScreen::SetStyle
, style
);
2179 stylesmenu
->update();
2182 stylesmenu
->setLabel(label
);
2183 menu
->insert(label
, stylesmenu
);
2184 rootmenuList
.push_back(stylesmenu
);
2187 blackbox
->addMenuTimestamp(stylesdir
);
2191 case 1090: { // workspaces
2194 i18n(ScreenSet
, ScreenWORKSPACESError
,
2195 "BScreen:parseMenuFile: [workspaces] error, "
2196 "no menu label defined\n"));
2200 menu
->insert(label
, workspacemenu
);
2206 return ((menu
->getCount() == 0) ? True
: False
);
2210 void BScreen::shutdown(void) {
2211 XSelectInput(blackbox
->getXDisplay(), getRootWindow(), NoEventMask
);
2212 XSync(blackbox
->getXDisplay(), False
);
2214 while(! windowList
.empty())
2215 unmanageWindow(windowList
.front(), True
);
2221 void BScreen::showPosition(int x
, int y
) {
2222 if (! geom_visible
) {
2223 XMoveResizeWindow(blackbox
->getXDisplay(), geom_window
,
2224 (getWidth() - geom_w
) / 2,
2225 (getHeight() - geom_h
) / 2, geom_w
, geom_h
);
2226 XMapWindow(blackbox
->getXDisplay(), geom_window
);
2227 XRaiseWindow(blackbox
->getXDisplay(), geom_window
);
2229 geom_visible
= True
;
2234 sprintf(label
, i18n(ScreenSet
, ScreenPositionFormat
,
2235 "X: %4d x Y: %4d"), x
, y
);
2237 XClearWindow(blackbox
->getXDisplay(), geom_window
);
2239 resource
.wstyle
.font
->drawString(geom_window
,
2240 resource
.bevel_width
, resource
.bevel_width
,
2241 resource
.wstyle
.l_text_focus
,
2246 void BScreen::showGeometry(unsigned int gx
, unsigned int gy
) {
2247 if (! geom_visible
) {
2248 XMoveResizeWindow(blackbox
->getXDisplay(), geom_window
,
2249 (getWidth() - geom_w
) / 2,
2250 (getHeight() - geom_h
) / 2, geom_w
, geom_h
);
2251 XMapWindow(blackbox
->getXDisplay(), geom_window
);
2252 XRaiseWindow(blackbox
->getXDisplay(), geom_window
);
2254 geom_visible
= True
;
2259 sprintf(label
, i18n(ScreenSet
, ScreenGeometryFormat
,
2260 "W: %4d x H: %4d"), gx
, gy
);
2262 XClearWindow(blackbox
->getXDisplay(), geom_window
);
2264 resource
.wstyle
.font
->drawString(geom_window
,
2265 resource
.bevel_width
, resource
.bevel_width
,
2266 resource
.wstyle
.l_text_focus
,
2271 void BScreen::hideGeometry(void) {
2273 XUnmapWindow(blackbox
->getXDisplay(), geom_window
);
2274 geom_visible
= False
;
2279 void BScreen::addStrut(Strut
*strut
) {
2280 strutList
.push_back(strut
);
2284 void BScreen::removeStrut(Strut
*strut
) {
2285 strutList
.remove(strut
);
2289 const Rect
& BScreen::availableArea(void) const {
2291 return getRect(); // return the full screen
2297 const RectList
& BScreen::allAvailableAreas(void) const {
2298 assert(isXineramaActive());
2299 assert(xineramaUsableArea
.size() > 0);
2300 fprintf(stderr
, "1found x %d y %d w %d h %d\n",
2301 xineramaUsableArea
[0].x(), xineramaUsableArea
[0].y(),
2302 xineramaUsableArea
[0].width(), xineramaUsableArea
[0].height());
2303 return xineramaUsableArea
;
2308 void BScreen::updateAvailableArea(void) {
2309 Rect old_area
= usableArea
;
2310 usableArea
= getRect(); // reset to full screen
2313 // reset to the full areas
2314 if (isXineramaActive())
2315 xineramaUsableArea
= getXineramaAreas();
2318 /* these values represent offsets from the screen edge
2319 * we look for the biggest offset on each edge and then apply them
2321 * do not be confused by the similarity to the names of Rect's members
2323 unsigned int current_left
= 0, current_right
= 0, current_top
= 0,
2326 StrutList::const_iterator it
= strutList
.begin(), end
= strutList
.end();
2328 for(; it
!= end
; ++it
) {
2330 if (strut
->left
> current_left
)
2331 current_left
= strut
->left
;
2332 if (strut
->top
> current_top
)
2333 current_top
= strut
->top
;
2334 if (strut
->right
> current_right
)
2335 current_right
= strut
->right
;
2336 if (strut
->bottom
> current_bottom
)
2337 current_bottom
= strut
->bottom
;
2340 usableArea
.setPos(current_left
, current_top
);
2341 usableArea
.setSize(usableArea
.width() - (current_left
+ current_right
),
2342 usableArea
.height() - (current_top
+ current_bottom
));
2345 if (isXineramaActive()) {
2346 // keep each of the ximerama-defined areas inside the strut
2347 RectList::iterator xit
, xend
= xineramaUsableArea
.end();
2348 for (xit
= xineramaUsableArea
.begin(); xit
!= xend
; ++xit
) {
2349 if (xit
->x() < usableArea
.x()) {
2350 xit
->setX(usableArea
.x());
2351 xit
->setWidth(xit
->width() - usableArea
.x());
2353 if (xit
->y() < usableArea
.y()) {
2354 xit
->setY(usableArea
.y());
2355 xit
->setHeight(xit
->height() - usableArea
.y());
2357 if (xit
->x() + xit
->width() > usableArea
.width())
2358 xit
->setWidth(usableArea
.width() - xit
->x());
2359 if (xit
->y() + xit
->height() > usableArea
.height())
2360 xit
->setHeight(usableArea
.height() - xit
->y());
2365 if (old_area
!= usableArea
) {
2366 BlackboxWindowList::iterator it
= windowList
.begin(),
2367 end
= windowList
.end();
2368 for (; it
!= end
; ++it
)
2369 if ((*it
)->isMaximized()) (*it
)->remaximize();
2376 Workspace
* BScreen::getWorkspace(unsigned int index
) {
2377 assert(index
< workspacesList
.size());
2378 return workspacesList
[index
];
2382 void BScreen::buttonPressEvent(const XButtonEvent
*xbutton
) {
2383 if (xbutton
->button
== 1) {
2384 if (! isRootColormapInstalled())
2385 image_control
->installRootColormap();
2387 if (workspacemenu
->isVisible())
2388 workspacemenu
->hide();
2390 if (rootmenu
->isVisible())
2392 } else if (xbutton
->button
== 2) {
2393 showWorkspaceMenu(xbutton
->x_root
, xbutton
->y_root
);
2394 } else if (xbutton
->button
== 3) {
2395 showRootMenu(xbutton
->x_root
, xbutton
->y_root
);
2397 } else if ((xbutton
->button
== 4 && resource
.root_scroll
== NormalScroll
) ||
2398 (xbutton
->button
== 5 && resource
.root_scroll
== ReverseScroll
)) {
2399 if (getCurrentWorkspaceID() >= getWorkspaceCount() - 1)
2400 changeWorkspaceID(0);
2402 changeWorkspaceID(getCurrentWorkspaceID() + 1);
2404 } else if ((xbutton
->button
== 5 && resource
.root_scroll
== NormalScroll
) ||
2405 (xbutton
->button
== 4 && resource
.root_scroll
== ReverseScroll
)) {
2406 if (getCurrentWorkspaceID() == 0)
2407 changeWorkspaceID(getWorkspaceCount() - 1);
2409 changeWorkspaceID(getCurrentWorkspaceID() - 1);
2414 void BScreen::showWorkspaceMenu(int x
, int y
) {
2415 int mx
= x
- (workspacemenu
->getWidth() / 2);
2416 int my
= y
- (workspacemenu
->getTitleHeight() / 2);
2421 if (mx
+ workspacemenu
->getWidth() > getWidth())
2422 mx
= getWidth() - workspacemenu
->getWidth() - getBorderWidth();
2424 if (my
+ workspacemenu
->getHeight() > getHeight())
2425 my
= getHeight() - workspacemenu
->getHeight() - getBorderWidth();
2427 workspacemenu
->move(mx
, my
);
2429 if (! workspacemenu
->isVisible()) {
2430 workspacemenu
->removeParent();
2431 workspacemenu
->show();
2436 void BScreen::showRootMenu(int x
, int y
) {
2437 int mx
= x
- (rootmenu
->getWidth() / 2);
2438 int my
= y
- (rootmenu
->getTitleHeight() / 2);
2443 if (mx
+ rootmenu
->getWidth() > getWidth())
2444 mx
= getWidth() - rootmenu
->getWidth() - getBorderWidth();
2446 if (my
+ rootmenu
->getHeight() > getHeight())
2447 my
= getHeight() - rootmenu
->getHeight() - getBorderWidth();
2449 rootmenu
->move(mx
, my
);
2451 if (! rootmenu
->isVisible()) {
2452 blackbox
->checkMenu();
2458 void BScreen::propertyNotifyEvent(const XPropertyEvent
*pe
) {
2459 if (pe
->atom
== xatom
->getAtom(XAtom::net_desktop_names
)) {
2460 // _NET_WM_DESKTOP_NAMES
2461 WorkspaceList::iterator it
= workspacesList
.begin();
2462 const WorkspaceList::iterator end
= workspacesList
.end();
2463 for (; it
!= end
; ++it
) {
2464 (*it
)->readName(); // re-read its name from the window property
2465 workspacemenu
->changeWorkspaceLabel((*it
)->getID(), (*it
)->getName());
2467 workspacemenu
->update();
2468 toolbar
->reconfigure();
2469 saveWorkspaceNames();
2474 void BScreen::toggleFocusModel(FocusModel model
) {
2475 std::for_each(windowList
.begin(), windowList
.end(),
2476 std::mem_fun(&BlackboxWindow::ungrabButtons
));
2478 if (model
== SloppyFocus
) {
2479 saveSloppyFocus(True
);
2481 // we're cheating here to save writing the config file 3 times
2482 resource
.auto_raise
= False
;
2483 resource
.click_raise
= False
;
2484 saveSloppyFocus(False
);
2487 std::for_each(windowList
.begin(), windowList
.end(),
2488 std::mem_fun(&BlackboxWindow::grabButtons
));
2492 BTexture
BScreen::readDatabaseTexture(const string
&rname
,
2493 const string
&default_color
,
2494 const Configuration
&style
) {
2498 if (style
.getValue(rname
, s
))
2499 texture
= BTexture(s
);
2501 texture
.setTexture(BTexture::Solid
| BTexture::Flat
);
2503 // associate this texture with this screen
2504 texture
.setDisplay(getBaseDisplay(), getScreenNumber());
2505 texture
.setImageControl(image_control
);
2507 texture
.setColor(readDatabaseColor(rname
+ ".color", default_color
, style
));
2508 texture
.setColorTo(readDatabaseColor(rname
+ ".colorTo", default_color
,
2515 BColor
BScreen::readDatabaseColor(const string
&rname
,
2516 const string
&default_color
,
2517 const Configuration
&style
) {
2520 if (style
.getValue(rname
, s
))
2521 color
= BColor(s
, getBaseDisplay(), getScreenNumber());
2523 color
= BColor(default_color
, getBaseDisplay(), getScreenNumber());
2528 BFont
*BScreen::readDatabaseFont(const string
&rbasename
,
2529 const Configuration
&style
) {
2536 if (style
.getValue(rbasename
+ "xft.font", s
) &&
2537 style
.getValue(rbasename
+ "xft.size", i
)) {
2540 bool italic
= False
;
2541 if (style
.getValue(rbasename
+ "xft.flags", s
)) {
2542 if (s
.find("bold") != string::npos
)
2544 if (s
.find("italic") != string::npos
)
2548 BFont
*b
= new BFont(blackbox
->getXDisplay(), this, family
, i
, bold
,
2549 italic
, resource
.aa_fonts
);
2553 delete b
; // fall back to the normal X font stuff
2557 style
.getValue(rbasename
+ "font", s
);
2558 // if this fails, a blank string will be used, which will cause the fallback
2561 BFont
*b
= new BFont(blackbox
->getXDisplay(), this, s
);
2563 exit(2); // can't continue without a font