XM.A.UpdatePointer interferes with XM.A.TiledWindowDragging?

Dear All, When I use XMonad.Actions.UpdatePointer, window dragging no longer works. If I do not use XM.A.UpdatePointer, window dragging works. Details: These are (what I think are) the relevant pieces from my xmonad.hs: (...) import XMonad.Actions.UpdatePointer import XMonad.Actions.TiledWindowDragging import XMonad.Layout.DraggingVisualizer (...) myConfig myWorkspaces = def { (...) , logHook = refocusLastLogHook <+> logHook def >> updatePointer (0.5, 0.5) (0.1, 0.1) } `additionalKeysP` myKeys2 `additionalMouseBindings` [((mod4Mask, 2), dragWindow)] --drag with mod + center button With the above, window dragging no longer works. However, if I comment out ">> updatePointer (0.5, 0.5) (0.1, 0.1)" window dragging works again. Am I doing something wrong? I've searched, and have not seen this mentioned (TiledWindowDragging is mentioned in relation to UpdatePointer here: https://github.com/xmonad/xmonad-contrib/issues/566#issuecomment-869240906, but it seemed a different issue) I am using xmonad and xmonad-contrib, both from master branches, updated as of today (2023-03-24): latest commits are 386d4e and e60805b for xmonad and xmonad-contrib, respectively. Best, -- Ramon Diaz-Uriarte Department of Biochemistry, Lab B-31 Facultad de Medicina Universidad Autónoma de Madrid Arzobispo Morcillo, 4 28029 Madrid Spain Phone: +34-91-497-2412 Email: rdiaz02@gmail.com r.diaz@uam.es ramon.diaz@iib.uam.es https://ligarto.org/rdiaz

