fluxbox/src/fluxbox.hh

264 lines
8.4 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.51 2003/04/27 04:28:04 rathnor 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
#include "Resource.hh"
2001-12-11 20:47:02 +00:00
#include "BaseDisplay.hh"
#include "Timer.hh"
#include "Observer.hh"
#include "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;
2003-04-15 12:22:52 +00:00
class Keys;
class BScreen;
class FbAtoms;
2002-08-04 15:55:13 +00:00
/**
main class for the window manager.
singleton type
*/
2003-01-10 00:41:15 +00:00
class Fluxbox : public BaseDisplay, public FbTk::TimeoutHandler,
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; }
2001-12-11 20:47:02 +00:00
2003-04-25 15:52:58 +00:00
inline Atom getFluxboxPidAtom() const { return m_fluxbox_pid; }
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
FluxboxWindow *searchGroup(Window, FluxboxWindow *);
FluxboxWindow *searchWindow(Window);
2003-04-25 15:52:58 +00:00
inline FluxboxWindow *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
2002-12-01 13:42:15 +00:00
inline const Time &getDoubleClickInterval() const { return resource.double_click_interval; }
2003-04-25 15:52:58 +00:00
inline const Time &getLastTime() const { return m_last_time; }
void addAtomHandler(AtomHandler *atomh);
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};
enum FocusModel { SLOPPYFOCUS=0, SEMISLOPPYFOCUS, CLICKTOFOCUS };
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 char *getMenuFilename() const { return m_rc_menufile->c_str(); }
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)
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
inline const timeval &getAutoRaiseDelay() const { return resource.auto_raise_delay; }
inline unsigned int getCacheLife() const { return *m_rc_cache_life * 60000; }
inline unsigned int getCacheMax() const { return *m_rc_cache_max; }
inline void maskWindowEvents(Window w, FluxboxWindow *bw)
2003-04-25 15:52:58 +00:00
{ m_masked = w; m_masked_window = bw; }
2002-12-01 13:42:15 +00:00
void watchKeyRelease(BScreen *screen, unsigned int mods);
2002-12-01 13:42:15 +00:00
void setFocusedWindow(FluxboxWindow *w);
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 *);
void saveTitlebarFilename(const char *);
void saveSlitlistFilename(const char *val) { m_rc_slitlistfile = (val == 0 ? "" : val); }
2003-04-15 12:22:52 +00:00
void saveWindowSearch(Window win, FluxboxWindow *fbwin);
void saveGroupSearch(Window win, FluxboxWindow *fbwin);
2002-12-01 13:42:15 +00:00
void save_rc();
2003-04-15 12:22:52 +00:00
void removeWindowSearch(Window win);
void removeGroupSearch(Window win);
void restart(const char *command = 0);
2002-12-01 13:42:15 +00:00
void reconfigure();
void rereadMenu();
void checkMenu();
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);
2002-10-13 21:55:56 +00:00
2002-12-01 13:42:15 +00:00
virtual void timeout();
2002-12-01 13:42:15 +00:00
inline const Cursor &getSessionCursor() const { return cursor.session; }
inline const Cursor &getMoveCursor() const { return cursor.move; }
inline const Cursor &getLowerLeftAngleCursor() const { return cursor.ll_angle; }
inline const Cursor &getLowerRightAngleCursor() const { return cursor.lr_angle; }
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
enum { B_AMERICANDATE = 1, B_EUROPEANDATE };
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
typedef std::vector<Fluxbox::Titlebar> TitlebarList;
2001-12-11 20:47:02 +00:00
private:
2002-12-01 13:42:15 +00:00
struct cursor {
Cursor session, move, ll_angle, lr_angle;
} cursor;
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;
struct resource {
Time double_click_interval;
timeval auto_raise_delay;
} resource;
2002-12-01 13:42:15 +00:00
std::string getRcFilename();
void getDefaultDataFilename(char *, std::string &);
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 doWindowAction(int action, const int param);
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;
2002-12-01 13:42:15 +00:00
ResourceManager m_resourcemanager, m_screen_rm;
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
//--- Resources
Resource<bool> m_rc_tabs;
Resource<int> m_rc_colors_per_channel, m_rc_numlayers;
2002-12-01 13:42:15 +00:00
Resource<std::string> m_rc_stylefile,
m_rc_menufile, m_rc_keyfile, m_rc_slitlistfile,
m_rc_groupfile;
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
Resource<TitlebarList> m_rc_titlebar_left, m_rc_titlebar_right;
Resource<unsigned int> m_rc_cache_life, m_rc_cache_max;
2001-12-11 20:47:02 +00:00
2003-04-25 15:52:58 +00:00
std::map<Window, FluxboxWindow *> m_window_search;
std::map<Window, FluxboxWindow *> 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;
FluxboxWindow *m_focused_window, *m_masked_window;
FbTk::Timer m_timer;
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;
Window m_masked;
std::string m_rc_file; ///< resource filename
char **m_argv;
int m_argc;
2002-10-13 21:55:56 +00:00
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[];
2002-04-28 18:55:43 +00:00
2003-04-25 15:52:58 +00:00
static Fluxbox *s_singleton;
2002-12-01 13:42:15 +00:00
std::vector<AtomHandler *> m_atomhandler;
2003-04-15 12:22:52 +00:00
2001-12-11 20:47:02 +00:00
};
2003-04-25 15:52:58 +00:00
#endif // FLUXBOX_HH