Resizing from compositor

This commit is contained in:
2022-09-03 19:55:31 +02:00
parent c9265ea20c
commit 7dc0a6194f
3 changed files with 31 additions and 2 deletions

View File

@@ -1,7 +1,7 @@
#include "common/shm.h"
#include "common/state.h"
#include "pointer.h"
#include "keyboard.h"
#include "pointer.h"
#include "protocols/xdg-shell-client-protocol.h"
#include <assert.h>
@@ -114,6 +114,24 @@ static void wl_surface_frame_done(void *data, struct wl_callback *cb, uint32_t t
state->last_frame = time;
}
static void xdg_toplevel_configure(void *data, struct xdg_toplevel *xdg_toplevel, int32_t width, int32_t height,
struct wl_array *states)
{
struct client_state *state = data;
if (width == 0 || height == 0) {
/* Compositor is deferring to us */
return;
}
state->width = width;
state->height = height;
}
static void xdg_toplevel_close(void *data, struct xdg_toplevel *xdg_toplevel)
{
struct client_state *state = data;
state->closed = true;
}
static const struct wl_registry_listener wl_registry_listener = {
.global = registry_handle_global,
.global_remove = registry_handle_global_remove,
@@ -140,6 +158,11 @@ static const struct wl_callback_listener wl_surface_frame_listener = {
.done = wl_surface_frame_done,
};
static const struct xdg_toplevel_listener xdg_toplevel_listener = {
.configure = xdg_toplevel_configure,
.close = xdg_toplevel_close,
};
static void wl_buffer_release(void *data, struct wl_buffer *wl_buffer)
{
/* Sent by the compositor when it's no longer using this buffer */
@@ -152,7 +175,8 @@ static const struct wl_buffer_listener wl_buffer_listener = {
static struct wl_buffer *draw_frame(struct client_state *state)
{
const int width = 640, height = 480;
int width = state->width;
int height = state->height;
int stride = width * 4;
int size = stride * height;
@@ -197,6 +221,8 @@ static struct wl_buffer *draw_frame(struct client_state *state)
int main(int argc, char *argv[])
{
struct client_state state = {0};
state.width = 640;
state.height = 480;
state.wl_display = wl_display_connect(NULL);
state.xkb_context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
@@ -214,6 +240,7 @@ int main(int argc, char *argv[])
xdg_surface_add_listener(state.xdg_surface, &xdg_surface_listener, &state);
state.xdg_toplevel = xdg_surface_get_toplevel(state.xdg_surface);
xdg_toplevel_add_listener(state.xdg_toplevel, &xdg_toplevel_listener, &state);
xdg_toplevel_set_title(state.xdg_toplevel, "Example client");
wl_surface_commit(state.wl_surface);