Instead of harcoding at 1080p, just grab the largest connected output and use that as the pool size. This allows us to be a bit more stingy on reallocing.
Unified · Split
| @@ -530,14 +530,40 @@ static const struct xdg_wm_base_listener xdg_wm_base_listener = { · 529 unmodified lines | ||
| 530 | 530 | .ping = xdg_wm_base_ping, |
| 531 | 531 | }; |
| 532 | 532 | |
| 533 | +static void | |
| 534 | +mode(void *data, struct wl_output*, uint, int x, int y, int) | |
| 535 | +{ | |
| 536 | + Wlwin *wl; | |
| 537 | + | |
| 538 | + wl = data; | |
| 539 | + if(x >= wl->monx && y >= wl->mony){ | |
| 540 | + wl->monx = x; | |
| 541 | + wl->mony = y; | |
| 542 | + } | |
| 543 | +} | |
| 544 | +static void done(void*, struct wl_output*){} | |
| 545 | +static void scale(void*, struct wl_output*, int){} | |
| 546 | +static void geometry(void*, struct wl_output*, int, int, int, int, int, const char*, const char*, int){} | |
| 547 | + | |
| 548 | +static const struct wl_output_listener output_listener = { | |
| 549 | + .geometry = geometry, | |
| 550 | + .mode = mode, | |
| 551 | + .done = done, | |
| 552 | + .scale = scale, | |
| 553 | +}; | |
| 554 | + | |
| 533 | 555 | static void |
| 534 | 556 | handle_global(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version) |
| 535 | 557 | { |
| 536 | 558 | Wlwin *wl; |
| 559 | + struct wl_output *out; | |
| 537 | 560 | |
| 538 | 561 | wl = data; |
| 539 | 562 | if(strcmp(interface, wl_shm_interface.name) == 0) { |
| 540 | 563 | wl->shm = wl_registry_bind(registry, name, &wl_shm_interface, 1); |
| 564 | + } else if(strcmp(interface, wl_output_interface.name) == 0) { | |
| 565 | + out = wl_registry_bind(registry, name, &wl_output_interface, 2); | |
| 566 | + wl_output_add_listener(out, &output_listener, wl); | |
| 541 | 567 | } else if(strcmp(interface, wl_seat_interface.name) == 0) { |
| 542 | 568 | //We don't support multiseat |
| 543 | 569 | if(wl->seat != nil) |
| @@ -39,8 +39,8 @@ newwlwin(void) · 38 unmodified lines | ||
| 39 | 39 | sysfatal("malloc Wlwin"); |
| 40 | 40 | wl->dx = 1024; |
| 41 | 41 | wl->dy = 1024; |
| 42 | − wl->monx = 1920; | |
| 43 | − wl->mony = 1080; | |
| 42 | + wl->monx = wl->dx; | |
| 43 | + wl->mony = wl->dy; | |
| 44 | 44 | return wl; |
| 45 | 45 | } |
| 46 | 46 | |
| @@ -60,6 +60,8 @@ wlflush(Wlwin *wl) · 13 unmodified lines | ||
| 60 | 60 | wl_surface_commit(wl->surface); |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | +void _screenresize(Rectangle); | |
| 64 | + | |
| 63 | 65 | void |
| 64 | 66 | wlresize(Wlwin *wl, int x, int y) |
| 65 | 67 | { |
| @@ -73,11 +75,7 @@ wlresize(Wlwin *wl, int x, int y) · 7 unmodified lines | ||
| 73 | 75 | r = Rect(0, 0, wl->dx, wl->dy); |
| 74 | 76 | gscreen = allocmemimage(r, XRGB32); |
| 75 | 77 | gscreen->clipr = ZR; |
| 76 | − qunlock(&drawlock); | |
| 77 | − | |
| 78 | − screenresize(r); | |
| 79 | − | |
| 80 | − qlock(&drawlock); | |
| 78 | + _screenresize(r); | |
| 81 | 79 | wl->dirty = 1; |
| 82 | 80 | wl->r = r; |
| 83 | 81 | wlflush(wl); |
| @@ -50,7 +50,6 @@ wlcreateshm(off_t size) · 49 unmodified lines | ||
| 50 | 50 | void |
| 51 | 51 | wlallocpool(Wlwin *wl) |
| 52 | 52 | { |
| 53 | − int screenx, screeny; | |
| 54 | 53 | int screensize, cursorsize; |
| 55 | 54 | int depth; |
| 56 | 55 | int fd; |
| @@ -59,9 +58,7 @@ wlallocpool(Wlwin *wl) · 2 unmodified lines | ||
| 59 | 58 | wl_shm_pool_destroy(wl->pool); |
| 60 | 59 | |
| 61 | 60 | depth = 4; |
| 62 | − screenx = wl->dx > wl->monx ? wl->dx : wl->monx; | |
| 63 | − screeny = wl->dy > wl->mony ? wl->dy : wl->mony; | |
| 64 | − screensize = screenx * screeny * depth; | |
| 61 | + screensize = wl->monx * wl->mony * depth; | |
| 65 | 62 | cursorsize = 16 * 16 * depth; |
| 66 | 63 | |
| 67 | 64 | fd = wlcreateshm(screensize+cursorsize); |
| @@ -89,6 +86,8 @@ wlallocbuffer(Wlwin *wl) · 21 unmodified lines | ||
| 89 | 86 | if(wl->pool == nil || size+(16*16*depth) > wl->poolsize) |
| 90 | 87 | wlallocpool(wl); |
| 91 | 88 | |
| 89 | + assert(size+(16*16*depth) <= wl->poolsize); | |
| 90 | + | |
| 92 | 91 | if(wl->screenbuffer != nil) |
| 93 | 92 | wl_buffer_destroy(wl->screenbuffer); |
| 94 | 93 | if(wl->cursorbuffer != nil) |