mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-07 18:35:34 +00:00
app: add support for system cursors
Signed-off-by: pierre <pierre.curto@gmail.com>
This commit is contained in:
@@ -764,16 +764,7 @@ func gio_onPointerEnter(data unsafe.Pointer, pointer *C.struct_wl_pointer, seria
|
||||
s.serial = serial
|
||||
w := callbackLoad(unsafe.Pointer(surf)).(*window)
|
||||
s.pointerFocus = w
|
||||
// Get images[0].
|
||||
img := *w.cursor.cursor.images
|
||||
buf := C.wl_cursor_image_get_buffer(img)
|
||||
if buf == nil {
|
||||
return
|
||||
}
|
||||
C.wl_pointer_set_cursor(pointer, serial, w.cursor.surf, C.int32_t(img.hotspot_x), C.int32_t(img.hotspot_y))
|
||||
C.wl_surface_attach(w.cursor.surf, buf, 0, 0)
|
||||
C.wl_surface_damage(w.cursor.surf, 0, 0, C.int32_t(img.width), C.int32_t(img.height))
|
||||
C.wl_surface_commit(w.cursor.surf)
|
||||
w.setCursor(pointer, serial)
|
||||
w.lastPos = f32.Point{X: fromFixed(x), Y: fromFixed(y)}
|
||||
}
|
||||
|
||||
@@ -917,6 +908,50 @@ func (w *window) WriteClipboard(s string) {
|
||||
w.disp.wakeup()
|
||||
}
|
||||
|
||||
func (w *window) SetCursor(name pointer.CursorName) {
|
||||
if name == pointer.CursorNone {
|
||||
C.wl_pointer_set_cursor(w.disp.seat.pointer, w.serial, nil, 0, 0)
|
||||
return
|
||||
}
|
||||
switch name {
|
||||
default:
|
||||
fallthrough
|
||||
case pointer.CursorDefault:
|
||||
name = "left_ptr"
|
||||
case pointer.CursorText:
|
||||
name = "xterm"
|
||||
case pointer.CursorPointer:
|
||||
name = "hand1"
|
||||
case pointer.CursorCrossHair:
|
||||
name = "crosshair"
|
||||
case pointer.CursorRowResize:
|
||||
name = "top_side"
|
||||
case pointer.CursorColResize:
|
||||
name = "left_side"
|
||||
}
|
||||
cname := C.CString(string(name))
|
||||
defer C.free(unsafe.Pointer(cname))
|
||||
c := C.wl_cursor_theme_get_cursor(w.cursor.theme, cname)
|
||||
if c == nil {
|
||||
return
|
||||
}
|
||||
w.cursor.cursor = c
|
||||
w.setCursor(w.disp.seat.pointer, w.serial)
|
||||
}
|
||||
|
||||
func (w *window) setCursor(pointer *C.struct_wl_pointer, serial C.uint32_t) {
|
||||
// Get images[0].
|
||||
img := *w.cursor.cursor.images
|
||||
buf := C.wl_cursor_image_get_buffer(img)
|
||||
if buf == nil {
|
||||
return
|
||||
}
|
||||
C.wl_pointer_set_cursor(pointer, serial, w.cursor.surf, C.int32_t(img.hotspot_x), C.int32_t(img.hotspot_y))
|
||||
C.wl_surface_attach(w.cursor.surf, buf, 0, 0)
|
||||
C.wl_surface_damage(w.cursor.surf, 0, 0, C.int32_t(img.width), C.int32_t(img.height))
|
||||
C.wl_surface_commit(w.cursor.surf)
|
||||
}
|
||||
|
||||
func (w *window) resetFling() {
|
||||
w.fling.start = false
|
||||
w.fling.anim = fling.Animation{}
|
||||
|
||||
Reference in New Issue
Block a user