@@ -19,7 +19,7 @@ import Control.Monad.IO.Class (MonadIO)
19
19
import Data.GI.Base (AttrOp ((:=) ), new )
20
20
import Data.IORef (IORef , newIORef )
21
21
import qualified Data.Map.Strict as Map
22
- import Data.Maybe (fromJust )
22
+ import Data.Maybe (fromJust , fromMaybe )
23
23
import Data.Text (Text )
24
24
import Data.Time.Clock.System (getSystemTime )
25
25
import Data.Word (Word16 )
@@ -32,6 +32,7 @@ import GuiInternals
32
32
( AppState ,
33
33
Inputs ,
34
34
KeyEvent (.. ),
35
+ KeyInput (.. ),
35
36
MouseButton (.. ),
36
37
backgroundPress ,
37
38
emptyAppState ,
@@ -119,15 +120,17 @@ backgroundPressCallback inputsRef stateRef eventButton = do
119
120
decodeKey :: Maybe Text -> Word16 -> KeyEvent
120
121
decodeKey mKeyStr keyCode =
121
122
case mKeyStr of
122
- Nothing -> UnknownKey
123
- Just keyStr -> case Map. lookup keyStr keyStrings of
124
- Just e -> e
125
- Nothing -> case Map. lookup keyCode keyCodes of
126
- Just e -> e
127
- Nothing -> UnknownKey
128
-
129
- keyPressCallback :: IORef Inputs -> IORef AppState -> Gdk. EventKey -> IO Bool
130
- keyPressCallback inputsRef stateRef eventKey = do
123
+ Nothing -> OtherKey " "
124
+ Just keyStr ->
125
+ fromMaybe
126
+ ( fromMaybe
127
+ (OtherKey keyStr)
128
+ (Map. lookup keyCode keyCodes)
129
+ )
130
+ (Map. lookup keyStr keyStrings)
131
+
132
+ getKeyInput :: MonadIO m => Gdk. EventKey -> m KeyInput
133
+ getKeyInput eventKey = do
131
134
-- TODO May want to check that ctrl is pressed by checking that
132
135
-- getEventKeyState is ModifierTypeControlMask. May also want to use
133
136
-- Gdk.KEY_?.
@@ -141,20 +144,22 @@ keyPressCallback inputsRef stateRef eventKey = do
141
144
keyCode <- Gdk. getEventKeyHardwareKeycode eventKey
142
145
-- putStrLn $ "key: " <> show mKey
143
146
-- putStrLn $ "keycode: " <> show keyCode
144
- let keyEvent = decodeKey mKey keyCode
147
+ pure $ KeyInput (fromMaybe " " mKey) (decodeKey mKey keyCode)
148
+
149
+ keyPressCallback :: IORef Inputs -> IORef AppState -> Gdk. EventKey -> IO Bool
150
+ keyPressCallback inputsRef stateRef eventKey = do
145
151
-- print keyEvent
146
- keyPress inputsRef stateRef keyEvent
152
+ keyInput <- getKeyInput eventKey
153
+ keyPress inputsRef stateRef keyInput
147
154
pure Gdk. EVENT_STOP
148
155
149
156
keyReleaseCallback :: IORef Inputs -> Gdk. EventKey -> IO Bool
150
157
keyReleaseCallback inputsRef eventKey = do
151
158
-- TODO May want to check that ctrl is pressed by checking that
152
159
-- getEventKeyState is ModifierTypeControlMask. May also want to use
153
160
-- Gdk.KEY_?.
154
- mKey <- Gdk. getEventKeyString eventKey
155
- keyCode <- Gdk. getEventKeyHardwareKeycode eventKey
156
- let keyEvent = decodeKey mKey keyCode
157
- keyRelease inputsRef keyEvent
161
+ keyInput <- getKeyInput eventKey
162
+ keyRelease inputsRef keyInput
158
163
pure Gdk. EVENT_STOP
159
164
160
165
scrollCallback :: IORef Inputs -> Gdk. EventScroll -> IO Bool
0 commit comments