xmonad / xmonad-contrib

Contributed modules for xmonad
https://xmonad.org
BSD 3-Clause "New" or "Revised" License
583 stars 274 forks source link

X.L.Hidden doesn't handle deleted windows #907

Open SheetKey opened 2 hours ago

SheetKey commented 2 hours ago

Problem Description

When a hidden window is deleted, the Window is not deleted from the HiddenWindows list. Restoring the window calls insertUp on a window id that does not correspond to a window. This inserts and focuses an empty rectangle. The rectangle cannot be deleted. While focused, it can be hidden. It cannot be manually focused; to regain focus I have to move any other windows in the workspace to a different workspace.

From what I can tell, there may not be a simple solution. It seems like X11 does not provide a way to check if a window id is valid, so we can't validate hidden window ids with X11. Since W.delete' is called, xmonad core does not keep track of the window while it is hidden, so we can't just use isClient. Perhaps hidden windows need to be handled similarly to floating windows.

Steps to Reproduce

Spawn a program, hide the window, kill the program from the terminal. Restore the hidden, but deleted window.

Configuration File

import XMonad

import XMonad.Layout.BinarySpacePartition

-- layouts modifiers
import XMonad.Layout.NoBorders (lessBorders, Ambiguity(OnlyScreenFloat))
import qualified XMonad.Layout.Hidden as H

main :: IO ()
main = do
  xmonad $
    def
    { modMask = mod4Mask
    , layoutHook = myLayout
    , terminal = "alacritty"
    , startupHook = myStartupHook
    , keys = testKeys
    }

testKeys :: XConfig Layout -> M.Map (KeyMask, KeySym) (X ())
testKeys c = mkKeymap c $
  [ ("M-<Return>", spawn $ terminal c)
  , ("M-x", spawn "rofi -show run")
  -- hide windows
  , ("M-h", withFocused H.hideWindow)
  , ("M-C-h", H.popNewestHiddenWindow)
  ]

myLayout = transformLayout $ emptyBSP ||| tallLeft
  where
    tallLeft = Tall 1 (3/100) (1/2)

transformLayout = id
  . avoidStruts
  . H.hiddenWindows
  . lessBorders OnlyScreenFloat

Checklist

xmonad --version does not work (Nixos issue?) so I don't know the version, but I'm on Nixos unstable.

TheMC47 commented 2 hours ago

Will adding an event hook that checks for DestroyWindowEvent fix the issue?

geekosaur commented 1 hour ago

It should; that's what it's there fore (after all, you can;'t do anything else with the window ID it includes).

You can validate window ID's, though, by doing what we normally avoid: calling getWindowAttributes (or in our case safeGetWindowAttributes) on it and looking for failure.