-
Notifications
You must be signed in to change notification settings - Fork 2
/
qutebrowser-doom-modeline.el
149 lines (123 loc) · 5.11 KB
/
qutebrowser-doom-modeline.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
139
140
141
142
143
144
145
146
147
148
149
;;; qutebrowser-doom-modeline.el --- Doom modeline for Qutebrowser -*- lexical-binding: t; -*-
;; Copyright (C) 2024 Lars Rustand.
;; 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, write to the Free Software
;; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
;;; Commentary:
;; Special doom-modeline for Qutebrowser buffers, displaying window
;; title, favicon, and URL. Meant to be used instead of the statusbar
;; in Qutebrowser.
;; Install:
;; 1. Remove Qutebrowser statusbar by setting:
;; 'c.statusbar.show = "never"'
;; in your config.py.
;;
;; 2. Enable the modeline:
;; (global-qutebrowser-doom-modeline-mode 1)
;;; Change Log:
;;; Code:
(require 'qutebrowser)
(require 'doom-modeline)
(defface qutebrowser-doom-rpc-unconnected
'((t (:inherit doom-modeline-urgent)))
"Face for the RPC not connected warning."
:group 'qutebrowser-faces)
(defsubst qutebrowser-doom--favicon ()
"Qutebrowser favicon."
(propertize ""
'display (or qutebrowser-exwm-favicon "")
'face '(:inherit doom-modeline)))
(defsubst qutebrowser-doom--title ()
"Qutebrowser title."
(propertize "%b"
'face (doom-modeline-face 'doom-modeline-buffer-file)
'mouse-face 'doom-modeline-highlight
'help-echo "Qutebrowser title
mouse-1: Previous buffer\nmouse-3: Next buffer"
'local-map mode-line-buffer-identification-keymap))
(defsubst qutebrowser-doom--url ()
"Qutebrowser visited or hovered URL."
(let ((url (or qutebrowser-exwm-hovered-url qutebrowser-exwm-current-url ""))
(face (if qutebrowser-exwm-hovered-url 'link-visited 'success)))
;; Avoid formatting nonsense
(string-replace "%" "%%" (propertize url 'face (doom-modeline-face face)))))
(defsubst qutebrowser-doom--rpc-status ()
"Qutebrowser RPC connection status."
(unless (qutebrowser-rpc-connected-p)
(let ((face (doom-modeline-face
'qutebrowser-doom-rpc-unconnected)))
(propertize "Not connected to RPC." 'face face))))
(doom-modeline-def-segment qutebrowser-rpc
"Display the RPC connection status."
(qutebrowser-doom--rpc-status))
(doom-modeline-def-segment qutebrowser-url
"Display the currently visited or hovered URL."
(concat
(doom-modeline-spc)
(qutebrowser-doom--url)))
(doom-modeline-def-segment qutebrowser-status
"Display combined status info."
(concat
(doom-modeline-spc)
(or
(qutebrowser-doom--rpc-status)
(qutebrowser-doom--url))))
(doom-modeline-def-segment qutebrowser-title
"Qutebrowser favicon and title."
(concat
(doom-modeline-vspc)
(qutebrowser-doom--favicon)
(doom-modeline-vspc)
(qutebrowser-doom--title)))
(doom-modeline-def-modeline 'qutebrowser-doom-modeline
'(bar workspace-name window-number modals qutebrowser-title)
'(qutebrowser-status))
(defun qutebrowser-doom-modeline--update (&rest _)
"Update the Doom modeline.
Simple wrapper around `force-mode-line-update' to ignore arguments when
run from `qutebrowser-on-<SIGNAL>-functions'."
(force-mode-line-update))
;;;###autoload
(define-minor-mode qutebrowser-doom-modeline-mode
"Minor mode combining Qutebrowser statusbar and Doom modeline."
:lighter nil
:global nil
(if qutebrowser-doom-modeline-mode
(progn
(qutebrowser-rpc-get-connection)
(add-hook 'qutebrowser-on-url-changed-functions
#'qutebrowser-doom-modeline--update nil t)
(add-hook 'qutebrowser-on-link-hovered-functions
#'qutebrowser-doom-modeline--update nil t)
(doom-modeline-set-modeline 'qutebrowser-doom-modeline))
(progn
(unless (doom-modeline-auto-set-modeline)
(doom-modeline-set-main-modeline))
(remove-hook 'qutebrowser-on-url-changed-functions
#'qutebrowser-doom-modeline--update t)
(remove-hook 'qutebrowser-on-link-hovered-functions
#'qutebrowser-doom-modeline--update t))))
(defun qutebrowser-doom-modeline-mode-maybe-enable ()
"Enable `qutebrowser-doom-modeline-mode' if the buffer is a Qutebrowser buffer."
(when (qutebrowser-exwm-p)
(qutebrowser-doom-modeline-mode 1)))
;;;###autoload
(define-globalized-minor-mode global-qutebrowser-doom-modeline-mode
qutebrowser-doom-modeline-mode
qutebrowser-doom-modeline-mode-maybe-enable
:group 'qutebrowser
(if global-qutebrowser-doom-modeline-mode
(add-hook 'exwm-manage-finish-hook #'qutebrowser-doom-modeline-mode-maybe-enable)
(remove-hook 'exwm-manage-finish-hook #'qutebrowser-doom-modeline-mode-maybe-enable)))
(provide 'qutebrowser-doom-modeline)
;;; qutebrowser-doom-modeline.el ends here