xmonad / xmonad

The core of xmonad, a small but functional ICCCM-compliant tiling window manager
https://xmonad.org
BSD 3-Clause "New" or "Revised" License
3.37k stars 291 forks source link

New floating windows sometimes are created partially off-screen #105

Closed donaldcallen closed 3 years ago

donaldcallen commented 7 years ago

Problem Description

New floating windows sometimes are created partially off-screen

Configuration File

Please include the smallest configuration file that reproduces the problem you are experiencing:

--
-- xmonad example config file.
--
-- A template showing all available configuration hooks,
-- and how to override the defaults in your own xmonad.hs conf file.
--
-- Normally, you'd only override those defaults you care about.
--

import XMonad
import Data.Monoid
import System.Exit

import qualified XMonad.StackSet as W
import qualified Data.Map        as M
import XMonad.Util.Run(spawnPipe)
import XMonad.Util.Run(safeSpawnProg)
import XMonad.Hooks.ManageDocks
import XMonad.Hooks.DynamicLog
import System.IO
import XMonad.Layout.SimpleFloat
import XMonad.Layout.Renamed as R
import XMonad.Hooks.Place
import XMonad.Actions.NoBorders

-- The preferred terminal program, which is used in a binding below and by
-- certain contrib modules.
myTerminal      = "terminal"

-- Whether focus follows the mouse pointer.
myFocusFollowsMouse :: Bool
myFocusFollowsMouse = True

-- Whether clicking on a window to focus also passes the click to the window
myClickJustFocuses :: Bool
myClickJustFocuses = False

-- Width of the window border in pixels.
myBorderWidth   = 3

-- modMask lets you specify which modkey you want to use. The default
-- is mod1Mask ("left alt").  You may also consider using mod3Mask
-- ("right alt"), which does not conflict with emacs keybindings. The
-- "windows key" is usually mod4Mask.
myModMask = mod4Mask

-- The default number of workspaces (virtual screens) and their names.
-- By default we use numeric strings, but any string may be used as a
-- workspace name. The number of workspaces is determined by the length
-- of this list.
--
-- A tagging example:
--
-- > workspaces = ["web", "irc", "code" ] ++ map show [4..9]
--
xmobarEscape = concatMap doubleLts
  where doubleLts '<' = "<<"
        doubleLts x   = [x]

-- Workspaces
myWorkspaces :: [String]        
myWorkspaces = clickable . (map xmobarEscape) $ ["0:Web", "1:Editor", "2:Files", "3:Finance", "4:Office", "5:PDFs", "6:Images", "7:Music", "8:Shell", "9:Scratch"]
  where                                                                       
         clickable l = [ "<action=`xdotool key super+"++show (i)++"`><action=`xdotool key super+shift+"++show (i)++"` button=3>"++ws++"</action></action>" | (i,ws) <- zip [0..9] l]
webx = 0
editorx = webx + 1
filesx = editorx + 1
financex = filesx + 1
officex = financex + 1
pdfsx = officex + 1
imagesx = pdfsx + 1
musicx = imagesx + 1
shellx = musicx + 1
scratchx = shellx + 1

-- Border colors for unfocused and focused windows, respectively.
--
myNormalBorderColor  = "#aaaaaa"
myFocusedBorderColor = "#222222"

