mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-02 03:45:58 +01:00
Merge pull request #485 from emersion/wl-backend-multiple-outputs
Multiple outputs with Wayland backend
This commit is contained in:
commit
a9fb071d49
5 changed files with 57 additions and 10 deletions
|
@ -1,6 +1,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <EGL/egl.h>
|
#include <EGL/egl.h>
|
||||||
#include <EGL/eglext.h>
|
#include <EGL/eglext.h>
|
||||||
#include <wayland-server.h>
|
#include <wayland-server.h>
|
||||||
|
@ -117,6 +118,38 @@ struct wlr_wl_backend_output *wlr_wl_output_for_surface(
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wlr_wl_output_layout_get_box(struct wlr_wl_backend *backend,
|
||||||
|
struct wlr_box *box) {
|
||||||
|
int min_x = INT_MAX, min_y = INT_MAX;
|
||||||
|
int max_x = INT_MIN, max_y = INT_MIN;
|
||||||
|
|
||||||
|
struct wlr_wl_backend_output *output;
|
||||||
|
wl_list_for_each(output, &backend->outputs, link) {
|
||||||
|
struct wlr_output *wlr_output = &output->wlr_output;
|
||||||
|
|
||||||
|
int width, height;
|
||||||
|
wlr_output_effective_resolution(wlr_output, &width, &height);
|
||||||
|
|
||||||
|
if (wlr_output->lx < min_x) {
|
||||||
|
min_x = wlr_output->lx;
|
||||||
|
}
|
||||||
|
if (wlr_output->ly < min_y) {
|
||||||
|
min_y = wlr_output->ly;
|
||||||
|
}
|
||||||
|
if (wlr_output->lx + width > max_x) {
|
||||||
|
max_x = wlr_output->lx + width;
|
||||||
|
}
|
||||||
|
if (wlr_output->ly + height > max_y) {
|
||||||
|
max_y = wlr_output->ly + height;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
box->x = min_x;
|
||||||
|
box->y = min_y;
|
||||||
|
box->width = max_x - min_x;
|
||||||
|
box->height = max_y - min_y;
|
||||||
|
}
|
||||||
|
|
||||||
struct wlr_backend *wlr_wl_backend_create(struct wl_display *display) {
|
struct wlr_backend *wlr_wl_backend_create(struct wl_display *display) {
|
||||||
wlr_log(L_INFO, "Creating wayland backend");
|
wlr_log(L_INFO, "Creating wayland backend");
|
||||||
|
|
||||||
|
|
|
@ -154,6 +154,8 @@ static void wlr_wl_output_destroy(struct wlr_output *_output) {
|
||||||
wl_signal_emit(&output->backend->backend.events.output_remove,
|
wl_signal_emit(&output->backend->backend.events.output_remove,
|
||||||
&output->wlr_output);
|
&output->wlr_output);
|
||||||
|
|
||||||
|
wl_list_remove(&output->link);
|
||||||
|
|
||||||
if (output->cursor.buf_size != 0) {
|
if (output->cursor.buf_size != 0) {
|
||||||
assert(output->cursor.data);
|
assert(output->cursor.data);
|
||||||
assert(output->cursor.buffer);
|
assert(output->cursor.buffer);
|
||||||
|
@ -171,6 +173,7 @@ static void wlr_wl_output_destroy(struct wlr_output *_output) {
|
||||||
if (output->frame_callback) {
|
if (output->frame_callback) {
|
||||||
wl_callback_destroy(output->frame_callback);
|
wl_callback_destroy(output->frame_callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
eglDestroySurface(output->backend->egl.display, output->surface);
|
eglDestroySurface(output->backend->egl.display, output->surface);
|
||||||
wl_egl_window_destroy(output->egl_window);
|
wl_egl_window_destroy(output->egl_window);
|
||||||
zxdg_toplevel_v6_destroy(output->xdg_toplevel);
|
zxdg_toplevel_v6_destroy(output->xdg_toplevel);
|
||||||
|
@ -233,7 +236,7 @@ static void xdg_toplevel_handle_close(void *data, struct zxdg_toplevel_v6 *xdg_t
|
||||||
struct wlr_wl_backend_output *output = data;
|
struct wlr_wl_backend_output *output = data;
|
||||||
assert(output && output->xdg_toplevel == xdg_toplevel);
|
assert(output && output->xdg_toplevel == xdg_toplevel);
|
||||||
|
|
||||||
wl_display_terminate(output->backend->local_display);
|
wlr_output_destroy((struct wlr_output *)output);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct zxdg_toplevel_v6_listener xdg_toplevel_listener = {
|
static struct zxdg_toplevel_v6_listener xdg_toplevel_listener = {
|
||||||
|
|
|
@ -21,7 +21,10 @@ static void pointer_handle_enter(void *data, struct wl_pointer *wl_pointer,
|
||||||
struct wlr_wl_pointer *wlr_wl_pointer = (struct wlr_wl_pointer *)dev->pointer;
|
struct wlr_wl_pointer *wlr_wl_pointer = (struct wlr_wl_pointer *)dev->pointer;
|
||||||
struct wlr_wl_backend_output *output =
|
struct wlr_wl_backend_output *output =
|
||||||
wlr_wl_output_for_surface(wlr_wl_dev->backend, surface);
|
wlr_wl_output_for_surface(wlr_wl_dev->backend, surface);
|
||||||
assert(output);
|
if (!output) {
|
||||||
|
// GNOME sends a pointer enter when the surface is being destroyed
|
||||||
|
return;
|
||||||
|
}
|
||||||
wlr_wl_pointer->current_output = output;
|
wlr_wl_pointer->current_output = output;
|
||||||
output->enter_serial = serial;
|
output->enter_serial = serial;
|
||||||
wlr_wl_output_update_cursor(output);
|
wlr_wl_output_update_cursor(output);
|
||||||
|
@ -49,23 +52,28 @@ static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct wlr_output *wlr_output = &wlr_wl_pointer->current_output->wlr_output;
|
||||||
|
|
||||||
struct wlr_box box;
|
struct wlr_box box;
|
||||||
wl_egl_window_get_attached_size(wlr_wl_pointer->current_output->egl_window,
|
wl_egl_window_get_attached_size(wlr_wl_pointer->current_output->egl_window,
|
||||||
&box.width, &box.height);
|
&box.width, &box.height);
|
||||||
box.x = wl_fixed_to_int(surface_x);
|
box.x = wl_fixed_to_int(surface_x);
|
||||||
box.y = wl_fixed_to_int(surface_y);
|
box.y = wl_fixed_to_int(surface_y);
|
||||||
struct wlr_box transformed;
|
struct wlr_box transformed;
|
||||||
wlr_output_transform_apply_to_box(
|
wlr_output_transform_apply_to_box(wlr_output->transform, &box, &transformed);
|
||||||
wlr_wl_pointer->current_output->wlr_output.transform, &box,
|
box.x /= wlr_output->scale;
|
||||||
&transformed);
|
box.y /= wlr_output->scale;
|
||||||
|
|
||||||
|
struct wlr_box layout_box;
|
||||||
|
wlr_wl_output_layout_get_box(wlr_wl_pointer->current_output->backend, &layout_box);
|
||||||
|
|
||||||
struct wlr_event_pointer_motion_absolute wlr_event;
|
struct wlr_event_pointer_motion_absolute wlr_event;
|
||||||
wlr_event.device = dev;
|
wlr_event.device = dev;
|
||||||
wlr_event.time_msec = time;
|
wlr_event.time_msec = time;
|
||||||
wlr_event.width_mm = transformed.width;
|
wlr_event.width_mm = layout_box.width;
|
||||||
wlr_event.height_mm = transformed.height;
|
wlr_event.height_mm = layout_box.height;
|
||||||
wlr_event.x_mm = transformed.x;
|
wlr_event.x_mm = transformed.x + wlr_output->lx + layout_box.x;
|
||||||
wlr_event.y_mm = transformed.y;
|
wlr_event.y_mm = transformed.y + wlr_output->ly + layout_box.y;
|
||||||
wl_signal_emit(&dev->pointer->events.motion_absolute, &wlr_event);
|
wl_signal_emit(&dev->pointer->events.motion_absolute, &wlr_event);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
#include <wayland-egl.h>
|
#include <wayland-egl.h>
|
||||||
#include <wlr/render/egl.h>
|
#include <wlr/render/egl.h>
|
||||||
#include <wlr/backend/wayland.h>
|
#include <wlr/backend/wayland.h>
|
||||||
|
#include <wlr/types/wlr_box.h>
|
||||||
#include <wlr/types/wlr_output.h>
|
#include <wlr/types/wlr_output.h>
|
||||||
#include <wlr/types/wlr_input_device.h>
|
#include <wlr/types/wlr_input_device.h>
|
||||||
#include <wayland-util.h>
|
#include <wayland-util.h>
|
||||||
|
@ -75,6 +76,8 @@ void wlr_wl_registry_poll(struct wlr_wl_backend *backend);
|
||||||
void wlr_wl_output_update_cursor(struct wlr_wl_backend_output *output);
|
void wlr_wl_output_update_cursor(struct wlr_wl_backend_output *output);
|
||||||
struct wlr_wl_backend_output *wlr_wl_output_for_surface(
|
struct wlr_wl_backend_output *wlr_wl_output_for_surface(
|
||||||
struct wlr_wl_backend *backend, struct wl_surface *surface);
|
struct wlr_wl_backend *backend, struct wl_surface *surface);
|
||||||
|
void wlr_wl_output_layout_get_box(struct wlr_wl_backend *backend,
|
||||||
|
struct wlr_box *box);
|
||||||
|
|
||||||
extern const struct wl_seat_listener seat_listener;
|
extern const struct wl_seat_listener seat_listener;
|
||||||
|
|
||||||
|
|
|
@ -272,9 +272,9 @@ void wlr_output_destroy(struct wlr_output *output) {
|
||||||
|
|
||||||
struct wlr_output_mode *mode, *tmp_mode;
|
struct wlr_output_mode *mode, *tmp_mode;
|
||||||
wl_list_for_each_safe(mode, tmp_mode, &output->modes, link) {
|
wl_list_for_each_safe(mode, tmp_mode, &output->modes, link) {
|
||||||
|
wl_list_remove(&mode->link);
|
||||||
free(mode);
|
free(mode);
|
||||||
}
|
}
|
||||||
wl_list_remove(&output->modes);
|
|
||||||
if (output->impl && output->impl->destroy) {
|
if (output->impl && output->impl->destroy) {
|
||||||
output->impl->destroy(output);
|
output->impl->destroy(output);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue