From ed3922aed913f8f42da3965fd130b3a23f7a49f0 Mon Sep 17 00:00:00 2001 From: jao Date: Sun, 28 Aug 2022 20:52:40 +0100 Subject: browsing docs with zathura in sway --- init.el | 78 ++++++++++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 51 insertions(+), 27 deletions(-) diff --git a/init.el b/init.el index 123ab66..9952379 100644 --- a/init.el +++ b/init.el @@ -251,6 +251,9 @@ (pdf-view-mode "application/pdf" (display-graphic-p)) ("zathura \"%s\"" "application/pdf") (image-mode "image/*" (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/*"))))) ;;; Crypto ;;;; PGP, EPG, passwords @@ -455,8 +458,26 @@ (jao-swaymsg ,msg))) (jao-def-swaymsg firefox "[app_id=firefox] focus") -(defvar jao-sway-enabled - (and (eq window-system 'pgtk) (not jao-xmonad-enabled))) +(defvar jao-sway-enabled (and (featurep 'pgtk) (not jao-xmonad-enabled))) + +(defconst jao-sway-get-active-title + "swaymsg -t get_tree | jq '.. | select(.type?) | select(.focused==true).name'") + +(defun jao-sway-get-active-title () + (let ((tl (jao-shell-string jao-sway-get-active-title))) + (and (string-match "\"\\(.+\\)\"" tl) (match-string 1 tl)))) + +(defun jao-sway-send (txt) (jao-shell-string "wtype" txt)) + +(defun jao-zathura--open-cmd (file page &optional suffix) + (format "zathura %s -P %s%s" file (or page 1) (or suffix ""))) + +(defun jao-sway-open-with-zathura (file page) + (let* ((a (jao-zathura--open-cmd file page "")) + (n (file-name-nondirectory file)) + (c (format "swaymsg [title=\"%s\"] focus || %s" n a))) + (jao-shell-exec c) + (when page (jao-sway-send (format "%dg" page))))) (defun jao-sway-set-wallpaper (f) (jao-swaymsg (format "output * bg %s fill" f)) @@ -472,7 +493,9 @@ (interactive) (if (jao-shell-running-p "tidal-hifi") (jao-swaymsg "[app_id=tidal-hifi] scratchpad show") - (start-process-shell-command "tidal-hifi" nil "tidal-hifi &") + (let ((c + "tidal-hifi --enable-features=UseOzonePlatform --ozone-platform=wayland &")) + (start-process-shell-command "tidal-hifi" nil c)) (jao-sway-run-or-focus-tidal))) (defun jao-sway-run-or-focus-firefox () @@ -480,18 +503,15 @@ (jao-sway-run-or-focus "firefox")) (defun jao-sway-enable () - (setq jao-browse-doc-use-emacs-p t) - (setq jao-wallpaper-random-wake nil) - (jao-trisect) + (interactive) + (defalias 'x-change-window-property #'ignore) + (setq jao-sway-enabled t) (jao-set-transparency 85) (jao-themes-setup) - (xmobar-mode) - (global-set-key (kbd "s-f") #'jao-sway-run-or-focus-firefox) - (defalias 'jao-streaming-list #'jao-sway-run-or-focus-tidal) + (jao-trisect) (message "Welcome to sway")) (when jao-sway-enabled - (defalias 'x-change-window-property #'ignore) (add-hook 'after-init-hook #'jao-sway-enable)) ;;;; wallpaper @@ -1771,10 +1791,13 @@ (string-to-number (match-string 4 title)) (match-string 2 title)))) -(defun jao-zathura-goto-org (&optional title) - (when-let* ((title (or title (jao-shell-string "xdotool" - "getactivewindow" - "getwindowname"))) +(defun jao-zathura-goto-org (&optional title no-ask) + (when-let* ((title (or title + (and jao-sway-enabled + (jao-sway-get-active-title)) + (jao-shell-string "xdotool" + "getactivewindow" + "getwindowname"))) (info (jao-zathura-file-info title)) (file (jao-org-pdf-to-org-file (car info))) (page (cadr info)) @@ -1785,7 +1808,7 @@ (lnk (format "[[doc:%s::%d][Page %s]]" fn page pageno))) (find-file file) (unless exists (jao-org-insert-doc-skeleton)) - (if (or (not exists) (y-or-n-p "Insert link?")) + (if (or (not exists) no-ask (y-or-n-p "Insert link?")) (insert lnk "\n") (kill-new lnk) (message "Link to %s (%s) killed" file page))))) @@ -1797,7 +1820,7 @@ (progn (when jao-xmonad-enabled (jao-shell-exec "xdotool set_destktop 2")) - (jao-shell-exec (format "zathura %s -P %s" file (or page 1)))) + (jao-shell-string (jao-zathura--open-cmd file page " &"))) (let* ((page (if page (format " && xdotool type %dg" page) "")) (cmd (format "xdotool windowactivate %s%s" id page))) (jao-shell-string cmd))))) @@ -1812,17 +1835,18 @@ (setq jao-org-open-pdf-fun 'jao-find-or-open) (defun jao-find-or-open (file &optional page height) - (if (and jao-browse-doc-use-emacs-p window-system) - (let* ((buffs (buffer-list)) - (b (catch 'done - (while buffs - (when (string-equal (buffer-file-name (car buffs)) file) - (throw 'done (car buffs))) - (setq buffs (cdr buffs)))))) - (jao-afio--goto-docs) - (if b (pop-to-buffer b) (find-file file)) - (when page (jao-doc-view-goto-page page height))) - (jao-zathura-open file page))) + (cond ((and jao-browse-doc-use-emacs-p window-system) + (let* ((buffs (buffer-list)) + (b (catch 'done + (while buffs + (when (string-equal (buffer-file-name (car buffs)) file) + (throw 'done (car buffs))) + (setq buffs (cdr buffs)))))) + (jao-afio--goto-docs) + (if b (pop-to-buffer b) (find-file file)) + (when page (jao-doc-view-goto-page page height)))) + (jao-sway-enabled (jao-sway-open-with-zathura file page)) + (t (jao-zathura-open file page)))) (defun jao-open-doc (&optional file page height) (interactive) -- cgit v1.2.3