Add solid background support to systemtray

* exwm-systemtray.el (exwm-systemtray-background-color): New user
option for configuring systemtray background color.
(exwm-systemtray--init): Configure background color for systemtray.
This commit is contained in:
Chris Feng 2020-02-02 00:00:00 +00:00
parent 36d2f0056e
commit 48db94f48b

View file

@ -67,13 +67,44 @@ You shall use the default value if using auto-hide minibuffer."
"Gap between icons." "Gap between icons."
:type 'integer) :type 'integer)
(defvar exwm-systemtray--embedder-window nil "The embedder window.")
(defcustom exwm-systemtray-background-color nil
"Background color of systemtray.
This should be a color, or nil for transparent background."
:type '(choice (const :tag "Transparent" nil)
(color))
:initialize #'custom-initialize-default
:set (lambda (symbol value)
(set-default symbol value)
;; Change the background color for embedder.
(when (and exwm--connection
exwm-systemtray--embedder-window)
(let ((background-pixel (exwm--color->pixel value)))
(xcb:+request exwm--connection
(make-instance 'xcb:ChangeWindowAttributes
:window exwm-systemtray--embedder-window
:value-mask (logior xcb:CW:BackPixmap
(if background-pixel
xcb:CW:BackPixel 0))
:background-pixmap
xcb:BackPixmap:ParentRelative
:background-pixel background-pixel))
;; Unmap & map to take effect immediately.
(xcb:+request exwm--connection
(make-instance 'xcb:UnmapWindow
:window exwm-systemtray--embedder-window))
(xcb:+request exwm--connection
(make-instance 'xcb:MapWindow
:window exwm-systemtray--embedder-window))
(xcb:flush exwm--connection)))))
;; GTK icons require at least 16 pixels to show normally. ;; GTK icons require at least 16 pixels to show normally.
(defconst exwm-systemtray--icon-min-size 16 "Minimum icon size.") (defconst exwm-systemtray--icon-min-size 16 "Minimum icon size.")
(defvar exwm-systemtray--connection nil "The X connection.") (defvar exwm-systemtray--connection nil "The X connection.")
(defvar exwm-systemtray--embedder-window nil "The embedder window.")
(defvar exwm-systemtray--list nil "The icon list.") (defvar exwm-systemtray--list nil "The icon list.")
(defvar exwm-systemtray--selection-owner-window nil (defvar exwm-systemtray--selection-owner-window nil
@ -438,6 +469,7 @@ You shall use the default value if using auto-hide minibuffer."
:data xcb:systemtray:ORIENTATION:HORZ))) :data xcb:systemtray:ORIENTATION:HORZ)))
;; Create the embedder. ;; Create the embedder.
(let ((id (xcb:generate-id exwm-systemtray--connection)) (let ((id (xcb:generate-id exwm-systemtray--connection))
(background-pixel (exwm--color->pixel exwm-systemtray-background-color))
frame parent depth y) frame parent depth y)
(setq exwm-systemtray--embedder-window id) (setq exwm-systemtray--embedder-window id)
(if (exwm-workspace--minibuffer-own-frame-p) (if (exwm-workspace--minibuffer-own-frame-p)
@ -473,8 +505,12 @@ You shall use the default value if using auto-hide minibuffer."
:border-width 0 :border-width 0
:class xcb:WindowClass:InputOutput :class xcb:WindowClass:InputOutput
:visual 0 :visual 0
:value-mask (logior xcb:CW:BackPixmap xcb:CW:EventMask) :value-mask (logior xcb:CW:BackPixmap
(if background-pixel
xcb:CW:BackPixel 0)
xcb:CW:EventMask)
:background-pixmap xcb:BackPixmap:ParentRelative :background-pixmap xcb:BackPixmap:ParentRelative
:background-pixel background-pixel
:event-mask xcb:EventMask:SubstructureNotify)) :event-mask xcb:EventMask:SubstructureNotify))
;; Set _NET_WM_NAME. ;; Set _NET_WM_NAME.
(xcb:+request exwm-systemtray--connection (xcb:+request exwm-systemtray--connection