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.cc205
1 files changed, 205 insertions, 0 deletions
diff --git a/src/FbTk/FbWindow.cc b/src/FbTk/FbWindow.cc
new file mode 100644
index 0000000..5c0b2d2
--- /dev/null
+++ b/src/FbTk/FbWindow.cc
@@ -0,0 +1,205 @@
1// FbWindow.cc for FbTk - fluxbox toolkit
2// Copyright (c) 2002 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.7 2003/02/23 16:52:16 fluxgen Exp $
23
24#include "FbWindow.hh"
25
26#include "Color.hh"
27#include "App.hh"
28
29#include <cassert>
30
31namespace FbTk {
32
33Display *FbWindow::s_display = 0;
34
35FbWindow::FbWindow():m_parent(0), m_screen_num(0), m_window(0), m_x(0), m_y(0),
36 m_width(0), m_height(0), m_border_width(0) {
37
38 if (s_display == 0)
39 s_display = App::instance()->display();
40}
41
42FbWindow::FbWindow(int screen_num,
43 int x, int y, size_t width, size_t height, long eventmask,
44 bool override_redirect,
45 int depth,
46 int class_type):
47 m_screen_num(screen_num),
48 m_parent(0) {
49
50 create(RootWindow(FbTk::App::instance()->display(), screen_num),
51 x, y, width, height, eventmask,
52 override_redirect, depth, class_type);
53};
54
55FbWindow::FbWindow(const FbWindow &parent,
56 int x, int y, size_t width, size_t height, long eventmask,
57 bool override_redirect,
58 int depth, int class_type):
59 m_parent(&parent),
60 m_screen_num(parent.screenNumber()) {
61
62 create(parent.window(), x, y, width, height, eventmask,
63 override_redirect, depth, class_type);
64
65
66};
67
68FbWindow::~FbWindow() {
69 if (m_window != 0)
70 XDestroyWindow(s_display, m_window);
71}
72
73
74void FbWindow::setBackgroundColor(const FbTk::Color &bg_color) {
75 XSetWindowBackground(s_display, m_window, bg_color.pixel());
76}
77
78void FbWindow::setBackgroundPixmap(Pixmap bg_pixmap) {
79 XSetWindowBackgroundPixmap(s_display, m_window, bg_pixmap);
80}
81
82void FbWindow::setBorderColor(const FbTk::Color &border_color) {
83 XSetWindowBorder(s_display, m_window, border_color.pixel());
84}
85void FbWindow::setBorderWidth(size_t size) {
86 XSetWindowBorderWidth(s_display, m_window, size);
87 m_border_width = size;
88}
89
90void FbWindow::setName(const char *name) {
91 XStoreName(s_display, m_window, name);
92}
93
94void FbWindow::setEventMask(long mask) {
95 XSelectInput(s_display, m_window, mask);
96}
97
98void FbWindow::clear() {
99 XClearWindow(s_display, m_window);
100}
101
102FbWindow &FbWindow::operator = (Window win) {
103 if (m_window != 0)
104 XDestroyWindow(s_display, m_window);
105 m_window = win;
106 if (m_window != 0)
107 updateGeometry();
108
109 return *this;
110}
111
112void FbWindow::show() {
113 XMapWindow(s_display, m_window);
114}
115
116void FbWindow::showSubwindows() {
117 XMapSubwindows(s_display, m_window);
118}
119
120void FbWindow::hide() {
121 XUnmapWindow(s_display, m_window);
122}
123
124void FbWindow::move(int x, int y) {
125 XMoveWindow(s_display, m_window, x, y);
126 m_x = x;
127 m_y = y;
128}
129
130void FbWindow::resize(size_t width, size_t height) {
131 XResizeWindow(s_display, m_window, width, height);
132 m_width = width;
133 m_height = height;
134}
135
136void FbWindow::moveResize(int x, int y, size_t width, size_t height) {
137 XMoveResizeWindow(s_display, m_window, x, y, width, height);
138 m_x = x;
139 m_y = y;
140 m_width = width;
141 m_height = height;
142}
143
144void FbWindow::lower() {
145 XLowerWindow(s_display, m_window);
146}
147
148void FbWindow::raise() {
149 XRaiseWindow(s_display, m_window);
150}
151
152int FbWindow::screenNumber() const {
153 return m_screen_num;
154}
155void FbWindow::updateGeometry() {
156 if (m_window == 0)
157 return;
158
159 Window root;
160 unsigned int border_width, depth;
161 XGetGeometry(s_display, m_window, &root, &m_x, &m_y,
162 (unsigned int *)&m_width, (unsigned int *)&m_height,
163 &border_width, &depth);
164}
165
166void FbWindow::create(Window parent, int x, int y,
167 size_t width, size_t height,
168 long eventmask, bool override_redirect,
169 int depth, int class_type) {
170
171
172 if (s_display == 0)
173 s_display = FbTk::App::instance()->display();
174
175 assert(s_display);
176
177 m_border_width = 0;
178
179 long valmask = CWEventMask;
180 XSetWindowAttributes values;
181 values.event_mask = eventmask;
182
183 if (override_redirect) {
184 valmask |= CWOverrideRedirect;
185 values.override_redirect = True;
186 }
187
188 m_window = XCreateWindow(s_display, parent, x, y, width, height,
189 0, // border width
190 depth, // depth
191 class_type, // class
192 CopyFromParent, // visual
193 valmask, // create mask
194 &values); // create atrribs
195
196 assert(m_window);
197
198 updateGeometry();
199}
200
201bool operator == (Window win, const FbWindow &fbwin) {
202 return win == fbwin.window();
203}
204
205};