I think that would not be surprising; we needed to update xmonad's
internal state, including running the `logHook`, during drags to avoid
other bugs. (https://github.com/xmonad/xmonad/commit/4565e2c90ef522d23d3afc2cf95b9f0b423d...)
Not sure what to do about this.
On Fri, Mar 24, 2023 at 8:32 AM Ramon Diaz-Uriarte
Dear All,
When I use XMonad.Actions.UpdatePointer, window dragging no longer works. If I do not use XM.A.UpdatePointer, window dragging works.
Details:
These are (what I think are) the relevant pieces from my xmonad.hs:
(...) import XMonad.Actions.UpdatePointer import XMonad.Actions.TiledWindowDragging import XMonad.Layout.DraggingVisualizer
(...)
myConfig myWorkspaces = def { (...) , logHook = refocusLastLogHook <+> logHook def >> updatePointer (0.5, 0.5) (0.1, 0.1) } `additionalKeysP` myKeys2 `additionalMouseBindings` [((mod4Mask, 2), dragWindow)] --drag with mod + center button
With the above, window dragging no longer works. However, if I comment out ">> updatePointer (0.5, 0.5) (0.1, 0.1)" window dragging works again.
Am I doing something wrong? I've searched, and have not seen this mentioned (TiledWindowDragging is mentioned in relation to UpdatePointer here: https://github.com/xmonad/xmonad-contrib/issues/566#issuecomment-869240906, but it seemed a different issue)
I am using xmonad and xmonad-contrib, both from master branches, updated as of today (2023-03-24): latest commits are 386d4e and e60805b for xmonad and xmonad-contrib, respectively.
Best,
-- Ramon Diaz-Uriarte Department of Biochemistry, Lab B-31 Facultad de Medicina Universidad Autónoma de Madrid Arzobispo Morcillo, 4 28029 Madrid Spain
Phone: +34-91-497-2412
Email: rdiaz02@gmail.com r.diaz@uam.es ramon.diaz@iib.uam.es
_______________________________________________ xmonad mailing list xmonad@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/xmonad
-- brandon s allbery kf8nh allbery.b@gmail.com

Hi! Seems the issue is that the pointer is warped back to the initial dragged window position before TiledWindowDragging updates the focused window, and thus no window switching is happening (because from the point of view of TiledWindowDragging the window was never dragged anywhere). As Brandon said, logHook is called on every internal state update, so UpdatePointer tries to update the pointer all the time, even in-between drag end and focus change. `updatePointer` contains some guards that are trying to detect common scenarios and prevent updating in such cases, but as we see it doesn't work perfectly. I suppose `updatePointer` should run only when it explicitly detects the window focus change event, instead of running all the time (maybe some manageHook wrapper?). That said, I found a (quite hacky) way to achieve what you want without rewriting UpdatePointer. The idea is to make a variable that stores if the drag is currently happening, and disable `updatePointer` while this variable is true: ``` -- necessary imports import XMonad.Prelude import Data.IORef (IORef, newIORef, readIORef, writeIORef) import System.IO.Unsafe import XMonad.Actions.AfterDrag -- the hacky code updatePointerEnabled :: IORef Bool updatePointerEnabled = unsafePerformIO (newIORef True) enableUpdatePointer :: X () enableUpdatePointer = io $ writeIORef updatePointerEnabled True disableUpdatePointer :: X () disableUpdatePointer = io $ writeIORef updatePointerEnabled False dragWindowMod :: Window -> X () dragWindowMod w = do disableUpdatePointer dragWindow w afterDrag $ do enableUpdatePointer updatePointerMod refPos ratio = do enabled <- io $ readIORef updatePointerEnabled when enabled $ do updatePointer refPos ratio -- use dragWindowMod and updatePointerMod instead of original functions ``` -- Best regards, Platon Pronko PGP 2A62D77A7A2CB94E On 2023-03-24 22:04, Brandon Allbery wrote:
I think that would not be surprising; we needed to update xmonad's internal state, including running the `logHook`, during drags to avoid other bugs. (https://github.com/xmonad/xmonad/commit/4565e2c90ef522d23d3afc2cf95b9f0b423d...) Not sure what to do about this.
On Fri, Mar 24, 2023 at 8:32 AM Ramon Diaz-Uriarte
wrote: Dear All,
When I use XMonad.Actions.UpdatePointer, window dragging no longer works. If I do not use XM.A.UpdatePointer, window dragging works.
Details:
These are (what I think are) the relevant pieces from my xmonad.hs:
(...) import XMonad.Actions.UpdatePointer import XMonad.Actions.TiledWindowDragging import XMonad.Layout.DraggingVisualizer
(...)
myConfig myWorkspaces = def { (...) , logHook = refocusLastLogHook <+> logHook def >> updatePointer (0.5, 0.5) (0.1, 0.1) } `additionalKeysP` myKeys2 `additionalMouseBindings` [((mod4Mask, 2), dragWindow)] --drag with mod + center button
With the above, window dragging no longer works. However, if I comment out ">> updatePointer (0.5, 0.5) (0.1, 0.1)" window dragging works again.
Am I doing something wrong? I've searched, and have not seen this mentioned (TiledWindowDragging is mentioned in relation to UpdatePointer here: https://github.com/xmonad/xmonad-contrib/issues/566#issuecomment-869240906, but it seemed a different issue)
I am using xmonad and xmonad-contrib, both from master branches, updated as of today (2023-03-24): latest commits are 386d4e and e60805b for xmonad and xmonad-contrib, respectively.
Best,
-- Ramon Diaz-Uriarte Department of Biochemistry, Lab B-31 Facultad de Medicina Universidad Autónoma de Madrid Arzobispo Morcillo, 4 28029 Madrid Spain
Phone: +34-91-497-2412
Email: rdiaz02@gmail.com r.diaz@uam.es ramon.diaz@iib.uam.es
_______________________________________________ xmonad mailing list xmonad@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/xmonad

Thanks a lot! This works perfectly.
For completeness, I noticed some corner cases if I enable focusFollowsMouse = False . Suppose the following:
- Two windows: Firefox and Emacs.
- Emacs has two buffers with different names
If the focused window is Firefox, and I move the mouse over Emacs, as soon as I cross to the other buffer in Emacs, the mouse pointer jumps back to Firefox.
Now, however, this might not be very relevant as I don't see why I would use updatePointer with focusFollowsMouse = False.
Thanks again,
R.
On Fri, 24-March-2023, at 15:23:41, Platon Pronko
Hi!
Seems the issue is that the pointer is warped back to the initial dragged window position before TiledWindowDragging updates the focused window, and thus no window switching is happening (because from the point of view of TiledWindowDragging the window was never dragged anywhere).
As Brandon said, logHook is called on every internal state update, so UpdatePointer tries to update the pointer all the time, even in-between drag end and focus change. `updatePointer` contains some guards that are trying to detect common scenarios and prevent updating in such cases, but as we see it doesn't work perfectly.
I suppose `updatePointer` should run only when it explicitly detects the window focus change event, instead of running all the time (maybe some manageHook wrapper?).
That said, I found a (quite hacky) way to achieve what you want without rewriting UpdatePointer. The idea is to make a variable that stores if the drag is currently happening, and disable `updatePointer` while this variable is true:
``` -- necessary imports import XMonad.Prelude import Data.IORef (IORef, newIORef, readIORef, writeIORef) import System.IO.Unsafe import XMonad.Actions.AfterDrag
-- the hacky code updatePointerEnabled :: IORef Bool updatePointerEnabled = unsafePerformIO (newIORef True) enableUpdatePointer :: X () enableUpdatePointer = io $ writeIORef updatePointerEnabled True disableUpdatePointer :: X () disableUpdatePointer = io $ writeIORef updatePointerEnabled False dragWindowMod :: Window -> X () dragWindowMod w = do disableUpdatePointer dragWindow w afterDrag $ do enableUpdatePointer updatePointerMod refPos ratio = do enabled <- io $ readIORef updatePointerEnabled when enabled $ do updatePointer refPos ratio
-- use dragWindowMod and updatePointerMod instead of original functions ```
-- Ramon Diaz-Uriarte Department of Biochemistry, Lab B-31 Facultad de Medicina Universidad Autónoma de Madrid Arzobispo Morcillo, 4 28029 Madrid Spain Phone: +34-91-497-2412 Email: rdiaz02@gmail.com r.diaz@uam.es ramon.diaz@iib.uam.es https://ligarto.org/rdiaz
participants (3)
-
Brandon Allbery
-
Platon Pronko
-
Ramon Diaz-Uriarte