]> icculus.org git repositories - dana/openbox.git/blob - src/frame.hh
readd titlebar buttons. but they dont press yet
[dana/openbox.git] / src / frame.hh
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 #ifndef   __frame_hh
3 #define   __frame_hh
4
5 /*! @file frame.hh
6 */
7
8 extern "C" {
9 #include <X11/Xlib.h>
10 }
11
12 #include "python.hh"
13 #include "otk/strut.hh"
14 #include "otk/rect.hh"
15 #include "otk/renderstyle.hh"
16 #include "otk/ustring.hh"
17 #include "otk/surface.hh"
18 #include "otk/eventhandler.hh"
19
20 #include <string>
21 #include <vector>
22
23 namespace ob {
24
25 class Client;
26
27 //! Varius geometry settings in the frame decorations
28 struct FrameGeometry {
29   int width; // title and handle
30   int font_height;
31   int title_height() { return font_height + bevel*2; }
32   int label_width;
33   int label_height() { return font_height; }
34   int handle_height; // static, from the style
35   int icon_x;        // x-position of the window icon button
36   int handle_y;
37   int button_size;   // static, from the style
38   int grip_width() { return button_size * 2; }
39   int bevel;         // static, from the style
40   int bwidth;  // frame elements' border width
41   int cbwidth; // client border width
42 };
43
44 //! Holds and decorates a frame around an Client (client window)
45 /*!
46   The frame is responsible for calling XSelectInput on the client window's new
47   parent with the SubstructureRedirectMask so that structure events for the
48   client are sent to the window manager.
49 */
50 class Frame : public otk::StyleNotify, public otk::EventHandler {
51 public:
52
53   //! The event mask to grab on frame windows
54   static const long event_mask = EnterWindowMask | LeaveWindowMask;
55    
56 private:
57   Client *_client;
58
59   //! The size of the frame on each side of the client window
60   otk::Strut _size;
61
62   //! The size of the frame on each side of the client window inside the border
63   otk::Strut _innersize;
64
65   //! The position and size of the entire frame (including borders)
66   otk::Rect _area;
67
68   bool _visible;
69   
70   // decoration windows
71   Window  _frame;   // sits under everything
72   Window  _plate;   // sits entirely under the client window
73   Window  _title;   // the titlebar
74   Window  _label;   // the section of the titlebar which shows the window name
75   Window  _handle;  // bottom bar
76   Window  _lgrip;   // lefthand resize grab on the handle
77   Window  _rgrip;   // righthand resize grab on the handle
78   Window  _max;     // maximize button
79   Window  _desk;    // all-desktops button
80   Window  _iconify; // iconify button
81   Window  _icon;    // window icon button
82   Window  _close;   // close button
83
84   // surfaces for each 
85   otk::Surface  *_frame_sur;
86   otk::Surface  *_title_sur;
87   otk::Surface  *_label_sur;
88   otk::Surface  *_handle_sur;
89   otk::Surface  *_grip_sur;
90   otk::Surface  *_max_sur;
91   otk::Surface  *_desk_sur;
92   otk::Surface  *_iconify_sur;
93   otk::Surface  *_icon_sur;
94   otk::Surface  *_close_sur;
95
96   std::string _layout; // layout of the titlebar
97   bool _max_press;
98   bool _desk_press;
99   bool _iconify_press;
100   bool _icon_press;
101   bool _close_press;
102
103   FrameGeometry geom;
104   
105   void applyStyle(const otk::RenderStyle &style);
106   void layoutTitle();
107   void renderLabel();
108   void renderMax();
109   void renderDesk();
110   void renderIconify();
111   void renderClose();
112   void renderIcon();
113
114 public:
115   //! Constructs an Frame object for a client
116   /*!
117     @param client The client which will be decorated by the new Frame
118   */
119   Frame(Client *client);
120   //! Destroys the Frame object
121   virtual ~Frame();
122
123   //! Returns the size of the frame on each side of the client
124   const otk::Strut& size() const { return _size; }
125   
126   //! Set the style to decorate the frame with
127   virtual void styleChanged(const otk::RenderStyle &style);
128
129   //! Reparents the client window from the root window onto the frame
130   void grabClient();
131   //! Reparents the client window back to the root window
132   void releaseClient();
133
134   //! Update the frame's size to match the client
135   void adjustSize();
136   //! Update the frame's position to match the client
137   void adjustPosition();
138   //! Shape the frame window to the client window
139   void adjustShape();
140   //! Update the frame to match the client's new state (for things like toggle
141   //! buttons, focus, and the title) XXX break this up
142   void adjustState();
143   void adjustFocus();
144   void adjustTitle();
145
146   //! Applies gravity to the client's position to find where the frame should
147   //! be positioned.
148   /*!
149     @return The proper coordinates for the frame, based on the client.
150   */
151   void clientGravity(int &x, int &y);
152
153   //! Reversly applies gravity to the frame's position to find where the client
154   //! should be positioned.
155   /*!
156     @return The proper coordinates for the client, based on the frame.
157   */
158   void frameGravity(int &x, int &y);
159
160   //! The position and size of the frame window
161   inline const otk::Rect& area() const { return _area; }
162
163   //! Returns if the frame is visible
164   inline bool visible() const { return _visible; }
165
166   //! Shows the frame
167   void show();
168   //! Hides the frame
169   void hide();
170
171   //! Returns the MouseContext for the given window id
172   /*!
173     Returns '-1' if no valid mouse context exists in the frame for the given
174     id.
175   */
176   ob::MouseContext::MC mouseContext(Window win) const;
177
178   //! Gets the window id of the frame's base top-level parent
179   inline Window window() const { return _frame; }
180   //! Gets the window id of the client's parent window
181   inline Window plate() const { return _plate; }
182
183   //! Returns a null terminated array of the window ids that make up the
184   //! frame's decorations.
185   Window *allWindows() const;
186 };
187
188 }
189
190 #endif // __frame_hh