1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
14 #include "otk/strut.hh"
15 #include "otk/rect.hh"
16 #include "otk/renderstyle.hh"
17 #include "otk/ustring.hh"
18 #include "otk/surface.hh"
19 #include "otk/eventhandler.hh"
26 //! Varius geometry settings in the frame decorations
27 struct FrameGeometry
{
28 int width
; // title and handle
30 int title_height() { return font_height
+ bevel
*2; }
32 int label_height() { return font_height
; }
33 int handle_height
; // static, from the style
34 int icon_x
; // x-position of the window icon button
35 int title_x
; // x-position of the window title
36 int iconify_x
; // x-position of the window iconify button
37 int desktop_x
; // x-position of the window all-desktops button
38 int max_x
; // x-position of the window maximize button
39 int close_x
; // x-position of the window close button
41 int button_size
; // static, from the style
42 int grip_width() { return button_size
* 2; }
43 int bevel
; // static, from the style
44 int bwidth
; // frame elements' border width
45 int cbwidth
; // client border width
48 //! Holds and decorates a frame around an Client (client window)
50 The frame is responsible for calling XSelectInput on the client window's new
51 parent with the SubstructureRedirectMask so that structure events for the
52 client are sent to the window manager.
54 class Frame
: public otk::StyleNotify
, public otk::EventHandler
{
57 //! The event mask to grab on frame windows
58 static const long event_mask
= EnterWindowMask
| LeaveWindowMask
;
63 //! The size of the frame on each side of the client window
66 //! The size of the frame on each side of the client window inside the border
67 otk::Strut _innersize
;
69 //! The position and size of the entire frame (including borders)
74 //! The decorations that are being displayed in the frame.
75 Client::DecorationFlags _decorations
;
78 Window _frame
; // sits under everything
79 Window _plate
; // sits entirely under the client window
80 Window _title
; // the titlebar
81 Window _label
; // the section of the titlebar which shows the window name
82 Window _handle
; // bottom bar
83 Window _lgrip
; // lefthand resize grab on the handle
84 Window _rgrip
; // righthand resize grab on the handle
85 Window _max
; // maximize button
86 Window _desk
; // all-desktops button
87 Window _iconify
; // iconify button
88 Window _icon
; // window icon button
89 Window _close
; // close button
92 otk::Surface
*_frame_sur
;
93 otk::Surface
*_title_sur
;
94 otk::Surface
*_label_sur
;
95 otk::Surface
*_handle_sur
;
96 otk::Surface
*_grip_sur
;
97 otk::Surface
*_max_sur
;
98 otk::Surface
*_desk_sur
;
99 otk::Surface
*_iconify_sur
;
100 otk::Surface
*_icon_sur
;
101 otk::Surface
*_close_sur
;
103 otk::ustring _layout
; // layout of the titlebar
110 unsigned int _press_button
; // mouse button that started the press
114 void applyStyle(const otk::RenderStyle
&style
);
119 void renderIconify();
124 //! Constructs an Frame object for a client
126 @param client The client which will be decorated by the new Frame
128 Frame(Client
*client
);
129 //! Destroys the Frame object
132 //! Returns the size of the frame on each side of the client
133 const otk::Strut
& size() const { return _size
; }
135 //! Set the style to decorate the frame with
136 virtual void styleChanged(const otk::RenderStyle
&style
);
138 //! Reparents the client window from the root window onto the frame
140 //! Reparents the client window back to the root window
141 void releaseClient();
143 //! Update the frame's size to match the client
145 //! Update the frame's position to match the client
146 void adjustPosition();
147 //! Shape the frame window to the client window
149 //! Update the frame to match the client's new state (for things like toggle
150 //! buttons, focus, and the title) XXX break this up
156 //! Applies gravity to the client's position to find where the frame should
159 @return The proper coordinates for the frame, based on the client.
161 void clientGravity(int &x
, int &y
);
163 //! Reversly applies gravity to the frame's position to find where the client
164 //! should be positioned.
166 @return The proper coordinates for the client, based on the frame.
168 void frameGravity(int &x
, int &y
);
170 //! The position and size of the frame window
171 inline const otk::Rect
& area() const { return _area
; }
173 //! Returns if the frame is visible
174 inline bool visible() const { return _visible
; }
181 void buttonPressHandler(const XButtonEvent
&e
);
182 void buttonReleaseHandler(const XButtonEvent
&e
);
184 //! Returns the MouseContext for the given window id
186 Returns '-1' if no valid mouse context exists in the frame for the given
189 ob::MouseContext::MC
mouseContext(Window win
) const;
191 //! Gets the window id of the frame's base top-level parent
192 inline Window
window() const { return _frame
; }
193 //! Gets the window id of the client's parent window
194 inline Window
plate() const { return _plate
; }
196 //! Returns a null terminated array of the window ids that make up the
197 //! frame's decorations.
198 Window
*allWindows() const;