aboutsummaryrefslogtreecommitdiffstats
path: root/sway/input/cursor.c
diff options
context:
space:
mode:
authorLibravatar emersion <contact@emersion.fr>2018-04-24 19:39:29 +0100
committerLibravatar emersion <contact@emersion.fr>2018-04-26 10:53:47 +0100
commitff61df17ffd358b03663a35fe7140e51e1ee98fc (patch)
tree3736887591d8464f577d2ad4a753a404d38d77ae /sway/input/cursor.c
parentMerge pull request #1863 from RyanDwyer/remove-workspace-layout (diff)
downloadsway-ff61df17ffd358b03663a35fe7140e51e1ee98fc.tar.gz
sway-ff61df17ffd358b03663a35fe7140e51e1ee98fc.tar.zst
sway-ff61df17ffd358b03663a35fe7140e51e1ee98fc.zip
Add map_from_region command
Diffstat (limited to 'sway/input/cursor.c')
-rw-r--r--sway/input/cursor.c60
1 files changed, 49 insertions, 11 deletions
diff --git a/sway/input/cursor.c b/sway/input/cursor.c
index 831109dc..944ad8eb 100644
--- a/sway/input/cursor.c
+++ b/sway/input/cursor.c
@@ -261,22 +261,60 @@ static void handle_touch_motion(struct wl_listener *listener, void *data) {
261 wlr_log(L_DEBUG, "TODO: handle touch motion event: %p", event); 261 wlr_log(L_DEBUG, "TODO: handle touch motion event: %p", event);
262} 262}
263 263
264static double apply_mapping_from_coord(double low, double high, double value) {
265 if (value == -1) {
266 return value;
267 }
268
269 value = (value - low) / (high - low);
270 if (value < 0) {
271 return 0;
272 } else if (value > 1) {
273 return 1;
274 } else {
275 return value;
276 }
277}
278
279static void apply_mapping_from_region(struct wlr_input_device *device,
280 struct input_config_mapped_from_region *region, double *x, double *y) {
281 double x1 = region->x1, x2 = region->x2;
282 double y1 = region->y1, y2 = region->y2;
283
284 if (region->mm) {
285 if (device->width_mm == 0 || device->height_mm == 0) {
286 return;
287 }
288 x1 /= device->width_mm;
289 x2 /= device->width_mm;
290 y1 /= device->height_mm;
291 y2 /= device->height_mm;
292 }
293
294 *x = apply_mapping_from_coord(x1, x2, *x);
295 *y = apply_mapping_from_coord(y1, y2, *y);
296}
297
264static void handle_tool_axis(struct wl_listener *listener, void *data) { 298static void handle_tool_axis(struct wl_listener *listener, void *data) {
265 struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_axis); 299 struct sway_cursor *cursor = wl_container_of(listener, cursor, tool_axis);
266 struct wlr_event_tablet_tool_axis *event = data; 300 struct wlr_event_tablet_tool_axis *event = data;
301 struct sway_input_device *input_device = event->device->data;
267 302
268 if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X) && 303 double x = -1, y = -1;
269 (event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) { 304 if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X)) {
270 wlr_cursor_warp_absolute(cursor->cursor, event->device, 305 x = event->x;
271 event->x, event->y); 306 }
272 cursor_send_pointer_motion(cursor, event->time_msec); 307 if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) {
273 } else if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_X)) { 308 y = event->y;
274 wlr_cursor_warp_absolute(cursor->cursor, event->device, event->x, -1);
275 cursor_send_pointer_motion(cursor, event->time_msec);
276 } else if ((event->updated_axes & WLR_TABLET_TOOL_AXIS_Y)) {
277 wlr_cursor_warp_absolute(cursor->cursor, event->device, -1, event->y);
278 cursor_send_pointer_motion(cursor, event->time_msec);
279 } 309 }
310
311 struct input_config *ic = input_device_get_config(input_device);
312 if (ic != NULL && ic->mapped_from_region != NULL) {
313 apply_mapping_from_region(event->device, ic->mapped_from_region, &x, &y);
314 }
315
316 wlr_cursor_warp_absolute(cursor->cursor, event->device, x, y);
317 cursor_send_pointer_motion(cursor, event->time_msec);
280} 318}
281 319
282static void handle_tool_tip(struct wl_listener *listener, void *data) { 320static void handle_tool_tip(struct wl_listener *listener, void *data) {