summaryrefslogtreecommitdiffstats
path: root/tv/5pkgs
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2020-10-03 03:23:18 +0200
committertv <tv@krebsco.de>2020-10-03 03:26:37 +0200
commit14d51411fac831d06530a2192b35e3fbd87de30e (patch)
tree7b4107406d305e4cf8b534bce5ac9fab05838022 /tv/5pkgs
parent74a6276be87fd307bddb7094caea6c2635f61b9d (diff)
tv xmonad: read screen/font width from build env
Diffstat (limited to 'tv/5pkgs')
-rw-r--r--tv/5pkgs/haskell/xmonad-tv/default.nix9
-rw-r--r--tv/5pkgs/haskell/xmonad-tv/src/THEnv/JSON.hs18
-rw-r--r--tv/5pkgs/haskell/xmonad-tv/src/main.hs21
-rw-r--r--tv/5pkgs/haskell/xmonad-tv/src/xmonad-tv.cabal7
4 files changed, 47 insertions, 8 deletions
diff --git a/tv/5pkgs/haskell/xmonad-tv/default.nix b/tv/5pkgs/haskell/xmonad-tv/default.nix
index 42eb13d..36dffaa 100644
--- a/tv/5pkgs/haskell/xmonad-tv/default.nix
+++ b/tv/5pkgs/haskell/xmonad-tv/default.nix
@@ -1,5 +1,6 @@
-{ mkDerivation, base, containers, directory, extra, stdenv, unix
-, X11, xmonad, xmonad-contrib, xmonad-stockholm
+{ mkDerivation, aeson, base, bytestring, containers, directory
+, extra, stdenv, template-haskell, th-env, unix, X11, xmonad
+, xmonad-contrib, xmonad-stockholm
}:
mkDerivation {
pname = "xmonad-tv";
@@ -8,8 +9,8 @@ mkDerivation {
isLibrary = false;
isExecutable = true;
executableHaskellDepends = [
- base containers directory extra unix X11 xmonad xmonad-contrib
- xmonad-stockholm
+ aeson base bytestring containers directory extra template-haskell
+ th-env unix X11 xmonad xmonad-contrib xmonad-stockholm
];
license = stdenv.lib.licenses.mit;
}
diff --git a/tv/5pkgs/haskell/xmonad-tv/src/THEnv/JSON.hs b/tv/5pkgs/haskell/xmonad-tv/src/THEnv/JSON.hs
new file mode 100644
index 0000000..2a3a0e5
--- /dev/null
+++ b/tv/5pkgs/haskell/xmonad-tv/src/THEnv/JSON.hs
@@ -0,0 +1,18 @@
+{-# LANGUAGE ScopedTypeVariables #-}
+
+module THEnv.JSON where
+
+import Data.Aeson (eitherDecode,FromJSON)
+import Data.ByteString.Lazy.Char8 (pack)
+import Language.Haskell.TH.Syntax (Exp,Lift(lift),Q)
+import THEnv (getCompileEnv)
+import Control.Monad
+
+getCompileEnvJSON :: (FromJSON a) => String -> Q a
+getCompileEnvJSON name =
+ either error (id :: a -> a) . eitherDecode . pack <$> getCompileEnv name
+
+getCompileEnvJSONExp ::
+ forall proxy a. (FromJSON a, Lift a) => proxy a -> String -> Q Exp
+getCompileEnvJSONExp _ =
+ (lift :: a -> Q Exp) <=< getCompileEnvJSON
diff --git a/tv/5pkgs/haskell/xmonad-tv/src/main.hs b/tv/5pkgs/haskell/xmonad-tv/src/main.hs
index c83b411..b8ddd27 100644
--- a/tv/5pkgs/haskell/xmonad-tv/src/main.hs
+++ b/tv/5pkgs/haskell/xmonad-tv/src/main.hs
@@ -1,4 +1,6 @@
{-# LANGUAGE LambdaCase #-}
+{-# LANGUAGE TemplateHaskell #-}
+{-# LANGUAGE TypeApplications #-}
module Main (main) where
@@ -32,10 +34,23 @@ import XMonad.Stockholm.Pager
import XMonad.Stockholm.Shutdown
import qualified Paths
+import THEnv.JSON (getCompileEnvJSONExp)
+
myFont :: String
myFont = "-schumacher-*-*-*-*-*-*-*-*-*-*-*-iso10646-*"
+myScreenWidth :: Dimension
+myScreenWidth =
+ $(getCompileEnvJSONExp (id @Dimension) "XMONAD_BUILD_SCREEN_WIDTH")
+
+myTermFontWidth :: Dimension
+myTermFontWidth =
+ $(getCompileEnvJSONExp (id @Dimension) "XMONAD_BUILD_TERM_FONT_WIDTH")
+
+myTermPadding :: Dimension
+myTermPadding = 2
+
main :: IO ()
main = getArgs >>= \case
@@ -46,7 +61,6 @@ main = getArgs >>= \case
mainNoArgs :: IO ()
mainNoArgs = do
- let width = 1366
workspaces0 <- getWorkspaces0
handleShutdownEvent <- newShutdownEventHandler
launch
@@ -60,8 +74,9 @@ mainNoArgs = do
smartBorders $
ResizableTall
1
- (10 * 6 / width)
- ((80 * 6 + 2 * (1+1+1))/width) []
+ (fromIntegral (10 * myTermFontWidth) / fromIntegral myScreenWidth)
+ (fromIntegral (80 * myTermFontWidth + 2 * (myTermPadding + borderWidth def)) / fromIntegral myScreenWidth)
+ []
|||
Full
, manageHook =
diff --git a/tv/5pkgs/haskell/xmonad-tv/src/xmonad-tv.cabal b/tv/5pkgs/haskell/xmonad-tv/src/xmonad-tv.cabal
index f10bc4a..d07e2b1 100644
--- a/tv/5pkgs/haskell/xmonad-tv/src/xmonad-tv.cabal
+++ b/tv/5pkgs/haskell/xmonad-tv/src/xmonad-tv.cabal
@@ -9,10 +9,14 @@ cabal-version: >=1.10
executable xmonad
main-is: main.hs
build-depends:
+ aeson,
base,
+ bytestring,
containers,
directory,
extra,
+ template-haskell,
+ th-env,
unix,
X11,
xmonad,
@@ -20,6 +24,7 @@ executable xmonad
xmonad-stockholm
other-modules:
Helpers.Path,
- Paths
+ Paths,
+ THEnv.JSON
default-language: Haskell2010
ghc-options: -O2 -Wall -threaded