shithub: drawterm

Download patch

ref: f11139d4c918802a87730bc14d094670ee4ce572
parent: 19f4185f3967a5c00053236015da22c0da2af41d
author: mia soweli <inbox@tachibana-labs.org>
date: Wed Jul 3 11:30:56 EDT 2024

gui-wl: Correct the previous cursor fix

The Plan 9 cursor bitmap is transformed into an ARGB8888 surface to be displayed by the
Wayland compositor. However, the mask used to decide the pixel colour was incorrect.

When j = 0 the mask is 1<<16 which is not valid.
When j = 15 the mask is 1<<1 which is not the final pixel.
This results in the cursor image being shifted 1px right, off the edge of the surface.
The correct mask is (1<<15) >> j;

Thanks moody for cleaning up the patch.

--- a/gui-wl/wl-util.c
+++ b/gui-wl/wl-util.c
@@ -54,7 +54,7 @@
 
 	depth = 4;
 	screensize = wl->monx * wl->mony * depth;
-	cursorsize = 32 * 32 * depth;
+	cursorsize = 16 * 16 * depth;
 
 	fd = wlcreateshm(screensize+cursorsize);
 	if(fd < 0)
@@ -90,7 +90,7 @@
 		wl_buffer_destroy(wl->cursorbuffer);
 
 	wl->screenbuffer = wl_shm_pool_create_buffer(wl->pool, 0, wl->dx, wl->dy, wl->dx*4, WL_SHM_FORMAT_XRGB8888);
-	wl->cursorbuffer = wl_shm_pool_create_buffer(wl->pool, size, 32, 32, 32*4, WL_SHM_FORMAT_ARGB8888);
+	wl->cursorbuffer = wl_shm_pool_create_buffer(wl->pool, size, 16, 16, 16*4, WL_SHM_FORMAT_ARGB8888);
 }
 
 enum {
@@ -109,26 +109,27 @@
 	uint16_t clr[16], set[16];
 
 	buf = wl->shm_data+(wl->dx*wl->dy*4);
-	for(i=0,j=0; i < 16; i++,j+=2){
+	for(i = 0, j = 0; i < 16; i++, j += 2){
 		clr[i] = c->clr[j]<<8 | c->clr[j+1];
 		set[i] = c->set[j]<<8 | c->set[j+1];
 	}
-	for(i=0; i < 32; i++){
-		for(j = 0; j < 32; j++){
-			pos = i*32 + j;
-			mask = (1<<16) >> j;
 
+	for(i = 0, pos = 0; i < 16; i++){
+		for(j = 0; j < 16; j++, pos++){
+			mask = (1<<15) >> j;
 			buf[pos] = Transparent;
-			if(i < 16 && clr[i] & mask)
+			if(clr[i] & mask)
 				buf[pos] = White;
-			if(i < 16 && set[i] & mask)
+			if(set[i] & mask)
 				buf[pos] = Black;
 		}
 	}
+
 	if(wl->cursorsurface == nil)
 		wl->cursorsurface = wl_compositor_create_surface(wl->compositor);
+
 	wl_surface_attach(wl->cursorsurface, wl->cursorbuffer, 0, 0);
-	wl_surface_damage(wl->cursorsurface, 0, 0, 32, 32);
+	wl_surface_damage(wl->cursorsurface, 0, 0, 16, 16);
 	wl_surface_commit(wl->cursorsurface);
 	wl_pointer_set_cursor(wl->pointer, wl->pointerserial, wl->cursorsurface, -c->offset.x, -c->offset.y);
 }