]> icculus.org git repositories - dana/openbox.git/blob - src/client.hh
read protocols too in OBClient
[dana/openbox.git] / src / client.hh
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 #ifndef   __client_hh
3 #define   __client_hh
4
5 extern "C" {
6 #include <X11/Xlib.h>
7 }
8
9 #include <string>
10
11 #include "otk/strut.hh"
12 #include "otk/rect.hh"
13
14 namespace ob {
15
16 class OBClient {
17 public:
18   enum Max { Max_None,
19              Max_Horz,
20              Max_Vert,
21              Max_Full };
22
23   enum WindowType { Type_Desktop,
24                     Type_Dock,
25                     Type_Toolbar,
26                     Type_Menu,
27                     Type_Utility,
28                     Type_Splash,
29                     Type_Dialog,
30                     Type_Normal };
31
32   enum MwmFlags { Functions   = 1 << 0,
33                   Decorations = 1 << 1 };
34
35   enum MwmFunctions { MwmFunc_All      = 1 << 0,
36                       MwmFunc_Resize   = 1 << 1,
37                       MwmFunc_Move     = 1 << 2,
38                       MwmFunc_Iconify  = 1 << 3,
39                       MwmFunc_Maximize = 1 << 4,
40                       MwmFunc_Close    = 1 << 5 };
41
42   enum MemDecorations { MemDecor_All      = 1 << 0,
43                         MemDecor_Border   = 1 << 1,
44                         MemDecor_Handle   = 1 << 2,
45                         MemDecor_Title    = 1 << 3,
46                         //MemDecor_Menu     = 1 << 4,
47                         MemDecor_Iconify  = 1 << 5,
48                         MemDecor_Maximize = 1 << 6 };
49
50   // this structure only contains 3 elements... the Motif 2.0 structure
51   // contains 5... we only need the first 3... so that is all we will define
52   typedef struct MwmHints {
53     static const int elements = 3;
54     unsigned long flags;
55     unsigned long functions;
56     unsigned long decorations;
57   };
58
59   enum StateAction { State_Remove = 0, // _NET_WM_STATE_REMOVE
60                      State_Add,        // _NET_WM_STATE_ADD
61                      State_Toggle      // _NET_WM_STATE_TOGGLE
62   };
63
64 private:
65   //! The actual window that this class is wrapping up
66   Window   _window;
67
68   //! The id of the group the window belongs to
69   Window   _group;
70
71   // XXX: transient_for, transients
72
73   //! The desktop on which the window resides (0xffffffff for all desktops)
74   unsigned long _desktop;
75
76   //! Normal window title
77   std::string  _title; // XXX: Have to keep track if this string is Utf8 or not
78   //! Window title when iconifiged
79   std::string  _icon_title;
80
81   //! The application that created the window
82   std::string  _app_name;
83   //! The class of the window, can used for grouping
84   std::string  _app_class;
85
86   //! The type of window (what its function is)
87   WindowType   _type;
88
89   //! Position and size of the window (relative to the root window)
90   otk::Rect    _area;
91
92   //! Width of the border on the window.
93   /*!
94     The window manager will set this to 0 while the window is being managed,
95     but needs to restore it afterwards, so it is saved here.
96   */
97   int _border_width;
98
99   // size bounds
100   // if min > max, then the window is not resizable
101   int _min_x, _min_y; // minumum size
102   int _max_x, _max_y; // maximum size
103   int _inc_x, _inc_y; // resize increments
104   int _base_x, _base_y; // base size
105
106   //! Where to place the decorated window in relation to the undecorated window
107   int _gravity;
108
109   //! The state of the window, one of WithdrawnState, IconicState, or
110   //! NormalState
111   long _wmstate;
112
113   //! Was the window's position requested by the application? if not, we should
114   //! place the window ourselves when it first appears
115   bool _positioned;
116   
117   //! Can the window receive input focus?
118   bool _can_focus;
119   //! Urgency flag
120   bool _urgent;
121   //! Notify the window when it receives focus?
122   bool _focus_notify;
123
124   //! The window uses shape extension to be non-rectangular?
125   bool _shaped;
126
127   //! The window is modal, so it must be processed before any windows it is
128   //! related to can be focused
129   bool _modal;
130   //! Only the window's titlebar is displayed
131   bool _shaded;
132   //! The window is iconified
133   bool _iconic;
134   //! The window is maximized to fill the screen vertically
135   bool _max_vert;
136   //! The window is maximized to fill the screen horizontally
137   bool _max_horz;
138   //! The window is a 'fullscreen' window, and should be on top of all others
139   bool _fullscreen;
140   //! The window should be on top of other windows of the same type
141   bool _floating;
142
143   // XXX: motif decoration hints!
144
145   void getDesktop();
146   void getType();
147   void getArea();
148   void getState();
149   void getShaped();
150
151   void setWMState(long state);
152   void setDesktop(long desktop);
153   void setState(StateAction action, long data1, long data2);
154
155   void updateProtocols();
156   void updateNormalHints();
157   void updateWMHints();
158   // XXX: updateTransientFor();
159   void updateTitle();
160   void updateClass();
161
162 public:
163   OBClient(Window window);
164   virtual ~OBClient();
165
166   inline Window window() const { return _window; }
167
168   inline WindowType type() const { return _type; }
169   inline unsigned long desktop() const { return _desktop; }
170   inline const std::string &title() const { return _title; }
171   inline const std::string &iconTitle() const { return _title; }
172   inline const std::string &appName() const { return _app_name; }
173   inline const std::string &appClass() const { return _app_class; }
174   inline bool canFocus() const { return _can_focus; }
175   inline bool urgent() const { return _urgent; }
176   inline bool focusNotify() const { return _focus_notify; }
177   inline bool shaped() const { return _shaped; }
178   inline int gravity() const { return _gravity; }
179
180   // states
181   inline bool modal() const { return _modal; }
182   inline bool shaded() const { return _shaded; }
183   inline bool iconic() const { return _iconic; }
184   inline bool maxVert() const { return _max_vert; }
185   inline bool maxHorz() const { return _max_horz; }
186   inline bool fullscreen() const { return _fullscreen; }
187   inline bool floating() const { return _floating; }
188
189   inline int minX() const { return _min_x; }
190   inline int minY() const { return _min_y; }
191   inline int maxX() const { return _max_x; }
192   inline int maxY() const { return _max_y; }
193   inline int incrementX() const { return _inc_x; }
194   inline int incrementY() const { return _inc_y; }
195   inline int baseX() const { return _base_x; }
196   inline int baseY() const { return _base_y; }
197
198   inline const otk::Rect &area() const { return _area; }
199
200   void update(const XPropertyEvent &e);
201   void update(const XClientMessageEvent &e);
202
203   void setArea(const otk::Rect &area);
204 };
205
206 }
207
208 #endif // __client_hh