about summary refs log tree commit diff
path: root/exwm-systemtray.el
diff options
context:
space:
mode:
authorChris Feng <chris.w.feng@gmail.com>2020-02-02T00·00+0000
committerChris Feng <chris.w.feng@gmail.com>2020-02-02T00·00+0000
commit48db94f48bea1137132345abfe8256cfc6219248 (patch)
tree7e3d9621a1829d91b8ce0414593b3029a7bb3c7b /exwm-systemtray.el
parent36d2f0056eff396d115d4cbf5777221fc5bb9c4c (diff)
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.
Diffstat (limited to 'exwm-systemtray.el')
-rw-r--r--exwm-systemtray.el42
1 files changed, 39 insertions, 3 deletions
diff --git a/exwm-systemtray.el b/exwm-systemtray.el
index 3d0990ec813a..20dc5226cf6f 100644
--- a/exwm-systemtray.el
+++ b/exwm-systemtray.el
@@ -67,13 +67,44 @@ You shall use the default value if using auto-hide minibuffer."
   "Gap between icons."
   :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.
 (defconst exwm-systemtray--icon-min-size 16 "Minimum icon size.")
 
 (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--selection-owner-window nil
@@ -438,6 +469,7 @@ You shall use the default value if using auto-hide minibuffer."
                        :data xcb:systemtray:ORIENTATION:HORZ)))
   ;; Create the embedder.
   (let ((id (xcb:generate-id exwm-systemtray--connection))
+        (background-pixel (exwm--color->pixel exwm-systemtray-background-color))
         frame parent depth y)
     (setq exwm-systemtray--embedder-window id)
     (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
                        :class xcb:WindowClass:InputOutput
                        :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-pixel background-pixel
                        :event-mask xcb:EventMask:SubstructureNotify))
     ;; Set _NET_WM_NAME.
     (xcb:+request exwm-systemtray--connection