]> icculus.org git repositories - dana/openbox.git/blob - src/openbox.hh
finish conversion to the new otk::OBProperty class with its new interface
[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
16 #include "otk/screeninfo.hh"
17 #include "otk/timerqueuemanager.hh"
18 #include "otk/property.hh"
19 #include "xeventhandler.hh"
20
21 namespace ob {
22
23 //! The main class for the Openbox window manager.
24 /*!
25   Only a single instance of the Openbox class may be used in the application. A
26   pointer to this instance is held in the Openbox::instance static member
27   variable.
28   Instantiation of this class begins the window manager. After instantiation,
29   the Openbox::eventLoop function should be called. The eventLoop method does
30   not exit until the window manager is ready to be destroyed. Destruction of
31   the Openbox class instance will shutdown the window manager.
32 */
33 class Openbox
34 {
35 public:
36   //! The single instance of the Openbox class for the application.
37   /*!
38     Since this variable is globally available in the application, the Openbox
39     class does not need to be passed around to any of the other classes.
40   */
41   static Openbox *instance;
42
43   //! The posible running states of the window manager
44   enum RunState {
45     State_Starting, //!< The window manager is starting up (being created)
46     State_Normal,   //!< The window manager is running in its normal state
47     State_Exiting   //!< The window manager is exiting (being destroyed)
48   };
49   
50 private:
51   // stuff that can be passed on the command line
52   //! Path to the config file to use/in use
53   /*!
54     Defaults to $(HOME)/.openbox/rc3
55   */
56   std::string _rcfilepath;
57   //! Path to the menu file to use/in use
58   /*!
59     Defaults to $(HOME)/.openbox/menu3
60   */
61   std::string _menufilepath;
62   //! The display requested by the user, or null to use the DISPLAY env var
63   char *_displayreq;
64   //! The value of argv[0], i.e. how this application was executed
65   char *_argv0;
66
67   //! Manages all timers for the application
68   /*!
69     Use of the otk::OBTimerQueueManager::fire funtion in this object ensures
70     that all timers fire when their times elapse.
71   */
72   otk::OBTimerQueueManager _timermanager;
73
74   //! The class which will handle raw XEvents
75   OBXEventHandler _xeventhandler;
76
77   //! Cached atoms on the display
78   /*!
79     This is a pointer because the OBProperty class uses otk::OBDisplay::display
80     in its constructor, so, it needs to be initialized <b>after</b> the display
81     is initialized in this class' constructor.
82   */
83   otk::OBProperty *_property;
84
85   //! The running state of the window manager
86   RunState _state;
87
88   //! When set to true, the Openbox::eventLoop function will stop and return
89   bool _doshutdown;
90
91   //! Parses the command line used when executing this application
92   void parseCommandLine(int argv, char **argv);
93   //! Displays the version string to stdout
94   void showVersion();
95   //! Displays usage information and help to stdout
96   void showHelp();
97
98   //! Handles signal events for the application
99   static void signalHandler(int signal);
100
101 public:
102   //! Openbox constructor.
103   /*!
104     \param argc Number of command line arguments, as received in main()
105     \param argv The command line arguments, as received in main()
106   */
107   Openbox(int argc, char **argv);
108   //! Openbox destructor.
109   virtual ~Openbox();
110
111   //! Returns the state of the window manager (starting, exiting, etc)
112   inline RunState state() const { return _state; }
113
114   //! Returns the otk::OBTimerQueueManager for the application
115   /*!
116     All otk::OBTimer objects used in the application should be made to use this
117     otk::OBTimerQueueManager.
118   */
119   inline otk::OBTimerQueueManager *timerManager() { return &_timermanager; }
120
121   //! The main function of the Openbox class
122   /*!
123     This function should be called after instantiating the Openbox class.
124     It loops indefinately while handling all events for the application.
125     The Openbox::shutdown method will cause this function to exit.
126   */
127   void eventLoop();
128
129   //! Requests that the window manager exit
130   /*!
131     Causes the Openbox::eventLoop function to stop looping, so that the window
132     manager can be destroyed.
133   */
134   inline void shutdown() { _doshutdown = true; }
135 };
136
137 }
138
139 #endif // __openbox_hh