Skip to content

Commit efd83cb

Browse files
zampierilucasemersion
authored andcommitted
Add libinput RotationAngle
This patch adds the libinput option RotationAngle to sway. Signoff-by: Lucas Zampieri <lzampier@redhat.com>
1 parent 991d759 commit efd83cb

File tree

8 files changed

+56
-0
lines changed

8 files changed

+56
-0
lines changed

include/sway/commands.h

+1
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ sway_cmd input_cmd_map_to_region;
262262
sway_cmd input_cmd_middle_emulation;
263263
sway_cmd input_cmd_natural_scroll;
264264
sway_cmd input_cmd_pointer_accel;
265+
sway_cmd input_cmd_rotation_angle;
265266
sway_cmd input_cmd_scroll_factor;
266267
sway_cmd input_cmd_repeat_delay;
267268
sway_cmd input_cmd_repeat_rate;

include/sway/config.h

+1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ struct input_config {
155155
int middle_emulation;
156156
int natural_scroll;
157157
float pointer_accel;
158+
float rotation_angle;
158159
float scroll_factor;
159160
int repeat_delay;
160161
int repeat_rate;

sway/commands/input.c

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ static const struct cmd_handler input_handlers[] = {
2323
{ "middle_emulation", input_cmd_middle_emulation },
2424
{ "natural_scroll", input_cmd_natural_scroll },
2525
{ "pointer_accel", input_cmd_pointer_accel },
26+
{ "rotation_angle", input_cmd_rotation_angle },
2627
{ "repeat_delay", input_cmd_repeat_delay },
2728
{ "repeat_rate", input_cmd_repeat_rate },
2829
{ "scroll_button", input_cmd_scroll_button },

sway/commands/input/rotation_angle.c

+29
Original file line numberDiff line numberDiff line change
@@ -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+
}

sway/config/input.c

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ struct input_config *new_input_config(const char* identifier) {
3131
input->middle_emulation = INT_MIN;
3232
input->natural_scroll = INT_MIN;
3333
input->accel_profile = INT_MIN;
34+
input->rotation_angle = FLT_MIN;
3435
input->pointer_accel = FLT_MIN;
3536
input->scroll_factor = FLT_MIN;
3637
input->scroll_button = INT_MIN;
@@ -74,6 +75,9 @@ void merge_input_config(struct input_config *dst, struct input_config *src) {
7475
if (src->natural_scroll != INT_MIN) {
7576
dst->natural_scroll = src->natural_scroll;
7677
}
78+
if (src->rotation_angle != FLT_MIN) {
79+
dst->rotation_angle = src->rotation_angle;
80+
}
7781
if (src->pointer_accel != FLT_MIN) {
7882
dst->pointer_accel = src->pointer_accel;
7983
}

sway/input/libinput.c

+15
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ static bool set_accel_speed(struct libinput_device *device, double speed) {
7979
return true;
8080
}
8181

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+
8292
static bool set_accel_profile(struct libinput_device *device,
8393
enum libinput_config_accel_profile profile) {
8494
if (!libinput_device_config_accel_is_available(device) ||
@@ -241,6 +251,9 @@ bool sway_input_configure_libinput_device(struct sway_input_device *input_device
241251
if (ic->pointer_accel != FLT_MIN) {
242252
changed |= set_accel_speed(device, ic->pointer_accel);
243253
}
254+
if (ic->rotation_angle != FLT_MIN) {
255+
changed |= set_rotation_angle(device, ic->rotation_angle);
256+
}
244257
if (ic->accel_profile != INT_MIN) {
245258
changed |= set_accel_profile(device, ic->accel_profile);
246259
}
@@ -298,6 +311,8 @@ void sway_input_reset_libinput_device(struct sway_input_device *input_device) {
298311
libinput_device_config_tap_get_default_drag_lock_enabled(device));
299312
changed |= set_accel_speed(device,
300313
libinput_device_config_accel_get_default_speed(device));
314+
changed |= set_rotation_angle(device,
315+
libinput_device_config_rotation_get_default_angle(device));
301316
changed |= set_accel_profile(device,
302317
libinput_device_config_accel_get_default_profile(device));
303318
changed |= set_natural_scroll(device,

sway/meson.build

+1
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ sway_sources = files(
167167
'commands/input/middle_emulation.c',
168168
'commands/input/natural_scroll.c',
169169
'commands/input/pointer_accel.c',
170+
'commands/input/rotation_angle.c',
170171
'commands/input/repeat_delay.c',
171172
'commands/input/repeat_rate.c',
172173
'commands/input/scroll_button.c',

sway/sway-input.5.scd

+4
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ The following commands may only be used in the configuration file.
175175
*input* <identifier> pointer_accel [<-1|1>]
176176
Changes the pointer acceleration for the specified input device.
177177

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+
178182
*input* <identifier> scroll_button disable|button[1-3,8,9]|<event-code-or-name>
179183
Sets the button used for scroll_method on_button_down. The button can
180184
be given as an event name or code, which can be obtained from *libinput

0 commit comments

Comments
 (0)