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 Workspace
*wkspc
= (Workspace
*) 0;
209 if (resource
.workspaces
!= 0) {
210 for (unsigned int i
= 0; i
< resource
.workspaces
; ++i
) {
211 wkspc
= new Workspace(this, workspacesList
.size());
212 workspacesList
.push_back(wkspc
);
213 workspacemenu
->insert(wkspc
->getName(), wkspc
->getMenu());
216 wkspc
= new Workspace(this, workspacesList
.size());
217 workspacesList
.push_back(wkspc
);
218 workspacemenu
->insert(wkspc
->getName(), wkspc
->getMenu());
220 saveWorkspaceNames();
222 updateNetizenWorkspaceCount();
224 workspacemenu
->insert(i18n(IconSet
, IconIcons
, "Icons"), iconmenu
);
225 workspacemenu
->update();
227 current_workspace
= workspacesList
.front();
229 xatom
->setValue(getRootWindow(), XAtom::net_current_desktop
,
230 XAtom::cardinal
, 0); //first workspace
232 workspacemenu
->setItemSelected(2, True
);
234 toolbar
= new Toolbar(this);
236 slit
= new Slit(this);
240 raiseWindows(0, 0); // this also initializes the empty stacking list
243 updateClientList(); // initialize the client lists, which will be empty
244 updateAvailableArea();
246 changeWorkspaceID(0);
248 unsigned int i
, j
, nchild
;
249 Window r
, p
, *children
;
250 XQueryTree(blackbox
->getXDisplay(), getRootWindow(), &r
, &p
,
253 // preen the window list of all icon windows... for better dockapp support
254 for (i
= 0; i
< nchild
; i
++) {
255 if (children
[i
] == None
) continue;
257 XWMHints
*wmhints
= XGetWMHints(blackbox
->getXDisplay(),
261 if ((wmhints
->flags
& IconWindowHint
) &&
262 (wmhints
->icon_window
!= children
[i
])) {
263 for (j
= 0; j
< nchild
; j
++) {
264 if (children
[j
] == wmhints
->icon_window
) {
275 // manage shown windows
276 for (i
= 0; i
< nchild
; ++i
) {
277 if (children
[i
] == None
|| (! blackbox
->validateWindow(children
[i
])))
280 XWindowAttributes attrib
;
281 if (XGetWindowAttributes(blackbox
->getXDisplay(), children
[i
], &attrib
)) {
282 if (attrib
.override_redirect
) continue;
284 if (attrib
.map_state
!= IsUnmapped
) {
285 manageWindow(children
[i
]);
292 // call this again just in case a window we found updates the Strut list
293 updateAvailableArea();
297 BScreen::~BScreen(void) {
298 if (! managed
) return;
300 if (geom_pixmap
!= None
)
301 image_control
->removeImage(geom_pixmap
);
303 if (geom_window
!= None
)
304 XDestroyWindow(blackbox
->getXDisplay(), geom_window
);
306 std::for_each(workspacesList
.begin(), workspacesList
.end(),
309 std::for_each(iconList
.begin(), iconList
.end(), PointerAssassin());
311 std::for_each(netizenList
.begin(), netizenList
.end(), PointerAssassin());
313 while (! desktopWindowList
.empty())
314 removeDesktopWindow(desktopWindowList
[0]);
316 while (! systrayWindowList
.empty())
317 removeSystrayWindow(systrayWindowList
[0]);
320 delete workspacemenu
;
325 delete image_control
;
327 if (resource
.wstyle
.font
)
328 delete resource
.wstyle
.font
;
329 if (resource
.mstyle
.t_font
)
330 delete resource
.mstyle
.t_font
;
331 if (resource
.mstyle
.f_font
)
332 delete resource
.mstyle
.f_font
;
333 if (resource
.tstyle
.font
)
334 delete resource
.tstyle
.font
;
336 XFreeGC(blackbox
->getXDisplay(), opGC
);
340 void BScreen::saveSloppyFocus(bool s
) {
341 resource
.sloppy_focus
= s
;
344 if (resource
.sloppy_focus
) {
345 fmodel
= "SloppyFocus";
346 if (resource
.auto_raise
) fmodel
+= " AutoRaise";
347 if (resource
.click_raise
) fmodel
+= " ClickRaise";
349 fmodel
= "ClickToFocus";
351 config
->setValue(screenstr
+ "focusModel", fmodel
);
355 void BScreen::saveAutoRaise(bool a
) {
356 resource
.auto_raise
= a
;
357 saveSloppyFocus(resource
.sloppy_focus
);
361 void BScreen::saveClickRaise(bool c
) {
362 resource
.click_raise
= c
;
363 saveSloppyFocus(resource
.sloppy_focus
);
367 void BScreen::saveImageDither(bool d
) {
368 image_control
->setDither(d
);
369 config
->setValue(screenstr
+ "imageDither", doImageDither());
373 void BScreen::saveOpaqueMove(bool o
) {
374 resource
.opaque_move
= o
;
375 config
->setValue(screenstr
+ "opaqueMove", resource
.opaque_move
);
379 void BScreen::saveFullMax(bool f
) {
380 resource
.full_max
= f
;
381 config
->setValue(screenstr
+ "fullMaximization", resource
.full_max
);
385 void BScreen::saveFocusNew(bool f
) {
386 resource
.focus_new
= f
;
387 config
->setValue(screenstr
+ "focusNewWindows", resource
.focus_new
);
391 void BScreen::saveFocusLast(bool f
) {
392 resource
.focus_last
= f
;
393 config
->setValue(screenstr
+ "focusLastWindow", resource
.focus_last
);
397 void BScreen::saveAAFonts(bool f
) {
398 resource
.aa_fonts
= f
;
400 config
->setValue(screenstr
+ "antialiasFonts", resource
.aa_fonts
);
404 void BScreen::saveHideToolbar(bool h
) {
405 resource
.hide_toolbar
= h
;
406 if (resource
.hide_toolbar
)
407 toolbar
->unmapToolbar();
409 toolbar
->mapToolbar();
410 config
->setValue(screenstr
+ "hideToolbar", resource
.hide_toolbar
);
414 void BScreen::saveWindowToWindowSnap(bool s
) {
415 resource
.window_to_window_snap
= s
;
416 config
->setValue(screenstr
+ "windowToWindowSnap",
417 resource
.window_to_window_snap
);
421 void BScreen::saveResizeZones(unsigned int z
) {
422 resource
.resize_zones
= z
;
423 config
->setValue(screenstr
+ "resizeZones", resource
.resize_zones
);
427 void BScreen::saveWindowCornerSnap(bool s
) {
428 resource
.window_corner_snap
= s
;
429 config
->setValue(screenstr
+ "windowCornerSnap",
430 resource
.window_corner_snap
);
434 void BScreen::saveWorkspaces(unsigned int w
) {
435 resource
.workspaces
= w
;
436 config
->setValue(screenstr
+ "workspaces", resource
.workspaces
);
440 void BScreen::savePlacementPolicy(int p
) {
441 resource
.placement_policy
= p
;
442 const char *placement
;
443 switch (resource
.placement_policy
) {
444 case CascadePlacement
: placement
= "CascadePlacement"; break;
445 case ColSmartPlacement
: placement
= "ColSmartPlacement"; break;
446 case RowSmartPlacement
: default: placement
= "RowSmartPlacement"; break;
448 config
->setValue(screenstr
+ "windowPlacement", placement
);
452 void BScreen::saveEdgeSnapThreshold(int t
) {
453 resource
.edge_snap_threshold
= t
;
454 config
->setValue(screenstr
+ "edgeSnapThreshold",
455 resource
.edge_snap_threshold
);
459 void BScreen::saveRowPlacementDirection(int d
) {
460 resource
.row_direction
= d
;
461 config
->setValue(screenstr
+ "rowPlacementDirection",
462 resource
.row_direction
== LeftRight
?
463 "LeftToRight" : "RightToLeft");
467 void BScreen::saveColPlacementDirection(int d
) {
468 resource
.col_direction
= d
;
469 config
->setValue(screenstr
+ "colPlacementDirection",
470 resource
.col_direction
== TopBottom
?
471 "TopToBottom" : "BottomToTop");
476 void BScreen::saveStrftimeFormat(const std::string
& format
) {
477 resource
.strftime_format
= format
;
478 config
->setValue(screenstr
+ "strftimeFormat", resource
.strftime_format
);
481 #else // !HAVE_STRFTIME
483 void BScreen::saveDateFormat(int f
) {
484 resource
.date_format
= f
;
485 config
->setValue(screenstr
+ "dateFormat",
486 resource
.date_format
== B_EuropeanDate
?
487 "European" : "American");
491 void BScreen::saveClock24Hour(Bool c
) {
492 resource
.clock24hour
= c
;
493 config
->setValue(screenstr
+ "clockFormat", resource
.clock24hour
? 24 : 12);
495 #endif // HAVE_STRFTIME
498 void BScreen::saveWorkspaceNames() {
499 XAtom::StringVect nameList
;
500 unsigned long numnames
= (unsigned) -1;
504 xatom
->getValue(getRootWindow(), XAtom::net_desktop_names
, XAtom::utf8
,
505 numnames
, nameList
)) {
506 for (unsigned int i
= 0; i
< nameList
.size(); ++i
) {
507 if (i
> 0) names
+= ",";
508 names
+= nameList
[i
];
511 config
->setValue(screenstr
+ "workspaceNames", names
);
515 void BScreen::save_rc(void) {
516 saveSloppyFocus(resource
.sloppy_focus
);
517 saveAutoRaise(resource
.auto_raise
);
518 saveImageDither(doImageDither());
519 saveAAFonts(resource
.aa_fonts
);
520 saveResizeZones(resource
.resize_zones
);
521 saveOpaqueMove(resource
.opaque_move
);
522 saveFullMax(resource
.full_max
);
523 saveFocusNew(resource
.focus_new
);
524 saveFocusLast(resource
.focus_last
);
525 saveHideToolbar(resource
.hide_toolbar
);
526 saveWindowToWindowSnap(resource
.window_to_window_snap
);
527 saveWindowCornerSnap(resource
.window_corner_snap
);
528 saveWorkspaces(resource
.workspaces
);
529 savePlacementPolicy(resource
.placement_policy
);
530 saveEdgeSnapThreshold(resource
.edge_snap_threshold
);
531 saveRowPlacementDirection(resource
.row_direction
);
532 saveColPlacementDirection(resource
.col_direction
);
534 saveStrftimeFormat(resource
.strftime_format
);
535 #else // !HAVE_STRFTIME
536 saveDateFormat(resource
.date_format
);
537 savwClock24Hour(resource
.clock24hour
);
538 #endif // HAVE_STRFTIME
545 void BScreen::load_rc(void) {
549 if (! config
->getValue(screenstr
+ "fullMaximization", resource
.full_max
))
550 resource
.full_max
= false;
552 if (! config
->getValue(screenstr
+ "focusNewWindows", resource
.focus_new
))
553 resource
.focus_new
= false;
555 if (! config
->getValue(screenstr
+ "focusLastWindow", resource
.focus_last
))
556 resource
.focus_last
= false;
558 if (! config
->getValue(screenstr
+ "workspaces", resource
.workspaces
))
559 resource
.workspaces
= 1;
561 if (! config
->getValue(screenstr
+ "opaqueMove", resource
.opaque_move
))
562 resource
.opaque_move
= false;
564 if (! config
->getValue(screenstr
+ "antialiasFonts", resource
.aa_fonts
))
565 resource
.aa_fonts
= true;
567 if (! config
->getValue(screenstr
+ "resizeZones", resource
.resize_zones
) ||
568 (resource
.resize_zones
!= 1 && resource
.resize_zones
!= 2 &&
569 resource
.resize_zones
!= 4))
570 resource
.resize_zones
= 4;
572 if (! config
->getValue(screenstr
+ "hideToolbar", resource
.hide_toolbar
))
573 resource
.hide_toolbar
= false;
575 if (! config
->getValue(screenstr
+ "windowToWindowSnap",
576 resource
.window_to_window_snap
))
577 resource
.window_to_window_snap
= true;
579 if (! config
->getValue(screenstr
+ "windowCornerSnap",
580 resource
.window_corner_snap
))
581 resource
.window_corner_snap
= true;
583 if (! config
->getValue(screenstr
+ "imageDither", b
))
585 image_control
->setDither(b
);
587 if (! config
->getValue(screenstr
+ "edgeSnapThreshold",
588 resource
.edge_snap_threshold
))
589 resource
.edge_snap_threshold
= 4;
591 if (config
->getValue(screenstr
+ "rowPlacementDirection", s
) &&
593 resource
.row_direction
= RightLeft
;
595 resource
.row_direction
= LeftRight
;
597 if (config
->getValue(screenstr
+ "colPlacementDirection", s
) &&
599 resource
.col_direction
= BottomTop
;
601 resource
.col_direction
= TopBottom
;
603 XAtom::StringVect workspaceNames
;
604 if (config
->getValue(screenstr
+ "workspaceNames", s
)) {
605 string::const_iterator it
= s
.begin(), end
= s
.end();
607 string::const_iterator tmp
= it
; // current string.begin()
608 it
= std::find(tmp
, end
, ','); // look for comma between tmp and end
609 workspaceNames
.push_back(string(tmp
, it
)); // s[tmp:it]
615 xatom
->setValue(getRootWindow(), XAtom::net_desktop_names
, XAtom::utf8
,
618 resource
.sloppy_focus
= true;
619 resource
.auto_raise
= false;
620 resource
.click_raise
= false;
621 if (config
->getValue(screenstr
+ "focusModel", s
)) {
622 if (s
.find("ClickToFocus") != string::npos
) {
623 resource
.sloppy_focus
= false;
626 if (s
.find("AutoRaise") != string::npos
)
627 resource
.auto_raise
= true;
628 if (s
.find("ClickRaise") != string::npos
)
629 resource
.click_raise
= true;
633 if (config
->getValue(screenstr
+ "windowPlacement", s
)) {
634 if (s
== "CascadePlacement")
635 resource
.placement_policy
= CascadePlacement
;
636 else if (s
== "ColSmartPlacement")
637 resource
.placement_policy
= ColSmartPlacement
;
638 else //if (s == "RowSmartPlacement")
639 resource
.placement_policy
= RowSmartPlacement
;
641 resource
.placement_policy
= RowSmartPlacement
;
644 if (config
->getValue(screenstr
+ "strftimeFormat", s
))
645 resource
.strftime_format
= s
;
647 resource
.strftime_format
= "%I:%M %p";
648 #else // !HAVE_STRFTIME
651 if (config
->getValue(screenstr
+ "dateFormat", s
) && s
== "European")
652 resource
.date_format
= B_EuropeanDate
;
654 resource
.date_format
= B_AmericanDate
;
656 if (! config
->getValue(screenstr
+ "clockFormat", l
))
658 resource
.clock24hour
= l
== 24;
659 #endif // HAVE_STRFTIME
663 void BScreen::reconfigure(void) {
670 gcv
.foreground
= WhitePixel(blackbox
->getXDisplay(),
672 gcv
.function
= GXinvert
;
673 gcv
.subwindow_mode
= IncludeInferiors
;
674 XChangeGC(blackbox
->getXDisplay(), opGC
,
675 GCForeground
| GCFunction
| GCSubwindowMode
, &gcv
);
677 const char *s
= i18n(ScreenSet
, ScreenPositionLength
,
678 "0: 0000 x 0: 0000");
680 geom_w
= resource
.wstyle
.font
->measureString(s
) + resource
.bevel_width
* 2;
681 geom_h
= resource
.wstyle
.font
->height() + resource
.bevel_width
* 2;
683 BTexture
* texture
= &(resource
.wstyle
.l_focus
);
684 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
685 if (geom_pixmap
== ParentRelative
) {
686 texture
= &(resource
.wstyle
.t_focus
);
687 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
690 XSetWindowBackground(blackbox
->getXDisplay(), geom_window
,
691 texture
->color().pixel());
693 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
694 geom_window
, geom_pixmap
);
696 XSetWindowBorderWidth(blackbox
->getXDisplay(), geom_window
,
697 resource
.border_width
);
698 XSetWindowBorder(blackbox
->getXDisplay(), geom_window
,
699 resource
.border_color
.pixel());
701 workspacemenu
->reconfigure();
702 iconmenu
->reconfigure();
704 typedef std::vector
<int> SubList
;
705 SubList remember_subs
;
707 // save the current open menus
708 Basemenu
*menu
= rootmenu
;
710 while ((submenu
= menu
->getCurrentSubmenu()) >= 0) {
711 remember_subs
.push_back(submenu
);
712 menu
= menu
->find(submenu
)->submenu();
718 rootmenu
->reconfigure();
720 // reopen the saved menus
722 const SubList::iterator subs_end
= remember_subs
.end();
723 for (SubList::iterator it
= remember_subs
.begin(); it
!= subs_end
; ++it
) {
724 menu
->drawSubmenu(*it
);
725 menu
= menu
->find(*it
)->submenu();
730 configmenu
->reconfigure();
732 toolbar
->reconfigure();
736 std::for_each(workspacesList
.begin(), workspacesList
.end(),
737 std::mem_fun(&Workspace::reconfigure
));
739 BlackboxWindowList::iterator iit
= iconList
.begin();
740 for (; iit
!= iconList
.end(); ++iit
) {
741 BlackboxWindow
*bw
= *iit
;
742 if (bw
->validateClient())
746 image_control
->timeout();
750 void BScreen::rereadMenu(void) {
754 rootmenu
->reconfigure();
758 void BScreen::LoadStyle(void) {
759 Configuration
style(False
);
761 const char *sfile
= blackbox
->getStyleFilename();
763 style
.setFile(sfile
);
764 if (! style
.load()) {
765 style
.setFile(DEFAULTSTYLE
);
767 style
.create(); // hardcoded default values will be used.
771 // merge in the rc file
772 style
.merge(config
->file(), True
);
776 // load fonts/fontsets
777 if (resource
.wstyle
.font
)
778 delete resource
.wstyle
.font
;
779 if (resource
.tstyle
.font
)
780 delete resource
.tstyle
.font
;
781 if (resource
.mstyle
.f_font
)
782 delete resource
.mstyle
.f_font
;
783 if (resource
.mstyle
.t_font
)
784 delete resource
.mstyle
.t_font
;
785 resource
.wstyle
.font
= resource
.tstyle
.font
= resource
.mstyle
.f_font
=
786 resource
.mstyle
.t_font
= (BFont
*) 0;
788 resource
.wstyle
.font
= readDatabaseFont("window.", style
);
789 resource
.tstyle
.font
= readDatabaseFont("toolbar.", style
);
790 resource
.mstyle
.t_font
= readDatabaseFont("menu.title.", style
);
791 resource
.mstyle
.f_font
= readDatabaseFont("menu.frame.", style
);
793 // load window config
794 resource
.wstyle
.t_focus
=
795 readDatabaseTexture("window.title.focus", "white", style
);
796 resource
.wstyle
.t_unfocus
=
797 readDatabaseTexture("window.title.unfocus", "black", style
);
798 resource
.wstyle
.l_focus
=
799 readDatabaseTexture("window.label.focus", "white", style
);
800 resource
.wstyle
.l_unfocus
=
801 readDatabaseTexture("window.label.unfocus", "black", style
);
802 resource
.wstyle
.h_focus
=
803 readDatabaseTexture("window.handle.focus", "white", style
);
804 resource
.wstyle
.h_unfocus
=
805 readDatabaseTexture("window.handle.unfocus", "black", style
);
806 resource
.wstyle
.g_focus
=
807 readDatabaseTexture("window.grip.focus", "white", style
);
808 resource
.wstyle
.g_unfocus
=
809 readDatabaseTexture("window.grip.unfocus", "black", style
);
810 resource
.wstyle
.b_focus
=
811 readDatabaseTexture("window.button.focus", "white", style
);
812 resource
.wstyle
.b_unfocus
=
813 readDatabaseTexture("window.button.unfocus", "black", style
);
814 resource
.wstyle
.b_pressed
=
815 readDatabaseTexture("window.button.pressed", "black", style
);
816 resource
.wstyle
.f_focus
=
817 readDatabaseColor("window.frame.focusColor", "white", style
);
818 resource
.wstyle
.f_unfocus
=
819 readDatabaseColor("window.frame.unfocusColor", "black", style
);
820 resource
.wstyle
.l_text_focus
=
821 readDatabaseColor("window.label.focus.textColor", "black", style
);
822 resource
.wstyle
.l_text_unfocus
=
823 readDatabaseColor("window.label.unfocus.textColor", "white", style
);
824 resource
.wstyle
.b_pic_focus
=
825 readDatabaseColor("window.button.focus.picColor", "black", style
);
826 resource
.wstyle
.b_pic_unfocus
=
827 readDatabaseColor("window.button.unfocus.picColor", "white", style
);
829 resource
.wstyle
.justify
= LeftJustify
;
830 if (style
.getValue("window.justify", s
)) {
831 if (s
== "right" || s
== "Right")
832 resource
.wstyle
.justify
= RightJustify
;
833 else if (s
== "center" || s
== "Center")
834 resource
.wstyle
.justify
= CenterJustify
;
837 // load toolbar config
838 resource
.tstyle
.toolbar
=
839 readDatabaseTexture("toolbar", "black", style
);
840 resource
.tstyle
.label
=
841 readDatabaseTexture("toolbar.label", "black", style
);
842 resource
.tstyle
.window
=
843 readDatabaseTexture("toolbar.windowLabel", "black", style
);
844 resource
.tstyle
.button
=
845 readDatabaseTexture("toolbar.button", "white", style
);
846 resource
.tstyle
.pressed
=
847 readDatabaseTexture("toolbar.button.pressed", "black", style
);
848 resource
.tstyle
.clock
=
849 readDatabaseTexture("toolbar.clock", "black", style
);
850 resource
.tstyle
.l_text
=
851 readDatabaseColor("toolbar.label.textColor", "white", style
);
852 resource
.tstyle
.w_text
=
853 readDatabaseColor("toolbar.windowLabel.textColor", "white", style
);
854 resource
.tstyle
.c_text
=
855 readDatabaseColor("toolbar.clock.textColor", "white", style
);
856 resource
.tstyle
.b_pic
=
857 readDatabaseColor("toolbar.button.picColor", "black", style
);
859 resource
.tstyle
.justify
= LeftJustify
;
860 if (style
.getValue("toolbar.justify", s
)) {
861 if (s
== "right" || s
== "Right")
862 resource
.tstyle
.justify
= RightJustify
;
863 else if (s
== "center" || s
== "Center")
864 resource
.tstyle
.justify
= CenterJustify
;
868 resource
.mstyle
.title
=
869 readDatabaseTexture("menu.title", "white", style
);
870 resource
.mstyle
.frame
=
871 readDatabaseTexture("menu.frame", "black", style
);
872 resource
.mstyle
.hilite
=
873 readDatabaseTexture("menu.hilite", "white", style
);
874 resource
.mstyle
.t_text
=
875 readDatabaseColor("menu.title.textColor", "black", style
);
876 resource
.mstyle
.f_text
=
877 readDatabaseColor("menu.frame.textColor", "white", style
);
878 resource
.mstyle
.d_text
=
879 readDatabaseColor("menu.frame.disableColor", "black", style
);
880 resource
.mstyle
.h_text
=
881 readDatabaseColor("menu.hilite.textColor", "black", style
);
883 resource
.mstyle
.t_justify
= LeftJustify
;
884 if (style
.getValue("menu.title.justify", s
)) {
885 if (s
== "right" || s
== "Right")
886 resource
.mstyle
.t_justify
= RightJustify
;
887 else if (s
== "center" || s
== "Center")
888 resource
.mstyle
.t_justify
= CenterJustify
;
891 resource
.mstyle
.f_justify
= LeftJustify
;
892 if (style
.getValue("menu.frame.justify", s
)) {
893 if (s
== "right" || s
== "Right")
894 resource
.mstyle
.f_justify
= RightJustify
;
895 else if (s
== "center" || s
== "Center")
896 resource
.mstyle
.f_justify
= CenterJustify
;
899 resource
.mstyle
.bullet
= Basemenu::Triangle
;
900 if (style
.getValue("menu.bullet", s
)) {
901 if (s
== "empty" || s
== "Empty")
902 resource
.mstyle
.bullet
= Basemenu::Empty
;
903 else if (s
== "square" || s
== "Square")
904 resource
.mstyle
.bullet
= Basemenu::Square
;
905 else if (s
== "diamond" || s
== "Diamond")
906 resource
.mstyle
.bullet
= Basemenu::Diamond
;
909 resource
.mstyle
.bullet_pos
= Basemenu::Left
;
910 if (style
.getValue("menu.bullet.position", s
)) {
911 if (s
== "right" || s
== "Right")
912 resource
.mstyle
.bullet_pos
= Basemenu::Right
;
915 resource
.border_color
=
916 readDatabaseColor("borderColor", "black", style
);
918 // load bevel, border and handle widths
919 if (! style
.getValue("handleWidth", resource
.handle_width
) ||
920 resource
.handle_width
> (getWidth() / 2) || resource
.handle_width
== 0)
921 resource
.handle_width
= 6;
923 if (! style
.getValue("borderWidth", resource
.border_width
))
924 resource
.border_width
= 1;
926 if (! style
.getValue("bevelWidth", resource
.bevel_width
) ||
927 resource
.bevel_width
> (getWidth() / 2) || resource
.bevel_width
== 0)
928 resource
.bevel_width
= 3;
930 if (! style
.getValue("frameWidth", resource
.frame_width
) ||
931 resource
.frame_width
> (getWidth() / 2))
932 resource
.frame_width
= resource
.bevel_width
;
934 if (style
.getValue("rootCommand", s
))
935 bexec(s
, displayString());
939 void BScreen::addIcon(BlackboxWindow
*w
) {
942 w
->setWorkspace(BSENTINEL
);
943 w
->setWindowNumber(iconList
.size());
945 iconList
.push_back(w
);
947 const char* title
= w
->getIconTitle();
948 iconmenu
->insert(title
);
953 void BScreen::removeIcon(BlackboxWindow
*w
) {
958 iconmenu
->remove(w
->getWindowNumber());
961 BlackboxWindowList::iterator it
= iconList
.begin(),
962 end
= iconList
.end();
963 for (int i
= 0; it
!= end
; ++it
)
964 (*it
)->setWindowNumber(i
++);
968 BlackboxWindow
*BScreen::getIcon(unsigned int index
) {
969 if (index
< iconList
.size()) {
970 BlackboxWindowList::iterator it
= iconList
.begin();
971 for (; index
> 0; --index
, ++it
) ; /* increment to index */
975 return (BlackboxWindow
*) 0;
979 unsigned int BScreen::addWorkspace(void) {
980 Workspace
*wkspc
= new Workspace(this, workspacesList
.size());
981 workspacesList
.push_back(wkspc
);
982 saveWorkspaces(getWorkspaceCount());
984 workspacemenu
->insert(wkspc
->getName(), wkspc
->getMenu(),
986 workspacemenu
->update();
988 toolbar
->reconfigure();
990 updateNetizenWorkspaceCount();
992 return workspacesList
.size();
996 unsigned int BScreen::removeLastWorkspace(void) {
997 if (workspacesList
.size() == 1)
1000 Workspace
*wkspc
= workspacesList
.back();
1002 if (current_workspace
->getID() == wkspc
->getID())
1003 changeWorkspaceID(current_workspace
->getID() - 1);
1007 workspacemenu
->remove(wkspc
->getID() + 2);
1008 workspacemenu
->update();
1010 workspacesList
.pop_back();
1013 saveWorkspaces(getWorkspaceCount());
1015 toolbar
->reconfigure();
1017 updateNetizenWorkspaceCount();
1019 return workspacesList
.size();
1023 void BScreen::changeWorkspaceID(unsigned int id
) {
1024 if (! current_workspace
|| id
== current_workspace
->getID()) return;
1026 BlackboxWindow
*focused
= blackbox
->getFocusedWindow();
1027 if (focused
&& focused
->getScreen() == this) {
1028 assert(focused
->isStuck() ||
1029 focused
->getWorkspaceNumber() == current_workspace
->getID());
1031 current_workspace
->setLastFocusedWindow(focused
);
1033 // if no window had focus, no need to store a last focus
1034 current_workspace
->setLastFocusedWindow((BlackboxWindow
*) 0);
1037 // when we switch workspaces, unfocus whatever was focused
1038 blackbox
->setFocusedWindow((BlackboxWindow
*) 0);
1040 current_workspace
->hideAll();
1041 workspacemenu
->setItemSelected(current_workspace
->getID() + 2, False
);
1043 current_workspace
= getWorkspace(id
);
1045 xatom
->setValue(getRootWindow(), XAtom::net_current_desktop
,
1046 XAtom::cardinal
, id
);
1048 workspacemenu
->setItemSelected(current_workspace
->getID() + 2, True
);
1049 toolbar
->redrawWorkspaceLabel(True
);
1051 current_workspace
->showAll();
1053 if (resource
.focus_last
&& current_workspace
->getLastFocusedWindow()) {
1054 XSync(blackbox
->getXDisplay(), False
);
1055 current_workspace
->getLastFocusedWindow()->setInputFocus();
1058 updateNetizenCurrentWorkspace();
1063 * Set the _NET_CLIENT_LIST root window property.
1065 void BScreen::updateClientList(void) {
1066 if (windowList
.size() > 0) {
1067 Window
*windows
= new Window
[windowList
.size()];
1068 Window
*win_it
= windows
;
1069 BlackboxWindowList::iterator it
= windowList
.begin();
1070 const BlackboxWindowList::iterator end
= windowList
.end();
1071 for (; it
!= end
; ++it
, ++win_it
)
1072 *win_it
= (*it
)->getClientWindow();
1073 xatom
->setValue(getRootWindow(), XAtom::net_client_list
, XAtom::window
,
1074 windows
, windowList
.size());
1077 xatom
->setValue(getRootWindow(), XAtom::net_client_list
, XAtom::window
,
1080 updateStackingList();
1085 * Set the _NET_CLIENT_LIST_STACKING root window property.
1087 void BScreen::updateStackingList(void) {
1089 BlackboxWindowList stack_order
;
1092 * Get the stacking order from all of the workspaces.
1093 * We start with the current workspace so that the sticky windows will be
1094 * in the right order on the current workspace.
1095 * XXX: Do we need to have sticky windows in the list once for each workspace?
1097 getCurrentWorkspace()->appendStackOrder(stack_order
);
1098 for (unsigned int i
= 0; i
< getWorkspaceCount(); ++i
)
1099 if (i
!= getCurrentWorkspaceID())
1100 getWorkspace(i
)->appendStackOrder(stack_order
);
1102 if (stack_order
.size() > 0) {
1103 // set the client list atoms
1104 Window
*windows
= new Window
[stack_order
.size()];
1105 Window
*win_it
= windows
;
1106 BlackboxWindowList::iterator it
= stack_order
.begin(),
1107 end
= stack_order
.end();
1108 for (; it
!= end
; ++it
, ++win_it
)
1109 *win_it
= (*it
)->getClientWindow();
1110 xatom
->setValue(getRootWindow(), XAtom::net_client_list_stacking
,
1111 XAtom::window
, windows
, stack_order
.size());
1114 xatom
->setValue(getRootWindow(), XAtom::net_client_list_stacking
,
1115 XAtom::window
, 0, 0);
1119 void BScreen::addSystrayWindow(Window window
) {
1120 systrayWindowList
.push_back(window
);
1121 xatom
->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows
,
1123 &systrayWindowList
[0], systrayWindowList
.size());
1124 blackbox
->saveSystrayWindowSearch(window
, this);
1128 void BScreen::removeSystrayWindow(Window window
) {
1129 WindowList::iterator it
= systrayWindowList
.begin();
1130 const WindowList::iterator end
= systrayWindowList
.end();
1131 for (; it
!= end
; ++it
)
1132 if (*it
== window
) {
1133 systrayWindowList
.erase(it
);
1134 xatom
->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows
,
1136 &systrayWindowList
[0], systrayWindowList
.size());
1137 blackbox
->removeSystrayWindowSearch(window
);
1143 void BScreen::addDesktopWindow(Window window
) {
1144 desktopWindowList
.push_back(window
);
1145 XLowerWindow(blackbox
->getXDisplay(), window
);
1146 XSelectInput(blackbox
->getXDisplay(), window
, StructureNotifyMask
);
1147 blackbox
->saveDesktopWindowSearch(window
, this);
1151 void BScreen::removeDesktopWindow(Window window
) {
1152 WindowList::iterator it
= desktopWindowList
.begin();
1153 const WindowList::iterator end
= desktopWindowList
.end();
1154 for (; it
!= end
; ++it
)
1155 if (*it
== window
) {
1156 desktopWindowList
.erase(it
);
1157 XSelectInput(blackbox
->getXDisplay(), window
, None
);
1158 blackbox
->removeDesktopWindowSearch(window
);
1164 void BScreen::manageWindow(Window w
) {
1165 new BlackboxWindow(blackbox
, w
, this);
1167 BlackboxWindow
*win
= blackbox
->searchWindow(w
);
1170 if (win
->isDesktop()) {
1171 // desktop windows cant do anything, so we remove all the normal window
1172 // stuff from them, they are only kept around so that we can keep them on
1173 // the bottom of the z-order
1175 addDesktopWindow(win
->getClientWindow());
1180 windowList
.push_back(win
);
1183 XMapRequestEvent mre
;
1185 if (blackbox
->isStartup()) win
->restoreAttributes();
1186 win
->mapRequestEvent(&mre
);
1190 void BScreen::unmanageWindow(BlackboxWindow
*w
, bool remap
) {
1193 if (w
->getWorkspaceNumber() != BSENTINEL
&&
1194 w
->getWindowNumber() != BSENTINEL
)
1195 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
1196 else if (w
->isIconic())
1199 windowList
.remove(w
);
1202 if (blackbox
->getFocusedWindow() == w
)
1203 blackbox
->setFocusedWindow((BlackboxWindow
*) 0);
1205 removeNetizen(w
->getClientWindow());
1208 some managed windows can also be window group controllers. when
1209 unmanaging such windows, we should also delete the window group.
1211 BWindowGroup
*group
= blackbox
->searchGroup(w
->getClientWindow());
1218 void BScreen::addNetizen(Netizen
*n
) {
1219 netizenList
.push_back(n
);
1221 n
->sendWorkspaceCount();
1222 n
->sendCurrentWorkspace();
1224 WorkspaceList::iterator it
= workspacesList
.begin();
1225 const WorkspaceList::iterator end
= workspacesList
.end();
1226 for (; it
!= end
; ++it
)
1227 (*it
)->sendWindowList(*n
);
1229 Window f
= ((blackbox
->getFocusedWindow()) ?
1230 blackbox
->getFocusedWindow()->getClientWindow() : None
);
1231 n
->sendWindowFocus(f
);
1235 void BScreen::removeNetizen(Window w
) {
1236 NetizenList::iterator it
= netizenList
.begin();
1237 for (; it
!= netizenList
.end(); ++it
) {
1238 if ((*it
)->getWindowID() == w
) {
1240 netizenList
.erase(it
);
1247 void BScreen::updateWorkArea(void) {
1248 if (workspacesList
.size() > 0) {
1249 unsigned long *dims
= new unsigned long[4 * workspacesList
.size()];
1250 for (unsigned int i
= 0, m
= workspacesList
.size(); i
< m
; ++i
) {
1251 // XXX: this could be different for each workspace
1252 const Rect
&area
= availableArea();
1253 dims
[(i
* 4) + 0] = area
.x();
1254 dims
[(i
* 4) + 1] = area
.y();
1255 dims
[(i
* 4) + 2] = area
.width();
1256 dims
[(i
* 4) + 3] = area
.height();
1258 xatom
->setValue(getRootWindow(), XAtom::net_workarea
, XAtom::cardinal
,
1259 dims
, 4 * workspacesList
.size());
1262 xatom
->setValue(getRootWindow(), XAtom::net_workarea
, XAtom::cardinal
,
1267 void BScreen::updateNetizenCurrentWorkspace(void) {
1268 std::for_each(netizenList
.begin(), netizenList
.end(),
1269 std::mem_fun(&Netizen::sendCurrentWorkspace
));
1273 void BScreen::updateNetizenWorkspaceCount(void) {
1274 xatom
->setValue(getRootWindow(), XAtom::net_number_of_desktops
,
1275 XAtom::cardinal
, workspacesList
.size());
1279 std::for_each(netizenList
.begin(), netizenList
.end(),
1280 std::mem_fun(&Netizen::sendWorkspaceCount
));
1284 void BScreen::updateNetizenWindowFocus(void) {
1285 Window f
= ((blackbox
->getFocusedWindow()) ?
1286 blackbox
->getFocusedWindow()->getClientWindow() : None
);
1288 xatom
->setValue(getRootWindow(), XAtom::net_active_window
,
1291 NetizenList::iterator it
= netizenList
.begin();
1292 for (; it
!= netizenList
.end(); ++it
)
1293 (*it
)->sendWindowFocus(f
);
1297 void BScreen::updateNetizenWindowAdd(Window w
, unsigned long p
) {
1298 NetizenList::iterator it
= netizenList
.begin();
1299 for (; it
!= netizenList
.end(); ++it
) {
1300 (*it
)->sendWindowAdd(w
, p
);
1305 void BScreen::updateNetizenWindowDel(Window w
) {
1306 NetizenList::iterator it
= netizenList
.begin();
1307 for (; it
!= netizenList
.end(); ++it
)
1308 (*it
)->sendWindowDel(w
);
1312 void BScreen::updateNetizenWindowRaise(Window w
) {
1313 NetizenList::iterator it
= netizenList
.begin();
1314 for (; it
!= netizenList
.end(); ++it
)
1315 (*it
)->sendWindowRaise(w
);
1319 void BScreen::updateNetizenWindowLower(Window w
) {
1320 NetizenList::iterator it
= netizenList
.begin();
1321 for (; it
!= netizenList
.end(); ++it
)
1322 (*it
)->sendWindowLower(w
);
1326 void BScreen::updateNetizenConfigNotify(XEvent
*e
) {
1327 NetizenList::iterator it
= netizenList
.begin();
1328 for (; it
!= netizenList
.end(); ++it
)
1329 (*it
)->sendConfigNotify(e
);
1333 void BScreen::raiseWindows(Window
*workspace_stack
, unsigned int num
) {
1334 // the 13 represents the number of blackbox windows such as menus
1335 Window
*session_stack
= new
1336 Window
[(num
+ workspacesList
.size() + rootmenuList
.size() + 13)];
1337 unsigned int i
= 0, k
= num
;
1339 XRaiseWindow(blackbox
->getXDisplay(), iconmenu
->getWindowID());
1340 *(session_stack
+ i
++) = iconmenu
->getWindowID();
1342 WorkspaceList::iterator wit
= workspacesList
.begin();
1343 const WorkspaceList::iterator w_end
= workspacesList
.end();
1344 for (; wit
!= w_end
; ++wit
)
1345 *(session_stack
+ i
++) = (*wit
)->getMenu()->getWindowID();
1347 *(session_stack
+ i
++) = workspacemenu
->getWindowID();
1349 *(session_stack
+ i
++) = configmenu
->getFocusmenu()->getWindowID();
1350 *(session_stack
+ i
++) = configmenu
->getPlacementmenu()->getWindowID();
1351 *(session_stack
+ i
++) = configmenu
->getWindowID();
1353 *(session_stack
+ i
++) = slit
->getMenu()->getDirectionmenu()->getWindowID();
1354 *(session_stack
+ i
++) = slit
->getMenu()->getPlacementmenu()->getWindowID();
1355 *(session_stack
+ i
++) = slit
->getMenu()->getWindowID();
1357 *(session_stack
+ i
++) =
1358 toolbar
->getMenu()->getPlacementmenu()->getWindowID();
1359 *(session_stack
+ i
++) = toolbar
->getMenu()->getWindowID();
1361 RootmenuList::iterator rit
= rootmenuList
.begin();
1362 for (; rit
!= rootmenuList
.end(); ++rit
)
1363 *(session_stack
+ i
++) = (*rit
)->getWindowID();
1364 *(session_stack
+ i
++) = rootmenu
->getWindowID();
1366 if (toolbar
->isOnTop())
1367 *(session_stack
+ i
++) = toolbar
->getWindowID();
1369 if (slit
->isOnTop())
1370 *(session_stack
+ i
++) = slit
->getWindowID();
1373 *(session_stack
+ i
++) = *(workspace_stack
+ k
);
1375 XRestackWindows(blackbox
->getXDisplay(), session_stack
, i
);
1377 delete [] session_stack
;
1379 updateStackingList();
1383 void BScreen::lowerDesktops(void) {
1384 if (desktopWindowList
.empty()) return;
1386 XLowerWindow(blackbox
->getXDisplay(), desktopWindowList
[0]);
1387 if (desktopWindowList
.size() > 1)
1388 XRestackWindows(blackbox
->getXDisplay(), &desktopWindowList
[0],
1389 desktopWindowList
.size());
1393 void BScreen::reassociateWindow(BlackboxWindow
*w
, unsigned int wkspc_id
,
1394 bool ignore_sticky
) {
1397 if (wkspc_id
== BSENTINEL
)
1398 wkspc_id
= current_workspace
->getID();
1400 if (w
->getWorkspaceNumber() == wkspc_id
)
1403 if (w
->isIconic()) {
1405 getWorkspace(wkspc_id
)->addWindow(w
);
1406 } else if (ignore_sticky
|| ! w
->isStuck()) {
1407 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
1408 getWorkspace(wkspc_id
)->addWindow(w
);
1410 updateStackingList();
1414 void BScreen::propagateWindowName(const BlackboxWindow
*bw
) {
1415 if (bw
->isIconic()) {
1416 iconmenu
->changeItemLabel(bw
->getWindowNumber(), bw
->getIconTitle());
1420 Clientmenu
*clientmenu
= getWorkspace(bw
->getWorkspaceNumber())->getMenu();
1421 clientmenu
->changeItemLabel(bw
->getWindowNumber(), bw
->getTitle());
1422 clientmenu
->update();
1424 if (blackbox
->getFocusedWindow() == bw
)
1425 toolbar
->redrawWindowLabel(True
);
1430 void BScreen::nextFocus(void) {
1431 BlackboxWindow
*focused
= blackbox
->getFocusedWindow(),
1435 // if window is not on this screen, ignore it
1436 if (focused
->getScreen()->getScreenNumber() != getScreenNumber())
1437 focused
= (BlackboxWindow
*) 0;
1440 if (focused
&& current_workspace
->getCount() > 1) {
1441 // next is the next window to recieve focus, current is a place holder
1442 BlackboxWindow
*current
;
1445 next
= current_workspace
->getNextWindowInList(current
);
1446 } while(! next
->setInputFocus() && next
!= focused
);
1448 if (next
!= focused
)
1449 current_workspace
->raiseWindow(next
);
1450 } else if (current_workspace
->getCount() >= 1) {
1451 next
= current_workspace
->getTopWindowOnStack();
1453 current_workspace
->raiseWindow(next
);
1454 next
->setInputFocus();
1459 void BScreen::prevFocus(void) {
1460 BlackboxWindow
*focused
= blackbox
->getFocusedWindow(),
1464 // if window is not on this screen, ignore it
1465 if (focused
->getScreen()->getScreenNumber() != getScreenNumber())
1466 focused
= (BlackboxWindow
*) 0;
1469 if (focused
&& current_workspace
->getCount() > 1) {
1470 // next is the next window to recieve focus, current is a place holder
1471 BlackboxWindow
*current
;
1474 next
= current_workspace
->getPrevWindowInList(current
);
1475 } while(! next
->setInputFocus() && next
!= focused
);
1477 if (next
!= focused
)
1478 current_workspace
->raiseWindow(next
);
1479 } else if (current_workspace
->getCount() >= 1) {
1480 next
= current_workspace
->getTopWindowOnStack();
1482 current_workspace
->raiseWindow(next
);
1483 next
->setInputFocus();
1488 void BScreen::raiseFocus(void) {
1489 BlackboxWindow
*focused
= blackbox
->getFocusedWindow();
1493 // if on this Screen, raise it
1494 if (focused
->getScreen()->getScreenNumber() == getScreenNumber()) {
1495 Workspace
*workspace
= getWorkspace(focused
->getWorkspaceNumber());
1496 workspace
->raiseWindow(focused
);
1501 void BScreen::InitMenu(void) {
1503 rootmenuList
.clear();
1505 while (rootmenu
->getCount())
1506 rootmenu
->remove(0);
1508 rootmenu
= new Rootmenu(this);
1510 bool defaultMenu
= True
;
1512 FILE *menu_file
= (FILE *) 0;
1513 const char *menu_filename
= blackbox
->getMenuFilename();
1516 if (! (menu_file
= fopen(menu_filename
, "r")))
1517 perror(menu_filename
);
1518 if (! menu_file
) { // opening the menu file failed, try the default menu
1519 menu_filename
= DEFAULTMENU
;
1520 if (! (menu_file
= fopen(menu_filename
, "r")))
1521 perror(menu_filename
);
1525 if (feof(menu_file
)) {
1526 fprintf(stderr
, i18n(ScreenSet
, ScreenEmptyMenuFile
,
1527 "%s: Empty menu file"),
1530 char line
[1024], label
[1024];
1531 memset(line
, 0, 1024);
1532 memset(label
, 0, 1024);
1534 while (fgets(line
, 1024, menu_file
) && ! feof(menu_file
)) {
1535 if (line
[0] != '#') {
1536 int i
, key
= 0, index
= -1, len
= strlen(line
);
1538 for (i
= 0; i
< len
; i
++) {
1539 if (line
[i
] == '[') index
= 0;
1540 else if (line
[i
] == ']') break;
1541 else if (line
[i
] != ' ')
1543 key
+= tolower(line
[i
]);
1546 if (key
== 517) { // [begin]
1548 for (i
= index
; i
< len
; i
++) {
1549 if (line
[i
] == '(') index
= 0;
1550 else if (line
[i
] == ')') break;
1551 else if (index
++ >= 0) {
1552 if (line
[i
] == '\\' && i
< len
- 1) i
++;
1553 label
[index
- 1] = line
[i
];
1557 if (index
== -1) index
= 0;
1558 label
[index
] = '\0';
1560 rootmenu
->setLabel(label
);
1561 defaultMenu
= parseMenuFile(menu_file
, rootmenu
);
1563 blackbox
->addMenuTimestamp(menu_filename
);
1573 rootmenu
->setInternalMenu();
1574 rootmenu
->insert(i18n(ScreenSet
, Screenxterm
, "xterm"),
1576 i18n(ScreenSet
, Screenxterm
, "xterm"));
1577 rootmenu
->insert(i18n(ScreenSet
, ScreenRestart
, "Restart"),
1579 rootmenu
->insert(i18n(ScreenSet
, ScreenExit
, "Exit"),
1581 rootmenu
->setLabel(i18n(BasemenuSet
, BasemenuBlackboxMenu
,
1587 bool BScreen::parseMenuFile(FILE *file
, Rootmenu
*menu
) {
1588 char line
[1024], label
[1024], command
[1024];
1590 while (! feof(file
)) {
1591 memset(line
, 0, 1024);
1592 memset(label
, 0, 1024);
1593 memset(command
, 0, 1024);
1595 if (fgets(line
, 1024, file
)) {
1596 if (line
[0] != '#') {
1597 int i
, key
= 0, parse
= 0, index
= -1, line_length
= strlen(line
);
1599 // determine the keyword
1600 for (i
= 0; i
< line_length
; i
++) {
1601 if (line
[i
] == '[') parse
= 1;
1602 else if (line
[i
] == ']') break;
1603 else if (line
[i
] != ' ')
1605 key
+= tolower(line
[i
]);
1608 // get the label enclosed in ()'s
1611 for (i
= 0; i
< line_length
; i
++) {
1612 if (line
[i
] == '(') {
1615 } else if (line
[i
] == ')') break;
1616 else if (index
++ >= 0) {
1617 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
1618 label
[index
- 1] = line
[i
];
1623 label
[index
] = '\0';
1628 // get the command enclosed in {}'s
1631 for (i
= 0; i
< line_length
; i
++) {
1632 if (line
[i
] == '{') {
1635 } else if (line
[i
] == '}') break;
1636 else if (index
++ >= 0) {
1637 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
1638 command
[index
- 1] = line
[i
];
1643 command
[index
] = '\0';
1650 return ((menu
->getCount() == 0) ? True
: False
);
1657 menu
->insert(label
);
1662 if ((! *label
) && (! *command
)) {
1663 fprintf(stderr
, i18n(ScreenSet
, ScreenEXECError
,
1664 "BScreen::parseMenuFile: [exec] error, "
1665 "no menu label and/or command defined\n"));
1669 menu
->insert(label
, BScreen::Execute
, command
);
1675 fprintf(stderr
, i18n(ScreenSet
, ScreenEXITError
,
1676 "BScreen::parseMenuFile: [exit] error, "
1677 "no menu label defined\n"));
1681 menu
->insert(label
, BScreen::Exit
);
1687 if ((! *label
) || (! *command
)) {
1689 i18n(ScreenSet
, ScreenSTYLEError
,
1690 "BScreen::parseMenuFile: [style] error, "
1691 "no menu label and/or filename defined\n"));
1695 string style
= expandTilde(command
);
1697 menu
->insert(label
, BScreen::SetStyle
, style
.c_str());
1704 fprintf(stderr
, i18n(ScreenSet
, ScreenCONFIGError
,
1705 "BScreen::parseMenufile: [config] error, "
1706 "no label defined"));
1710 menu
->insert(label
, configmenu
);
1714 case 740: // include
1717 fprintf(stderr
, i18n(ScreenSet
, ScreenINCLUDEError
,
1718 "BScreen::parseMenuFile: [include] error, "
1719 "no filename defined\n"));
1723 string newfile
= expandTilde(label
);
1724 FILE *submenufile
= fopen(newfile
.c_str(), "r");
1728 if (fstat(fileno(submenufile
), &buf
) ||
1729 (! S_ISREG(buf
.st_mode
))) {
1731 i18n(ScreenSet
, ScreenINCLUDEErrorReg
,
1732 "BScreen::parseMenuFile: [include] error: "
1733 "'%s' is not a regular file\n"), newfile
.c_str());
1737 if (! feof(submenufile
)) {
1738 if (! parseMenuFile(submenufile
, menu
))
1739 blackbox
->addMenuTimestamp(newfile
);
1741 fclose(submenufile
);
1744 perror(newfile
.c_str());
1750 case 767: // submenu
1753 fprintf(stderr
, i18n(ScreenSet
, ScreenSUBMENUError
,
1754 "BScreen::parseMenuFile: [submenu] error, "
1755 "no menu label defined\n"));
1759 Rootmenu
*submenu
= new Rootmenu(this);
1762 submenu
->setLabel(command
);
1764 submenu
->setLabel(label
);
1766 parseMenuFile(file
, submenu
);
1768 menu
->insert(label
, submenu
);
1769 rootmenuList
.push_back(submenu
);
1774 case 773: // restart
1777 fprintf(stderr
, i18n(ScreenSet
, ScreenRESTARTError
,
1778 "BScreen::parseMenuFile: [restart] error, "
1779 "no menu label defined\n"));
1784 menu
->insert(label
, BScreen::RestartOther
, command
);
1786 menu
->insert(label
, BScreen::Restart
);
1791 case 845: // reconfig
1795 i18n(ScreenSet
, ScreenRECONFIGError
,
1796 "BScreen::parseMenuFile: [reconfig] error, "
1797 "no menu label defined\n"));
1801 menu
->insert(label
, BScreen::Reconfigure
);
1806 case 995: // stylesdir
1807 case 1113: // stylesmenu
1809 bool newmenu
= ((key
== 1113) ? True
: False
);
1811 if ((! *label
) || ((! *command
) && newmenu
)) {
1813 i18n(ScreenSet
, ScreenSTYLESDIRError
,
1814 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1815 " error, no directory defined\n"));
1819 char *directory
= ((newmenu
) ? command
: label
);
1821 string stylesdir
= expandTilde(directory
);
1823 struct stat statbuf
;
1825 if (! stat(stylesdir
.c_str(), &statbuf
)) {
1826 if (S_ISDIR(statbuf
.st_mode
)) {
1827 Rootmenu
*stylesmenu
;
1830 stylesmenu
= new Rootmenu(this);
1834 DIR *d
= opendir(stylesdir
.c_str());
1836 std::vector
<string
> ls
;
1838 while((p
= readdir(d
)))
1839 ls
.push_back(p
->d_name
);
1843 std::sort(ls
.begin(), ls
.end());
1845 std::vector
<string
>::iterator it
= ls
.begin(),
1847 for (; it
!= end
; ++it
) {
1848 const string
& fname
= *it
;
1850 if (fname
[fname
.size()-1] == '~')
1853 string style
= stylesdir
;
1857 if ((! stat(style
.c_str(), &statbuf
)) &&
1858 S_ISREG(statbuf
.st_mode
))
1859 stylesmenu
->insert(fname
, BScreen::SetStyle
, style
);
1862 stylesmenu
->update();
1865 stylesmenu
->setLabel(label
);
1866 menu
->insert(label
, stylesmenu
);
1867 rootmenuList
.push_back(stylesmenu
);
1870 blackbox
->addMenuTimestamp(stylesdir
);
1873 i18n(ScreenSet
, ScreenSTYLESDIRErrorNotDir
,
1874 "BScreen::parseMenuFile:"
1875 " [stylesdir/stylesmenu] error, %s is not a"
1876 " directory\n"), stylesdir
.c_str());
1880 i18n(ScreenSet
, ScreenSTYLESDIRErrorNoExist
,
1881 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1882 " error, %s does not exist\n"), stylesdir
.c_str());
1887 case 1090: // workspaces
1891 i18n(ScreenSet
, ScreenWORKSPACESError
,
1892 "BScreen:parseMenuFile: [workspaces] error, "
1893 "no menu label defined\n"));
1897 menu
->insert(label
, workspacemenu
);
1906 return ((menu
->getCount() == 0) ? True
: False
);
1910 void BScreen::shutdown(void) {
1911 XSelectInput(blackbox
->getXDisplay(), getRootWindow(), NoEventMask
);
1912 XSync(blackbox
->getXDisplay(), False
);
1914 while(! windowList
.empty())
1915 unmanageWindow(windowList
.front(), True
);
1921 void BScreen::showPosition(int x
, int y
) {
1922 if (! geom_visible
) {
1923 XMoveResizeWindow(blackbox
->getXDisplay(), geom_window
,
1924 (getWidth() - geom_w
) / 2,
1925 (getHeight() - geom_h
) / 2, geom_w
, geom_h
);
1926 XMapWindow(blackbox
->getXDisplay(), geom_window
);
1927 XRaiseWindow(blackbox
->getXDisplay(), geom_window
);
1929 geom_visible
= True
;
1934 sprintf(label
, i18n(ScreenSet
, ScreenPositionFormat
,
1935 "X: %4d x Y: %4d"), x
, y
);
1937 XClearWindow(blackbox
->getXDisplay(), geom_window
);
1939 resource
.wstyle
.font
->drawString(geom_window
,
1940 resource
.bevel_width
, resource
.bevel_width
,
1941 resource
.wstyle
.l_text_focus
,
1946 void BScreen::showGeometry(unsigned int gx
, unsigned int gy
) {
1947 if (! geom_visible
) {
1948 XMoveResizeWindow(blackbox
->getXDisplay(), geom_window
,
1949 (getWidth() - geom_w
) / 2,
1950 (getHeight() - geom_h
) / 2, geom_w
, geom_h
);
1951 XMapWindow(blackbox
->getXDisplay(), geom_window
);
1952 XRaiseWindow(blackbox
->getXDisplay(), geom_window
);
1954 geom_visible
= True
;
1959 sprintf(label
, i18n(ScreenSet
, ScreenGeometryFormat
,
1960 "W: %4d x H: %4d"), gx
, gy
);
1962 XClearWindow(blackbox
->getXDisplay(), geom_window
);
1964 resource
.wstyle
.font
->drawString(geom_window
,
1965 resource
.bevel_width
, resource
.bevel_width
,
1966 resource
.wstyle
.l_text_focus
,
1971 void BScreen::hideGeometry(void) {
1973 XUnmapWindow(blackbox
->getXDisplay(), geom_window
);
1974 geom_visible
= False
;
1979 void BScreen::addStrut(Strut
*strut
) {
1980 strutList
.push_back(strut
);
1984 void BScreen::removeStrut(Strut
*strut
) {
1985 strutList
.remove(strut
);
1989 const Rect
& BScreen::availableArea(void) const {
1991 return getRect(); // return the full screen
1996 void BScreen::updateAvailableArea(void) {
1997 Rect old_area
= usableArea
;
1998 usableArea
= getRect(); // reset to full screen
2000 /* these values represent offsets from the screen edge
2001 * we look for the biggest offset on each edge and then apply them
2003 * do not be confused by the similarity to the names of Rect's members
2005 unsigned int current_left
= 0, current_right
= 0, current_top
= 0,
2008 StrutList::const_iterator it
= strutList
.begin(), end
= strutList
.end();
2010 for(; it
!= end
; ++it
) {
2012 if (strut
->left
> current_left
)
2013 current_left
= strut
->left
;
2014 if (strut
->top
> current_top
)
2015 current_top
= strut
->top
;
2016 if (strut
->right
> current_right
)
2017 current_right
= strut
->right
;
2018 if (strut
->bottom
> current_bottom
)
2019 current_bottom
= strut
->bottom
;
2022 usableArea
.setPos(current_left
, current_top
);
2023 usableArea
.setSize(usableArea
.width() - (current_left
+ current_right
),
2024 usableArea
.height() - (current_top
+ current_bottom
));
2026 if (old_area
!= usableArea
) {
2027 BlackboxWindowList::iterator it
= windowList
.begin(),
2028 end
= windowList
.end();
2029 for (; it
!= end
; ++it
)
2030 if ((*it
)->isMaximized()) (*it
)->remaximize();
2037 Workspace
* BScreen::getWorkspace(unsigned int index
) {
2038 assert(index
< workspacesList
.size());
2039 return workspacesList
[index
];
2043 void BScreen::buttonPressEvent(const XButtonEvent
*xbutton
) {
2044 if (xbutton
->button
== 1) {
2045 if (! isRootColormapInstalled())
2046 image_control
->installRootColormap();
2048 if (workspacemenu
->isVisible())
2049 workspacemenu
->hide();
2051 if (rootmenu
->isVisible())
2053 } else if (xbutton
->button
== 2) {
2054 int mx
= xbutton
->x_root
- (workspacemenu
->getWidth() / 2);
2055 int my
= xbutton
->y_root
- (workspacemenu
->getTitleHeight() / 2);
2060 if (mx
+ workspacemenu
->getWidth() > getWidth())
2061 mx
= getWidth() - workspacemenu
->getWidth() - getBorderWidth();
2063 if (my
+ workspacemenu
->getHeight() > getHeight())
2064 my
= getHeight() - workspacemenu
->getHeight() - getBorderWidth();
2066 workspacemenu
->move(mx
, my
);
2068 if (! workspacemenu
->isVisible()) {
2069 workspacemenu
->removeParent();
2070 workspacemenu
->show();
2072 } else if (xbutton
->button
== 3) {
2073 int mx
= xbutton
->x_root
- (rootmenu
->getWidth() / 2);
2074 int my
= xbutton
->y_root
- (rootmenu
->getTitleHeight() / 2);
2079 if (mx
+ rootmenu
->getWidth() > getWidth())
2080 mx
= getWidth() - rootmenu
->getWidth() - getBorderWidth();
2082 if (my
+ rootmenu
->getHeight() > getHeight())
2083 my
= getHeight() - rootmenu
->getHeight() - getBorderWidth();
2085 rootmenu
->move(mx
, my
);
2087 if (! rootmenu
->isVisible()) {
2088 blackbox
->checkMenu();
2092 } else if (xbutton
->button
== 4) {
2093 if (getCurrentWorkspaceID() >= getWorkspaceCount() - 1)
2094 changeWorkspaceID(0);
2096 changeWorkspaceID(getCurrentWorkspaceID() + 1);
2098 } else if (xbutton
->button
== 5) {
2099 if (getCurrentWorkspaceID() == 0)
2100 changeWorkspaceID(getWorkspaceCount() - 1);
2102 changeWorkspaceID(getCurrentWorkspaceID() - 1);
2107 void BScreen::toggleFocusModel(FocusModel model
) {
2108 std::for_each(windowList
.begin(), windowList
.end(),
2109 std::mem_fun(&BlackboxWindow::ungrabButtons
));
2111 if (model
== SloppyFocus
) {
2112 saveSloppyFocus(True
);
2114 // we're cheating here to save writing the config file 3 times
2115 resource
.auto_raise
= False
;
2116 resource
.click_raise
= False
;
2117 saveSloppyFocus(False
);
2120 std::for_each(windowList
.begin(), windowList
.end(),
2121 std::mem_fun(&BlackboxWindow::grabButtons
));
2125 BTexture
BScreen::readDatabaseTexture(const string
&rname
,
2126 const string
&default_color
,
2127 const Configuration
&style
) {
2131 if (style
.getValue(rname
, s
))
2132 texture
= BTexture(s
);
2134 texture
.setTexture(BTexture::Solid
| BTexture::Flat
);
2136 // associate this texture with this screen
2137 texture
.setDisplay(getBaseDisplay(), getScreenNumber());
2138 texture
.setImageControl(image_control
);
2140 if (texture
.texture() & BTexture::Solid
) {
2141 texture
.setColor(readDatabaseColor(rname
+ ".color",
2142 default_color
, style
));
2143 texture
.setColorTo(readDatabaseColor(rname
+ ".colorTo",
2144 default_color
, style
));
2145 } else if (texture
.texture() & BTexture::Gradient
) {
2146 texture
.setColor(readDatabaseColor(rname
+ ".color",
2147 default_color
, style
));
2148 texture
.setColorTo(readDatabaseColor(rname
+ ".colorTo",
2149 default_color
, style
));
2156 BColor
BScreen::readDatabaseColor(const string
&rname
,
2157 const string
&default_color
,
2158 const Configuration
&style
) {
2161 if (style
.getValue(rname
, s
))
2162 color
= BColor(s
, getBaseDisplay(), getScreenNumber());
2164 color
= BColor(default_color
, getBaseDisplay(), getScreenNumber());
2169 BFont
*BScreen::readDatabaseFont(const string
&rbasename
,
2170 const Configuration
&style
) {
2177 if (style
.getValue(rbasename
+ "xft.font", s
) &&
2178 style
.getValue(rbasename
+ "xft.size", i
)) {
2181 bool italic
= False
;
2182 if (style
.getValue(rbasename
+ "xft.flags", s
)) {
2183 if (s
.find("bold") != string::npos
)
2185 if (s
.find("italic") != string::npos
)
2189 BFont
*b
= new BFont(blackbox
->getXDisplay(), this, family
, i
, bold
,
2190 italic
, resource
.aa_fonts
);
2194 delete b
; // fall back to the normal X font stuff
2198 style
.getValue(rbasename
+ "font", s
);
2199 // if this fails, a blank string will be used, which will cause the fallback
2202 BFont
*b
= new BFont(blackbox
->getXDisplay(), this, s
);
2204 exit(2); // can't continue without a font