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 specialWindowList
, 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_corner_snap
, aa_fonts
,
151 ignore_shaded
, ignore_maximized
, workspace_warping
;
153 int snap_to_windows
, snap_to_edges
;
154 unsigned int snap_offset
;
158 unsigned int workspaces
;
159 int toolbar_placement
, toolbar_width_percent
, placement_policy
,
160 snap_threshold
, row_direction
, col_direction
, root_scroll
,
163 unsigned int handle_width
, bevel_width
, frame_width
, border_width
,
167 std::string strftime_format
;
168 #else // !HAVE_STRFTIME
171 #endif // HAVE_STRFTIME
174 std::string screenstr
;
176 BScreen(const BScreen
&);
177 BScreen
& operator=(const BScreen
&);
179 bool parseMenuFile(FILE *file
, Rootmenu
*menu
);
181 BTexture
readDatabaseTexture(const std::string
&rname
,
182 const std::string
&default_color
,
183 const Configuration
&style
);
184 BColor
readDatabaseColor(const std::string
&rname
,
185 const std::string
&default_color
,
186 const Configuration
&style
);
187 BFont
*readDatabaseFont(const std::string
&rbasename
,
188 const Configuration
&style
);
191 void LoadStyle(void);
193 void updateWorkArea(void);
195 enum { WindowNoSnap
= 0, WindowSnap
, WindowResistance
};
196 enum { RowSmartPlacement
= 1, ColSmartPlacement
, CascadePlacement
,
197 UnderMousePlacement
, ClickMousePlacement
, LeftRight
, RightLeft
,
198 TopBottom
, BottomTop
, IgnoreShaded
, IgnoreMaximized
};
199 enum { RoundBullet
= 1, TriangleBullet
, SquareBullet
, NoBullet
};
200 enum { Restart
= 1, RestartOther
, Exit
, Shutdown
, Execute
, Reconfigure
,
201 WindowShade
, WindowIconify
, WindowMaximize
, WindowClose
, WindowRaise
,
202 WindowLower
, WindowStick
, WindowKill
, SetStyle
};
203 enum FocusModel
{ SloppyFocus
, ClickToFocus
};
204 enum RootScrollDirection
{ NoScroll
= 0, NormalScroll
, ReverseScroll
};
206 BScreen(Blackbox
*bb
, unsigned int scrn
);
209 inline bool isSloppyFocus(void) const { return resource
.sloppy_focus
; }
210 inline bool isRootColormapInstalled(void) const
211 { return root_colormap_installed
; }
212 inline bool doAutoRaise(void) const { return resource
.auto_raise
; }
213 inline bool doClickRaise(void) const { return resource
.click_raise
; }
214 inline bool isScreenManaged(void) const { return managed
; }
215 inline bool doAAFonts(void) const { return resource
.aa_fonts
; }
216 inline bool doImageDither(void) const { return image_control
->doDither(); }
217 inline bool doOrderedDither(void) const { return resource
.ordered_dither
; }
218 inline bool doOpaqueMove(void) const { return resource
.opaque_move
; }
219 inline bool doFullMax(void) const { return resource
.full_max
; }
220 inline bool doFocusNew(void) const { return resource
.focus_new
; }
221 inline bool doFocusLast(void) const { return resource
.focus_last
; }
222 inline bool doHideToolbar(void) const { return resource
.hide_toolbar
; }
223 inline int getWindowToWindowSnap(void) const
224 { return resource
.snap_to_windows
; }
225 inline int getWindowToEdgeSnap(void) const
226 { return resource
.snap_to_edges
; }
227 inline bool getWindowCornerSnap(void) const
228 { return resource
.window_corner_snap
; }
229 inline bool allowScrollLock(void) const { return resource
.allow_scroll_lock
; }
230 inline bool doWorkspaceWarping(void) const
231 { return resource
.workspace_warping
; }
232 inline int rootScrollDirection(void) const { return resource
.root_scroll
; }
234 inline const GC
&getOpGC(void) const { return opGC
; }
236 inline Blackbox
*getBlackbox(void) { return blackbox
; }
237 inline BColor
*getBorderColor(void) { return &resource
.border_color
; }
238 inline BImageControl
*getImageControl(void) { return image_control
; }
239 inline Rootmenu
*getRootmenu(void) { return rootmenu
; }
241 inline Slit
*getSlit(void) { return slit
; }
242 inline Toolbar
*getToolbar(void) { return toolbar
; }
244 Workspace
*getWorkspace(unsigned int index
);
246 inline Workspace
*getCurrentWorkspace(void) { return current_workspace
; }
248 inline Workspacemenu
*getWorkspacemenu(void) { return workspacemenu
; }
250 inline unsigned int getHandleWidth(void) const
251 { return resource
.handle_width
; }
252 inline unsigned int getBevelWidth(void) const
253 { return resource
.bevel_width
; }
254 inline unsigned int getFrameWidth(void) const
255 { return resource
.frame_width
; }
256 inline unsigned int getBorderWidth(void) const
257 { return resource
.border_width
; }
258 inline unsigned int getResizeZones(void) const
259 { return resource
.resize_zones
; }
260 inline bool getPlaceIgnoreShaded(void) const
261 { return resource
.ignore_shaded
; }
262 inline bool getPlaceIgnoreMaximized(void) const
263 { return resource
.ignore_maximized
; }
265 inline unsigned int getCurrentWorkspaceID(void) const
266 { return current_workspace
->getID(); }
267 inline unsigned int getWorkspaceCount(void) const
268 { return workspacesList
.size(); }
269 inline unsigned int getIconCount(void) const { return iconList
.size(); }
270 inline unsigned int getNumberOfWorkspaces(void) const
271 { return resource
.workspaces
; }
272 inline int getPlacementPolicy(void) const
273 { return resource
.placement_policy
; }
274 inline int getSnapOffset(void) const
275 { return resource
.snap_offset
; }
276 inline int getSnapThreshold(void) const
277 { return resource
.snap_threshold
; }
278 inline int getResistanceSize(void) const
279 { return resource
.resistance_size
; }
280 inline int getRowPlacementDirection(void) const
281 { return resource
.row_direction
; }
282 inline int getColPlacementDirection(void) const
283 { return resource
.col_direction
; }
285 void changeWorkspaceCount(unsigned int new_count
);
287 inline void setRootColormapInstalled(bool r
) { root_colormap_installed
= r
; }
288 void saveSloppyFocus(bool s
);
289 void saveAutoRaise(bool a
);
290 void saveClickRaise(bool c
);
291 void saveWorkspaces(unsigned int w
);
292 void savePlacementPolicy(int p
);
293 void saveRowPlacementDirection(int d
);
294 void saveColPlacementDirection(int d
);
295 void saveSnapThreshold(int t
);
296 void saveSnapOffset(int o
);
297 void saveResistanceSize(int s
);
298 void saveImageDither(bool d
);
299 void saveAAFonts(bool f
);
300 void saveOpaqueMove(bool o
);
301 void saveFullMax(bool f
);
302 void saveFocusNew(bool f
);
303 void saveFocusLast(bool f
);
304 void saveHideToolbar(bool h
);
305 void saveWindowToEdgeSnap(int s
);
306 void saveWindowToWindowSnap(int s
);
307 void saveWindowCornerSnap(bool s
);
308 void saveResizeZones(unsigned int z
);
309 void savePlaceIgnoreShaded(bool i
);
310 void savePlaceIgnoreMaximized(bool i
);
311 void saveAllowScrollLock(bool a
);
312 void saveWorkspaceWarping(bool w
);
313 void saveRootScrollDirection(int d
);
314 inline void iconUpdate(void) { iconmenu
->update(); }
317 inline const char *getStrftimeFormat(void)
318 { return resource
.strftime_format
.c_str(); }
319 void saveStrftimeFormat(const std::string
& format
);
320 #else // !HAVE_STRFTIME
321 inline int getDateFormat(void) { return resource
.date_format
; }
322 inline void saveDateFormat(int f
);
323 inline bool isClock24Hour(void) { return resource
.clock24hour
; }
324 inline void saveClock24Hour(bool c
);
325 #endif // HAVE_STRFTIME
327 inline WindowStyle
*getWindowStyle(void) { return &resource
.wstyle
; }
328 inline MenuStyle
*getMenuStyle(void) { return &resource
.mstyle
; }
329 inline ToolbarStyle
*getToolbarStyle(void) { return &resource
.tstyle
; }
331 BlackboxWindow
*getIcon(unsigned int index
);
333 // allAvailableAreas should be used whenever possible instead of this function
334 // as then Xinerama will work correctly.
335 const Rect
& availableArea(void) const;
337 const RectList
& allAvailableAreas(void) const;
339 void updateAvailableArea(void);
340 void addStrut(Strut
*strut
);
341 void removeStrut(Strut
*strut
);
343 unsigned int addWorkspace(void);
344 unsigned int removeLastWorkspace(void);
345 void changeWorkspaceID(unsigned int id
);
346 void saveWorkspaceNames(void);
348 void addNetizen(Netizen
*n
);
349 void removeNetizen(Window w
);
351 void addSystrayWindow(Window window
);
352 void removeSystrayWindow(Window window
);
354 void addIcon(BlackboxWindow
*w
);
355 void removeIcon(BlackboxWindow
*w
);
357 void updateClientList(void);
358 void updateStackingList(void);
359 void manageWindow(Window w
);
360 void unmanageWindow(BlackboxWindow
*w
, bool remap
);
361 void raiseWindows(Window
*workspace_stack
, unsigned int num
);
362 void lowerWindows(Window
*workspace_stack
, unsigned int num
);
363 void reassociateWindow(BlackboxWindow
*w
, unsigned int wkspc_id
,
365 void propagateWindowName(const BlackboxWindow
*bw
);
366 void prevFocus(void);
367 void nextFocus(void);
368 void raiseFocus(void);
371 void reconfigure(void);
372 void toggleFocusModel(FocusModel model
);
373 void rereadMenu(void);
375 void showPosition(int x
, int y
);
376 void showGeometry(unsigned int gx
, unsigned int gy
);
377 void hideGeometry(void);
379 void buttonPressEvent(const XButtonEvent
*xbutton
);
380 void propertyNotifyEvent(const XPropertyEvent
*pe
);
382 void updateNetizenCurrentWorkspace(void);
383 void updateNetizenWorkspaceCount(void);
384 void updateNetizenWindowFocus(void);
385 void updateNetizenWindowAdd(Window w
, unsigned long p
);
386 void updateNetizenWindowDel(Window w
);
387 void updateNetizenConfigNotify(XEvent
*e
);
388 void updateNetizenWindowRaise(Window w
);
389 void updateNetizenWindowLower(Window w
);
393 #endif // __Screen_hh