45 lines
1.0 KiB
Go
45 lines
1.0 KiB
Go
// Copyright (c) 2026 Storm Dragon
|
|
// Authors: Storm Dragon, Angus Kola
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
package xorg
|
|
|
|
/*
|
|
#cgo pkg-config: x11
|
|
#include "commands_native.h"
|
|
*/
|
|
import "C"
|
|
|
|
type PointerPosition struct {
|
|
X, Y, PID int
|
|
Window uint64
|
|
Known bool
|
|
}
|
|
|
|
// PointerReader owns one X connection. Use it from one goroutine and close it
|
|
// after that goroutine has stopped.
|
|
type PointerReader struct{ display *C.Display }
|
|
|
|
func OpenPointerReader() *PointerReader {
|
|
display := C.XOpenDisplay(nil)
|
|
if display == nil {
|
|
return nil
|
|
}
|
|
return &PointerReader{display: display}
|
|
}
|
|
|
|
func (reader *PointerReader) Read() PointerPosition {
|
|
if reader == nil || reader.display == nil {
|
|
return PointerPosition{}
|
|
}
|
|
value := C.cthulhu_read_pointer(reader.display)
|
|
return PointerPosition{X: int(value.x), Y: int(value.y), PID: int(value.pid),
|
|
Window: uint64(value.window), Known: value.known != 0}
|
|
}
|
|
|
|
func (reader *PointerReader) Close() {
|
|
if reader != nil && reader.display != nil {
|
|
C.XCloseDisplay(reader.display)
|
|
reader.display = nil
|
|
}
|
|
}
|