mirror of
https://gitlab.freedesktop.org/wlroots/wlroots.git
synced 2024-11-22 15:12:26 +00:00
rootston: touch to focus
This commit is contained in:
parent
ac4841ba37
commit
12758a00a2
@ -10,7 +10,7 @@ struct roots_drag_icon {
|
||||
bool mapped;
|
||||
|
||||
bool is_pointer;
|
||||
bool touch_id;
|
||||
int32_t touch_id;
|
||||
|
||||
int32_t sx;
|
||||
int32_t sy;
|
||||
@ -26,8 +26,9 @@ struct roots_seat {
|
||||
struct wl_list link;
|
||||
struct wl_list drag_icons;
|
||||
|
||||
// coordinates of the touch grab if one exists
|
||||
double touch_grab_x, touch_grab_y;
|
||||
// coordinates of the first touch point if it exists
|
||||
int32_t touch_id;
|
||||
double touch_x, touch_y;
|
||||
|
||||
struct roots_view *focus;
|
||||
|
||||
|
@ -487,6 +487,11 @@ void wlr_seat_touch_send_up(struct wlr_seat *seat, uint32_t time,
|
||||
void wlr_seat_touch_send_motion(struct wlr_seat *seat, uint32_t time,
|
||||
int32_t touch_id, double sx, double sy);
|
||||
|
||||
/**
|
||||
* How many touch points are currently down for the seat.
|
||||
*/
|
||||
int wlr_seat_touch_num_points(struct wlr_seat *seat);
|
||||
|
||||
/**
|
||||
* Whether or not the seat has a touch grab other than the default grab.
|
||||
*/
|
||||
|
@ -128,13 +128,14 @@ static void roots_cursor_update_position(struct roots_cursor *cursor, uint32_t t
|
||||
|
||||
static void roots_cursor_press_button(struct roots_cursor *cursor,
|
||||
struct wlr_input_device *device, uint32_t time, uint32_t button,
|
||||
uint32_t state) {
|
||||
uint32_t state, double lx, double ly) {
|
||||
struct roots_seat *seat = cursor->seat;
|
||||
struct roots_desktop *desktop = seat->input->server->desktop;
|
||||
bool is_touch = device->type == WLR_INPUT_DEVICE_TOUCH;
|
||||
|
||||
struct wlr_surface *surface;
|
||||
double sx, sy;
|
||||
struct roots_view *view = view_at(desktop,
|
||||
cursor->cursor->x, cursor->cursor->y, &surface, &sx, &sy);
|
||||
struct roots_view *view = view_at(desktop, lx, ly, &surface, &sx, &sy);
|
||||
|
||||
if (state == WLR_BUTTON_PRESSED && view && roots_seat_has_meta_pressed(seat)) {
|
||||
roots_seat_focus_view(seat, view);
|
||||
@ -165,14 +166,20 @@ static void roots_cursor_press_button(struct roots_cursor *cursor,
|
||||
return;
|
||||
}
|
||||
|
||||
uint32_t serial =
|
||||
wlr_seat_pointer_notify_button(seat->seat, time, button, state);
|
||||
uint32_t serial;
|
||||
if (is_touch) {
|
||||
serial = wl_display_get_serial(desktop->server->wl_display);
|
||||
} else {
|
||||
serial = wlr_seat_pointer_notify_button(seat->seat, time, button, state);
|
||||
}
|
||||
|
||||
int i;
|
||||
switch (state) {
|
||||
case WLR_BUTTON_RELEASED:
|
||||
seat->cursor->mode = ROOTS_CURSOR_PASSTHROUGH;
|
||||
roots_cursor_update_position(cursor, time);
|
||||
if (!is_touch) {
|
||||
roots_cursor_update_position(cursor, time);
|
||||
}
|
||||
break;
|
||||
case WLR_BUTTON_PRESSED:
|
||||
i = cursor->input_events_idx;
|
||||
@ -203,7 +210,7 @@ void roots_cursor_handle_motion_absolute(struct roots_cursor *cursor,
|
||||
void roots_cursor_handle_button(struct roots_cursor *cursor,
|
||||
struct wlr_event_pointer_button *event) {
|
||||
roots_cursor_press_button(cursor, event->device, event->time_msec,
|
||||
event->button, event->state);
|
||||
event->button, event->state, cursor->cursor->x, cursor->cursor->y);
|
||||
}
|
||||
|
||||
void roots_cursor_handle_axis(struct roots_cursor *cursor,
|
||||
@ -231,12 +238,29 @@ void roots_cursor_handle_touch_down(struct roots_cursor *cursor,
|
||||
wlr_seat_touch_notify_down(cursor->seat->seat, surface,
|
||||
event->time_msec, event->slot, sx, sy);
|
||||
}
|
||||
|
||||
if (wlr_seat_touch_num_points(cursor->seat->seat) == 1) {
|
||||
cursor->seat->touch_id = event->slot;
|
||||
cursor->seat->touch_x = lx;
|
||||
cursor->seat->touch_y = ly;
|
||||
roots_cursor_press_button(cursor, event->device, event->time_msec,
|
||||
BTN_LEFT, 1, lx, ly);
|
||||
}
|
||||
}
|
||||
|
||||
void roots_cursor_handle_touch_up(struct roots_cursor *cursor,
|
||||
struct wlr_event_touch_up *event) {
|
||||
struct wlr_touch_point *point = wlr_seat_touch_get_point(cursor->seat->seat, event->slot);
|
||||
if (!point) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (wlr_seat_touch_num_points(cursor->seat->seat) == 1) {
|
||||
roots_cursor_press_button(cursor, event->device, event->time_msec,
|
||||
BTN_LEFT, 0, cursor->seat->touch_x, cursor->seat->touch_y);
|
||||
}
|
||||
|
||||
wlr_seat_touch_notify_up(cursor->seat->seat, event->time_msec, event->slot);
|
||||
//roots_cursor_press_button(cursor, event->device, event->time_msec, BTN_LEFT, 0);
|
||||
}
|
||||
|
||||
void roots_cursor_handle_touch_motion(struct roots_cursor *cursor,
|
||||
@ -271,9 +295,9 @@ void roots_cursor_handle_touch_motion(struct roots_cursor *cursor,
|
||||
event->slot);
|
||||
}
|
||||
|
||||
if (wlr_seat_touch_has_grab(cursor->seat->seat)) {
|
||||
cursor->seat->touch_grab_x = lx;
|
||||
cursor->seat->touch_grab_y = ly;
|
||||
if (event->slot == cursor->seat->touch_id) {
|
||||
cursor->seat->touch_x = lx;
|
||||
cursor->seat->touch_y = ly;
|
||||
}
|
||||
}
|
||||
|
||||
@ -298,7 +322,8 @@ void roots_cursor_handle_tool_axis(struct roots_cursor *cursor,
|
||||
void roots_cursor_handle_tool_tip(struct roots_cursor *cursor,
|
||||
struct wlr_event_tablet_tool_tip *event) {
|
||||
roots_cursor_press_button(cursor, event->device,
|
||||
event->time_msec, BTN_LEFT, event->state);
|
||||
event->time_msec, BTN_LEFT, event->state, cursor->cursor->x,
|
||||
cursor->cursor->y);
|
||||
}
|
||||
|
||||
void roots_cursor_handle_request_set_cursor(struct roots_cursor *cursor,
|
||||
|
@ -209,8 +209,8 @@ static void output_frame_notify(struct wl_listener *listener, void *data) {
|
||||
struct wlr_touch_point *point =
|
||||
wlr_seat_touch_get_point(seat->seat, drag_icon->touch_id);
|
||||
if (point) {
|
||||
icon_x = seat->touch_grab_x + drag_icon->sx;
|
||||
icon_y = seat->touch_grab_y + drag_icon->sy;
|
||||
icon_x = seat->touch_x + drag_icon->sx;
|
||||
icon_y = seat->touch_y + drag_icon->sy;
|
||||
render_surface(icon, desktop, wlr_output, &now, icon_x, icon_y, 0);
|
||||
}
|
||||
}
|
||||
|
@ -1138,6 +1138,10 @@ void wlr_seat_touch_send_motion(struct wlr_seat *seat, uint32_t time, int32_t to
|
||||
wl_touch_send_frame(point->client->touch);
|
||||
}
|
||||
|
||||
int wlr_seat_touch_num_points(struct wlr_seat *seat) {
|
||||
return wl_list_length(&seat->touch_state.touch_points);
|
||||
}
|
||||
|
||||
bool wlr_seat_touch_has_grab(struct wlr_seat *seat) {
|
||||
return seat->touch_state.grab->interface != &default_touch_grab_impl;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user