Skip to content

Commit

Permalink
Getting stuff hooked back up
Browse files Browse the repository at this point in the history
  • Loading branch information
david-janssen committed May 15, 2020
1 parent f70c5d2 commit 1b20e77
Show file tree
Hide file tree
Showing 20 changed files with 875 additions and 1,467 deletions.
6 changes: 2 additions & 4 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ module Main
)
where

import KPrelude
import KMonad.Args.Cmd
import KMonad.App
import KMonad.Args (run)

main :: IO ()
main = getCmd >>= print
main = run
8 changes: 6 additions & 2 deletions kmonad.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ library
KMonad.App
KMonad.App.Dispatch
KMonad.App.Hooks
KMonad.App.PressHandler
KMonad.App.Keymap
KMonad.App.Sluice
KMonad.Args
KMonad.Args.Cmd
KMonad.Args.Parser
KMonad.Args.Joiner
KMonad.Args.Types
KMonad.Button
KMonad.Keyboard
KMonad.Keyboard.Keycode
Expand Down Expand Up @@ -171,7 +175,7 @@ executable kmonad
-- MultiParamTypeClasses
-- MultiWayIf
-- NamedFieldPuns
NoImplicitPrelude
-- NoImplicitPrelude
-- OverloadedStrings
-- PartialTypeSignatures
-- PatternGuards
Expand Down
3 changes: 1 addition & 2 deletions src/KLisp/Joiner.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,9 @@ where

import KPrelude hiding (uncons)

import KLisp.Types
import KMonad.Args.Types

import KMonad.Button
import KMonad.Daemon
import KMonad.Keyboard
import KMonad.Keyboard.IO
import KMonad.Keyboard.IO.Linux.DeviceSource
Expand Down
1 change: 0 additions & 1 deletion src/KLisp/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import KPrelude
import KMonad.Button
import KMonad.Keyboard
import KMonad.Keyboard.IO
import KMonad.Daemon.KeyHandler (Keymap)

import Text.Megaparsec
import Text.Megaparsec.Char
Expand Down
30 changes: 14 additions & 16 deletions src/KMonad/App.hs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import KMonad.Keyboard
import KMonad.Keyboard.IO
import KMonad.Util

import qualified KMonad.App.Dispatch as Dp
import qualified KMonad.App.Hooks as Hs
import qualified KMonad.App.Sluice as Sl
import qualified KMonad.App.PressHandler as Ph
import qualified KMonad.App.Dispatch as Dp
import qualified KMonad.App.Hooks as Hs
import qualified KMonad.App.Sluice as Sl
import qualified KMonad.App.Keymap as Km

--------------------------------------------------------------------------------
-- $appcfg
Expand All @@ -48,9 +48,8 @@ import qualified KMonad.App.PressHandler as Ph
data AppCfg = AppCfg
{ _keySinkDev :: Acquire KeySink -- ^ How to open a 'KeySink'
, _keySourceDev :: Acquire KeySource -- ^ How to open a 'KeySource'
, _keymapCfg :: Keymap Button -- ^ The map defining the 'Button' layout
, _keymapCfg :: LMap Button -- ^ The map defining the 'Button' layout
, _firstLayer :: LayerTag -- ^ Active layer when KMonad starts
, _acLogFunc :: LogFunc -- ^ How to perform logging
}
makeClassy ''AppCfg

Expand All @@ -68,7 +67,7 @@ data AppEnv = AppEnv
, _sluice :: Sl.Sluice

-- Other components
, _keymap :: Ph.PressHandler
, _keymap :: Km.Keymap
}
makeClassy ''AppEnv

Expand Down Expand Up @@ -99,7 +98,7 @@ initAppEnv cfg = flip runContT pure $ do
slc <- Sl.mkSluice $ Hs.pull hks

-- Initialize the button environments in the keymap
phl <- Ph.mkPressHandler (cfg^.firstLayer) (cfg^.keymapCfg)
phl <- Km.mkKeymap (cfg^.firstLayer) (cfg^.keymapCfg)

pure $ AppEnv
{ _keLogFunc = lgf
Expand All @@ -122,7 +121,7 @@ initAppEnv cfg = flip runContT pure $ do
-- | Trigger the button-action press currently registered to 'Keycode'
pressKey :: (HasAppEnv e, HasLogFunc e) => Keycode -> RIO e ()
pressKey c =
view keymap >>= flip Ph.lookupKey c >>= \case
view keymap >>= flip Km.lookupKey c >>= \case
Nothing -> pure () -- If the keycode does not occur in our keymap
Just b -> runBEnv b Press >>= \case
Nothing -> pure () -- If the previous action on this key was *not* a release
Expand All @@ -144,11 +143,10 @@ loop = forever $ view sluice >>= Sl.pull >>= \case
_ -> pure ()

-- | Run 'KMonad' using the provided configuration
startApp :: MonadIO m => AppCfg -> m ()
startApp c = runRIO (c^.acLogFunc) $ do
app <- initAppEnv c
runRIO app loop

startApp :: HasLogFunc e => AppCfg -> RIO e ()
startApp c = initAppEnv c >>= flip runRIO loop


--------------------------------------------------------------------------------
-- $kenv
--
Expand Down Expand Up @@ -185,5 +183,5 @@ instance MonadK (RIO KEnv) where
hookNext t f = view hooks >>= \hs -> Hs.hookNext hs t f
hookWithin ms t f = view hooks >>= \hs -> Hs.hookWithin hs ms t f

-- Layer-ops are sent to the 'PressHandler'
layerOp o = view keymap >>= \hl -> Ph.layerOp hl o
-- Layer-ops are sent to the 'Keymap'
layerOp o = view keymap >>= \hl -> Km.layerOp hl o
115 changes: 0 additions & 115 deletions src/KMonad/App/DispatchOld.hs

This file was deleted.

Loading

0 comments on commit 1b20e77

Please sign in to comment.