From b50c8be2dda362dbe4c2be42132374c23338f98d Mon Sep 17 00:00:00 2001 From: yunfachi Date: Thu, 30 Nov 2023 18:17:00 +0300 Subject: [PATCH] feat(desktop): add xmonad --- home/desktop/xmonad/default.nix | 5 ++ home/desktop/xmonad/xmonad.hs | 148 ++++++++++++++++++++++++++++++++ modules/desktop/default.nix | 10 ++- modules/desktop/xmonad.nix | 19 ++++ modules/server/default.nix | 10 ++- 5 files changed, 184 insertions(+), 8 deletions(-) create mode 100644 home/desktop/xmonad/default.nix create mode 100644 home/desktop/xmonad/xmonad.hs create mode 100644 modules/desktop/xmonad.nix diff --git a/home/desktop/xmonad/default.nix b/home/desktop/xmonad/default.nix new file mode 100644 index 0000000..c65a63a --- /dev/null +++ b/home/desktop/xmonad/default.nix @@ -0,0 +1,5 @@ +{...}: { + xsession.windowManager.xmonad = { + config = ./xmonad.hs; + }; +} diff --git a/home/desktop/xmonad/xmonad.hs b/home/desktop/xmonad/xmonad.hs new file mode 100644 index 0000000..9f8e640 --- /dev/null +++ b/home/desktop/xmonad/xmonad.hs @@ -0,0 +1,148 @@ +------------- +-- imports -- +------------- +import XMonad +import XMonad.Actions.UpdateFocus +import XMonad.Hooks.DynamicProperty + +{-- layouts --} +import XMonad.Layout.Gaps (gaps, Direction2D(D, L, R, U)) +import XMonad.Layout.Spacing (spacingRaw, Border(Border)) +import XMonad.Layout.Grid +import XMonad.Layout.NoBorders + +{-- launch process --} +import XMonad.Util.SpawnOnce (spawnOnce) + +{-- for keybinds --} +import qualified XMonad.StackSet as W +import qualified Data.Map as M +import XMonad.Actions.CopyWindow + +--------------- +-- variables -- +--------------- +myTerminal = "kitty" +myModMask = mod4Mask {-- super --} +myFocusFollowsMouse = True +myBorderWidth = 1 +myNormalBorderColor = "#666666" +myFocusedBorderColor = "#ffffff" +myWorkspaces = ["1", "2", "3", "4", "5"] + +------------------------- +-- auto start programs -- +------------------------- +myStartupHook = do + spawnOnce "xrandr --output DP-3 --mode 1920x1080 --rate 144 --primary --brightness 1.0" + +---------------------------------------------------------------------- +-- keybinds +---------------------------------------------------------------------- +myKeys conf@(XConfig {XMonad.modMask = super}) = M.fromList $ + [ + {-- launch a terminal --} + ((super, xK_Return), + spawn myTerminal), + + {-- kill active window --} + ((super, xK_q), + kill), + + {-- rebuild XMonad --} + ((super, xK_r), + spawn "xmonad --recompile; xmonad --restart"), + + + + {-- show window on all workspaces --} + ((super, xK_f), + windows copyToAll), + + {-- show window on all workspaces --} + ((super .|. shiftMask, xK_f), + killAllOtherCopies), + + + + {-- swap the focused window and master window --} + ((super, xK_z), + windows W.swapMaster), + + {-- shrink the master window --} + ((super, xK_x), + sendMessage Shrink), + + {-- expand the master window --} + ((super, xK_c), + sendMessage Expand), + + {-- back to tiling mode --} + ((super, xK_v), + withFocused $ windows . W.sink), + + {-- change layout --} + ((super, xK_l), + sendMessage NextLayout) + ] + + ++ + + [ + {-- move the workspace or send the window to the any workspaces --} + ((m .|. super, k), windows $ f i) + | (i, k) <- zip (XMonad.workspaces conf) [xK_1 .. xK_9] + , (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)] + ] + +------------------ +-- window rules -- +------------------ +myManageHook :: ManageHook +myManageHook = composeAll + [ + className =? "Bar" --> doIgnore, + + title =? "Picture-in-Picture" --> doFloat + ] + +------------ +-- layout -- +------------ +myLayoutHook = + gaps [(L, 0), (R, 0), (U, 0), (D, 0)] $ + + spacingRaw True (Border gap gap gap gap) + True (Border gap gap gap gap) + True $ + + Grid ||| + Mirror (Tall 1 (3/100) (3/5)) ||| + noBorders Full + + where + nmaster = 1 + delta = 3/100 + fraction = 1/2 + + gap = 5 +---------- +-- main -- +---------- +main :: IO () +main = xmonad $ defaults + +defaults = def + { + terminal = myTerminal, + modMask = myModMask, + focusFollowsMouse = myFocusFollowsMouse, + borderWidth = myBorderWidth, + normalBorderColor = myNormalBorderColor, + focusedBorderColor = myFocusedBorderColor, + workspaces = myWorkspaces, + keys = myKeys, + layoutHook = myLayoutHook, + startupHook = myStartupHook, + handleEventHook = dynamicPropertyChange "WM_NAME" myManageHook <+> focusOnMouseMove + } \ No newline at end of file diff --git a/modules/desktop/default.nix b/modules/desktop/default.nix index 3ebe08a..9181cdb 100644 --- a/modules/desktop/default.nix +++ b/modules/desktop/default.nix @@ -1,5 +1,7 @@ -{...}: { - imports = [ - ../core - ]; +{lib, ...}: { + imports = + map (n: toString ./. + "/${n}") (lib.remove "default.nix" (builtins.attrNames (builtins.readDir ./.))) + ++ [ + ../core + ]; } diff --git a/modules/desktop/xmonad.nix b/modules/desktop/xmonad.nix new file mode 100644 index 0000000..bc8e947 --- /dev/null +++ b/modules/desktop/xmonad.nix @@ -0,0 +1,19 @@ +{...}: { + services.xserver = { + enable = true; + + windowManager.xmonad = { + enable = true; + enableContribAndExtras = true; + + extraPackages = hp: [ + hp.dbus + hp.monad-logger + ]; + }; + + displayManager.defaultSession = "none+xmonad"; + xkbOptions = "grp:win_space_toggle"; + layout = "us,ru"; + }; +} diff --git a/modules/server/default.nix b/modules/server/default.nix index 3ebe08a..9181cdb 100644 --- a/modules/server/default.nix +++ b/modules/server/default.nix @@ -1,5 +1,7 @@ -{...}: { - imports = [ - ../core - ]; +{lib, ...}: { + imports = + map (n: toString ./. + "/${n}") (lib.remove "default.nix" (builtins.attrNames (builtins.readDir ./.))) + ++ [ + ../core + ]; }