fluxbox/src/Keys.hh

161 lines
5 KiB
C++
Raw Normal View History

// Keys.hh for Fluxbox - an X11 Window manager
2005-01-24 18:34:57 +00:00
// Copyright (c) 2001 - 2003 Henrik Kinnunen (fluxgen at fluxbox dot org)
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
// 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-02-17 19:00:24 +00:00
#ifndef KEYS_HH
#define KEYS_HH
2001-12-11 20:47:02 +00:00
2003-12-16 23:36:06 +00:00
#include "FbTk/NotCopyable.hh"
#include "FbTk/RefCount.hh"
#include "FbTk/Command.hh"
#include "FbTk/KeyUtil.hh"
2003-02-28 23:37:41 +00:00
2007-12-30 15:32:53 +00:00
#include <string>
#include <list>
#include <map>
namespace FbTk {
class EventHandler;
}
2003-02-28 23:37:41 +00:00
class Keys:private FbTk::NotCopyable {
2001-12-11 20:47:02 +00:00
public:
2007-02-09 18:13:01 +00:00
// contexts for events
// it's ok if there is overlap; it will be worked out in t_key::find()
// eventHandlers should submit bitwise-or of contexts the event happened in
enum {
GLOBAL = 0x01,
ON_DESKTOP = 0x02,
ON_TOOLBAR = 0x04,
ON_ICONBUTTON = 0x08,
ON_TITLEBAR = 0x10,
ON_WINDOW = 0x20,
ON_TAB = 0x40,
ON_SLIT = 0x80
// and so on...
};
2007-10-13 21:51:37 +00:00
/// constructor
explicit Keys();
2002-12-01 13:42:15 +00:00
/// destructor
~Keys();
2002-12-01 13:42:15 +00:00
/**
Load configuration from file
@return true on success, else false
*/
2003-12-20 17:37:57 +00:00
bool load(const char *filename = 0);
/**
Save keybindings to a file
Note: the file will be overwritten
@return true on success, else false
*/
bool save(const char *filename = 0) const;
/// bind a key action from a string
/// @return false on failure
bool addBinding(const std::string &binding);
2002-12-01 13:42:15 +00:00
/**
do action from XKeyEvent; return false if not bound to anything
2002-12-01 13:42:15 +00:00
*/
2007-12-09 20:47:41 +00:00
bool doAction(int type, unsigned int mods, unsigned int key, int context,
Time time = 0);
2007-10-13 21:51:37 +00:00
/// register a window so that proper keys/buttons get grabbed on it
void registerWindow(Window win, FbTk::EventHandler &handler, int context);
2007-10-13 21:51:37 +00:00
/// unregister window
void unregisterWindow(Window win);
2003-12-20 17:37:57 +00:00
2002-12-01 13:42:15 +00:00
/**
Reload configuration from filename
@return true on success, else false
*/
bool reconfigure(const char *filename);
2003-12-20 17:37:57 +00:00
const std::string filename() const { return m_filename; }
void keyMode(std::string keyMode);
2001-12-11 20:47:02 +00:00
private:
2002-12-01 13:42:15 +00:00
void deleteTree();
void grabKey(unsigned int key, unsigned int mod);
void ungrabKeys();
2007-10-13 21:51:37 +00:00
void grabButton(unsigned int button, unsigned int mod, int context);
2007-02-09 18:13:01 +00:00
void ungrabButtons();
2007-10-13 21:51:37 +00:00
void grabWindow(Window win);
2006-04-11 19:22:24 +00:00
2007-09-30 11:35:20 +00:00
// Load default keybindings for when there are errors loading the initial one
void loadDefaults();
2006-04-11 19:22:24 +00:00
std::string m_filename;
class t_key;
2007-10-13 21:51:37 +00:00
typedef std::list<t_key*> keylist_t;
2006-04-11 19:22:24 +00:00
class t_key {
2002-12-01 13:42:15 +00:00
public:
2007-02-09 18:13:01 +00:00
t_key(int type, unsigned int mod, unsigned int key, int context,
2007-12-09 20:47:41 +00:00
bool isdouble);
2002-12-01 13:42:15 +00:00
t_key(t_key *k);
~t_key();
2006-04-11 19:22:24 +00:00
2007-02-09 18:13:01 +00:00
t_key *find(int type_, unsigned int mod_, unsigned int key_,
2007-12-09 20:47:41 +00:00
int context_, bool isdouble_) {
// t_key ctor sets context_ of 0 to GLOBAL, so we must here too
context_ = context_ ? context_ : GLOBAL;
2007-10-13 21:51:37 +00:00
keylist_t::iterator it = keylist.begin(), it_end = keylist.end();
for (; it != it_end; it++) {
if ((*it)->type == type_ && (*it)->key == key_ &&
2007-12-09 20:47:41 +00:00
((*it)->context & context_) > 0 &&
isdouble_ == (*it)->isdouble && (*it)->mod ==
2007-02-09 18:13:01 +00:00
FbTk::KeyUtil::instance().isolateModifierMask(mod_))
2007-10-13 21:51:37 +00:00
return *it;
2006-04-11 19:22:24 +00:00
}
2002-12-01 13:42:15 +00:00
return 0;
}
2006-04-11 19:22:24 +00:00
FbTk::RefCount<FbTk::Command> m_command;
2007-02-09 18:13:01 +00:00
int context; // ON_TITLEBAR, etc.: bitwise-or of all desired contexts
int type; // KeyPress or ButtonPress
unsigned int key; // key code or button number
2002-12-01 13:42:15 +00:00
unsigned int mod;
2007-12-09 20:47:41 +00:00
bool isdouble;
2006-04-11 19:22:24 +00:00
keylist_t keylist;
2002-12-01 13:42:15 +00:00
};
void setKeyMode(t_key *keyMode);
2002-08-04 15:55:13 +00:00
typedef std::map<std::string, t_key *> keyspace_t;
t_key *m_keylist;
keyspace_t m_map;
Display *m_display; ///< display connection
2007-10-13 21:51:37 +00:00
typedef std::map<Window, int> WindowMap;
typedef std::map<Window, FbTk::EventHandler*> HandlerMap;
2007-10-13 21:51:37 +00:00
WindowMap m_window_map;
HandlerMap m_handler_map;
2001-12-11 20:47:02 +00:00
};
2003-08-19 16:19:28 +00:00
#endif // KEYS_HH