microsoft / wslg

Enabling the Windows Subsystem for Linux to include support for Wayland and X server related scenarios
MIT License
10.27k stars 311 forks source link

Ability to move windows when the title bar is off screen #529

Open shebiki opened 3 years ago

shebiki commented 3 years ago

Sometimes my WSLg apps appear with the title bar off screen. From what I can tell no keyboard shortcut exists to move back on screen.

Other tickets mention that window snapping, alt-dragging and windows+arrow keys don't work.

I'd love a workaround to enable using the application when this happens without having to restart it several times until it decides to position the window with the titlebar on screen again.

spronovo commented 3 years ago

Hi @shebiki,

Thanks for the feedback. Which application are you seeing this with? Only this application or many of them? Could you reproduce the problem then attach your /mnt/wslg/weston.log to this bug?

In theory Weston is supposed to be positioning a newly created window such that it fits properly within the display area. However, XWayland or the application itself can overwrite this and pick a location of their choice for the window on the desktop, including outside of the visible area. It would be useful to understand what's going on here.

shebiki commented 3 years ago

This happened when opening RubyMine but had previously bitten me a while ago (frequently at the time) with JetBrains Toolbox. I don't remember if this only happened when using multiple monitors or also happened on a single monitor. Will try and reproduce to get more specifics.

tyingq commented 3 years ago

A short script that will position all the windows top left. A crappy workaround, but it "works". You may need to install xdotool if it's not there already.

#!/usr/bin/bash
sx=30
sy=30
for window in $(xdotool search -name .)
do
   xdotool windowmove $window $sx $sy
   xdotool windowunmap $window
   xdotool windowmap $window
   sx=$(($sx + 40))
   sy=$(($sy + 40))
done

You could modify this to use "xwininfo", which asks you to click on a window (anywhere, not just the titlebar), and returns the id you would need to drive xdotool to move it. Like: xwininfo | grep -i 'window id' | awk '{print $4}' should extract just the window id you need.

Edit: Updated script to unmap/remap window because I'm seeing a new bug where windows get unmapped.

hideyukn88 commented 3 years ago

@shebiki, when this happen, would you please check, using xwininfo, if the window position match to where it's on Windows desktop? (assuming you are only using single monitor with 100% DPI, since multiple monitor with non-100% DPI, coordinate translation between X space and Windows desktop space could be tricky). I would like to check if this is because the window is actually correctly positioned in X11 space, but not at expected position at Windows side, Thanks!

garyo commented 3 years ago

Here's an xwininfo dump for this; my WSL2 X11 Emacs window currently has its title bar completely off screen, and there's no way to bring it back. I'm using a standard 1920x1200 monitor at 100% (no HiDPI).

I'm running latest WSLg preview version from Microsoft store, with Ubuntu 20.04 distro.

% xwininfo
xwininfo: Window id: 0xa0001b "[*Messages*] - tower1 - Emacs 28.0.50 (WSL2)"

  Absolute upper-left X:  -28
  Absolute upper-left Y:  -47
  Relative upper-left X:  38
  Relative upper-left Y:  59
  Width: 1013
  Height: 943
  Depth: 24
  Visual: 0x1ae
  Visual Class: TrueColor
  Border width: 0
  Class: InputOutput
  Colormap: 0xa0001a (not installed)
  Bit Gravity State: NorthWestGravity
  Window Gravity State: NorthWestGravity
  Backing Store State: NotUseful
  Save Under State: no
  Map State: IsViewable
  Override Redirect State: no
  Corners:  +-28+-47  -2855+-47  -2855-305  +-28-305
  -geometry 108x50+-66+-106

And yes, that xwininfo position approximately looks like what I'm actually seeing. Windows is off the top left of the display screen.

garyo commented 3 years ago

In my humble opinion, this should be marked as "Bug" rather than "Enhancement" since once a window opens with its task bar off screen, there is no way to get it back at all. It is a pretty serious bug for me. See also #332 which I think is the same bug.

snapwich commented 2 years ago

this is definitely a bug. i'm trying to use intellij and the configuration window opens up with the title bar off the screen. there's no way to drag or move the window, restarting the application does fix the positioning... so basically the application is unusable.

