mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-25 22:25:58 +01:00
Implement pointer motion and buttons
This commit is contained in:
parent
5b92d4fecf
commit
eaf6c0ccf4
7 changed files with 107 additions and 40 deletions
|
@ -48,6 +48,8 @@ struct roots_desktop *desktop_create(struct roots_server *server,
|
|||
void desktop_destroy(struct roots_desktop *desktop);
|
||||
|
||||
void view_destroy(struct roots_view *view);
|
||||
struct roots_view *view_at(struct roots_desktop *desktop, int x, int y);
|
||||
void view_activate(struct roots_view *view, bool activate);
|
||||
|
||||
void output_add_notify(struct wl_listener *listener, void *data);
|
||||
void output_remove_notify(struct wl_listener *listener, void *data);
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
#ifndef _ROOTSTON_VIEW_H
|
||||
#define _ROOTSTON_VIEW_H
|
||||
#include <stdbool.h>
|
||||
#include <wlr/types/wlr_xdg_shell_v6.h>
|
||||
#include <wlr/types/wlr_box.h>
|
||||
#include <wlr/types/wlr_surface.h>
|
||||
#include <wlr/types/wlr_xdg_shell_v6.h>
|
||||
|
||||
struct roots_wl_shell_surface {
|
||||
// TODO
|
||||
|
@ -41,6 +42,15 @@ struct roots_view {
|
|||
};
|
||||
struct wlr_surface *wlr_surface;
|
||||
struct wl_list link;
|
||||
// TODO: This would probably be better as a field that's updated on a
|
||||
// configure event from the xdg_shell
|
||||
// If not then this should follow the typical type/impl pattern we use
|
||||
// elsewhere
|
||||
void (*get_input_bounds)(struct roots_view *view, struct wlr_box *box);
|
||||
void (*activate)(struct roots_view *view, bool active);
|
||||
};
|
||||
|
||||
void view_get_input_bounds(struct roots_view *view, struct wlr_box *box);
|
||||
void view_activate(struct roots_view *view, bool active);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#include <string.h>
|
||||
#include <wayland-server.h>
|
||||
#include <wlr/types/wlr_cursor.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include "rootston/config.h"
|
||||
#include "rootston/input.h"
|
||||
#include "rootston/desktop.h"
|
||||
|
@ -15,23 +16,34 @@ void cursor_update_position(struct roots_input *input, uint32_t time) {
|
|||
surface->position.ly = sample->cursor->y - sample->motion_context.off_y;
|
||||
return;
|
||||
}
|
||||
|
||||
struct wlr_xdg_surface_v6 *surface = example_xdg_surface_at(sample,
|
||||
sample->cursor->x, sample->cursor->y);
|
||||
|
||||
if (surface) {
|
||||
struct example_xdg_surface_v6 *esurface = surface->data;
|
||||
|
||||
double sx = sample->cursor->x - esurface->position.lx;
|
||||
double sy = sample->cursor->y - esurface->position.ly;
|
||||
|
||||
// TODO z-order
|
||||
wlr_seat_pointer_enter(sample->wl_seat, surface->surface, sx, sy);
|
||||
wlr_seat_pointer_send_motion(sample->wl_seat, time, sx, sy);
|
||||
} else {
|
||||
wlr_seat_pointer_clear_focus(sample->wl_seat);
|
||||
}
|
||||
*/
|
||||
struct roots_desktop *desktop = input->server->desktop;
|
||||
struct roots_view *view = view_at(
|
||||
desktop, input->cursor->x, input->cursor->y);
|
||||
if (view) {
|
||||
struct wlr_box box;
|
||||
view_get_input_bounds(view, &box);
|
||||
double sx = input->cursor->x - view->x;
|
||||
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_send_motion(input->wl_seat, time, sx, sy);
|
||||
} else {
|
||||
wlr_seat_pointer_clear_focus(input->wl_seat);
|
||||
}
|
||||
}
|
||||
|
||||
static void set_view_focus(struct roots_input *input,
|
||||
struct roots_desktop *desktop, struct roots_view *view) {
|
||||
if (input->active_view == view) {
|
||||
return;
|
||||
}
|
||||
struct roots_view *_view;
|
||||
wl_list_for_each(_view, &desktop->views, link) {
|
||||
view_activate(_view, _view == view);
|
||||
}
|
||||
input->active_view = view;
|
||||
input->mode = ROOTS_CURSOR_PASSTHROUGH;
|
||||
}
|
||||
|
||||
static void handle_cursor_motion(struct wl_listener *listener, void *data) {
|
||||
|
@ -61,43 +73,35 @@ static void handle_cursor_axis(struct wl_listener *listener, void *data) {
|
|||
}
|
||||
|
||||
static void handle_cursor_button(struct wl_listener *listener, void *data) {
|
||||
/* TODO
|
||||
struct sample_state *sample =
|
||||
wl_container_of(listener, sample, cursor_button);
|
||||
struct roots_input *input = wl_container_of(listener, input, cursor_button);
|
||||
struct wlr_event_pointer_button *event = data;
|
||||
|
||||
struct wlr_xdg_surface_v6 *surface =
|
||||
example_xdg_surface_at(sample, sample->cursor->x, sample->cursor->y);
|
||||
struct roots_desktop *desktop = input->server->desktop;
|
||||
struct roots_view *view = view_at(
|
||||
desktop, input->cursor->x, input->cursor->y);
|
||||
|
||||
uint32_t serial = wlr_seat_pointer_send_button(sample->wl_seat,
|
||||
uint32_t serial = wlr_seat_pointer_send_button(input->wl_seat,
|
||||
(uint32_t)event->time_usec, event->button, event->state);
|
||||
|
||||
int i;
|
||||
switch (event->state) {
|
||||
case WLR_BUTTON_RELEASED:
|
||||
/*
|
||||
if (sample->motion_context.surface) {
|
||||
sample->motion_context.surface = NULL;
|
||||
}
|
||||
*/
|
||||
break;
|
||||
case WLR_BUTTON_PRESSED:
|
||||
i = sample->input_cache_idx;
|
||||
sample->input_cache[i].serial = serial;
|
||||
sample->input_cache[i].cursor = sample->cursor;
|
||||
sample->input_cache[i].device = event->device;
|
||||
sample->input_cache_idx = (i + 1)
|
||||
% (sizeof(sample->input_cache) / sizeof(sample->input_cache[0]));
|
||||
example_set_focused_surface(sample, surface);
|
||||
wlr_log(L_DEBUG, "Stored event %d at %d", serial, i);
|
||||
if (sample->mod_down && event->button == BTN_LEFT) {
|
||||
struct example_xdg_surface_v6 *esurface = surface->data;
|
||||
sample->motion_context.surface = esurface;
|
||||
sample->motion_context.off_x = sample->cursor->x - esurface->position.lx;
|
||||
sample->motion_context.off_y = sample->cursor->y - esurface->position.ly;
|
||||
wlr_seat_pointer_clear_focus(sample->wl_seat);
|
||||
}
|
||||
i = input->input_events_idx;
|
||||
input->input_events[i].serial = serial;
|
||||
input->input_events[i].cursor = input->cursor;
|
||||
input->input_events[i].device = event->device;
|
||||
input->input_events_idx = (i + 1)
|
||||
% (sizeof(input->input_events) / sizeof(input->input_events[0]));
|
||||
set_view_focus(input, desktop, view);
|
||||
break;
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
static void handle_tool_axis(struct wl_listener *listener, void *data) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#define _POSIX_C_SOURCE 199309L
|
||||
#include <time.h>
|
||||
#include <stdlib.h>
|
||||
#include <wlr/types/wlr_box.h>
|
||||
#include <wlr/types/wlr_compositor.h>
|
||||
#include <wlr/types/wlr_cursor.h>
|
||||
#include <wlr/types/wlr_gamma_control.h>
|
||||
|
@ -16,6 +17,34 @@ void view_destroy(struct roots_view *view) {
|
|||
free(view);
|
||||
}
|
||||
|
||||
void view_get_input_bounds(struct roots_view *view, struct wlr_box *box) {
|
||||
if (view->get_input_bounds) {
|
||||
view->get_input_bounds(view, box);
|
||||
return;
|
||||
}
|
||||
box->x = box->y = 0;
|
||||
}
|
||||
|
||||
void view_activate(struct roots_view *view, bool activate) {
|
||||
if (view->activate) {
|
||||
view->activate(view, activate);
|
||||
}
|
||||
}
|
||||
|
||||
struct roots_view *view_at(struct roots_desktop *desktop, int x, int y) {
|
||||
struct roots_view *view;
|
||||
wl_list_for_each(view, &desktop->views, link) {
|
||||
struct wlr_box box;
|
||||
view_get_input_bounds(view, &box);
|
||||
box.x += view->x;
|
||||
box.y += view->y;
|
||||
if (wlr_box_contains_point(&box, x, y)) {
|
||||
return view;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
struct roots_desktop *desktop_create(struct roots_server *server,
|
||||
struct roots_config *config) {
|
||||
struct roots_desktop *desktop = calloc(1, sizeof(struct roots_desktop));
|
||||
|
|
|
@ -82,6 +82,8 @@ struct roots_input *input_create(struct roots_server *server,
|
|||
assert(input->xcursor = wlr_xcursor_theme_get_cursor(theme, "left_ptr"));
|
||||
|
||||
assert(input->wl_seat = wlr_seat_create(server->wl_display, "seat0"));
|
||||
wlr_seat_set_capabilities(input->wl_seat, WL_SEAT_CAPABILITY_KEYBOARD
|
||||
| WL_SEAT_CAPABILITY_POINTER | WL_SEAT_CAPABILITY_TOUCH);
|
||||
|
||||
wl_list_init(&input->keyboards);
|
||||
wl_list_init(&input->pointers);
|
||||
|
|
|
@ -1,11 +1,28 @@
|
|||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <wayland-server.h>
|
||||
#include <wlr/types/wlr_xdg_shell_v6.h>
|
||||
#include <wlr/types/wlr_box.h>
|
||||
#include <wlr/types/wlr_surface.h>
|
||||
#include <wlr/types/wlr_xdg_shell_v6.h>
|
||||
#include <wlr/util/log.h>
|
||||
#include "rootston/desktop.h"
|
||||
#include "rootston/server.h"
|
||||
|
||||
static void get_input_bounds(struct roots_view *view, struct wlr_box *box) {
|
||||
assert(view->type == ROOTS_XDG_SHELL_V6_VIEW);
|
||||
struct wlr_xdg_surface_v6 *surf = view->xdg_surface_v6;
|
||||
memcpy(box, surf->geometry, sizeof(struct wlr_box));
|
||||
}
|
||||
|
||||
static void activate(struct roots_view *view, bool active) {
|
||||
assert(view->type == ROOTS_XDG_SHELL_V6_VIEW);
|
||||
struct wlr_xdg_surface_v6 *surf = view->xdg_surface_v6;
|
||||
if (surf->role == WLR_XDG_SURFACE_V6_ROLE_TOPLEVEL) {
|
||||
wlr_xdg_toplevel_v6_set_activated(surf, active);
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_destroy(struct wl_listener *listener, void *data) {
|
||||
struct roots_xdg_surface_v6 *roots_xdg_surface =
|
||||
wl_container_of(listener, roots_xdg_surface, destroy);
|
||||
|
@ -46,6 +63,8 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) {
|
|||
view->xdg_surface_v6 = surface;
|
||||
view->roots_xdg_surface_v6 = roots_surface;
|
||||
view->wlr_surface = surface->surface;
|
||||
view->get_input_bounds = get_input_bounds;
|
||||
view->activate = activate;
|
||||
roots_surface->view = view;
|
||||
wl_list_insert(&desktop->views, &view->link);
|
||||
}
|
||||
|
|
|
@ -157,6 +157,7 @@ static void wl_seat_bind(struct wl_client *wl_client, void *_wlr_seat,
|
|||
wl_resource_set_implementation(handle->wl_resource, &wl_seat_impl,
|
||||
handle, wlr_seat_handle_resource_destroy);
|
||||
wl_list_insert(&wlr_seat->handles, &handle->link);
|
||||
wl_seat_send_name(handle->wl_resource, wlr_seat->name);
|
||||
wl_seat_send_capabilities(handle->wl_resource, wlr_seat->capabilities);
|
||||
wl_signal_emit(&wlr_seat->events.client_bound, handle);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue