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
62 enum TextJustify
{ LeftJustify
= 1, RightJustify
, CenterJustify
};
65 BColor f_focus
, f_unfocus
, l_text_focus
, l_text_unfocus
, b_pic_focus
,
67 BTexture t_focus
, t_unfocus
, l_focus
, l_unfocus
, h_focus
, h_unfocus
,
68 b_focus
, b_unfocus
, b_pressed
, g_focus
, g_unfocus
;
74 void doJustify(const std::string
&text
, int &start_pos
,
75 unsigned int max_length
, unsigned int modifier
) const;
79 BColor l_text
, w_text
, c_text
, b_pic
;
80 BTexture toolbar
, label
, window
, button
, pressed
, clock
;
86 void doJustify(const std::string
&text
, int &start_pos
,
87 unsigned int max_length
, unsigned int modifier
) const;
91 BColor t_text
, f_text
, h_text
, d_text
;
92 BTexture title
, frame
, hilite
;
94 BFont
*t_font
, *f_font
;
96 TextJustify t_justify
, f_justify
;
97 int bullet
, bullet_pos
;
100 class BScreen
: public ScreenInfo
{
102 bool root_colormap_installed
, managed
, geom_visible
;
108 BImageControl
*image_control
;
109 Configmenu
*configmenu
;
112 Configuration
*config
;
115 typedef std::list
<Rootmenu
*> RootmenuList
;
116 RootmenuList rootmenuList
;
118 typedef std::list
<Netizen
*> NetizenList
;
119 NetizenList netizenList
;
120 BlackboxWindowList iconList
, windowList
;
122 typedef std::vector
<Window
> WindowList
;
123 WindowList desktopWindowList
, systrayWindowList
;
127 Workspace
*current_workspace
;
128 Workspacemenu
*workspacemenu
;
130 unsigned int geom_w
, geom_h
;
131 unsigned long event_mask
;
135 RectList xineramaUsableArea
;
138 typedef std::list
<Strut
*> StrutList
;
140 typedef std::vector
<Workspace
*> WorkspaceList
;
141 WorkspaceList workspacesList
;
143 struct screen_resource
{
148 bool sloppy_focus
, auto_raise
, auto_edge_balance
, ordered_dither
,
149 opaque_move
, full_max
, focus_new
, focus_last
, click_raise
,
150 allow_scroll_lock
, hide_toolbar
, window_to_window_snap
,
151 window_corner_snap
, aa_fonts
, ignore_shaded
, ignore_maximized
,
155 unsigned int workspaces
;
156 int toolbar_placement
, toolbar_width_percent
, placement_policy
,
157 edge_snap_threshold
, row_direction
, col_direction
, root_scroll
;
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
, ClickMousePlacement
, LeftRight
, RightLeft
,
193 TopBottom
, BottomTop
, IgnoreShaded
, IgnoreMaximized
};
194 enum { RoundBullet
= 1, TriangleBullet
, SquareBullet
, NoBullet
};
195 enum { Restart
= 1, RestartOther
, Exit
, Shutdown
, Execute
, Reconfigure
,
196 WindowShade
, WindowIconify
, WindowMaximize
, WindowClose
, WindowRaise
,
197 WindowLower
, WindowStick
, WindowKill
, SetStyle
};
198 enum FocusModel
{ SloppyFocus
, ClickToFocus
};
199 enum RootScrollDirection
{ NoScroll
, NormalScroll
, ReverseScroll
};
201 BScreen(Blackbox
*bb
, unsigned int scrn
);
204 inline bool isSloppyFocus(void) const { return resource
.sloppy_focus
; }
205 inline bool isRootColormapInstalled(void) const
206 { return root_colormap_installed
; }
207 inline bool doAutoRaise(void) const { return resource
.auto_raise
; }
208 inline bool doClickRaise(void) const { return resource
.click_raise
; }
209 inline bool isScreenManaged(void) const { return managed
; }
210 inline bool doAAFonts(void) const { return resource
.aa_fonts
; }
211 inline bool doImageDither(void) const { return image_control
->doDither(); }
212 inline bool doOrderedDither(void) const { return resource
.ordered_dither
; }
213 inline bool doOpaqueMove(void) const { return resource
.opaque_move
; }
214 inline bool doFullMax(void) const { return resource
.full_max
; }
215 inline bool doFocusNew(void) const { return resource
.focus_new
; }
216 inline bool doFocusLast(void) const { return resource
.focus_last
; }
217 inline bool doHideToolbar(void) const { return resource
.hide_toolbar
; }
218 inline bool getWindowToWindowSnap(void) const
219 { return resource
.window_to_window_snap
; }
220 inline bool getWindowCornerSnap(void) const
221 { return resource
.window_corner_snap
; }
222 inline bool allowScrollLock(void) const { return resource
.allow_scroll_lock
; }
223 inline bool doWorkspaceWarping(void) const
224 { return resource
.workspace_warping
; }
225 inline int rootScrollDirection(void) const { return resource
.root_scroll
; }
227 inline const GC
&getOpGC(void) const { return opGC
; }
229 inline Blackbox
*getBlackbox(void) { return blackbox
; }
230 inline BColor
*getBorderColor(void) { return &resource
.border_color
; }
231 inline BImageControl
*getImageControl(void) { return image_control
; }
232 inline Rootmenu
*getRootmenu(void) { return rootmenu
; }
234 inline Slit
*getSlit(void) { return slit
; }
235 inline Toolbar
*getToolbar(void) { return toolbar
; }
237 Workspace
*getWorkspace(unsigned int index
);
239 inline Workspace
*getCurrentWorkspace(void) { return current_workspace
; }
241 inline Workspacemenu
*getWorkspacemenu(void) { return workspacemenu
; }
243 inline unsigned int getHandleWidth(void) const
244 { return resource
.handle_width
; }
245 inline unsigned int getBevelWidth(void) const
246 { return resource
.bevel_width
; }
247 inline unsigned int getFrameWidth(void) const
248 { return resource
.frame_width
; }
249 inline unsigned int getBorderWidth(void) const
250 { return resource
.border_width
; }
251 inline unsigned int getResizeZones(void) const
252 { return resource
.resize_zones
; }
253 inline bool getPlaceIgnoreShaded(void) const
254 { return resource
.ignore_shaded
; }
255 inline bool getPlaceIgnoreMaximized(void) const
256 { return resource
.ignore_maximized
; }
258 inline unsigned int getCurrentWorkspaceID(void) const
259 { return current_workspace
->getID(); }
260 inline unsigned int getWorkspaceCount(void) const
261 { return workspacesList
.size(); }
262 inline unsigned int getIconCount(void) const { return iconList
.size(); }
263 inline unsigned int getNumberOfWorkspaces(void) const
264 { return resource
.workspaces
; }
265 inline int getPlacementPolicy(void) const
266 { return resource
.placement_policy
; }
267 inline int getEdgeSnapThreshold(void) const
268 { return resource
.edge_snap_threshold
; }
269 inline int getRowPlacementDirection(void) const
270 { return resource
.row_direction
; }
271 inline int getColPlacementDirection(void) const
272 { return resource
.col_direction
; }
274 void changeWorkspaceCount(unsigned int new_count
);
276 inline void setRootColormapInstalled(bool r
) { root_colormap_installed
= r
; }
277 void saveSloppyFocus(bool s
);
278 void saveAutoRaise(bool a
);
279 void saveClickRaise(bool c
);
280 void saveWorkspaces(unsigned int w
);
281 void savePlacementPolicy(int p
);
282 void saveRowPlacementDirection(int d
);
283 void saveColPlacementDirection(int d
);
284 void saveEdgeSnapThreshold(int t
);
285 void saveImageDither(bool d
);
286 void saveAAFonts(bool f
);
287 void saveOpaqueMove(bool o
);
288 void saveFullMax(bool f
);
289 void saveFocusNew(bool f
);
290 void saveFocusLast(bool f
);
291 void saveHideToolbar(bool h
);
292 void saveWindowToWindowSnap(bool s
);
293 void saveWindowCornerSnap(bool s
);
294 void saveResizeZones(unsigned int z
);
295 void savePlaceIgnoreShaded(bool i
);
296 void savePlaceIgnoreMaximized(bool i
);
297 void saveAllowScrollLock(bool a
);
298 void saveWorkspaceWarping(bool w
);
299 void saveRootScrollDirection(int d
);
300 inline void iconUpdate(void) { iconmenu
->update(); }
303 inline const char *getStrftimeFormat(void)
304 { return resource
.strftime_format
.c_str(); }
305 void saveStrftimeFormat(const std::string
& format
);
306 #else // !HAVE_STRFTIME
307 inline int getDateFormat(void) { return resource
.date_format
; }
308 inline void saveDateFormat(int f
);
309 inline bool isClock24Hour(void) { return resource
.clock24hour
; }
310 inline void saveClock24Hour(bool c
);
311 #endif // HAVE_STRFTIME
313 inline WindowStyle
*getWindowStyle(void) { return &resource
.wstyle
; }
314 inline MenuStyle
*getMenuStyle(void) { return &resource
.mstyle
; }
315 inline ToolbarStyle
*getToolbarStyle(void) { return &resource
.tstyle
; }
317 BlackboxWindow
*getIcon(unsigned int index
);
319 // allAvailableAreas should be used whenever possible instead of this function
320 // as then Xinerama will work correctly.
321 const Rect
& availableArea(void) const;
323 const RectList
& allAvailableAreas(void) const;
325 void updateAvailableArea(void);
326 void addStrut(Strut
*strut
);
327 void removeStrut(Strut
*strut
);
329 unsigned int addWorkspace(void);
330 unsigned int removeLastWorkspace(void);
331 void changeWorkspaceID(unsigned int id
);
332 void saveWorkspaceNames(void);
334 void addNetizen(Netizen
*n
);
335 void removeNetizen(Window w
);
337 void addSystrayWindow(Window window
);
338 void removeSystrayWindow(Window window
);
340 void addIcon(BlackboxWindow
*w
);
341 void removeIcon(BlackboxWindow
*w
);
343 void updateClientList(void);
344 void updateStackingList(void);
345 void manageWindow(Window w
);
346 void unmanageWindow(BlackboxWindow
*w
, bool remap
);
347 void raiseWindows(Window
*workspace_stack
, unsigned int num
);
348 void lowerWindows(Window
*workspace_stack
, unsigned int num
);
349 void reassociateWindow(BlackboxWindow
*w
, unsigned int wkspc_id
,
351 void propagateWindowName(const BlackboxWindow
*bw
);
352 void prevFocus(void);
353 void nextFocus(void);
354 void raiseFocus(void);
357 void reconfigure(void);
358 void toggleFocusModel(FocusModel model
);
359 void rereadMenu(void);
361 void showPosition(int x
, int y
);
362 void showGeometry(unsigned int gx
, unsigned int gy
);
363 void hideGeometry(void);
365 void buttonPressEvent(const XButtonEvent
*xbutton
);
366 void propertyNotifyEvent(const XPropertyEvent
*pe
);
368 void updateNetizenCurrentWorkspace(void);
369 void updateNetizenWorkspaceCount(void);
370 void updateNetizenWindowFocus(void);
371 void updateNetizenWindowAdd(Window w
, unsigned long p
);
372 void updateNetizenWindowDel(Window w
);
373 void updateNetizenConfigNotify(XEvent
*e
);
374 void updateNetizenWindowRaise(Window w
);
375 void updateNetizenWindowLower(Window w
);
379 #endif // __Screen_hh