]> Dogcows Code - chaz/openbox/blob - src/Screen.hh
snapping/resistance is optional for window and edge snapping
[chaz/openbox] / src / Screen.hh
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)
5 //
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:
12 //
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
15 //
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.
23
24 #ifndef __Screen_hh
25 #define __Screen_hh
26
27 extern "C" {
28 #include <X11/Xlib.h>
29
30 #ifdef TIME_WITH_SYS_TIME
31 # include <sys/time.h>
32 # include <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
37 # include <time.h>
38 # endif // HAVE_SYS_TIME_H
39 #endif // TIME_WITH_SYS_TIME
40 }
41
42 #include <list>
43 #include <vector>
44
45 #include "Color.hh"
46 #include "Texture.hh"
47 #include "Image.hh"
48 #include "Configmenu.hh"
49 #include "Iconmenu.hh"
50 #include "Netizen.hh"
51 #include "Rootmenu.hh"
52 #include "Timer.hh"
53 #include "Workspace.hh"
54 #include "Workspacemenu.hh"
55 #include "blackbox.hh"
56
57 class Slit; // forward reference
58 class BFont;
59 class XAtom;
60 struct Strut;
61
62 enum TextJustify { LeftJustify = 1, RightJustify, CenterJustify };
63
64 struct WindowStyle {
65 BColor f_focus, f_unfocus, l_text_focus, l_text_unfocus, b_pic_focus,
66 b_pic_unfocus;
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;
69
70 BFont *font;
71
72 TextJustify justify;
73
74 void doJustify(const std::string &text, int &start_pos,
75 unsigned int max_length, unsigned int modifier) const;
76 };
77
78 struct ToolbarStyle {
79 BColor l_text, w_text, c_text, b_pic;
80 BTexture toolbar, label, window, button, pressed, clock;
81
82 BFont *font;
83
84 TextJustify justify;
85
86 void doJustify(const std::string &text, int &start_pos,
87 unsigned int max_length, unsigned int modifier) const;
88 };
89
90 struct MenuStyle {
91 BColor t_text, f_text, h_text, d_text;
92 BTexture title, frame, hilite;
93
94 BFont *t_font, *f_font;
95
96 TextJustify t_justify, f_justify;
97 int bullet, bullet_pos;
98 };
99
100 class BScreen : public ScreenInfo {
101 private:
102 bool root_colormap_installed, managed, geom_visible;
103 GC opGC;
104 Pixmap geom_pixmap;
105 Window geom_window;
106
107 Blackbox *blackbox;
108 BImageControl *image_control;
109 Configmenu *configmenu;
110 Iconmenu *iconmenu;
111 Rootmenu *rootmenu;
112 Configuration *config;
113 XAtom *xatom;
114
115 typedef std::list<Rootmenu*> RootmenuList;
116 RootmenuList rootmenuList;
117
118 typedef std::list<Netizen*> NetizenList;
119 NetizenList netizenList;
120 BlackboxWindowList iconList, windowList;
121
122 typedef std::vector<Window> WindowList;
123 WindowList desktopWindowList, systrayWindowList;
124
125 Slit *slit;
126 Toolbar *toolbar;
127 Workspace *current_workspace;
128 Workspacemenu *workspacemenu;
129
130 unsigned int geom_w, geom_h;
131 unsigned long event_mask;
132
133 Rect usableArea;
134 #ifdef XINERAMA
135 RectList xineramaUsableArea;
136 #endif // XINERAMA
137
138 typedef std::list<Strut*> StrutList;
139 StrutList strutList;
140 typedef std::vector<Workspace*> WorkspaceList;
141 WorkspaceList workspacesList;
142
143 struct screen_resource {
144 WindowStyle wstyle;
145 ToolbarStyle tstyle;
146 MenuStyle mstyle;
147
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,
152 workspace_warping;
153 BColor border_color;
154
155 unsigned int workspaces;
156 int toolbar_placement, toolbar_width_percent, placement_policy,
157 edge_snap_threshold, row_direction, col_direction, root_scroll;
158
159 unsigned int handle_width, bevel_width, frame_width, border_width,
160 resize_zones;
161
162 #ifdef HAVE_STRFTIME
163 std::string strftime_format;
164 #else // !HAVE_STRFTIME
165 bool clock24hour;
166 int date_format;
167 #endif // HAVE_STRFTIME
168
169 } resource;
170 std::string screenstr;
171
172 BScreen(const BScreen&);
173 BScreen& operator=(const BScreen&);
174
175 bool parseMenuFile(FILE *file, Rootmenu *menu);
176
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);
185
186 void InitMenu(void);
187 void LoadStyle(void);
188
189 void updateWorkArea(void);
190 public:
191 enum { WindowNoSnap = 0, WindowSnap, WindowResistance };
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 };
200 enum RootScrollDirection { NoScroll = 0, NormalScroll, ReverseScroll };
201
202 BScreen(Blackbox *bb, unsigned int scrn);
203 ~BScreen(void);
204
205 inline bool isSloppyFocus(void) const { return resource.sloppy_focus; }
206 inline bool isRootColormapInstalled(void) const
207 { return root_colormap_installed; }
208 inline bool doAutoRaise(void) const { return resource.auto_raise; }
209 inline bool doClickRaise(void) const { return resource.click_raise; }
210 inline bool isScreenManaged(void) const { return managed; }
211 inline bool doAAFonts(void) const { return resource.aa_fonts; }
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; }
219 inline bool getWindowToWindowSnap(void) const
220 { return resource.window_to_window_snap; }
221 inline bool getWindowCornerSnap(void) const
222 { return resource.window_corner_snap; }
223 inline bool allowScrollLock(void) const { return resource.allow_scroll_lock; }
224 inline bool doWorkspaceWarping(void) const
225 { return resource.workspace_warping; }
226 inline int rootScrollDirection(void) const { return resource.root_scroll; }
227
228 inline const GC &getOpGC(void) const { return opGC; }
229
230 inline Blackbox *getBlackbox(void) { return blackbox; }
231 inline BColor *getBorderColor(void) { return &resource.border_color; }
232 inline BImageControl *getImageControl(void) { return image_control; }
233 inline Rootmenu *getRootmenu(void) { return rootmenu; }
234
235 inline Slit *getSlit(void) { return slit; }
236 inline Toolbar *getToolbar(void) { return toolbar; }
237
238 Workspace *getWorkspace(unsigned int index);
239
240 inline Workspace *getCurrentWorkspace(void) { return current_workspace; }
241
242 inline Workspacemenu *getWorkspacemenu(void) { return workspacemenu; }
243
244 inline unsigned int getHandleWidth(void) const
245 { return resource.handle_width; }
246 inline unsigned int getBevelWidth(void) const
247 { return resource.bevel_width; }
248 inline unsigned int getFrameWidth(void) const
249 { return resource.frame_width; }
250 inline unsigned int getBorderWidth(void) const
251 { return resource.border_width; }
252 inline unsigned int getResizeZones(void) const
253 { return resource.resize_zones; }
254 inline bool getPlaceIgnoreShaded(void) const
255 { return resource.ignore_shaded; }
256 inline bool getPlaceIgnoreMaximized(void) const
257 { return resource.ignore_maximized; }
258
259 inline unsigned int getCurrentWorkspaceID(void) const
260 { return current_workspace->getID(); }
261 inline unsigned int getWorkspaceCount(void) const
262 { return workspacesList.size(); }
263 inline unsigned int getIconCount(void) const { return iconList.size(); }
264 inline unsigned int getNumberOfWorkspaces(void) const
265 { return resource.workspaces; }
266 inline int getPlacementPolicy(void) const
267 { return resource.placement_policy; }
268 inline int getEdgeSnapThreshold(void) const
269 { return resource.edge_snap_threshold; }
270 inline int getRowPlacementDirection(void) const
271 { return resource.row_direction; }
272 inline int getColPlacementDirection(void) const
273 { return resource.col_direction; }
274
275 void changeWorkspaceCount(unsigned int new_count);
276
277 inline void setRootColormapInstalled(bool r) { root_colormap_installed = r; }
278 void saveSloppyFocus(bool s);
279 void saveAutoRaise(bool a);
280 void saveClickRaise(bool c);
281 void saveWorkspaces(unsigned int w);
282 void savePlacementPolicy(int p);
283 void saveRowPlacementDirection(int d);
284 void saveColPlacementDirection(int d);
285 void saveEdgeSnapThreshold(int t);
286 void saveImageDither(bool d);
287 void saveAAFonts(bool f);
288 void saveOpaqueMove(bool o);
289 void saveFullMax(bool f);
290 void saveFocusNew(bool f);
291 void saveFocusLast(bool f);
292 void saveHideToolbar(bool h);
293 void saveWindowToWindowSnap(bool s);
294 void saveWindowCornerSnap(bool s);
295 void saveResizeZones(unsigned int z);
296 void savePlaceIgnoreShaded(bool i);
297 void savePlaceIgnoreMaximized(bool i);
298 void saveAllowScrollLock(bool a);
299 void saveWorkspaceWarping(bool w);
300 void saveRootScrollDirection(int d);
301 inline void iconUpdate(void) { iconmenu->update(); }
302
303 #ifdef HAVE_STRFTIME
304 inline const char *getStrftimeFormat(void)
305 { return resource.strftime_format.c_str(); }
306 void saveStrftimeFormat(const std::string& format);
307 #else // !HAVE_STRFTIME
308 inline int getDateFormat(void) { return resource.date_format; }
309 inline void saveDateFormat(int f);
310 inline bool isClock24Hour(void) { return resource.clock24hour; }
311 inline void saveClock24Hour(bool c);
312 #endif // HAVE_STRFTIME
313
314 inline WindowStyle *getWindowStyle(void) { return &resource.wstyle; }
315 inline MenuStyle *getMenuStyle(void) { return &resource.mstyle; }
316 inline ToolbarStyle *getToolbarStyle(void) { return &resource.tstyle; }
317
318 BlackboxWindow *getIcon(unsigned int index);
319
320 // allAvailableAreas should be used whenever possible instead of this function
321 // as then Xinerama will work correctly.
322 const Rect& availableArea(void) const;
323 #ifdef XINERAMA
324 const RectList& allAvailableAreas(void) const;
325 #endif // XINERAMA
326 void updateAvailableArea(void);
327 void addStrut(Strut *strut);
328 void removeStrut(Strut *strut);
329
330 unsigned int addWorkspace(void);
331 unsigned int removeLastWorkspace(void);
332 void changeWorkspaceID(unsigned int id);
333 void saveWorkspaceNames(void);
334
335 void addNetizen(Netizen *n);
336 void removeNetizen(Window w);
337
338 void addSystrayWindow(Window window);
339 void removeSystrayWindow(Window window);
340
341 void addIcon(BlackboxWindow *w);
342 void removeIcon(BlackboxWindow *w);
343
344 void updateClientList(void);
345 void updateStackingList(void);
346 void manageWindow(Window w);
347 void unmanageWindow(BlackboxWindow *w, bool remap);
348 void raiseWindows(Window *workspace_stack, unsigned int num);
349 void lowerWindows(Window *workspace_stack, unsigned int num);
350 void reassociateWindow(BlackboxWindow *w, unsigned int wkspc_id,
351 bool ignore_sticky);
352 void propagateWindowName(const BlackboxWindow *bw);
353 void prevFocus(void);
354 void nextFocus(void);
355 void raiseFocus(void);
356 void load_rc(void);
357 void save_rc(void);
358 void reconfigure(void);
359 void toggleFocusModel(FocusModel model);
360 void rereadMenu(void);
361 void shutdown(void);
362 void showPosition(int x, int y);
363 void showGeometry(unsigned int gx, unsigned int gy);
364 void hideGeometry(void);
365
366 void buttonPressEvent(const XButtonEvent *xbutton);
367 void propertyNotifyEvent(const XPropertyEvent *pe);
368
369 void updateNetizenCurrentWorkspace(void);
370 void updateNetizenWorkspaceCount(void);
371 void updateNetizenWindowFocus(void);
372 void updateNetizenWindowAdd(Window w, unsigned long p);
373 void updateNetizenWindowDel(Window w);
374 void updateNetizenConfigNotify(XEvent *e);
375 void updateNetizenWindowRaise(Window w);
376 void updateNetizenWindowLower(Window w);
377 };
378
379
380 #endif // __Screen_hh
This page took 0.052362 seconds and 5 git commands to generate.