]> icculus.org git repositories - dana/openbox.git/blob - src/openbox.hh
might not compile... ob uses its own widgets now, which subclass only the base otk...
[dana/openbox.git] / src / openbox.hh
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 #ifndef   __openbox_hh
3 #define   __openbox_hh
4
5 /*! @file openbox.hh
6   @brief The main class for the Openbox window manager
7 */
8
9 /*
10   cuz girls look soooo goood.. on the end of my DICK
11 */
12
13 extern "C" {
14 #include <X11/Xlib.h>
15 }
16
17 #include <string>
18 #include <vector>
19 #include <map>
20
21 #include "otk/screeninfo.hh"
22 #include "otk/timerqueuemanager.hh"
23 #include "otk/property.hh"
24 #include "otk/configuration.hh"
25 #include "otk/eventdispatcher.hh"
26 #include "otk/eventhandler.hh"
27
28 namespace ob {
29
30 class OBScreen;
31 class OBClient;
32 class OBActions;
33
34 //! Mouse cursors used throughout Openbox
35 struct Cursors {
36   Cursor session;  //!< The default mouse cursor
37   Cursor move;     //!< For moving a window
38   Cursor ll_angle; //!< For resizing the bottom left corner of a window
39   Cursor lr_angle; //!< For resizing the bottom right corner of a window
40   Cursor ul_angle; //!< For resizing the top left corner of a window
41   Cursor ur_angle; //!< For resizing the right corner of a window
42 };
43
44
45 //! The main class for the Openbox window manager
46 /*!
47   Only a single instance of the Openbox class may be used in the application. A
48   pointer to this instance is held in the Openbox::instance static member
49   variable.
50   Instantiation of this class begins the window manager. After instantiation,
51   the Openbox::eventLoop function should be called. The eventLoop method does
52   not exit until the window manager is ready to be destroyed. Destruction of
53   the Openbox class instance will shutdown the window manager.
54 */
55 class Openbox : public otk::OtkEventDispatcher, public otk::OtkEventHandler
56 {
57 public:
58   //! The single instance of the Openbox class for the application
59   /*!
60     Since this variable is globally available in the application, the Openbox
61     class does not need to be passed around to any of the other classes.
62   */
63   static Openbox *instance;
64
65   //! The posible running states of the window manager
66   enum RunState {
67     State_Starting, //!< The window manager is starting up (being created)
68     State_Normal,   //!< The window manager is running in its normal state
69     State_Exiting   //!< The window manager is exiting (being destroyed)
70   };
71
72   //! A map for looking up a specific client class from the window id
73   typedef std::map<Window, OBClient *> ClientMap;
74
75   //! A list of OBScreen classes
76   typedef std::vector<OBScreen *> ScreenList;
77   
78 private:
79   // stuff that can be passed on the command line
80   //! Path to the config file to use/in use
81   /*!
82     Defaults to $(HOME)/.openbox/rc3
83   */
84   std::string _rcfilepath;
85   //! Path to the menu file to use/in use
86   /*!
87     Defaults to $(HOME)/.openbox/menu3
88   */
89   std::string _menufilepath;
90   //! Path to the script file to execute on startup
91   /*!
92     Defaults to $(HOME)/.openbox/user.py
93   */
94   std::string _scriptfilepath;
95   //! The display requested by the user, or null to use the DISPLAY env var
96   char *_displayreq;
97   //! The value of argv[0], i.e. how this application was executed
98   char *_argv0;
99
100   //! A list of all managed clients
101   ClientMap _clients;
102
103   //! A list of all the managed screens
104   ScreenList _screens;
105   
106   //! Manages all timers for the application
107   /*!
108     Use of the otk::OBTimerQueueManager::fire funtion in this object ensures
109     that all timers fire when their times elapse.
110   */
111   otk::OBTimerQueueManager _timermanager;
112
113   //! Cached atoms on the display
114   /*!
115     This is a pointer because the OBProperty class uses otk::OBDisplay::display
116     in its constructor, so, it needs to be initialized <b>after</b> the display
117     is initialized in this class' constructor.
118   */
119   otk::OBProperty *_property;
120
121   //! The action interface through which all user-available actions occur
122   OBActions *_actions;
123
124   //! Run the application in synchronous mode? (for debugging)
125   bool _sync;
126
127   //! The running state of the window manager
128   RunState _state;
129
130   //! Mouse cursors used throughout Openbox
131   Cursors _cursors;
132
133   //! When set to true, the Openbox::eventLoop function will stop and return
134   bool _doshutdown;
135
136   //! The configuration of the application. TEMPORARY
137   otk::Configuration _config;
138
139   //! The client with input focus
140   /*!
141     Updated by the clients themselves.
142   */
143   OBClient *_focused_client;
144
145   //! The screen with input focus
146   /*!
147     Updated by the clients when they update the Openbox::focused_client
148     property.
149   */
150   OBScreen *_focused_screen;
151   
152   //! Parses the command line used when executing this application
153   void parseCommandLine(int argv, char **argv);
154   //! Displays the version string to stdout
155   void showVersion();
156   //! Displays usage information and help to stdout
157   void showHelp();
158
159   //! Handles signal events for the application
160   static void signalHandler(int signal);
161
162 public:
163 #ifndef SWIG
164   //! Openbox constructor.
165   /*!
166     \param argc Number of command line arguments, as received in main()
167     \param argv The command line arguments, as received in main()
168   */
169   Openbox(int argc, char **argv);
170   //! Openbox destructor.
171   virtual ~Openbox();
172 #endif
173
174   //! Returns the state of the window manager (starting, exiting, etc)
175   inline RunState state() const { return _state; }
176
177   //! Returns the otk::OBTimerQueueManager for the application
178   /*!
179     All otk::OBTimer objects used in the application should be made to use this
180     otk::OBTimerQueueManager.
181   */
182   inline otk::OBTimerQueueManager *timerManager() { return &_timermanager; }
183
184   //! Returns the otk::OBProperty instance for the window manager
185   inline const otk::OBProperty *property() const { return _property; }
186
187   //! Returns a managed screen
188   inline OBScreen *screen(int num) {
189     assert(num >= 0); assert(num < (signed)_screens.size());
190     if (num >= screenCount())
191       return NULL;
192     return _screens[num];
193   }
194
195   //! Returns the number of managed screens
196   inline int screenCount() const {
197     return (signed)_screens.size();
198   }
199
200   //! Returns the mouse cursors used throughout Openbox
201   inline const Cursors &cursors() const { return _cursors; }
202
203 #ifndef SWIG
204   //! The main function of the Openbox class
205   /*!
206     This function should be called after instantiating the Openbox class.
207     It loops indefinately while handling all events for the application.
208     The Openbox::shutdown method will cause this function to exit.
209   */
210   void eventLoop();
211 #endif
212
213   //! Adds an OBClient to the client list for lookups
214   void addClient(Window window, OBClient *client);
215
216   //! Removes an OBClient from the client list for lookups
217   void removeClient(Window window);
218
219   //! Finds an OBClient based on its window id
220   OBClient *findClient(Window window);
221
222   //! The client with input focus
223   inline OBClient *focusedClient() { return _focused_client; }
224
225   //! Change the client which has focus.
226   /*!
227     This is called by the clients themselves when their focus state changes.
228   */
229   void setFocusedClient(OBClient *c);
230
231   //! The screen with input focus
232   inline OBScreen *focusedScreen() { return _focused_screen; }
233   
234   //! Requests that the window manager exit
235   /*!
236     Causes the Openbox::eventLoop function to stop looping, so that the window
237     manager can be destroyed.
238   */
239   inline void shutdown() { _doshutdown = true; }
240 };
241
242 }
243
244 #endif // __openbox_hh