diff options
author | Baitinq <manuelpalenzuelamerino@gmail.com> | 2022-07-04 11:48:31 +0200 |
---|---|---|
committer | Baitinq <manuelpalenzuelamerino@gmail.com> | 2022-07-05 14:12:47 +0200 |
commit | 834f19223d817258108ad780a1bde2058ab3ee17 (patch) | |
tree | d7e954b3424b247200b07f9058a0e0364600a51f | |
parent | fmt (diff) | |
download | nixos-config-834f19223d817258108ad780a1bde2058ab3ee17.tar.gz nixos-config-834f19223d817258108ad780a1bde2058ab3ee17.tar.bz2 nixos-config-834f19223d817258108ad780a1bde2058ab3ee17.zip |
Switch windowmanager to xmonad
-rw-r--r-- | dotfiles/.xinitrc | 5 | ||||
-rw-r--r-- | dotfiles/sxhkd/xmonad | 46 | ||||
-rw-r--r-- | dotfiles/xmobar.hs | 27 | ||||
-rw-r--r-- | dotfiles/xmonad.hs | 223 | ||||
-rw-r--r-- | hosts/default.nix | 2 | ||||
-rw-r--r-- | hosts/home.nix | 20 | ||||
-rw-r--r-- | hosts/phobos/home.nix | 7 | ||||
-rw-r--r-- | modules/xorg/default.nix | 1 | ||||
-rw-r--r-- | packages/default.nix | 1 | ||||
-rw-r--r-- | packages/xmonadctl/default.nix | 6 | ||||
-rw-r--r-- | packages/xmonadctl/xmonadctl.hs | 51 |
11 files changed, 379 insertions, 10 deletions
diff --git a/dotfiles/.xinitrc b/dotfiles/.xinitrc index a4a32a9..1920a74 100644 --- a/dotfiles/.xinitrc +++ b/dotfiles/.xinitrc @@ -51,6 +51,8 @@ fi xrandr --auto #xrandr -s 1920x1080 & +xsetroot -cursor_name left_ptr + sxhkd & clipmenud & unclutter & @@ -65,5 +67,6 @@ dwmbar & while :; do ssh-agent smart-wallpaper -d ~/Images/Wallpapers/Day -n ~/Images/Wallpapers/Night -l $LOCATION -r; done & -exec dwm 2> /tmp/dwm.log +exec xmonad 2> /tmp/xmonad.log +#exec dwm 2> /tmp/dwm.log diff --git a/dotfiles/sxhkd/xmonad b/dotfiles/sxhkd/xmonad new file mode 100644 index 0000000..bcefaff --- /dev/null +++ b/dotfiles/sxhkd/xmonad @@ -0,0 +1,46 @@ +################################## +# +##### DWM ##### +################################## + +alt + shift + q + xmonadctl quit + +alt + q + xmonadctl kill-window + +alt + {1-9} + xmonadctl focus-workspace-{1-9} + +alt + shift + {1-9} + xmonadctl send-to-workspace-{1-9} + +#alt + Tab +# dwmc view + +#alt + 0 +# dwmc viewall + +#alt + shift + 0 +# dwmc tagall + +#move clockwise & anticlockwise +alt + {h,j,k} + xmonadctl focus-{master,next,prev} + +#move windows clockwise and anticlockwsie +alt + shift + {h,j,k} + xmonadctl swap-with-{master,next,prev} + +alt + f + xmonadctl togglefullscreen +alt + F11 + xmonadctl togglefullscreen + +alt + ctrl + period + xmonadctl next-layout +alt + space + xmonadctl next-layout + +################################## +################################## \ No newline at end of file diff --git a/dotfiles/xmobar.hs b/dotfiles/xmobar.hs new file mode 100644 index 0000000..1636209 --- /dev/null +++ b/dotfiles/xmobar.hs @@ -0,0 +1,27 @@ + +Config { + + -- appearance + font = "xft:Noto Sans Display Nerd Font:size=10" + , bgColor = "#222222" + , fgColor = "#bbbbbb" + , position = Top + , border = NoBorder + , borderColor = "#222222" + + -- layout + , sepChar = "%" -- delineator between plugin names and straight text + , alignSep = "}{" -- separator between left-right alignment + , template = "%XMonadLog% }{ %WM_NAME%" + + -- general behavior + , lowerOnStart = True -- send to bottom of window stack on start + , hideOnStart = False -- start with window unmapped (hidden) + , allDesktops = True -- show on all desktops + , overrideRedirect = True -- set the Override Redirect flag (Xlib) + , pickBroadest = False -- choose widest display (multi-monitor) + , persistent = True -- enable/disable hiding (True = disabled) + + , commands = [ Run XMonadLog, + Run XPropertyLog "WM_NAME" ] + } diff --git a/dotfiles/xmonad.hs b/dotfiles/xmonad.hs new file mode 100644 index 0000000..0c0e320 --- /dev/null +++ b/dotfiles/xmonad.hs @@ -0,0 +1,223 @@ +-- xmonad config used by Malcolm MD +-- https://github.com/randomthought/xmonad-config + +import System.IO +import System.Exit + +import qualified Data.List as L + +import XMonad +import XMonad.Actions.Navigation2D +import XMonad.Actions.UpdatePointer + +import XMonad.Hooks.DynamicLog +import XMonad.Hooks.ManageDocks +import XMonad.Hooks.ManageHelpers +import XMonad.Hooks.SetWMName + +import XMonad.Layout.Gaps +import XMonad.Layout.Fullscreen +import XMonad.Layout.BinarySpacePartition as BSP +import XMonad.Layout.NoBorders +import XMonad.Layout.Tabbed +import XMonad.Layout.ThreeColumns +import XMonad.Layout.Spacing +import XMonad.Layout.MultiToggle +import XMonad.Layout.MultiToggle.Instances +import XMonad.Layout.NoFrillsDecoration +import XMonad.Layout.Renamed +import XMonad.Layout.Simplest +import XMonad.Layout.SubLayouts +import XMonad.Layout.WindowNavigation +import XMonad.Layout.ZoomRow + +import XMonad.Util.Run(spawnPipe) +import XMonad.Util.EZConfig(additionalKeys) +import XMonad.Util.Cursor + +import Graphics.X11.ExtraTypes.XF86 +import qualified XMonad.StackSet as W +import qualified Data.Map as M + +import XMonad.Hooks.ServerMode +import XMonad.Actions.WorkspaceNames + +import XMonad.Hooks.StatusBar +import XMonad.Hooks.StatusBar.PP + +------------------------------------------------------------------------ +-- Workspaces +-- The default number of workspaces (virtual screens) and their names. +-- +myWorkspaces :: [String] +myWorkspaces = map show [1..9] + + +------------------------------------------------------------------------ +-- Window rules +-- Execute arbitrary actions and WindowSet manipulations when managing +-- a new window. You can use this to, for example, always float a +-- particular program, or have a client always appear on a particular +-- workspace. +-- +-- To find the property name associated with a program, use +-- > xprop | grep WM_CLASS +-- and click on the client you're interested in. +-- +-- To match on the WM_NAME, you can use 'title' in the same way that +-- 'className' and 'resource' are used below. +-- +myManageHook = composeAll + [ + isFullscreen --> (doF W.focusDown <+> doFullFloat) + ] + + + +------------------------------------------------------------------------ +-- 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. + +gap = 7 + +myGaps = gaps [(U, gap), (R, gap), (L, gap), (D, gap)] +addSpace = renamed [CutWordsLeft 2] . spacing gap + +tiledLayout = renamed [Replace "[]"] $ tiled + where + -- default tiling algorithm partitions the screen into two panes + tiled = Tall nmaster delta ratio + + -- The default number of windows in the master pane + nmaster = 1 + + -- Default proportion of screen occupied by master pane + ratio = 1/2 + + -- Percent of screen to increment by when resizing panes + delta = 3/100 + +layouts = tiledLayout + +myLayout = smartBorders + $ mkToggle (NOBORDERS ?? FULL ?? EOT) + $ avoidStruts $ myGaps $ addSpace + $ layouts + +------------------------------------------------------------------------ +-- Colors and borders + +-- Width of the window border in pixels. +myBorderWidth = 1 + +myNormalBorderColor = "#000000" +myFocusedBorderColor = "#005577" + + ------------------------------------------------------------------------ +-- External commands +myCommands :: [(String, X ())] +myCommands = + [ ("decrease-master-size" , sendMessage Shrink ) + , ("increase-master-size" , sendMessage Expand ) + , ("decrease-master-count" , sendMessage $ IncMasterN (-1) ) + , ("increase-master-count" , sendMessage $ IncMasterN ( 1) ) + , ("focus-prev" , windows W.focusUp ) + , ("focus-next" , windows W.focusDown ) + , ("focus-master" , windows W.focusMaster ) + , ("swap-with-prev" , windows W.swapUp ) + , ("swap-with-next" , windows W.swapDown ) + , ("swap-with-master" , windows W.swapMaster ) + , ("togglefullscreen" , sendMessage $ Toggle FULL ) + , ("next-layout" , sendMessage NextLayout ) + , ("kill-window" , kill ) + , ("quit" , io $ exitWith ExitSuccess ) + , ("restart" , spawn "xmonad --recompile; xmonad --restart" ) + ] + +----------------------------------------------------------------------- +-- Custom server mode + +myServerModeEventHook = serverModeEventHookCmd' $ return myCommands' +myCommands' = ("list-commands", listMyServerCmds) : myCommands ++ wscs ++ sccs -- ++ spcs + where + wscs = [((m ++ s), windows $f s) | s <- myWorkspaces + , (f, m) <- [(W.view, "focus-workspace-"), (W.shift, "send-to-workspace-")] ] + + sccs = [((m ++ show sc), screenWorkspace (fromIntegral sc) >>= flip whenJust (windows . f)) + | sc <- [0..10], (f, m) <- [(W.view, "focus-screen-"), (W.shift, "send-to-screen-")]] + +listMyServerCmds :: X () +listMyServerCmds = spawn ("echo '" ++ asmc ++ "' | xmessage -file -") + where asmc = concat $ "Available commands:" : map (\(x, _)-> " " ++ x) myCommands' + +------------------------------------------------------------------------ +-- Mouse bindings +-- +-- Focus rules +-- True if your focus should follow your mouse cursor. +myFocusFollowsMouse :: Bool +myFocusFollowsMouse = False + +myMouseBindings (XConfig {XMonad.modMask = modMask}) = M.fromList $ + [ + -- mod-button1, Set the window to floating mode and move by dragging + ((modMask, button1), + (\w -> focus w >> mouseMoveWindow w)) + + -- mod-button2, Raise the window to the top of the stack + , ((modMask, button2), + (\w -> focus w >> windows W.swapMaster)) + + -- mod-button3, Set the window to floating mode and resize by dragging + , ((modMask, button3), + (\w -> focus w >> mouseResizeWindow w)) + + -- you may also bind events to the mouse scroll wheel (button4 and button5) + ] + +------------------------------------------------------------------------ +-- Run xmonad with all the defaults we set up. +-- + +getNumberOfWindowsInWorkpace :: X Int +getNumberOfWindowsInWorkpace = withWindowSet (pure . length . W.index) + +myStatusBar = statusBarProp "xmobar" (do + numWindows <- getNumberOfWindowsInWorkpace + return $ xmobarPP { + ppCurrent = (\s -> + if numWindows > 0 + then ((xmobarBorder "Top" "#bbbbbb" 4 . xmobarColor "#bbbbbb" "#005577") (" " ++ s ++ " ")) + else (xmobarColor "#bbbbbb" "#005577" (" " ++ s ++ " ")) + ) + , ppTitle = shorten 77 + , ppSep = " | " + , ppLayout = (\_ -> "") + , ppHidden = (\s -> xmobarBorder "Top" "#bbbbbb" 2 (" " ++ s ++ " ")) --probs better way to do this + , ppHiddenNoWindows = wrap " " " " + } + ) + +main :: IO () +main = do + spawn "xmobar" + xmonad . withSB myStatusBar . docks + $ def { + focusFollowsMouse = myFocusFollowsMouse, + borderWidth = myBorderWidth, + workspaces = myWorkspaces, + normalBorderColor = myNormalBorderColor, + focusedBorderColor = myFocusedBorderColor, + + mouseBindings = myMouseBindings, + + layoutHook = myLayout, + handleEventHook = fullscreenEventHook <+> myServerModeEventHook, + manageHook = manageDocks <+> myManageHook + } \ No newline at end of file diff --git a/hosts/default.nix b/hosts/default.nix index 16e8d03..e1ab080 100644 --- a/hosts/default.nix +++ b/hosts/default.nix @@ -1,7 +1,7 @@ { user, lib, nixpkgs, nur, inputs, home-manager, ... }: let secrets = import ../secrets; - + hosts = [ { hostname = "phobos"; system = "x86_64-linux"; location = secrets.main_location; } { hostname = "luna"; system = "x86_64-linux"; location = secrets.main_location; } diff --git a/hosts/home.nix b/hosts/home.nix index c1df4c6..568f426 100644 --- a/hosts/home.nix +++ b/hosts/home.nix @@ -1,4 +1,4 @@ -{ config, lib, pkgs, inputs, user, hostname, secrets, ... }: +{ config, lib, pkgs, inputs, user, hostname, secrets, location, ... }: let dotfiles = ../dotfiles; in @@ -17,7 +17,7 @@ in discord mpv sxiv - dwm + #dwm st dmenu unclutter @@ -41,6 +41,22 @@ in ]); }; + xsession.windowManager.xmonad = { + enable = true; + enableContribAndExtras = true; + #extraPackages = pkgs: [pkgs.xmonadctl]; + config = dotfiles + "/xmonad.hs"; + }; + + programs.xmobar = { + enable = true; + extraConfig = builtins.readFile (dotfiles + "/xmobar.hs"); + }; + + home.sessionVariables = { + LOCATION = "${location}"; + }; + services = { gpg-agent = { enable = true; diff --git a/hosts/phobos/home.nix b/hosts/phobos/home.nix index 8891df0..f235f93 100644 --- a/hosts/phobos/home.nix +++ b/hosts/phobos/home.nix @@ -16,12 +16,9 @@ in kindlegen manga-cli mov-cli + xmonadctl ]); - home.sessionVariables = { - LOCATION = "${location}"; - }; - programs.firefox.profiles.default.settings = { "media.ffmpeg.vaapi.enabled" = true; #Hardware acceleration }; @@ -51,7 +48,7 @@ in ''; "sxhkd/sxhkdrc".text = - builtins.readFile (dotfiles + "/sxhkd/dwm") + + builtins.readFile (dotfiles + "/sxhkd/xmonad") + builtins.readFile (dotfiles + "/sxhkd/base") + '' diff --git a/modules/xorg/default.nix b/modules/xorg/default.nix index 50b070e..31a4aa1 100644 --- a/modules/xorg/default.nix +++ b/modules/xorg/default.nix @@ -4,7 +4,6 @@ enable = true; displayManager.startx.enable = true; - windowManager.dwm.enable = true; dpi = 96; }; diff --git a/packages/default.nix b/packages/default.nix index 8bee5e4..83797f0 100644 --- a/packages/default.nix +++ b/packages/default.nix @@ -8,5 +8,6 @@ final: prev: kindlegen = prev.callPackage ./kindlegen { }; manga-cli = prev.callPackage ./manga-cli { }; mov-cli = prev.callPackage ./mov-cli { }; + xmonadctl = prev.callPackage ./xmonadctl { }; }; } diff --git a/packages/xmonadctl/default.nix b/packages/xmonadctl/default.nix new file mode 100644 index 0000000..01d2566 --- /dev/null +++ b/packages/xmonadctl/default.nix @@ -0,0 +1,6 @@ +{ writers, haskellPackages, ... }: +writers.writeHaskellBin "xmonadctl" +{ + libraries = [ haskellPackages.xmonad-contrib haskellPackages.X11 ]; +} + (builtins.readFile ./xmonadctl.hs) diff --git a/packages/xmonadctl/xmonadctl.hs b/packages/xmonadctl/xmonadctl.hs new file mode 100644 index 0000000..a3cc73f --- /dev/null +++ b/packages/xmonadctl/xmonadctl.hs @@ -0,0 +1,51 @@ +import Graphics.X11.Xlib +import Graphics.X11.Xlib.Extras +import System.Environment +import System.IO +import Data.Char + +main :: IO () +main = parse True "XMONAD_COMMAND" =<< getArgs + +parse :: Bool -> String -> [String] -> IO () +parse input addr args = case args of + ["--"] | input -> repl addr + | otherwise -> return () + ("--":xs) -> sendAll addr xs + ("-a":a:xs) -> parse input a xs + ("-h":_) -> showHelp + ("--help":_) -> showHelp + ("-?":_) -> showHelp + (a@('-':_):_) -> hPutStrLn stderr ("Unknown option " ++ a) + + (x:xs) -> sendCommand addr x >> parse False addr xs + [] | input -> repl addr + | otherwise -> return () + + +repl :: String -> IO () +repl addr = do e <- isEOF + case e of + True -> return () + False -> do l <- getLine + sendCommand addr l + repl addr + +sendAll :: String -> [String] -> IO () +sendAll addr ss = foldr (\a b -> sendCommand addr a >> b) (return ()) ss + +sendCommand :: String -> String -> IO () +sendCommand addr s = do + d <- openDisplay "" + rw <- rootWindow d $ defaultScreen d + a <- internAtom d addr False + m <- internAtom d s False + allocaXEvent $ \e -> do + setEventType e clientMessage + setClientMessageEvent e rw a 32 m currentTime + sendEvent d rw False structureNotifyMask e + sync d False + +showHelp :: IO () +showHelp = do pn <- getProgName + putStrLn ("Send commands to a running instance of xmonad. xmonad.hs must be configured with XMonad.Hooks.ServerMode to work.\n-a atomname can be used at any point in the command line arguments to change which atom it is sending on.\nIf sent with no arguments or only -a atom arguments, it will read commands from stdin.\nEx:\n" ++ pn ++ " cmd1 cmd2\n" ++ pn ++ " -a XMONAD_COMMAND cmd1 cmd2 cmd3 -a XMONAD_PRINT hello world\n" ++ pn ++ " -a XMONAD_PRINT # will read data from stdin.\nThe atom defaults to XMONAD_COMMAND.") \ No newline at end of file |