From 54be96d8b6c8e812dab2456c2e3c522840c62d99 Mon Sep 17 00:00:00 2001 From: Timothy DeHerrera Date: Tue, 9 Jun 2020 10:36:38 -0600 Subject: [PATCH] graphical#xmonad: init profile --- pkgs/applications/misc/dzvol.nix | 18 +++ pkgs/default.nix | 1 + profiles/graphical/default.nix | 4 +- profiles/graphical/xmonad/_xmonad.hs | 87 ++++++++++++++ profiles/graphical/xmonad/_xmonad.nix | 106 ++++++++++++++++++ profiles/graphical/xmonad/default.nix | 11 ++ profiles/graphical/xmonad/scripts/autostart | 16 +++ profiles/graphical/xmonad/scripts/stoggle | 45 ++++++++ profiles/graphical/xmonad/scripts/touchtoggle | 12 ++ profiles/graphical/xmonad/xmonad.hs.nix | 19 ++++ 10 files changed, 318 insertions(+), 1 deletion(-) create mode 100644 pkgs/applications/misc/dzvol.nix create mode 100644 profiles/graphical/xmonad/_xmonad.hs create mode 100644 profiles/graphical/xmonad/_xmonad.nix create mode 100644 profiles/graphical/xmonad/default.nix create mode 100644 profiles/graphical/xmonad/scripts/autostart create mode 100644 profiles/graphical/xmonad/scripts/stoggle create mode 100644 profiles/graphical/xmonad/scripts/touchtoggle create mode 100644 profiles/graphical/xmonad/xmonad.hs.nix diff --git a/pkgs/applications/misc/dzvol.nix b/pkgs/applications/misc/dzvol.nix new file mode 100644 index 00000000..2532c0d0 --- /dev/null +++ b/pkgs/applications/misc/dzvol.nix @@ -0,0 +1,18 @@ +{ stdenv, pkgconfig, alsaLib, x11, fetchFromGitHub }: +stdenv.mkDerivation { + name = "dzvol"; + src = fetchFromGitHub { + owner = "allevaton"; + repo = "dzvol"; + rev = "ca7099520525df2d54ad24f6def22819d5f36b3b"; + sha256 = "1xx7xai6hzrm3gs026z41pl877y849vpfi71syj6cj3ir9h16lpz"; + }; + + installPhase = '' + mkdir -p $out/bin + cp dzvol $out/bin + ''; + + buildInputs = [ pkgconfig alsaLib x11 ]; + hardeningDisable = [ "format" ]; +} diff --git a/pkgs/default.nix b/pkgs/default.nix index 184797f8..99b464cc 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -4,4 +4,5 @@ final: prev: { dejavu_nerdfont = prev.callPackage ./data/fonts/dejavu-nerdfont { }; purs = prev.callPackage ./shells/zsh/purs { }; pure = prev.callPackage ./shells/zsh/pure { }; + dzvol = prev.callPackage ./applications/misc/dzvol.nix { }; } diff --git a/profiles/graphical/default.nix b/profiles/graphical/default.nix index 2371bbc1..b82d3eb8 100644 --- a/profiles/graphical/default.nix +++ b/profiles/graphical/default.nix @@ -1,7 +1,7 @@ { config, pkgs, ... }: let inherit (builtins) readFile; in { - imports = [ ./sway ../develop ]; + imports = [ ./sway ../develop ./xmonad ]; hardware.opengl.enable = true; hardware.opengl.driSupport = true; @@ -54,6 +54,8 @@ in { ]; }; + services.xbanish.enable = true; + services.xserver = { enable = true; diff --git a/profiles/graphical/xmonad/_xmonad.hs b/profiles/graphical/xmonad/_xmonad.hs new file mode 100644 index 00000000..3fc24ac2 --- /dev/null +++ b/profiles/graphical/xmonad/_xmonad.hs @@ -0,0 +1,87 @@ +import XMonad +import XMonad.Config.Desktop (desktopConfig) +import XMonad.Hooks.EwmhDesktops (ewmh) +import XMonad.Hooks.ICCCMFocus (takeTopFocus) +import XMonad.Hooks.ManageDocks +import XMonad.Util.EZConfig (additionalKeys) + +import Data.Maybe (fromMaybe) +import Graphics.X11.ExtraTypes.XF86 (xF86XK_AudioLowerVolume, + xF86XK_AudioMute, + xF86XK_AudioRaiseVolume) +import Graphics.X11.Types (KeyMask, KeySym, Window) +import System.Environment (lookupEnv) +import XMonad.Layout.ResizableTile (ResizableTall(..), + MirrorResize (MirrorShrink, + MirrorExpand)) +import XMonad.Layout.MultiToggle +import XMonad.Layout.MultiToggle.Instances + +import Control.Monad (liftM2) +import Data.Monoid (Endo) +import XMonad.Core (Layout, Query, + ScreenDetail, ScreenId, + WorkspaceId, X) +import XMonad.Hooks.SetWMName (setWMName) +import XMonad.Layout.NoBorders (smartBorders) +import XMonad.Layout.PerWorkspace (onWorkspace) +import XMonad.Layout.Reflect (reflectHoriz) +import XMonad.Util.Cursor +import qualified XMonad.StackSet as S (StackSet, greedyView, + shift) + +main :: IO () +main = + xmonad . ewmh $ desktopConfig + { terminal = "alacritty" + , modMask = myModKey + , layoutHook = avoidStruts myLayout + , workspaces = myWorkspaces + , startupHook = myAutostart + , manageHook = myManageHook + <+> manageHook defaultConfig + <+> manageDocks + , borderWidth = 1 + , logHook = takeTopFocus + } + `additionalKeys` myKeys + +myLayout = smartBorders + . mkToggle ( NBFULL ?? EOT) + . onWorkspace "7:im" ( half ||| Mirror half ||| tiled ||| reflectHoriz tiled ) + $ tiled ||| reflectHoriz tiled ||| half ||| Mirror half + where + tiled = ResizableTall nmaster delta ratiot [] + half = ResizableTall nmaster delta ratioh [] + nmaster = 1 + ratiot = 309/500 + ratioh = 1/2 + delta = 1/9 + +myWorkspaces :: [ String ] +myWorkspaces = ["1:main", "2:art", "3:net", "4:pdf", "5:game", "6:media", "7:im", "8", "9"] + +-- Move Programs by X11 Class to specific workspaces on opening +myManageHook :: Query + ( Endo + ( S.StackSet WorkspaceId (Layout Window) Window ScreenId ScreenDetail ) + ) +myManageHook = composeAll + [ className =? "st-256color" --> viewShift "1:main" + , className =? "qutebrowser" --> viewShift "1:main" + , className =? "Gimp" --> viewShift "2:art" + , className =? "krita" --> viewShift "2:art" + , className =? "qBittorrent" --> viewShift "3:torrent" + , className =? "PCSX2" --> viewShift "5:game" + , className =? "RPCS3" --> viewShift "5:game" + , className =? "mpv" --> viewShift "6:media" + , className =? "Zathura" --> viewShift "4:pdf" + , className =? "Signal" --> doShift "7:im" + , className =? "Steam" --> doFloat + , className =? "Wine" --> doFloat + ] + where viewShift = doF . liftM2 (.) S.greedyView S.shift + +-- Set ModKey to the Windows Key +myModKey :: KeyMask +myModKey = mod4Mask diff --git a/profiles/graphical/xmonad/_xmonad.nix b/profiles/graphical/xmonad/_xmonad.nix new file mode 100644 index 00000000..26ef5031 --- /dev/null +++ b/profiles/graphical/xmonad/_xmonad.nix @@ -0,0 +1,106 @@ +{ autostart, screenshots, touchtoggle, dzvol, stoggle }: '' + -- Function for fullscreen toggle + fullToggle :: X () + fullToggle = do + spawn "${stoggle}" + sendMessage $ Toggle NBFULL + sendMessage $ SetStruts [] [minBound .. maxBound] + + -- function to call dzen2 and show volume in the middle of the screen + dzcall :: String + dzcall = "${dzvol}/bin/dzvol -fn 'DejaVu Sans Mono for Powerline-16:normal'" + + myAutostart :: X () + myAutostart = do + spawn "${autostart}" + setWMName "LG3D" + sendMessage $ SetStruts [] [minBound .. maxBound] + setDefaultCursor xC_left_ptr + + -- Set custom keybinds below following the structure: + -- ( ( ModifierKey, KeyPress ), Action ) + myKeys :: [ ( ( KeyMask, KeySym ), X () ) ] + myKeys = + -- toggle fullscreen, along with power state + [ ( ( myModKey , xK_f ) + , fullToggle + ) + -- resize windows in master pane + , ( ( myModKey , xK_Left ) + , sendMessage MirrorExpand + ) + , ( ( myModKey , xK_Right ) + , sendMessage MirrorShrink + ) + , ( ( myModKey , xK_Up ) + , sendMessage MirrorExpand + ) + , ( ( myModKey , xK_Down ) + , sendMessage MirrorShrink + ) + -- toggle systray + , ( ( myModKey .|. shiftMask , xK_f ) + , sendMessage ToggleStruts + ) + -- lower volume + , ( ( 0 , xF86XK_AudioLowerVolume ) + , spawn dzcall + ) + -- raise volume + , ( ( 0 , xF86XK_AudioRaiseVolume ) + , spawn dzcall + ) + -- mute volume + , ( ( 0 , xF86XK_AudioMute ) + , spawn dzcall + ) + -- start qutebrowser + , ( ( myModKey , xK_b ) + , spawn "qute" + ) + -- screen lock + , ( ( myModKey .|. shiftMask , xK_l ) + + , spawn "loginctl lock-session" + ) + -- screenshot + , ( ( myModKey , xK_Print ) + , spawn "maim -u \ + \ | png2ff | xz -9 - \ + \ > ~/${screenshots}/$(date +%m.%d.%y_%I.%M.%S_%p).ff.xz" + ) + -- screenshot focused window + , ( ( myModKey .|. shiftMask , xK_Print ) + + , spawn "maim -u -i$(xdotool getactivewindow) \ + \ | png2ff \ + \ | xz -9 - \ + \ > ~/${screenshots}/$(date +%m.%d.%y_%I.%M.%S_%p).ff.xz" + ) + -- screenshot selection to clipboard + , ( ( myModKey .|. controlMask , xK_Print ) + + , spawn "maim -s -u \ + \ | xclip -selection clipboard -t image/png" + ) + -- screenshot selection file + , ( ( myModKey .|. controlMask .|. shiftMask, xK_Print ) + + , spawn "maim -s -u \ + \ | png2ff \ + \ | xz -9 - \ + \ > ~/${screenshots}/$(date +%m.%d.%y_%I.%M.%S_%p).ff.xz" + ) + -- screenshot selection to imgur and paste url in clipboard + , ( ( myModKey .|. shiftMask , xK_i ) + + , spawn "maim -s -u /tmp/img.png; \ + \ imgurbash2 /tmp/img.png; \ + \ rm /tmp/img.png" + ) + -- dmenu frontend for network manager + , ( ( myModKey , xK_n ) + , spawn "networkmanager_dmenu -fn 'DejaVu Sans Mono for Powerline-16:normal'" + ) + ] +'' diff --git a/profiles/graphical/xmonad/default.nix b/profiles/graphical/xmonad/default.nix new file mode 100644 index 00000000..f35ca16d --- /dev/null +++ b/profiles/graphical/xmonad/default.nix @@ -0,0 +1,11 @@ +{ pkgs, ... }: { + environment.systemPackages = with pkgs; [ xss-lock dzvol maim ]; + + services.xserver.windowManager.xmonad = { + enable = true; + enableContribAndExtras = true; + config = import ./xmonad.hs.nix { inherit pkgs; }; + }; + + programs.slock.enable = true; +} diff --git a/profiles/graphical/xmonad/scripts/autostart b/profiles/graphical/xmonad/scripts/autostart new file mode 100644 index 00000000..46bc7fee --- /dev/null +++ b/profiles/graphical/xmonad/scripts/autostart @@ -0,0 +1,16 @@ +#!/usr/bin/env zsh + +terminal="alacritty" + +# set screen locker to slock +pgrep -x xss-lock \ +|| xss-lock slock&! + +pgrep -x xbanish \ +|| xbanish&! + +${terminal} -e tmux new-session -As $(whoami)&! + +if ! pgrep -f qutebrowser; then + ${BROWSER} &! +fi diff --git a/profiles/graphical/xmonad/scripts/stoggle b/profiles/graphical/xmonad/scripts/stoggle new file mode 100644 index 00000000..bdb9c379 --- /dev/null +++ b/profiles/graphical/xmonad/scripts/stoggle @@ -0,0 +1,45 @@ +#!/usr/bin/env zsh +# variables for dzen2 +WIDTH=512 +WINDOW_HEIGHT=$( xdpyinfo \ + | awk '$1 ~ /dimensions/ {split($2,arr,"x"); print int(arr[2])}' \ +) +WINDOW_WIDTH=$( xdpyinfo \ + | awk '$1 ~ /dimensions/ {split($2,arr,"x"); print int(arr[1])}' \ +) +XPOS=$(( ( ${WINDOW_WIDTH} / 2 ) - ( ${WIDTH} / 2 ) )) +YPOS=$(( ${WINDOW_HEIGHT} / 2 )) + +readonly WIDTH WINDOW_HEIGHT WINDOW_WIDTH XPOS YPOS + +# get current state of dpms +xset -q \ + | grep -Eo 'DPMS is (Enabled|Disabled)' \ + | awk '{print $3}' \ + | read dpms_state + +# function to call dzen2 with current state +dzen2_dpms_state () { + local -r \ + new_dpms_state=$1 + + print "Power Management ${new_dpms_state}" \ + | dzen2 -fn "DejaVu Sans Mono for Powerline-16:normal" -p 2 -tw ${WIDTH} -x ${XPOS} -y ${YPOS} +} + + case $dpms_state in + Enabled) + xset -dpms + xset s off + dzen2_dpms_state "Disabled" + ;; + Disabled) + xset +dpms + xset s on + xset s 300 + dzen2_dpms_state "Enabled" + ;; + *) + exit 1 + ;; + esac diff --git a/profiles/graphical/xmonad/scripts/touchtoggle b/profiles/graphical/xmonad/scripts/touchtoggle new file mode 100644 index 00000000..2ef3ef07 --- /dev/null +++ b/profiles/graphical/xmonad/scripts/touchtoggle @@ -0,0 +1,12 @@ +#!/usr/bin/env zsh +touchpad_name=$(libinput list-devices | grep -B 5 "pointer gesture" | awk '/Device/ {for (i=2; i