Merge pull request #43 from acrisci/feature/shell-surface-interface

shell surface interface
This commit is contained in:
Drew DeVault 2017-08-09 17:30:51 -04:00 committed by GitHub
commit 3ce1341e3c
7 changed files with 331 additions and 5 deletions

1
examples/.gitignore vendored Normal file
View File

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

View File

@ -19,7 +19,18 @@ struct wl_shell_state {
struct wl_list wl_resources;
};
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,
struct wl_shell_state *state);
void xdg_shell_init(struct wl_display *display,
struct xdg_shell_state *state);
void xdg_shell_release(struct xdg_shell_state *state);
#endif

View File

@ -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,9 @@ 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);
xdg_shell_release(&state.xdg_shell);
}

View File

@ -1,12 +1,95 @@
#include <assert.h>
#include <wayland-server.h>
#include <wlr/util/log.h>
#include <stdlib.h>
#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_texture *wlr_texture;
};
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 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;
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 = {

View File

@ -0,0 +1,205 @@
#include <assert.h>
#include <wayland-server.h>
#include <wlr/util/log.h>
#include <stdlib.h>
#include "compositor.h"
#include "xdg-shell-unstable-v6-protocol.h"
static void resource_destructor(struct wl_client *client,
struct wl_resource *resource) {
wl_resource_destroy(resource);
}
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 = resource_destructor,
.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
};
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_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);
wl_resource_set_implementation(toplevel_resource,
&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,
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 = 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,
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 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_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,
.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,
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, NULL);
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;
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);
}
}

View File

@ -8,10 +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/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)

View File

@ -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