From 347707c9629334278cd85922a407d73629210c7b Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Sat, 5 Aug 2017 12:57:34 -0400 Subject: [PATCH 01/10] Add shell surface stubs Add stubs for the wl_shell_surface interface. Implement wl_shell_get_shell_surface by creating the shell surface and settings its implementation to these stubs. --- examples/compositor/wl_shell.c | 85 +++++++++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) diff --git a/examples/compositor/wl_shell.c b/examples/compositor/wl_shell.c index f2ec3c56..b8cf126c 100644 --- a/examples/compositor/wl_shell.c +++ b/examples/compositor/wl_shell.c @@ -1,12 +1,95 @@ #include #include #include +#include #include "compositor.h" +static void shell_surface_pong(struct wl_client *client, struct wl_resource + *resource, uint32_t serial) { + wlr_log(L_DEBUG, "TODO: implement shell surface pong"); +} + +static void shell_surface_move(struct wl_client *client, struct wl_resource + *resource, struct wl_resource *seat, uint32_t serial) { + wlr_log(L_DEBUG, "TODO: implement shell surface move"); +} + +static void shell_surface_resize(struct wl_client *client, + struct wl_resource *resource, struct wl_resource *seat, uint32_t serial, + uint32_t edges) { + wlr_log(L_DEBUG, "TODO: implement shell surface resize"); +} + +static void shell_surface_set_toplevel(struct wl_client *client, + struct wl_resource *resource) { + wlr_log(L_DEBUG, "TODO: implement shell surface set_toplevel"); +} + +static void shell_surface_set_transient(struct wl_client *client, + struct wl_resource *resource, struct wl_resource *parent, int32_t x, + int32_t y, uint32_t flags) { + wlr_log(L_DEBUG, "TODO: implement shell surface set_transient"); +} + +static void shell_surface_set_fullscreen(struct wl_client *client, + struct wl_resource *resource, uint32_t method, uint32_t framerate, + struct wl_resource *output) { + wlr_log(L_DEBUG, "TODO: implement shell surface set_fullscreen"); +} + +static void shell_surface_set_popup(struct wl_client *client, + struct wl_resource *resource, struct wl_resource *seat, uint32_t serial, + struct wl_resource *parent, int32_t x, int32_t y, uint32_t flags) { + wlr_log(L_DEBUG, "TODO: implement shell surface set_popup"); +} + +static void shell_surface_set_maximized(struct wl_client *client, + struct wl_resource *resource, struct wl_resource *output) { + wlr_log(L_DEBUG, "TODO: implement shell surface set_maximized"); +} + +static void shell_surface_set_title(struct wl_client *client, + struct wl_resource *resource, const char *title) { + wlr_log(L_DEBUG, "TODO: implement shell surface set_title"); +} + +static void shell_surface_set_class(struct wl_client *client, + struct wl_resource *resource, const char *class_) { + wlr_log(L_DEBUG, "TODO: implement shell surface set_class"); +} + +struct wl_shell_surface_interface shell_surface_interface = { + .pong = shell_surface_pong, + .move = shell_surface_move, + .resize = shell_surface_resize, + .set_toplevel = shell_surface_set_toplevel, + .set_transient = shell_surface_set_transient, + .set_fullscreen = shell_surface_set_fullscreen, + .set_popup = shell_surface_set_popup, + .set_maximized = shell_surface_set_maximized, + .set_title = shell_surface_set_title, + .set_class = shell_surface_set_class, +}; + +struct shell_surface_state { + struct wlr_surface *wlr_surface; +}; + +static void destroy_shell_surface(struct wl_resource *resource) { + struct shell_surface_state *state = wl_resource_get_user_data(resource); + free(state); +} + void wl_shell_get_shell_surface(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *surface) { - wlr_log(L_DEBUG, "TODO: implement get_shell_surface"); + struct wlr_surface *wlr_surface = wl_resource_get_user_data(surface); + struct shell_surface_state *state = malloc(sizeof(struct shell_surface_state)); + state->wlr_surface = wlr_surface; + struct wl_resource *shell_surface_resource = wl_resource_create(client, + &wl_shell_surface_interface, wl_resource_get_version(resource), id); + wl_resource_set_implementation(shell_surface_resource, + &shell_surface_interface, state, destroy_shell_surface); } static struct wl_shell_interface wl_shell_impl = { From c3f15ea284b1fc78fc555fd28992e3d098ee4393 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 8 Aug 2017 08:09:14 -0400 Subject: [PATCH 02/10] Add xdg shell stubs --- examples/.gitignore | 1 + examples/compositor.h | 8 ++ examples/compositor/gen-protos.sh | 11 +++ examples/compositor/main.c | 2 + examples/compositor/xdg_shell.c | 119 ++++++++++++++++++++++++++++++ examples/meson.build | 24 +++++- 6 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 examples/.gitignore create mode 100755 examples/compositor/gen-protos.sh create mode 100644 examples/compositor/xdg_shell.c diff --git a/examples/.gitignore b/examples/.gitignore new file mode 100644 index 00000000..38582982 --- /dev/null +++ b/examples/.gitignore @@ -0,0 +1 @@ +/compositor/protocols diff --git a/examples/compositor.h b/examples/compositor.h index abe1a743..5d652dbe 100644 --- a/examples/compositor.h +++ b/examples/compositor.h @@ -19,7 +19,15 @@ struct wl_shell_state { 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, struct wl_shell_state *state); +void xdg_shell_init(struct wl_display *display, + struct xdg_shell_state *state); + #endif diff --git a/examples/compositor/gen-protos.sh b/examples/compositor/gen-protos.sh new file mode 100755 index 00000000..d1d06407 --- /dev/null +++ b/examples/compositor/gen-protos.sh @@ -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 + diff --git a/examples/compositor/main.c b/examples/compositor/main.c index 8e5fcc34..86fda4ed 100644 --- a/examples/compositor/main.c +++ b/examples/compositor/main.c @@ -20,6 +20,7 @@ struct sample_state { struct wlr_renderer *renderer; struct wl_compositor_state compositor; struct wl_shell_state shell; + struct xdg_shell_state xdg_shell; }; void handle_output_frame(struct output_state *output, struct timespec *ts) { @@ -57,6 +58,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); compositor_run(&compositor); } diff --git a/examples/compositor/xdg_shell.c b/examples/compositor/xdg_shell.c new file mode 100644 index 00000000..73e879c8 --- /dev/null +++ b/examples/compositor/xdg_shell.c @@ -0,0 +1,119 @@ +#include +#include +#include +#include +#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); +} diff --git a/examples/meson.build b/examples/meson.build index a44a4946..51561e8a 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -11,7 +11,29 @@ executable('tablet', 'tablet.c', dependencies: dep_wlr, link_with: lib_shared) compositor_src = [ 'compositor/main.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) From 15885ab54a821135b94857bd0d9fe017c854906b Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Tue, 8 Aug 2017 17:22:11 -0400 Subject: [PATCH 03/10] implement xdg toplevel stubs --- examples/compositor/gen-protos.sh | 11 ---- examples/compositor/xdg_shell.c | 90 ++++++++++++++++++++++++++++++- 2 files changed, 89 insertions(+), 12 deletions(-) delete mode 100755 examples/compositor/gen-protos.sh diff --git a/examples/compositor/gen-protos.sh b/examples/compositor/gen-protos.sh deleted file mode 100755 index d1d06407..00000000 --- a/examples/compositor/gen-protos.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/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 - diff --git a/examples/compositor/xdg_shell.c b/examples/compositor/xdg_shell.c index 73e879c8..82ac6838 100644 --- a/examples/compositor/xdg_shell.c +++ b/examples/compositor/xdg_shell.c @@ -5,6 +5,90 @@ #include "compositor.h" #include "compositor/protocols/xdg-shell.h" +static void xdg_toplevel_destroy(struct wl_client *client, + struct wl_resource *resource) { + wlr_log(L_DEBUG, "TODO: xdg toplevel destroy"); +} + +static void xdg_toplevel_set_parent(struct wl_client *client, + struct wl_resource *resource, struct wl_resource *parent_resource) { + wlr_log(L_DEBUG, "TODO: toplevel set parent"); +} + +static void xdg_toplevel_set_title(struct wl_client *client, + struct wl_resource *resource, const char *title) { + wlr_log(L_DEBUG, "TODO: toplevel set title"); +} + +static void xdg_toplevel_set_app_id(struct wl_client *client, + struct wl_resource *resource, const char *app_id) { + wlr_log(L_DEBUG, "TODO: toplevel set app id"); +} + +static void xdg_toplevel_show_window_menu(struct wl_client *client, + struct wl_resource *resource, struct wl_resource *seat, uint32_t serial, + int32_t x, int32_t y) { + wlr_log(L_DEBUG, "TODO: toplevel show window menu"); +} + +static void xdg_toplevel_move(struct wl_client *client, struct wl_resource *resource, struct wl_resource *seat_resource, uint32_t serial) { + wlr_log(L_DEBUG, "TODO: toplevel move"); +} + +static void xdg_toplevel_resize(struct wl_client *client, struct wl_resource + *resource, struct wl_resource *seat_resource, uint32_t serial, + uint32_t edges) { + wlr_log(L_DEBUG, "TODO: toplevel resize"); +} + +static void xdg_toplevel_set_max_size(struct wl_client *client, + struct wl_resource *resource, int32_t width, int32_t height) { + wlr_log(L_DEBUG, "TODO: toplevel set max size"); +} + +static void xdg_toplevel_set_min_size(struct wl_client *client, + struct wl_resource *resource, int32_t width, int32_t height) { + wlr_log(L_DEBUG, "TODO: toplevel set min size"); +} + +static void xdg_toplevel_set_maximized(struct wl_client *client, + struct wl_resource *resource) { + wlr_log(L_DEBUG, "TODO: toplevel set maximized"); +} + +static void xdg_toplevel_unset_maximized(struct wl_client *client, struct wl_resource *resource) { + wlr_log(L_DEBUG, "TODO: toplevel unset maximized"); +} + +static void xdg_toplevel_set_fullscreen(struct wl_client *client, struct wl_resource *resource, struct wl_resource *output_resource) { + wlr_log(L_DEBUG, "TODO: toplevel set fullscreen"); +} + +static void xdg_toplevel_unset_fullscreen(struct wl_client *client, struct wl_resource *resource) { + wlr_log(L_DEBUG, "TODO: toplevel unset fullscreen"); +} + +static void xdg_toplevel_set_minimized(struct wl_client *client, struct wl_resource *resource) { + wlr_log(L_DEBUG, "TODO: toplevel set minimized"); +} + +static const struct zxdg_toplevel_v6_interface zxdg_toplevel_v6_implementation = { + .destroy = xdg_toplevel_destroy, + .set_parent = xdg_toplevel_set_parent, + .set_title = xdg_toplevel_set_title, + .set_app_id = xdg_toplevel_set_app_id, + .show_window_menu = xdg_toplevel_show_window_menu, + .move = xdg_toplevel_move, + .resize = xdg_toplevel_resize, + .set_max_size = xdg_toplevel_set_max_size, + .set_min_size = xdg_toplevel_set_min_size, + .set_maximized = xdg_toplevel_set_maximized, + .unset_maximized = xdg_toplevel_unset_maximized, + .set_fullscreen = xdg_toplevel_set_fullscreen, + .unset_fullscreen = xdg_toplevel_unset_fullscreen, + .set_minimized = xdg_toplevel_set_minimized +}; + static void xdg_surface_destroy(struct wl_client *client, struct wl_resource *resource) { wlr_log(L_DEBUG, "TODO xdg surface destroy"); @@ -17,7 +101,11 @@ static void destroy_xdg_shell_surface(struct wl_resource *resource) { 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"); + struct xdg_surface_state *state = wl_resource_get_user_data(resource); + 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, destroy_xdg_shell_surface); } static void xdg_surface_get_popup(struct wl_client *client, From 5add87cac602b4fb8a484f42707165d1e2ad8d89 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 9 Aug 2017 07:12:26 -0400 Subject: [PATCH 04/10] rename wlr_surface to wlr_texture --- examples/compositor/wl_shell.c | 6 +++--- examples/compositor/xdg_shell.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/examples/compositor/wl_shell.c b/examples/compositor/wl_shell.c index b8cf126c..dcff3f91 100644 --- a/examples/compositor/wl_shell.c +++ b/examples/compositor/wl_shell.c @@ -72,7 +72,7 @@ struct wl_shell_surface_interface shell_surface_interface = { }; struct shell_surface_state { - struct wlr_surface *wlr_surface; + struct wlr_texture *wlr_texture; }; static void destroy_shell_surface(struct wl_resource *resource) { @@ -83,9 +83,9 @@ static void destroy_shell_surface(struct wl_resource *resource) { void wl_shell_get_shell_surface(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *surface) { - struct wlr_surface *wlr_surface = wl_resource_get_user_data(surface); + struct wlr_texture *wlr_texture = wl_resource_get_user_data(surface); struct shell_surface_state *state = malloc(sizeof(struct shell_surface_state)); - state->wlr_surface = wlr_surface; + state->wlr_texture = wlr_texture; struct wl_resource *shell_surface_resource = wl_resource_create(client, &wl_shell_surface_interface, wl_resource_get_version(resource), id); wl_resource_set_implementation(shell_surface_resource, diff --git a/examples/compositor/xdg_shell.c b/examples/compositor/xdg_shell.c index 82ac6838..5d0d9e8d 100644 --- a/examples/compositor/xdg_shell.c +++ b/examples/compositor/xdg_shell.c @@ -135,7 +135,7 @@ static const struct zxdg_surface_v6_interface zxdg_surface_v6_implementation = { }; struct xdg_surface_state { - struct wlr_surface *wlr_surface; + struct wlr_texture *wlr_texture; }; static void xdg_shell_destroy(struct wl_client *client, @@ -151,9 +151,9 @@ static void xdg_shell_create_positioner(struct wl_client *client, 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 wlr_texture *wlr_texture = wl_resource_get_user_data(surface_resource); struct xdg_surface_state *state = malloc(sizeof(struct xdg_surface_state)); - state->wlr_surface = wlr_surface; + 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, From a6c7d8d14f2f418eeb066b5062f031ee4ebeda82 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 9 Aug 2017 07:27:49 -0400 Subject: [PATCH 05/10] send configure event after creating toplevel The xdg shell protocol requires us to send a configure in order for the client to start attaching buffers. --- examples/compositor.h | 1 + examples/compositor/xdg_shell.c | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/examples/compositor.h b/examples/compositor.h index 5d652dbe..7d786127 100644 --- a/examples/compositor.h +++ b/examples/compositor.h @@ -22,6 +22,7 @@ struct wl_shell_state { struct xdg_shell_state { struct wl_global *wl_global; struct wl_list wl_resources; + struct wl_display *display; }; void wl_shell_init(struct wl_display *display, diff --git a/examples/compositor/xdg_shell.c b/examples/compositor/xdg_shell.c index 5d0d9e8d..4933b9e4 100644 --- a/examples/compositor/xdg_shell.c +++ b/examples/compositor/xdg_shell.c @@ -89,6 +89,12 @@ 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 xdg_surface_destroy(struct wl_client *client, struct wl_resource *resource) { wlr_log(L_DEBUG, "TODO xdg surface destroy"); @@ -106,6 +112,7 @@ static void xdg_surface_get_toplevel(struct wl_client *client, &zxdg_toplevel_v6_interface, wl_resource_get_version(resource), id); wl_resource_set_implementation(toplevel_resource, &zxdg_toplevel_v6_implementation, state, destroy_xdg_shell_surface); + zxdg_surface_v6_send_configure(resource, wl_display_next_serial(state->display)); } static void xdg_surface_get_popup(struct wl_client *client, @@ -134,10 +141,6 @@ static const struct zxdg_surface_v6_interface zxdg_surface_v6_implementation = { .set_window_geometry = xdg_surface_set_window_geometry, }; -struct xdg_surface_state { - struct wlr_texture *wlr_texture; -}; - static void xdg_shell_destroy(struct wl_client *client, struct wl_resource *resource) { wlr_log(L_DEBUG, "TODO: xdg shell destroy"); @@ -151,8 +154,10 @@ static void xdg_shell_create_positioner(struct wl_client *client, 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); @@ -203,5 +208,6 @@ 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; + state->display = display; wl_list_init(&state->wl_resources); } From bdfe9faf58a373a158be85d12ddc5d09fb3ea70f Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 9 Aug 2017 07:30:30 -0400 Subject: [PATCH 06/10] Add todo for destroy_xdg_shell_surface This free was causing crashes so remove the implementation and make a note to do it later. --- examples/compositor/xdg_shell.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/compositor/xdg_shell.c b/examples/compositor/xdg_shell.c index 4933b9e4..a9d1f3f1 100644 --- a/examples/compositor/xdg_shell.c +++ b/examples/compositor/xdg_shell.c @@ -101,8 +101,8 @@ static void xdg_surface_destroy(struct wl_client *client, } static void destroy_xdg_shell_surface(struct wl_resource *resource) { - struct xdg_surface_state *state = wl_resource_get_user_data(resource); - free(state); + wlr_log(L_DEBUG, "TODO destroy xdg shell surface"); + //struct xdg_surface_state *state = wl_resource_get_user_data(resource); } static void xdg_surface_get_toplevel(struct wl_client *client, From 816a7f82574dd263ce26d1855a60986af0290667 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 9 Aug 2017 10:55:23 -0400 Subject: [PATCH 07/10] add xdg shell destructors --- examples/compositor.h | 2 ++ examples/compositor/main.c | 2 ++ examples/compositor/xdg_shell.c | 52 +++++++++++++-------------------- 3 files changed, 25 insertions(+), 31 deletions(-) diff --git a/examples/compositor.h b/examples/compositor.h index 7d786127..4649a8d3 100644 --- a/examples/compositor.h +++ b/examples/compositor.h @@ -31,4 +31,6 @@ void wl_shell_init(struct wl_display *display, void xdg_shell_init(struct wl_display *display, struct xdg_shell_state *state); +void xdg_shell_release(struct xdg_shell_state *state); + #endif diff --git a/examples/compositor/main.c b/examples/compositor/main.c index 86fda4ed..9d320c97 100644 --- a/examples/compositor/main.c +++ b/examples/compositor/main.c @@ -61,4 +61,6 @@ int main() { xdg_shell_init(compositor.display, &state.xdg_shell); compositor_run(&compositor); + + xdg_shell_release(&state.xdg_shell); } diff --git a/examples/compositor/xdg_shell.c b/examples/compositor/xdg_shell.c index a9d1f3f1..62cb76a0 100644 --- a/examples/compositor/xdg_shell.c +++ b/examples/compositor/xdg_shell.c @@ -5,9 +5,9 @@ #include "compositor.h" #include "compositor/protocols/xdg-shell.h" -static void xdg_toplevel_destroy(struct wl_client *client, +static void resource_destructor(struct wl_client *client, struct wl_resource *resource) { - wlr_log(L_DEBUG, "TODO: xdg toplevel destroy"); + wl_resource_destroy(resource); } static void xdg_toplevel_set_parent(struct wl_client *client, @@ -73,7 +73,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 = xdg_toplevel_destroy, + .destroy = resource_destructor, .set_parent = xdg_toplevel_set_parent, .set_title = xdg_toplevel_set_title, .set_app_id = xdg_toplevel_set_app_id, @@ -95,14 +95,9 @@ struct xdg_surface_state { }; -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) { - wlr_log(L_DEBUG, "TODO destroy xdg shell surface"); - //struct xdg_surface_state *state = wl_resource_get_user_data(resource); + struct xdg_surface_state *state = wl_resource_get_user_data(resource); + free(state); } static void xdg_surface_get_toplevel(struct wl_client *client, @@ -111,7 +106,7 @@ static void xdg_surface_get_toplevel(struct wl_client *client, 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, destroy_xdg_shell_surface); + &zxdg_toplevel_v6_implementation, state, NULL); zxdg_surface_v6_send_configure(resource, wl_display_next_serial(state->display)); } @@ -134,18 +129,13 @@ static void xdg_surface_set_window_geometry(struct wl_client *client, } static const struct zxdg_surface_v6_interface zxdg_surface_v6_implementation = { - .destroy = xdg_surface_destroy, + .destroy = resource_destructor, .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, }; -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"); @@ -156,6 +146,7 @@ static void xdg_shell_get_xdg_surface(struct wl_client *client, struct 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); + wlr_log(L_DEBUG, "@@ MALLOC STATE"); struct xdg_surface_state *state = malloc(sizeof(struct xdg_surface_state)); state->display = shell_state->display; state->wlr_texture = wlr_texture; @@ -170,24 +161,12 @@ static void xdg_shell_pong(struct wl_client *client, struct wl_resource *resourc } static struct zxdg_shell_v6_interface xdg_shell_impl = { - .destroy = xdg_shell_destroy, + .destroy = resource_destructor, .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; @@ -200,7 +179,7 @@ static void xdg_shell_bind(struct wl_client *wl_client, void *_state, 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); + state, NULL); wl_list_insert(&state->wl_resources, wl_resource_get_link(wl_resource)); } @@ -211,3 +190,14 @@ void xdg_shell_init(struct wl_display *display, struct xdg_shell_state *state) { state->display = display; wl_list_init(&state->wl_resources); } + +void xdg_shell_release(struct xdg_shell_state *state) { + if (!state) + return; + + struct wl_resource *_resource = NULL; + wl_resource_for_each(_resource, &state->wl_resources) { + struct wl_list *link = wl_resource_get_link(_resource); + wl_list_remove(link); + } +} From 26edd5fb9eb4b724133f6beb6aaf634c7e0b7ba2 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 9 Aug 2017 12:23:38 -0400 Subject: [PATCH 08/10] cleanup for style and formatting --- examples/compositor/xdg_shell.c | 46 +++++++++++++++++---------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/examples/compositor/xdg_shell.c b/examples/compositor/xdg_shell.c index 62cb76a0..3eaad449 100644 --- a/examples/compositor/xdg_shell.c +++ b/examples/compositor/xdg_shell.c @@ -7,7 +7,7 @@ static void resource_destructor(struct wl_client *client, struct wl_resource *resource) { - wl_resource_destroy(resource); + wl_resource_destroy(resource); } static void xdg_toplevel_set_parent(struct wl_client *client, @@ -31,13 +31,15 @@ static void xdg_toplevel_show_window_menu(struct wl_client *client, wlr_log(L_DEBUG, "TODO: toplevel show window menu"); } -static void xdg_toplevel_move(struct wl_client *client, struct wl_resource *resource, struct wl_resource *seat_resource, uint32_t serial) { +static void xdg_toplevel_move(struct wl_client *client, + struct wl_resource *resource, struct wl_resource *seat_resource, + uint32_t serial) { wlr_log(L_DEBUG, "TODO: toplevel move"); } -static void xdg_toplevel_resize(struct wl_client *client, struct wl_resource - *resource, struct wl_resource *seat_resource, uint32_t serial, - uint32_t edges) { +static void xdg_toplevel_resize(struct wl_client *client, + struct wl_resource *resource, struct wl_resource *seat_resource, + uint32_t serial, uint32_t edges) { wlr_log(L_DEBUG, "TODO: toplevel resize"); } @@ -104,10 +106,10 @@ 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); struct wl_resource *toplevel_resource = wl_resource_create(client, - &zxdg_toplevel_v6_interface, wl_resource_get_version(resource), id); + &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, state, NULL); + zxdg_surface_v6_send_configure(resource, wl_display_next_serial(state->display)); } static void xdg_surface_get_popup(struct wl_client *client, @@ -129,11 +131,11 @@ 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, - .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, + .destroy = resource_destructor, + .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, }; static void xdg_shell_create_positioner(struct wl_client *client, @@ -146,14 +148,13 @@ static void xdg_shell_get_xdg_surface(struct wl_client *client, struct 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); - wlr_log(L_DEBUG, "@@ MALLOC STATE"); 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); + &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); + &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) { @@ -177,9 +178,9 @@ static void xdg_shell_bind(struct wl_client *wl_client, void *_state, return; } struct wl_resource *wl_resource = wl_resource_create( - wl_client, &zxdg_shell_v6_interface, version, id); + wl_client, &zxdg_shell_v6_interface, version, id); wl_resource_set_implementation(wl_resource, &xdg_shell_impl, - state, NULL); + state, NULL); wl_list_insert(&state->wl_resources, wl_resource_get_link(wl_resource)); } @@ -192,12 +193,13 @@ void xdg_shell_init(struct wl_display *display, struct xdg_shell_state *state) { } void xdg_shell_release(struct xdg_shell_state *state) { - if (!state) + if (!state) { return; + } - struct wl_resource *_resource = NULL; - wl_resource_for_each(_resource, &state->wl_resources) { - struct wl_list *link = wl_resource_get_link(_resource); + struct wl_resource *resource = NULL; + wl_resource_for_each(resource, &state->wl_resources) { + struct wl_list *link = wl_resource_get_link(resource); wl_list_remove(link); } } From 5a7595af77bdccf245dcdd9245cf0d408344f633 Mon Sep 17 00:00:00 2001 From: Tony Crisci Date: Wed, 9 Aug 2017 13:25:52 -0400 Subject: [PATCH 09/10] use generators for wayland protocol gen --- examples/compositor/xdg_shell.c | 2 +- examples/meson.build | 30 +++++++++++++++--------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/examples/compositor/xdg_shell.c b/examples/compositor/xdg_shell.c index 3eaad449..5130bce6 100644 --- a/examples/compositor/xdg_shell.c +++ b/examples/compositor/xdg_shell.c @@ -3,7 +3,7 @@ #include #include #include "compositor.h" -#include "compositor/protocols/xdg-shell.h" +#include "xdg-shell-unstable-v6-protocol.h" static void resource_destructor(struct wl_client *client, struct wl_resource *resource) { diff --git a/examples/meson.build b/examples/meson.build index 51561e8a..646a4b88 100644 --- a/examples/meson.build +++ b/examples/meson.build @@ -8,32 +8,32 @@ 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@']) + compositor_src = [ 'compositor/main.c', 'compositor/wl_compositor.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'] + [ 'unstable', 'xdg-shell', 'xdg-shell-unstable-v6.xml' ] ] 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']) + 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) From bd2e9a7168dc530c03b7b45ecfdd5ce0aff0ddb8 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Wed, 9 Aug 2017 17:30:22 -0400 Subject: [PATCH 10/10] Style cleanup --- examples/compositor/wl_shell.c | 4 ++-- examples/compositor/xdg_shell.c | 8 ++++---- render/matrix.c | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/examples/compositor/wl_shell.c b/examples/compositor/wl_shell.c index dcff3f91..e56f5c9e 100644 --- a/examples/compositor/wl_shell.c +++ b/examples/compositor/wl_shell.c @@ -81,8 +81,8 @@ static void destroy_shell_surface(struct wl_resource *resource) { } void wl_shell_get_shell_surface(struct wl_client *client, - struct wl_resource *resource, uint32_t id, - struct wl_resource *surface) { + struct wl_resource *resource, uint32_t id, + struct wl_resource *surface) { struct wlr_texture *wlr_texture = wl_resource_get_user_data(surface); struct shell_surface_state *state = malloc(sizeof(struct shell_surface_state)); state->wlr_texture = wlr_texture; diff --git a/examples/compositor/xdg_shell.c b/examples/compositor/xdg_shell.c index 5130bce6..2efeecfa 100644 --- a/examples/compositor/xdg_shell.c +++ b/examples/compositor/xdg_shell.c @@ -162,10 +162,10 @@ static void xdg_shell_pong(struct wl_client *client, struct wl_resource *resourc } static struct zxdg_shell_v6_interface xdg_shell_impl = { - .destroy = resource_destructor, - .create_positioner = xdg_shell_create_positioner, - .get_xdg_surface = xdg_shell_get_xdg_surface, - .pong = xdg_shell_pong, + .destroy = resource_destructor, + .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, diff --git a/render/matrix.c b/render/matrix.c index a927ed74..e49d365e 100644 --- a/render/matrix.c +++ b/render/matrix.c @@ -10,7 +10,7 @@ static inline int mind(int row, int col) { void wlr_matrix_identity(float (*output)[16]) { static const float identity[16] = { - 1.0f, 0.0f, 0.0f, 0.0f, + 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f