fluxbox/src/Window.hh

386 lines
12 KiB
C++
Raw Normal View History

// Window.hh for Fluxbox Window Manager
// Copyright (c) 2001-2002 Henrik Kinnunen (fluxgen@linuxmail.org)
2001-12-19 13:53:35 +00:00
//
2001-12-11 20:47:02 +00:00
// Window.hh for Blackbox - an X11 Window manager
// Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
//
// 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,
2002-01-18 01:33:58 +00:00
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
2001-12-11 20:47:02 +00:00
// 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.
2002-09-07 20:16:43 +00:00
// $Id: Window.hh,v 1.30 2002/09/07 20:13:55 fluxgen Exp $
#ifndef WINDOW_HH
#define WINDOW_HH
2001-12-11 20:47:02 +00:00
2002-08-11 22:33:41 +00:00
#include "BaseDisplay.hh"
#include "Timer.hh"
#include "Windowmenu.hh"
2002-09-07 20:16:43 +00:00
#include "Subject.hh"
2002-08-11 22:33:41 +00:00
2001-12-11 20:47:02 +00:00
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#ifdef SHAPE
#include <X11/extensions/shape.h>
2001-12-11 20:47:02 +00:00
#endif // SHAPE
#include <vector>
#include <string>
2002-05-30 15:49:10 +00:00
#define PropMwmHintsElements 3
class Tab;
2001-12-11 20:47:02 +00:00
2002-08-04 15:55:13 +00:00
/**
Creates the window frame and handles any window event for it
TODO: this is to huge!
*/
2001-12-11 20:47:02 +00:00
class FluxboxWindow : public TimeoutHandler {
public:
enum WinLayer {
LAYER_BOTTOM = 0x01,
LAYER_BELOW = 0x02,
LAYER_NORMAL = 0x04,
LAYER_TOP = 0x08
};
enum Decoration {DECOR_NONE=0, DECOR_NORMAL, DECOR_TINY, DECOR_TOOL};
//Motif wm Hints
enum {
MwmHintsFunctions = (1l << 0),
MwmHintsDecorations = (1l << 1)
};
//Motif wm functions
enum MwmFunc{
MwmFuncAll = (1l << 0),
MwmFuncResize = (1l << 1),
MwmFuncMove = (1l << 2),
MwmFuncIconify = (1l << 3),
MwmFuncMaximize = (1l << 4),
MwmFuncClose = (1l << 5)
};
//Motif wm decorations
enum MwmDecor {
MwmDecorAll = (1l << 0),
MwmDecorBorder = (1l << 1),
MwmDecorHandle = (1l << 2),
MwmDecorTitle = (1l << 3),
MwmDecorMenu = (1l << 4),
MwmDecorIconify = (1l << 5),
MwmDecorMaximize = (1l << 6)
};
2002-08-04 15:55:13 +00:00
explicit FluxboxWindow(Window win, BScreen *scr = 0);
virtual ~FluxboxWindow();
2002-08-04 15:55:13 +00:00
/**
@name accessors
*/
//@{
inline bool isTransient() const { return ((transient) ? true : false); }
inline bool hasTransient() const { return ((client.transient) ? true : false); }
inline bool isManaged() const { return managed; }
inline bool isFocused() const { return focused; }
inline bool isVisible() const { return visible; }
inline bool isIconic() const { return iconic; }
inline bool isShaded() const { return shaded; }
inline bool isMaximized() const { return maximized; }
inline bool isIconifiable() const { return functions.iconify; }
inline bool isMaximizable() const { return functions.maximize; }
inline bool isResizable() const { return functions.resize; }
inline bool isClosable() const { return functions.close; }
inline bool isStuck() const { return stuck; }
inline bool hasTitlebar() const { return decorations.titlebar; }
inline bool hasTab() const { return (tab!=0 ? true : false); }
inline bool isMoving() const { return moving; }
inline bool isResizing() const { return resizing; }
2002-08-04 15:55:13 +00:00
inline const BScreen *getScreen() const { return screen; }
inline BScreen *getScreen() { return screen; }
inline const Tab *getTab() const { return tab; }
inline Tab *getTab() { return tab; }
inline const FluxboxWindow *getTransient() const { return client.transient; }
inline FluxboxWindow *getTransient() { return client.transient; }
inline const FluxboxWindow *getTransientFor() const { return client.transient_for; }
inline FluxboxWindow *getTransientFor() { return client.transient_for; }
inline const Window &getFrameWindow() const { return frame.window; }
inline const Window &getClientWindow() const { return client.window; }
inline Windowmenu *getWindowmenu() { return windowmenu; }
inline const std::string &getTitle() const { return client.title; }
inline const std::string &getIconTitle() const { return client.icon_title; }
inline int getXFrame() const { return frame.x; }
inline int getYFrame() const { return frame.y; }
inline int getXClient() const { return client.x; }
inline int getYClient() const { return client.y; }
inline unsigned int getWorkspaceNumber() const { return workspace_number; }
inline int getWindowNumber() const { return window_number; }
inline WinLayer getLayer() const { return m_layer; }
inline unsigned int getWidth() const { return frame.width; }
inline unsigned int getHeight() const { return frame.height; }
inline unsigned int getClientHeight() const { return client.height; }
inline unsigned int getClientWidth() const { return client.width; }
inline unsigned int getTitleHeight() const { return frame.title_h; }
2002-08-11 22:33:41 +00:00
const std::string className() const { return m_class_name; }
const std::string instanceName() const { return m_instance_name; }
2002-08-04 15:55:13 +00:00
bool isLowerTab() const;
2002-09-07 20:16:43 +00:00
// signals
FbTk::Subject &stateSig() { return m_statesig; }
const FbTk::Subject &stateSig() const { return m_statesig; }
FbTk::Subject &hintSig() { return m_hintsig; }
const FbTk::Subject &hintSig() const { return m_hintsig; }
FbTk::Subject &workspaceSig() { return m_workspacesig; }
const FbTk::Subject &workspaceSig() const { return m_workspacesig; }
2002-08-04 15:55:13 +00:00
//@}
2002-01-18 01:33:58 +00:00
inline void setWindowNumber(int n) { window_number = n; }
2002-03-23 15:14:45 +00:00
inline const timeval &getLastFocusTime() const {return lastFocusTime;}
2002-03-18 19:58:06 +00:00
bool validateClient();
bool setInputFocus();
2001-12-11 20:47:02 +00:00
void setTab(bool flag);
2002-08-11 22:33:41 +00:00
void setFocusFlag(bool flag);
void iconify();
2002-01-18 01:33:58 +00:00
void deiconify(bool = true, bool = true);
void close();
void withdraw();
2002-01-18 01:33:58 +00:00
void maximize(unsigned int);
void shade();
void stick();
void unstick();
void reconfigure();
2002-01-18 01:33:58 +00:00
void installColormap(bool);
2002-08-16 10:44:17 +00:00
void restore(bool remap);
2002-01-18 01:33:58 +00:00
void configure(int dx, int dy, unsigned int dw, unsigned int dh);
void setWorkspace(int n);
void changeBlackboxHints(BaseDisplay::BlackboxHints *bh);
void restoreAttributes();
2002-08-12 03:28:17 +00:00
void showMenu(int mx, int my);
void pauseMoving();
void resumeMoving();
void buttonPressEvent(XButtonEvent *be);
void buttonReleaseEvent(XButtonEvent *be);
void motionNotifyEvent(XMotionEvent *me);
bool destroyNotifyEvent(XDestroyWindowEvent *dwe);
void mapRequestEvent(XMapRequestEvent *mre);
void mapNotifyEvent(XMapEvent *mapev);
bool unmapNotifyEvent(XUnmapEvent *unmapev);
void propertyNotifyEvent(Atom a);
void exposeEvent(XExposeEvent *ee);
void configureRequestEvent(XConfigureRequestEvent *ce);
void setDecoration(Decoration decoration);
void toggleDecoration();
2002-08-04 15:55:13 +00:00
#ifdef SHAPE
2002-01-18 01:33:58 +00:00
void shapeEvent(XShapeEvent *);
2002-08-04 15:55:13 +00:00
#endif // SHAPE
2001-12-11 20:47:02 +00:00
virtual void timeout();
2001-12-11 20:47:02 +00:00
// this structure only contains 3 elements... the Motif 2.0 structure contains
// 5... we only need the first 3... so that is all we will define
typedef struct MwmHints {
unsigned long flags; // Motif wm flags
unsigned long functions; // Motif wm functions
unsigned long decorations; // Motif wm decorations
2001-12-11 20:47:02 +00:00
} MwmHints;
2002-08-04 15:55:13 +00:00
2002-09-07 20:16:43 +00:00
class WinSubject: public FbTk::Subject {
public:
WinSubject(FluxboxWindow &w):m_win(w) { }
FluxboxWindow &win() { return m_win; }
const FluxboxWindow &win() const { return m_win; }
private:
FluxboxWindow &m_win;
};
2001-12-11 20:47:02 +00:00
private:
2002-09-07 20:16:43 +00:00
// state and hint signals
WinSubject m_hintsig, m_statesig, m_workspacesig;
BImageControl *image_ctrl; //image control for rendering
2002-08-11 22:33:41 +00:00
// got from WM_CLASS
std::string m_instance_name;
std::string m_class_name;
//Window state
2002-01-18 01:33:58 +00:00
bool moving, resizing, shaded, maximized, visible, iconic, transient,
focused, stuck, modal, send_focus_message, managed;
2002-01-18 01:33:58 +00:00
BScreen *screen;
2002-03-19 00:15:58 +00:00
BTimer timer;
2002-01-18 01:33:58 +00:00
Display *display;
BaseDisplay::BlackboxAttributes blackbox_attrib;
Time lastButtonPressTime;
Windowmenu *windowmenu;
2002-03-18 19:58:06 +00:00
timeval lastFocusTime;
2002-03-23 15:14:45 +00:00
int focus_mode, window_number;
unsigned int workspace_number;
2002-01-18 01:33:58 +00:00
unsigned long current_state;
2002-02-26 22:35:58 +00:00
WinLayer m_layer;
Decoration old_decoration;
2002-01-18 01:33:58 +00:00
struct _client {
FluxboxWindow *transient_for, // which window are we a transient for?
*transient; // which window is our transient?
Window window, window_group;
std::string title, icon_title;
int x, y, old_bw;
2001-12-11 20:47:02 +00:00
unsigned int width, height, title_text_w,
min_width, min_height, max_width, max_height, width_inc, height_inc,
min_aspect_x, min_aspect_y, max_aspect_x, max_aspect_y,
base_width, base_height, win_gravity;
unsigned long initial_state, normal_hint_flags, wm_hint_flags;
MwmHints *mwm_hint;
2001-12-19 13:53:35 +00:00
BaseDisplay::BlackboxHints *blackbox_hint;
2001-12-11 20:47:02 +00:00
} client;
struct _decorations {
bool titlebar, handle, border, iconify,
maximize, close, menu, sticky, shade, tab;
2001-12-11 20:47:02 +00:00
} decorations;
struct _functions {
bool resize, move, iconify, maximize, close;
} functions;
2002-01-18 01:33:58 +00:00
2001-12-11 20:47:02 +00:00
Tab *tab;
friend class Tab; //TODO: Don't like long distant friendship
2001-12-19 13:53:35 +00:00
2001-12-11 20:47:02 +00:00
typedef void (*ButtonDrawProc)(FluxboxWindow *, Window, bool);
typedef void (*ButtonEventProc)(FluxboxWindow *, XButtonEvent *);
2002-01-18 01:33:58 +00:00
struct Button {
int type;
Window win;
bool used;
ButtonEventProc pressed;
ButtonEventProc released;
ButtonDrawProc draw;
};
2001-12-11 20:47:02 +00:00
2002-01-18 01:33:58 +00:00
std::vector<Button> buttonlist;
struct _frame {
Bool shaped;
unsigned long ulabel_pixel, flabel_pixel, utitle_pixel,
ftitle_pixel, uhandle_pixel, fhandle_pixel, ubutton_pixel,
fbutton_pixel, pbutton_pixel, uborder_pixel, fborder_pixel,
ugrip_pixel, fgrip_pixel;
Pixmap ulabel, flabel, utitle, ftitle, uhandle, fhandle,
ubutton, fbutton, pbutton, ugrip, fgrip;
Window window, plate, title, label, handle,
2001-12-11 20:47:02 +00:00
right_grip, left_grip;
2002-01-18 01:33:58 +00:00
int x, y, resize_x, resize_y, move_x, move_y, grab_x, grab_y,
y_border, y_handle, save_x, save_y;
2002-01-18 01:33:58 +00:00
unsigned int width, height, title_h, label_w, label_h, handle_h,
button_w, button_h, grip_w, grip_h, mwm_border_w, border_h,
bevel_w, resize_w, resize_h, snap_w, snap_h, move_ws;
2002-01-18 01:33:58 +00:00
} frame;
2001-12-11 20:47:02 +00:00
2002-01-18 01:33:58 +00:00
enum { F_NOINPUT = 0, F_PASSIVE, F_LOCALLYACTIVE, F_GLOBALLYACTIVE };
2001-12-11 20:47:02 +00:00
void grabButtons();
2002-01-18 01:33:58 +00:00
void createButton(int type, ButtonEventProc, ButtonEventProc, ButtonDrawProc);
void startMoving(Window win);
void stopMoving();
void startResizing(XMotionEvent *me, bool left);
void stopResizing(Window win=0);
2002-04-04 22:39:52 +00:00
void updateIcon();
// Decoration functions
void createTitlebar();
void destroyTitlebar();
void createHandle();
void destroyHandle();
2002-05-21 21:25:10 +00:00
void checkTransient();
2002-02-07 15:13:19 +00:00
Window findTitleButton(int type);
private:
2002-01-18 01:33:58 +00:00
//event callbacks
static void stickyButton_cb(FluxboxWindow *, XButtonEvent *);
2001-12-11 20:47:02 +00:00
static void stickyPressed_cb(FluxboxWindow *, XButtonEvent *);
2002-01-18 01:33:58 +00:00
static void iconifyButton_cb(FluxboxWindow *, XButtonEvent *);
static void iconifyPressed_cb(FluxboxWindow *, XButtonEvent *);
static void maximizeButton_cb(FluxboxWindow *, XButtonEvent *);
2001-12-11 20:47:02 +00:00
static void maximizePressed_cb(FluxboxWindow *, XButtonEvent *);
2002-01-18 01:33:58 +00:00
static void closeButton_cb(FluxboxWindow *, XButtonEvent *);
static void closePressed_cb(FluxboxWindow *, XButtonEvent *);
2001-12-11 20:47:02 +00:00
static void shadeButton_cb(FluxboxWindow *, XButtonEvent *);
2002-01-18 01:33:58 +00:00
//draw callbacks
static void stickyDraw_cb(FluxboxWindow *, Window, bool);
static void iconifyDraw_cb(FluxboxWindow *, Window, bool);
static void maximizeDraw_cb(FluxboxWindow *, Window, bool);
static void closeDraw_cb(FluxboxWindow *, Window, bool);
static void shadeDraw_cb(FluxboxWindow *, Window, bool);
2001-12-11 20:47:02 +00:00
static void grabButton(Display *display, unsigned int button, Window window, Cursor cursor);
//button base draw... background
2002-01-18 01:33:58 +00:00
void drawButtonBase(Window, bool);
bool getState();
2002-01-18 01:33:58 +00:00
Window createToplevelWindow(int, int, unsigned int, unsigned int,
unsigned int);
Window createChildWindow(Window, Cursor = None);
void getWMName();
void getWMIconName();
void getWMNormalHints();
void getWMProtocols();
void getWMHints();
void getMWMHints();
void getBlackboxHints();
void setNetWMAttributes();
void associateClientWindow();
void decorate();
void decorateLabel();
2002-01-18 01:33:58 +00:00
void positionButtons(bool redecorate_label = false);
void positionWindows();
2002-01-18 01:33:58 +00:00
void redrawLabel();
void redrawAllButtons();
2001-12-11 20:47:02 +00:00
void restoreGravity();
void setGravityOffsets();
2002-01-18 01:33:58 +00:00
void setState(unsigned long);
void upsize();
void downsize();
2002-01-18 01:33:58 +00:00
void right_fixsize(int * = 0, int * = 0);
void left_fixsize(int * = 0, int * = 0);
2001-12-11 20:47:02 +00:00
};
2002-07-10 14:46:42 +00:00
#endif // WINDOW_HH