summaryrefslogtreecommitdiff
path: root/src/fluxbox.hh
blob: df2db9b00c01085b1d31fa2dbe801d9f741b6fa3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
// fluxbox.hh for Fluxbox Window Manager
// Copyright (c) 2001 - 2002 Henrik Kinnunen (fluxgen@linuxmail.org)
//
// blackbox.hh for Blackbox - an X11 Window manager
// Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.	IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.

// $Id: fluxbox.hh,v 1.10 2002/02/17 18:42:15 fluxgen Exp $

#ifndef	 FLUXBOX_HH
#define	 FLUXBOX_HH

#include <X11/Xlib.h>
#include <X11/Xresource.h>

#ifdef		HAVE_STDIO_H
# include <stdio.h>
#endif // HAVE_STDIO_H

#ifdef		TIME_WITH_SYS_TIME
#	include <sys/time.h>
#	include <time.h>
#else // !TIME_WITH_SYS_TIME
#	ifdef		HAVE_SYS_TIME_H
#		include <sys/time.h>
#	else // !HAVE_SYS_TIME_H
#		include <time.h>
#	endif // HAVE_SYS_TIME_H
#endif // TIME_WITH_SYS_TIME

#ifndef _RESOURCE_HH_
#include "Resource.hh"
#endif

#ifndef _KEYS_HH_
#include "Keys.hh"
#endif

#ifndef _BASEDISPLAY_HH_
#include "BaseDisplay.hh"
#endif

#ifndef _IMAGE_HH_
#include "Image.hh"
#endif

#ifndef _LINKEDLIST_HH_
#include "LinkedList.hh"
#endif

#ifndef _TIMER_HH_
#include "Timer.hh"
#endif 

#ifndef _WINDOW_HH_
#include "Window.hh"
#endif 

#ifndef _TAB_HH_
#include "Tab.hh"
#endif

#ifndef _TOOLBAR_HH_
#include "Toolbar.hh"
#endif

#ifdef		SLIT
#	include "Slit.hh"
#endif // SLIT

#include <string>
#include <vector>

class Fluxbox : public BaseDisplay, public TimeoutHandler {	
public:
	
	
	static Fluxbox *instance(int m_argc=0, char **m_argv=0, char *dpy_name=0, char *rc=0);
	
	inline bool useTabs() { return *m_rc_tabs; }
	inline bool useIconBar() { return *m_rc_iconbar; }
	inline void saveTabs(bool value) { *m_rc_tabs = value; }
	inline void saveIconBar(bool value) { m_rc_iconbar = value; }
#ifdef		HAVE_GETPID
	inline const Atom &getFluxboxPidAtom(void) const { return fluxbox_pid; }
	#ifdef KDE
	//For KDE dock applets
	inline const Atom &getKWM1DockwindowAtom(void) const { return kwm1_dockwindow; } //KDE v1.x
	inline const Atom &getKWM2DockwindowAtom(void) const { return kwm2_dockwindow; } //KDE v2.x
	#endif
#endif // HAVE_GETPID

	Basemenu *searchMenu(Window);

	FluxboxWindow *searchGroup(Window, FluxboxWindow *);
	FluxboxWindow *searchWindow(Window);
	inline FluxboxWindow *getFocusedWindow(void) { return focused_window; }

		
	BScreen *searchScreen(Window);

	inline const Time &getDoubleClickInterval(void) const
		{ return resource.double_click_interval; }
	inline const Time &getLastTime(void) const { return last_time; }

	Toolbar *searchToolbar(Window);
	Tab *searchTab(Window);
	
	enum Titlebar{SHADE=0, MINIMIZE, MAXIMIZE, CLOSE, STICK, MENU, EMPTY};		
	
	inline const std::vector<Fluxbox::Titlebar>& getTitlebarRight() { return *m_rc_titlebar_right; }
	inline const std::vector<Fluxbox::Titlebar>& getTitlebarLeft() { return *m_rc_titlebar_left; }
	inline const char *getStyleFilename(void)
		{ return m_rc_stylefile->c_str(); }

	inline const char *getMenuFilename(void)
		{ return m_rc_menufile->c_str(); }

	inline const int &getColorsPerChannel(void)
		{ return *m_rc_colors_per_channel; }

	inline const timeval &getAutoRaiseDelay(void) const
		{ return resource.auto_raise_delay; }

	inline const unsigned int getCacheLife(void)
		{ return *m_rc_cache_life * 60000; }
	inline const unsigned int getCacheMax(void)
		{ return *m_rc_cache_max; }

	inline void maskWindowEvents(Window w, FluxboxWindow *bw)
		{ masked = w; masked_window = bw; }
	inline void setNoFocus(Bool f) { no_focus = f; }

