summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorjao <jao@gnu.org>2022-09-07 05:49:01 +0100
committerjao <jao@gnu.org>2022-09-07 05:49:01 +0100
commit8c6838311257cd90217801953ad8e4846384ef5e (patch)
treedc562bec05b22fdcc55d6ac9d60467b52232704f
parent0986db35bb51d5b3426a0aad9467bd3b1765358d (diff)
downloadelibs-8c6838311257cd90217801953ad8e4846384ef5e.tar.gz
elibs-8c6838311257cd90217801953ad8e4846384ef5e.tar.bz2
jao-wayland factored out
-rw-r--r--init.el132
-rw-r--r--lib/eos/jao-wayland.el148
2 files changed, 155 insertions, 125 deletions
diff --git a/init.el b/init.el
index de13c05..6c295f0 100644
--- a/init.el
+++ b/init.el
@@ -454,84 +454,16 @@
(add-hook 'after-init-hook #'jao-xmonad-enable t))
;;;; wayland
-(defvar jao-wayland-enabled
- (string= "wayland" (or (getenv "XDG_SESSION_TYPE") "")))
+
+(use-package jao-wayland :demand t)
(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"))
-
-(defsubst jao-wayland-type (&rest args)
- (apply #'jao-shell-exec* t "wtype" args))
-
-;;;; river
-(defvar jao-river-enabled (jao-shell-running-p "river"))
-(defun jao-river-enabled-p () jao-river-enabled)
-
-(defsubst jao-river-to-ws (n)
- (jao-wayland-type "-M" "win" (format "%s" n)))
-
-(defsubst jao-river-window-list ()
- (jao-shell-output "lswt -j" (lambda () (let ((json-false nil)) (json-read)))))
-
-(defun jao-river-focused ()
- (seq-some (lambda (w) (and (alist-get 'activated w) w))
- (jao-river-window-list)))
-
-(defsubst jao-river-get-focused-title ()
- (alist-get 'title (jao-river-focused)))
-
-(defun jao-river-focus-window (title &optional rx)
- (let* ((ws (jao-river-window-list))
- (fltr (if rx #'string-match-p #'string=) )
- (w (seq-find (lambda (w) (funcall fltr title (alist-get 'title w "")))
- ws)))
- (or (alist-get 'activated w)
- (seq-some (lambda (_ignored)
- (jao-shell-exec "riverctl focus-view next" t)
- (funcall fltr title (jao-river-get-focused-title)))
- (and w ws)))))
-
-(defun jao-river-zathura-to-org ()
- (let ((title (jao-river-get-focused-title)))
- (jao-river-to-ws 1)
- (jao-pdf-goto-zathura-org title t)))
-
-(defun jao-river-zathura-kill-link ()
- (when-let* ((title (jao-river-get-focused-title))
- (lnk (jao-pdf-zathura-org-link title)))
- (jao-river-to-ws 1)
- (kill-new lnk)
- (message "Link to %s killed" title)))
-
-(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* "riverctl" "spawn" (jao-pdf-zathura-open-cmd file page)))
- (when page (sit-for 0.2) (jao-wayland-type (format "%dg" page)))))
-
-(defun jao-river-set-wallpaper (f)
- (jao-shell-exec (concat "swaybg -m fill -i " f " &")))
-
-(defun jao-river-restart-i3bar ()
(interactive)
- (jao-shell-kill-p "i3bar-river")
- (jao-shell-exec "riverctl spawn i3bar-river")
- (sit-for 0.2)
- (jao-tracking-set-log ""))
+ (defalias 'x-change-window-property #'ignore)
+ (when (eq 'pgtk window-system) (jao-set-transparency 85))
+ (jao-themes-setup)
+ (jao-trisect)
+ (message "Welcome to wayland"))
(defun jao-river-enable ()
(jao-wayland-enable)
@@ -539,59 +471,9 @@
(jao-tracking-set-log ""))
(message "Welcome to river"))
-(defun jao-river-toggle-emacs ()
- (if (member (jao-river-get-focused-title) '("emacsclient" "emacs"))
- (jao-shell-exec "riverctl focus-previous-tags")
- (jao-river-to-ws 1)
- (unless (jao-river-focus-window "^emacs\\(client\\)?" t)
- (jao-shell-exec* "riverctl" "spawn" "efoot"))))
-
(when jao-river-enabled
(add-hook 'after-init-hook #'jao-river-enable))
-;;;; sway
-(defun jao-sway-msg (msg)
- (shell-command (format "swaymsg '%s' >/dev/null" msg)))
-
-(defmacro jao-def-swaymsg (name msg)
- `(defun ,(intern (format "jao-sway-%s" name)) ()
- (interactive)
- (jao-sway-msg ,msg)))
-
-(jao-def-swaymsg firefox "[app_id=Firefox] focus")
-
-(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'")
-
-(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-zathura-org ()
- (jao-pdf-goto-zathura-org (jao-sway-get-active-title) t))
-
-(defun jao-sway-open-with-zathura (file page)
- (let ((n (file-name-nondirectory file)))
- (jao-sway-msg "workspace number 3")
- (unless (= 0 (jao-sway-msg (format "[title=\"%s\"] focus" n)))
- (jao-shell-exec (jao-pdf-zathura-open-cmd file page)))
- (when page (sit-for 0.2) (jao-wayland-type (format "%dg" page)))))
-
-(defun jao-sway-set-wallpaper (f)
- (jao-sway-msg (format "output * bg %s fill" f)))
-
-(defun jao-sway-run-or-focus (cmd &optional ws)
- (if (jao-shell-running-p "firefox")
- (jao-sway-msg (format "[app_id=%s] focus" cmd))
- (jao-sway-msg (format "workspace %s" (or ws 2)))
- (start-process-shell-command cmd nil cmd)))
-
-(defun jao-sway-run-or-focus-firefox ()
- (interactive)
- (jao-sway-run-or-focus "firefox"))
-
(when jao-sway-enabled
(add-hook 'after-init-hook #'jao-wayland-enable))
diff --git a/lib/eos/jao-wayland.el b/lib/eos/jao-wayland.el
new file mode 100644
index 0000000..8de32cc
--- /dev/null
+++ b/lib/eos/jao-wayland.el
@@ -0,0 +1,148 @@
+;;; jao-wayland.el --- interacting with wayland compositors -*- lexical-binding: t; -*-
+
+;; Copyright (C) 2022 jao
+
+;; Author: jao <mail@jao.io>
+;; Keywords: convenience
+
+;; This program is free software; you can redistribute it and/or modify
+;; it under the terms of the GNU General Public License as published by
+;; the Free Software Foundation, either version 3 of the License, or
+;; (at your option) any later version.
+
+;; This program is distributed in the hope that it will be useful,
+;; but WITHOUT ANY WARRANTY; without even the implied warranty of
+;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+;; GNU General Public License for more details.
+
+;; You should have received a copy of the GNU General Public License
+;; along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+(require 'jao-shell)
+(require 'jao-pdf)
+(require 'jao-tracking)
+
+;;; wayland
+(defvar jao-wayland-enabled
+ (string= "wayland" (or (getenv "XDG_SESSION_TYPE") "")))
+
+(defsubst jao-wayland-type (&rest args)
+ (apply #'jao-shell-exec* t "wtype" args))
+
+;;; river
+(defvar jao-river-enabled (jao-shell-running-p "river"))
+(defun jao-river-enabled-p () jao-river-enabled)
+
+(defsubst jao-river-to-ws (n)
+ (jao-wayland-type "-M" "win" (format "%s" n)))
+
+(defsubst jao-river-window-list ()
+ (jao-shell-output "lswt -j" (lambda () (let ((json-false nil)) (json-read)))))
+
+(defun jao-river-focused ()
+ (seq-some (lambda (w) (and (alist-get 'activated w) w))
+ (jao-river-window-list)))
+
+(defsubst jao-river-get-focused-title ()
+ (alist-get 'title (jao-river-focused)))
+
+(defun jao-river-focus-window (title &optional rx)
+ (let* ((ws (jao-river-window-list))
+ (fltr (if rx #'string-match-p #'string=) )
+ (w (seq-find (lambda (w) (funcall fltr title (alist-get 'title w "")))
+ ws)))
+ (or (alist-get 'activated w)
+ (seq-some (lambda (_ignored)
+ (jao-shell-exec "riverctl focus-view next" t)
+ (funcall fltr title (jao-river-get-focused-title)))
+ (and w ws)))))
+
+(defun jao-river-zathura-to-org ()
+ (let ((title (jao-river-get-focused-title)))
+ (jao-river-to-ws 1)
+ (jao-pdf-goto-zathura-org title t)))
+
+(defun jao-river-zathura-kill-link ()
+ (when-let* ((title (jao-river-get-focused-title))
+ (lnk (jao-pdf-zathura-org-link title)))
+ (jao-river-to-ws 1)
+ (kill-new lnk)
+ (message "Link to %s killed" title)))
+
+(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* "riverctl" "spawn" (jao-pdf-zathura-open-cmd file page)))
+ (when page (sit-for 0.2) (jao-wayland-type (format "%dg" page)))))
+
+(defun jao-river-set-wallpaper (f)
+ (jao-shell-exec (concat "swaybg -m fill -i " f " &")))
+
+(defun jao-river-restart-i3bar ()
+ (interactive)
+ (jao-shell-kill-p "i3bar-river")
+ (jao-shell-exec "riverctl spawn i3bar-river")
+ (sit-for 0.2)
+ (jao-tracking-set-log ""))
+
+(defun jao-river-toggle-emacs ()
+ (if (member (jao-river-get-focused-title) '("emacsclient" "emacs"))
+ (jao-shell-exec "riverctl focus-previous-tags")
+ (jao-river-to-ws 1)
+ (unless (jao-river-focus-window "^emacs\\(client\\)?" t)
+ (jao-shell-exec* "riverctl" "spawn" "efoot"))))
+
+;;; sway
+(defun jao-sway-msg (msg)
+ (shell-command (format "swaymsg '%s' >/dev/null" msg)))
+
+(defmacro jao-def-swaymsg (name msg)
+ `(defun ,(intern (format "jao-sway-%s" name)) ()
+ (interactive)
+ (jao-sway-msg ,msg)))
+
+(jao-def-swaymsg firefox "[app_id=Firefox] focus")
+
+(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'")
+
+(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-zathura-org ()
+ (jao-pdf-goto-zathura-org (jao-sway-get-active-title) t))
+
+(defun jao-sway-open-with-zathura (file page)
+ (let ((n (file-name-nondirectory file)))
+ (jao-sway-msg "workspace number 3")
+ (unless (= 0 (jao-sway-msg (format "[title=\"%s\"] focus" n)))
+ (jao-shell-exec (jao-pdf-zathura-open-cmd file page)))
+ (when page (sit-for 0.2) (jao-wayland-type (format "%dg" page)))))
+
+(defun jao-sway-set-wallpaper (f)
+ (jao-sway-msg (format "output * bg %s fill" f)))
+
+(defun jao-sway-run-or-focus (cmd &optional ws)
+ (if (jao-shell-running-p "firefox")
+ (jao-sway-msg (format "[app_id=%s] focus" cmd))
+ (jao-sway-msg (format "workspace %s" (or ws 2)))
+ (start-process-shell-command cmd nil cmd)))
+
+(defun jao-sway-run-or-focus-firefox ()
+ (interactive)
+ (jao-sway-run-or-focus "firefox"))
+
+(provide 'jao-wayland)
+;;; jao-wayland.el ends here