Refactor meson and move xdg-shell into wlroots

This commit is contained in:
Drew DeVault 2017-08-11 09:37:09 -04:00
parent a6efb90382
commit 62d8b252c0
11 changed files with 232 additions and 177 deletions

View file

@ -1,29 +1,33 @@
wlr_files += files(
'backend.c',
'udev.c',
'session/direct-ipc.c',
'session/direct.c',
'session/session.c',
'drm/backend.c',
'drm/drm.c',
'drm/drm-atomic.c',
'drm/drm-legacy.c',
'drm/drm-properties.c',
'drm/drm-util.c',
'libinput/backend.c',
'libinput/events.c',
'libinput/keyboard.c',
'libinput/pointer.c',
'libinput/tablet_pad.c',
'libinput/tablet_tool.c',
'libinput/touch.c',
'multi/backend.c',
'wayland/backend.c',
'wayland/output.c',
'wayland/registry.c',
'wayland/wl_seat.c',
backend_files = files(
'backend.c',
'udev.c',
'session/direct-ipc.c',
'session/direct.c',
'session/session.c',
'drm/backend.c',
'drm/drm.c',
'drm/drm-atomic.c',
'drm/drm-legacy.c',
'drm/drm-properties.c',
'drm/drm-util.c',
'libinput/backend.c',
'libinput/events.c',
'libinput/keyboard.c',
'libinput/pointer.c',
'libinput/tablet_pad.c',
'libinput/tablet_tool.c',
'libinput/touch.c',
'multi/backend.c',
'wayland/backend.c',
'wayland/output.c',
'wayland/registry.c',
'wayland/wl_seat.c',
)
if dep_systemd.found()
wlr_files += files('session/logind.c')
if systemd.found()
wlr_files += files('session/logind.c')
endif
lib_wlr_backend = static_library('wlr_backend', backend_files,
include_directories: wlr_inc,
dependencies: [wayland_server, egl, gbm, libinput, systemd])

View file

@ -11,6 +11,7 @@
#include <wlr/render/gles2.h>
#include <wlr/types/wlr_output.h>
#include <wlr/types/wlr_surface.h>
#include <wlr/types/wlr_xdg_shell_v6.h>
#include <xkbcommon/xkbcommon.h>
#include <wlr/util/log.h>
#include "shared.h"
@ -20,7 +21,7 @@ struct sample_state {
struct wlr_renderer *renderer;
struct wl_compositor_state compositor;
struct wl_shell_state shell;
struct xdg_shell_state xdg_shell;
struct wlr_xdg_shell_v6 *xdg_shell;
};
/*
@ -72,9 +73,7 @@ int main() {
wl_display_init_shm(compositor.display);
wl_compositor_init(compositor.display, &state.compositor, state.renderer);
wl_shell_init(compositor.display, &state.shell);
xdg_shell_init(compositor.display, &state.xdg_shell);
state.xdg_shell = wlr_xdg_shell_v6_init(compositor.display);
compositor_run(&compositor);
xdg_shell_release(&state.xdg_shell);
}

View file

@ -1,39 +1,19 @@
lib_shared = static_library('shared',
['shared.c', 'cat.c'],
dependencies: dep_wlr)
dependencies: wlroots)
executable('simple', 'simple.c', dependencies: dep_wlr, link_with: lib_shared)
executable('rotation', 'rotation.c', dependencies: dep_wlr, link_with: lib_shared)
executable('pointer', 'pointer.c', dependencies: dep_wlr, link_with: lib_shared)
executable('touch', 'touch.c', dependencies: dep_wlr, link_with: lib_shared)
executable('tablet', 'tablet.c', dependencies: dep_wlr, link_with: lib_shared)
wayland_scanner = find_program('wayland-scanner')
wl_protocol_dir = dep_wayland_proto.get_pkgconfig_variable('pkgdatadir')
wayland_scanner_server = generator(wayland_scanner,
output: '@BASENAME@-protocol.h',
arguments: ['server-header', '@INPUT@', '@OUTPUT@'])
wayland_scanner_code = generator(wayland_scanner,
output: '@BASENAME@-protocol.c',
arguments: ['code', '@INPUT@', '@OUTPUT@'])
executable('simple', 'simple.c', dependencies: wlroots, link_with: lib_shared)
executable('rotation', 'rotation.c', dependencies: wlroots, link_with: lib_shared)
executable('pointer', 'pointer.c', dependencies: wlroots, link_with: lib_shared)
executable('touch', 'touch.c', dependencies: wlroots, link_with: lib_shared)
executable('tablet', 'tablet.c', dependencies: wlroots, link_with: lib_shared)
compositor_src = [
'compositor/main.c',
'compositor/wl_compositor.c',
'compositor/wl_shell.c',
'compositor/xdg_shell.c',
]
protocols = [
[ 'unstable', 'xdg-shell', 'xdg-shell-unstable-v6.xml' ]
]
foreach p : protocols
xml = join_paths([wl_protocol_dir] + p)
compositor_src += wayland_scanner_code.process(xml)
compositor_src += wayland_scanner_server.process(xml)
endforeach
executable('compositor', compositor_src, dependencies: dep_wlr, link_with: lib_shared)
executable('compositor', compositor_src,
dependencies: wlroots,
link_with: lib_shared)

View file

@ -0,0 +1,20 @@
#ifndef _WLR_XDG_SHELL_V6_H
#define _WLR_XDG_SHELL_V6_H
#include <wayland-server.h>
struct wlr_xdg_shell_v6 {
struct wl_global *wl_global;
struct wl_list wl_resources;
struct wl_list surfaces;
};
struct wlr_xdg_surface_v6 {
struct wl_resource *resource;
struct wl_resource *surface;
struct wl_list link;
};
struct wlr_xdg_shell_v6 *wlr_xdg_shell_v6_init(struct wl_display *display);
void wlr_xdg_shell_v6_destroy(struct wlr_xdg_shell_v6 *xdg_shell);
#endif

View file

@ -19,61 +19,71 @@ if cc.get_id() == 'clang'
add_project_arguments('-Wno-missing-braces', language: 'c')
endif
dep_wayland_server = dependency('wayland-server')
dep_wayland_client = dependency('wayland-client')
dep_wayland_egl = dependency('wayland-egl')
dep_wayland_proto = dependency('wayland-protocols')
dep_egl = dependency('egl')
dep_glesv2 = dependency('glesv2')
dep_drm = dependency('libdrm')
dep_gbm = dependency('gbm')
dep_libinput = dependency('libinput')
dep_xkbcommon = dependency('xkbcommon')
dep_udev = dependency('libudev')
dep_pixman = dependency('pixman-1')
dep_libcap = dependency('libcap', required: false)
dep_systemd = dependency('libsystemd', required: false)
dep_math = cc.find_library('m', required: false)
wayland_server = dependency('wayland-server')
wayland_client = dependency('wayland-client')
wayland_egl = dependency('wayland-egl')
wayland_protos = dependency('wayland-protocols')
egl = dependency('egl')
glesv2 = dependency('glesv2')
drm = dependency('libdrm')
gbm = dependency('gbm')
libinput = dependency('libinput')
xkbcommon = dependency('xkbcommon')
udev = dependency('libudev')
pixman = dependency('pixman-1')
libcap = dependency('libcap', required: false)
systemd = dependency('libsystemd', required: false)
math = cc.find_library('m', required: false)
all_deps = [
dep_wayland_server,
dep_wayland_client,
dep_wayland_egl,
dep_wayland_proto,
dep_egl,
dep_glesv2,
dep_drm,
dep_gbm,
dep_libinput,
dep_xkbcommon,
dep_udev,
dep_pixman,
dep_libcap,
dep_systemd,
dep_math,
]
if dep_libcap.found()
if libcap.found()
add_project_arguments('-DHAS_LIBCAP', language: 'c')
endif
if dep_systemd.found()
if systemd.found()
add_project_arguments('-DHAS_SYSTEMD', language: 'c')
endif
wlr_files = []
subdir('protocol')
subdir('backend')
subdir('render')
subdir('types')
subdir('util')
subdir('xcursor')
_wlr_deps = [
wayland_server,
wayland_client,
wayland_egl,
wayland_protos,
egl,
glesv2,
drm,
gbm,
libinput,
xkbcommon,
udev,
pixman,
libcap,
systemd,
math,
]
lib_wlr = library('wlroots', wlr_files,
dependencies: all_deps,
link_whole: [
lib_wl_protos,
lib_wlr_backend,
lib_wlr_render,
lib_wlr_types,
lib_wlr_util,
lib_wlr_xcursor,
],
dependencies: _wlr_deps,
include_directories: wlr_inc)
dep_wlr = declare_dependency(link_with: lib_wlr,
dependencies: all_deps,
wlroots = declare_dependency(link_with: lib_wlr,
dependencies: _wlr_deps,
include_directories: wlr_inc)
subdir('examples')

29
protocol/meson.build Normal file
View file

@ -0,0 +1,29 @@
wl_protocol_dir = wayland_protos.get_pkgconfig_variable('pkgdatadir')
wayland_scanner = find_program('wayland-scanner')
wayland_scanner_server = generator(wayland_scanner,
output: '@BASENAME@-protocol.h',
arguments: ['server-header', '@INPUT@', '@OUTPUT@'])
wayland_scanner_code = generator(wayland_scanner,
output: '@BASENAME@-protocol.c',
arguments: ['code', '@INPUT@', '@OUTPUT@'])
protocols = [
[ wl_protocol_dir, 'unstable/xdg-shell/xdg-shell-unstable-v6.xml' ]
]
wl_protos_src = []
wl_protos_headers = []
foreach p : protocols
xml = join_paths(p)
wl_protos_src += wayland_scanner_code.process(xml)
wl_protos_headers += wayland_scanner_server.process(xml)
endforeach
lib_wl_protos = static_library('wl_protos', wl_protos_src + wl_protos_headers)
wlr_protos = declare_dependency(
link_with: lib_wl_protos,
sources: wl_protos_headers)

View file

@ -1,11 +1,13 @@
wlr_files += files(
'egl.c',
'matrix.c',
'gles2/pixel_format.c',
'gles2/renderer.c',
'gles2/shaders.c',
'gles2/texture.c',
'gles2/util.c',
'wlr_renderer.c',
'wlr_texture.c',
)
lib_wlr_render = static_library('wlr_render', files(
'egl.c',
'matrix.c',
'gles2/pixel_format.c',
'gles2/renderer.c',
'gles2/shaders.c',
'gles2/texture.c',
'gles2/util.c',
'wlr_renderer.c',
'wlr_texture.c',
),
include_directories: wlr_inc,
dependencies: [glesv2, egl])

View file

@ -1,11 +1,14 @@
wlr_files += files(
'wlr_input_device.c',
'wlr_keyboard.c',
'wlr_output.c',
'wlr_pointer.c',
'wlr_region.c',
'wlr_surface.c',
'wlr_tablet_pad.c',
'wlr_tablet_tool.c',
'wlr_touch.c',
)
lib_wlr_types = static_library('wlr_types', [
'wlr_input_device.c',
'wlr_keyboard.c',
'wlr_output.c',
'wlr_pointer.c',
'wlr_region.c',
'wlr_surface.c',
'wlr_tablet_pad.c',
'wlr_tablet_tool.c',
'wlr_touch.c',
'wlr_xdg_shell_v6.c',
],
include_directories: wlr_inc,
dependencies: [wayland_server, pixman, wlr_protos])

View file

@ -1,12 +1,12 @@
#include <assert.h>
#include <wayland-server.h>
#include <wlr/util/log.h>
#include <stdlib.h>
#include "compositor.h"
#include <wayland-server.h>
#include <wlr/types/wlr_xdg_shell_v6.h>
#include <wlr/util/log.h>
#include "xdg-shell-unstable-v6-protocol.h"
static void resource_destructor(struct wl_client *client,
struct wl_resource *resource) {
static void resource_destroy(struct wl_client *client, struct wl_resource *resource) {
// TODO: we probably need to do more than this
wl_resource_destroy(resource);
}
@ -75,7 +75,7 @@ static void xdg_toplevel_set_minimized(struct wl_client *client, struct wl_resou
}
static const struct zxdg_toplevel_v6_interface zxdg_toplevel_v6_implementation = {
.destroy = resource_destructor,
.destroy = resource_destroy,
.set_parent = xdg_toplevel_set_parent,
.set_title = xdg_toplevel_set_title,
.set_app_id = xdg_toplevel_set_app_id,
@ -91,25 +91,20 @@ static const struct zxdg_toplevel_v6_interface zxdg_toplevel_v6_implementation =
.set_minimized = xdg_toplevel_set_minimized
};
struct xdg_surface_state {
struct wlr_texture *wlr_texture;
struct wl_display *display;
};
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_destroy(struct wl_resource *resource) {
struct wlr_xdg_surface_v6 *surface = wl_resource_get_user_data(resource);
free(surface);
}
static void xdg_surface_get_toplevel(struct wl_client *client,
struct wl_resource *resource, uint32_t id) {
struct xdg_surface_state *state = wl_resource_get_user_data(resource);
// TODO: Flesh out
struct wl_resource *toplevel_resource = wl_resource_create(client,
&zxdg_toplevel_v6_interface, wl_resource_get_version(resource), id);
wl_resource_set_implementation(toplevel_resource,
&zxdg_toplevel_v6_implementation, state, NULL);
zxdg_surface_v6_send_configure(resource, wl_display_next_serial(state->display));
&zxdg_toplevel_v6_implementation, NULL, NULL);
struct wl_display *display = wl_client_get_display(client);
zxdg_surface_v6_send_configure(resource, wl_display_next_serial(display));
}
static void xdg_surface_get_popup(struct wl_client *client,
@ -118,7 +113,6 @@ static void xdg_surface_get_popup(struct wl_client *client,
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");
@ -131,7 +125,7 @@ static void xdg_surface_set_window_geometry(struct wl_client *client,
}
static const struct zxdg_surface_v6_interface zxdg_surface_v6_implementation = {
.destroy = resource_destructor,
.destroy = resource_destroy,
.get_toplevel = xdg_surface_get_toplevel,
.get_popup = xdg_surface_get_popup,
.ack_configure = xdg_surface_ack_configure,
@ -143,63 +137,75 @@ static void xdg_shell_create_positioner(struct wl_client *client,
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 xdg_shell_state *shell_state = wl_resource_get_user_data(resource);
struct wlr_texture *wlr_texture = wl_resource_get_user_data(surface_resource);
struct xdg_surface_state *state = malloc(sizeof(struct xdg_surface_state));
state->display = shell_state->display;
state->wlr_texture = wlr_texture;
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_get_xdg_surface(struct wl_client *client,
struct wl_resource *_xdg_shell, uint32_t id,
struct wl_resource *_surface) {
struct wlr_xdg_shell_v6 *xdg_shell = wl_resource_get_user_data(_xdg_shell);
struct wlr_xdg_surface_v6 *surface =
calloc(1, sizeof(struct wlr_xdg_surface_v6));
surface->surface = _surface;
surface->resource = wl_resource_create(client,
&zxdg_surface_v6_interface, wl_resource_get_version(_xdg_shell), id);
wl_resource_set_implementation(surface->resource,
&zxdg_surface_v6_implementation, surface, xdg_surface_destroy);
wl_list_insert(&xdg_shell->surfaces, &surface->link);
}
static void xdg_shell_pong(struct wl_client *client, struct wl_resource *resource, uint32_t serial) {
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 = resource_destructor,
.destroy = resource_destroy,
.create_positioner = xdg_shell_create_positioner,
.get_xdg_surface = xdg_shell_get_xdg_surface,
.pong = xdg_shell_pong,
};
static void xdg_shell_bind(struct wl_client *wl_client, void *_state,
static void xdg_shell_bind(struct wl_client *wl_client, void *_xdg_shell,
uint32_t version, uint32_t id) {
struct xdg_shell_state *state = _state;
assert(wl_client && state);
struct wlr_xdg_shell_v6 *xdg_shell = _xdg_shell;
assert(wl_client && xdg_shell);
if (version > 1) {
wlr_log(L_ERROR, "Client requested unsupported wl_shell version, disconnecting");
wlr_log(L_ERROR, "Client requested unsupported xdg_shell_v6 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, NULL);
wl_list_insert(&state->wl_resources, wl_resource_get_link(wl_resource));
wl_resource_set_implementation(wl_resource, &xdg_shell_impl, xdg_shell, NULL);
wl_list_insert(&xdg_shell->wl_resources, wl_resource_get_link(wl_resource));
}
void xdg_shell_init(struct wl_display *display, struct xdg_shell_state *state) {
struct wlr_xdg_shell_v6 *wlr_xdg_shell_v6_init(struct wl_display *display) {
struct wlr_xdg_shell_v6 *xdg_shell =
calloc(1, sizeof(struct wlr_xdg_shell_v6));
if (!xdg_shell) {
return NULL;
}
struct wl_global *wl_global = wl_global_create(display,
&zxdg_shell_v6_interface, 1, state, xdg_shell_bind);
state->wl_global = wl_global;
state->display = display;
wl_list_init(&state->wl_resources);
&zxdg_shell_v6_interface, 1, xdg_shell, xdg_shell_bind);
if (!wl_global) {
wlr_xdg_shell_v6_destroy(xdg_shell);
return NULL;
}
xdg_shell->wl_global = wl_global;
wl_list_init(&xdg_shell->wl_resources);
wl_list_init(&xdg_shell->surfaces);
return xdg_shell;
}
void xdg_shell_release(struct xdg_shell_state *state) {
if (!state) {
void wlr_xdg_shell_v6_destroy(struct wlr_xdg_shell_v6 *xdg_shell) {
if (!xdg_shell) {
return;
}
struct wl_resource *resource = NULL, *temp = NULL;
wl_resource_for_each_safe(resource, temp, &state->wl_resources) {
wl_resource_for_each_safe(resource, temp, &xdg_shell->wl_resources) {
struct wl_list *link = wl_resource_get_link(resource);
wl_list_remove(link);
}
// TODO: destroy surfaces
wl_global_destroy(xdg_shell->wl_global);
free(xdg_shell);
}

View file

@ -1,4 +1,5 @@
wlr_files += files(
'list.c',
'log.c',
)
lib_wlr_util = static_library('wlr_util', files(
'list.c',
'log.c',
),
include_directories: wlr_inc)

View file

@ -1,4 +1,5 @@
wlr_files += files(
'xcursor.c',
'wlr_cursor.c',
)
lib_wlr_xcursor = static_library('wlr_xcursor', files(
'xcursor.c',
'wlr_cursor.c',
),
include_directories: wlr_inc)