This repository has been archived by the owner on May 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
frame-workflow-exwm.el
91 lines (74 loc) · 3.45 KB
/
frame-workflow-exwm.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
;;; frame-workflow-exwm.el --- Integrate frame-workflow with EXWM -*- lexical-binding: t -*-
;; Copyright (C) 2018 by Akira Komamura
;; Author: Akira Komamura <akira.komamura@gmail.com>
;; Package-Version: 0.1
;; Package-Requires: ((emacs "25.1") (exwm "0.18"))
;; Keywords: frames unix
;; URL: https://github.com/akirak/frame-workflow
;; This file is not part of GNU Emacs.
;;; License:
;; 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 <http://www.gnu.org/licenses/>.
;;; Commentary:
;; This library provides utilities to integrate frame-workflow with EXWM.
;;; Code:
(require 'exwm-workspace)
(require 'cl-lib)
(defun frame-workflow-exwm--visible-workspace-index-alist ()
"Get an alist of visible EXWM workspaces."
(cl-loop for i from 0 to (1- (exwm-workspace--count))
for frm = (exwm-workspace--workspace-from-frame-or-index i)
when (exwm-workspace--active-p frm)
collect (cons i frm)))
(defun frame-workflow-exwm--format-with-index (index frame)
"Return a string of INDEX:FRAME."
(let ((name (frame-parameter frame 'workflow-prototype)))
(concat (int-to-string index)
(if name
(concat ":" (symbol-name name))
""))))
(defun frame-workflow-exwm--2-combinations (list)
"Return all combinations from LIST."
(cl-loop for (i . r) on list by 'cdr
append (cl-loop for j in r
collect (list i j))))
(defun frame-workflow-exwm--select-two-visible-workspaces ()
"Select two visible workspaces."
(pcase (frame-workflow-exwm--visible-workspace-index-alist)
;; Only one workspace: Do nothing
(`(,_) nil)
;; Two workspaces
(`((,_ . ,w1) (,_ . ,w2)) (list w1 w2))
;; More than two workspaces: Select two via completing-read
(wss (let* ((selections (frame-workflow-exwm--2-combinations wss))
(candidates (cl-loop for ((i1 . w1) (i2 . w2)) in selections
collect (cons (concat (frame-workflow-exwm--format-with-index i1 w1)
" <-> "
(frame-workflow-exwm--format-with-index i2 w2))
(cons w1 w2))))
(result (completing-read "Workspaces to swap: " candidates nil t)))
(pcase (cdr (assoc result candidates))
(`(,w1 . ,w2) (list w1 w2)))))))
;;;###autoload
(defun frame-workflow-exwm-swap-workspaces (w1 w2)
"Swap two workspaces.
W1 and W2 are frames.
If this function is called interactively, the user can select two workspaces
from visible workspaces."
(interactive (or (frame-workflow-exwm--select-two-visible-workspaces)
'(nil nil)))
(if (and (framep w1) (framep w2))
(exwm-workspace-swap w1 w2)
(message "There is only one visible frame.")))
(provide 'frame-workflow-exwm)
;;; frame-workflow-exwm.el ends here