2002-01-09 14:11:20 +00:00
|
|
|
// 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.
|
2002-01-07 23:46:58 +00:00
|
|
|
|
2003-10-05 07:20:47 +00:00
|
|
|
// $Id: Keys.hh,v 1.29 2003/10/05 07:19:36 rathnor Exp $
|
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>
|
2001-12-29 10:32:04 +00:00
|
|
|
#include <X11/Xlib.h>
|
|
|
|
|
2003-02-28 23:37:41 +00:00
|
|
|
#include "NotCopyable.hh"
|
2003-06-30 14:57:14 +00:00
|
|
|
#include "RefCount.hh"
|
|
|
|
namespace FbTk {
|
|
|
|
class Command;
|
|
|
|
};
|
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
|
|
|
|
*/
|
2003-02-28 23:37:41 +00:00
|
|
|
explicit Keys(const char *filename=0);
|
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
|
|
|
|
*/
|
|
|
|
bool load(const char *filename=0);
|
|
|
|
/**
|
2003-06-30 14:57:14 +00:00
|
|
|
do action from XKeyEvent
|
2002-12-01 13:42:15 +00:00
|
|
|
*/
|
2003-06-30 14:57:14 +00:00
|
|
|
void doAction(XKeyEvent &ke);
|
2002-12-01 13:42:15 +00:00
|
|
|
/**
|
|
|
|
Reload configuration from filename
|
|
|
|
@return true on success, else false
|
|
|
|
*/
|
|
|
|
bool reconfigure(const char *filename);
|
2002-01-07 23:46:58 +00:00
|
|
|
|
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
|
|
|
|
2002-12-01 13:42:15 +00:00
|
|
|
void bindKey(unsigned int key, unsigned int mod);
|
|
|
|
/**
|
|
|
|
@param modstr modifier string (i.e Mod4, Mod5)
|
|
|
|
@return modifier number that match modstr
|
|
|
|
*/
|
2003-10-05 07:20:47 +00:00
|
|
|
|
2002-12-01 13:42:15 +00:00
|
|
|
std::string filename;
|
2001-12-11 20:47:02 +00:00
|
|
|
|
2002-12-01 13:42:15 +00:00
|
|
|
class t_key {
|
|
|
|
public:
|
2003-06-30 14:57:14 +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();
|
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;
|
|
|
|
}
|
2003-06-30 14:57:14 +00:00
|
|
|
inline t_key *find(XKeyEvent &ke) {
|
2002-12-01 13:42:15 +00:00
|
|
|
for (unsigned int i=0; i<keylist.size(); i++) {
|
2003-06-30 14:57:14 +00:00
|
|
|
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
|
|
|
|
2003-06-30 14:57:14 +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
|
|
|
|
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;
|
|
|
|
std::vector<t_key *> keylist;
|
|
|
|
};
|
2003-06-30 14:57:14 +00:00
|
|
|
|
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;
|
2003-09-06 13:58:06 +00:00
|
|
|
|
|
|
|
Display *m_display; ///< display connection
|
|
|
|
|
2001-12-11 20:47:02 +00:00
|
|
|
};
|
|
|
|
|
2003-08-19 16:19:28 +00:00
|
|
|
#endif // KEYS_HH
|