------------------------------------------------------------------------
-- Key bindings. Add, modify or remove key bindings here.
--
myKeys conf@(XConfig {XMonad.modMask = modm}) = M.fromList $

    -- launch a terminal
    [ ((modm,               xK_x     ), spawn myTerminal)

    -- launch dmenu
    , ((modm,               xK_p     ), spawn "dmenu_run")

    -- launch clock
    , ((modm,               xK_c     ), spawn "run_xclock")

    -- launch date/time and battery display
    , ((modm .|. shiftMask, xK_c     ), spawn "battery")

    -- close focused window
    , ((modm .|. shiftMask, xK_d     ), kill)

     -- Rotate through the available layout algorithms
    , ((modm,               xK_space ), sendMessage NextLayout)

    --  Reset the layouts on the current workspace to default
    , ((modm .|. shiftMask, xK_space ), setLayout $ XMonad.layoutHook conf)

    -- Resize viewed windows to the correct size
    , ((modm,               xK_n     ), refresh)

    -- Move focus to the next window
    , ((modm,               xK_Tab   ), windows W.focusDown)

    -- Move focus to the next window
    , ((modm,               xK_j     ), windows W.focusDown)

    -- Move focus to the previous window
    , ((modm,               xK_k     ), windows W.focusUp  )

    -- Move focus to the master window
    , ((modm,               xK_m     ), windows W.focusMaster  )

    -- Swap the focused window and the master window
    , ((modm,               xK_Return), windows W.swapMaster)

    -- Swap the focused window with the next window
    , ((modm .|. shiftMask, xK_j     ), windows W.swapDown  )

    -- Swap the focused window with the previous window
    , ((modm .|. shiftMask, xK_k     ), windows W.swapUp    )

    -- Shrink the master area
    , ((modm,               xK_h     ), sendMessage Shrink)

    -- Expand the master area
    , ((modm,               xK_l     ), sendMessage Expand)

    -- Push window back into tiling
    , ((modm,               xK_t     ), withFocused $ windows . W.sink)

    -- Increment the number of windows in the master area
    , ((modm              , xK_comma ), sendMessage (IncMasterN 1))

    -- Deincrement the number of windows in the master area
    , ((modm              , xK_period), sendMessage (IncMasterN (-1)))

    -- Toggle the status bar gap
    -- Use this binding with avoidStruts from Hooks.ManageDocks.
    -- See also the statusBar function from Hooks.DynamicLog.
    --
    , ((modm              , xK_b     ), sendMessage ToggleStruts)

    -- Quit xmonad
    , ((modm .|. shiftMask, xK_q     ), io (exitWith ExitSuccess))

    -- Restart xmonad
    , ((modm              , xK_q     ), spawn "xmonad --recompile; xmonad --restart")

    -- Run xmessage with a summary of the default keybindings (useful for beginners)
    , ((modm .|. shiftMask, xK_slash ), spawn ("echo \"" ++ help ++ "\" | xmessage -file -"))

    -- Switch to workspace 0 with `
    , ((modm              , xK_grave     ), windows (W.greedyView ((XMonad.workspaces conf) !! 0)))

    -- Shift to workspace 0 with `
    , ((modm .|. shiftMask, xK_grave     ), windows (W.shift ((XMonad.workspaces conf) !! 0)))

    -- Toggle border of focused window
    , ((modm,  xK_g ),   withFocused toggleBorder)

    ]
    ++

    --
    -- mod-[0..9], Switch to workspace N
    -- mod-shift-[0..9], Move client to workspace N
    --
    [((m .|. modm, k), windows $ f i)
        | (i, k) <- zip (XMonad.workspaces conf) [xK_0 .. xK_9]
        , (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)]]

------------------------------------------------------------------------
-- Mouse bindings: default actions bound to mouse events
--
myMouseBindings (XConfig {XMonad.modMask = modm}) = M.fromList $

    -- mod-button1, Set the window to floating mode and move by dragging
    [ ((modm, button1), (\w -> focus w >> mouseMoveWindow w
                                       >> windows W.shiftMaster))

    -- mod-button2, Raise the window to the top of the stack
    , ((modm, button2), (\w -> focus w >> windows W.shiftMaster))

    -- mod-button3, Set the window to floating mode and resize by dragging
    , ((modm, button3), (\w -> focus w >> mouseResizeWindow w
                                       >> windows W.shiftMaster))

    -- you may also bind events to the mouse scroll wheel (button4 and button5)
    ]

------------------------------------------------------------------------
-- Layouts:

-- You can specify and transform your layouts by modifying these values.
-- If you change layout bindings be sure to use 'mod-shift-space' after
-- restarting (with 'mod-q') to reset your layout state to the new
-- defaults, as xmonad preserves your old layout settings by default.
--
-- The available layouts.  Note that each layout is separated by |||,
-- which denotes layout choice.
--
myLayout = avoidStruts (tiled ||| renamed [R.Replace "Wide"] (Mirror tiled) ||| renamed [R.Replace "One"] (Full) ||| renamed [R.Replace "Float"] (simpleFloat))
  where
     -- default tiling algorithm partitions the screen into two panes
     tiled   = Tall nmaster delta ratio

     -- The default number of windows in the master pane
     nmaster = 1

     -- Default proportion of screen occupied by master pane
     ratio   = 1/2

     -- Percent of screen to increment by when resizing panes
     delta   = 3/100

------------------------------------------------------------------------
-- Window rules:

-- Execute arbitrary actions and WindowSet manipulations when managing
-- a new window. You can use this to, for example, always float a
-- particular program, or have a client always appear on a particular
-- workspace.
--
-- To find the property name associated with a program, use
-- > xprop | grep WM_CLASS
-- and click on the client you're interested in.
--
-- To match on the WM_NAME, you can use 'title' in the same way that
-- 'className' and 'resource' are used below.
--

