{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses, ViewPatterns #-}
module XMonad.Layout.WindowSwitcherDecoration
(
windowSwitcherDecoration,
windowSwitcherDecorationWithButtons,
windowSwitcherDecorationWithImageButtons,
WindowSwitcherDecoration, ImageWindowSwitcherDecoration,
) where
import XMonad
import XMonad.Layout.Decoration
import XMonad.Layout.DecorationAddons
import XMonad.Layout.ImageButtonDecoration
import XMonad.Layout.DraggingVisualizer
import qualified XMonad.StackSet as S
import XMonad.Prelude
import Foreign.C.Types(CInt)
windowSwitcherDecoration :: (Eq a, Shrinker s) => s -> Theme
-> l a -> ModifiedLayout (Decoration WindowSwitcherDecoration s) l a
windowSwitcherDecoration :: forall a s (l :: * -> *).
(Eq a, Shrinker s) =>
s
-> Theme
-> l a
-> ModifiedLayout (Decoration WindowSwitcherDecoration s) l a
windowSwitcherDecoration s
s Theme
c = s
-> Theme
-> WindowSwitcherDecoration a
-> l a
-> ModifiedLayout (Decoration WindowSwitcherDecoration s) l a
forall (ds :: * -> *) a s (l :: * -> *).
(DecorationStyle ds a, Shrinker s) =>
s -> Theme -> ds a -> l a -> ModifiedLayout (Decoration ds s) l a
decoration s
s Theme
c (WindowSwitcherDecoration a
-> l a
-> ModifiedLayout (Decoration WindowSwitcherDecoration s) l a)
-> WindowSwitcherDecoration a
-> l a
-> ModifiedLayout (Decoration WindowSwitcherDecoration s) l a
forall a b. (a -> b) -> a -> b
$ Bool -> WindowSwitcherDecoration a
forall a. Bool -> WindowSwitcherDecoration a
WSD Bool
False
windowSwitcherDecorationWithButtons :: (Eq a, Shrinker s) => s -> Theme
-> l a -> ModifiedLayout (Decoration WindowSwitcherDecoration s) l a
windowSwitcherDecorationWithButtons :: forall a s (l :: * -> *).
(Eq a, Shrinker s) =>
s
-> Theme
-> l a
-> ModifiedLayout (Decoration WindowSwitcherDecoration s) l a
windowSwitcherDecorationWithButtons s
s Theme
c = s
-> Theme
-> WindowSwitcherDecoration a
-> l a
-> ModifiedLayout (Decoration WindowSwitcherDecoration s) l a
forall (ds :: * -> *) a s (l :: * -> *).
(DecorationStyle ds a, Shrinker s) =>
s -> Theme -> ds a -> l a -> ModifiedLayout (Decoration ds s) l a
decoration s
s Theme
c (WindowSwitcherDecoration a
-> l a
-> ModifiedLayout (Decoration WindowSwitcherDecoration s) l a)
-> WindowSwitcherDecoration a
-> l a
-> ModifiedLayout (Decoration WindowSwitcherDecoration s) l a
forall a b. (a -> b) -> a -> b
$ Bool -> WindowSwitcherDecoration a
forall a. Bool -> WindowSwitcherDecoration a
WSD Bool
True
newtype WindowSwitcherDecoration a = WSD Bool deriving (Int -> WindowSwitcherDecoration a -> ShowS
[WindowSwitcherDecoration a] -> ShowS
WindowSwitcherDecoration a -> String
(Int -> WindowSwitcherDecoration a -> ShowS)
-> (WindowSwitcherDecoration a -> String)
-> ([WindowSwitcherDecoration a] -> ShowS)
-> Show (WindowSwitcherDecoration a)
forall a. Int -> WindowSwitcherDecoration a -> ShowS
forall a. [WindowSwitcherDecoration a] -> ShowS
forall a. WindowSwitcherDecoration a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Int -> WindowSwitcherDecoration a -> ShowS
showsPrec :: Int -> WindowSwitcherDecoration a -> ShowS
$cshow :: forall a. WindowSwitcherDecoration a -> String
show :: WindowSwitcherDecoration a -> String
$cshowList :: forall a. [WindowSwitcherDecoration a] -> ShowS
showList :: [WindowSwitcherDecoration a] -> ShowS
Show, ReadPrec [WindowSwitcherDecoration a]
ReadPrec (WindowSwitcherDecoration a)
Int -> ReadS (WindowSwitcherDecoration a)
ReadS [WindowSwitcherDecoration a]
(Int -> ReadS (WindowSwitcherDecoration a))
-> ReadS [WindowSwitcherDecoration a]
-> ReadPrec (WindowSwitcherDecoration a)
-> ReadPrec [WindowSwitcherDecoration a]
-> Read (WindowSwitcherDecoration a)
forall a. ReadPrec [WindowSwitcherDecoration a]
forall a. ReadPrec (WindowSwitcherDecoration a)
forall a. Int -> ReadS (WindowSwitcherDecoration a)
forall a. ReadS [WindowSwitcherDecoration a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: forall a. Int -> ReadS (WindowSwitcherDecoration a)
readsPrec :: Int -> ReadS (WindowSwitcherDecoration a)
$creadList :: forall a. ReadS [WindowSwitcherDecoration a]
readList :: ReadS [WindowSwitcherDecoration a]
$creadPrec :: forall a. ReadPrec (WindowSwitcherDecoration a)
readPrec :: ReadPrec (WindowSwitcherDecoration a)
$creadListPrec :: forall a. ReadPrec [WindowSwitcherDecoration a]
readListPrec :: ReadPrec [WindowSwitcherDecoration a]
Read)
instance Eq a => DecorationStyle WindowSwitcherDecoration a where
describeDeco :: WindowSwitcherDecoration a -> String
describeDeco WindowSwitcherDecoration a
_ = String
"WindowSwitcherDeco"
decorationCatchClicksHook :: WindowSwitcherDecoration a -> Word64 -> Int -> Int -> X Bool
decorationCatchClicksHook (WSD Bool
withButtons) Word64
mainw Int
dFL Int
dFR = if Bool
withButtons
then Word64 -> Int -> Int -> X Bool
titleBarButtonHandler Word64
mainw Int
dFL Int
dFR
else Bool -> X Bool
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
decorationWhileDraggingHook :: WindowSwitcherDecoration a
-> CInt
-> CInt
-> (Word64, Rectangle)
-> Position
-> Position
-> X ()
decorationWhileDraggingHook WindowSwitcherDecoration a
_ = CInt -> CInt -> (Word64, Rectangle) -> Position -> Position -> X ()
handleTiledDraggingInProgress
decorationAfterDraggingHook :: WindowSwitcherDecoration a -> (Word64, Rectangle) -> Word64 -> X ()
decorationAfterDraggingHook WindowSwitcherDecoration a
_ (Word64
mainw, Rectangle
_) Word64
decoWin = do Word64 -> X ()
focus Word64
mainw
hasCrossed <- Word64 -> Word64 -> X Bool
handleScreenCrossing Word64
mainw Word64
decoWin
unless hasCrossed $ do sendMessage DraggingStopped
performWindowSwitching mainw
windowSwitcherDecorationWithImageButtons :: (Eq a, Shrinker s) => s -> Theme
-> l a -> ModifiedLayout (Decoration ImageWindowSwitcherDecoration s) l a
windowSwitcherDecorationWithImageButtons :: forall a s (l :: * -> *).
(Eq a, Shrinker s) =>
s
-> Theme
-> l a
-> ModifiedLayout (Decoration ImageWindowSwitcherDecoration s) l a
windowSwitcherDecorationWithImageButtons s
s Theme
c = s
-> Theme
-> ImageWindowSwitcherDecoration a
-> l a
-> ModifiedLayout (Decoration ImageWindowSwitcherDecoration s) l a
forall (ds :: * -> *) a s (l :: * -> *).
(DecorationStyle ds a, Shrinker s) =>
s -> Theme -> ds a -> l a -> ModifiedLayout (Decoration ds s) l a
decoration s
s Theme
c (ImageWindowSwitcherDecoration a
-> l a
-> ModifiedLayout (Decoration ImageWindowSwitcherDecoration s) l a)
-> ImageWindowSwitcherDecoration a
-> l a
-> ModifiedLayout (Decoration ImageWindowSwitcherDecoration s) l a
forall a b. (a -> b) -> a -> b
$ Bool -> ImageWindowSwitcherDecoration a
forall a. Bool -> ImageWindowSwitcherDecoration a
IWSD Bool
True
newtype ImageWindowSwitcherDecoration a = IWSD Bool deriving (Int -> ImageWindowSwitcherDecoration a -> ShowS
[ImageWindowSwitcherDecoration a] -> ShowS
ImageWindowSwitcherDecoration a -> String
(Int -> ImageWindowSwitcherDecoration a -> ShowS)
-> (ImageWindowSwitcherDecoration a -> String)
-> ([ImageWindowSwitcherDecoration a] -> ShowS)
-> Show (ImageWindowSwitcherDecoration a)
forall a. Int -> ImageWindowSwitcherDecoration a -> ShowS
forall a. [ImageWindowSwitcherDecoration a] -> ShowS
forall a. ImageWindowSwitcherDecoration a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Int -> ImageWindowSwitcherDecoration a -> ShowS
showsPrec :: Int -> ImageWindowSwitcherDecoration a -> ShowS
$cshow :: forall a. ImageWindowSwitcherDecoration a -> String
show :: ImageWindowSwitcherDecoration a -> String
$cshowList :: forall a. [ImageWindowSwitcherDecoration a] -> ShowS
showList :: [ImageWindowSwitcherDecoration a] -> ShowS
Show, ReadPrec [ImageWindowSwitcherDecoration a]
ReadPrec (ImageWindowSwitcherDecoration a)
Int -> ReadS (ImageWindowSwitcherDecoration a)
ReadS [ImageWindowSwitcherDecoration a]
(Int -> ReadS (ImageWindowSwitcherDecoration a))
-> ReadS [ImageWindowSwitcherDecoration a]
-> ReadPrec (ImageWindowSwitcherDecoration a)
-> ReadPrec [ImageWindowSwitcherDecoration a]
-> Read (ImageWindowSwitcherDecoration a)
forall a. ReadPrec [ImageWindowSwitcherDecoration a]
forall a. ReadPrec (ImageWindowSwitcherDecoration a)
forall a. Int -> ReadS (ImageWindowSwitcherDecoration a)
forall a. ReadS [ImageWindowSwitcherDecoration a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: forall a. Int -> ReadS (ImageWindowSwitcherDecoration a)
readsPrec :: Int -> ReadS (ImageWindowSwitcherDecoration a)
$creadList :: forall a. ReadS [ImageWindowSwitcherDecoration a]
readList :: ReadS [ImageWindowSwitcherDecoration a]
$creadPrec :: forall a. ReadPrec (ImageWindowSwitcherDecoration a)
readPrec :: ReadPrec (ImageWindowSwitcherDecoration a)
$creadListPrec :: forall a. ReadPrec [ImageWindowSwitcherDecoration a]
readListPrec :: ReadPrec [ImageWindowSwitcherDecoration a]
Read)
instance Eq a => DecorationStyle ImageWindowSwitcherDecoration a where
describeDeco :: ImageWindowSwitcherDecoration a -> String
describeDeco ImageWindowSwitcherDecoration a
_ = String
"ImageWindowSwitcherDeco"
decorationCatchClicksHook :: ImageWindowSwitcherDecoration a -> Word64 -> Int -> Int -> X Bool
decorationCatchClicksHook (IWSD Bool
withButtons) Word64
mainw Int
dFL Int
dFR = if Bool
withButtons
then Word64 -> Int -> Int -> X Bool
imageTitleBarButtonHandler Word64
mainw Int
dFL Int
dFR
else Bool -> X Bool
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
decorationWhileDraggingHook :: ImageWindowSwitcherDecoration a
-> CInt
-> CInt
-> (Word64, Rectangle)
-> Position
-> Position
-> X ()
decorationWhileDraggingHook ImageWindowSwitcherDecoration a
_ = CInt -> CInt -> (Word64, Rectangle) -> Position -> Position -> X ()
handleTiledDraggingInProgress
decorationAfterDraggingHook :: ImageWindowSwitcherDecoration a
-> (Word64, Rectangle) -> Word64 -> X ()
decorationAfterDraggingHook ImageWindowSwitcherDecoration a
_ (Word64
mainw, Rectangle
_) Word64
decoWin = do Word64 -> X ()
focus Word64
mainw
hasCrossed <- Word64 -> Word64 -> X Bool
handleScreenCrossing Word64
mainw Word64
decoWin
unless hasCrossed $ do sendMessage DraggingStopped
performWindowSwitching mainw
handleTiledDraggingInProgress :: CInt -> CInt -> (Window, Rectangle) -> Position -> Position -> X ()
handleTiledDraggingInProgress :: CInt -> CInt -> (Word64, Rectangle) -> Position -> Position -> X ()
handleTiledDraggingInProgress CInt
ex CInt
ey (Word64
mainw, Rectangle
r) Position
x Position
y = do
let rect :: Rectangle
rect = Position -> Position -> Dimension -> Dimension -> Rectangle
Rectangle (Position
x Position -> Position -> Position
forall a. Num a => a -> a -> a
- (CInt -> Position
forall a b. (Integral a, Num b) => a -> b
fi CInt
ex Position -> Position -> Position
forall a. Num a => a -> a -> a
- Rectangle -> Position
rect_x Rectangle
r))
(Position
y Position -> Position -> Position
forall a. Num a => a -> a -> a
- (CInt -> Position
forall a b. (Integral a, Num b) => a -> b
fi CInt
ey Position -> Position -> Position
forall a. Num a => a -> a -> a
- Rectangle -> Position
rect_y Rectangle
r))
(Rectangle -> Dimension
rect_width Rectangle
r)
(Rectangle -> Dimension
rect_height Rectangle
r)
DraggingVisualizerMsg -> X ()
forall a. Message a => a -> X ()
sendMessage (DraggingVisualizerMsg -> X ()) -> DraggingVisualizerMsg -> X ()
forall a b. (a -> b) -> a -> b
$ Word64 -> Rectangle -> DraggingVisualizerMsg
DraggingWindow Word64
mainw Rectangle
rect
performWindowSwitching :: Window -> X ()
performWindowSwitching :: Word64 -> X ()
performWindowSwitching Word64
win =
(Display -> X ()) -> X ()
forall a. (Display -> X a) -> X a
withDisplay ((Display -> X ()) -> X ()) -> (Display -> X ()) -> X ()
forall a b. (a -> b) -> a -> b
$ \Display
d -> do
root <- (XConf -> Word64) -> X Word64
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks XConf -> Word64
theRoot
(_, _, selWin, _, _, _, _, _) <- io $ queryPointer d root
ws <- gets windowset
let allWindows = StackSet String (Layout Word64) Word64 ScreenId ScreenDetail
-> [Word64]
forall i l a s sd. StackSet i l a s sd -> [a]
S.index StackSet String (Layout Word64) Word64 ScreenId ScreenDetail
ws
when ((win `elem` allWindows) && (selWin `elem` allWindows)) $ do
let allWindowsSwitched = (Word64 -> Word64) -> [Word64] -> [Word64]
forall a b. (a -> b) -> [a] -> [b]
map (Word64 -> Word64 -> Word64 -> Word64
forall {a}. Eq a => a -> a -> a -> a
switchEntries Word64
win Word64
selWin) [Word64]
allWindows
let (ls, notEmpty -> t :| rs) = break (win ==) allWindowsSwitched
let newStack = Word64 -> [Word64] -> [Word64] -> Stack Word64
forall a. a -> [a] -> [a] -> Stack a
S.Stack Word64
t ([Word64] -> [Word64]
forall a. [a] -> [a]
reverse [Word64]
ls) [Word64]
rs
windows $ S.modify' $ const newStack
where
switchEntries :: a -> a -> a -> a
switchEntries a
a a
b a
x
| a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
a = a
b
| a
x a -> a -> Bool
forall a. Eq a => a -> a -> Bool
== a
b = a
a
| Bool
otherwise = a
x