mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-05 04:06:08 -05:00
main: handle window resize
This commit is contained in:
parent
68108ad7d8
commit
4de6a8ad38
1 changed files with 22 additions and 14 deletions
36
main.c
36
main.c
|
|
@ -30,6 +30,23 @@ struct context {
|
|||
struct wayland wl;
|
||||
};
|
||||
|
||||
static void
|
||||
resize(struct context *c, int width, int height)
|
||||
{
|
||||
LOG_DBG("resize: %dx%d", width, height);
|
||||
|
||||
struct buffer *buf = shm_get_buffer(c->wl.shm, width, height);
|
||||
|
||||
cairo_set_operator(buf->cairo, CAIRO_OPERATOR_SOURCE);
|
||||
cairo_set_source_rgba(buf->cairo, 1.0, 0.0, 0.0, 1.0);
|
||||
cairo_rectangle(buf->cairo, 0, 0, buf->width, buf->height);
|
||||
cairo_fill(buf->cairo);
|
||||
|
||||
wl_surface_attach(c->wl.surface, buf->wl_buf, 0, 0);
|
||||
wl_surface_damage(c->wl.surface, 0, 0, buf->width, buf->height);
|
||||
wl_surface_commit(c->wl.surface);
|
||||
}
|
||||
|
||||
static void
|
||||
shm_format(void *data, struct wl_shm *wl_shm, uint32_t format)
|
||||
{
|
||||
|
|
@ -128,6 +145,10 @@ xdg_toplevel_configure(void *data, struct xdg_toplevel *xdg_toplevel,
|
|||
{
|
||||
//struct context *c = data;
|
||||
LOG_DBG("xdg-toplevel: configure: %dx%d", width, height);
|
||||
if (width <= 0 || height <= 0)
|
||||
return;
|
||||
|
||||
resize(data, width, height);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -227,18 +248,7 @@ main(int argc, const char *const *argv)
|
|||
/* TODO: use font metrics to calculate initial size from ROWS x COLS */
|
||||
const int default_width = 300;
|
||||
const int default_height = 300;
|
||||
struct buffer *buf = shm_get_buffer(c.wl.shm, default_width, default_height);
|
||||
|
||||
cairo_set_operator(buf->cairo, CAIRO_OPERATOR_SOURCE);
|
||||
cairo_set_source_rgba(buf->cairo, 1.0, 0.0, 0.0, 1.0);
|
||||
cairo_rectangle(buf->cairo, 0, 0, buf->width, buf->height);
|
||||
cairo_fill(buf->cairo);
|
||||
|
||||
wl_surface_attach(c.wl.surface, buf->wl_buf, 0, 0);
|
||||
wl_surface_damage(c.wl.surface, 0, 0, buf->width, buf->height);
|
||||
|
||||
|
||||
wl_surface_commit(c.wl.surface);
|
||||
resize(&c, default_width, default_height);
|
||||
|
||||
wl_display_dispatch_pending(c.wl.display);
|
||||
|
||||
|
|
@ -247,10 +257,8 @@ main(int argc, const char *const *argv)
|
|||
{.fd = wl_display_get_fd(c.wl.display), .events = POLLIN},
|
||||
};
|
||||
|
||||
LOG_DBG("polling...");
|
||||
wl_display_flush(c.wl.display);
|
||||
poll(fds, 1, -1);
|
||||
LOG_DBG("lsdjfldsf");
|
||||
|
||||
if (fds[0].revents & POLLHUP) {
|
||||
LOG_WARN("disconnected from wayland");
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue