module Hbro.Util where
import Hbro.Types
import qualified Data.Map as Map
import qualified Data.Set as Set
import Graphics.UI.Gtk
import System.Process
instance Ord Modifier where
m <= m' = fromEnum m <= fromEnum m'
keyToString :: KeyVal -> Maybe String
keyToString keyVal = case keyToChar keyVal of
Just ' ' -> Just "<Space>"
Just char -> Just [char]
_ -> case keyName keyVal of
"Caps_Lock" -> Nothing
"Shift_L" -> Nothing
"Shift_R" -> Nothing
"Control_L" -> Nothing
"Control_R" -> Nothing
"Alt_L" -> Nothing
"Alt_R" -> Nothing
"Super_L" -> Nothing
"Super_R" -> Nothing
"Menu" -> Nothing
"ISO_Level3_Shift" -> Nothing
"dead_circumflex" -> Just "^"
"dead_diaeresis" -> Just "ยจ"
x -> Just ('<':x ++ ">")
importKeyBindings :: [(([Modifier], String), (Browser -> IO ()))] -> Map.Map (Set.Set Modifier, String) (Browser -> IO ())
importKeyBindings list = Map.fromList $ importKeyBindings' list
importKeyBindings' :: [(([Modifier], String), (Browser -> IO ()))] -> [((Set.Set Modifier, String), (Browser -> IO ()))]
importKeyBindings' (((a, b), c):t) = ((Set.fromList a, b), c):(importKeyBindings' t)
importKeyBindings' _ = []
runCommand' :: String -> IO ()
runCommand' command = runCommand command >> return ()
runExternalCommand :: String -> IO ()
runExternalCommand command = runCommand' $ "nohup " ++ command ++ " > /dev/null 2>&1"