Xmonad: when floating a window, move or resize it
Asked Answered
K

2

12

I prefer to use the keyboard to float or sink windows. Unfortunately, when floated, windows aren't moved or resized, so there is little visual indication that they aren't still tiled. Ideally, upon shifting to the float layer, I'd have them move to the center of the screen and/or resize.

The best solution would work together with the function below (or something similar), which I call with a keybind -- I'd like floating via mouse click to still work normally.

toggleFloat = withFocused (\windowId -> do
                              { floats <- gets (W.floating . windowset);
                                if windowId `M.member` floats
                                then withFocused $ windows . W.sink
                                else float windowId })

(Code stolen, I still have no grasp of Haskell :c)

Edit: the keysMoveWindowTo stuff in the modified code below can actually just replace "float windowId", which it makes superfluous.

Keiko answered 6/2, 2012 at 8:24 Comment(0)
S
8

I suppose you've xmonad-contrib package installed. Then you should take a look at XMonad.Actions.FloatKeys

I guess modified function will be:

...
import XMonad.Actions.FloatKeys
...

toggleFloat = withFocused (\windowId -> do
                              { floats <- gets (W.floating . windowset);
                                if windowId `M.member` floats
                                then withFocused $ windows . W.sink
                                else do
                                     keysMoveWindowTo (x, y) (gx1, gy1) windowId
                                     keysResizeWindow (dx, dy) (gx2, gy2) windowId
                              }
                          ) 

where x,y,dx,dy,gx1,gy1,gx2,gy2 are your settings.
Operator % mentioned in docs is from Data.Ratio; a % b means rational number with numerator a and denominator b. You have to import if you want to use it:

import Data.Ratio ((%))
Shermy answered 6/2, 2012 at 9:24 Comment(3)
Haha 30 minutes ago I overcame my inexplicable, masochistic refusal to even consider adding yet more contrib stuff in my xmonad.hs, found FloatKeys right away, fiddled around for a minute and rushed back here to say N/M N/M GUYS. But there will be no dignity salvaged ... on StackOverflow.comKeiko
I was trying to do this and discovered that windows auto-float when you do keysMoveWindow or keysResize window. So I just have keybindings for those, plus sinkFocused = withFocused $ windows . W.sink for sinking them again.Corposant
Thanks, I'll update answer later today, didn't try without float back then.Shermy
M
5

Float window with mod+left dragging, resize it with mod+right dragging.

Marlborough answered 18/11, 2020 at 1:10 Comment(1)
How do you undo it?Jaret

© 2022 - 2024 — McMap. All rights reserved.