diff --git a/controller.go b/controller.go index 7652998..d389986 100644 --- a/controller.go +++ b/controller.go @@ -111,6 +111,35 @@ func NewWlRootsController( }, nil } +// NewKWinController creates a KWin / Linux Wayland controller via PipeWire and /dev/uinput. +// +// Despite the name "KWin", this controller works with any Wayland compositor that +// implements the XDG Screencast Portal and kernel has uinput support (e.g., GNOME). +// +// deviceNode is the uinput device node path (e.g., "/dev/uinput"). +// screenWidth and screenHeight are the screen dimensions in pixels. +// useWin32VkCode specifies whether key codes are interpreted as Win32 Virtual-Key codes +// (VK_*) and translated to Linux evdev codes internally. If false, key codes are passed +// through as raw evdev codes. +// +// Dependencies: pipewire (1.0+), xdg-desktop-portal. +func NewKWinController( + deviceNode string, + screenWidth, screenHeight int, + useWin32VkCode bool, +) (*Controller, error) { + handle := native.MaaKWinControllerCreate(deviceNode, screenWidth, screenHeight, useWin32VkCode) + if handle == 0 { + return nil, errors.New("failed to create KWin controller") + } + + initControllerStore(handle) + + return &Controller{ + handle: handle, + }, nil +} + // NewMacOSController creates a macOS controller for native macOS applications. // windowID is the CGWindowID of the target window (0 for desktop). // screencapMethod is the macOS screencap method to use. diff --git a/internal/native/framework.go b/internal/native/framework.go index a1e80c8..ff20785 100644 --- a/internal/native/framework.go +++ b/internal/native/framework.go @@ -218,6 +218,7 @@ var ( MaaPlayCoverControllerCreate func(address, uuid string) uintptr MaaWin32ControllerCreate func(hWnd unsafe.Pointer, screencapMethods uint64, mouseMethod, keyboardMethod uint64) uintptr MaaWlRootsControllerCreate func(wlrSocketPath string, useWin32VkCode bool) uintptr + MaaKWinControllerCreate func(deviceNode string, screenWidth, screenHeight int, useWin32VkCode bool) uintptr MaaCustomControllerCreate func(controller unsafe.Pointer, controllerArg uintptr) uintptr MaaGamepadControllerCreate func(hWnd unsafe.Pointer, gamepadType MaaGamepadType, screencapMethod uint64) uintptr MaaMacOSControllerCreate func(windowID uint32, screencapMethod MaaMacOSScreencapMethod, inputMethod MaaMacOSInputMethod) uintptr @@ -447,6 +448,7 @@ var frameworkEntries = []Entry{ {&MaaPlayCoverControllerCreate, "MaaPlayCoverControllerCreate"}, {&MaaWin32ControllerCreate, "MaaWin32ControllerCreate"}, {&MaaWlRootsControllerCreate, "MaaWlRootsControllerCreate"}, + {&MaaKWinControllerCreate, "MaaKWinControllerCreate"}, {&MaaCustomControllerCreate, "MaaCustomControllerCreate"}, {&MaaGamepadControllerCreate, "MaaGamepadControllerCreate"}, {&MaaMacOSControllerCreate, "MaaMacOSControllerCreate"},