aboutsummaryrefslogtreecommitdiff
path: root/plug/src/Config.hs
blob: c76898ec406f79b2c6a466b2bd9f11fff673763e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
module Config () where

import Control.Monad.IO.Class (liftIO)
import Data.Bits (shiftL, (.&.))
import Data.Word (Word32)
import Montis.Core
import Montis.Base.Foreign.Runtime
import Montis.Standard.Drag (DragConfig (DragConfig), unwrapSelf)
import Montis.Standard.Keys (KeysConfig (KeysConfig), subkeys)
import Montis.Standard.Mouse (MouseConfig (MouseConfig))

foreign export ccall "plugin_cold_start"
  coldStart :: MontisColdStart

foreign export ccall "plugin_hot_start"
  hotStart :: MontisHotStart

coldStart :: MontisColdStart
coldStart = coldStartMontis config

hotStart :: MontisHotStart
hotStart = hotStartMontis config

keys :: KeyEvent -> Montis Bool
keys ev
  | keyEvent_modifiers ev .&. mod1Mask == 0 = return False
  | otherwise = case keyEvent_codepoint ev of
      'j' -> do
        liftIO (putStrLn "j was pressed!")
        subkeys $ \ev -> case keyEvent_codepoint ev of
          'k' -> do
            liftIO (putStrLn "k was pressed after j!")
            self <- getSelfPtr
            liftIO $ foreign_warpCursor (unwrapSelf self) 0 0
            return True
          _ -> return False
      _ -> return False

mod1Mask :: Word32
mod1Mask = 1 `shiftL` 3 -- WLR_MODIFIER_ALT

config :: MontisConfig
config =
  install MouseConfig $
    install (DragConfig mod1Mask) $
      install (KeysConfig keys) defaultConfig