From 5e24cc2b8e3fa66e3b18c332c64fee211e08dfdc Mon Sep 17 00:00:00 2001 From: Benson Chu Date: Thu, 31 Aug 2023 16:38:00 +0800 Subject: [PATCH] Reworking loads of exwm tagging --- exwm-x/exwmx-appconfig | 32 +-- lisp/exwm-tagging/exwm-tag.el | 54 +++-- lisp/exwm-tagging/my-exwmx-quickrun-2.el | 288 +++++++++++++++++++++++ 3 files changed, 333 insertions(+), 41 deletions(-) create mode 100644 lisp/exwm-tagging/my-exwmx-quickrun-2.el diff --git a/exwm-x/exwmx-appconfig b/exwm-x/exwmx-appconfig index 27e83ec..b018374 100644 --- a/exwm-x/exwmx-appconfig +++ b/exwm-x/exwmx-appconfig @@ -1,17 +1,17 @@ -(:command "firefox" :alias "firefox" :pretty-name "firefox" :paste-key "C-v" :class "firefox" :instance "firefox" :title "Picture-in-Picture" :floating nil :size-and-position default :workspace current-workspace :add-prefix-keys nil :remove-prefix-keys nil :ignore-simulation-keys nil :eval nil :key "1ef6e3e7ca8f8d6c04a5a72cd355a8e6") -(:command "firefox2" :alias "firefox2" :pretty-name "firefox2" :paste-key "C-v" :class "Firefox" :instance "firefox2" :title "Pocket: Log In - Mozilla Firefox" :floating nil :size-and-position default :workspace current-workspace :add-prefix-keys nil :remove-prefix-keys nil :ignore-simulation-keys nil :eval nil :key "e1e4ce0c539a41461b840e5cd3d1ab94") -(:command "lutris" :alias "lutris" :pretty-name "lutris" :paste-key "C-v" :class "Lutris" :instance "lutris" :title "Lutris" :floating nil :size-and-position default :workspace current-workspace :add-prefix-keys nil :remove-prefix-keys nil :ignore-simulation-keys nil :eval nil :key "d5f5f739289cc9c6286881ecd659d2a5") -(:command "mgtv" :alias "mgtv" :pretty-name "mgtv" :paste-key "C-v" :class "mgtv" :instance "mgtv" :title "哆啦A梦第二季 第70集 - 视频在线观看 - 哆啦A梦 第二季 - 芒果TV - Mozilla Firefox" :floating nil :size-and-position default :workspace current-workspace :add-prefix-keys nil :remove-prefix-keys nil :ignore-simulation-keys nil :eval nil :key "618647de63882e1c4e7209cd22bea289") -(:command "steam" :alias "Steam" :pretty-name "Steam" :paste-key "C-v" :class "Steam" :instance "Steam" :title "Steam" :floating nil :size-and-position default :workspace current-workspace :add-prefix-keys nil :remove-prefix-keys nil :ignore-simulation-keys nil :eval nil :key "a68f5a036e9cd3dd4c8ae09a73f8d3db") -(:command "work" :alias "work" :pretty-name "work" :paste-key "C-v" :class "Firefox" :instance "work" :title "Pocket: Log In - Mozilla Firefox" :floating nil :size-and-position default :workspace current-workspace :add-prefix-keys nil :remove-prefix-keys nil :ignore-simulation-keys nil :eval nil :key "ca58c8720d794df8d0b88c6dceea8c69") -(:command "firefox" :alias "firefox" :pretty-name "firefox" :paste-key "C-v" :class "Firefox" :instance "firefox" :title "Text from Minibuffer - GNU Emacs Lisp Reference Manual - Mozilla Firefox" :floating nil :size-and-position default :workspace current-workspace :add-prefix-keys nil :remove-prefix-keys nil :ignore-simulation-keys nil :eval nil :key "b6160ae814a3ea99d1a7636d9c636519") -(:command "pcmanfm" :alias "pcmanfm" :pretty-name "pcmanfm" :paste-key "C-v" :class "Pcmanfm" :instance "pcmanfm" :title "exwm-x" :floating nil :size-and-position default :workspace current-workspace :add-prefix-keys nil :remove-prefix-keys nil :ignore-simulation-keys nil :eval nil :key "50e978cd291dcc11f145ca5835193ae1") -(:command "Navigator" :alias "Navigator" :pretty-name "Navigator" :paste-key "C-v" :class "Firefox" :instance "Navigator" :title "mkropat/jumpapp: A run-or-raise application switcher for any X11 desktop - Mozilla Firefox" :floating nil :size-and-position default :workspace current-workspace :add-prefix-keys nil :remove-prefix-keys nil :ignore-simulation-keys nil :eval nil :key "b5686ca42c47fd5dec0b9efe8739ce94") -(:command "school" :alias "school" :pretty-name "school" :paste-key "C-v" :class "Firefox" :instance "school" :title "Pocket: Log In - Mozilla Firefox" :floating nil :size-and-position default :workspace current-workspace :add-prefix-keys nil :remove-prefix-keys nil :ignore-simulation-keys nil :eval nil :key "45308901feaebc917a2ff5e74187ea33") -(:command "youtube" :alias "youtube" :pretty-name "youtube" :paste-key "C-v" :class "Firefox" :instance "youtube" :title "(4) Water & Dust Resistant PC Case - WHO NEEDS THIS?? - YouTube - Mozilla Firefox" :floating nil :size-and-position default :workspace current-workspace :add-prefix-keys nil :remove-prefix-keys nil :ignore-simulation-keys nil :eval nil :key "e63021d849994bb88d64a4d86ed1f4e6") -(:command "emacs" :alias "emacs" :pretty-name "emacs" :paste-key "C-v" :class "Emacs" :instance "emacs" :title "emacs@ArchLinuvo" :floating nil :size-and-position default :workspace current-workspace :add-prefix-keys nil :remove-prefix-keys t :ignore-simulation-keys nil :eval nil :key "d174de6e20bb093cb298146666b92ac1") -(:command "qutebrowser" :alias "qutebrowser" :pretty-name "qutebrowser" :paste-key "C-v" :class "qutebrowser" :instance "qutebrowser" :title "DuckDuckGo — Privacy, simplified. - qutebrowser" :floating nil :size-and-position default :workspace current-workspace :add-prefix-keys nil :remove-prefix-keys nil :ignore-simulation-keys nil :eval nil :key "5a90ddb8976a59d030137fc4414e2918") -(:command "VirtualBox Machine" :alias "VirtualBox Machine" :pretty-name "VirtualBox Machine" :paste-key "C-v" :class "VirtualBox Machine" :instance "VirtualBox Machine" :title "Windows 7 [Running] - Oracle VM VirtualBox" :floating nil :size-and-position default :workspace current-workspace :add-prefix-keys nil :remove-prefix-keys nil :ignore-simulation-keys nil :eval nil :key "9032cdf6364297438c1892d892122db3") +(:command "firefox" :alias "Navigator" :pretty-name "firefox3" :paste-key "C-v" :class "firefox" :instance "Navigator" :title nil :floating nil :size-and-position default :workspace current-workspace :add-prefix-keys nil :remove-prefix-keys nil :ignore-simulation-keys nil :eval nil :key "8ae6552419703180476fa4387f9cf8b9") +(:command "firefox" :alias "Navigator" :pretty-name "firefox1" :paste-key "C-v" :class "firefox" :instance "Navigator" :title nil :floating nil :size-and-position default :workspace current-workspace :add-prefix-keys nil :remove-prefix-keys nil :ignore-simulation-keys nil :eval nil :key "15f370a4572c4a0b89c8146f0c6c5ffe") +(:command firefox :alias "Navigator" :pretty-name "firefox" :paste-key "C-v" :class "firefox" :instance "Navigator" :title nil :floating nil :size-and-position default :workspace current-workspace :add-prefix-keys nil :remove-prefix-keys nil :ignore-simulation-keys nil :eval nil :key "c2bee0373d986f9561845a4e1ae0374d") +(:command "discord" :alias "discord" :pretty-name "discord" :paste-key "C-v" :class "discord" :instance "discord" :title nil :floating nil :size-and-position default :workspace current-workspace :add-prefix-keys nil :remove-prefix-keys nil :ignore-simulation-keys nil :eval nil :key "4ad4943e4fc9da6b8421dbd655ac09ec") (:command "clementine" :alias "clementine" :pretty-name "clementine" :paste-key "C-v" :class "Clementine" :instance "clementine" :title "Takeshi Abo - First leap" :floating nil :size-and-position default :workspace current-workspace :add-prefix-keys nil :remove-prefix-keys nil :ignore-simulation-keys nil :eval nil :key "6d1a0cd2fd349b32c844ad096ceaa529") -(:command "firefox1" :alias "firefox1" :pretty-name "firefox1" :paste-key "C-v" :class "Firefox" :instance "firefox1" :title "Pocket: Log In - Mozilla Firefox" :floating nil :size-and-position default :workspace current-workspace :add-prefix-keys nil :remove-prefix-keys nil :ignore-simulation-keys nil :eval nil :key "849af83f8d4b10d19178dbeccfdd99f4") -(:command "refirefox" :alias "refirefox" :pretty-name "refirefox" :paste-key "C-v" :class "firefox" :instance "refirefox" :title "search forward - Google Search - Mozilla Firefox" :floating nil :size-and-position default :workspace current-workspace :add-prefix-keys nil :remove-prefix-keys nil :ignore-simulation-keys nil :eval nil :key "f1fb4bfe8f5845f8dee8f8e6585a1076") +(:command "VirtualBox Machine" :alias "VirtualBox Machine" :pretty-name "VirtualBox Machine" :paste-key "C-v" :class "VirtualBox Machine" :instance "VirtualBox Machine" :title "Windows 7 [Running] - Oracle VM VirtualBox" :floating nil :size-and-position default :workspace current-workspace :add-prefix-keys nil :remove-prefix-keys nil :ignore-simulation-keys nil :eval nil :key "9032cdf6364297438c1892d892122db3") +(:command "qutebrowser" :alias "qutebrowser" :pretty-name "qutebrowser" :paste-key "C-v" :class "qutebrowser" :instance "qutebrowser" :title "DuckDuckGo — Privacy, simplified. - qutebrowser" :floating nil :size-and-position default :workspace current-workspace :add-prefix-keys nil :remove-prefix-keys nil :ignore-simulation-keys nil :eval nil :key "5a90ddb8976a59d030137fc4414e2918") +(:command "emacs" :alias "emacs" :pretty-name "emacs" :paste-key "C-v" :class "Emacs" :instance "emacs" :title "emacs@ArchLinuvo" :floating nil :size-and-position default :workspace current-workspace :add-prefix-keys nil :remove-prefix-keys t :ignore-simulation-keys nil :eval nil :key "d174de6e20bb093cb298146666b92ac1") +(:command "Navigator" :alias "Navigator" :pretty-name "Navigator" :paste-key "C-v" :class "Firefox" :instance "Navigator" :title "mkropat/jumpapp: A run-or-raise application switcher for any X11 desktop - Mozilla Firefox" :floating nil :size-and-position default :workspace current-workspace :add-prefix-keys nil :remove-prefix-keys nil :ignore-simulation-keys nil :eval nil :key "b5686ca42c47fd5dec0b9efe8739ce94") +(:command "work" :alias "work" :pretty-name "work" :paste-key "C-v" :class "Firefox" :instance "work" :title "Pocket: Log In - Mozilla Firefox" :floating nil :size-and-position default :workspace current-workspace :add-prefix-keys nil :remove-prefix-keys nil :ignore-simulation-keys nil :eval nil :key "ca58c8720d794df8d0b88c6dceea8c69") +(:command "steam" :alias "Steam" :pretty-name "Steam" :paste-key "C-v" :class "Steam" :instance "Steam" :title "Steam" :floating nil :size-and-position default :workspace current-workspace :add-prefix-keys nil :remove-prefix-keys nil :ignore-simulation-keys nil :eval nil :key "a68f5a036e9cd3dd4c8ae09a73f8d3db") +(:command "mgtv" :alias "mgtv" :pretty-name "mgtv" :paste-key "C-v" :class "mgtv" :instance "mgtv" :title "哆啦A梦第二季 第70集 - 视频在线观看 - 哆啦A梦 第二季 - 芒果TV - Mozilla Firefox" :floating nil :size-and-position default :workspace current-workspace :add-prefix-keys nil :remove-prefix-keys nil :ignore-simulation-keys nil :eval nil :key "618647de63882e1c4e7209cd22bea289") +(:command "lutris" :alias "lutris" :pretty-name "lutris" :paste-key "C-v" :class "Lutris" :instance "lutris" :title "Lutris" :floating nil :size-and-position default :workspace current-workspace :add-prefix-keys nil :remove-prefix-keys nil :ignore-simulation-keys nil :eval nil :key "d5f5f739289cc9c6286881ecd659d2a5") +(:command "pcmanfm" :alias nil :pretty-name "pcmanfm" :paste-key "C-v" :class "Pcmanfm" :instance "pcmanfm" :title nil :floating nil :size-and-position default :workspace current-workspace :add-prefix-keys nil :remove-prefix-keys nil :ignore-simulation-keys nil :eval nil :key "50e978cd291dcc11f145ca5835193ae1") +(:command "firefox" :alias "Navigator" :pretty-name "firefox" :paste-key "C-v" :class "firefox" :instance "Navigator" :title nil :floating nil :size-and-position default :workspace current-workspace :add-prefix-keys nil :remove-prefix-keys nil :ignore-simulation-keys nil :eval nil :key "61fd33ff3615b1e582accf4eba6ff1ee") +(:command firefox :alias "Navigator" :pretty-name "youtube" :paste-key "C-v" :class "firefox" :instance "Navigator" :title nil :floating nil :size-and-position default :workspace current-workspace :add-prefix-keys nil :remove-prefix-keys nil :ignore-simulation-keys nil :eval nil :key "c1d685634c050571eb12fba803934e74") +(:command "firefox" :alias "Navigator" :pretty-name "firefox2" :paste-key "C-v" :class "firefox" :instance "Navigator" :title nil :floating nil :size-and-position default :workspace current-workspace :add-prefix-keys nil :remove-prefix-keys nil :ignore-simulation-keys nil :eval nil :key "83cf4fcff6f07dd334aabe6207f087b0") diff --git a/lisp/exwm-tagging/exwm-tag.el b/lisp/exwm-tagging/exwm-tag.el index ece1bb6..02558e4 100644 --- a/lisp/exwm-tagging/exwm-tag.el +++ b/lisp/exwm-tagging/exwm-tag.el @@ -25,7 +25,7 @@ ;;; Code: (use-package exwm-x) (use-package hydra) -(require 'my-exwmx-quickrun) +(require 'my-exwmx-quickrun-2) (require 'exwmx-appconfig) (defun lock-screen () @@ -36,22 +36,26 @@ (interactive (list (completing-read "Name: " - (mapcar (lambda (a) (plist-get a :instance)) + (mapcar (lambda (a) (plist-get a :pretty-name)) (exwmx-appconfig--get-all-appconfigs))))) - (if (and (get-buffer name) - (not (equal (get-buffer name) (current-buffer))) - (y-or-n-p (format "Already a buffer named \"%s\". Would you like to swap?" name))) - (let ((oname (completing-read "Name of other buffer: " - (mapcar (lambda (a) (plist-get a :instance)) - (exwmx-appconfig--get-all-appconfigs))))) - (exwm-workspace-rename-buffer "This is a stupid name that no one would ever choose for a buffer, hopefully") - (with-current-buffer (get-buffer name) - (exwm-workspace-rename-buffer oname) - (setq-local exwm-instance-name oname)) - (exwm-workspace-rename-buffer name) - (setq-local exwm-instance-name name)) - (exwm-workspace-rename-buffer name) - (setq-local exwm-instance-name name))) + (cl-labels ((name-pretty (buffer name) + (with-current-buffer buffer + (exwm-workspace-rename-buffer name) + (setq-local exwmx-pretty-name name)))) + (if (equal name (buffer-name)) + (setq-local exwmx-pretty-name name) + (let ((obuffer (get-buffer name))) + (if (not obuffer) + (name-pretty (current-buffer) name) + (when (y-or-n-p (format "Already a buffer named \"%s\". Would you like to swap?" name)) + (let ((oname (completing-read "Name of other buffer: " + (mapcar (lambda (a) (plist-get a :instance)) + (exwmx-appconfig--get-all-appconfigs))))) + (name-pretty (current-buffer) + "This is a stupid name that no one would ever choose for a buffer, hopefully") + (name-pretty obuffer oname) + (name-pretty (current-buffer) + name)))))))) ;; Add these hooks in a suitable place (e.g., as done in exwm-config-default) @@ -88,15 +92,15 @@ (define-key *root-map* (kbd "f") '*firefox-map*) (define-key *firefox-map* (kbd "c") (quickrun-lambda "google-chrome-stable" "chrome")) -(define-key *firefox-map* (kbd "f") (quickrun-lambda "firefox -P default-release" "firefox")) -(define-key *firefox-map* (kbd "1") (quickrun-lambda "firefox -P default-release" "firefox1")) -(define-key *firefox-map* (kbd "2") (quickrun-lambda "firefox -P default-release" "firefox2")) -(define-key *firefox-map* (kbd "3") (quickrun-lambda "firefox -P default-release" "firefox3")) -(define-key *firefox-map* (kbd "4") (quickrun-lambda "firefox -P default-release" "firefox4")) -(define-key *firefox-map* (kbd "d") (quickrun-lambda "firefox -P default-release" "development")) -(define-key *firefox-map* (kbd "s") (quickrun-lambda "firefox -P default-release" "school")) -(define-key *firefox-map* (kbd "w") (quickrun-lambda "firefox -P default-release" "work")) -(define-key *firefox-map* (kbd "y") (quickrun-lambda "firefox -P default-release" "youtube")) +(define-key *firefox-map* (kbd "f") (quickrun-lambda "firefox" "firefox")) +(define-key *firefox-map* (kbd "1") (quickrun-lambda "firefox" "firefox1")) +(define-key *firefox-map* (kbd "2") (quickrun-lambda "firefox" "firefox2")) +(define-key *firefox-map* (kbd "3") (quickrun-lambda "firefox" "firefox3")) +(define-key *firefox-map* (kbd "4") (quickrun-lambda "firefox" "firefox4")) +(define-key *firefox-map* (kbd "d") (quickrun-lambda "firefox" "development")) +(define-key *firefox-map* (kbd "s") (quickrun-lambda "firefox" "school")) +(define-key *firefox-map* (kbd "w") (quickrun-lambda "firefox" "work")) +(define-key *firefox-map* (kbd "y") (quickrun-lambda "firefox" "youtube")) ;; Musics (define-prefix-command '*music-map*) diff --git a/lisp/exwm-tagging/my-exwmx-quickrun-2.el b/lisp/exwm-tagging/my-exwmx-quickrun-2.el new file mode 100644 index 0000000..2cfa2d3 --- /dev/null +++ b/lisp/exwm-tagging/my-exwmx-quickrun-2.el @@ -0,0 +1,288 @@ +;;; my-exwmx-quickrun-2.el --- -*- lexical-binding: t -*- + +;; Copyright (C) 2023 Benson Chu + +;; Author: Benson Chu +;; Created: [2023-08-31 14:21] + +;; This file is not part of GNU Emacs + +;; 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 . + +;;; Commentary: + +;;; Code: + +;; TODO: add buffer name to appconfig + +;; (add-hook 'exwm-update-class-hook #'exwmx-grocery--rename-exwm-buffer) +;; (add-hook 'exwm-update-title-hook #'exwmx-grocery--rename-exwm-buffer) + +;; Manage `exwm-manage-finish-hook' +;; (add-hook 'exwm-manage-finish-hook #'exwmx-grocery--manage-finish-function) + +(defun exwmx-appconfig () + "EXWM-X's application configure tool, which will pop to a buffer. +and insert an appconfig template to let user edit. then user can +use `exwmx-appconfig-file' to save the appconfig to `exwmx-appconfig-file' +or use `exwmx-appconfig-ignore' ignore." + (interactive) + (if (not (derived-mode-p 'exwm-mode)) + (message "EXWM-X: Current window is not a window of application.") + (unless (file-readable-p exwmx-appconfig-file) + (append-to-file "" nil exwmx-appconfig-file)) + (let* ((buffer (get-buffer-create exwmx-appconfig-buffer)) + (hash (md5 (concat exwm-class-name exwm-instance-name (or exwmx-pretty-name "")))) + (history (exwmx-appconfig--search + `((:key ,hash)))) + (appconfig (list :command exwm-instance-name + :alias exwm-instance-name + :pretty-name exwmx-pretty-name + :paste-key exwmx-sendstring-default-paste-key + :class exwm-class-name + :instance exwm-instance-name + :title exwm-title + :floating nil + :size-and-position 'default + :workspace 'current-workspace + :add-prefix-keys nil + :remove-prefix-keys nil + :ignore-simulation-keys nil + :eval nil))) + (while history + (let ((prop (pop history)) + (value (pop history))) + (when (keywordp prop) + (plist-put appconfig prop value)))) + (plist-put appconfig :key hash) + (with-current-buffer buffer + (text-mode) + (exwmx-appconfig-mode) + (setq truncate-lines t) + (erase-buffer) + (exwmx-appconfig--insert-plist appconfig) + (goto-char (point-min)) + (setq header-line-format + (substitute-command-keys + (concat + "\\" + "Appconfig: " + "Finish with `\\[exwmx-appconfig-finish]', " + "Ignore with `\\[exwmx-appconfig-ignore]'. ")))) + (pop-to-buffer buffer)))) + +(defun exwmx-buffer-match-p (appconfig buffer) + (cl-assert + (eq 'exwm-mode + (with-current-buffer buffer + major-mode))) + (cl-assert + (plistp appconfig)) + (let ((class (plist-get appconfig :class)) + (instance (plist-get appconfig :instance)) + (title (plist-get appconfig :title)) + (pretty (plist-get appconfig :pretty-name))) + (with-current-buffer buffer + (and + (or class instance title pretty) + (or (not class) (exwmx--string-match-p class exwm-class-name)) + (or (not instance) (exwmx--string-match-p instance exwm-instance-name)) + (or (not title) (exwmx--string-match-p instance exwm-title)) + (or (not pretty) (exwmx--string-match-p (format "^%s$" pretty) exwmx-pretty-name)))))) + +(defun exwmx-find-buffer (appconfig) + (let ((current (current-buffer)) + (buffers (buffer-list)) + (result '())) + (while buffers + (let ((buffer (pop buffers))) + (when (and (eq 'exwm-mode (with-current-buffer buffer + major-mode)) + (exwmx-buffer-match-p appconfig buffer)) + (push buffer result)))) + (setq result (reverse result)) + ;; If two more buffers are found, switch between these buffer. + (if (and (cadr result) + (eq (car result) current)) + (cadr result) + (car result)))) + +(exwmx-find-buffer '(:pretty-name "firefox")) + +(defun exwmx-select-window () + (if (= 1 (length (window-list))) + (selected-window) + (let ((index (switch-window--prompt "Run command in window: "))) + (cl-loop for c from 1 + for win in (switch-window--list) + until (= c index) + finally return win)))) + +(defun my/exwmx-quickrun (command &optional search-alias ruler) + "Run `command' to launch an application, if application's window is found, +just switch to this window, when `search-alias' is t, `command' will be regard +as an appconfig alias and search it from `exwmx-appconfig-file', by default, +:class and :instance is used to search application, user can override +it by argument `ruler', ruler can be a plist with keys: :class, :instance +and :title or just a key list." + (cl-assert (or (not ruler) (exwmx--plist-p ruler))) + (let* ((keys + ;; Deal with ruler which is like (:class :instance :title) + (or (and ruler (exwmx--clean-keylist ruler)) + '(:class :instance :pretty-name :pretty-name))) + (name (plist-get ruler :pretty-name)) + (appconfigs (exwmx-appconfig--get-all-appconfigs)) + (matched-appconfig (exwmx-appconfig--search + (if search-alias + (cons `(:alias ,command) + (and name `((:pretty-name ,name)))) + (cons `(:command ,command) + (and name `((:pretty-name ,name))))))) + (cmd (if (not search-alias) + command + (or (plist-get matched-appconfig :command) + (when appconfigs + (let ((appconfig (exwmx-appconfig--select-appconfig))) + (plist-put appconfig :alias command) + (exwmx-appconfig--add-appconfig appconfig) + (plist-get appconfig :command)))))) + (buffer (exwmx-find-buffer + (or ruler + (exwmx-appconfig--get-subset matched-appconfig keys))))) + (if (and search-alias (not cmd)) + (message "EXWM-X: please run `exwmx-appconfig' to add appconfig.") + (message "EXWM-X Quick Run: %s" cmd)) + ;; If current application window is a floating-window, minumize it. + (when (and (eq major-mode 'exwm-mode) + exwm--floating-frame) + (exwm-floating-hide)) + (if buffer + (let ((exwm-layout-show-all-buffers nil)) + (exwm-workspace-switch-to-buffer buffer)) + (when cmd + (exwmx-register-x-window + matched-appconfig (exwmx-select-window)) + (exwmx-shell-command cmd))))) + +(defmacro quickrun-lambda (cmd name) + (let ((name-gensym (intern (format "quickrun-%s" + (or name cmd))))) + `(defun ,name-gensym () + (interactive) + (my/exwmx-quickrun ,cmd nil '(:pretty-name ,name))))) + +(defun exwmx-launch-program (command &optional process-name) + (interactive (list (read-program))) + (setq dmenu--history-list (cons command (remove command dmenu--history-list))) + (when (> (length dmenu--history-list) + dmenu-history-size) + (setcdr (nthcdr (- dmenu-history-size 1) + dmenu--history-list) + nil)) + (my/exwmx-quickrun command)) + +(defmacro exec (body) + `#'(lambda () + (interactive) + ,body)) + +(defun exwmx/rename-firefox-windows () + (interactive) + (cl-labels ((rename (buffer name) + (with-current-buffer buffer + (exwm-workspace-rename-buffer name) + (setq-local exwmx-pretty-name name)))) + (let ((buffers + (remove-if-not + #'(lambda (buffer) + (with-current-buffer buffer + (and (eq 'exwm-mode major-mode) + (string-match-p "firefox" exwm-class-name)))) + (buffer-list))) + yt others) + (while buffers + (let ((buffer (pop buffers))) + (with-current-buffer buffer + (cond ((string-match-p "youtube" (downcase exwm-title)) + (setq yt buffer)) + (t (push buffer others)))))) + (when yt + (rename yt "youtube")) + (dotimes (i (length others)) + (let ((buffer (nth i others))) + (rename buffer + (if (eq 0 i) + "firefox" + (concat "firefox" (number-to-string i))))))))) + +;;------------------------------------------------------------------;; +(defvar exwmx/destination-windows (make-hash-table :test #'equal)) + +(defun exwmx-register-x-window (appconfig window) + (puthash appconfig window exwmx/destination-windows)) + +(defun exwmx-appconfig--search-all (search-ruler-alist) + (let ((appconfigs (exwmx-appconfig--get-all-appconfigs)) + appconfig-matched) + (while appconfigs + (let ((appconfig (pop appconfigs))) + (dolist (rule search-ruler-alist) + (let* ((key (nth 0 rule)) + (search-string (nth 1 rule)) + (test-function (or (nth 2 rule) #'equal)) + (prop-value (plist-get appconfig key))) + (when (and (functionp test-function) + (funcall test-function search-string prop-value)) + (push appconfig appconfig-matched)))))) + appconfig-matched)) + +(defun exwmx-appconfig-candidates () + (exwmx-appconfig--search-all + `((:class ,exwm-class-name)))) + +(defun exwmx-manage-x-window () + (if-let* ((appconfigs (exwmx-appconfig-candidates)) + (matched-config + (-any (lambda (c) (and (gethash c exwmx/destination-windows) + c)) + appconfigs)) + (name (plist-get matched-config :pretty-name)) + (window (gethash matched-config exwmx/destination-windows))) + (unwind-protect + (progn + (exwm-workspace-rename-buffer name) + (when (and (window-live-p window) + (not (eq window (selected-window)))) + (let ((curr (current-buffer))) + (save-selected-window + (previous-buffer) + (window--display-buffer curr window 'reuse nil))))) + (setq-local exwmx-pretty-name name) + (remhash matched-config exwmx/destination-windows)) + (exwm-workspace-rename-buffer + (or exwm-class-name exwm-instance-name exwm-title)))) + +(add-hook 'exwm-manage-finish-hook 'exwmx-manage-x-window) + +;;------------------------------------------------------------------;; +;; (let ((debug/appconfig (exwmx-appconfig--search `((:command "pcmanfm")))) +;; (debug/buffer (get-buffer "*EXWM*"))) +;; (cl-assert (exwmx-buffer-match-p debug/appconfig debug/buffer)) +;; (cl-assert (exwmx-buffer-match-p '(:class "Pcmanfm") debug/buffer)) +;; (cl-assert (exwmx-buffer-match-p '(:instance "pcmanfm") debug/buffer)) +;; (cl-assert (exwmx-find-buffer debug/appconfig)) +;; (cl-assert (eq debug/buffer (exwmx-find-buffer debug/appconfig)))) + +(provide 'my-exwmx-quickrun-2) +;;; my-exwmx-quickrun-2.el ends here