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
):
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,12 +138,21 @@ namespace comfortable_swipe::gesture
swipe_gesture::update();
if (this->is_mousedown())
{
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;
}

View File

@ -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

View File

@ -37,14 +37,14 @@ namespace comfortable_swipe::service
// read all service names from process (pgrep)
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
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");
}
}
}