From 36d320348eeeb9c952c35e37910c8990fee6db5a Mon Sep 17 00:00:00 2001 From: Spencer Janssen Date: Mon, 24 Sep 2007 11:06:06 +0200 Subject: Split float up darcs-hash:20070924090606-a5988-b94b64e5deabad4a02cf8510b5113e0bb5617714.gz --- Operations.hs | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'Operations.hs') diff --git a/Operations.hs b/Operations.hs index 2a52e2d..f2a6be7 100644 --- a/Operations.hs +++ b/Operations.hs @@ -451,24 +451,22 @@ initColor dpy c = (color_pixel . fst) `liftM` allocNamedColor dpy colormap c ------------------------------------------------------------------------ -- | Floating layer support --- | Make a tiled window floating, using its suggested rectangle -float :: Window -> X () -float w = withDisplay $ \d -> do +-- | Given a window, find the screen it is located on, and compute +-- the geometry of that window wrt. that screen. +floatLocation :: Window -> X (ScreenId, W.RationalRect) +floatLocation w = withDisplay $ \d -> do ws <- gets windowset wa <- io $ getWindowAttributes d w - let sc = fromMaybe (W.current ws) $ find (pointWithin (fi $ wa_x wa) (fi $ wa_y wa) . screenRect . W.screenDetail) $ W.current ws : W.visible ws + let sc = fromMaybe (W.current ws) $ find (pointWithin (fi $ wa_x wa) (fi $ wa_y wa) . screenRect . W.screenDetail) $ W.screens ws sr = screenRect . W.screenDetail $ sc - sw = W.tag . W.workspace $ sc bw = fi . wa_border_width $ wa rr = (W.RationalRect ((fi (wa_x wa) - fi (rect_x sr)) % fi (rect_width sr)) ((fi (wa_y wa) - fi (rect_y sr)) % fi (rect_height sr)) (fi (wa_width wa + bw*2) % fi (rect_width sr)) (fi (wa_height wa + bw*2) % fi (rect_height sr))) - if maybe False (`elem` (map W.tag . W.hidden $ ws)) (W.findIndex w ws) - then windows $ W.float w rr - else windows $ maybe id W.focusWindow (W.peek ws) . W.shiftWin sw w . W.float w rr + return (W.screen $ sc, rr) where fi x = fromIntegral x pointWithin :: Integer -> Integer -> Rectangle -> Bool pointWithin x y r = x >= fi (rect_x r) && @@ -476,6 +474,17 @@ float w = withDisplay $ \d -> do y >= fi (rect_y r) && y < fi (rect_y r) + fi (rect_height r) +-- | Make a tiled window floating, using its suggested rectangle +float :: Window -> X () +float w = do + (sc, rr) <- floatLocation w + windows $ \ws -> W.float w rr . fromMaybe ws $ do + i <- W.findIndex w ws + guard $ i `elem` map (W.tag . W.workspace) (W.screens ws) + f <- W.peek ws + sw <- W.lookupWorkspace sc ws + return (W.focusWindow f . W.shiftWin sw w $ ws) + -- --------------------------------------------------------------------- -- Mouse handling -- cgit v1.2.3