mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-12-23 10:29:49 +01:00
Merge pull request #98 from martinetd/wayland_backend_xdg
Wayland backend xdg
This commit is contained in:
commit
30b676e3a8
6 changed files with 97 additions and 33 deletions
|
@ -31,4 +31,4 @@ endif
|
||||||
|
|
||||||
lib_wlr_backend = static_library('wlr_backend', backend_files,
|
lib_wlr_backend = static_library('wlr_backend', backend_files,
|
||||||
include_directories: wlr_inc,
|
include_directories: wlr_inc,
|
||||||
dependencies: [wayland_server, egl, gbm, libinput, systemd])
|
dependencies: [wayland_server, egl, gbm, libinput, systemd, wlr_protos])
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
#include <wlr/interfaces/wlr_input_device.h>
|
#include <wlr/interfaces/wlr_input_device.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
#include "backend/wayland.h"
|
#include "backend/wayland.h"
|
||||||
|
#include "xdg-shell-unstable-v6-client-protocol.h"
|
||||||
|
|
||||||
|
|
||||||
static int dispatch_events(int fd, uint32_t mask, void *data) {
|
static int dispatch_events(int fd, uint32_t mask, void *data) {
|
||||||
struct wlr_wl_backend *backend = data;
|
struct wlr_wl_backend *backend = data;
|
||||||
|
@ -89,7 +91,7 @@ static void wlr_wl_backend_destroy(struct wlr_backend *_backend) {
|
||||||
wlr_egl_free(&backend->egl);
|
wlr_egl_free(&backend->egl);
|
||||||
if (backend->seat) wl_seat_destroy(backend->seat);
|
if (backend->seat) wl_seat_destroy(backend->seat);
|
||||||
if (backend->shm) wl_shm_destroy(backend->shm);
|
if (backend->shm) wl_shm_destroy(backend->shm);
|
||||||
if (backend->shell) wl_shell_destroy(backend->shell);
|
if (backend->shell) zxdg_shell_v6_destroy(backend->shell);
|
||||||
if (backend->compositor) wl_compositor_destroy(backend->compositor);
|
if (backend->compositor) wl_compositor_destroy(backend->compositor);
|
||||||
if (backend->registry) wl_registry_destroy(backend->registry);
|
if (backend->registry) wl_registry_destroy(backend->registry);
|
||||||
if (backend->remote_display) wl_display_disconnect(backend->remote_display);
|
if (backend->remote_display) wl_display_disconnect(backend->remote_display);
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
#include <wlr/interfaces/wlr_output.h>
|
#include <wlr/interfaces/wlr_output.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
#include "backend/wayland.h"
|
#include "backend/wayland.h"
|
||||||
|
#include "xdg-shell-unstable-v6-client-protocol.h"
|
||||||
|
|
||||||
int os_create_anonymous_file(off_t size);
|
int os_create_anonymous_file(off_t size);
|
||||||
|
|
||||||
|
@ -136,7 +137,8 @@ static void wlr_wl_output_destroy(struct wlr_output *_output) {
|
||||||
}
|
}
|
||||||
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);
|
||||||
wl_shell_surface_destroy(output->shell_surface);
|
zxdg_toplevel_v6_destroy(output->xdg_toplevel);
|
||||||
|
zxdg_surface_v6_destroy(output->xdg_surface);
|
||||||
wl_surface_destroy(output->surface);
|
wl_surface_destroy(output->surface);
|
||||||
free(output);
|
free(output);
|
||||||
}
|
}
|
||||||
|
@ -162,16 +164,29 @@ static struct wlr_output_impl output_impl = {
|
||||||
.move_cursor = wlr_wl_output_move_cursor
|
.move_cursor = wlr_wl_output_move_cursor
|
||||||
};
|
};
|
||||||
|
|
||||||
void handle_ping(void *data, struct wl_shell_surface *ssurface, uint32_t serial) {
|
static void xdg_surface_handle_configure(void *data, struct zxdg_surface_v6 *xdg_surface,
|
||||||
|
uint32_t serial) {
|
||||||
struct wlr_wl_backend_output *output = data;
|
struct wlr_wl_backend_output *output = data;
|
||||||
assert(output && output->shell_surface == ssurface);
|
assert(output && output->xdg_surface == xdg_surface);
|
||||||
wl_shell_surface_pong(ssurface, serial);
|
|
||||||
|
zxdg_surface_v6_ack_configure(xdg_surface, serial);
|
||||||
|
|
||||||
|
// nothing else?
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_configure(void *data, struct wl_shell_surface *wl_shell_surface,
|
static struct zxdg_surface_v6_listener xdg_surface_listener = {
|
||||||
uint32_t edges, int32_t width, int32_t height){
|
.configure = xdg_surface_handle_configure,
|
||||||
|
};
|
||||||
|
|
||||||
|
static void xdg_toplevel_handle_configure(void *data, struct zxdg_toplevel_v6 *xdg_toplevel,
|
||||||
|
int32_t width, int32_t height, struct wl_array *states) {
|
||||||
struct wlr_wl_backend_output *output = data;
|
struct wlr_wl_backend_output *output = data;
|
||||||
assert(output && output->shell_surface == wl_shell_surface);
|
assert(output && output->xdg_toplevel == xdg_toplevel);
|
||||||
|
|
||||||
|
if (width == 0 && height == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// loop over states for maximized etc?
|
||||||
wl_egl_window_resize(output->egl_window, width, height, 0, 0);
|
wl_egl_window_resize(output->egl_window, width, height, 0, 0);
|
||||||
output->wlr_output.width = width;
|
output->wlr_output.width = width;
|
||||||
output->wlr_output.height = height;
|
output->wlr_output.height = height;
|
||||||
|
@ -179,14 +194,16 @@ void handle_configure(void *data, struct wl_shell_surface *wl_shell_surface,
|
||||||
wl_signal_emit(&output->wlr_output.events.resolution, output);
|
wl_signal_emit(&output->wlr_output.events.resolution, output);
|
||||||
}
|
}
|
||||||
|
|
||||||
void handle_popup_done(void *data, struct wl_shell_surface *wl_shell_surface) {
|
static void xdg_toplevel_handle_close(void *data, struct zxdg_toplevel_v6 *xdg_toplevel) {
|
||||||
wlr_log(L_ERROR, "Unexpected wl_shell_surface.popup_done event");
|
struct wlr_wl_backend_output *output = data;
|
||||||
|
assert(output && output->xdg_toplevel == xdg_toplevel);
|
||||||
|
|
||||||
|
wl_display_terminate(output->backend->local_display);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct wl_shell_surface_listener shell_surface_listener = {
|
static struct zxdg_toplevel_v6_listener xdg_toplevel_listener = {
|
||||||
.ping = handle_ping,
|
.configure = xdg_toplevel_handle_configure,
|
||||||
.configure = handle_configure,
|
.close = xdg_toplevel_handle_close,
|
||||||
.popup_done = handle_popup_done
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct wlr_output *wlr_wl_output_create(struct wlr_backend *_backend) {
|
struct wlr_output *wlr_wl_output_create(struct wlr_backend *_backend) {
|
||||||
|
@ -216,28 +233,44 @@ struct wlr_output *wlr_wl_output_create(struct wlr_backend *_backend) {
|
||||||
|
|
||||||
output->backend = backend;
|
output->backend = backend;
|
||||||
|
|
||||||
// TODO: error handling
|
|
||||||
output->surface = wl_compositor_create_surface(backend->compositor);
|
output->surface = wl_compositor_create_surface(backend->compositor);
|
||||||
output->shell_surface =
|
if (!output->surface) {
|
||||||
wl_shell_get_shell_surface(backend->shell, output->surface);
|
wlr_log_errno(L_ERROR, "Could not create output surface");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
output->xdg_surface =
|
||||||
|
zxdg_shell_v6_get_xdg_surface(backend->shell, output->surface);
|
||||||
|
if (!output->xdg_surface) {
|
||||||
|
wlr_log_errno(L_ERROR, "Could not get xdg surface");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
output->xdg_toplevel =
|
||||||
|
zxdg_surface_v6_get_toplevel(output->xdg_surface);
|
||||||
|
if (!output->xdg_toplevel) {
|
||||||
|
wlr_log_errno(L_ERROR, "Could not get xdg toplevel");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
wl_shell_surface_set_class(output->shell_surface, "sway");
|
zxdg_toplevel_v6_set_app_id(output->xdg_toplevel, "wlroots");
|
||||||
wl_shell_surface_set_title(output->shell_surface, "sway-wl");
|
zxdg_toplevel_v6_set_title(output->xdg_toplevel, "wlroots");
|
||||||
wl_shell_surface_add_listener(output->shell_surface,
|
zxdg_surface_v6_add_listener(output->xdg_surface,
|
||||||
&shell_surface_listener, output);
|
&xdg_surface_listener, output);
|
||||||
wl_shell_surface_set_toplevel(output->shell_surface);
|
zxdg_toplevel_v6_add_listener(output->xdg_toplevel,
|
||||||
|
&xdg_toplevel_listener, output);
|
||||||
|
wl_surface_commit(output->surface);
|
||||||
|
|
||||||
output->egl_window = wl_egl_window_create(output->surface,
|
output->egl_window = wl_egl_window_create(output->surface,
|
||||||
wlr_output->width, wlr_output->height);
|
wlr_output->width, wlr_output->height);
|
||||||
output->egl_surface = wlr_egl_create_surface(&backend->egl, output->egl_window);
|
output->egl_surface = wlr_egl_create_surface(&backend->egl, output->egl_window);
|
||||||
|
|
||||||
|
wl_display_roundtrip(output->backend->remote_display);
|
||||||
|
|
||||||
// start rendering loop per callbacks by rendering first frame
|
// start rendering loop per callbacks by rendering first frame
|
||||||
if (!eglMakeCurrent(output->backend->egl.display,
|
if (!eglMakeCurrent(output->backend->egl.display,
|
||||||
output->egl_surface, output->egl_surface,
|
output->egl_surface, output->egl_surface,
|
||||||
output->backend->egl.context)) {
|
output->backend->egl.context)) {
|
||||||
wlr_log(L_ERROR, "eglMakeCurrent failed: %s", egl_error());
|
wlr_log(L_ERROR, "eglMakeCurrent failed: %s", egl_error());
|
||||||
free(output);
|
goto error;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
glViewport(0, 0, wlr_output->width, wlr_output->height);
|
glViewport(0, 0, wlr_output->width, wlr_output->height);
|
||||||
|
@ -249,16 +282,18 @@ struct wlr_output *wlr_wl_output_create(struct wlr_backend *_backend) {
|
||||||
|
|
||||||
if (!eglSwapBuffers(output->backend->egl.display, output->egl_surface)) {
|
if (!eglSwapBuffers(output->backend->egl.display, output->egl_surface)) {
|
||||||
wlr_log(L_ERROR, "eglSwapBuffers failed: %s", egl_error());
|
wlr_log(L_ERROR, "eglSwapBuffers failed: %s", egl_error());
|
||||||
free(output);
|
goto error;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (list_add(backend->outputs, wlr_output) == -1) {
|
if (list_add(backend->outputs, wlr_output) == -1) {
|
||||||
wlr_log(L_ERROR, "Allocation failed");
|
wlr_log(L_ERROR, "Allocation failed");
|
||||||
free(output);
|
goto error;
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
wlr_output_create_global(wlr_output, backend->local_display);
|
wlr_output_create_global(wlr_output, backend->local_display);
|
||||||
wl_signal_emit(&backend->backend.events.output_add, wlr_output);
|
wl_signal_emit(&backend->backend.events.output_add, wlr_output);
|
||||||
return wlr_output;
|
return wlr_output;
|
||||||
|
|
||||||
|
error:
|
||||||
|
wlr_output_destroy(&output->wlr_output);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,18 @@
|
||||||
#include <wayland-client.h>
|
#include <wayland-client.h>
|
||||||
#include <wlr/util/log.h>
|
#include <wlr/util/log.h>
|
||||||
#include "backend/wayland.h"
|
#include "backend/wayland.h"
|
||||||
|
#include "xdg-shell-unstable-v6-client-protocol.h"
|
||||||
|
|
||||||
|
|
||||||
|
static void xdg_shell_handle_ping(void *data, struct zxdg_shell_v6 *shell,
|
||||||
|
uint32_t serial) {
|
||||||
|
zxdg_shell_v6_pong(shell, serial);
|
||||||
|
}
|
||||||
|
|
||||||
|
static const struct zxdg_shell_v6_listener xdg_shell_listener = {
|
||||||
|
xdg_shell_handle_ping,
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
static void registry_global(void *data, struct wl_registry *registry,
|
static void registry_global(void *data, struct wl_registry *registry,
|
||||||
uint32_t name, const char *interface, uint32_t version) {
|
uint32_t name, const char *interface, uint32_t version) {
|
||||||
|
@ -13,9 +25,10 @@ static void registry_global(void *data, struct wl_registry *registry,
|
||||||
if (strcmp(interface, wl_compositor_interface.name) == 0) {
|
if (strcmp(interface, wl_compositor_interface.name) == 0) {
|
||||||
backend->compositor = wl_registry_bind(registry, name,
|
backend->compositor = wl_registry_bind(registry, name,
|
||||||
&wl_compositor_interface, version);
|
&wl_compositor_interface, version);
|
||||||
} else if (strcmp(interface, wl_shell_interface.name) == 0) {
|
} else if (strcmp(interface, zxdg_shell_v6_interface.name) == 0) {
|
||||||
backend->shell = wl_registry_bind(registry, name,
|
backend->shell = wl_registry_bind(registry, name,
|
||||||
&wl_shell_interface, version);
|
&zxdg_shell_v6_interface, version);
|
||||||
|
zxdg_shell_v6_add_listener(backend->shell, &xdg_shell_listener, NULL);
|
||||||
} else if (strcmp(interface, wl_shm_interface.name) == 0) {
|
} else if (strcmp(interface, wl_shm_interface.name) == 0) {
|
||||||
backend->shm = wl_registry_bind(registry, name,
|
backend->shm = wl_registry_bind(registry, name,
|
||||||
&wl_shm_interface, version);
|
&wl_shm_interface, version);
|
||||||
|
|
|
@ -24,7 +24,7 @@ struct wlr_wl_backend {
|
||||||
struct wl_event_source *remote_display_src;
|
struct wl_event_source *remote_display_src;
|
||||||
struct wl_registry *registry;
|
struct wl_registry *registry;
|
||||||
struct wl_compositor *compositor;
|
struct wl_compositor *compositor;
|
||||||
struct wl_shell *shell;
|
struct zxdg_shell_v6 *shell;
|
||||||
struct wl_shm *shm;
|
struct wl_shm *shm;
|
||||||
struct wl_seat *seat;
|
struct wl_seat *seat;
|
||||||
struct wl_pointer *pointer;
|
struct wl_pointer *pointer;
|
||||||
|
@ -36,7 +36,8 @@ struct wlr_wl_backend_output {
|
||||||
|
|
||||||
struct wlr_wl_backend *backend;
|
struct wlr_wl_backend *backend;
|
||||||
struct wl_surface *surface;
|
struct wl_surface *surface;
|
||||||
struct wl_shell_surface *shell_surface;
|
struct zxdg_surface_v6 *xdg_surface;
|
||||||
|
struct zxdg_toplevel_v6 *xdg_toplevel;
|
||||||
struct wl_egl_window *egl_window;
|
struct wl_egl_window *egl_window;
|
||||||
struct wl_callback *frame_callback;
|
struct wl_callback *frame_callback;
|
||||||
|
|
||||||
|
|
|
@ -10,10 +10,18 @@ wayland_scanner_code = generator(wayland_scanner,
|
||||||
output: '@BASENAME@-protocol.c',
|
output: '@BASENAME@-protocol.c',
|
||||||
arguments: ['code', '@INPUT@', '@OUTPUT@'])
|
arguments: ['code', '@INPUT@', '@OUTPUT@'])
|
||||||
|
|
||||||
|
wayland_scanner_client = generator(wayland_scanner,
|
||||||
|
output: '@BASENAME@-client-protocol.h',
|
||||||
|
arguments: ['client-header', '@INPUT@', '@OUTPUT@'])
|
||||||
|
|
||||||
protocols = [
|
protocols = [
|
||||||
[ wl_protocol_dir, 'unstable/xdg-shell/xdg-shell-unstable-v6.xml' ]
|
[ wl_protocol_dir, 'unstable/xdg-shell/xdg-shell-unstable-v6.xml' ]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
client_protocols = [
|
||||||
|
[ wl_protocol_dir, 'unstable/xdg-shell/xdg-shell-unstable-v6.xml' ]
|
||||||
|
]
|
||||||
|
|
||||||
wl_protos_src = []
|
wl_protos_src = []
|
||||||
wl_protos_headers = []
|
wl_protos_headers = []
|
||||||
|
|
||||||
|
@ -23,6 +31,11 @@ foreach p : protocols
|
||||||
wl_protos_headers += wayland_scanner_server.process(xml)
|
wl_protos_headers += wayland_scanner_server.process(xml)
|
||||||
endforeach
|
endforeach
|
||||||
|
|
||||||
|
foreach p : client_protocols
|
||||||
|
xml = join_paths(p)
|
||||||
|
wl_protos_headers += wayland_scanner_client.process(xml)
|
||||||
|
endforeach
|
||||||
|
|
||||||
lib_wl_protos = static_library('wl_protos', wl_protos_src + wl_protos_headers)
|
lib_wl_protos = static_library('wl_protos', wl_protos_src + wl_protos_headers)
|
||||||
wlr_protos = declare_dependency(
|
wlr_protos = declare_dependency(
|
||||||
link_with: lib_wl_protos,
|
link_with: lib_wl_protos,
|
||||||
|
|
Loading…
Reference in a new issue