fluxbox/src/fluxbox.hh

316 lines
11 KiB
C++
Raw Normal View History

// fluxbox.hh for Fluxbox Window Manager
2003-03-22 13:31:04 +00:00
// Copyright (c) 2001 - 2003 Henrik Kinnunen (fluxgen at users.sourceforge.net)
//
2001-12-11 20:47:02 +00:00
// blackbox.hh for Blackbox - an X11 Window manager
2003-03-22 13:31:04 +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,
2003-03-22 13:31:04 +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.
// $Id: fluxbox.hh,v 1.85 2004/04/18 21:16:06 fluxgen Exp $
2001-12-11 20:47:02 +00:00
2002-02-17 18:42:15 +00:00
#ifndef FLUXBOX_HH
#define FLUXBOX_HH
2001-12-11 20:47:02 +00:00
2003-12-19 00:35:08 +00:00
#include "FbTk/App.hh"
#include "FbTk/Resource.hh"
#include "FbTk/Timer.hh"
#include "FbTk/Observer.hh"
#include "FbTk/SignalHandler.hh"
#include <X11/Xlib.h>
#include <X11/Xresource.h>
#include <cstdio>
2003-04-25 15:52:58 +00:00
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif // HAVE_CONFIG_H
#ifdef TIME_WITH_SYS_TIME
#include <sys/time.h>
#include <time.h>
#else // !TIME_WITH_SYS_TIME
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#else // !HAVE_SYS_TIME_H
#include <time.h>
#endif // HAVE_SYS_TIME_H
#endif // TIME_WITH_SYS_TIME
2002-10-19 14:15:07 +00:00
#include <list>
#include <map>
#include <memory>
2001-12-11 20:47:02 +00:00
#include <string>
#include <vector>
class AtomHandler;
2002-11-30 20:16:14 +00:00
class FluxboxWindow;
class WinClient;
2003-04-15 12:22:52 +00:00
class Keys;
class BScreen;
class FbAtoms;
2003-12-03 00:33:30 +00:00
class Toolbar;
/// main class for the window manager.
2002-08-04 15:55:13 +00:00
/**
singleton type
*/
2003-08-11 17:15:51 +00:00
class Fluxbox : public FbTk::App,
2002-12-01 13:42:15 +00:00
public FbTk::SignalEventHandler,
public FbTk::Observer {
2001-12-11 20:47:02 +00:00
public:
2003-04-25 15:52:58 +00:00
Fluxbox(int argc, char **argv, const char * dpy_name= 0,
const char *rcfilename = 0);
2002-12-01 13:42:15 +00:00
virtual ~Fluxbox();
2001-12-11 20:47:02 +00:00
2003-04-25 15:52:58 +00:00
static Fluxbox *instance() { return s_singleton; }
/// main event loop
void eventLoop();
bool validateWindow(Window win) const;
void grab();
void ungrab();
2003-12-20 17:40:50 +00:00
Keys *keys() { return m_key.get(); }
2003-04-25 15:52:58 +00:00
inline Atom getFluxboxPidAtom() const { return m_fluxbox_pid; }
2001-12-11 20:47:02 +00:00
// Not currently implemented until we decide how it'll be used
//WinClient *searchGroup(Window);
WinClient *searchWindow(Window);
inline WinClient *getFocusedWindow() { return m_focused_window; }
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
BScreen *searchScreen(Window w);
2001-12-11 20:47:02 +00:00
2003-12-19 00:35:08 +00:00
inline unsigned int getDoubleClickInterval() const { return *m_rc_double_click_interval; }
inline unsigned int getUpdateDelayTime() const { return *m_rc_update_delay_time; }
2003-12-21 23:24:25 +00:00
inline Time getLastTime() const { return m_last_time; }
2003-04-25 15:52:58 +00:00
const AtomHandler* getAtomHandler(std::string name);
void addAtomHandler(AtomHandler *atomh, std::string name= "");
2003-04-25 15:52:58 +00:00
void removeAtomHandler(AtomHandler *atomh);
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
/// obsolete
enum Titlebar{SHADE=0, MINIMIZE, MAXIMIZE, CLOSE, STICK, MENU, EMPTY};
2003-12-19 00:35:08 +00:00
2004-02-10 18:45:57 +00:00
inline bool getIgnoreBorder() const { return *m_rc_ignoreborder; }
2003-04-15 12:22:52 +00:00
inline const std::vector<Fluxbox::Titlebar>& getTitlebarRight() const { return *m_rc_titlebar_right; }
inline const std::vector<Fluxbox::Titlebar>& getTitlebarLeft() const { return *m_rc_titlebar_left; }
inline const std::string &getStyleFilename() const { return *m_rc_stylefile; }
2002-12-01 13:42:15 +00:00
inline const std::string &getMenuFilename() const { return *m_rc_menufile; }
2002-12-01 13:42:15 +00:00
inline const std::string &getSlitlistFilename() const { return *m_rc_slitlistfile; }
inline int colorsPerChannel() const { return *m_rc_colors_per_channel; }
inline int getNumberOfLayers() const { return *m_rc_numlayers; }
// class to store layer numbers (special Resource type)
// we have a special resource type because we need to be able to name certain layers
// a Resource<int> wouldn't allow this
class Layer {
public:
2003-04-15 12:22:52 +00:00
explicit Layer(int i) : m_num(i) {};
inline int getNum() const { return m_num; }
Layer &operator=(int num) { m_num = num; return *this; }
private:
int m_num;
};
// TODO these probably should be configurable
2003-02-16 15:12:08 +00:00
inline int getMenuLayer() const { return 0; }
inline int getAboveDockLayer() const { return 2; }
inline int getDockLayer() const { return 4; }
inline int getTopLayer() const { return 6; }
inline int getNormalLayer() const { return 8; }
inline int getBottomLayer() const { return 10; }
inline int getDesktopLayer() const { return 12; }
2002-12-01 13:42:15 +00:00
2003-10-05 06:28:47 +00:00
inline time_t getAutoRaiseDelay() const { return *m_rc_auto_raise_delay; }
2002-12-01 13:42:15 +00:00
inline unsigned int getCacheLife() const { return *m_rc_cache_life * 60000; }
inline unsigned int getCacheMax() const { return *m_rc_cache_max; }
2003-12-31 00:35:21 +00:00
inline bool useMod1() const { return *m_rc_use_mod1; }
2002-12-01 13:42:15 +00:00
2003-12-30 20:56:41 +00:00
inline void maskWindowEvents(Window w, FluxboxWindow *bw)
{ m_masked = w; m_masked_window = bw; }
void watchKeyRelease(BScreen &screen, unsigned int mods);
void setFocusedWindow(WinClient *w);
2003-12-30 20:56:41 +00:00
void revertFocus(BScreen &screen);
2004-03-21 09:00:25 +00:00
// like revertFocus, but specifically related to this window (transients etc)
void unfocusWindow(WinClient &client, bool full_revert = true, bool unfocus_frame = false);
2002-12-01 13:42:15 +00:00
void shutdown();
2003-04-15 12:22:52 +00:00
void load_rc(BScreen &scr);
void loadRootCommand(BScreen &scr);
2002-12-01 13:42:15 +00:00
void loadTitlebar();
void saveStyleFilename(const char *val) { m_rc_stylefile = (val == 0 ? "" : val); }
void saveMenuFilename(const char *);
2003-05-13 00:20:49 +00:00
void clearMenuFilenames();
2002-12-01 13:42:15 +00:00
void saveTitlebarFilename(const char *);
void saveSlitlistFilename(const char *val) { m_rc_slitlistfile = (val == 0 ? "" : val); }
void saveWindowSearch(Window win, WinClient *winclient);
// some windows relate to the group, not the client, so we record separately
// searchWindow on these windows will give the active client in the group
void saveWindowSearchGroup(Window win, FluxboxWindow *fbwin);
void saveGroupSearch(Window win, WinClient *winclient);
2002-12-01 13:42:15 +00:00
void save_rc();
2003-04-15 12:22:52 +00:00
void removeWindowSearch(Window win);
void removeWindowSearchGroup(Window win);
2003-04-15 12:22:52 +00:00
void removeGroupSearch(Window win);
void restart(const char *command = 0);
2002-12-01 13:42:15 +00:00
void reconfigure();
void rereadMenu();
2003-05-13 00:20:49 +00:00
/// reloads the menus if the timestamps changed
2002-12-01 13:42:15 +00:00
void checkMenu();
2004-01-11 16:10:51 +00:00
void hideExtraMenus(BScreen &screen);
2002-12-01 13:42:15 +00:00
/// handle any system signal sent to the application
void handleSignal(int signum);
void update(FbTk::Subject *changed);
2002-12-01 13:42:15 +00:00
void attachSignals(FluxboxWindow &win);
void attachSignals(WinClient &winclient);
2002-10-13 21:55:56 +00:00
2003-08-11 17:15:51 +00:00
void timed_reconfigure();
bool isStartup() const { return m_starting; }
2004-01-11 16:10:51 +00:00
2002-12-01 13:42:15 +00:00
typedef std::vector<Fluxbox::Titlebar> TitlebarList;
2003-05-13 00:20:49 +00:00
/// @return whether the timestamps on the menu changed
bool menuTimestampsChanged() const;
2003-05-14 14:37:06 +00:00
bool haveShape() const { return m_have_shape; }
int shapeEventbase() const { return m_shape_eventbase; }
2003-05-27 11:55:23 +00:00
void getDefaultDataFilename(char *, std::string &);
// screen mouse was in at last key event
BScreen *mouseScreen() { return m_mousescreen; }
// screen of window that last key event (i.e. focused window) went to
BScreen *keyScreen() { return m_keyscreen; }
// screen we are watching for modifier changes
BScreen *watchingScreen() { return m_watching_screen; }
const XEvent &lastEvent() const { return m_last_event; }
2001-12-11 20:47:02 +00:00
private:
2002-12-01 13:42:15 +00:00
typedef struct MenuTimestamp {
2003-04-25 15:52:58 +00:00
std::string filename;
2002-12-01 13:42:15 +00:00
time_t timestamp;
} MenuTimestamp;
2003-12-19 00:35:08 +00:00
2002-12-01 13:42:15 +00:00
std::string getRcFilename();
void load_rc();
2002-12-01 13:42:15 +00:00
void reload_rc();
void real_rereadMenu();
void real_reconfigure();
2002-12-01 13:42:15 +00:00
void handleEvent(XEvent *xe);
2002-12-01 13:42:15 +00:00
void setupConfigFiles();
void handleButtonEvent(XButtonEvent &be);
void handleUnmapNotify(XUnmapEvent &ue);
void handleClientMessage(XClientMessageEvent &ce);
void handleKeyEvent(XKeyEvent &ke);
2003-04-15 12:22:52 +00:00
void setTitlebar(std::vector<Fluxbox::Titlebar>& dir, const char *arg);
2003-04-14 15:28:52 +00:00
2003-04-15 12:22:52 +00:00
std::auto_ptr<FbAtoms> m_fbatoms;
FbTk::ResourceManager m_resourcemanager, &m_screen_rm;
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
//--- Resources
2003-12-19 00:35:08 +00:00
2003-05-18 22:04:06 +00:00
FbTk::Resource<bool> m_rc_tabs, m_rc_ignoreborder;
2003-12-19 00:35:08 +00:00
FbTk::Resource<int> m_rc_colors_per_channel, m_rc_numlayers,
m_rc_double_click_interval, m_rc_update_delay_time;
2003-05-18 22:04:06 +00:00
FbTk::Resource<std::string> m_rc_stylefile,
2002-12-01 13:42:15 +00:00
m_rc_menufile, m_rc_keyfile, m_rc_slitlistfile,
m_rc_groupfile;
2001-12-11 20:47:02 +00:00
2003-05-18 22:04:06 +00:00
FbTk::Resource<TitlebarList> m_rc_titlebar_left, m_rc_titlebar_right;
FbTk::Resource<unsigned int> m_rc_cache_life, m_rc_cache_max;
2003-10-05 06:28:47 +00:00
FbTk::Resource<time_t> m_rc_auto_raise_delay;
2003-12-31 00:35:21 +00:00
FbTk::Resource<bool> m_rc_use_mod1; /// temporary!, to disable mod1 for resize/move
std::map<Window, WinClient *> m_window_search;
std::map<Window, FluxboxWindow *> m_window_search_group;
// A window is the group leader, which can map to several
// WinClients in the group, it is *not* fluxbox's concept of groups
// See ICCCM section 4.1.11
// The group leader (which may not be mapped, so may not have a WinClient)
// will have it's window being the group index
std::multimap<Window, WinClient *> m_group_search;
2001-12-11 20:47:02 +00:00
2003-04-25 15:52:58 +00:00
std::list<MenuTimestamp *> m_menu_timestamps;
2002-12-01 13:42:15 +00:00
typedef std::list<BScreen *> ScreenList;
2003-04-25 15:52:58 +00:00
ScreenList m_screen_list;
WinClient *m_focused_window;
2003-12-30 20:56:41 +00:00
FluxboxWindow *m_masked_window;
2003-04-25 15:52:58 +00:00
BScreen *m_mousescreen, *m_keyscreen;
2003-04-25 15:52:58 +00:00
BScreen *m_watching_screen;
unsigned int m_watch_keyrelease;
2001-12-11 20:47:02 +00:00
2003-04-25 15:52:58 +00:00
Atom m_fluxbox_pid;
2001-12-11 20:47:02 +00:00
2003-04-25 15:52:58 +00:00
bool m_reconfigure_wait, m_reread_menu_wait;
Time m_last_time;
2003-12-30 20:56:41 +00:00
Window m_masked;
2003-04-25 15:52:58 +00:00
std::string m_rc_file; ///< resource filename
char **m_argv;
int m_argc;
XEvent m_last_event;
2002-10-13 21:55:56 +00:00
FbTk::Timer m_reconfig_timer; ///< when we execute reconfig command we must wait at least to next event round
2003-04-25 15:52:58 +00:00
std::auto_ptr<Keys> m_key;
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
//default arguments for titlebar left and right
2003-04-25 15:52:58 +00:00
static Fluxbox::Titlebar s_titlebar_left[], s_titlebar_right[];
static Fluxbox *s_singleton;
typedef std::map<AtomHandler *, std::string> AtomHandlerContainer;
typedef AtomHandlerContainer::iterator AtomHandlerContainerIt;
AtomHandlerContainer m_atomhandler;
2003-12-03 00:33:30 +00:00
std::vector<Toolbar *> m_toolbars;
bool m_starting;
bool m_shutdown;
int m_server_grabs;
2003-05-12 04:23:31 +00:00
int m_randr_event_type; ///< the type number of randr event
2003-05-14 14:37:06 +00:00
int m_shape_eventbase; ///< event base for shape events
bool m_have_shape; ///< if shape is supported by server
2003-05-11 22:19:17 +00:00
const char *m_RC_PATH;
const char *m_RC_INIT_FILE;
2003-07-23 10:43:30 +00:00
Atom m_kwm1_dockwindow, m_kwm2_dockwindow;
2001-12-11 20:47:02 +00:00
};
2003-04-25 15:52:58 +00:00
#endif // FLUXBOX_HH