Skip to content

Commit 2ff5011

Browse files
committed
Wayland: switch pointer position handling to doubles
This reduces even further the amount of work we have to do when scaling and potentially improves input accuracy as now the input code is free from any form of rounding.
1 parent b97110c commit 2ff5011

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

platform/linuxbsd/wayland/wayland_thread.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,10 +1412,10 @@ void WaylandThread::_wl_pointer_on_motion(void *data, struct wl_pointer *wl_poin
14121412
PointerData &pd = ss->pointer_data_buffer;
14131413

14141414
// TODO: Scale only when sending the Wayland message.
1415-
pd.position.x = wl_fixed_to_int(surface_x);
1416-
pd.position.y = wl_fixed_to_int(surface_y);
1415+
pd.position.x = wl_fixed_to_double(surface_x);
1416+
pd.position.y = wl_fixed_to_double(surface_y);
14171417

1418-
pd.position = scale_vector2i(pd.position, window_state_get_scale_factor(ws));
1418+
pd.position *= window_state_get_scale_factor(ws);
14191419

14201420
pd.motion_time = time;
14211421
}
@@ -1528,7 +1528,7 @@ void WaylandThread::_wl_pointer_on_frame(void *data, struct wl_pointer *wl_point
15281528
mm->set_position(pd.position);
15291529
mm->set_global_position(pd.position);
15301530

1531-
Vector2i pos_delta = pd.position - old_pd.position;
1531+
Vector2 pos_delta = pd.position - old_pd.position;
15321532

15331533
if (old_pd.relative_motion_time != pd.relative_motion_time) {
15341534
uint32_t time_delta = pd.relative_motion_time - old_pd.relative_motion_time;
@@ -1645,7 +1645,7 @@ void WaylandThread::_wl_pointer_on_frame(void *data, struct wl_pointer *wl_point
16451645

16461646
// We have to set the last position pressed here as we can't take for
16471647
// granted what the individual events might have seen due to them not having
1648-
// a garaunteed order.
1648+
// a guaranteed order.
16491649
if (mb->is_pressed()) {
16501650
pd.last_pressed_position = pd.position;
16511651
}
@@ -2372,9 +2372,9 @@ void WaylandThread::_wp_tablet_tool_on_motion(void *data, struct zwp_tablet_tool
23722372

23732373
double scale_factor = window_state_get_scale_factor(ws);
23742374

2375-
td.position.x = wl_fixed_to_int(x);
2376-
td.position.y = wl_fixed_to_int(y);
2377-
td.position = scale_vector2i(td.position, scale_factor);
2375+
td.position.x = wl_fixed_to_double(x);
2376+
td.position.y = wl_fixed_to_double(y);
2377+
td.position *= scale_factor;
23782378

23792379
td.motion_time = OS::get_singleton()->get_ticks_msec();
23802380
}
@@ -2509,7 +2509,7 @@ void WaylandThread::_wp_tablet_tool_on_frame(void *data, struct zwp_tablet_tool_
25092509
mm->set_relative(td.position - old_td.position);
25102510
mm->set_relative_screen_position(mm->get_relative());
25112511

2512-
Vector2i pos_delta = td.position - old_td.position;
2512+
Vector2 pos_delta = td.position - old_td.position;
25132513
uint32_t time_delta = td.motion_time - old_td.motion_time;
25142514
mm->set_velocity((Vector2)pos_delta / time_delta);
25152515

platform/linuxbsd/wayland/wayland_thread.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ class WaylandThread {
295295
};
296296

297297
struct PointerData {
298-
Point2i position;
298+
Point2 position;
299299
uint32_t motion_time = 0;
300300

301301
// Relative motion has its own optional event and so needs its own time.
@@ -305,7 +305,7 @@ class WaylandThread {
305305
BitField<MouseButtonMask> pressed_button_mask;
306306

307307
MouseButton last_button_pressed = MouseButton::NONE;
308-
Point2i last_pressed_position;
308+
Point2 last_pressed_position;
309309

310310
// This is needed to check for a new double click every time.
311311
bool double_click_begun = false;
@@ -325,14 +325,14 @@ class WaylandThread {
325325
};
326326

327327
struct TabletToolData {
328-
Point2i position;
328+
Point2 position;
329329
Vector2 tilt;
330330
uint32_t pressure = 0;
331331

332332
BitField<MouseButtonMask> pressed_button_mask;
333333

334334
MouseButton last_button_pressed = MouseButton::NONE;
335-
Point2i last_pressed_position;
335+
Point2 last_pressed_position;
336336

337337
bool double_click_begun = false;
338338

0 commit comments

Comments
 (0)