Session: draw the program's own pointer - resize arrows at window edges, I-beams, its hide

The compositor threw every wl_pointer.set_cursor image away and the app drew one fixed arrow,
so the desktop never showed labwc's resize arrows at a window's edges and corners. Ported from
Bannerlator (7f19c669): the cursor surface gets a role, its image is snapshotted on commit with
its hotspot, and a NULL surface or buffer is an authoritative hide; the app's overlay draws the
image at the session's scale. New here: labwc on Vulkan/GLES hands its cursor over as a dma-buf
(wlroots' nested backend, usually UBWC), so it is read back through a small linear host-visible
copy (vkp_image_readback). The built-in arrow stays until a program sets a cursor.
This commit is contained in:
The412Banner committed 2026-09-25 08:28:26 -04:00
1 parent 347a5a4dcb
commit c331836bce
7 files changed
+305 -6

No files matched your search

@@ -6,13 +6,35 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.FilterQuality
import androidx.compose.ui.graphics.ImageBitmap
import androidx.compose.ui.graphics.Path
import androidx.compose.ui.graphics.drawscope.Stroke
/**
* The session's pointer. [image]: the program's own cursor (wl_pointer.set_cursor - labwc's resize
* arrows, a text field's I-beam), in session pixels, drawn [imageScale] times larger with its hotspot
* ([hotX], [hotY]) on [position]; null = the program has not set one, and the built-in arrow is drawn.
*/
@Composable
fun CursorOverlay(position: Offset, visible: Boolean, scale: Float) {
fun CursorOverlay(
position: Offset, visible: Boolean, scale: Float,
image: ImageBitmap? = null, hotX: Int = 0, hotY: Int = 0, imageScale: Float = 1f,
) {
if (!visible) return
Canvas(modifier = Modifier.fillMaxSize()) {
if (image != null) {
val w = (image.width * imageScale).toInt().coerceAtLeast(1)
val h = (image.height * imageScale).toInt().coerceAtLeast(1)
drawImage(
image,
dstOffset = androidx.compose.ui.unit.IntOffset(
(position.x - hotX * imageScale).toInt(), (position.y - hotY * imageScale).toInt()),
dstSize = androidx.compose.ui.unit.IntSize(w, h),
filterQuality = FilterQuality.Low,
)
return@Canvas
}
val s = 11f * scale
val path = Path().apply {
moveTo(position.x, position.y)