aboutsummaryrefslogtreecommitdiff
path: root/rootston
diff options
context:
space:
mode:
Diffstat (limited to 'rootston')
-rw-r--r--rootston/cursor.c94
-rw-r--r--rootston/desktop.c8
-rw-r--r--rootston/seat.c44
3 files changed, 126 insertions, 20 deletions
diff --git a/rootston/cursor.c b/rootston/cursor.c
index 8bd514cc..8a34cd13 100644
--- a/rootston/cursor.c
+++ b/rootston/cursor.c
@@ -30,19 +30,81 @@ void roots_cursor_destroy(struct roots_cursor *cursor) {
// TODO
}
+static void seat_view_deco_motion(struct roots_seat_view *view, double deco_vx, double deco_vy) {
+ struct roots_cursor *cursor = view->seat->cursor;
+
+ double vx = deco_vx;
+ double vy = deco_vy;
+ if (view->has_button_grab) {
+ vx = view->grab_vx;
+ vy = view->grab_vy;
+ }
+
+ bool is_titlebar = vy < 0 && -vy < view->view->titlebar_height;
+ uint32_t edges = 0;
+ if (vx < 0) {
+ edges |= WLR_EDGE_LEFT;
+ } else if (vx > view->view->wlr_surface->current->width) {
+ edges |= WLR_EDGE_RIGHT;
+ } else if (vy > view->view->wlr_surface->current->height) {
+ edges |= WLR_EDGE_BOTTOM;
+ } else if (-vy > view->view->titlebar_height) {
+ edges |= WLR_EDGE_TOP;
+ }
+
+ if (view->has_button_grab) {
+ if (is_titlebar) {
+ roots_seat_begin_move(view->seat, view->view);
+ } else if (edges) {
+ roots_seat_begin_resize(view->seat, view->view, edges);
+ }
+ view->has_button_grab = false;
+ } else {
+ if (is_titlebar) {
+ wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager,
+ cursor->default_xcursor, cursor->cursor);
+ } else if (edges) {
+ const char *resize_name = wlr_xcursor_get_resize_name(edges);
+ wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager,
+ resize_name, cursor->cursor);
+ }
+ }
+}
+
+static void seat_view_deco_leave(struct roots_seat_view *view) {
+ view->has_button_grab = false;
+}
+
+static void seat_view_deco_button(struct roots_seat_view *view, double vx,
+ double vy, uint32_t button, uint32_t state) {
+ if (button == BTN_LEFT && state == WLR_BUTTON_PRESSED) {
+ view->has_button_grab = true;
+ view->grab_vx = vx;
+ view->grab_vy = vy;
+ } else {
+ view->has_button_grab = false;
+ }
+}
+
static void roots_cursor_update_position(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;
+ 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_view *seat_view =
+ roots_seat_view_from_view(seat, 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 && cursor->cursor_client;
- if (view) {
+ if (view && surface) {
struct wl_client *view_client =
wl_resource_get_client(view->wlr_surface->resource);
set_compositor_cursor = view_client != cursor->cursor_client;
@@ -52,7 +114,15 @@ static void roots_cursor_update_position(struct roots_cursor *cursor,
cursor->default_xcursor, cursor->cursor);
cursor->cursor_client = NULL;
}
- if (view) {
+ if (view && !surface) {
+ if (seat_view) {
+ cursor->pointer_view = seat_view;
+ seat_view_deco_motion(seat_view,
+ cursor->cursor->x - seat_view->view->x,
+ cursor->cursor->y - seat_view->view->y);
+ }
+ } 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 {
@@ -166,16 +236,30 @@ static void roots_cursor_press_button(struct roots_cursor *cursor,
}
return;
}
+
+ if (view && !surface) {
+ if (cursor->pointer_view) {
+ seat_view_deco_button(cursor->pointer_view,
+ cursor->cursor->x - cursor->pointer_view->view->x,
+ cursor->cursor->y - cursor->pointer_view->view->y,
+ button, state);
+ }
+ }
+
if (state == WLR_BUTTON_RELEASED &&
cursor->mode != ROOTS_CURSOR_PASSTHROUGH) {
cursor->mode = ROOTS_CURSOR_PASSTHROUGH;
+ wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager,
+ cursor->default_xcursor, cursor->cursor);
if (seat->seat->pointer_state.button_count == 0) {
return;
}
}
- if (!is_touch) {
- wlr_seat_pointer_notify_button(seat->seat, time, button, state);
+ if (view && surface) {
+ if (!is_touch) {
+ wlr_seat_pointer_notify_button(seat->seat, time, button, state);
+ }
}
switch (state) {
diff --git a/rootston/desktop.c b/rootston/desktop.c
index 3de1f669..1ec1d552 100644
--- a/rootston/desktop.c
+++ b/rootston/desktop.c
@@ -392,6 +392,14 @@ struct roots_view *desktop_view_at(struct roots_desktop *desktop, double lx,
if (view_at(view, lx, ly, surface, sx, sy)) {
return view;
}
+
+ if (view->decorated) {
+ struct wlr_box deco_box;
+ view_get_deco_box(view, &deco_box);
+ if (wlr_box_contains_point(&deco_box, lx, ly)) {
+ return view;
+ }
+ }
}
return NULL;
}
diff --git a/rootston/seat.c b/rootston/seat.c
index 130c7b27..06c0caa6 100644
--- a/rootston/seat.c
+++ b/rootston/seat.c
@@ -580,7 +580,7 @@ static struct roots_seat_view *seat_add_view(struct roots_seat *seat,
seat_view->seat = seat;
seat_view->view = view;
- wl_list_insert(&seat->views, &seat_view->link);
+ wl_list_insert(seat->views.prev, &seat_view->link);
seat_view->view_destroy.notify = seat_view_handle_destroy;
wl_signal_add(&view->events.destroy, &seat_view->view_destroy);
@@ -588,6 +588,31 @@ static struct roots_seat_view *seat_add_view(struct roots_seat *seat,
return seat_view;
}
+struct roots_seat_view *roots_seat_view_from_view(
+ struct roots_seat *seat, struct roots_view *view) {
+ if (view == NULL) {
+ return NULL;
+ }
+
+ bool found = false;
+ struct roots_seat_view *seat_view = NULL;
+ wl_list_for_each(seat_view, &seat->views, link) {
+ if (seat_view->view == view) {
+ found = true;
+ break;
+ }
+ }
+ if (!found) {
+ seat_view = seat_add_view(seat, view);
+ if (seat_view == NULL) {
+ wlr_log(L_ERROR, "Allocation failed");
+ return NULL;
+ }
+ }
+
+ return seat_view;
+}
+
void roots_seat_set_focus(struct roots_seat *seat, struct roots_view *view) {
// Make sure the view will be rendered on top of others, even if it's
// already focused in this seat
@@ -605,22 +630,11 @@ void roots_seat_set_focus(struct roots_seat *seat, struct roots_view *view) {
view->xwayland_surface->override_redirect) {
return;
}
-
struct roots_seat_view *seat_view = NULL;
if (view != NULL) {
- bool found = false;
- wl_list_for_each(seat_view, &seat->views, link) {
- if (seat_view->view == view) {
- found = true;
- break;
- }
- }
- if (!found) {
- seat_view = seat_add_view(seat, view);
- if (seat_view == NULL) {
- wlr_log(L_ERROR, "Allocation failed");
- return;
- }
+ seat_view = roots_seat_view_from_view(seat, view);
+ if (seat_view == NULL) {
+ return;
}
}