aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/FbWindow.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk/FbWindow.hh')
-rw-r--r--src/FbTk/FbWindow.hh237
1 files changed, 237 insertions, 0 deletions
diff --git a/src/FbTk/FbWindow.hh b/src/FbTk/FbWindow.hh
new file mode 100644
index 0000000..33d2158
--- /dev/null
+++ b/src/FbTk/FbWindow.hh
@@ -0,0 +1,237 @@
1// FbWindow.hh for FbTk - fluxbox toolkit
2// Copyright (c) 2002 - 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net)
3//
4// Permission is hereby granted, free of charge, to any person obtaining a
5// copy of this software and associated documentation files (the "Software"),
6// to deal in the Software without restriction, including without limitation
7// the rights to use, copy, modify, merge, publish, distribute, sublicense,
8// and/or sell copies of the Software, and to permit persons to whom the
9// Software is furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20// DEALINGS IN THE SOFTWARE.
21
22// $Id: FbWindow.hh,v 1.28 2004/01/21 20:22:26 fluxgen Exp $
23
24#ifndef FBTK_FBWINDOW_HH
25#define FBTK_FBWINDOW_HH
26
27#include "FbDrawable.hh"
28
29#include <X11/Xlib.h>
30#include <memory>
31
32
33namespace FbTk {
34
35class Color;
36class Transparent;
37
38/// Wrapper for X window
39/**
40 * Example:
41 * FbWindow window(0, 10, 10, 100, 100, ExposeMask | ButtonPressMask); \n
42 * this will create a window on screen 0, position 10 10, size 100 100 \n
43 * and with eventmask Expose and ButtonPress. \n
44 * You need to register it to some eventhandler so you can catch events: \n
45 * EventManager::instance()->add(your_eventhandler, window); \n
46 * @see EventHandler
47 * @see EventManager
48 */
49class FbWindow: public FbDrawable {
50public:
51 FbWindow();
52
53 FbWindow(const FbWindow &win_copy);
54
55 FbWindow(int screen_num,
56 int x, int y, unsigned int width, unsigned int height, long eventmask,
57 bool overrride_redirect = false,
58 int depth = CopyFromParent,
59 int class_type = InputOutput);
60
61 FbWindow(const FbWindow &parent,
62 int x, int y,
63 unsigned int width, unsigned int height,
64 long eventmask,
65 bool overrride_redirect = false,
66 int depth = CopyFromParent,
67 int class_type = InputOutput);
68
69 virtual ~FbWindow();
70 virtual void setBackgroundColor(const FbTk::Color &bg_color);
71 virtual void setBackgroundPixmap(Pixmap bg_pixmap);
72 virtual void setBorderColor(const FbTk::Color &border_color);
73 virtual void setBorderWidth(unsigned int size);
74 /// set window name ("title")
75 void setName(const char *name);
76 void setEventMask(long mask);
77 /// clear window with background pixmap or color
78 virtual void clear();
79 /// @param exposures wheter Expose event should be generated
80 virtual void clearArea(int x, int y,
81 unsigned int width, unsigned int height,
82 bool exposures = false);
83 void updateTransparent(int x = -1, int y = -1, unsigned int width = 0, unsigned int height = 0);
84
85 void setAlpha(unsigned char alpha);
86
87 virtual FbWindow &operator = (const FbWindow &win);
88 /// assign a new X window to this
89 virtual FbWindow &operator = (Window win);
90 virtual void hide();
91 virtual void show();
92 virtual void showSubwindows();
93
94 virtual inline void move(int x, int y) {
95 XMoveWindow(s_display, m_window, x, y);
96 m_x = x;
97 m_y = y;
98 }
99
100 virtual inline void resize(unsigned int width, unsigned int height) {
101 XResizeWindow(s_display, m_window, width, height);
102 m_width = width;
103 m_height = height;
104 }
105
106 virtual inline void moveResize(int x, int y, unsigned int width, unsigned int height) {
107 XMoveResizeWindow(s_display, m_window, x, y, width, height);
108 m_x = x;
109 m_y = y;
110 m_width = width;
111 m_height = height;
112 }
113 virtual void lower();
114 virtual void raise();
115 void setInputFocus(int revert_to, int time);
116 /// defines a cursor for this window
117 void setCursor(Cursor cur);
118 /// uses the parents cursor instead
119 void unsetCursor();
120 void reparent(const FbWindow &parent, int x, int y);
121
122 bool property(Atom property,
123 long long_offset, long long_length,
124 bool do_delete,
125 Atom req_type,
126 Atom *actual_type_return,
127 int *actual_format_return,
128 unsigned long *nitems_return,
129 unsigned long *bytes_after_return,
130 unsigned char **prop_return) const;
131
132 void changeProperty(Atom property, Atom type,
133 int format,
134 int mode,
135 unsigned char *data,
136 int nelements);
137
138 inline void sendEvent(bool propagate,
139 long eventmask,
140 XEvent &event) const {
141 XSendEvent(s_display,
142 window(),
143 propagate,
144 eventmask,
145 &event);
146 }
147 /// @return parent FbWindow
148 const FbWindow *parent() const { return m_parent; }
149 /// @return real X window
150 inline Window window() const { return m_window; }
151 /// @return drawable (the X window)
152 inline Drawable drawable() const { return window(); }
153 inline int x() const { return m_x; }
154 inline int y() const { return m_y; }
155 inline unsigned int width() const { return m_width; }
156 inline unsigned int height() const { return m_height; }
157 inline unsigned int borderWidth() const { return m_border_width; }
158 inline int depth() const { return m_depth; }
159 unsigned char alpha() const;
160
161 int screenNumber() const;
162 long eventMask() const;
163 /// compare X window
164 inline bool operator == (Window win) const { return m_window == win; }
165 inline bool operator != (Window win) const { return m_window != win; }
166 /// compare two windows
167 inline bool operator == (const FbWindow &win) const { return m_window == win.m_window; }
168 inline bool operator != (const FbWindow &win) const { return m_window != win.m_window; }
169 /// updates x,y, width, height and screen num from X window
170 void updateGeometry();
171 inline void updateGeometry(int x, int y,
172 unsigned int width, unsigned int height) {
173 m_x = x; m_y = y; m_width = width; m_height = height;
174 }
175 inline void translateCoordinates(const FbWindow &dest, int x, int y,
176 int &ret_x, int &ret_y,
177 Window &child_return) const {
178 XTranslateCoordinates(s_display,
179 window(),
180 dest.window(),
181 x, y,
182 &ret_x, &ret_y,
183 &child_return);
184 }
185protected:
186 /// creates a window with x window client (m_window = client)
187 explicit FbWindow(Window client);
188 void setBufferPixmap(Pixmap pm);
189
190private:
191 /// sets new X window and destroys old
192 void setNew(Window win);
193 /// creates a new X window
194 void create(Window parent, int x, int y, unsigned int width, unsigned int height,
195 long eventmask,
196 bool override_redirect,
197 int depth,
198 int class_type);
199 static Display *s_display; ///< display connection
200 const FbWindow *m_parent; ///< parent FbWindow
201 int m_screen_num; ///< screen num on which this window exist
202 mutable Window m_window; ///< the X window
203 int m_x, m_y; ///< position of window
204 unsigned int m_width, m_height; ///< size of window
205 unsigned int m_border_width; ///< border size
206 int m_depth; ///< bit depth
207 bool m_destroy; ///< wheter the x window was created before
208 std::auto_ptr<FbTk::Transparent> m_transparent;
209 Pixmap m_buffer_pm;
210};
211
212bool operator == (Window win, const FbWindow &fbwin);
213
214/// helper class for some STL routines
215class ChangeProperty {
216public:
217 ChangeProperty(Display *disp, Atom prop, int mode,
218 unsigned char *state, int num):m_disp(disp),
219 m_prop(prop), m_state(state), m_num(num), m_mode(mode){
220
221 }
222 void operator () (FbTk::FbWindow *win) {
223 XChangeProperty(m_disp, win->window(), m_prop, m_prop, 32, m_mode,
224 m_state, m_num);
225 }
226private:
227 Display *m_disp;
228 Atom m_prop;
229 unsigned char *m_state;
230 int m_num;
231 int m_mode;
232
233};
234
235} // end namespace FbTk
236
237#endif // FBTK_FBWINDOW_HH