Get rid of hideous get_default_button() hack
+62 −58 · 4 files changed
-
gesture.cc+45 −10 -
gesture.h+2 −36 -
grabber.cc+0 −7 -
main.cc+15 −5
@@ -16,6 +16,13 @@ #include "gesture.h" #include "prefdb.h" +#include <boost/archive/text_oarchive.hpp> +#include <boost/archive/text_iarchive.hpp> +#include <boost/serialization/vector.hpp> +#include <boost/serialization/export.hpp> + +BOOST_CLASS_EXPORT(Stroke) + void update_triple(RTriple e, float x, float y, Time t) { e->x = x; e->y = y; @@ -28,9 +35,42 @@ RTriple create_triple(float x, float y, Time t) { return e; } -Stroke::Stroke(PreStroke &ps, int trigger_, int button_, unsigned int modifiers_, bool timeout_) : button(button_), modifiers(modifiers_), timeout(timeout_) { - trigger = (trigger_ == get_default_button()) ? 0 : trigger_; +template<class Archive> void Stroke::save(Archive & ar, const unsigned int version) const { + std::vector<Point> ps; + for (unsigned int i = 0; i < size(); i++) + ps.push_back(points(i)); + ar & ps; + ar & button; + ar & trigger; + ar & timeout; + ar & modifiers; +} + +template<class Archive> void Stroke::load(Archive & ar, const unsigned int version) { + std::vector<Point> ps; + ar & ps; + if (ps.size()) { + stroke_t *s = stroke_alloc(ps.size()); + for (std::vector<Point>::iterator i = ps.begin(); i != ps.end(); ++i) + stroke_add_point(s, i->x, i->y); + stroke_finish(s); + stroke.reset(s, &stroke_free); + } + if (version == 0) return; + ar & button; + if (version >= 2) + ar & trigger; + if (version < 4 && (!button || trigger == (int)prefs.button.get().button)) + trigger = 0; + if (version < 3) + return; + ar & timeout; + if (version < 5) + return; + ar & modifiers; +} +Stroke::Stroke(PreStroke &ps, int trigger_, int button_, unsigned int modifiers_, bool timeout_) : trigger(trigger_), button(button_), modifiers(modifiers_), timeout(timeout_) { if (ps.valid()) { stroke_t *s = stroke_alloc(ps.size()); for (std::vector<RTriple>::iterator i = ps.begin(); i != ps.end(); ++i) @@ -48,12 +88,8 @@ int Stroke::compare(RStroke a, RStroke b, double &score) { return -1; if (a->button != b->button) return -1; - if (a->trigger != b->trigger) { - if (a->trigger && b->trigger) - return -1; - if (a->trigger + b->trigger != get_default_button()) - return -1; - } + if (a->trigger != b->trigger) + return -1; if (a->modifiers != b->modifiers) return -1; if (!a->stroke || !b->stroke) { @@ -61,8 +97,7 @@ int Stroke::compare(RStroke a, RStroke b, double &score) { score = 1.0; return 1; } - else - return -1; + return -1; } double cost = stroke_compare(a->stroke.get(), b->stroke.get(), NULL, NULL); if (cost >= stroke_infinity) @@ -34,8 +34,6 @@ class PreStroke; typedef boost::shared_ptr<Stroke> RStroke; typedef boost::shared_ptr<PreStroke> RPreStroke; -int get_default_button(); - struct Triple { float x; float y; @@ -85,40 +83,8 @@ private: static Glib::RefPtr<Gdk::Pixbuf> pbEmpty; BOOST_SERIALIZATION_SPLIT_MEMBER() - template<class Archive> void save(Archive & ar, const unsigned int version) const { - std::vector<Point> ps; - for (unsigned int i = 0; i < size(); i++) - ps.push_back(points(i)); - ar & ps; - ar & button; - ar & trigger; - ar & timeout; - ar & modifiers; - } - template<class Archive> void load(Archive & ar, const unsigned int version) { - std::vector<Point> ps; - ar & ps; - if (ps.size()) { - stroke_t *s = stroke_alloc(ps.size()); - for (std::vector<Point>::iterator i = ps.begin(); i != ps.end(); ++i) - stroke_add_point(s, i->x, i->y); - stroke_finish(s); - stroke.reset(s, &stroke_free); - } - if (version == 0) return; - ar & button; - if (version >= 2) - ar & trigger; - if (version < 4 && (!button || trigger == get_default_button())) - trigger = 0; - if (version < 3) - return; - ar & timeout; - if (version < 5) - return; - ar & modifiers; - } - + template<class Archive> void load(Archive & ar, const unsigned int version); + template<class Archive> void save(Archive & ar, const unsigned int version) const; public: int trigger; int button; @@ -510,13 +510,6 @@ guint Grabber::get_default_mods(guint button) { return AnyModifier; } -int get_default_button() { - if (grabber) - return grabber->get_default_button(); - else - return prefs.button.get().button; -} - void Grabber::update() { std::map<std::string, RButtonInfo>::const_iterator i = prefs.exceptions.ref().find(current_class->get()); active = true; @@ -819,6 +819,7 @@ static void get_timeouts(TimeoutType type, int *init, int *final) { class StrokeHandler : public Handler, public sigc::trackable { guint button; + guint trigger; RPreStroke cur; bool is_gesture; bool drawing; @@ -845,7 +846,7 @@ class StrokeHandler : public Handler, public sigc::trackable { c.reset(new PreStroke); if (b && prefs.advanced_ignore.get()) c.reset(new PreStroke); - return Stroke::create(*c, button, b, modifiers, false); + return Stroke::create(*c, trigger, b, modifiers, false); } bool timeout() { @@ -857,7 +858,7 @@ class StrokeHandler : public Handler, public sigc::trackable { c.reset(new PreStroke); RStroke s; if (prefs.timeout_gestures.get() || grabber->is_click_hold(button)) - s = Stroke::create(*c, button, 0, modifiers, true); + s = Stroke::create(*c, trigger, 0, modifiers, true); parent->replace_child(AdvancedHandler::create(s, last, button, 0, cur)); XFlush(dpy); return false; @@ -865,7 +866,7 @@ class StrokeHandler : public Handler, public sigc::trackable { void do_instant() { PreStroke ps; - RStroke s = Stroke::create(ps, button, button, modifiers, false); + RStroke s = Stroke::create(ps, trigger, button, modifiers, false); parent->replace_child(AdvancedHandler::create(s, orig, button, button, cur)); } @@ -966,8 +967,17 @@ protected: parent->replace_child(NULL); } public: - StrokeHandler(guint b, RTriple e) : button(b), is_gesture(false), drawing(false), last(e), orig(e), - init_timeout(prefs.init_timeout.get()), final_timeout(prefs.final_timeout.get()), radius(16) { + StrokeHandler(guint b, RTriple e) : + button(b), + trigger(grabber->get_default_button() == (int)b ? 0 : b), + is_gesture(false), + drawing(false), + last(e), + orig(e), + init_timeout(prefs.init_timeout.get()), + final_timeout(prefs.final_timeout.get()), + radius(16) + { const std::map<std::string, TimeoutType> &dt = prefs.device_timeout.ref(); std::map<std::string, TimeoutType>::const_iterator j = dt.find(current_dev->name); if (j != dt.end())