about summary refs log tree commit diff
path: root/exwm-floating.el
diff options
context:
space:
mode:
authorChris Feng <chris.w.feng@gmail.com>2019-09-13T00·00+0000
committerChris Feng <chris.w.feng@gmail.com>2019-09-13T00·00+0000
commit48b15e25ad9009b1135db6344de156ef4154758f (patch)
tree69d6a6c7c1a025cd87629db7d7a30abbae5847aa /exwm-floating.el
parentcb9607814f3cfcfa3c5597370edc5300c259119e (diff)
Improve user options
* exwm-floating.el (exwm-floating-border-color)
(exwm-floating-border-width): Make changes take effect w/o restart.
(exwm-floating--init-border): Refactored out from
`exwm-floating--init'.

* exwm-workspace.el (exwm-workspace-minibuffer-position): Clarify
a restart is required.
Diffstat (limited to 'exwm-floating.el')
-rw-r--r--exwm-floating.el111
1 files changed, 84 insertions, 27 deletions
diff --git a/exwm-floating.el b/exwm-floating.el
index f4557ebd575e..27ee574ad748 100644
--- a/exwm-floating.el
+++ b/exwm-floating.el
@@ -44,20 +44,70 @@ context of the corresponding buffer."
 context of the corresponding buffer."
   :type 'hook)
 
+(defvar exwm-floating--border-pixel nil
+  "Border pixel drawn around floating X windows.")
+
 (defcustom exwm-floating-border-color "navy"
   "Border color of floating windows."
-  :type 'color)
+  :type 'color
+  :initialize #'custom-initialize-default
+  :set (lambda (symbol value)
+         (set-default symbol value)
+         ;; Change border color for all floating X windows.
+         (exwm-floating--init-border)
+         (dolist (pair exwm--id-buffer-alist)
+           (with-current-buffer (cdr pair)
+             (when exwm--floating-frame
+               (xcb:+request exwm--connection
+                   (make-instance 'xcb:ChangeWindowAttributes
+                                  :window
+                                  (frame-parameter exwm--floating-frame
+                                                   'exwm-container)
+                                  :value-mask xcb:CW:BorderPixel
+                                  :border-pixel
+                                  exwm-floating--border-pixel)))))
+         (when exwm--connection
+           (xcb:flush exwm--connection))))
 
 (defcustom exwm-floating-border-width 1
   "Border width of floating windows."
-  :type 'integer)
+  :type '(integer
+          :validate (lambda (widget)
+                      (when (< (widget-value widget) 0)
+                        (widget-put widget :error "Border width is at least 0")
+                        widget)))
+  :initialize #'custom-initialize-default
+  :set (lambda (symbol value)
+         (let ((delta (- value exwm-floating-border-width))
+               container)
+           (set-default symbol value)
+           ;; Change border width for all floating X windows.
+           (dolist (pair exwm--id-buffer-alist)
+             (with-current-buffer (cdr pair)
+               (when exwm--floating-frame
+                 (setq container (frame-parameter exwm--floating-frame
+                                                  'exwm-container))
+                 (with-slots (x y)
+                     (xcb:+request-unchecked+reply exwm--connection
+                         (make-instance 'xcb:GetGeometry
+                                        :drawable container))
+                   (xcb:+request exwm--connection
+                       (make-instance 'xcb:ConfigureWindow
+                                      :window container
+                                      :value-mask
+                                      (logior xcb:ConfigWindow:X
+                                              xcb:ConfigWindow:Y
+                                              xcb:ConfigWindow:BorderWidth)
+                                      :border-width value
+                                      :x (- x delta)
+                                      :y (- y delta)))))))
+           (when exwm--connection
+             (xcb:flush exwm--connection)))))
 
 (defvar exwm-floating--border-colormap nil
   "Colormap used by the border pixel.
 
 This is also used by X window containers.")
-(defvar exwm-floating--border-pixel nil
-  "Border pixel drawn around floating X windows.")
 
 ;; Cursors for moving/resizing a window
 (defvar exwm-floating--cursor-move nil)
@@ -679,32 +729,39 @@ Both DELTA-X and DELTA-Y default to 1.  This command should be bound locally."
                           nil nil))
     (xcb:flush exwm--connection)))
 
+(defun exwm-floating--init-border ()
+  "Initialize border colormap and pixel."
+  (exwm--log)
+  ;; Use the default colormap.
+  (unless exwm-floating--border-colormap
+    (with-slots (roots) (xcb:get-setup exwm--connection)
+      (with-slots (default-colormap) (car roots)
+        (setq exwm-floating--border-colormap default-colormap))))
+  ;; Free any previously allocated pixel.
+  (when exwm-floating--border-pixel
+    (xcb:+request exwm--connection
+        (make-instance 'xcb:FreeColors
+                       :cmap exwm-floating--border-colormap
+                       :plane-mask 0
+                       :pixels (vector exwm-floating--border-pixel)))
+    (setq exwm-floating--border-pixel nil))
+  ;; Allocate new pixel.
+  (let ((color (x-color-values (or exwm-floating-border-color "")))
+         reply)
+    (when color
+      (setq reply (xcb:+request-unchecked+reply exwm--connection
+                      (make-instance 'xcb:AllocColor
+                                     :cmap exwm-floating--border-colormap
+                                     :red (pop color)
+                                     :green (pop color)
+                                     :blue (pop color))))
+      (when reply
+        (setq exwm-floating--border-pixel (slot-value reply 'pixel))))))
+
 (defun exwm-floating--init ()
   "Initialize floating module."
   (exwm--log)
-  ;; Check border width.
-  (unless (and (integerp exwm-floating-border-width)
-               (> exwm-floating-border-width 0))
-    (setq exwm-floating-border-width 0))
-  ;; Initialize border pixel.
-  (when (> exwm-floating-border-width 0)
-    (setq exwm-floating--border-colormap
-          (slot-value (car (slot-value
-                            (xcb:get-setup exwm--connection) 'roots))
-                      'default-colormap))
-    (unless (stringp exwm-floating-border-color)
-      (setq exwm-floating-border-color ""))
-    (let* ((color (x-color-values exwm-floating-border-color))
-           reply)
-      (when color
-        (setq reply (xcb:+request-unchecked+reply exwm--connection
-                        (make-instance 'xcb:AllocColor
-                                       :cmap exwm-floating--border-colormap
-                                       :red (pop color)
-                                       :green (pop color)
-                                       :blue (pop color))))
-        (when reply
-          (setq exwm-floating--border-pixel (slot-value reply 'pixel))))))
+  (exwm-floating--init-border)
   ;; Initialize cursors for moving/resizing a window
   (xcb:cursor:init exwm--connection)
   (setq exwm-floating--cursor-move