Fix stop script and mouse gesture on button 4/5

This commit is contained in:
Rico Tiongson 2020-04-18 02:38:13 +08:00
parent 169f8dc788
commit 68fce3819f
3 changed files with 36 additions and 15 deletions

View File

@ -42,6 +42,7 @@ namespace comfortable_swipe::gesture
const char* hold4 const char* hold4
): ):
comfortable_swipe::gesture::swipe_gesture(), comfortable_swipe::gesture::swipe_gesture(),
button(-1),
hold3(hold3), hold3(hold3),
hold4(hold4), hold4(hold4),
flag_mousedown(false) flag_mousedown(false)
@ -58,7 +59,7 @@ namespace comfortable_swipe::gesture
*/ */
void mouse_hold_gesture::do_mousedown(const char * mouseinput) 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) if (button != -1)
{ {
// eg. MOUSE DOWN hold3 mouse1 // eg. MOUSE DOWN hold3 mouse1
@ -77,11 +78,11 @@ namespace comfortable_swipe::gesture
*/ */
void mouse_hold_gesture::do_mouseup(const char * mouseinput) 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) if (button != -1)
{ {
std::printf("MOUSE UP hold%d %s\n", this->fingers, mouseinput); 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 // send mouse up on associated button
xdo_mouse_up(this->xdo, CURRENTWINDOW, button); xdo_mouse_up(this->xdo, CURRENTWINDOW, button);
@ -94,7 +95,7 @@ namespace comfortable_swipe::gesture
* Utility method to parse mouse number from input. * Utility method to parse mouse number from input.
* Returns -1 on failure. * 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 // just move without holding button down
if (std::strcmp(input, "move") == 0) if (std::strcmp(input, "move") == 0)
@ -137,11 +138,20 @@ namespace comfortable_swipe::gesture
swipe_gesture::update(); swipe_gesture::update();
if (this->is_mousedown()) if (this->is_mousedown())
{ {
xdo_move_mouse_relative( if (0 <= this->button && this->button <= 3)
this->xdo, {
this->udx, // drag mouse with pointer during update
this->udy 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. * 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; return this->flag_mousedown;
} }

View File

@ -36,6 +36,9 @@ namespace comfortable_swipe::gesture
const char* hold4 // 4 finger mouse down const char* hold4 // 4 finger mouse down
); );
// the button being clicked
int button;
virtual ~mouse_hold_gesture(); virtual ~mouse_hold_gesture();
// override begin and end for mousedown // override begin and end for mousedown
@ -46,10 +49,10 @@ namespace comfortable_swipe::gesture
// provide our own mouse functions // provide our own mouse functions
virtual void do_mousedown(const char*); virtual void do_mousedown(const char*);
virtual void do_mouseup(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 // 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: protected:
// command holders // command holders

View File

@ -37,14 +37,14 @@ namespace comfortable_swipe::service
// read all service names from process (pgrep) // read all service names from process (pgrep)
std::array<char, 128> buffer; std::array<char, 128> buffer;
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen("pgrep -f comfortable-swipe", "r"), pclose); std::unique_ptr<FILE, decltype(&pclose)> pipe(popen("pgrep -f \"$(which comfortable-swipe)\"", "r"), pclose);
// make sure pipe exists // make sure pipe exists
if (!pipe) if (!pipe)
throw std::runtime_error("stop command failed"); throw std::runtime_error("stop command failed");
// buffer what to kill // buffer what to kill
std::string kill = "kill"; std::string kill = "";
// read until end of line // read until end of line
while (!std::feof(pipe.get())) while (!std::feof(pipe.get()))
@ -61,7 +61,15 @@ namespace comfortable_swipe::service
} }
// run "kill {pid1} {pid2}..." // 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");
}
} }
} }