Fix stop script and mouse gesture on button 4/5
This commit is contained in:
parent
169f8dc788
commit
68fce3819f
@ -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,12 +138,21 @@ namespace comfortable_swipe::gesture
|
|||||||
swipe_gesture::update();
|
swipe_gesture::update();
|
||||||
if (this->is_mousedown())
|
if (this->is_mousedown())
|
||||||
{
|
{
|
||||||
|
if (0 <= this->button && this->button <= 3)
|
||||||
|
{
|
||||||
|
// drag mouse with pointer during update
|
||||||
xdo_move_mouse_relative(
|
xdo_move_mouse_relative(
|
||||||
this->xdo,
|
this->xdo,
|
||||||
this->udx,
|
this->udx,
|
||||||
this->udy
|
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;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
@ -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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user