diff --git a/comfortable_swipe/gesture/mouse_hold_gesture.cpp b/comfortable_swipe/gesture/mouse_hold_gesture.cpp index 4e58580..c6fd11b 100644 --- a/comfortable_swipe/gesture/mouse_hold_gesture.cpp +++ b/comfortable_swipe/gesture/mouse_hold_gesture.cpp @@ -42,6 +42,7 @@ namespace comfortable_swipe::gesture const char* hold4 ): comfortable_swipe::gesture::swipe_gesture(), + button(-1), hold3(hold3), hold4(hold4), flag_mousedown(false) @@ -58,7 +59,7 @@ namespace comfortable_swipe::gesture */ void mouse_hold_gesture::do_mousedown(const char * mouseinput) { - int button = this->parse_mouse_button(mouseinput); + const int button = this->button = this->parse_mouse_button(mouseinput); if (button != -1) { // eg. MOUSE DOWN hold3 mouse1 @@ -77,11 +78,11 @@ namespace comfortable_swipe::gesture */ void mouse_hold_gesture::do_mouseup(const char * mouseinput) { - int button = this->parse_mouse_button(mouseinput); + const int button = this->button = this->parse_mouse_button(mouseinput); if (button != -1) { std::printf("MOUSE UP hold%d %s\n", this->fingers, mouseinput); - if (1 <= button && button <= 3) + if (1 <= button && button <= 5) { // send mouse up on associated button xdo_mouse_up(this->xdo, CURRENTWINDOW, button); @@ -94,7 +95,7 @@ namespace comfortable_swipe::gesture * Utility method to parse mouse number from input. * Returns -1 on failure. */ - int mouse_hold_gesture::parse_mouse_button(const char *input) + int mouse_hold_gesture::parse_mouse_button(const char * input) const { // just move without holding button down if (std::strcmp(input, "move") == 0) @@ -137,11 +138,20 @@ namespace comfortable_swipe::gesture swipe_gesture::update(); if (this->is_mousedown()) { - xdo_move_mouse_relative( - this->xdo, - this->udx, - this->udy - ); + if (0 <= this->button && this->button <= 3) + { + // drag mouse with pointer during update + xdo_move_mouse_relative( + this->xdo, + this->udx, + this->udy + ); + } + else if (4 <= this->button && this->button <= 5) + { + // perform wheel during update + xdo_mouse_down(this->xdo, CURRENTWINDOW, this->button); + } } } @@ -170,7 +180,7 @@ namespace comfortable_swipe::gesture /** * Utility method to check if mouse is current held. */ - bool mouse_hold_gesture::is_mousedown() + bool mouse_hold_gesture::is_mousedown() const { return this->flag_mousedown; } diff --git a/comfortable_swipe/gesture/mouse_hold_gesture.h b/comfortable_swipe/gesture/mouse_hold_gesture.h index 74e7659..971646c 100644 --- a/comfortable_swipe/gesture/mouse_hold_gesture.h +++ b/comfortable_swipe/gesture/mouse_hold_gesture.h @@ -36,6 +36,9 @@ namespace comfortable_swipe::gesture const char* hold4 // 4 finger mouse down ); + // the button being clicked + int button; + virtual ~mouse_hold_gesture(); // override begin and end for mousedown @@ -46,10 +49,10 @@ namespace comfortable_swipe::gesture // provide our own mouse functions virtual void do_mousedown(const char*); virtual void do_mouseup(const char*); - virtual bool is_mousedown(); + virtual bool is_mousedown() const; // utility method to parse mouse input given config characters - virtual int parse_mouse_button(const char*); + virtual int parse_mouse_button(const char*) const; protected: // command holders diff --git a/comfortable_swipe/service/stop.cpp b/comfortable_swipe/service/stop.cpp index c046752..6fb81af 100644 --- a/comfortable_swipe/service/stop.cpp +++ b/comfortable_swipe/service/stop.cpp @@ -37,14 +37,14 @@ namespace comfortable_swipe::service // read all service names from process (pgrep) std::array buffer; - std::unique_ptr pipe(popen("pgrep -f comfortable-swipe", "r"), pclose); + std::unique_ptr pipe(popen("pgrep -f \"$(which comfortable-swipe)\"", "r"), pclose); // make sure pipe exists if (!pipe) throw std::runtime_error("stop command failed"); // buffer what to kill - std::string kill = "kill"; + std::string kill = ""; // read until end of line while (!std::feof(pipe.get())) @@ -61,7 +61,15 @@ namespace comfortable_swipe::service } // run "kill {pid1} {pid2}..." - (void) std::system(kill.data()); + if (kill.length()) + { + std::printf("Stopped%s\n", kill.c_str()); + (void) std::system(("kill" + kill).c_str()); + } + else + { + std::puts("No program to stop"); + } } }