SimulaVR / Simula

Linux VR Desktop
MIT License
2.91k stars 87 forks source link

Let users customize default keyboard shortcuts (in dhall) #61

Closed lboklin closed 4 years ago

lboklin commented 5 years ago

How should we handle user configuration such as key bindings, default window layouts, themes, etc?

Possible formats:

georgewsinger commented 5 years ago

Good for flagging this (per the request of @MayBeTall_twitter).

This is a reversible decision long-term so we can go with any of these without too much fret. I have an (extremely weak) preference for YAML. I think i3 uses it's own custom configuration format.

KaneTW commented 5 years ago

I'm in favor of Dhall because new things, or YAML if we want a more common format. Strong no against JSON (it's not a user-readable format)

georgewsinger commented 5 years ago

+1 for Dhall also.

lboklin commented 5 years ago

Yeah I echo @KaneTW's preferences. Dhall can also compile into other formats such as YAML.

Dhall's first-class Haskell integration would make it the smoothest experience I think.

lboklin commented 5 years ago

I suppose we have settled on Dhall via consensus. If the format proves unsuitable for our purposes or there are any other future objections, the issue may be reopened up until a point where the format has been used enough in practice that reversing the decision is infeasible. [Slams club]

georgewsinger commented 4 years ago

Just started working on Simula's dhall config (a mere 1.5 years later).

image

:smiley:

georgewsinger commented 4 years ago

Dhall primer. These are some good primers on dhall:

Simula config. Our config might look like

-- ./config.dhall

{ -- The following are parsed as special Simula commands (defined internally)
  keyEscape     = Some "toggleInputGrab"
, keyApostrophe = Some "moveCursor"
, keyAlt        = Some "grabWindow"
, keyF          = Some "orientWindow"
, keyEnter      = Some "leftClick"
, key9          = Some "scaleWindowSmaller"
, key0          = Some "scaleWindowLarger"
, keyMinus      = Some "zoomWindowOut"
, keyEquals     = Some "zoomWindowIn"
, keyComma      = Some "moveWindowTowardsUser"
, keyPeriod     = Some "moveWindowAwayFromUser"
, keyBackspace  = Some "killWindow"
, keyW          = Some "launchDefaultHMDWebcam"
, keySlash      = Some "launchDefaultTerminal"

-- Everything else is parsed as a normal shell commands
, keyK          = Some "firefox -new-window"
, keyG          = Some "google-chrome-stable --new-window google.com"

-- Define all other keys as `None Text`
, keyA          = None Text
, keyB          = None Text
-- ..
}

which when imported via dhall

-- SimulaServer.hs
{-# LANGUAGE DeriveGeneric     #-}
{-# LANGUAGE OverloadedStrings #-}

import Dhall

data KeyboardConfig = KeyboardConfig {
   _keyEscape         :: Maybe String
 , _keyTab            :: Maybe String
 -- ..
} deriving (Generic, Show)

instance FromDhall KeyboardConfig

_on_simula_shortcut :: GodotSimulaServer -> [GodotVariant] -> IO ()
_on_simula_shortcut gss [godotScanCodeGVar, isPressedGVar] = do
   -- ..
   defaultKeyboardConfig <- input auto "./config.dhall"
   -- ..

should be parsed as

defaultKeyboardConfig = KeyboardConfig { 
                                         _keyEscape     = Just "toggleInputGrab"
                                       , _keyApostrophe = Just "moveCursor"
                                       , _keyAlt        = Just "grabWindow"
                                       , _keyF          = Just "orientWindow"
                                       , _keyEnter      = Just "leftClick"
                                       , _key9          = Just "scaleWindowSmaller"
                                       , _key0          = Just "scaleWindowLarger"
                                       , _keyMinus      = Just "zoomWindowOut"
                                       , _keyEquals     = Just "zoomWindowIn"
                                       , _keyComma      = Just "moveWindowTowardsUser"
                                       , _keyPeriod     = Just "moveWindowAwayFromUser"
                                       , _keyBackspace  = Just "killWindow"
                                       , _keyW          = Just "launchDefaultHMDWebcam"
                                       , _keySlash      = Just "launchDefaultTerminal"

                                       -- Everything else is parsed as a normal shell commands
                                       , _keyK          = Just "firefox -new-window"
                                       , _keyG          = Just "google-chrome-stable --new-window google.com"

                                      -- ...
}

What is not clear to me yet is how to duplicate the rest of on_simula_shortcut functionality using this config (just have to think about it some).

georgewsinger commented 4 years ago

We just added keyboard shortcut customizability to our most recent commits (see README and ./config.dhall). Let me know if there's things I should add to our config. Right now we have (i) keyboard shortcuts; (ii) default launch resolution for apps; (iii) default launch scale for apps.