diff options
author | Lucas Zampieri <lzampier@redhat.com> | 2022-11-24 17:18:50 -0300 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2022-12-09 11:28:53 +0100 |
commit | efd83cb8b911d88a17263a4ee8e62cf07dbfa4bd (patch) | |
tree | 5ae5c45e912e30a06f836d77b93de6d2a36217cd | |
parent | criteria: be lenient on window_role and instance too (diff) | |
download | sway-efd83cb8b911d88a17263a4ee8e62cf07dbfa4bd.tar.gz sway-efd83cb8b911d88a17263a4ee8e62cf07dbfa4bd.tar.zst sway-efd83cb8b911d88a17263a4ee8e62cf07dbfa4bd.zip |
Add libinput RotationAngle
This patch adds the libinput option RotationAngle to sway.
Signoff-by: Lucas Zampieri <lzampier@redhat.com>
-rw-r--r-- | include/sway/commands.h | 1 | ||||
-rw-r--r-- | include/sway/config.h | 1 | ||||
-rw-r--r-- | sway/commands/input.c | 1 | ||||
-rw-r--r-- | sway/commands/input/rotation_angle.c | 29 | ||||
-rw-r--r-- | sway/config/input.c | 4 | ||||
-rw-r--r-- | sway/input/libinput.c | 15 | ||||
-rw-r--r-- | sway/meson.build | 1 | ||||
-rw-r--r-- | sway/sway-input.5.scd | 4 |
8 files changed, 56 insertions, 0 deletions
diff --git a/include/sway/commands.h b/include/sway/commands.h index ddd2f219..599347ef 100644 --- a/include/sway/commands.h +++ b/include/sway/commands.h | |||
@@ -262,6 +262,7 @@ sway_cmd input_cmd_map_to_region; | |||
262 | sway_cmd input_cmd_middle_emulation; | 262 | sway_cmd input_cmd_middle_emulation; |
263 | sway_cmd input_cmd_natural_scroll; | 263 | sway_cmd input_cmd_natural_scroll; |
264 | sway_cmd input_cmd_pointer_accel; | 264 | sway_cmd input_cmd_pointer_accel; |
265 | sway_cmd input_cmd_rotation_angle; | ||
265 | sway_cmd input_cmd_scroll_factor; | 266 | sway_cmd input_cmd_scroll_factor; |
266 | sway_cmd input_cmd_repeat_delay; | 267 | sway_cmd input_cmd_repeat_delay; |
267 | sway_cmd input_cmd_repeat_rate; | 268 | sway_cmd input_cmd_repeat_rate; |
diff --git a/include/sway/config.h b/include/sway/config.h index ce2b8502..8415627b 100644 --- a/include/sway/config.h +++ b/include/sway/config.h | |||
@@ -155,6 +155,7 @@ struct input_config { | |||
155 | int middle_emulation; | 155 | int middle_emulation; |
156 | int natural_scroll; | 156 | int natural_scroll; |
157 | float pointer_accel; | 157 | float pointer_accel; |
158 | float rotation_angle; | ||
158 | float scroll_factor; | 159 | float scroll_factor; |
159 | int repeat_delay; | 160 | int repeat_delay; |
160 | int repeat_rate; | 161 | int repeat_rate; |
diff --git a/sway/commands/input.c b/sway/commands/input.c index ea531659..740124ea 100644 --- a/sway/commands/input.c +++ b/sway/commands/input.c | |||
@@ -23,6 +23,7 @@ static const struct cmd_handler input_handlers[] = { | |||
23 | { "middle_emulation", input_cmd_middle_emulation }, | 23 | { "middle_emulation", input_cmd_middle_emulation }, |
24 | { "natural_scroll", input_cmd_natural_scroll }, | 24 | { "natural_scroll", input_cmd_natural_scroll }, |
25 | { "pointer_accel", input_cmd_pointer_accel }, | 25 | { "pointer_accel", input_cmd_pointer_accel }, |
26 | { "rotation_angle", input_cmd_rotation_angle }, | ||
26 | { "repeat_delay", input_cmd_repeat_delay }, | 27 | { "repeat_delay", input_cmd_repeat_delay }, |
27 | { "repeat_rate", input_cmd_repeat_rate }, | 28 | { "repeat_rate", input_cmd_repeat_rate }, |
28 | { "scroll_button", input_cmd_scroll_button }, | 29 | { "scroll_button", input_cmd_scroll_button }, |
diff --git a/sway/commands/input/rotation_angle.c b/sway/commands/input/rotation_angle.c new file mode 100644 index 00000000..5e278fff --- /dev/null +++ b/sway/commands/input/rotation_angle.c | |||
@@ -0,0 +1,29 @@ | |||
1 | #include <math.h> | ||
2 | #include <stdlib.h> | ||
3 | #include <string.h> | ||
4 | #include "sway/config.h" | ||
5 | #include "sway/commands.h" | ||
6 | #include "sway/input/input-manager.h" | ||
7 | #include "util.h" | ||
8 | |||
9 | struct cmd_results *input_cmd_rotation_angle(int argc, char **argv) { | ||
10 | struct cmd_results *error = NULL; | ||
11 | if ((error = checkarg(argc, "rotation_angle", EXPECTED_AT_LEAST, 1))) { | ||
12 | return error; | ||
13 | } | ||
14 | struct input_config *ic = config->handler_context.input_config; | ||
15 | if (!ic) { | ||
16 | return cmd_results_new(CMD_FAILURE, "No input device defined."); | ||
17 | } | ||
18 | |||
19 | float rotation_angle = parse_float(argv[0]); | ||
20 | if (isnan(rotation_angle)) { | ||
21 | return cmd_results_new(CMD_INVALID, | ||
22 | "Invalid rotation_angle; expected float."); | ||
23 | } if (rotation_angle < 0 || rotation_angle > 360) { | ||
24 | return cmd_results_new(CMD_INVALID, "Input out of range [0, 360)"); | ||
25 | } | ||
26 | ic->rotation_angle = rotation_angle; | ||
27 | |||
28 | return cmd_results_new(CMD_SUCCESS, NULL); | ||
29 | } | ||
diff --git a/sway/config/input.c b/sway/config/input.c index a98204df..2ee165c9 100644 --- a/sway/config/input.c +++ b/sway/config/input.c | |||
@@ -31,6 +31,7 @@ struct input_config *new_input_config(const char* identifier) { | |||
31 | input->middle_emulation = INT_MIN; | 31 | input->middle_emulation = INT_MIN; |
32 | input->natural_scroll = INT_MIN; | 32 | input->natural_scroll = INT_MIN; |
33 | input->accel_profile = INT_MIN; | 33 | input->accel_profile = INT_MIN; |
34 | input->rotation_angle = FLT_MIN; | ||
34 | input->pointer_accel = FLT_MIN; | 35 | input->pointer_accel = FLT_MIN; |
35 | input->scroll_factor = FLT_MIN; | 36 | input->scroll_factor = FLT_MIN; |
36 | input->scroll_button = INT_MIN; | 37 | input->scroll_button = INT_MIN; |
@@ -74,6 +75,9 @@ void merge_input_config(struct input_config *dst, struct input_config *src) { | |||
74 | if (src->natural_scroll != INT_MIN) { | 75 | if (src->natural_scroll != INT_MIN) { |
75 | dst->natural_scroll = src->natural_scroll; | 76 | dst->natural_scroll = src->natural_scroll; |
76 | } | 77 | } |
78 | if (src->rotation_angle != FLT_MIN) { | ||
79 | dst->rotation_angle = src->rotation_angle; | ||
80 | } | ||
77 | if (src->pointer_accel != FLT_MIN) { | 81 | if (src->pointer_accel != FLT_MIN) { |
78 | dst->pointer_accel = src->pointer_accel; | 82 | dst->pointer_accel = src->pointer_accel; |
79 | } | 83 | } |
diff --git a/sway/input/libinput.c b/sway/input/libinput.c index 53019301..10bd0e35 100644 --- a/sway/input/libinput.c +++ b/sway/input/libinput.c | |||
@@ -79,6 +79,16 @@ static bool set_accel_speed(struct libinput_device *device, double speed) { | |||
79 | return true; | 79 | return true; |
80 | } | 80 | } |
81 | 81 | ||
82 | static bool set_rotation_angle(struct libinput_device *device, double angle) { | ||
83 | if (!libinput_device_config_rotation_is_available(device) || | ||
84 | libinput_device_config_rotation_get_angle(device) == angle) { | ||
85 | return false; | ||
86 | } | ||
87 | sway_log(SWAY_DEBUG, "rotation_set_angle(%f)", angle); | ||
88 | log_status(libinput_device_config_rotation_set_angle(device, angle)); | ||
89 | return true; | ||
90 | } | ||
91 | |||
82 | static bool set_accel_profile(struct libinput_device *device, | 92 | static bool set_accel_profile(struct libinput_device *device, |
83 | enum libinput_config_accel_profile profile) { | 93 | enum libinput_config_accel_profile profile) { |
84 | if (!libinput_device_config_accel_is_available(device) || | 94 | if (!libinput_device_config_accel_is_available(device) || |
@@ -241,6 +251,9 @@ bool sway_input_configure_libinput_device(struct sway_input_device *input_device | |||
241 | if (ic->pointer_accel != FLT_MIN) { | 251 | if (ic->pointer_accel != FLT_MIN) { |
242 | changed |= set_accel_speed(device, ic->pointer_accel); | 252 | changed |= set_accel_speed(device, ic->pointer_accel); |
243 | } | 253 | } |
254 | if (ic->rotation_angle != FLT_MIN) { | ||
255 | changed |= set_rotation_angle(device, ic->rotation_angle); | ||
256 | } | ||
244 | if (ic->accel_profile != INT_MIN) { | 257 | if (ic->accel_profile != INT_MIN) { |
245 | changed |= set_accel_profile(device, ic->accel_profile); | 258 | changed |= set_accel_profile(device, ic->accel_profile); |
246 | } | 259 | } |
@@ -298,6 +311,8 @@ void sway_input_reset_libinput_device(struct sway_input_device *input_device) { | |||
298 | libinput_device_config_tap_get_default_drag_lock_enabled(device)); | 311 | libinput_device_config_tap_get_default_drag_lock_enabled(device)); |
299 | changed |= set_accel_speed(device, | 312 | changed |= set_accel_speed(device, |
300 | libinput_device_config_accel_get_default_speed(device)); | 313 | libinput_device_config_accel_get_default_speed(device)); |
314 | changed |= set_rotation_angle(device, | ||
315 | libinput_device_config_rotation_get_default_angle(device)); | ||
301 | changed |= set_accel_profile(device, | 316 | changed |= set_accel_profile(device, |
302 | libinput_device_config_accel_get_default_profile(device)); | 317 | libinput_device_config_accel_get_default_profile(device)); |
303 | changed |= set_natural_scroll(device, | 318 | changed |= set_natural_scroll(device, |
diff --git a/sway/meson.build b/sway/meson.build index b2412d5e..c6a27434 100644 --- a/sway/meson.build +++ b/sway/meson.build | |||
@@ -167,6 +167,7 @@ sway_sources = files( | |||
167 | 'commands/input/middle_emulation.c', | 167 | 'commands/input/middle_emulation.c', |
168 | 'commands/input/natural_scroll.c', | 168 | 'commands/input/natural_scroll.c', |
169 | 'commands/input/pointer_accel.c', | 169 | 'commands/input/pointer_accel.c', |
170 | 'commands/input/rotation_angle.c', | ||
170 | 'commands/input/repeat_delay.c', | 171 | 'commands/input/repeat_delay.c', |
171 | 'commands/input/repeat_rate.c', | 172 | 'commands/input/repeat_rate.c', |
172 | 'commands/input/scroll_button.c', | 173 | 'commands/input/scroll_button.c', |
diff --git a/sway/sway-input.5.scd b/sway/sway-input.5.scd index e073c45d..91c978d6 100644 --- a/sway/sway-input.5.scd +++ b/sway/sway-input.5.scd | |||
@@ -175,6 +175,10 @@ The following commands may only be used in the configuration file. | |||
175 | *input* <identifier> pointer_accel [<-1|1>] | 175 | *input* <identifier> pointer_accel [<-1|1>] |
176 | Changes the pointer acceleration for the specified input device. | 176 | Changes the pointer acceleration for the specified input device. |
177 | 177 | ||
178 | *input* <identifier> rotation_angle <angle> | ||
179 | Sets the rotation angle of the device to the given clockwise angle in | ||
180 | degrees. The angle must be between 0.0 (inclusive) and 360.0 (exclusive). | ||
181 | |||
178 | *input* <identifier> scroll_button disable|button[1-3,8,9]|<event-code-or-name> | 182 | *input* <identifier> scroll_button disable|button[1-3,8,9]|<event-code-or-name> |
179 | Sets the button used for scroll_method on_button_down. The button can | 183 | Sets the button used for scroll_method on_button_down. The button can |
180 | be given as an event name or code, which can be obtained from *libinput | 184 | be given as an event name or code, which can be obtained from *libinput |