]> Dogcows Code - chaz/openbox/blob - src/Screen.hh
3ed724f99f8674fc0cf317ecaea7a058f5fbbdf2
[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 #include <X11/Xresource.h>
30
31 #ifdef TIME_WITH_SYS_TIME
32 # include <sys/time.h>
33 # include <time.h>
34 #else // !TIME_WITH_SYS_TIME
35 # ifdef HAVE_SYS_TIME_H
36 # include <sys/time.h>
37 # else // !HAVE_SYS_TIME_H
38 # include <time.h>
39 # endif // HAVE_SYS_TIME_H
40 #endif // TIME_WITH_SYS_TIME
41 }
42
43 #include <list>
44 #include <vector>
45
46 #include "Color.hh"
47 #include "Texture.hh"
48 #include "Image.hh"
49 #include "Configmenu.hh"
50 #include "Iconmenu.hh"
51 #include "Netizen.hh"
52 #include "Rootmenu.hh"
53 #include "Timer.hh"
54 #include "Workspace.hh"
55 #include "Workspacemenu.hh"
56 #include "blackbox.hh"
57 class Slit; // forward reference
58
59 enum TextJustify { LeftJustify = 1, RightJustify, CenterJustify };
60
61 struct WindowStyle {
62 BColor f_focus, f_unfocus, l_text_focus, l_text_unfocus, b_pic_focus,
63 b_pic_unfocus;
64 BTexture t_focus, t_unfocus, l_focus, l_unfocus, h_focus, h_unfocus,
65 b_focus, b_unfocus, b_pressed, g_focus, g_unfocus;
66
67 XFontSet fontset;
68 XFontSetExtents *fontset_extents;
69 XFontStruct *font;
70
71 TextJustify justify;
72
73 int doJustify(const char *text, int &start_pos, unsigned int max_length,
74 unsigned int modifier, bool multibyte) const;
75 };
76
77 struct ToolbarStyle {
78 BColor l_text, w_text, c_text, b_pic;
79 BTexture toolbar, label, window, button, pressed, clock;
80
81 XFontSet fontset;
82 XFontSetExtents *fontset_extents;
83 XFontStruct *font;
84
85 TextJustify justify;
86
87 int doJustify(const char *text, int &start_pos, unsigned int max_length,
88 unsigned int modifier, bool multibyte) const;
89 };
90
91 struct MenuStyle {
92 BColor t_text, f_text, h_text, d_text;
93 BTexture title, frame, hilite;
94
95 XFontSet t_fontset, f_fontset;
96 XFontSetExtents *t_fontset_extents, *f_fontset_extents;
97 XFontStruct *t_font, *f_font;
98
99 TextJustify t_justify, f_justify;
100 int bullet, bullet_pos;
101 };
102
103 struct Strut {
104 unsigned int top, bottom, left, right;
105
106 Strut(void): top(0), bottom(0), left(0), right(0) {}
107 };
108
109 class BScreen : public ScreenInfo {
110 private:
111 bool root_colormap_installed, managed, geom_visible;
112 GC opGC;
113 Pixmap geom_pixmap;
114 Window geom_window;
115
116 Blackbox *blackbox;
117 BImageControl *image_control;
118 Configmenu *configmenu;
119 Iconmenu *iconmenu;
120 Rootmenu *rootmenu;
121 Configuration *config;
122
123 typedef std::list<Rootmenu*> RootmenuList;
124 RootmenuList rootmenuList;
125
126 typedef std::list<Netizen*> NetizenList;
127 NetizenList netizenList;
128 BlackboxWindowList iconList, windowList;
129
130 Slit *slit;
131 Toolbar *toolbar;
132 Workspace *current_workspace;
133 Workspacemenu *workspacemenu;
134
135 unsigned int geom_w, geom_h;
136 unsigned long event_mask;
137
138 Rect usableArea;
139
140 typedef std::list<Strut*> StrutList;
141 StrutList strutList;
142 typedef std::vector<std::string> WorkspaceNamesList;
143 WorkspaceNamesList workspaceNames;
144 typedef std::vector<Workspace*> WorkspaceList;
145 WorkspaceList workspacesList;
146
147 struct screen_resource {
148 WindowStyle wstyle;
149 ToolbarStyle tstyle;
150 MenuStyle mstyle;
151
152 bool sloppy_focus, auto_raise, auto_edge_balance, ordered_dither,
153 opaque_move, full_max, focus_new, focus_last, click_raise,
154 hide_toolbar;
155 BColor border_color;
156
157 unsigned int workspaces;
158 int toolbar_placement, toolbar_width_percent, placement_policy,
159 edge_snap_threshold, row_direction, col_direction;
160
161 unsigned int handle_width, bevel_width, frame_width, border_width;
162
163 #ifdef HAVE_STRFTIME
164 std::string strftime_format;
165 #else // !HAVE_STRFTIME
166 bool clock24hour;
167 int date_format;
168 #endif // HAVE_STRFTIME
169
170 } resource;
171 std::string screenstr;
172
173 BScreen(const BScreen&);
174 BScreen& operator=(const BScreen&);
175
176 bool parseMenuFile(FILE *file, Rootmenu *menu);
177
178 BTexture readDatabaseTexture(const std::string &rname,
179 const std::string &default_color,
180 Configuration &style);
181 BColor readDatabaseColor(const std::string &rname,
182 const std::string &default_color,
183 Configuration &style);
184 XFontSet readDatabaseFontSet(const std::string &rname, Configuration &style);
185 XFontStruct *readDatabaseFont(const std::string &rname, Configuration &style);
186 XFontSet createFontSet(const std::string &fontname);
187
188 void InitMenu(void);
189 void LoadStyle(void);
190
191
192 public:
193 enum { RowSmartPlacement = 1, ColSmartPlacement, CascadePlacement,
194 UnderMousePlacement, LeftRight, RightLeft, TopBottom, BottomTop };
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
201 BScreen(Blackbox *bb, unsigned int scrn);
202 ~BScreen(void);
203
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 doImageDither(void) const { return image_control->doDither(); }
211 inline bool doOrderedDither(void) const { return resource.ordered_dither; }
212 inline bool doOpaqueMove(void) const { return resource.opaque_move; }
213 inline bool doFullMax(void) const { return resource.full_max; }
214 inline bool doFocusNew(void) const { return resource.focus_new; }
215 inline bool doFocusLast(void) const { return resource.focus_last; }
216 inline bool doHideToolbar(void) const { return resource.hide_toolbar; }
217
218 inline const GC &getOpGC(void) const { return opGC; }
219
220 inline Blackbox *getBlackbox(void) { return blackbox; }
221 inline BColor *getBorderColor(void) { return &resource.border_color; }
222 inline BImageControl *getImageControl(void) { return image_control; }
223 inline Rootmenu *getRootmenu(void) { return rootmenu; }
224
225 inline Slit *getSlit(void) { return slit; }
226 inline Toolbar *getToolbar(void) { return toolbar; }
227
228 Workspace *getWorkspace(unsigned int index);
229
230 inline Workspace *getCurrentWorkspace(void) { return current_workspace; }
231
232 inline Workspacemenu *getWorkspacemenu(void) { return workspacemenu; }
233
234 inline unsigned int getHandleWidth(void) const
235 { return resource.handle_width; }
236 inline unsigned int getBevelWidth(void) const
237 { return resource.bevel_width; }
238 inline unsigned int getFrameWidth(void) const
239 { return resource.frame_width; }
240 inline unsigned int getBorderWidth(void) const
241 { return resource.border_width; }
242
243 inline unsigned int getCurrentWorkspaceID(void)
244 { return current_workspace->getID(); }
245 inline unsigned int getWorkspaceCount(void)
246 { return workspacesList.size(); }
247 inline unsigned int getIconCount(void) { return iconList.size(); }
248 inline unsigned int getNumberOfWorkspaces(void) const
249 { return resource.workspaces; }
250 inline int getPlacementPolicy(void) const
251 { return resource.placement_policy; }
252 inline int getEdgeSnapThreshold(void) const
253 { return resource.edge_snap_threshold; }
254 inline int getRowPlacementDirection(void) const
255 { return resource.row_direction; }
256 inline int getColPlacementDirection(void) const
257 { return resource.col_direction; }
258
259 inline void setRootColormapInstalled(bool r) { root_colormap_installed = r; }
260 void saveSloppyFocus(bool s);
261 void saveAutoRaise(bool a);
262 void saveClickRaise(bool c);
263 void saveWorkspaces(unsigned int w);
264 void savePlacementPolicy(int p);
265 void saveRowPlacementDirection(int d);
266 void saveColPlacementDirection(int d);
267 void saveEdgeSnapThreshold(int t);
268 void saveImageDither(bool d);
269 void saveOpaqueMove(bool o);
270 void saveFullMax(bool f);
271 void saveFocusNew(bool f);
272 void saveFocusLast(bool f);
273 void saveHideToolbar(bool h);
274 inline void iconUpdate(void) { iconmenu->update(); }
275
276 #ifdef HAVE_STRFTIME
277 inline const char *getStrftimeFormat(void)
278 { return resource.strftime_format.c_str(); }
279 void saveStrftimeFormat(const std::string& format);
280 #else // !HAVE_STRFTIME
281 inline int getDateFormat(void) { return resource.date_format; }
282 inline void saveDateFormat(int f);
283 inline bool isClock24Hour(void) { return resource.clock24hour; }
284 inline void saveClock24Hour(bool c);
285 #endif // HAVE_STRFTIME
286
287 inline WindowStyle *getWindowStyle(void) { return &resource.wstyle; }
288 inline MenuStyle *getMenuStyle(void) { return &resource.mstyle; }
289 inline ToolbarStyle *getToolbarStyle(void) { return &resource.tstyle; }
290
291 BlackboxWindow *getIcon(unsigned int index);
292
293 const Rect& availableArea(void) const;
294 void updateAvailableArea(void);
295 void addStrut(Strut *strut);
296 void removeStrut(Strut *strut);
297
298 unsigned int addWorkspace(void);
299 unsigned int removeLastWorkspace(void);
300 void removeWorkspaceNames(void);
301 void addWorkspaceName(const std::string& name);
302 const std::string getNameOfWorkspace(unsigned int id);
303 void changeWorkspaceID(unsigned int id);
304 void saveWorkspaceNames(void);
305
306 void addNetizen(Netizen *n);
307 void removeNetizen(Window w);
308
309 void addIcon(BlackboxWindow *w);
310 void removeIcon(BlackboxWindow *w);
311
312 void manageWindow(Window w);
313 void unmanageWindow(BlackboxWindow *w, bool remap);
314 void raiseWindows(Window *workspace_stack, unsigned int num);
315 void reassociateWindow(BlackboxWindow *w, unsigned int wkspc_id,
316 bool ignore_sticky);
317 void propagateWindowName(const BlackboxWindow *bw);
318 void prevFocus(void);
319 void nextFocus(void);
320 void raiseFocus(void);
321 void load_rc(void);
322 void save_rc(void);
323 void reconfigure(void);
324 void toggleFocusModel(FocusModel model);
325 void updateFocusModel(void);
326 void rereadMenu(void);
327 void shutdown(void);
328 void showPosition(int x, int y);
329 void showGeometry(unsigned int gx, unsigned int gy);
330 void hideGeometry(void);
331
332 void buttonPressEvent(XButtonEvent *xbutton);
333
334 void updateNetizenCurrentWorkspace(void);
335 void updateNetizenWorkspaceCount(void);
336 void updateNetizenWindowFocus(void);
337 void updateNetizenWindowAdd(Window w, unsigned long p);
338 void updateNetizenWindowDel(Window w);
339 void updateNetizenConfigNotify(XEvent *e);
340 void updateNetizenWindowRaise(Window w);
341 void updateNetizenWindowLower(Window w);
342 };
343
344
345 #endif // __Screen_hh
This page took 0.052444 seconds and 4 git commands to generate.