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
74 #include "blackbox.hh"
75 #include "Clientmenu.hh"
77 #include "Iconmenu.hh"
81 #include "Rootmenu.hh"
85 #include "Workspace.hh"
86 #include "Workspacemenu.hh"
89 #ifndef FONT_ELEMENT_SIZE
90 #define FONT_ELEMENT_SIZE 50
91 #endif // FONT_ELEMENT_SIZE
94 static bool running
= True
;
96 static int anotherWMRunning(Display
*display
, XErrorEvent
*) {
97 fprintf(stderr
, i18n(ScreenSet
, ScreenAnotherWMRunning
,
98 "BScreen::BScreen: an error occured while querying the X server.\n"
99 " another window manager already running on display %s.\n"),
100 DisplayString(display
));
108 BScreen::BScreen(Blackbox
*bb
, unsigned int scrn
) : ScreenInfo(bb
, scrn
) {
110 screenstr
= (string
)"session.screen" + itostring(scrn
) + '.';
111 config
= blackbox
->getConfig();
112 xatom
= blackbox
->getXAtom();
114 event_mask
= ColormapChangeMask
| EnterWindowMask
| PropertyChangeMask
|
115 SubstructureRedirectMask
| ButtonPressMask
| ButtonReleaseMask
;
117 XErrorHandler old
= XSetErrorHandler((XErrorHandler
) anotherWMRunning
);
118 XSelectInput(getBaseDisplay()->getXDisplay(), getRootWindow(), event_mask
);
119 XSync(getBaseDisplay()->getXDisplay(), False
);
120 XSetErrorHandler((XErrorHandler
) old
);
123 if (! managed
) return;
125 fprintf(stderr
, i18n(ScreenSet
, ScreenManagingScreen
,
126 "BScreen::BScreen: managing screen %d "
127 "using visual 0x%lx, depth %d\n"),
128 getScreenNumber(), XVisualIDFromVisual(getVisual()),
133 resource
.mstyle
.t_fontset
= resource
.mstyle
.f_fontset
=
134 resource
.tstyle
.fontset
= resource
.wstyle
.fontset
= (XFontSet
) 0;
135 resource
.mstyle
.t_font
= resource
.mstyle
.f_font
= resource
.tstyle
.font
=
136 resource
.wstyle
.font
= (XFontStruct
*) 0;
138 xatom
->setSupported(this); // set-up netwm support
140 xatom
->setValue(getRootWindow(), XAtom::blackbox_pid
, XAtom::cardinal
,
141 (unsigned long) getpid());
142 #endif // HAVE_GETPID
144 XDefineCursor(blackbox
->getXDisplay(), getRootWindow(),
145 blackbox
->getSessionCursor());
147 // start off full screen, top left.
148 usableArea
.setSize(getWidth(), getHeight());
151 new BImageControl(blackbox
, this, True
, blackbox
->getColorsPerChannel(),
152 blackbox
->getCacheLife(), blackbox
->getCacheMax());
153 image_control
->installRootColormap();
154 root_colormap_installed
= True
;
160 unsigned long gc_value_mask
= GCForeground
;
161 if (! i18n
.multibyte()) gc_value_mask
|= GCFont
;
163 gcv
.foreground
= WhitePixel(blackbox
->getXDisplay(), getScreenNumber())
164 ^ BlackPixel(blackbox
->getXDisplay(), getScreenNumber());
165 gcv
.function
= GXxor
;
166 gcv
.subwindow_mode
= IncludeInferiors
;
167 opGC
= XCreateGC(blackbox
->getXDisplay(), getRootWindow(),
168 GCForeground
| GCFunction
| GCSubwindowMode
, &gcv
);
170 const char *s
= i18n(ScreenSet
, ScreenPositionLength
,
171 "0: 0000 x 0: 0000");
174 if (i18n
.multibyte()) {
175 XRectangle ink
, logical
;
176 XmbTextExtents(resource
.wstyle
.fontset
, s
, l
, &ink
, &logical
);
177 geom_w
= logical
.width
;
179 geom_h
= resource
.wstyle
.fontset_extents
->max_ink_extent
.height
;
181 geom_h
= resource
.wstyle
.font
->ascent
+
182 resource
.wstyle
.font
->descent
;
184 geom_w
= XTextWidth(resource
.wstyle
.font
, s
, l
);
187 geom_w
+= (resource
.bevel_width
* 2);
188 geom_h
+= (resource
.bevel_width
* 2);
190 XSetWindowAttributes attrib
;
191 unsigned long mask
= CWBorderPixel
| CWColormap
| CWSaveUnder
;
192 attrib
.border_pixel
= getBorderColor()->pixel();
193 attrib
.colormap
= getColormap();
194 attrib
.save_under
= True
;
196 geom_window
= XCreateWindow(blackbox
->getXDisplay(), getRootWindow(),
197 0, 0, geom_w
, geom_h
, resource
.border_width
,
198 getDepth(), InputOutput
, getVisual(),
200 geom_visible
= False
;
202 BTexture
* texture
= &(resource
.wstyle
.l_focus
);
203 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
204 if (geom_pixmap
== ParentRelative
) {
205 texture
= &(resource
.wstyle
.t_focus
);
206 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
209 XSetWindowBackground(blackbox
->getXDisplay(), geom_window
,
210 texture
->color().pixel());
212 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
213 geom_window
, geom_pixmap
);
215 workspacemenu
= new Workspacemenu(this);
216 iconmenu
= new Iconmenu(this);
217 configmenu
= new Configmenu(this);
219 Workspace
*wkspc
= (Workspace
*) 0;
220 if (resource
.workspaces
!= 0) {
221 for (unsigned int i
= 0; i
< resource
.workspaces
; ++i
) {
222 wkspc
= new Workspace(this, workspacesList
.size());
223 workspacesList
.push_back(wkspc
);
224 workspacemenu
->insert(wkspc
->getName(), wkspc
->getMenu());
227 wkspc
= new Workspace(this, workspacesList
.size());
228 workspacesList
.push_back(wkspc
);
229 workspacemenu
->insert(wkspc
->getName(), wkspc
->getMenu());
231 saveWorkspaceNames();
233 updateNetizenWorkspaceCount();
235 workspacemenu
->insert(i18n(IconSet
, IconIcons
, "Icons"), iconmenu
);
236 workspacemenu
->update();
238 current_workspace
= workspacesList
.front();
240 xatom
->setValue(getRootWindow(), XAtom::net_current_desktop
,
241 XAtom::cardinal
, 0); //first workspace
243 workspacemenu
->setItemSelected(2, True
);
245 toolbar
= new Toolbar(this);
247 slit
= new Slit(this);
254 updateAvailableArea();
256 changeWorkspaceID(0);
258 unsigned int i
, j
, nchild
;
259 Window r
, p
, *children
;
260 XQueryTree(blackbox
->getXDisplay(), getRootWindow(), &r
, &p
,
263 // preen the window list of all icon windows... for better dockapp support
264 for (i
= 0; i
< nchild
; i
++) {
265 if (children
[i
] == None
) continue;
267 XWMHints
*wmhints
= XGetWMHints(blackbox
->getXDisplay(),
271 if ((wmhints
->flags
& IconWindowHint
) &&
272 (wmhints
->icon_window
!= children
[i
])) {
273 for (j
= 0; j
< nchild
; j
++) {
274 if (children
[j
] == wmhints
->icon_window
) {
285 // manage shown windows
286 for (i
= 0; i
< nchild
; ++i
) {
287 if (children
[i
] == None
|| (! blackbox
->validateWindow(children
[i
])))
290 XWindowAttributes attrib
;
291 if (XGetWindowAttributes(blackbox
->getXDisplay(), children
[i
], &attrib
)) {
292 if (attrib
.override_redirect
) continue;
294 if (attrib
.map_state
!= IsUnmapped
) {
295 manageWindow(children
[i
]);
302 // call this again just in case a window we found updates the Strut list
303 updateAvailableArea();
307 BScreen::~BScreen(void) {
308 if (! managed
) return;
310 if (geom_pixmap
!= None
)
311 image_control
->removeImage(geom_pixmap
);
313 if (geom_window
!= None
)
314 XDestroyWindow(blackbox
->getXDisplay(), geom_window
);
316 std::for_each(workspacesList
.begin(), workspacesList
.end(),
319 std::for_each(iconList
.begin(), iconList
.end(), PointerAssassin());
321 std::for_each(netizenList
.begin(), netizenList
.end(), PointerAssassin());
324 delete workspacemenu
;
329 delete image_control
;
331 if (resource
.wstyle
.fontset
)
332 XFreeFontSet(blackbox
->getXDisplay(), resource
.wstyle
.fontset
);
333 if (resource
.mstyle
.t_fontset
)
334 XFreeFontSet(blackbox
->getXDisplay(), resource
.mstyle
.t_fontset
);
335 if (resource
.mstyle
.f_fontset
)
336 XFreeFontSet(blackbox
->getXDisplay(), resource
.mstyle
.f_fontset
);
337 if (resource
.tstyle
.fontset
)
338 XFreeFontSet(blackbox
->getXDisplay(), resource
.tstyle
.fontset
);
340 if (resource
.wstyle
.font
)
341 XFreeFont(blackbox
->getXDisplay(), resource
.wstyle
.font
);
342 if (resource
.mstyle
.t_font
)
343 XFreeFont(blackbox
->getXDisplay(), resource
.mstyle
.t_font
);
344 if (resource
.mstyle
.f_font
)
345 XFreeFont(blackbox
->getXDisplay(), resource
.mstyle
.f_font
);
346 if (resource
.tstyle
.font
)
347 XFreeFont(blackbox
->getXDisplay(), resource
.tstyle
.font
);
349 XFreeGC(blackbox
->getXDisplay(), opGC
);
353 void BScreen::removeWorkspaceNames(void) {
354 workspaceNames
.clear();
357 void BScreen::saveSloppyFocus(bool s
) {
358 resource
.sloppy_focus
= s
;
361 if (resource
.sloppy_focus
) {
362 fmodel
= "SloppyFocus";
363 if (resource
.auto_raise
) fmodel
+= " AutoRaise";
364 if (resource
.click_raise
) fmodel
+= " ClickRaise";
366 fmodel
= "ClickToFocus";
368 config
->setValue(screenstr
+ "focusModel", fmodel
);
372 void BScreen::saveAutoRaise(bool a
) {
373 resource
.auto_raise
= a
;
374 saveSloppyFocus(resource
.sloppy_focus
);
378 void BScreen::saveClickRaise(bool c
) {
379 resource
.click_raise
= c
;
380 saveSloppyFocus(resource
.sloppy_focus
);
384 void BScreen::saveImageDither(bool d
) {
385 image_control
->setDither(d
);
386 config
->setValue(screenstr
+ "imageDither", doImageDither());
390 void BScreen::saveOpaqueMove(bool o
) {
391 resource
.opaque_move
= o
;
392 config
->setValue(screenstr
+ "opaqueMove", resource
.opaque_move
);
396 void BScreen::saveFullMax(bool f
) {
397 resource
.full_max
= f
;
398 config
->setValue(screenstr
+ "fullMaximization", resource
.full_max
);
402 void BScreen::saveFocusNew(bool f
) {
403 resource
.focus_new
= f
;
404 config
->setValue(screenstr
+ "focusNewWindows", resource
.focus_new
);
408 void BScreen::saveFocusLast(bool f
) {
409 resource
.focus_last
= f
;
410 config
->setValue(screenstr
+ "focusLastWindow", resource
.focus_last
);
414 void BScreen::saveHideToolbar(bool h
) {
415 resource
.hide_toolbar
= h
;
416 if (resource
.hide_toolbar
)
417 toolbar
->unmapToolbar();
419 toolbar
->mapToolbar();
420 config
->setValue(screenstr
+ "hideToolbar", resource
.hide_toolbar
);
424 void BScreen::saveWorkspaces(unsigned int w
) {
425 resource
.workspaces
= w
;
426 config
->setValue(screenstr
+ "workspaces", resource
.workspaces
);
430 void BScreen::savePlacementPolicy(int p
) {
431 resource
.placement_policy
= p
;
432 const char *placement
;
433 switch (resource
.placement_policy
) {
434 case CascadePlacement
: placement
= "CascadePlacement"; break;
435 case ColSmartPlacement
: placement
= "ColSmartPlacement"; break;
436 case RowSmartPlacement
: default: placement
= "RowSmartPlacement"; break;
438 config
->setValue(screenstr
+ "windowPlacement", placement
);
442 void BScreen::saveEdgeSnapThreshold(int t
) {
443 resource
.edge_snap_threshold
= t
;
444 config
->setValue(screenstr
+ "edgeSnapThreshold",
445 resource
.edge_snap_threshold
);
449 void BScreen::saveRowPlacementDirection(int d
) {
450 resource
.row_direction
= d
;
451 config
->setValue(screenstr
+ "rowPlacementDirection",
452 resource
.row_direction
== LeftRight
?
453 "LeftToRight" : "RightToLeft");
457 void BScreen::saveColPlacementDirection(int d
) {
458 resource
.col_direction
= d
;
459 config
->setValue(screenstr
+ "colPlacementDirection",
460 resource
.col_direction
== TopBottom
?
461 "TopToBottom" : "BottomToTop");
466 void BScreen::saveStrftimeFormat(const std::string
& format
) {
467 resource
.strftime_format
= format
;
468 config
->setValue(screenstr
+ "strftimeFormat", resource
.strftime_format
);
471 #else // !HAVE_STRFTIME
473 void BScreen::saveDateFormat(int f
) {
474 resource
.date_format
= f
;
475 config
->setValue(screenstr
+ "dateFormat",
476 resource
.date_format
== B_EuropeanDate
?
477 "European" : "American");
481 void BScreen::saveClock24Hour(Bool c
) {
482 resource
.clock24hour
= c
;
483 config
->setValue(screenstr
+ "clockFormat", resource
.clock24hour
? 24 : 12);
485 #endif // HAVE_STRFTIME
488 void BScreen::saveWorkspaceNames() {
490 WorkspaceList::iterator it
;
491 WorkspaceList::iterator last
= workspacesList
.end() - 1;
492 for (it
= workspacesList
.begin(); it
!= workspacesList
.end(); ++it
) {
493 names
+= (*it
)->getName();
497 config
->setValue(screenstr
+ "workspaceNames", names
);
501 void BScreen::save_rc(void) {
502 saveSloppyFocus(resource
.sloppy_focus
);
503 saveAutoRaise(resource
.auto_raise
);
504 saveImageDither(doImageDither());
505 saveOpaqueMove(resource
.opaque_move
);
506 saveFullMax(resource
.full_max
);
507 saveFocusNew(resource
.focus_new
);
508 saveFocusLast(resource
.focus_last
);
509 saveHideToolbar(resource
.hide_toolbar
);
510 saveWorkspaces(resource
.workspaces
);
511 savePlacementPolicy(resource
.placement_policy
);
512 saveEdgeSnapThreshold(resource
.edge_snap_threshold
);
513 saveRowPlacementDirection(resource
.row_direction
);
514 saveColPlacementDirection(resource
.col_direction
);
516 saveStrftimeFormat(resource
.strftime_format
);
517 #else // !HAVE_STRFTIME
518 saveDateFormat(resource
.date_format
);
519 savwClock24Hour(resource
.clock24hour
);
520 #endif // HAVE_STRFTIME
527 void BScreen::load_rc(void) {
531 if (! config
->getValue(screenstr
+ "fullMaximization", resource
.full_max
))
532 resource
.full_max
= false;
534 if (! config
->getValue(screenstr
+ "focusNewWindows", resource
.focus_new
))
535 resource
.focus_new
= false;
537 if (! config
->getValue(screenstr
+ "focusLastWindow", resource
.focus_last
))
538 resource
.focus_last
= false;
540 if (! config
->getValue(screenstr
+ "workspaces", resource
.workspaces
))
541 resource
.workspaces
= 1;
543 if (! config
->getValue(screenstr
+ "opaqueMove", resource
.opaque_move
))
544 resource
.opaque_move
= false;
546 if (! config
->getValue(screenstr
+ "hideToolbar", resource
.hide_toolbar
))
547 resource
.hide_toolbar
= false;
549 if (! config
->getValue(screenstr
+ "imageDither", b
))
551 image_control
->setDither(b
);
553 if (! config
->getValue(screenstr
+ "edgeSnapThreshold",
554 resource
.edge_snap_threshold
))
555 resource
.edge_snap_threshold
= 4;
557 if (config
->getValue(screenstr
+ "rowPlacementDirection", s
) &&
559 resource
.row_direction
= RightLeft
;
561 resource
.row_direction
= LeftRight
;
563 if (config
->getValue(screenstr
+ "colPlacementDirection", s
) &&
565 resource
.col_direction
= BottomTop
;
567 resource
.col_direction
= TopBottom
;
569 removeWorkspaceNames();
570 if (config
->getValue(screenstr
+ "workspaceNames", s
)) {
571 string::const_iterator it
= s
.begin(), end
= s
.end();
573 string::const_iterator tmp
= it
; // current string.begin()
574 it
= std::find(tmp
, end
, ','); // look for comma between tmp and end
575 addWorkspaceName(string(tmp
, it
)); // s[tmp:it]
582 resource
.sloppy_focus
= true;
583 resource
.auto_raise
= false;
584 resource
.click_raise
= false;
585 if (config
->getValue(screenstr
+ "focusModel", s
)) {
586 if (s
.find("ClickToFocus") != string::npos
) {
587 resource
.sloppy_focus
= false;
590 if (s
.find("AutoRaise") != string::npos
)
591 resource
.auto_raise
= true;
592 if (s
.find("ClickRaise") != string::npos
)
593 resource
.click_raise
= true;
597 if (config
->getValue(screenstr
+ "windowPlacement", s
)) {
598 if (s
== "CascadePlacement")
599 resource
.placement_policy
= CascadePlacement
;
600 else if (s
== "ColSmartPlacement")
601 resource
.placement_policy
= ColSmartPlacement
;
602 else //if (s == "RowSmartPlacement")
603 resource
.placement_policy
= RowSmartPlacement
;
605 resource
.placement_policy
= RowSmartPlacement
;
608 if (config
->getValue(screenstr
+ "strftimeFormat", s
))
609 resource
.strftime_format
= s
;
611 resource
.strftime_format
= "%I:%M %p";
612 #else // !HAVE_STRFTIME
615 if (config
->getValue(screenstr
+ "dateFormat", s
) && s
== "European")
616 resource
.date_format
= B_EuropeanDate
;
618 resource
.date_format
= B_AmericanDate
;
620 if (! config
->getValue(screenstr
+ "clockFormat", l
))
622 resource
.clock24hour
= l
== 24;
623 #endif // HAVE_STRFTIME
627 void BScreen::reconfigure(void) {
634 unsigned long gc_value_mask
= GCForeground
;
635 if (! i18n
.multibyte()) gc_value_mask
|= GCFont
;
637 gcv
.foreground
= WhitePixel(blackbox
->getXDisplay(),
639 gcv
.function
= GXinvert
;
640 gcv
.subwindow_mode
= IncludeInferiors
;
641 XChangeGC(blackbox
->getXDisplay(), opGC
,
642 GCForeground
| GCFunction
| GCSubwindowMode
, &gcv
);
644 const char *s
= i18n(ScreenSet
, ScreenPositionLength
,
645 "0: 0000 x 0: 0000");
648 if (i18n
.multibyte()) {
649 XRectangle ink
, logical
;
650 XmbTextExtents(resource
.wstyle
.fontset
, s
, l
, &ink
, &logical
);
651 geom_w
= logical
.width
;
653 geom_h
= resource
.wstyle
.fontset_extents
->max_ink_extent
.height
;
655 geom_w
= XTextWidth(resource
.wstyle
.font
, s
, l
);
657 geom_h
= resource
.wstyle
.font
->ascent
+ resource
.wstyle
.font
->descent
;
660 geom_w
+= (resource
.bevel_width
* 2);
661 geom_h
+= (resource
.bevel_width
* 2);
663 BTexture
* texture
= &(resource
.wstyle
.l_focus
);
664 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
665 if (geom_pixmap
== ParentRelative
) {
666 texture
= &(resource
.wstyle
.t_focus
);
667 geom_pixmap
= texture
->render(geom_w
, geom_h
, geom_pixmap
);
670 XSetWindowBackground(blackbox
->getXDisplay(), geom_window
,
671 texture
->color().pixel());
673 XSetWindowBackgroundPixmap(blackbox
->getXDisplay(),
674 geom_window
, geom_pixmap
);
676 XSetWindowBorderWidth(blackbox
->getXDisplay(), geom_window
,
677 resource
.border_width
);
678 XSetWindowBorder(blackbox
->getXDisplay(), geom_window
,
679 resource
.border_color
.pixel());
681 workspacemenu
->reconfigure();
682 iconmenu
->reconfigure();
684 typedef std::vector
<int> SubList
;
685 SubList remember_subs
;
687 // save the current open menus
688 Basemenu
*menu
= rootmenu
;
690 while ((submenu
= menu
->getCurrentSubmenu()) >= 0) {
691 remember_subs
.push_back(submenu
);
692 menu
= menu
->find(submenu
)->submenu();
698 rootmenu
->reconfigure();
700 // reopen the saved menus
702 const SubList::iterator subs_end
= remember_subs
.end();
703 for (SubList::iterator it
= remember_subs
.begin(); it
!= subs_end
; ++it
) {
704 menu
->drawSubmenu(*it
);
705 menu
= menu
->find(*it
)->submenu();
710 configmenu
->reconfigure();
712 toolbar
->reconfigure();
716 std::for_each(workspacesList
.begin(), workspacesList
.end(),
717 std::mem_fun(&Workspace::reconfigure
));
719 BlackboxWindowList::iterator iit
= iconList
.begin();
720 for (; iit
!= iconList
.end(); ++iit
) {
721 BlackboxWindow
*bw
= *iit
;
722 if (bw
->validateClient())
726 image_control
->timeout();
730 void BScreen::rereadMenu(void) {
734 rootmenu
->reconfigure();
738 void BScreen::LoadStyle(void) {
741 const char *sfile
= blackbox
->getStyleFilename();
743 style
.setFile(sfile
);
744 if (! style
.load()) {
745 style
.setFile(DEFAULTSTYLE
);
747 style
.create(); // hardcoded default values will be used.
753 // load fonts/fontsets
754 if (resource
.wstyle
.fontset
)
755 XFreeFontSet(blackbox
->getXDisplay(), resource
.wstyle
.fontset
);
756 if (resource
.tstyle
.fontset
)
757 XFreeFontSet(blackbox
->getXDisplay(), resource
.tstyle
.fontset
);
758 if (resource
.mstyle
.f_fontset
)
759 XFreeFontSet(blackbox
->getXDisplay(), resource
.mstyle
.f_fontset
);
760 if (resource
.mstyle
.t_fontset
)
761 XFreeFontSet(blackbox
->getXDisplay(), resource
.mstyle
.t_fontset
);
762 resource
.wstyle
.fontset
= 0;
763 resource
.tstyle
.fontset
= 0;
764 resource
.mstyle
.f_fontset
= 0;
765 resource
.mstyle
.t_fontset
= 0;
766 if (resource
.wstyle
.font
)
767 XFreeFont(blackbox
->getXDisplay(), resource
.wstyle
.font
);
768 if (resource
.tstyle
.font
)
769 XFreeFont(blackbox
->getXDisplay(), resource
.tstyle
.font
);
770 if (resource
.mstyle
.f_font
)
771 XFreeFont(blackbox
->getXDisplay(), resource
.mstyle
.f_font
);
772 if (resource
.mstyle
.t_font
)
773 XFreeFont(blackbox
->getXDisplay(), resource
.mstyle
.t_font
);
774 resource
.wstyle
.font
= 0;
775 resource
.tstyle
.font
= 0;
776 resource
.mstyle
.f_font
= 0;
777 resource
.mstyle
.t_font
= 0;
779 if (i18n
.multibyte()) {
780 resource
.wstyle
.fontset
= readDatabaseFontSet("window.font", style
);
781 resource
.tstyle
.fontset
= readDatabaseFontSet("toolbar.font", style
);
782 resource
.mstyle
.t_fontset
= readDatabaseFontSet("menu.title.font", style
);
783 resource
.mstyle
.f_fontset
= readDatabaseFontSet("menu.frame.font", style
);
785 resource
.mstyle
.t_fontset_extents
=
786 XExtentsOfFontSet(resource
.mstyle
.t_fontset
);
787 resource
.mstyle
.f_fontset_extents
=
788 XExtentsOfFontSet(resource
.mstyle
.f_fontset
);
789 resource
.tstyle
.fontset_extents
=
790 XExtentsOfFontSet(resource
.tstyle
.fontset
);
791 resource
.wstyle
.fontset_extents
=
792 XExtentsOfFontSet(resource
.wstyle
.fontset
);
794 resource
.wstyle
.font
= readDatabaseFont("window.font", style
);
795 resource
.tstyle
.font
= readDatabaseFont("toolbar.font", style
);
796 resource
.mstyle
.t_font
= readDatabaseFont("menu.title.font", style
);
797 resource
.mstyle
.f_font
= readDatabaseFont("menu.frame.font", style
);
800 // load window config
801 resource
.wstyle
.t_focus
=
802 readDatabaseTexture("window.title.focus", "white", style
);
803 resource
.wstyle
.t_unfocus
=
804 readDatabaseTexture("window.title.unfocus", "black", style
);
805 resource
.wstyle
.l_focus
=
806 readDatabaseTexture("window.label.focus", "white", style
);
807 resource
.wstyle
.l_unfocus
=
808 readDatabaseTexture("window.label.unfocus", "black", style
);
809 resource
.wstyle
.h_focus
=
810 readDatabaseTexture("window.handle.focus", "white", style
);
811 resource
.wstyle
.h_unfocus
=
812 readDatabaseTexture("window.handle.unfocus", "black", style
);
813 resource
.wstyle
.g_focus
=
814 readDatabaseTexture("window.grip.focus", "white", style
);
815 resource
.wstyle
.g_unfocus
=
816 readDatabaseTexture("window.grip.unfocus", "black", style
);
817 resource
.wstyle
.b_focus
=
818 readDatabaseTexture("window.button.focus", "white", style
);
819 resource
.wstyle
.b_unfocus
=
820 readDatabaseTexture("window.button.unfocus", "black", style
);
821 resource
.wstyle
.b_pressed
=
822 readDatabaseTexture("window.button.pressed", "black", style
);
823 resource
.wstyle
.f_focus
=
824 readDatabaseColor("window.frame.focusColor", "white", style
);
825 resource
.wstyle
.f_unfocus
=
826 readDatabaseColor("window.frame.unfocusColor", "black", style
);
827 resource
.wstyle
.l_text_focus
=
828 readDatabaseColor("window.label.focus.textColor", "black", style
);
829 resource
.wstyle
.l_text_unfocus
=
830 readDatabaseColor("window.label.unfocus.textColor", "white", style
);
831 resource
.wstyle
.b_pic_focus
=
832 readDatabaseColor("window.button.focus.picColor", "black", style
);
833 resource
.wstyle
.b_pic_unfocus
=
834 readDatabaseColor("window.button.unfocus.picColor", "white", style
);
836 resource
.wstyle
.justify
= LeftJustify
;
837 if (style
.getValue("window.justify", s
)) {
838 if (s
== "right" || s
== "Right")
839 resource
.wstyle
.justify
= RightJustify
;
840 else if (s
== "center" || s
== "Center")
841 resource
.wstyle
.justify
= CenterJustify
;
844 // load toolbar config
845 resource
.tstyle
.toolbar
=
846 readDatabaseTexture("toolbar", "black", style
);
847 resource
.tstyle
.label
=
848 readDatabaseTexture("toolbar.label", "black", style
);
849 resource
.tstyle
.window
=
850 readDatabaseTexture("toolbar.windowLabel", "black", style
);
851 resource
.tstyle
.button
=
852 readDatabaseTexture("toolbar.button", "white", style
);
853 resource
.tstyle
.pressed
=
854 readDatabaseTexture("toolbar.button.pressed", "black", style
);
855 resource
.tstyle
.clock
=
856 readDatabaseTexture("toolbar.clock", "black", style
);
857 resource
.tstyle
.l_text
=
858 readDatabaseColor("toolbar.label.textColor", "white", style
);
859 resource
.tstyle
.w_text
=
860 readDatabaseColor("toolbar.windowLabel.textColor", "white", style
);
861 resource
.tstyle
.c_text
=
862 readDatabaseColor("toolbar.clock.textColor", "white", style
);
863 resource
.tstyle
.b_pic
=
864 readDatabaseColor("toolbar.button.picColor", "black", style
);
866 resource
.tstyle
.justify
= LeftJustify
;
867 if (style
.getValue("toolbar.justify", s
)) {
868 if (s
== "right" || s
== "Right")
869 resource
.tstyle
.justify
= RightJustify
;
870 else if (s
== "center" || s
== "Center")
871 resource
.tstyle
.justify
= CenterJustify
;
875 resource
.mstyle
.title
=
876 readDatabaseTexture("menu.title", "white", style
);
877 resource
.mstyle
.frame
=
878 readDatabaseTexture("menu.frame", "black", style
);
879 resource
.mstyle
.hilite
=
880 readDatabaseTexture("menu.hilite", "white", style
);
881 resource
.mstyle
.t_text
=
882 readDatabaseColor("menu.title.textColor", "black", style
);
883 resource
.mstyle
.f_text
=
884 readDatabaseColor("menu.frame.textColor", "white", style
);
885 resource
.mstyle
.d_text
=
886 readDatabaseColor("menu.frame.disableColor", "black", style
);
887 resource
.mstyle
.h_text
=
888 readDatabaseColor("menu.hilite.textColor", "black", style
);
890 resource
.mstyle
.t_justify
= LeftJustify
;
891 if (style
.getValue("menu.title.justify", s
)) {
892 if (s
== "right" || s
== "Right")
893 resource
.mstyle
.t_justify
= RightJustify
;
894 else if (s
== "center" || s
== "Center")
895 resource
.mstyle
.t_justify
= CenterJustify
;
898 resource
.mstyle
.f_justify
= LeftJustify
;
899 if (style
.getValue("menu.frame.justify", s
)) {
900 if (s
== "right" || s
== "Right")
901 resource
.mstyle
.f_justify
= RightJustify
;
902 else if (s
== "center" || s
== "Center")
903 resource
.mstyle
.f_justify
= CenterJustify
;
906 resource
.mstyle
.bullet
= Basemenu::Triangle
;
907 if (style
.getValue("menu.bullet", s
)) {
908 if (s
== "empty" || s
== "Empty")
909 resource
.mstyle
.bullet
= Basemenu::Empty
;
910 else if (s
== "square" || s
== "Square")
911 resource
.mstyle
.bullet
= Basemenu::Square
;
912 else if (s
== "diamond" || s
== "Diamond")
913 resource
.mstyle
.bullet
= Basemenu::Diamond
;
916 resource
.mstyle
.bullet_pos
= Basemenu::Left
;
917 if (style
.getValue("menu.bullet.position", s
)) {
918 if (s
== "right" || s
== "Right")
919 resource
.mstyle
.bullet_pos
= Basemenu::Right
;
922 resource
.border_color
=
923 readDatabaseColor("borderColor", "black", style
);
925 // load bevel, border and handle widths
926 if (! style
.getValue("handleWidth", resource
.handle_width
) ||
927 resource
.handle_width
> (getWidth() / 2) || resource
.handle_width
== 0)
928 resource
.handle_width
= 6;
930 if (! style
.getValue("borderWidth", resource
.border_width
))
931 resource
.border_width
= 1;
933 if (! style
.getValue("bevelWidth", resource
.bevel_width
) ||
934 resource
.bevel_width
> (getWidth() / 2) || resource
.bevel_width
== 0)
935 resource
.bevel_width
= 3;
937 if (! style
.getValue("frameWidth", resource
.frame_width
) ||
938 resource
.frame_width
> (getWidth() / 2))
939 resource
.frame_width
= resource
.bevel_width
;
941 if (style
.getValue("rootCommand", s
))
942 bexec(s
, displayString());
946 void BScreen::addIcon(BlackboxWindow
*w
) {
949 w
->setWorkspace(BSENTINEL
);
950 w
->setWindowNumber(iconList
.size());
952 iconList
.push_back(w
);
954 const char* title
= w
->getIconTitle();
955 iconmenu
->insert(title
);
960 void BScreen::removeIcon(BlackboxWindow
*w
) {
965 iconmenu
->remove(w
->getWindowNumber());
968 BlackboxWindowList::iterator it
= iconList
.begin(),
969 end
= iconList
.end();
970 for (int i
= 0; it
!= end
; ++it
)
971 (*it
)->setWindowNumber(i
++);
975 BlackboxWindow
*BScreen::getIcon(unsigned int index
) {
976 if (index
< iconList
.size()) {
977 BlackboxWindowList::iterator it
= iconList
.begin();
978 for (; index
> 0; --index
, ++it
) ; /* increment to index */
982 return (BlackboxWindow
*) 0;
986 unsigned int BScreen::addWorkspace(void) {
987 Workspace
*wkspc
= new Workspace(this, workspacesList
.size());
988 workspacesList
.push_back(wkspc
);
989 saveWorkspaces(getWorkspaceCount());
990 saveWorkspaceNames();
992 workspacemenu
->insert(wkspc
->getName(), wkspc
->getMenu(),
994 workspacemenu
->update();
996 toolbar
->reconfigure();
998 updateNetizenWorkspaceCount();
1000 return workspacesList
.size();
1004 unsigned int BScreen::removeLastWorkspace(void) {
1005 if (workspacesList
.size() == 1)
1008 Workspace
*wkspc
= workspacesList
.back();
1010 if (current_workspace
->getID() == wkspc
->getID())
1011 changeWorkspaceID(current_workspace
->getID() - 1);
1015 workspacemenu
->remove(wkspc
->getID() + 2);
1016 workspacemenu
->update();
1018 workspacesList
.pop_back();
1021 saveWorkspaces(getWorkspaceCount());
1022 saveWorkspaceNames();
1024 toolbar
->reconfigure();
1026 updateNetizenWorkspaceCount();
1028 return workspacesList
.size();
1032 void BScreen::changeWorkspaceID(unsigned int id
) {
1033 if (! current_workspace
) return;
1035 if (id
!= current_workspace
->getID()) {
1036 current_workspace
->hideAll();
1038 workspacemenu
->setItemSelected(current_workspace
->getID() + 2, False
);
1040 if (blackbox
->getFocusedWindow() &&
1041 blackbox
->getFocusedWindow()->getScreen() == this &&
1042 (! blackbox
->getFocusedWindow()->isStuck())) {
1043 current_workspace
->setLastFocusedWindow(blackbox
->getFocusedWindow());
1044 blackbox
->setFocusedWindow((BlackboxWindow
*) 0);
1047 current_workspace
= getWorkspace(id
);
1049 xatom
->setValue(getRootWindow(), XAtom::net_current_desktop
,
1050 XAtom::cardinal
, id
);
1053 workspacemenu
->setItemSelected(current_workspace
->getID() + 2, True
);
1054 toolbar
->redrawWorkspaceLabel(True
);
1056 current_workspace
->showAll();
1058 if (resource
.focus_last
&& current_workspace
->getLastFocusedWindow()) {
1059 XSync(blackbox
->getXDisplay(), False
);
1060 current_workspace
->getLastFocusedWindow()->setInputFocus();
1064 updateNetizenCurrentWorkspace();
1068 void BScreen::manageWindow(Window w
) {
1069 new BlackboxWindow(blackbox
, w
, this);
1071 BlackboxWindow
*win
= blackbox
->searchWindow(w
);
1075 windowList
.push_back(win
);
1077 XMapRequestEvent mre
;
1079 win
->restoreAttributes();
1080 win
->mapRequestEvent(&mre
);
1084 void BScreen::unmanageWindow(BlackboxWindow
*w
, bool remap
) {
1087 if (w
->getWorkspaceNumber() != BSENTINEL
&&
1088 w
->getWindowNumber() != BSENTINEL
)
1089 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
1090 else if (w
->isIconic())
1093 windowList
.remove(w
);
1095 if (blackbox
->getFocusedWindow() == w
)
1096 blackbox
->setFocusedWindow((BlackboxWindow
*) 0);
1098 removeNetizen(w
->getClientWindow());
1101 some managed windows can also be window group controllers. when
1102 unmanaging such windows, we should also delete the window group.
1104 BWindowGroup
*group
= blackbox
->searchGroup(w
->getClientWindow());
1111 void BScreen::addNetizen(Netizen
*n
) {
1112 netizenList
.push_back(n
);
1114 n
->sendWorkspaceCount();
1115 n
->sendCurrentWorkspace();
1117 WorkspaceList::iterator it
= workspacesList
.begin();
1118 const WorkspaceList::iterator end
= workspacesList
.end();
1119 for (; it
!= end
; ++it
)
1120 (*it
)->sendWindowList(*n
);
1122 Window f
= ((blackbox
->getFocusedWindow()) ?
1123 blackbox
->getFocusedWindow()->getClientWindow() : None
);
1124 n
->sendWindowFocus(f
);
1128 void BScreen::removeNetizen(Window w
) {
1129 NetizenList::iterator it
= netizenList
.begin();
1130 for (; it
!= netizenList
.end(); ++it
) {
1131 if ((*it
)->getWindowID() == w
) {
1133 netizenList
.erase(it
);
1140 void BScreen::updateNetizenCurrentWorkspace(void) {
1141 std::for_each(netizenList
.begin(), netizenList
.end(),
1142 std::mem_fun(&Netizen::sendCurrentWorkspace
));
1146 void BScreen::updateNetizenWorkspaceCount(void) {
1147 xatom
->setValue(getRootWindow(), XAtom::net_number_of_desktops
,
1148 XAtom::cardinal
, workspacesList
.size());
1150 std::for_each(netizenList
.begin(), netizenList
.end(),
1151 std::mem_fun(&Netizen::sendWorkspaceCount
));
1155 void BScreen::updateNetizenWindowFocus(void) {
1156 Window f
= ((blackbox
->getFocusedWindow()) ?
1157 blackbox
->getFocusedWindow()->getClientWindow() : None
);
1158 NetizenList::iterator it
= netizenList
.begin();
1159 for (; it
!= netizenList
.end(); ++it
)
1160 (*it
)->sendWindowFocus(f
);
1164 void BScreen::updateNetizenWindowAdd(Window w
, unsigned long p
) {
1165 NetizenList::iterator it
= netizenList
.begin();
1166 for (; it
!= netizenList
.end(); ++it
) {
1167 (*it
)->sendWindowAdd(w
, p
);
1172 void BScreen::updateNetizenWindowDel(Window w
) {
1173 NetizenList::iterator it
= netizenList
.begin();
1174 for (; it
!= netizenList
.end(); ++it
)
1175 (*it
)->sendWindowDel(w
);
1179 void BScreen::updateNetizenWindowRaise(Window w
) {
1180 NetizenList::iterator it
= netizenList
.begin();
1181 for (; it
!= netizenList
.end(); ++it
)
1182 (*it
)->sendWindowRaise(w
);
1186 void BScreen::updateNetizenWindowLower(Window w
) {
1187 NetizenList::iterator it
= netizenList
.begin();
1188 for (; it
!= netizenList
.end(); ++it
)
1189 (*it
)->sendWindowLower(w
);
1193 void BScreen::updateNetizenConfigNotify(XEvent
*e
) {
1194 NetizenList::iterator it
= netizenList
.begin();
1195 for (; it
!= netizenList
.end(); ++it
)
1196 (*it
)->sendConfigNotify(e
);
1200 void BScreen::raiseWindows(Window
*workspace_stack
, unsigned int num
) {
1202 Window
*session_stack
= new
1203 Window
[(num
+ workspacesList
.size() + rootmenuList
.size() + 13)];
1204 unsigned int i
= 0, k
= num
;
1206 XRaiseWindow(blackbox
->getXDisplay(), iconmenu
->getWindowID());
1207 *(session_stack
+ i
++) = iconmenu
->getWindowID();
1209 WorkspaceList::iterator wit
= workspacesList
.begin();
1210 const WorkspaceList::iterator w_end
= workspacesList
.end();
1211 for (; wit
!= w_end
; ++wit
)
1212 *(session_stack
+ i
++) = (*wit
)->getMenu()->getWindowID();
1214 *(session_stack
+ i
++) = workspacemenu
->getWindowID();
1216 *(session_stack
+ i
++) = configmenu
->getFocusmenu()->getWindowID();
1217 *(session_stack
+ i
++) = configmenu
->getPlacementmenu()->getWindowID();
1218 *(session_stack
+ i
++) = configmenu
->getWindowID();
1220 *(session_stack
+ i
++) = slit
->getMenu()->getDirectionmenu()->getWindowID();
1221 *(session_stack
+ i
++) = slit
->getMenu()->getPlacementmenu()->getWindowID();
1222 *(session_stack
+ i
++) = slit
->getMenu()->getWindowID();
1224 *(session_stack
+ i
++) =
1225 toolbar
->getMenu()->getPlacementmenu()->getWindowID();
1226 *(session_stack
+ i
++) = toolbar
->getMenu()->getWindowID();
1228 RootmenuList::iterator rit
= rootmenuList
.begin();
1229 for (; rit
!= rootmenuList
.end(); ++rit
)
1230 *(session_stack
+ i
++) = (*rit
)->getWindowID();
1231 *(session_stack
+ i
++) = rootmenu
->getWindowID();
1233 if (toolbar
->isOnTop())
1234 *(session_stack
+ i
++) = toolbar
->getWindowID();
1236 if (slit
->isOnTop())
1237 *(session_stack
+ i
++) = slit
->getWindowID();
1240 *(session_stack
+ i
++) = *(workspace_stack
+ k
);
1242 XRestackWindows(blackbox
->getXDisplay(), session_stack
, i
);
1244 delete [] session_stack
;
1248 void BScreen::addWorkspaceName(const string
& name
) {
1249 workspaceNames
.push_back(name
);
1254 * I would love to kill this function and the accompanying workspaceNames
1255 * list. However, we have a chicken and egg situation. The names are read
1256 * in during load_rc() which happens before the workspaces are created.
1257 * The current solution is to read the names into a list, then use the list
1258 * later for constructing the workspaces. It is only used during initial
1261 const string
BScreen::getNameOfWorkspace(unsigned int id
) {
1262 if (id
< workspaceNames
.size())
1263 return workspaceNames
[id
];
1268 void BScreen::reassociateWindow(BlackboxWindow
*w
, unsigned int wkspc_id
,
1269 bool ignore_sticky
) {
1272 if (wkspc_id
== BSENTINEL
)
1273 wkspc_id
= current_workspace
->getID();
1275 if (w
->getWorkspaceNumber() == wkspc_id
)
1278 if (w
->isIconic()) {
1280 getWorkspace(wkspc_id
)->addWindow(w
);
1281 } else if (ignore_sticky
|| ! w
->isStuck()) {
1282 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
1283 getWorkspace(wkspc_id
)->addWindow(w
);
1288 void BScreen::propagateWindowName(const BlackboxWindow
*bw
) {
1289 if (bw
->isIconic()) {
1290 iconmenu
->changeItemLabel(bw
->getWindowNumber(), bw
->getIconTitle());
1294 Clientmenu
*clientmenu
= getWorkspace(bw
->getWorkspaceNumber())->getMenu();
1295 clientmenu
->changeItemLabel(bw
->getWindowNumber(), bw
->getTitle());
1296 clientmenu
->update();
1298 if (blackbox
->getFocusedWindow() == bw
)
1299 toolbar
->redrawWindowLabel(True
);
1304 void BScreen::nextFocus(void) {
1305 BlackboxWindow
*focused
= blackbox
->getFocusedWindow(),
1309 // if window is not on this screen, ignore it
1310 if (focused
->getScreen()->getScreenNumber() != getScreenNumber())
1311 focused
= (BlackboxWindow
*) 0;
1314 if (focused
&& current_workspace
->getCount() > 1) {
1315 // next is the next window to recieve focus, current is a place holder
1316 BlackboxWindow
*current
;
1319 next
= current_workspace
->getNextWindowInList(current
);
1320 } while(! next
->setInputFocus() && next
!= focused
);
1322 if (next
!= focused
)
1323 current_workspace
->raiseWindow(next
);
1324 } else if (current_workspace
->getCount() >= 1) {
1325 next
= current_workspace
->getTopWindowOnStack();
1327 current_workspace
->raiseWindow(next
);
1328 next
->setInputFocus();
1333 void BScreen::prevFocus(void) {
1334 BlackboxWindow
*focused
= blackbox
->getFocusedWindow(),
1338 // if window is not on this screen, ignore it
1339 if (focused
->getScreen()->getScreenNumber() != getScreenNumber())
1340 focused
= (BlackboxWindow
*) 0;
1343 if (focused
&& current_workspace
->getCount() > 1) {
1344 // next is the next window to recieve focus, current is a place holder
1345 BlackboxWindow
*current
;
1348 next
= current_workspace
->getPrevWindowInList(current
);
1349 } while(! next
->setInputFocus() && next
!= focused
);
1351 if (next
!= focused
)
1352 current_workspace
->raiseWindow(next
);
1353 } else if (current_workspace
->getCount() >= 1) {
1354 next
= current_workspace
->getTopWindowOnStack();
1356 current_workspace
->raiseWindow(next
);
1357 next
->setInputFocus();
1362 void BScreen::raiseFocus(void) {
1363 BlackboxWindow
*focused
= blackbox
->getFocusedWindow();
1367 // if on this Screen, raise it
1368 if (focused
->getScreen()->getScreenNumber() == getScreenNumber()) {
1369 Workspace
*workspace
= getWorkspace(focused
->getWorkspaceNumber());
1370 workspace
->raiseWindow(focused
);
1375 void BScreen::InitMenu(void) {
1377 rootmenuList
.clear();
1379 while (rootmenu
->getCount())
1380 rootmenu
->remove(0);
1382 rootmenu
= new Rootmenu(this);
1384 bool defaultMenu
= True
;
1386 FILE *menu_file
= (FILE *) 0;
1387 const char *menu_filename
= blackbox
->getMenuFilename();
1390 if (! (menu_file
= fopen(menu_filename
, "r")))
1391 perror(menu_filename
);
1392 if (! menu_file
) { // opening the menu file failed, try the default menu
1393 menu_filename
= DEFAULTMENU
;
1394 if (! (menu_file
= fopen(menu_filename
, "r")))
1395 perror(menu_filename
);
1399 if (feof(menu_file
)) {
1400 fprintf(stderr
, i18n(ScreenSet
, ScreenEmptyMenuFile
,
1401 "%s: Empty menu file"),
1404 char line
[1024], label
[1024];
1405 memset(line
, 0, 1024);
1406 memset(label
, 0, 1024);
1408 while (fgets(line
, 1024, menu_file
) && ! feof(menu_file
)) {
1409 if (line
[0] != '#') {
1410 int i
, key
= 0, index
= -1, len
= strlen(line
);
1412 for (i
= 0; i
< len
; i
++) {
1413 if (line
[i
] == '[') index
= 0;
1414 else if (line
[i
] == ']') break;
1415 else if (line
[i
] != ' ')
1417 key
+= tolower(line
[i
]);
1420 if (key
== 517) { // [begin]
1422 for (i
= index
; i
< len
; i
++) {
1423 if (line
[i
] == '(') index
= 0;
1424 else if (line
[i
] == ')') break;
1425 else if (index
++ >= 0) {
1426 if (line
[i
] == '\\' && i
< len
- 1) i
++;
1427 label
[index
- 1] = line
[i
];
1431 if (index
== -1) index
= 0;
1432 label
[index
] = '\0';
1434 rootmenu
->setLabel(label
);
1435 defaultMenu
= parseMenuFile(menu_file
, rootmenu
);
1437 blackbox
->addMenuTimestamp(menu_filename
);
1447 rootmenu
->setInternalMenu();
1448 rootmenu
->insert(i18n(ScreenSet
, Screenxterm
, "xterm"),
1450 i18n(ScreenSet
, Screenxterm
, "xterm"));
1451 rootmenu
->insert(i18n(ScreenSet
, ScreenRestart
, "Restart"),
1453 rootmenu
->insert(i18n(ScreenSet
, ScreenExit
, "Exit"),
1455 rootmenu
->setLabel(i18n(BasemenuSet
, BasemenuBlackboxMenu
,
1461 bool BScreen::parseMenuFile(FILE *file
, Rootmenu
*menu
) {
1462 char line
[1024], label
[1024], command
[1024];
1464 while (! feof(file
)) {
1465 memset(line
, 0, 1024);
1466 memset(label
, 0, 1024);
1467 memset(command
, 0, 1024);
1469 if (fgets(line
, 1024, file
)) {
1470 if (line
[0] != '#') {
1471 int i
, key
= 0, parse
= 0, index
= -1, line_length
= strlen(line
);
1473 // determine the keyword
1474 for (i
= 0; i
< line_length
; i
++) {
1475 if (line
[i
] == '[') parse
= 1;
1476 else if (line
[i
] == ']') break;
1477 else if (line
[i
] != ' ')
1479 key
+= tolower(line
[i
]);
1482 // get the label enclosed in ()'s
1485 for (i
= 0; i
< line_length
; i
++) {
1486 if (line
[i
] == '(') {
1489 } else if (line
[i
] == ')') break;
1490 else if (index
++ >= 0) {
1491 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
1492 label
[index
- 1] = line
[i
];
1497 label
[index
] = '\0';
1502 // get the command enclosed in {}'s
1505 for (i
= 0; i
< line_length
; i
++) {
1506 if (line
[i
] == '{') {
1509 } else if (line
[i
] == '}') break;
1510 else if (index
++ >= 0) {
1511 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
1512 command
[index
- 1] = line
[i
];
1517 command
[index
] = '\0';
1524 return ((menu
->getCount() == 0) ? True
: False
);
1531 menu
->insert(label
);
1536 if ((! *label
) && (! *command
)) {
1537 fprintf(stderr
, i18n(ScreenSet
, ScreenEXECError
,
1538 "BScreen::parseMenuFile: [exec] error, "
1539 "no menu label and/or command defined\n"));
1543 menu
->insert(label
, BScreen::Execute
, command
);
1549 fprintf(stderr
, i18n(ScreenSet
, ScreenEXITError
,
1550 "BScreen::parseMenuFile: [exit] error, "
1551 "no menu label defined\n"));
1555 menu
->insert(label
, BScreen::Exit
);
1561 if ((! *label
) || (! *command
)) {
1563 i18n(ScreenSet
, ScreenSTYLEError
,
1564 "BScreen::parseMenuFile: [style] error, "
1565 "no menu label and/or filename defined\n"));
1569 string style
= expandTilde(command
);
1571 menu
->insert(label
, BScreen::SetStyle
, style
.c_str());
1578 fprintf(stderr
, i18n(ScreenSet
, ScreenCONFIGError
,
1579 "BScreen::parseMenufile: [config] error, "
1580 "no label defined"));
1584 menu
->insert(label
, configmenu
);
1588 case 740: // include
1591 fprintf(stderr
, i18n(ScreenSet
, ScreenINCLUDEError
,
1592 "BScreen::parseMenuFile: [include] error, "
1593 "no filename defined\n"));
1597 string newfile
= expandTilde(label
);
1598 FILE *submenufile
= fopen(newfile
.c_str(), "r");
1602 if (fstat(fileno(submenufile
), &buf
) ||
1603 (! S_ISREG(buf
.st_mode
))) {
1605 i18n(ScreenSet
, ScreenINCLUDEErrorReg
,
1606 "BScreen::parseMenuFile: [include] error: "
1607 "'%s' is not a regular file\n"), newfile
.c_str());
1611 if (! feof(submenufile
)) {
1612 if (! parseMenuFile(submenufile
, menu
))
1613 blackbox
->addMenuTimestamp(newfile
);
1615 fclose(submenufile
);
1618 perror(newfile
.c_str());
1624 case 767: // submenu
1627 fprintf(stderr
, i18n(ScreenSet
, ScreenSUBMENUError
,
1628 "BScreen::parseMenuFile: [submenu] error, "
1629 "no menu label defined\n"));
1633 Rootmenu
*submenu
= new Rootmenu(this);
1636 submenu
->setLabel(command
);
1638 submenu
->setLabel(label
);
1640 parseMenuFile(file
, submenu
);
1642 menu
->insert(label
, submenu
);
1643 rootmenuList
.push_back(submenu
);
1648 case 773: // restart
1651 fprintf(stderr
, i18n(ScreenSet
, ScreenRESTARTError
,
1652 "BScreen::parseMenuFile: [restart] error, "
1653 "no menu label defined\n"));
1658 menu
->insert(label
, BScreen::RestartOther
, command
);
1660 menu
->insert(label
, BScreen::Restart
);
1665 case 845: // reconfig
1669 i18n(ScreenSet
, ScreenRECONFIGError
,
1670 "BScreen::parseMenuFile: [reconfig] error, "
1671 "no menu label defined\n"));
1675 menu
->insert(label
, BScreen::Reconfigure
);
1680 case 995: // stylesdir
1681 case 1113: // stylesmenu
1683 bool newmenu
= ((key
== 1113) ? True
: False
);
1685 if ((! *label
) || ((! *command
) && newmenu
)) {
1687 i18n(ScreenSet
, ScreenSTYLESDIRError
,
1688 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1689 " error, no directory defined\n"));
1693 char *directory
= ((newmenu
) ? command
: label
);
1695 string stylesdir
= expandTilde(directory
);
1697 struct stat statbuf
;
1699 if (! stat(stylesdir
.c_str(), &statbuf
)) {
1700 if (S_ISDIR(statbuf
.st_mode
)) {
1701 Rootmenu
*stylesmenu
;
1704 stylesmenu
= new Rootmenu(this);
1708 DIR *d
= opendir(stylesdir
.c_str());
1710 std::vector
<string
> ls
;
1712 while((p
= readdir(d
)))
1713 ls
.push_back(p
->d_name
);
1717 std::sort(ls
.begin(), ls
.end());
1719 std::vector
<string
>::iterator it
= ls
.begin(),
1721 for (; it
!= end
; ++it
) {
1722 const string
& fname
= *it
;
1724 if (fname
[fname
.size()-1] == '~')
1727 string style
= stylesdir
;
1731 if ((! stat(style
.c_str(), &statbuf
)) &&
1732 S_ISREG(statbuf
.st_mode
))
1733 stylesmenu
->insert(fname
, BScreen::SetStyle
, style
);
1736 stylesmenu
->update();
1739 stylesmenu
->setLabel(label
);
1740 menu
->insert(label
, stylesmenu
);
1741 rootmenuList
.push_back(stylesmenu
);
1744 blackbox
->addMenuTimestamp(stylesdir
);
1747 i18n(ScreenSet
, ScreenSTYLESDIRErrorNotDir
,
1748 "BScreen::parseMenuFile:"
1749 " [stylesdir/stylesmenu] error, %s is not a"
1750 " directory\n"), stylesdir
.c_str());
1754 i18n(ScreenSet
, ScreenSTYLESDIRErrorNoExist
,
1755 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1756 " error, %s does not exist\n"), stylesdir
.c_str());
1761 case 1090: // workspaces
1765 i18n(ScreenSet
, ScreenWORKSPACESError
,
1766 "BScreen:parseMenuFile: [workspaces] error, "
1767 "no menu label defined\n"));
1771 menu
->insert(label
, workspacemenu
);
1780 return ((menu
->getCount() == 0) ? True
: False
);
1784 void BScreen::shutdown(void) {
1785 XSelectInput(blackbox
->getXDisplay(), getRootWindow(), NoEventMask
);
1786 XSync(blackbox
->getXDisplay(), False
);
1788 while(! windowList
.empty())
1789 unmanageWindow(windowList
.front(), True
);
1795 void BScreen::showPosition(int x
, int y
) {
1796 if (! geom_visible
) {
1797 XMoveResizeWindow(blackbox
->getXDisplay(), geom_window
,
1798 (getWidth() - geom_w
) / 2,
1799 (getHeight() - geom_h
) / 2, geom_w
, geom_h
);
1800 XMapWindow(blackbox
->getXDisplay(), geom_window
);
1801 XRaiseWindow(blackbox
->getXDisplay(), geom_window
);
1803 geom_visible
= True
;
1808 sprintf(label
, i18n(ScreenSet
, ScreenPositionFormat
,
1809 "X: %4d x Y: %4d"), x
, y
);
1811 XClearWindow(blackbox
->getXDisplay(), geom_window
);
1813 BPen
pen(resource
.wstyle
.l_text_focus
, resource
.wstyle
.font
);
1814 if (i18n
.multibyte()) {
1815 XmbDrawString(blackbox
->getXDisplay(), geom_window
,
1816 resource
.wstyle
.fontset
, pen
.gc(),
1817 resource
.bevel_width
, resource
.bevel_width
-
1818 resource
.wstyle
.fontset_extents
->max_ink_extent
.y
,
1819 label
, strlen(label
));
1821 XDrawString(blackbox
->getXDisplay(), geom_window
,
1822 pen
.gc(), resource
.bevel_width
,
1823 resource
.wstyle
.font
->ascent
+ resource
.bevel_width
,
1824 label
, strlen(label
));
1829 void BScreen::showGeometry(unsigned int gx
, unsigned int gy
) {
1830 if (! geom_visible
) {
1831 XMoveResizeWindow(blackbox
->getXDisplay(), geom_window
,
1832 (getWidth() - geom_w
) / 2,
1833 (getHeight() - geom_h
) / 2, geom_w
, geom_h
);
1834 XMapWindow(blackbox
->getXDisplay(), geom_window
);
1835 XRaiseWindow(blackbox
->getXDisplay(), geom_window
);
1837 geom_visible
= True
;
1842 sprintf(label
, i18n(ScreenSet
, ScreenGeometryFormat
,
1843 "W: %4d x H: %4d"), gx
, gy
);
1845 XClearWindow(blackbox
->getXDisplay(), geom_window
);
1847 BPen
pen(resource
.wstyle
.l_text_focus
, resource
.wstyle
.font
);
1848 if (i18n
.multibyte()) {
1849 XmbDrawString(blackbox
->getXDisplay(), geom_window
,
1850 resource
.wstyle
.fontset
, pen
.gc(),
1851 resource
.bevel_width
, resource
.bevel_width
-
1852 resource
.wstyle
.fontset_extents
->max_ink_extent
.y
,
1853 label
, strlen(label
));
1855 XDrawString(blackbox
->getXDisplay(), geom_window
,
1856 pen
.gc(), resource
.bevel_width
,
1857 resource
.wstyle
.font
->ascent
+
1858 resource
.bevel_width
, label
, strlen(label
));
1863 void BScreen::hideGeometry(void) {
1865 XUnmapWindow(blackbox
->getXDisplay(), geom_window
);
1866 geom_visible
= False
;
1871 void BScreen::addStrut(Strut
*strut
) {
1872 strutList
.push_back(strut
);
1876 void BScreen::removeStrut(Strut
*strut
) {
1877 strutList
.remove(strut
);
1881 const Rect
& BScreen::availableArea(void) const {
1883 return getRect(); // return the full screen
1888 void BScreen::updateAvailableArea(void) {
1889 Rect old_area
= usableArea
;
1890 usableArea
= getRect(); // reset to full screen
1892 /* these values represent offsets from the screen edge
1893 * we look for the biggest offset on each edge and then apply them
1895 * do not be confused by the similarity to the names of Rect's members
1897 unsigned int current_left
= 0, current_right
= 0, current_top
= 0,
1900 StrutList::const_iterator it
= strutList
.begin(), end
= strutList
.end();
1902 for(; it
!= end
; ++it
) {
1904 if (strut
->left
> current_left
)
1905 current_left
= strut
->left
;
1906 if (strut
->top
> current_top
)
1907 current_top
= strut
->top
;
1908 if (strut
->right
> current_right
)
1909 current_right
= strut
->right
;
1910 if (strut
->bottom
> current_bottom
)
1911 current_bottom
= strut
->bottom
;
1914 usableArea
.setPos(current_left
, current_top
);
1915 usableArea
.setSize(usableArea
.width() - (current_left
+ current_right
),
1916 usableArea
.height() - (current_top
+ current_bottom
));
1918 if (old_area
!= usableArea
) {
1919 BlackboxWindowList::iterator it
= windowList
.begin(),
1920 end
= windowList
.end();
1921 for (; it
!= end
; ++it
)
1922 if ((*it
)->isMaximized()) (*it
)->remaximize();
1927 Workspace
* BScreen::getWorkspace(unsigned int index
) {
1928 assert(index
< workspacesList
.size());
1929 return workspacesList
[index
];
1933 void BScreen::buttonPressEvent(XButtonEvent
*xbutton
) {
1934 if (xbutton
->button
== 1) {
1935 if (! isRootColormapInstalled())
1936 image_control
->installRootColormap();
1938 if (workspacemenu
->isVisible())
1939 workspacemenu
->hide();
1941 if (rootmenu
->isVisible())
1943 } else if (xbutton
->button
== 2) {
1944 int mx
= xbutton
->x_root
- (workspacemenu
->getWidth() / 2);
1945 int my
= xbutton
->y_root
- (workspacemenu
->getTitleHeight() / 2);
1950 if (mx
+ workspacemenu
->getWidth() > getWidth())
1951 mx
= getWidth() - workspacemenu
->getWidth() - getBorderWidth();
1953 if (my
+ workspacemenu
->getHeight() > getHeight())
1954 my
= getHeight() - workspacemenu
->getHeight() - getBorderWidth();
1956 workspacemenu
->move(mx
, my
);
1958 if (! workspacemenu
->isVisible()) {
1959 workspacemenu
->removeParent();
1960 workspacemenu
->show();
1962 } else if (xbutton
->button
== 3) {
1963 int mx
= xbutton
->x_root
- (rootmenu
->getWidth() / 2);
1964 int my
= xbutton
->y_root
- (rootmenu
->getTitleHeight() / 2);
1969 if (mx
+ rootmenu
->getWidth() > getWidth())
1970 mx
= getWidth() - rootmenu
->getWidth() - getBorderWidth();
1972 if (my
+ rootmenu
->getHeight() > getHeight())
1973 my
= getHeight() - rootmenu
->getHeight() - getBorderWidth();
1975 rootmenu
->move(mx
, my
);
1977 if (! rootmenu
->isVisible()) {
1978 blackbox
->checkMenu();
1982 } else if (xbutton
->button
== 4) {
1983 if (getCurrentWorkspaceID() >= getWorkspaceCount() - 1)
1984 changeWorkspaceID(0);
1986 changeWorkspaceID(getCurrentWorkspaceID() + 1);
1988 } else if (xbutton
->button
== 5) {
1989 if (getCurrentWorkspaceID() == 0)
1990 changeWorkspaceID(getWorkspaceCount() - 1);
1992 changeWorkspaceID(getCurrentWorkspaceID() - 1);
1997 void BScreen::toggleFocusModel(FocusModel model
) {
1998 if (model
== SloppyFocus
) {
1999 saveSloppyFocus(True
);
2001 saveSloppyFocus(False
);
2002 saveAutoRaise(False
);
2003 saveClickRaise(False
);
2010 void BScreen::updateFocusModel()
2012 std::for_each(workspacesList
.begin(), workspacesList
.end(),
2013 std::mem_fun(&Workspace::updateFocusModel
));
2017 BTexture
BScreen::readDatabaseTexture(const string
&rname
,
2018 const string
&default_color
,
2019 Configuration
&style
) {
2023 if (style
.getValue(rname
, s
))
2024 texture
= BTexture(s
);
2026 texture
.setTexture(BTexture::Solid
| BTexture::Flat
);
2028 // associate this texture with this screen
2029 texture
.setDisplay(getBaseDisplay(), getScreenNumber());
2030 texture
.setImageControl(image_control
);
2032 if (texture
.texture() & BTexture::Solid
) {
2033 texture
.setColor(readDatabaseColor(rname
+ ".color",
2034 default_color
, style
));
2035 texture
.setColorTo(readDatabaseColor(rname
+ ".colorTo",
2036 default_color
, style
));
2037 } else if (texture
.texture() & BTexture::Gradient
) {
2038 texture
.setColor(readDatabaseColor(rname
+ ".color",
2039 default_color
, style
));
2040 texture
.setColorTo(readDatabaseColor(rname
+ ".colorTo",
2041 default_color
, style
));
2048 BColor
BScreen::readDatabaseColor(const string
&rname
,
2049 const string
&default_color
,
2050 Configuration
&style
) {
2053 if (style
.getValue(rname
, s
))
2054 color
= BColor(s
, getBaseDisplay(), getScreenNumber());
2056 color
= BColor(default_color
, getBaseDisplay(), getScreenNumber());
2061 XFontSet
BScreen::readDatabaseFontSet(const string
&rname
,
2062 Configuration
&style
) {
2063 char *defaultFont
= "fixed";
2065 bool load_default
= True
;
2067 XFontSet fontset
= 0;
2068 if (style
.getValue(rname
, s
) && (fontset
= createFontSet(s
)))
2069 load_default
= False
;
2072 fontset
= createFontSet(defaultFont
);
2076 i18n(ScreenSet
, ScreenDefaultFontLoadFail
,
2077 "BScreen::setCurrentStyle(): couldn't load default font.\n"));
2086 XFontStruct
*BScreen::readDatabaseFont(const string
&rname
,
2087 Configuration
&style
) {
2088 char *defaultFont
= "fixed";
2090 bool load_default
= False
;
2092 XFontStruct
*font
= 0;
2093 if (style
.getValue(rname
, s
)) {
2094 if ((font
= XLoadQueryFont(blackbox
->getXDisplay(), s
.c_str())) == NULL
) {
2096 i18n(ScreenSet
, ScreenFontLoadFail
,
2097 "BScreen::setCurrentStyle(): couldn't load font '%s'\n"),
2100 load_default
= True
;
2103 load_default
= True
;
2107 font
= XLoadQueryFont(blackbox
->getXDisplay(), defaultFont
);
2110 i18n(ScreenSet
, ScreenDefaultFontLoadFail
,
2111 "BScreen::setCurrentStyle(): couldn't load default font.\n"));
2120 #ifndef HAVE_STRCASESTR
2121 static const char * strcasestr(const char *str
, const char *ptn
) {
2122 const char *s2
, *p2
;
2123 for(; *str
; str
++) {
2124 for(s2
=str
,p2
=ptn
; ; s2
++,p2
++) {
2125 if (! *p2
) return str
;
2126 if (toupper(*s2
) != toupper(*p2
)) break;
2131 #endif // HAVE_STRCASESTR
2134 static const char *getFontElement(const char *pattern
, char *buf
,
2140 va_start(va
, bufsiz
);
2142 buf
[bufsiz
-2] = '*';
2143 while((v
= va_arg(va
, char *)) != NULL
) {
2144 p
= strcasestr(pattern
, v
);
2146 strncpy(buf
, p
+1, bufsiz
-2);
2147 p2
= strchr(buf
, '-');
2154 strncpy(buf
, "*", bufsiz
);
2159 static const char *getFontSize(const char *pattern
, int *size
) {
2161 const char *p2
=NULL
;
2164 for (p
=pattern
; 1; p
++) {
2166 if (p2
!=NULL
&& n
>1 && n
<72) {
2167 *size
= n
; return p2
+1;
2169 *size
= 16; return NULL
;
2171 } else if (*p
=='-') {
2172 if (n
>1 && n
<72 && p2
!=NULL
) {
2177 } else if (*p
>='0' && *p
<='9' && p2
!=NULL
) {
2187 XFontSet
BScreen::createFontSet(const string
&fontname
) {
2189 char **missing
, *def
= "-";
2190 int nmissing
, pixel_size
= 0, buf_size
= 0;
2191 char weight
[FONT_ELEMENT_SIZE
], slant
[FONT_ELEMENT_SIZE
];
2193 fs
= XCreateFontSet(blackbox
->getXDisplay(),
2194 fontname
.c_str(), &missing
, &nmissing
, &def
);
2195 if (fs
&& (! nmissing
))
2198 const char *nfontname
= fontname
.c_str();
2199 #ifdef HAVE_SETLOCALE
2201 if (nmissing
) XFreeStringList(missing
);
2203 setlocale(LC_CTYPE
, "C");
2204 fs
= XCreateFontSet(blackbox
->getXDisplay(), fontname
.c_str(),
2205 &missing
, &nmissing
, &def
);
2206 setlocale(LC_CTYPE
, "");
2208 #endif // HAVE_SETLOCALE
2211 XFontStruct
**fontstructs
;
2213 XFontsOfFontSet(fs
, &fontstructs
, &fontnames
);
2214 nfontname
= fontnames
[0];
2217 getFontElement(nfontname
, weight
, FONT_ELEMENT_SIZE
,
2218 "-medium-", "-bold-", "-demibold-", "-regular-", NULL
);
2219 getFontElement(nfontname
, slant
, FONT_ELEMENT_SIZE
,
2220 "-r-", "-i-", "-o-", "-ri-", "-ro-", NULL
);
2221 getFontSize(nfontname
, &pixel_size
);
2223 if (! strcmp(weight
, "*"))
2224 strncpy(weight
, "medium", FONT_ELEMENT_SIZE
);
2225 if (! strcmp(slant
, "*"))
2226 strncpy(slant
, "r", FONT_ELEMENT_SIZE
);
2229 else if (pixel_size
> 97)
2232 buf_size
= strlen(nfontname
) + (FONT_ELEMENT_SIZE
* 2) + 64;
2233 char *pattern2
= new char[buf_size
];
2236 "-*-*-%s-%s-*-*-%d-*-*-*-*-*-*-*,"
2237 "-*-*-*-*-*-*-%d-*-*-*-*-*-*-*,*",
2238 nfontname
, weight
, slant
, pixel_size
, pixel_size
);
2239 nfontname
= pattern2
;
2242 XFreeStringList(missing
);
2244 XFreeFontSet(blackbox
->getXDisplay(), fs
);
2246 fs
= XCreateFontSet(blackbox
->getXDisplay(), nfontname
, &missing
,