Added an action class and started the even handler.
This commit is contained in:
parent
0326ac961f
commit
f586e55a8c
6 changed files with 144 additions and 33 deletions
|
@ -4,7 +4,7 @@ CPPFLAGS= @CPPFLAGS@ @DEBUG@
|
||||||
|
|
||||||
EXTRA_PROGRAMS = epist
|
EXTRA_PROGRAMS = epist
|
||||||
|
|
||||||
epist_SOURCES = epist.cc window.cc screen.cc main.cc
|
epist_SOURCES = epist.cc window.cc screen.cc main.cc actions.cc
|
||||||
epist_LDADD = ../../src/XAtom.o ../../src/BaseDisplay.o \
|
epist_LDADD = ../../src/XAtom.o ../../src/BaseDisplay.o \
|
||||||
../../src/Util.o ../../src/i18n.o \
|
../../src/Util.o ../../src/i18n.o \
|
||||||
../../src/GCCache.o ../../src/Color.o ../../src/Texture.o \
|
../../src/GCCache.o ../../src/Color.o ../../src/Texture.o \
|
||||||
|
|
|
@ -1,5 +1,14 @@
|
||||||
// xOr: this is crap.
|
#ifndef __actions_hh
|
||||||
enum ActionType {
|
#define __actions_hh
|
||||||
|
#include <list>
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include <X11/X.h>
|
||||||
|
}
|
||||||
|
class Action {
|
||||||
|
public:
|
||||||
|
// xOr: this is crap.
|
||||||
|
enum ActionType {
|
||||||
noaction = 0,
|
noaction = 0,
|
||||||
execute,
|
execute,
|
||||||
iconify,
|
iconify,
|
||||||
|
@ -11,8 +20,6 @@ enum ActionType {
|
||||||
moveWindowDown,
|
moveWindowDown,
|
||||||
moveWindowLeft,
|
moveWindowLeft,
|
||||||
moveWindowRight,
|
moveWindowRight,
|
||||||
nextWindow,
|
|
||||||
prevWindow,
|
|
||||||
|
|
||||||
nextWindow,
|
nextWindow,
|
||||||
prevWindow,
|
prevWindow,
|
||||||
|
@ -35,7 +42,21 @@ enum ActionType {
|
||||||
numberChain,
|
numberChain,
|
||||||
|
|
||||||
cancel,
|
cancel,
|
||||||
|
};
|
||||||
|
|
||||||
NUM_ACTIONS
|
private:
|
||||||
|
enum Action::ActionType _type;
|
||||||
|
const KeyCode _keycode;
|
||||||
|
const int _modifierMask;
|
||||||
|
|
||||||
|
public:
|
||||||
|
inline enum ActionType type() const { return _type;}
|
||||||
|
inline const KeyCode keycode() const { return _keycode; }
|
||||||
|
inline const int modifierMask() const { return _modifierMask; }
|
||||||
|
|
||||||
|
Action::Action(enum ActionType type, KeyCode keycode, int modifierMask);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef list<Action> ActionList;
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
|
@ -75,6 +75,16 @@ epist::epist(char **argv, char *dpy_name, char *rc_file)
|
||||||
cout << "No compatible window manager found on any screens. Aborting.\n";
|
cout << "No compatible window manager found on any screens. Aborting.\n";
|
||||||
::exit(1);
|
::exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_actions.push_back(Action(Action::nextDesktop,
|
||||||
|
XKeysymToKeycode(getXDisplay(),
|
||||||
|
XStringToKeysym("Tab")),
|
||||||
|
Mod1Mask));
|
||||||
|
_actions.push_back(Action(Action::prevDesktop,
|
||||||
|
XKeysymToKeycode(getXDisplay(),
|
||||||
|
XStringToKeysym("Tab")),
|
||||||
|
ControlMask));
|
||||||
|
activateGrabs();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -82,7 +92,24 @@ epist::~epist() {
|
||||||
delete _xatom;
|
delete _xatom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// XGrabKey(_epist->getXDisplay(), XKeysymToKeycode(_epist->getXDisplay(),
|
||||||
|
// XStringToKeysym("F5")),
|
||||||
|
// Mod1Mask, _root, True, GrabModeAsync, GrabModeAsync);
|
||||||
|
|
||||||
|
void epist::activateGrabs() {
|
||||||
|
|
||||||
|
ScreenList::const_iterator scrit, scrend = _screens.end();
|
||||||
|
|
||||||
|
for (scrit = _screens.begin(); scrit != scrend; ++scrit) {
|
||||||
|
ActionList::const_iterator end = _actions.end();
|
||||||
|
|
||||||
|
for(ActionList::const_iterator ait = _actions.begin();
|
||||||
|
ait != end; ++ait) {
|
||||||
|
XGrabKey(getXDisplay(), ait->keycode(), ait->modifierMask(),
|
||||||
|
(*scrit)->rootWindow(), True, GrabModeAsync, GrabModeAsync);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
bool epist::handleSignal(int sig) {
|
bool epist::handleSignal(int sig) {
|
||||||
switch (sig) {
|
switch (sig) {
|
||||||
case SIGHUP:
|
case SIGHUP:
|
||||||
|
|
|
@ -30,6 +30,8 @@ extern "C" {
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
#include <actions.hh>
|
||||||
|
|
||||||
#include "../../src/BaseDisplay.hh"
|
#include "../../src/BaseDisplay.hh"
|
||||||
|
|
||||||
class XAtom;
|
class XAtom;
|
||||||
|
@ -49,9 +51,12 @@ private:
|
||||||
typedef WindowLookup::value_type WindowLookupPair;
|
typedef WindowLookup::value_type WindowLookupPair;
|
||||||
WindowLookup _windows;
|
WindowLookup _windows;
|
||||||
|
|
||||||
|
ActionList _actions;
|
||||||
|
|
||||||
virtual void process_event(XEvent *e);
|
virtual void process_event(XEvent *e);
|
||||||
virtual bool handleSignal(int sig);
|
virtual bool handleSignal(int sig);
|
||||||
|
|
||||||
|
void activateGrabs();
|
||||||
public:
|
public:
|
||||||
epist(char **argv, char *display_name, char *rc_file);
|
epist(char **argv, char *display_name, char *rc_file);
|
||||||
virtual ~epist();
|
virtual ~epist();
|
||||||
|
@ -61,6 +66,8 @@ public:
|
||||||
void addWindow(XWindow *window);
|
void addWindow(XWindow *window);
|
||||||
void removeWindow(XWindow *window);
|
void removeWindow(XWindow *window);
|
||||||
XWindow *findWindow(Window window) const;
|
XWindow *findWindow(Window window) const;
|
||||||
|
|
||||||
|
list<Action> actions(void) { return _actions; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __epist_hh
|
#endif // __epist_hh
|
||||||
|
|
|
@ -137,10 +137,30 @@ void screen::processEvent(const XEvent &e) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case KeyPress:
|
case KeyPress:
|
||||||
|
handleKeypress(e);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void screen::handleKeypress(const XEvent &e) {
|
||||||
|
list<Action>::const_iterator it = _epist->actions().begin();
|
||||||
|
list<Action>::const_iterator end = _epist->actions().end();
|
||||||
|
for (; it != end; ++it) {
|
||||||
|
if (e.xkey.keycode == it->keycode() &&
|
||||||
|
e.xkey.state == it->modifierMask() )
|
||||||
|
{
|
||||||
|
switch (it->type()) {
|
||||||
|
case Action::nextDesktop:
|
||||||
|
cycleWorkspace(true);
|
||||||
|
break;
|
||||||
|
case Action::prevDesktop:
|
||||||
|
cycleWorkspace(false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// do we want to add this window to our list?
|
// do we want to add this window to our list?
|
||||||
bool screen::doAddWindow(Window window) const {
|
bool screen::doAddWindow(Window window) const {
|
||||||
|
@ -238,3 +258,35 @@ void screen::updateActiveWindow() {
|
||||||
perror("putenv()");
|
perror("putenv()");
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
void screen::cycleWorkspace(const bool forward) {
|
||||||
|
cout << "blef" << endl;
|
||||||
|
|
||||||
|
unsigned long currentDesktop = 0;
|
||||||
|
unsigned long numDesktops = 0;
|
||||||
|
|
||||||
|
if (_xatom->getValue(_root, XAtom::net_current_desktop, XAtom::cardinal,
|
||||||
|
currentDesktop)) {
|
||||||
|
if (forward)
|
||||||
|
++currentDesktop;
|
||||||
|
else
|
||||||
|
--currentDesktop;
|
||||||
|
|
||||||
|
cout << currentDesktop << endl;
|
||||||
|
|
||||||
|
|
||||||
|
_xatom->getValue(_root, XAtom::net_number_of_desktops, XAtom::cardinal,
|
||||||
|
numDesktops);
|
||||||
|
|
||||||
|
if ( ( (signed)currentDesktop) == -1)
|
||||||
|
currentDesktop = numDesktops - 1;
|
||||||
|
else if (currentDesktop >= numDesktops)
|
||||||
|
currentDesktop = 0;
|
||||||
|
|
||||||
|
|
||||||
|
_xatom->sendClientMessage(_root, XAtom::net_current_desktop, _root,
|
||||||
|
currentDesktop);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,6 +62,10 @@ public:
|
||||||
inline bool managed() const { return _managed; }
|
inline bool managed() const { return _managed; }
|
||||||
|
|
||||||
void processEvent(const XEvent &e);
|
void processEvent(const XEvent &e);
|
||||||
|
|
||||||
|
void handleKeypress(const XEvent &e);
|
||||||
|
|
||||||
|
void cycleWorkspace(const bool forward);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // __screen_hh
|
#endif // __screen_hh
|
||||||
|
|
Loading…
Reference in a new issue