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"
56 #define AttribShaded (1l << 0)
57 #define AttribMaxHoriz (1l << 1)
58 #define AttribMaxVert (1l << 2)
59 #define AttribOmnipresent (1l << 3)
60 #define AttribWorkspace (1l << 4)
61 #define AttribStack (1l << 5)
62 #define AttribDecoration (1l << 6)
65 #define StackNormal (1)
66 #define StackBottom (2)
69 #define DecorNormal (1)
73 struct BlackboxHints
{
74 unsigned long flags
, attrib
, workspace
, stack
, decoration
;
77 struct BlackboxAttributes
{
78 unsigned long flags
, attrib
, workspace
, stack
, decoration
;
79 int premax_x
, premax_y
;
80 unsigned int premax_w
, premax_h
;
83 #define PropBlackboxHintsElements (5)
84 #define PropBlackboxAttributesElements (9)
98 class Blackbox
: public BaseDisplay
, public TimeoutHandler
{
101 Cursor session
, move
, ll_angle
, lr_angle
;
105 struct MenuTimestamp
{
106 std::string filename
;
111 Time double_click_interval
;
113 std::string style_file
;
114 int colors_per_channel
;
115 timeval auto_raise_delay
;
116 unsigned long cache_life
, cache_max
;
117 std::string titlebar_layout
;
118 bool window_to_window_snap
;
119 bool window_corner_snap
;
122 typedef std::map
<Window
, BlackboxWindow
*> WindowLookup
;
123 typedef WindowLookup::value_type WindowLookupPair
;
124 WindowLookup windowSearchList
;
126 typedef std::map
<Window
, BWindowGroup
*> GroupLookup
;
127 typedef GroupLookup::value_type GroupLookupPair
;
128 GroupLookup groupSearchList
;
130 typedef std::map
<Window
, Basemenu
*> MenuLookup
;
131 typedef MenuLookup::value_type MenuLookupPair
;
132 MenuLookup menuSearchList
;
134 typedef std::map
<Window
, Toolbar
*> ToolbarLookup
;
135 typedef ToolbarLookup::value_type ToolbarLookupPair
;
136 ToolbarLookup toolbarSearchList
;
138 typedef std::map
<Window
, Slit
*> SlitLookup
;
139 typedef SlitLookup::value_type SlitLookupPair
;
140 SlitLookup slitSearchList
;
142 typedef std::list
<MenuTimestamp
*> MenuTimestampList
;
143 MenuTimestampList menuTimestamps
;
145 typedef std::list
<BScreen
*> ScreenList
;
146 ScreenList screenList
;
148 BScreen
*active_screen
;
149 BlackboxWindow
*focused_window
;
151 Configuration config
;
154 bool no_focus
, reconfigure_wait
, reread_menu_wait
;
157 std::string menu_file
, rc_file
;
159 Blackbox(const Blackbox
&);
160 Blackbox
& operator=(const Blackbox
&);
164 void real_rereadMenu(void);
165 void real_reconfigure(void);
167 virtual void process_event(XEvent
*);
171 Blackbox(char **m_argv
, char *dpy_name
= 0, char *rc
= 0, char *menu
= 0);
172 virtual ~Blackbox(void);
174 Basemenu
*searchMenu(Window window
);
175 BWindowGroup
*searchGroup(Window window
);
176 BlackboxWindow
*searchWindow(Window window
);
177 BScreen
*searchScreen(Window window
);
178 Toolbar
*searchToolbar(Window
);
179 Slit
*searchSlit(Window
);
181 void saveMenuSearch(Window window
, Basemenu
*data
);
182 void saveWindowSearch(Window window
, BlackboxWindow
*data
);
183 void saveGroupSearch(Window window
, BWindowGroup
*data
);
184 void saveToolbarSearch(Window window
, Toolbar
*data
);
185 void saveSlitSearch(Window window
, Slit
*data
);
186 void removeMenuSearch(Window window
);
187 void removeWindowSearch(Window window
);
188 void removeGroupSearch(Window window
);
189 void removeToolbarSearch(Window window
);
190 void removeSlitSearch(Window window
);
192 inline XAtom
*getXAtom(void) { return xatom
; }
194 inline BlackboxWindow
*getFocusedWindow(void) { return focused_window
; }
196 inline Configuration
*getConfig() { return &config
; }
197 inline const Time
&getDoubleClickInterval(void) const
198 { return resource
.double_click_interval
; }
199 inline const Time
&getLastTime(void) const { return last_time
; }
201 inline const char *getStyleFilename(void) const
202 { return resource
.style_file
.c_str(); }
203 inline const char *getMenuFilename(void) const
204 { return menu_file
.c_str(); }
206 inline int getColorsPerChannel(void) const
207 { return resource
.colors_per_channel
; }
209 inline std::string
getTitlebarLayout(void) const
210 { return resource
.titlebar_layout
; }
212 inline const timeval
&getAutoRaiseDelay(void) const
213 { return resource
.auto_raise_delay
; }
215 inline unsigned long getCacheLife(void) const
216 { return resource
.cache_life
; }
217 inline unsigned long getCacheMax(void) const
218 { return resource
.cache_max
; }
220 inline bool getWindowToWindowSnap(void) const
221 { return resource
.window_to_window_snap
; }
222 inline bool getWindowCornerSnap(void) const
223 { return resource
.window_corner_snap
; }
225 inline void setNoFocus(bool f
) { no_focus
= f
; }
227 inline Cursor
getSessionCursor(void) const
228 { return cursor
.session
; }
229 inline Cursor
getMoveCursor(void) const
230 { return cursor
.move
; }
231 inline Cursor
getLowerLeftAngleCursor(void) const
232 { return cursor
.ll_angle
; }
233 inline Cursor
getLowerRightAngleCursor(void) const
234 { return cursor
.lr_angle
; }
236 void setFocusedWindow(BlackboxWindow
*w
);
238 void saveStyleFilename(const std::string
& filename
);
239 void saveWindowToWindowSnap(bool);
240 void saveWindowCornerSnap(bool);
241 void addMenuTimestamp(const std::string
& filename
);
242 void restart(const char *prog
= 0);
243 void reconfigure(void);
244 void rereadMenu(void);
245 void checkMenu(void);
247 bool validateWindow(Window window
);
249 virtual bool handleSignal(int sig
);
251 virtual void timeout(void);
253 #ifndef HAVE_STRFTIME
254 enum { B_AmericanDate
= 1, B_EuropeanDate
};
255 #endif // HAVE_STRFTIME
257 inline Atom
getWMDeleteAtom(void) const
258 { return xatom
->getAtom(XAtom::wm_delete_window
); }
259 inline Atom
getWMProtocolsAtom(void) const
260 { return xatom
->getAtom(XAtom::wm_protocols
); }
261 inline Atom
getWMTakeFocusAtom(void) const
262 { return xatom
->getAtom(XAtom::wm_take_focus
); }
263 inline Atom
getWMColormapAtom(void) const
264 { return xatom
->getAtom(XAtom::wm_colormap_windows
); }
265 inline Atom
getMotifWMHintsAtom(void) const
266 { return xatom
->getAtom(XAtom::motif_wm_hints
); }
268 // this atom is for normal app->WM hints about decorations, stacking,
269 // starting workspace etc...
270 inline Atom
getBlackboxHintsAtom(void) const
271 { return xatom
->getAtom(XAtom::blackbox_hints
); }
273 // these atoms are for normal app->WM interaction beyond the scope of the
275 inline Atom
getBlackboxAttributesAtom(void) const
276 { return xatom
->getAtom(XAtom::blackbox_attributes
); }
277 inline Atom
getBlackboxChangeAttributesAtom(void) const
278 { return xatom
->getAtom(XAtom::blackbox_change_attributes
); }
280 // these atoms are for window->WM interaction, with more control and
281 // information on window "structure"... common examples are
282 // notifying apps when windows are raised/lowered... when the user changes
283 // workspaces... i.e. "pager talk"
284 inline Atom
getBlackboxStructureMessagesAtom(void) const
285 { return xatom
->getAtom(XAtom::blackbox_structure_messages
); }
287 // *Notify* portions of the NETStructureMessages protocol
288 inline Atom
getBlackboxNotifyStartupAtom(void) const
289 { return xatom
->getAtom(XAtom::blackbox_notify_startup
); }
290 inline Atom
getBlackboxNotifyWindowAddAtom(void) const
291 { return xatom
->getAtom(XAtom::blackbox_notify_window_add
); }
292 inline Atom
getBlackboxNotifyWindowDelAtom(void) const
293 { return xatom
->getAtom(XAtom::blackbox_notify_window_del
); }
294 inline Atom
getBlackboxNotifyWindowFocusAtom(void) const
295 { return xatom
->getAtom(XAtom::blackbox_notify_window_focus
); }
296 inline Atom
getBlackboxNotifyCurrentWorkspaceAtom(void) const
297 { return xatom
->getAtom(XAtom::blackbox_notify_current_workspace
); }
298 inline Atom
getBlackboxNotifyWorkspaceCountAtom(void) const
299 { return xatom
->getAtom(XAtom::blackbox_notify_workspace_count
); }
300 inline Atom
getBlackboxNotifyWindowRaiseAtom(void) const
301 { return xatom
->getAtom(XAtom::blackbox_notify_window_raise
); }
302 inline Atom
getBlackboxNotifyWindowLowerAtom(void) const
303 { return xatom
->getAtom(XAtom::blackbox_notify_window_lower
); }
305 // atoms to change that request changes to the desktop environment during
306 // runtime... these messages can be sent by any client... as the sending
307 // client window id is not included in the ClientMessage event...
308 inline Atom
getBlackboxChangeWorkspaceAtom(void) const
309 { return xatom
->getAtom(XAtom::blackbox_change_workspace
); }
310 inline Atom
getBlackboxChangeWindowFocusAtom(void) const
311 { return xatom
->getAtom(XAtom::blackbox_change_window_focus
); }
312 inline Atom
getBlackboxCycleWindowFocusAtom(void) const
313 { return xatom
->getAtom(XAtom::blackbox_cycle_window_focus
); }
317 #endif // __blackbox_hh