support resizing background on display change

This commit is contained in:
K. Lange 2018-02-25 20:42:04 +09:00 committed by Kevin Lange
parent fc6afe84e3
commit 3f3ec78510

View File

@ -1,3 +1,5 @@
#include <stdio.h>
#include "lib/yutani.h"
#include "lib/graphics.h"
@ -5,6 +7,17 @@ static yutani_t * yctx;
static yutani_window_t * wina;
static gfx_context_t * ctx;
static void draw_background(int width, int height) {
draw_fill(ctx, rgb(110,110,110));
}
static void resize_finish(int width, int height) {
yutani_window_resize_accept(yctx, wina, width, height);
reinit_graphics_yutani(ctx, wina);
draw_background(width, height);
yutani_window_resize_done(yctx, wina);
yutani_flip(yctx, wina);
}
int main (int argc, char ** argv) {
yctx = yutani_init();
@ -12,7 +25,8 @@ int main (int argc, char ** argv) {
yutani_window_move(yctx, wina, 0, 0);
yutani_set_stack(yctx, wina, YUTANI_ZORDER_BOTTOM);
ctx = init_graphics_yutani(wina);
draw_fill(ctx, rgb(110,110,110));
draw_background(yctx->display_width, yctx->display_height);
yutani_flip(yctx, wina);
int should_exit = 0;
@ -20,6 +34,16 @@ int main (int argc, char ** argv) {
yutani_msg_t * m = yutani_poll(yctx);
if (m) {
switch (m->type) {
case YUTANI_MSG_WELCOME:
fprintf(stderr, "Request to resize desktop received, resizing to %d x %d\n", yctx->display_width, yctx->display_height);
yutani_window_resize_offer(yctx, wina, yctx->display_width, yctx->display_height);
break;
case YUTANI_MSG_RESIZE_OFFER:
{
struct yutani_msg_window_resize * wr = (void*)m->data;
resize_finish(wr->width, wr->height);
}
break;
case YUTANI_MSG_SESSION_END:
should_exit = 1;
break;