2002-01-09 14:11:20 +00:00
|
|
|
// 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.
|
2002-01-07 23:46:58 +00:00
|
|
|
|
2004-11-19 11:37:27 +00:00
|
|
|
// $Id$
|
2002-01-07 23:46:58 +00:00
|
|
|
|
2002-02-17 19:00:24 +00:00
|
|
|
#ifndef KEYS_HH
|
|
|
|
#define KEYS_HH
|
2001-12-11 20:47:02 +00:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2007-01-05 16:54:34 +00:00
|
|
|
#include <list>
|
2006-04-12 15:51:37 +00:00
|
|
|
#include <map>
|
2001-12-29 10:32:04 +00:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
|
2003-12-16 23:36:06 +00:00
|
|
|
#include "FbTk/NotCopyable.hh"
|
|
|
|
#include "FbTk/RefCount.hh"
|
|
|
|
#include "FbTk/Command.hh"
|
2005-05-06 09:22:53 +00:00
|
|
|
#include "FbTk/KeyUtil.hh"
|
2003-02-28 23:37:41 +00:00
|
|
|
|
|
|
|
class Keys:private FbTk::NotCopyable {
|
2001-12-11 20:47:02 +00:00
|
|
|
public:
|
2003-06-30 14:57:14 +00:00
|
|
|
|
2002-12-01 13:42:15 +00:00
|
|
|
/**
|
|
|
|
Constructor
|
|
|
|
@param display display connection
|
|
|
|
@param filename file to load, default none
|
|
|
|
*/
|
2006-04-12 15:51:37 +00:00
|
|
|
explicit Keys();
|
2002-12-01 13:42:15 +00:00
|
|
|
/// destructor
|
|
|
|
~Keys();
|
2003-04-15 00:50:25 +00:00
|
|
|
|
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
|
|
|
/**
|
2006-04-12 15:51:37 +00:00
|
|
|
do action from XKeyEvent; return false if not bound to anything
|
2002-12-01 13:42:15 +00:00
|
|
|
*/
|
2006-04-12 15:51:37 +00:00
|
|
|
bool doAction(XKeyEvent &ke);
|
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; }
|
2006-04-12 15:51:37 +00:00
|
|
|
void keyMode(std::string keyMode);
|
2001-12-11 20:47:02 +00:00
|
|
|
private:
|
2002-12-01 13:42:15 +00:00
|
|
|
void deleteTree();
|
2003-10-05 07:20:47 +00:00
|
|
|
|
2007-01-05 16:54:34 +00:00
|
|
|
void grabKey(unsigned int key, unsigned int mod);
|
|
|
|
void ungrabKeys();
|
2006-04-11 19:22:24 +00:00
|
|
|
|
|
|
|
std::string m_filename;
|
|
|
|
|
|
|
|
class t_key;
|
|
|
|
typedef std::vector<t_key*> keylist_t;
|
|
|
|
|
|
|
|
class t_key {
|
2002-12-01 13:42:15 +00:00
|
|
|
public:
|
2006-04-11 19:22:24 +00:00
|
|
|
t_key(unsigned int key, unsigned int mod,
|
2003-06-30 14:57:14 +00:00
|
|
|
FbTk::RefCount<FbTk::Command> command = FbTk::RefCount<FbTk::Command>(0));
|
2002-12-01 13:42:15 +00:00
|
|
|
t_key(t_key *k);
|
|
|
|
~t_key();
|
2006-04-11 19:22:24 +00:00
|
|
|
|
|
|
|
t_key *find(unsigned int key_, unsigned int mod_) {
|
2006-04-02 21:37:44 +00:00
|
|
|
for (size_t i = 0; i < keylist.size(); i++) {
|
2005-05-06 09:22:53 +00:00
|
|
|
if (keylist[i]->key == key_ && keylist[i]->mod == FbTk::KeyUtil::instance().isolateModifierMask(mod_))
|
2006-04-11 19:22:24 +00:00
|
|
|
return keylist[i];
|
|
|
|
}
|
2002-12-01 13:42:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2006-04-11 19:22:24 +00:00
|
|
|
t_key *find(XKeyEvent &ke) {
|
2006-04-02 21:37:44 +00:00
|
|
|
for (size_t i = 0; i < keylist.size(); i++) {
|
2006-04-11 19:22:24 +00:00
|
|
|
if (keylist[i]->key == ke.keycode &&
|
2005-05-06 09:22:53 +00:00
|
|
|
keylist[i]->mod == FbTk::KeyUtil::instance().isolateModifierMask(ke.state))
|
2006-04-11 19:22:24 +00:00
|
|
|
return keylist[i];
|
|
|
|
}
|
2002-12-01 13:42:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2006-04-11 19:22:24 +00:00
|
|
|
|
|
|
|
bool operator == (XKeyEvent &ke) const {
|
2005-05-06 09:22:53 +00:00
|
|
|
return (mod == FbTk::KeyUtil::instance().isolateModifierMask(ke.state) && key == ke.keycode);
|
2002-12-01 13:42:15 +00:00
|
|
|
}
|
2006-04-11 19:22:24 +00:00
|
|
|
|
2003-06-30 14:57:14 +00:00
|
|
|
FbTk::RefCount<FbTk::Command> m_command;
|
2002-12-01 13:42:15 +00:00
|
|
|
unsigned int key;
|
|
|
|
unsigned int mod;
|
2006-04-11 19:22:24 +00:00
|
|
|
keylist_t keylist;
|
2002-12-01 13:42:15 +00:00
|
|
|
};
|
2003-06-30 14:57:14 +00:00
|
|
|
|
2006-12-19 18:08:33 +00:00
|
|
|
void setKeyMode(t_key *keyMode);
|
2002-08-04 15:55:13 +00:00
|
|
|
|
2006-12-19 18:08:33 +00:00
|
|
|
typedef std::map<std::string, t_key *> keyspace_t;
|
|
|
|
t_key *m_keylist;
|
2006-04-12 15:51:37 +00:00
|
|
|
keyspace_t m_map;
|
2003-09-06 13:58:06 +00:00
|
|
|
|
|
|
|
Display *m_display; ///< display connection
|
2007-01-05 16:54:34 +00:00
|
|
|
std::list<Window> m_window_list;
|
2001-12-11 20:47:02 +00:00
|
|
|
};
|
|
|
|
|
2003-08-19 16:19:28 +00:00
|
|
|
#endif // KEYS_HH
|