mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-05 05:05:57 +01:00
Add wlr_output_set_cursor_surface
This commit is contained in:
parent
65d57920e5
commit
9b83caa658
4 changed files with 50 additions and 12 deletions
|
@ -55,9 +55,15 @@ static void wlr_wl_output_transform(struct wlr_output *_output,
|
||||||
static bool wlr_wl_output_set_cursor(struct wlr_output *_output,
|
static bool wlr_wl_output_set_cursor(struct wlr_output *_output,
|
||||||
const uint8_t *buf, int32_t stride, uint32_t width, uint32_t height,
|
const uint8_t *buf, int32_t stride, uint32_t width, uint32_t height,
|
||||||
int32_t hotspot_x, int32_t hotspot_y) {
|
int32_t hotspot_x, int32_t hotspot_y) {
|
||||||
|
|
||||||
struct wlr_wl_backend_output *output = (struct wlr_wl_backend_output *)_output;
|
struct wlr_wl_backend_output *output = (struct wlr_wl_backend_output *)_output;
|
||||||
struct wlr_wl_backend *backend = output->backend;
|
struct wlr_wl_backend *backend = output->backend;
|
||||||
|
|
||||||
|
if (!buf) {
|
||||||
|
wl_pointer_set_cursor(output->backend->pointer, output->enter_serial,
|
||||||
|
NULL, 0, 0);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
stride *= 4; // stride is given in pixels, we need it in bytes
|
stride *= 4; // stride is given in pixels, we need it in bytes
|
||||||
|
|
||||||
if (!backend->shm || !backend->pointer) {
|
if (!backend->shm || !backend->pointer) {
|
||||||
|
|
|
@ -54,18 +54,22 @@ struct wlr_output {
|
||||||
void *data;
|
void *data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct wlr_surface;
|
||||||
|
|
||||||
void wlr_output_enable(struct wlr_output *output, bool enable);
|
void wlr_output_enable(struct wlr_output *output, bool enable);
|
||||||
bool wlr_output_set_mode(struct wlr_output *output,
|
bool wlr_output_set_mode(struct wlr_output *output,
|
||||||
struct wlr_output_mode *mode);
|
struct wlr_output_mode *mode);
|
||||||
void wlr_output_transform(struct wlr_output *output,
|
void wlr_output_transform(struct wlr_output *output,
|
||||||
enum wl_output_transform transform);
|
enum wl_output_transform transform);
|
||||||
bool wlr_output_set_cursor(struct wlr_output *output,
|
bool wlr_output_set_cursor(struct wlr_output *output,
|
||||||
const uint8_t *buf, int32_t stride, uint32_t width, uint32_t height,
|
const uint8_t *buf, int32_t stride, uint32_t width, uint32_t height,
|
||||||
int32_t hotspot_x, int32_t hotspot_y);
|
int32_t hotspot_x, int32_t hotspot_y);
|
||||||
|
bool wlr_output_set_cursor_surface(struct wlr_output *output,
|
||||||
|
struct wlr_surface *surface, int32_t hotspot_x, int32_t hotspot_y);
|
||||||
bool wlr_output_move_cursor(struct wlr_output *output, int x, int y);
|
bool wlr_output_move_cursor(struct wlr_output *output, int x, int y);
|
||||||
void wlr_output_destroy(struct wlr_output *output);
|
void wlr_output_destroy(struct wlr_output *output);
|
||||||
void wlr_output_effective_resolution(struct wlr_output *output,
|
void wlr_output_effective_resolution(struct wlr_output *output,
|
||||||
int *width, int *height);
|
int *width, int *height);
|
||||||
void wlr_output_make_current(struct wlr_output *output);
|
void wlr_output_make_current(struct wlr_output *output);
|
||||||
void wlr_output_swap_buffers(struct wlr_output *output);
|
void wlr_output_swap_buffers(struct wlr_output *output);
|
||||||
void wlr_output_set_gamma(struct wlr_output *output,
|
void wlr_output_set_gamma(struct wlr_output *output,
|
||||||
|
|
|
@ -278,14 +278,18 @@ static void handle_request_set_cursor(struct wl_listener *listener,
|
||||||
void *data) {
|
void *data) {
|
||||||
struct roots_input *input = wl_container_of(listener, input,
|
struct roots_input *input = wl_container_of(listener, input,
|
||||||
request_set_cursor);
|
request_set_cursor);
|
||||||
//struct wlr_seat_pointer_request_set_cursor_event *event = data;
|
struct wlr_seat_pointer_request_set_cursor_event *event = data;
|
||||||
|
if (event->surface == NULL) {
|
||||||
|
wlr_log(L_DEBUG, "handle_request_set_cursor with NULL surface");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
wlr_log(L_DEBUG, "handle_request_set_cursor");
|
||||||
|
|
||||||
struct wlr_xcursor_image *image = input->xcursor->images[0];
|
|
||||||
struct roots_output *output;
|
struct roots_output *output;
|
||||||
wl_list_for_each(output, &input->server->desktop->outputs, link) {
|
wl_list_for_each(output, &input->server->desktop->outputs, link) {
|
||||||
if (!wlr_output_set_cursor(output->wlr_output, image->buffer,
|
if (!wlr_output_set_cursor_surface(output->wlr_output,
|
||||||
image->width, image->width, image->height,
|
event->surface, event->hotspot_x, event->hotspot_y)) {
|
||||||
image->hotspot_x, image->hotspot_y)) {
|
|
||||||
wlr_log(L_DEBUG, "Failed to set hardware cursor");
|
wlr_log(L_DEBUG, "Failed to set hardware cursor");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <tgmath.h>
|
#include <tgmath.h>
|
||||||
#include <wayland-server.h>
|
#include <wayland-server.h>
|
||||||
#include <wlr/types/wlr_output.h>
|
#include <wlr/types/wlr_output.h>
|
||||||
|
#include <wlr/types/wlr_surface.h>
|
||||||
#include <wlr/interfaces/wlr_output.h>
|
#include <wlr/interfaces/wlr_output.h>
|
||||||
#include <wlr/util/list.h>
|
#include <wlr/util/list.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
|
@ -158,7 +159,8 @@ bool wlr_output_set_cursor(struct wlr_output *output,
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!output->cursor.texture) {
|
if (!output->cursor.texture) {
|
||||||
output->cursor.texture = wlr_render_texture_create(output->cursor.renderer);
|
output->cursor.texture =
|
||||||
|
wlr_render_texture_create(output->cursor.renderer);
|
||||||
if (!output->cursor.texture) {
|
if (!output->cursor.texture) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -168,6 +170,28 @@ bool wlr_output_set_cursor(struct wlr_output *output,
|
||||||
WL_SHM_FORMAT_ARGB8888, stride, width, height, buf);
|
WL_SHM_FORMAT_ARGB8888, stride, width, height, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool wlr_output_set_cursor_surface(struct wlr_output *output,
|
||||||
|
struct wlr_surface *surface, int32_t hotspot_x, int32_t hotspot_y) {
|
||||||
|
if (output->impl->set_cursor) {
|
||||||
|
output->impl->set_cursor(output, NULL, 0, 0, 0, 0, 0);
|
||||||
|
wlr_log(L_INFO, "TODO: wlr_output_set_cursor_surface for hw cursors");
|
||||||
|
}
|
||||||
|
|
||||||
|
output->cursor.is_sw = true;
|
||||||
|
output->cursor.width = surface->current->width;
|
||||||
|
output->cursor.height = surface->current->height;
|
||||||
|
output->cursor.hotspot_x = hotspot_x;
|
||||||
|
output->cursor.hotspot_y = hotspot_y;
|
||||||
|
|
||||||
|
wlr_texture_destroy(output->cursor.texture);
|
||||||
|
output->cursor.texture = surface->texture;
|
||||||
|
|
||||||
|
wlr_renderer_destroy(output->cursor.renderer);
|
||||||
|
output->cursor.renderer = surface->renderer;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
bool wlr_output_move_cursor(struct wlr_output *output, int x, int y) {
|
bool wlr_output_move_cursor(struct wlr_output *output, int x, int y) {
|
||||||
output->cursor.x = x;
|
output->cursor.x = x;
|
||||||
output->cursor.y = y;
|
output->cursor.y = y;
|
||||||
|
|
Loading…
Reference in a new issue