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>
37 #endif // HAVE_STDLIB_H
41 #endif // HAVE_STRING_H
45 #endif // HAVE_CTYPE_H
48 # include <sys/types.h>
50 #endif // HAVE_UNISTD_H
54 #endif // HAVE_DIRENT_H
58 #endif // HAVE_LOCALE_H
60 #ifdef HAVE_SYS_STAT_H
61 # include <sys/stat.h>
62 #endif // HAVE_SYS_STAT_H
66 #endif // HAVE_STDARG_H
77 #include "blackbox.hh"
78 #include "Clientmenu.hh"
80 #include "Iconmenu.hh"
84 #include "Rootmenu.hh"
88 #include "Workspace.hh"
89 #include "Workspacemenu.hh"
92 #ifndef FONT_ELEMENT_SIZE
93 #define FONT_ELEMENT_SIZE 50
94 #endif // FONT_ELEMENT_SIZE
97 static bool running
= True
;
99 static int anotherWMRunning(Display
*display
, XErrorEvent
*) {
100 fprintf(stderr
, i18n(ScreenSet
, ScreenAnotherWMRunning
,
101 "BScreen::BScreen: an error occured while querying the X server.\n"
102 " another window manager already running on display %s.\n"),
103 DisplayString(display
));
111 BScreen::BScreen(Blackbox
*bb
, unsigned int scrn
) : ScreenInfo(bb
, scrn
) {
113 screenstr
= (string
)"session.screen" + itostring(scrn
) + '.';
114 config
= blackbox
->getConfig();
115 xatom
= blackbox
->getXAtom();
117 event_mask
= ColormapChangeMask
| EnterWindowMask
| PropertyChangeMask
|
118 SubstructureRedirectMask
| ButtonPressMask
| ButtonReleaseMask
;
120 XErrorHandler old
= XSetErrorHandler((XErrorHandler
) anotherWMRunning
);
121 XSelectInput(getBaseDisplay()->getXDisplay(), getRootWindow(), event_mask
);
122 XSync(getBaseDisplay()->getXDisplay(), False
);
123 XSetErrorHandler((XErrorHandler
) old
);
126 if (! managed
) return;
128 fprintf(stderr
, i18n(ScreenSet
, ScreenManagingScreen
,
129 "BScreen::BScreen: managing screen %d "
130 "using visual 0x%lx, depth %d\n"),
131 getScreenNumber(), XVisualIDFromVisual(getVisual()),
136 resource
.mstyle
.t_fontset
= resource
.mstyle
.f_fontset
=
137 resource
.tstyle
.fontset
= resource
.wstyle
.fontset
= (XFontSet
) 0;
138 resource
.mstyle
.t_font
= resource
.mstyle
.f_font
= resource
.tstyle
.font
=
139 resource
.wstyle
.font
= (XFontStruct
*) 0;
141 xatom
->setSupported(this); // set-up netwm support
143 xatom
->setValue(getRootWindow(), XAtom::blackbox_pid
, XAtom::cardinal
,
144 (unsigned long) getpid());
145 #endif // HAVE_GETPID
147 XDefineCursor(blackbox
->getXDisplay(), getRootWindow(),
148 blackbox
->getSessionCursor());
150 // start off full screen, top left.
151 usableArea
.setSize(getWidth(), getHeight());
154 new BImageControl(blackbox
, this, True
, blackbox
->getColorsPerChannel(),
155 blackbox
->getCacheLife(), blackbox
->getCacheMax());
156 image_control
->installRootColormap();
157 root_colormap_installed
= True
;
163 unsigned long gc_value_mask
= GCForeground
;
164 if (! i18n
.multibyte()) gc_value_mask
|= GCFont
;
166 gcv
.foreground
= WhitePixel(blackbox
->getXDisplay(), getScreenNumber())
167 ^ BlackPixel(blackbox
->getXDisplay(), getScreenNumber());
168 gcv
.function
= GXxor
;
169 gcv
.subwindow_mode
= IncludeInferiors
;
170 opGC
= XCreateGC(blackbox
->getXDisplay(), getRootWindow(),
171 GCForeground
| GCFunction
| GCSubwindowMode
, &gcv
);
173 const char *s
= i18n(ScreenSet
, ScreenPositionLength
,
174 "0: 0000 x 0: 0000");
177 if (i18n
.multibyte()) {
178 XRectangle ink
, logical
;
179 XmbTextExtents(resource
.wstyle
.fontset
, s
, l
, &ink
, &logical
);
180 geom_w
= logical
.width
;
182 geom_h
= resource
.wstyle
.fontset_extents
->max_ink_extent
.height
;
184 geom_h
= resource
.wstyle
.font
->ascent
+
185 resource
.wstyle
.font
->descent
;
187 geom_w
= XTextWidth(resource
.wstyle
.font
, s
, l
);
190 geom_w
+= (resource
.bevel_width
* 2);
191 geom_h
+= (resource
.bevel_width
* 2);
193 XSetWindowAttributes attrib
;
194 unsigned long mask
= CWBorderPixel
| CWColormap
| CWSaveUnder
;
195 attrib
.border_pixel
= getBorderColor()->pixel();
196 attrib
.colormap
= getColormap();
197 attrib
.save_under
= True
;
199 geom_window
= XCreateWindow(blackbox
->getXDisplay(), getRootWindow(),
200 0, 0, geom_w
, geom_h
, resource
.border_width
,
201 getDepth(), InputOutput
, getVisual(),
203 geom_visible
= False
;
205 BTexture
* texture
= &(resource
.wstyle
.l_focus
);
206 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
207 if (geom_pixmap
== ParentRelative
) {
208 texture
= &(resource
.wstyle
.t_focus
);
209 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
212 XSetWindowBackground(blackbox
->getXDisplay(), geom_window
,
213 texture
->color().pixel());
215 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
216 geom_window
, geom_pixmap
);
218 workspacemenu
= new Workspacemenu(this);
219 iconmenu
= new Iconmenu(this);
220 configmenu
= new Configmenu(this);
222 Workspace
*wkspc
= (Workspace
*) 0;
223 if (resource
.workspaces
!= 0) {
224 for (unsigned int i
= 0; i
< resource
.workspaces
; ++i
) {
225 wkspc
= new Workspace(this, workspacesList
.size());
226 workspacesList
.push_back(wkspc
);
227 workspacemenu
->insert(wkspc
->getName(), wkspc
->getMenu());
230 wkspc
= new Workspace(this, workspacesList
.size());
231 workspacesList
.push_back(wkspc
);
232 workspacemenu
->insert(wkspc
->getName(), wkspc
->getMenu());
234 saveWorkspaceNames();
236 updateNetizenWorkspaceCount();
238 workspacemenu
->insert(i18n(IconSet
, IconIcons
, "Icons"), iconmenu
);
239 workspacemenu
->update();
241 current_workspace
= workspacesList
.front();
243 xatom
->setValue(getRootWindow(), XAtom::net_current_desktop
,
244 XAtom::cardinal
, 0); //first workspace
246 workspacemenu
->setItemSelected(2, True
);
248 toolbar
= new Toolbar(this);
250 slit
= new Slit(this);
257 updateAvailableArea();
259 changeWorkspaceID(0);
261 unsigned int i
, j
, nchild
;
262 Window r
, p
, *children
;
263 XQueryTree(blackbox
->getXDisplay(), getRootWindow(), &r
, &p
,
266 // preen the window list of all icon windows... for better dockapp support
267 for (i
= 0; i
< nchild
; i
++) {
268 if (children
[i
] == None
) continue;
270 XWMHints
*wmhints
= XGetWMHints(blackbox
->getXDisplay(),
274 if ((wmhints
->flags
& IconWindowHint
) &&
275 (wmhints
->icon_window
!= children
[i
])) {
276 for (j
= 0; j
< nchild
; j
++) {
277 if (children
[j
] == wmhints
->icon_window
) {
288 // manage shown windows
289 for (i
= 0; i
< nchild
; ++i
) {
290 if (children
[i
] == None
|| (! blackbox
->validateWindow(children
[i
])))
293 XWindowAttributes attrib
;
294 if (XGetWindowAttributes(blackbox
->getXDisplay(), children
[i
], &attrib
)) {
295 if (attrib
.override_redirect
) continue;
297 if (attrib
.map_state
!= IsUnmapped
) {
298 manageWindow(children
[i
]);
305 // call this again just in case a window we found updates the Strut list
306 updateAvailableArea();
310 BScreen::~BScreen(void) {
311 if (! managed
) return;
313 if (geom_pixmap
!= None
)
314 image_control
->removeImage(geom_pixmap
);
316 if (geom_window
!= None
)
317 XDestroyWindow(blackbox
->getXDisplay(), geom_window
);
319 std::for_each(workspacesList
.begin(), workspacesList
.end(),
322 std::for_each(iconList
.begin(), iconList
.end(), PointerAssassin());
324 std::for_each(netizenList
.begin(), netizenList
.end(), PointerAssassin());
327 delete workspacemenu
;
332 delete image_control
;
334 if (resource
.wstyle
.fontset
)
335 XFreeFontSet(blackbox
->getXDisplay(), resource
.wstyle
.fontset
);
336 if (resource
.mstyle
.t_fontset
)
337 XFreeFontSet(blackbox
->getXDisplay(), resource
.mstyle
.t_fontset
);
338 if (resource
.mstyle
.f_fontset
)
339 XFreeFontSet(blackbox
->getXDisplay(), resource
.mstyle
.f_fontset
);
340 if (resource
.tstyle
.fontset
)
341 XFreeFontSet(blackbox
->getXDisplay(), resource
.tstyle
.fontset
);
343 if (resource
.wstyle
.font
)
344 XFreeFont(blackbox
->getXDisplay(), resource
.wstyle
.font
);
345 if (resource
.mstyle
.t_font
)
346 XFreeFont(blackbox
->getXDisplay(), resource
.mstyle
.t_font
);
347 if (resource
.mstyle
.f_font
)
348 XFreeFont(blackbox
->getXDisplay(), resource
.mstyle
.f_font
);
349 if (resource
.tstyle
.font
)
350 XFreeFont(blackbox
->getXDisplay(), resource
.tstyle
.font
);
352 XFreeGC(blackbox
->getXDisplay(), opGC
);
356 void BScreen::removeWorkspaceNames(void) {
357 workspaceNames
.clear();
360 void BScreen::saveSloppyFocus(bool s
) {
361 resource
.sloppy_focus
= s
;
364 if (resource
.sloppy_focus
) {
365 fmodel
= "SloppyFocus";
366 if (resource
.auto_raise
) fmodel
+= " AutoRaise";
367 if (resource
.click_raise
) fmodel
+= " ClickRaise";
369 fmodel
= "ClickToFocus";
371 config
->setValue(screenstr
+ "focusModel", fmodel
);
375 void BScreen::saveAutoRaise(bool a
) {
376 resource
.auto_raise
= a
;
377 saveSloppyFocus(resource
.sloppy_focus
);
381 void BScreen::saveClickRaise(bool c
) {
382 resource
.click_raise
= c
;
383 saveSloppyFocus(resource
.sloppy_focus
);
387 void BScreen::saveImageDither(bool d
) {
388 image_control
->setDither(d
);
389 config
->setValue(screenstr
+ "imageDither", doImageDither());
393 void BScreen::saveOpaqueMove(bool o
) {
394 resource
.opaque_move
= o
;
395 config
->setValue(screenstr
+ "opaqueMove", resource
.opaque_move
);
399 void BScreen::saveFullMax(bool f
) {
400 resource
.full_max
= f
;
401 config
->setValue(screenstr
+ "fullMaximization", resource
.full_max
);
405 void BScreen::saveFocusNew(bool f
) {
406 resource
.focus_new
= f
;
407 config
->setValue(screenstr
+ "focusNewWindows", resource
.focus_new
);
411 void BScreen::saveFocusLast(bool f
) {
412 resource
.focus_last
= f
;
413 config
->setValue(screenstr
+ "focusLastWindow", resource
.focus_last
);
417 void BScreen::saveHideToolbar(bool h
) {
418 resource
.hide_toolbar
= h
;
419 if (resource
.hide_toolbar
)
420 toolbar
->unmapToolbar();
422 toolbar
->mapToolbar();
423 config
->setValue(screenstr
+ "hideToolbar", resource
.hide_toolbar
);
427 void BScreen::saveWorkspaces(unsigned int w
) {
428 resource
.workspaces
= w
;
429 config
->setValue(screenstr
+ "workspaces", resource
.workspaces
);
433 void BScreen::savePlacementPolicy(int p
) {
434 resource
.placement_policy
= p
;
435 const char *placement
;
436 switch (resource
.placement_policy
) {
437 case CascadePlacement
: placement
= "CascadePlacement"; break;
438 case ColSmartPlacement
: placement
= "ColSmartPlacement"; break;
439 case RowSmartPlacement
: default: placement
= "RowSmartPlacement"; break;
441 config
->setValue(screenstr
+ "windowPlacement", placement
);
445 void BScreen::saveEdgeSnapThreshold(int t
) {
446 resource
.edge_snap_threshold
= t
;
447 config
->setValue(screenstr
+ "edgeSnapThreshold",
448 resource
.edge_snap_threshold
);
452 void BScreen::saveRowPlacementDirection(int d
) {
453 resource
.row_direction
= d
;
454 config
->setValue(screenstr
+ "rowPlacementDirection",
455 resource
.row_direction
== LeftRight
?
456 "LeftToRight" : "RightToLeft");
460 void BScreen::saveColPlacementDirection(int d
) {
461 resource
.col_direction
= d
;
462 config
->setValue(screenstr
+ "colPlacementDirection",
463 resource
.col_direction
== TopBottom
?
464 "TopToBottom" : "BottomToTop");
469 void BScreen::saveStrftimeFormat(const std::string
& format
) {
470 resource
.strftime_format
= format
;
471 config
->setValue(screenstr
+ "strftimeFormat", resource
.strftime_format
);
474 #else // !HAVE_STRFTIME
476 void BScreen::saveDateFormat(int f
) {
477 resource
.date_format
= f
;
478 config
->setValue(screenstr
+ "dateFormat",
479 resource
.date_format
== B_EuropeanDate
?
480 "European" : "American");
484 void BScreen::saveClock24Hour(Bool c
) {
485 resource
.clock24hour
= c
;
486 config
->setValue(screenstr
+ "clockFormat", resource
.clock24hour
? 24 : 12);
488 #endif // HAVE_STRFTIME
491 void BScreen::saveWorkspaceNames() {
493 WorkspaceList::iterator it
;
494 WorkspaceList::iterator last
= workspacesList
.end() - 1;
495 for (it
= workspacesList
.begin(); it
!= workspacesList
.end(); ++it
) {
496 names
+= (*it
)->getName();
500 config
->setValue(screenstr
+ "workspaceNames", names
);
504 void BScreen::save_rc(void) {
505 saveSloppyFocus(resource
.sloppy_focus
);
506 saveAutoRaise(resource
.auto_raise
);
507 saveImageDither(doImageDither());
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 saveWorkspaces(resource
.workspaces
);
514 savePlacementPolicy(resource
.placement_policy
);
515 saveEdgeSnapThreshold(resource
.edge_snap_threshold
);
516 saveRowPlacementDirection(resource
.row_direction
);
517 saveColPlacementDirection(resource
.col_direction
);
519 saveStrftimeFormat(resource
.strftime_format
);
520 #else // !HAVE_STRFTIME
521 saveDateFormat(resource
.date_format
);
522 savwClock24Hour(resource
.clock24hour
);
523 #endif // HAVE_STRFTIME
530 void BScreen::load_rc(void) {
534 if (! config
->getValue(screenstr
+ "fullMaximization", resource
.full_max
))
535 resource
.full_max
= false;
537 if (! config
->getValue(screenstr
+ "focusNewWindows", resource
.focus_new
))
538 resource
.focus_new
= false;
540 if (! config
->getValue(screenstr
+ "focusLastWindow", resource
.focus_last
))
541 resource
.focus_last
= false;
543 if (! config
->getValue(screenstr
+ "workspaces", resource
.workspaces
))
544 resource
.workspaces
= 1;
546 if (! config
->getValue(screenstr
+ "opaqueMove", resource
.opaque_move
))
547 resource
.opaque_move
= false;
549 if (! config
->getValue(screenstr
+ "hideToolbar", resource
.hide_toolbar
))
550 resource
.hide_toolbar
= false;
552 if (! config
->getValue(screenstr
+ "imageDither", b
))
554 image_control
->setDither(b
);
556 if (! config
->getValue(screenstr
+ "edgeSnapThreshold",
557 resource
.edge_snap_threshold
))
558 resource
.edge_snap_threshold
= 4;
560 if (config
->getValue(screenstr
+ "rowPlacementDirection", s
) &&
562 resource
.row_direction
= RightLeft
;
564 resource
.row_direction
= LeftRight
;
566 if (config
->getValue(screenstr
+ "colPlacementDirection", s
) &&
568 resource
.col_direction
= BottomTop
;
570 resource
.col_direction
= TopBottom
;
572 removeWorkspaceNames();
573 if (config
->getValue(screenstr
+ "workspaceNames", s
)) {
574 string::const_iterator it
= s
.begin(), end
= s
.end();
576 string::const_iterator tmp
= it
; // current string.begin()
577 it
= std::find(tmp
, end
, ','); // look for comma between tmp and end
578 addWorkspaceName(string(tmp
, it
)); // s[tmp:it]
585 resource
.sloppy_focus
= true;
586 resource
.auto_raise
= false;
587 resource
.click_raise
= false;
588 if (config
->getValue(screenstr
+ "focusModel", s
)) {
589 if (s
.find("ClickToFocus") != string::npos
) {
590 resource
.sloppy_focus
= false;
593 if (s
.find("AutoRaise") != string::npos
)
594 resource
.auto_raise
= true;
595 if (s
.find("ClickRaise") != string::npos
)
596 resource
.click_raise
= true;
600 if (config
->getValue(screenstr
+ "windowPlacement", s
)) {
601 if (s
== "CascadePlacement")
602 resource
.placement_policy
= CascadePlacement
;
603 else if (s
== "ColSmartPlacement")
604 resource
.placement_policy
= ColSmartPlacement
;
605 else //if (s == "RowSmartPlacement")
606 resource
.placement_policy
= RowSmartPlacement
;
608 resource
.placement_policy
= RowSmartPlacement
;
611 if (config
->getValue(screenstr
+ "strftimeFormat", s
))
612 resource
.strftime_format
= s
;
614 resource
.strftime_format
= "%I:%M %p";
615 #else // !HAVE_STRFTIME
618 if (config
->getValue(screenstr
+ "dateFormat", s
) && s
== "European")
619 resource
.date_format
= B_EuropeanDate
;
621 resource
.date_format
= B_AmericanDate
;
623 if (! config
->getValue(screenstr
+ "clockFormat", l
))
625 resource
.clock24hour
= l
== 24;
626 #endif // HAVE_STRFTIME
630 void BScreen::reconfigure(void) {
637 unsigned long gc_value_mask
= GCForeground
;
638 if (! i18n
.multibyte()) gc_value_mask
|= GCFont
;
640 gcv
.foreground
= WhitePixel(blackbox
->getXDisplay(),
642 gcv
.function
= GXinvert
;
643 gcv
.subwindow_mode
= IncludeInferiors
;
644 XChangeGC(blackbox
->getXDisplay(), opGC
,
645 GCForeground
| GCFunction
| GCSubwindowMode
, &gcv
);
647 const char *s
= i18n(ScreenSet
, ScreenPositionLength
,
648 "0: 0000 x 0: 0000");
651 if (i18n
.multibyte()) {
652 XRectangle ink
, logical
;
653 XmbTextExtents(resource
.wstyle
.fontset
, s
, l
, &ink
, &logical
);
654 geom_w
= logical
.width
;
656 geom_h
= resource
.wstyle
.fontset_extents
->max_ink_extent
.height
;
658 geom_w
= XTextWidth(resource
.wstyle
.font
, s
, l
);
660 geom_h
= resource
.wstyle
.font
->ascent
+ resource
.wstyle
.font
->descent
;
663 geom_w
+= (resource
.bevel_width
* 2);
664 geom_h
+= (resource
.bevel_width
* 2);
666 BTexture
* texture
= &(resource
.wstyle
.l_focus
);
667 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
668 if (geom_pixmap
== ParentRelative
) {
669 texture
= &(resource
.wstyle
.t_focus
);
670 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
673 XSetWindowBackground(blackbox
->getXDisplay(), geom_window
,
674 texture
->color().pixel());
676 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
677 geom_window
, geom_pixmap
);
679 XSetWindowBorderWidth(blackbox
->getXDisplay(), geom_window
,
680 resource
.border_width
);
681 XSetWindowBorder(blackbox
->getXDisplay(), geom_window
,
682 resource
.border_color
.pixel());
684 workspacemenu
->reconfigure();
685 iconmenu
->reconfigure();
687 typedef std::vector
<int> SubList
;
688 SubList remember_subs
;
690 // save the current open menus
691 Basemenu
*menu
= rootmenu
;
693 while ((submenu
= menu
->getCurrentSubmenu()) >= 0) {
694 remember_subs
.push_back(submenu
);
695 menu
= menu
->find(submenu
)->submenu();
701 rootmenu
->reconfigure();
703 // reopen the saved menus
705 const SubList::iterator subs_end
= remember_subs
.end();
706 for (SubList::iterator it
= remember_subs
.begin(); it
!= subs_end
; ++it
) {
707 menu
->drawSubmenu(*it
);
708 menu
= menu
->find(*it
)->submenu();
713 configmenu
->reconfigure();
715 toolbar
->reconfigure();
719 std::for_each(workspacesList
.begin(), workspacesList
.end(),
720 std::mem_fun(&Workspace::reconfigure
));
722 BlackboxWindowList::iterator iit
= iconList
.begin();
723 for (; iit
!= iconList
.end(); ++iit
) {
724 BlackboxWindow
*bw
= *iit
;
725 if (bw
->validateClient())
729 image_control
->timeout();
733 void BScreen::rereadMenu(void) {
737 rootmenu
->reconfigure();
741 void BScreen::LoadStyle(void) {
744 const char *sfile
= blackbox
->getStyleFilename();
746 style
.setFile(sfile
);
747 if (! style
.load()) {
748 style
.setFile(DEFAULTSTYLE
);
750 style
.create(); // hardcoded default values will be used.
756 // load fonts/fontsets
757 if (resource
.wstyle
.fontset
)
758 XFreeFontSet(blackbox
->getXDisplay(), resource
.wstyle
.fontset
);
759 if (resource
.tstyle
.fontset
)
760 XFreeFontSet(blackbox
->getXDisplay(), resource
.tstyle
.fontset
);
761 if (resource
.mstyle
.f_fontset
)
762 XFreeFontSet(blackbox
->getXDisplay(), resource
.mstyle
.f_fontset
);
763 if (resource
.mstyle
.t_fontset
)
764 XFreeFontSet(blackbox
->getXDisplay(), resource
.mstyle
.t_fontset
);
765 resource
.wstyle
.fontset
= 0;
766 resource
.tstyle
.fontset
= 0;
767 resource
.mstyle
.f_fontset
= 0;
768 resource
.mstyle
.t_fontset
= 0;
769 if (resource
.wstyle
.font
)
770 XFreeFont(blackbox
->getXDisplay(), resource
.wstyle
.font
);
771 if (resource
.tstyle
.font
)
772 XFreeFont(blackbox
->getXDisplay(), resource
.tstyle
.font
);
773 if (resource
.mstyle
.f_font
)
774 XFreeFont(blackbox
->getXDisplay(), resource
.mstyle
.f_font
);
775 if (resource
.mstyle
.t_font
)
776 XFreeFont(blackbox
->getXDisplay(), resource
.mstyle
.t_font
);
777 resource
.wstyle
.font
= 0;
778 resource
.tstyle
.font
= 0;
779 resource
.mstyle
.f_font
= 0;
780 resource
.mstyle
.t_font
= 0;
782 if (i18n
.multibyte()) {
783 resource
.wstyle
.fontset
= readDatabaseFontSet("window.font", style
);
784 resource
.tstyle
.fontset
= readDatabaseFontSet("toolbar.font", style
);
785 resource
.mstyle
.t_fontset
= readDatabaseFontSet("menu.title.font", style
);
786 resource
.mstyle
.f_fontset
= readDatabaseFontSet("menu.frame.font", style
);
788 resource
.mstyle
.t_fontset_extents
=
789 XExtentsOfFontSet(resource
.mstyle
.t_fontset
);
790 resource
.mstyle
.f_fontset_extents
=
791 XExtentsOfFontSet(resource
.mstyle
.f_fontset
);
792 resource
.tstyle
.fontset_extents
=
793 XExtentsOfFontSet(resource
.tstyle
.fontset
);
794 resource
.wstyle
.fontset_extents
=
795 XExtentsOfFontSet(resource
.wstyle
.fontset
);
797 resource
.wstyle
.font
= readDatabaseFont("window.font", style
);
798 resource
.tstyle
.font
= readDatabaseFont("toolbar.font", style
);
799 resource
.mstyle
.t_font
= readDatabaseFont("menu.title.font", style
);
800 resource
.mstyle
.f_font
= readDatabaseFont("menu.frame.font", style
);
803 // load window config
804 resource
.wstyle
.t_focus
=
805 readDatabaseTexture("window.title.focus", "white", style
);
806 resource
.wstyle
.t_unfocus
=
807 readDatabaseTexture("window.title.unfocus", "black", style
);
808 resource
.wstyle
.l_focus
=
809 readDatabaseTexture("window.label.focus", "white", style
);
810 resource
.wstyle
.l_unfocus
=
811 readDatabaseTexture("window.label.unfocus", "black", style
);
812 resource
.wstyle
.h_focus
=
813 readDatabaseTexture("window.handle.focus", "white", style
);
814 resource
.wstyle
.h_unfocus
=
815 readDatabaseTexture("window.handle.unfocus", "black", style
);
816 resource
.wstyle
.g_focus
=
817 readDatabaseTexture("window.grip.focus", "white", style
);
818 resource
.wstyle
.g_unfocus
=
819 readDatabaseTexture("window.grip.unfocus", "black", style
);
820 resource
.wstyle
.b_focus
=
821 readDatabaseTexture("window.button.focus", "white", style
);
822 resource
.wstyle
.b_unfocus
=
823 readDatabaseTexture("window.button.unfocus", "black", style
);
824 resource
.wstyle
.b_pressed
=
825 readDatabaseTexture("window.button.pressed", "black", style
);
826 resource
.wstyle
.f_focus
=
827 readDatabaseColor("window.frame.focusColor", "white", style
);
828 resource
.wstyle
.f_unfocus
=
829 readDatabaseColor("window.frame.unfocusColor", "black", style
);
830 resource
.wstyle
.l_text_focus
=
831 readDatabaseColor("window.label.focus.textColor", "black", style
);
832 resource
.wstyle
.l_text_unfocus
=
833 readDatabaseColor("window.label.unfocus.textColor", "white", style
);
834 resource
.wstyle
.b_pic_focus
=
835 readDatabaseColor("window.button.focus.picColor", "black", style
);
836 resource
.wstyle
.b_pic_unfocus
=
837 readDatabaseColor("window.button.unfocus.picColor", "white", style
);
839 resource
.wstyle
.justify
= LeftJustify
;
840 if (style
.getValue("window.justify", s
)) {
841 if (s
== "right" || s
== "Right")
842 resource
.wstyle
.justify
= RightJustify
;
843 else if (s
== "center" || s
== "Center")
844 resource
.wstyle
.justify
= CenterJustify
;
847 // load toolbar config
848 resource
.tstyle
.toolbar
=
849 readDatabaseTexture("toolbar", "black", style
);
850 resource
.tstyle
.label
=
851 readDatabaseTexture("toolbar.label", "black", style
);
852 resource
.tstyle
.window
=
853 readDatabaseTexture("toolbar.windowLabel", "black", style
);
854 resource
.tstyle
.button
=
855 readDatabaseTexture("toolbar.button", "white", style
);
856 resource
.tstyle
.pressed
=
857 readDatabaseTexture("toolbar.button.pressed", "black", style
);
858 resource
.tstyle
.clock
=
859 readDatabaseTexture("toolbar.clock", "black", style
);
860 resource
.tstyle
.l_text
=
861 readDatabaseColor("toolbar.label.textColor", "white", style
);
862 resource
.tstyle
.w_text
=
863 readDatabaseColor("toolbar.windowLabel.textColor", "white", style
);
864 resource
.tstyle
.c_text
=
865 readDatabaseColor("toolbar.clock.textColor", "white", style
);
866 resource
.tstyle
.b_pic
=
867 readDatabaseColor("toolbar.button.picColor", "black", style
);
869 resource
.tstyle
.justify
= LeftJustify
;
870 if (style
.getValue("toolbar.justify", s
)) {
871 if (s
== "right" || s
== "Right")
872 resource
.tstyle
.justify
= RightJustify
;
873 else if (s
== "center" || s
== "Center")
874 resource
.tstyle
.justify
= CenterJustify
;
878 resource
.mstyle
.title
=
879 readDatabaseTexture("menu.title", "white", style
);
880 resource
.mstyle
.frame
=
881 readDatabaseTexture("menu.frame", "black", style
);
882 resource
.mstyle
.hilite
=
883 readDatabaseTexture("menu.hilite", "white", style
);
884 resource
.mstyle
.t_text
=
885 readDatabaseColor("menu.title.textColor", "black", style
);
886 resource
.mstyle
.f_text
=
887 readDatabaseColor("menu.frame.textColor", "white", style
);
888 resource
.mstyle
.d_text
=
889 readDatabaseColor("menu.frame.disableColor", "black", style
);
890 resource
.mstyle
.h_text
=
891 readDatabaseColor("menu.hilite.textColor", "black", style
);
893 resource
.mstyle
.t_justify
= LeftJustify
;
894 if (style
.getValue("menu.title.justify", s
)) {
895 if (s
== "right" || s
== "Right")
896 resource
.mstyle
.t_justify
= RightJustify
;
897 else if (s
== "center" || s
== "Center")
898 resource
.mstyle
.t_justify
= CenterJustify
;
901 resource
.mstyle
.f_justify
= LeftJustify
;
902 if (style
.getValue("menu.frame.justify", s
)) {
903 if (s
== "right" || s
== "Right")
904 resource
.mstyle
.f_justify
= RightJustify
;
905 else if (s
== "center" || s
== "Center")
906 resource
.mstyle
.f_justify
= CenterJustify
;
909 resource
.mstyle
.bullet
= Basemenu::Triangle
;
910 if (style
.getValue("menu.bullet", s
)) {
911 if (s
== "empty" || s
== "Empty")
912 resource
.mstyle
.bullet
= Basemenu::Empty
;
913 else if (s
== "square" || s
== "Square")
914 resource
.mstyle
.bullet
= Basemenu::Square
;
915 else if (s
== "diamond" || s
== "Diamond")
916 resource
.mstyle
.bullet
= Basemenu::Diamond
;
919 resource
.mstyle
.bullet_pos
= Basemenu::Left
;
920 if (style
.getValue("menu.bullet.position", s
)) {
921 if (s
== "right" || s
== "Right")
922 resource
.mstyle
.bullet_pos
= Basemenu::Right
;
925 resource
.border_color
=
926 readDatabaseColor("borderColor", "black", style
);
928 // load bevel, border and handle widths
929 if (! style
.getValue("handleWidth", resource
.handle_width
) ||
930 resource
.handle_width
> (getWidth() / 2) || resource
.handle_width
== 0)
931 resource
.handle_width
= 6;
933 if (! style
.getValue("borderWidth", resource
.border_width
))
934 resource
.border_width
= 1;
936 if (! style
.getValue("bevelWidth", resource
.bevel_width
) ||
937 resource
.bevel_width
> (getWidth() / 2) || resource
.bevel_width
== 0)
938 resource
.bevel_width
= 3;
940 if (! style
.getValue("frameWidth", resource
.frame_width
) ||
941 resource
.frame_width
> (getWidth() / 2))
942 resource
.frame_width
= resource
.bevel_width
;
944 if (style
.getValue("rootCommand", s
))
945 bexec(s
, displayString());
949 void BScreen::addIcon(BlackboxWindow
*w
) {
952 w
->setWorkspace(BSENTINEL
);
953 w
->setWindowNumber(iconList
.size());
955 iconList
.push_back(w
);
957 const char* title
= w
->getIconTitle();
958 iconmenu
->insert(title
);
963 void BScreen::removeIcon(BlackboxWindow
*w
) {
968 iconmenu
->remove(w
->getWindowNumber());
971 BlackboxWindowList::iterator it
= iconList
.begin(),
972 end
= iconList
.end();
973 for (int i
= 0; it
!= end
; ++it
)
974 (*it
)->setWindowNumber(i
++);
978 BlackboxWindow
*BScreen::getIcon(unsigned int index
) {
979 if (index
< iconList
.size()) {
980 BlackboxWindowList::iterator it
= iconList
.begin();
981 for (; index
> 0; --index
, ++it
) ; /* increment to index */
985 return (BlackboxWindow
*) 0;
989 unsigned int BScreen::addWorkspace(void) {
990 Workspace
*wkspc
= new Workspace(this, workspacesList
.size());
991 workspacesList
.push_back(wkspc
);
992 saveWorkspaces(getWorkspaceCount());
993 saveWorkspaceNames();
995 workspacemenu
->insert(wkspc
->getName(), wkspc
->getMenu(),
997 workspacemenu
->update();
999 toolbar
->reconfigure();
1001 updateNetizenWorkspaceCount();
1003 return workspacesList
.size();
1007 unsigned int BScreen::removeLastWorkspace(void) {
1008 if (workspacesList
.size() == 1)
1011 Workspace
*wkspc
= workspacesList
.back();
1013 if (current_workspace
->getID() == wkspc
->getID())
1014 changeWorkspaceID(current_workspace
->getID() - 1);
1018 workspacemenu
->remove(wkspc
->getID() + 2);
1019 workspacemenu
->update();
1021 workspacesList
.pop_back();
1024 saveWorkspaces(getWorkspaceCount());
1025 saveWorkspaceNames();
1027 toolbar
->reconfigure();
1029 updateNetizenWorkspaceCount();
1031 return workspacesList
.size();
1035 void BScreen::changeWorkspaceID(unsigned int id
) {
1036 if (! current_workspace
) return;
1038 if (id
!= current_workspace
->getID()) {
1039 current_workspace
->hideAll();
1041 workspacemenu
->setItemSelected(current_workspace
->getID() + 2, False
);
1043 if (blackbox
->getFocusedWindow() &&
1044 blackbox
->getFocusedWindow()->getScreen() == this &&
1045 ! blackbox
->getFocusedWindow()->isStuck()) {
1046 current_workspace
->setLastFocusedWindow(blackbox
->getFocusedWindow());
1047 blackbox
->setFocusedWindow((BlackboxWindow
*) 0);
1050 current_workspace
= getWorkspace(id
);
1052 xatom
->setValue(getRootWindow(), XAtom::net_current_desktop
,
1053 XAtom::cardinal
, id
);
1056 workspacemenu
->setItemSelected(current_workspace
->getID() + 2, True
);
1057 toolbar
->redrawWorkspaceLabel(True
);
1059 current_workspace
->showAll();
1061 if (resource
.focus_last
&& current_workspace
->getLastFocusedWindow()) {
1062 XSync(blackbox
->getXDisplay(), False
);
1063 current_workspace
->getLastFocusedWindow()->setInputFocus();
1067 updateNetizenCurrentWorkspace();
1071 void BScreen::manageWindow(Window w
) {
1072 new BlackboxWindow(blackbox
, w
, this);
1074 BlackboxWindow
*win
= blackbox
->searchWindow(w
);
1078 windowList
.push_back(win
);
1080 XMapRequestEvent mre
;
1082 win
->restoreAttributes();
1083 win
->mapRequestEvent(&mre
);
1087 void BScreen::unmanageWindow(BlackboxWindow
*w
, bool remap
) {
1090 if (w
->getWorkspaceNumber() != BSENTINEL
&&
1091 w
->getWindowNumber() != BSENTINEL
)
1092 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
1093 else if (w
->isIconic())
1096 windowList
.remove(w
);
1098 if (blackbox
->getFocusedWindow() == w
)
1099 blackbox
->setFocusedWindow((BlackboxWindow
*) 0);
1101 removeNetizen(w
->getClientWindow());
1104 some managed windows can also be window group controllers. when
1105 unmanaging such windows, we should also delete the window group.
1107 BWindowGroup
*group
= blackbox
->searchGroup(w
->getClientWindow());
1114 void BScreen::addNetizen(Netizen
*n
) {
1115 netizenList
.push_back(n
);
1117 n
->sendWorkspaceCount();
1118 n
->sendCurrentWorkspace();
1120 WorkspaceList::iterator it
= workspacesList
.begin();
1121 const WorkspaceList::iterator end
= workspacesList
.end();
1122 for (; it
!= end
; ++it
)
1123 (*it
)->sendWindowList(*n
);
1125 Window f
= ((blackbox
->getFocusedWindow()) ?
1126 blackbox
->getFocusedWindow()->getClientWindow() : None
);
1127 n
->sendWindowFocus(f
);
1131 void BScreen::removeNetizen(Window w
) {
1132 NetizenList::iterator it
= netizenList
.begin();
1133 for (; it
!= netizenList
.end(); ++it
) {
1134 if ((*it
)->getWindowID() == w
) {
1136 netizenList
.erase(it
);
1143 void BScreen::updateNetizenCurrentWorkspace(void) {
1144 std::for_each(netizenList
.begin(), netizenList
.end(),
1145 std::mem_fun(&Netizen::sendCurrentWorkspace
));
1149 void BScreen::updateNetizenWorkspaceCount(void) {
1150 xatom
->setValue(getRootWindow(), XAtom::net_number_of_desktops
,
1151 XAtom::cardinal
, workspacesList
.size());
1153 std::for_each(netizenList
.begin(), netizenList
.end(),
1154 std::mem_fun(&Netizen::sendWorkspaceCount
));
1158 void BScreen::updateNetizenWindowFocus(void) {
1159 Window f
= ((blackbox
->getFocusedWindow()) ?
1160 blackbox
->getFocusedWindow()->getClientWindow() : None
);
1161 NetizenList::iterator it
= netizenList
.begin();
1162 for (; it
!= netizenList
.end(); ++it
)
1163 (*it
)->sendWindowFocus(f
);
1167 void BScreen::updateNetizenWindowAdd(Window w
, unsigned long p
) {
1168 NetizenList::iterator it
= netizenList
.begin();
1169 for (; it
!= netizenList
.end(); ++it
) {
1170 (*it
)->sendWindowAdd(w
, p
);
1175 void BScreen::updateNetizenWindowDel(Window w
) {
1176 NetizenList::iterator it
= netizenList
.begin();
1177 for (; it
!= netizenList
.end(); ++it
)
1178 (*it
)->sendWindowDel(w
);
1182 void BScreen::updateNetizenWindowRaise(Window w
) {
1183 NetizenList::iterator it
= netizenList
.begin();
1184 for (; it
!= netizenList
.end(); ++it
)
1185 (*it
)->sendWindowRaise(w
);
1189 void BScreen::updateNetizenWindowLower(Window w
) {
1190 NetizenList::iterator it
= netizenList
.begin();
1191 for (; it
!= netizenList
.end(); ++it
)
1192 (*it
)->sendWindowLower(w
);
1196 void BScreen::updateNetizenConfigNotify(XEvent
*e
) {
1197 NetizenList::iterator it
= netizenList
.begin();
1198 for (; it
!= netizenList
.end(); ++it
)
1199 (*it
)->sendConfigNotify(e
);
1203 void BScreen::raiseWindows(Window
*workspace_stack
, unsigned int num
) {
1205 Window
*session_stack
= new
1206 Window
[(num
+ workspacesList
.size() + rootmenuList
.size() + 13)];
1207 unsigned int i
= 0, k
= num
;
1209 XRaiseWindow(blackbox
->getXDisplay(), iconmenu
->getWindowID());
1210 *(session_stack
+ i
++) = iconmenu
->getWindowID();
1212 WorkspaceList::iterator wit
= workspacesList
.begin();
1213 const WorkspaceList::iterator w_end
= workspacesList
.end();
1214 for (; wit
!= w_end
; ++wit
)
1215 *(session_stack
+ i
++) = (*wit
)->getMenu()->getWindowID();
1217 *(session_stack
+ i
++) = workspacemenu
->getWindowID();
1219 *(session_stack
+ i
++) = configmenu
->getFocusmenu()->getWindowID();
1220 *(session_stack
+ i
++) = configmenu
->getPlacementmenu()->getWindowID();
1221 *(session_stack
+ i
++) = configmenu
->getWindowID();
1223 *(session_stack
+ i
++) = slit
->getMenu()->getDirectionmenu()->getWindowID();
1224 *(session_stack
+ i
++) = slit
->getMenu()->getPlacementmenu()->getWindowID();
1225 *(session_stack
+ i
++) = slit
->getMenu()->getWindowID();
1227 *(session_stack
+ i
++) =
1228 toolbar
->getMenu()->getPlacementmenu()->getWindowID();
1229 *(session_stack
+ i
++) = toolbar
->getMenu()->getWindowID();
1231 RootmenuList::iterator rit
= rootmenuList
.begin();
1232 for (; rit
!= rootmenuList
.end(); ++rit
)
1233 *(session_stack
+ i
++) = (*rit
)->getWindowID();
1234 *(session_stack
+ i
++) = rootmenu
->getWindowID();
1236 if (toolbar
->isOnTop())
1237 *(session_stack
+ i
++) = toolbar
->getWindowID();
1239 if (slit
->isOnTop())
1240 *(session_stack
+ i
++) = slit
->getWindowID();
1243 *(session_stack
+ i
++) = *(workspace_stack
+ k
);
1245 XRestackWindows(blackbox
->getXDisplay(), session_stack
, i
);
1247 delete [] session_stack
;
1251 void BScreen::addWorkspaceName(const string
& name
) {
1252 workspaceNames
.push_back(name
);
1257 * I would love to kill this function and the accompanying workspaceNames
1258 * list. However, we have a chicken and egg situation. The names are read
1259 * in during load_rc() which happens before the workspaces are created.
1260 * The current solution is to read the names into a list, then use the list
1261 * later for constructing the workspaces. It is only used during initial
1264 const string
BScreen::getNameOfWorkspace(unsigned int id
) {
1265 if (id
< workspaceNames
.size())
1266 return workspaceNames
[id
];
1271 void BScreen::reassociateWindow(BlackboxWindow
*w
, unsigned int wkspc_id
,
1272 bool ignore_sticky
) {
1275 if (wkspc_id
== BSENTINEL
)
1276 wkspc_id
= current_workspace
->getID();
1278 if (w
->getWorkspaceNumber() == wkspc_id
)
1281 if (w
->isIconic()) {
1283 getWorkspace(wkspc_id
)->addWindow(w
);
1284 } else if (ignore_sticky
|| ! w
->isStuck()) {
1285 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
1286 getWorkspace(wkspc_id
)->addWindow(w
);
1291 void BScreen::propagateWindowName(const BlackboxWindow
*bw
) {
1292 if (bw
->isIconic()) {
1293 iconmenu
->changeItemLabel(bw
->getWindowNumber(), bw
->getIconTitle());
1297 Clientmenu
*clientmenu
= getWorkspace(bw
->getWorkspaceNumber())->getMenu();
1298 clientmenu
->changeItemLabel(bw
->getWindowNumber(), bw
->getTitle());
1299 clientmenu
->update();
1301 if (blackbox
->getFocusedWindow() == bw
)
1302 toolbar
->redrawWindowLabel(True
);
1307 void BScreen::nextFocus(void) {
1308 BlackboxWindow
*focused
= blackbox
->getFocusedWindow(),
1312 // if window is not on this screen, ignore it
1313 if (focused
->getScreen()->getScreenNumber() != getScreenNumber())
1314 focused
= (BlackboxWindow
*) 0;
1317 if (focused
&& current_workspace
->getCount() > 1) {
1318 // next is the next window to recieve focus, current is a place holder
1319 BlackboxWindow
*current
;
1322 next
= current_workspace
->getNextWindowInList(current
);
1323 } while(! next
->setInputFocus() && next
!= focused
);
1325 if (next
!= focused
)
1326 current_workspace
->raiseWindow(next
);
1327 } else if (current_workspace
->getCount() >= 1) {
1328 next
= current_workspace
->getTopWindowOnStack();
1330 current_workspace
->raiseWindow(next
);
1331 next
->setInputFocus();
1336 void BScreen::prevFocus(void) {
1337 BlackboxWindow
*focused
= blackbox
->getFocusedWindow(),
1341 // if window is not on this screen, ignore it
1342 if (focused
->getScreen()->getScreenNumber() != getScreenNumber())
1343 focused
= (BlackboxWindow
*) 0;
1346 if (focused
&& current_workspace
->getCount() > 1) {
1347 // next is the next window to recieve focus, current is a place holder
1348 BlackboxWindow
*current
;
1351 next
= current_workspace
->getPrevWindowInList(current
);
1352 } while(! next
->setInputFocus() && next
!= focused
);
1354 if (next
!= focused
)
1355 current_workspace
->raiseWindow(next
);
1356 } else if (current_workspace
->getCount() >= 1) {
1357 next
= current_workspace
->getTopWindowOnStack();
1359 current_workspace
->raiseWindow(next
);
1360 next
->setInputFocus();
1365 void BScreen::raiseFocus(void) {
1366 BlackboxWindow
*focused
= blackbox
->getFocusedWindow();
1370 // if on this Screen, raise it
1371 if (focused
->getScreen()->getScreenNumber() == getScreenNumber()) {
1372 Workspace
*workspace
= getWorkspace(focused
->getWorkspaceNumber());
1373 workspace
->raiseWindow(focused
);
1378 void BScreen::InitMenu(void) {
1380 rootmenuList
.clear();
1382 while (rootmenu
->getCount())
1383 rootmenu
->remove(0);
1385 rootmenu
= new Rootmenu(this);
1387 bool defaultMenu
= True
;
1389 FILE *menu_file
= (FILE *) 0;
1390 const char *menu_filename
= blackbox
->getMenuFilename();
1393 if (! (menu_file
= fopen(menu_filename
, "r")))
1394 perror(menu_filename
);
1395 if (! menu_file
) { // opening the menu file failed, try the default menu
1396 menu_filename
= DEFAULTMENU
;
1397 if (! (menu_file
= fopen(menu_filename
, "r")))
1398 perror(menu_filename
);
1402 if (feof(menu_file
)) {
1403 fprintf(stderr
, i18n(ScreenSet
, ScreenEmptyMenuFile
,
1404 "%s: Empty menu file"),
1407 char line
[1024], label
[1024];
1408 memset(line
, 0, 1024);
1409 memset(label
, 0, 1024);
1411 while (fgets(line
, 1024, menu_file
) && ! feof(menu_file
)) {
1412 if (line
[0] != '#') {
1413 int i
, key
= 0, index
= -1, len
= strlen(line
);
1415 for (i
= 0; i
< len
; i
++) {
1416 if (line
[i
] == '[') index
= 0;
1417 else if (line
[i
] == ']') break;
1418 else if (line
[i
] != ' ')
1420 key
+= tolower(line
[i
]);
1423 if (key
== 517) { // [begin]
1425 for (i
= index
; i
< len
; i
++) {
1426 if (line
[i
] == '(') index
= 0;
1427 else if (line
[i
] == ')') break;
1428 else if (index
++ >= 0) {
1429 if (line
[i
] == '\\' && i
< len
- 1) i
++;
1430 label
[index
- 1] = line
[i
];
1434 if (index
== -1) index
= 0;
1435 label
[index
] = '\0';
1437 rootmenu
->setLabel(label
);
1438 defaultMenu
= parseMenuFile(menu_file
, rootmenu
);
1440 blackbox
->addMenuTimestamp(menu_filename
);
1450 rootmenu
->setInternalMenu();
1451 rootmenu
->insert(i18n(ScreenSet
, Screenxterm
, "xterm"),
1453 i18n(ScreenSet
, Screenxterm
, "xterm"));
1454 rootmenu
->insert(i18n(ScreenSet
, ScreenRestart
, "Restart"),
1456 rootmenu
->insert(i18n(ScreenSet
, ScreenExit
, "Exit"),
1458 rootmenu
->setLabel(i18n(BasemenuSet
, BasemenuBlackboxMenu
,
1464 bool BScreen::parseMenuFile(FILE *file
, Rootmenu
*menu
) {
1465 char line
[1024], label
[1024], command
[1024];
1467 while (! feof(file
)) {
1468 memset(line
, 0, 1024);
1469 memset(label
, 0, 1024);
1470 memset(command
, 0, 1024);
1472 if (fgets(line
, 1024, file
)) {
1473 if (line
[0] != '#') {
1474 int i
, key
= 0, parse
= 0, index
= -1, line_length
= strlen(line
);
1476 // determine the keyword
1477 for (i
= 0; i
< line_length
; i
++) {
1478 if (line
[i
] == '[') parse
= 1;
1479 else if (line
[i
] == ']') break;
1480 else if (line
[i
] != ' ')
1482 key
+= tolower(line
[i
]);
1485 // get the label enclosed in ()'s
1488 for (i
= 0; i
< line_length
; i
++) {
1489 if (line
[i
] == '(') {
1492 } else if (line
[i
] == ')') break;
1493 else if (index
++ >= 0) {
1494 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
1495 label
[index
- 1] = line
[i
];
1500 label
[index
] = '\0';
1505 // get the command enclosed in {}'s
1508 for (i
= 0; i
< line_length
; i
++) {
1509 if (line
[i
] == '{') {
1512 } else if (line
[i
] == '}') break;
1513 else if (index
++ >= 0) {
1514 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
1515 command
[index
- 1] = line
[i
];
1520 command
[index
] = '\0';
1527 return ((menu
->getCount() == 0) ? True
: False
);
1534 menu
->insert(label
);
1539 if ((! *label
) && (! *command
)) {
1540 fprintf(stderr
, i18n(ScreenSet
, ScreenEXECError
,
1541 "BScreen::parseMenuFile: [exec] error, "
1542 "no menu label and/or command defined\n"));
1546 menu
->insert(label
, BScreen::Execute
, command
);
1552 fprintf(stderr
, i18n(ScreenSet
, ScreenEXITError
,
1553 "BScreen::parseMenuFile: [exit] error, "
1554 "no menu label defined\n"));
1558 menu
->insert(label
, BScreen::Exit
);
1564 if ((! *label
) || (! *command
)) {
1566 i18n(ScreenSet
, ScreenSTYLEError
,
1567 "BScreen::parseMenuFile: [style] error, "
1568 "no menu label and/or filename defined\n"));
1572 string style
= expandTilde(command
);
1574 menu
->insert(label
, BScreen::SetStyle
, style
.c_str());
1581 fprintf(stderr
, i18n(ScreenSet
, ScreenCONFIGError
,
1582 "BScreen::parseMenufile: [config] error, "
1583 "no label defined"));
1587 menu
->insert(label
, configmenu
);
1591 case 740: // include
1594 fprintf(stderr
, i18n(ScreenSet
, ScreenINCLUDEError
,
1595 "BScreen::parseMenuFile: [include] error, "
1596 "no filename defined\n"));
1600 string newfile
= expandTilde(label
);
1601 FILE *submenufile
= fopen(newfile
.c_str(), "r");
1605 if (fstat(fileno(submenufile
), &buf
) ||
1606 (! S_ISREG(buf
.st_mode
))) {
1608 i18n(ScreenSet
, ScreenINCLUDEErrorReg
,
1609 "BScreen::parseMenuFile: [include] error: "
1610 "'%s' is not a regular file\n"), newfile
.c_str());
1614 if (! feof(submenufile
)) {
1615 if (! parseMenuFile(submenufile
, menu
))
1616 blackbox
->addMenuTimestamp(newfile
);
1618 fclose(submenufile
);
1621 perror(newfile
.c_str());
1627 case 767: // submenu
1630 fprintf(stderr
, i18n(ScreenSet
, ScreenSUBMENUError
,
1631 "BScreen::parseMenuFile: [submenu] error, "
1632 "no menu label defined\n"));
1636 Rootmenu
*submenu
= new Rootmenu(this);
1639 submenu
->setLabel(command
);
1641 submenu
->setLabel(label
);
1643 parseMenuFile(file
, submenu
);
1645 menu
->insert(label
, submenu
);
1646 rootmenuList
.push_back(submenu
);
1651 case 773: // restart
1654 fprintf(stderr
, i18n(ScreenSet
, ScreenRESTARTError
,
1655 "BScreen::parseMenuFile: [restart] error, "
1656 "no menu label defined\n"));
1661 menu
->insert(label
, BScreen::RestartOther
, command
);
1663 menu
->insert(label
, BScreen::Restart
);
1668 case 845: // reconfig
1672 i18n(ScreenSet
, ScreenRECONFIGError
,
1673 "BScreen::parseMenuFile: [reconfig] error, "
1674 "no menu label defined\n"));
1678 menu
->insert(label
, BScreen::Reconfigure
);
1683 case 995: // stylesdir
1684 case 1113: // stylesmenu
1686 bool newmenu
= ((key
== 1113) ? True
: False
);
1688 if ((! *label
) || ((! *command
) && newmenu
)) {
1690 i18n(ScreenSet
, ScreenSTYLESDIRError
,
1691 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1692 " error, no directory defined\n"));
1696 char *directory
= ((newmenu
) ? command
: label
);
1698 string stylesdir
= expandTilde(directory
);
1700 struct stat statbuf
;
1702 if (! stat(stylesdir
.c_str(), &statbuf
)) {
1703 if (S_ISDIR(statbuf
.st_mode
)) {
1704 Rootmenu
*stylesmenu
;
1707 stylesmenu
= new Rootmenu(this);
1711 DIR *d
= opendir(stylesdir
.c_str());
1713 std::vector
<string
> ls
;
1715 while((p
= readdir(d
)))
1716 ls
.push_back(p
->d_name
);
1720 std::sort(ls
.begin(), ls
.end());
1722 std::vector
<string
>::iterator it
= ls
.begin(),
1724 for (; it
!= end
; ++it
) {
1725 const string
& fname
= *it
;
1727 if (fname
[fname
.size()-1] == '~')
1730 string style
= stylesdir
;
1734 if ((! stat(style
.c_str(), &statbuf
)) &&
1735 S_ISREG(statbuf
.st_mode
))
1736 stylesmenu
->insert(fname
, BScreen::SetStyle
, style
);
1739 stylesmenu
->update();
1742 stylesmenu
->setLabel(label
);
1743 menu
->insert(label
, stylesmenu
);
1744 rootmenuList
.push_back(stylesmenu
);
1747 blackbox
->addMenuTimestamp(stylesdir
);
1750 i18n(ScreenSet
, ScreenSTYLESDIRErrorNotDir
,
1751 "BScreen::parseMenuFile:"
1752 " [stylesdir/stylesmenu] error, %s is not a"
1753 " directory\n"), stylesdir
.c_str());
1757 i18n(ScreenSet
, ScreenSTYLESDIRErrorNoExist
,
1758 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1759 " error, %s does not exist\n"), stylesdir
.c_str());
1764 case 1090: // workspaces
1768 i18n(ScreenSet
, ScreenWORKSPACESError
,
1769 "BScreen:parseMenuFile: [workspaces] error, "
1770 "no menu label defined\n"));
1774 menu
->insert(label
, workspacemenu
);
1783 return ((menu
->getCount() == 0) ? True
: False
);
1787 void BScreen::shutdown(void) {
1788 XSelectInput(blackbox
->getXDisplay(), getRootWindow(), NoEventMask
);
1789 XSync(blackbox
->getXDisplay(), False
);
1791 while(! windowList
.empty())
1792 unmanageWindow(windowList
.front(), True
);
1798 void BScreen::showPosition(int x
, int y
) {
1799 if (! geom_visible
) {
1800 XMoveResizeWindow(blackbox
->getXDisplay(), geom_window
,
1801 (getWidth() - geom_w
) / 2,
1802 (getHeight() - geom_h
) / 2, geom_w
, geom_h
);
1803 XMapWindow(blackbox
->getXDisplay(), geom_window
);
1804 XRaiseWindow(blackbox
->getXDisplay(), geom_window
);
1806 geom_visible
= True
;
1811 sprintf(label
, i18n(ScreenSet
, ScreenPositionFormat
,
1812 "X: %4d x Y: %4d"), x
, y
);
1814 XClearWindow(blackbox
->getXDisplay(), geom_window
);
1816 BPen
pen(resource
.wstyle
.l_text_focus
, resource
.wstyle
.font
);
1817 if (i18n
.multibyte()) {
1818 XmbDrawString(blackbox
->getXDisplay(), geom_window
,
1819 resource
.wstyle
.fontset
, pen
.gc(),
1820 resource
.bevel_width
, resource
.bevel_width
-
1821 resource
.wstyle
.fontset_extents
->max_ink_extent
.y
,
1822 label
, strlen(label
));
1824 XDrawString(blackbox
->getXDisplay(), geom_window
,
1825 pen
.gc(), resource
.bevel_width
,
1826 resource
.wstyle
.font
->ascent
+ resource
.bevel_width
,
1827 label
, strlen(label
));
1832 void BScreen::showGeometry(unsigned int gx
, unsigned int gy
) {
1833 if (! geom_visible
) {
1834 XMoveResizeWindow(blackbox
->getXDisplay(), geom_window
,
1835 (getWidth() - geom_w
) / 2,
1836 (getHeight() - geom_h
) / 2, geom_w
, geom_h
);
1837 XMapWindow(blackbox
->getXDisplay(), geom_window
);
1838 XRaiseWindow(blackbox
->getXDisplay(), geom_window
);
1840 geom_visible
= True
;
1845 sprintf(label
, i18n(ScreenSet
, ScreenGeometryFormat
,
1846 "W: %4d x H: %4d"), gx
, gy
);
1848 XClearWindow(blackbox
->getXDisplay(), geom_window
);
1850 BPen
pen(resource
.wstyle
.l_text_focus
, resource
.wstyle
.font
);
1851 if (i18n
.multibyte()) {
1852 XmbDrawString(blackbox
->getXDisplay(), geom_window
,
1853 resource
.wstyle
.fontset
, pen
.gc(),
1854 resource
.bevel_width
, resource
.bevel_width
-
1855 resource
.wstyle
.fontset_extents
->max_ink_extent
.y
,
1856 label
, strlen(label
));
1858 XDrawString(blackbox
->getXDisplay(), geom_window
,
1859 pen
.gc(), resource
.bevel_width
,
1860 resource
.wstyle
.font
->ascent
+
1861 resource
.bevel_width
, label
, strlen(label
));
1866 void BScreen::hideGeometry(void) {
1868 XUnmapWindow(blackbox
->getXDisplay(), geom_window
);
1869 geom_visible
= False
;
1874 void BScreen::addStrut(Strut
*strut
) {
1875 strutList
.push_back(strut
);
1879 void BScreen::removeStrut(Strut
*strut
) {
1880 strutList
.remove(strut
);
1884 const Rect
& BScreen::availableArea(void) const {
1886 return getRect(); // return the full screen
1891 void BScreen::updateAvailableArea(void) {
1892 Rect old_area
= usableArea
;
1893 usableArea
= getRect(); // reset to full screen
1895 /* these values represent offsets from the screen edge
1896 * we look for the biggest offset on each edge and then apply them
1898 * do not be confused by the similarity to the names of Rect's members
1900 unsigned int current_left
= 0, current_right
= 0, current_top
= 0,
1903 StrutList::const_iterator it
= strutList
.begin(), end
= strutList
.end();
1905 for(; it
!= end
; ++it
) {
1907 if (strut
->left
> current_left
)
1908 current_left
= strut
->left
;
1909 if (strut
->top
> current_top
)
1910 current_top
= strut
->top
;
1911 if (strut
->right
> current_right
)
1912 current_right
= strut
->right
;
1913 if (strut
->bottom
> current_bottom
)
1914 current_bottom
= strut
->bottom
;
1917 usableArea
.setPos(current_left
, current_top
);
1918 usableArea
.setSize(usableArea
.width() - (current_left
+ current_right
),
1919 usableArea
.height() - (current_top
+ current_bottom
));
1921 if (old_area
!= usableArea
) {
1922 BlackboxWindowList::iterator it
= windowList
.begin(),
1923 end
= windowList
.end();
1924 for (; it
!= end
; ++it
)
1925 if ((*it
)->isMaximized()) (*it
)->remaximize();
1930 Workspace
* BScreen::getWorkspace(unsigned int index
) {
1931 assert(index
< workspacesList
.size());
1932 return workspacesList
[index
];
1936 void BScreen::buttonPressEvent(XButtonEvent
*xbutton
) {
1937 if (xbutton
->button
== 1) {
1938 if (! isRootColormapInstalled())
1939 image_control
->installRootColormap();
1941 if (workspacemenu
->isVisible())
1942 workspacemenu
->hide();
1944 if (rootmenu
->isVisible())
1946 } else if (xbutton
->button
== 2) {
1947 int mx
= xbutton
->x_root
- (workspacemenu
->getWidth() / 2);
1948 int my
= xbutton
->y_root
- (workspacemenu
->getTitleHeight() / 2);
1953 if (mx
+ workspacemenu
->getWidth() > getWidth())
1954 mx
= getWidth() - workspacemenu
->getWidth() - getBorderWidth();
1956 if (my
+ workspacemenu
->getHeight() > getHeight())
1957 my
= getHeight() - workspacemenu
->getHeight() - getBorderWidth();
1959 workspacemenu
->move(mx
, my
);
1961 if (! workspacemenu
->isVisible()) {
1962 workspacemenu
->removeParent();
1963 workspacemenu
->show();
1965 } else if (xbutton
->button
== 3) {
1966 int mx
= xbutton
->x_root
- (rootmenu
->getWidth() / 2);
1967 int my
= xbutton
->y_root
- (rootmenu
->getTitleHeight() / 2);
1972 if (mx
+ rootmenu
->getWidth() > getWidth())
1973 mx
= getWidth() - rootmenu
->getWidth() - getBorderWidth();
1975 if (my
+ rootmenu
->getHeight() > getHeight())
1976 my
= getHeight() - rootmenu
->getHeight() - getBorderWidth();
1978 rootmenu
->move(mx
, my
);
1980 if (! rootmenu
->isVisible()) {
1981 blackbox
->checkMenu();
1985 } else if (xbutton
->button
== 4) {
1986 if (getCurrentWorkspaceID() >= getWorkspaceCount() - 1)
1987 changeWorkspaceID(0);
1989 changeWorkspaceID(getCurrentWorkspaceID() + 1);
1991 } else if (xbutton
->button
== 5) {
1992 if (getCurrentWorkspaceID() == 0)
1993 changeWorkspaceID(getWorkspaceCount() - 1);
1995 changeWorkspaceID(getCurrentWorkspaceID() - 1);
2000 void BScreen::toggleFocusModel(FocusModel model
) {
2001 if (model
== SloppyFocus
) {
2002 saveSloppyFocus(True
);
2004 saveSloppyFocus(False
);
2005 saveAutoRaise(False
);
2006 saveClickRaise(False
);
2013 void BScreen::updateFocusModel()
2015 std::for_each(workspacesList
.begin(), workspacesList
.end(),
2016 std::mem_fun(&Workspace::updateFocusModel
));
2020 BTexture
BScreen::readDatabaseTexture(const string
&rname
,
2021 const string
&default_color
,
2022 Configuration
&style
) {
2026 if (style
.getValue(rname
, s
))
2027 texture
= BTexture(s
);
2029 texture
.setTexture(BTexture::Solid
| BTexture::Flat
);
2031 // associate this texture with this screen
2032 texture
.setDisplay(getBaseDisplay(), getScreenNumber());
2033 texture
.setImageControl(image_control
);
2035 if (texture
.texture() & BTexture::Solid
) {
2036 texture
.setColor(readDatabaseColor(rname
+ ".color",
2037 default_color
, style
));
2038 texture
.setColorTo(readDatabaseColor(rname
+ ".colorTo",
2039 default_color
, style
));
2040 } else if (texture
.texture() & BTexture::Gradient
) {
2041 texture
.setColor(readDatabaseColor(rname
+ ".color",
2042 default_color
, style
));
2043 texture
.setColorTo(readDatabaseColor(rname
+ ".colorTo",
2044 default_color
, style
));
2051 BColor
BScreen::readDatabaseColor(const string
&rname
,
2052 const string
&default_color
,
2053 Configuration
&style
) {
2056 if (style
.getValue(rname
, s
))
2057 color
= BColor(s
, getBaseDisplay(), getScreenNumber());
2059 color
= BColor(default_color
, getBaseDisplay(), getScreenNumber());
2064 XFontSet
BScreen::readDatabaseFontSet(const string
&rname
,
2065 Configuration
&style
) {
2066 char *defaultFont
= "fixed";
2068 bool load_default
= True
;
2070 XFontSet fontset
= 0;
2071 if (style
.getValue(rname
, s
) && (fontset
= createFontSet(s
)))
2072 load_default
= False
;
2075 fontset
= createFontSet(defaultFont
);
2079 i18n(ScreenSet
, ScreenDefaultFontLoadFail
,
2080 "BScreen::setCurrentStyle(): couldn't load default font.\n"));
2089 XFontStruct
*BScreen::readDatabaseFont(const string
&rname
,
2090 Configuration
&style
) {
2091 char *defaultFont
= "fixed";
2093 bool load_default
= False
;
2095 XFontStruct
*font
= 0;
2096 if (style
.getValue(rname
, s
)) {
2097 if ((font
= XLoadQueryFont(blackbox
->getXDisplay(), s
.c_str())) == NULL
) {
2099 i18n(ScreenSet
, ScreenFontLoadFail
,
2100 "BScreen::setCurrentStyle(): couldn't load font '%s'\n"),
2103 load_default
= True
;
2106 load_default
= True
;
2110 font
= XLoadQueryFont(blackbox
->getXDisplay(), defaultFont
);
2113 i18n(ScreenSet
, ScreenDefaultFontLoadFail
,
2114 "BScreen::setCurrentStyle(): couldn't load default font.\n"));
2123 #ifndef HAVE_STRCASESTR
2124 static const char * strcasestr(const char *str
, const char *ptn
) {
2125 const char *s2
, *p2
;
2126 for(; *str
; str
++) {
2127 for(s2
=str
,p2
=ptn
; ; s2
++,p2
++) {
2128 if (! *p2
) return str
;
2129 if (toupper(*s2
) != toupper(*p2
)) break;
2134 #endif // HAVE_STRCASESTR
2137 static const char *getFontElement(const char *pattern
, char *buf
,
2143 va_start(va
, bufsiz
);
2145 buf
[bufsiz
-2] = '*';
2146 while((v
= va_arg(va
, char *)) != NULL
) {
2147 p
= strcasestr(pattern
, v
);
2149 strncpy(buf
, p
+1, bufsiz
-2);
2150 p2
= strchr(buf
, '-');
2157 strncpy(buf
, "*", bufsiz
);
2162 static const char *getFontSize(const char *pattern
, int *size
) {
2164 const char *p2
=NULL
;
2167 for (p
=pattern
; 1; p
++) {
2169 if (p2
!=NULL
&& n
>1 && n
<72) {
2170 *size
= n
; return p2
+1;
2172 *size
= 16; return NULL
;
2174 } else if (*p
=='-') {
2175 if (n
>1 && n
<72 && p2
!=NULL
) {
2180 } else if (*p
>='0' && *p
<='9' && p2
!=NULL
) {
2190 XFontSet
BScreen::createFontSet(const string
&fontname
) {
2192 char **missing
, *def
= "-";
2193 int nmissing
, pixel_size
= 0, buf_size
= 0;
2194 char weight
[FONT_ELEMENT_SIZE
], slant
[FONT_ELEMENT_SIZE
];
2196 fs
= XCreateFontSet(blackbox
->getXDisplay(),
2197 fontname
.c_str(), &missing
, &nmissing
, &def
);
2198 if (fs
&& (! nmissing
))
2201 const char *nfontname
= fontname
.c_str();
2202 #ifdef HAVE_SETLOCALE
2204 if (nmissing
) XFreeStringList(missing
);
2206 setlocale(LC_CTYPE
, "C");
2207 fs
= XCreateFontSet(blackbox
->getXDisplay(), fontname
.c_str(),
2208 &missing
, &nmissing
, &def
);
2209 setlocale(LC_CTYPE
, "");
2211 #endif // HAVE_SETLOCALE
2214 XFontStruct
**fontstructs
;
2216 XFontsOfFontSet(fs
, &fontstructs
, &fontnames
);
2217 nfontname
= fontnames
[0];
2220 getFontElement(nfontname
, weight
, FONT_ELEMENT_SIZE
,
2221 "-medium-", "-bold-", "-demibold-", "-regular-", NULL
);
2222 getFontElement(nfontname
, slant
, FONT_ELEMENT_SIZE
,
2223 "-r-", "-i-", "-o-", "-ri-", "-ro-", NULL
);
2224 getFontSize(nfontname
, &pixel_size
);
2226 if (! strcmp(weight
, "*"))
2227 strncpy(weight
, "medium", FONT_ELEMENT_SIZE
);
2228 if (! strcmp(slant
, "*"))
2229 strncpy(slant
, "r", FONT_ELEMENT_SIZE
);
2232 else if (pixel_size
> 97)
2235 buf_size
= strlen(nfontname
) + (FONT_ELEMENT_SIZE
* 2) + 64;
2236 char *pattern2
= new char[buf_size
];
2239 "-*-*-%s-%s-*-*-%d-*-*-*-*-*-*-*,"
2240 "-*-*-*-*-*-*-%d-*-*-*-*-*-*-*,*",
2241 nfontname
, weight
, slant
, pixel_size
, pixel_size
);
2242 nfontname
= pattern2
;
2245 XFreeStringList(missing
);
2247 XFreeFontSet(blackbox
->getXDisplay(), fs
);
2249 fs
= XCreateFontSet(blackbox
->getXDisplay(), nfontname
, &missing
,