Skip to content

Commit

Permalink
RepeatedAction: Allow to run actions on begin and end
Browse files Browse the repository at this point in the history
Allow to run SEND_KEYS, RUN_COMMAND and MOUSE_CLICK actions on gesture
begin and on gesture end.
  • Loading branch information
JoseExposito committed Dec 1, 2024
1 parent e3b48bf commit 92ef05f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ Options:
| repeat | `true`/`false` | Whether to execute the keyboard shortcut multiple times (default: `false`). This is useful to perform actions like pinch to zoom. |
| modifiers | Keysym | Typical values are: `Shift_L`, `Control_L`, `Alt_L`, `Alt_R`, `Meta_L`, `Super_L`, `Hyper_L`. You can use multiple keysyms: `Control_L+Alt_L`.See "Keysyms" below for more information. |
| keys | Keysym | Shortcut keys. You can use multiple keysyms: `A+B+C`. See "Keysyms" below for more information. |
| on | `begin`/`end` | Only used when `repeat` is `false`. Whether to execute the shortcut at the beginning or at the end of the gesture. |
| on | `begin`/`end`/`begin-and-end` | Only used when `repeat` is `false`. Whether to execute the shortcut at the beginning and/or at the end of the gesture. |
| decreaseKeys | Keysym | Only used when `repeat` is `true`. Keys to press when you change the gesture direction to the opposite. You can use multiple keysyms: `A+B+C`. This is useful to perform actions like pinch to zoom, check `Example 2` below. |
| times | 2...15 | Only used when `repeat` is `true`. Number of times to repeat the action. |
| animate | `true`/`false` | Set it to `true` to display the animation set in `animation`. `false` otherwise. |
Expand Down Expand Up @@ -640,7 +640,7 @@ Options:
| - | - | - |
| repeat | `true`/`false` | `true` if the command should be executed multiple times. `false` otherwise. |
| command | Command | The command to execute. |
| on | `begin`/`end` | Only used when `repeat` is `false`. If the command should be executed on the beginning or on the end of the gesture. |
| on | `begin`/`end`/`begin-and-end` | Only used when `repeat` is `false`. If the command should be executed and/on the beginning or on the end of the gesture. |
| decreaseCommand | Command | Only used when `repeat` is `true`. Command to run when you change the gesture direction to the opposite. Check `Example 2` below. |
| times | 2...15 | Only used when `repeat` is `true`. Number of times to repeat the action. |
| animate | `true`/`false` | Set it to `true` to display the animation set in `animation`. `false` otherwise. |
Expand Down Expand Up @@ -681,7 +681,7 @@ Options:
| Option | Value | Description |
| - | - | - |
| button | `1`/`2`/`3`/`8`/`9` | Left click (1), middle click (2), right click (3), back button (8) or forward button (9) |
| on | `begin`/`end` | If the command should be executed on the beginning or on the end of the gesture. |
| on | `begin`/`end`/`begin-and-end` | If the mouse click should be executed on the beginning and/or on the end of the gesture. |

Example:

Expand Down
6 changes: 6 additions & 0 deletions src/actions/execute-action-on.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ enum class ExecuteActionOn {
NOT_SUPPORTED,
BEGIN,
END,
BEGIN_AND_END,
// Adding a new value? Don't forget to add it in executeActionOnFromStr and
// shouldExecuteAction
};
Expand All @@ -35,6 +36,9 @@ inline ExecuteActionOn executeActionOnFromStr(const std::string &str) {
if (str == "end") {
return ExecuteActionOn::END;
}
if (str == "begin-and-end") {
return ExecuteActionOn::BEGIN_AND_END;
}
return ExecuteActionOn::NOT_SUPPORTED;
}

Expand All @@ -44,6 +48,8 @@ inline bool shouldExecuteAction(ExecuteActionOn phase, ExecuteActionOn config) {
return phase == ExecuteActionOn::BEGIN;
case ExecuteActionOn::END:
return phase == ExecuteActionOn::END;
case ExecuteActionOn::BEGIN_AND_END:
return true;
default:
return false;
}
Expand Down
5 changes: 4 additions & 1 deletion src/actions/repeated-action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ void RepeatedAction::onGestureUpdate(const Gesture &gesture) {
void RepeatedAction::onGestureEnd(const Gesture &gesture) {
if (!this->repeat &&
shouldExecuteAction(ExecuteActionOn::END, this->executeActionOn)) {
if (gesture.percentage() >= this->threshold) {
// Do not take into account the threshold is the action is executed on begin
// and end. Otherwise, we could miss could execute only the on begin part.
if (this->executeActionOn == ExecuteActionOn::BEGIN_AND_END ||
gesture.percentage() >= this->threshold) {
this->executeAction(gesture);
}
}
Expand Down

0 comments on commit 92ef05f

Please sign in to comment.