aboutsummaryrefslogtreecommitdiff
path: root/rootston/cursor.c
diff options
context:
space:
mode:
Diffstat (limited to 'rootston/cursor.c')
-rw-r--r--rootston/cursor.c131
1 files changed, 15 insertions, 116 deletions
diff --git a/rootston/cursor.c b/rootston/cursor.c
index 10bb4dd3..71075aa9 100644
--- a/rootston/cursor.c
+++ b/rootston/cursor.c
@@ -58,19 +58,21 @@ static void roots_cursor_update_position(struct roots_cursor *cursor,
}
break;
case ROOTS_CURSOR_MOVE:
- if (seat->focus) {
+ view = roots_seat_get_focus(seat);
+ if (view != NULL) {
double dx = cursor->cursor->x - cursor->offs_x;
double dy = cursor->cursor->y - cursor->offs_y;
- view_move(seat->focus, cursor->view_x + dx,
+ view_move(view, cursor->view_x + dx,
cursor->view_y + dy);
}
break;
case ROOTS_CURSOR_RESIZE:
- if (seat->focus) {
+ view = roots_seat_get_focus(seat);
+ if (view != NULL) {
double dx = cursor->cursor->x - cursor->offs_x;
double dy = cursor->cursor->y - cursor->offs_y;
- double active_x = seat->focus->x;
- double active_y = seat->focus->y;
+ double active_x = view->x;
+ double active_y = view->y;
int width = cursor->view_width;
int height = cursor->view_height;
if (cursor->resize_edges & ROOTS_CURSOR_RESIZE_EDGE_TOP) {
@@ -99,18 +101,18 @@ static void roots_cursor_update_position(struct roots_cursor *cursor,
height = 0;
}
- if (active_x != seat->focus->x ||
- active_y != seat->focus->y) {
- view_move_resize(seat->focus, active_x, active_y,
+ if (active_x != view->x ||
+ active_y != view->y) {
+ view_move_resize(view, active_x, active_y,
width, height);
} else {
- view_resize(seat->focus, width, height);
+ view_resize(view, width, height);
}
}
break;
case ROOTS_CURSOR_ROTATE:
- if (seat->focus) {
- struct roots_view *view = seat->focus;
+ view = roots_seat_get_focus(seat);
+ if (view != NULL) {
int ox = view->x + view->wlr_surface->current->width/2,
oy = view->y + view->wlr_surface->current->height/2;
int ux = cursor->offs_x - ox,
@@ -124,7 +126,6 @@ static void roots_cursor_update_position(struct roots_cursor *cursor,
}
break;
}
-
}
static void roots_cursor_press_button(struct roots_cursor *cursor,
@@ -141,7 +142,7 @@ static void roots_cursor_press_button(struct roots_cursor *cursor,
if (state == WLR_BUTTON_PRESSED &&
view &&
roots_seat_has_meta_pressed(seat)) {
- roots_seat_focus_view(seat, view);
+ roots_seat_set_focus(seat, view);
uint32_t edges;
switch (button) {
@@ -192,7 +193,7 @@ static void roots_cursor_press_button(struct roots_cursor *cursor,
cursor->input_events[i].device = device;
cursor->input_events_idx = (i + 1)
% (sizeof(cursor->input_events) / sizeof(cursor->input_events[0]));
- roots_seat_focus_view(seat, view);
+ roots_seat_set_focus(seat, view);
break;
}
}
@@ -354,105 +355,3 @@ void roots_cursor_handle_request_set_cursor(struct roots_cursor *cursor,
event->hotspot_y);
cursor->cursor_client = event->seat_client->client;
}
-
-static void handle_drag_icon_commit(struct wl_listener *listener, void *data) {
- struct roots_drag_icon *drag_icon =
- wl_container_of(listener, drag_icon, surface_commit);
- drag_icon->sx += drag_icon->surface->current->sx;
- drag_icon->sy += drag_icon->surface->current->sy;
-}
-
-static void handle_drag_icon_destroy(struct wl_listener *listener, void *data) {
- struct roots_drag_icon *drag_icon =
- wl_container_of(listener, drag_icon, surface_destroy);
- wl_list_remove(&drag_icon->link);
- wl_list_remove(&drag_icon->surface_destroy.link);
- wl_list_remove(&drag_icon->surface_commit.link);
- free(drag_icon);
-}
-
-static struct roots_drag_icon *seat_add_drag_icon(struct roots_seat *seat,
- struct wlr_surface *icon_surface) {
- if (!icon_surface) {
- return NULL;
- }
-
- struct roots_drag_icon *iter_icon;
- wl_list_for_each(iter_icon, &seat->drag_icons, link) {
- if (iter_icon->surface == icon_surface) {
- // already in the list
- return iter_icon;
- }
- }
-
- struct roots_drag_icon *drag_icon =
- calloc(1, sizeof(struct roots_drag_icon));
- drag_icon->mapped = true;
- drag_icon->surface = icon_surface;
- wl_list_insert(&seat->drag_icons, &drag_icon->link);
-
- wl_signal_add(&icon_surface->events.destroy,
- &drag_icon->surface_destroy);
- drag_icon->surface_destroy.notify = handle_drag_icon_destroy;
-
- wl_signal_add(&icon_surface->events.commit,
- &drag_icon->surface_commit);
- drag_icon->surface_commit.notify = handle_drag_icon_commit;
-
- return drag_icon;
-}
-
-static void seat_unmap_drag_icon(struct roots_seat *seat,
- struct wlr_surface *icon_surface) {
- if (!icon_surface) {
- return;
- }
-
- struct roots_drag_icon *icon;
- wl_list_for_each(icon, &seat->drag_icons, link) {
- if (icon->surface == icon_surface) {
- icon->mapped = false;
- }
- }
-}
-
-void roots_cursor_handle_pointer_grab_begin(struct roots_cursor *cursor,
- struct wlr_seat_pointer_grab *grab) {
- if (grab->interface == &wlr_data_device_pointer_drag_interface) {
- struct wlr_drag *drag = grab->data;
- struct roots_drag_icon *icon =
- seat_add_drag_icon(cursor->seat, drag->icon);
- if (icon) {
- icon->is_pointer = true;
- }
- }
-}
-
-void roots_cursor_handle_pointer_grab_end(struct roots_cursor *cursor,
- struct wlr_seat_pointer_grab *grab) {
- if (grab->interface == &wlr_data_device_pointer_drag_interface) {
- struct wlr_drag *drag = grab->data;
- seat_unmap_drag_icon(cursor->seat, drag->icon);
- }
-}
-
-void roots_cursor_handle_touch_grab_begin(struct roots_cursor *cursor,
- struct wlr_seat_touch_grab *grab) {
- if (grab->interface == &wlr_data_device_touch_drag_interface) {
- struct wlr_drag *drag = grab->data;
- struct roots_drag_icon *icon =
- seat_add_drag_icon(cursor->seat, drag->icon);
- if (icon) {
- icon->is_pointer = false;
- icon->touch_id = drag->grab_touch_id;
- }
- }
-}
-
-void roots_cursor_handle_touch_grab_end(struct roots_cursor *cursor,
- struct wlr_seat_touch_grab *grab) {
- if (grab->interface == &wlr_data_device_touch_drag_interface) {
- struct wlr_drag *drag = grab->data;
- seat_unmap_drag_icon(cursor->seat, drag->icon);
- }
-}