From 5a505b096066e1e5a4049f2ca4ebf8df086e87c5 Mon Sep 17 00:00:00 2001 From: jao Date: Tue, 30 Aug 2022 22:30:15 +0100 Subject: wayland, or wetting a foot in the river --- data/foot.ini | 56 +++++++++++++++++++++++++++ init.el | 120 ++++++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 143 insertions(+), 33 deletions(-) create mode 100644 data/foot.ini diff --git a/data/foot.ini b/data/foot.ini new file mode 100644 index 0000000..484fd1a --- /dev/null +++ b/data/foot.ini @@ -0,0 +1,56 @@ +# -*- conf -*- + +font=DejaVu Sans Mono:size=5 +font-bold=DejaVu Sans Mono:size=5:weight=semibold +# underline-offset=10 + +# font=Iosevka Comfy Fixed:size=5.5 +pad=5x1 + +# initial-window-size-pixels=700x500 # Or, +# initial-window-size-chars= +# initial-window-mode=windowed +# shell=$SHELL (if set, otherwise user's default shell from /etc/passwd) +# term=foot +# login-shell=no +# workers= + +[scrollback] +# lines=1000 +# multiplier=3.0 +# indicator-position=relative +# indicator-format= + +[cursor] +style=block +color=ffffff b22222 +blink=no + +[mouse] +hide-when-typing=yes +# alternate-scroll-mode=yes + +[colors] +alpha=0.85 +background=ffffff +foreground=000000 + +regular0= 073642 +regular1= dc322f +regular2= 859900 +regular3= b58900 +regular4= 268bd2 +regular5= d33682 +regular6= 2aa198 +regular7= eee8d5 +bright0= 002b36 +bright1= cb4b16 +bright2= 586e75 +bright3= 657b83 +bright4= 839496 +bright5= 6c71c4 +bright6= 93a1a1 +bright7= fdf6e3 + +# selection-foreground= +# selection-background= diff --git a/init.el b/init.el index c803bc1..bfb2b14 100644 --- a/init.el +++ b/init.el @@ -252,11 +252,12 @@ ("zathura \"%s\"" "application/pdf") (image-mode "image/*" (display-graphic-p)) ("firefox --private-window \"%s\"" "text/html" - (and jao-sway-enabled (not (display-graphic-p)))) + (and jao-wayland-enabled (not (display-graphic-p)))) ;; ("firefox \"%s\" && swaymsg [app_id=Firefox] focus" "text/html" ;; (and jao-sway-enabled (not (display-graphic-p)))) ("swayimg \"%s\"" "image/*" jao-sway-enabled) - ("feh \"%s\"" "image/*"))))) + ("imv-wayland \"%s\"" "image/*" jao-wayland-enabled) + ("imv-x11 \"%s\"" "image/*" (display-graphic-p)))))) ;;; Crypto ;;;; PGP, EPG, passwords (setq auth-source-debug nil) @@ -450,10 +451,74 @@ (when jao-xmonad-enabled (add-hook 'after-init-hook #'jao-xmonad-enable t)) -;;;; sway -(defun jao-swaymsg (msg) - (shell-command (format "swaymsg '%s' >/dev/null" msg))) +;;;; wayland +(defvar jao-wayland-enabled + (string= "wayland" (or (getenv "XDG_SESSION_TYPE") ""))) + +(defun jao-wayland-enable () + (interactive) + (defalias 'x-change-window-property #'ignore) + (when (eq 'pgtk window-system) (jao-set-transparency 85)) + (jao-themes-setup) + (jao-trisect) + (message "Welcome to wayland")) + +(when jao-sway-enabled + (add-hook 'after-init-hook #'jao-wayland-enable)) + +(defun jao-wayland-type (&rest args) + (apply 'jao-shell-string "wtype" args)) + +;;;; river +(defvar jao-river-enabled (jao-shell-running-p "river")) + +(defun jao-river-to-ws (n) + (jao-wayland-type "-M" "win" (format "%s" n))) + +(defun jao-river-window-list () + (let ((json-false nil) + (json-null nil)) + (json-read-from-string (shell-command-to-string "lswt -j")))) + +(defun jao-river-focused () + (seq-some (lambda (w) (and (alist-get 'activated w) w)) + (jao-river-window-list))) + +(defun jao-river-get-focused-title () + (alist-get 'title (jao-river-focused))) + +(defun jao-river-focus-window (title) + (let* ((ws (jao-river-window-list)) + (w (seq-some (lambda (w) (and (equal title (alist-get 'title w)) w)) + ws))) + (or (alist-get 'activated w) + (seq-some (lambda (_ignored) + (jao-shell-string "riverctl focus-view next") + (equal title (jao-river-get-focused-title))) + (and w ws))))) + +(defun jao-river-zathura-to-org () + (let ((title (jao-river-get-focused-title))) + (jao-notify title "Opening ORG counterpart") + (jao-pdf-goto-zathura-org title t) + (jao-river-to-ws 1))) + +(defun jao-river-find-zathura-window (file) + (let ((frx (regexp-quote (file-name-nondirectory file)))) + (seq-some (lambda (w) + (and (string-suffix-p ".zathura" (alist-get 'app_id w "")) + (string-match-p frx (alist-get 'title w "")) + w)) + (jao-river-window-list)))) + +(defun jao-river-open-with-zathura (file page) + (let ((wd (jao-river-find-zathura-window file))) + (jao-river-to-ws 3) + (or (and wd (jao-river-focus-window (alist-get 'title wd))) + (jao-shell-exec (jao-pdf-zathura-open-cmd file page ""))) + (when page (sit-for 0.2) (jao-wayland-type (format "%dg" page))))) +;;;; sway (defmacro jao-def-swaymsg (name msg) `(defun ,(intern (format "jao-sway-%s" name)) () (interactive) @@ -461,8 +526,7 @@ (jao-def-swaymsg firefox "[app_id=Firefox] focus") -(defvar jao-sway-enabled - (string= "wayland" (or (getenv "XDG_SESSION_TYPE") ""))) +(defvar jao-sway-enabled (jao-shell-running-p "sway")) (defconst jao-sway-get-active-title "swaymsg -t get_tree | jq '.. | select(.type?) | select(.focused==true).name'") @@ -474,14 +538,12 @@ (defun jao-sway-zathura-org () (jao-pdf-goto-zathura-org (jao-sway-get-active-title) t)) -(defun jao-sway-send (&rest args) (apply 'jao-shell-string "wtype" args)) - (defun jao-sway-switch-layout () (sit-for 0.2) (let ((n (length (split-string (jao-shell-string "pidof zathura") " ")))) - (cond ((= n 1) (jao-sway-send "-M" "win" "b")) - ((= n 2) (jao-sway-send "-M" "win" "lv")) - ((= n 3) (jao-sway-send "-M" "win" "S"))))) + (cond ((= n 1) (jao-wayland-type "-M" "win" "b")) + ((= n 2) (jao-wayland-type "-M" "win" "lv")) + ((= n 3) (jao-wayland-type "-M" "win" "S"))))) (defun jao-sway-open-with-zathura (file page) (let ((n (file-name-nondirectory file))) @@ -489,11 +551,13 @@ (unless (= 0 (jao-swaymsg (format "[title=\"%s\"] focus" n))) (jao-shell-exec (jao-pdf-zathura-open-cmd file page ""))) ;; (jao-sway-switch-layout) - (when page (sit-for 0.2) (jao-sway-send (format "%dg" page))))) + (when page (sit-for 0.2) (jao-wayland-type (format "%dg" page))))) (defun jao-sway-set-wallpaper (f) - (jao-swaymsg (format "output * bg %s fill" f)) - (make-symbolic-link f "~/.wallpaper.sway" t)) + (make-symbolic-link f "~/.wallpaper.sway" t) + (if jao-sway-enabled + (jao-swaymsg (format "output * bg %s fill" f)) + (jao-shell-exec "swaybg -m fill -i ~/.wallpaper.sway"))) (defun jao-sway-run-or-focus (cmd &optional ws) (if (jao-shell-running-p "firefox") @@ -505,17 +569,6 @@ (interactive) (jao-sway-run-or-focus "firefox")) -(defun jao-sway-enable () - (interactive) - (defalias 'x-change-window-property #'ignore) - (when (eq 'pgtk window-system) (jao-set-transparency 85)) - (jao-themes-setup) - (jao-trisect) - (message "Welcome to sway")) - -(when jao-sway-enabled - (add-hook 'after-init-hook #'jao-sway-enable)) - ;;;; wallpaper (defvar jao-wallpaper-dir "~/.wallpapers/") @@ -538,7 +591,7 @@ (file-symlink-p current) t)))) (make-symbolic-link (expand-file-name f) current t) - (if jao-sway-enabled + (if jao-wayland-enabled (jao-sway-set-wallpaper (expand-file-name f)) (shell-command (format "xwallpaper --zoom %s" f)))))) @@ -576,7 +629,7 @@ (defun jao-lock-screen () (interactive) - (if jao-sway-enabled + (if jao-wayland-enabled (shell-command "swaylock -i ~/.lockimage") (jao-xlock-screen))) @@ -1588,10 +1641,10 @@ (let ((url (or (car url) (jao-url-around-point)))) (if (not url) (message "No URL at point") - (when (and (jao-exwm-enabled-p) (fboundp 'jao-exwm-firefox)) - (jao-exwm-firefox)) - (when (and jao-sway-enabled (fboundp 'jao-sway-firefox)) - (jao-sway-firefox)) + (cond ((and (jao-exwm-enabled-p) (fboundp 'jao-exwm-firefox)) + (jao-exwm-firefox)) + (jao-river-enabled (jao-river-to-ws 2)) + (jao-sway-enabled (jao-sway-firefox))) (browse-url-generic url)))) (setq jao-browse-url-external-function 'jao-browse-with-external-browser) @@ -1814,6 +1867,7 @@ (jao-afio--goto-docs) (if b (pop-to-buffer b) (find-file file)) (when page (jao-doc-view-goto-page page height)))) + (jao-river-enabled (jao-river-open-with-zathura file page)) (jao-sway-enabled (jao-sway-open-with-zathura file page)) (t (jao-zathura-open file page)))) @@ -3261,7 +3315,7 @@ (package-list-packages)) (defun jao-window-system-p () - (or jao-exwm-enabled jao-xmonad-enabled jao-sway-enabled)) + (or jao-exwm-enabled jao-xmonad-enabled jao-wayland-enabled)) (defun jao-reveal () (interactive) -- cgit v1.2.3