mvodanovic commented 2 years ago

I'm using PyCharm (so also a JetBrains IDE) and it happens to me as well, dual monitor setup. For me the application was completely off screen so I couldn't use xwinfo since it requires you to click on the window. I've managed to "fix" it by opening PowerShell and killing WSL with "wsl --shutdown" and then opening a new Linux terminal so that WSL starts again. After this the IDE appears on screen.

IvanCobotic commented 2 years ago

I would like to use the wslg X11 server for openGL applications over ssh, to get the graphics acceleration. I typically open windows with matplotlib or Open3D. If I stay on one screen things work ok, but in a dual monitor setup when move a window between my screens the window will often pop out of view with no way to bring it back. This was so annoying for me so I moved back to VcXsrv instead of using the built in wslg.

Is there any update when this issue will be adressed for WSLg ?

devaminb commented 2 years ago

Same here. I'm using PyCharm and some windows are off-screen.

Luckily, I've found this solution: https://unix.stackexchange.com/a/324577.

Simply, install xdotool (sudo apt update && sudo apt install xdotool), then run:

xdotool selectwindow windowmove 50 50

Select the window that is off-screen and it will bring its top-left corner back 50 pixels from the left of the screen, and 50 pixels down from the top.

It's just a workaround but it's clean (just one short command).

Owen1212055 commented 2 years ago

I would love to see a solution to this as well, using IntelliJ Ultimate I experience this often.

I can reproduce this when doing things such as resolving git conflicts, where a separate window is opened and half of it is not visible making it not able to be dragged back down. image

Using the provided tool above, I'm correctly able to have it snapped back into my screen. image

ROBYER1 commented 2 years ago

This issue is plaguing me always when using WSL 2, still no fix?

Jepson2k commented 2 years ago

A quick solution I've found that seems to work without having to restart anything is enabling "Automatically hide the taskbar" in settings and then disabling it. At least for the applications I work with, this pops them back into view.

wuxu92 commented 2 years ago

thanks to @devaminb method, I wrote a script to automatically reset all the off-screen windows' location.


function resetwindow {
    for pid in $(xdotool search -name --onlyvisible --maxdepth 2 .); do
        read -r x y < <(xwininfo -id "$pid" | grep Absolute | awk '{print $4}' | xargs)
        if [[ "$x" -lt 1 ]] || [[ "$y" -lt 1 ]]; then
            xdotool windowmove "$pid" 150 150
        fi
    done
}
a10cat commented 6 months ago

This might just be a corner case, but run into this issue again, after changing my setup

❯ weston-info

*** Please use wayland-info instead
*** weston-info is deprecated and will be removed in a future version

interface: 'wl_compositor', version: 4, name: 1
interface: 'wl_subcompositor', version: 1, name: 2
interface: 'wp_viewporter', version: 1, name: 3
interface: 'zxdg_output_manager_v1', version: 2, name: 4
        xdg_output_v1
                output: 22
                name: 'rdp-1'
                logical_x: 0, logical_y: 476
                logical_width: 1920, logical_height: 1080
        xdg_output_v1
                output: 12
                name: 'rdp-0'
                logical_x: 1920, logical_y: 0
                logical_width: 2560, logical_height: 1440
[...]
❯ xwininfo

xwininfo: Please select the window about which you
          would like information by clicking the
          mouse in that window.

xwininfo: Window id: 0x60004c "WindowTitle"

  Absolute upper-left X:  6
  Absolute upper-left Y:  27
  Relative upper-left X:  38
  Relative upper-left Y:  59

basically translates to something like this: image where blue is the desktop's surface, and red is the window's frame

dovholuknf commented 2 months ago

Should it be helpful, I have a setup where two monitors are at eye level. Monitor 3 shown in the screen cap is my "main" monitor. Monitor 1 is a laptop screen that sits physically lower on the desk so i arrange my monitors like this:

image

When a new window comes up, it is displayed "off the top of the screen" as though the Monitor 3 is being used for alignment, even though the window pops up on Monitor 1 and should be pushed "lower" on the virtual display

When the monitors are set to the same height this doesn't seem to be a problem for me: image