mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-04-04 07:15:29 -04: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;
|
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
|
static void
|
||||||
shm_format(void *data, struct wl_shm *wl_shm, uint32_t format)
|
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;
|
//struct context *c = data;
|
||||||
LOG_DBG("xdg-toplevel: configure: %dx%d", width, height);
|
LOG_DBG("xdg-toplevel: configure: %dx%d", width, height);
|
||||||
|
if (width <= 0 || height <= 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
resize(data, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
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 */
|
/* TODO: use font metrics to calculate initial size from ROWS x COLS */
|
||||||
const int default_width = 300;
|
const int default_width = 300;
|
||||||
const int default_height = 300;
|
const int default_height = 300;
|
||||||
struct buffer *buf = shm_get_buffer(c.wl.shm, default_width, default_height);
|
resize(&c, 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);
|
|
||||||
|
|
||||||
wl_display_dispatch_pending(c.wl.display);
|
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},
|
{.fd = wl_display_get_fd(c.wl.display), .events = POLLIN},
|
||||||
};
|
};
|
||||||
|
|
||||||
LOG_DBG("polling...");
|
|
||||||
wl_display_flush(c.wl.display);
|
wl_display_flush(c.wl.display);
|
||||||
poll(fds, 1, -1);
|
poll(fds, 1, -1);
|
||||||
LOG_DBG("lsdjfldsf");
|
|
||||||
|
|
||||||
if (fds[0].revents & POLLHUP) {
|
if (fds[0].revents & POLLHUP) {
|
||||||
LOG_WARN("disconnected from wayland");
|
LOG_WARN("disconnected from wayland");
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue