]> Dogcows Code - chaz/openbox/blob - src/blackbox.hh
add Configuration class for generic configuration data load/save-ing.
[chaz/openbox] / src / blackbox.hh
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 // blackbox.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 __blackbox_hh
25 #define __blackbox_hh
26
27 extern "C" {
28 #include <X11/Xlib.h>
29
30 #ifdef HAVE_STDIO_H
31 # include <stdio.h>
32 #endif // HAVE_STDIO_H
33
34 #ifdef TIME_WITH_SYS_TIME
35 # include <sys/time.h>
36 # include <time.h>
37 #else // !TIME_WITH_SYS_TIME
38 # ifdef HAVE_SYS_TIME_H
39 # include <sys/time.h>
40 # else // !HAVE_SYS_TIME_H
41 # include <time.h>
42 # endif // HAVE_SYS_TIME_H
43 #endif // TIME_WITH_SYS_TIME
44 }
45
46 #include <list>
47 #include <map>
48 #include <string>
49
50 #include "i18n.hh"
51 #include "BaseDisplay.hh"
52 #include "Configuration.hh"
53 #include "Timer.hh"
54
55 #define AttribShaded (1l << 0)
56 #define AttribMaxHoriz (1l << 1)
57 #define AttribMaxVert (1l << 2)
58 #define AttribOmnipresent (1l << 3)
59 #define AttribWorkspace (1l << 4)
60 #define AttribStack (1l << 5)
61 #define AttribDecoration (1l << 6)
62
63 #define StackTop (0)
64 #define StackNormal (1)
65 #define StackBottom (2)
66
67 #define DecorNone (0)
68 #define DecorNormal (1)
69 #define DecorTiny (2)
70 #define DecorTool (3)
71
72 struct BlackboxHints {
73 unsigned long flags, attrib, workspace, stack, decoration;
74 };
75
76 struct BlackboxAttributes {
77 unsigned long flags, attrib, workspace, stack, decoration;
78 int premax_x, premax_y;
79 unsigned int premax_w, premax_h;
80 };
81
82 #define PropBlackboxHintsElements (5)
83 #define PropBlackboxAttributesElements (9)
84
85
86 //forward declaration
87 class BScreen;
88 class Blackbox;
89 class BlackboxWindow;
90 class BWindowGroup;
91 class Basemenu;
92 class Toolbar;
93 class Slit;
94
95 extern I18n i18n;
96
97 class Blackbox : public BaseDisplay, public TimeoutHandler {
98 private:
99 struct BCursor {
100 Cursor session, move, ll_angle, lr_angle;
101 };
102 BCursor cursor;
103
104 struct MenuTimestamp {
105 std::string filename;
106 time_t timestamp;
107 };
108
109 struct BResource {
110 Time double_click_interval;
111
112 std::string style_file;
113 int colors_per_channel;
114 timeval auto_raise_delay;
115 unsigned long cache_life, cache_max;
116 } resource;
117
118 typedef std::map<Window, BlackboxWindow*> WindowLookup;
119 typedef WindowLookup::value_type WindowLookupPair;
120 WindowLookup windowSearchList;
121
122 typedef std::map<Window, BWindowGroup*> GroupLookup;
123 typedef GroupLookup::value_type GroupLookupPair;
124 GroupLookup groupSearchList;
125
126 typedef std::map<Window, Basemenu*> MenuLookup;
127 typedef MenuLookup::value_type MenuLookupPair;
128 MenuLookup menuSearchList;
129
130 typedef std::map<Window, Toolbar*> ToolbarLookup;
131 typedef ToolbarLookup::value_type ToolbarLookupPair;
132 ToolbarLookup toolbarSearchList;
133
134 typedef std::map<Window, Slit*> SlitLookup;
135 typedef SlitLookup::value_type SlitLookupPair;
136 SlitLookup slitSearchList;
137
138 typedef std::list<MenuTimestamp*> MenuTimestampList;
139 MenuTimestampList menuTimestamps;
140
141 typedef std::list<BScreen*> ScreenList;
142 ScreenList screenList;
143
144 BScreen *active_screen;
145 BlackboxWindow *focused_window;
146 BTimer *timer;
147 Configuration config;
148
149 bool no_focus, reconfigure_wait, reread_menu_wait;
150 Time last_time;
151 char **argv;
152 std::string menu_file, rc_file;
153
154 Atom xa_wm_colormap_windows, xa_wm_protocols, xa_wm_state,
155 xa_wm_delete_window, xa_wm_take_focus, xa_wm_change_state,
156 motif_wm_hints;
157
158 // NETAttributes
159 Atom blackbox_attributes, blackbox_change_attributes, blackbox_hints;
160 #ifdef HAVE_GETPID
161 Atom blackbox_pid;
162 #endif // HAVE_GETPID
163
164 // NETStructureMessages
165 Atom blackbox_structure_messages, blackbox_notify_startup,
166 blackbox_notify_window_add, blackbox_notify_window_del,
167 blackbox_notify_window_focus, blackbox_notify_current_workspace,
168 blackbox_notify_workspace_count, blackbox_notify_window_raise,
169 blackbox_notify_window_lower;
170
171 // message_types for client -> wm messages
172 Atom blackbox_change_workspace, blackbox_change_window_focus,
173 blackbox_cycle_window_focus;
174
175 #ifdef NEWWMSPEC
176 // root window properties
177 Atom net_supported, net_client_list, net_client_list_stacking,
178 net_number_of_desktops, net_desktop_geometry, net_desktop_viewport,
179 net_current_desktop, net_desktop_names, net_active_window, net_workarea,
180 net_supporting_wm_check, net_virtual_roots;
181
182 // root window messages
183 Atom net_close_window, net_wm_moveresize;
184
185 // application window properties
186 Atom net_properties, net_wm_name, net_wm_desktop, net_wm_window_type,
187 net_wm_state, net_wm_strut, net_wm_icon_geometry, net_wm_icon, net_wm_pid,
188 net_wm_handled_icons;
189
190 // application protocols
191 Atom net_wm_ping;
192 #endif // NEWWMSPEC
193
194 Blackbox(const Blackbox&);
195 Blackbox& operator=(const Blackbox&);
196
197 void load_rc(void);
198 void save_rc(void);
199 void real_rereadMenu(void);
200 void real_reconfigure(void);
201
202 void init_icccm(void);
203
204 virtual void process_event(XEvent *);
205
206
207 public:
208 Blackbox(char **m_argv, char *dpy_name = 0, char *rc = 0, char *menu = 0);
209 virtual ~Blackbox(void);
210
211 Basemenu *searchMenu(Window window);
212 BWindowGroup *searchGroup(Window window);
213 BlackboxWindow *searchWindow(Window window);
214 BScreen *searchScreen(Window window);
215 Toolbar *searchToolbar(Window);
216 Slit *searchSlit(Window);
217
218 void saveMenuSearch(Window window, Basemenu *data);
219 void saveWindowSearch(Window window, BlackboxWindow *data);
220 void saveGroupSearch(Window window, BWindowGroup *data);
221 void saveToolbarSearch(Window window, Toolbar *data);
222 void saveSlitSearch(Window window, Slit *data);
223 void removeMenuSearch(Window window);
224 void removeWindowSearch(Window window);
225 void removeGroupSearch(Window window);
226 void removeToolbarSearch(Window window);
227 void removeSlitSearch(Window window);
228
229 inline BlackboxWindow *getFocusedWindow(void) { return focused_window; }
230
231 inline Configuration *getConfig() { return &config; }
232 inline const Time &getDoubleClickInterval(void) const
233 { return resource.double_click_interval; }
234 inline const Time &getLastTime(void) const { return last_time; }
235
236 inline const char *getStyleFilename(void) const
237 { return resource.style_file.c_str(); }
238 inline const char *getMenuFilename(void) const
239 { return menu_file.c_str(); }
240
241 inline int getColorsPerChannel(void) const
242 { return resource.colors_per_channel; }
243
244 inline const timeval &getAutoRaiseDelay(void) const
245 { return resource.auto_raise_delay; }
246
247 inline unsigned long getCacheLife(void) const
248 { return resource.cache_life; }
249 inline unsigned long getCacheMax(void) const
250 { return resource.cache_max; }
251
252 inline void setNoFocus(bool f) { no_focus = f; }
253
254 inline Cursor getSessionCursor(void) const
255 { return cursor.session; }
256 inline Cursor getMoveCursor(void) const
257 { return cursor.move; }
258 inline Cursor getLowerLeftAngleCursor(void) const
259 { return cursor.ll_angle; }
260 inline Cursor getLowerRightAngleCursor(void) const
261 { return cursor.lr_angle; }
262
263 void setFocusedWindow(BlackboxWindow *w);
264 void shutdown(void);
265 void saveStyleFilename(const std::string& filename);
266 void addMenuTimestamp(const std::string& filename);
267 void restart(const char *prog = 0);
268 void reconfigure(void);
269 void rereadMenu(void);
270 void checkMenu(void);
271
272 bool validateWindow(Window window);
273
274 virtual bool handleSignal(int sig);
275
276 virtual void timeout(void);
277
278 #ifndef HAVE_STRFTIME
279 enum { B_AmericanDate = 1, B_EuropeanDate };
280 #endif // HAVE_STRFTIME
281
282 #ifdef HAVE_GETPID
283 inline Atom getBlackboxPidAtom(void) const { return blackbox_pid; }
284 #endif // HAVE_GETPID
285
286 inline Atom getWMChangeStateAtom(void) const
287 { return xa_wm_change_state; }
288 inline Atom getWMStateAtom(void) const
289 { return xa_wm_state; }
290 inline Atom getWMDeleteAtom(void) const
291 { return xa_wm_delete_window; }
292 inline Atom getWMProtocolsAtom(void) const
293 { return xa_wm_protocols; }
294 inline Atom getWMTakeFocusAtom(void) const
295 { return xa_wm_take_focus; }
296 inline Atom getWMColormapAtom(void) const
297 { return xa_wm_colormap_windows; }
298 inline Atom getMotifWMHintsAtom(void) const
299 { return motif_wm_hints; }
300
301 // this atom is for normal app->WM hints about decorations, stacking,
302 // starting workspace etc...
303 inline Atom getBlackboxHintsAtom(void) const
304 { return blackbox_hints;}
305
306 // these atoms are for normal app->WM interaction beyond the scope of the
307 // ICCCM...
308 inline Atom getBlackboxAttributesAtom(void) const
309 { return blackbox_attributes; }
310 inline Atom getBlackboxChangeAttributesAtom(void) const
311 { return blackbox_change_attributes; }
312
313 // these atoms are for window->WM interaction, with more control and
314 // information on window "structure"... common examples are
315 // notifying apps when windows are raised/lowered... when the user changes
316 // workspaces... i.e. "pager talk"
317 inline Atom getBlackboxStructureMessagesAtom(void) const
318 { return blackbox_structure_messages; }
319
320 // *Notify* portions of the NETStructureMessages protocol
321 inline Atom getBlackboxNotifyStartupAtom(void) const
322 { return blackbox_notify_startup; }
323 inline Atom getBlackboxNotifyWindowAddAtom(void) const
324 { return blackbox_notify_window_add; }
325 inline Atom getBlackboxNotifyWindowDelAtom(void) const
326 { return blackbox_notify_window_del; }
327 inline Atom getBlackboxNotifyWindowFocusAtom(void) const
328 { return blackbox_notify_window_focus; }
329 inline Atom getBlackboxNotifyCurrentWorkspaceAtom(void) const
330 { return blackbox_notify_current_workspace; }
331 inline Atom getBlackboxNotifyWorkspaceCountAtom(void) const
332 { return blackbox_notify_workspace_count; }
333 inline Atom getBlackboxNotifyWindowRaiseAtom(void) const
334 { return blackbox_notify_window_raise; }
335 inline Atom getBlackboxNotifyWindowLowerAtom(void) const
336 { return blackbox_notify_window_lower; }
337
338 // atoms to change that request changes to the desktop environment during
339 // runtime... these messages can be sent by any client... as the sending
340 // client window id is not included in the ClientMessage event...
341 inline Atom getBlackboxChangeWorkspaceAtom(void) const
342 { return blackbox_change_workspace; }
343 inline Atom getBlackboxChangeWindowFocusAtom(void) const
344 { return blackbox_change_window_focus; }
345 inline Atom getBlackboxCycleWindowFocusAtom(void) const
346 { return blackbox_cycle_window_focus; }
347
348 #ifdef NEWWMSPEC
349 // root window properties
350 inline Atom getNETSupportedAtom(void) const
351 { return net_supported; }
352 inline Atom getNETClientListAtom(void) const
353 { return net_client_list; }
354 inline Atom getNETClientListStackingAtom(void) const
355 { return net_client_list_stacking; }
356 inline Atom getNETNumberOfDesktopsAtom(void) const
357 { return net_number_of_desktops; }
358 inline Atom getNETDesktopGeometryAtom(void) const
359 { return net_desktop_geometry; }
360 inline Atom getNETDesktopViewportAtom(void) const
361 { return net_desktop_viewport; }
362 inline Atom getNETCurrentDesktopAtom(void) const
363 { return net_current_desktop; }
364 inline Atom getNETDesktopNamesAtom(void) const
365 { return net_desktop_names; }
366 inline Atom getNETActiveWindowAtom(void) const
367 { return net_active_window; }
368 inline Atom getNETWorkareaAtom(void) const
369 { return net_workarea; }
370 inline Atom getNETSupportingWMCheckAtom(void) const
371 { return net_supporting_wm_check; }
372 inline Atom getNETVirtualRootsAtom(void) const
373 { return net_virtual_roots; }
374
375 // root window messages
376 inline Atom getNETCloseWindowAtom(void) const
377 { return net_close_window; }
378 inline Atom getNETWMMoveResizeAtom(void) const
379 { return net_wm_moveresize; }
380
381 // application window properties
382 inline Atom getNETPropertiesAtom(void) const
383 { return net_properties; }
384 inline Atom getNETWMNameAtom(void) const
385 { return net_wm_name; }
386 inline Atom getNETWMDesktopAtom(void) const
387 { return net_wm_desktop; }
388 inline Atom getNETWMWindowTypeAtom(void) const
389 { return net_wm_window_type; }
390 inline Atom getNETWMStateAtom(void) const
391 { return net_wm_state; }
392 inline Atom getNETWMStrutAtom(void) const
393 { return net_wm_strut; }
394 inline Atom getNETWMIconGeometryAtom(void) const
395 { return net_wm_icon_geometry; }
396 inline Atom getNETWMIconAtom(void) const
397 { return net_wm_icon; }
398 inline Atom getNETWMPidAtom(void) const
399 { return net_wm_pid; }
400 inline Atom getNETWMHandledIconsAtom(void) const
401 { return net_wm_handled_icons; }
402
403 // application protocols
404 inline Atom getNETWMPingAtom(void) const
405 { return net_wm_ping; }
406 #endif // NEWWMSPEC
407 };
408
409
410 #endif // __blackbox_hh
This page took 0.052437 seconds and 5 git commands to generate.