From 11e0d683af31b1a79d2585cf814a9912377753cd Mon Sep 17 00:00:00 2001 From: Kurnevsky Evgeny Date: Tue, 8 Dec 2015 23:42:21 +0300 Subject: [PATCH 1/3] UpdatePointer bugfix. --- XMonad/Actions/UpdatePointer.hs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/XMonad/Actions/UpdatePointer.hs b/XMonad/Actions/UpdatePointer.hs index 8dbf5b61..4a218505 100644 --- a/XMonad/Actions/UpdatePointer.hs +++ b/XMonad/Actions/UpdatePointer.hs @@ -1,7 +1,7 @@ ----------------------------------------------------------------------------- -- | -- Module : XMonadContrib.UpdatePointer --- Copyright : (c) Robert Marlow +-- Copyright : (c) Robert Marlow , 2015 Evgeny Kurnevsky -- License : BSD3-style (see LICENSE) -- -- Maintainer : Robert Marlow @@ -28,6 +28,7 @@ import Control.Arrow import Control.Monad import XMonad.StackSet (member, peek, screenDetail, current) import Data.Maybe +import qualified Foreign as Foreign (peek, alloca) -- $usage -- You can use this module with the following in your @~\/.xmonad\/xmonad.hs@: @@ -63,9 +64,15 @@ updatePointer :: (Rational, Rational) -> (Rational, Rational) -> X () updatePointer refPos ratio = do ws <- gets windowset dpy <- asks display + let defaultRect = screenRect $ screenDetail $ current ws rect <- case peek ws of - Nothing -> return $ (screenRect . screenDetail .current) ws - Just w -> windowAttributesToRectangle `fmap` io (getWindowAttributes dpy w) + Nothing -> return defaultRect + Just w -> do -- We can't use just getWindowAttributes here bacause + -- the window might be closed. + maybeAttributes <- io $ getWindowAttributesMaybe dpy w + return $ case maybeAttributes of + Nothing -> defaultRect + Just attributes -> windowAttributesToRectangle attributes root <- asks theRoot mouseIsMoving <- asks mouseFocused (_sameRoot,_,currentWindow,rootX,rootY,_,_,_) <- io $ queryPointer dpy root @@ -89,6 +96,13 @@ updatePointer refPos ratio = do (round . clip boundsX $ fi rootX) (round . clip boundsY $ fi rootY) +getWindowAttributesMaybe :: Display -> Window -> IO (Maybe WindowAttributes) +getWindowAttributesMaybe d w = Foreign.alloca $ \p -> do + status <- xGetWindowAttributes d w p + if status /= 0 + then fmap Just $ Foreign.peek p + else return Nothing + windowAttributesToRectangle :: WindowAttributes -> Rectangle windowAttributesToRectangle wa = Rectangle (fi (wa_x wa)) (fi (wa_y wa)) From 86280c50637810b10c1595d98fc6aa7d668c697b Mon Sep 17 00:00:00 2001 From: Kurnevsky Evgeny Date: Wed, 30 Dec 2015 12:07:33 +0300 Subject: [PATCH 2/3] Rewrite XMonad.Actions.UpdatePointer bugfix with Control.Exception.try. --- XMonad/Actions/UpdatePointer.hs | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/XMonad/Actions/UpdatePointer.hs b/XMonad/Actions/UpdatePointer.hs index 4a218505..4293f5c4 100644 --- a/XMonad/Actions/UpdatePointer.hs +++ b/XMonad/Actions/UpdatePointer.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE ScopedTypeVariables #-} ----------------------------------------------------------------------------- -- | -- Module : XMonadContrib.UpdatePointer @@ -28,7 +29,7 @@ import Control.Arrow import Control.Monad import XMonad.StackSet (member, peek, screenDetail, current) import Data.Maybe -import qualified Foreign as Foreign (peek, alloca) +import Control.Exception -- $usage -- You can use this module with the following in your @~\/.xmonad\/xmonad.hs@: @@ -67,12 +68,10 @@ updatePointer refPos ratio = do let defaultRect = screenRect $ screenDetail $ current ws rect <- case peek ws of Nothing -> return defaultRect - Just w -> do -- We can't use just getWindowAttributes here bacause - -- the window might be closed. - maybeAttributes <- io $ getWindowAttributesMaybe dpy w - return $ case maybeAttributes of - Nothing -> defaultRect - Just attributes -> windowAttributesToRectangle attributes + Just w -> do tryAttributes <- io $ try $ getWindowAttributes dpy w + return $ case tryAttributes of + Left (_ :: SomeException) -> defaultRect + Right attributes -> windowAttributesToRectangle attributes root <- asks theRoot mouseIsMoving <- asks mouseFocused (_sameRoot,_,currentWindow,rootX,rootY,_,_,_) <- io $ queryPointer dpy root @@ -96,13 +95,6 @@ updatePointer refPos ratio = do (round . clip boundsX $ fi rootX) (round . clip boundsY $ fi rootY) -getWindowAttributesMaybe :: Display -> Window -> IO (Maybe WindowAttributes) -getWindowAttributesMaybe d w = Foreign.alloca $ \p -> do - status <- xGetWindowAttributes d w p - if status /= 0 - then fmap Just $ Foreign.peek p - else return Nothing - windowAttributesToRectangle :: WindowAttributes -> Rectangle windowAttributesToRectangle wa = Rectangle (fi (wa_x wa)) (fi (wa_y wa)) From a8d290b83071a035d61d4a5dfab5cfb4483347e8 Mon Sep 17 00:00:00 2001 From: Kurnevsky Evgeny Date: Wed, 14 Dec 2016 11:49:28 +0300 Subject: [PATCH 3/3] Update CHANGES.md --- CHANGES.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index a5aa3731..259ae8e2 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -67,6 +67,10 @@ - Fix `raiseNextMaybe` cycling between 2 workspaces only. + * `XMonad.Actions.UpdatePointer` + + - Fix bug when cursor gets stuck in one of the corners. + ## 0.12 (December 14, 2015)