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)
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.
29 #include <X11/Xresource.h>
33 #endif // HAVE_STDIO_H
35 #ifdef TIME_WITH_SYS_TIME
36 # include <sys/time.h>
38 #else // !TIME_WITH_SYS_TIME
39 # ifdef HAVE_SYS_TIME_H
40 # include <sys/time.h>
41 # else // !HAVE_SYS_TIME_H
43 # endif // HAVE_SYS_TIME_H
44 #endif // TIME_WITH_SYS_TIME
52 #include "BaseDisplay.hh"
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)
64 #define StackNormal (1)
65 #define StackBottom (2)
68 #define DecorNormal (1)
72 struct BlackboxHints
{
73 unsigned long flags
, attrib
, workspace
, stack
, decoration
;
76 struct BlackboxAttributes
{
77 unsigned long flags
, attrib
, workspace
, stack
, decoration
;
78 int premax_x
, premax_y
;
79 unsigned int premax_w
, premax_h
;
82 #define PropBlackboxHintsElements (5)
83 #define PropBlackboxAttributesElements (9)
97 class Blackbox
: public BaseDisplay
, public TimeoutHandler
{
100 Cursor session
, move
, ll_angle
, lr_angle
;
104 struct MenuTimestamp
{
105 std::string filename
;
110 Time double_click_interval
;
112 std::string menu_file
, style_file
;
113 int colors_per_channel
;
114 timeval auto_raise_delay
;
115 unsigned long cache_life
, cache_max
;
118 typedef std::map
<Window
, BlackboxWindow
*> WindowLookup
;
119 typedef WindowLookup::value_type WindowLookupPair
;
120 WindowLookup windowSearchList
;
122 typedef std::map
<Window
, BWindowGroup
*> GroupLookup
;
123 typedef GroupLookup::value_type GroupLookupPair
;
124 GroupLookup groupSearchList
;
126 typedef std::map
<Window
, Basemenu
*> MenuLookup
;
127 typedef MenuLookup::value_type MenuLookupPair
;
128 MenuLookup menuSearchList
;
130 typedef std::map
<Window
, Toolbar
*> ToolbarLookup
;
131 typedef ToolbarLookup::value_type ToolbarLookupPair
;
132 ToolbarLookup toolbarSearchList
;
134 typedef std::map
<Window
, Slit
*> SlitLookup
;
135 typedef SlitLookup::value_type SlitLookupPair
;
136 SlitLookup slitSearchList
;
138 typedef std::list
<MenuTimestamp
*> MenuTimestampList
;
139 MenuTimestampList menuTimestamps
;
141 typedef std::list
<BScreen
*> ScreenList
;
142 ScreenList screenList
;
144 BScreen
*active_screen
;
145 BlackboxWindow
*focused_window
;
148 bool no_focus
, reconfigure_wait
, reread_menu_wait
;
153 Atom xa_wm_colormap_windows
, xa_wm_protocols
, xa_wm_state
,
154 xa_wm_delete_window
, xa_wm_take_focus
, xa_wm_change_state
,
158 Atom blackbox_attributes
, blackbox_change_attributes
, blackbox_hints
;
161 #endif // HAVE_GETPID
163 // NETStructureMessages
164 Atom blackbox_structure_messages
, blackbox_notify_startup
,
165 blackbox_notify_window_add
, blackbox_notify_window_del
,
166 blackbox_notify_window_focus
, blackbox_notify_current_workspace
,
167 blackbox_notify_workspace_count
, blackbox_notify_window_raise
,
168 blackbox_notify_window_lower
;
170 // message_types for client -> wm messages
171 Atom blackbox_change_workspace
, blackbox_change_window_focus
,
172 blackbox_cycle_window_focus
;
175 // root window properties
176 Atom net_supported
, net_client_list
, net_client_list_stacking
,
177 net_number_of_desktops
, net_desktop_geometry
, net_desktop_viewport
,
178 net_current_desktop
, net_desktop_names
, net_active_window
, net_workarea
,
179 net_supporting_wm_check
, net_virtual_roots
;
181 // root window messages
182 Atom net_close_window
, net_wm_moveresize
;
184 // application window properties
185 Atom net_properties
, net_wm_name
, net_wm_desktop
, net_wm_window_type
,
186 net_wm_state
, net_wm_strut
, net_wm_icon_geometry
, net_wm_icon
, net_wm_pid
,
187 net_wm_handled_icons
;
189 // application protocols
193 Blackbox(const Blackbox
&);
194 Blackbox
& operator=(const Blackbox
&);
198 void reload_rc(void);
199 void real_rereadMenu(void);
200 void real_reconfigure(void);
202 void init_icccm(void);
204 virtual void process_event(XEvent
*);
208 Blackbox(char **m_argv
, char *dpy_name
= 0, char *rc
= 0);
209 virtual ~Blackbox(void);
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
);
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
);
229 inline BlackboxWindow
*getFocusedWindow(void) { return focused_window
; }
231 inline const Time
&getDoubleClickInterval(void) const
232 { return resource
.double_click_interval
; }
233 inline const Time
&getLastTime(void) const { return last_time
; }
235 inline const char *getStyleFilename(void) const
236 { return resource
.style_file
.c_str(); }
237 inline const char *getMenuFilename(void) const
238 { return resource
.menu_file
.c_str(); }
240 inline int getColorsPerChannel(void) const
241 { return resource
.colors_per_channel
; }
243 inline const timeval
&getAutoRaiseDelay(void) const
244 { return resource
.auto_raise_delay
; }
246 inline unsigned long getCacheLife(void) const
247 { return resource
.cache_life
; }
248 inline unsigned long getCacheMax(void) const
249 { return resource
.cache_max
; }
251 inline void setNoFocus(bool f
) { no_focus
= f
; }
253 inline Cursor
getSessionCursor(void) const
254 { return cursor
.session
; }
255 inline Cursor
getMoveCursor(void) const
256 { return cursor
.move
; }
257 inline Cursor
getLowerLeftAngleCursor(void) const
258 { return cursor
.ll_angle
; }
259 inline Cursor
getLowerRightAngleCursor(void) const
260 { return cursor
.lr_angle
; }
262 void setFocusedWindow(BlackboxWindow
*w
);
264 void load_rc(BScreen
*screen
);
265 void saveStyleFilename(const std::string
& filename
);
266 void saveMenuFilename(const std::string
& filename
);
267 void restart(const char *prog
= 0);
268 void reconfigure(void);
269 void rereadMenu(void);
270 void checkMenu(void);
272 bool validateWindow(Window window
);
274 virtual bool handleSignal(int sig
);
276 virtual void timeout(void);
278 #ifndef HAVE_STRFTIME
279 enum { B_AmericanDate
= 1, B_EuropeanDate
};
280 #endif // HAVE_STRFTIME
283 inline Atom
getBlackboxPidAtom(void) const { return blackbox_pid
; }
284 #endif // HAVE_GETPID
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
; }
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
;}
306 // these atoms are for normal app->WM interaction beyond the scope of the
308 inline Atom
getBlackboxAttributesAtom(void) const
309 { return blackbox_attributes
; }
310 inline Atom
getBlackboxChangeAttributesAtom(void) const
311 { return blackbox_change_attributes
; }
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
; }
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
; }
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
; }
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
; }
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
; }
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
; }
403 // application protocols
404 inline Atom
getNETWMPingAtom(void) const
405 { return net_wm_ping
; }
410 #endif // __blackbox_hh