1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 // Screen.hh 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.
29 #include <X11/Xresource.h>
31 #ifdef TIME_WITH_SYS_TIME
32 # include <sys/time.h>
34 #else // !TIME_WITH_SYS_TIME
35 # ifdef HAVE_SYS_TIME_H
36 # include <sys/time.h>
37 # else // !HAVE_SYS_TIME_H
39 # endif // HAVE_SYS_TIME_H
40 #endif // TIME_WITH_SYS_TIME
49 #include "Configmenu.hh"
50 #include "Iconmenu.hh"
52 #include "Rootmenu.hh"
54 #include "Workspace.hh"
55 #include "Workspacemenu.hh"
56 #include "blackbox.hh"
57 class Slit
; // forward reference
60 enum TextJustify
{ LeftJustify
= 1, RightJustify
, CenterJustify
};
63 BColor f_focus
, f_unfocus
, l_text_focus
, l_text_unfocus
, b_pic_focus
,
65 BTexture t_focus
, t_unfocus
, l_focus
, l_unfocus
, h_focus
, h_unfocus
,
66 b_focus
, b_unfocus
, b_pressed
, g_focus
, g_unfocus
;
69 XFontSetExtents
*fontset_extents
;
74 int doJustify(const char *text
, int &start_pos
, unsigned int max_length
,
75 unsigned int modifier
, bool multibyte
) const;
79 BColor l_text
, w_text
, c_text
, b_pic
;
80 BTexture toolbar
, label
, window
, button
, pressed
, clock
;
83 XFontSetExtents
*fontset_extents
;
88 int doJustify(const char *text
, int &start_pos
, unsigned int max_length
,
89 unsigned int modifier
, bool multibyte
) const;
93 BColor t_text
, f_text
, h_text
, d_text
;
94 BTexture title
, frame
, hilite
;
96 XFontSet t_fontset
, f_fontset
;
97 XFontSetExtents
*t_fontset_extents
, *f_fontset_extents
;
98 XFontStruct
*t_font
, *f_font
;
100 TextJustify t_justify
, f_justify
;
101 int bullet
, bullet_pos
;
105 unsigned int top
, bottom
, left
, right
;
107 Strut(void): top(0), bottom(0), left(0), right(0) {}
110 class BScreen
: public ScreenInfo
{
112 bool root_colormap_installed
, managed
, geom_visible
;
118 BImageControl
*image_control
;
119 Configmenu
*configmenu
;
122 Configuration
*config
;
125 typedef std::list
<Rootmenu
*> RootmenuList
;
126 RootmenuList rootmenuList
;
128 typedef std::list
<Netizen
*> NetizenList
;
129 NetizenList netizenList
;
130 BlackboxWindowList iconList
, windowList
;
134 Workspace
*current_workspace
;
135 Workspacemenu
*workspacemenu
;
137 unsigned int geom_w
, geom_h
;
138 unsigned long event_mask
;
142 typedef std::list
<Strut
*> StrutList
;
144 typedef std::vector
<std::string
> WorkspaceNamesList
;
145 WorkspaceNamesList workspaceNames
;
146 typedef std::vector
<Workspace
*> WorkspaceList
;
147 WorkspaceList workspacesList
;
149 struct screen_resource
{
154 bool sloppy_focus
, auto_raise
, auto_edge_balance
, ordered_dither
,
155 opaque_move
, full_max
, focus_new
, focus_last
, click_raise
,
159 unsigned int workspaces
;
160 int toolbar_placement
, toolbar_width_percent
, placement_policy
,
161 edge_snap_threshold
, row_direction
, col_direction
;
163 unsigned int handle_width
, bevel_width
, frame_width
, border_width
;
166 std::string strftime_format
;
167 #else // !HAVE_STRFTIME
170 #endif // HAVE_STRFTIME
173 std::string screenstr
;
175 BScreen(const BScreen
&);
176 BScreen
& operator=(const BScreen
&);
178 bool parseMenuFile(FILE *file
, Rootmenu
*menu
);
180 BTexture
readDatabaseTexture(const std::string
&rname
,
181 const std::string
&default_color
,
182 Configuration
&style
);
183 BColor
readDatabaseColor(const std::string
&rname
,
184 const std::string
&default_color
,
185 Configuration
&style
);
186 XFontSet
readDatabaseFontSet(const std::string
&rname
, Configuration
&style
);
187 XFontStruct
*readDatabaseFont(const std::string
&rname
, Configuration
&style
);
188 XFontSet
createFontSet(const std::string
&fontname
);
191 void LoadStyle(void);
195 enum { RowSmartPlacement
= 1, ColSmartPlacement
, CascadePlacement
,
196 UnderMousePlacement
, LeftRight
, RightLeft
, TopBottom
, BottomTop
};
197 enum { RoundBullet
= 1, TriangleBullet
, SquareBullet
, NoBullet
};
198 enum { Restart
= 1, RestartOther
, Exit
, Shutdown
, Execute
, Reconfigure
,
199 WindowShade
, WindowIconify
, WindowMaximize
, WindowClose
, WindowRaise
,
200 WindowLower
, WindowStick
, WindowKill
, SetStyle
};
201 enum FocusModel
{ SloppyFocus
, ClickToFocus
};
203 BScreen(Blackbox
*bb
, unsigned int scrn
);
206 inline bool isSloppyFocus(void) const { return resource
.sloppy_focus
; }
207 inline bool isRootColormapInstalled(void) const
208 { return root_colormap_installed
; }
209 inline bool doAutoRaise(void) const { return resource
.auto_raise
; }
210 inline bool doClickRaise(void) const { return resource
.click_raise
; }
211 inline bool isScreenManaged(void) const { return managed
; }
212 inline bool doImageDither(void) const { return image_control
->doDither(); }
213 inline bool doOrderedDither(void) const { return resource
.ordered_dither
; }
214 inline bool doOpaqueMove(void) const { return resource
.opaque_move
; }
215 inline bool doFullMax(void) const { return resource
.full_max
; }
216 inline bool doFocusNew(void) const { return resource
.focus_new
; }
217 inline bool doFocusLast(void) const { return resource
.focus_last
; }
218 inline bool doHideToolbar(void) const { return resource
.hide_toolbar
; }
220 inline const GC
&getOpGC(void) const { return opGC
; }
222 inline Blackbox
*getBlackbox(void) { return blackbox
; }
223 inline BColor
*getBorderColor(void) { return &resource
.border_color
; }
224 inline BImageControl
*getImageControl(void) { return image_control
; }
225 inline Rootmenu
*getRootmenu(void) { return rootmenu
; }
227 inline Slit
*getSlit(void) { return slit
; }
228 inline Toolbar
*getToolbar(void) { return toolbar
; }
230 Workspace
*getWorkspace(unsigned int index
);
232 inline Workspace
*getCurrentWorkspace(void) { return current_workspace
; }
234 inline Workspacemenu
*getWorkspacemenu(void) { return workspacemenu
; }
236 inline unsigned int getHandleWidth(void) const
237 { return resource
.handle_width
; }
238 inline unsigned int getBevelWidth(void) const
239 { return resource
.bevel_width
; }
240 inline unsigned int getFrameWidth(void) const
241 { return resource
.frame_width
; }
242 inline unsigned int getBorderWidth(void) const
243 { return resource
.border_width
; }
245 inline unsigned int getCurrentWorkspaceID(void)
246 { return current_workspace
->getID(); }
247 inline unsigned int getWorkspaceCount(void)
248 { return workspacesList
.size(); }
249 inline unsigned int getIconCount(void) { return iconList
.size(); }
250 inline unsigned int getNumberOfWorkspaces(void) const
251 { return resource
.workspaces
; }
252 inline int getPlacementPolicy(void) const
253 { return resource
.placement_policy
; }
254 inline int getEdgeSnapThreshold(void) const
255 { return resource
.edge_snap_threshold
; }
256 inline int getRowPlacementDirection(void) const
257 { return resource
.row_direction
; }
258 inline int getColPlacementDirection(void) const
259 { return resource
.col_direction
; }
261 inline void setRootColormapInstalled(bool r
) { root_colormap_installed
= r
; }
262 void saveSloppyFocus(bool s
);
263 void saveAutoRaise(bool a
);
264 void saveClickRaise(bool c
);
265 void saveWorkspaces(unsigned int w
);
266 void savePlacementPolicy(int p
);
267 void saveRowPlacementDirection(int d
);
268 void saveColPlacementDirection(int d
);
269 void saveEdgeSnapThreshold(int t
);
270 void saveImageDither(bool d
);
271 void saveOpaqueMove(bool o
);
272 void saveFullMax(bool f
);
273 void saveFocusNew(bool f
);
274 void saveFocusLast(bool f
);
275 void saveHideToolbar(bool h
);
276 inline void iconUpdate(void) { iconmenu
->update(); }
279 inline const char *getStrftimeFormat(void)
280 { return resource
.strftime_format
.c_str(); }
281 void saveStrftimeFormat(const std::string
& format
);
282 #else // !HAVE_STRFTIME
283 inline int getDateFormat(void) { return resource
.date_format
; }
284 inline void saveDateFormat(int f
);
285 inline bool isClock24Hour(void) { return resource
.clock24hour
; }
286 inline void saveClock24Hour(bool c
);
287 #endif // HAVE_STRFTIME
289 inline WindowStyle
*getWindowStyle(void) { return &resource
.wstyle
; }
290 inline MenuStyle
*getMenuStyle(void) { return &resource
.mstyle
; }
291 inline ToolbarStyle
*getToolbarStyle(void) { return &resource
.tstyle
; }
293 BlackboxWindow
*getIcon(unsigned int index
);
295 const Rect
& availableArea(void) const;
296 void updateAvailableArea(void);
297 void addStrut(Strut
*strut
);
298 void removeStrut(Strut
*strut
);
300 unsigned int addWorkspace(void);
301 unsigned int removeLastWorkspace(void);
302 void removeWorkspaceNames(void);
303 void addWorkspaceName(const std::string
& name
);
304 const std::string
getNameOfWorkspace(unsigned int id
);
305 void changeWorkspaceID(unsigned int id
);
306 void saveWorkspaceNames(void);
308 void addNetizen(Netizen
*n
);
309 void removeNetizen(Window w
);
311 void addIcon(BlackboxWindow
*w
);
312 void removeIcon(BlackboxWindow
*w
);
314 void manageWindow(Window w
);
315 void unmanageWindow(BlackboxWindow
*w
, bool remap
);
316 void raiseWindows(Window
*workspace_stack
, unsigned int num
);
317 void reassociateWindow(BlackboxWindow
*w
, unsigned int wkspc_id
,
319 void propagateWindowName(const BlackboxWindow
*bw
);
320 void prevFocus(void);
321 void nextFocus(void);
322 void raiseFocus(void);
325 void reconfigure(void);
326 void toggleFocusModel(FocusModel model
);
327 void updateFocusModel(void);
328 void rereadMenu(void);
330 void showPosition(int x
, int y
);
331 void showGeometry(unsigned int gx
, unsigned int gy
);
332 void hideGeometry(void);
334 void buttonPressEvent(XButtonEvent
*xbutton
);
336 void updateNetizenCurrentWorkspace(void);
337 void updateNetizenWorkspaceCount(void);
338 void updateNetizenWindowFocus(void);
339 void updateNetizenWindowAdd(Window w
, unsigned long p
);
340 void updateNetizenWindowDel(Window w
);
341 void updateNetizenConfigNotify(XEvent
*e
);
342 void updateNetizenWindowRaise(Window w
);
343 void updateNetizenWindowLower(Window w
);
347 #endif // __Screen_hh