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 list, 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());
314 delete workspacemenu
;
319 delete image_control
;
321 if (resource
.wstyle
.font
)
322 delete resource
.wstyle
.font
;
323 if (resource
.mstyle
.t_font
)
324 delete resource
.mstyle
.t_font
;
325 if (resource
.mstyle
.f_font
)
326 delete resource
.mstyle
.f_font
;
327 if (resource
.tstyle
.font
)
328 delete resource
.tstyle
.font
;
330 XFreeGC(blackbox
->getXDisplay(), opGC
);
334 void BScreen::saveSloppyFocus(bool s
) {
335 resource
.sloppy_focus
= s
;
338 if (resource
.sloppy_focus
) {
339 fmodel
= "SloppyFocus";
340 if (resource
.auto_raise
) fmodel
+= " AutoRaise";
341 if (resource
.click_raise
) fmodel
+= " ClickRaise";
343 fmodel
= "ClickToFocus";
345 config
->setValue(screenstr
+ "focusModel", fmodel
);
349 void BScreen::saveAutoRaise(bool a
) {
350 resource
.auto_raise
= a
;
351 saveSloppyFocus(resource
.sloppy_focus
);
355 void BScreen::saveClickRaise(bool c
) {
356 resource
.click_raise
= c
;
357 saveSloppyFocus(resource
.sloppy_focus
);
361 void BScreen::saveImageDither(bool d
) {
362 image_control
->setDither(d
);
363 config
->setValue(screenstr
+ "imageDither", doImageDither());
367 void BScreen::saveOpaqueMove(bool o
) {
368 resource
.opaque_move
= o
;
369 config
->setValue(screenstr
+ "opaqueMove", resource
.opaque_move
);
373 void BScreen::saveFullMax(bool f
) {
374 resource
.full_max
= f
;
375 config
->setValue(screenstr
+ "fullMaximization", resource
.full_max
);
379 void BScreen::saveFocusNew(bool f
) {
380 resource
.focus_new
= f
;
381 config
->setValue(screenstr
+ "focusNewWindows", resource
.focus_new
);
385 void BScreen::saveFocusLast(bool f
) {
386 resource
.focus_last
= f
;
387 config
->setValue(screenstr
+ "focusLastWindow", resource
.focus_last
);
391 void BScreen::saveHideToolbar(bool h
) {
392 resource
.hide_toolbar
= h
;
393 if (resource
.hide_toolbar
)
394 toolbar
->unmapToolbar();
396 toolbar
->mapToolbar();
397 config
->setValue(screenstr
+ "hideToolbar", resource
.hide_toolbar
);
401 void BScreen::saveWindowToWindowSnap(bool s
) {
402 resource
.window_to_window_snap
= s
;
403 config
->setValue(screenstr
+ "windowToWindowSnap",
404 resource
.window_to_window_snap
);
408 void BScreen::saveWindowCornerSnap(bool s
) {
409 resource
.window_corner_snap
= s
;
410 config
->setValue(screenstr
+ "windowCornerSnap",
411 resource
.window_corner_snap
);
415 void BScreen::saveWorkspaces(unsigned int w
) {
416 resource
.workspaces
= w
;
417 config
->setValue(screenstr
+ "workspaces", resource
.workspaces
);
421 void BScreen::savePlacementPolicy(int p
) {
422 resource
.placement_policy
= p
;
423 const char *placement
;
424 switch (resource
.placement_policy
) {
425 case CascadePlacement
: placement
= "CascadePlacement"; break;
426 case ColSmartPlacement
: placement
= "ColSmartPlacement"; break;
427 case RowSmartPlacement
: default: placement
= "RowSmartPlacement"; break;
429 config
->setValue(screenstr
+ "windowPlacement", placement
);
433 void BScreen::saveEdgeSnapThreshold(int t
) {
434 resource
.edge_snap_threshold
= t
;
435 config
->setValue(screenstr
+ "edgeSnapThreshold",
436 resource
.edge_snap_threshold
);
440 void BScreen::saveRowPlacementDirection(int d
) {
441 resource
.row_direction
= d
;
442 config
->setValue(screenstr
+ "rowPlacementDirection",
443 resource
.row_direction
== LeftRight
?
444 "LeftToRight" : "RightToLeft");
448 void BScreen::saveColPlacementDirection(int d
) {
449 resource
.col_direction
= d
;
450 config
->setValue(screenstr
+ "colPlacementDirection",
451 resource
.col_direction
== TopBottom
?
452 "TopToBottom" : "BottomToTop");
457 void BScreen::saveStrftimeFormat(const std::string
& format
) {
458 resource
.strftime_format
= format
;
459 config
->setValue(screenstr
+ "strftimeFormat", resource
.strftime_format
);
462 #else // !HAVE_STRFTIME
464 void BScreen::saveDateFormat(int f
) {
465 resource
.date_format
= f
;
466 config
->setValue(screenstr
+ "dateFormat",
467 resource
.date_format
== B_EuropeanDate
?
468 "European" : "American");
472 void BScreen::saveClock24Hour(Bool c
) {
473 resource
.clock24hour
= c
;
474 config
->setValue(screenstr
+ "clockFormat", resource
.clock24hour
? 24 : 12);
476 #endif // HAVE_STRFTIME
479 void BScreen::saveWorkspaceNames() {
480 XAtom::StringVect nameList
;
481 unsigned long numnames
= (unsigned) -1;
485 xatom
->getValue(getRootWindow(), XAtom::net_desktop_names
, XAtom::utf8
,
486 numnames
, nameList
)) {
487 for (unsigned int i
= 0; i
< nameList
.size(); ++i
) {
488 if (i
> 0) names
+= ",";
489 names
+= nameList
[i
];
492 config
->setValue(screenstr
+ "workspaceNames", names
);
496 void BScreen::save_rc(void) {
497 saveSloppyFocus(resource
.sloppy_focus
);
498 saveAutoRaise(resource
.auto_raise
);
499 saveImageDither(doImageDither());
500 saveOpaqueMove(resource
.opaque_move
);
501 saveFullMax(resource
.full_max
);
502 saveFocusNew(resource
.focus_new
);
503 saveFocusLast(resource
.focus_last
);
504 saveHideToolbar(resource
.hide_toolbar
);
505 saveWindowToWindowSnap(resource
.window_to_window_snap
);
506 saveWindowCornerSnap(resource
.window_corner_snap
);
507 saveWorkspaces(resource
.workspaces
);
508 savePlacementPolicy(resource
.placement_policy
);
509 saveEdgeSnapThreshold(resource
.edge_snap_threshold
);
510 saveRowPlacementDirection(resource
.row_direction
);
511 saveColPlacementDirection(resource
.col_direction
);
513 saveStrftimeFormat(resource
.strftime_format
);
514 #else // !HAVE_STRFTIME
515 saveDateFormat(resource
.date_format
);
516 savwClock24Hour(resource
.clock24hour
);
517 #endif // HAVE_STRFTIME
524 void BScreen::load_rc(void) {
528 if (! config
->getValue(screenstr
+ "fullMaximization", resource
.full_max
))
529 resource
.full_max
= false;
531 if (! config
->getValue(screenstr
+ "focusNewWindows", resource
.focus_new
))
532 resource
.focus_new
= false;
534 if (! config
->getValue(screenstr
+ "focusLastWindow", resource
.focus_last
))
535 resource
.focus_last
= false;
537 if (! config
->getValue(screenstr
+ "workspaces", resource
.workspaces
))
538 resource
.workspaces
= 1;
540 if (! config
->getValue(screenstr
+ "opaqueMove", resource
.opaque_move
))
541 resource
.opaque_move
= false;
543 if (! config
->getValue(screenstr
+ "hideToolbar", resource
.hide_toolbar
))
544 resource
.hide_toolbar
= false;
546 if (! config
->getValue(screenstr
+ "windowToWindowSnap",
547 resource
.window_to_window_snap
))
548 resource
.window_to_window_snap
= true;
550 if (! config
->getValue(screenstr
+ "windowCornerSnap",
551 resource
.window_corner_snap
))
552 resource
.window_corner_snap
= true;
554 if (! config
->getValue(screenstr
+ "imageDither", b
))
556 image_control
->setDither(b
);
558 if (! config
->getValue(screenstr
+ "edgeSnapThreshold",
559 resource
.edge_snap_threshold
))
560 resource
.edge_snap_threshold
= 4;
562 if (config
->getValue(screenstr
+ "rowPlacementDirection", s
) &&
564 resource
.row_direction
= RightLeft
;
566 resource
.row_direction
= LeftRight
;
568 if (config
->getValue(screenstr
+ "colPlacementDirection", s
) &&
570 resource
.col_direction
= BottomTop
;
572 resource
.col_direction
= TopBottom
;
574 XAtom::StringVect workspaceNames
;
575 if (config
->getValue(screenstr
+ "workspaceNames", s
)) {
576 string::const_iterator it
= s
.begin(), end
= s
.end();
578 string::const_iterator tmp
= it
; // current string.begin()
579 it
= std::find(tmp
, end
, ','); // look for comma between tmp and end
580 workspaceNames
.push_back(string(tmp
, it
)); // s[tmp:it]
586 xatom
->setValue(getRootWindow(), XAtom::net_desktop_names
, XAtom::utf8
,
589 resource
.sloppy_focus
= true;
590 resource
.auto_raise
= false;
591 resource
.click_raise
= false;
592 if (config
->getValue(screenstr
+ "focusModel", s
)) {
593 if (s
.find("ClickToFocus") != string::npos
) {
594 resource
.sloppy_focus
= false;
597 if (s
.find("AutoRaise") != string::npos
)
598 resource
.auto_raise
= true;
599 if (s
.find("ClickRaise") != string::npos
)
600 resource
.click_raise
= true;
604 if (config
->getValue(screenstr
+ "windowPlacement", s
)) {
605 if (s
== "CascadePlacement")
606 resource
.placement_policy
= CascadePlacement
;
607 else if (s
== "ColSmartPlacement")
608 resource
.placement_policy
= ColSmartPlacement
;
609 else //if (s == "RowSmartPlacement")
610 resource
.placement_policy
= RowSmartPlacement
;
612 resource
.placement_policy
= RowSmartPlacement
;
615 if (config
->getValue(screenstr
+ "strftimeFormat", s
))
616 resource
.strftime_format
= s
;
618 resource
.strftime_format
= "%I:%M %p";
619 #else // !HAVE_STRFTIME
622 if (config
->getValue(screenstr
+ "dateFormat", s
) && s
== "European")
623 resource
.date_format
= B_EuropeanDate
;
625 resource
.date_format
= B_AmericanDate
;
627 if (! config
->getValue(screenstr
+ "clockFormat", l
))
629 resource
.clock24hour
= l
== 24;
630 #endif // HAVE_STRFTIME
634 void BScreen::reconfigure(void) {
641 gcv
.foreground
= WhitePixel(blackbox
->getXDisplay(),
643 gcv
.function
= GXinvert
;
644 gcv
.subwindow_mode
= IncludeInferiors
;
645 XChangeGC(blackbox
->getXDisplay(), opGC
,
646 GCForeground
| GCFunction
| GCSubwindowMode
, &gcv
);
648 const char *s
= i18n(ScreenSet
, ScreenPositionLength
,
649 "0: 0000 x 0: 0000");
651 geom_w
= resource
.wstyle
.font
->measureString(s
) + resource
.bevel_width
* 2;
652 geom_h
= resource
.wstyle
.font
->height() + resource
.bevel_width
* 2;
654 BTexture
* texture
= &(resource
.wstyle
.l_focus
);
655 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
656 if (geom_pixmap
== ParentRelative
) {
657 texture
= &(resource
.wstyle
.t_focus
);
658 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
661 XSetWindowBackground(blackbox
->getXDisplay(), geom_window
,
662 texture
->color().pixel());
664 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
665 geom_window
, geom_pixmap
);
667 XSetWindowBorderWidth(blackbox
->getXDisplay(), geom_window
,
668 resource
.border_width
);
669 XSetWindowBorder(blackbox
->getXDisplay(), geom_window
,
670 resource
.border_color
.pixel());
672 workspacemenu
->reconfigure();
673 iconmenu
->reconfigure();
675 typedef std::vector
<int> SubList
;
676 SubList remember_subs
;
678 // save the current open menus
679 Basemenu
*menu
= rootmenu
;
681 while ((submenu
= menu
->getCurrentSubmenu()) >= 0) {
682 remember_subs
.push_back(submenu
);
683 menu
= menu
->find(submenu
)->submenu();
689 rootmenu
->reconfigure();
691 // reopen the saved menus
693 const SubList::iterator subs_end
= remember_subs
.end();
694 for (SubList::iterator it
= remember_subs
.begin(); it
!= subs_end
; ++it
) {
695 menu
->drawSubmenu(*it
);
696 menu
= menu
->find(*it
)->submenu();
701 configmenu
->reconfigure();
703 toolbar
->reconfigure();
707 std::for_each(workspacesList
.begin(), workspacesList
.end(),
708 std::mem_fun(&Workspace::reconfigure
));
710 BlackboxWindowList::iterator iit
= iconList
.begin();
711 for (; iit
!= iconList
.end(); ++iit
) {
712 BlackboxWindow
*bw
= *iit
;
713 if (bw
->validateClient())
717 image_control
->timeout();
721 void BScreen::rereadMenu(void) {
725 rootmenu
->reconfigure();
729 void BScreen::LoadStyle(void) {
732 const char *sfile
= blackbox
->getStyleFilename();
734 style
.setFile(sfile
);
735 if (! style
.load()) {
736 style
.setFile(DEFAULTSTYLE
);
738 style
.create(); // hardcoded default values will be used.
744 // load fonts/fontsets
745 if (resource
.wstyle
.font
)
746 delete resource
.wstyle
.font
;
747 if (resource
.tstyle
.font
)
748 delete resource
.tstyle
.font
;
749 if (resource
.mstyle
.f_font
)
750 delete resource
.mstyle
.f_font
;
751 if (resource
.mstyle
.t_font
)
752 delete resource
.mstyle
.t_font
;
753 resource
.wstyle
.font
= resource
.tstyle
.font
= resource
.mstyle
.f_font
=
754 resource
.mstyle
.t_font
= (BFont
*) 0;
756 resource
.wstyle
.font
= readDatabaseFont("window.font", style
);
757 resource
.tstyle
.font
= readDatabaseFont("toolbar.font", style
);
758 resource
.mstyle
.t_font
= readDatabaseFont("menu.title.font", style
);
759 resource
.mstyle
.f_font
= readDatabaseFont("menu.frame.font", style
);
761 // load window config
762 resource
.wstyle
.t_focus
=
763 readDatabaseTexture("window.title.focus", "white", style
);
764 resource
.wstyle
.t_unfocus
=
765 readDatabaseTexture("window.title.unfocus", "black", style
);
766 resource
.wstyle
.l_focus
=
767 readDatabaseTexture("window.label.focus", "white", style
);
768 resource
.wstyle
.l_unfocus
=
769 readDatabaseTexture("window.label.unfocus", "black", style
);
770 resource
.wstyle
.h_focus
=
771 readDatabaseTexture("window.handle.focus", "white", style
);
772 resource
.wstyle
.h_unfocus
=
773 readDatabaseTexture("window.handle.unfocus", "black", style
);
774 resource
.wstyle
.g_focus
=
775 readDatabaseTexture("window.grip.focus", "white", style
);
776 resource
.wstyle
.g_unfocus
=
777 readDatabaseTexture("window.grip.unfocus", "black", style
);
778 resource
.wstyle
.b_focus
=
779 readDatabaseTexture("window.button.focus", "white", style
);
780 resource
.wstyle
.b_unfocus
=
781 readDatabaseTexture("window.button.unfocus", "black", style
);
782 resource
.wstyle
.b_pressed
=
783 readDatabaseTexture("window.button.pressed", "black", style
);
784 resource
.wstyle
.f_focus
=
785 readDatabaseColor("window.frame.focusColor", "white", style
);
786 resource
.wstyle
.f_unfocus
=
787 readDatabaseColor("window.frame.unfocusColor", "black", style
);
788 resource
.wstyle
.l_text_focus
=
789 readDatabaseColor("window.label.focus.textColor", "black", style
);
790 resource
.wstyle
.l_text_unfocus
=
791 readDatabaseColor("window.label.unfocus.textColor", "white", style
);
792 resource
.wstyle
.b_pic_focus
=
793 readDatabaseColor("window.button.focus.picColor", "black", style
);
794 resource
.wstyle
.b_pic_unfocus
=
795 readDatabaseColor("window.button.unfocus.picColor", "white", style
);
797 resource
.wstyle
.justify
= LeftJustify
;
798 if (style
.getValue("window.justify", s
)) {
799 if (s
== "right" || s
== "Right")
800 resource
.wstyle
.justify
= RightJustify
;
801 else if (s
== "center" || s
== "Center")
802 resource
.wstyle
.justify
= CenterJustify
;
805 // load toolbar config
806 resource
.tstyle
.toolbar
=
807 readDatabaseTexture("toolbar", "black", style
);
808 resource
.tstyle
.label
=
809 readDatabaseTexture("toolbar.label", "black", style
);
810 resource
.tstyle
.window
=
811 readDatabaseTexture("toolbar.windowLabel", "black", style
);
812 resource
.tstyle
.button
=
813 readDatabaseTexture("toolbar.button", "white", style
);
814 resource
.tstyle
.pressed
=
815 readDatabaseTexture("toolbar.button.pressed", "black", style
);
816 resource
.tstyle
.clock
=
817 readDatabaseTexture("toolbar.clock", "black", style
);
818 resource
.tstyle
.l_text
=
819 readDatabaseColor("toolbar.label.textColor", "white", style
);
820 resource
.tstyle
.w_text
=
821 readDatabaseColor("toolbar.windowLabel.textColor", "white", style
);
822 resource
.tstyle
.c_text
=
823 readDatabaseColor("toolbar.clock.textColor", "white", style
);
824 resource
.tstyle
.b_pic
=
825 readDatabaseColor("toolbar.button.picColor", "black", style
);
827 resource
.tstyle
.justify
= LeftJustify
;
828 if (style
.getValue("toolbar.justify", s
)) {
829 if (s
== "right" || s
== "Right")
830 resource
.tstyle
.justify
= RightJustify
;
831 else if (s
== "center" || s
== "Center")
832 resource
.tstyle
.justify
= CenterJustify
;
836 resource
.mstyle
.title
=
837 readDatabaseTexture("menu.title", "white", style
);
838 resource
.mstyle
.frame
=
839 readDatabaseTexture("menu.frame", "black", style
);
840 resource
.mstyle
.hilite
=
841 readDatabaseTexture("menu.hilite", "white", style
);
842 resource
.mstyle
.t_text
=
843 readDatabaseColor("menu.title.textColor", "black", style
);
844 resource
.mstyle
.f_text
=
845 readDatabaseColor("menu.frame.textColor", "white", style
);
846 resource
.mstyle
.d_text
=
847 readDatabaseColor("menu.frame.disableColor", "black", style
);
848 resource
.mstyle
.h_text
=
849 readDatabaseColor("menu.hilite.textColor", "black", style
);
851 resource
.mstyle
.t_justify
= LeftJustify
;
852 if (style
.getValue("menu.title.justify", s
)) {
853 if (s
== "right" || s
== "Right")
854 resource
.mstyle
.t_justify
= RightJustify
;
855 else if (s
== "center" || s
== "Center")
856 resource
.mstyle
.t_justify
= CenterJustify
;
859 resource
.mstyle
.f_justify
= LeftJustify
;
860 if (style
.getValue("menu.frame.justify", s
)) {
861 if (s
== "right" || s
== "Right")
862 resource
.mstyle
.f_justify
= RightJustify
;
863 else if (s
== "center" || s
== "Center")
864 resource
.mstyle
.f_justify
= CenterJustify
;
867 resource
.mstyle
.bullet
= Basemenu::Triangle
;
868 if (style
.getValue("menu.bullet", s
)) {
869 if (s
== "empty" || s
== "Empty")
870 resource
.mstyle
.bullet
= Basemenu::Empty
;
871 else if (s
== "square" || s
== "Square")
872 resource
.mstyle
.bullet
= Basemenu::Square
;
873 else if (s
== "diamond" || s
== "Diamond")
874 resource
.mstyle
.bullet
= Basemenu::Diamond
;
877 resource
.mstyle
.bullet_pos
= Basemenu::Left
;
878 if (style
.getValue("menu.bullet.position", s
)) {
879 if (s
== "right" || s
== "Right")
880 resource
.mstyle
.bullet_pos
= Basemenu::Right
;
883 resource
.border_color
=
884 readDatabaseColor("borderColor", "black", style
);
886 // load bevel, border and handle widths
887 if (! style
.getValue("handleWidth", resource
.handle_width
) ||
888 resource
.handle_width
> (getWidth() / 2) || resource
.handle_width
== 0)
889 resource
.handle_width
= 6;
891 if (! style
.getValue("borderWidth", resource
.border_width
))
892 resource
.border_width
= 1;
894 if (! style
.getValue("bevelWidth", resource
.bevel_width
) ||
895 resource
.bevel_width
> (getWidth() / 2) || resource
.bevel_width
== 0)
896 resource
.bevel_width
= 3;
898 if (! style
.getValue("frameWidth", resource
.frame_width
) ||
899 resource
.frame_width
> (getWidth() / 2))
900 resource
.frame_width
= resource
.bevel_width
;
902 if (style
.getValue("rootCommand", s
))
903 bexec(s
, displayString());
907 void BScreen::addIcon(BlackboxWindow
*w
) {
910 w
->setWorkspace(BSENTINEL
);
911 w
->setWindowNumber(iconList
.size());
913 iconList
.push_back(w
);
915 const char* title
= w
->getIconTitle();
916 iconmenu
->insert(title
);
921 void BScreen::removeIcon(BlackboxWindow
*w
) {
926 iconmenu
->remove(w
->getWindowNumber());
929 BlackboxWindowList::iterator it
= iconList
.begin(),
930 end
= iconList
.end();
931 for (int i
= 0; it
!= end
; ++it
)
932 (*it
)->setWindowNumber(i
++);
936 BlackboxWindow
*BScreen::getIcon(unsigned int index
) {
937 if (index
< iconList
.size()) {
938 BlackboxWindowList::iterator it
= iconList
.begin();
939 for (; index
> 0; --index
, ++it
) ; /* increment to index */
943 return (BlackboxWindow
*) 0;
947 unsigned int BScreen::addWorkspace(void) {
948 Workspace
*wkspc
= new Workspace(this, workspacesList
.size());
949 workspacesList
.push_back(wkspc
);
950 saveWorkspaces(getWorkspaceCount());
952 workspacemenu
->insert(wkspc
->getName(), wkspc
->getMenu(),
954 workspacemenu
->update();
956 toolbar
->reconfigure();
958 updateNetizenWorkspaceCount();
960 return workspacesList
.size();
964 unsigned int BScreen::removeLastWorkspace(void) {
965 if (workspacesList
.size() == 1)
968 Workspace
*wkspc
= workspacesList
.back();
970 if (current_workspace
->getID() == wkspc
->getID())
971 changeWorkspaceID(current_workspace
->getID() - 1);
975 workspacemenu
->remove(wkspc
->getID() + 2);
976 workspacemenu
->update();
978 workspacesList
.pop_back();
981 saveWorkspaces(getWorkspaceCount());
983 toolbar
->reconfigure();
985 updateNetizenWorkspaceCount();
987 return workspacesList
.size();
991 void BScreen::changeWorkspaceID(unsigned int id
) {
992 if (! current_workspace
) return;
994 if (id
!= current_workspace
->getID()) {
995 BlackboxWindow
*focused
= blackbox
->getFocusedWindow();
996 if (focused
&& focused
->getScreen() == this && ! focused
->isStuck()) {
997 if (focused
->getWorkspaceNumber() != current_workspace
->getID()) {
998 fprintf(stderr
, "%s is on the wrong workspace, aborting\n",
999 focused
->getTitle());
1002 current_workspace
->setLastFocusedWindow(focused
);
1004 // if no window had focus, no need to store a last focus
1005 current_workspace
->setLastFocusedWindow((BlackboxWindow
*) 0);
1007 // when we switch workspaces, unfocus whatever was focused
1008 blackbox
->setFocusedWindow((BlackboxWindow
*) 0);
1010 current_workspace
->hideAll();
1011 workspacemenu
->setItemSelected(current_workspace
->getID() + 2, False
);
1013 current_workspace
= getWorkspace(id
);
1015 xatom
->setValue(getRootWindow(), XAtom::net_current_desktop
,
1016 XAtom::cardinal
, id
);
1018 workspacemenu
->setItemSelected(current_workspace
->getID() + 2, True
);
1019 toolbar
->redrawWorkspaceLabel(True
);
1021 current_workspace
->showAll();
1023 if (resource
.focus_last
&& current_workspace
->getLastFocusedWindow()) {
1024 XSync(blackbox
->getXDisplay(), False
);
1025 current_workspace
->getLastFocusedWindow()->setInputFocus();
1029 updateNetizenCurrentWorkspace();
1034 * Set the _NET_CLIENT_LIST root window property.
1036 void BScreen::updateClientList(void) {
1037 if (windowList
.size() > 0) {
1038 Window
*windows
= new Window
[windowList
.size()];
1039 Window
*win_it
= windows
;
1040 BlackboxWindowList::iterator it
= windowList
.begin();
1041 const BlackboxWindowList::iterator end
= windowList
.end();
1042 for (; it
!= end
; ++it
, ++win_it
)
1043 *win_it
= (*it
)->getClientWindow();
1044 xatom
->setValue(getRootWindow(), XAtom::net_client_list
, XAtom::window
,
1045 windows
, windowList
.size());
1048 xatom
->setValue(getRootWindow(), XAtom::net_client_list
, XAtom::window
,
1054 * Set the _NET_CLIENT_LIST_STACKING root window property.
1056 void BScreen::updateStackingList(void) {
1058 BlackboxWindowList stack_order
;
1061 * Get the atacking order from all of the workspaces.
1062 * We start with the current workspace so that the sticky windows will be
1063 * in the right order on the current workspace.
1064 * XXX: Do we need to have sticky windows in the list once for each workspace?
1066 getCurrentWorkspace()->appendStackOrder(stack_order
);
1067 for (unsigned int i
= 0; i
< getWorkspaceCount(); ++i
)
1068 if (i
!= getCurrentWorkspaceID())
1069 getWorkspace(i
)->appendStackOrder(stack_order
);
1071 if (stack_order
.size() > 0) {
1072 // set the client list atoms
1073 Window
*windows
= new Window
[stack_order
.size()];
1074 Window
*win_it
= windows
;
1075 BlackboxWindowList::iterator it
= stack_order
.begin();
1076 const BlackboxWindowList::iterator end
= stack_order
.end();
1077 for (; it
!= end
; ++it
, ++win_it
)
1078 *win_it
= (*it
)->getClientWindow();
1079 xatom
->setValue(getRootWindow(), XAtom::net_client_list_stacking
,
1080 XAtom::window
, windows
, stack_order
.size());
1083 xatom
->setValue(getRootWindow(), XAtom::net_client_list_stacking
,
1084 XAtom::window
, 0, 0);
1088 void BScreen::addSystrayWindow(Window window
) {
1089 systrayWindowList
.push_back(window
);
1090 xatom
->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows
,
1092 &systrayWindowList
[0], systrayWindowList
.size());
1093 blackbox
->saveSystrayWindowSearch(window
, this);
1097 void BScreen::removeSystrayWindow(Window window
) {
1098 WindowList::iterator it
= systrayWindowList
.begin();
1099 const WindowList::iterator end
= systrayWindowList
.end();
1100 for (; it
!= end
; ++it
)
1101 if (*it
== window
) {
1102 systrayWindowList
.erase(it
);
1103 xatom
->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows
,
1105 &systrayWindowList
[0], systrayWindowList
.size());
1106 blackbox
->removeSystrayWindowSearch(window
);
1112 void BScreen::addDesktopWindow(Window window
) {
1113 desktopWindowList
.push_back(window
);
1114 XLowerWindow(blackbox
->getXDisplay(), window
);
1115 XSelectInput(blackbox
->getXDisplay(), window
, StructureNotifyMask
);
1116 blackbox
->saveDesktopWindowSearch(window
, this);
1120 void BScreen::removeDesktopWindow(Window window
) {
1121 WindowList::iterator it
= desktopWindowList
.begin();
1122 const WindowList::iterator end
= desktopWindowList
.end();
1123 for (; it
!= end
; ++it
)
1124 if (*it
== window
) {
1125 desktopWindowList
.erase(it
);
1126 XSelectInput(blackbox
->getXDisplay(), window
, None
);
1127 blackbox
->removeDesktopWindowSearch(window
);
1133 void BScreen::manageWindow(Window w
) {
1134 new BlackboxWindow(blackbox
, w
, this);
1136 BlackboxWindow
*win
= blackbox
->searchWindow(w
);
1139 if (win
->isDesktop()) {
1140 // desktop windows cant do anything, so we remove all the normal window
1141 // stuff from them, they are only kept around so that we can keep them on
1142 // the bottom of the z-order
1144 addDesktopWindow(win
->getClientWindow());
1149 windowList
.push_back(win
);
1152 XMapRequestEvent mre
;
1154 if (blackbox
->isStartup()) win
->restoreAttributes();
1155 win
->mapRequestEvent(&mre
);
1159 void BScreen::unmanageWindow(BlackboxWindow
*w
, bool remap
) {
1162 if (w
->getWorkspaceNumber() != BSENTINEL
&&
1163 w
->getWindowNumber() != BSENTINEL
)
1164 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
1165 else if (w
->isIconic())
1168 windowList
.remove(w
);
1171 if (blackbox
->getFocusedWindow() == w
)
1172 blackbox
->setFocusedWindow((BlackboxWindow
*) 0);
1174 removeNetizen(w
->getClientWindow());
1177 some managed windows can also be window group controllers. when
1178 unmanaging such windows, we should also delete the window group.
1180 BWindowGroup
*group
= blackbox
->searchGroup(w
->getClientWindow());
1187 void BScreen::addNetizen(Netizen
*n
) {
1188 netizenList
.push_back(n
);
1190 n
->sendWorkspaceCount();
1191 n
->sendCurrentWorkspace();
1193 WorkspaceList::iterator it
= workspacesList
.begin();
1194 const WorkspaceList::iterator end
= workspacesList
.end();
1195 for (; it
!= end
; ++it
)
1196 (*it
)->sendWindowList(*n
);
1198 Window f
= ((blackbox
->getFocusedWindow()) ?
1199 blackbox
->getFocusedWindow()->getClientWindow() : None
);
1200 n
->sendWindowFocus(f
);
1204 void BScreen::removeNetizen(Window w
) {
1205 NetizenList::iterator it
= netizenList
.begin();
1206 for (; it
!= netizenList
.end(); ++it
) {
1207 if ((*it
)->getWindowID() == w
) {
1209 netizenList
.erase(it
);
1216 void BScreen::updateWorkArea(void) {
1217 if (workspacesList
.size() > 0) {
1218 unsigned long *dims
= new unsigned long[4 * workspacesList
.size()];
1219 for (unsigned int i
= 0, m
= workspacesList
.size(); i
< m
; ++i
) {
1220 // XXX: this could be different for each workspace
1221 const Rect
&area
= availableArea();
1222 dims
[(i
* 4) + 0] = area
.x();
1223 dims
[(i
* 4) + 1] = area
.y();
1224 dims
[(i
* 4) + 2] = area
.width();
1225 dims
[(i
* 4) + 3] = area
.height();
1227 xatom
->setValue(getRootWindow(), XAtom::net_workarea
, XAtom::cardinal
,
1228 dims
, 4 * workspacesList
.size());
1231 xatom
->setValue(getRootWindow(), XAtom::net_workarea
, XAtom::cardinal
,
1236 void BScreen::updateNetizenCurrentWorkspace(void) {
1237 std::for_each(netizenList
.begin(), netizenList
.end(),
1238 std::mem_fun(&Netizen::sendCurrentWorkspace
));
1242 void BScreen::updateNetizenWorkspaceCount(void) {
1243 xatom
->setValue(getRootWindow(), XAtom::net_number_of_desktops
,
1244 XAtom::cardinal
, workspacesList
.size());
1248 std::for_each(netizenList
.begin(), netizenList
.end(),
1249 std::mem_fun(&Netizen::sendWorkspaceCount
));
1253 void BScreen::updateNetizenWindowFocus(void) {
1254 Window f
= ((blackbox
->getFocusedWindow()) ?
1255 blackbox
->getFocusedWindow()->getClientWindow() : None
);
1257 xatom
->setValue(getRootWindow(), XAtom::net_active_window
,
1260 NetizenList::iterator it
= netizenList
.begin();
1261 for (; it
!= netizenList
.end(); ++it
)
1262 (*it
)->sendWindowFocus(f
);
1266 void BScreen::updateNetizenWindowAdd(Window w
, unsigned long p
) {
1267 NetizenList::iterator it
= netizenList
.begin();
1268 for (; it
!= netizenList
.end(); ++it
) {
1269 (*it
)->sendWindowAdd(w
, p
);
1274 void BScreen::updateNetizenWindowDel(Window w
) {
1275 NetizenList::iterator it
= netizenList
.begin();
1276 for (; it
!= netizenList
.end(); ++it
)
1277 (*it
)->sendWindowDel(w
);
1281 void BScreen::updateNetizenWindowRaise(Window w
) {
1282 NetizenList::iterator it
= netizenList
.begin();
1283 for (; it
!= netizenList
.end(); ++it
)
1284 (*it
)->sendWindowRaise(w
);
1288 void BScreen::updateNetizenWindowLower(Window w
) {
1289 NetizenList::iterator it
= netizenList
.begin();
1290 for (; it
!= netizenList
.end(); ++it
)
1291 (*it
)->sendWindowLower(w
);
1295 void BScreen::updateNetizenConfigNotify(XEvent
*e
) {
1296 NetizenList::iterator it
= netizenList
.begin();
1297 for (; it
!= netizenList
.end(); ++it
)
1298 (*it
)->sendConfigNotify(e
);
1302 void BScreen::raiseWindows(Window
*workspace_stack
, unsigned int num
) {
1303 // the 13 represents the number of blackbox windows such as menus
1304 Window
*session_stack
= new
1305 Window
[(num
+ workspacesList
.size() + rootmenuList
.size() + 13)];
1306 unsigned int i
= 0, k
= num
;
1308 XRaiseWindow(blackbox
->getXDisplay(), iconmenu
->getWindowID());
1309 *(session_stack
+ i
++) = iconmenu
->getWindowID();
1311 WorkspaceList::iterator wit
= workspacesList
.begin();
1312 const WorkspaceList::iterator w_end
= workspacesList
.end();
1313 for (; wit
!= w_end
; ++wit
)
1314 *(session_stack
+ i
++) = (*wit
)->getMenu()->getWindowID();
1316 *(session_stack
+ i
++) = workspacemenu
->getWindowID();
1318 *(session_stack
+ i
++) = configmenu
->getFocusmenu()->getWindowID();
1319 *(session_stack
+ i
++) = configmenu
->getPlacementmenu()->getWindowID();
1320 *(session_stack
+ i
++) = configmenu
->getWindowID();
1322 *(session_stack
+ i
++) = slit
->getMenu()->getDirectionmenu()->getWindowID();
1323 *(session_stack
+ i
++) = slit
->getMenu()->getPlacementmenu()->getWindowID();
1324 *(session_stack
+ i
++) = slit
->getMenu()->getWindowID();
1326 *(session_stack
+ i
++) =
1327 toolbar
->getMenu()->getPlacementmenu()->getWindowID();
1328 *(session_stack
+ i
++) = toolbar
->getMenu()->getWindowID();
1330 RootmenuList::iterator rit
= rootmenuList
.begin();
1331 for (; rit
!= rootmenuList
.end(); ++rit
)
1332 *(session_stack
+ i
++) = (*rit
)->getWindowID();
1333 *(session_stack
+ i
++) = rootmenu
->getWindowID();
1335 if (toolbar
->isOnTop())
1336 *(session_stack
+ i
++) = toolbar
->getWindowID();
1338 if (slit
->isOnTop())
1339 *(session_stack
+ i
++) = slit
->getWindowID();
1342 *(session_stack
+ i
++) = *(workspace_stack
+ k
);
1344 XRestackWindows(blackbox
->getXDisplay(), session_stack
, i
);
1346 delete [] session_stack
;
1348 updateStackingList();
1352 void BScreen::lowerDesktops(void) {
1353 if (desktopWindowList
.empty()) return;
1355 XLowerWindow(blackbox
->getXDisplay(), desktopWindowList
[0]);
1356 if (desktopWindowList
.size() > 1)
1357 XRestackWindows(blackbox
->getXDisplay(), &desktopWindowList
[0],
1358 desktopWindowList
.size());
1362 void BScreen::reassociateWindow(BlackboxWindow
*w
, unsigned int wkspc_id
,
1363 bool ignore_sticky
) {
1366 if (wkspc_id
== BSENTINEL
)
1367 wkspc_id
= current_workspace
->getID();
1369 if (w
->getWorkspaceNumber() == wkspc_id
)
1372 if (w
->isIconic()) {
1374 getWorkspace(wkspc_id
)->addWindow(w
);
1375 } else if (ignore_sticky
|| ! w
->isStuck()) {
1376 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
1377 getWorkspace(wkspc_id
)->addWindow(w
);
1382 void BScreen::propagateWindowName(const BlackboxWindow
*bw
) {
1383 if (bw
->isIconic()) {
1384 iconmenu
->changeItemLabel(bw
->getWindowNumber(), bw
->getIconTitle());
1388 Clientmenu
*clientmenu
= getWorkspace(bw
->getWorkspaceNumber())->getMenu();
1389 clientmenu
->changeItemLabel(bw
->getWindowNumber(), bw
->getTitle());
1390 clientmenu
->update();
1392 if (blackbox
->getFocusedWindow() == bw
)
1393 toolbar
->redrawWindowLabel(True
);
1398 void BScreen::nextFocus(void) {
1399 BlackboxWindow
*focused
= blackbox
->getFocusedWindow(),
1403 // if window is not on this screen, ignore it
1404 if (focused
->getScreen()->getScreenNumber() != getScreenNumber())
1405 focused
= (BlackboxWindow
*) 0;
1408 if (focused
&& current_workspace
->getCount() > 1) {
1409 // next is the next window to recieve focus, current is a place holder
1410 BlackboxWindow
*current
;
1413 next
= current_workspace
->getNextWindowInList(current
);
1414 } while(! next
->setInputFocus() && next
!= focused
);
1416 if (next
!= focused
)
1417 current_workspace
->raiseWindow(next
);
1418 } else if (current_workspace
->getCount() >= 1) {
1419 next
= current_workspace
->getTopWindowOnStack();
1421 current_workspace
->raiseWindow(next
);
1422 next
->setInputFocus();
1427 void BScreen::prevFocus(void) {
1428 BlackboxWindow
*focused
= blackbox
->getFocusedWindow(),
1432 // if window is not on this screen, ignore it
1433 if (focused
->getScreen()->getScreenNumber() != getScreenNumber())
1434 focused
= (BlackboxWindow
*) 0;
1437 if (focused
&& current_workspace
->getCount() > 1) {
1438 // next is the next window to recieve focus, current is a place holder
1439 BlackboxWindow
*current
;
1442 next
= current_workspace
->getPrevWindowInList(current
);
1443 } while(! next
->setInputFocus() && next
!= focused
);
1445 if (next
!= focused
)
1446 current_workspace
->raiseWindow(next
);
1447 } else if (current_workspace
->getCount() >= 1) {
1448 next
= current_workspace
->getTopWindowOnStack();
1450 current_workspace
->raiseWindow(next
);
1451 next
->setInputFocus();
1456 void BScreen::raiseFocus(void) {
1457 BlackboxWindow
*focused
= blackbox
->getFocusedWindow();
1461 // if on this Screen, raise it
1462 if (focused
->getScreen()->getScreenNumber() == getScreenNumber()) {
1463 Workspace
*workspace
= getWorkspace(focused
->getWorkspaceNumber());
1464 workspace
->raiseWindow(focused
);
1469 void BScreen::InitMenu(void) {
1471 rootmenuList
.clear();
1473 while (rootmenu
->getCount())
1474 rootmenu
->remove(0);
1476 rootmenu
= new Rootmenu(this);
1478 bool defaultMenu
= True
;
1480 FILE *menu_file
= (FILE *) 0;
1481 const char *menu_filename
= blackbox
->getMenuFilename();
1484 if (! (menu_file
= fopen(menu_filename
, "r")))
1485 perror(menu_filename
);
1486 if (! menu_file
) { // opening the menu file failed, try the default menu
1487 menu_filename
= DEFAULTMENU
;
1488 if (! (menu_file
= fopen(menu_filename
, "r")))
1489 perror(menu_filename
);
1493 if (feof(menu_file
)) {
1494 fprintf(stderr
, i18n(ScreenSet
, ScreenEmptyMenuFile
,
1495 "%s: Empty menu file"),
1498 char line
[1024], label
[1024];
1499 memset(line
, 0, 1024);
1500 memset(label
, 0, 1024);
1502 while (fgets(line
, 1024, menu_file
) && ! feof(menu_file
)) {
1503 if (line
[0] != '#') {
1504 int i
, key
= 0, index
= -1, len
= strlen(line
);
1506 for (i
= 0; i
< len
; i
++) {
1507 if (line
[i
] == '[') index
= 0;
1508 else if (line
[i
] == ']') break;
1509 else if (line
[i
] != ' ')
1511 key
+= tolower(line
[i
]);
1514 if (key
== 517) { // [begin]
1516 for (i
= index
; i
< len
; i
++) {
1517 if (line
[i
] == '(') index
= 0;
1518 else if (line
[i
] == ')') break;
1519 else if (index
++ >= 0) {
1520 if (line
[i
] == '\\' && i
< len
- 1) i
++;
1521 label
[index
- 1] = line
[i
];
1525 if (index
== -1) index
= 0;
1526 label
[index
] = '\0';
1528 rootmenu
->setLabel(label
);
1529 defaultMenu
= parseMenuFile(menu_file
, rootmenu
);
1531 blackbox
->addMenuTimestamp(menu_filename
);
1541 rootmenu
->setInternalMenu();
1542 rootmenu
->insert(i18n(ScreenSet
, Screenxterm
, "xterm"),
1544 i18n(ScreenSet
, Screenxterm
, "xterm"));
1545 rootmenu
->insert(i18n(ScreenSet
, ScreenRestart
, "Restart"),
1547 rootmenu
->insert(i18n(ScreenSet
, ScreenExit
, "Exit"),
1549 rootmenu
->setLabel(i18n(BasemenuSet
, BasemenuBlackboxMenu
,
1555 bool BScreen::parseMenuFile(FILE *file
, Rootmenu
*menu
) {
1556 char line
[1024], label
[1024], command
[1024];
1558 while (! feof(file
)) {
1559 memset(line
, 0, 1024);
1560 memset(label
, 0, 1024);
1561 memset(command
, 0, 1024);
1563 if (fgets(line
, 1024, file
)) {
1564 if (line
[0] != '#') {
1565 int i
, key
= 0, parse
= 0, index
= -1, line_length
= strlen(line
);
1567 // determine the keyword
1568 for (i
= 0; i
< line_length
; i
++) {
1569 if (line
[i
] == '[') parse
= 1;
1570 else if (line
[i
] == ']') break;
1571 else if (line
[i
] != ' ')
1573 key
+= tolower(line
[i
]);
1576 // get the label enclosed in ()'s
1579 for (i
= 0; i
< line_length
; i
++) {
1580 if (line
[i
] == '(') {
1583 } else if (line
[i
] == ')') break;
1584 else if (index
++ >= 0) {
1585 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
1586 label
[index
- 1] = line
[i
];
1591 label
[index
] = '\0';
1596 // get the command enclosed in {}'s
1599 for (i
= 0; i
< line_length
; i
++) {
1600 if (line
[i
] == '{') {
1603 } else if (line
[i
] == '}') break;
1604 else if (index
++ >= 0) {
1605 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
1606 command
[index
- 1] = line
[i
];
1611 command
[index
] = '\0';
1618 return ((menu
->getCount() == 0) ? True
: False
);
1625 menu
->insert(label
);
1630 if ((! *label
) && (! *command
)) {
1631 fprintf(stderr
, i18n(ScreenSet
, ScreenEXECError
,
1632 "BScreen::parseMenuFile: [exec] error, "
1633 "no menu label and/or command defined\n"));
1637 menu
->insert(label
, BScreen::Execute
, command
);
1643 fprintf(stderr
, i18n(ScreenSet
, ScreenEXITError
,
1644 "BScreen::parseMenuFile: [exit] error, "
1645 "no menu label defined\n"));
1649 menu
->insert(label
, BScreen::Exit
);
1655 if ((! *label
) || (! *command
)) {
1657 i18n(ScreenSet
, ScreenSTYLEError
,
1658 "BScreen::parseMenuFile: [style] error, "
1659 "no menu label and/or filename defined\n"));
1663 string style
= expandTilde(command
);
1665 menu
->insert(label
, BScreen::SetStyle
, style
.c_str());
1672 fprintf(stderr
, i18n(ScreenSet
, ScreenCONFIGError
,
1673 "BScreen::parseMenufile: [config] error, "
1674 "no label defined"));
1678 menu
->insert(label
, configmenu
);
1682 case 740: // include
1685 fprintf(stderr
, i18n(ScreenSet
, ScreenINCLUDEError
,
1686 "BScreen::parseMenuFile: [include] error, "
1687 "no filename defined\n"));
1691 string newfile
= expandTilde(label
);
1692 FILE *submenufile
= fopen(newfile
.c_str(), "r");
1696 if (fstat(fileno(submenufile
), &buf
) ||
1697 (! S_ISREG(buf
.st_mode
))) {
1699 i18n(ScreenSet
, ScreenINCLUDEErrorReg
,
1700 "BScreen::parseMenuFile: [include] error: "
1701 "'%s' is not a regular file\n"), newfile
.c_str());
1705 if (! feof(submenufile
)) {
1706 if (! parseMenuFile(submenufile
, menu
))
1707 blackbox
->addMenuTimestamp(newfile
);
1709 fclose(submenufile
);
1712 perror(newfile
.c_str());
1718 case 767: // submenu
1721 fprintf(stderr
, i18n(ScreenSet
, ScreenSUBMENUError
,
1722 "BScreen::parseMenuFile: [submenu] error, "
1723 "no menu label defined\n"));
1727 Rootmenu
*submenu
= new Rootmenu(this);
1730 submenu
->setLabel(command
);
1732 submenu
->setLabel(label
);
1734 parseMenuFile(file
, submenu
);
1736 menu
->insert(label
, submenu
);
1737 rootmenuList
.push_back(submenu
);
1742 case 773: // restart
1745 fprintf(stderr
, i18n(ScreenSet
, ScreenRESTARTError
,
1746 "BScreen::parseMenuFile: [restart] error, "
1747 "no menu label defined\n"));
1752 menu
->insert(label
, BScreen::RestartOther
, command
);
1754 menu
->insert(label
, BScreen::Restart
);
1759 case 845: // reconfig
1763 i18n(ScreenSet
, ScreenRECONFIGError
,
1764 "BScreen::parseMenuFile: [reconfig] error, "
1765 "no menu label defined\n"));
1769 menu
->insert(label
, BScreen::Reconfigure
);
1774 case 995: // stylesdir
1775 case 1113: // stylesmenu
1777 bool newmenu
= ((key
== 1113) ? True
: False
);
1779 if ((! *label
) || ((! *command
) && newmenu
)) {
1781 i18n(ScreenSet
, ScreenSTYLESDIRError
,
1782 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1783 " error, no directory defined\n"));
1787 char *directory
= ((newmenu
) ? command
: label
);
1789 string stylesdir
= expandTilde(directory
);
1791 struct stat statbuf
;
1793 if (! stat(stylesdir
.c_str(), &statbuf
)) {
1794 if (S_ISDIR(statbuf
.st_mode
)) {
1795 Rootmenu
*stylesmenu
;
1798 stylesmenu
= new Rootmenu(this);
1802 DIR *d
= opendir(stylesdir
.c_str());
1804 std::vector
<string
> ls
;
1806 while((p
= readdir(d
)))
1807 ls
.push_back(p
->d_name
);
1811 std::sort(ls
.begin(), ls
.end());
1813 std::vector
<string
>::iterator it
= ls
.begin(),
1815 for (; it
!= end
; ++it
) {
1816 const string
& fname
= *it
;
1818 if (fname
[fname
.size()-1] == '~')
1821 string style
= stylesdir
;
1825 if ((! stat(style
.c_str(), &statbuf
)) &&
1826 S_ISREG(statbuf
.st_mode
))
1827 stylesmenu
->insert(fname
, BScreen::SetStyle
, style
);
1830 stylesmenu
->update();
1833 stylesmenu
->setLabel(label
);
1834 menu
->insert(label
, stylesmenu
);
1835 rootmenuList
.push_back(stylesmenu
);
1838 blackbox
->addMenuTimestamp(stylesdir
);
1841 i18n(ScreenSet
, ScreenSTYLESDIRErrorNotDir
,
1842 "BScreen::parseMenuFile:"
1843 " [stylesdir/stylesmenu] error, %s is not a"
1844 " directory\n"), stylesdir
.c_str());
1848 i18n(ScreenSet
, ScreenSTYLESDIRErrorNoExist
,
1849 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1850 " error, %s does not exist\n"), stylesdir
.c_str());
1855 case 1090: // workspaces
1859 i18n(ScreenSet
, ScreenWORKSPACESError
,
1860 "BScreen:parseMenuFile: [workspaces] error, "
1861 "no menu label defined\n"));
1865 menu
->insert(label
, workspacemenu
);
1874 return ((menu
->getCount() == 0) ? True
: False
);
1878 void BScreen::shutdown(void) {
1879 XSelectInput(blackbox
->getXDisplay(), getRootWindow(), NoEventMask
);
1880 XSync(blackbox
->getXDisplay(), False
);
1882 while(! windowList
.empty())
1883 unmanageWindow(windowList
.front(), True
);
1889 void BScreen::showPosition(int x
, int y
) {
1890 if (! geom_visible
) {
1891 XMoveResizeWindow(blackbox
->getXDisplay(), geom_window
,
1892 (getWidth() - geom_w
) / 2,
1893 (getHeight() - geom_h
) / 2, geom_w
, geom_h
);
1894 XMapWindow(blackbox
->getXDisplay(), geom_window
);
1895 XRaiseWindow(blackbox
->getXDisplay(), geom_window
);
1897 geom_visible
= True
;
1902 sprintf(label
, i18n(ScreenSet
, ScreenPositionFormat
,
1903 "X: %4d x Y: %4d"), x
, y
);
1905 XClearWindow(blackbox
->getXDisplay(), geom_window
);
1907 resource
.wstyle
.font
->drawString(geom_window
,
1908 resource
.bevel_width
, resource
.bevel_width
,
1909 resource
.wstyle
.l_text_focus
,
1914 void BScreen::showGeometry(unsigned int gx
, unsigned int gy
) {
1915 if (! geom_visible
) {
1916 XMoveResizeWindow(blackbox
->getXDisplay(), geom_window
,
1917 (getWidth() - geom_w
) / 2,
1918 (getHeight() - geom_h
) / 2, geom_w
, geom_h
);
1919 XMapWindow(blackbox
->getXDisplay(), geom_window
);
1920 XRaiseWindow(blackbox
->getXDisplay(), geom_window
);
1922 geom_visible
= True
;
1927 sprintf(label
, i18n(ScreenSet
, ScreenGeometryFormat
,
1928 "W: %4d x H: %4d"), gx
, gy
);
1930 XClearWindow(blackbox
->getXDisplay(), geom_window
);
1932 resource
.wstyle
.font
->drawString(geom_window
,
1933 resource
.bevel_width
, resource
.bevel_width
,
1934 resource
.wstyle
.l_text_focus
,
1939 void BScreen::hideGeometry(void) {
1941 XUnmapWindow(blackbox
->getXDisplay(), geom_window
);
1942 geom_visible
= False
;
1947 void BScreen::addStrut(Strut
*strut
) {
1948 strutList
.push_back(strut
);
1952 void BScreen::removeStrut(Strut
*strut
) {
1953 strutList
.remove(strut
);
1957 const Rect
& BScreen::availableArea(void) const {
1959 return getRect(); // return the full screen
1964 void BScreen::updateAvailableArea(void) {
1965 Rect old_area
= usableArea
;
1966 usableArea
= getRect(); // reset to full screen
1968 /* these values represent offsets from the screen edge
1969 * we look for the biggest offset on each edge and then apply them
1971 * do not be confused by the similarity to the names of Rect's members
1973 unsigned int current_left
= 0, current_right
= 0, current_top
= 0,
1976 StrutList::const_iterator it
= strutList
.begin(), end
= strutList
.end();
1978 for(; it
!= end
; ++it
) {
1980 if (strut
->left
> current_left
)
1981 current_left
= strut
->left
;
1982 if (strut
->top
> current_top
)
1983 current_top
= strut
->top
;
1984 if (strut
->right
> current_right
)
1985 current_right
= strut
->right
;
1986 if (strut
->bottom
> current_bottom
)
1987 current_bottom
= strut
->bottom
;
1990 usableArea
.setPos(current_left
, current_top
);
1991 usableArea
.setSize(usableArea
.width() - (current_left
+ current_right
),
1992 usableArea
.height() - (current_top
+ current_bottom
));
1994 if (old_area
!= usableArea
) {
1995 BlackboxWindowList::iterator it
= windowList
.begin(),
1996 end
= windowList
.end();
1997 for (; it
!= end
; ++it
)
1998 if ((*it
)->isMaximized()) (*it
)->remaximize();
2005 Workspace
* BScreen::getWorkspace(unsigned int index
) {
2006 assert(index
< workspacesList
.size());
2007 return workspacesList
[index
];
2011 void BScreen::buttonPressEvent(const XButtonEvent
*xbutton
) {
2012 if (xbutton
->button
== 1) {
2013 if (! isRootColormapInstalled())
2014 image_control
->installRootColormap();
2016 if (workspacemenu
->isVisible())
2017 workspacemenu
->hide();
2019 if (rootmenu
->isVisible())
2021 } else if (xbutton
->button
== 2) {
2022 int mx
= xbutton
->x_root
- (workspacemenu
->getWidth() / 2);
2023 int my
= xbutton
->y_root
- (workspacemenu
->getTitleHeight() / 2);
2028 if (mx
+ workspacemenu
->getWidth() > getWidth())
2029 mx
= getWidth() - workspacemenu
->getWidth() - getBorderWidth();
2031 if (my
+ workspacemenu
->getHeight() > getHeight())
2032 my
= getHeight() - workspacemenu
->getHeight() - getBorderWidth();
2034 workspacemenu
->move(mx
, my
);
2036 if (! workspacemenu
->isVisible()) {
2037 workspacemenu
->removeParent();
2038 workspacemenu
->show();
2040 } else if (xbutton
->button
== 3) {
2041 int mx
= xbutton
->x_root
- (rootmenu
->getWidth() / 2);
2042 int my
= xbutton
->y_root
- (rootmenu
->getTitleHeight() / 2);
2047 if (mx
+ rootmenu
->getWidth() > getWidth())
2048 mx
= getWidth() - rootmenu
->getWidth() - getBorderWidth();
2050 if (my
+ rootmenu
->getHeight() > getHeight())
2051 my
= getHeight() - rootmenu
->getHeight() - getBorderWidth();
2053 rootmenu
->move(mx
, my
);
2055 if (! rootmenu
->isVisible()) {
2056 blackbox
->checkMenu();
2060 } else if (xbutton
->button
== 4) {
2061 if (getCurrentWorkspaceID() >= getWorkspaceCount() - 1)
2062 changeWorkspaceID(0);
2064 changeWorkspaceID(getCurrentWorkspaceID() + 1);
2066 } else if (xbutton
->button
== 5) {
2067 if (getCurrentWorkspaceID() == 0)
2068 changeWorkspaceID(getWorkspaceCount() - 1);
2070 changeWorkspaceID(getCurrentWorkspaceID() - 1);
2075 void BScreen::toggleFocusModel(FocusModel model
) {
2076 std::for_each(windowList
.begin(), windowList
.end(),
2077 std::mem_fun(&BlackboxWindow::ungrabButtons
));
2079 if (model
== SloppyFocus
) {
2080 saveSloppyFocus(True
);
2082 // we're cheating here to save writing the config file 3 times
2083 resource
.auto_raise
= False
;
2084 resource
.click_raise
= False
;
2085 saveSloppyFocus(False
);
2088 std::for_each(windowList
.begin(), windowList
.end(),
2089 std::mem_fun(&BlackboxWindow::grabButtons
));
2093 BTexture
BScreen::readDatabaseTexture(const string
&rname
,
2094 const string
&default_color
,
2095 const Configuration
&style
) {
2099 if (style
.getValue(rname
, s
))
2100 texture
= BTexture(s
);
2102 texture
.setTexture(BTexture::Solid
| BTexture::Flat
);
2104 // associate this texture with this screen
2105 texture
.setDisplay(getBaseDisplay(), getScreenNumber());
2106 texture
.setImageControl(image_control
);
2108 if (texture
.texture() & BTexture::Solid
) {
2109 texture
.setColor(readDatabaseColor(rname
+ ".color",
2110 default_color
, style
));
2111 texture
.setColorTo(readDatabaseColor(rname
+ ".colorTo",
2112 default_color
, style
));
2113 } else if (texture
.texture() & BTexture::Gradient
) {
2114 texture
.setColor(readDatabaseColor(rname
+ ".color",
2115 default_color
, style
));
2116 texture
.setColorTo(readDatabaseColor(rname
+ ".colorTo",
2117 default_color
, style
));
2124 BColor
BScreen::readDatabaseColor(const string
&rname
,
2125 const string
&default_color
,
2126 const Configuration
&style
) {
2129 if (style
.getValue(rname
, s
))
2130 color
= BColor(s
, getBaseDisplay(), getScreenNumber());
2132 color
= BColor(default_color
, getBaseDisplay(), getScreenNumber());
2137 BFont
*BScreen::readDatabaseFont(const string
&rname
,
2138 const Configuration
&style
) {
2142 style
.getValue(rname
, s
); // if this fails, a blank string will be used,
2143 // which will cause the fallback font to load.
2145 BFont
*b
= new BFont(blackbox
->getXDisplay(), this, s
);
2147 exit(2); // can't continue without a font