History

gui-wl: grab monitor size from compositor

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.

Jacob Moody committed 4 years ago

Commit 44f57781 parent 54f615f3 files · +34 −11Browse files

Unified · Split

3 files
  1. gui-wl/wl-cb.c +26 −0
  2. gui-wl/wl-screen.c +5 −7
  3. gui-wl/wl-util.c +3 −4
gui-wl/wl-cb.c+26−0
@@ -530,14 +530,40 @@ static const struct xdg_wm_base_listener xdg_wm_base_listener = { · 529 unmodified lines
530530 .ping = xdg_wm_base_ping,
531531 };
532532
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+
533555 static void
534556 handle_global(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version)
535557 {
536558 Wlwin *wl;
559+ struct wl_output *out;
537560
538561 wl = data;
539562 if(strcmp(interface, wl_shm_interface.name) == 0) {
540563 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);
541567 } else if(strcmp(interface, wl_seat_interface.name) == 0) {
542568 //We don't support multiseat
543569 if(wl->seat != nil)
gui-wl/wl-screen.c+5−7
@@ -39,8 +39,8 @@ newwlwin(void) · 38 unmodified lines
3939 sysfatal("malloc Wlwin");
4040 wl->dx = 1024;
4141 wl->dy = 1024;
42− wl->monx = 1920;
43− wl->mony = 1080;
42+ wl->monx = wl->dx;
43+ wl->mony = wl->dy;
4444 return wl;
4545 }
4646
@@ -60,6 +60,8 @@ wlflush(Wlwin *wl) · 13 unmodified lines
6060 wl_surface_commit(wl->surface);
6161 }
6262
63+void _screenresize(Rectangle);
64+
6365 void
6466 wlresize(Wlwin *wl, int x, int y)
6567 {
@@ -73,11 +75,7 @@ wlresize(Wlwin *wl, int x, int y) · 7 unmodified lines
7375 r = Rect(0, 0, wl->dx, wl->dy);
7476 gscreen = allocmemimage(r, XRGB32);
7577 gscreen->clipr = ZR;
76− qunlock(&drawlock);
77−
78− screenresize(r);
79−
80− qlock(&drawlock);
78+ _screenresize(r);
8179 wl->dirty = 1;
8280 wl->r = r;
8381 wlflush(wl);
gui-wl/wl-util.c+3−4
@@ -50,7 +50,6 @@ wlcreateshm(off_t size) · 49 unmodified lines
5050 void
5151 wlallocpool(Wlwin *wl)
5252 {
53− int screenx, screeny;
5453 int screensize, cursorsize;
5554 int depth;
5655 int fd;
@@ -59,9 +58,7 @@ wlallocpool(Wlwin *wl) · 2 unmodified lines
5958 wl_shm_pool_destroy(wl->pool);
6059
6160 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;
6562 cursorsize = 16 * 16 * depth;
6663
6764 fd = wlcreateshm(screensize+cursorsize);
@@ -89,6 +86,8 @@ wlallocbuffer(Wlwin *wl) · 21 unmodified lines
8986 if(wl->pool == nil || size+(16*16*depth) > wl->poolsize)
9087 wlallocpool(wl);
9188
89+ assert(size+(16*16*depth) <= wl->poolsize);
90+
9291 if(wl->screenbuffer != nil)
9392 wl_buffer_destroy(wl->screenbuffer);
9493 if(wl->cursorbuffer != nil)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t