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 BlackboxWindow
*focused
= blackbox
->getFocusedWindow();
1044 if (focused
&& focused
->getScreen() == this && ! focused
->isStuck()) {
1045 if (focused
->getWorkspaceNumber() != current_workspace
->getID()) {
1046 fprintf(stderr
, "%s is on the wrong workspace, aborting\n",
1047 focused
->getTitle());
1050 current_workspace
->setLastFocusedWindow(focused
);
1051 blackbox
->setFocusedWindow((BlackboxWindow
*) 0);
1054 current_workspace
= getWorkspace(id
);
1056 xatom
->setValue(getRootWindow(), XAtom::net_current_desktop
,
1057 XAtom::cardinal
, id
);
1060 workspacemenu
->setItemSelected(current_workspace
->getID() + 2, True
);
1061 toolbar
->redrawWorkspaceLabel(True
);
1063 current_workspace
->showAll();
1065 if (resource
.focus_last
&& current_workspace
->getLastFocusedWindow()) {
1066 XSync(blackbox
->getXDisplay(), False
);
1067 current_workspace
->getLastFocusedWindow()->setInputFocus();
1071 updateNetizenCurrentWorkspace();
1075 void BScreen::manageWindow(Window w
) {
1076 new BlackboxWindow(blackbox
, w
, this);
1078 BlackboxWindow
*win
= blackbox
->searchWindow(w
);
1082 windowList
.push_back(win
);
1084 XMapRequestEvent mre
;
1086 if (blackbox
->isStartup())
1087 win
->restoreAttributes();
1088 win
->mapRequestEvent(&mre
);
1092 void BScreen::unmanageWindow(BlackboxWindow
*w
, bool remap
) {
1095 if (w
->getWorkspaceNumber() != BSENTINEL
&&
1096 w
->getWindowNumber() != BSENTINEL
)
1097 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
1098 else if (w
->isIconic())
1101 windowList
.remove(w
);
1103 if (blackbox
->getFocusedWindow() == w
)
1104 blackbox
->setFocusedWindow((BlackboxWindow
*) 0);
1106 removeNetizen(w
->getClientWindow());
1109 some managed windows can also be window group controllers. when
1110 unmanaging such windows, we should also delete the window group.
1112 BWindowGroup
*group
= blackbox
->searchGroup(w
->getClientWindow());
1119 void BScreen::addNetizen(Netizen
*n
) {
1120 netizenList
.push_back(n
);
1122 n
->sendWorkspaceCount();
1123 n
->sendCurrentWorkspace();
1125 WorkspaceList::iterator it
= workspacesList
.begin();
1126 const WorkspaceList::iterator end
= workspacesList
.end();
1127 for (; it
!= end
; ++it
)
1128 (*it
)->sendWindowList(*n
);
1130 Window f
= ((blackbox
->getFocusedWindow()) ?
1131 blackbox
->getFocusedWindow()->getClientWindow() : None
);
1132 n
->sendWindowFocus(f
);
1136 void BScreen::removeNetizen(Window w
) {
1137 NetizenList::iterator it
= netizenList
.begin();
1138 for (; it
!= netizenList
.end(); ++it
) {
1139 if ((*it
)->getWindowID() == w
) {
1141 netizenList
.erase(it
);
1148 void BScreen::updateNetizenCurrentWorkspace(void) {
1149 std::for_each(netizenList
.begin(), netizenList
.end(),
1150 std::mem_fun(&Netizen::sendCurrentWorkspace
));
1154 void BScreen::updateNetizenWorkspaceCount(void) {
1155 xatom
->setValue(getRootWindow(), XAtom::net_number_of_desktops
,
1156 XAtom::cardinal
, workspacesList
.size());
1158 std::for_each(netizenList
.begin(), netizenList
.end(),
1159 std::mem_fun(&Netizen::sendWorkspaceCount
));
1163 void BScreen::updateNetizenWindowFocus(void) {
1164 Window f
= ((blackbox
->getFocusedWindow()) ?
1165 blackbox
->getFocusedWindow()->getClientWindow() : None
);
1166 NetizenList::iterator it
= netizenList
.begin();
1167 for (; it
!= netizenList
.end(); ++it
)
1168 (*it
)->sendWindowFocus(f
);
1172 void BScreen::updateNetizenWindowAdd(Window w
, unsigned long p
) {
1173 NetizenList::iterator it
= netizenList
.begin();
1174 for (; it
!= netizenList
.end(); ++it
) {
1175 (*it
)->sendWindowAdd(w
, p
);
1180 void BScreen::updateNetizenWindowDel(Window w
) {
1181 NetizenList::iterator it
= netizenList
.begin();
1182 for (; it
!= netizenList
.end(); ++it
)
1183 (*it
)->sendWindowDel(w
);
1187 void BScreen::updateNetizenWindowRaise(Window w
) {
1188 NetizenList::iterator it
= netizenList
.begin();
1189 for (; it
!= netizenList
.end(); ++it
)
1190 (*it
)->sendWindowRaise(w
);
1194 void BScreen::updateNetizenWindowLower(Window w
) {
1195 NetizenList::iterator it
= netizenList
.begin();
1196 for (; it
!= netizenList
.end(); ++it
)
1197 (*it
)->sendWindowLower(w
);
1201 void BScreen::updateNetizenConfigNotify(XEvent
*e
) {
1202 NetizenList::iterator it
= netizenList
.begin();
1203 for (; it
!= netizenList
.end(); ++it
)
1204 (*it
)->sendConfigNotify(e
);
1208 void BScreen::raiseWindows(Window
*workspace_stack
, unsigned int num
) {
1210 Window
*session_stack
= new
1211 Window
[(num
+ workspacesList
.size() + rootmenuList
.size() + 13)];
1212 unsigned int i
= 0, k
= num
;
1214 XRaiseWindow(blackbox
->getXDisplay(), iconmenu
->getWindowID());
1215 *(session_stack
+ i
++) = iconmenu
->getWindowID();
1217 WorkspaceList::iterator wit
= workspacesList
.begin();
1218 const WorkspaceList::iterator w_end
= workspacesList
.end();
1219 for (; wit
!= w_end
; ++wit
)
1220 *(session_stack
+ i
++) = (*wit
)->getMenu()->getWindowID();
1222 *(session_stack
+ i
++) = workspacemenu
->getWindowID();
1224 *(session_stack
+ i
++) = configmenu
->getFocusmenu()->getWindowID();
1225 *(session_stack
+ i
++) = configmenu
->getPlacementmenu()->getWindowID();
1226 *(session_stack
+ i
++) = configmenu
->getWindowID();
1228 *(session_stack
+ i
++) = slit
->getMenu()->getDirectionmenu()->getWindowID();
1229 *(session_stack
+ i
++) = slit
->getMenu()->getPlacementmenu()->getWindowID();
1230 *(session_stack
+ i
++) = slit
->getMenu()->getWindowID();
1232 *(session_stack
+ i
++) =
1233 toolbar
->getMenu()->getPlacementmenu()->getWindowID();
1234 *(session_stack
+ i
++) = toolbar
->getMenu()->getWindowID();
1236 RootmenuList::iterator rit
= rootmenuList
.begin();
1237 for (; rit
!= rootmenuList
.end(); ++rit
)
1238 *(session_stack
+ i
++) = (*rit
)->getWindowID();
1239 *(session_stack
+ i
++) = rootmenu
->getWindowID();
1241 if (toolbar
->isOnTop())
1242 *(session_stack
+ i
++) = toolbar
->getWindowID();
1244 if (slit
->isOnTop())
1245 *(session_stack
+ i
++) = slit
->getWindowID();
1248 *(session_stack
+ i
++) = *(workspace_stack
+ k
);
1250 XRestackWindows(blackbox
->getXDisplay(), session_stack
, i
);
1252 delete [] session_stack
;
1256 void BScreen::addWorkspaceName(const string
& name
) {
1257 workspaceNames
.push_back(name
);
1262 * I would love to kill this function and the accompanying workspaceNames
1263 * list. However, we have a chicken and egg situation. The names are read
1264 * in during load_rc() which happens before the workspaces are created.
1265 * The current solution is to read the names into a list, then use the list
1266 * later for constructing the workspaces. It is only used during initial
1269 const string
BScreen::getNameOfWorkspace(unsigned int id
) {
1270 if (id
< workspaceNames
.size())
1271 return workspaceNames
[id
];
1276 void BScreen::reassociateWindow(BlackboxWindow
*w
, unsigned int wkspc_id
,
1277 bool ignore_sticky
) {
1280 if (wkspc_id
== BSENTINEL
)
1281 wkspc_id
= current_workspace
->getID();
1283 if (w
->getWorkspaceNumber() == wkspc_id
)
1286 if (w
->isIconic()) {
1288 getWorkspace(wkspc_id
)->addWindow(w
);
1289 } else if (ignore_sticky
|| ! w
->isStuck()) {
1290 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
1291 getWorkspace(wkspc_id
)->addWindow(w
);
1296 void BScreen::propagateWindowName(const BlackboxWindow
*bw
) {
1297 if (bw
->isIconic()) {
1298 iconmenu
->changeItemLabel(bw
->getWindowNumber(), bw
->getIconTitle());
1302 Clientmenu
*clientmenu
= getWorkspace(bw
->getWorkspaceNumber())->getMenu();
1303 clientmenu
->changeItemLabel(bw
->getWindowNumber(), bw
->getTitle());
1304 clientmenu
->update();
1306 if (blackbox
->getFocusedWindow() == bw
)
1307 toolbar
->redrawWindowLabel(True
);
1312 void BScreen::nextFocus(void) {
1313 BlackboxWindow
*focused
= blackbox
->getFocusedWindow(),
1317 // if window is not on this screen, ignore it
1318 if (focused
->getScreen()->getScreenNumber() != getScreenNumber())
1319 focused
= (BlackboxWindow
*) 0;
1322 if (focused
&& current_workspace
->getCount() > 1) {
1323 // next is the next window to recieve focus, current is a place holder
1324 BlackboxWindow
*current
;
1327 next
= current_workspace
->getNextWindowInList(current
);
1328 } while(! next
->setInputFocus() && next
!= focused
);
1330 if (next
!= focused
)
1331 current_workspace
->raiseWindow(next
);
1332 } else if (current_workspace
->getCount() >= 1) {
1333 next
= current_workspace
->getTopWindowOnStack();
1335 current_workspace
->raiseWindow(next
);
1336 next
->setInputFocus();
1341 void BScreen::prevFocus(void) {
1342 BlackboxWindow
*focused
= blackbox
->getFocusedWindow(),
1346 // if window is not on this screen, ignore it
1347 if (focused
->getScreen()->getScreenNumber() != getScreenNumber())
1348 focused
= (BlackboxWindow
*) 0;
1351 if (focused
&& current_workspace
->getCount() > 1) {
1352 // next is the next window to recieve focus, current is a place holder
1353 BlackboxWindow
*current
;
1356 next
= current_workspace
->getPrevWindowInList(current
);
1357 } while(! next
->setInputFocus() && next
!= focused
);
1359 if (next
!= focused
)
1360 current_workspace
->raiseWindow(next
);
1361 } else if (current_workspace
->getCount() >= 1) {
1362 next
= current_workspace
->getTopWindowOnStack();
1364 current_workspace
->raiseWindow(next
);
1365 next
->setInputFocus();
1370 void BScreen::raiseFocus(void) {
1371 BlackboxWindow
*focused
= blackbox
->getFocusedWindow();
1375 // if on this Screen, raise it
1376 if (focused
->getScreen()->getScreenNumber() == getScreenNumber()) {
1377 Workspace
*workspace
= getWorkspace(focused
->getWorkspaceNumber());
1378 workspace
->raiseWindow(focused
);
1383 void BScreen::InitMenu(void) {
1385 rootmenuList
.clear();
1387 while (rootmenu
->getCount())
1388 rootmenu
->remove(0);
1390 rootmenu
= new Rootmenu(this);
1392 bool defaultMenu
= True
;
1394 FILE *menu_file
= (FILE *) 0;
1395 const char *menu_filename
= blackbox
->getMenuFilename();
1398 if (! (menu_file
= fopen(menu_filename
, "r")))
1399 perror(menu_filename
);
1400 if (! menu_file
) { // opening the menu file failed, try the default menu
1401 menu_filename
= DEFAULTMENU
;
1402 if (! (menu_file
= fopen(menu_filename
, "r")))
1403 perror(menu_filename
);
1407 if (feof(menu_file
)) {
1408 fprintf(stderr
, i18n(ScreenSet
, ScreenEmptyMenuFile
,
1409 "%s: Empty menu file"),
1412 char line
[1024], label
[1024];
1413 memset(line
, 0, 1024);
1414 memset(label
, 0, 1024);
1416 while (fgets(line
, 1024, menu_file
) && ! feof(menu_file
)) {
1417 if (line
[0] != '#') {
1418 int i
, key
= 0, index
= -1, len
= strlen(line
);
1420 for (i
= 0; i
< len
; i
++) {
1421 if (line
[i
] == '[') index
= 0;
1422 else if (line
[i
] == ']') break;
1423 else if (line
[i
] != ' ')
1425 key
+= tolower(line
[i
]);
1428 if (key
== 517) { // [begin]
1430 for (i
= index
; i
< len
; i
++) {
1431 if (line
[i
] == '(') index
= 0;
1432 else if (line
[i
] == ')') break;
1433 else if (index
++ >= 0) {
1434 if (line
[i
] == '\\' && i
< len
- 1) i
++;
1435 label
[index
- 1] = line
[i
];
1439 if (index
== -1) index
= 0;
1440 label
[index
] = '\0';
1442 rootmenu
->setLabel(label
);
1443 defaultMenu
= parseMenuFile(menu_file
, rootmenu
);
1445 blackbox
->addMenuTimestamp(menu_filename
);
1455 rootmenu
->setInternalMenu();
1456 rootmenu
->insert(i18n(ScreenSet
, Screenxterm
, "xterm"),
1458 i18n(ScreenSet
, Screenxterm
, "xterm"));
1459 rootmenu
->insert(i18n(ScreenSet
, ScreenRestart
, "Restart"),
1461 rootmenu
->insert(i18n(ScreenSet
, ScreenExit
, "Exit"),
1463 rootmenu
->setLabel(i18n(BasemenuSet
, BasemenuBlackboxMenu
,
1469 bool BScreen::parseMenuFile(FILE *file
, Rootmenu
*menu
) {
1470 char line
[1024], label
[1024], command
[1024];
1472 while (! feof(file
)) {
1473 memset(line
, 0, 1024);
1474 memset(label
, 0, 1024);
1475 memset(command
, 0, 1024);
1477 if (fgets(line
, 1024, file
)) {
1478 if (line
[0] != '#') {
1479 int i
, key
= 0, parse
= 0, index
= -1, line_length
= strlen(line
);
1481 // determine the keyword
1482 for (i
= 0; i
< line_length
; i
++) {
1483 if (line
[i
] == '[') parse
= 1;
1484 else if (line
[i
] == ']') break;
1485 else if (line
[i
] != ' ')
1487 key
+= tolower(line
[i
]);
1490 // get the label enclosed in ()'s
1493 for (i
= 0; i
< line_length
; i
++) {
1494 if (line
[i
] == '(') {
1497 } else if (line
[i
] == ')') break;
1498 else if (index
++ >= 0) {
1499 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
1500 label
[index
- 1] = line
[i
];
1505 label
[index
] = '\0';
1510 // get the command enclosed in {}'s
1513 for (i
= 0; i
< line_length
; i
++) {
1514 if (line
[i
] == '{') {
1517 } else if (line
[i
] == '}') break;
1518 else if (index
++ >= 0) {
1519 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
1520 command
[index
- 1] = line
[i
];
1525 command
[index
] = '\0';
1532 return ((menu
->getCount() == 0) ? True
: False
);
1539 menu
->insert(label
);
1544 if ((! *label
) && (! *command
)) {
1545 fprintf(stderr
, i18n(ScreenSet
, ScreenEXECError
,
1546 "BScreen::parseMenuFile: [exec] error, "
1547 "no menu label and/or command defined\n"));
1551 menu
->insert(label
, BScreen::Execute
, command
);
1557 fprintf(stderr
, i18n(ScreenSet
, ScreenEXITError
,
1558 "BScreen::parseMenuFile: [exit] error, "
1559 "no menu label defined\n"));
1563 menu
->insert(label
, BScreen::Exit
);
1569 if ((! *label
) || (! *command
)) {
1571 i18n(ScreenSet
, ScreenSTYLEError
,
1572 "BScreen::parseMenuFile: [style] error, "
1573 "no menu label and/or filename defined\n"));
1577 string style
= expandTilde(command
);
1579 menu
->insert(label
, BScreen::SetStyle
, style
.c_str());
1586 fprintf(stderr
, i18n(ScreenSet
, ScreenCONFIGError
,
1587 "BScreen::parseMenufile: [config] error, "
1588 "no label defined"));
1592 menu
->insert(label
, configmenu
);
1596 case 740: // include
1599 fprintf(stderr
, i18n(ScreenSet
, ScreenINCLUDEError
,
1600 "BScreen::parseMenuFile: [include] error, "
1601 "no filename defined\n"));
1605 string newfile
= expandTilde(label
);
1606 FILE *submenufile
= fopen(newfile
.c_str(), "r");
1610 if (fstat(fileno(submenufile
), &buf
) ||
1611 (! S_ISREG(buf
.st_mode
))) {
1613 i18n(ScreenSet
, ScreenINCLUDEErrorReg
,
1614 "BScreen::parseMenuFile: [include] error: "
1615 "'%s' is not a regular file\n"), newfile
.c_str());
1619 if (! feof(submenufile
)) {
1620 if (! parseMenuFile(submenufile
, menu
))
1621 blackbox
->addMenuTimestamp(newfile
);
1623 fclose(submenufile
);
1626 perror(newfile
.c_str());
1632 case 767: // submenu
1635 fprintf(stderr
, i18n(ScreenSet
, ScreenSUBMENUError
,
1636 "BScreen::parseMenuFile: [submenu] error, "
1637 "no menu label defined\n"));
1641 Rootmenu
*submenu
= new Rootmenu(this);
1644 submenu
->setLabel(command
);
1646 submenu
->setLabel(label
);
1648 parseMenuFile(file
, submenu
);
1650 menu
->insert(label
, submenu
);
1651 rootmenuList
.push_back(submenu
);
1656 case 773: // restart
1659 fprintf(stderr
, i18n(ScreenSet
, ScreenRESTARTError
,
1660 "BScreen::parseMenuFile: [restart] error, "
1661 "no menu label defined\n"));
1666 menu
->insert(label
, BScreen::RestartOther
, command
);
1668 menu
->insert(label
, BScreen::Restart
);
1673 case 845: // reconfig
1677 i18n(ScreenSet
, ScreenRECONFIGError
,
1678 "BScreen::parseMenuFile: [reconfig] error, "
1679 "no menu label defined\n"));
1683 menu
->insert(label
, BScreen::Reconfigure
);
1688 case 995: // stylesdir
1689 case 1113: // stylesmenu
1691 bool newmenu
= ((key
== 1113) ? True
: False
);
1693 if ((! *label
) || ((! *command
) && newmenu
)) {
1695 i18n(ScreenSet
, ScreenSTYLESDIRError
,
1696 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1697 " error, no directory defined\n"));
1701 char *directory
= ((newmenu
) ? command
: label
);
1703 string stylesdir
= expandTilde(directory
);
1705 struct stat statbuf
;
1707 if (! stat(stylesdir
.c_str(), &statbuf
)) {
1708 if (S_ISDIR(statbuf
.st_mode
)) {
1709 Rootmenu
*stylesmenu
;
1712 stylesmenu
= new Rootmenu(this);
1716 DIR *d
= opendir(stylesdir
.c_str());
1718 std::vector
<string
> ls
;
1720 while((p
= readdir(d
)))
1721 ls
.push_back(p
->d_name
);
1725 std::sort(ls
.begin(), ls
.end());
1727 std::vector
<string
>::iterator it
= ls
.begin(),
1729 for (; it
!= end
; ++it
) {
1730 const string
& fname
= *it
;
1732 if (fname
[fname
.size()-1] == '~')
1735 string style
= stylesdir
;
1739 if ((! stat(style
.c_str(), &statbuf
)) &&
1740 S_ISREG(statbuf
.st_mode
))
1741 stylesmenu
->insert(fname
, BScreen::SetStyle
, style
);
1744 stylesmenu
->update();
1747 stylesmenu
->setLabel(label
);
1748 menu
->insert(label
, stylesmenu
);
1749 rootmenuList
.push_back(stylesmenu
);
1752 blackbox
->addMenuTimestamp(stylesdir
);
1755 i18n(ScreenSet
, ScreenSTYLESDIRErrorNotDir
,
1756 "BScreen::parseMenuFile:"
1757 " [stylesdir/stylesmenu] error, %s is not a"
1758 " directory\n"), stylesdir
.c_str());
1762 i18n(ScreenSet
, ScreenSTYLESDIRErrorNoExist
,
1763 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1764 " error, %s does not exist\n"), stylesdir
.c_str());
1769 case 1090: // workspaces
1773 i18n(ScreenSet
, ScreenWORKSPACESError
,
1774 "BScreen:parseMenuFile: [workspaces] error, "
1775 "no menu label defined\n"));
1779 menu
->insert(label
, workspacemenu
);
1788 return ((menu
->getCount() == 0) ? True
: False
);
1792 void BScreen::shutdown(void) {
1793 XSelectInput(blackbox
->getXDisplay(), getRootWindow(), NoEventMask
);
1794 XSync(blackbox
->getXDisplay(), False
);
1796 while(! windowList
.empty())
1797 unmanageWindow(windowList
.front(), True
);
1803 void BScreen::showPosition(int x
, int y
) {
1804 if (! geom_visible
) {
1805 XMoveResizeWindow(blackbox
->getXDisplay(), geom_window
,
1806 (getWidth() - geom_w
) / 2,
1807 (getHeight() - geom_h
) / 2, geom_w
, geom_h
);
1808 XMapWindow(blackbox
->getXDisplay(), geom_window
);
1809 XRaiseWindow(blackbox
->getXDisplay(), geom_window
);
1811 geom_visible
= True
;
1816 sprintf(label
, i18n(ScreenSet
, ScreenPositionFormat
,
1817 "X: %4d x Y: %4d"), x
, y
);
1819 XClearWindow(blackbox
->getXDisplay(), geom_window
);
1821 BPen
pen(resource
.wstyle
.l_text_focus
, resource
.wstyle
.font
);
1822 if (i18n
.multibyte()) {
1823 XmbDrawString(blackbox
->getXDisplay(), geom_window
,
1824 resource
.wstyle
.fontset
, pen
.gc(),
1825 resource
.bevel_width
, resource
.bevel_width
-
1826 resource
.wstyle
.fontset_extents
->max_ink_extent
.y
,
1827 label
, strlen(label
));
1829 XDrawString(blackbox
->getXDisplay(), geom_window
,
1830 pen
.gc(), resource
.bevel_width
,
1831 resource
.wstyle
.font
->ascent
+ resource
.bevel_width
,
1832 label
, strlen(label
));
1837 void BScreen::showGeometry(unsigned int gx
, unsigned int gy
) {
1838 if (! geom_visible
) {
1839 XMoveResizeWindow(blackbox
->getXDisplay(), geom_window
,
1840 (getWidth() - geom_w
) / 2,
1841 (getHeight() - geom_h
) / 2, geom_w
, geom_h
);
1842 XMapWindow(blackbox
->getXDisplay(), geom_window
);
1843 XRaiseWindow(blackbox
->getXDisplay(), geom_window
);
1845 geom_visible
= True
;
1850 sprintf(label
, i18n(ScreenSet
, ScreenGeometryFormat
,
1851 "W: %4d x H: %4d"), gx
, gy
);
1853 XClearWindow(blackbox
->getXDisplay(), geom_window
);
1855 BPen
pen(resource
.wstyle
.l_text_focus
, resource
.wstyle
.font
);
1856 if (i18n
.multibyte()) {
1857 XmbDrawString(blackbox
->getXDisplay(), geom_window
,
1858 resource
.wstyle
.fontset
, pen
.gc(),
1859 resource
.bevel_width
, resource
.bevel_width
-
1860 resource
.wstyle
.fontset_extents
->max_ink_extent
.y
,
1861 label
, strlen(label
));
1863 XDrawString(blackbox
->getXDisplay(), geom_window
,
1864 pen
.gc(), resource
.bevel_width
,
1865 resource
.wstyle
.font
->ascent
+
1866 resource
.bevel_width
, label
, strlen(label
));
1871 void BScreen::hideGeometry(void) {
1873 XUnmapWindow(blackbox
->getXDisplay(), geom_window
);
1874 geom_visible
= False
;
1879 void BScreen::addStrut(Strut
*strut
) {
1880 strutList
.push_back(strut
);
1884 void BScreen::removeStrut(Strut
*strut
) {
1885 strutList
.remove(strut
);
1889 const Rect
& BScreen::availableArea(void) const {
1891 return getRect(); // return the full screen
1896 void BScreen::updateAvailableArea(void) {
1897 Rect old_area
= usableArea
;
1898 usableArea
= getRect(); // reset to full screen
1900 /* these values represent offsets from the screen edge
1901 * we look for the biggest offset on each edge and then apply them
1903 * do not be confused by the similarity to the names of Rect's members
1905 unsigned int current_left
= 0, current_right
= 0, current_top
= 0,
1908 StrutList::const_iterator it
= strutList
.begin(), end
= strutList
.end();
1910 for(; it
!= end
; ++it
) {
1912 if (strut
->left
> current_left
)
1913 current_left
= strut
->left
;
1914 if (strut
->top
> current_top
)
1915 current_top
= strut
->top
;
1916 if (strut
->right
> current_right
)
1917 current_right
= strut
->right
;
1918 if (strut
->bottom
> current_bottom
)
1919 current_bottom
= strut
->bottom
;
1922 usableArea
.setPos(current_left
, current_top
);
1923 usableArea
.setSize(usableArea
.width() - (current_left
+ current_right
),
1924 usableArea
.height() - (current_top
+ current_bottom
));
1926 if (old_area
!= usableArea
) {
1927 BlackboxWindowList::iterator it
= windowList
.begin(),
1928 end
= windowList
.end();
1929 for (; it
!= end
; ++it
)
1930 if ((*it
)->isMaximized()) (*it
)->remaximize();
1935 Workspace
* BScreen::getWorkspace(unsigned int index
) {
1936 assert(index
< workspacesList
.size());
1937 return workspacesList
[index
];
1941 void BScreen::buttonPressEvent(XButtonEvent
*xbutton
) {
1942 if (xbutton
->button
== 1) {
1943 if (! isRootColormapInstalled())
1944 image_control
->installRootColormap();
1946 if (workspacemenu
->isVisible())
1947 workspacemenu
->hide();
1949 if (rootmenu
->isVisible())
1951 } else if (xbutton
->button
== 2) {
1952 int mx
= xbutton
->x_root
- (workspacemenu
->getWidth() / 2);
1953 int my
= xbutton
->y_root
- (workspacemenu
->getTitleHeight() / 2);
1958 if (mx
+ workspacemenu
->getWidth() > getWidth())
1959 mx
= getWidth() - workspacemenu
->getWidth() - getBorderWidth();
1961 if (my
+ workspacemenu
->getHeight() > getHeight())
1962 my
= getHeight() - workspacemenu
->getHeight() - getBorderWidth();
1964 workspacemenu
->move(mx
, my
);
1966 if (! workspacemenu
->isVisible()) {
1967 workspacemenu
->removeParent();
1968 workspacemenu
->show();
1970 } else if (xbutton
->button
== 3) {
1971 int mx
= xbutton
->x_root
- (rootmenu
->getWidth() / 2);
1972 int my
= xbutton
->y_root
- (rootmenu
->getTitleHeight() / 2);
1977 if (mx
+ rootmenu
->getWidth() > getWidth())
1978 mx
= getWidth() - rootmenu
->getWidth() - getBorderWidth();
1980 if (my
+ rootmenu
->getHeight() > getHeight())
1981 my
= getHeight() - rootmenu
->getHeight() - getBorderWidth();
1983 rootmenu
->move(mx
, my
);
1985 if (! rootmenu
->isVisible()) {
1986 blackbox
->checkMenu();
1990 } else if (xbutton
->button
== 4) {
1991 if (getCurrentWorkspaceID() >= getWorkspaceCount() - 1)
1992 changeWorkspaceID(0);
1994 changeWorkspaceID(getCurrentWorkspaceID() + 1);
1996 } else if (xbutton
->button
== 5) {
1997 if (getCurrentWorkspaceID() == 0)
1998 changeWorkspaceID(getWorkspaceCount() - 1);
2000 changeWorkspaceID(getCurrentWorkspaceID() - 1);
2005 void BScreen::toggleFocusModel(FocusModel model
) {
2006 if (model
== SloppyFocus
) {
2007 saveSloppyFocus(True
);
2009 saveSloppyFocus(False
);
2010 saveAutoRaise(False
);
2011 saveClickRaise(False
);
2018 void BScreen::updateFocusModel()
2020 std::for_each(workspacesList
.begin(), workspacesList
.end(),
2021 std::mem_fun(&Workspace::updateFocusModel
));
2025 BTexture
BScreen::readDatabaseTexture(const string
&rname
,
2026 const string
&default_color
,
2027 Configuration
&style
) {
2031 if (style
.getValue(rname
, s
))
2032 texture
= BTexture(s
);
2034 texture
.setTexture(BTexture::Solid
| BTexture::Flat
);
2036 // associate this texture with this screen
2037 texture
.setDisplay(getBaseDisplay(), getScreenNumber());
2038 texture
.setImageControl(image_control
);
2040 if (texture
.texture() & BTexture::Solid
) {
2041 texture
.setColor(readDatabaseColor(rname
+ ".color",
2042 default_color
, style
));
2043 texture
.setColorTo(readDatabaseColor(rname
+ ".colorTo",
2044 default_color
, style
));
2045 } else if (texture
.texture() & BTexture::Gradient
) {
2046 texture
.setColor(readDatabaseColor(rname
+ ".color",
2047 default_color
, style
));
2048 texture
.setColorTo(readDatabaseColor(rname
+ ".colorTo",
2049 default_color
, style
));
2056 BColor
BScreen::readDatabaseColor(const string
&rname
,
2057 const string
&default_color
,
2058 Configuration
&style
) {
2061 if (style
.getValue(rname
, s
))
2062 color
= BColor(s
, getBaseDisplay(), getScreenNumber());
2064 color
= BColor(default_color
, getBaseDisplay(), getScreenNumber());
2069 XFontSet
BScreen::readDatabaseFontSet(const string
&rname
,
2070 Configuration
&style
) {
2071 char *defaultFont
= "fixed";
2073 bool load_default
= True
;
2075 XFontSet fontset
= 0;
2076 if (style
.getValue(rname
, s
) && (fontset
= createFontSet(s
)))
2077 load_default
= False
;
2080 fontset
= createFontSet(defaultFont
);
2084 i18n(ScreenSet
, ScreenDefaultFontLoadFail
,
2085 "BScreen::setCurrentStyle(): couldn't load default font.\n"));
2094 XFontStruct
*BScreen::readDatabaseFont(const string
&rname
,
2095 Configuration
&style
) {
2096 char *defaultFont
= "fixed";
2098 bool load_default
= False
;
2100 XFontStruct
*font
= 0;
2101 if (style
.getValue(rname
, s
)) {
2102 if ((font
= XLoadQueryFont(blackbox
->getXDisplay(), s
.c_str())) == NULL
) {
2104 i18n(ScreenSet
, ScreenFontLoadFail
,
2105 "BScreen::setCurrentStyle(): couldn't load font '%s'\n"),
2108 load_default
= True
;
2111 load_default
= True
;
2115 font
= XLoadQueryFont(blackbox
->getXDisplay(), defaultFont
);
2118 i18n(ScreenSet
, ScreenDefaultFontLoadFail
,
2119 "BScreen::setCurrentStyle(): couldn't load default font.\n"));
2128 #ifndef HAVE_STRCASESTR
2129 static const char * strcasestr(const char *str
, const char *ptn
) {
2130 const char *s2
, *p2
;
2131 for(; *str
; str
++) {
2132 for(s2
=str
,p2
=ptn
; ; s2
++,p2
++) {
2133 if (! *p2
) return str
;
2134 if (toupper(*s2
) != toupper(*p2
)) break;
2139 #endif // HAVE_STRCASESTR
2142 static const char *getFontElement(const char *pattern
, char *buf
,
2148 va_start(va
, bufsiz
);
2150 buf
[bufsiz
-2] = '*';
2151 while((v
= va_arg(va
, char *)) != NULL
) {
2152 p
= strcasestr(pattern
, v
);
2154 strncpy(buf
, p
+1, bufsiz
-2);
2155 p2
= strchr(buf
, '-');
2162 strncpy(buf
, "*", bufsiz
);
2167 static const char *getFontSize(const char *pattern
, int *size
) {
2169 const char *p2
=NULL
;
2172 for (p
=pattern
; 1; p
++) {
2174 if (p2
!=NULL
&& n
>1 && n
<72) {
2175 *size
= n
; return p2
+1;
2177 *size
= 16; return NULL
;
2179 } else if (*p
=='-') {
2180 if (n
>1 && n
<72 && p2
!=NULL
) {
2185 } else if (*p
>='0' && *p
<='9' && p2
!=NULL
) {
2195 XFontSet
BScreen::createFontSet(const string
&fontname
) {
2197 char **missing
, *def
= "-";
2198 int nmissing
, pixel_size
= 0, buf_size
= 0;
2199 char weight
[FONT_ELEMENT_SIZE
], slant
[FONT_ELEMENT_SIZE
];
2201 fs
= XCreateFontSet(blackbox
->getXDisplay(),
2202 fontname
.c_str(), &missing
, &nmissing
, &def
);
2203 if (fs
&& (! nmissing
))
2206 const char *nfontname
= fontname
.c_str();
2207 #ifdef HAVE_SETLOCALE
2209 if (nmissing
) XFreeStringList(missing
);
2211 setlocale(LC_CTYPE
, "C");
2212 fs
= XCreateFontSet(blackbox
->getXDisplay(), fontname
.c_str(),
2213 &missing
, &nmissing
, &def
);
2214 setlocale(LC_CTYPE
, "");
2216 #endif // HAVE_SETLOCALE
2219 XFontStruct
**fontstructs
;
2221 XFontsOfFontSet(fs
, &fontstructs
, &fontnames
);
2222 nfontname
= fontnames
[0];
2225 getFontElement(nfontname
, weight
, FONT_ELEMENT_SIZE
,
2226 "-medium-", "-bold-", "-demibold-", "-regular-", NULL
);
2227 getFontElement(nfontname
, slant
, FONT_ELEMENT_SIZE
,
2228 "-r-", "-i-", "-o-", "-ri-", "-ro-", NULL
);
2229 getFontSize(nfontname
, &pixel_size
);
2231 if (! strcmp(weight
, "*"))
2232 strncpy(weight
, "medium", FONT_ELEMENT_SIZE
);
2233 if (! strcmp(slant
, "*"))
2234 strncpy(slant
, "r", FONT_ELEMENT_SIZE
);
2237 else if (pixel_size
> 97)
2240 buf_size
= strlen(nfontname
) + (FONT_ELEMENT_SIZE
* 2) + 64;
2241 char *pattern2
= new char[buf_size
];
2244 "-*-*-%s-%s-*-*-%d-*-*-*-*-*-*-*,"
2245 "-*-*-*-*-*-*-%d-*-*-*-*-*-*-*,*",
2246 nfontname
, weight
, slant
, pixel_size
, pixel_size
);
2247 nfontname
= pattern2
;
2250 XFreeStringList(missing
);
2252 XFreeFontSet(blackbox
->getXDisplay(), fs
);
2254 fs
= XCreateFontSet(blackbox
->getXDisplay(), nfontname
, &missing
,