	void setFocusedWindow(FluxboxWindow *w);
	void shutdown(void);
	void load_rc(BScreen *);
	void loadRootCommand(BScreen *);
	void loadTitlebar();
	void saveStyleFilename(const char *val) { m_rc_stylefile = (val == 0 ? "" : val); }
	void saveMenuFilename(const char *);
	void saveTitlebarFilename(const char *);
	void saveMenuSearch(Window, Basemenu *);
	void saveWindowSearch(Window, FluxboxWindow *);
	void saveToolbarSearch(Window, Toolbar *);
	void saveTabSearch(Window, Tab *);
	void saveGroupSearch(Window, FluxboxWindow *);	
	void removeMenuSearch(Window);
	void removeWindowSearch(Window);
	void removeToolbarSearch(Window);
	void removeTabSearch(Window);
	void removeGroupSearch(Window);
	void restart(const char * = 0);
	void reconfigure(void);
	void reconfigureTabs(void);
	void rereadMenu(void);
	void checkMenu(void);

	virtual Bool handleSignal(int);

	virtual void timeout(void);

#ifdef		SLIT
	Slit *searchSlit(Window);

	void saveSlitSearch(Window, Slit *);
	void removeSlitSearch(Window);
#endif // SLIT

#ifndef	 HAVE_STRFTIME

	enum { B_AMERICANDATE = 1, B_EUROPEANDATE };
#endif // HAVE_STRFTIME
	
	template <class Z>
	class DataSearch {
	private:
		Window window;
		Z *data;


	public:
		DataSearch(Window w, Z *d) { window = w; data = d; }

		inline const Window &getWindow(void) const { return window; }
		inline Z *getData(void) { return data; }
	};
	
	typedef std::vector<Fluxbox::Titlebar> TitlebarList;
		
private:
	void handleButtonEvent(XButtonEvent &be);
	void handleUnmapNotify(XUnmapEvent &ue);
	void handleClientMessage(XClientMessageEvent &ce);
	void handleKeyEvent(XKeyEvent &ke);	
	void doWindowAction(Keys::KeyAction action);
	#ifdef GNOME
	bool checkGnomeAtoms(XClientMessageEvent &ce);
	#endif
	#ifdef NEWWMSPEC
	bool checkNETWMAtoms(XClientMessageEvent &ce);
	#endif
	typedef struct MenuTimestamp {
		char *filename;
		time_t timestamp;
	} MenuTimestamp;

	struct resource {
		Time double_click_interval;		
		timeval auto_raise_delay;
	} resource;
		
	ResourceManager m_resourcemanager, m_screen_rm;
	
	//--- Resources
	Resource<bool> m_rc_tabs, m_rc_iconbar;
	Resource<int> m_rc_colors_per_channel;
	Resource<std::string> m_rc_stylefile, 
		m_rc_menufile, m_rc_keyfile;	
	
	Resource<TitlebarList> m_rc_titlebar_left, m_rc_titlebar_right;
	Resource<unsigned int> m_rc_cache_life, m_rc_cache_max;

	//std::vector<std::string> parseTitleArgs(const char *arg);
	void setTitlebar(std::vector<Fluxbox::Titlebar>& dir, const char *arg);
	
	typedef DataSearch<FluxboxWindow> WindowSearch;
	LinkedList<WindowSearch> *windowSearchList, *groupSearchList;
	typedef DataSearch<Basemenu> MenuSearch;
	LinkedList<MenuSearch> *menuSearchList;
	typedef DataSearch<Toolbar> ToolbarSearch;
	LinkedList<ToolbarSearch> *toolbarSearchList;
	typedef DataSearch<Tab> TabSearch;
	LinkedList<TabSearch> *tabSearchList;
	
#ifdef		SLIT
	typedef DataSearch<Slit> SlitSearch;
	LinkedList<SlitSearch> *slitSearchList;
  #ifdef KDE
	//For KDE dock applets
	Atom kwm1_dockwindow; //KDE v1.x
	Atom kwm2_dockwindow; //KDE v2.x
	#endif//KDE
#endif // SLIT

	LinkedList<MenuTimestamp> *menuTimestamps;
	LinkedList<BScreen> *screenList;

	FluxboxWindow *focused_window, *masked_window;
	BTimer *timer;

#ifdef		HAVE_GETPID
	Atom fluxbox_pid;
#endif // HAVE_GETPID

	bool no_focus, reconfigure_wait, reread_menu_wait;
	Time last_time;
	Window masked;
	char *rc_file, **argv;
	int argc;
	Keys *key;

	
protected:
	Fluxbox(int, char **, char * = 0, char * = 0);
	char *getRcFilename();
	void load_rc(void);
	void save_rc(void);
	void reload_rc(void);
	void real_rereadMenu(void);
	void real_reconfigure(void);

	virtual void process_event(XEvent *);
	//only main should be able to creat new blackbox object
	//TODO this must be removed!
	friend int main(int,char **);
	static Fluxbox *singleton;	//singleton object ( can only be destroyed by main )
	virtual ~Fluxbox(void);

};


#endif // _FLUXBOX_HH_