working pointer motion
This commit is contained in:
parent
9333a7eb53
commit
e69b052a6d
|
@ -3,6 +3,7 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <wlr/types/wlr_box.h>
|
#include <wlr/types/wlr_box.h>
|
||||||
|
#include <wlr/types/wlr_surface.h>
|
||||||
#include "list.h"
|
#include "list.h"
|
||||||
|
|
||||||
typedef struct sway_container swayc_t;
|
typedef struct sway_container swayc_t;
|
||||||
|
@ -136,4 +137,7 @@ swayc_t *destroy_view(swayc_t *view);
|
||||||
|
|
||||||
swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type);
|
swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type);
|
||||||
|
|
||||||
|
swayc_t *swayc_at(swayc_t *parent, double lx, double ly,
|
||||||
|
struct wlr_surface **surface, double *sx, double *sy);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -4,9 +4,12 @@
|
||||||
#include "sway/input/seat.h"
|
#include "sway/input/seat.h"
|
||||||
|
|
||||||
struct sway_cursor {
|
struct sway_cursor {
|
||||||
|
struct sway_seat *seat;
|
||||||
struct wlr_cursor *cursor;
|
struct wlr_cursor *cursor;
|
||||||
struct wlr_xcursor_manager *xcursor_manager;
|
struct wlr_xcursor_manager *xcursor_manager;
|
||||||
|
|
||||||
|
double x, y;
|
||||||
|
|
||||||
struct wl_listener motion;
|
struct wl_listener motion;
|
||||||
struct wl_listener motion_absolute;
|
struct wl_listener motion_absolute;
|
||||||
struct wl_listener button;
|
struct wl_listener button;
|
||||||
|
|
|
@ -25,8 +25,8 @@ static void output_frame_view(swayc_t *view, void *data) {
|
||||||
}
|
}
|
||||||
// TODO
|
// TODO
|
||||||
// - Deal with wlr_output_layout
|
// - Deal with wlr_output_layout
|
||||||
int width = sway_view->width;
|
int width = sway_view->surface->current->width;
|
||||||
int height = sway_view->height;
|
int height = sway_view->surface->current->height;
|
||||||
int render_width = width * wlr_output->scale;
|
int render_width = width * wlr_output->scale;
|
||||||
int render_height = height * wlr_output->scale;
|
int render_height = height * wlr_output->scale;
|
||||||
double ox = view->x, oy = view->y;
|
double ox = view->x, oy = view->y;
|
||||||
|
@ -40,19 +40,33 @@ static void output_frame_view(swayc_t *view, void *data) {
|
||||||
// return;
|
// return;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
|
// if the shell specifies window geometry, make the top left corner of the
|
||||||
|
// window in the top left corner of the container to avoid arbitrarily
|
||||||
|
// sized gaps based on the attached buffer size
|
||||||
|
int window_offset_x = 0;
|
||||||
|
int window_offset_y = 0;
|
||||||
|
|
||||||
|
if (view->sway_view->type == SWAY_XDG_SHELL_V6_VIEW) {
|
||||||
|
window_offset_x = view->sway_view->wlr_xdg_surface_v6->geometry->x;
|
||||||
|
window_offset_y = view->sway_view->wlr_xdg_surface_v6->geometry->y;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
double rotation = 0;
|
double rotation = 0;
|
||||||
float matrix[16];
|
float matrix[16];
|
||||||
|
|
||||||
float translate_origin[16];
|
float translate_origin[16];
|
||||||
wlr_matrix_translate(&translate_origin,
|
wlr_matrix_translate(&translate_origin,
|
||||||
(int)ox + render_width / 2, (int)oy + render_height / 2, 0);
|
(int)ox + render_width / 2 - window_offset_x,
|
||||||
|
(int)oy + render_height / 2 - window_offset_y,
|
||||||
|
0);
|
||||||
|
|
||||||
float rotate[16];
|
float rotate[16];
|
||||||
wlr_matrix_rotate(&rotate, rotation);
|
wlr_matrix_rotate(&rotate, rotation);
|
||||||
|
|
||||||
float translate_center[16];
|
float translate_center[16];
|
||||||
wlr_matrix_translate(&translate_center, -render_width / 2,
|
wlr_matrix_translate(&translate_center,
|
||||||
|
-render_width / 2,
|
||||||
-render_height / 2, 0);
|
-render_height / 2, 0);
|
||||||
|
|
||||||
float scale[16];
|
float scale[16];
|
||||||
|
|
|
@ -2,16 +2,44 @@
|
||||||
#include <wlr/types/wlr_cursor.h>
|
#include <wlr/types/wlr_cursor.h>
|
||||||
#include <wlr/types/wlr_xcursor_manager.h>
|
#include <wlr/types/wlr_xcursor_manager.h>
|
||||||
#include "sway/input/cursor.h"
|
#include "sway/input/cursor.h"
|
||||||
|
#include "sway/view.h"
|
||||||
|
#include "list.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
|
static void cursor_update_position(struct sway_cursor *cursor) {
|
||||||
|
double x = cursor->cursor->x;
|
||||||
|
double y = cursor->cursor->y;
|
||||||
|
|
||||||
|
wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager,
|
||||||
|
"left_ptr", cursor->cursor);
|
||||||
|
|
||||||
|
cursor->x = x;
|
||||||
|
cursor->y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void cursor_send_pointer_motion(struct sway_cursor *cursor,
|
||||||
|
uint32_t time) {
|
||||||
|
struct wlr_seat *seat = cursor->seat->seat;
|
||||||
|
struct wlr_surface *surface = NULL;
|
||||||
|
double sx, sy;
|
||||||
|
swayc_t *swayc =
|
||||||
|
swayc_at(&root_container, cursor->x, cursor->y, &surface, &sx, &sy);
|
||||||
|
if (swayc) {
|
||||||
|
wlr_seat_pointer_enter(seat, surface, sx, sy);
|
||||||
|
wlr_seat_pointer_notify_motion(seat, time, sx, sy);
|
||||||
|
} else {
|
||||||
|
wlr_seat_pointer_clear_focus(seat);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void handle_cursor_motion(struct wl_listener *listener, void *data) {
|
static void handle_cursor_motion(struct wl_listener *listener, void *data) {
|
||||||
struct sway_cursor *cursor =
|
struct sway_cursor *cursor =
|
||||||
wl_container_of(listener, cursor, motion);
|
wl_container_of(listener, cursor, motion);
|
||||||
struct wlr_event_pointer_motion *event = data;
|
struct wlr_event_pointer_motion *event = data;
|
||||||
sway_log(L_DEBUG, "TODO: handle cursor motion event: dx=%f, dy=%f", event->delta_x, event->delta_y);
|
wlr_cursor_move(cursor->cursor, event->device,
|
||||||
wlr_cursor_move(cursor->cursor, event->device, event->delta_x, event->delta_y);
|
event->delta_x, event->delta_y);
|
||||||
sway_log(L_DEBUG, "TODO: new x=%f, y=%f", cursor->cursor->x, cursor->cursor->y);
|
cursor_update_position(cursor);
|
||||||
wlr_xcursor_manager_set_cursor_image(cursor->xcursor_manager, "left_ptr", cursor->cursor);
|
cursor_send_pointer_motion(cursor, event->time_msec);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_cursor_motion_absolute(struct wl_listener *listener,
|
static void handle_cursor_motion_absolute(struct wl_listener *listener,
|
||||||
|
@ -19,7 +47,10 @@ static void handle_cursor_motion_absolute(struct wl_listener *listener,
|
||||||
struct sway_cursor *cursor =
|
struct sway_cursor *cursor =
|
||||||
wl_container_of(listener, cursor, motion_absolute);
|
wl_container_of(listener, cursor, motion_absolute);
|
||||||
struct wlr_event_pointer_motion_absolute *event = data;
|
struct wlr_event_pointer_motion_absolute *event = data;
|
||||||
sway_log(L_DEBUG, "TODO: handle event: %p", event);
|
wlr_cursor_warp_absolute(cursor->cursor, event->device,
|
||||||
|
event->x_mm / event->width_mm, event->y_mm / event->height_mm);
|
||||||
|
cursor_update_position(cursor);
|
||||||
|
cursor_send_pointer_motion(cursor, event->time_msec);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_cursor_button(struct wl_listener *listener, void *data) {
|
static void handle_cursor_button(struct wl_listener *listener, void *data) {
|
||||||
|
@ -91,6 +122,7 @@ struct sway_cursor *sway_cursor_create(struct sway_seat *seat) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cursor->seat = seat;
|
||||||
wlr_cursor_attach_output_layout(wlr_cursor, root_container.output_layout);
|
wlr_cursor_attach_output_layout(wlr_cursor, root_container.output_layout);
|
||||||
|
|
||||||
// input events
|
// input events
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <wlr/types/wlr_output_layout.h>
|
#include <wlr/types/wlr_output_layout.h>
|
||||||
|
#include <wlr/types/wlr_wl_shell.h>
|
||||||
#include "sway/container.h"
|
#include "sway/container.h"
|
||||||
#include "sway/layout.h"
|
#include "sway/layout.h"
|
||||||
#include "sway/output.h"
|
#include "sway/output.h"
|
||||||
|
@ -168,3 +169,62 @@ swayc_t *swayc_parent_by_type(swayc_t *container, enum swayc_types type) {
|
||||||
} while (container && container->type != type);
|
} while (container && container->type != type);
|
||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
swayc_t *swayc_at(swayc_t *parent, double lx, double ly,
|
||||||
|
struct wlr_surface **surface, double *sx, double *sy) {
|
||||||
|
list_t *queue = create_list();
|
||||||
|
list_add(queue, parent);
|
||||||
|
|
||||||
|
swayc_t *swayc = NULL;
|
||||||
|
while (queue->length) {
|
||||||
|
swayc = queue->items[0];
|
||||||
|
list_del(queue, 0);
|
||||||
|
if (swayc->type == C_VIEW) {
|
||||||
|
struct sway_view *sview = swayc->sway_view;
|
||||||
|
swayc_t *soutput = swayc_parent_by_type(swayc, C_OUTPUT);
|
||||||
|
struct wlr_box *output_box =
|
||||||
|
wlr_output_layout_get_box(root_container.output_layout,
|
||||||
|
soutput->sway_output->wlr_output);
|
||||||
|
double ox = lx - output_box->x;
|
||||||
|
double oy = ly - output_box->y;
|
||||||
|
double view_sx = ox - swayc->x;
|
||||||
|
double view_sy = oy - swayc->y;
|
||||||
|
int width = swayc->sway_view->surface->current->width;
|
||||||
|
int height = swayc->sway_view->surface->current->height;
|
||||||
|
|
||||||
|
// TODO popups and subsurfaces
|
||||||
|
switch (sview->type) {
|
||||||
|
case SWAY_WL_SHELL_VIEW:
|
||||||
|
break;
|
||||||
|
case SWAY_XDG_SHELL_V6_VIEW:
|
||||||
|
// the top left corner of the sway container is the
|
||||||
|
// coordinate of the top left corner of the window geometry
|
||||||
|
view_sx += sview->wlr_xdg_surface_v6->geometry->x;
|
||||||
|
view_sy += sview->wlr_xdg_surface_v6->geometry->y;
|
||||||
|
break;
|
||||||
|
case SWAY_XWAYLAND_VIEW:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (view_sx > 0 && view_sx < width &&
|
||||||
|
view_sy > 0 && view_sy < height &&
|
||||||
|
pixman_region32_contains_point(
|
||||||
|
&sview->surface->current->input,
|
||||||
|
view_sx, view_sy, NULL)) {
|
||||||
|
*sx = view_sx;
|
||||||
|
*sy = view_sy;
|
||||||
|
*surface = swayc->sway_view->surface;
|
||||||
|
list_free(queue);
|
||||||
|
return swayc;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
list_cat(queue, swayc->children);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
list_free(queue);
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue