From 048994c7948528630b5c13f56dd22a9b2972e09c Mon Sep 17 00:00:00 2001 From: Chris Feng Date: Mon, 10 Aug 2015 14:23:37 +0800 Subject: Remove redundant code caused by the concurrency of events (continued) Remove `exwm--with-current-id`, which was introduced to as a wrapper to `with-current-buffer` to do extra checks. Note that in functions run as hooks, the validation of window ID is still required as they are not synchronized with events. --- exwm-input.el | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) (limited to 'exwm-input.el') diff --git a/exwm-input.el b/exwm-input.el index 97dfd53e36..24aa94abda 100644 --- a/exwm-input.el +++ b/exwm-input.el @@ -56,7 +56,7 @@ It's updated in several occasions, and only used by `exwm-input--set-focus'.") (defun exwm-input--set-focus (id) "Set input focus to window ID in a proper way." - (exwm--with-current-id id + (with-current-buffer (exwm--id->buffer id) (exwm--log "Set focus ID to #x%x" id) (setq exwm-input--focus-id id) (if (and (not exwm--hints-input) @@ -105,21 +105,24 @@ It's updated in several occasions, and only used by `exwm-input--set-focus'.") exwm--floating-frame) (x-focus-frame exwm--floating-frame))) ;; Finally focus the window - (exwm-input--set-focus exwm-input--focus-id)) - (exwm--with-current-id exwm-input--focus-id - (exwm--log "Set focus ID to #x%x" xcb:Window:None) - (setq exwm-input--focus-id xcb:Window:None) - (let ((frame (selected-frame))) - (if exwm--floating-frame - (unless (or (eq frame exwm--floating-frame) - (active-minibuffer-window)) - ;; Redirect input focus to the workspace frame - (exwm--log "Redirect input focus (%s => %s)" - exwm--floating-frame frame) - (redirect-frame-focus exwm--floating-frame frame)) - ;; Focus the workspace frame - (exwm--log "Focus on workspace %s" frame) - (x-focus-frame frame)))))) + (when (exwm--id->buffer exwm-input--focus-id) + (exwm-input--set-focus exwm-input--focus-id))) + (let ((buffer (exwm--id->buffer exwm-input--focus-id))) + (when buffer + (with-current-buffer buffer + (exwm--log "Set focus ID to #x%x" xcb:Window:None) + (setq exwm-input--focus-id xcb:Window:None) + (let ((frame (selected-frame))) + (if exwm--floating-frame + (unless (or (eq frame exwm--floating-frame) + (active-minibuffer-window)) + ;; Redirect input focus to the workspace frame + (exwm--log "Redirect input focus (%s => %s)" + exwm--floating-frame frame) + (redirect-frame-focus exwm--floating-frame frame)) + ;; Focus the workspace frame + (exwm--log "Focus on workspace %s" frame) + (x-focus-frame frame)))))))) (setq exwm-input--focus-lock nil))) (defun exwm-input--finish-key-sequence () @@ -163,7 +166,7 @@ It's updated in several occasions, and only used by `exwm-input--set-focus'.") (t ;; Click to focus (unless (and (boundp 'exwm--id) (= event exwm--id)) - (exwm--with-current-id event + (with-current-buffer (exwm--id->buffer event) (select-frame-set-input-focus (or exwm--floating-frame exwm--frame)) (select-window (get-buffer-window nil 'visible)))) -- cgit 1.4.1