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());
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::saveAAFonts(bool f
) {
392 resource
.aa_fonts
= f
;
394 config
->setValue(screenstr
+ "antialiasFonts", resource
.aa_fonts
);
398 void BScreen::saveHideToolbar(bool h
) {
399 resource
.hide_toolbar
= h
;
400 if (resource
.hide_toolbar
)
401 toolbar
->unmapToolbar();
403 toolbar
->mapToolbar();
404 config
->setValue(screenstr
+ "hideToolbar", resource
.hide_toolbar
);
408 void BScreen::saveWindowToWindowSnap(bool s
) {
409 resource
.window_to_window_snap
= s
;
410 config
->setValue(screenstr
+ "windowToWindowSnap",
411 resource
.window_to_window_snap
);
415 void BScreen::saveResizeZones(unsigned int z
) {
416 resource
.resize_zones
= z
;
417 config
->setValue(screenstr
+ "resizeZones", resource
.resize_zones
);
421 void BScreen::saveWindowCornerSnap(bool s
) {
422 resource
.window_corner_snap
= s
;
423 config
->setValue(screenstr
+ "windowCornerSnap",
424 resource
.window_corner_snap
);
428 void BScreen::saveWorkspaces(unsigned int w
) {
429 resource
.workspaces
= w
;
430 config
->setValue(screenstr
+ "workspaces", resource
.workspaces
);
434 void BScreen::savePlacementPolicy(int p
) {
435 resource
.placement_policy
= p
;
436 const char *placement
;
437 switch (resource
.placement_policy
) {
438 case CascadePlacement
: placement
= "CascadePlacement"; break;
439 case ColSmartPlacement
: placement
= "ColSmartPlacement"; break;
440 case RowSmartPlacement
: default: placement
= "RowSmartPlacement"; break;
442 config
->setValue(screenstr
+ "windowPlacement", placement
);
446 void BScreen::saveEdgeSnapThreshold(int t
) {
447 resource
.edge_snap_threshold
= t
;
448 config
->setValue(screenstr
+ "edgeSnapThreshold",
449 resource
.edge_snap_threshold
);
453 void BScreen::saveRowPlacementDirection(int d
) {
454 resource
.row_direction
= d
;
455 config
->setValue(screenstr
+ "rowPlacementDirection",
456 resource
.row_direction
== LeftRight
?
457 "LeftToRight" : "RightToLeft");
461 void BScreen::saveColPlacementDirection(int d
) {
462 resource
.col_direction
= d
;
463 config
->setValue(screenstr
+ "colPlacementDirection",
464 resource
.col_direction
== TopBottom
?
465 "TopToBottom" : "BottomToTop");
470 void BScreen::saveStrftimeFormat(const std::string
& format
) {
471 resource
.strftime_format
= format
;
472 config
->setValue(screenstr
+ "strftimeFormat", resource
.strftime_format
);
475 #else // !HAVE_STRFTIME
477 void BScreen::saveDateFormat(int f
) {
478 resource
.date_format
= f
;
479 config
->setValue(screenstr
+ "dateFormat",
480 resource
.date_format
== B_EuropeanDate
?
481 "European" : "American");
485 void BScreen::saveClock24Hour(Bool c
) {
486 resource
.clock24hour
= c
;
487 config
->setValue(screenstr
+ "clockFormat", resource
.clock24hour
? 24 : 12);
489 #endif // HAVE_STRFTIME
492 void BScreen::saveWorkspaceNames() {
493 XAtom::StringVect nameList
;
494 unsigned long numnames
= (unsigned) -1;
498 xatom
->getValue(getRootWindow(), XAtom::net_desktop_names
, XAtom::utf8
,
499 numnames
, nameList
)) {
500 for (unsigned int i
= 0; i
< nameList
.size(); ++i
) {
501 if (i
> 0) names
+= ",";
502 names
+= nameList
[i
];
505 config
->setValue(screenstr
+ "workspaceNames", names
);
509 void BScreen::save_rc(void) {
510 saveSloppyFocus(resource
.sloppy_focus
);
511 saveAutoRaise(resource
.auto_raise
);
512 saveImageDither(doImageDither());
513 saveAAFonts(resource
.aa_fonts
);
514 saveResizeZones(resource
.resize_zones
);
515 saveOpaqueMove(resource
.opaque_move
);
516 saveFullMax(resource
.full_max
);
517 saveFocusNew(resource
.focus_new
);
518 saveFocusLast(resource
.focus_last
);
519 saveHideToolbar(resource
.hide_toolbar
);
520 saveWindowToWindowSnap(resource
.window_to_window_snap
);
521 saveWindowCornerSnap(resource
.window_corner_snap
);
522 saveWorkspaces(resource
.workspaces
);
523 savePlacementPolicy(resource
.placement_policy
);
524 saveEdgeSnapThreshold(resource
.edge_snap_threshold
);
525 saveRowPlacementDirection(resource
.row_direction
);
526 saveColPlacementDirection(resource
.col_direction
);
528 saveStrftimeFormat(resource
.strftime_format
);
529 #else // !HAVE_STRFTIME
530 saveDateFormat(resource
.date_format
);
531 savwClock24Hour(resource
.clock24hour
);
532 #endif // HAVE_STRFTIME
539 void BScreen::load_rc(void) {
543 if (! config
->getValue(screenstr
+ "fullMaximization", resource
.full_max
))
544 resource
.full_max
= false;
546 if (! config
->getValue(screenstr
+ "focusNewWindows", resource
.focus_new
))
547 resource
.focus_new
= false;
549 if (! config
->getValue(screenstr
+ "focusLastWindow", resource
.focus_last
))
550 resource
.focus_last
= false;
552 if (! config
->getValue(screenstr
+ "workspaces", resource
.workspaces
))
553 resource
.workspaces
= 1;
555 if (! config
->getValue(screenstr
+ "opaqueMove", resource
.opaque_move
))
556 resource
.opaque_move
= false;
558 if (! config
->getValue(screenstr
+ "antialiasFonts", resource
.aa_fonts
))
559 resource
.aa_fonts
= true;
561 if (! config
->getValue(screenstr
+ "resizeZones", resource
.resize_zones
) ||
562 (resource
.resize_zones
!= 1 && resource
.resize_zones
!= 2 &&
563 resource
.resize_zones
!= 4))
564 resource
.resize_zones
= 4;
566 if (! config
->getValue(screenstr
+ "hideToolbar", resource
.hide_toolbar
))
567 resource
.hide_toolbar
= false;
569 if (! config
->getValue(screenstr
+ "windowToWindowSnap",
570 resource
.window_to_window_snap
))
571 resource
.window_to_window_snap
= true;
573 if (! config
->getValue(screenstr
+ "windowCornerSnap",
574 resource
.window_corner_snap
))
575 resource
.window_corner_snap
= true;
577 if (! config
->getValue(screenstr
+ "imageDither", b
))
579 image_control
->setDither(b
);
581 if (! config
->getValue(screenstr
+ "edgeSnapThreshold",
582 resource
.edge_snap_threshold
))
583 resource
.edge_snap_threshold
= 4;
585 if (config
->getValue(screenstr
+ "rowPlacementDirection", s
) &&
587 resource
.row_direction
= RightLeft
;
589 resource
.row_direction
= LeftRight
;
591 if (config
->getValue(screenstr
+ "colPlacementDirection", s
) &&
593 resource
.col_direction
= BottomTop
;
595 resource
.col_direction
= TopBottom
;
597 XAtom::StringVect workspaceNames
;
598 if (config
->getValue(screenstr
+ "workspaceNames", s
)) {
599 string::const_iterator it
= s
.begin(), end
= s
.end();
601 string::const_iterator tmp
= it
; // current string.begin()
602 it
= std::find(tmp
, end
, ','); // look for comma between tmp and end
603 workspaceNames
.push_back(string(tmp
, it
)); // s[tmp:it]
609 xatom
->setValue(getRootWindow(), XAtom::net_desktop_names
, XAtom::utf8
,
612 resource
.sloppy_focus
= true;
613 resource
.auto_raise
= false;
614 resource
.click_raise
= false;
615 if (config
->getValue(screenstr
+ "focusModel", s
)) {
616 if (s
.find("ClickToFocus") != string::npos
) {
617 resource
.sloppy_focus
= false;
620 if (s
.find("AutoRaise") != string::npos
)
621 resource
.auto_raise
= true;
622 if (s
.find("ClickRaise") != string::npos
)
623 resource
.click_raise
= true;
627 if (config
->getValue(screenstr
+ "windowPlacement", s
)) {
628 if (s
== "CascadePlacement")
629 resource
.placement_policy
= CascadePlacement
;
630 else if (s
== "ColSmartPlacement")
631 resource
.placement_policy
= ColSmartPlacement
;
632 else //if (s == "RowSmartPlacement")
633 resource
.placement_policy
= RowSmartPlacement
;
635 resource
.placement_policy
= RowSmartPlacement
;
638 if (config
->getValue(screenstr
+ "strftimeFormat", s
))
639 resource
.strftime_format
= s
;
641 resource
.strftime_format
= "%I:%M %p";
642 #else // !HAVE_STRFTIME
645 if (config
->getValue(screenstr
+ "dateFormat", s
) && s
== "European")
646 resource
.date_format
= B_EuropeanDate
;
648 resource
.date_format
= B_AmericanDate
;
650 if (! config
->getValue(screenstr
+ "clockFormat", l
))
652 resource
.clock24hour
= l
== 24;
653 #endif // HAVE_STRFTIME
657 void BScreen::reconfigure(void) {
664 gcv
.foreground
= WhitePixel(blackbox
->getXDisplay(),
666 gcv
.function
= GXinvert
;
667 gcv
.subwindow_mode
= IncludeInferiors
;
668 XChangeGC(blackbox
->getXDisplay(), opGC
,
669 GCForeground
| GCFunction
| GCSubwindowMode
, &gcv
);
671 const char *s
= i18n(ScreenSet
, ScreenPositionLength
,
672 "0: 0000 x 0: 0000");
674 geom_w
= resource
.wstyle
.font
->measureString(s
) + resource
.bevel_width
* 2;
675 geom_h
= resource
.wstyle
.font
->height() + resource
.bevel_width
* 2;
677 BTexture
* texture
= &(resource
.wstyle
.l_focus
);
678 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
679 if (geom_pixmap
== ParentRelative
) {
680 texture
= &(resource
.wstyle
.t_focus
);
681 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
684 XSetWindowBackground(blackbox
->getXDisplay(), geom_window
,
685 texture
->color().pixel());
687 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
688 geom_window
, geom_pixmap
);
690 XSetWindowBorderWidth(blackbox
->getXDisplay(), geom_window
,
691 resource
.border_width
);
692 XSetWindowBorder(blackbox
->getXDisplay(), geom_window
,
693 resource
.border_color
.pixel());
695 workspacemenu
->reconfigure();
696 iconmenu
->reconfigure();
698 typedef std::vector
<int> SubList
;
699 SubList remember_subs
;
701 // save the current open menus
702 Basemenu
*menu
= rootmenu
;
704 while ((submenu
= menu
->getCurrentSubmenu()) >= 0) {
705 remember_subs
.push_back(submenu
);
706 menu
= menu
->find(submenu
)->submenu();
712 rootmenu
->reconfigure();
714 // reopen the saved menus
716 const SubList::iterator subs_end
= remember_subs
.end();
717 for (SubList::iterator it
= remember_subs
.begin(); it
!= subs_end
; ++it
) {
718 menu
->drawSubmenu(*it
);
719 menu
= menu
->find(*it
)->submenu();
724 configmenu
->reconfigure();
726 toolbar
->reconfigure();
730 std::for_each(workspacesList
.begin(), workspacesList
.end(),
731 std::mem_fun(&Workspace::reconfigure
));
733 BlackboxWindowList::iterator iit
= iconList
.begin();
734 for (; iit
!= iconList
.end(); ++iit
) {
735 BlackboxWindow
*bw
= *iit
;
736 if (bw
->validateClient())
740 image_control
->timeout();
744 void BScreen::rereadMenu(void) {
748 rootmenu
->reconfigure();
752 void BScreen::LoadStyle(void) {
753 Configuration
style(False
);
755 const char *sfile
= blackbox
->getStyleFilename();
757 style
.setFile(sfile
);
758 if (! style
.load()) {
759 style
.setFile(DEFAULTSTYLE
);
761 style
.create(); // hardcoded default values will be used.
765 // merge in the rc file
766 style
.merge(config
->file(), True
);
770 // load fonts/fontsets
771 if (resource
.wstyle
.font
)
772 delete resource
.wstyle
.font
;
773 if (resource
.tstyle
.font
)
774 delete resource
.tstyle
.font
;
775 if (resource
.mstyle
.f_font
)
776 delete resource
.mstyle
.f_font
;
777 if (resource
.mstyle
.t_font
)
778 delete resource
.mstyle
.t_font
;
779 resource
.wstyle
.font
= resource
.tstyle
.font
= resource
.mstyle
.f_font
=
780 resource
.mstyle
.t_font
= (BFont
*) 0;
782 resource
.wstyle
.font
= readDatabaseFont("window.", style
);
783 resource
.tstyle
.font
= readDatabaseFont("toolbar.", style
);
784 resource
.mstyle
.t_font
= readDatabaseFont("menu.title.", style
);
785 resource
.mstyle
.f_font
= readDatabaseFont("menu.frame.", style
);
787 // load window config
788 resource
.wstyle
.t_focus
=
789 readDatabaseTexture("window.title.focus", "white", style
);
790 resource
.wstyle
.t_unfocus
=
791 readDatabaseTexture("window.title.unfocus", "black", style
);
792 resource
.wstyle
.l_focus
=
793 readDatabaseTexture("window.label.focus", "white", style
);
794 resource
.wstyle
.l_unfocus
=
795 readDatabaseTexture("window.label.unfocus", "black", style
);
796 resource
.wstyle
.h_focus
=
797 readDatabaseTexture("window.handle.focus", "white", style
);
798 resource
.wstyle
.h_unfocus
=
799 readDatabaseTexture("window.handle.unfocus", "black", style
);
800 resource
.wstyle
.g_focus
=
801 readDatabaseTexture("window.grip.focus", "white", style
);
802 resource
.wstyle
.g_unfocus
=
803 readDatabaseTexture("window.grip.unfocus", "black", style
);
804 resource
.wstyle
.b_focus
=
805 readDatabaseTexture("window.button.focus", "white", style
);
806 resource
.wstyle
.b_unfocus
=
807 readDatabaseTexture("window.button.unfocus", "black", style
);
808 resource
.wstyle
.b_pressed
=
809 readDatabaseTexture("window.button.pressed", "black", style
);
810 resource
.wstyle
.f_focus
=
811 readDatabaseColor("window.frame.focusColor", "white", style
);
812 resource
.wstyle
.f_unfocus
=
813 readDatabaseColor("window.frame.unfocusColor", "black", style
);
814 resource
.wstyle
.l_text_focus
=
815 readDatabaseColor("window.label.focus.textColor", "black", style
);
816 resource
.wstyle
.l_text_unfocus
=
817 readDatabaseColor("window.label.unfocus.textColor", "white", style
);
818 resource
.wstyle
.b_pic_focus
=
819 readDatabaseColor("window.button.focus.picColor", "black", style
);
820 resource
.wstyle
.b_pic_unfocus
=
821 readDatabaseColor("window.button.unfocus.picColor", "white", style
);
823 resource
.wstyle
.justify
= LeftJustify
;
824 if (style
.getValue("window.justify", s
)) {
825 if (s
== "right" || s
== "Right")
826 resource
.wstyle
.justify
= RightJustify
;
827 else if (s
== "center" || s
== "Center")
828 resource
.wstyle
.justify
= CenterJustify
;
831 // load toolbar config
832 resource
.tstyle
.toolbar
=
833 readDatabaseTexture("toolbar", "black", style
);
834 resource
.tstyle
.label
=
835 readDatabaseTexture("toolbar.label", "black", style
);
836 resource
.tstyle
.window
=
837 readDatabaseTexture("toolbar.windowLabel", "black", style
);
838 resource
.tstyle
.button
=
839 readDatabaseTexture("toolbar.button", "white", style
);
840 resource
.tstyle
.pressed
=
841 readDatabaseTexture("toolbar.button.pressed", "black", style
);
842 resource
.tstyle
.clock
=
843 readDatabaseTexture("toolbar.clock", "black", style
);
844 resource
.tstyle
.l_text
=
845 readDatabaseColor("toolbar.label.textColor", "white", style
);
846 resource
.tstyle
.w_text
=
847 readDatabaseColor("toolbar.windowLabel.textColor", "white", style
);
848 resource
.tstyle
.c_text
=
849 readDatabaseColor("toolbar.clock.textColor", "white", style
);
850 resource
.tstyle
.b_pic
=
851 readDatabaseColor("toolbar.button.picColor", "black", style
);
853 resource
.tstyle
.justify
= LeftJustify
;
854 if (style
.getValue("toolbar.justify", s
)) {
855 if (s
== "right" || s
== "Right")
856 resource
.tstyle
.justify
= RightJustify
;
857 else if (s
== "center" || s
== "Center")
858 resource
.tstyle
.justify
= CenterJustify
;
862 resource
.mstyle
.title
=
863 readDatabaseTexture("menu.title", "white", style
);
864 resource
.mstyle
.frame
=
865 readDatabaseTexture("menu.frame", "black", style
);
866 resource
.mstyle
.hilite
=
867 readDatabaseTexture("menu.hilite", "white", style
);
868 resource
.mstyle
.t_text
=
869 readDatabaseColor("menu.title.textColor", "black", style
);
870 resource
.mstyle
.f_text
=
871 readDatabaseColor("menu.frame.textColor", "white", style
);
872 resource
.mstyle
.d_text
=
873 readDatabaseColor("menu.frame.disableColor", "black", style
);
874 resource
.mstyle
.h_text
=
875 readDatabaseColor("menu.hilite.textColor", "black", style
);
877 resource
.mstyle
.t_justify
= LeftJustify
;
878 if (style
.getValue("menu.title.justify", s
)) {
879 if (s
== "right" || s
== "Right")
880 resource
.mstyle
.t_justify
= RightJustify
;
881 else if (s
== "center" || s
== "Center")
882 resource
.mstyle
.t_justify
= CenterJustify
;
885 resource
.mstyle
.f_justify
= LeftJustify
;
886 if (style
.getValue("menu.frame.justify", s
)) {
887 if (s
== "right" || s
== "Right")
888 resource
.mstyle
.f_justify
= RightJustify
;
889 else if (s
== "center" || s
== "Center")
890 resource
.mstyle
.f_justify
= CenterJustify
;
893 resource
.mstyle
.bullet
= Basemenu::Triangle
;
894 if (style
.getValue("menu.bullet", s
)) {
895 if (s
== "empty" || s
== "Empty")
896 resource
.mstyle
.bullet
= Basemenu::Empty
;
897 else if (s
== "square" || s
== "Square")
898 resource
.mstyle
.bullet
= Basemenu::Square
;
899 else if (s
== "diamond" || s
== "Diamond")
900 resource
.mstyle
.bullet
= Basemenu::Diamond
;
903 resource
.mstyle
.bullet_pos
= Basemenu::Left
;
904 if (style
.getValue("menu.bullet.position", s
)) {
905 if (s
== "right" || s
== "Right")
906 resource
.mstyle
.bullet_pos
= Basemenu::Right
;
909 resource
.border_color
=
910 readDatabaseColor("borderColor", "black", style
);
912 // load bevel, border and handle widths
913 if (! style
.getValue("handleWidth", resource
.handle_width
) ||
914 resource
.handle_width
> (getWidth() / 2) || resource
.handle_width
== 0)
915 resource
.handle_width
= 6;
917 if (! style
.getValue("borderWidth", resource
.border_width
))
918 resource
.border_width
= 1;
920 if (! style
.getValue("bevelWidth", resource
.bevel_width
) ||
921 resource
.bevel_width
> (getWidth() / 2) || resource
.bevel_width
== 0)
922 resource
.bevel_width
= 3;
924 if (! style
.getValue("frameWidth", resource
.frame_width
) ||
925 resource
.frame_width
> (getWidth() / 2))
926 resource
.frame_width
= resource
.bevel_width
;
928 if (style
.getValue("rootCommand", s
))
929 bexec(s
, displayString());
933 void BScreen::addIcon(BlackboxWindow
*w
) {
936 w
->setWorkspace(BSENTINEL
);
937 w
->setWindowNumber(iconList
.size());
939 iconList
.push_back(w
);
941 const char* title
= w
->getIconTitle();
942 iconmenu
->insert(title
);
947 void BScreen::removeIcon(BlackboxWindow
*w
) {
952 iconmenu
->remove(w
->getWindowNumber());
955 BlackboxWindowList::iterator it
= iconList
.begin(),
956 end
= iconList
.end();
957 for (int i
= 0; it
!= end
; ++it
)
958 (*it
)->setWindowNumber(i
++);
962 BlackboxWindow
*BScreen::getIcon(unsigned int index
) {
963 if (index
< iconList
.size()) {
964 BlackboxWindowList::iterator it
= iconList
.begin();
965 for (; index
> 0; --index
, ++it
) ; /* increment to index */
969 return (BlackboxWindow
*) 0;
973 unsigned int BScreen::addWorkspace(void) {
974 Workspace
*wkspc
= new Workspace(this, workspacesList
.size());
975 workspacesList
.push_back(wkspc
);
976 saveWorkspaces(getWorkspaceCount());
978 workspacemenu
->insert(wkspc
->getName(), wkspc
->getMenu(),
980 workspacemenu
->update();
982 toolbar
->reconfigure();
984 updateNetizenWorkspaceCount();
986 return workspacesList
.size();
990 unsigned int BScreen::removeLastWorkspace(void) {
991 if (workspacesList
.size() == 1)
994 Workspace
*wkspc
= workspacesList
.back();
996 if (current_workspace
->getID() == wkspc
->getID())
997 changeWorkspaceID(current_workspace
->getID() - 1);
1001 workspacemenu
->remove(wkspc
->getID() + 2);
1002 workspacemenu
->update();
1004 workspacesList
.pop_back();
1007 saveWorkspaces(getWorkspaceCount());
1009 toolbar
->reconfigure();
1011 updateNetizenWorkspaceCount();
1013 return workspacesList
.size();
1017 void BScreen::changeWorkspaceID(unsigned int id
) {
1018 if (! current_workspace
|| id
== current_workspace
->getID()) return;
1020 BlackboxWindow
*focused
= blackbox
->getFocusedWindow();
1021 if (focused
&& focused
->getScreen() == this) {
1022 assert(focused
->isStuck() ||
1023 focused
->getWorkspaceNumber() == current_workspace
->getID());
1025 current_workspace
->setLastFocusedWindow(focused
);
1027 // if no window had focus, no need to store a last focus
1028 current_workspace
->setLastFocusedWindow((BlackboxWindow
*) 0);
1031 // when we switch workspaces, unfocus whatever was focused
1032 blackbox
->setFocusedWindow((BlackboxWindow
*) 0);
1034 current_workspace
->hideAll();
1035 workspacemenu
->setItemSelected(current_workspace
->getID() + 2, False
);
1037 current_workspace
= getWorkspace(id
);
1039 xatom
->setValue(getRootWindow(), XAtom::net_current_desktop
,
1040 XAtom::cardinal
, id
);
1042 workspacemenu
->setItemSelected(current_workspace
->getID() + 2, True
);
1043 toolbar
->redrawWorkspaceLabel(True
);
1045 current_workspace
->showAll();
1047 if (resource
.focus_last
&& current_workspace
->getLastFocusedWindow()) {
1048 XSync(blackbox
->getXDisplay(), False
);
1049 current_workspace
->getLastFocusedWindow()->setInputFocus();
1052 updateNetizenCurrentWorkspace();
1057 * Set the _NET_CLIENT_LIST root window property.
1059 void BScreen::updateClientList(void) {
1060 if (windowList
.size() > 0) {
1061 Window
*windows
= new Window
[windowList
.size()];
1062 Window
*win_it
= windows
;
1063 BlackboxWindowList::iterator it
= windowList
.begin();
1064 const BlackboxWindowList::iterator end
= windowList
.end();
1065 for (; it
!= end
; ++it
, ++win_it
)
1066 *win_it
= (*it
)->getClientWindow();
1067 xatom
->setValue(getRootWindow(), XAtom::net_client_list
, XAtom::window
,
1068 windows
, windowList
.size());
1071 xatom
->setValue(getRootWindow(), XAtom::net_client_list
, XAtom::window
,
1074 updateStackingList();
1079 * Set the _NET_CLIENT_LIST_STACKING root window property.
1081 void BScreen::updateStackingList(void) {
1083 BlackboxWindowList stack_order
;
1086 * Get the stacking order from all of the workspaces.
1087 * We start with the current workspace so that the sticky windows will be
1088 * in the right order on the current workspace.
1089 * XXX: Do we need to have sticky windows in the list once for each workspace?
1091 getCurrentWorkspace()->appendStackOrder(stack_order
);
1092 for (unsigned int i
= 0; i
< getWorkspaceCount(); ++i
)
1093 if (i
!= getCurrentWorkspaceID())
1094 getWorkspace(i
)->appendStackOrder(stack_order
);
1096 if (stack_order
.size() > 0) {
1097 // set the client list atoms
1098 Window
*windows
= new Window
[stack_order
.size()];
1099 Window
*win_it
= windows
;
1100 BlackboxWindowList::iterator it
= stack_order
.begin(),
1101 end
= stack_order
.end();
1102 for (; it
!= end
; ++it
, ++win_it
)
1103 *win_it
= (*it
)->getClientWindow();
1104 xatom
->setValue(getRootWindow(), XAtom::net_client_list_stacking
,
1105 XAtom::window
, windows
, stack_order
.size());
1108 xatom
->setValue(getRootWindow(), XAtom::net_client_list_stacking
,
1109 XAtom::window
, 0, 0);
1113 void BScreen::addSystrayWindow(Window window
) {
1114 systrayWindowList
.push_back(window
);
1115 xatom
->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows
,
1117 &systrayWindowList
[0], systrayWindowList
.size());
1118 blackbox
->saveSystrayWindowSearch(window
, this);
1122 void BScreen::removeSystrayWindow(Window window
) {
1123 WindowList::iterator it
= systrayWindowList
.begin();
1124 const WindowList::iterator end
= systrayWindowList
.end();
1125 for (; it
!= end
; ++it
)
1126 if (*it
== window
) {
1127 systrayWindowList
.erase(it
);
1128 xatom
->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows
,
1130 &systrayWindowList
[0], systrayWindowList
.size());
1131 blackbox
->removeSystrayWindowSearch(window
);
1137 void BScreen::addDesktopWindow(Window window
) {
1138 desktopWindowList
.push_back(window
);
1139 XLowerWindow(blackbox
->getXDisplay(), window
);
1140 XSelectInput(blackbox
->getXDisplay(), window
, StructureNotifyMask
);
1141 blackbox
->saveDesktopWindowSearch(window
, this);
1145 void BScreen::removeDesktopWindow(Window window
) {
1146 WindowList::iterator it
= desktopWindowList
.begin();
1147 const WindowList::iterator end
= desktopWindowList
.end();
1148 for (; it
!= end
; ++it
)
1149 if (*it
== window
) {
1150 desktopWindowList
.erase(it
);
1151 XSelectInput(blackbox
->getXDisplay(), window
, None
);
1152 blackbox
->removeDesktopWindowSearch(window
);
1158 void BScreen::manageWindow(Window w
) {
1159 new BlackboxWindow(blackbox
, w
, this);
1161 BlackboxWindow
*win
= blackbox
->searchWindow(w
);
1164 if (win
->isDesktop()) {
1165 // desktop windows cant do anything, so we remove all the normal window
1166 // stuff from them, they are only kept around so that we can keep them on
1167 // the bottom of the z-order
1169 addDesktopWindow(win
->getClientWindow());
1174 windowList
.push_back(win
);
1177 XMapRequestEvent mre
;
1179 if (blackbox
->isStartup()) win
->restoreAttributes();
1180 win
->mapRequestEvent(&mre
);
1184 void BScreen::unmanageWindow(BlackboxWindow
*w
, bool remap
) {
1187 if (w
->getWorkspaceNumber() != BSENTINEL
&&
1188 w
->getWindowNumber() != BSENTINEL
)
1189 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
1190 else if (w
->isIconic())
1193 windowList
.remove(w
);
1196 if (blackbox
->getFocusedWindow() == w
)
1197 blackbox
->setFocusedWindow((BlackboxWindow
*) 0);
1199 removeNetizen(w
->getClientWindow());
1202 some managed windows can also be window group controllers. when
1203 unmanaging such windows, we should also delete the window group.
1205 BWindowGroup
*group
= blackbox
->searchGroup(w
->getClientWindow());
1212 void BScreen::addNetizen(Netizen
*n
) {
1213 netizenList
.push_back(n
);
1215 n
->sendWorkspaceCount();
1216 n
->sendCurrentWorkspace();
1218 WorkspaceList::iterator it
= workspacesList
.begin();
1219 const WorkspaceList::iterator end
= workspacesList
.end();
1220 for (; it
!= end
; ++it
)
1221 (*it
)->sendWindowList(*n
);
1223 Window f
= ((blackbox
->getFocusedWindow()) ?
1224 blackbox
->getFocusedWindow()->getClientWindow() : None
);
1225 n
->sendWindowFocus(f
);
1229 void BScreen::removeNetizen(Window w
) {
1230 NetizenList::iterator it
= netizenList
.begin();
1231 for (; it
!= netizenList
.end(); ++it
) {
1232 if ((*it
)->getWindowID() == w
) {
1234 netizenList
.erase(it
);
1241 void BScreen::updateWorkArea(void) {
1242 if (workspacesList
.size() > 0) {
1243 unsigned long *dims
= new unsigned long[4 * workspacesList
.size()];
1244 for (unsigned int i
= 0, m
= workspacesList
.size(); i
< m
; ++i
) {
1245 // XXX: this could be different for each workspace
1246 const Rect
&area
= availableArea();
1247 dims
[(i
* 4) + 0] = area
.x();
1248 dims
[(i
* 4) + 1] = area
.y();
1249 dims
[(i
* 4) + 2] = area
.width();
1250 dims
[(i
* 4) + 3] = area
.height();
1252 xatom
->setValue(getRootWindow(), XAtom::net_workarea
, XAtom::cardinal
,
1253 dims
, 4 * workspacesList
.size());
1256 xatom
->setValue(getRootWindow(), XAtom::net_workarea
, XAtom::cardinal
,
1261 void BScreen::updateNetizenCurrentWorkspace(void) {
1262 std::for_each(netizenList
.begin(), netizenList
.end(),
1263 std::mem_fun(&Netizen::sendCurrentWorkspace
));
1267 void BScreen::updateNetizenWorkspaceCount(void) {
1268 xatom
->setValue(getRootWindow(), XAtom::net_number_of_desktops
,
1269 XAtom::cardinal
, workspacesList
.size());
1273 std::for_each(netizenList
.begin(), netizenList
.end(),
1274 std::mem_fun(&Netizen::sendWorkspaceCount
));
1278 void BScreen::updateNetizenWindowFocus(void) {
1279 Window f
= ((blackbox
->getFocusedWindow()) ?
1280 blackbox
->getFocusedWindow()->getClientWindow() : None
);
1282 xatom
->setValue(getRootWindow(), XAtom::net_active_window
,
1285 NetizenList::iterator it
= netizenList
.begin();
1286 for (; it
!= netizenList
.end(); ++it
)
1287 (*it
)->sendWindowFocus(f
);
1291 void BScreen::updateNetizenWindowAdd(Window w
, unsigned long p
) {
1292 NetizenList::iterator it
= netizenList
.begin();
1293 for (; it
!= netizenList
.end(); ++it
) {
1294 (*it
)->sendWindowAdd(w
, p
);
1299 void BScreen::updateNetizenWindowDel(Window w
) {
1300 NetizenList::iterator it
= netizenList
.begin();
1301 for (; it
!= netizenList
.end(); ++it
)
1302 (*it
)->sendWindowDel(w
);
1306 void BScreen::updateNetizenWindowRaise(Window w
) {
1307 NetizenList::iterator it
= netizenList
.begin();
1308 for (; it
!= netizenList
.end(); ++it
)
1309 (*it
)->sendWindowRaise(w
);
1313 void BScreen::updateNetizenWindowLower(Window w
) {
1314 NetizenList::iterator it
= netizenList
.begin();
1315 for (; it
!= netizenList
.end(); ++it
)
1316 (*it
)->sendWindowLower(w
);
1320 void BScreen::updateNetizenConfigNotify(XEvent
*e
) {
1321 NetizenList::iterator it
= netizenList
.begin();
1322 for (; it
!= netizenList
.end(); ++it
)
1323 (*it
)->sendConfigNotify(e
);
1327 void BScreen::raiseWindows(Window
*workspace_stack
, unsigned int num
) {
1328 // the 13 represents the number of blackbox windows such as menus
1329 Window
*session_stack
= new
1330 Window
[(num
+ workspacesList
.size() + rootmenuList
.size() + 13)];
1331 unsigned int i
= 0, k
= num
;
1333 XRaiseWindow(blackbox
->getXDisplay(), iconmenu
->getWindowID());
1334 *(session_stack
+ i
++) = iconmenu
->getWindowID();
1336 WorkspaceList::iterator wit
= workspacesList
.begin();
1337 const WorkspaceList::iterator w_end
= workspacesList
.end();
1338 for (; wit
!= w_end
; ++wit
)
1339 *(session_stack
+ i
++) = (*wit
)->getMenu()->getWindowID();
1341 *(session_stack
+ i
++) = workspacemenu
->getWindowID();
1343 *(session_stack
+ i
++) = configmenu
->getFocusmenu()->getWindowID();
1344 *(session_stack
+ i
++) = configmenu
->getPlacementmenu()->getWindowID();
1345 *(session_stack
+ i
++) = configmenu
->getWindowID();
1347 *(session_stack
+ i
++) = slit
->getMenu()->getDirectionmenu()->getWindowID();
1348 *(session_stack
+ i
++) = slit
->getMenu()->getPlacementmenu()->getWindowID();
1349 *(session_stack
+ i
++) = slit
->getMenu()->getWindowID();
1351 *(session_stack
+ i
++) =
1352 toolbar
->getMenu()->getPlacementmenu()->getWindowID();
1353 *(session_stack
+ i
++) = toolbar
->getMenu()->getWindowID();
1355 RootmenuList::iterator rit
= rootmenuList
.begin();
1356 for (; rit
!= rootmenuList
.end(); ++rit
)
1357 *(session_stack
+ i
++) = (*rit
)->getWindowID();
1358 *(session_stack
+ i
++) = rootmenu
->getWindowID();
1360 if (toolbar
->isOnTop())
1361 *(session_stack
+ i
++) = toolbar
->getWindowID();
1363 if (slit
->isOnTop())
1364 *(session_stack
+ i
++) = slit
->getWindowID();
1367 *(session_stack
+ i
++) = *(workspace_stack
+ k
);
1369 XRestackWindows(blackbox
->getXDisplay(), session_stack
, i
);
1371 delete [] session_stack
;
1373 updateStackingList();
1377 void BScreen::lowerDesktops(void) {
1378 if (desktopWindowList
.empty()) return;
1380 XLowerWindow(blackbox
->getXDisplay(), desktopWindowList
[0]);
1381 if (desktopWindowList
.size() > 1)
1382 XRestackWindows(blackbox
->getXDisplay(), &desktopWindowList
[0],
1383 desktopWindowList
.size());
1387 void BScreen::reassociateWindow(BlackboxWindow
*w
, unsigned int wkspc_id
,
1388 bool ignore_sticky
) {
1391 if (wkspc_id
== BSENTINEL
)
1392 wkspc_id
= current_workspace
->getID();
1394 if (w
->getWorkspaceNumber() == wkspc_id
)
1397 if (w
->isIconic()) {
1399 getWorkspace(wkspc_id
)->addWindow(w
);
1400 } else if (ignore_sticky
|| ! w
->isStuck()) {
1401 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
1402 getWorkspace(wkspc_id
)->addWindow(w
);
1404 updateStackingList();
1408 void BScreen::propagateWindowName(const BlackboxWindow
*bw
) {
1409 if (bw
->isIconic()) {
1410 iconmenu
->changeItemLabel(bw
->getWindowNumber(), bw
->getIconTitle());
1414 Clientmenu
*clientmenu
= getWorkspace(bw
->getWorkspaceNumber())->getMenu();
1415 clientmenu
->changeItemLabel(bw
->getWindowNumber(), bw
->getTitle());
1416 clientmenu
->update();
1418 if (blackbox
->getFocusedWindow() == bw
)
1419 toolbar
->redrawWindowLabel(True
);
1424 void BScreen::nextFocus(void) {
1425 BlackboxWindow
*focused
= blackbox
->getFocusedWindow(),
1429 // if window is not on this screen, ignore it
1430 if (focused
->getScreen()->getScreenNumber() != getScreenNumber())
1431 focused
= (BlackboxWindow
*) 0;
1434 if (focused
&& current_workspace
->getCount() > 1) {
1435 // next is the next window to recieve focus, current is a place holder
1436 BlackboxWindow
*current
;
1439 next
= current_workspace
->getNextWindowInList(current
);
1440 } while(! next
->setInputFocus() && next
!= focused
);
1442 if (next
!= focused
)
1443 current_workspace
->raiseWindow(next
);
1444 } else if (current_workspace
->getCount() >= 1) {
1445 next
= current_workspace
->getTopWindowOnStack();
1447 current_workspace
->raiseWindow(next
);
1448 next
->setInputFocus();
1453 void BScreen::prevFocus(void) {
1454 BlackboxWindow
*focused
= blackbox
->getFocusedWindow(),
1458 // if window is not on this screen, ignore it
1459 if (focused
->getScreen()->getScreenNumber() != getScreenNumber())
1460 focused
= (BlackboxWindow
*) 0;
1463 if (focused
&& current_workspace
->getCount() > 1) {
1464 // next is the next window to recieve focus, current is a place holder
1465 BlackboxWindow
*current
;
1468 next
= current_workspace
->getPrevWindowInList(current
);
1469 } while(! next
->setInputFocus() && next
!= focused
);
1471 if (next
!= focused
)
1472 current_workspace
->raiseWindow(next
);
1473 } else if (current_workspace
->getCount() >= 1) {
1474 next
= current_workspace
->getTopWindowOnStack();
1476 current_workspace
->raiseWindow(next
);
1477 next
->setInputFocus();
1482 void BScreen::raiseFocus(void) {
1483 BlackboxWindow
*focused
= blackbox
->getFocusedWindow();
1487 // if on this Screen, raise it
1488 if (focused
->getScreen()->getScreenNumber() == getScreenNumber()) {
1489 Workspace
*workspace
= getWorkspace(focused
->getWorkspaceNumber());
1490 workspace
->raiseWindow(focused
);
1495 void BScreen::InitMenu(void) {
1497 rootmenuList
.clear();
1499 while (rootmenu
->getCount())
1500 rootmenu
->remove(0);
1502 rootmenu
= new Rootmenu(this);
1504 bool defaultMenu
= True
;
1506 FILE *menu_file
= (FILE *) 0;
1507 const char *menu_filename
= blackbox
->getMenuFilename();
1510 if (! (menu_file
= fopen(menu_filename
, "r")))
1511 perror(menu_filename
);
1512 if (! menu_file
) { // opening the menu file failed, try the default menu
1513 menu_filename
= DEFAULTMENU
;
1514 if (! (menu_file
= fopen(menu_filename
, "r")))
1515 perror(menu_filename
);
1519 if (feof(menu_file
)) {
1520 fprintf(stderr
, i18n(ScreenSet
, ScreenEmptyMenuFile
,
1521 "%s: Empty menu file"),
1524 char line
[1024], label
[1024];
1525 memset(line
, 0, 1024);
1526 memset(label
, 0, 1024);
1528 while (fgets(line
, 1024, menu_file
) && ! feof(menu_file
)) {
1529 if (line
[0] != '#') {
1530 int i
, key
= 0, index
= -1, len
= strlen(line
);
1532 for (i
= 0; i
< len
; i
++) {
1533 if (line
[i
] == '[') index
= 0;
1534 else if (line
[i
] == ']') break;
1535 else if (line
[i
] != ' ')
1537 key
+= tolower(line
[i
]);
1540 if (key
== 517) { // [begin]
1542 for (i
= index
; i
< len
; i
++) {
1543 if (line
[i
] == '(') index
= 0;
1544 else if (line
[i
] == ')') break;
1545 else if (index
++ >= 0) {
1546 if (line
[i
] == '\\' && i
< len
- 1) i
++;
1547 label
[index
- 1] = line
[i
];
1551 if (index
== -1) index
= 0;
1552 label
[index
] = '\0';
1554 rootmenu
->setLabel(label
);
1555 defaultMenu
= parseMenuFile(menu_file
, rootmenu
);
1557 blackbox
->addMenuTimestamp(menu_filename
);
1567 rootmenu
->setInternalMenu();
1568 rootmenu
->insert(i18n(ScreenSet
, Screenxterm
, "xterm"),
1570 i18n(ScreenSet
, Screenxterm
, "xterm"));
1571 rootmenu
->insert(i18n(ScreenSet
, ScreenRestart
, "Restart"),
1573 rootmenu
->insert(i18n(ScreenSet
, ScreenExit
, "Exit"),
1575 rootmenu
->setLabel(i18n(BasemenuSet
, BasemenuBlackboxMenu
,
1581 bool BScreen::parseMenuFile(FILE *file
, Rootmenu
*menu
) {
1582 char line
[1024], label
[1024], command
[1024];
1584 while (! feof(file
)) {
1585 memset(line
, 0, 1024);
1586 memset(label
, 0, 1024);
1587 memset(command
, 0, 1024);
1589 if (fgets(line
, 1024, file
)) {
1590 if (line
[0] != '#') {
1591 int i
, key
= 0, parse
= 0, index
= -1, line_length
= strlen(line
);
1593 // determine the keyword
1594 for (i
= 0; i
< line_length
; i
++) {
1595 if (line
[i
] == '[') parse
= 1;
1596 else if (line
[i
] == ']') break;
1597 else if (line
[i
] != ' ')
1599 key
+= tolower(line
[i
]);
1602 // get the label enclosed in ()'s
1605 for (i
= 0; i
< line_length
; i
++) {
1606 if (line
[i
] == '(') {
1609 } else if (line
[i
] == ')') break;
1610 else if (index
++ >= 0) {
1611 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
1612 label
[index
- 1] = line
[i
];
1617 label
[index
] = '\0';
1622 // get the command enclosed in {}'s
1625 for (i
= 0; i
< line_length
; i
++) {
1626 if (line
[i
] == '{') {
1629 } else if (line
[i
] == '}') break;
1630 else if (index
++ >= 0) {
1631 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
1632 command
[index
- 1] = line
[i
];
1637 command
[index
] = '\0';
1644 return ((menu
->getCount() == 0) ? True
: False
);
1651 menu
->insert(label
);
1656 if ((! *label
) && (! *command
)) {
1657 fprintf(stderr
, i18n(ScreenSet
, ScreenEXECError
,
1658 "BScreen::parseMenuFile: [exec] error, "
1659 "no menu label and/or command defined\n"));
1663 menu
->insert(label
, BScreen::Execute
, command
);
1669 fprintf(stderr
, i18n(ScreenSet
, ScreenEXITError
,
1670 "BScreen::parseMenuFile: [exit] error, "
1671 "no menu label defined\n"));
1675 menu
->insert(label
, BScreen::Exit
);
1681 if ((! *label
) || (! *command
)) {
1683 i18n(ScreenSet
, ScreenSTYLEError
,
1684 "BScreen::parseMenuFile: [style] error, "
1685 "no menu label and/or filename defined\n"));
1689 string style
= expandTilde(command
);
1691 menu
->insert(label
, BScreen::SetStyle
, style
.c_str());
1698 fprintf(stderr
, i18n(ScreenSet
, ScreenCONFIGError
,
1699 "BScreen::parseMenufile: [config] error, "
1700 "no label defined"));
1704 menu
->insert(label
, configmenu
);
1708 case 740: // include
1711 fprintf(stderr
, i18n(ScreenSet
, ScreenINCLUDEError
,
1712 "BScreen::parseMenuFile: [include] error, "
1713 "no filename defined\n"));
1717 string newfile
= expandTilde(label
);
1718 FILE *submenufile
= fopen(newfile
.c_str(), "r");
1722 if (fstat(fileno(submenufile
), &buf
) ||
1723 (! S_ISREG(buf
.st_mode
))) {
1725 i18n(ScreenSet
, ScreenINCLUDEErrorReg
,
1726 "BScreen::parseMenuFile: [include] error: "
1727 "'%s' is not a regular file\n"), newfile
.c_str());
1731 if (! feof(submenufile
)) {
1732 if (! parseMenuFile(submenufile
, menu
))
1733 blackbox
->addMenuTimestamp(newfile
);
1735 fclose(submenufile
);
1738 perror(newfile
.c_str());
1744 case 767: // submenu
1747 fprintf(stderr
, i18n(ScreenSet
, ScreenSUBMENUError
,
1748 "BScreen::parseMenuFile: [submenu] error, "
1749 "no menu label defined\n"));
1753 Rootmenu
*submenu
= new Rootmenu(this);
1756 submenu
->setLabel(command
);
1758 submenu
->setLabel(label
);
1760 parseMenuFile(file
, submenu
);
1762 menu
->insert(label
, submenu
);
1763 rootmenuList
.push_back(submenu
);
1768 case 773: // restart
1771 fprintf(stderr
, i18n(ScreenSet
, ScreenRESTARTError
,
1772 "BScreen::parseMenuFile: [restart] error, "
1773 "no menu label defined\n"));
1778 menu
->insert(label
, BScreen::RestartOther
, command
);
1780 menu
->insert(label
, BScreen::Restart
);
1785 case 845: // reconfig
1789 i18n(ScreenSet
, ScreenRECONFIGError
,
1790 "BScreen::parseMenuFile: [reconfig] error, "
1791 "no menu label defined\n"));
1795 menu
->insert(label
, BScreen::Reconfigure
);
1800 case 995: // stylesdir
1801 case 1113: // stylesmenu
1803 bool newmenu
= ((key
== 1113) ? True
: False
);
1805 if ((! *label
) || ((! *command
) && newmenu
)) {
1807 i18n(ScreenSet
, ScreenSTYLESDIRError
,
1808 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1809 " error, no directory defined\n"));
1813 char *directory
= ((newmenu
) ? command
: label
);
1815 string stylesdir
= expandTilde(directory
);
1817 struct stat statbuf
;
1819 if (! stat(stylesdir
.c_str(), &statbuf
)) {
1820 if (S_ISDIR(statbuf
.st_mode
)) {
1821 Rootmenu
*stylesmenu
;
1824 stylesmenu
= new Rootmenu(this);
1828 DIR *d
= opendir(stylesdir
.c_str());
1830 std::vector
<string
> ls
;
1832 while((p
= readdir(d
)))
1833 ls
.push_back(p
->d_name
);
1837 std::sort(ls
.begin(), ls
.end());
1839 std::vector
<string
>::iterator it
= ls
.begin(),
1841 for (; it
!= end
; ++it
) {
1842 const string
& fname
= *it
;
1844 if (fname
[fname
.size()-1] == '~')
1847 string style
= stylesdir
;
1851 if ((! stat(style
.c_str(), &statbuf
)) &&
1852 S_ISREG(statbuf
.st_mode
))
1853 stylesmenu
->insert(fname
, BScreen::SetStyle
, style
);
1856 stylesmenu
->update();
1859 stylesmenu
->setLabel(label
);
1860 menu
->insert(label
, stylesmenu
);
1861 rootmenuList
.push_back(stylesmenu
);
1864 blackbox
->addMenuTimestamp(stylesdir
);
1867 i18n(ScreenSet
, ScreenSTYLESDIRErrorNotDir
,
1868 "BScreen::parseMenuFile:"
1869 " [stylesdir/stylesmenu] error, %s is not a"
1870 " directory\n"), stylesdir
.c_str());
1874 i18n(ScreenSet
, ScreenSTYLESDIRErrorNoExist
,
1875 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1876 " error, %s does not exist\n"), stylesdir
.c_str());
1881 case 1090: // workspaces
1885 i18n(ScreenSet
, ScreenWORKSPACESError
,
1886 "BScreen:parseMenuFile: [workspaces] error, "
1887 "no menu label defined\n"));
1891 menu
->insert(label
, workspacemenu
);
1900 return ((menu
->getCount() == 0) ? True
: False
);
1904 void BScreen::shutdown(void) {
1905 XSelectInput(blackbox
->getXDisplay(), getRootWindow(), NoEventMask
);
1906 XSync(blackbox
->getXDisplay(), False
);
1908 while(! windowList
.empty())
1909 unmanageWindow(windowList
.front(), True
);
1915 void BScreen::showPosition(int x
, int y
) {
1916 if (! geom_visible
) {
1917 XMoveResizeWindow(blackbox
->getXDisplay(), geom_window
,
1918 (getWidth() - geom_w
) / 2,
1919 (getHeight() - geom_h
) / 2, geom_w
, geom_h
);
1920 XMapWindow(blackbox
->getXDisplay(), geom_window
);
1921 XRaiseWindow(blackbox
->getXDisplay(), geom_window
);
1923 geom_visible
= True
;
1928 sprintf(label
, i18n(ScreenSet
, ScreenPositionFormat
,
1929 "X: %4d x Y: %4d"), x
, y
);
1931 XClearWindow(blackbox
->getXDisplay(), geom_window
);
1933 resource
.wstyle
.font
->drawString(geom_window
,
1934 resource
.bevel_width
, resource
.bevel_width
,
1935 resource
.wstyle
.l_text_focus
,
1940 void BScreen::showGeometry(unsigned int gx
, unsigned int gy
) {
1941 if (! geom_visible
) {
1942 XMoveResizeWindow(blackbox
->getXDisplay(), geom_window
,
1943 (getWidth() - geom_w
) / 2,
1944 (getHeight() - geom_h
) / 2, geom_w
, geom_h
);
1945 XMapWindow(blackbox
->getXDisplay(), geom_window
);
1946 XRaiseWindow(blackbox
->getXDisplay(), geom_window
);
1948 geom_visible
= True
;
1953 sprintf(label
, i18n(ScreenSet
, ScreenGeometryFormat
,
1954 "W: %4d x H: %4d"), gx
, gy
);
1956 XClearWindow(blackbox
->getXDisplay(), geom_window
);
1958 resource
.wstyle
.font
->drawString(geom_window
,
1959 resource
.bevel_width
, resource
.bevel_width
,
1960 resource
.wstyle
.l_text_focus
,
1965 void BScreen::hideGeometry(void) {
1967 XUnmapWindow(blackbox
->getXDisplay(), geom_window
);
1968 geom_visible
= False
;
1973 void BScreen::addStrut(Strut
*strut
) {
1974 strutList
.push_back(strut
);
1978 void BScreen::removeStrut(Strut
*strut
) {
1979 strutList
.remove(strut
);
1983 const Rect
& BScreen::availableArea(void) const {
1985 return getRect(); // return the full screen
1990 void BScreen::updateAvailableArea(void) {
1991 Rect old_area
= usableArea
;
1992 usableArea
= getRect(); // reset to full screen
1994 /* these values represent offsets from the screen edge
1995 * we look for the biggest offset on each edge and then apply them
1997 * do not be confused by the similarity to the names of Rect's members
1999 unsigned int current_left
= 0, current_right
= 0, current_top
= 0,
2002 StrutList::const_iterator it
= strutList
.begin(), end
= strutList
.end();
2004 for(; it
!= end
; ++it
) {
2006 if (strut
->left
> current_left
)
2007 current_left
= strut
->left
;
2008 if (strut
->top
> current_top
)
2009 current_top
= strut
->top
;
2010 if (strut
->right
> current_right
)
2011 current_right
= strut
->right
;
2012 if (strut
->bottom
> current_bottom
)
2013 current_bottom
= strut
->bottom
;
2016 usableArea
.setPos(current_left
, current_top
);
2017 usableArea
.setSize(usableArea
.width() - (current_left
+ current_right
),
2018 usableArea
.height() - (current_top
+ current_bottom
));
2020 if (old_area
!= usableArea
) {
2021 BlackboxWindowList::iterator it
= windowList
.begin(),
2022 end
= windowList
.end();
2023 for (; it
!= end
; ++it
)
2024 if ((*it
)->isMaximized()) (*it
)->remaximize();
2031 Workspace
* BScreen::getWorkspace(unsigned int index
) {
2032 assert(index
< workspacesList
.size());
2033 return workspacesList
[index
];
2037 void BScreen::buttonPressEvent(const XButtonEvent
*xbutton
) {
2038 if (xbutton
->button
== 1) {
2039 if (! isRootColormapInstalled())
2040 image_control
->installRootColormap();
2042 if (workspacemenu
->isVisible())
2043 workspacemenu
->hide();
2045 if (rootmenu
->isVisible())
2047 } else if (xbutton
->button
== 2) {
2048 int mx
= xbutton
->x_root
- (workspacemenu
->getWidth() / 2);
2049 int my
= xbutton
->y_root
- (workspacemenu
->getTitleHeight() / 2);
2054 if (mx
+ workspacemenu
->getWidth() > getWidth())
2055 mx
= getWidth() - workspacemenu
->getWidth() - getBorderWidth();
2057 if (my
+ workspacemenu
->getHeight() > getHeight())
2058 my
= getHeight() - workspacemenu
->getHeight() - getBorderWidth();
2060 workspacemenu
->move(mx
, my
);
2062 if (! workspacemenu
->isVisible()) {
2063 workspacemenu
->removeParent();
2064 workspacemenu
->show();
2066 } else if (xbutton
->button
== 3) {
2067 int mx
= xbutton
->x_root
- (rootmenu
->getWidth() / 2);
2068 int my
= xbutton
->y_root
- (rootmenu
->getTitleHeight() / 2);
2073 if (mx
+ rootmenu
->getWidth() > getWidth())
2074 mx
= getWidth() - rootmenu
->getWidth() - getBorderWidth();
2076 if (my
+ rootmenu
->getHeight() > getHeight())
2077 my
= getHeight() - rootmenu
->getHeight() - getBorderWidth();
2079 rootmenu
->move(mx
, my
);
2081 if (! rootmenu
->isVisible()) {
2082 blackbox
->checkMenu();
2086 } else if (xbutton
->button
== 4) {
2087 if (getCurrentWorkspaceID() >= getWorkspaceCount() - 1)
2088 changeWorkspaceID(0);
2090 changeWorkspaceID(getCurrentWorkspaceID() + 1);
2092 } else if (xbutton
->button
== 5) {
2093 if (getCurrentWorkspaceID() == 0)
2094 changeWorkspaceID(getWorkspaceCount() - 1);
2096 changeWorkspaceID(getCurrentWorkspaceID() - 1);
2101 void BScreen::toggleFocusModel(FocusModel model
) {
2102 std::for_each(windowList
.begin(), windowList
.end(),
2103 std::mem_fun(&BlackboxWindow::ungrabButtons
));
2105 if (model
== SloppyFocus
) {
2106 saveSloppyFocus(True
);
2108 // we're cheating here to save writing the config file 3 times
2109 resource
.auto_raise
= False
;
2110 resource
.click_raise
= False
;
2111 saveSloppyFocus(False
);
2114 std::for_each(windowList
.begin(), windowList
.end(),
2115 std::mem_fun(&BlackboxWindow::grabButtons
));
2119 BTexture
BScreen::readDatabaseTexture(const string
&rname
,
2120 const string
&default_color
,
2121 const Configuration
&style
) {
2125 if (style
.getValue(rname
, s
))
2126 texture
= BTexture(s
);
2128 texture
.setTexture(BTexture::Solid
| BTexture::Flat
);
2130 // associate this texture with this screen
2131 texture
.setDisplay(getBaseDisplay(), getScreenNumber());
2132 texture
.setImageControl(image_control
);
2134 if (texture
.texture() & BTexture::Solid
) {
2135 texture
.setColor(readDatabaseColor(rname
+ ".color",
2136 default_color
, style
));
2137 texture
.setColorTo(readDatabaseColor(rname
+ ".colorTo",
2138 default_color
, style
));
2139 } else if (texture
.texture() & BTexture::Gradient
) {
2140 texture
.setColor(readDatabaseColor(rname
+ ".color",
2141 default_color
, style
));
2142 texture
.setColorTo(readDatabaseColor(rname
+ ".colorTo",
2143 default_color
, style
));
2150 BColor
BScreen::readDatabaseColor(const string
&rname
,
2151 const string
&default_color
,
2152 const Configuration
&style
) {
2155 if (style
.getValue(rname
, s
))
2156 color
= BColor(s
, getBaseDisplay(), getScreenNumber());
2158 color
= BColor(default_color
, getBaseDisplay(), getScreenNumber());
2163 BFont
*BScreen::readDatabaseFont(const string
&rbasename
,
2164 const Configuration
&style
) {
2171 if (style
.getValue(rbasename
+ "xft.font", s
) &&
2172 style
.getValue(rbasename
+ "xft.size", i
)) {
2175 bool italic
= False
;
2176 if (style
.getValue(rbasename
+ "xft.flags", s
)) {
2177 if (s
.find("bold") != string::npos
)
2179 if (s
.find("italic") != string::npos
)
2183 BFont
*b
= new BFont(blackbox
->getXDisplay(), this, family
, i
, bold
,
2184 italic
, resource
.aa_fonts
);
2188 delete b
; // fall back to the normal X font stuff
2192 style
.getValue(rbasename
+ "font", s
);
2193 // if this fails, a blank string will be used, which will cause the fallback
2196 BFont
*b
= new BFont(blackbox
->getXDisplay(), this, s
);
2198 exit(2); // can't continue without a font