Resizing from compositor
This commit is contained in:
@@ -58,4 +58,6 @@ struct client_state
|
|||||||
struct xkb_state *xkb_state;
|
struct xkb_state *xkb_state;
|
||||||
struct xkb_context *xkb_context;
|
struct xkb_context *xkb_context;
|
||||||
struct xkb_keymap *xkb_keymap;
|
struct xkb_keymap *xkb_keymap;
|
||||||
|
int width, height;
|
||||||
|
bool closed;
|
||||||
};
|
};
|
||||||
|
|||||||
BIN
compositor
BIN
compositor
Binary file not shown.
31
compositor.c
31
compositor.c
@@ -1,7 +1,7 @@
|
|||||||
#include "common/shm.h"
|
#include "common/shm.h"
|
||||||
#include "common/state.h"
|
#include "common/state.h"
|
||||||
#include "pointer.h"
|
|
||||||
#include "keyboard.h"
|
#include "keyboard.h"
|
||||||
|
#include "pointer.h"
|
||||||
#include "protocols/xdg-shell-client-protocol.h"
|
#include "protocols/xdg-shell-client-protocol.h"
|
||||||
|
|
||||||
#include <assert.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;
|
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 = {
|
static const struct wl_registry_listener wl_registry_listener = {
|
||||||
.global = registry_handle_global,
|
.global = registry_handle_global,
|
||||||
.global_remove = registry_handle_global_remove,
|
.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,
|
.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)
|
static void wl_buffer_release(void *data, struct wl_buffer *wl_buffer)
|
||||||
{
|
{
|
||||||
/* Sent by the compositor when it's no longer using this 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)
|
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 stride = width * 4;
|
||||||
int size = stride * height;
|
int size = stride * height;
|
||||||
|
|
||||||
@@ -197,6 +221,8 @@ static struct wl_buffer *draw_frame(struct client_state *state)
|
|||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
struct client_state state = {0};
|
struct client_state state = {0};
|
||||||
|
state.width = 640;
|
||||||
|
state.height = 480;
|
||||||
|
|
||||||
state.wl_display = wl_display_connect(NULL);
|
state.wl_display = wl_display_connect(NULL);
|
||||||
state.xkb_context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
|
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);
|
xdg_surface_add_listener(state.xdg_surface, &xdg_surface_listener, &state);
|
||||||
|
|
||||||
state.xdg_toplevel = xdg_surface_get_toplevel(state.xdg_surface);
|
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");
|
xdg_toplevel_set_title(state.xdg_toplevel, "Example client");
|
||||||
wl_surface_commit(state.wl_surface);
|
wl_surface_commit(state.wl_surface);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user