]> Dogcows Code - chaz/openbox/blob - src/frame.hh
buttons press!
[chaz/openbox] / 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
98 bool _max_press;
99 bool _desk_press;
100 bool _iconify_press;
101 bool _icon_press;
102 bool _close_press;
103 unsigned int _press_button; // mouse button that started the press
104
105 FrameGeometry geom;
106
107 void applyStyle(const otk::RenderStyle &style);
108 void layoutTitle();
109 void renderLabel();
110 void renderMax();
111 void renderDesk();
112 void renderIconify();
113 void renderClose();
114 void renderIcon();
115
116 public:
117 //! Constructs an Frame object for a client
118 /*!
119 @param client The client which will be decorated by the new Frame
120 */
121 Frame(Client *client);
122 //! Destroys the Frame object
123 virtual ~Frame();
124
125 //! Returns the size of the frame on each side of the client
126 const otk::Strut& size() const { return _size; }
127
128 //! Set the style to decorate the frame with
129 virtual void styleChanged(const otk::RenderStyle &style);
130
131 //! Reparents the client window from the root window onto the frame
132 void grabClient();
133 //! Reparents the client window back to the root window
134 void releaseClient();
135
136 //! Update the frame's size to match the client
137 void adjustSize();
138 //! Update the frame's position to match the client
139 void adjustPosition();
140 //! Shape the frame window to the client window
141 void adjustShape();
142 //! Update the frame to match the client's new state (for things like toggle
143 //! buttons, focus, and the title) XXX break this up
144 void adjustState();
145 void adjustFocus();
146 void adjustTitle();
147
148 //! Applies gravity to the client's position to find where the frame should
149 //! be positioned.
150 /*!
151 @return The proper coordinates for the frame, based on the client.
152 */
153 void clientGravity(int &x, int &y);
154
155 //! Reversly applies gravity to the frame's position to find where the client
156 //! should be positioned.
157 /*!
158 @return The proper coordinates for the client, based on the frame.
159 */
160 void frameGravity(int &x, int &y);
161
162 //! The position and size of the frame window
163 inline const otk::Rect& area() const { return _area; }
164
165 //! Returns if the frame is visible
166 inline bool visible() const { return _visible; }
167
168 //! Shows the frame
169 void show();
170 //! Hides the frame
171 void hide();
172
173 void buttonPressHandler(const XButtonEvent &e);
174 void buttonReleaseHandler(const XButtonEvent &e);
175
176 //! Returns the MouseContext for the given window id
177 /*!
178 Returns '-1' if no valid mouse context exists in the frame for the given
179 id.
180 */
181 ob::MouseContext::MC mouseContext(Window win) const;
182
183 //! Gets the window id of the frame's base top-level parent
184 inline Window window() const { return _frame; }
185 //! Gets the window id of the client's parent window
186 inline Window plate() const { return _plate; }
187
188 //! Returns a null terminated array of the window ids that make up the
189 //! frame's decorations.
190 Window *allWindows() const;
191 };
192
193 }
194
195 #endif // __frame_hh
This page took 0.049013 seconds and 5 git commands to generate.