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::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::saveWindowCornerSnap(bool s
) {
416 resource
.window_corner_snap
= s
;
417 config
->setValue(screenstr
+ "windowCornerSnap",
418 resource
.window_corner_snap
);
422 void BScreen::saveWorkspaces(unsigned int w
) {
423 resource
.workspaces
= w
;
424 config
->setValue(screenstr
+ "workspaces", resource
.workspaces
);
428 void BScreen::savePlacementPolicy(int p
) {
429 resource
.placement_policy
= p
;
430 const char *placement
;
431 switch (resource
.placement_policy
) {
432 case CascadePlacement
: placement
= "CascadePlacement"; break;
433 case ColSmartPlacement
: placement
= "ColSmartPlacement"; break;
434 case RowSmartPlacement
: default: placement
= "RowSmartPlacement"; break;
436 config
->setValue(screenstr
+ "windowPlacement", placement
);
440 void BScreen::saveEdgeSnapThreshold(int t
) {
441 resource
.edge_snap_threshold
= t
;
442 config
->setValue(screenstr
+ "edgeSnapThreshold",
443 resource
.edge_snap_threshold
);
447 void BScreen::saveRowPlacementDirection(int d
) {
448 resource
.row_direction
= d
;
449 config
->setValue(screenstr
+ "rowPlacementDirection",
450 resource
.row_direction
== LeftRight
?
451 "LeftToRight" : "RightToLeft");
455 void BScreen::saveColPlacementDirection(int d
) {
456 resource
.col_direction
= d
;
457 config
->setValue(screenstr
+ "colPlacementDirection",
458 resource
.col_direction
== TopBottom
?
459 "TopToBottom" : "BottomToTop");
464 void BScreen::saveStrftimeFormat(const std::string
& format
) {
465 resource
.strftime_format
= format
;
466 config
->setValue(screenstr
+ "strftimeFormat", resource
.strftime_format
);
469 #else // !HAVE_STRFTIME
471 void BScreen::saveDateFormat(int f
) {
472 resource
.date_format
= f
;
473 config
->setValue(screenstr
+ "dateFormat",
474 resource
.date_format
== B_EuropeanDate
?
475 "European" : "American");
479 void BScreen::saveClock24Hour(Bool c
) {
480 resource
.clock24hour
= c
;
481 config
->setValue(screenstr
+ "clockFormat", resource
.clock24hour
? 24 : 12);
483 #endif // HAVE_STRFTIME
486 void BScreen::saveWorkspaceNames() {
487 XAtom::StringVect nameList
;
488 unsigned long numnames
= (unsigned) -1;
492 xatom
->getValue(getRootWindow(), XAtom::net_desktop_names
, XAtom::utf8
,
493 numnames
, nameList
)) {
494 for (unsigned int i
= 0; i
< nameList
.size(); ++i
) {
495 if (i
> 0) names
+= ",";
496 names
+= nameList
[i
];
499 config
->setValue(screenstr
+ "workspaceNames", names
);
503 void BScreen::save_rc(void) {
504 saveSloppyFocus(resource
.sloppy_focus
);
505 saveAutoRaise(resource
.auto_raise
);
506 saveImageDither(doImageDither());
507 saveAAFonts(resource
.aa_fonts
);
508 saveOpaqueMove(resource
.opaque_move
);
509 saveFullMax(resource
.full_max
);
510 saveFocusNew(resource
.focus_new
);
511 saveFocusLast(resource
.focus_last
);
512 saveHideToolbar(resource
.hide_toolbar
);
513 saveWindowToWindowSnap(resource
.window_to_window_snap
);
514 saveWindowCornerSnap(resource
.window_corner_snap
);
515 saveWorkspaces(resource
.workspaces
);
516 savePlacementPolicy(resource
.placement_policy
);
517 saveEdgeSnapThreshold(resource
.edge_snap_threshold
);
518 saveRowPlacementDirection(resource
.row_direction
);
519 saveColPlacementDirection(resource
.col_direction
);
521 saveStrftimeFormat(resource
.strftime_format
);
522 #else // !HAVE_STRFTIME
523 saveDateFormat(resource
.date_format
);
524 savwClock24Hour(resource
.clock24hour
);
525 #endif // HAVE_STRFTIME
532 void BScreen::load_rc(void) {
536 if (! config
->getValue(screenstr
+ "fullMaximization", resource
.full_max
))
537 resource
.full_max
= false;
539 if (! config
->getValue(screenstr
+ "focusNewWindows", resource
.focus_new
))
540 resource
.focus_new
= false;
542 if (! config
->getValue(screenstr
+ "focusLastWindow", resource
.focus_last
))
543 resource
.focus_last
= false;
545 if (! config
->getValue(screenstr
+ "workspaces", resource
.workspaces
))
546 resource
.workspaces
= 1;
548 if (! config
->getValue(screenstr
+ "opaqueMove", resource
.opaque_move
))
549 resource
.opaque_move
= false;
551 if (! config
->getValue(screenstr
+ "antialiasFonts", resource
.aa_fonts
))
552 resource
.aa_fonts
= true;
554 if (! config
->getValue(screenstr
+ "hideToolbar", resource
.hide_toolbar
))
555 resource
.hide_toolbar
= false;
557 if (! config
->getValue(screenstr
+ "windowToWindowSnap",
558 resource
.window_to_window_snap
))
559 resource
.window_to_window_snap
= true;
561 if (! config
->getValue(screenstr
+ "windowCornerSnap",
562 resource
.window_corner_snap
))
563 resource
.window_corner_snap
= true;
565 if (! config
->getValue(screenstr
+ "imageDither", b
))
567 image_control
->setDither(b
);
569 if (! config
->getValue(screenstr
+ "edgeSnapThreshold",
570 resource
.edge_snap_threshold
))
571 resource
.edge_snap_threshold
= 4;
573 if (config
->getValue(screenstr
+ "rowPlacementDirection", s
) &&
575 resource
.row_direction
= RightLeft
;
577 resource
.row_direction
= LeftRight
;
579 if (config
->getValue(screenstr
+ "colPlacementDirection", s
) &&
581 resource
.col_direction
= BottomTop
;
583 resource
.col_direction
= TopBottom
;
585 XAtom::StringVect workspaceNames
;
586 if (config
->getValue(screenstr
+ "workspaceNames", s
)) {
587 string::const_iterator it
= s
.begin(), end
= s
.end();
589 string::const_iterator tmp
= it
; // current string.begin()
590 it
= std::find(tmp
, end
, ','); // look for comma between tmp and end
591 workspaceNames
.push_back(string(tmp
, it
)); // s[tmp:it]
597 xatom
->setValue(getRootWindow(), XAtom::net_desktop_names
, XAtom::utf8
,
600 resource
.sloppy_focus
= true;
601 resource
.auto_raise
= false;
602 resource
.click_raise
= false;
603 if (config
->getValue(screenstr
+ "focusModel", s
)) {
604 if (s
.find("ClickToFocus") != string::npos
) {
605 resource
.sloppy_focus
= false;
608 if (s
.find("AutoRaise") != string::npos
)
609 resource
.auto_raise
= true;
610 if (s
.find("ClickRaise") != string::npos
)
611 resource
.click_raise
= true;
615 if (config
->getValue(screenstr
+ "windowPlacement", s
)) {
616 if (s
== "CascadePlacement")
617 resource
.placement_policy
= CascadePlacement
;
618 else if (s
== "ColSmartPlacement")
619 resource
.placement_policy
= ColSmartPlacement
;
620 else //if (s == "RowSmartPlacement")
621 resource
.placement_policy
= RowSmartPlacement
;
623 resource
.placement_policy
= RowSmartPlacement
;
626 if (config
->getValue(screenstr
+ "strftimeFormat", s
))
627 resource
.strftime_format
= s
;
629 resource
.strftime_format
= "%I:%M %p";
630 #else // !HAVE_STRFTIME
633 if (config
->getValue(screenstr
+ "dateFormat", s
) && s
== "European")
634 resource
.date_format
= B_EuropeanDate
;
636 resource
.date_format
= B_AmericanDate
;
638 if (! config
->getValue(screenstr
+ "clockFormat", l
))
640 resource
.clock24hour
= l
== 24;
641 #endif // HAVE_STRFTIME
645 void BScreen::reconfigure(void) {
652 gcv
.foreground
= WhitePixel(blackbox
->getXDisplay(),
654 gcv
.function
= GXinvert
;
655 gcv
.subwindow_mode
= IncludeInferiors
;
656 XChangeGC(blackbox
->getXDisplay(), opGC
,
657 GCForeground
| GCFunction
| GCSubwindowMode
, &gcv
);
659 const char *s
= i18n(ScreenSet
, ScreenPositionLength
,
660 "0: 0000 x 0: 0000");
662 geom_w
= resource
.wstyle
.font
->measureString(s
) + resource
.bevel_width
* 2;
663 geom_h
= resource
.wstyle
.font
->height() + resource
.bevel_width
* 2;
665 BTexture
* texture
= &(resource
.wstyle
.l_focus
);
666 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
667 if (geom_pixmap
== ParentRelative
) {
668 texture
= &(resource
.wstyle
.t_focus
);
669 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
672 XSetWindowBackground(blackbox
->getXDisplay(), geom_window
,
673 texture
->color().pixel());
675 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
676 geom_window
, geom_pixmap
);
678 XSetWindowBorderWidth(blackbox
->getXDisplay(), geom_window
,
679 resource
.border_width
);
680 XSetWindowBorder(blackbox
->getXDisplay(), geom_window
,
681 resource
.border_color
.pixel());
683 workspacemenu
->reconfigure();
684 iconmenu
->reconfigure();
686 typedef std::vector
<int> SubList
;
687 SubList remember_subs
;
689 // save the current open menus
690 Basemenu
*menu
= rootmenu
;
692 while ((submenu
= menu
->getCurrentSubmenu()) >= 0) {
693 remember_subs
.push_back(submenu
);
694 menu
= menu
->find(submenu
)->submenu();
700 rootmenu
->reconfigure();
702 // reopen the saved menus
704 const SubList::iterator subs_end
= remember_subs
.end();
705 for (SubList::iterator it
= remember_subs
.begin(); it
!= subs_end
; ++it
) {
706 menu
->drawSubmenu(*it
);
707 menu
= menu
->find(*it
)->submenu();
712 configmenu
->reconfigure();
714 toolbar
->reconfigure();
718 std::for_each(workspacesList
.begin(), workspacesList
.end(),
719 std::mem_fun(&Workspace::reconfigure
));
721 BlackboxWindowList::iterator iit
= iconList
.begin();
722 for (; iit
!= iconList
.end(); ++iit
) {
723 BlackboxWindow
*bw
= *iit
;
724 if (bw
->validateClient())
728 image_control
->timeout();
732 void BScreen::rereadMenu(void) {
736 rootmenu
->reconfigure();
740 void BScreen::LoadStyle(void) {
741 Configuration
style(False
);
743 const char *sfile
= blackbox
->getStyleFilename();
745 style
.setFile(sfile
);
746 if (! style
.load()) {
747 style
.setFile(DEFAULTSTYLE
);
749 style
.create(); // hardcoded default values will be used.
753 // merge in the rc file
754 style
.merge(config
->file(), True
);
758 // load fonts/fontsets
759 if (resource
.wstyle
.font
)
760 delete resource
.wstyle
.font
;
761 if (resource
.tstyle
.font
)
762 delete resource
.tstyle
.font
;
763 if (resource
.mstyle
.f_font
)
764 delete resource
.mstyle
.f_font
;
765 if (resource
.mstyle
.t_font
)
766 delete resource
.mstyle
.t_font
;
767 resource
.wstyle
.font
= resource
.tstyle
.font
= resource
.mstyle
.f_font
=
768 resource
.mstyle
.t_font
= (BFont
*) 0;
770 resource
.wstyle
.font
= readDatabaseFont("window.", style
);
771 resource
.tstyle
.font
= readDatabaseFont("toolbar.", style
);
772 resource
.mstyle
.t_font
= readDatabaseFont("menu.title.", style
);
773 resource
.mstyle
.f_font
= readDatabaseFont("menu.frame.", style
);
775 // load window config
776 resource
.wstyle
.t_focus
=
777 readDatabaseTexture("window.title.focus", "white", style
);
778 resource
.wstyle
.t_unfocus
=
779 readDatabaseTexture("window.title.unfocus", "black", style
);
780 resource
.wstyle
.l_focus
=
781 readDatabaseTexture("window.label.focus", "white", style
);
782 resource
.wstyle
.l_unfocus
=
783 readDatabaseTexture("window.label.unfocus", "black", style
);
784 resource
.wstyle
.h_focus
=
785 readDatabaseTexture("window.handle.focus", "white", style
);
786 resource
.wstyle
.h_unfocus
=
787 readDatabaseTexture("window.handle.unfocus", "black", style
);
788 resource
.wstyle
.g_focus
=
789 readDatabaseTexture("window.grip.focus", "white", style
);
790 resource
.wstyle
.g_unfocus
=
791 readDatabaseTexture("window.grip.unfocus", "black", style
);
792 resource
.wstyle
.b_focus
=
793 readDatabaseTexture("window.button.focus", "white", style
);
794 resource
.wstyle
.b_unfocus
=
795 readDatabaseTexture("window.button.unfocus", "black", style
);
796 resource
.wstyle
.b_pressed
=
797 readDatabaseTexture("window.button.pressed", "black", style
);
798 resource
.wstyle
.f_focus
=
799 readDatabaseColor("window.frame.focusColor", "white", style
);
800 resource
.wstyle
.f_unfocus
=
801 readDatabaseColor("window.frame.unfocusColor", "black", style
);
802 resource
.wstyle
.l_text_focus
=
803 readDatabaseColor("window.label.focus.textColor", "black", style
);
804 resource
.wstyle
.l_text_unfocus
=
805 readDatabaseColor("window.label.unfocus.textColor", "white", style
);
806 resource
.wstyle
.b_pic_focus
=
807 readDatabaseColor("window.button.focus.picColor", "black", style
);
808 resource
.wstyle
.b_pic_unfocus
=
809 readDatabaseColor("window.button.unfocus.picColor", "white", style
);
811 resource
.wstyle
.justify
= LeftJustify
;
812 if (style
.getValue("window.justify", s
)) {
813 if (s
== "right" || s
== "Right")
814 resource
.wstyle
.justify
= RightJustify
;
815 else if (s
== "center" || s
== "Center")
816 resource
.wstyle
.justify
= CenterJustify
;
819 // load toolbar config
820 resource
.tstyle
.toolbar
=
821 readDatabaseTexture("toolbar", "black", style
);
822 resource
.tstyle
.label
=
823 readDatabaseTexture("toolbar.label", "black", style
);
824 resource
.tstyle
.window
=
825 readDatabaseTexture("toolbar.windowLabel", "black", style
);
826 resource
.tstyle
.button
=
827 readDatabaseTexture("toolbar.button", "white", style
);
828 resource
.tstyle
.pressed
=
829 readDatabaseTexture("toolbar.button.pressed", "black", style
);
830 resource
.tstyle
.clock
=
831 readDatabaseTexture("toolbar.clock", "black", style
);
832 resource
.tstyle
.l_text
=
833 readDatabaseColor("toolbar.label.textColor", "white", style
);
834 resource
.tstyle
.w_text
=
835 readDatabaseColor("toolbar.windowLabel.textColor", "white", style
);
836 resource
.tstyle
.c_text
=
837 readDatabaseColor("toolbar.clock.textColor", "white", style
);
838 resource
.tstyle
.b_pic
=
839 readDatabaseColor("toolbar.button.picColor", "black", style
);
841 resource
.tstyle
.justify
= LeftJustify
;
842 if (style
.getValue("toolbar.justify", s
)) {
843 if (s
== "right" || s
== "Right")
844 resource
.tstyle
.justify
= RightJustify
;
845 else if (s
== "center" || s
== "Center")
846 resource
.tstyle
.justify
= CenterJustify
;
850 resource
.mstyle
.title
=
851 readDatabaseTexture("menu.title", "white", style
);
852 resource
.mstyle
.frame
=
853 readDatabaseTexture("menu.frame", "black", style
);
854 resource
.mstyle
.hilite
=
855 readDatabaseTexture("menu.hilite", "white", style
);
856 resource
.mstyle
.t_text
=
857 readDatabaseColor("menu.title.textColor", "black", style
);
858 resource
.mstyle
.f_text
=
859 readDatabaseColor("menu.frame.textColor", "white", style
);
860 resource
.mstyle
.d_text
=
861 readDatabaseColor("menu.frame.disableColor", "black", style
);
862 resource
.mstyle
.h_text
=
863 readDatabaseColor("menu.hilite.textColor", "black", style
);
865 resource
.mstyle
.t_justify
= LeftJustify
;
866 if (style
.getValue("menu.title.justify", s
)) {
867 if (s
== "right" || s
== "Right")
868 resource
.mstyle
.t_justify
= RightJustify
;
869 else if (s
== "center" || s
== "Center")
870 resource
.mstyle
.t_justify
= CenterJustify
;
873 resource
.mstyle
.f_justify
= LeftJustify
;
874 if (style
.getValue("menu.frame.justify", s
)) {
875 if (s
== "right" || s
== "Right")
876 resource
.mstyle
.f_justify
= RightJustify
;
877 else if (s
== "center" || s
== "Center")
878 resource
.mstyle
.f_justify
= CenterJustify
;
881 resource
.mstyle
.bullet
= Basemenu::Triangle
;
882 if (style
.getValue("menu.bullet", s
)) {
883 if (s
== "empty" || s
== "Empty")
884 resource
.mstyle
.bullet
= Basemenu::Empty
;
885 else if (s
== "square" || s
== "Square")
886 resource
.mstyle
.bullet
= Basemenu::Square
;
887 else if (s
== "diamond" || s
== "Diamond")
888 resource
.mstyle
.bullet
= Basemenu::Diamond
;
891 resource
.mstyle
.bullet_pos
= Basemenu::Left
;
892 if (style
.getValue("menu.bullet.position", s
)) {
893 if (s
== "right" || s
== "Right")
894 resource
.mstyle
.bullet_pos
= Basemenu::Right
;
897 resource
.border_color
=
898 readDatabaseColor("borderColor", "black", style
);
900 // load bevel, border and handle widths
901 if (! style
.getValue("handleWidth", resource
.handle_width
) ||
902 resource
.handle_width
> (getWidth() / 2) || resource
.handle_width
== 0)
903 resource
.handle_width
= 6;
905 if (! style
.getValue("borderWidth", resource
.border_width
))
906 resource
.border_width
= 1;
908 if (! style
.getValue("bevelWidth", resource
.bevel_width
) ||
909 resource
.bevel_width
> (getWidth() / 2) || resource
.bevel_width
== 0)
910 resource
.bevel_width
= 3;
912 if (! style
.getValue("frameWidth", resource
.frame_width
) ||
913 resource
.frame_width
> (getWidth() / 2))
914 resource
.frame_width
= resource
.bevel_width
;
916 if (style
.getValue("rootCommand", s
))
917 bexec(s
, displayString());
921 void BScreen::addIcon(BlackboxWindow
*w
) {
924 w
->setWorkspace(BSENTINEL
);
925 w
->setWindowNumber(iconList
.size());
927 iconList
.push_back(w
);
929 const char* title
= w
->getIconTitle();
930 iconmenu
->insert(title
);
935 void BScreen::removeIcon(BlackboxWindow
*w
) {
940 iconmenu
->remove(w
->getWindowNumber());
943 BlackboxWindowList::iterator it
= iconList
.begin(),
944 end
= iconList
.end();
945 for (int i
= 0; it
!= end
; ++it
)
946 (*it
)->setWindowNumber(i
++);
950 BlackboxWindow
*BScreen::getIcon(unsigned int index
) {
951 if (index
< iconList
.size()) {
952 BlackboxWindowList::iterator it
= iconList
.begin();
953 for (; index
> 0; --index
, ++it
) ; /* increment to index */
957 return (BlackboxWindow
*) 0;
961 unsigned int BScreen::addWorkspace(void) {
962 Workspace
*wkspc
= new Workspace(this, workspacesList
.size());
963 workspacesList
.push_back(wkspc
);
964 saveWorkspaces(getWorkspaceCount());
966 workspacemenu
->insert(wkspc
->getName(), wkspc
->getMenu(),
968 workspacemenu
->update();
970 toolbar
->reconfigure();
972 updateNetizenWorkspaceCount();
974 return workspacesList
.size();
978 unsigned int BScreen::removeLastWorkspace(void) {
979 if (workspacesList
.size() == 1)
982 Workspace
*wkspc
= workspacesList
.back();
984 if (current_workspace
->getID() == wkspc
->getID())
985 changeWorkspaceID(current_workspace
->getID() - 1);
989 workspacemenu
->remove(wkspc
->getID() + 2);
990 workspacemenu
->update();
992 workspacesList
.pop_back();
995 saveWorkspaces(getWorkspaceCount());
997 toolbar
->reconfigure();
999 updateNetizenWorkspaceCount();
1001 return workspacesList
.size();
1005 void BScreen::changeWorkspaceID(unsigned int id
) {
1006 if (! current_workspace
) return;
1008 if (id
!= current_workspace
->getID()) {
1009 BlackboxWindow
*focused
= blackbox
->getFocusedWindow();
1010 if (focused
&& focused
->getScreen() == this && ! focused
->isStuck()) {
1011 if (focused
->getWorkspaceNumber() != current_workspace
->getID()) {
1012 fprintf(stderr
, "%s is on the wrong workspace, aborting\n",
1013 focused
->getTitle());
1016 current_workspace
->setLastFocusedWindow(focused
);
1018 // if no window had focus, no need to store a last focus
1019 current_workspace
->setLastFocusedWindow((BlackboxWindow
*) 0);
1021 // when we switch workspaces, unfocus whatever was focused
1022 blackbox
->setFocusedWindow((BlackboxWindow
*) 0);
1024 current_workspace
->hideAll();
1025 workspacemenu
->setItemSelected(current_workspace
->getID() + 2, False
);
1027 current_workspace
= getWorkspace(id
);
1029 xatom
->setValue(getRootWindow(), XAtom::net_current_desktop
,
1030 XAtom::cardinal
, id
);
1032 workspacemenu
->setItemSelected(current_workspace
->getID() + 2, True
);
1033 toolbar
->redrawWorkspaceLabel(True
);
1035 current_workspace
->showAll();
1037 if (resource
.focus_last
&& current_workspace
->getLastFocusedWindow()) {
1038 XSync(blackbox
->getXDisplay(), False
);
1039 current_workspace
->getLastFocusedWindow()->setInputFocus();
1043 updateNetizenCurrentWorkspace();
1048 * Set the _NET_CLIENT_LIST root window property.
1050 void BScreen::updateClientList(void) {
1051 if (windowList
.size() > 0) {
1052 Window
*windows
= new Window
[windowList
.size()];
1053 Window
*win_it
= windows
;
1054 BlackboxWindowList::iterator it
= windowList
.begin();
1055 const BlackboxWindowList::iterator end
= windowList
.end();
1056 for (; it
!= end
; ++it
, ++win_it
)
1057 *win_it
= (*it
)->getClientWindow();
1058 xatom
->setValue(getRootWindow(), XAtom::net_client_list
, XAtom::window
,
1059 windows
, windowList
.size());
1062 xatom
->setValue(getRootWindow(), XAtom::net_client_list
, XAtom::window
,
1068 * Set the _NET_CLIENT_LIST_STACKING root window property.
1070 void BScreen::updateStackingList(void) {
1072 BlackboxWindowList stack_order
;
1075 * Get the atacking order from all of the workspaces.
1076 * We start with the current workspace so that the sticky windows will be
1077 * in the right order on the current workspace.
1078 * XXX: Do we need to have sticky windows in the list once for each workspace?
1080 getCurrentWorkspace()->appendStackOrder(stack_order
);
1081 for (unsigned int i
= 0; i
< getWorkspaceCount(); ++i
)
1082 if (i
!= getCurrentWorkspaceID())
1083 getWorkspace(i
)->appendStackOrder(stack_order
);
1085 if (stack_order
.size() > 0) {
1086 // set the client list atoms
1087 Window
*windows
= new Window
[stack_order
.size()];
1088 Window
*win_it
= windows
;
1089 BlackboxWindowList::iterator it
= stack_order
.begin();
1090 const BlackboxWindowList::iterator end
= stack_order
.end();
1091 for (; it
!= end
; ++it
, ++win_it
)
1092 *win_it
= (*it
)->getClientWindow();
1093 xatom
->setValue(getRootWindow(), XAtom::net_client_list_stacking
,
1094 XAtom::window
, windows
, stack_order
.size());
1097 xatom
->setValue(getRootWindow(), XAtom::net_client_list_stacking
,
1098 XAtom::window
, 0, 0);
1102 void BScreen::addSystrayWindow(Window window
) {
1103 systrayWindowList
.push_back(window
);
1104 xatom
->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows
,
1106 &systrayWindowList
[0], systrayWindowList
.size());
1107 blackbox
->saveSystrayWindowSearch(window
, this);
1111 void BScreen::removeSystrayWindow(Window window
) {
1112 WindowList::iterator it
= systrayWindowList
.begin();
1113 const WindowList::iterator end
= systrayWindowList
.end();
1114 for (; it
!= end
; ++it
)
1115 if (*it
== window
) {
1116 systrayWindowList
.erase(it
);
1117 xatom
->setValue(getRootWindow(), XAtom::kde_net_system_tray_windows
,
1119 &systrayWindowList
[0], systrayWindowList
.size());
1120 blackbox
->removeSystrayWindowSearch(window
);
1126 void BScreen::addDesktopWindow(Window window
) {
1127 desktopWindowList
.push_back(window
);
1128 XLowerWindow(blackbox
->getXDisplay(), window
);
1129 XSelectInput(blackbox
->getXDisplay(), window
, StructureNotifyMask
);
1130 blackbox
->saveDesktopWindowSearch(window
, this);
1134 void BScreen::removeDesktopWindow(Window window
) {
1135 WindowList::iterator it
= desktopWindowList
.begin();
1136 const WindowList::iterator end
= desktopWindowList
.end();
1137 for (; it
!= end
; ++it
)
1138 if (*it
== window
) {
1139 desktopWindowList
.erase(it
);
1140 XSelectInput(blackbox
->getXDisplay(), window
, None
);
1141 blackbox
->removeDesktopWindowSearch(window
);
1147 void BScreen::manageWindow(Window w
) {
1148 new BlackboxWindow(blackbox
, w
, this);
1150 BlackboxWindow
*win
= blackbox
->searchWindow(w
);
1153 if (win
->isDesktop()) {
1154 // desktop windows cant do anything, so we remove all the normal window
1155 // stuff from them, they are only kept around so that we can keep them on
1156 // the bottom of the z-order
1158 addDesktopWindow(win
->getClientWindow());
1163 windowList
.push_back(win
);
1166 XMapRequestEvent mre
;
1168 if (blackbox
->isStartup()) win
->restoreAttributes();
1169 win
->mapRequestEvent(&mre
);
1173 void BScreen::unmanageWindow(BlackboxWindow
*w
, bool remap
) {
1176 if (w
->getWorkspaceNumber() != BSENTINEL
&&
1177 w
->getWindowNumber() != BSENTINEL
)
1178 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
1179 else if (w
->isIconic())
1182 windowList
.remove(w
);
1185 if (blackbox
->getFocusedWindow() == w
)
1186 blackbox
->setFocusedWindow((BlackboxWindow
*) 0);
1188 removeNetizen(w
->getClientWindow());
1191 some managed windows can also be window group controllers. when
1192 unmanaging such windows, we should also delete the window group.
1194 BWindowGroup
*group
= blackbox
->searchGroup(w
->getClientWindow());
1201 void BScreen::addNetizen(Netizen
*n
) {
1202 netizenList
.push_back(n
);
1204 n
->sendWorkspaceCount();
1205 n
->sendCurrentWorkspace();
1207 WorkspaceList::iterator it
= workspacesList
.begin();
1208 const WorkspaceList::iterator end
= workspacesList
.end();
1209 for (; it
!= end
; ++it
)
1210 (*it
)->sendWindowList(*n
);
1212 Window f
= ((blackbox
->getFocusedWindow()) ?
1213 blackbox
->getFocusedWindow()->getClientWindow() : None
);
1214 n
->sendWindowFocus(f
);
1218 void BScreen::removeNetizen(Window w
) {
1219 NetizenList::iterator it
= netizenList
.begin();
1220 for (; it
!= netizenList
.end(); ++it
) {
1221 if ((*it
)->getWindowID() == w
) {
1223 netizenList
.erase(it
);
1230 void BScreen::updateWorkArea(void) {
1231 if (workspacesList
.size() > 0) {
1232 unsigned long *dims
= new unsigned long[4 * workspacesList
.size()];
1233 for (unsigned int i
= 0, m
= workspacesList
.size(); i
< m
; ++i
) {
1234 // XXX: this could be different for each workspace
1235 const Rect
&area
= availableArea();
1236 dims
[(i
* 4) + 0] = area
.x();
1237 dims
[(i
* 4) + 1] = area
.y();
1238 dims
[(i
* 4) + 2] = area
.width();
1239 dims
[(i
* 4) + 3] = area
.height();
1241 xatom
->setValue(getRootWindow(), XAtom::net_workarea
, XAtom::cardinal
,
1242 dims
, 4 * workspacesList
.size());
1245 xatom
->setValue(getRootWindow(), XAtom::net_workarea
, XAtom::cardinal
,
1250 void BScreen::updateNetizenCurrentWorkspace(void) {
1251 std::for_each(netizenList
.begin(), netizenList
.end(),
1252 std::mem_fun(&Netizen::sendCurrentWorkspace
));
1256 void BScreen::updateNetizenWorkspaceCount(void) {
1257 xatom
->setValue(getRootWindow(), XAtom::net_number_of_desktops
,
1258 XAtom::cardinal
, workspacesList
.size());
1262 std::for_each(netizenList
.begin(), netizenList
.end(),
1263 std::mem_fun(&Netizen::sendWorkspaceCount
));
1267 void BScreen::updateNetizenWindowFocus(void) {
1268 Window f
= ((blackbox
->getFocusedWindow()) ?
1269 blackbox
->getFocusedWindow()->getClientWindow() : None
);
1271 xatom
->setValue(getRootWindow(), XAtom::net_active_window
,
1274 NetizenList::iterator it
= netizenList
.begin();
1275 for (; it
!= netizenList
.end(); ++it
)
1276 (*it
)->sendWindowFocus(f
);
1280 void BScreen::updateNetizenWindowAdd(Window w
, unsigned long p
) {
1281 NetizenList::iterator it
= netizenList
.begin();
1282 for (; it
!= netizenList
.end(); ++it
) {
1283 (*it
)->sendWindowAdd(w
, p
);
1288 void BScreen::updateNetizenWindowDel(Window w
) {
1289 NetizenList::iterator it
= netizenList
.begin();
1290 for (; it
!= netizenList
.end(); ++it
)
1291 (*it
)->sendWindowDel(w
);
1295 void BScreen::updateNetizenWindowRaise(Window w
) {
1296 NetizenList::iterator it
= netizenList
.begin();
1297 for (; it
!= netizenList
.end(); ++it
)
1298 (*it
)->sendWindowRaise(w
);
1302 void BScreen::updateNetizenWindowLower(Window w
) {
1303 NetizenList::iterator it
= netizenList
.begin();
1304 for (; it
!= netizenList
.end(); ++it
)
1305 (*it
)->sendWindowLower(w
);
1309 void BScreen::updateNetizenConfigNotify(XEvent
*e
) {
1310 NetizenList::iterator it
= netizenList
.begin();
1311 for (; it
!= netizenList
.end(); ++it
)
1312 (*it
)->sendConfigNotify(e
);
1316 void BScreen::raiseWindows(Window
*workspace_stack
, unsigned int num
) {
1317 // the 13 represents the number of blackbox windows such as menus
1318 Window
*session_stack
= new
1319 Window
[(num
+ workspacesList
.size() + rootmenuList
.size() + 13)];
1320 unsigned int i
= 0, k
= num
;
1322 XRaiseWindow(blackbox
->getXDisplay(), iconmenu
->getWindowID());
1323 *(session_stack
+ i
++) = iconmenu
->getWindowID();
1325 WorkspaceList::iterator wit
= workspacesList
.begin();
1326 const WorkspaceList::iterator w_end
= workspacesList
.end();
1327 for (; wit
!= w_end
; ++wit
)
1328 *(session_stack
+ i
++) = (*wit
)->getMenu()->getWindowID();
1330 *(session_stack
+ i
++) = workspacemenu
->getWindowID();
1332 *(session_stack
+ i
++) = configmenu
->getFocusmenu()->getWindowID();
1333 *(session_stack
+ i
++) = configmenu
->getPlacementmenu()->getWindowID();
1334 *(session_stack
+ i
++) = configmenu
->getWindowID();
1336 *(session_stack
+ i
++) = slit
->getMenu()->getDirectionmenu()->getWindowID();
1337 *(session_stack
+ i
++) = slit
->getMenu()->getPlacementmenu()->getWindowID();
1338 *(session_stack
+ i
++) = slit
->getMenu()->getWindowID();
1340 *(session_stack
+ i
++) =
1341 toolbar
->getMenu()->getPlacementmenu()->getWindowID();
1342 *(session_stack
+ i
++) = toolbar
->getMenu()->getWindowID();
1344 RootmenuList::iterator rit
= rootmenuList
.begin();
1345 for (; rit
!= rootmenuList
.end(); ++rit
)
1346 *(session_stack
+ i
++) = (*rit
)->getWindowID();
1347 *(session_stack
+ i
++) = rootmenu
->getWindowID();
1349 if (toolbar
->isOnTop())
1350 *(session_stack
+ i
++) = toolbar
->getWindowID();
1352 if (slit
->isOnTop())
1353 *(session_stack
+ i
++) = slit
->getWindowID();
1356 *(session_stack
+ i
++) = *(workspace_stack
+ k
);
1358 XRestackWindows(blackbox
->getXDisplay(), session_stack
, i
);
1360 delete [] session_stack
;
1362 updateStackingList();
1366 void BScreen::lowerDesktops(void) {
1367 if (desktopWindowList
.empty()) return;
1369 XLowerWindow(blackbox
->getXDisplay(), desktopWindowList
[0]);
1370 if (desktopWindowList
.size() > 1)
1371 XRestackWindows(blackbox
->getXDisplay(), &desktopWindowList
[0],
1372 desktopWindowList
.size());
1376 void BScreen::reassociateWindow(BlackboxWindow
*w
, unsigned int wkspc_id
,
1377 bool ignore_sticky
) {
1380 if (wkspc_id
== BSENTINEL
)
1381 wkspc_id
= current_workspace
->getID();
1383 if (w
->getWorkspaceNumber() == wkspc_id
)
1386 if (w
->isIconic()) {
1388 getWorkspace(wkspc_id
)->addWindow(w
);
1389 } else if (ignore_sticky
|| ! w
->isStuck()) {
1390 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
1391 getWorkspace(wkspc_id
)->addWindow(w
);
1396 void BScreen::propagateWindowName(const BlackboxWindow
*bw
) {
1397 if (bw
->isIconic()) {
1398 iconmenu
->changeItemLabel(bw
->getWindowNumber(), bw
->getIconTitle());
1402 Clientmenu
*clientmenu
= getWorkspace(bw
->getWorkspaceNumber())->getMenu();
1403 clientmenu
->changeItemLabel(bw
->getWindowNumber(), bw
->getTitle());
1404 clientmenu
->update();
1406 if (blackbox
->getFocusedWindow() == bw
)
1407 toolbar
->redrawWindowLabel(True
);
1412 void BScreen::nextFocus(void) {
1413 BlackboxWindow
*focused
= blackbox
->getFocusedWindow(),
1417 // if window is not on this screen, ignore it
1418 if (focused
->getScreen()->getScreenNumber() != getScreenNumber())
1419 focused
= (BlackboxWindow
*) 0;
1422 if (focused
&& current_workspace
->getCount() > 1) {
1423 // next is the next window to recieve focus, current is a place holder
1424 BlackboxWindow
*current
;
1427 next
= current_workspace
->getNextWindowInList(current
);
1428 } while(! next
->setInputFocus() && next
!= focused
);
1430 if (next
!= focused
)
1431 current_workspace
->raiseWindow(next
);
1432 } else if (current_workspace
->getCount() >= 1) {
1433 next
= current_workspace
->getTopWindowOnStack();
1435 current_workspace
->raiseWindow(next
);
1436 next
->setInputFocus();
1441 void BScreen::prevFocus(void) {
1442 BlackboxWindow
*focused
= blackbox
->getFocusedWindow(),
1446 // if window is not on this screen, ignore it
1447 if (focused
->getScreen()->getScreenNumber() != getScreenNumber())
1448 focused
= (BlackboxWindow
*) 0;
1451 if (focused
&& current_workspace
->getCount() > 1) {
1452 // next is the next window to recieve focus, current is a place holder
1453 BlackboxWindow
*current
;
1456 next
= current_workspace
->getPrevWindowInList(current
);
1457 } while(! next
->setInputFocus() && next
!= focused
);
1459 if (next
!= focused
)
1460 current_workspace
->raiseWindow(next
);
1461 } else if (current_workspace
->getCount() >= 1) {
1462 next
= current_workspace
->getTopWindowOnStack();
1464 current_workspace
->raiseWindow(next
);
1465 next
->setInputFocus();
1470 void BScreen::raiseFocus(void) {
1471 BlackboxWindow
*focused
= blackbox
->getFocusedWindow();
1475 // if on this Screen, raise it
1476 if (focused
->getScreen()->getScreenNumber() == getScreenNumber()) {
1477 Workspace
*workspace
= getWorkspace(focused
->getWorkspaceNumber());
1478 workspace
->raiseWindow(focused
);
1483 void BScreen::InitMenu(void) {
1485 rootmenuList
.clear();
1487 while (rootmenu
->getCount())
1488 rootmenu
->remove(0);
1490 rootmenu
= new Rootmenu(this);
1492 bool defaultMenu
= True
;
1494 FILE *menu_file
= (FILE *) 0;
1495 const char *menu_filename
= blackbox
->getMenuFilename();
1498 if (! (menu_file
= fopen(menu_filename
, "r")))
1499 perror(menu_filename
);
1500 if (! menu_file
) { // opening the menu file failed, try the default menu
1501 menu_filename
= DEFAULTMENU
;
1502 if (! (menu_file
= fopen(menu_filename
, "r")))
1503 perror(menu_filename
);
1507 if (feof(menu_file
)) {
1508 fprintf(stderr
, i18n(ScreenSet
, ScreenEmptyMenuFile
,
1509 "%s: Empty menu file"),
1512 char line
[1024], label
[1024];
1513 memset(line
, 0, 1024);
1514 memset(label
, 0, 1024);
1516 while (fgets(line
, 1024, menu_file
) && ! feof(menu_file
)) {
1517 if (line
[0] != '#') {
1518 int i
, key
= 0, index
= -1, len
= strlen(line
);
1520 for (i
= 0; i
< len
; i
++) {
1521 if (line
[i
] == '[') index
= 0;
1522 else if (line
[i
] == ']') break;
1523 else if (line
[i
] != ' ')
1525 key
+= tolower(line
[i
]);
1528 if (key
== 517) { // [begin]
1530 for (i
= index
; i
< len
; i
++) {
1531 if (line
[i
] == '(') index
= 0;
1532 else if (line
[i
] == ')') break;
1533 else if (index
++ >= 0) {
1534 if (line
[i
] == '\\' && i
< len
- 1) i
++;
1535 label
[index
- 1] = line
[i
];
1539 if (index
== -1) index
= 0;
1540 label
[index
] = '\0';
1542 rootmenu
->setLabel(label
);
1543 defaultMenu
= parseMenuFile(menu_file
, rootmenu
);
1545 blackbox
->addMenuTimestamp(menu_filename
);
1555 rootmenu
->setInternalMenu();
1556 rootmenu
->insert(i18n(ScreenSet
, Screenxterm
, "xterm"),
1558 i18n(ScreenSet
, Screenxterm
, "xterm"));
1559 rootmenu
->insert(i18n(ScreenSet
, ScreenRestart
, "Restart"),
1561 rootmenu
->insert(i18n(ScreenSet
, ScreenExit
, "Exit"),
1563 rootmenu
->setLabel(i18n(BasemenuSet
, BasemenuBlackboxMenu
,
1569 bool BScreen::parseMenuFile(FILE *file
, Rootmenu
*menu
) {
1570 char line
[1024], label
[1024], command
[1024];
1572 while (! feof(file
)) {
1573 memset(line
, 0, 1024);
1574 memset(label
, 0, 1024);
1575 memset(command
, 0, 1024);
1577 if (fgets(line
, 1024, file
)) {
1578 if (line
[0] != '#') {
1579 int i
, key
= 0, parse
= 0, index
= -1, line_length
= strlen(line
);
1581 // determine the keyword
1582 for (i
= 0; i
< line_length
; i
++) {
1583 if (line
[i
] == '[') parse
= 1;
1584 else if (line
[i
] == ']') break;
1585 else if (line
[i
] != ' ')
1587 key
+= tolower(line
[i
]);
1590 // get the label enclosed in ()'s
1593 for (i
= 0; i
< line_length
; i
++) {
1594 if (line
[i
] == '(') {
1597 } else if (line
[i
] == ')') break;
1598 else if (index
++ >= 0) {
1599 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
1600 label
[index
- 1] = line
[i
];
1605 label
[index
] = '\0';
1610 // get the command enclosed in {}'s
1613 for (i
= 0; i
< line_length
; i
++) {
1614 if (line
[i
] == '{') {
1617 } else if (line
[i
] == '}') break;
1618 else if (index
++ >= 0) {
1619 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
1620 command
[index
- 1] = line
[i
];
1625 command
[index
] = '\0';
1632 return ((menu
->getCount() == 0) ? True
: False
);
1639 menu
->insert(label
);
1644 if ((! *label
) && (! *command
)) {
1645 fprintf(stderr
, i18n(ScreenSet
, ScreenEXECError
,
1646 "BScreen::parseMenuFile: [exec] error, "
1647 "no menu label and/or command defined\n"));
1651 menu
->insert(label
, BScreen::Execute
, command
);
1657 fprintf(stderr
, i18n(ScreenSet
, ScreenEXITError
,
1658 "BScreen::parseMenuFile: [exit] error, "
1659 "no menu label defined\n"));
1663 menu
->insert(label
, BScreen::Exit
);
1669 if ((! *label
) || (! *command
)) {
1671 i18n(ScreenSet
, ScreenSTYLEError
,
1672 "BScreen::parseMenuFile: [style] error, "
1673 "no menu label and/or filename defined\n"));
1677 string style
= expandTilde(command
);
1679 menu
->insert(label
, BScreen::SetStyle
, style
.c_str());
1686 fprintf(stderr
, i18n(ScreenSet
, ScreenCONFIGError
,
1687 "BScreen::parseMenufile: [config] error, "
1688 "no label defined"));
1692 menu
->insert(label
, configmenu
);
1696 case 740: // include
1699 fprintf(stderr
, i18n(ScreenSet
, ScreenINCLUDEError
,
1700 "BScreen::parseMenuFile: [include] error, "
1701 "no filename defined\n"));
1705 string newfile
= expandTilde(label
);
1706 FILE *submenufile
= fopen(newfile
.c_str(), "r");
1710 if (fstat(fileno(submenufile
), &buf
) ||
1711 (! S_ISREG(buf
.st_mode
))) {
1713 i18n(ScreenSet
, ScreenINCLUDEErrorReg
,
1714 "BScreen::parseMenuFile: [include] error: "
1715 "'%s' is not a regular file\n"), newfile
.c_str());
1719 if (! feof(submenufile
)) {
1720 if (! parseMenuFile(submenufile
, menu
))
1721 blackbox
->addMenuTimestamp(newfile
);
1723 fclose(submenufile
);
1726 perror(newfile
.c_str());
1732 case 767: // submenu
1735 fprintf(stderr
, i18n(ScreenSet
, ScreenSUBMENUError
,
1736 "BScreen::parseMenuFile: [submenu] error, "
1737 "no menu label defined\n"));
1741 Rootmenu
*submenu
= new Rootmenu(this);
1744 submenu
->setLabel(command
);
1746 submenu
->setLabel(label
);
1748 parseMenuFile(file
, submenu
);
1750 menu
->insert(label
, submenu
);
1751 rootmenuList
.push_back(submenu
);
1756 case 773: // restart
1759 fprintf(stderr
, i18n(ScreenSet
, ScreenRESTARTError
,
1760 "BScreen::parseMenuFile: [restart] error, "
1761 "no menu label defined\n"));
1766 menu
->insert(label
, BScreen::RestartOther
, command
);
1768 menu
->insert(label
, BScreen::Restart
);
1773 case 845: // reconfig
1777 i18n(ScreenSet
, ScreenRECONFIGError
,
1778 "BScreen::parseMenuFile: [reconfig] error, "
1779 "no menu label defined\n"));
1783 menu
->insert(label
, BScreen::Reconfigure
);
1788 case 995: // stylesdir
1789 case 1113: // stylesmenu
1791 bool newmenu
= ((key
== 1113) ? True
: False
);
1793 if ((! *label
) || ((! *command
) && newmenu
)) {
1795 i18n(ScreenSet
, ScreenSTYLESDIRError
,
1796 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1797 " error, no directory defined\n"));
1801 char *directory
= ((newmenu
) ? command
: label
);
1803 string stylesdir
= expandTilde(directory
);
1805 struct stat statbuf
;
1807 if (! stat(stylesdir
.c_str(), &statbuf
)) {
1808 if (S_ISDIR(statbuf
.st_mode
)) {
1809 Rootmenu
*stylesmenu
;
1812 stylesmenu
= new Rootmenu(this);
1816 DIR *d
= opendir(stylesdir
.c_str());
1818 std::vector
<string
> ls
;
1820 while((p
= readdir(d
)))
1821 ls
.push_back(p
->d_name
);
1825 std::sort(ls
.begin(), ls
.end());
1827 std::vector
<string
>::iterator it
= ls
.begin(),
1829 for (; it
!= end
; ++it
) {
1830 const string
& fname
= *it
;
1832 if (fname
[fname
.size()-1] == '~')
1835 string style
= stylesdir
;
1839 if ((! stat(style
.c_str(), &statbuf
)) &&
1840 S_ISREG(statbuf
.st_mode
))
1841 stylesmenu
->insert(fname
, BScreen::SetStyle
, style
);
1844 stylesmenu
->update();
1847 stylesmenu
->setLabel(label
);
1848 menu
->insert(label
, stylesmenu
);
1849 rootmenuList
.push_back(stylesmenu
);
1852 blackbox
->addMenuTimestamp(stylesdir
);
1855 i18n(ScreenSet
, ScreenSTYLESDIRErrorNotDir
,
1856 "BScreen::parseMenuFile:"
1857 " [stylesdir/stylesmenu] error, %s is not a"
1858 " directory\n"), stylesdir
.c_str());
1862 i18n(ScreenSet
, ScreenSTYLESDIRErrorNoExist
,
1863 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1864 " error, %s does not exist\n"), stylesdir
.c_str());
1869 case 1090: // workspaces
1873 i18n(ScreenSet
, ScreenWORKSPACESError
,
1874 "BScreen:parseMenuFile: [workspaces] error, "
1875 "no menu label defined\n"));
1879 menu
->insert(label
, workspacemenu
);
1888 return ((menu
->getCount() == 0) ? True
: False
);
1892 void BScreen::shutdown(void) {
1893 XSelectInput(blackbox
->getXDisplay(), getRootWindow(), NoEventMask
);
1894 XSync(blackbox
->getXDisplay(), False
);
1896 while(! windowList
.empty())
1897 unmanageWindow(windowList
.front(), True
);
1903 void BScreen::showPosition(int x
, int y
) {
1904 if (! geom_visible
) {
1905 XMoveResizeWindow(blackbox
->getXDisplay(), geom_window
,
1906 (getWidth() - geom_w
) / 2,
1907 (getHeight() - geom_h
) / 2, geom_w
, geom_h
);
1908 XMapWindow(blackbox
->getXDisplay(), geom_window
);
1909 XRaiseWindow(blackbox
->getXDisplay(), geom_window
);
1911 geom_visible
= True
;
1916 sprintf(label
, i18n(ScreenSet
, ScreenPositionFormat
,
1917 "X: %4d x Y: %4d"), x
, y
);
1919 XClearWindow(blackbox
->getXDisplay(), geom_window
);
1921 resource
.wstyle
.font
->drawString(geom_window
,
1922 resource
.bevel_width
, resource
.bevel_width
,
1923 resource
.wstyle
.l_text_focus
,
1928 void BScreen::showGeometry(unsigned int gx
, unsigned int gy
) {
1929 if (! geom_visible
) {
1930 XMoveResizeWindow(blackbox
->getXDisplay(), geom_window
,
1931 (getWidth() - geom_w
) / 2,
1932 (getHeight() - geom_h
) / 2, geom_w
, geom_h
);
1933 XMapWindow(blackbox
->getXDisplay(), geom_window
);
1934 XRaiseWindow(blackbox
->getXDisplay(), geom_window
);
1936 geom_visible
= True
;
1941 sprintf(label
, i18n(ScreenSet
, ScreenGeometryFormat
,
1942 "W: %4d x H: %4d"), gx
, gy
);
1944 XClearWindow(blackbox
->getXDisplay(), geom_window
);
1946 resource
.wstyle
.font
->drawString(geom_window
,
1947 resource
.bevel_width
, resource
.bevel_width
,
1948 resource
.wstyle
.l_text_focus
,
1953 void BScreen::hideGeometry(void) {
1955 XUnmapWindow(blackbox
->getXDisplay(), geom_window
);
1956 geom_visible
= False
;
1961 void BScreen::addStrut(Strut
*strut
) {
1962 strutList
.push_back(strut
);
1966 void BScreen::removeStrut(Strut
*strut
) {
1967 strutList
.remove(strut
);
1971 const Rect
& BScreen::availableArea(void) const {
1973 return getRect(); // return the full screen
1978 void BScreen::updateAvailableArea(void) {
1979 Rect old_area
= usableArea
;
1980 usableArea
= getRect(); // reset to full screen
1982 /* these values represent offsets from the screen edge
1983 * we look for the biggest offset on each edge and then apply them
1985 * do not be confused by the similarity to the names of Rect's members
1987 unsigned int current_left
= 0, current_right
= 0, current_top
= 0,
1990 StrutList::const_iterator it
= strutList
.begin(), end
= strutList
.end();
1992 for(; it
!= end
; ++it
) {
1994 if (strut
->left
> current_left
)
1995 current_left
= strut
->left
;
1996 if (strut
->top
> current_top
)
1997 current_top
= strut
->top
;
1998 if (strut
->right
> current_right
)
1999 current_right
= strut
->right
;
2000 if (strut
->bottom
> current_bottom
)
2001 current_bottom
= strut
->bottom
;
2004 usableArea
.setPos(current_left
, current_top
);
2005 usableArea
.setSize(usableArea
.width() - (current_left
+ current_right
),
2006 usableArea
.height() - (current_top
+ current_bottom
));
2008 if (old_area
!= usableArea
) {
2009 BlackboxWindowList::iterator it
= windowList
.begin(),
2010 end
= windowList
.end();
2011 for (; it
!= end
; ++it
)
2012 if ((*it
)->isMaximized()) (*it
)->remaximize();
2019 Workspace
* BScreen::getWorkspace(unsigned int index
) {
2020 assert(index
< workspacesList
.size());
2021 return workspacesList
[index
];
2025 void BScreen::buttonPressEvent(const XButtonEvent
*xbutton
) {
2026 if (xbutton
->button
== 1) {
2027 if (! isRootColormapInstalled())
2028 image_control
->installRootColormap();
2030 if (workspacemenu
->isVisible())
2031 workspacemenu
->hide();
2033 if (rootmenu
->isVisible())
2035 } else if (xbutton
->button
== 2) {
2036 int mx
= xbutton
->x_root
- (workspacemenu
->getWidth() / 2);
2037 int my
= xbutton
->y_root
- (workspacemenu
->getTitleHeight() / 2);
2042 if (mx
+ workspacemenu
->getWidth() > getWidth())
2043 mx
= getWidth() - workspacemenu
->getWidth() - getBorderWidth();
2045 if (my
+ workspacemenu
->getHeight() > getHeight())
2046 my
= getHeight() - workspacemenu
->getHeight() - getBorderWidth();
2048 workspacemenu
->move(mx
, my
);
2050 if (! workspacemenu
->isVisible()) {
2051 workspacemenu
->removeParent();
2052 workspacemenu
->show();
2054 } else if (xbutton
->button
== 3) {
2055 int mx
= xbutton
->x_root
- (rootmenu
->getWidth() / 2);
2056 int my
= xbutton
->y_root
- (rootmenu
->getTitleHeight() / 2);
2061 if (mx
+ rootmenu
->getWidth() > getWidth())
2062 mx
= getWidth() - rootmenu
->getWidth() - getBorderWidth();
2064 if (my
+ rootmenu
->getHeight() > getHeight())
2065 my
= getHeight() - rootmenu
->getHeight() - getBorderWidth();
2067 rootmenu
->move(mx
, my
);
2069 if (! rootmenu
->isVisible()) {
2070 blackbox
->checkMenu();
2074 } else if (xbutton
->button
== 4) {
2075 if (getCurrentWorkspaceID() >= getWorkspaceCount() - 1)
2076 changeWorkspaceID(0);
2078 changeWorkspaceID(getCurrentWorkspaceID() + 1);
2080 } else if (xbutton
->button
== 5) {
2081 if (getCurrentWorkspaceID() == 0)
2082 changeWorkspaceID(getWorkspaceCount() - 1);
2084 changeWorkspaceID(getCurrentWorkspaceID() - 1);
2089 void BScreen::toggleFocusModel(FocusModel model
) {
2090 std::for_each(windowList
.begin(), windowList
.end(),
2091 std::mem_fun(&BlackboxWindow::ungrabButtons
));
2093 if (model
== SloppyFocus
) {
2094 saveSloppyFocus(True
);
2096 // we're cheating here to save writing the config file 3 times
2097 resource
.auto_raise
= False
;
2098 resource
.click_raise
= False
;
2099 saveSloppyFocus(False
);
2102 std::for_each(windowList
.begin(), windowList
.end(),
2103 std::mem_fun(&BlackboxWindow::grabButtons
));
2107 BTexture
BScreen::readDatabaseTexture(const string
&rname
,
2108 const string
&default_color
,
2109 const Configuration
&style
) {
2113 if (style
.getValue(rname
, s
))
2114 texture
= BTexture(s
);
2116 texture
.setTexture(BTexture::Solid
| BTexture::Flat
);
2118 // associate this texture with this screen
2119 texture
.setDisplay(getBaseDisplay(), getScreenNumber());
2120 texture
.setImageControl(image_control
);
2122 if (texture
.texture() & BTexture::Solid
) {
2123 texture
.setColor(readDatabaseColor(rname
+ ".color",
2124 default_color
, style
));
2125 texture
.setColorTo(readDatabaseColor(rname
+ ".colorTo",
2126 default_color
, style
));
2127 } else if (texture
.texture() & BTexture::Gradient
) {
2128 texture
.setColor(readDatabaseColor(rname
+ ".color",
2129 default_color
, style
));
2130 texture
.setColorTo(readDatabaseColor(rname
+ ".colorTo",
2131 default_color
, style
));
2138 BColor
BScreen::readDatabaseColor(const string
&rname
,
2139 const string
&default_color
,
2140 const Configuration
&style
) {
2143 if (style
.getValue(rname
, s
))
2144 color
= BColor(s
, getBaseDisplay(), getScreenNumber());
2146 color
= BColor(default_color
, getBaseDisplay(), getScreenNumber());
2151 BFont
*BScreen::readDatabaseFont(const string
&rbasename
,
2152 const Configuration
&style
) {
2159 if (style
.getValue(rbasename
+ "xft.font", s
) &&
2160 style
.getValue(rbasename
+ "xft.size", i
)) {
2163 bool italic
= False
;
2164 if (style
.getValue(rbasename
+ "xft.flags", s
)) {
2165 if (s
.find("bold") != string::npos
)
2167 if (s
.find("italic") != string::npos
)
2171 BFont
*b
= new BFont(blackbox
->getXDisplay(), this, family
, i
, bold
,
2172 italic
, resource
.aa_fonts
);
2176 delete b
; // fall back to the normal X font stuff
2180 style
.getValue(rbasename
+ "font", s
);
2181 // if this fails, a blank string will be used, which will cause the fallback
2184 BFont
*b
= new BFont(blackbox
->getXDisplay(), this, s
);
2186 exit(2); // can't continue without a font