]> icculus.org git repositories - dana/openbox.git/blob - src/openbox.hh
manage and unmanage windows in OBScreen
[dana/openbox.git] / src / openbox.hh
1 // -*- mode: C++; indent-tabs-mode: nil; -*-
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 extern "C" {
10 #include <X11/Xlib.h>
11 }
12
13 #include <string>
14 #include <vector>
15 #include <map>
16
17 #include "otk/screeninfo.hh"
18 #include "otk/timerqueuemanager.hh"
19 #include "otk/property.hh"
20 #include "otk/configuration.hh"
21 #include "xeventhandler.hh"
22 #include "client.hh"
23
24 namespace ob {
25
26 class OBScreen;
27
28 //! The main class for the Openbox window manager.
29 /*!
30   Only a single instance of the Openbox class may be used in the application. A
31   pointer to this instance is held in the Openbox::instance static member
32   variable.
33   Instantiation of this class begins the window manager. After instantiation,
34   the Openbox::eventLoop function should be called. The eventLoop method does
35   not exit until the window manager is ready to be destroyed. Destruction of
36   the Openbox class instance will shutdown the window manager.
37 */
38 class Openbox
39 {
40 public:
41   //! The single instance of the Openbox class for the application.
42   /*!
43     Since this variable is globally available in the application, the Openbox
44     class does not need to be passed around to any of the other classes.
45   */
46   static Openbox *instance;
47
48   //! The posible running states of the window manager
49   enum RunState {
50     State_Starting, //!< The window manager is starting up (being created)
51     State_Normal,   //!< The window manager is running in its normal state
52     State_Exiting   //!< The window manager is exiting (being destroyed)
53   };
54
55   //! Mouse cursors used throughout Openbox
56   struct Cursors {
57     Cursor session;  //!< The default mouse cursor
58     Cursor move;     //!< For moving a window
59     Cursor ll_angle; //!< For resizing the bottom left corner of a window
60     Cursor lr_angle; //!< For resizing the bottom right corner of a window
61     Cursor ul_angle; //!< For resizing the top left corner of a window
62     Cursor ur_angle; //!< For resizing the right corner of a window
63   };
64   
65   //! A map for looking up a specific client class from the window id
66   typedef std::map<Window, OBClient *> ClientMap;
67
68   //! A list of OBScreen classes
69   typedef std::vector<OBScreen *> ScreenList;
70   
71 private:
72   // stuff that can be passed on the command line
73   //! Path to the config file to use/in use
74   /*!
75     Defaults to $(HOME)/.openbox/rc3
76   */
77   std::string _rcfilepath;
78   //! Path to the menu file to use/in use
79   /*!
80     Defaults to $(HOME)/.openbox/menu3
81   */
82   std::string _menufilepath;
83   //! The display requested by the user, or null to use the DISPLAY env var
84   char *_displayreq;
85   //! The value of argv[0], i.e. how this application was executed
86   char *_argv0;
87
88   //! A list of all managed clients
89   ClientMap _clients;
90
91   //! A list of all the managed screens
92   ScreenList _screens;
93   
94   //! Manages all timers for the application
95   /*!
96     Use of the otk::OBTimerQueueManager::fire funtion in this object ensures
97     that all timers fire when their times elapse.
98   */
99   otk::OBTimerQueueManager _timermanager;
100
101   //! The class which will handle raw XEvents
102   OBXEventHandler _xeventhandler;
103
104   //! Cached atoms on the display
105   /*!
106     This is a pointer because the OBProperty class uses otk::OBDisplay::display
107     in its constructor, so, it needs to be initialized <b>after</b> the display
108     is initialized in this class' constructor.
109   */
110   otk::OBProperty *_property;
111
112   //! The running state of the window manager
113   RunState _state;
114
115   //! Mouse cursors used throughout Openbox
116   Cursors _cursors;
117
118   //! When set to true, the Openbox::eventLoop function will stop and return
119   bool _doshutdown;
120
121   //! The configuration of the application. TEMPORARY
122   otk::Configuration _config;
123
124   //! Parses the command line used when executing this application
125   void parseCommandLine(int argv, char **argv);
126   //! Displays the version string to stdout
127   void showVersion();
128   //! Displays usage information and help to stdout
129   void showHelp();
130
131   //! Handles signal events for the application
132   static void signalHandler(int signal);
133
134 public:
135   //! Openbox constructor.
136   /*!
137     \param argc Number of command line arguments, as received in main()
138     \param argv The command line arguments, as received in main()
139   */
140   Openbox(int argc, char **argv);
141   //! Openbox destructor.
142   virtual ~Openbox();
143
144   //! Returns the state of the window manager (starting, exiting, etc)
145   inline RunState state() const { return _state; }
146
147   //! Returns the otk::OBTimerQueueManager for the application
148   /*!
149     All otk::OBTimer objects used in the application should be made to use this
150     otk::OBTimerQueueManager.
151   */
152   inline otk::OBTimerQueueManager *timerManager() { return &_timermanager; }
153
154   //! Returns the otk::OBProperty instance for the window manager
155   inline const otk::OBProperty *property() const { return _property; }
156
157   //! Returns a managed screen
158   inline OBScreen *screen(int num) {
159     assert(num >= 0); assert(num < (signed)_screens.size());
160     return _screens[num];
161   }
162
163   //! Returns the mouse cursors used throughout Openbox
164   inline const Cursors &cursors() const { return _cursors; }
165
166   //! The main function of the Openbox class
167   /*!
168     This function should be called after instantiating the Openbox class.
169     It loops indefinately while handling all events for the application.
170     The Openbox::shutdown method will cause this function to exit.
171   */
172   void eventLoop();
173
174   //! Adds an OBClient to the client list for lookups
175   void addClient(Window window, OBClient *client);
176
177   //! Removes an OBClient from the client list for lookups
178   void removeClient(Window window);
179
180   //! Finds an OBClient based on its window id
181   OBClient *findClient(Window window);
182
183   //! Requests that the window manager exit
184   /*!
185     Causes the Openbox::eventLoop function to stop looping, so that the window
186     manager can be destroyed.
187   */
188   inline void shutdown() { _doshutdown = true; }
189 };
190
191 }
192
193 #endif // __openbox_hh