2020-11-02 04:09:48 +13:00
|
|
|
package desktop
|
|
|
|
|
|
|
|
import (
|
2021-01-13 11:48:15 +13:00
|
|
|
"os/exec"
|
|
|
|
|
2020-11-02 04:09:48 +13:00
|
|
|
"demodesk/neko/internal/types"
|
|
|
|
"demodesk/neko/internal/desktop/xorg"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (manager *DesktopManagerCtx) Move(x, y int) {
|
|
|
|
xorg.Move(x, y)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (manager *DesktopManagerCtx) Scroll(x, y int) {
|
|
|
|
xorg.Scroll(x, y)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (manager *DesktopManagerCtx) ButtonDown(code int) error {
|
|
|
|
return xorg.ButtonDown(code)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (manager *DesktopManagerCtx) KeyDown(code uint64) error {
|
|
|
|
return xorg.KeyDown(code)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (manager *DesktopManagerCtx) ButtonUp(code int) error {
|
|
|
|
return xorg.ButtonUp(code)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (manager *DesktopManagerCtx) KeyUp(code uint64) error {
|
|
|
|
return xorg.KeyUp(code)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (manager *DesktopManagerCtx) ResetKeys() {
|
|
|
|
xorg.ResetKeys()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (manager *DesktopManagerCtx) ScreenConfigurations() map[int]types.ScreenConfiguration {
|
|
|
|
return xorg.ScreenConfigurations
|
|
|
|
}
|
|
|
|
|
|
|
|
func (manager *DesktopManagerCtx) GetScreenSize() *types.ScreenSize {
|
|
|
|
return xorg.GetScreenSize()
|
|
|
|
}
|
|
|
|
|
2020-11-04 12:27:47 +13:00
|
|
|
func (manager *DesktopManagerCtx) ChangeScreenSize(width int, height int, rate int) error {
|
2021-01-05 07:39:21 +13:00
|
|
|
mu.Lock()
|
2020-11-08 05:22:25 +13:00
|
|
|
manager.emmiter.Emit("before_screen_size_change")
|
2021-01-05 07:39:21 +13:00
|
|
|
|
|
|
|
defer func() {
|
|
|
|
manager.emmiter.Emit("after_screen_size_change")
|
|
|
|
mu.Unlock()
|
|
|
|
}()
|
|
|
|
|
|
|
|
return xorg.ChangeScreenSize(width, height, rate)
|
2020-11-04 12:27:47 +13:00
|
|
|
}
|
|
|
|
|
2021-01-13 11:48:15 +13:00
|
|
|
func (manager *DesktopManagerCtx) SetKeyboardLayout(layout string) error {
|
|
|
|
// TOOD: Use native API.
|
|
|
|
cmd := exec.Command("setxkbmap", layout)
|
|
|
|
_, err := cmd.Output()
|
|
|
|
return err
|
2020-11-02 04:09:48 +13:00
|
|
|
}
|
|
|
|
|
2021-01-13 10:54:13 +13:00
|
|
|
func (manager *DesktopManagerCtx) SetKeyboardModifiers(mod types.KeyboardModifiers) {
|
|
|
|
if mod.NumLock != nil {
|
|
|
|
xorg.SetKeyboardModifier(xorg.KBD_NUM_LOCK, *mod.NumLock)
|
|
|
|
}
|
|
|
|
|
|
|
|
if mod.CapsLock != nil {
|
|
|
|
xorg.SetKeyboardModifier(xorg.KBD_CAPS_LOCK, *mod.CapsLock)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (manager *DesktopManagerCtx) GetKeyboardModifiers() types.KeyboardModifiers {
|
2021-01-13 11:35:11 +13:00
|
|
|
modifiers := xorg.GetKeyboardModifiers()
|
|
|
|
|
|
|
|
NumLock := (modifiers & xorg.KBD_NUM_LOCK) != 0
|
|
|
|
CapsLock := (modifiers & xorg.KBD_CAPS_LOCK) != 0
|
2021-01-13 10:54:13 +13:00
|
|
|
|
|
|
|
return types.KeyboardModifiers{
|
|
|
|
NumLock: &NumLock,
|
|
|
|
CapsLock: &CapsLock,
|
|
|
|
}
|
2020-11-02 04:09:48 +13:00
|
|
|
}
|
2021-01-10 10:58:18 +13:00
|
|
|
|
|
|
|
func (manager *DesktopManagerCtx) GetCursorImage() *types.CursorImage {
|
|
|
|
return xorg.GetCursorImage()
|
|
|
|
}
|