From e6892216a6851307c822a71841ad2dc986facb77 Mon Sep 17 00:00:00 2001 From: James Ferguson Date: Mon, 3 Dec 2018 11:25:11 -0500 Subject: 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. --- exwm-randr.el | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'exwm-randr.el') 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. -- cgit 1.4.1