fluxbox/src/Keys.hh

132 lines
4 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
#include <string>
#include <vector>
#include <list>
#include <map>
#include <X11/Xlib.h>
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
class Keys:private FbTk::NotCopyable {
2001-12-11 20:47:02 +00:00
public:
2002-12-01 13:42:15 +00:00
/**
Constructor
@param display display connection
@param filename file to load, default none
*/
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
*/
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; }
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();
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,
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_) {
for (size_t i = 0; i < keylist.size(); i++) {
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) {
for (size_t i = 0; i < keylist.size(); i++) {
2006-04-11 19:22:24 +00:00
if (keylist[i]->key == ke.keycode &&
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 {
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
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
};
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
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