Implement xdg surface request_move
This commit is contained in:
parent
96b401c05d
commit
0ca7932c3f
|
@ -28,6 +28,7 @@ enum roots_view_type {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct roots_view {
|
struct roots_view {
|
||||||
|
struct roots_desktop *desktop;
|
||||||
double x, y;
|
double x, y;
|
||||||
float rotation;
|
float rotation;
|
||||||
// TODO: Something for roots-enforced width/height
|
// TODO: Something for roots-enforced width/height
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
// TODO: BSD et al
|
||||||
|
#include <linux/input-event-codes.h>
|
||||||
#include <wayland-server.h>
|
#include <wayland-server.h>
|
||||||
#include <wlr/types/wlr_cursor.h>
|
#include <wlr/types/wlr_cursor.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
|
@ -18,7 +20,6 @@ void cursor_update_position(struct roots_input *input, uint32_t time) {
|
||||||
view_get_input_bounds(view, &box);
|
view_get_input_bounds(view, &box);
|
||||||
double sx = input->cursor->x - view->x;
|
double sx = input->cursor->x - view->x;
|
||||||
double sy = input->cursor->y - view->y;
|
double sy = input->cursor->y - view->y;
|
||||||
wlr_log(L_DEBUG, "Moving cursor in view at %f, %f", sx, sy);
|
|
||||||
wlr_seat_pointer_enter(input->wl_seat, view->wlr_surface, sx, sy);
|
wlr_seat_pointer_enter(input->wl_seat, view->wlr_surface, sx, sy);
|
||||||
wlr_seat_pointer_send_motion(input->wl_seat, time, sx, sy);
|
wlr_seat_pointer_send_motion(input->wl_seat, time, sx, sy);
|
||||||
} else {
|
} else {
|
||||||
|
@ -26,21 +27,16 @@ void cursor_update_position(struct roots_input *input, uint32_t time) {
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ROOTS_CURSOR_MOVE:
|
case ROOTS_CURSOR_MOVE:
|
||||||
|
if (input->active_view) {
|
||||||
|
input->active_view->x = input->cursor->x - input->offs_x;
|
||||||
|
input->active_view->y = input->cursor->y - input->offs_y;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case ROOTS_CURSOR_RESIZE:
|
case ROOTS_CURSOR_RESIZE:
|
||||||
break;
|
break;
|
||||||
case ROOTS_CURSOR_ROTATE:
|
case ROOTS_CURSOR_ROTATE:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
if (input->motion_context.surface) {
|
|
||||||
struct example_xdg_surface_v6 *surface;
|
|
||||||
surface = sample->motion_context.surface;
|
|
||||||
surface->position.lx = sample->cursor->x - sample->motion_context.off_x;
|
|
||||||
surface->position.ly = sample->cursor->y - sample->motion_context.off_y;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void set_view_focus(struct roots_input *input,
|
static void set_view_focus(struct roots_input *input,
|
||||||
|
@ -82,27 +78,25 @@ static void handle_cursor_axis(struct wl_listener *listener, void *data) {
|
||||||
event->orientation, event->delta);
|
event->orientation, event->delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_cursor_button(struct wl_listener *listener, void *data) {
|
static void do_cursor_button_press(struct roots_input *input,
|
||||||
struct roots_input *input = wl_container_of(listener, input, cursor_button);
|
struct wlr_cursor *cursor, struct wlr_input_device *device,
|
||||||
struct wlr_event_pointer_button *event = data;
|
uint32_t time, uint32_t button, uint32_t state) {
|
||||||
|
|
||||||
struct roots_desktop *desktop = input->server->desktop;
|
struct roots_desktop *desktop = input->server->desktop;
|
||||||
struct roots_view *view = view_at(
|
struct roots_view *view = view_at(desktop,
|
||||||
desktop, input->cursor->x, input->cursor->y);
|
input->cursor->x, input->cursor->y);
|
||||||
|
uint32_t serial = wlr_seat_pointer_send_button(
|
||||||
uint32_t serial = wlr_seat_pointer_send_button(input->wl_seat,
|
input->wl_seat, time, button, state);
|
||||||
(uint32_t)event->time_usec, event->button, event->state);
|
|
||||||
|
|
||||||
int i;
|
int i;
|
||||||
switch (event->state) {
|
switch (state) {
|
||||||
case WLR_BUTTON_RELEASED:
|
case WLR_BUTTON_RELEASED:
|
||||||
input->active_view = NULL;
|
input->active_view = NULL;
|
||||||
|
input->mode = ROOTS_CURSOR_PASSTHROUGH;
|
||||||
break;
|
break;
|
||||||
case WLR_BUTTON_PRESSED:
|
case WLR_BUTTON_PRESSED:
|
||||||
i = input->input_events_idx;
|
i = input->input_events_idx;
|
||||||
input->input_events[i].serial = serial;
|
input->input_events[i].serial = serial;
|
||||||
input->input_events[i].cursor = input->cursor;
|
input->input_events[i].cursor = cursor;
|
||||||
input->input_events[i].device = event->device;
|
input->input_events[i].device = device;
|
||||||
input->input_events_idx = (i + 1)
|
input->input_events_idx = (i + 1)
|
||||||
% (sizeof(input->input_events) / sizeof(input->input_events[0]));
|
% (sizeof(input->input_events) / sizeof(input->input_events[0]));
|
||||||
set_view_focus(input, desktop, view);
|
set_view_focus(input, desktop, view);
|
||||||
|
@ -110,6 +104,13 @@ static void handle_cursor_button(struct wl_listener *listener, void *data) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void handle_cursor_button(struct wl_listener *listener, void *data) {
|
||||||
|
struct roots_input *input = wl_container_of(listener, input, cursor_button);
|
||||||
|
struct wlr_event_pointer_button *event = data;
|
||||||
|
do_cursor_button_press(input, input->cursor, event->device,
|
||||||
|
(uint32_t)event->time_usec, event->button, event->state);
|
||||||
|
}
|
||||||
|
|
||||||
static void handle_tool_axis(struct wl_listener *listener, void *data) {
|
static void handle_tool_axis(struct wl_listener *listener, void *data) {
|
||||||
struct roots_input *input = wl_container_of(listener, input, cursor_tool_axis);
|
struct roots_input *input = wl_container_of(listener, input, cursor_tool_axis);
|
||||||
struct wlr_event_tablet_tool_axis *event = data;
|
struct wlr_event_tablet_tool_axis *event = data;
|
||||||
|
@ -122,15 +123,10 @@ static void handle_tool_axis(struct wl_listener *listener, void *data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_tool_tip(struct wl_listener *listener, void *data) {
|
static void handle_tool_tip(struct wl_listener *listener, void *data) {
|
||||||
struct roots_input *input = wl_container_of(listener, input, tool_tip);
|
struct roots_input *input = wl_container_of(listener, input, cursor_tool_tip);
|
||||||
struct wlr_event_tablet_tool_tip *event = data;
|
struct wlr_event_tablet_tool_tip *event = data;
|
||||||
|
do_cursor_button_press(input, input->cursor, event->device,
|
||||||
struct roots_desktop *desktop = input->server->desktop;
|
(uint32_t)event->time_usec, BTN_LEFT, event->state);
|
||||||
struct roots_view *view = view_at(
|
|
||||||
desktop, input->cursor->x, input->cursor->y);
|
|
||||||
set_view_focus(input, desktop, view);
|
|
||||||
wlr_seat_pointer_send_button(input->wl_seat, (uint32_t)event->time_usec,
|
|
||||||
BTN_LEFT, event->state);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void cursor_initialize(struct roots_input *input) {
|
void cursor_initialize(struct roots_input *input) {
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
#include "rootston/desktop.h"
|
#include "rootston/desktop.h"
|
||||||
#include "rootston/server.h"
|
#include "rootston/server.h"
|
||||||
|
#include "rootston/input.h"
|
||||||
|
|
||||||
static void get_input_bounds(struct roots_view *view, struct wlr_box *box) {
|
static void get_input_bounds(struct roots_view *view, struct wlr_box *box) {
|
||||||
assert(view->type == ROOTS_XDG_SHELL_V6_VIEW);
|
assert(view->type == ROOTS_XDG_SHELL_V6_VIEW);
|
||||||
|
@ -23,6 +24,32 @@ static void activate(struct roots_view *view, bool active) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void handle_request_move(struct wl_listener *listener, void *data) {
|
||||||
|
struct roots_xdg_surface_v6 *roots_xdg_surface =
|
||||||
|
wl_container_of(listener, roots_xdg_surface, request_move);
|
||||||
|
struct roots_view *view = roots_xdg_surface->view;
|
||||||
|
struct roots_input *input = view->desktop->server->input;
|
||||||
|
struct wlr_xdg_toplevel_v6_move_event *e = data;
|
||||||
|
|
||||||
|
// TODO: Some of this might want to live in cursor.c I guess
|
||||||
|
struct roots_input_event *event = NULL;
|
||||||
|
size_t len = sizeof(input->input_events) / sizeof(*input->input_events);
|
||||||
|
for (size_t i = 0; i < len; ++i) {
|
||||||
|
if (input->input_events[i].cursor
|
||||||
|
&& input->input_events[i].serial == e->serial) {
|
||||||
|
event = &input->input_events[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!event || input->mode != ROOTS_CURSOR_PASSTHROUGH) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
input->mode = ROOTS_CURSOR_MOVE;
|
||||||
|
input->offs_x = input->cursor->x - view->x;
|
||||||
|
input->offs_y = input->cursor->y - view->y;
|
||||||
|
wlr_seat_pointer_clear_focus(input->wl_seat);
|
||||||
|
}
|
||||||
|
|
||||||
static void handle_destroy(struct wl_listener *listener, void *data) {
|
static void handle_destroy(struct wl_listener *listener, void *data) {
|
||||||
struct roots_xdg_surface_v6 *roots_xdg_surface =
|
struct roots_xdg_surface_v6 *roots_xdg_surface =
|
||||||
wl_container_of(listener, roots_xdg_surface, destroy);
|
wl_container_of(listener, roots_xdg_surface, destroy);
|
||||||
|
@ -54,6 +81,8 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
|
||||||
wl_list_init(&roots_surface->ping_timeout.link);
|
wl_list_init(&roots_surface->ping_timeout.link);
|
||||||
wl_list_init(&roots_surface->request_minimize.link);
|
wl_list_init(&roots_surface->request_minimize.link);
|
||||||
wl_list_init(&roots_surface->request_move.link);
|
wl_list_init(&roots_surface->request_move.link);
|
||||||
|
roots_surface->request_move.notify = handle_request_move;
|
||||||
|
wl_signal_add(&surface->events.request_move, &roots_surface->request_move);
|
||||||
wl_list_init(&roots_surface->request_resize.link);
|
wl_list_init(&roots_surface->request_resize.link);
|
||||||
wl_list_init(&roots_surface->request_show_window_menu.link);
|
wl_list_init(&roots_surface->request_show_window_menu.link);
|
||||||
|
|
||||||
|
@ -65,6 +94,7 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
|
||||||
view->wlr_surface = surface->surface;
|
view->wlr_surface = surface->surface;
|
||||||
view->get_input_bounds = get_input_bounds;
|
view->get_input_bounds = get_input_bounds;
|
||||||
view->activate = activate;
|
view->activate = activate;
|
||||||
|
view->desktop = desktop;
|
||||||
roots_surface->view = view;
|
roots_surface->view = view;
|
||||||
wl_list_insert(&desktop->views, &view->link);
|
wl_list_insert(&desktop->views, &view->link);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue