diff --git a/lib/comfortable_swipe b/lib/comfortable_swipe
index 7c917ca..a7ebc06 100644
--- a/lib/comfortable_swipe
+++ b/lib/comfortable_swipe
@@ -29,6 +29,7 @@ along with this program. If not, see .
#include "gesture/swipe_gesture.cpp"
#include "gesture/swipe_gesture.regex.cpp"
#include "gesture/keyboard_swipe_gesture.cpp"
+#include "gesture/mouse_swipe_gesture.cpp"
#include "service/autostart.cpp"
#include "service/buffer.cpp"
#include "service/config.cpp"
diff --git a/lib/gesture/keyboard_swipe_gesture.cpp b/lib/gesture/keyboard_swipe_gesture.cpp
index 9d4489a..7f2dc30 100644
--- a/lib/gesture/keyboard_swipe_gesture.cpp
+++ b/lib/gesture/keyboard_swipe_gesture.cpp
@@ -20,8 +20,6 @@ along with this program. If not, see .
*/
#include // std::cout, std::endl
-#include // std::stoi, std::stof
-#include // std::regex, std::regex_match, std::cmatch
#include "keyboard_swipe_gesture.h"
extern "C"
diff --git a/lib/gesture/mouse_swipe_gesture.cpp b/lib/gesture/mouse_swipe_gesture.cpp
new file mode 100644
index 0000000..d9553de
--- /dev/null
+++ b/lib/gesture/mouse_swipe_gesture.cpp
@@ -0,0 +1,159 @@
+#ifndef __COMFORTABLE_SWIPE__gesture_mouse_swipe_gesture__
+#define __COMFORTABLE_SWIPE__gesture_mouse_swipe_gesture__
+
+/*
+Comfortable Swipe
+by Rico Tiongson
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see .
+*/
+
+#include // std::cout, std::endl
+#include // std::sscanf
+#include "mouse_swipe_gesture.h"
+
+extern "C"
+{
+ #include // xdo, xdo_new, xdo_free,
+ // xdo_get_mouse_location
+ // CURRENT_WINDOW
+}
+
+namespace comfortable_swipe::gesture
+{
+ /**
+ * Constructs a new mouse gesture, given "hold3" and "hold4" configurations.
+ */
+ mouse_swipe_gesture::mouse_swipe_gesture
+ (
+ const char* hold3,
+ const char* hold4
+ ):
+ comfortable_swipe::gesture::swipe_gesture(),
+ hold3(hold3),
+ hold4(hold4),
+ flag_mousedown(false)
+ { }
+
+ /**
+ * Destructs this mouse swipe gesture.
+ */
+ mouse_swipe_gesture::~mouse_swipe_gesture()
+ { }
+
+ /**
+ * Run mousedown command on hold input.
+ */
+ void mouse_swipe_gesture::do_mousedown(const char * mouseinput)
+ {
+ int mouse = this->parse_mouse_input(mouseinput);
+ if (mouse != -1)
+ {
+ std::cout << "MOUSE DOWN " << mouse << std::endl;
+ this->flag_mousedown = true;
+ }
+ }
+
+ /**
+ *
+ */
+ void mouse_swipe_gesture::do_mouseup(const char * mouseinput)
+ {
+ int mouse = this->parse_mouse_input(mouseinput);
+ if (mouse != -1)
+ {
+ std::cout << "MOUSE UP " << mouse << std::endl;
+ this->flag_mousedown = false;
+ }
+ }
+
+ /**
+ * Utility method to parse mouse number from input.
+ * Returns -1 on failure.
+ */
+ int mouse_swipe_gesture::parse_mouse_input(const char *input)
+ {
+ // parse mouse number
+ int mouseno;
+ if (std::sscanf(input, "mouse%d", &mouseno) == 1)
+ {
+ return mouseno;
+ }
+ return -1;
+ }
+
+ /**
+ * Hook on begin of mouse swipe gesture.
+ */
+ void mouse_swipe_gesture::begin()
+ {
+ // call superclass method
+ swipe_gesture::begin();
+ // dispatch mouse down event
+ if (this->fingers == 3)
+ {
+ this->do_mousedown(this->hold3);
+ }
+ else if (this->fingers == 4)
+ {
+ this->do_mousedown(this->hold4);
+ }
+ }
+
+ /**
+ * Hook on end of mouse swipe gesture.
+ */
+ void mouse_swipe_gesture::update()
+ {
+ // call superclass method
+ swipe_gesture::update();
+ if (this->is_mousedown())
+ {
+ // TODO: drag mouse while it's updating
+ std::cout << this->dx << " " << this->dy << std::endl;
+ }
+
+ }
+
+ /**
+ * Hook on end of swipe gesture.
+ */
+ void mouse_swipe_gesture::end()
+ {
+ if (this->is_mousedown())
+ {
+ if (this->fingers == 3)
+ {
+ this->do_mouseup(this->hold3);
+ }
+ else if (this->fingers == 4)
+ {
+ this->do_mouseup(this->hold4);
+ }
+ }
+
+ // call superclass method
+ swipe_gesture::end();
+ }
+
+ /**
+ * Utility method to check if mouse is current held.
+ */
+ bool mouse_swipe_gesture::is_mousedown()
+ {
+ return this->flag_mousedown;
+ }
+}
+
+#endif /* __COMFORTABLE_SWIPE__gesture_mouse_swipe_gesture__ */
diff --git a/lib/gesture/mouse_swipe_gesture.h b/lib/gesture/mouse_swipe_gesture.h
new file mode 100644
index 0000000..fa1b0a8
--- /dev/null
+++ b/lib/gesture/mouse_swipe_gesture.h
@@ -0,0 +1,69 @@
+#ifndef __COMFORTABLE_SWIPE__gesture_mouse_swipe_gesture_h__
+#define __COMFORTABLE_SWIPE__gesture_mouse_swipe_gesture_h__
+
+/*
+Comfortable Swipe
+by Rico Tiongson
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see .
+*/
+
+#include "swipe_gesture.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+namespace comfortable_swipe::gesture
+{
+ class mouse_swipe_gesture : public swipe_gesture
+ {
+ public:
+ // constructor
+ mouse_swipe_gesture(
+ const char* hold3, // 3 finger mouse down
+ const char* hold4 // 4 finger mouse down
+ );
+
+ virtual ~mouse_swipe_gesture();
+
+ // override begin and end for mousedown
+ virtual void begin() override;
+ virtual void update() override;
+ virtual void end() override;
+
+ // provide our own mouse functions
+ virtual void do_mousedown(const char*);
+ virtual void do_mouseup(const char*);
+ virtual bool is_mousedown();
+
+ protected:
+ // command holders
+ const char * hold3;
+ const char * hold4;
+
+ // flag we can use to check if mouse is down
+ bool flag_mousedown;
+
+ private:
+ // utility method to parse mouse input given config characters
+ int parse_mouse_input(const char*);
+ };
+}
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __COMFORTABLE_SWIPE__gesture_mouse_swipe_gesture_h__ */
diff --git a/lib/service/buffer.cpp b/lib/service/buffer.cpp
index 69dbbb4..ed76b1d 100644
--- a/lib/service/buffer.cpp
+++ b/lib/service/buffer.cpp
@@ -40,7 +40,7 @@ namespace comfortable_swipe::service
comfortable_swipe::util::conf_filename()
);
- // initialize swipe gesture handler
+ // initialize keyboard swipe gesture handler
comfortable_swipe::gesture::keyboard_swipe_gesture keyboard_swipe
(
config.count("threshold") ? std::stof(config["threshold"]) : 0.0,
@@ -54,14 +54,28 @@ namespace comfortable_swipe::service
config["down4"].c_str()
);
+ // initialize mouse swipe gesture handler
+ comfortable_swipe::gesture::mouse_swipe_gesture mouse_hold
+ (
+ "",
+ "mouse1"
+ );
+
// prepare data containers
std::array line;
// start reading lines from input one by one
while (fgets_unlocked(line.data(), line.size(), stdin) != NULL)
{
- // attempt to parse swipe gestures
- keyboard_swipe.parse_line(line.data());
+ // prioritize mouse hold gesture first
+ mouse_hold.parse_line(line.data());
+
+ // if mouse hold fails, try keyboard hold
+ if (!mouse_hold.is_mousedown())
+ {
+ // attempt to parse keyboard gestures
+ keyboard_swipe.parse_line(line.data());
+ }
}
}
}