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
,
153 ignore_shaded
, ignore_maximized
;
156 unsigned int workspaces
;
157 int toolbar_placement
, toolbar_width_percent
, placement_policy
,
158 edge_snap_threshold
, row_direction
, col_direction
;
160 unsigned int handle_width
, bevel_width
, frame_width
, border_width
,
164 std::string strftime_format
;
165 #else // !HAVE_STRFTIME
168 #endif // HAVE_STRFTIME
171 std::string screenstr
;
173 BScreen(const BScreen
&);
174 BScreen
& operator=(const BScreen
&);
176 bool parseMenuFile(FILE *file
, Rootmenu
*menu
);
178 BTexture
readDatabaseTexture(const std::string
&rname
,
179 const std::string
&default_color
,
180 const Configuration
&style
);
181 BColor
readDatabaseColor(const std::string
&rname
,
182 const std::string
&default_color
,
183 const Configuration
&style
);
184 BFont
*readDatabaseFont(const std::string
&rbasename
,
185 const Configuration
&style
);
188 void LoadStyle(void);
190 void updateWorkArea(void);
192 enum { RowSmartPlacement
= 1, ColSmartPlacement
, CascadePlacement
,
193 UnderMousePlacement
, ClickMousePlacement
, LeftRight
, RightLeft
,
194 TopBottom
, BottomTop
, IgnoreShaded
, IgnoreMaximized
};
195 enum { RoundBullet
= 1, TriangleBullet
, SquareBullet
, NoBullet
};
196 enum { Restart
= 1, RestartOther
, Exit
, Shutdown
, Execute
, Reconfigure
,
197 WindowShade
, WindowIconify
, WindowMaximize
, WindowClose
, WindowRaise
,
198 WindowLower
, WindowStick
, WindowKill
, SetStyle
};
199 enum FocusModel
{ SloppyFocus
, ClickToFocus
};
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
; }
223 inline const GC
&getOpGC(void) const { return opGC
; }
225 inline Blackbox
*getBlackbox(void) { return blackbox
; }
226 inline BColor
*getBorderColor(void) { return &resource
.border_color
; }
227 inline BImageControl
*getImageControl(void) { return image_control
; }
228 inline Rootmenu
*getRootmenu(void) { return rootmenu
; }
230 inline Slit
*getSlit(void) { return slit
; }
231 inline Toolbar
*getToolbar(void) { return toolbar
; }
233 Workspace
*getWorkspace(unsigned int index
);
235 inline Workspace
*getCurrentWorkspace(void) { return current_workspace
; }
237 inline Workspacemenu
*getWorkspacemenu(void) { return workspacemenu
; }
239 inline unsigned int getHandleWidth(void) const
240 { return resource
.handle_width
; }
241 inline unsigned int getBevelWidth(void) const
242 { return resource
.bevel_width
; }
243 inline unsigned int getFrameWidth(void) const
244 { return resource
.frame_width
; }
245 inline unsigned int getBorderWidth(void) const
246 { return resource
.border_width
; }
247 inline unsigned int getResizeZones(void) const
248 { return resource
.resize_zones
; }
249 inline bool getPlaceIgnoreShaded(void) const
250 { return resource
.ignore_shaded
; }
251 inline bool getPlaceIgnoreMaximized(void) const
252 { return resource
.ignore_maximized
; }
254 inline unsigned int getCurrentWorkspaceID(void) const
255 { return current_workspace
->getID(); }
256 inline unsigned int getWorkspaceCount(void) const
257 { return workspacesList
.size(); }
258 inline unsigned int getIconCount(void) const { return iconList
.size(); }
259 inline unsigned int getNumberOfWorkspaces(void) const
260 { return resource
.workspaces
; }
261 inline int getPlacementPolicy(void) const
262 { return resource
.placement_policy
; }
263 inline int getEdgeSnapThreshold(void) const
264 { return resource
.edge_snap_threshold
; }
265 inline int getRowPlacementDirection(void) const
266 { return resource
.row_direction
; }
267 inline int getColPlacementDirection(void) const
268 { return resource
.col_direction
; }
270 void changeWorkspaceCount(unsigned int new_count
);
272 inline void setRootColormapInstalled(bool r
) { root_colormap_installed
= r
; }
273 void saveSloppyFocus(bool s
);
274 void saveAutoRaise(bool a
);
275 void saveClickRaise(bool c
);
276 void saveWorkspaces(unsigned int w
);
277 void savePlacementPolicy(int p
);
278 void saveRowPlacementDirection(int d
);
279 void saveColPlacementDirection(int d
);
280 void saveEdgeSnapThreshold(int t
);
281 void saveImageDither(bool d
);
282 void saveAAFonts(bool f
);
283 void saveOpaqueMove(bool o
);
284 void saveFullMax(bool f
);
285 void saveFocusNew(bool f
);
286 void saveFocusLast(bool f
);
287 void saveHideToolbar(bool h
);
288 void saveWindowToWindowSnap(bool s
);
289 void saveWindowCornerSnap(bool s
);
290 void saveResizeZones(unsigned int z
);
291 void savePlaceIgnoreShaded(bool i
);
292 void savePlaceIgnoreMaximized(bool i
);
293 inline void iconUpdate(void) { iconmenu
->update(); }
296 inline const char *getStrftimeFormat(void)
297 { return resource
.strftime_format
.c_str(); }
298 void saveStrftimeFormat(const std::string
& format
);
299 #else // !HAVE_STRFTIME
300 inline int getDateFormat(void) { return resource
.date_format
; }
301 inline void saveDateFormat(int f
);
302 inline bool isClock24Hour(void) { return resource
.clock24hour
; }
303 inline void saveClock24Hour(bool c
);
304 #endif // HAVE_STRFTIME
306 inline WindowStyle
*getWindowStyle(void) { return &resource
.wstyle
; }
307 inline MenuStyle
*getMenuStyle(void) { return &resource
.mstyle
; }
308 inline ToolbarStyle
*getToolbarStyle(void) { return &resource
.tstyle
; }
310 BlackboxWindow
*getIcon(unsigned int index
);
312 const Rect
& availableArea(void) const;
313 void updateAvailableArea(void);
314 void addStrut(Strut
*strut
);
315 void removeStrut(Strut
*strut
);
317 unsigned int addWorkspace(void);
318 unsigned int removeLastWorkspace(void);
319 void changeWorkspaceID(unsigned int id
);
320 void saveWorkspaceNames(void);
322 void addNetizen(Netizen
*n
);
323 void removeNetizen(Window w
);
325 void addSystrayWindow(Window window
);
326 void removeSystrayWindow(Window window
);
328 void addIcon(BlackboxWindow
*w
);
329 void removeIcon(BlackboxWindow
*w
);
331 void updateClientList(void);
332 void updateStackingList(void);
333 void manageWindow(Window w
);
334 void unmanageWindow(BlackboxWindow
*w
, bool remap
);
335 void raiseWindows(Window
*workspace_stack
, unsigned int num
);
336 void lowerWindows(Window
*workspace_stack
, unsigned int num
);
337 void reassociateWindow(BlackboxWindow
*w
, unsigned int wkspc_id
,
339 void propagateWindowName(const BlackboxWindow
*bw
);
340 void prevFocus(void);
341 void nextFocus(void);
342 void raiseFocus(void);
345 void reconfigure(void);
346 void toggleFocusModel(FocusModel model
);
347 void rereadMenu(void);
349 void showPosition(int x
, int y
);
350 void showGeometry(unsigned int gx
, unsigned int gy
);
351 void hideGeometry(void);
353 void buttonPressEvent(const XButtonEvent
*xbutton
);
354 void propertyNotifyEvent(const XPropertyEvent
*pe
);
356 void updateNetizenCurrentWorkspace(void);
357 void updateNetizenWorkspaceCount(void);
358 void updateNetizenWindowFocus(void);
359 void updateNetizenWindowAdd(Window w
, unsigned long p
);
360 void updateNetizenWindowDel(Window w
);
361 void updateNetizenConfigNotify(XEvent
*e
);
362 void updateNetizenWindowRaise(Window w
);
363 void updateNetizenWindowLower(Window w
);
367 #endif // __Screen_hh