mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-13 00:45:58 +01:00
Refactor cursor event passhtrough
This commit is contained in:
parent
212d957c69
commit
662f40b8ae
3 changed files with 80 additions and 60 deletions
|
@ -73,8 +73,12 @@ struct roots_desktop *desktop_create(struct roots_server *server,
|
|||
void desktop_destroy(struct roots_desktop *desktop);
|
||||
struct roots_output *desktop_output_from_wlr_output(
|
||||
struct roots_desktop *desktop, struct wlr_output *output);
|
||||
|
||||
struct roots_view *desktop_view_at(struct roots_desktop *desktop, double lx,
|
||||
double ly, struct wlr_surface **surface, double *sx, double *sy);
|
||||
struct wlr_surface *desktop_surface_at(struct roots_desktop *desktop,
|
||||
double lx, double ly, double *sx, double *sy,
|
||||
struct roots_view **view);
|
||||
|
||||
struct roots_view *view_create(struct roots_desktop *desktop);
|
||||
void view_destroy(struct roots_view *view);
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <dev/evdev/input-event-codes.h>
|
||||
#endif
|
||||
#include "rootston/cursor.h"
|
||||
#include "rootston/desktop.h"
|
||||
#include "rootston/xcursor.h"
|
||||
|
||||
struct roots_cursor *roots_cursor_create(struct roots_seat *seat) {
|
||||
|
@ -98,51 +99,56 @@ static void seat_view_deco_button(struct roots_seat_view *view, double sx,
|
|||
}
|
||||
}
|
||||
|
||||
static void roots_cursor_update_position(struct roots_cursor *cursor,
|
||||
static void roots_passthrough_cursor(struct roots_cursor *cursor,
|
||||
uint32_t time) {
|
||||
struct roots_desktop *desktop = cursor->seat->input->server->desktop;
|
||||
struct roots_seat *seat = cursor->seat;
|
||||
struct roots_view *view;
|
||||
struct wlr_surface *surface = NULL;
|
||||
double sx, sy;
|
||||
switch (cursor->mode) {
|
||||
case ROOTS_CURSOR_PASSTHROUGH:
|
||||
view = desktop_view_at(desktop, cursor->cursor->x, cursor->cursor->y,
|
||||
&surface, &sx, &sy);
|
||||
|
||||
struct roots_seat *seat = cursor->seat;
|
||||
struct roots_desktop *desktop = seat->input->server->desktop;
|
||||
struct wlr_surface *surface = desktop_surface_at(desktop,
|
||||
cursor->cursor->x, cursor->cursor->y, &sx, &sy, &view);
|
||||
|
||||
if (!surface && cursor->cursor_client) {
|
||||
wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager,
|
||||
cursor->default_xcursor, cursor->cursor);
|
||||
cursor->cursor_client = NULL;
|
||||
}
|
||||
|
||||
if (view) {
|
||||
struct roots_seat_view *seat_view =
|
||||
roots_seat_view_from_view(seat, view);
|
||||
if (cursor->pointer_view && (surface || seat_view != cursor->pointer_view)) {
|
||||
if (cursor->pointer_view && (surface ||
|
||||
seat_view != cursor->pointer_view)) {
|
||||
seat_view_deco_leave(cursor->pointer_view);
|
||||
cursor->pointer_view = NULL;
|
||||
}
|
||||
bool set_compositor_cursor = !view && !surface && cursor->cursor_client;
|
||||
if (view && surface) {
|
||||
struct wl_client *view_client =
|
||||
wl_resource_get_client(view->wlr_surface->resource);
|
||||
set_compositor_cursor = view_client != cursor->cursor_client;
|
||||
}
|
||||
if (set_compositor_cursor) {
|
||||
wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager,
|
||||
cursor->default_xcursor, cursor->cursor);
|
||||
cursor->cursor_client = NULL;
|
||||
}
|
||||
if (view && !surface) {
|
||||
if (seat_view) {
|
||||
cursor->pointer_view = seat_view;
|
||||
seat_view_deco_motion(seat_view, sx, sy);
|
||||
}
|
||||
} if (view && surface) {
|
||||
// motion over a view surface
|
||||
wlr_seat_pointer_notify_enter(seat->seat, surface, sx, sy);
|
||||
wlr_seat_pointer_notify_motion(seat->seat, time, sx, sy);
|
||||
} else {
|
||||
wlr_seat_pointer_clear_focus(seat->seat);
|
||||
if (!surface) {
|
||||
cursor->pointer_view = seat_view;
|
||||
seat_view_deco_motion(seat_view, sx, sy);
|
||||
}
|
||||
}
|
||||
|
||||
struct roots_drag_icon *drag_icon;
|
||||
wl_list_for_each(drag_icon, &seat->drag_icons, link) {
|
||||
roots_drag_icon_update_position(drag_icon);
|
||||
}
|
||||
if (surface) {
|
||||
wlr_seat_pointer_notify_enter(seat->seat, surface, sx, sy);
|
||||
wlr_seat_pointer_notify_motion(seat->seat, time, sx, sy);
|
||||
} else {
|
||||
wlr_seat_pointer_clear_focus(seat->seat);
|
||||
}
|
||||
|
||||
struct roots_drag_icon *drag_icon;
|
||||
wl_list_for_each(drag_icon, &seat->drag_icons, link) {
|
||||
roots_drag_icon_update_position(drag_icon);
|
||||
}
|
||||
}
|
||||
|
||||
static void roots_cursor_update_position(
|
||||
struct roots_cursor *cursor, uint32_t time) {
|
||||
struct roots_seat *seat = cursor->seat;
|
||||
struct roots_view *view;
|
||||
switch (cursor->mode) {
|
||||
case ROOTS_CURSOR_PASSTHROUGH:
|
||||
roots_passthrough_cursor(cursor, time);
|
||||
break;
|
||||
case ROOTS_CURSOR_MOVE:
|
||||
view = roots_seat_get_focus(seat);
|
||||
|
@ -180,15 +186,9 @@ static void roots_cursor_update_position(struct roots_cursor *cursor,
|
|||
} else if (cursor->resize_edges & WLR_EDGE_RIGHT) {
|
||||
width += dx;
|
||||
}
|
||||
|
||||
if (width < 1) {
|
||||
width = 1;
|
||||
}
|
||||
if (height < 1) {
|
||||
height = 1;
|
||||
}
|
||||
|
||||
view_move_resize(view, x, y, width, height);
|
||||
view_move_resize(view, x, y,
|
||||
width < 1 ? 1 : width,
|
||||
height < 1 ? 1 : height);
|
||||
}
|
||||
break;
|
||||
case ROOTS_CURSOR_ROTATE:
|
||||
|
@ -214,15 +214,15 @@ static void roots_cursor_press_button(struct roots_cursor *cursor,
|
|||
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 = NULL;
|
||||
double sx, sy;
|
||||
struct roots_view *view =
|
||||
desktop_view_at(desktop, lx, ly, &surface, &sx, &sy);
|
||||
struct roots_view *view;
|
||||
struct wlr_surface *surface = desktop_surface_at(desktop,
|
||||
lx, ly, &sx, &sy, &view);
|
||||
|
||||
if (state == WLR_BUTTON_PRESSED &&
|
||||
view &&
|
||||
if (state == WLR_BUTTON_PRESSED && view &&
|
||||
roots_seat_has_meta_pressed(seat)) {
|
||||
roots_seat_set_focus(seat, view);
|
||||
|
||||
|
@ -250,11 +250,9 @@ static void roots_cursor_press_button(struct roots_cursor *cursor,
|
|||
break;
|
||||
}
|
||||
} else {
|
||||
|
||||
if (view && !surface) {
|
||||
if (cursor->pointer_view) {
|
||||
seat_view_deco_button(cursor->pointer_view, sx, sy, button, state);
|
||||
}
|
||||
if (view && !surface && cursor->pointer_view) {
|
||||
seat_view_deco_button(cursor->pointer_view,
|
||||
sx, sy, button, state);
|
||||
}
|
||||
|
||||
if (state == WLR_BUTTON_RELEASED &&
|
||||
|
@ -308,7 +306,6 @@ void roots_cursor_handle_axis(struct roots_cursor *cursor,
|
|||
void roots_cursor_handle_touch_down(struct roots_cursor *cursor,
|
||||
struct wlr_event_touch_down *event) {
|
||||
struct roots_desktop *desktop = cursor->seat->input->server->desktop;
|
||||
struct wlr_surface *surface = NULL;
|
||||
double lx, ly;
|
||||
bool result = wlr_cursor_absolute_to_layout_coords(cursor->cursor,
|
||||
event->device, event->x, event->y, &lx, &ly);
|
||||
|
@ -316,7 +313,8 @@ void roots_cursor_handle_touch_down(struct roots_cursor *cursor,
|
|||
return;
|
||||
}
|
||||
double sx, sy;
|
||||
desktop_view_at(desktop, lx, ly, &surface, &sx, &sy);
|
||||
struct wlr_surface *surface = desktop_surface_at(
|
||||
desktop, lx, ly, &sx, &sy, NULL);
|
||||
|
||||
uint32_t serial = 0;
|
||||
if (surface) {
|
||||
|
@ -359,17 +357,16 @@ void roots_cursor_handle_touch_motion(struct roots_cursor *cursor,
|
|||
return;
|
||||
}
|
||||
|
||||
struct wlr_surface *surface = NULL;
|
||||
double lx, ly;
|
||||
bool result =
|
||||
wlr_cursor_absolute_to_layout_coords(cursor->cursor,
|
||||
bool result = wlr_cursor_absolute_to_layout_coords(cursor->cursor,
|
||||
event->device, event->x, event->y, &lx, &ly);
|
||||
if (!result) {
|
||||
return;
|
||||
}
|
||||
|
||||
double sx, sy;
|
||||
desktop_view_at(desktop, lx, ly, &surface, &sx, &sy);
|
||||
struct wlr_surface *surface = desktop_surface_at(
|
||||
desktop, lx, ly, &sx, &sy, NULL);
|
||||
|
||||
if (surface) {
|
||||
wlr_seat_touch_point_focus(cursor->seat->seat, surface,
|
||||
|
|
|
@ -657,6 +657,25 @@ struct roots_view *desktop_view_at(struct roots_desktop *desktop, double lx,
|
|||
return NULL;
|
||||
}
|
||||
|
||||
struct wlr_surface *desktop_surface_at(struct roots_desktop *desktop,
|
||||
double lx, double ly, double *sx, double *sy,
|
||||
struct roots_view **view) {
|
||||
//struct wlr_output *wlr_output =
|
||||
// wlr_output_layout_output_at(desktop->layout, lx, ly);
|
||||
// TODO: Iterate over layers
|
||||
*view = NULL;
|
||||
struct roots_view *_view;
|
||||
struct wlr_surface *surface = NULL;
|
||||
if ((_view = desktop_view_at(desktop, lx, ly, &surface, sx, sy))) {
|
||||
if (view) {
|
||||
*view = _view;
|
||||
}
|
||||
return surface;
|
||||
}
|
||||
// TODO: Iterate over layers
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void handle_layout_change(struct wl_listener *listener, void *data) {
|
||||
struct roots_desktop *desktop =
|
||||
wl_container_of(listener, desktop, layout_change);
|
||||
|
|
Loading…
Reference in a new issue