Skip to content

Commit

Permalink
Refactor event handling code
Browse files Browse the repository at this point in the history
  • Loading branch information
thjaeger committed Feb 19, 2013
1 parent 9acb361 commit 3996017
Show file tree
Hide file tree
Showing 8 changed files with 1,288 additions and 1,186 deletions.
2 changes: 2 additions & 0 deletions actiondb.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class Unique;
class Modifiers;
typedef boost::shared_ptr<Modifiers> RModifiers;

bool mods_equal(RModifiers m1, RModifiers m2);

class Action {
friend class boost::serialization::access;
friend std::ostream& operator<<(std::ostream& output, const Action& c);
Expand Down
2 changes: 1 addition & 1 deletion actions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ bool Actions::select_app(const Gtk::TreeModel::Path& path, const Gtk::TreeModel:
}

void Actions::on_add_app() {
std::string name = select_window();
std::string name = grabber->select_window();
if (actions.apps.count(name)) {
apps_model->foreach(sigc::bind(sigc::mem_fun(*this, &Actions::select_app), actions.apps[name]));
return;
Expand Down
34 changes: 20 additions & 14 deletions grabber.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "actiondb.h" // TODO
#include "handler.h"
#include "grabber.h"
#include "main.h"
#include "prefs.h"
Expand All @@ -23,7 +23,6 @@
#include <X11/Xutil.h>
#include <glibmm/i18n.h>

extern Window get_window(Window w, Atom prop);
extern Source<bool> disabled;
extern Source<Window> current_app_window;
extern Source<bool> recording;
Expand Down Expand Up @@ -91,7 +90,7 @@ BiMap<unsigned int, Window> minimized;
unsigned int minimized_n = 0;

void get_frame(Window w) {
Window frame = get_window(w, *_NET_FRAME_WINDOW);
Window frame = xstate->get_window(w, *_NET_FRAME_WINDOW);
if (!frame)
return;
frame_win.add(frame, w);
Expand Down Expand Up @@ -143,7 +142,7 @@ bool Children::handle(XEvent &ev) {
minimized.erase2(ev.xproperty.window);
return true;
}
if (has_atom(ev.xproperty.window, *_NET_WM_STATE, *_NET_WM_STATE_HIDDEN))
if (xstate->has_atom(ev.xproperty.window, *_NET_WM_STATE, *_NET_WM_STATE_HIDDEN))
minimized.add(minimized_n++, ev.xproperty.window);
else
minimized.erase2(ev.xproperty.window);
Expand Down Expand Up @@ -204,7 +203,7 @@ class IdleNotifier : public Base {
void run() { f(); }
public:
IdleNotifier(sigc::slot<void> f_) : f(f_) {}
virtual void notify() { queue(sigc::mem_fun(*this, &IdleNotifier::run)); }
virtual void notify() { xstate->queue(sigc::mem_fun(*this, &IdleNotifier::run)); }
};

void Grabber::unminimize() {
Expand Down Expand Up @@ -262,8 +261,6 @@ bool Grabber::init_xi() {
return false;
}

current_dev = NULL;

for (int i = 0; i < n; i++)
new_device(info + i);
XIFreeDeviceInfo(info);
Expand Down Expand Up @@ -321,9 +318,8 @@ bool Grabber::hierarchy_changed(XIHierarchyEvent *event) {
} else if (info->flags & XISlaveRemoved) {
if (verbosity >= 1)
printf("Device %d removed.\n", info->deviceid);
xstate->remove_device(info->deviceid);
xi_devs.erase(info->deviceid);
if (current_dev && current_dev->dev == info->deviceid)
current_dev = NULL;
changed = true;
} else if (info->flags & (XISlaveAttached | XISlaveDetached)) {
DeviceMap::iterator i = xi_devs.find(info->deviceid);
Expand Down Expand Up @@ -419,8 +415,7 @@ void Grabber::XiDevice::grab_button(ButtonInfo &bi, bool grab) {
XIGrabButton(dpy, dev, bi.button, ROOT, None, GrabModeAsync, GrabModeAsync, False, &device_mask, nmods, modifiers);
else {
XIUngrabButton(dpy, dev, bi.button, ROOT, nmods, modifiers);
if (current_dev && current_dev->dev == dev)
xinput_pressed.clear();
xstate->ungrab(dev);
}
}

Expand All @@ -437,8 +432,7 @@ void Grabber::grab_xi(bool grab) {
void Grabber::XiDevice::grab_device(GrabState grab) {
if (grab == GrabNo) {
XIUngrabDevice(dpy, dev, CurrentTime);
if (current_dev && current_dev->dev == dev)
xinput_pressed.clear();
xstate->ungrab(dev);
return;
}
XIGrabDevice(dpy, dev, ROOT, CurrentTime, None, GrabModeAsync, GrabModeAsync, False,
Expand Down Expand Up @@ -482,6 +476,18 @@ void Grabber::set() {
}
}

void Grabber::queue_suspend() {
xstate->queue(sigc::mem_fun(*this, &Grabber::suspend));
}

void Grabber::queue_resume() {
xstate->queue(sigc::mem_fun(*this, &Grabber::resume));
}

std::string Grabber::select_window() {
return xstate->select_window();
}

bool Grabber::is_grabbed(guint b) {
for (std::vector<ButtonInfo>::iterator i = buttons.begin(); i != buttons.end(); i++)
if (i->button == b)
Expand Down Expand Up @@ -543,7 +549,7 @@ void Grabber::update() {
}

// Fuck Xlib
bool has_wm_state(Window w) {
static bool has_wm_state(Window w) {
static XAtom WM_STATE("WM_STATE");
Atom actual_type_return;
int actual_format_return;
Expand Down
15 changes: 3 additions & 12 deletions grabber.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,6 @@ class Children {
class Grabber;
extern Grabber *grabber;

bool has_wm_state(Window w);
bool has_atom(Window w, Atom prop, Atom value);

void queue(sigc::slot<void> f);
std::string select_window();
void fake_core_button(guint b, bool press);

class Grabber {
friend class Handler;
friend class StrokeHandler;
Expand Down Expand Up @@ -110,8 +103,9 @@ class Grabber {
bool handle(XEvent &ev) { return children.handle(ev); }
Out<std::string> *current_class;

void queue_suspend() { queue(sigc::mem_fun(*this, &Grabber::suspend)); }
void queue_resume() { queue(sigc::mem_fun(*this, &Grabber::resume)); }
void queue_suspend();
void queue_resume();
std::string select_window();

void new_device(XIDeviceInfo *);

Expand All @@ -126,9 +120,6 @@ class Grabber {
void unminimize();
};

extern Grabber::XiDevice *current_dev;
extern std::set<guint> xinput_pressed;

class GrabFailedException : public std::exception {
char *msg;
public:
Expand Down
Loading

0 comments on commit 3996017

Please sign in to comment.