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.
30 #ifdef TIME_WITH_SYS_TIME
31 # include <sys/time.h>
33 #else // !TIME_WITH_SYS_TIME
34 # ifdef HAVE_SYS_TIME_H
35 # include <sys/time.h>
36 # else // !HAVE_SYS_TIME_H
38 # endif // HAVE_SYS_TIME_H
39 #endif // TIME_WITH_SYS_TIME
48 #include "Configmenu.hh"
49 #include "Iconmenu.hh"
51 #include "Rootmenu.hh"
53 #include "Workspace.hh"
54 #include "Workspacemenu.hh"
55 #include "blackbox.hh"
57 class Slit
; // forward reference
61 enum TextJustify
{ LeftJustify
= 1, RightJustify
, CenterJustify
};
64 BColor f_focus
, f_unfocus
, l_text_focus
, l_text_unfocus
, b_pic_focus
,
66 BTexture t_focus
, t_unfocus
, l_focus
, l_unfocus
, h_focus
, h_unfocus
,
67 b_focus
, b_unfocus
, b_pressed
, g_focus
, g_unfocus
;
73 void doJustify(const std::string
&text
, int &start_pos
,
74 unsigned int max_length
, unsigned int modifier
) const;
78 BColor l_text
, w_text
, c_text
, b_pic
;
79 BTexture toolbar
, label
, window
, button
, pressed
, clock
;
85 void doJustify(const std::string
&text
, int &start_pos
,
86 unsigned int max_length
, unsigned int modifier
) const;
90 BColor t_text
, f_text
, h_text
, d_text
;
91 BTexture title
, frame
, hilite
;
93 BFont
*t_font
, *f_font
;
95 TextJustify t_justify
, f_justify
;
96 int bullet
, bullet_pos
;
100 unsigned int top
, bottom
, left
, right
;
102 Strut(void): top(0), bottom(0), left(0), right(0) {}
105 class BScreen
: public ScreenInfo
{
107 bool root_colormap_installed
, managed
, geom_visible
;
113 BImageControl
*image_control
;
114 Configmenu
*configmenu
;
117 Configuration
*config
;
120 typedef std::list
<Rootmenu
*> RootmenuList
;
121 RootmenuList rootmenuList
;
123 typedef std::list
<Netizen
*> NetizenList
;
124 NetizenList netizenList
;
125 BlackboxWindowList iconList
, windowList
;
127 typedef std::vector
<Window
> WindowList
;
128 WindowList desktopWindowList
, systrayWindowList
;
132 Workspace
*current_workspace
;
133 Workspacemenu
*workspacemenu
;
135 unsigned int geom_w
, geom_h
;
136 unsigned long event_mask
;
140 typedef std::list
<Strut
*> StrutList
;
142 typedef std::vector
<Workspace
*> WorkspaceList
;
143 WorkspaceList workspacesList
;
145 struct screen_resource
{
150 bool sloppy_focus
, auto_raise
, auto_edge_balance
, ordered_dither
,
151 opaque_move
, full_max
, focus_new
, focus_last
, click_raise
,
152 hide_toolbar
, window_to_window_snap
, window_corner_snap
, aa_fonts
;
155 unsigned int workspaces
;
156 int toolbar_placement
, toolbar_width_percent
, placement_policy
,
157 edge_snap_threshold
, row_direction
, col_direction
;
159 unsigned int handle_width
, bevel_width
, frame_width
, border_width
,
163 std::string strftime_format
;
164 #else // !HAVE_STRFTIME
167 #endif // HAVE_STRFTIME
170 std::string screenstr
;
172 BScreen(const BScreen
&);
173 BScreen
& operator=(const BScreen
&);
175 bool parseMenuFile(FILE *file
, Rootmenu
*menu
);
177 BTexture
readDatabaseTexture(const std::string
&rname
,
178 const std::string
&default_color
,
179 const Configuration
&style
);
180 BColor
readDatabaseColor(const std::string
&rname
,
181 const std::string
&default_color
,
182 const Configuration
&style
);
183 BFont
*readDatabaseFont(const std::string
&rbasename
,
184 const Configuration
&style
);
187 void LoadStyle(void);
189 void updateWorkArea(void);
191 enum { RowSmartPlacement
= 1, ColSmartPlacement
, CascadePlacement
,
192 UnderMousePlacement
, LeftRight
, RightLeft
, TopBottom
, BottomTop
};
193 enum { RoundBullet
= 1, TriangleBullet
, SquareBullet
, NoBullet
};
194 enum { Restart
= 1, RestartOther
, Exit
, Shutdown
, Execute
, Reconfigure
,
195 WindowShade
, WindowIconify
, WindowMaximize
, WindowClose
, WindowRaise
,
196 WindowLower
, WindowStick
, WindowKill
, SetStyle
};
197 enum FocusModel
{ SloppyFocus
, ClickToFocus
};
199 BScreen(Blackbox
*bb
, unsigned int scrn
);
202 inline bool isSloppyFocus(void) const { return resource
.sloppy_focus
; }
203 inline bool isRootColormapInstalled(void) const
204 { return root_colormap_installed
; }
205 inline bool doAutoRaise(void) const { return resource
.auto_raise
; }
206 inline bool doClickRaise(void) const { return resource
.click_raise
; }
207 inline bool isScreenManaged(void) const { return managed
; }
208 inline bool doAAFonts(void) const { return resource
.aa_fonts
; }
209 inline bool doImageDither(void) const { return image_control
->doDither(); }
210 inline bool doOrderedDither(void) const { return resource
.ordered_dither
; }
211 inline bool doOpaqueMove(void) const { return resource
.opaque_move
; }
212 inline bool doFullMax(void) const { return resource
.full_max
; }
213 inline bool doFocusNew(void) const { return resource
.focus_new
; }
214 inline bool doFocusLast(void) const { return resource
.focus_last
; }
215 inline bool doHideToolbar(void) const { return resource
.hide_toolbar
; }
216 inline bool getWindowToWindowSnap(void) const
217 { return resource
.window_to_window_snap
; }
218 inline bool getWindowCornerSnap(void) const
219 { return resource
.window_corner_snap
; }
221 inline const GC
&getOpGC(void) const { return opGC
; }
223 inline Blackbox
*getBlackbox(void) { return blackbox
; }
224 inline BColor
*getBorderColor(void) { return &resource
.border_color
; }
225 inline BImageControl
*getImageControl(void) { return image_control
; }
226 inline Rootmenu
*getRootmenu(void) { return rootmenu
; }
228 inline Slit
*getSlit(void) { return slit
; }
229 inline Toolbar
*getToolbar(void) { return toolbar
; }
231 Workspace
*getWorkspace(unsigned int index
);
233 inline Workspace
*getCurrentWorkspace(void) { return current_workspace
; }
235 inline Workspacemenu
*getWorkspacemenu(void) { return workspacemenu
; }
237 inline unsigned int getHandleWidth(void) const
238 { return resource
.handle_width
; }
239 inline unsigned int getBevelWidth(void) const
240 { return resource
.bevel_width
; }
241 inline unsigned int getFrameWidth(void) const
242 { return resource
.frame_width
; }
243 inline unsigned int getBorderWidth(void) const
244 { return resource
.border_width
; }
245 inline unsigned int getResizeZones(void) const
246 { return resource
.resize_zones
; }
248 inline unsigned int getCurrentWorkspaceID(void)
249 { return current_workspace
->getID(); }
250 inline unsigned int getWorkspaceCount(void)
251 { return workspacesList
.size(); }
252 inline unsigned int getIconCount(void) { return iconList
.size(); }
253 inline unsigned int getNumberOfWorkspaces(void) const
254 { return resource
.workspaces
; }
255 inline int getPlacementPolicy(void) const
256 { return resource
.placement_policy
; }
257 inline int getEdgeSnapThreshold(void) const
258 { return resource
.edge_snap_threshold
; }
259 inline int getRowPlacementDirection(void) const
260 { return resource
.row_direction
; }
261 inline int getColPlacementDirection(void) const
262 { return resource
.col_direction
; }
264 inline void setRootColormapInstalled(bool r
) { root_colormap_installed
= r
; }
265 void saveSloppyFocus(bool s
);
266 void saveAutoRaise(bool a
);
267 void saveClickRaise(bool c
);
268 void saveWorkspaces(unsigned int w
);
269 void savePlacementPolicy(int p
);
270 void saveRowPlacementDirection(int d
);
271 void saveColPlacementDirection(int d
);
272 void saveEdgeSnapThreshold(int t
);
273 void saveImageDither(bool d
);
274 void saveAAFonts(bool f
);
275 void saveOpaqueMove(bool o
);
276 void saveFullMax(bool f
);
277 void saveFocusNew(bool f
);
278 void saveFocusLast(bool f
);
279 void saveHideToolbar(bool h
);
280 void saveWindowToWindowSnap(bool s
);
281 void saveWindowCornerSnap(bool s
);
282 void saveResizeZones(unsigned int z
);
283 inline void iconUpdate(void) { iconmenu
->update(); }
286 inline const char *getStrftimeFormat(void)
287 { return resource
.strftime_format
.c_str(); }
288 void saveStrftimeFormat(const std::string
& format
);
289 #else // !HAVE_STRFTIME
290 inline int getDateFormat(void) { return resource
.date_format
; }
291 inline void saveDateFormat(int f
);
292 inline bool isClock24Hour(void) { return resource
.clock24hour
; }
293 inline void saveClock24Hour(bool c
);
294 #endif // HAVE_STRFTIME
296 inline WindowStyle
*getWindowStyle(void) { return &resource
.wstyle
; }
297 inline MenuStyle
*getMenuStyle(void) { return &resource
.mstyle
; }
298 inline ToolbarStyle
*getToolbarStyle(void) { return &resource
.tstyle
; }
300 BlackboxWindow
*getIcon(unsigned int index
);
302 const Rect
& availableArea(void) const;
303 void updateAvailableArea(void);
304 void addStrut(Strut
*strut
);
305 void removeStrut(Strut
*strut
);
307 unsigned int addWorkspace(void);
308 unsigned int removeLastWorkspace(void);
309 void changeWorkspaceID(unsigned int id
);
310 void saveWorkspaceNames(void);
312 void addNetizen(Netizen
*n
);
313 void removeNetizen(Window w
);
315 void addDesktopWindow(Window window
);
316 void removeDesktopWindow(Window window
);
318 void addSystrayWindow(Window window
);
319 void removeSystrayWindow(Window window
);
321 void addIcon(BlackboxWindow
*w
);
322 void removeIcon(BlackboxWindow
*w
);
324 void updateClientList(void);
325 void updateStackingList(void);
326 void manageWindow(Window w
);
327 void unmanageWindow(BlackboxWindow
*w
, bool remap
);
328 void raiseWindows(Window
*workspace_stack
, unsigned int num
);
329 void lowerDesktops(void);
330 void reassociateWindow(BlackboxWindow
*w
, unsigned int wkspc_id
,
332 void propagateWindowName(const BlackboxWindow
*bw
);
333 void prevFocus(void);
334 void nextFocus(void);
335 void raiseFocus(void);
338 void reconfigure(void);
339 void toggleFocusModel(FocusModel model
);
340 void rereadMenu(void);
342 void showPosition(int x
, int y
);
343 void showGeometry(unsigned int gx
, unsigned int gy
);
344 void hideGeometry(void);
346 void buttonPressEvent(const XButtonEvent
*xbutton
);
348 void updateNetizenCurrentWorkspace(void);
349 void updateNetizenWorkspaceCount(void);
350 void updateNetizenWindowFocus(void);
351 void updateNetizenWindowAdd(Window w
, unsigned long p
);
352 void updateNetizenWindowDel(Window w
);
353 void updateNetizenConfigNotify(XEvent
*e
);
354 void updateNetizenWindowRaise(Window w
);
355 void updateNetizenWindowLower(Window w
);
359 #endif // __Screen_hh