2002-12-03 16:25:27 +00:00
|
|
|
// FbWindow.cc for FbTk - fluxbox toolkit
|
2003-04-29 09:00:13 +00:00
|
|
|
// Copyright (c) 2002-2003 Henrik Kinnunen (fluxgen at users.sourceforge.net)
|
2002-12-03 16:25:27 +00:00
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the "Software"),
|
|
|
|
// to deal in the Software without restriction, including without limitation
|
|
|
|
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
// and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
// Software is furnished to do so, subject to the following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included in
|
|
|
|
// all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
// DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2003-10-14 21:49:21 +00:00
|
|
|
// $Id: FbWindow.cc,v 1.27 2003/10/14 21:49:21 fluxgen Exp $
|
2002-12-03 16:25:27 +00:00
|
|
|
|
|
|
|
#include "FbWindow.hh"
|
|
|
|
|
2003-08-04 12:44:43 +00:00
|
|
|
#include "EventManager.hh"
|
2002-12-03 16:25:27 +00:00
|
|
|
#include "Color.hh"
|
|
|
|
#include "App.hh"
|
2003-08-04 12:44:43 +00:00
|
|
|
#include "Transparent.hh"
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif // HAVE_CONFIG_H
|
|
|
|
|
|
|
|
#include <X11/Xatom.h>
|
2002-12-03 16:25:27 +00:00
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
namespace FbTk {
|
|
|
|
|
2003-08-04 12:44:43 +00:00
|
|
|
namespace {
|
|
|
|
Pixmap getRootPixmap(int screen_num) {
|
|
|
|
Pixmap root_pm = 0;
|
|
|
|
// get root pixmap for transparency
|
|
|
|
Display *disp = FbTk::App::instance()->display();
|
|
|
|
Atom real_type;
|
|
|
|
int real_format;
|
|
|
|
unsigned long items_read, items_left;
|
|
|
|
unsigned int *data;
|
|
|
|
if (XGetWindowProperty(disp, RootWindow(disp, screen_num),
|
|
|
|
XInternAtom(disp, "_XROOTPMAP_ID", false),
|
|
|
|
0L, 1L,
|
|
|
|
false, XA_PIXMAP, &real_type,
|
|
|
|
&real_format, &items_read, &items_left,
|
|
|
|
(unsigned char **) &data) == Success &&
|
|
|
|
items_read) {
|
|
|
|
root_pm = (Pixmap) (*data);
|
|
|
|
XFree(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
return root_pm;
|
|
|
|
}
|
|
|
|
|
|
|
|
}; // end anonymous namespace
|
|
|
|
|
2002-12-03 16:25:27 +00:00
|
|
|
Display *FbWindow::s_display = 0;
|
|
|
|
|
2003-01-05 22:58:11 +00:00
|
|
|
FbWindow::FbWindow():m_parent(0), m_screen_num(0), m_window(0), m_x(0), m_y(0),
|
2003-09-14 09:51:40 +00:00
|
|
|
m_width(0), m_height(0), m_border_width(0), m_depth(0), m_destroy(true),
|
|
|
|
m_buffer_pm(0) {
|
2002-12-16 11:17:26 +00:00
|
|
|
|
2002-12-03 21:59:58 +00:00
|
|
|
if (s_display == 0)
|
|
|
|
s_display = App::instance()->display();
|
2002-12-03 16:25:27 +00:00
|
|
|
}
|
|
|
|
|
2003-08-04 12:44:43 +00:00
|
|
|
FbWindow::FbWindow(const FbWindow& the_copy):m_parent(the_copy.parent()),
|
|
|
|
m_screen_num(the_copy.screenNumber()), m_window(the_copy.window()),
|
|
|
|
m_x(the_copy.x()), m_y(the_copy.y()),
|
|
|
|
m_width(the_copy.width()), m_height(the_copy.height()),
|
|
|
|
m_border_width(the_copy.borderWidth()),
|
2003-09-14 09:51:40 +00:00
|
|
|
m_depth(the_copy.depth()), m_destroy(true),
|
|
|
|
m_buffer_pm(0) {
|
2003-08-04 12:44:43 +00:00
|
|
|
if (s_display == 0)
|
|
|
|
s_display = App::instance()->display();
|
|
|
|
|
|
|
|
the_copy.m_window = 0;
|
|
|
|
}
|
|
|
|
|
2002-12-03 16:25:27 +00:00
|
|
|
FbWindow::FbWindow(int screen_num,
|
2003-04-16 16:02:14 +00:00
|
|
|
int x, int y,
|
|
|
|
unsigned int width, unsigned int height,
|
|
|
|
long eventmask,
|
2002-12-03 16:25:27 +00:00
|
|
|
bool override_redirect,
|
|
|
|
int depth,
|
2002-12-16 11:17:26 +00:00
|
|
|
int class_type):
|
|
|
|
m_screen_num(screen_num),
|
2003-09-14 09:51:40 +00:00
|
|
|
m_parent(0), m_destroy(true),
|
|
|
|
m_buffer_pm(0) {
|
2002-12-03 16:25:27 +00:00
|
|
|
|
|
|
|
create(RootWindow(FbTk::App::instance()->display(), screen_num),
|
|
|
|
x, y, width, height, eventmask,
|
|
|
|
override_redirect, depth, class_type);
|
|
|
|
};
|
|
|
|
|
|
|
|
FbWindow::FbWindow(const FbWindow &parent,
|
2003-04-14 12:13:36 +00:00
|
|
|
int x, int y, unsigned int width, unsigned int height,
|
|
|
|
long eventmask,
|
2002-12-03 16:25:27 +00:00
|
|
|
bool override_redirect,
|
2002-12-16 11:17:26 +00:00
|
|
|
int depth, int class_type):
|
2003-04-17 14:16:20 +00:00
|
|
|
m_parent(&parent),
|
2003-09-14 09:51:40 +00:00
|
|
|
m_screen_num(parent.screenNumber()), m_destroy(true),
|
|
|
|
m_buffer_pm(0) {
|
2002-12-03 16:25:27 +00:00
|
|
|
|
|
|
|
create(parent.window(), x, y, width, height, eventmask,
|
|
|
|
override_redirect, depth, class_type);
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2003-05-06 23:50:31 +00:00
|
|
|
FbWindow::FbWindow(Window client):m_parent(0), m_window(0),
|
2003-05-13 14:07:24 +00:00
|
|
|
m_screen_num(0),
|
2003-09-14 09:51:40 +00:00
|
|
|
m_destroy(false), // don't destroy this window
|
|
|
|
m_buffer_pm(0) {
|
2003-05-10 23:11:33 +00:00
|
|
|
|
|
|
|
setNew(client);
|
2003-04-14 12:13:36 +00:00
|
|
|
}
|
|
|
|
|
2002-12-03 16:25:27 +00:00
|
|
|
FbWindow::~FbWindow() {
|
2003-04-17 14:16:20 +00:00
|
|
|
|
|
|
|
if (m_window != 0) {
|
|
|
|
// so we don't get any dangling eventhandler for this window
|
|
|
|
FbTk::EventManager::instance()->remove(m_window);
|
|
|
|
if (m_destroy)
|
|
|
|
XDestroyWindow(s_display, m_window);
|
|
|
|
}
|
2002-12-03 16:25:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void FbWindow::setBackgroundColor(const FbTk::Color &bg_color) {
|
|
|
|
XSetWindowBackground(s_display, m_window, bg_color.pixel());
|
|
|
|
}
|
|
|
|
|
|
|
|
void FbWindow::setBackgroundPixmap(Pixmap bg_pixmap) {
|
|
|
|
XSetWindowBackgroundPixmap(s_display, m_window, bg_pixmap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FbWindow::setBorderColor(const FbTk::Color &border_color) {
|
|
|
|
XSetWindowBorder(s_display, m_window, border_color.pixel());
|
|
|
|
}
|
2003-08-04 12:44:43 +00:00
|
|
|
|
2003-04-14 12:13:36 +00:00
|
|
|
void FbWindow::setBorderWidth(unsigned int size) {
|
2002-12-03 16:25:27 +00:00
|
|
|
XSetWindowBorderWidth(s_display, m_window, size);
|
2003-01-05 22:58:11 +00:00
|
|
|
m_border_width = size;
|
2002-12-03 16:25:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FbWindow::setName(const char *name) {
|
|
|
|
XStoreName(s_display, m_window, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FbWindow::setEventMask(long mask) {
|
|
|
|
XSelectInput(s_display, m_window, mask);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FbWindow::clear() {
|
|
|
|
XClearWindow(s_display, m_window);
|
|
|
|
}
|
|
|
|
|
2003-06-24 10:12:57 +00:00
|
|
|
void FbWindow::clearArea(int x, int y,
|
|
|
|
unsigned int width, unsigned int height,
|
|
|
|
bool exposures) {
|
|
|
|
XClearArea(s_display, window(), x, y, width, height, exposures);
|
|
|
|
}
|
|
|
|
|
2003-08-04 12:44:43 +00:00
|
|
|
void FbWindow::updateTransparent(int the_x, int the_y, unsigned int the_width, unsigned int the_height) {
|
|
|
|
#ifdef HAVE_XRENDER
|
|
|
|
if (width() == 0 || height() == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (the_width == 0 || the_height == 0) {
|
|
|
|
the_width = width();
|
|
|
|
the_height = height();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (the_x < 0 || the_y < 0) {
|
|
|
|
the_x = 0;
|
|
|
|
the_y = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!m_transparent.get())
|
|
|
|
return;
|
|
|
|
|
|
|
|
// update source and destination if needed
|
|
|
|
Pixmap root = getRootPixmap(screenNumber());
|
|
|
|
if (m_transparent->source() != root)
|
|
|
|
m_transparent->setSource(root, screenNumber());
|
|
|
|
|
2003-09-14 09:51:40 +00:00
|
|
|
if (m_buffer_pm) {
|
|
|
|
if (m_transparent->dest() != m_buffer_pm) {
|
|
|
|
m_transparent->setDest(m_buffer_pm, screenNumber());
|
|
|
|
}
|
|
|
|
} else if (m_transparent->dest() != window())
|
2003-08-04 12:44:43 +00:00
|
|
|
m_transparent->setDest(window(), screenNumber());
|
|
|
|
|
2003-09-14 09:51:40 +00:00
|
|
|
|
2003-08-04 12:44:43 +00:00
|
|
|
// get root position
|
|
|
|
|
|
|
|
const FbWindow *root_parent = parent();
|
|
|
|
// our position in parent ("root")
|
|
|
|
int root_x = x() + borderWidth(), root_y = y() + borderWidth();
|
|
|
|
if (root_parent != 0) {
|
|
|
|
root_x += root_parent->x() + root_parent->borderWidth();
|
|
|
|
root_y += root_parent->y() + root_parent->borderWidth();
|
|
|
|
while (root_parent->parent() != 0) {
|
|
|
|
root_parent = root_parent->parent();
|
|
|
|
root_x += root_parent->x() + root_parent->borderWidth();
|
|
|
|
root_y += root_parent->y() + root_parent->borderWidth();
|
|
|
|
}
|
|
|
|
|
|
|
|
} // else toplevel window so we already have x, y set
|
|
|
|
|
|
|
|
// render background image from root pos to our window
|
|
|
|
m_transparent->render(root_x + the_x, root_y + the_y,
|
|
|
|
the_x, the_y,
|
|
|
|
the_width, the_height);
|
|
|
|
#endif // HAVE_XRENDER
|
|
|
|
}
|
|
|
|
|
|
|
|
void FbWindow::setAlpha(unsigned char alpha) {
|
|
|
|
#ifdef HAVE_XRENDER
|
|
|
|
if (m_transparent.get() == 0 && alpha != 0) {
|
|
|
|
m_transparent.reset(new Transparent(getRootPixmap(screenNumber()), window(), alpha, screenNumber()));
|
|
|
|
} else if (alpha != 0 && alpha != m_transparent->alpha())
|
|
|
|
m_transparent->setAlpha(alpha);
|
|
|
|
else if (alpha == 0)
|
|
|
|
m_transparent.reset(0); // destroy transparent object
|
|
|
|
#endif // HAVE_XRENDER
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FbWindow &FbWindow::operator = (const FbWindow &win) {
|
|
|
|
m_parent = win.parent();
|
|
|
|
m_screen_num = win.screenNumber();
|
|
|
|
m_window = win.window();
|
|
|
|
m_x = win.x();
|
|
|
|
m_y = win.y();
|
|
|
|
m_width = win.width();
|
|
|
|
m_height = win.height();
|
|
|
|
m_border_width = win.borderWidth();
|
|
|
|
m_depth = win.depth();
|
|
|
|
// take over this window
|
|
|
|
win.m_window = 0;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2002-12-03 16:25:27 +00:00
|
|
|
FbWindow &FbWindow::operator = (Window win) {
|
2003-05-10 23:11:33 +00:00
|
|
|
setNew(win);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FbWindow::setNew(Window win) {
|
2003-05-19 08:27:49 +00:00
|
|
|
if (s_display == 0)
|
|
|
|
s_display = App::instance()->display();
|
|
|
|
|
2003-04-14 12:13:36 +00:00
|
|
|
if (m_window != 0 && m_destroy)
|
2002-12-03 16:25:27 +00:00
|
|
|
XDestroyWindow(s_display, m_window);
|
|
|
|
m_window = win;
|
2003-05-06 23:50:31 +00:00
|
|
|
if (m_window != 0) {
|
2002-12-03 21:59:58 +00:00
|
|
|
updateGeometry();
|
2003-05-06 23:50:31 +00:00
|
|
|
XWindowAttributes attr;
|
|
|
|
attr.screen = 0;
|
|
|
|
//get screen number
|
|
|
|
if (XGetWindowAttributes(s_display,
|
|
|
|
m_window,
|
|
|
|
&attr) != 0 && attr.screen != 0) {
|
|
|
|
m_screen_num = XScreenNumberOfScreen(attr.screen);
|
|
|
|
}
|
2003-05-10 23:11:33 +00:00
|
|
|
}
|
2002-12-03 16:25:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FbWindow::show() {
|
|
|
|
XMapWindow(s_display, m_window);
|
|
|
|
}
|
|
|
|
|
2002-12-16 11:17:26 +00:00
|
|
|
void FbWindow::showSubwindows() {
|
|
|
|
XMapSubwindows(s_display, m_window);
|
|
|
|
}
|
|
|
|
|
2002-12-03 16:25:27 +00:00
|
|
|
void FbWindow::hide() {
|
|
|
|
XUnmapWindow(s_display, m_window);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FbWindow::move(int x, int y) {
|
|
|
|
XMoveWindow(s_display, m_window, x, y);
|
|
|
|
m_x = x;
|
|
|
|
m_y = y;
|
|
|
|
}
|
|
|
|
|
2003-04-14 12:13:36 +00:00
|
|
|
void FbWindow::resize(unsigned int width, unsigned int height) {
|
2002-12-03 16:25:27 +00:00
|
|
|
XResizeWindow(s_display, m_window, width, height);
|
|
|
|
m_width = width;
|
|
|
|
m_height = height;
|
|
|
|
}
|
|
|
|
|
2003-04-14 12:13:36 +00:00
|
|
|
void FbWindow::moveResize(int x, int y, unsigned int width, unsigned int height) {
|
2002-12-03 16:25:27 +00:00
|
|
|
XMoveResizeWindow(s_display, m_window, x, y, width, height);
|
|
|
|
m_x = x;
|
|
|
|
m_y = y;
|
|
|
|
m_width = width;
|
|
|
|
m_height = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FbWindow::lower() {
|
2003-07-02 05:17:30 +00:00
|
|
|
XLowerWindow(s_display, window());
|
2002-12-03 16:25:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FbWindow::raise() {
|
2003-07-02 05:17:30 +00:00
|
|
|
XRaiseWindow(s_display, window());
|
|
|
|
}
|
|
|
|
|
|
|
|
void FbWindow::setInputFocus(int revert_to, int time) {
|
|
|
|
XSetInputFocus(s_display, window(), revert_to, time);
|
2002-12-03 16:25:27 +00:00
|
|
|
}
|
|
|
|
|
2003-05-17 10:43:20 +00:00
|
|
|
void FbWindow::setCursor(Cursor cur) {
|
|
|
|
XDefineCursor(s_display, window(), cur);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FbWindow::unsetCursor() {
|
|
|
|
XUndefineCursor(s_display, window());
|
|
|
|
}
|
|
|
|
|
2003-08-15 13:52:06 +00:00
|
|
|
void FbWindow::reparent(const FbWindow &parent, int x, int y) {
|
|
|
|
XReparentWindow(s_display, window(), parent.window(), x, y);
|
|
|
|
m_parent = &parent;
|
|
|
|
updateGeometry();
|
|
|
|
}
|
2003-05-19 22:38:55 +00:00
|
|
|
|
|
|
|
bool FbWindow::property(Atom property,
|
|
|
|
long long_offset, long long_length,
|
|
|
|
bool do_delete,
|
|
|
|
Atom req_type,
|
|
|
|
Atom *actual_type_return,
|
|
|
|
int *actual_format_return,
|
|
|
|
unsigned long *nitems_return,
|
|
|
|
unsigned long *bytes_after_return,
|
|
|
|
unsigned char **prop_return) const {
|
2003-08-04 12:44:43 +00:00
|
|
|
if (XGetWindowProperty(s_display, window(),
|
|
|
|
property, long_offset, long_length, do_delete,
|
|
|
|
req_type, actual_type_return,
|
|
|
|
actual_format_return, nitems_return,
|
|
|
|
bytes_after_return, prop_return) == Success)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
2003-05-19 22:38:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FbWindow::changeProperty(Atom property, Atom type,
|
|
|
|
int format,
|
|
|
|
int mode,
|
|
|
|
unsigned char *data,
|
|
|
|
int nelements) {
|
|
|
|
|
|
|
|
XChangeProperty(s_display, m_window, property, type,
|
|
|
|
format, mode,
|
|
|
|
data, nelements);
|
|
|
|
}
|
|
|
|
|
2002-12-16 11:17:26 +00:00
|
|
|
int FbWindow::screenNumber() const {
|
|
|
|
return m_screen_num;
|
|
|
|
}
|
2003-04-14 12:13:36 +00:00
|
|
|
|
2003-08-26 23:45:36 +00:00
|
|
|
long FbWindow::eventMask() const {
|
|
|
|
XWindowAttributes attrib;
|
|
|
|
if (XGetWindowAttributes(s_display, window(),
|
|
|
|
&attrib) == Success) {
|
|
|
|
return attrib.your_event_mask;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-09-14 09:51:40 +00:00
|
|
|
void FbWindow::setBufferPixmap(Pixmap pm) {
|
|
|
|
m_buffer_pm = pm;
|
|
|
|
}
|
|
|
|
|
2002-12-03 16:25:27 +00:00
|
|
|
void FbWindow::updateGeometry() {
|
|
|
|
if (m_window == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
Window root;
|
2003-02-23 16:52:17 +00:00
|
|
|
unsigned int border_width, depth;
|
2002-12-03 16:25:27 +00:00
|
|
|
XGetGeometry(s_display, m_window, &root, &m_x, &m_y,
|
2003-02-23 16:52:17 +00:00
|
|
|
(unsigned int *)&m_width, (unsigned int *)&m_height,
|
|
|
|
&border_width, &depth);
|
2003-05-10 13:26:37 +00:00
|
|
|
m_depth = depth;
|
2002-12-03 16:25:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FbWindow::create(Window parent, int x, int y,
|
2003-04-14 12:13:36 +00:00
|
|
|
unsigned int width, unsigned int height,
|
2002-12-03 16:25:27 +00:00
|
|
|
long eventmask, bool override_redirect,
|
|
|
|
int depth, int class_type) {
|
|
|
|
|
|
|
|
|
|
|
|
if (s_display == 0)
|
|
|
|
s_display = FbTk::App::instance()->display();
|
|
|
|
|
2003-01-05 22:58:11 +00:00
|
|
|
m_border_width = 0;
|
|
|
|
|
2002-12-03 16:25:27 +00:00
|
|
|
long valmask = CWEventMask;
|
|
|
|
XSetWindowAttributes values;
|
|
|
|
values.event_mask = eventmask;
|
|
|
|
|
|
|
|
if (override_redirect) {
|
|
|
|
valmask |= CWOverrideRedirect;
|
|
|
|
values.override_redirect = True;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_window = XCreateWindow(s_display, parent, x, y, width, height,
|
|
|
|
0, // border width
|
|
|
|
depth, // depth
|
|
|
|
class_type, // class
|
|
|
|
CopyFromParent, // visual
|
|
|
|
valmask, // create mask
|
|
|
|
&values); // create atrribs
|
|
|
|
|
|
|
|
assert(m_window);
|
|
|
|
|
|
|
|
updateGeometry();
|
2003-10-14 21:49:21 +00:00
|
|
|
FbWindow::setBackgroundColor(Color("gray", screenNumber()));
|
2002-12-03 16:25:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool operator == (Window win, const FbWindow &fbwin) {
|
|
|
|
return win == fbwin.window();
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|