aboutsummaryrefslogtreecommitdiff
path: root/src
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
parentb25fd24b490f14a5e3f02a68d7bda60b90aa1253 (diff)
downloadfluxbox_pavel-d559c49e0ab91b2f21febd683096dae1856f813e.zip
fluxbox_pavel-d559c49e0ab91b2f21febd683096dae1856f813e.tar.bz2
simple X window wrapper
Diffstat (limited to 'src')
-rw-r--r--src/FbTk/FbWindow.cc186
-rw-r--r--src/FbTk/FbWindow.hh96
2 files changed, 282 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};
diff --git a/src/FbTk/FbWindow.hh b/src/FbTk/FbWindow.hh
new file mode 100644
index 0000000..fbd6d85
--- /dev/null
+++ b/src/FbTk/FbWindow.hh
@@ -0,0 +1,96 @@
1// FbWindow.hh 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.hh,v 1.1 2002/12/03 16:25:25 fluxgen Exp $
23
24#ifndef FBTK_FBWINDOW_HH
25#define FBTK_FBWINDOW_HH
26
27#include <X11/Xlib.h>
28
29namespace FbTk {
30
31class Color;
32
33/**
34 Wrapper for X window
35 */
36class FbWindow {
37public:
38
39 FbWindow();
40 FbWindow(const FbWindow &win_copy);
41 FbWindow(int screen_num,
42 int x, int y, size_t width, size_t height, long eventmask,
43 bool overrride_redirect = false,
44 int depth = CopyFromParent,
45 int class_type = InputOutput);
46 FbWindow(const FbWindow &parent,
47 int x, int y, size_t width, size_t height, long eventmask,
48 bool overrride_redirect = false,
49 int depth = CopyFromParent,
50 int class_type = InputOutput);
51
52
53 virtual ~FbWindow();
54 void setBackgroundColor(const FbTk::Color &bg_color);
55 void setBackgroundPixmap(Pixmap bg_pixmap);
56 void setBorderColor(const FbTk::Color &border_color);
57 void setBorderWidth(size_t size);
58 /// set window name (for title)
59 void setName(const char *name);
60 void setEventMask(long mask);
61 /// clear window with background pixmap or color
62 void clear();
63 /// assign a new X window to this
64 FbWindow &operator = (Window win);
65 void hide();
66 void show();
67 virtual void move(int x, int y);
68 virtual void resize(size_t width, size_t height);
69 virtual void moveResize(int x, int y, size_t width, size_t height);
70 void lower();
71 void raise();
72
73 Window window() const { return m_window; }
74 int x() const { return m_x; }
75 int y() const { return m_y; }
76 size_t width() const { return m_width; }
77 size_t height() const { return m_height; }
78 /// compare X window
79 bool operator == (Window win) const { return m_window == win; }
80private:
81 void updateGeometry();
82 void create(Window parent, int x, int y, size_t width, size_t height, long eventmask,
83 bool override_redirect,
84 int depth,
85 int class_type);
86 static Display *s_display;
87 Window m_window; ///< X window
88 int m_x, m_y; ///< position
89 size_t m_width, m_height;
90};
91
92bool operator == (Window win, const FbWindow &fbwin);
93
94}; // end namespace FbTk
95
96#endif // FBTK_FBWINDOW_HH