about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJames Ferguson <wjcferguson@gmail.com>2018-12-03T16·25-0500
committerJames Ferguson <wjcferguson@gmail.com>2018-12-05T13·21-0500
commite6892216a6851307c822a71841ad2dc986facb77 (patch)
treea0911d95fdf3ad36919c9c839c99eeb276298cd5
parent58f7916619d11a8a4ad5d0bb926e7281054dd964 (diff)
Only call exwm-randr-screen-change-hook on new event sequence number
Multiple event callbacks are triggered per physical monitor plug event.
This de-duplicates the events triggering the running of the hook.
-rw-r--r--exwm-randr.el11
1 files changed, 9 insertions, 2 deletions
diff --git a/exwm-randr.el b/exwm-randr.el
index a0fe959a7c49..59b291261f6c 100644
--- a/exwm-randr.el
+++ b/exwm-randr.el
@@ -95,6 +95,8 @@ corresponding monitors whenever the monitors are active.
 
 (defvar exwm-workspace--fullscreen-frame-count)
 (defvar exwm-workspace--list)
+(defvar exwm-randr--prev-screen-change-seqnum nil
+  "The most recent ScreenChangeNotify sequence number.")
 (declare-function exwm-workspace--count "exwm-workspace.el")
 (declare-function exwm-workspace--set-active "exwm-workspace.el"
                   (frame active))
@@ -193,12 +195,17 @@ corresponding monitors whenever the monitors are active.
 (define-obsolete-function-alias 'exwm-randr--refresh #'exwm-randr-refresh
   "27.1")
 
-(defun exwm-randr--on-ScreenChangeNotify (_data _synthetic)
+(defun exwm-randr--on-ScreenChangeNotify (data _synthetic)
   "Handle `ScreenChangeNotify' event.
 
 Run `exwm-randr-screen-change-hook' (usually user scripts to configure RandR)."
   (exwm--log)
-  (run-hooks 'exwm-randr-screen-change-hook))
+  (let ((evt (make-instance 'xcb:randr:ScreenChangeNotify)))
+    (xcb:unmarshal evt data)
+    (let ((seqnum (slot-value evt '~sequence)))
+      (unless (equal seqnum exwm-randr--prev-screen-change-seqnum)
+        (setq exwm-randr--prev-screen-change-seqnum seqnum)
+        (run-hooks 'exwm-randr-screen-change-hook)))))
 
 (defun exwm-randr--on-Notify (data _synthetic)
   "Handle `CrtcChangeNotify' and `OutputChangeNotify' events.