Skip to content

Commit

Permalink
feat(desktop): add xmonad
Browse files Browse the repository at this point in the history
  • Loading branch information
yunfachi committed Nov 30, 2023
1 parent 34e97fa commit b50c8be
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 8 deletions.
5 changes: 5 additions & 0 deletions home/desktop/xmonad/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{...}: {
xsession.windowManager.xmonad = {
config = ./xmonad.hs;
};
}
148 changes: 148 additions & 0 deletions home/desktop/xmonad/xmonad.hs
Original file line number Diff line number Diff line change
@@ -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
}
10 changes: 6 additions & 4 deletions modules/desktop/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{...}: {
imports = [
../core
];
{lib, ...}: {
imports =
map (n: toString ./. + "/${n}") (lib.remove "default.nix" (builtins.attrNames (builtins.readDir ./.)))
++ [
../core
];
}
19 changes: 19 additions & 0 deletions modules/desktop/xmonad.nix
Original file line number Diff line number Diff line change
@@ -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";
};
}
10 changes: 6 additions & 4 deletions modules/server/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{...}: {
imports = [
../core
];
{lib, ...}: {
imports =
map (n: toString ./. + "/${n}") (lib.remove "default.nix" (builtins.attrNames (builtins.readDir ./.)))
++ [
../core
];
}

0 comments on commit b50c8be

Please sign in to comment.