dotfiles/.emacs.d/desktop.org

6.6 KiB

Desktop

Exwm Desktop

[Desktop Entry]
Name=EXWM
Comment=Emacs Window Manager
Exec=sh /home/jaeus/.emacs.d/exwm/start-exwm.sh
TryExec=sh
Type=Application
X-LightDM-DesktopName=exwm
DesktopNames=exwm
#!/bin/sh
# Fire it up for WSL
VETHER_IP=$(/bin/grep nameserver /etc/resolv.conf 2> /dev/null | /bin/tr -s ' ' | /bin/cut -d' ' -f2)
export DISPLAY=$VETHER_IP:10.0
picom -b --config $HOME/.xmonad/scripts/picom.conf &
exec dbus-launch --exit-with-session emacs -mm --debug-init -l ~/.emacs.d/desktop.el

Configuration

EXWM

  (defun efs/run-in-background (command)
    (let ((command-parts (split-string command "[ ]+")))
      (apply #'call-process `(,(car command-parts) nil 0 nil ,@(cdr command-parts)))))

  (defun efs/exwm-init-hook ()
    ;; Make workspace 1 be the one where we land at startup
    (exwm-workspace-switch-create 1)
    (efs/start-panel)
    ;; if not wsl
    (efs/run-in-background "xsetroot -cursor_name left_ptr &")
    (efs/run-in-background "nm-applet &")
    (efs/run-in-background "pamac-tray &")
    ;;(efs/run-in-background "xfce4-power-manager &")
    (efs/run-in-background "volumeicon &")
    (efs/run-in-background "numlockx on &")
    (efs/run-in-background "blueberry-tray &")
    (efs/run-in-background "fcitx &")

    ;; Launch apps that will run in the background
    (efs/run-in-background "dwall -s firewatch")
    (efs/run-in-background "picom -b --config $HOME/.xmonad/scripts/picom.conf &")
    )

  (defun efs/exwm-update-class ()
    (exwm-workspace-rename-buffer exwm-class-name))

  (defun efs/exwm-update-title ()
    (pcase exwm-class-name
      ("Firefox" (exwm-workspace-rename-buffer (format "Firefox: %s" exwm-title)))))

  ;; This function isn't currently used, only serves as an example how to
  ;; position a window
  (defun efs/position-window ()
    (let* ((pos (frame-position))
           (pos-x (car pos))
           (pos-y (cdr pos)))

      (exwm-floating-move (- pos-x) (- pos-y))))

  ;;(defun efs/configure-window-by-class ()
  ;;  (interactive)
  ;;  (pcase exwm-class-name
  ;;    ("vivaldi-stable" (exwm-workspace-move-window 2))
  ;;    ("Sol" (exwm-workspace-move-window 3))
  ;;    ("mpv" (exwm-floating-toggle-floating)
  ;;           (exwm-layout-toggle-mode-line))))

  ;; This function should be used only after configuring autorandr!
  ;;(defun efs/update-displays ()
  ;;  (efs/run-in-background "autorandr --change --force")
  ;;  (efs/set-wallpaper)
  ;;  (message "Display config: %s"
  ;;           (string-trim (shell-command-to-string "autorandr --current"))))

  (use-package exwm
    :config
    ;; Set the default number of workspaces
    (setq exwm-workspace-number 10)

    ;; When window "class" updates, use it to set the buffer name
    (add-hook 'exwm-update-class-hook #'efs/exwm-update-class)

    ;; When window title updates, use it to set the buffer name
    (add-hook 'exwm-update-title-hook #'efs/exwm-update-title)

    ;; Configure windows as they're created
    ;;(add-hook 'exwm-manage-finish-hook #'efs/configure-window-by-class)

    ;; When EXWM starts up, do some extra confifuration
    (add-hook 'exwm-init-hook #'efs/exwm-init-hook)

    ;; Automatically send the mouse cursor to the selected workspace's display
    (setq exwm-workspace-warp-cursor t)

    ;; Window focus should follow the mouse pointer
    (setq mouse-autoselect-window t
          focus-follows-mouse t)

    ;; These keys should always pass through to Emacs
    (setq exwm-input-prefix-keys
          '(?\C-x
            ?\C-u
            ?\C-h
            ?\M-x
            ?\M-`
            ?\M-&
            ?\M-:
            ?\C-\M-j  ;; Buffer list
            ?\C-\ ))  ;; Ctrl+Space

    ;; Ctrl+Q will enable the next key to be sent directly
    (define-key exwm-mode-map [?\C-q] 'exwm-input-send-next-key)

    ;; Set up global key bindings.  These always work, no matter the input state!
    ;; Keep in mind that changing this list after EXWM initializes has no effect.
    (setq exwm-input-global-keys
          `(
            ;; Reset to line-mode (C-c C-k switches to char-mode via exwm-input-release-keyboard)
            ([?\s-r] . exwm-reset)

            ;; Move between windows
            ([s-left] . windmove-left)
            ([s-right] . windmove-right)
            ([s-up] . windmove-up)
            ([s-down] . windmove-down)

            ;;([s-space] . toggle-frame-fullscreen)
            ([?\s-f] . exwm-floating-toggle-floating)

            ;; Launch applications via shell command
            ([?\s-&] . (lambda (command)
                         (interactive (list (read-shell-command "$ ")))
                         (start-process-shell-command command nil command)))

            ;; Switch workspace
            ([?\s-w] . exwm-workspace-switch)
            ([?\s-`] . (lambda () (interactive) (exwm-workspace-switch-create 0)))

            ;; 's-N': Switch to certain workspace with Super (Win) plus a number key (0 - 9)
            ,@(mapcar (lambda (i)
                        `(,(kbd (format "s-%d" i)) .
                          (lambda ()
                            (interactive)
                            (exwm-workspace-switch-create ,i))))
                      (number-sequence 0 9))))

    (require 'exwm-systemtray)
    (setq exwm-systemtray-height 32)
    (exwm-systemtray-enable)
    (exwm-enable))

  (use-package desktop-environment
    :after exwm
    :config (desktop-environment-mode)
    :custom
    (desktop-environment-brightness-small-increment "2%+")
    (desktop-environment-brightness-small-decrement "2%-")
    (desktop-environment-brightness-normal-increment "5%+")
    (desktop-environment-brightness-normal-decrement "5%-"))

  ;; Make sure the server is started (better to do this in your main Emacs config!)
  (server-start)

Polybar

(defvar efs/polybar-process nil
  "Holds the process of the running Polybar instance, if any")

(defun efs/kill-panel ()
  (interactive)
  (when efs/polybar-process
    (ignore-errors
      (kill-process efs/polybar-process)))
  (setq efs/polybar-process nil))

(defun efs/start-panel ()
  (interactive)
  (efs/kill-panel)
  (setq efs/polybar-process (start-process-shell-command "polybar" nil "polybar panel")))

(defun efs/send-polybar-hook (module-name hook-index)
  (start-process-shell-command "polybar-msg" nil (format "polybar-msg hook %s %s" module-name hook-index)))

(defun efs/send-polybar-exwm-workspace ()
  (efs/send-polybar-hook "exwm-workspace" 1))

;; Update panel indicator when workspace changes
(add-hook 'exwm-workspace-switch-hook #'efs/send-polybar-exwm-workspace)