myManageHook =  composeAll
    [ placeHook (withGaps (20,50,20,50) simpleSmart)
    , className =? "MPlayer"        --> doFloat
    , (className =? "Newcash" <&&> resource =? "Dialog") --> doFloat
    , className =? "Gimp"           --> doFloat
    , className =? "Galculator"     --> doFloat
    , className =? "Gnome-alsamixer"     --> doFloat
    , className =? "Newcash"             --> doFloat
    , className =? "XV"             --> doFloat
    , className =? "XVroot"             --> doFloat
    , className =? "XClock"             --> doFloat
    , className =? "Opera"       --> doShift (myWorkspaces !! webx)
    , className =? "Firefox"       --> doShift (myWorkspaces !! webx)
    , className =? "Chromium"       --> doShift (myWorkspaces !! webx)
    , className =? "Chrome"       --> doShift (myWorkspaces !! webx)
    , className =? "Sublime_text"       --> doShift (myWorkspaces !! editorx)
    , className =? "Gvim"       --> doShift (myWorkspaces !! editorx)
    , className =? "ROX-Filer"      --> doShift (myWorkspaces !! filesx)
    , className =? "Gnumeric"       --> doShift (myWorkspaces !! officex)
    , className =? "libreoffice-calc"       --> doShift (myWorkspaces !! officex)
    , className =? "libreoffice-writer"       --> doShift (myWorkspaces !! officex)
    , className =? "libreoffice-startcenter"       --> doShift (myWorkspaces !! officex)
    , className =? "Xpdf"       --> doShift (myWorkspaces !! pdfsx)
    , className =? "MuPDF"       --> doShift (myWorkspaces !! pdfsx)
    , className =? "Evince"       --> doShift (myWorkspaces !! pdfsx)
    , className =? "Gimp"           --> doShift (myWorkspaces !! imagesx)
    , className =? "Gpicview"           --> doShift (myWorkspaces !! imagesx)
    , className =? "Newcash"        --> doShift (myWorkspaces !! financex)
    ]

------------------------------------------------------------------------
-- Event handling

-- * EwmhDesktops users should change this to ewmhDesktopsEventHook
--
-- Defines a custom handler function for X Events. The function should
-- return (All True) if the default handler is to be run afterwards. To
-- combine event hooks use mappend or mconcat from Data.Monoid.
--
myEventHook = mconcat
                  [ docksEventHook
                  , handleEventHook def ]

------------------------------------------------------------------------
-- Status bars and logging

-- Perform an arbitrary action on each internal state change or X event.
-- See the 'XMonad.Hooks.DynamicLog' extension for examples.
--
-- myLogHook = 
------------------------------------------------------------------------
-- Startup hook

-- Perform an arbitrary action each time xmonad starts or is restarted
-- with mod-q.  Used by, e.g., XMonad.Layout.PerWorkspace to initialize
-- per-workspace layout choices.
--
-- By default, do nothing.
myStartupHook = return ()

------------------------------------------------------------------------
-- Now run xmonad with all the defaults we set up.

-- Run xmonad with the settings you specify. No need to modify this.
--
main = do
    xmproc <- spawnPipe "xmobar /home/dca/.config/xmobar.config"
    xmonad (def {
      -- simple stuff
        terminal           = myTerminal,
        focusFollowsMouse  = myFocusFollowsMouse,
        clickJustFocuses   = myClickJustFocuses,
        borderWidth        = myBorderWidth,
        modMask            = myModMask,
        workspaces         = myWorkspaces,
        normalBorderColor  = myNormalBorderColor,
        focusedBorderColor = myFocusedBorderColor,
        keys               = myKeys,
        mouseBindings      = myMouseBindings,
        layoutHook         = myLayout,
        manageHook         = myManageHook,
        handleEventHook    = myEventHook,
        logHook            = dynamicLogWithPP (xmobarPP
                                { ppOutput = hPutStrLn xmproc
                                    , ppTitle = xmobarColor "yellow" "" 
                                }),
        startupHook        = myStartupHook
    })

