aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/FbWindow.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk/FbWindow.cc')
-rw-r--r--src/FbTk/FbWindow.cc287
1 files changed, 287 insertions, 0 deletions
diff --git a/src/FbTk/FbWindow.cc b/src/FbTk/FbWindow.cc
new file mode 100644
index 0000000..509dd6c
--- /dev/null
+++ b/src/FbTk/FbWindow.cc
@@ -0,0 +1,287 @@
1// FbWindow.cc 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.cc,v 1.22 2003/07/02 05:17:30 fluxgen Exp $
23
24#include "FbWindow.hh"
25#include "EventManager.hh"
26
27#include "Color.hh"
28#include "App.hh"
29
30#include <cassert>
31
32namespace FbTk {
33
34Display *FbWindow::s_display = 0;
35
36FbWindow::FbWindow():m_parent(0), m_screen_num(0), m_window(0), m_x(0), m_y(0),
37 m_width(0), m_height(0), m_border_width(0), m_depth(0), m_destroy(true) {
38
39 if (s_display == 0)
40 s_display = App::instance()->display();
41}
42
43FbWindow::FbWindow(int screen_num,
44 int x, int y,
45 unsigned int width, unsigned int height,
46 long eventmask,
47 bool override_redirect,
48 int depth,
49 int class_type):
50 m_screen_num(screen_num),
51 m_parent(0), m_destroy(true) {
52
53 create(RootWindow(FbTk::App::instance()->display(), screen_num),
54 x, y, width, height, eventmask,
55 override_redirect, depth, class_type);
56};
57
58FbWindow::FbWindow(const FbWindow &parent,
59 int x, int y, unsigned int width, unsigned int height,
60 long eventmask,
61 bool override_redirect,
62 int depth, int class_type):
63 m_parent(&parent),
64 m_screen_num(parent.screenNumber()), m_destroy(true) {
65
66 create(parent.window(), x, y, width, height, eventmask,
67 override_redirect, depth, class_type);
68
69
70};
71
72FbWindow::FbWindow(Window client):m_parent(0), m_window(0),
73 m_screen_num(0),
74 m_destroy(false) { // don't destroy this window
75
76 setNew(client);
77}
78
79FbWindow::~FbWindow() {
80
81 if (m_window != 0) {
82 // so we don't get any dangling eventhandler for this window
83 FbTk::EventManager::instance()->remove(m_window);
84 if (m_destroy)
85 XDestroyWindow(s_display, m_window);
86 }
87}
88
89
90void FbWindow::setBackgroundColor(const FbTk::Color &bg_color) {
91 XSetWindowBackground(s_display, m_window, bg_color.pixel());
92}
93
94void FbWindow::setBackgroundPixmap(Pixmap bg_pixmap) {
95 XSetWindowBackgroundPixmap(s_display, m_window, bg_pixmap);
96}
97
98void FbWindow::setBorderColor(const FbTk::Color &border_color) {
99 XSetWindowBorder(s_display, m_window, border_color.pixel());
100}
101void FbWindow::setBorderWidth(unsigned int size) {
102 XSetWindowBorderWidth(s_display, m_window, size);
103 m_border_width = size;
104}
105
106void FbWindow::setName(const char *name) {
107 XStoreName(s_display, m_window, name);
108}
109
110void FbWindow::setEventMask(long mask) {
111 XSelectInput(s_display, m_window, mask);
112}
113
114void FbWindow::clear() {
115 XClearWindow(s_display, m_window);
116}
117
118void FbWindow::clearArea(int x, int y,
119 unsigned int width, unsigned int height,
120 bool exposures) {
121 XClearArea(s_display, window(), x, y, width, height, exposures);
122}
123
124FbWindow &FbWindow::operator = (Window win) {
125 setNew(win);
126 return *this;
127}
128
129void FbWindow::setNew(Window win) {
130 if (s_display == 0)
131 s_display = App::instance()->display();
132
133 if (m_window != 0 && m_destroy)
134 XDestroyWindow(s_display, m_window);
135 m_window = win;
136 if (m_window != 0) {
137 updateGeometry();
138 XWindowAttributes attr;
139 attr.screen = 0;
140 //get screen number
141 if (XGetWindowAttributes(s_display,
142 m_window,
143 &attr) != 0 && attr.screen != 0) {
144 m_screen_num = XScreenNumberOfScreen(attr.screen);
145 }
146 }
147}
148
149void FbWindow::show() {
150 XMapWindow(s_display, m_window);
151}
152
153void FbWindow::showSubwindows() {
154 XMapSubwindows(s_display, m_window);
155}
156
157void FbWindow::hide() {
158 XUnmapWindow(s_display, m_window);
159}
160
161void FbWindow::move(int x, int y) {
162 XMoveWindow(s_display, m_window, x, y);
163 m_x = x;
164 m_y = y;
165}
166
167void FbWindow::resize(unsigned int width, unsigned int height) {
168 XResizeWindow(s_display, m_window, width, height);
169 m_width = width;
170 m_height = height;
171}
172
173void FbWindow::moveResize(int x, int y, unsigned int width, unsigned int height) {
174 XMoveResizeWindow(s_display, m_window, x, y, width, height);
175 m_x = x;
176 m_y = y;
177 m_width = width;
178 m_height = height;
179}
180
181void FbWindow::lower() {
182 XLowerWindow(s_display, window());
183}
184
185void FbWindow::raise() {
186 XRaiseWindow(s_display, window());
187}
188
189void FbWindow::setInputFocus(int revert_to, int time) {
190 XSetInputFocus(s_display, window(), revert_to, time);
191}
192
193void FbWindow::setCursor(Cursor cur) {
194 XDefineCursor(s_display, window(), cur);
195}
196
197void FbWindow::unsetCursor() {
198 XUndefineCursor(s_display, window());
199}
200
201
202bool FbWindow::property(Atom property,
203 long long_offset, long long_length,
204 bool do_delete,
205 Atom req_type,
206 Atom *actual_type_return,
207 int *actual_format_return,
208 unsigned long *nitems_return,
209 unsigned long *bytes_after_return,
210 unsigned char **prop_return) const {
211 if (XGetWindowProperty(s_display, window(),
212 property, long_offset, long_length, do_delete,
213 req_type, actual_type_return,
214 actual_format_return, nitems_return,
215 bytes_after_return, prop_return) == Success)
216 return true;
217
218 return false;
219}
220
221void FbWindow::changeProperty(Atom property, Atom type,
222 int format,
223 int mode,
224 unsigned char *data,
225 int nelements) {
226
227 XChangeProperty(s_display, m_window, property, type,
228 format, mode,
229 data, nelements);
230}
231
232int FbWindow::screenNumber() const {
233 return m_screen_num;
234}
235
236void FbWindow::updateGeometry() {
237 if (m_window == 0)
238 return;
239
240 Window root;
241 unsigned int border_width, depth;
242 XGetGeometry(s_display, m_window, &root, &m_x, &m_y,
243 (unsigned int *)&m_width, (unsigned int *)&m_height,
244 &border_width, &depth);
245 m_depth = depth;
246}
247
248void FbWindow::create(Window parent, int x, int y,
249 unsigned int width, unsigned int height,
250 long eventmask, bool override_redirect,
251 int depth, int class_type) {
252
253
254 if (s_display == 0)
255 s_display = FbTk::App::instance()->display();
256
257 assert(s_display);
258
259 m_border_width = 0;
260
261 long valmask = CWEventMask;
262 XSetWindowAttributes values;
263 values.event_mask = eventmask;
264
265 if (override_redirect) {
266 valmask |= CWOverrideRedirect;
267 values.override_redirect = True;
268 }
269
270 m_window = XCreateWindow(s_display, parent, x, y, width, height,
271 0, // border width
272 depth, // depth
273 class_type, // class
274 CopyFromParent, // visual
275 valmask, // create mask
276 &values); // create atrribs
277
278 assert(m_window);
279
280 updateGeometry();
281}
282
283bool operator == (Window win, const FbWindow &fbwin) {
284 return win == fbwin.window();
285}
286
287};