diff --git a/emacs-lisp/windows_and_frames.org b/emacs-lisp/windows_and_frames.org index 478f720..ba88827 100644 --- a/emacs-lisp/windows_and_frames.org +++ b/emacs-lisp/windows_and_frames.org @@ -30,3 +30,19 @@ Disable window changing using the mouse, it saves me from accidental switches. (funcall fun event)))) (advice-add 'mouse-set-region :around 'cv/mouse-set-region) #+end_src + +#+begin_src emacs-lisp + (defun maybe-delete-frame-buffer (frame) + "When a dedicated FRAME is deleted, also kill its buffer. + A dedicated frame contains a single window whose buffer is not + displayed anywhere else." + (let ((windows (window-list frame))) + (when (eq 1 (length windows)) + (let ((buffer (window-buffer (car windows)))) + (when (eq 1 (length (get-buffer-window-list buffer nil t))) + (when (frame-parameter frame 'unsplittable) + (with-current-buffer buffer + (when (equal major-mode #'vterm-mode) (message "VTERM") (kill-process (get-buffer-process buffer))) + (kill-buffer buffer)))))))) + (add-to-list 'delete-frame-functions #'maybe-delete-frame-buffer) +#+end_src diff --git a/home-manager/modules/xmonad/app/Main.hs b/home-manager/modules/xmonad/app/Main.hs index 33c0790..7c9995d 100644 --- a/home-manager/modules/xmonad/app/Main.hs +++ b/home-manager/modules/xmonad/app/Main.hs @@ -14,6 +14,7 @@ {-# LANGUAGE BlockArguments #-} {-# LANGUAGE LambdaCase #-} +{-# LANGUAGE TupleSections #-} import XMonad import Data.Monoid @@ -40,6 +41,8 @@ import XMonad.Actions.UpdatePointer import XMonad.Actions.FloatKeys import XMonad.Actions.Warp import XMonad.Actions.CopyWindow +import XMonad.StackSet (Workspace, integrate', stack) +import Foreign.C.String (peekCString) import Control.Monad @@ -87,6 +90,21 @@ getCurrentLayout :: X String getCurrentLayout = gets windowset <&> description . W.layout . W.workspace . W.current +workspacesGrouped :: X [(WorkspaceId, Window, String)] +workspacesGrouped = withDisplay \dpy -> do + ws <- gets windowset + let x = map W.workspace (W.current ws : W.visible ws) + let y = W.hidden ws + mapM (\v -> do + let windows = getWorkspaceWindows v + mapM (\win -> getWindowTitle win dpy <&> \title -> (W.tag v, win, title)) windows) (x ++ y) <&> concat + +getWorkspaceWindows :: Workspace i l Window -> [Window] +getWorkspaceWindows w = integrate' $ stack w + +getWindowTitle :: Window -> Display -> X String +getWindowTitle w d = liftIO $ getTextProperty d w wM_NAME >>= (peekCString . tp_value) + modm :: KeyMask modm = mod4Mask @@ -94,11 +112,9 @@ modm = mod4Mask -- Key bindings. Add, modify or remove key bindings here. -- myKeymap c = - -- launch a terminal - [ ("M-S-", spawn "alacritty") - + [ -- launch dmenu - , ("M-e", spawn "dmenu_run") + ("M-e", spawn "dmenu_run") -- close focused window , ("M-S-q", io exitSuccess) @@ -173,16 +189,20 @@ myKeymap c = , ("" , spawn "brightnessctl set +5%") , ("" , spawn "brightnessctl set 5%-") - , ("" , spawn "notify -t 5000 \"Music: Play\"" >> spawn "playerctl play-pause") - , ("" , spawn "notify -t 5000 \"Music: Stop\"" >> spawn "playerctl stop") - , ("" , spawn "notify -t 5000 \"Music: Prev\"" >> spawn "playerctl previous") - , ("" , spawn "notify -t 5000 \"Music: Next\"" >> spawn "playerctl next") + , ("" , spawn "notify-send -t 5000 \"Music: Play\"" >> spawn "playerctl play-pause") + , ("" , spawn "notify-send -t 5000 \"Music: Stop\"" >> spawn "playerctl stop") + , ("" , spawn "notify-send -t 5000 \"Music: Prev\"" >> spawn "playerctl previous") + , ("" , spawn "notify-send -t 5000 \"Music: Next\"" >> spawn "playerctl next") , ("" , spawn "toggle-touchpad") , ("M-", spawn "auxmenu") + , ("M-", spawn "emacsclient -cn") + , ("M-S-", spawn "emacs-vterm") + , ("M-", spawn "alacritty") , ("M-", withDisplay $ \dpy -> withFocused $ \window -> toggleFullscreen dpy window) + , ("M-", (workspacesGrouped >>= \ws -> (liftIO . print $ ws))) ] ++ diff --git a/home-manager/modules/xmonad/default.nix b/home-manager/modules/xmonad/default.nix index 4c36ad3..229b054 100644 --- a/home-manager/modules/xmonad/default.nix +++ b/home-manager/modules/xmonad/default.nix @@ -31,6 +31,9 @@ auxmenu = pkgs.writeShellScriptBin "auxmenu" (builtins.readFile ./scripts/auxmenu.sh); + emacs-vterm = + pkgs.writeShellScriptBin "emacs-vterm" + (builtins.readFile ./scripts/emacs-vterm.sh); in pkgs.buildEnv { name = "xmonad-runenv"; @@ -43,6 +46,7 @@ reload toggle-touchpad auxmenu + emacs-vterm libnotify x11_ssh_askpass ]; diff --git a/home-manager/modules/xmonad/scripts/emacs-vterm.sh b/home-manager/modules/xmonad/scripts/emacs-vterm.sh new file mode 100644 index 0000000..ecef9fa --- /dev/null +++ b/home-manager/modules/xmonad/scripts/emacs-vterm.sh @@ -0,0 +1 @@ +emacsclient -cn --eval "(progn (vterm t) (set-frame-parameter nil 'unsplittable t) (set-window-dedicated-p (selected-window) t))"