shithub: drawterm

Download patch

ref: f9ae0c837bf8351037689f1985c1a52c1570ba30
parent: c4ea4d299aa1bbbcc972c04adf06c18245ce7674
author: Jacob Moody <moody@posixcafe.org>
date: Sat Dec 23 13:52:05 EST 2023

gui-wl: make primary selection not strictly required

Wayland cage does not provide a primary selection but
runs otherwise, so print a warning and move on. Also
cleans up instances of sysfatal which should really be
panics instead.

--- a/gui-wl/wl-cb.c
+++ b/gui-wl/wl-cb.c
@@ -776,8 +776,8 @@
 	wl_display_roundtrip(wl->display);
 	wl->xkb_context = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
 
-	if(wl->shm == nil || wl->compositor == nil || wl->xdg_wm_base == nil || wl->seat == nil || wl->primsel == nil)
-		sysfatal("registration fell short");
+	if(wl->shm == nil || wl->compositor == nil || wl->xdg_wm_base == nil || wl->seat == nil)
+		panic("required wayland capabilities not met");
 
 	if(wl->vpmgr != nil)
 		wl->vpointer = zwlr_virtual_pointer_manager_v1_create_virtual_pointer(wl->vpmgr, wl->seat);
@@ -808,7 +808,10 @@
 	if(wl->data_device_manager != nil && wl->seat != nil){
 		wl->data_device = wl_data_device_manager_get_data_device(wl->data_device_manager, wl->seat);
 		wl_data_device_add_listener(wl->data_device, &data_device_listener, wl);
-		wl->primsel_device = zwp_primary_selection_device_manager_v1_get_device(wl->primsel, wl->seat);
+		if(wl->primsel != nil)
+			wl->primsel_device = zwp_primary_selection_device_manager_v1_get_device(wl->primsel, wl->seat);
+		else
+			iprint("primary selection not available, clipboard will not work\n");
 	}
 }
 
--- a/gui-wl/wl-screen.c
+++ b/gui-wl/wl-screen.c
@@ -36,7 +36,7 @@
 
 	wl = mallocz(sizeof *wl, 1);
 	if(wl == nil)
-		sysfatal("malloc Wlwin");
+		panic("malloc Wlwin");
 	wl->dx = 1024;
 	wl->dy = 1024;
 	wl->monx = wl->dx;
@@ -185,7 +185,7 @@
 	gwin = wl;
 	wl->display = wl_display_connect(nil);
 	if(wl->display == nil)
-		sysfatal("could not connect to display");
+		panic("could not connect to display");
 
 	memimageinit();
 	wlsetcb(wl);
--- a/gui-wl/wl-util.c
+++ b/gui-wl/wl-util.c
@@ -34,7 +34,7 @@
 	int fd;
 
 	if((dir = getenv("XDG_RUNTIME_DIR")) == nil)
-		sysfatal("XDG_RUNTIME_DIR not set");
+		panic("XDG_RUNTIME_DIR not set");
 
 	path = malloc(strlen(dir) + sizeof(name) + 1);
 	strcpy(path, dir);
@@ -63,12 +63,12 @@
 
 	fd = wlcreateshm(screensize+cursorsize);
 	if(fd < 0)
-		sysfatal("could not mk_shm_fd");
+		panic("could not mk_shm_fd");
 	ftruncate(fd, screensize+cursorsize);
 
 	wl->shm_data = mmap(nil, screensize+cursorsize, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
 	if(wl->shm_data == MAP_FAILED)
-		sysfatal("could not mmap shm_data");
+		panic("could not mmap shm_data");
 
 	wl->pool = wl_shm_create_pool(wl->shm, fd, screensize+cursorsize);
 	wl->poolsize = screensize+cursorsize;