2002-01-09 14:11:20 +00:00
|
|
|
// Keys.hh for Fluxbox - an X11 Window manager
|
2001-12-11 20:47:02 +00:00
|
|
|
// Copyright (c) 2001 Henrik Kinnunen (fluxgen@linuxmail.org)
|
|
|
|
//
|
|
|
|
// 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
|
|
|
|
2002-08-04 15:55:13 +00:00
|
|
|
// $Id: Keys.hh,v 1.15 2002/08/04 15:55:13 fluxgen 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>
|
|
|
|
|
2001-12-11 20:47:02 +00:00
|
|
|
class Keys
|
|
|
|
{
|
|
|
|
public:
|
2002-08-04 15:55:13 +00:00
|
|
|
/**
|
|
|
|
Key actions
|
|
|
|
*/
|
2002-02-26 22:19:51 +00:00
|
|
|
enum KeyAction{
|
2001-12-29 10:32:04 +00:00
|
|
|
ICONIFY=0,
|
2002-02-04 06:42:00 +00:00
|
|
|
RAISE, LOWER,
|
2001-12-29 10:32:04 +00:00
|
|
|
CLOSE,
|
|
|
|
ABORTKEYCHAIN,
|
2002-02-26 22:19:51 +00:00
|
|
|
WORKSPACE,
|
2002-02-04 06:42:00 +00:00
|
|
|
WORKSPACE1, WORKSPACE2, WORKSPACE3, WORKSPACE4,
|
|
|
|
WORKSPACE5, WORKSPACE6, WORKSPACE7, WORKSPACE8,
|
|
|
|
WORKSPACE9, WORKSPACE10, WORKSPACE11, WORKSPACE12,
|
2002-06-29 10:44:50 +00:00
|
|
|
SENDTOWORKSPACE, // Send window to a workspace
|
2002-02-04 06:42:00 +00:00
|
|
|
NEXTWORKSPACE, PREVWORKSPACE,
|
2001-12-29 10:32:04 +00:00
|
|
|
LEFTWORKSPACE, RIGHTWORKSPACE,
|
|
|
|
KILLWINDOW, NEXTWINDOW, PREVWINDOW,
|
2002-05-02 07:10:03 +00:00
|
|
|
NEXTTAB, PREVTAB, FIRSTTAB, LASTTAB, MOVETABPREV, MOVETABNEXT,
|
2002-06-29 10:44:50 +00:00
|
|
|
SHADE, MAXIMIZE,
|
|
|
|
STICK, // Make Sticky
|
|
|
|
EXECUTE, // Run command
|
|
|
|
VERTMAX, // Maximize vertical
|
|
|
|
HORIZMAX, // Maximize horizontal
|
2002-02-04 06:42:00 +00:00
|
|
|
NUDGERIGHT, NUDGELEFT,NUDGEUP, NUDGEDOWN,
|
|
|
|
BIGNUDGERIGHT, BIGNUDGELEFT, BIGNUDGEUP, BIGNUDGEDOWN,
|
|
|
|
HORIZINC, VERTINC, HORIZDEC, VERTDEC,
|
2002-06-29 10:44:50 +00:00
|
|
|
TOGGLEDECOR,// toggle visibility of decor (title, frame, handles)
|
|
|
|
TOGGLETAB, // toggle visibilty of tab
|
|
|
|
ROOTMENU, // pop up rootmenu
|
|
|
|
LASTKEYGRAB //mark end of keygrabbs
|
2001-12-11 20:47:02 +00:00
|
|
|
};
|
2002-08-04 15:55:13 +00:00
|
|
|
/**
|
|
|
|
Constructor
|
|
|
|
@param display display connection
|
|
|
|
@param filename file to load, default none
|
|
|
|
*/
|
2002-07-27 18:03:39 +00:00
|
|
|
Keys(Display *display, const char *filename=0);
|
|
|
|
/// destructor
|
2001-12-11 20:47:02 +00:00
|
|
|
~Keys();
|
2002-07-27 18:03:39 +00:00
|
|
|
/**
|
|
|
|
Load configuration from file
|
|
|
|
@return true on success, else false
|
|
|
|
*/
|
|
|
|
bool load(const char *filename=0);
|
|
|
|
/**
|
|
|
|
Determine action from XKeyEvent
|
|
|
|
@return KeyAction value
|
|
|
|
*/
|
2001-12-11 20:47:02 +00:00
|
|
|
KeyAction getAction(XKeyEvent *ke);
|
2002-07-27 18:03:39 +00:00
|
|
|
/**
|
|
|
|
Reload configuration from filename
|
|
|
|
@return true on success, else false
|
|
|
|
*/
|
|
|
|
bool reconfigure(const char *filename);
|
|
|
|
/**
|
|
|
|
Get string value of the KeyAction enum value
|
|
|
|
@return string of action
|
|
|
|
*/
|
2001-12-11 20:47:02 +00:00
|
|
|
const char *getActionStr(KeyAction action);
|
2002-07-27 18:03:39 +00:00
|
|
|
/**
|
|
|
|
Get command to execute (key action EXECUTE)
|
|
|
|
@return string to command
|
|
|
|
*/
|
|
|
|
const std::string &getExecCommand() { return m_execcmdstring; }
|
|
|
|
/**
|
|
|
|
@return number of parameters
|
|
|
|
*/
|
2002-02-20 23:10:48 +00:00
|
|
|
int getParam() const { return m_param; }
|
2002-01-07 23:46:58 +00:00
|
|
|
|
2001-12-11 20:47:02 +00:00
|
|
|
private:
|
|
|
|
void deleteTree();
|
2002-01-07 23:46:58 +00:00
|
|
|
void ungrabKeys();
|
2001-12-11 20:47:02 +00:00
|
|
|
void bindKey(unsigned int key, unsigned int mod);
|
2002-08-04 15:55:13 +00:00
|
|
|
/**
|
|
|
|
@param modstr modifier string (i.e Mod4, Mod5)
|
|
|
|
@return modifier number that match modstr
|
|
|
|
*/
|
2002-01-07 23:46:58 +00:00
|
|
|
unsigned int getModifier(const char *modstr);
|
2002-08-04 15:55:13 +00:00
|
|
|
/**
|
|
|
|
@param keystr a key string (i.e F1, Enter)
|
|
|
|
@return key number that match keystr
|
|
|
|
*/
|
2002-01-07 23:46:58 +00:00
|
|
|
unsigned int getKey(const char *keystr);
|
2002-08-04 15:55:13 +00:00
|
|
|
/**
|
|
|
|
grab a key
|
|
|
|
@param key the key
|
|
|
|
@param mod the modifier
|
|
|
|
*/
|
2001-12-11 20:47:02 +00:00
|
|
|
void grabKey(unsigned int key, unsigned int mod);
|
|
|
|
std::string filename;
|
|
|
|
|
|
|
|
class t_key {
|
|
|
|
public:
|
2001-12-29 10:32:04 +00:00
|
|
|
t_key(unsigned int key, unsigned int mod, KeyAction action_ = Keys::LASTKEYGRAB);
|
2001-12-11 20:47:02 +00:00
|
|
|
t_key(t_key *k);
|
|
|
|
~t_key();
|
|
|
|
|
|
|
|
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) {
|
|
|
|
for (unsigned int i=0; i<keylist.size(); i++) {
|
|
|
|
if (keylist[i]->key == ke->keycode && keylist[i]->mod == ke->state)
|
|
|
|
return keylist[i];
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool operator == (XKeyEvent *ke) {
|
|
|
|
return (mod == ke->state && key == ke->keycode);
|
|
|
|
}
|
|
|
|
|
|
|
|
KeyAction action;
|
|
|
|
unsigned int key;
|
|
|
|
unsigned int mod;
|
|
|
|
std::vector<t_key *> keylist;
|
|
|
|
std::string execcommand;
|
2002-02-20 23:10:48 +00:00
|
|
|
int param; // parameter to comands
|
2001-12-11 20:47:02 +00:00
|
|
|
};
|
2002-07-27 18:03:39 +00:00
|
|
|
/**
|
|
|
|
merge two linked list
|
|
|
|
@return true on success, else false
|
|
|
|
*/
|
2001-12-11 20:47:02 +00:00
|
|
|
bool mergeTree(t_key *newtree, t_key *basetree=0);
|
2002-08-04 15:55:13 +00:00
|
|
|
|
2002-07-27 18:03:39 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
/// debug function
|
2001-12-11 20:47:02 +00:00
|
|
|
void showTree();
|
2002-07-27 18:03:39 +00:00
|
|
|
/// debug function
|
2001-12-11 20:47:02 +00:00
|
|
|
void showKeyTree(t_key *key, unsigned int w=0);
|
2002-07-27 18:03:39 +00:00
|
|
|
#endif //DEBUG
|
|
|
|
|
2001-12-11 20:47:02 +00:00
|
|
|
struct t_actionstr{
|
|
|
|
const char *string;
|
|
|
|
KeyAction action;
|
|
|
|
};
|
2002-07-27 18:03:39 +00:00
|
|
|
|
2001-12-11 20:47:02 +00:00
|
|
|
static t_actionstr m_actionlist[];
|
|
|
|
|
|
|
|
std::vector<t_key *> m_keylist;
|
2002-08-04 15:55:13 +00:00
|
|
|
t_key *m_abortkey; ///< abortkey for keygrabbing chain
|
|
|
|
std::string m_execcmdstring; ///< copy of the execcommandstring
|
|
|
|
int m_param; ///< copy of the param argument
|
|
|
|
Display *m_display; ///< display connection
|
2001-12-11 20:47:02 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // _KEYS_HH_
|