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 int remember_sub
= rootmenu
->getCurrentSubmenu();
687 rootmenu
->reconfigure();
688 rootmenu
->drawSubmenu(remember_sub
);
690 configmenu
->reconfigure();
692 toolbar
->reconfigure();
696 std::for_each(workspacesList
.begin(), workspacesList
.end(),
697 std::mem_fun(&Workspace::reconfigure
));
699 BlackboxWindowList::iterator iit
= iconList
.begin();
700 for (; iit
!= iconList
.end(); ++iit
) {
701 BlackboxWindow
*bw
= *iit
;
702 if (bw
->validateClient())
706 image_control
->timeout();
710 void BScreen::rereadMenu(void) {
714 rootmenu
->reconfigure();
718 void BScreen::LoadStyle(void) {
721 const char *sfile
= blackbox
->getStyleFilename();
723 style
.setFile(sfile
);
724 if (! style
.load()) {
725 style
.setFile(DEFAULTSTYLE
);
727 style
.create(); // hardcoded default values will be used.
733 // load fonts/fontsets
734 if (resource
.wstyle
.fontset
)
735 XFreeFontSet(blackbox
->getXDisplay(), resource
.wstyle
.fontset
);
736 if (resource
.tstyle
.fontset
)
737 XFreeFontSet(blackbox
->getXDisplay(), resource
.tstyle
.fontset
);
738 if (resource
.mstyle
.f_fontset
)
739 XFreeFontSet(blackbox
->getXDisplay(), resource
.mstyle
.f_fontset
);
740 if (resource
.mstyle
.t_fontset
)
741 XFreeFontSet(blackbox
->getXDisplay(), resource
.mstyle
.t_fontset
);
742 resource
.wstyle
.fontset
= 0;
743 resource
.tstyle
.fontset
= 0;
744 resource
.mstyle
.f_fontset
= 0;
745 resource
.mstyle
.t_fontset
= 0;
746 if (resource
.wstyle
.font
)
747 XFreeFont(blackbox
->getXDisplay(), resource
.wstyle
.font
);
748 if (resource
.tstyle
.font
)
749 XFreeFont(blackbox
->getXDisplay(), resource
.tstyle
.font
);
750 if (resource
.mstyle
.f_font
)
751 XFreeFont(blackbox
->getXDisplay(), resource
.mstyle
.f_font
);
752 if (resource
.mstyle
.t_font
)
753 XFreeFont(blackbox
->getXDisplay(), resource
.mstyle
.t_font
);
754 resource
.wstyle
.font
= 0;
755 resource
.tstyle
.font
= 0;
756 resource
.mstyle
.f_font
= 0;
757 resource
.mstyle
.t_font
= 0;
759 if (i18n
.multibyte()) {
760 resource
.wstyle
.fontset
= readDatabaseFontSet("window.font", style
);
761 resource
.tstyle
.fontset
= readDatabaseFontSet("toolbar.font", style
);
762 resource
.mstyle
.t_fontset
= readDatabaseFontSet("menu.title.font", style
);
763 resource
.mstyle
.f_fontset
= readDatabaseFontSet("menu.frame.font", style
);
765 resource
.mstyle
.t_fontset_extents
=
766 XExtentsOfFontSet(resource
.mstyle
.t_fontset
);
767 resource
.mstyle
.f_fontset_extents
=
768 XExtentsOfFontSet(resource
.mstyle
.f_fontset
);
769 resource
.tstyle
.fontset_extents
=
770 XExtentsOfFontSet(resource
.tstyle
.fontset
);
771 resource
.wstyle
.fontset_extents
=
772 XExtentsOfFontSet(resource
.wstyle
.fontset
);
774 resource
.wstyle
.font
= readDatabaseFont("window.font", style
);
775 resource
.tstyle
.font
= readDatabaseFont("toolbar.font", style
);
776 resource
.mstyle
.t_font
= readDatabaseFont("menu.title.font", style
);
777 resource
.mstyle
.f_font
= readDatabaseFont("menu.frame.font", style
);
780 // load window config
781 resource
.wstyle
.t_focus
=
782 readDatabaseTexture("window.title.focus", "white", style
);
783 resource
.wstyle
.t_unfocus
=
784 readDatabaseTexture("window.title.unfocus", "black", style
);
785 resource
.wstyle
.l_focus
=
786 readDatabaseTexture("window.label.focus", "white", style
);
787 resource
.wstyle
.l_unfocus
=
788 readDatabaseTexture("window.label.unfocus", "black", style
);
789 resource
.wstyle
.h_focus
=
790 readDatabaseTexture("window.handle.focus", "white", style
);
791 resource
.wstyle
.h_unfocus
=
792 readDatabaseTexture("window.handle.unfocus", "black", style
);
793 resource
.wstyle
.g_focus
=
794 readDatabaseTexture("window.grip.focus", "white", style
);
795 resource
.wstyle
.g_unfocus
=
796 readDatabaseTexture("window.grip.unfocus", "black", style
);
797 resource
.wstyle
.b_focus
=
798 readDatabaseTexture("window.button.focus", "white", style
);
799 resource
.wstyle
.b_unfocus
=
800 readDatabaseTexture("window.button.unfocus", "black", style
);
801 resource
.wstyle
.b_pressed
=
802 readDatabaseTexture("window.button.pressed", "black", style
);
803 resource
.wstyle
.f_focus
=
804 readDatabaseColor("window.frame.focusColor", "white", style
);
805 resource
.wstyle
.f_unfocus
=
806 readDatabaseColor("window.frame.unfocusColor", "black", style
);
807 resource
.wstyle
.l_text_focus
=
808 readDatabaseColor("window.label.focus.textColor", "black", style
);
809 resource
.wstyle
.l_text_unfocus
=
810 readDatabaseColor("window.label.unfocus.textColor", "white", style
);
811 resource
.wstyle
.b_pic_focus
=
812 readDatabaseColor("window.button.focus.picColor", "black", style
);
813 resource
.wstyle
.b_pic_unfocus
=
814 readDatabaseColor("window.button.unfocus.picColor", "white", style
);
816 resource
.wstyle
.justify
= LeftJustify
;
817 if (style
.getValue("window.justify", s
)) {
818 if (s
== "right" || s
== "Right")
819 resource
.wstyle
.justify
= RightJustify
;
820 else if (s
== "center" || s
== "Center")
821 resource
.wstyle
.justify
= CenterJustify
;
824 // load toolbar config
825 resource
.tstyle
.toolbar
=
826 readDatabaseTexture("toolbar", "black", style
);
827 resource
.tstyle
.label
=
828 readDatabaseTexture("toolbar.label", "black", style
);
829 resource
.tstyle
.window
=
830 readDatabaseTexture("toolbar.windowLabel", "black", style
);
831 resource
.tstyle
.button
=
832 readDatabaseTexture("toolbar.button", "white", style
);
833 resource
.tstyle
.pressed
=
834 readDatabaseTexture("toolbar.button.pressed", "black", style
);
835 resource
.tstyle
.clock
=
836 readDatabaseTexture("toolbar.clock", "black", style
);
837 resource
.tstyle
.l_text
=
838 readDatabaseColor("toolbar.label.textColor", "white", style
);
839 resource
.tstyle
.w_text
=
840 readDatabaseColor("toolbar.windowLabel.textColor", "white", style
);
841 resource
.tstyle
.c_text
=
842 readDatabaseColor("toolbar.clock.textColor", "white", style
);
843 resource
.tstyle
.b_pic
=
844 readDatabaseColor("toolbar.button.picColor", "black", style
);
846 resource
.tstyle
.justify
= LeftJustify
;
847 if (style
.getValue("toolbar.justify", s
)) {
848 if (s
== "right" || s
== "Right")
849 resource
.tstyle
.justify
= RightJustify
;
850 else if (s
== "center" || s
== "Center")
851 resource
.tstyle
.justify
= CenterJustify
;
855 resource
.mstyle
.title
=
856 readDatabaseTexture("menu.title", "white", style
);
857 resource
.mstyle
.frame
=
858 readDatabaseTexture("menu.frame", "black", style
);
859 resource
.mstyle
.hilite
=
860 readDatabaseTexture("menu.hilite", "white", style
);
861 resource
.mstyle
.t_text
=
862 readDatabaseColor("menu.title.textColor", "black", style
);
863 resource
.mstyle
.f_text
=
864 readDatabaseColor("menu.frame.textColor", "white", style
);
865 resource
.mstyle
.d_text
=
866 readDatabaseColor("menu.frame.disableColor", "black", style
);
867 resource
.mstyle
.h_text
=
868 readDatabaseColor("menu.hilite.textColor", "black", style
);
870 resource
.mstyle
.t_justify
= LeftJustify
;
871 if (style
.getValue("menu.title.justify", s
)) {
872 if (s
== "right" || s
== "Right")
873 resource
.mstyle
.t_justify
= RightJustify
;
874 else if (s
== "center" || s
== "Center")
875 resource
.mstyle
.t_justify
= CenterJustify
;
878 resource
.mstyle
.f_justify
= LeftJustify
;
879 if (style
.getValue("menu.frame.justify", s
)) {
880 if (s
== "right" || s
== "Right")
881 resource
.mstyle
.f_justify
= RightJustify
;
882 else if (s
== "center" || s
== "Center")
883 resource
.mstyle
.f_justify
= CenterJustify
;
886 resource
.mstyle
.bullet
= Basemenu::Triangle
;
887 if (style
.getValue("menu.bullet", s
)) {
888 if (s
== "empty" || s
== "Empty")
889 resource
.mstyle
.bullet
= Basemenu::Empty
;
890 else if (s
== "square" || s
== "Square")
891 resource
.mstyle
.bullet
= Basemenu::Square
;
892 else if (s
== "diamond" || s
== "Diamond")
893 resource
.mstyle
.bullet
= Basemenu::Diamond
;
896 resource
.mstyle
.bullet_pos
= Basemenu::Left
;
897 if (style
.getValue("menu.bullet.position", s
)) {
898 if (s
== "right" || s
== "Right")
899 resource
.mstyle
.bullet_pos
= Basemenu::Right
;
902 resource
.border_color
=
903 readDatabaseColor("borderColor", "black", style
);
905 // load bevel, border and handle widths
906 if (! style
.getValue("handleWidth", resource
.handle_width
) ||
907 resource
.handle_width
> (getWidth() / 2) || resource
.handle_width
== 0)
908 resource
.handle_width
= 6;
910 if (! style
.getValue("borderWidth", resource
.border_width
))
911 resource
.border_width
= 1;
913 if (! style
.getValue("bevelWidth", resource
.bevel_width
) ||
914 resource
.bevel_width
> (getWidth() / 2) || resource
.bevel_width
== 0)
915 resource
.bevel_width
= 3;
917 if (! style
.getValue("frameWidth", resource
.frame_width
) ||
918 resource
.frame_width
> (getWidth() / 2))
919 resource
.frame_width
= resource
.bevel_width
;
921 if (style
.getValue("rootCommand", s
))
922 bexec(s
, displayString());
926 void BScreen::addIcon(BlackboxWindow
*w
) {
929 w
->setWorkspace(BSENTINEL
);
930 w
->setWindowNumber(iconList
.size());
932 iconList
.push_back(w
);
934 const char* title
= w
->getIconTitle();
935 iconmenu
->insert(title
);
940 void BScreen::removeIcon(BlackboxWindow
*w
) {
945 iconmenu
->remove(w
->getWindowNumber());
948 BlackboxWindowList::iterator it
= iconList
.begin(),
949 end
= iconList
.end();
950 for (int i
= 0; it
!= end
; ++it
)
951 (*it
)->setWindowNumber(i
++);
955 BlackboxWindow
*BScreen::getIcon(unsigned int index
) {
956 if (index
< iconList
.size()) {
957 BlackboxWindowList::iterator it
= iconList
.begin();
958 for (; index
> 0; --index
, ++it
) ; /* increment to index */
962 return (BlackboxWindow
*) 0;
966 unsigned int BScreen::addWorkspace(void) {
967 Workspace
*wkspc
= new Workspace(this, workspacesList
.size());
968 workspacesList
.push_back(wkspc
);
969 saveWorkspaces(getWorkspaceCount());
970 saveWorkspaceNames();
972 workspacemenu
->insert(wkspc
->getName(), wkspc
->getMenu(),
974 workspacemenu
->update();
976 toolbar
->reconfigure();
978 updateNetizenWorkspaceCount();
980 return workspacesList
.size();
984 unsigned int BScreen::removeLastWorkspace(void) {
985 if (workspacesList
.size() == 1)
988 Workspace
*wkspc
= workspacesList
.back();
990 if (current_workspace
->getID() == wkspc
->getID())
991 changeWorkspaceID(current_workspace
->getID() - 1);
995 workspacemenu
->remove(wkspc
->getID() + 2);
996 workspacemenu
->update();
998 workspacesList
.pop_back();
1001 saveWorkspaces(getWorkspaceCount());
1002 saveWorkspaceNames();
1004 toolbar
->reconfigure();
1006 updateNetizenWorkspaceCount();
1008 return workspacesList
.size();
1012 void BScreen::changeWorkspaceID(unsigned int id
) {
1013 if (! current_workspace
) return;
1015 if (id
!= current_workspace
->getID()) {
1016 current_workspace
->hideAll();
1018 workspacemenu
->setItemSelected(current_workspace
->getID() + 2, False
);
1020 if (blackbox
->getFocusedWindow() &&
1021 blackbox
->getFocusedWindow()->getScreen() == this &&
1022 (! blackbox
->getFocusedWindow()->isStuck())) {
1023 current_workspace
->setLastFocusedWindow(blackbox
->getFocusedWindow());
1024 blackbox
->setFocusedWindow((BlackboxWindow
*) 0);
1027 current_workspace
= getWorkspace(id
);
1029 xatom
->setValue(getRootWindow(), XAtom::net_current_desktop
,
1030 XAtom::cardinal
, id
);
1033 workspacemenu
->setItemSelected(current_workspace
->getID() + 2, True
);
1034 toolbar
->redrawWorkspaceLabel(True
);
1036 current_workspace
->showAll();
1038 if (resource
.focus_last
&& current_workspace
->getLastFocusedWindow()) {
1039 XSync(blackbox
->getXDisplay(), False
);
1040 current_workspace
->getLastFocusedWindow()->setInputFocus();
1044 updateNetizenCurrentWorkspace();
1048 void BScreen::manageWindow(Window w
) {
1049 new BlackboxWindow(blackbox
, w
, this);
1051 BlackboxWindow
*win
= blackbox
->searchWindow(w
);
1055 windowList
.push_back(win
);
1057 XMapRequestEvent mre
;
1059 win
->restoreAttributes();
1060 win
->mapRequestEvent(&mre
);
1064 void BScreen::unmanageWindow(BlackboxWindow
*w
, bool remap
) {
1067 if (w
->getWorkspaceNumber() != BSENTINEL
&&
1068 w
->getWindowNumber() != BSENTINEL
)
1069 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
1070 else if (w
->isIconic())
1073 windowList
.remove(w
);
1075 if (blackbox
->getFocusedWindow() == w
)
1076 blackbox
->setFocusedWindow((BlackboxWindow
*) 0);
1078 removeNetizen(w
->getClientWindow());
1081 some managed windows can also be window group controllers. when
1082 unmanaging such windows, we should also delete the window group.
1084 BWindowGroup
*group
= blackbox
->searchGroup(w
->getClientWindow());
1091 void BScreen::addNetizen(Netizen
*n
) {
1092 netizenList
.push_back(n
);
1094 n
->sendWorkspaceCount();
1095 n
->sendCurrentWorkspace();
1097 WorkspaceList::iterator it
= workspacesList
.begin();
1098 const WorkspaceList::iterator end
= workspacesList
.end();
1099 for (; it
!= end
; ++it
)
1100 (*it
)->sendWindowList(*n
);
1102 Window f
= ((blackbox
->getFocusedWindow()) ?
1103 blackbox
->getFocusedWindow()->getClientWindow() : None
);
1104 n
->sendWindowFocus(f
);
1108 void BScreen::removeNetizen(Window w
) {
1109 NetizenList::iterator it
= netizenList
.begin();
1110 for (; it
!= netizenList
.end(); ++it
) {
1111 if ((*it
)->getWindowID() == w
) {
1113 netizenList
.erase(it
);
1120 void BScreen::updateNetizenCurrentWorkspace(void) {
1121 std::for_each(netizenList
.begin(), netizenList
.end(),
1122 std::mem_fun(&Netizen::sendCurrentWorkspace
));
1126 void BScreen::updateNetizenWorkspaceCount(void) {
1127 xatom
->setValue(getRootWindow(), XAtom::net_number_of_desktops
,
1128 XAtom::cardinal
, workspacesList
.size());
1130 std::for_each(netizenList
.begin(), netizenList
.end(),
1131 std::mem_fun(&Netizen::sendWorkspaceCount
));
1135 void BScreen::updateNetizenWindowFocus(void) {
1136 Window f
= ((blackbox
->getFocusedWindow()) ?
1137 blackbox
->getFocusedWindow()->getClientWindow() : None
);
1138 NetizenList::iterator it
= netizenList
.begin();
1139 for (; it
!= netizenList
.end(); ++it
)
1140 (*it
)->sendWindowFocus(f
);
1144 void BScreen::updateNetizenWindowAdd(Window w
, unsigned long p
) {
1145 NetizenList::iterator it
= netizenList
.begin();
1146 for (; it
!= netizenList
.end(); ++it
) {
1147 (*it
)->sendWindowAdd(w
, p
);
1152 void BScreen::updateNetizenWindowDel(Window w
) {
1153 NetizenList::iterator it
= netizenList
.begin();
1154 for (; it
!= netizenList
.end(); ++it
)
1155 (*it
)->sendWindowDel(w
);
1159 void BScreen::updateNetizenWindowRaise(Window w
) {
1160 NetizenList::iterator it
= netizenList
.begin();
1161 for (; it
!= netizenList
.end(); ++it
)
1162 (*it
)->sendWindowRaise(w
);
1166 void BScreen::updateNetizenWindowLower(Window w
) {
1167 NetizenList::iterator it
= netizenList
.begin();
1168 for (; it
!= netizenList
.end(); ++it
)
1169 (*it
)->sendWindowLower(w
);
1173 void BScreen::updateNetizenConfigNotify(XEvent
*e
) {
1174 NetizenList::iterator it
= netizenList
.begin();
1175 for (; it
!= netizenList
.end(); ++it
)
1176 (*it
)->sendConfigNotify(e
);
1180 void BScreen::raiseWindows(Window
*workspace_stack
, unsigned int num
) {
1182 Window
*session_stack
= new
1183 Window
[(num
+ workspacesList
.size() + rootmenuList
.size() + 13)];
1184 unsigned int i
= 0, k
= num
;
1186 XRaiseWindow(blackbox
->getXDisplay(), iconmenu
->getWindowID());
1187 *(session_stack
+ i
++) = iconmenu
->getWindowID();
1189 WorkspaceList::iterator wit
= workspacesList
.begin();
1190 const WorkspaceList::iterator w_end
= workspacesList
.end();
1191 for (; wit
!= w_end
; ++wit
)
1192 *(session_stack
+ i
++) = (*wit
)->getMenu()->getWindowID();
1194 *(session_stack
+ i
++) = workspacemenu
->getWindowID();
1196 *(session_stack
+ i
++) = configmenu
->getFocusmenu()->getWindowID();
1197 *(session_stack
+ i
++) = configmenu
->getPlacementmenu()->getWindowID();
1198 *(session_stack
+ i
++) = configmenu
->getWindowID();
1200 *(session_stack
+ i
++) = slit
->getMenu()->getDirectionmenu()->getWindowID();
1201 *(session_stack
+ i
++) = slit
->getMenu()->getPlacementmenu()->getWindowID();
1202 *(session_stack
+ i
++) = slit
->getMenu()->getWindowID();
1204 *(session_stack
+ i
++) =
1205 toolbar
->getMenu()->getPlacementmenu()->getWindowID();
1206 *(session_stack
+ i
++) = toolbar
->getMenu()->getWindowID();
1208 RootmenuList::iterator rit
= rootmenuList
.begin();
1209 for (; rit
!= rootmenuList
.end(); ++rit
)
1210 *(session_stack
+ i
++) = (*rit
)->getWindowID();
1211 *(session_stack
+ i
++) = rootmenu
->getWindowID();
1213 if (toolbar
->isOnTop())
1214 *(session_stack
+ i
++) = toolbar
->getWindowID();
1216 if (slit
->isOnTop())
1217 *(session_stack
+ i
++) = slit
->getWindowID();
1220 *(session_stack
+ i
++) = *(workspace_stack
+ k
);
1222 XRestackWindows(blackbox
->getXDisplay(), session_stack
, i
);
1224 delete [] session_stack
;
1228 void BScreen::addWorkspaceName(const string
& name
) {
1229 workspaceNames
.push_back(name
);
1234 * I would love to kill this function and the accompanying workspaceNames
1235 * list. However, we have a chicken and egg situation. The names are read
1236 * in during load_rc() which happens before the workspaces are created.
1237 * The current solution is to read the names into a list, then use the list
1238 * later for constructing the workspaces. It is only used during initial
1241 const string
BScreen::getNameOfWorkspace(unsigned int id
) {
1242 if (id
< workspaceNames
.size())
1243 return workspaceNames
[id
];
1248 void BScreen::reassociateWindow(BlackboxWindow
*w
, unsigned int wkspc_id
,
1249 bool ignore_sticky
) {
1252 if (wkspc_id
== BSENTINEL
)
1253 wkspc_id
= current_workspace
->getID();
1255 if (w
->getWorkspaceNumber() == wkspc_id
)
1258 if (w
->isIconic()) {
1260 getWorkspace(wkspc_id
)->addWindow(w
);
1261 } else if (ignore_sticky
|| ! w
->isStuck()) {
1262 getWorkspace(w
->getWorkspaceNumber())->removeWindow(w
);
1263 getWorkspace(wkspc_id
)->addWindow(w
);
1268 void BScreen::propagateWindowName(const BlackboxWindow
*bw
) {
1269 if (bw
->isIconic()) {
1270 iconmenu
->changeItemLabel(bw
->getWindowNumber(), bw
->getIconTitle());
1274 Clientmenu
*clientmenu
= getWorkspace(bw
->getWorkspaceNumber())->getMenu();
1275 clientmenu
->changeItemLabel(bw
->getWindowNumber(), bw
->getTitle());
1276 clientmenu
->update();
1278 if (blackbox
->getFocusedWindow() == bw
)
1279 toolbar
->redrawWindowLabel(True
);
1284 void BScreen::nextFocus(void) {
1285 BlackboxWindow
*focused
= blackbox
->getFocusedWindow(),
1289 // if window is not on this screen, ignore it
1290 if (focused
->getScreen()->getScreenNumber() != getScreenNumber())
1291 focused
= (BlackboxWindow
*) 0;
1294 if (focused
&& current_workspace
->getCount() > 1) {
1295 // next is the next window to recieve focus, current is a place holder
1296 BlackboxWindow
*current
;
1299 next
= current_workspace
->getNextWindowInList(current
);
1300 } while(! next
->setInputFocus() && next
!= focused
);
1302 if (next
!= focused
)
1303 current_workspace
->raiseWindow(next
);
1304 } else if (current_workspace
->getCount() >= 1) {
1305 next
= current_workspace
->getTopWindowOnStack();
1307 current_workspace
->raiseWindow(next
);
1308 next
->setInputFocus();
1313 void BScreen::prevFocus(void) {
1314 BlackboxWindow
*focused
= blackbox
->getFocusedWindow(),
1318 // if window is not on this screen, ignore it
1319 if (focused
->getScreen()->getScreenNumber() != getScreenNumber())
1320 focused
= (BlackboxWindow
*) 0;
1323 if (focused
&& current_workspace
->getCount() > 1) {
1324 // next is the next window to recieve focus, current is a place holder
1325 BlackboxWindow
*current
;
1328 next
= current_workspace
->getPrevWindowInList(current
);
1329 } while(! next
->setInputFocus() && next
!= focused
);
1331 if (next
!= focused
)
1332 current_workspace
->raiseWindow(next
);
1333 } else if (current_workspace
->getCount() >= 1) {
1334 next
= current_workspace
->getTopWindowOnStack();
1336 current_workspace
->raiseWindow(next
);
1337 next
->setInputFocus();
1342 void BScreen::raiseFocus(void) {
1343 BlackboxWindow
*focused
= blackbox
->getFocusedWindow();
1347 // if on this Screen, raise it
1348 if (focused
->getScreen()->getScreenNumber() == getScreenNumber()) {
1349 Workspace
*workspace
= getWorkspace(focused
->getWorkspaceNumber());
1350 workspace
->raiseWindow(focused
);
1355 void BScreen::InitMenu(void) {
1357 rootmenuList
.clear();
1359 while (rootmenu
->getCount())
1360 rootmenu
->remove(0);
1362 rootmenu
= new Rootmenu(this);
1364 bool defaultMenu
= True
;
1366 FILE *menu_file
= (FILE *) 0;
1367 const char *menu_filename
= blackbox
->getMenuFilename();
1370 if (! (menu_file
= fopen(menu_filename
, "r")))
1371 perror(menu_filename
);
1372 if (! menu_file
) { // opening the menu file failed, try the default menu
1373 menu_filename
= DEFAULTMENU
;
1374 if (! (menu_file
= fopen(menu_filename
, "r")))
1375 perror(menu_filename
);
1379 if (feof(menu_file
)) {
1380 fprintf(stderr
, i18n(ScreenSet
, ScreenEmptyMenuFile
,
1381 "%s: Empty menu file"),
1384 char line
[1024], label
[1024];
1385 memset(line
, 0, 1024);
1386 memset(label
, 0, 1024);
1388 while (fgets(line
, 1024, menu_file
) && ! feof(menu_file
)) {
1389 if (line
[0] != '#') {
1390 int i
, key
= 0, index
= -1, len
= strlen(line
);
1392 for (i
= 0; i
< len
; i
++) {
1393 if (line
[i
] == '[') index
= 0;
1394 else if (line
[i
] == ']') break;
1395 else if (line
[i
] != ' ')
1397 key
+= tolower(line
[i
]);
1400 if (key
== 517) { // [begin]
1402 for (i
= index
; i
< len
; i
++) {
1403 if (line
[i
] == '(') index
= 0;
1404 else if (line
[i
] == ')') break;
1405 else if (index
++ >= 0) {
1406 if (line
[i
] == '\\' && i
< len
- 1) i
++;
1407 label
[index
- 1] = line
[i
];
1411 if (index
== -1) index
= 0;
1412 label
[index
] = '\0';
1414 rootmenu
->setLabel(label
);
1415 defaultMenu
= parseMenuFile(menu_file
, rootmenu
);
1417 blackbox
->addMenuTimestamp(menu_filename
);
1427 rootmenu
->setInternalMenu();
1428 rootmenu
->insert(i18n(ScreenSet
, Screenxterm
, "xterm"),
1430 i18n(ScreenSet
, Screenxterm
, "xterm"));
1431 rootmenu
->insert(i18n(ScreenSet
, ScreenRestart
, "Restart"),
1433 rootmenu
->insert(i18n(ScreenSet
, ScreenExit
, "Exit"),
1435 rootmenu
->setLabel(i18n(BasemenuSet
, BasemenuBlackboxMenu
,
1441 bool BScreen::parseMenuFile(FILE *file
, Rootmenu
*menu
) {
1442 char line
[1024], label
[1024], command
[1024];
1444 while (! feof(file
)) {
1445 memset(line
, 0, 1024);
1446 memset(label
, 0, 1024);
1447 memset(command
, 0, 1024);
1449 if (fgets(line
, 1024, file
)) {
1450 if (line
[0] != '#') {
1451 int i
, key
= 0, parse
= 0, index
= -1, line_length
= strlen(line
);
1453 // determine the keyword
1454 for (i
= 0; i
< line_length
; i
++) {
1455 if (line
[i
] == '[') parse
= 1;
1456 else if (line
[i
] == ']') break;
1457 else if (line
[i
] != ' ')
1459 key
+= tolower(line
[i
]);
1462 // get the label enclosed in ()'s
1465 for (i
= 0; i
< line_length
; i
++) {
1466 if (line
[i
] == '(') {
1469 } else if (line
[i
] == ')') break;
1470 else if (index
++ >= 0) {
1471 if (line
[i
] == '\\' && i
< line_length
- 1) i
++;
1472 label
[index
- 1] = line
[i
];
1477 label
[index
] = '\0';
1482 // get the command 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 command
[index
- 1] = line
[i
];
1497 command
[index
] = '\0';
1504 return ((menu
->getCount() == 0) ? True
: False
);
1511 menu
->insert(label
);
1516 if ((! *label
) && (! *command
)) {
1517 fprintf(stderr
, i18n(ScreenSet
, ScreenEXECError
,
1518 "BScreen::parseMenuFile: [exec] error, "
1519 "no menu label and/or command defined\n"));
1523 menu
->insert(label
, BScreen::Execute
, command
);
1529 fprintf(stderr
, i18n(ScreenSet
, ScreenEXITError
,
1530 "BScreen::parseMenuFile: [exit] error, "
1531 "no menu label defined\n"));
1535 menu
->insert(label
, BScreen::Exit
);
1541 if ((! *label
) || (! *command
)) {
1543 i18n(ScreenSet
, ScreenSTYLEError
,
1544 "BScreen::parseMenuFile: [style] error, "
1545 "no menu label and/or filename defined\n"));
1549 string style
= expandTilde(command
);
1551 menu
->insert(label
, BScreen::SetStyle
, style
.c_str());
1558 fprintf(stderr
, i18n(ScreenSet
, ScreenCONFIGError
,
1559 "BScreen::parseMenufile: [config] error, "
1560 "no label defined"));
1564 menu
->insert(label
, configmenu
);
1568 case 740: // include
1571 fprintf(stderr
, i18n(ScreenSet
, ScreenINCLUDEError
,
1572 "BScreen::parseMenuFile: [include] error, "
1573 "no filename defined\n"));
1577 string newfile
= expandTilde(label
);
1578 FILE *submenufile
= fopen(newfile
.c_str(), "r");
1582 if (fstat(fileno(submenufile
), &buf
) ||
1583 (! S_ISREG(buf
.st_mode
))) {
1585 i18n(ScreenSet
, ScreenINCLUDEErrorReg
,
1586 "BScreen::parseMenuFile: [include] error: "
1587 "'%s' is not a regular file\n"), newfile
.c_str());
1591 if (! feof(submenufile
)) {
1592 if (! parseMenuFile(submenufile
, menu
))
1593 blackbox
->addMenuTimestamp(newfile
);
1595 fclose(submenufile
);
1598 perror(newfile
.c_str());
1604 case 767: // submenu
1607 fprintf(stderr
, i18n(ScreenSet
, ScreenSUBMENUError
,
1608 "BScreen::parseMenuFile: [submenu] error, "
1609 "no menu label defined\n"));
1613 Rootmenu
*submenu
= new Rootmenu(this);
1616 submenu
->setLabel(command
);
1618 submenu
->setLabel(label
);
1620 parseMenuFile(file
, submenu
);
1622 menu
->insert(label
, submenu
);
1623 rootmenuList
.push_back(submenu
);
1628 case 773: // restart
1631 fprintf(stderr
, i18n(ScreenSet
, ScreenRESTARTError
,
1632 "BScreen::parseMenuFile: [restart] error, "
1633 "no menu label defined\n"));
1638 menu
->insert(label
, BScreen::RestartOther
, command
);
1640 menu
->insert(label
, BScreen::Restart
);
1645 case 845: // reconfig
1649 i18n(ScreenSet
, ScreenRECONFIGError
,
1650 "BScreen::parseMenuFile: [reconfig] error, "
1651 "no menu label defined\n"));
1655 menu
->insert(label
, BScreen::Reconfigure
);
1660 case 995: // stylesdir
1661 case 1113: // stylesmenu
1663 bool newmenu
= ((key
== 1113) ? True
: False
);
1665 if ((! *label
) || ((! *command
) && newmenu
)) {
1667 i18n(ScreenSet
, ScreenSTYLESDIRError
,
1668 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1669 " error, no directory defined\n"));
1673 char *directory
= ((newmenu
) ? command
: label
);
1675 string stylesdir
= expandTilde(directory
);
1677 struct stat statbuf
;
1679 if (! stat(stylesdir
.c_str(), &statbuf
)) {
1680 if (S_ISDIR(statbuf
.st_mode
)) {
1681 Rootmenu
*stylesmenu
;
1684 stylesmenu
= new Rootmenu(this);
1688 DIR *d
= opendir(stylesdir
.c_str());
1690 std::vector
<string
> ls
;
1692 while((p
= readdir(d
)))
1693 ls
.push_back(p
->d_name
);
1697 std::sort(ls
.begin(), ls
.end());
1699 std::vector
<string
>::iterator it
= ls
.begin(),
1701 for (; it
!= end
; ++it
) {
1702 const string
& fname
= *it
;
1704 if (fname
[fname
.size()-1] == '~')
1707 string style
= stylesdir
;
1711 if ((! stat(style
.c_str(), &statbuf
)) &&
1712 S_ISREG(statbuf
.st_mode
))
1713 stylesmenu
->insert(fname
, BScreen::SetStyle
, style
);
1716 stylesmenu
->update();
1719 stylesmenu
->setLabel(label
);
1720 menu
->insert(label
, stylesmenu
);
1721 rootmenuList
.push_back(stylesmenu
);
1724 blackbox
->addMenuTimestamp(stylesdir
);
1727 i18n(ScreenSet
, ScreenSTYLESDIRErrorNotDir
,
1728 "BScreen::parseMenuFile:"
1729 " [stylesdir/stylesmenu] error, %s is not a"
1730 " directory\n"), stylesdir
.c_str());
1734 i18n(ScreenSet
, ScreenSTYLESDIRErrorNoExist
,
1735 "BScreen::parseMenuFile: [stylesdir/stylesmenu]"
1736 " error, %s does not exist\n"), stylesdir
.c_str());
1741 case 1090: // workspaces
1745 i18n(ScreenSet
, ScreenWORKSPACESError
,
1746 "BScreen:parseMenuFile: [workspaces] error, "
1747 "no menu label defined\n"));
1751 menu
->insert(label
, workspacemenu
);
1760 return ((menu
->getCount() == 0) ? True
: False
);
1764 void BScreen::shutdown(void) {
1765 XSelectInput(blackbox
->getXDisplay(), getRootWindow(), NoEventMask
);
1766 XSync(blackbox
->getXDisplay(), False
);
1768 while(! windowList
.empty())
1769 unmanageWindow(windowList
.front(), True
);
1775 void BScreen::showPosition(int x
, int y
) {
1776 if (! geom_visible
) {
1777 XMoveResizeWindow(blackbox
->getXDisplay(), geom_window
,
1778 (getWidth() - geom_w
) / 2,
1779 (getHeight() - geom_h
) / 2, geom_w
, geom_h
);
1780 XMapWindow(blackbox
->getXDisplay(), geom_window
);
1781 XRaiseWindow(blackbox
->getXDisplay(), geom_window
);
1783 geom_visible
= True
;
1788 sprintf(label
, i18n(ScreenSet
, ScreenPositionFormat
,
1789 "X: %4d x Y: %4d"), x
, y
);
1791 XClearWindow(blackbox
->getXDisplay(), geom_window
);
1793 BPen
pen(resource
.wstyle
.l_text_focus
, resource
.wstyle
.font
);
1794 if (i18n
.multibyte()) {
1795 XmbDrawString(blackbox
->getXDisplay(), geom_window
,
1796 resource
.wstyle
.fontset
, pen
.gc(),
1797 resource
.bevel_width
, resource
.bevel_width
-
1798 resource
.wstyle
.fontset_extents
->max_ink_extent
.y
,
1799 label
, strlen(label
));
1801 XDrawString(blackbox
->getXDisplay(), geom_window
,
1802 pen
.gc(), resource
.bevel_width
,
1803 resource
.wstyle
.font
->ascent
+ resource
.bevel_width
,
1804 label
, strlen(label
));
1809 void BScreen::showGeometry(unsigned int gx
, unsigned int gy
) {
1810 if (! geom_visible
) {
1811 XMoveResizeWindow(blackbox
->getXDisplay(), geom_window
,
1812 (getWidth() - geom_w
) / 2,
1813 (getHeight() - geom_h
) / 2, geom_w
, geom_h
);
1814 XMapWindow(blackbox
->getXDisplay(), geom_window
);
1815 XRaiseWindow(blackbox
->getXDisplay(), geom_window
);
1817 geom_visible
= True
;
1822 sprintf(label
, i18n(ScreenSet
, ScreenGeometryFormat
,
1823 "W: %4d x H: %4d"), gx
, gy
);
1825 XClearWindow(blackbox
->getXDisplay(), geom_window
);
1827 BPen
pen(resource
.wstyle
.l_text_focus
, resource
.wstyle
.font
);
1828 if (i18n
.multibyte()) {
1829 XmbDrawString(blackbox
->getXDisplay(), geom_window
,
1830 resource
.wstyle
.fontset
, pen
.gc(),
1831 resource
.bevel_width
, resource
.bevel_width
-
1832 resource
.wstyle
.fontset_extents
->max_ink_extent
.y
,
1833 label
, strlen(label
));
1835 XDrawString(blackbox
->getXDisplay(), geom_window
,
1836 pen
.gc(), resource
.bevel_width
,
1837 resource
.wstyle
.font
->ascent
+
1838 resource
.bevel_width
, label
, strlen(label
));
1843 void BScreen::hideGeometry(void) {
1845 XUnmapWindow(blackbox
->getXDisplay(), geom_window
);
1846 geom_visible
= False
;
1851 void BScreen::addStrut(Strut
*strut
) {
1852 strutList
.push_back(strut
);
1856 void BScreen::removeStrut(Strut
*strut
) {
1857 strutList
.remove(strut
);
1861 const Rect
& BScreen::availableArea(void) const {
1863 return getRect(); // return the full screen
1868 void BScreen::updateAvailableArea(void) {
1869 Rect old_area
= usableArea
;
1870 usableArea
= getRect(); // reset to full screen
1872 /* these values represent offsets from the screen edge
1873 * we look for the biggest offset on each edge and then apply them
1875 * do not be confused by the similarity to the names of Rect's members
1877 unsigned int current_left
= 0, current_right
= 0, current_top
= 0,
1880 StrutList::const_iterator it
= strutList
.begin(), end
= strutList
.end();
1882 for(; it
!= end
; ++it
) {
1884 if (strut
->left
> current_left
)
1885 current_left
= strut
->left
;
1886 if (strut
->top
> current_top
)
1887 current_top
= strut
->top
;
1888 if (strut
->right
> current_right
)
1889 current_right
= strut
->right
;
1890 if (strut
->bottom
> current_bottom
)
1891 current_bottom
= strut
->bottom
;
1894 usableArea
.setPos(current_left
, current_top
);
1895 usableArea
.setSize(usableArea
.width() - (current_left
+ current_right
),
1896 usableArea
.height() - (current_top
+ current_bottom
));
1898 if (old_area
!= usableArea
) {
1899 BlackboxWindowList::iterator it
= windowList
.begin(),
1900 end
= windowList
.end();
1901 for (; it
!= end
; ++it
)
1902 if ((*it
)->isMaximized()) (*it
)->remaximize();
1907 Workspace
* BScreen::getWorkspace(unsigned int index
) {
1908 assert(index
< workspacesList
.size());
1909 return workspacesList
[index
];
1913 void BScreen::buttonPressEvent(XButtonEvent
*xbutton
) {
1914 if (xbutton
->button
== 1) {
1915 if (! isRootColormapInstalled())
1916 image_control
->installRootColormap();
1918 if (workspacemenu
->isVisible())
1919 workspacemenu
->hide();
1921 if (rootmenu
->isVisible())
1923 } else if (xbutton
->button
== 2) {
1924 int mx
= xbutton
->x_root
- (workspacemenu
->getWidth() / 2);
1925 int my
= xbutton
->y_root
- (workspacemenu
->getTitleHeight() / 2);
1930 if (mx
+ workspacemenu
->getWidth() > getWidth())
1931 mx
= getWidth() - workspacemenu
->getWidth() - getBorderWidth();
1933 if (my
+ workspacemenu
->getHeight() > getHeight())
1934 my
= getHeight() - workspacemenu
->getHeight() - getBorderWidth();
1936 workspacemenu
->move(mx
, my
);
1938 if (! workspacemenu
->isVisible()) {
1939 workspacemenu
->removeParent();
1940 workspacemenu
->show();
1942 } else if (xbutton
->button
== 3) {
1943 int mx
= xbutton
->x_root
- (rootmenu
->getWidth() / 2);
1944 int my
= xbutton
->y_root
- (rootmenu
->getTitleHeight() / 2);
1949 if (mx
+ rootmenu
->getWidth() > getWidth())
1950 mx
= getWidth() - rootmenu
->getWidth() - getBorderWidth();
1952 if (my
+ rootmenu
->getHeight() > getHeight())
1953 my
= getHeight() - rootmenu
->getHeight() - getBorderWidth();
1955 rootmenu
->move(mx
, my
);
1957 if (! rootmenu
->isVisible()) {
1958 blackbox
->checkMenu();
1962 } else if (xbutton
->button
== 4) {
1963 if (getCurrentWorkspaceID() >= getWorkspaceCount() - 1)
1964 changeWorkspaceID(0);
1966 changeWorkspaceID(getCurrentWorkspaceID() + 1);
1968 } else if (xbutton
->button
== 5) {
1969 if (getCurrentWorkspaceID() == 0)
1970 changeWorkspaceID(getWorkspaceCount() - 1);
1972 changeWorkspaceID(getCurrentWorkspaceID() - 1);
1977 void BScreen::toggleFocusModel(FocusModel model
) {
1978 if (model
== SloppyFocus
) {
1979 saveSloppyFocus(True
);
1981 saveSloppyFocus(False
);
1982 saveAutoRaise(False
);
1983 saveClickRaise(False
);
1990 void BScreen::updateFocusModel()
1992 std::for_each(workspacesList
.begin(), workspacesList
.end(),
1993 std::mem_fun(&Workspace::updateFocusModel
));
1997 BTexture
BScreen::readDatabaseTexture(const string
&rname
,
1998 const string
&default_color
,
1999 Configuration
&style
) {
2003 if (style
.getValue(rname
, s
))
2004 texture
= BTexture(s
);
2006 texture
.setTexture(BTexture::Solid
| BTexture::Flat
);
2008 // associate this texture with this screen
2009 texture
.setDisplay(getBaseDisplay(), getScreenNumber());
2010 texture
.setImageControl(image_control
);
2012 if (texture
.texture() & BTexture::Solid
) {
2013 texture
.setColor(readDatabaseColor(rname
+ ".color",
2014 default_color
, style
));
2015 texture
.setColorTo(readDatabaseColor(rname
+ ".colorTo",
2016 default_color
, style
));
2017 } else if (texture
.texture() & BTexture::Gradient
) {
2018 texture
.setColor(readDatabaseColor(rname
+ ".color",
2019 default_color
, style
));
2020 texture
.setColorTo(readDatabaseColor(rname
+ ".colorTo",
2021 default_color
, style
));
2028 BColor
BScreen::readDatabaseColor(const string
&rname
,
2029 const string
&default_color
,
2030 Configuration
&style
) {
2033 if (style
.getValue(rname
, s
))
2034 color
= BColor(s
, getBaseDisplay(), getScreenNumber());
2036 color
= BColor(default_color
, getBaseDisplay(), getScreenNumber());
2041 XFontSet
BScreen::readDatabaseFontSet(const string
&rname
,
2042 Configuration
&style
) {
2043 char *defaultFont
= "fixed";
2045 bool load_default
= True
;
2047 XFontSet fontset
= 0;
2048 if (style
.getValue(rname
, s
) && (fontset
= createFontSet(s
)))
2049 load_default
= False
;
2052 fontset
= createFontSet(defaultFont
);
2056 i18n(ScreenSet
, ScreenDefaultFontLoadFail
,
2057 "BScreen::setCurrentStyle(): couldn't load default font.\n"));
2066 XFontStruct
*BScreen::readDatabaseFont(const string
&rname
,
2067 Configuration
&style
) {
2068 char *defaultFont
= "fixed";
2070 bool load_default
= False
;
2072 XFontStruct
*font
= 0;
2073 if (style
.getValue(rname
, s
)) {
2074 if ((font
= XLoadQueryFont(blackbox
->getXDisplay(), s
.c_str())) == NULL
) {
2076 i18n(ScreenSet
, ScreenFontLoadFail
,
2077 "BScreen::setCurrentStyle(): couldn't load font '%s'\n"),
2080 load_default
= True
;
2083 load_default
= True
;
2087 font
= XLoadQueryFont(blackbox
->getXDisplay(), defaultFont
);
2090 i18n(ScreenSet
, ScreenDefaultFontLoadFail
,
2091 "BScreen::setCurrentStyle(): couldn't load default font.\n"));
2100 #ifndef HAVE_STRCASESTR
2101 static const char * strcasestr(const char *str
, const char *ptn
) {
2102 const char *s2
, *p2
;
2103 for(; *str
; str
++) {
2104 for(s2
=str
,p2
=ptn
; ; s2
++,p2
++) {
2105 if (! *p2
) return str
;
2106 if (toupper(*s2
) != toupper(*p2
)) break;
2111 #endif // HAVE_STRCASESTR
2114 static const char *getFontElement(const char *pattern
, char *buf
,
2120 va_start(va
, bufsiz
);
2122 buf
[bufsiz
-2] = '*';
2123 while((v
= va_arg(va
, char *)) != NULL
) {
2124 p
= strcasestr(pattern
, v
);
2126 strncpy(buf
, p
+1, bufsiz
-2);
2127 p2
= strchr(buf
, '-');
2134 strncpy(buf
, "*", bufsiz
);
2139 static const char *getFontSize(const char *pattern
, int *size
) {
2141 const char *p2
=NULL
;
2144 for (p
=pattern
; 1; p
++) {
2146 if (p2
!=NULL
&& n
>1 && n
<72) {
2147 *size
= n
; return p2
+1;
2149 *size
= 16; return NULL
;
2151 } else if (*p
=='-') {
2152 if (n
>1 && n
<72 && p2
!=NULL
) {
2157 } else if (*p
>='0' && *p
<='9' && p2
!=NULL
) {
2167 XFontSet
BScreen::createFontSet(const string
&fontname
) {
2169 char **missing
, *def
= "-";
2170 int nmissing
, pixel_size
= 0, buf_size
= 0;
2171 char weight
[FONT_ELEMENT_SIZE
], slant
[FONT_ELEMENT_SIZE
];
2173 fs
= XCreateFontSet(blackbox
->getXDisplay(),
2174 fontname
.c_str(), &missing
, &nmissing
, &def
);
2175 if (fs
&& (! nmissing
))
2178 const char *nfontname
= fontname
.c_str();
2179 #ifdef HAVE_SETLOCALE
2181 if (nmissing
) XFreeStringList(missing
);
2183 setlocale(LC_CTYPE
, "C");
2184 fs
= XCreateFontSet(blackbox
->getXDisplay(), fontname
.c_str(),
2185 &missing
, &nmissing
, &def
);
2186 setlocale(LC_CTYPE
, "");
2188 #endif // HAVE_SETLOCALE
2191 XFontStruct
**fontstructs
;
2193 XFontsOfFontSet(fs
, &fontstructs
, &fontnames
);
2194 nfontname
= fontnames
[0];
2197 getFontElement(nfontname
, weight
, FONT_ELEMENT_SIZE
,
2198 "-medium-", "-bold-", "-demibold-", "-regular-", NULL
);
2199 getFontElement(nfontname
, slant
, FONT_ELEMENT_SIZE
,
2200 "-r-", "-i-", "-o-", "-ri-", "-ro-", NULL
);
2201 getFontSize(nfontname
, &pixel_size
);
2203 if (! strcmp(weight
, "*"))
2204 strncpy(weight
, "medium", FONT_ELEMENT_SIZE
);
2205 if (! strcmp(slant
, "*"))
2206 strncpy(slant
, "r", FONT_ELEMENT_SIZE
);
2209 else if (pixel_size
> 97)
2212 buf_size
= strlen(nfontname
) + (FONT_ELEMENT_SIZE
* 2) + 64;
2213 char *pattern2
= new char[buf_size
];
2216 "-*-*-%s-%s-*-*-%d-*-*-*-*-*-*-*,"
2217 "-*-*-*-*-*-*-%d-*-*-*-*-*-*-*,*",
2218 nfontname
, weight
, slant
, pixel_size
, pixel_size
);
2219 nfontname
= pattern2
;
2222 XFreeStringList(missing
);
2224 XFreeFontSet(blackbox
->getXDisplay(), fs
);
2226 fs
= XCreateFontSet(blackbox
->getXDisplay(), nfontname
, &missing
,