fluxbox/src/FbTk/FbWindow.hh

258 lines
9 KiB
C++
Raw Normal View History

2002-12-03 16:25:27 +00:00
// FbWindow.hh for FbTk - fluxbox toolkit
2005-01-24 18:02:34 +00:00
// Copyright (c) 2002 - 2005 Henrik Kinnunen (fluxgen at fluxbox dot org)
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.
2004-11-19 11:37:27 +00:00
// $Id$
2002-12-03 16:25:27 +00:00
#ifndef FBTK_FBWINDOW_HH
#define FBTK_FBWINDOW_HH
2003-04-29 08:51:59 +00:00
#include "FbDrawable.hh"
2002-12-03 16:25:27 +00:00
#include <X11/Xlib.h>
2003-08-04 12:43:21 +00:00
#include <memory>
#include <string>
2002-12-03 16:25:27 +00:00
namespace FbTk {
class Color;
2003-08-04 12:43:21 +00:00
class Transparent;
class FbPixmap;
class FbWindowRenderer;
2002-12-03 16:25:27 +00:00
2003-04-29 08:51:59 +00:00
/// Wrapper for X window
2003-05-10 13:24:59 +00:00
/**
* Example:
* FbWindow window(0, 10, 10, 100, 100, ExposeMask | ButtonPressMask); \n
* this will create a window on screen 0, position 10 10, size 100 100 \n
* and with eventmask Expose and ButtonPress. \n
* You need to register it to some eventhandler so you can catch events: \n
* EventManager::instance()->add(your_eventhandler, window); \n
* @see EventHandler
* @see EventManager
*/
2003-04-29 08:51:59 +00:00
class FbWindow: public FbDrawable {
2002-12-03 16:25:27 +00:00
public:
FbWindow();
2003-05-10 13:24:59 +00:00
2002-12-03 16:25:27 +00:00
FbWindow(const FbWindow &win_copy);
2003-05-10 13:24:59 +00:00
2002-12-03 16:25:27 +00:00
FbWindow(int screen_num,
2003-04-14 12:04:32 +00:00
int x, int y, unsigned int width, unsigned int height, long eventmask,
2002-12-03 16:25:27 +00:00
bool overrride_redirect = false,
bool save_unders = false,
2002-12-03 16:25:27 +00:00
int depth = CopyFromParent,
int class_type = InputOutput);
2003-05-10 13:24:59 +00:00
2002-12-03 16:25:27 +00:00
FbWindow(const FbWindow &parent,
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 overrride_redirect = false,
bool save_unders = false,
2002-12-03 16:25:27 +00:00
int depth = CopyFromParent,
int class_type = InputOutput);
virtual ~FbWindow();
2003-08-13 09:28:44 +00:00
virtual void setBackgroundColor(const FbTk::Color &bg_color);
virtual void setBackgroundPixmap(Pixmap bg_pixmap);
virtual void setBorderColor(const FbTk::Color &border_color);
virtual void setBorderWidth(unsigned int size);
/// set window name ("title")
2002-12-03 16:25:27 +00:00
void setName(const char *name);
void setEventMask(long mask);
/// clear window with background pixmap or color
2003-04-29 08:51:59 +00:00
virtual void clear();
2003-06-24 10:12:57 +00:00
/// @param exposures wheter Expose event should be generated
virtual void clearArea(int x, int y,
unsigned int width, unsigned int height,
bool exposures = false);
void updateTransparent(int x = -1, int y = -1, unsigned int width = 0, unsigned int height = 0, Pixmap dest_override = None, bool override_is_offset = false);
2003-08-04 12:43:21 +00:00
void setAlpha(unsigned char alpha);
2003-09-10 21:26:28 +00:00
virtual FbWindow &operator = (const FbWindow &win);
2002-12-03 16:25:27 +00:00
/// assign a new X window to this
2003-08-04 12:43:21 +00:00
virtual FbWindow &operator = (Window win);
virtual void hide();
virtual void show();
virtual void showSubwindows();
2002-12-16 11:17:26 +00:00
/// Notify that the parent window was moved,
/// thus the absolute position of this one moved
virtual inline void parentMoved() {
updateBackground(true);
}
2003-12-30 17:17:05 +00:00
virtual inline void move(int x, int y) {
if (x == m_x && y == m_y)
return;
2003-12-30 17:17:05 +00:00
XMoveWindow(s_display, m_window, x, y);
m_x = x;
m_y = y;
updateBackground(true);
2003-12-30 17:17:05 +00:00
}
virtual inline void resize(unsigned int width, unsigned int height) {
if (width == m_width && height == m_height)
return;
XResizeWindow(s_display, m_window, width, height);
m_width = width;
m_height = height;
updateBackground(false);
2003-12-30 17:17:05 +00:00
}
virtual inline void moveResize(int x, int y, unsigned int width, unsigned int height) {
if (x == m_x && y == m_y && width == m_width && height == m_height)
return;
2003-12-30 17:17:05 +00:00
XMoveResizeWindow(s_display, m_window, x, y, width, height);
m_x = x;
m_y = y;
m_width = width;
m_height = height;
updateBackground(false);
2003-12-30 17:17:05 +00:00
}
2003-04-14 12:04:32 +00:00
virtual void lower();
virtual void raise();
2003-07-02 05:17:30 +00:00
void setInputFocus(int revert_to, int time);
2003-05-17 10:43:20 +00:00
/// defines a cursor for this window
void setCursor(Cursor cur);
/// uses the parents cursor instead
void unsetCursor();
void reparent(const FbWindow &parent, int x, int y, bool continuing = true);
2003-05-17 10:43:20 +00:00
2003-05-19 22:38:55 +00:00
bool 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;
void changeProperty(Atom property, Atom type,
int format,
int mode,
unsigned char *data,
int nelements);
2004-12-21 16:12:28 +00:00
void deleteProperty(Atom property);
std::string textProperty(Atom property) const;
2003-05-10 13:24:59 +00:00
/// @return parent FbWindow
2002-12-16 11:17:26 +00:00
const FbWindow *parent() const { return m_parent; }
2003-05-10 13:24:59 +00:00
/// @return real X window
2003-04-29 08:51:59 +00:00
inline Window window() const { return m_window; }
2003-05-10 13:24:59 +00:00
/// @return drawable (the X window)
2003-04-29 08:51:59 +00:00
inline Drawable drawable() const { return window(); }
2004-01-21 20:22:26 +00:00
inline int x() const { return m_x; }
inline int y() const { return m_y; }
inline unsigned int width() const { return m_width; }
inline unsigned int height() const { return m_height; }
inline unsigned int borderWidth() const { return m_border_width; }
inline int depth() const { return m_depth; }
2004-06-07 20:24:38 +00:00
unsigned char alpha() const;
2002-12-16 11:17:26 +00:00
int screenNumber() const;
2003-08-26 23:45:36 +00:00
long eventMask() const;
2002-12-03 16:25:27 +00:00
/// compare X window
2004-01-21 20:22:26 +00:00
inline bool operator == (Window win) const { return m_window == win; }
inline bool operator != (Window win) const { return m_window != win; }
2002-12-04 00:02:52 +00:00
/// compare two windows
2004-01-21 20:22:26 +00:00
inline bool operator == (const FbWindow &win) const { return m_window == win.m_window; }
inline bool operator != (const FbWindow &win) const { return m_window != win.m_window; }
2002-12-16 11:17:26 +00:00
// used for composite
void setOpaque(unsigned char alpha);
void setRenderer(FbWindowRenderer &renderer) { m_renderer = &renderer; }
2005-04-26 04:18:10 +00:00
void sendConfigureNotify(int x, int y, unsigned int width, unsigned int height);
/// forces full background change, recalcing of alpha values if necessary
void updateBackground(bool only_if_alpha);
2003-04-14 12:04:32 +00:00
protected:
2003-05-10 13:24:59 +00:00
/// creates a window with x window client (m_window = client)
2003-04-14 12:04:32 +00:00
explicit FbWindow(Window client);
2004-06-13 00:32:40 +00:00
/// updates x,y, width, height and screen num from X window
void updateGeometry();
2002-12-03 16:25:27 +00:00
private:
/// sets new X window and destroys old
2003-05-10 23:11:33 +00:00
void setNew(Window win);
/// creates a new X window
2003-04-14 12:04:32 +00:00
void create(Window parent, int x, int y, unsigned int width, unsigned int height,
long eventmask,
2002-12-03 16:25:27 +00:00
bool override_redirect,
bool save_unders,
2002-12-03 16:25:27 +00:00
int depth,
int class_type);
2003-05-10 13:24:59 +00:00
const FbWindow *m_parent; ///< parent FbWindow
int m_screen_num; ///< screen num on which this window exist
2003-08-04 12:43:21 +00:00
mutable Window m_window; ///< the X window
2003-01-05 22:58:11 +00:00
int m_x, m_y; ///< position of window
2003-04-14 12:04:32 +00:00
unsigned int m_width, m_height; ///< size of window
2003-05-10 13:24:59 +00:00
unsigned int m_border_width; ///< border size
int m_depth; ///< bit depth
2003-04-14 12:04:32 +00:00
bool m_destroy; ///< wheter the x window was created before
2003-08-04 12:43:21 +00:00
std::auto_ptr<FbTk::Transparent> m_transparent;
bool m_lastbg_color_set;
unsigned long m_lastbg_color;
Pixmap m_lastbg_pm;
FbWindowRenderer *m_renderer;
2002-12-03 16:25:27 +00:00
};
bool operator == (Window win, const FbWindow &fbwin);
2003-05-10 13:24:59 +00:00
/// helper class for some STL routines
2003-04-14 12:04:32 +00:00
class ChangeProperty {
public:
ChangeProperty(Display *disp, Atom prop, int mode,
unsigned char *state, int num):m_disp(disp),
2003-12-30 17:17:05 +00:00
m_prop(prop), m_state(state), m_num(num), m_mode(mode){
2003-04-14 12:04:32 +00:00
}
void operator () (FbTk::FbWindow *win) {
XChangeProperty(m_disp, win->window(), m_prop, m_prop, 32, m_mode,
m_state, m_num);
}
private:
Display *m_disp;
Atom m_prop;
unsigned char *m_state;
int m_num;
int m_mode;
};
2003-08-04 12:43:21 +00:00
/// Interface class to render FbWindow foregrounds.
class FbWindowRenderer {
public:
virtual void renderForeground(FbWindow &win, FbDrawable &drawable) = 0;
2003-04-14 12:04:32 +00:00
};
2003-12-16 17:06:52 +00:00
} // end namespace FbTk
2002-12-03 16:25:27 +00:00
#endif // FBTK_FBWINDOW_HH