aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/FbWindow.cc
diff options
context:
space:
mode:
authorfluxgen <fluxgen>2002-12-03 16:25:27 (GMT)
committerfluxgen <fluxgen>2002-12-03 16:25:27 (GMT)
commitd559c49e0ab91b2f21febd683096dae1856f813e (patch)
treefc97d15742af94fa2f87813bc36d3313050ae971 /src/FbTk/FbWindow.cc
parentb25fd24b490f14a5e3f02a68d7bda60b90aa1253 (diff)
downloadfluxbox-d559c49e0ab91b2f21febd683096dae1856f813e.zip
fluxbox-d559c49e0ab91b2f21febd683096dae1856f813e.tar.bz2
simple X window wrapper
Diffstat (limited to 'src/FbTk/FbWindow.cc')
-rw-r--r--src/FbTk/FbWindow.cc186
1 files changed, 186 insertions, 0 deletions
diff --git a/src/FbTk/FbWindow.cc b/src/FbTk/FbWindow.cc
new file mode 100644
index 0000000..d42db25
--- /dev/null
+++ b/src/FbTk/FbWindow.cc
@@ -0,0 +1,186 @@
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.1 2002/12/03 16:25:27 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_window(0) {
36
37}
38
39FbWindow::FbWindow(int screen_num,
40 int x, int y, size_t width, size_t height, long eventmask,
41 bool override_redirect,
42 int depth,
43 int class_type) {
44
45 create(RootWindow(FbTk::App::instance()->display(), screen_num),
46 x, y, width, height, eventmask,
47 override_redirect, depth, class_type);
48};
49
50FbWindow::FbWindow(const FbWindow &parent,
51 int x, int y, size_t width, size_t height, long eventmask,
52 bool override_redirect,
53 int depth, int class_type) {
54
55 create(parent.window(), x, y, width, height, eventmask,
56 override_redirect, depth, class_type);
57
58
59};
60
61FbWindow::~FbWindow() {
62 if (m_window != 0)
63 XDestroyWindow(s_display, m_window);
64}
65
66
67void FbWindow::setBackgroundColor(const FbTk::Color &bg_color) {
68 XSetWindowBackground(s_display, m_window, bg_color.pixel());
69}
70
71void FbWindow::setBackgroundPixmap(Pixmap bg_pixmap) {
72 XSetWindowBackgroundPixmap(s_display, m_window, bg_pixmap);
73}
74
75void FbWindow::setBorderColor(const FbTk::Color &border_color) {
76 XSetWindowBorder(s_display, m_window, border_color.pixel());
77}
78void FbWindow::setBorderWidth(size_t size) {
79 XSetWindowBorderWidth(s_display, m_window, size);
80}
81
82void FbWindow::setName(const char *name) {
83 XStoreName(s_display, m_window, name);
84}
85
86void FbWindow::setEventMask(long mask) {
87 XSelectInput(s_display, m_window, mask);
88}
89
90void FbWindow::clear() {
91 XClearWindow(s_display, m_window);
92}
93
94FbWindow &FbWindow::operator = (Window win) {
95 if (m_window != 0)
96 XDestroyWindow(s_display, m_window);
97 m_window = win;
98 updateGeometry();
99
100 return *this;
101}
102
103void FbWindow::show() {
104 XMapWindow(s_display, m_window);
105}
106
107void FbWindow::hide() {
108 XUnmapWindow(s_display, m_window);
109}
110
111void FbWindow::move(int x, int y) {
112 XMoveWindow(s_display, m_window, x, y);
113 m_x = x;
114 m_y = y;
115}
116
117void FbWindow::resize(size_t width, size_t height) {
118 XResizeWindow(s_display, m_window, width, height);
119 m_width = width;
120 m_height = height;
121}
122
123void FbWindow::moveResize(int x, int y, size_t width, size_t height) {
124 XMoveResizeWindow(s_display, m_window, x, y, width, height);
125 m_x = x;
126 m_y = y;
127 m_width = width;
128 m_height = height;
129}
130
131void FbWindow::lower() {
132 XLowerWindow(s_display, m_window);
133}
134
135void FbWindow::raise() {
136 XRaiseWindow(s_display, m_window);
137}
138
139void FbWindow::updateGeometry() {
140 if (m_window == 0)
141 return;
142
143 Window root;
144 size_t border_width, depth;
145 XGetGeometry(s_display, m_window, &root, &m_x, &m_y,
146 &m_width, &m_height, &border_width, &depth);
147}
148
149void FbWindow::create(Window parent, int x, int y,
150 size_t width, size_t height,
151 long eventmask, bool override_redirect,
152 int depth, int class_type) {
153
154
155 if (s_display == 0)
156 s_display = FbTk::App::instance()->display();
157
158 assert(s_display);
159
160 long valmask = CWEventMask;
161 XSetWindowAttributes values;
162 values.event_mask = eventmask;
163
164 if (override_redirect) {
165 valmask |= CWOverrideRedirect;
166 values.override_redirect = True;
167 }
168
169 m_window = XCreateWindow(s_display, parent, x, y, width, height,
170 0, // border width
171 depth, // depth
172 class_type, // class
173 CopyFromParent, // visual
174 valmask, // create mask
175 &values); // create atrribs
176
177 assert(m_window);
178
179 updateGeometry();
180}
181
182bool operator == (Window win, const FbWindow &fbwin) {
183 return win == fbwin.window();
184}
185
186};