aboutsummaryrefslogtreecommitdiff
path: root/src/Wetterhorn/Core.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Wetterhorn/Core.hs')
-rw-r--r--src/Wetterhorn/Core.hs39
1 files changed, 32 insertions, 7 deletions
diff --git a/src/Wetterhorn/Core.hs b/src/Wetterhorn/Core.hs
index 2f885f9..4a48f28 100644
--- a/src/Wetterhorn/Core.hs
+++ b/src/Wetterhorn/Core.hs
@@ -34,6 +34,8 @@ import Numeric (showHex)
import Text.Printf
import Wetterhorn.Core.ForeignInterface (ForeignInterface)
import qualified Wetterhorn.Core.ForeignInterface as ForeignInterface
+import Wetterhorn.WlRoots (WlrInputDevice, wlrSeatKeyboardNotifyKey, wlrSeatSetKeyboard)
+import Data.Char (chr, ord)
data WContext = WContext
{ ctxForeignInterface :: ForeignInterface,
@@ -79,9 +81,10 @@ data KeyEvent = KeyEvent
state :: KeyState,
modifiers :: Word32,
keysym :: Word32,
- codepoint :: Char
+ codepoint :: Char,
+ device :: Ptr WlrInputDevice
}
- deriving (Show, Read, Ord, Eq)
+ deriving (Show, Ord, Eq)
data WConfig = WConfig
{ keybindingHandler :: KeyEvent -> W Bool,
@@ -91,19 +94,41 @@ data WConfig = WConfig
defaultBindings :: Map (KeyState, Word32, Word32) (W ())
defaultBindings =
Map.fromList
- [ ((KeyPressed, 0x8, 0x72), requestHotReload),
- ((KeyPressed, 0x8, 0x6c), requestLog "This is a log statement!\n"),
- ((KeyPressed, 0x8, 0x71), requestExit 0)
+ [ ((KeyPressed, 0x8, sym 'r'), requestHotReload),
+ ((KeyPressed, 0x8, sym 'l'), requestLog "This is a log statement!\n"),
+ ((KeyPressed, 0x8, sym 't'), wio $ ForeignInterface.doShellExec "alacritty"),
+ ((KeyPressed, 0x9, sym 'T'), wio $ ForeignInterface.doShellExec "gnome-terminal"),
+ ((KeyPressed, 0x8, sym 'c'), wio $ ForeignInterface.doShellExec "pavucontrol"),
+ ((KeyPressed, 0x8, sym 'q'), requestExit 0)
]
+ where
+ sym = fromIntegral . ord
+
defaultConfig :: WConfig
defaultConfig =
WConfig
{ keybindingHandler = \keyEvent -> do
i <- incrementState
+ seatPtr <- (wio . ForeignInterface.getSeat . ctxForeignInterface) =<< getWContext
+
wio $ printf "%d - Got %s\n" i (show keyEvent)
- maybe (return False) (fmap (const True)) $
- Map.lookup
+ maybe
+ ( wio $ do
+ wlrSeatSetKeyboard seatPtr (device keyEvent)
+ wlrSeatKeyboardNotifyKey
+ seatPtr
+ (timeMs keyEvent)
+ (keycode keyEvent)
+ ( case state keyEvent of
+ KeyReleased -> 0
+ _ -> 1
+ )
+
+ return True
+ )
+ (fmap (const True))
+ $ Map.lookup
(state keyEvent, modifiers keyEvent, keysym keyEvent)
defaultBindings,
surfaceHandler = \state ptr -> wio (printf "Surface %s is %s\n" (showHex (ptrToIntPtr ptr) "") (show state))