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
;
120 typedef std::map
<Window
, BlackboxWindow
*> WindowLookup
;
121 typedef WindowLookup::value_type WindowLookupPair
;
122 WindowLookup windowSearchList
;
124 typedef std::map
<Window
, BWindowGroup
*> GroupLookup
;
125 typedef GroupLookup::value_type GroupLookupPair
;
126 GroupLookup groupSearchList
;
128 typedef std::map
<Window
, Basemenu
*> MenuLookup
;
129 typedef MenuLookup::value_type MenuLookupPair
;
130 MenuLookup menuSearchList
;
132 typedef std::map
<Window
, Toolbar
*> ToolbarLookup
;
133 typedef ToolbarLookup::value_type ToolbarLookupPair
;
134 ToolbarLookup toolbarSearchList
;
136 typedef std::map
<Window
, Slit
*> SlitLookup
;
137 typedef SlitLookup::value_type SlitLookupPair
;
138 SlitLookup slitSearchList
;
140 typedef std::list
<MenuTimestamp
*> MenuTimestampList
;
141 MenuTimestampList menuTimestamps
;
143 typedef std::list
<BScreen
*> ScreenList
;
144 ScreenList screenList
;
146 BScreen
*active_screen
;
147 BlackboxWindow
*focused_window
;
149 Configuration config
;
152 bool no_focus
, reconfigure_wait
, reread_menu_wait
;
155 std::string menu_file
, rc_file
;
157 Blackbox(const Blackbox
&);
158 Blackbox
& operator=(const Blackbox
&);
162 void real_rereadMenu(void);
163 void real_reconfigure(void);
165 virtual void process_event(XEvent
*);
169 Blackbox(char **m_argv
, char *dpy_name
= 0, char *rc
= 0, char *menu
= 0);
170 virtual ~Blackbox(void);
172 Basemenu
*searchMenu(Window window
);
173 BWindowGroup
*searchGroup(Window window
);
174 BlackboxWindow
*searchWindow(Window window
);
175 BScreen
*searchScreen(Window window
);
176 Toolbar
*searchToolbar(Window
);
177 Slit
*searchSlit(Window
);
179 void saveMenuSearch(Window window
, Basemenu
*data
);
180 void saveWindowSearch(Window window
, BlackboxWindow
*data
);
181 void saveGroupSearch(Window window
, BWindowGroup
*data
);
182 void saveToolbarSearch(Window window
, Toolbar
*data
);
183 void saveSlitSearch(Window window
, Slit
*data
);
184 void removeMenuSearch(Window window
);
185 void removeWindowSearch(Window window
);
186 void removeGroupSearch(Window window
);
187 void removeToolbarSearch(Window window
);
188 void removeSlitSearch(Window window
);
190 inline XAtom
*getXAtom(void) { return xatom
; }
192 inline BlackboxWindow
*getFocusedWindow(void) { return focused_window
; }
194 inline Configuration
*getConfig() { return &config
; }
195 inline const Time
&getDoubleClickInterval(void) const
196 { return resource
.double_click_interval
; }
197 inline const Time
&getLastTime(void) const { return last_time
; }
199 inline const char *getStyleFilename(void) const
200 { return resource
.style_file
.c_str(); }
201 inline const char *getMenuFilename(void) const
202 { return menu_file
.c_str(); }
204 inline int getColorsPerChannel(void) const
205 { return resource
.colors_per_channel
; }
207 inline std::string
getTitlebarLayout(void) const
208 { return resource
.titlebar_layout
; }
210 inline const timeval
&getAutoRaiseDelay(void) const
211 { return resource
.auto_raise_delay
; }
213 inline unsigned long getCacheLife(void) const
214 { return resource
.cache_life
; }
215 inline unsigned long getCacheMax(void) const
216 { return resource
.cache_max
; }
218 inline void setNoFocus(bool f
) { no_focus
= f
; }
220 inline Cursor
getSessionCursor(void) const
221 { return cursor
.session
; }
222 inline Cursor
getMoveCursor(void) const
223 { return cursor
.move
; }
224 inline Cursor
getLowerLeftAngleCursor(void) const
225 { return cursor
.ll_angle
; }
226 inline Cursor
getLowerRightAngleCursor(void) const
227 { return cursor
.lr_angle
; }
229 void setFocusedWindow(BlackboxWindow
*w
);
231 void saveStyleFilename(const std::string
& filename
);
232 void addMenuTimestamp(const std::string
& filename
);
233 void restart(const char *prog
= 0);
234 void reconfigure(void);
235 void rereadMenu(void);
236 void checkMenu(void);
238 bool validateWindow(Window window
);
240 virtual bool handleSignal(int sig
);
242 virtual void timeout(void);
244 #ifndef HAVE_STRFTIME
245 enum { B_AmericanDate
= 1, B_EuropeanDate
};
246 #endif // HAVE_STRFTIME
248 inline Atom
getWMChangeStateAtom(void) const
249 { return xatom
->getAtom(XAtom::wm_change_state
); }
250 inline Atom
getWMStateAtom(void) const
251 { return xatom
->getAtom(XAtom::wm_state
); }
252 inline Atom
getWMDeleteAtom(void) const
253 { return xatom
->getAtom(XAtom::wm_delete_window
); }
254 inline Atom
getWMProtocolsAtom(void) const
255 { return xatom
->getAtom(XAtom::wm_protocols
); }
256 inline Atom
getWMTakeFocusAtom(void) const
257 { return xatom
->getAtom(XAtom::wm_take_focus
); }
258 inline Atom
getWMColormapAtom(void) const
259 { return xatom
->getAtom(XAtom::wm_colormap_windows
); }
260 inline Atom
getMotifWMHintsAtom(void) const
261 { return xatom
->getAtom(XAtom::motif_wm_hints
); }
263 // this atom is for normal app->WM hints about decorations, stacking,
264 // starting workspace etc...
265 inline Atom
getBlackboxHintsAtom(void) const
266 { return xatom
->getAtom(XAtom::blackbox_hints
); }
268 // these atoms are for normal app->WM interaction beyond the scope of the
270 inline Atom
getBlackboxAttributesAtom(void) const
271 { return xatom
->getAtom(XAtom::blackbox_attributes
); }
272 inline Atom
getBlackboxChangeAttributesAtom(void) const
273 { return xatom
->getAtom(XAtom::blackbox_change_attributes
); }
275 // these atoms are for window->WM interaction, with more control and
276 // information on window "structure"... common examples are
277 // notifying apps when windows are raised/lowered... when the user changes
278 // workspaces... i.e. "pager talk"
279 inline Atom
getBlackboxStructureMessagesAtom(void) const
280 { return xatom
->getAtom(XAtom::blackbox_structure_messages
); }
282 // *Notify* portions of the NETStructureMessages protocol
283 inline Atom
getBlackboxNotifyStartupAtom(void) const
284 { return xatom
->getAtom(XAtom::blackbox_notify_startup
); }
285 inline Atom
getBlackboxNotifyWindowAddAtom(void) const
286 { return xatom
->getAtom(XAtom::blackbox_notify_window_add
); }
287 inline Atom
getBlackboxNotifyWindowDelAtom(void) const
288 { return xatom
->getAtom(XAtom::blackbox_notify_window_del
); }
289 inline Atom
getBlackboxNotifyWindowFocusAtom(void) const
290 { return xatom
->getAtom(XAtom::blackbox_notify_window_focus
); }
291 inline Atom
getBlackboxNotifyCurrentWorkspaceAtom(void) const
292 { return xatom
->getAtom(XAtom::blackbox_notify_current_workspace
); }
293 inline Atom
getBlackboxNotifyWorkspaceCountAtom(void) const
294 { return xatom
->getAtom(XAtom::blackbox_notify_workspace_count
); }
295 inline Atom
getBlackboxNotifyWindowRaiseAtom(void) const
296 { return xatom
->getAtom(XAtom::blackbox_notify_window_raise
); }
297 inline Atom
getBlackboxNotifyWindowLowerAtom(void) const
298 { return xatom
->getAtom(XAtom::blackbox_notify_window_lower
); }
300 // atoms to change that request changes to the desktop environment during
301 // runtime... these messages can be sent by any client... as the sending
302 // client window id is not included in the ClientMessage event...
303 inline Atom
getBlackboxChangeWorkspaceAtom(void) const
304 { return xatom
->getAtom(XAtom::blackbox_change_workspace
); }
305 inline Atom
getBlackboxChangeWindowFocusAtom(void) const
306 { return xatom
->getAtom(XAtom::blackbox_change_window_focus
); }
307 inline Atom
getBlackboxCycleWindowFocusAtom(void) const
308 { return xatom
->getAtom(XAtom::blackbox_cycle_window_focus
); }
312 #endif // __blackbox_hh