-- | Finally, a copy of the default bindings in simple textual tabular format.
help :: String
help = unlines ["The default modifier key is 'alt'. Default keybindings:",
    "",
    "-- launching and killing programs",
    "mod-x            Launch xterminal",
    "mod-p            Launch dmenu",
    "mod-c            Launch xclock",
    "mod-Shift-d      Close/kill the focused window",
    "mod-Space        Rotate through the available layout algorithms",
    "mod-Shift-Space  Reset the layouts on the current workSpace to default",
    "mod-n            Resize/refresh viewed windows to the correct size",
    "",
    "-- move focus up or down the window stack",
    "mod-Tab        Move focus to the next window",
    "mod-Shift-Tab  Move focus to the previous window",
    "mod-j          Move focus to the next window",
    "mod-k          Move focus to the previous window",
    "mod-m          Move focus to the master window",
    "",
    "-- modifying the window order",
    "mod-Return   Swap the focused window and the master window",
    "mod-Shift-j  Swap the focused window with the next window",
    "mod-Shift-k  Swap the focused window with the previous window",
    "",
    "-- resizing the master/slave ratio",
    "mod-h  Shrink the master area",
    "mod-l  Expand the master area",
    "",
    "-- floating layer support",
    "mod-t  Push window back into tiling; unfloat and re-tile it",
    "",
    "-- increase or decrease number of windows in the master area",
    "mod-comma  (mod-,)   Increment the number of windows in the master area",
    "mod-period (mod-.)   Deincrement the number of windows in the master area",
    "",
    "-- quit, or restart",
    "mod-Shift-q  Quit xmonad",
    "mod-q        Restart xmonad",
    "mod-[0/~,1..9]   Switch to workSpace N",
    "",
    "-- Workspaces & screens",
    "mod-Shift-[0/~,1..9]   Move client to workspace N",
    "mod-{w,e,r}        Switch to physical/Xinerama screens 1, 2, or 3",
    "mod-Shift-{w,e,r}  Move client to screen 1, 2, or 3",
    "",
    "-- Mouse bindings: default actions bound to mouse events",
    "mod-button1  Set the window to floating mode and move by dragging",
    "mod-button2  Raise the window to the top of the stack",
    "mod-button3  Set the window to floating mode and resize by dragging"]

Checklist

pjones commented 7 years ago

It seems likely that this is related to #106. Please see comments there.

geekosaur commented 7 years ago

On Tue, May 2, 2017 at 10:47 AM, donaldcallen notifications@github.com wrote:

Please include the smallest configuration file that reproduces the problem you are experiencing:

---- xmonad example config file.---- A template showing all available configuration hooks,-- and how to override the defaults in your own xmonad.hs conf file.---- Normally, you'd only override those defaults you care about.--

In other words, the smallest config file you can come up with is the evil one that overrides everything in a way that locks you to a single release of xmonad. This is arguably broken no matter what.

Did you even read what the comment says? Or does the word "normally" mean something different to you? Also you have already used it with versions it may well be incompatible with, because the past several versions have a very large DO NOT USE in the mega-example. Or did you remove that as being pointless?

-- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

donaldcallen commented 7 years ago

On 2 May 2017 at 11:29, Peter J. Jones notifications@github.com wrote:

It seems likely that this is related to #106 https://github.com/xmonad/xmonad/issues/106. Please see comments there.

Removing SimpleFloat seems to have made the placement of newly-created floating windows much more sensible, so I think your suggestion was helpful. Thank you.

But testing this has brought up another issue: the complexity of the floating windows placement algorithm. I am using a financial management application, newcash, that I wrote myself (C, gtk3, sqlite3). My xmonad.hs requests that newcash windows float; like Gimp, it's just not the right sort of application for tiling. I display a window containing the transactions that move money in or out of a particular account. If you select a transaction, you can display its splits in yet another window. I just tried creating a lot of those split-windows. Generally the placement was sensible, but as free screen space began to get scarce, the placement of each window took longer and longer. At one point, the whole window manager got hung for a couple of minutes, no response to any window manager gestures, such as switching tags or attempting to quit. I thought it was dead and was thinking about rebooting when it came back to life. So I think it's just the placement algorithm getting extremely slow when the screen gets crowded. Shall I file another problem report about this?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/xmonad/xmonad/issues/105#issuecomment-298670206, or mute the thread https://github.com/notifications/unsubscribe-auth/AEzjJ8ycrPzIbOQIYb2Y5a-d97FL4sDDks5r10vngaJpZM4NOPoV .

geekosaur commented 7 years ago

On Tue, May 2, 2017 at 2:17 PM, donaldcallen notifications@github.com wrote:

But testing this has brought up another issue: the complexity of the floating windows placement algorithm

Floating windows are an utter hack. This is an ancient bug. :(

-- brandon s allbery kf8nh sine nomine associates allbery.b@gmail.com ballbery@sinenomine.net unix, openafs, kerberos, infrastructure, xmonad http://sinenomine.net

liskin commented 3 years ago

This looks like a bug in XMonad.Hooks.Place, but we don't have any reproduction steps here, and the maintainer of that module is long gone from xmonad development, so it's unlikely we'll be able to fix this. I'll close this now. If this is still an issue for you, please include reproduction steps or at least a video of the bug being reproduced.

geekosaur commented 3 years ago

I see this somewhat regularly with XMonad.Hooks.Place and the Ubuntu upgrade dialog — but that is pretty obviously using the last size it had, so it's an interaction which includes the program ignoring the size that xmonad gives the window.