]> Dogcows Code - chaz/openbox/blob - src/Screen.hh
add Configuration class for generic configuration data load/save-ing.
[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 BColor border_color;
155
156 unsigned int workspaces;
157 int toolbar_placement, toolbar_width_percent, placement_policy,
158 edge_snap_threshold, row_direction, col_direction;
159
160 unsigned int handle_width, bevel_width, frame_width, border_width;
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 Configuration &style);
180 BColor readDatabaseColor(const std::string &rname,
181 const std::string &default_color,
182 Configuration &style);
183 XFontSet readDatabaseFontSet(const std::string &rname, Configuration &style);
184 XFontStruct *readDatabaseFont(const std::string &rname, Configuration &style);
185 XFontSet createFontSet(const std::string &fontname);
186
187 void InitMenu(void);
188 void LoadStyle(void);
189
190
191 public:
192 enum { RowSmartPlacement = 1, ColSmartPlacement, CascadePlacement, LeftRight,
193 RightLeft, TopBottom, BottomTop };
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
200 BScreen(Blackbox *bb, unsigned int scrn);
201 ~BScreen(void);
202
203 inline bool isSloppyFocus(void) const { return resource.sloppy_focus; }
204 inline bool isRootColormapInstalled(void) const
205 { return root_colormap_installed; }
206 inline bool doAutoRaise(void) const { return resource.auto_raise; }
207 inline bool doClickRaise(void) const { return resource.click_raise; }
208 inline bool isScreenManaged(void) const { return managed; }
209 inline bool doImageDither(void) const { return image_control->doDither(); }
210 inline bool doOrderedDither(void) const { return resource.ordered_dither; }
211 inline bool doOpaqueMove(void) const { return resource.opaque_move; }
212 inline bool doFullMax(void) const { return resource.full_max; }
213 inline bool doFocusNew(void) const { return resource.focus_new; }
214 inline bool doFocusLast(void) const { return resource.focus_last; }
215
216 inline const GC &getOpGC(void) const { return opGC; }
217
218 inline Blackbox *getBlackbox(void) { return blackbox; }
219 inline BColor *getBorderColor(void) { return &resource.border_color; }
220 inline BImageControl *getImageControl(void) { return image_control; }
221 inline Rootmenu *getRootmenu(void) { return rootmenu; }
222
223 inline Slit *getSlit(void) { return slit; }
224 inline Toolbar *getToolbar(void) { return toolbar; }
225
226 Workspace *getWorkspace(unsigned int index);
227
228 inline Workspace *getCurrentWorkspace(void) { return current_workspace; }
229
230 inline Workspacemenu *getWorkspacemenu(void) { return workspacemenu; }
231
232 inline unsigned int getHandleWidth(void) const
233 { return resource.handle_width; }
234 inline unsigned int getBevelWidth(void) const
235 { return resource.bevel_width; }
236 inline unsigned int getFrameWidth(void) const
237 { return resource.frame_width; }
238 inline unsigned int getBorderWidth(void) const
239 { return resource.border_width; }
240
241 inline unsigned int getCurrentWorkspaceID(void)
242 { return current_workspace->getID(); }
243 inline unsigned int getWorkspaceCount(void)
244 { return workspacesList.size(); }
245 inline unsigned int getIconCount(void) { return iconList.size(); }
246 inline unsigned int getNumberOfWorkspaces(void) const
247 { return resource.workspaces; }
248 inline int getPlacementPolicy(void) const
249 { return resource.placement_policy; }
250 inline int getEdgeSnapThreshold(void) const
251 { return resource.edge_snap_threshold; }
252 inline int getRowPlacementDirection(void) const
253 { return resource.row_direction; }
254 inline int getColPlacementDirection(void) const
255 { return resource.col_direction; }
256
257 inline void setRootColormapInstalled(bool r) { root_colormap_installed = r; }
258 void saveSloppyFocus(bool s);
259 void saveAutoRaise(bool a);
260 void saveClickRaise(bool c);
261 void saveWorkspaces(unsigned int w);
262 void savePlacementPolicy(int p);
263 void saveRowPlacementDirection(int d);
264 void saveColPlacementDirection(int d);
265 void saveEdgeSnapThreshold(int t);
266 void saveImageDither(bool d);
267 void saveOpaqueMove(bool o);
268 void saveFullMax(bool f);
269 void saveFocusNew(bool f);
270 void saveFocusLast(bool f);
271 inline void iconUpdate(void) { iconmenu->update(); }
272
273 #ifdef HAVE_STRFTIME
274 inline const char *getStrftimeFormat(void)
275 { return resource.strftime_format.c_str(); }
276 void saveStrftimeFormat(const std::string& format);
277 #else // !HAVE_STRFTIME
278 inline int getDateFormat(void) { return resource.date_format; }
279 inline void saveDateFormat(int f);
280 inline bool isClock24Hour(void) { return resource.clock24hour; }
281 inline void saveClock24Hour(bool c);
282 #endif // HAVE_STRFTIME
283
284 inline WindowStyle *getWindowStyle(void) { return &resource.wstyle; }
285 inline MenuStyle *getMenuStyle(void) { return &resource.mstyle; }
286 inline ToolbarStyle *getToolbarStyle(void) { return &resource.tstyle; }
287
288 BlackboxWindow *getIcon(unsigned int index);
289
290 const Rect& availableArea(void) const;
291 void updateAvailableArea(void);
292 void addStrut(Strut *strut);
293 void removeStrut(Strut *strut);
294
295 unsigned int addWorkspace(void);
296 unsigned int removeLastWorkspace(void);
297 void removeWorkspaceNames(void);
298 void addWorkspaceName(const std::string& name);
299 const std::string getNameOfWorkspace(unsigned int id);
300 void changeWorkspaceID(unsigned int id);
301 void saveWorkspaceNames(void);
302
303 void addNetizen(Netizen *n);
304 void removeNetizen(Window w);
305
306 void addIcon(BlackboxWindow *w);
307 void removeIcon(BlackboxWindow *w);
308
309 void manageWindow(Window w);
310 void unmanageWindow(BlackboxWindow *w, bool remap);
311 void raiseWindows(Window *workspace_stack, unsigned int num);
312 void reassociateWindow(BlackboxWindow *w, unsigned int wkspc_id,
313 bool ignore_sticky);
314 void propagateWindowName(const BlackboxWindow *bw);
315 void prevFocus(void);
316 void nextFocus(void);
317 void raiseFocus(void);
318 void load_rc(void);
319 void save_rc(void);
320 void reconfigure(void);
321 void toggleFocusModel(FocusModel model);
322 void updateFocusModel(void);
323 void rereadMenu(void);
324 void shutdown(void);
325 void showPosition(int x, int y);
326 void showGeometry(unsigned int gx, unsigned int gy);
327 void hideGeometry(void);
328
329 void buttonPressEvent(XButtonEvent *xbutton);
330
331 void updateNetizenCurrentWorkspace(void);
332 void updateNetizenWorkspaceCount(void);
333 void updateNetizenWindowFocus(void);
334 void updateNetizenWindowAdd(Window w, unsigned long p);
335 void updateNetizenWindowDel(Window w);
336 void updateNetizenConfigNotify(XEvent *e);
337 void updateNetizenWindowRaise(Window w);
338 void updateNetizenWindowLower(Window w);
339 };
340
341
342 #endif // __Screen_hh
This page took 0.057392 seconds and 5 git commands to generate.