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