Add xdg shell stubs

This commit is contained in:
Tony Crisci 2017-08-08 08:09:14 -04:00
parent 347707c962
commit c3f15ea284
6 changed files with 164 additions and 1 deletions

1
examples/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/compositor/protocols

View File

@ -19,7 +19,15 @@ struct wl_shell_state {
struct wl_list wl_resources; struct wl_list wl_resources;
}; };
struct xdg_shell_state {
struct wl_global *wl_global;
struct wl_list wl_resources;
};
void wl_shell_init(struct wl_display *display, void wl_shell_init(struct wl_display *display,
struct wl_shell_state *state); struct wl_shell_state *state);
void xdg_shell_init(struct wl_display *display,
struct xdg_shell_state *state);
#endif #endif

View File

@ -0,0 +1,11 @@
#!/usr/bin/env bash
# TODO add me to the build system
set -e
rm -rf xdg-shell
mkdir -p xdg-shell
wayland-scanner code /usr/share/wayland-protocols/unstable/xdg-shell/xdg-shell-unstable-v6.xml xdg-shell/xdg-shell.c
wayland-scanner server-header /usr/share/wayland-protocols/unstable/xdg-shell/xdg-shell-unstable-v6.xml xdg-shell/xdg-shell.h

View File

@ -20,6 +20,7 @@ struct sample_state {
struct wlr_renderer *renderer; struct wlr_renderer *renderer;
struct wl_compositor_state compositor; struct wl_compositor_state compositor;
struct wl_shell_state shell; struct wl_shell_state shell;
struct xdg_shell_state xdg_shell;
}; };
void handle_output_frame(struct output_state *output, struct timespec *ts) { void handle_output_frame(struct output_state *output, struct timespec *ts) {
@ -57,6 +58,7 @@ int main() {
wl_display_init_shm(compositor.display); wl_display_init_shm(compositor.display);
wl_compositor_init(compositor.display, &state.compositor, state.renderer); wl_compositor_init(compositor.display, &state.compositor, state.renderer);
wl_shell_init(compositor.display, &state.shell); wl_shell_init(compositor.display, &state.shell);
xdg_shell_init(compositor.display, &state.xdg_shell);
compositor_run(&compositor); compositor_run(&compositor);
} }

View File

@ -0,0 +1,119 @@
#include <assert.h>
#include <wayland-server.h>
#include <wlr/util/log.h>
#include <stdlib.h>
#include "compositor.h"
#include "compositor/protocols/xdg-shell.h"
static void xdg_surface_destroy(struct wl_client *client,
struct wl_resource *resource) {
wlr_log(L_DEBUG, "TODO xdg surface destroy");
}
static void destroy_xdg_shell_surface(struct wl_resource *resource) {
struct xdg_surface_state *state = wl_resource_get_user_data(resource);
free(state);
}
static void xdg_surface_get_toplevel(struct wl_client *client,
struct wl_resource *resource, uint32_t id) {
wlr_log(L_DEBUG, "TODO xdg surface get toplevel");
}
static void xdg_surface_get_popup(struct wl_client *client,
struct wl_resource *resource, uint32_t id, struct wl_resource *parent,
struct wl_resource *wl_positioner) {
wlr_log(L_DEBUG, "TODO xdg surface get popup");
}
static void xdg_surface_ack_configure(struct wl_client *client,
struct wl_resource *resource, uint32_t serial) {
wlr_log(L_DEBUG, "TODO xdg surface ack configure");
}
static void xdg_surface_set_window_geometry(struct wl_client *client,
struct wl_resource *resource, int32_t x, int32_t y, int32_t width,
int32_t height) {
wlr_log(L_DEBUG, "TODO xdg surface set window geometry");
}
static const struct zxdg_surface_v6_interface zxdg_surface_v6_implementation = {
.destroy = xdg_surface_destroy,
.get_toplevel = xdg_surface_get_toplevel,
.get_popup = xdg_surface_get_popup,
.ack_configure = xdg_surface_ack_configure,
.set_window_geometry = xdg_surface_set_window_geometry,
};
struct xdg_surface_state {
struct wlr_surface *wlr_surface;
};
static void xdg_shell_destroy(struct wl_client *client,
struct wl_resource *resource) {
wlr_log(L_DEBUG, "TODO: xdg shell destroy");
}
static void xdg_shell_create_positioner(struct wl_client *client,
struct wl_resource *resource, uint32_t id) {
wlr_log(L_DEBUG, "TODO: xdg shell create positioner");
}
static void xdg_shell_get_xdg_surface(struct wl_client *client, struct
wl_resource *resource, uint32_t id,
struct wl_resource *surface_resource) {
struct wlr_surface *wlr_surface = wl_resource_get_user_data(surface_resource);
struct xdg_surface_state *state = malloc(sizeof(struct xdg_surface_state));
state->wlr_surface = wlr_surface;
struct wl_resource *shell_surface_resource = wl_resource_create(client,
&zxdg_surface_v6_interface, wl_resource_get_version(resource), id);
wl_resource_set_implementation(shell_surface_resource,
&zxdg_surface_v6_implementation, state, destroy_xdg_shell_surface);
}
static void xdg_shell_pong(struct wl_client *client, struct wl_resource *resource, uint32_t serial) {
wlr_log(L_DEBUG, "TODO xdg shell pong");
}
static struct zxdg_shell_v6_interface xdg_shell_impl = {
.destroy = xdg_shell_destroy,
.create_positioner = xdg_shell_create_positioner,
.get_xdg_surface = xdg_shell_get_xdg_surface,
.pong = xdg_shell_pong,
};
static void xdg_destroy_shell(struct wl_resource *resource) {
struct xdg_shell_state *state = wl_resource_get_user_data(resource);
struct wl_resource *_resource = NULL;
wl_resource_for_each(_resource, &state->wl_resources) {
if (_resource == resource) {
struct wl_list *link = wl_resource_get_link(_resource);
wl_list_remove(link);
break;
}
}
}
static void xdg_shell_bind(struct wl_client *wl_client, void *_state,
uint32_t version, uint32_t id) {
struct xdg_shell_state *state = _state;
assert(wl_client && state);
if (version > 1) {
wlr_log(L_ERROR, "Client requested unsupported wl_shell version, disconnecting");
wl_client_destroy(wl_client);
return;
}
struct wl_resource *wl_resource = wl_resource_create(
wl_client, &zxdg_shell_v6_interface, version, id);
wl_resource_set_implementation(wl_resource, &xdg_shell_impl,
state, xdg_destroy_shell);
wl_list_insert(&state->wl_resources, wl_resource_get_link(wl_resource));
}
void xdg_shell_init(struct wl_display *display, struct xdg_shell_state *state) {
struct wl_global *wl_global = wl_global_create(display,
&zxdg_shell_v6_interface, 1, state, xdg_shell_bind);
state->wl_global = wl_global;
wl_list_init(&state->wl_resources);
}

View File

@ -11,7 +11,29 @@ executable('tablet', 'tablet.c', dependencies: dep_wlr, link_with: lib_shared)
compositor_src = [ compositor_src = [
'compositor/main.c', 'compositor/main.c',
'compositor/wl_compositor.c', 'compositor/wl_compositor.c',
'compositor/wl_shell.c' 'compositor/wl_shell.c',
'compositor/xdg_shell.c',
'compositor/protocols/xdg-shell.c',
] ]
wayland_scanner = find_program('wayland-scanner')
wayland_protocols_pkgdatadir = dep_wayland_proto.get_pkgconfig_variable('pkgdatadir')
protocols_src = meson.current_source_dir() + '/compositor/protocols'
run_command(['mkdir', '-p', protocols_src])
protocols = [
['/unstable/xdg-shell/xdg-shell-unstable-v6.xml', 'xdg-shell']
]
foreach p : protocols
xml = wayland_protocols_pkgdatadir + p[0]
run_command([wayland_scanner, 'code', xml,
protocols_src + '/' + p[1] + '.c'])
run_command([wayland_scanner, 'server-header', xml,
protocols_src + '/' + p[1] + '.h'])
endforeach
executable('compositor', compositor_src, dependencies: dep_wlr, link_with: lib_shared) executable('compositor', compositor_src, dependencies: dep_wlr, link_with: lib_shared)