fluxbox/src/Window.hh

521 lines
18 KiB
C++
Raw Normal View History

// Window.hh for Fluxbox Window Manager
2003-05-15 11:17:29 +00:00
// Copyright (c) 2001 - 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net)
2001-12-19 13:53:35 +00:00
//
2001-12-11 20:47:02 +00:00
// Window.hh for Blackbox - an X11 Window manager
2002-12-13 20:35:36 +00:00
// Copyright (c) 1997 - 2000 Brad Hughes (bhughes at tcac.net)
2001-12-11 20:47:02 +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
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.
2004-11-19 11:37:27 +00:00
// $Id$
#ifndef WINDOW_HH
#define WINDOW_HH
2001-12-11 20:47:02 +00:00
2004-08-10 12:05:47 +00:00
#include "FbTk/Timer.hh"
#include "FbTk/Subject.hh"
#include "FbTk/EventHandler.hh"
#include "FbTk/XLayerItem.hh"
2003-12-18 18:03:23 +00:00
#include "FbWinFrame.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>
#include <vector>
#include <string>
2002-10-19 10:56:30 +00:00
#include <memory>
2003-04-14 15:01:55 +00:00
#include <map>
2003-04-14 15:01:55 +00:00
class WinClient;
class FbWinFrameTheme;
class BScreen;
2003-05-15 11:17:29 +00:00
class FbWinFrame;
2003-08-19 16:15:32 +00:00
namespace FbTk {
2003-08-19 16:15:32 +00:00
class TextButton;
class MenuTheme;
class ImageControl;
2003-02-03 13:53:48 +00:00
class XLayer;
class Menu;
2003-12-17 01:21:49 +00:00
}
2002-11-15 12:17:03 +00:00
2002-12-13 20:35:36 +00:00
/// Creates the window frame and handles any window event for it
class FluxboxWindow: public FbTk::EventHandler {
2001-12-11 20:47:02 +00:00
public:
/// Represents certain "preset" sets of decorations.
2002-12-13 20:35:36 +00:00
enum Decoration {
DECOR_NONE=0, ///< no decor at all
DECOR_NORMAL, ///< normal normal
DECOR_TINY, ///< tiny decoration
DECOR_TOOL ///< decor tool
2002-12-01 13:42:15 +00:00
};
2002-12-13 20:35:36 +00:00
/// Motif wm Hints
2002-12-01 13:42:15 +00:00
enum {
2002-12-13 20:35:36 +00:00
MwmHintsFunctions = (1l << 0), ///< use motif wm functions
MwmHintsDecorations = (1l << 1) ///< use motif wm decorations
2002-12-01 13:42:15 +00:00
};
2002-12-13 20:35:36 +00:00
/// Motif wm functions
2002-12-01 13:42:15 +00:00
enum MwmFunc{
2002-12-13 20:35:36 +00:00
MwmFuncAll = (1l << 0), ///< all motif wm functions
MwmFuncResize = (1l << 1), ///< resize
MwmFuncMove = (1l << 2), ///< move
MwmFuncIconify = (1l << 3), ///< iconify
MwmFuncMaximize = (1l << 4), ///< maximize
MwmFuncClose = (1l << 5) ///< close
2002-12-01 13:42:15 +00:00
};
2002-12-13 20:35:36 +00:00
/// Motif wm decorations
2002-12-01 13:42:15 +00:00
enum MwmDecor {
2002-12-13 20:35:36 +00:00
MwmDecorAll = (1l << 0), /// all decorations
MwmDecorBorder = (1l << 1), /// border
MwmDecorHandle = (1l << 2), /// handle
MwmDecorTitle = (1l << 3), /// title
MwmDecorMenu = (1l << 4), /// menu
MwmDecorIconify = (1l << 5), /// iconify
MwmDecorMaximize = (1l << 6) /// maximize
2002-12-01 13:42:15 +00:00
};
2003-05-10 14:27:57 +00:00
/// attributes for BlackboxHints
enum Attrib {
ATTRIB_SHADED = 0x01,
ATTRIB_MAXHORIZ = 0x02,
ATTRIB_MAXVERT = 0x04,
ATTRIB_OMNIPRESENT = 0x08,
ATTRIB_WORKSPACE = 0x10,
ATTRIB_STACK = 0x20,
ATTRIB_DECORATION = 0x40,
ATTRIB_HIDDEN = 0x80,
2003-05-10 14:27:57 +00:00
};
/**
* Types of maximization
*/
enum MaximizeMode {
MAX_NONE = 0, ///< normal state
MAX_HORZ = 1, ///< maximize horizontal
MAX_VERT = 2, ///< maximize vertical
MAX_FULL = 3 ///< maximize full
};
/**
This enumeration represents individual decoration
attributes, they can be OR-d together to get a mask.
Useful for saving.
*/
enum DecorationMask {
DECORM_TITLEBAR = (1<<0),
DECORM_HANDLE = (1<<1),
DECORM_BORDER = (1<<2),
DECORM_ICONIFY = (1<<3),
DECORM_MAXIMIZE = (1<<4),
DECORM_CLOSE = (1<<5),
DECORM_MENU = (1<<6),
DECORM_STICKY = (1<<7),
DECORM_SHADE = (1<<8),
DECORM_TAB = (1<<9),
DECORM_ENABLED = (1<<10),
DECORM_LAST = (1<<11) // useful for getting "All"
};
enum ResizeCorner {
2003-12-18 18:03:23 +00:00
LEFTTOP,
LEFTBOTTOM,
RIGHTBOTTOM,
RIGHTTOP
};
2003-05-10 14:27:57 +00:00
typedef struct _blackbox_hints {
unsigned long flags, attrib, workspace, stack;
int decoration;
} BlackboxHints;
typedef struct _blackbox_attributes {
unsigned long flags, attrib, workspace, stack;
int premax_x, premax_y;
unsigned int premax_w, premax_h;
} BlackboxAttributes;
2003-04-14 15:01:55 +00:00
typedef std::list<WinClient *> ClientList;
// this should perhaps be a refcount??
typedef std::list<std::pair<const char *, FbTk::Menu *> > ExtraMenus;
2003-04-14 15:01:55 +00:00
/// create a window from a client
2003-12-18 18:03:23 +00:00
FluxboxWindow(WinClient &client,
2003-04-14 15:01:55 +00:00
FbWinFrameTheme &tm,
FbTk::XLayer &layer);
2002-12-01 13:42:15 +00:00
virtual ~FluxboxWindow();
2003-04-14 15:01:55 +00:00
/// attach client to our client list and remove it from old window
void attachClient(WinClient &client, int x=-1, int y=-1);
2003-04-14 15:01:55 +00:00
/// detach client (remove it from list) and create a new window for it
bool detachClient(WinClient &client);
2003-04-16 12:28:39 +00:00
/// detach current working client if we have more than one
void detachCurrentClient();
2003-04-14 15:01:55 +00:00
/// remove client from client list
bool removeClient(WinClient &client);
/// set new current client and raise it
2003-12-30 20:56:41 +00:00
bool setCurrentClient(WinClient &client, bool setinput = true);
2003-04-14 15:01:55 +00:00
WinClient *findClient(Window win);
void nextClient();
void prevClient();
2003-07-28 12:42:32 +00:00
void moveClientLeft();
void moveClientRight();
void moveClientRightOf(WinClient &win, WinClient &dest);
void moveClientLeftOf(WinClient &win, WinClient &dest);
void moveClientTo(WinClient &win, int x, int y);
ClientList::iterator getClientInsertPosition(int x, int y);
2003-12-30 20:56:41 +00:00
bool setInputFocus();
2003-02-16 16:43:00 +00:00
void raiseAndFocus() { raise(); setInputFocus(); }
void setFocusFlag(bool flag);
2003-02-16 17:57:54 +00:00
// map this window
void show();
// unmap this window
void hide() { hide(true); }
void hide(bool interrupt_moving);
void iconify();
2003-09-12 16:30:21 +00:00
void deiconify(bool reassoc = true, bool do_raise = true);
/// close current client
void close();
/// kill current client
void kill();
/// set the window in withdrawn state
void withdraw(bool interrupt_moving);
/// toggle maximize
void maximize(int type = MAX_FULL);
/// maximizes the window horizontal
void maximizeHorizontal();
/// maximizes the window vertical
void maximizeVertical();
/// maximizes the window fully
void maximizeFull();
/// toggles shade
void shade();
/// toggles sticky
void stick();
void raise();
2003-02-09 14:11:14 +00:00
void lower();
void tempRaise();
2003-02-09 14:11:14 +00:00
void raiseLayer();
void lowerLayer();
void moveToLayer(int layernum);
void setFocusHidden(bool value);
void setIconHidden(bool value);
void reconfigure();
2003-07-28 12:42:32 +00:00
void installColormap(bool);
2003-04-14 15:01:55 +00:00
void restore(WinClient *client, bool remap);
void restore(bool remap);
/// move frame to x, y
void move(int x, int y, int gravity = ForgetGravity);
/// resize frame to width, height
void resize(unsigned int width, unsigned int height);
/// move and resize frame to pox x,y and size width, height
void moveResize(int x, int y, unsigned int width, unsigned int height, int gravity = ForgetGravity);
void setWorkspace(int n);
2003-05-10 14:27:57 +00:00
void changeBlackboxHints(const BlackboxHints &bh);
2003-07-28 16:29:25 +00:00
void updateFunctions();
2003-02-16 17:57:54 +00:00
void restoreAttributes();
void showMenu(int mx, int my);
// popup menu on last button press position
void popupMenu();
void pauseMoving();
void resumeMoving();
/**
@name event handlers
*/
//@{
void handleEvent(XEvent &event);
void buttonPressEvent(XButtonEvent &be);
void buttonReleaseEvent(XButtonEvent &be);
void motionNotifyEvent(XMotionEvent &me);
void destroyNotifyEvent(XDestroyWindowEvent &dwe);
void mapRequestEvent(XMapRequestEvent &mre);
void mapNotifyEvent(XMapEvent &mapev);
void unmapNotifyEvent(XUnmapEvent &unmapev);
void exposeEvent(XExposeEvent &ee);
void configureRequestEvent(XConfigureRequestEvent &ce);
void propertyNotifyEvent(WinClient &client, Atom a);
void enterNotifyEvent(XCrossingEvent &ev);
void leaveNotifyEvent(XCrossingEvent &ev);
//@}
2004-02-16 20:47:51 +00:00
void setDecoration(Decoration decoration, bool apply = true);
void applyDecorations(bool initial = false);
void toggleDecoration();
2003-05-15 11:17:29 +00:00
unsigned int decorationMask() const;
void setDecorationMask(unsigned int mask);
2002-12-01 13:42:15 +00:00
/**
@name accessors
*/
//@{
// whether this window can be tabbed with other windows,
// and others tabbed with it
inline void setTabable(bool tabable) { functions.tabable = tabable; }
inline bool isTabable() { return functions.tabable; }
inline void setMovable(bool movable) { functions.move = movable; }
inline void setResizable(bool resizable) { functions.resize = resizable; }
inline bool isFocusHidden() const { return (m_blackbox_attrib.flags & ATTRIB_HIDDEN); }
inline bool isIconHidden() const { return m_icon_hidden; }
2003-04-14 15:01:55 +00:00
inline bool isManaged() const { return m_managed; }
inline bool isFocused() const { return focused; }
2003-05-15 11:17:29 +00:00
bool isVisible() const;
2003-04-14 15:01:55 +00:00
inline bool isIconic() const { return iconic; }
inline bool isShaded() const { return shaded; }
inline bool isMaximized() const { return maximized == MAX_FULL; }
2003-04-14 15:01:55 +00:00
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 isMoving() const { return moving; }
inline bool isResizing() const { return resizing; }
2002-12-01 13:42:15 +00:00
bool isGroupable() const;
2003-04-14 15:01:55 +00:00
inline int numClients() const { return m_clientlist.size(); }
2004-03-21 09:00:25 +00:00
inline bool empty() const { return m_clientlist.empty(); }
2003-04-14 15:01:55 +00:00
inline ClientList &clientList() { return m_clientlist; }
inline const ClientList &clientList() const { return m_clientlist; }
inline WinClient &winClient() { return *m_client; }
inline const WinClient &winClient() const { return *m_client; }
2003-05-10 16:53:09 +00:00
inline const BScreen &screen() const { return m_screen; }
inline BScreen &screen() { return m_screen; }
2003-04-14 15:01:55 +00:00
2003-05-15 11:17:29 +00:00
inline const FbTk::XLayerItem &layerItem() const { return m_layeritem; }
inline FbTk::XLayerItem &layerItem() { return m_layeritem; }
2003-04-14 15:01:55 +00:00
2003-05-15 11:17:29 +00:00
Window clientWindow() const;
2003-05-15 11:17:29 +00:00
FbTk::FbWindow &fbWindow();
const FbTk::FbWindow &fbWindow() const;
FbTk::Menu &menu() { return *m_windowmenu.get(); }
const FbTk::Menu &menu() const { return *m_windowmenu.get(); }
2003-02-16 15:12:08 +00:00
// for extras to add menus.
// These menus will be marked internal,
// and deleted when the window dies (as opposed to Screen
void addExtraMenu(const char *label, FbTk::Menu *menu);
void removeExtraMenu(FbTk::Menu *menu);
ExtraMenus &extraMenus() { return m_extramenus; }
const ExtraMenus &extraMenus() const { return m_extramenus; }
const FbTk::FbWindow &parent() const { return m_parent; }
FbTk::FbWindow &parent() { return m_parent; }
2003-05-15 11:17:29 +00:00
const std::string &title() const;
const std::string &iconTitle() const;
2003-12-18 18:03:23 +00:00
inline int x() const { return frame().x(); }
inline int y() const { return frame().y(); }
inline unsigned int width() const { return frame().width(); }
inline unsigned int height() const { return frame().height(); }
2003-05-15 11:17:29 +00:00
unsigned int workspaceNumber() const { return m_workspace_number; }
2003-06-24 14:57:54 +00:00
2003-05-15 11:17:29 +00:00
int layerNum() const { return m_layernum; }
void setLayerNum(int layernum);
2003-05-11 13:36:12 +00:00
2003-12-18 18:03:23 +00:00
unsigned int titlebarHeight() const;
2002-12-01 13:42:15 +00:00
bool isLowerTab() const;
2003-04-14 15:01:55 +00:00
int initialState() const;
2003-12-18 18:03:23 +00:00
inline FbWinFrame &frame() { return m_frame; }
inline const FbWinFrame &frame() const { return m_frame; }
2002-12-01 13:42:15 +00:00
/**
@name signals
@{
2002-12-01 13:42:15 +00:00
*/
FbTk::Subject &stateSig() { return m_statesig; }
const FbTk::Subject &stateSig() const { return m_statesig; }
FbTk::Subject &layerSig() { return m_layersig; }
const FbTk::Subject &layerSig() const { return m_layersig; }
2002-12-01 13:42:15 +00:00
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; }
FbTk::Subject &dieSig() { return m_diesig; }
const FbTk::Subject &dieSig() const { return m_diesig; }
FbTk::Subject &focusSig() { return m_focussig; }
2003-12-07 17:47:42 +00:00
FbTk::Subject &titleSig() { return m_titlesig; }
2002-12-13 20:35:36 +00:00
/** @} */ // end group signals
2002-12-01 13:42:15 +00:00
void reconfigTheme();
2003-05-15 11:17:29 +00:00
const timeval &lastFocusTime() const { return m_last_focus_time;}
2002-12-01 13:42:15 +00:00
//@}
2002-12-01 13:42:15 +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;
};
2002-09-07 20:16:43 +00:00
2003-07-28 12:42:32 +00:00
bool oplock; ///< Used to help stop transient loops occurring by locking a window during certain operations
2004-03-21 09:00:25 +00:00
2001-12-11 20:47:02 +00:00
private:
static const int PropBlackboxAttributesElements = 8;
2003-07-28 12:42:32 +00:00
void setupWindow();
void setupMenu();
2003-07-28 12:42:32 +00:00
2003-04-14 15:01:55 +00:00
void init();
2003-06-12 14:35:36 +00:00
/// applies a shape mask to the window if it has one
2003-05-14 14:43:06 +00:00
void shape();
2003-07-28 12:42:32 +00:00
void updateClientLeftWindow();
void grabButtons();
void startMoving(Window win);
void stopMoving(bool interrupted = false);
void startResizing(Window win, int x, int y);
void stopResizing(bool interrupted = false);
2003-04-15 14:40:24 +00:00
/// try to attach current attaching client to a window at pos x, y
void attachTo(int x, int y, bool interrupted = false);
2003-04-15 14:40:24 +00:00
bool getState();
/// gets title string from client window and updates frame's title
void updateTitleFromClient(WinClient &client);
/// gets icon name from client window
void updateIconNameFromClient(WinClient &client);
void updateMWMHintsFromClient(WinClient &client);
2003-12-07 17:47:42 +00:00
void updateBlackboxHintsFromClient(const WinClient &client);
void updateRememberStateFromClient(WinClient &client);
void saveBlackboxAttribs();
void associateClientWindow(bool use_attrs = false, int x = 0, int y = 0, unsigned int width = 1, unsigned int height = 1);
void restoreGravity();
void setGravityOffsets();
void setState(unsigned long stateval, bool setting_up);
2003-04-20 02:47:15 +00:00
// modifies left and top if snap is necessary
void doSnapping(int &left, int &top);
// user_w/h return the values that should be shown to the user
void fixsize(int *user_w = 0, int *user_h = 0);
void moveResizeClient(WinClient &client, int x, int y, unsigned int width, unsigned int height);
/// sends configurenotify to all clients
void sendConfigureNotify(bool send_to_netizens = true);
2004-04-12 18:19:10 +00:00
static void grabPointer(Window grab_window,
Bool owner_events,
unsigned int event_mask,
int pointer_mode, int keyboard_mode,
Window confine_to,
Cursor cursor,
Time time);
static void ungrabPointer(Time time);
2002-12-01 13:42:15 +00:00
// state and hint signals
2003-12-07 17:47:42 +00:00
WinSubject m_hintsig, m_statesig, m_layersig, m_workspacesig, m_diesig, m_focussig, m_titlesig;
2002-09-07 20:16:43 +00:00
class ThemeListener: public FbTk::Observer {
public:
ThemeListener(FluxboxWindow &win):m_win(win) { }
void update(FbTk::Subject *) {
m_win.reconfigTheme();
}
private:
FluxboxWindow &m_win;
};
ThemeListener m_themelistener;
2003-05-10 16:53:09 +00:00
// Window states
bool moving, resizing, shaded, iconic,
focused, stuck, m_managed;
2003-06-12 14:35:36 +00:00
int maximized;
2003-04-15 14:40:24 +00:00
WinClient *m_attaching_tab;
2002-12-01 13:42:15 +00:00
2003-05-10 16:53:09 +00:00
BScreen &m_screen; /// screen on which this window exist
FbTk::Timer m_timer;
2003-04-14 15:01:55 +00:00
Display *display; /// display connection
2003-05-10 16:53:09 +00:00
BlackboxAttributes m_blackbox_attrib;
2002-12-01 13:42:15 +00:00
std::auto_ptr<FbTk::Menu> m_windowmenu;
2003-05-24 13:01:48 +00:00
2003-05-10 16:53:09 +00:00
timeval m_last_focus_time;
2003-05-10 16:53:09 +00:00
int m_button_grab_x, m_button_grab_y; // handles last button press event for move
int m_last_resize_x, m_last_resize_y; // handles last button press event for resize
int m_last_move_x, m_last_move_y; // handles last pos for non opaque moving
unsigned int m_last_resize_h, m_last_resize_w; // handles height/width for resize "window"
2002-12-01 13:42:15 +00:00
2003-05-10 16:53:09 +00:00
unsigned int m_workspace_number;
unsigned long m_current_state;
2003-05-10 16:53:09 +00:00
Decoration m_old_decoration;
2002-12-01 13:42:15 +00:00
2003-04-14 15:01:55 +00:00
ClientList m_clientlist;
2003-12-17 01:21:49 +00:00
WinClient *m_client; ///< current client
2003-08-19 16:15:32 +00:00
typedef std::map<WinClient *, FbTk::TextButton *> Client2ButtonMap;
2003-04-14 15:01:55 +00:00
Client2ButtonMap m_labelbuttons;
2002-12-01 13:42:15 +00:00
2003-04-14 15:01:55 +00:00
// just temporary solution
friend class WinClient;
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
struct _decorations {
bool titlebar, handle, border, iconify,
maximize, close, menu, sticky, shade, tab, enabled;
} decorations;
2001-12-11 20:47:02 +00:00
bool m_toggled_decos;
2002-12-01 13:42:15 +00:00
struct _functions {
bool resize, move, iconify, maximize, close, tabable;
2002-12-01 13:42:15 +00:00
} functions;
2003-05-14 14:43:06 +00:00
bool m_shaped; ///< if the window is shaped with a mask
bool m_icon_hidden; ///< if the window is in the iconbar
int m_old_pos_x, m_old_pos_y; ///< old position so we can restore from maximized
unsigned int m_old_width, m_old_height; ///< old size so we can restore from maximized state
int m_last_button_x, ///< last known x position of the mouse button
m_last_button_y; ///< last known y position of the mouse button
2003-12-18 18:03:23 +00:00
FbWinFrame m_frame;
2002-12-01 13:42:15 +00:00
2003-02-09 14:11:14 +00:00
FbTk::XLayerItem m_layeritem;
int m_layernum;
FbTk::FbWindow &m_parent; ///< window on which we draw move/resize rectangle (the "root window")
ResizeCorner m_resize_corner;
ExtraMenus m_extramenus;
2004-04-12 18:19:10 +00:00
static int s_num_grabs; ///< number of XGrabPointer's
2001-12-11 20:47:02 +00:00
};
2002-07-10 14:46:42 +00:00
#endif // WINDOW_HH