From f7aec870258258afe1c852da3931fa22c998999c Mon Sep 17 00:00:00 2001 From: Schrottkatze Date: Wed, 6 Dec 2023 13:14:02 +0100 Subject: [PATCH] start work on xmobar config --- flake.nix | 2 +- haskell/xmobar/xmobar.hs | 27 +++++++++++++ haskell/xmonad/xmonad.hs | 81 +++++++------------------------------ modules/desktop/polybar.nix | 1 + modules/desktop/xmonad.nix | 25 ++++++++++-- 5 files changed, 65 insertions(+), 71 deletions(-) create mode 100644 haskell/xmobar/xmobar.hs diff --git a/flake.nix b/flake.nix index c06d9f3..db7820e 100644 --- a/flake.nix +++ b/flake.nix @@ -36,7 +36,7 @@ devShells."x86_64-linux".default = pkgs.mkShell { buildInputs = [ (pkgs.haskellPackages.ghcWithPackages - (pkgs: with pkgs; [xmonad xmonad-contrib])) + (pkgs: with pkgs; [xmonad xmonad-contrib xmobar])) pkgs.haskell-language-server ]; }; diff --git a/haskell/xmobar/xmobar.hs b/haskell/xmobar/xmobar.hs new file mode 100644 index 0000000..a2fe690 --- /dev/null +++ b/haskell/xmobar/xmobar.hs @@ -0,0 +1,27 @@ + import Xmobar + + config :: Config + config = + defaultConfig + { font = "FiraCode Nerd Font", + allDesktops = True, + alpha = 255, + bgColor = "#282828", + fgColor = "#ebdbb2", + commands = + -- [ Run XMonadLog, + -- Run $ Memory ["t", "Mem: %"] 10, + -- Run $ Kbd [], + -- Run $ Date "%a %_d %b %Y %H:%M:%S" "date" 10 + -- ], + [ Run $ Memory ["t", "Mem: %"] 10, + Run $ Kbd [], + Run $ Date "%a %_d %b %Y %H:%M:%S" "date" 10 + ], + template = "%kbd% | %date% | %memory%", + alignSep = "}{", + position = TopH 24 + } + + main :: IO () + main = xmobar config -- or: configFromArgs config >>= xmobar diff --git a/haskell/xmonad/xmonad.hs b/haskell/xmonad/xmonad.hs index 5c02930..8a936e9 100644 --- a/haskell/xmonad/xmonad.hs +++ b/haskell/xmonad/xmonad.hs @@ -24,6 +24,7 @@ import XMonad.Prompt import XMonad.Prompt.Layout import XMonad.StackSet qualified as W import XMonad.Actions.NoBorders +import XMonad.Util.EZConfig myKeys conf@(XConfig {XMonad.modMask = modm}) = M.fromList $ @@ -94,17 +95,6 @@ myMouseBindings (XConfig {XMonad.modMask = modm}) = ) ] ------------------------------------------------------------------------- --- Layouts: - --- You can specify and transform your layouts by modifying these values. --- If you change layout bindings be sure to use 'mod-shift-space' after --- restarting (with 'mod-q') to reset your layout state to the new --- defaults, as xmonad preserves your old layout settings by default. --- --- The available layouts. Note that each layout is separated by |||, --- which denotes layout choice. - tabCfg = def { activeColor = "#282828", @@ -118,10 +108,12 @@ tabCfg = urgentTextColor = "#ebdbb2" } -myLayout = avoidStruts $ autoChoose ||| threeCol ||| tiled ||| tabbed shrinkText tabCfg ||| Mirror tiled +myLayout = setupSpacing $ avoidStruts $ autoChoose ||| tabbed shrinkText tabCfg where -- default tiling algorithm partitions the screen into two panes - autoChoose = IfMax 2 tiled $ IfMax 3 tiled_mag $ IfMax 4 Grid threeCol + autoChoose = IfMax 2 tiled $ IfMax 3 tiled_mag $ IfMax 4 grid_mag threeCol + setupSpacing = spacingRaw True (Border 0 0 0 0) True (Border 7 7 7 7) True + grid_mag = magnifiercz 1.4 Grid tiled = Tall nmaster delta ratio tiled_mag = magnifiercz' 1.4 tiled threeCol = magnifiercz' 1.6 $ ThreeColMid nmaster delta ratio @@ -144,61 +136,23 @@ myManageHook = resource =? "kdesktop" --> doIgnore ] ------------------------------------------------------------------------- --- Event handling - --- * EwmhDesktops users should change this to ewmhDesktopsEventHook - --- --- Defines a custom handler function for X Events. The function should --- return (All True) if the default handler is to be run afterwards. To --- combine event hooks use mappend or mconcat from Data.Monoid. --- -myEventHook = mempty - -focusChangeHook (FocusChangeEvent {ev_event_type = t, ev_window = window}) = do - when (t == focusIn) $ spawn "notify-send 'focusIn'" - when (t == focusOut) $ spawn "notify-send 'focusOut'" - return $ All True - ------------------------------------------------------------------------- --- Status bars and logging - --- Perform an arbitrary action on each internal state change or X event. --- See the 'XMonad.Hooks.DynamicLog' extension for examples. --- -myLogHook = return () - ------------------------------------------------------------------------- --- Startup hook - --- Perform an arbitrary action each time xmonad starts or is restarted --- with mod-q. Used by, e.g., XMonad.Layout.PerWorkspace to initialize --- per-workspace layout choices. --- --- By default, do nothing. myStartupHook = do spawn "pgrep oneko || oneko -tofocus -tora -position +-1+5 -fg palevioletred3 -bg pink -name 'Rose the desktop kitty'" spawn "pgrep volumeicon || volumeicon" spawn "pgrep nm-applet || nm-applet" spawn "pgrep mullvad-gui || mullvad-vpn" spawn "feh --bg-fill ~/Pictures/wallpaper.jpg" + killStatusBar "xmobar" + spawnStatusBar "xmobar" ------------------------------------------------------------------------- --- Now run xmonad with all the defaults we set up. +xmeowbar = statusBarProp "xmobar" $ pure xmobarPP +polybar = statusBarProp "polybar" $ pure xmobarPP +barSpawner 0 = pure $ xmeowbar <> polybar +barSpawner _ = mempty --- Run xmonad with the settings you specify. No need to modify this. --- -mySB = statusBarProp "polybar" (pure xmobarPP) +main :: IO() +main = xmonad $ docks $ dynamicSBs barSpawner $ ewmh defaults -main = xmonad $ docks $ withSB mySB (ewmh defaults) - --- A structure containing your configuration settings, overriding --- fields in the default config. Any you don't override, will --- use the defaults defined in xmonad/XMonad/Config.hs --- --- No need to modify this. --- defaults = def { -- simple stuff @@ -210,14 +164,9 @@ defaults = workspaces = ["comms", "browser"] ++ map show [3 .. 9], normalBorderColor = "#3c3836", focusedBorderColor = "#504945", - -- , clientMask = focusChangeMask .|. XMonad.clientMask - -- key bindings keys = myKeys, mouseBindings = myMouseBindings, - -- hooks, layouts - layoutHook = spacingRaw True (Border 0 0 0 0) True (Border 7 7 7 7) True myLayout, + layoutHook =myLayout, manageHook = myManageHook, - handleEventHook = myEventHook, - logHook = myLogHook, startupHook = myStartupHook - } + } diff --git a/modules/desktop/polybar.nix b/modules/desktop/polybar.nix index 9e6fd03..7db300d 100644 --- a/modules/desktop/polybar.nix +++ b/modules/desktop/polybar.nix @@ -29,6 +29,7 @@ }; "bar/status" = { # Style + bottom = true; width = "100%"; height = "24px"; radius = 0; diff --git a/modules/desktop/xmonad.nix b/modules/desktop/xmonad.nix index 38b58e9..793723b 100644 --- a/modules/desktop/xmonad.nix +++ b/modules/desktop/xmonad.nix @@ -1,11 +1,28 @@ { - config, lib, pkgs, ... -}: -with lib; { - home-manager.users.jade = {pkgs, ...}: { +}: { + home-manager.users.jade = { + config, + pkgs, + ... + }: let + xmobarGhc = pkgs.haskellPackages.ghcWithPackages (pkgs: with pkgs; [xmobar]); + in { + home.packages = [xmobarGhc pkgs.xmonadctl]; + programs.xmobar = { + enable = true; + }; + home.file."xmobar.hs" = { + source = ../../haskell/xmobar/xmobar.hs; + target = ".config/xmobar/xmobar.hs"; + onChange = '' + export PATH=${lib.makeBinPath [xmobarGhc]}:$PATH + ${pkgs.xmobar}/bin/xmobar --recompile + ${pkgs.haskellPackages.xmonad}/bin/xmonad --restart + ''; + }; xsession.windowManager.xmonad = { enable = true; enableContribAndExtras = true;