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.
32 #endif // HAVE_STDIO_H
34 #ifdef TIME_WITH_SYS_TIME
35 # include <sys/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
42 # endif // HAVE_SYS_TIME_H
43 #endif // TIME_WITH_SYS_TIME
51 #include "BaseDisplay.hh"
52 #include "Configuration.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 style_file
;
113 int colors_per_channel
;
114 timeval auto_raise_delay
;
115 unsigned long cache_life
, cache_max
;
116 std::string titlebar_layout
;
119 typedef std::map
<Window
, BlackboxWindow
*> WindowLookup
;
120 typedef WindowLookup::value_type WindowLookupPair
;
121 WindowLookup windowSearchList
;
123 typedef std::map
<Window
, BWindowGroup
*> GroupLookup
;
124 typedef GroupLookup::value_type GroupLookupPair
;
125 GroupLookup groupSearchList
;
127 typedef std::map
<Window
, Basemenu
*> MenuLookup
;
128 typedef MenuLookup::value_type MenuLookupPair
;
129 MenuLookup menuSearchList
;
131 typedef std::map
<Window
, Toolbar
*> ToolbarLookup
;
132 typedef ToolbarLookup::value_type ToolbarLookupPair
;
133 ToolbarLookup toolbarSearchList
;
135 typedef std::map
<Window
, Slit
*> SlitLookup
;
136 typedef SlitLookup::value_type SlitLookupPair
;
137 SlitLookup slitSearchList
;
139 typedef std::list
<MenuTimestamp
*> MenuTimestampList
;
140 MenuTimestampList menuTimestamps
;
142 typedef std::list
<BScreen
*> ScreenList
;
143 ScreenList screenList
;
145 BScreen
*active_screen
;
146 BlackboxWindow
*focused_window
;
148 Configuration config
;
150 bool no_focus
, reconfigure_wait
, reread_menu_wait
;
153 std::string menu_file
, rc_file
;
155 Atom xa_wm_colormap_windows
, xa_wm_protocols
, xa_wm_state
,
156 xa_wm_delete_window
, xa_wm_take_focus
, xa_wm_change_state
,
160 Atom blackbox_attributes
, blackbox_change_attributes
, blackbox_hints
;
163 #endif // HAVE_GETPID
165 // NETStructureMessages
166 Atom blackbox_structure_messages
, blackbox_notify_startup
,
167 blackbox_notify_window_add
, blackbox_notify_window_del
,
168 blackbox_notify_window_focus
, blackbox_notify_current_workspace
,
169 blackbox_notify_workspace_count
, blackbox_notify_window_raise
,
170 blackbox_notify_window_lower
;
172 // message_types for client -> wm messages
173 Atom blackbox_change_workspace
, blackbox_change_window_focus
,
174 blackbox_cycle_window_focus
;
177 // root window properties
178 Atom net_supported
, net_client_list
, net_client_list_stacking
,
179 net_number_of_desktops
, net_desktop_geometry
, net_desktop_viewport
,
180 net_current_desktop
, net_desktop_names
, net_active_window
, net_workarea
,
181 net_supporting_wm_check
, net_virtual_roots
;
183 // root window messages
184 Atom net_close_window
, net_wm_moveresize
;
186 // application window properties
187 Atom net_properties
, net_wm_name
, net_wm_desktop
, net_wm_window_type
,
188 net_wm_state
, net_wm_strut
, net_wm_icon_geometry
, net_wm_icon
, net_wm_pid
,
189 net_wm_handled_icons
;
191 // application protocols
195 Blackbox(const Blackbox
&);
196 Blackbox
& operator=(const Blackbox
&);
200 void real_rereadMenu(void);
201 void real_reconfigure(void);
203 void init_icccm(void);
205 virtual void process_event(XEvent
*);
209 Blackbox(char **m_argv
, char *dpy_name
= 0, char *rc
= 0, char *menu
= 0);
210 virtual ~Blackbox(void);
212 Basemenu
*searchMenu(Window window
);
213 BWindowGroup
*searchGroup(Window window
);
214 BlackboxWindow
*searchWindow(Window window
);
215 BScreen
*searchScreen(Window window
);
216 Toolbar
*searchToolbar(Window
);
217 Slit
*searchSlit(Window
);
219 void saveMenuSearch(Window window
, Basemenu
*data
);
220 void saveWindowSearch(Window window
, BlackboxWindow
*data
);
221 void saveGroupSearch(Window window
, BWindowGroup
*data
);
222 void saveToolbarSearch(Window window
, Toolbar
*data
);
223 void saveSlitSearch(Window window
, Slit
*data
);
224 void removeMenuSearch(Window window
);
225 void removeWindowSearch(Window window
);
226 void removeGroupSearch(Window window
);
227 void removeToolbarSearch(Window window
);
228 void removeSlitSearch(Window window
);
230 inline BlackboxWindow
*getFocusedWindow(void) { return focused_window
; }
232 inline Configuration
*getConfig() { return &config
; }
233 inline const Time
&getDoubleClickInterval(void) const
234 { return resource
.double_click_interval
; }
235 inline const Time
&getLastTime(void) const { return last_time
; }
237 inline const char *getStyleFilename(void) const
238 { return resource
.style_file
.c_str(); }
239 inline const char *getMenuFilename(void) const
240 { return menu_file
.c_str(); }
242 inline int getColorsPerChannel(void) const
243 { return resource
.colors_per_channel
; }
245 inline std::string
getTitlebarLayout(void) const
246 { return resource
.titlebar_layout
; }
248 inline const timeval
&getAutoRaiseDelay(void) const
249 { return resource
.auto_raise_delay
; }
251 inline unsigned long getCacheLife(void) const
252 { return resource
.cache_life
; }
253 inline unsigned long getCacheMax(void) const
254 { return resource
.cache_max
; }
256 inline void setNoFocus(bool f
) { no_focus
= f
; }
258 inline Cursor
getSessionCursor(void) const
259 { return cursor
.session
; }
260 inline Cursor
getMoveCursor(void) const
261 { return cursor
.move
; }
262 inline Cursor
getLowerLeftAngleCursor(void) const
263 { return cursor
.ll_angle
; }
264 inline Cursor
getLowerRightAngleCursor(void) const
265 { return cursor
.lr_angle
; }
267 void setFocusedWindow(BlackboxWindow
*w
);
269 void saveStyleFilename(const std::string
& filename
);
270 void addMenuTimestamp(const std::string
& filename
);
271 void restart(const char *prog
= 0);
272 void reconfigure(void);
273 void rereadMenu(void);
274 void checkMenu(void);
276 bool validateWindow(Window window
);
278 virtual bool handleSignal(int sig
);
280 virtual void timeout(void);
282 #ifndef HAVE_STRFTIME
283 enum { B_AmericanDate
= 1, B_EuropeanDate
};
284 #endif // HAVE_STRFTIME
287 inline Atom
getBlackboxPidAtom(void) const { return blackbox_pid
; }
288 #endif // HAVE_GETPID
290 inline Atom
getWMChangeStateAtom(void) const
291 { return xa_wm_change_state
; }
292 inline Atom
getWMStateAtom(void) const
293 { return xa_wm_state
; }
294 inline Atom
getWMDeleteAtom(void) const
295 { return xa_wm_delete_window
; }
296 inline Atom
getWMProtocolsAtom(void) const
297 { return xa_wm_protocols
; }
298 inline Atom
getWMTakeFocusAtom(void) const
299 { return xa_wm_take_focus
; }
300 inline Atom
getWMColormapAtom(void) const
301 { return xa_wm_colormap_windows
; }
302 inline Atom
getMotifWMHintsAtom(void) const
303 { return motif_wm_hints
; }
305 // this atom is for normal app->WM hints about decorations, stacking,
306 // starting workspace etc...
307 inline Atom
getBlackboxHintsAtom(void) const
308 { return blackbox_hints
;}
310 // these atoms are for normal app->WM interaction beyond the scope of the
312 inline Atom
getBlackboxAttributesAtom(void) const
313 { return blackbox_attributes
; }
314 inline Atom
getBlackboxChangeAttributesAtom(void) const
315 { return blackbox_change_attributes
; }
317 // these atoms are for window->WM interaction, with more control and
318 // information on window "structure"... common examples are
319 // notifying apps when windows are raised/lowered... when the user changes
320 // workspaces... i.e. "pager talk"
321 inline Atom
getBlackboxStructureMessagesAtom(void) const
322 { return blackbox_structure_messages
; }
324 // *Notify* portions of the NETStructureMessages protocol
325 inline Atom
getBlackboxNotifyStartupAtom(void) const
326 { return blackbox_notify_startup
; }
327 inline Atom
getBlackboxNotifyWindowAddAtom(void) const
328 { return blackbox_notify_window_add
; }
329 inline Atom
getBlackboxNotifyWindowDelAtom(void) const
330 { return blackbox_notify_window_del
; }
331 inline Atom
getBlackboxNotifyWindowFocusAtom(void) const
332 { return blackbox_notify_window_focus
; }
333 inline Atom
getBlackboxNotifyCurrentWorkspaceAtom(void) const
334 { return blackbox_notify_current_workspace
; }
335 inline Atom
getBlackboxNotifyWorkspaceCountAtom(void) const
336 { return blackbox_notify_workspace_count
; }
337 inline Atom
getBlackboxNotifyWindowRaiseAtom(void) const
338 { return blackbox_notify_window_raise
; }
339 inline Atom
getBlackboxNotifyWindowLowerAtom(void) const
340 { return blackbox_notify_window_lower
; }
342 // atoms to change that request changes to the desktop environment during
343 // runtime... these messages can be sent by any client... as the sending
344 // client window id is not included in the ClientMessage event...
345 inline Atom
getBlackboxChangeWorkspaceAtom(void) const
346 { return blackbox_change_workspace
; }
347 inline Atom
getBlackboxChangeWindowFocusAtom(void) const
348 { return blackbox_change_window_focus
; }
349 inline Atom
getBlackboxCycleWindowFocusAtom(void) const
350 { return blackbox_cycle_window_focus
; }
353 // root window properties
354 inline Atom
getNETSupportedAtom(void) const
355 { return net_supported
; }
356 inline Atom
getNETClientListAtom(void) const
357 { return net_client_list
; }
358 inline Atom
getNETClientListStackingAtom(void) const
359 { return net_client_list_stacking
; }
360 inline Atom
getNETNumberOfDesktopsAtom(void) const
361 { return net_number_of_desktops
; }
362 inline Atom
getNETDesktopGeometryAtom(void) const
363 { return net_desktop_geometry
; }
364 inline Atom
getNETDesktopViewportAtom(void) const
365 { return net_desktop_viewport
; }
366 inline Atom
getNETCurrentDesktopAtom(void) const
367 { return net_current_desktop
; }
368 inline Atom
getNETDesktopNamesAtom(void) const
369 { return net_desktop_names
; }
370 inline Atom
getNETActiveWindowAtom(void) const
371 { return net_active_window
; }
372 inline Atom
getNETWorkareaAtom(void) const
373 { return net_workarea
; }
374 inline Atom
getNETSupportingWMCheckAtom(void) const
375 { return net_supporting_wm_check
; }
376 inline Atom
getNETVirtualRootsAtom(void) const
377 { return net_virtual_roots
; }
379 // root window messages
380 inline Atom
getNETCloseWindowAtom(void) const
381 { return net_close_window
; }
382 inline Atom
getNETWMMoveResizeAtom(void) const
383 { return net_wm_moveresize
; }
385 // application window properties
386 inline Atom
getNETPropertiesAtom(void) const
387 { return net_properties
; }
388 inline Atom
getNETWMNameAtom(void) const
389 { return net_wm_name
; }
390 inline Atom
getNETWMDesktopAtom(void) const
391 { return net_wm_desktop
; }
392 inline Atom
getNETWMWindowTypeAtom(void) const
393 { return net_wm_window_type
; }
394 inline Atom
getNETWMStateAtom(void) const
395 { return net_wm_state
; }
396 inline Atom
getNETWMStrutAtom(void) const
397 { return net_wm_strut
; }
398 inline Atom
getNETWMIconGeometryAtom(void) const
399 { return net_wm_icon_geometry
; }
400 inline Atom
getNETWMIconAtom(void) const
401 { return net_wm_icon
; }
402 inline Atom
getNETWMPidAtom(void) const
403 { return net_wm_pid
; }
404 inline Atom
getNETWMHandledIconsAtom(void) const
405 { return net_wm_handled_icons
; }
407 // application protocols
408 inline Atom
getNETWMPingAtom(void) const
409 { return net_wm_ping
; }
414 #endif // __blackbox_hh