aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJosh Rahm <rahm@google.com>2020-02-03 18:56:05 -0700
committerJosh Rahm <rahm@google.com>2020-02-03 18:56:05 -0700
commit04489c6c77e9c80e5b3332b81cea149dad1c7d88 (patch)
tree55b661576f0bba5daabce53f1620861f2f8eae90 /src
parente3b47c680b20aab1e703ce0525364244422c27e8 (diff)
downloadrde-04489c6c77e9c80e5b3332b81cea149dad1c7d88.tar.gz
rde-04489c6c77e9c80e5b3332b81cea149dad1c7d88.tar.bz2
rde-04489c6c77e9c80e5b3332b81cea149dad1c7d88.zip
Add ability to show layout format!
Diffstat (limited to 'src')
-rw-r--r--src/Internal/Hash.hs11
-rw-r--r--src/Internal/Layout.hs33
-rw-r--r--src/Internal/LayoutDraw.hs109
-rw-r--r--src/Main.hs9
4 files changed, 144 insertions, 18 deletions
diff --git a/src/Internal/Hash.hs b/src/Internal/Hash.hs
new file mode 100644
index 0000000..63f6043
--- /dev/null
+++ b/src/Internal/Hash.hs
@@ -0,0 +1,11 @@
+{-# LANGUAGE OverloadedStrings #-}
+module Internal.Hash where
+
+import Numeric (showHex)
+import qualified Data.ByteString as BS
+import qualified Data.ByteString.Char8 as BC
+import qualified Crypto.Hash.SHA1 as SHA1
+
+quickHash :: String -> String
+quickHash str =
+ concatMap (flip showHex "") $ BS.unpack (SHA1.hash $ BC.pack str)
diff --git a/src/Internal/Layout.hs b/src/Internal/Layout.hs
index 2b35dbc..4cfe3d3 100644
--- a/src/Internal/Layout.hs
+++ b/src/Internal/Layout.hs
@@ -10,11 +10,11 @@ import XMonad
import qualified XMonad.StackSet as W
myLayout =
- spiral (6/7) |||
- Center 0.7 |||
- Tall 1 (3/100) (1/2) |||
- ThreeCol 1 (3/100) (1/2) |||
- Grid
+ spiral (6/7) |||
+ Center 0.7 |||
+ Tall 1 (3/100) (1/2) |||
+ ThreeCol 1 (3/100) (1/2) |||
+ Grid
data Center a =
@@ -23,9 +23,8 @@ data Center a =
}
deriving (Show, Read)
-instance LayoutClass Center a where
- doLayout l (Rectangle x y w h) stack =
-
+instance (Show a) => LayoutClass Center a where
+ doLayout l r@(Rectangle x y w h) stack = do
let wf = fromIntegral w
hf = fromIntegral h
x' = (wf - wf * proportion l) / 2
@@ -43,14 +42,16 @@ instance LayoutClass Center a where
portion = fromIntegral $ nWin `div` 6
winRem = fromIntegral $ nWin `mod` 6
- in
- return $
- (zip (W.integrate stack) (
- (:) middleRect $
- (divRect topRect (portion * 2))
- ++ (divRect rightRect portion)
- ++ (divRect bottomRect (portion * 2))
- ++ (divRect leftRect (portion + winRem))), Just l)
+ in do
+ let ret =
+ (zip (W.integrate stack) (
+ (:) middleRect $
+ (divRect topRect (portion * 2))
+ ++ (divRect rightRect portion)
+ ++ (divRect bottomRect (portion * 2))
+ ++ (divRect leftRect (portion + winRem))), Just l)
+ liftIO $ writeFile "/tmp/wtf.txt" (description l ++ ": " ++ show (fst ret))
+ return ret
where
divRect (Rectangle x y w h) n =
if h > w
diff --git a/src/Internal/LayoutDraw.hs b/src/Internal/LayoutDraw.hs
new file mode 100644
index 0000000..3b3d3f0
--- /dev/null
+++ b/src/Internal/LayoutDraw.hs
@@ -0,0 +1,109 @@
+{-# LANGUAGE FlexibleInstances, FlexibleContexts, MultiParamTypeClasses,
+ScopedTypeVariables #-}
+module Internal.LayoutDraw where
+
+import System.Process
+import Text.Printf
+import Control.Arrow
+import Control.Exception
+import Control.Monad
+import Graphics.Rendering.Cairo
+import Graphics.Rendering.Cairo.Internal (Render(runRender))
+import Graphics.Rendering.Cairo.Types (Cairo(Cairo))
+
+import System.FilePath
+import XMonad
+import XMonad.StackSet as S
+import Data.Maybe
+import System.Directory
+
+import Internal.Layout
+import Internal.Hash
+
+showLayout :: X (Maybe String)
+showLayout = do
+ winset <- gets windowset
+ let layout = S.layout . S.workspace . S.current $ winset
+ xpm <- drawPng layout
+ return $ Just $ printf "<icon=%s/>" xpm
+
+drawPng :: (LayoutClass layout Window) => layout Window -> X String
+drawPng l = do
+ dir <- getXMonadDir
+ let sixWindows = [1..(4 :: Window)]
+ let stack = differentiate sixWindows
+ (rects, _) <-
+ runLayout (Workspace "0" l stack) (Rectangle 0 0 (64 * 30) (32 * 30))
+ return ()
+
+ let descr = description l
+ let pngCacheDir = dir </> "icons" </> "cache"
+
+ liftIO $ createDirectoryIfMissing True pngCacheDir
+ let testf = dir </> "text.txt"
+ let filepathPng = pngCacheDir </> (quickHash descr ++ ".png")
+ let filepathXpm = pngCacheDir </> (quickHash descr ++ ".xpm")
+
+ let colors = [
+ (1.0, 1.0, 1.0),
+ (0.9, 0.9, 1.0),
+ (0.8, 0.8, 1.0),
+ (0.7, 0.7, 1.0),
+ (0.6, 0.6, 1.0),
+ (0.5, 0.5, 1.0),
+ (0.4, 0.4, 1.0),
+ (0.3, 0.3, 1.0),
+ (0.2, 0.2, 1.0),
+ (0.1, 0.1, 1.0),
+ (0.0, 0.0, 1.0)
+ ]
+
+ exists <- liftIO $ doesFileExist filepathXpm
+ when (not exists) $
+ liftIO $ do
+ withImageSurface FormatARGB32 64 32 $ \surface -> do
+ renderWith surface $ do
+ setLineCap LineCapButt
+ setLineJoin LineJoinMiter
+
+ forM_ (zip (map (second padR) rects) colors) $
+ \((wind, Rectangle x y w h), (r, g, b)) -> do
+ setSourceRGBA r g b 1
+
+ rectangle
+ (fromIntegral $ floor (fromIntegral x / 30.0))
+ (fromIntegral $ floor (fromIntegral y / 30.0))
+ (fromIntegral $ floor (fromIntegral w / 30.0))
+ (fromIntegral $ floor (fromIntegral h / 30.0))
+
+ fill
+
+ surfaceWriteToPNG surface filepathPng
+
+ _ <- readProcessWithExitCode
+ "/usr/bin/convert"
+ [filepathPng, filepathXpm]
+ ""
+ return ()
+
+ return filepathXpm
+ where
+ padR (Rectangle x y w h) =
+ Rectangle x y (max 1 $ w - 120) (max 1 $ h - 120)
+
+newtype InterceptLayout l a =
+ InterceptLayout {
+ unIntercept :: (l a)
+ } deriving (Show, Read)
+
+instance (LayoutClass l Window) => LayoutClass (InterceptLayout l) Window where
+ runLayout (Workspace t l s) rect = do
+ (rects, mr) <- runLayout (Workspace t (unIntercept l) s) rect
+ return (rects, fmap InterceptLayout mr)
+
+ handleMessage this mesg = do
+ ret <- handleMessage (unIntercept this) mesg
+ -- mapM_ drawThing ret
+ return (InterceptLayout <$> ret)
+
+ description = ("Intercepted "++) . description . unIntercept
diff --git a/src/Main.hs b/src/Main.hs
index 98fb384..77a53a0 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -18,6 +18,7 @@ main = do
-- Execute some commands.
homeDir <- getHomeDirectory
let fp = homeDir </> ".xmonad" </> "startup"
+ let theLayout = myLayout
config <-
applyKeys $ def
@@ -27,8 +28,10 @@ main = do
, keys = \config -> mempty
, focusedBorderColor = "#FFFFFF"
, normalBorderColor = "#000000"
- , layoutHook = spacingRaw True (Border 5 5 5 5) True (Border 5 5 5 5) True $
- myLayout
+ , layoutHook =
+ spacingRaw True (Border 5 5 5 5) True (Border 5 5 5 5) True $
+ InterceptLayout $
+ myLayout
, startupHook = do
spawn fp
, manageHook = composeAll [
@@ -39,6 +42,7 @@ main = do
, className =? "gnubby_ssh_prompt" --> doFloat
]
}
+
let toggleStructsKey XConfig {XMonad.modMask = modMask} = (modMask, xK_b)
xmonad =<<
@@ -54,6 +58,7 @@ main = do
(printf "<fn=1>%s</fn>" :: String -> String)
, ppSep = xmobarColor "#404040" "" " ──── "
+ , ppExtras = [showLayout]
}
toggleStructsKey
config { modMask = mod4Mask }