-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdecor.el
138 lines (116 loc) · 4.52 KB
/
decor.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
;;; decor.el --- Modify visual decorations -*- lexical-binding: t; -*-
;; Copyright (C) 2024 Peter Badida
;; Author: Peter Badida <keyweeusr@gmail.com>
;; Keywords: convenience, window, decoration, distraction, xprop, xwayland
;; Version: 1.3.2
;; Package-Requires: ((emacs "24.1"))
;; Homepage: https://github.com/KeyWeeUsr/decor
;; 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 attempts to simplify removal of all frame (window) decorations
;; via two simple functions and possibly some constants later for
;; customization.
;;; Code:
(defgroup decor
nil
"Customization group for `decor-mode'."
:group 'convenience
:group 'external
:group 'frames
:group 'x)
(defcustom decor-always-check-deps
t
"Always look up binaries, libraries and other required tools."
:group 'decor
:type 'boolean)
(defcustom decor-use-frame-parameter
t
"Direct change via `frame-parameter', if compiled with decoration support."
:group 'decor
:type 'boolean)
(defun decor--check-bin (buff-name cmd)
"Check if a binary is present on the system.
Argument BUFF-NAME destination to write failure to.
Argument CMD name of the checked binary."
(when (eq (executable-find cmd) nil)
(save-window-excursion
(switch-to-buffer (get-buffer-create buff-name))
(insert (format "'%s' not found\n" cmd)))
t))
(defun decor--check-deps ()
"Check if all deps are present on the system."
(let ((buff-name "*decor deps*")
(failed nil))
;; clean first
(kill-buffer (get-buffer-create buff-name))
;; binaries
(when (or (eq window-system 'x)
(and (string= (getenv "XDG_SESSION_TYPE") "wayland")
(decor--check-bin buff-name "Xwayland")))
(dolist (item (list "xprop"))
(when (decor--check-bin buff-name item) (setq failed t))))
(if (eq failed t)
(progn
(switch-to-buffer (get-buffer-create buff-name))
(error "Some deps are missing"))
(kill-buffer (get-buffer-create buff-name)))))
(defun decor-toggle-single-frame (win-id on &optional frame)
"Toggle decorations of a single frame.
Argument WIN-ID frame's window ID.
Argument ON t/nil to enable/disable.
Optional argument FRAME reference to target frame."
(if (and frame decor-use-frame-parameter)
(set-frame-parameter frame 'undecorated (not on))
(call-process "xprop"
nil nil nil
"-id" win-id "-format" "_MOTIF_WM_HINTS" "32c"
"-set" "_MOTIF_WM_HINTS" (if (eq on t) "1" "2"))))
(defun decor-toggle-new-frame (&optional frame)
"Toggle decorations for a new FRAME via `after-make-frame-functions'."
(when frame
(decor-toggle-single-frame
(frame-parameter frame 'outer-window-id) nil frame)))
(defun decor-toggle-all-frames (on)
"Toggle decorations ON (t) or off (nil) for all Emacs frames."
(dolist (frame (frame-list))
(let ((win-id (frame-parameter frame 'outer-window-id)))
(if (or win-id decor-use-frame-parameter)
(decor-toggle-single-frame win-id on frame)
(warn "decor: Could not handle frame %s, missing outer-window-id"
frame)))))
(defun decor-all-frames-on ()
"Toggle decorations on for all Emacs frames."
(interactive)
(when (and decor-always-check-deps (not decor-use-frame-parameter))
(decor--check-deps))
(decor-toggle-all-frames t))
(defun decor-all-frames-off ()
"Toggle decorations off for all Emacs frames."
(interactive)
(when decor-always-check-deps
(decor--check-deps))
(decor-toggle-all-frames nil))
;;;###autoload
(define-minor-mode decor-mode
"Trigger custom decoration of all Emacs desktop Frames."
:global t
:group 'decor
(if decor-mode
(progn
(decor-all-frames-off)
(add-hook 'after-make-frame-functions
#'decor-toggle-new-frame))
(decor-all-frames-on)
(remove-hook 'after-make-frame-functions
#'decor-toggle-new-frame)))
(provide 'decor)
;;; decor.el ends here