From f1b6eb338204ffc08b068337bc8c7245462de736 Mon Sep 17 00:00:00 2001 From: Philip Date: Fri, 28 Aug 2015 13:43:54 +0000 Subject: [PATCH] Warp mouse pointer only when necessary. Remove last call to `exwm--make-emacs-idle-for'. Remove `exwm--make-emacs-idle-for'. Should close https://github.com/ch11ng/exwm/issues/39. --- exwm-floating.el | 2 +- exwm-input.el | 5 ++--- exwm-workspace.el | 44 +++++++++++++++++++++++++++----------------- exwm.el | 4 ---- 4 files changed, 30 insertions(+), 25 deletions(-) diff --git a/exwm-floating.el b/exwm-floating.el index 0b4f327..b900164 100644 --- a/exwm-floating.el +++ b/exwm-floating.el @@ -258,7 +258,7 @@ (with-slots (root-x root-y win-x win-y) (xcb:+request-unchecked+reply exwm--connection (make-instance 'xcb:QueryPointer :window id)) - (select-frame-set-input-focus frame) ;raise and focus it + (exwm-workspace--select-frame frame) (setq width (frame-pixel-width frame) height (frame-pixel-height frame)) (unless type diff --git a/exwm-input.el b/exwm-input.el index eb53b41..294cd20 100644 --- a/exwm-input.el +++ b/exwm-input.el @@ -117,13 +117,12 @@ It's updated in several occasions, and only used by `exwm-input--set-focus'.") (progn (when exwm--floating-frame (redirect-frame-focus exwm--floating-frame nil) - (select-frame-set-input-focus exwm--floating-frame t)) + (exwm-workspace--select-frame exwm--floating-frame t)) (exwm--log "Set focus on #x%x" exwm--id) (exwm-input--set-focus exwm--id)) (when (eq (selected-window) exwm-input--focus-window) (exwm--log "Focus on %s" exwm-input--focus-window) - (select-frame-set-input-focus (window-frame exwm-input--focus-window) - t) + (exwm-workspace--select-frame (window-frame exwm-input--focus-window) t) (dolist (pair exwm--id-buffer-alist) (with-current-buffer (cdr pair) (when (and exwm--floating-frame diff --git a/exwm-workspace.el b/exwm-workspace.el index f4e1dd1..da592a4 100644 --- a/exwm-workspace.el +++ b/exwm-workspace.el @@ -88,10 +88,32 @@ (defvar exwm-workspace--current nil "Current active workspace.") (defvar exwm-workspace-current-index 0 "Index of current active workspace.") -(defun exwm-workspace-switch (index &optional force) +(defun exwm-workspace--select-frame (frame &optional norecord) + ;; Move mouse when necessary + (let* ((position (mouse-pixel-position)) + (x (+ (cadr position) (car (frame-position (car position))))) + (y (+ (cddr position) (cdr (frame-position (car position))))) + (edges (frame-edges frame))) + (if (or (not (memq frame exwm-workspace--list)) + (and x + (>= x (nth 0 edges)) + (> (nth 2 edges) x) + (>= y (nth 1 edges)) + (> (nth 3 edges) y))) + (progn (select-frame frame) + (raise-frame frame) + (x-focus-frame frame)) + (select-frame-set-input-focus frame norecord) + (when (or (>= x (nth 2 edges)) (>= y (nth 3 edges))) + (setq x (/ (- (nth 2 edges) (nth 0 edges)) 2) + y (/ (- (nth 3 edges) (nth 1 edges)) 2)) + (set-mouse-pixel-position frame x y))))) + +(defun exwm-workspace-switch (index &optional force selected) "Switch to workspace INDEX. Query for INDEX if it's not specified. -The optional FORCE option is for internal use only." +The optional FORCE option is for internal use only. The optional +SELECTED option indicates that the frame is already selected." (interactive (list (unless (and (eq major-mode 'exwm-mode) exwm--fullscreen) ;it's invisible @@ -110,19 +132,8 @@ The optional FORCE option is for internal use only." (let ((frame (elt exwm-workspace--list index))) (setq exwm-workspace--current frame exwm-workspace-current-index index) - (select-frame-set-input-focus frame) - ;; Move mouse when necessary - (let ((position (mouse-pixel-position)) - x y w h) - (unless (eq frame (car position)) - (setq x (cadr position) - y (cddr position) - w (frame-pixel-width frame) - h (frame-pixel-height frame)) - (when (or (> x w) (> y h)) - (setq x (/ w 2) - y (/ h 2))) - (set-mouse-pixel-position frame x y))) + (unless selected + (exwm-workspace--select-frame frame)) (setq default-minibuffer-frame frame) ;; Hide windows in other workspaces by preprending a space (dolist (i exwm--id-buffer-alist) @@ -135,7 +146,6 @@ The optional FORCE option is for internal use only." (set-frame-parameter frame 'exwm--urgency nil) ;; Update switch workspace history (exwm-workspace--update-switch-history) - (exwm--make-emacs-idle-for 0.1) ;FIXME ;; Update _NET_CURRENT_DESKTOP (xcb:+request exwm--connection (make-instance 'xcb:ewmh:set-_NET_CURRENT_DESKTOP @@ -148,7 +158,7 @@ The optional FORCE option is for internal use only." (exwm--log "Focus on workspace %s" index) (when (and index (/= index exwm-workspace-current-index)) (exwm--log "Workspace was switched unexpectedly") - (exwm-workspace-switch index)))) + (exwm-workspace-switch index nil t)))) (defun exwm-workspace-move-window (index &optional id) "Move window ID to workspace INDEX." diff --git a/exwm.el b/exwm.el index 3b2705a..09e7b69 100644 --- a/exwm.el +++ b/exwm.el @@ -187,10 +187,6 @@ xcb:EventMask:SubstructureRedirect))) (xcb:flush exwm--connection)) -(defun exwm--make-emacs-idle-for (seconds) - "Put Emacs in idle state for SECONDS seconds." - (with-timeout (seconds) (read-event))) - (defun exwm-reset () "Reset window to standard state: non-fullscreen, line-mode." (interactive)