fluxbox/src/Keys.hh

125 lines
3.8 KiB
C++
Raw Normal View History

// Keys.hh for Fluxbox - an X11 Window manager
2003-08-19 16:19:28 +00:00
// Copyright (c) 2001 - 2003 Henrik Kinnunen (fluxgen at users.sourceforge.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,
// 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.
2003-12-20 17:37:57 +00:00
// $Id: Keys.hh,v 1.31 2003/12/20 17:37:20 fluxgen Exp $
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 <X11/Xlib.h>
2003-12-16 23:36:06 +00:00
#include "FbTk/NotCopyable.hh"
#include "FbTk/RefCount.hh"
#include "FbTk/Command.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
*/
2003-02-28 23:37:41 +00:00
explicit Keys(const char *filename=0);
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
2002-12-01 13:42:15 +00:00
*/
void 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; }
2001-12-11 20:47:02 +00:00
private:
2002-12-01 13:42:15 +00:00
void deleteTree();
2002-12-01 13:42:15 +00:00
void bindKey(unsigned int key, unsigned int mod);
2003-12-20 17:37:57 +00:00
std::string m_filename;
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
class t_key {
public:
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();
2001-12-11 20:47:02 +00:00
2002-12-01 13:42:15 +00:00
inline t_key *find(unsigned int key_, unsigned int mod_) {
for (unsigned int i=0; i<keylist.size(); i++) {
if (keylist[i]->key == key_ && keylist[i]->mod == mod_)
return keylist[i];
}
return 0;
}
inline t_key *find(XKeyEvent &ke) {
2002-12-01 13:42:15 +00:00
for (unsigned int i=0; i<keylist.size(); i++) {
if (keylist[i]->key == ke.keycode && keylist[i]->mod == ke.state)
2002-12-01 13:42:15 +00:00
return keylist[i];
}
return 0;
}
2001-12-11 20:47:02 +00:00
inline bool operator == (XKeyEvent &ke) const {
return (mod == ke.state && key == ke.keycode);
2002-12-01 13:42:15 +00:00
}
2001-12-11 20:47:02 +00:00
FbTk::RefCount<FbTk::Command> m_command;
2002-12-01 13:42:15 +00:00
unsigned int key;
unsigned int mod;
std::vector<t_key *> keylist;
};
2002-12-01 13:42:15 +00:00
/**
merge two linked list
@return true on success, else false
*/
bool mergeTree(t_key *newtree, t_key *basetree=0);
2002-08-04 15:55:13 +00:00
2002-12-01 13:42:15 +00:00
std::vector<t_key *> m_keylist;
Display *m_display; ///< display connection
2003-12-20 17:37:57 +00:00
unsigned int m_current_line;
2001-12-11 20:47:02 +00:00
};
2003-08-19 16:19:28 +00:00
#endif // KEYS_HH