Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dialogs switch the stack to an incorrect window #712

Closed
sitepodmatt opened this issue Nov 12, 2020 · 30 comments · Fixed by #910 or #1007
Closed

Dialogs switch the stack to an incorrect window #712

sitepodmatt opened this issue Nov 12, 2020 · 30 comments · Fixed by #910 or #1007

Comments

@sitepodmatt
Copy link

sitepodmatt commented Nov 12, 2020

(1) Issue/Bug Description
When using window stacking, popos changes active stack window when a IntelliJ IDEA based product in a stack application launches a dialog (such as Settings)

(2) Steps to reproduce (if you know):

Create a popos stack
Add a Jetbrain's IntelliJ IDEA (could also be a variant such as WebStorm, Rider, CLion, PyCharm, PhpStorm or RubyMine, DataGrip, AppCode or Android Studio)
Add another app such as Firefox.
Do an action that launches a dialog from the IntelliJ such as opening settings (File -> Settings) popos shell needlessly switches the stack to the wrong window.

(3) Expected behavior: No switching of my stack

(4) Distribution (run cat /etc/os-release): Pop!_OS 20.10

(5) Gnome Shell version: 3.38.1

(6) Pop Shell version (run apt policy pop-shell or provide the latest commit if building locally):

1.0.0160468824220.10~d1d2b0e

(7) Where was Pop Shell installed from: apt-get install popos-desktop

I found this #407 but it doesn't explain why the stack is changing active window, unless it's expecting the dialog to open as part of the stack and trying to focus it but it isn't there??

Perhaps it should only refocus the stack if a window is actually added to the stack, as the modal appears correctly in all other manners?

@sitepodmatt
Copy link
Author

sitepodmatt commented Nov 12, 2020

image

tl;dr popos is changing window the active window in the stack when it shouldnt - i got automatically switched to the browser here by just triggering a rename dialog in intellij. Oddly PopOS shell switches back to the correct window once I've completed the action so more annoying at this stage than anything else

@sitepodmatt
Copy link
Author

NAME="Pop!_OS"
VERSION="20.10"
ID=pop
ID_LIKE="ubuntu debian"
PRETTY_NAME="Pop!_OS 20.10"
VERSION_ID="20.10"
HOME_URL="https://pop.system76.com"
SUPPORT_URL="https://support.system76.com"
BUG_REPORT_URL="https://github.com/pop-os/pop/issues"
PRIVACY_POLICY_URL="https://system76.com/privacy"
VERSION_CODENAME=groovy
UBUNTU_CODENAME=groovy
LOGO=distributor-logo-pop-os

@mmstick
Copy link
Member

mmstick commented Nov 13, 2020

Dialogs aren't permitted to tile, so something else is happening. I've been looking into this

@sitepodmatt
Copy link
Author

Thanks. I've updated the bug description tl;dr - easier to replicate via just opening settings rather than trying to get a rename window going.

@sitepodmatt
Copy link
Author

Was this fixed by 2a3560a?

@sitepodmatt
Copy link
Author

Just tried with latest verison, still busted, in stacking mode, opening a dialog like rename variable (shift+f6) switches the stack window

@sitepodmatt
Copy link
Author

sitepodmatt commented Feb 24, 2021

Just to update replication instructions on latest, renaming has become inline in many Jetbrains IDEs, ill choose most popular IntelliJ, so stacking setup with three windows (ff, intellij, terminal), so easiest way now is to shift twice in quick succession (brings up the All tasks selector), and choose the first option for example (Analyse Stack trace or thread dump), pop os gets confused and focuses the nth window in the stack (the terminal) whilst this dialog is showing, and back to nth-1 (the middle - intellij ) after closing..

@sitepodmatt
Copy link
Author

To be clear, this is not a problem in i3wm on the same popos distro (and thus same intellij), and seems to only happen in stacking mode

@hoshsadiq
Copy link

Hello all, I have the same issue. I don't know much about the inner workings here but it looks to me like an off by one index somewhere. It seems to always switch to the last window I have selected, i.e. if I Firefox, Spotify, IntelliJ, if I open Firefox, then IntelliJ, then open a dialog, it shows Firefox, however, if I open Spotify, then IntelliJ, dialogs switch to Spotify.

Also, dragging editor windows also causes this, which makes dropping windows extremely hard.

@sitepodmatt
Copy link
Author

sitepodmatt commented Mar 4, 2021

Yes, I initially thought it off by one too, I think it's expecting the dialog to be part of the stack and then it tries to switch to it but that exceeds the number of windows in the stack so either lands on the next one or back at 0

@mmstick would any diagnosis material help on this? a video via dropbox for example?

@sitepodmatt
Copy link
Author

sitepodmatt commented Mar 17, 2021

Could this be related to having _NET_WM_STATE_SKIP_TASKBAR?

WM_STATE(WM_STATE):
window state: Normal
icon window: 0x0
_NET_WM_DESKTOP(CARDINAL) = 0
_GTK_EDGE_CONSTRAINTS(CARDINAL) = 170
_NET_WM_ALLOWED_ACTIONS(ATOM) = _NET_WM_ACTION_MOVE, _NET_WM_ACTION_RESIZE, _NET_WM_ACTION_FULLSCREEN, _NET_WM_ACTION_MAXIMIZE_HORZ, _NET_WM_ACTION_MAXIMIZE_VERT, _NET_WM_ACTION_CHANGE_DESKTOP, _NET_WM_ACTION_CLOSE, _NET_WM_ACTION_ABOVE, _NET_WM_ACTION_BELOW
_NET_WM_STATE(ATOM) = _NET_WM_STATE_SKIP_PAGER, _NET_WM_STATE_SKIP_TASKBAR
WM_HINTS(WM_HINTS):
Client accepts input or input focus: True
Initial state is Normal State.
bitmap id # to use for icon: 0x8c00007
bitmap id # of mask for icon: 0x8c00012
window id # of group leader: 0x8c00001
_GTK_THEME_VARIANT(UTF8_STRING) =
XdndAware(ATOM) = BITMAP
_NET_WM_STATE(ATOM) = _NET_WM_STATE_SKIP_TASKBAR
WM_HINTS(WM_HINTS):
Client accepts input or input focus: False
window id # of group leader: 0x4c00089
WM_TRANSIENT_FOR(WINDOW): window id # 0x4c00089
_NET_WM_PID(CARDINAL) = 54328
WM_CLIENT_MACHINE(STRING) = "asus36"
WM_PROTOCOLS(ATOM): protocols WM_DELETE_WINDOW, WM_TAKE_FOCUS
WM_NAME(STRING) = "Settings"
WM_NORMAL_HINTS(WM_SIZE_HINTS):
user specified location: 609, 27
program specified location: 609, 27
program specified size: 992 by 952
program specified minimum size: 900 by 700
window gravity: NorthWest

@sitepodmatt
Copy link
Author

This is still happening in the latest dev branch, although not as much.

activate is getting called in stack.ts, and then usually the first window is getting selected due to Ecs.entity_eq(entity, component.entity) returning true. There are times I can't replicate this though now until I select a different window in stack and then switch back to IntelliJ then it's replicatable again. Will try and do some more exhuastive debugging

@sitepodmatt
Copy link
Author

1616834689767=== activate called ==
ist :false
ist :activate@/home/matt/.local/share/gnome-shell/extensions/[email protected]/stack.js:79:31
on_focused@/home/matt/.local/share/gnome-shell/extensions/[email protected]/extension.js:490:197
signals_attach/</<@/home/matt/.local/share/gnome-shell/extensions/[email protected]/extension.js:1319:26

ist2:false
1616834689779=== activate called ==
ist :false
ist :activate@/home/matt/.local/share/gnome-shell/extensions/[email protected]/stack.js:79:31
on_focused@/home/matt/.local/share/gnome-shell/extensions/[email protected]/extension.js:490:197
signals_attach/</<@/home/matt/.local/share/gnome-shell/extensions/[email protected]/extension.js:1319:26

Here how activate is being called... seem to come from focus

@sitepodmatt
Copy link
Author

    focus_window(): Window.ShellWindow | null {
        let focused = this.get_window(display.get_focus_window())
        //if (!focused && this.last_focused) {
        //    focused = this.windows.get(this.last_focused);
        //}
        return focused;
    }

Okay managed to get this solved for my use case, but unsure what other problems I've introduced here by simply commenting out.

@sitepodmatt
Copy link
Author

sitepodmatt commented Mar 27, 2021

Revising src/extensions.ts:L590

    focus_window(): Window.ShellWindow | null {
        let focused = this.get_window(display.get_focus_window())
        if (!focused && this.last_focused ) {
            // THE CULPRIT ↓↓↓
            focused = this.windows.get(this.last_focused);
            if (focused && focused.stack !== null) {
              focused = null
            }
        }
        return focused;
    }

This now works and I've reduce the hack to apply to stack only, I'm heavily skeptical that this is the correct fix though, @mmstick any thoughts on further troubleshooting this?

@sitepodmatt
Copy link
Author

sitepodmatt commented Mar 27, 2021

just further ramblings, it seems this can also be solved by wrapping the 'notify::focus-window' handler ~L1670 with a GLib.timeout_add 300ms, as get_focus_window() does not return null after 300ms, perhaps suggesting Swing dialogs are somewhat delayed by coming into focus after whatever event notifies new dialog/window. Interesting..

@mmstick mmstick mentioned this issue Mar 29, 2021
@mmstick mmstick reopened this Apr 8, 2021
@mmstick
Copy link
Member

mmstick commented Apr 8, 2021

300ms delay breaks active hint and management mode

@sitepodmatt
Copy link
Author

sitepodmatt commented Apr 9, 2021

Eek. I wonder if we changed it to fire immediately if there is a focused window, and only if falsey, then schedule a timeout for 300ms to run? 300ms see

@hoshsadiq
Copy link

I've just upgraded my machine's packages (pop-shell==1.1.0~1620418263~20.10~9507dc3) and the behaviour has gotten worse. When any of the previous popups show up in IntelliJ it completely hides IntelliJ and the popup. It is impossible to change back to IntelliJ unless I Alt+` twice which brings back the popup, but not the main IntelliJ window.

@lhotari
Copy link
Contributor

lhotari commented Jun 5, 2021

I upgraded to Pop OS 21.04 beta & COSMIC. This problem exists and makes window stacking unusable with IntelliJ or other Jetbrains IDEs.

@mmstick is there a plan to address this issue?

@mmstick
Copy link
Member

mmstick commented Jun 5, 2021

@lhotari All issues are planned to be addressed, but wanting to fix them doesn't automatically make the solution known.

@hoshsadiq
Copy link

Is there any way to permanently disable the stacks feature until this gets fixed? IntelliJ is pretty much unusable with this bug. I feel like I've seen the option previously but I can't find it any more.

@lhotari
Copy link
Contributor

lhotari commented Jun 18, 2021

All issues are planned to be addressed, but wanting to fix them doesn't automatically make the solution known.

@mmstick I really love Pop OS Shell. Pop OS Shell has the best window manager that I have ever used and the stacking and auto-tiling features are incredible. This single bug makes the user experience terrible. The reason is that I use IntelliJ and this bug shows up mainly with IntelliJ (and other Jetbrains IDE products).
If there was a bug bounty, I'd pay cash to get this fixed. :)

@lhotari
Copy link
Contributor

lhotari commented Jun 18, 2021

The problem might be caused by IntelliJ. I found this blog post: https://makandracards.com/makandra/40343-how-to-fix-rubymine-intellij-find-file-dialog-losing-focus-on-awesome-wm . It suggests enabling focus.follows.mouse.workarounds registry setting in IntelliJ. It references https://youtrack.jetbrains.com/issue/IDEA-112015 . I tried this and also the other setting ide.settings.move.mouse.on.default.button. but enabling those settings doesn't make a difference.

@lhotari
Copy link
Contributor

lhotari commented Jun 18, 2021

I found a workaround for using IntelliJ. If I change the focus to some other window outside of the stack and then switch the focus back to IntelliJ, the dialogs get focus as expected. The problem with IntelliJ seems to occur when another window such as Gnome Terminal or Chrome has been the previous window as part of the same stack. Switching between multiple IntelliJ windows in the same stack doesn't cause the problem.

@lhotari
Copy link
Contributor

lhotari commented Jun 18, 2021

Even though the blog post "How to fix: RubyMine / IntelliJ "find file" dialog losing focus on awesome wm" is in different context, I wonder if the details in about using sun-awt-X11-XDialogPeer and sun-awt-X11-XFramePeer for detecting the focused dialog would be helpful for fixing this issue?

This was the lua script in

-- Enable sloppy focus (without defocusing IntelliJ dialogs)
c:connect_signal("mouse::enter", function(c)
    local focused = client.focus
    if focused 
        and focused.class == c.class
        and focused.instance == "sun-awt-X11-XDialogPeer"
        and c.instance == "sun-awt-X11-XFramePeer"
        then
            return
    end

    if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
        and awful.client.focus.filter(c) then
        client.focus = c
    end
end)

something similar can be found in i3 workarounds for Java applications: https://stackoverflow.com/a/32596391/

for_window [instance="sun-awt-X11-XFramePeer"] floating enable
for_window [instance="sun-awt-X11-XDialogPeer"] floating enable

also found in GitHub here "Kludge IntelliJ IDEA splash popup to be transient":
raboof/notion@995bca3
That seems to be kludges for Notion tiling, tabbed window manager for the X window system.

Perhaps we need some kludges for IntelliJ in Pop-OS Shell?

@lhotari
Copy link
Contributor

lhotari commented Jun 18, 2021

I used this type of shell function to get information about the popup dialog:

function show_info_for_new_jetbrains_windows() {
    ws=$(xdotool search --onlyvisible --class 'jetbrains.*')
    while true; do
        wstmp=$(xdotool search --onlyvisible --class 'jetbrains.*')
        wsnew=$(diff <(echo "$ws") <(echo "$wstmp") | awk '/^>/ {print $2}')
        echo found windows: $wsnew
        for win in $wsnew; do
            xwininfo -id $win -all
            xprop -id $win
        done
        ws=$wstmp
        sleep 0.5
    done
}

(function based on script in raboof/notion#321 (comment))

Here's the output for the "Find in Files" popup dialog in IntelliJ Idea Ultimate:

found windows: 96472735
96472738

xwininfo: Window id: 0x5c00e9f " "

  Root window id: 0x7a8 (the root window) (has no name)
  Parent window id: 0x7a8 (the root window) (has no name)
     2 children:
     0x5c00ea5 "FocusProxy": ("Focus-Proxy-Window" "FocusProxy")  1x1+-1+-1  +2012+1105
     0x5c00ea2 "Content window": ("jetbrains-idea" "jetbrains-idea")  1357x758+0+0  +2013+1106

  Absolute upper-left X:  2013
  Absolute upper-left Y:  1106
  Relative upper-left X:  2013
  Relative upper-left Y:  1106
  Width: 1357
  Height: 758
  Depth: 24
  Visual: 0x21
  Visual Class: TrueColor
  Border width: 0
  Class: InputOutput
  Colormap: 0x20 (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:  +2013+1106  -470+1106  -470-296  +2013-296
  -geometry 1357x758+2013+1106

  Bit gravity: NorthWestGravity
  Window gravity: NorthWestGravity
  Backing-store hint: NotUseful
  Backing-planes to be preserved: 0xffffffff
  Backing pixel: 0
  Save-unders: No

  Someone wants these events:
      ButtonPress
      ButtonRelease
      EnterWindow
      LeaveWindow
      PointerMotion
      ButtonMotion
      Exposure
      VisibilityChange
      StructureNotify
      PropertyChange
      OwnerGrabButton
  Do not propagate these events:
  Override redirection?: No

  Window manager hints:
      Client accepts input or input focus: No
      Displayed on desktop 0
      Window type:
          Dialog
      Window state:
          Skip Taskbar
          Focused
      Process id: 313688 on host pop-os
      Frame extents: 0, 0, 37, 0

  Normal window size hints:
      User supplied location: 2013, 1106
      Program supplied location: 2013, 1106
      Program supplied size: 1357 by 758
      Program supplied minimum size: 535 by 256
      Program supplied window gravity: NorthWestGravity
  No zoom window size hints defined

  No window shape defined
  No border shape defined

WM_STATE(WM_STATE):
		window state: Normal
		icon window: 0x0
_NET_WM_DESKTOP(CARDINAL) = 0
_GTK_EDGE_CONSTRAINTS(CARDINAL) = 170
_NET_WM_ALLOWED_ACTIONS(ATOM) = _NET_WM_ACTION_MOVE, _NET_WM_ACTION_RESIZE, _NET_WM_ACTION_CHANGE_DESKTOP, _NET_WM_ACTION_CLOSE, _NET_WM_ACTION_ABOVE, _NET_WM_ACTION_BELOW
_NET_WM_WINDOW_TYPE(ATOM) = _NET_WM_WINDOW_TYPE_DIALOG
_OL_DECOR_DEL(ATOM) = _OL_DECOR_HEADER, _OL_DECOR_RESIZE, _OL_DECOR_CLOSE
_MOTIF_WM_HINTS(_MOTIF_WM_HINTS) = 0x3, 0x26, 0x0, 0x0, 0x0
_NET_FRAME_EXTENTS(CARDINAL) = 0, 0, 37, 0
_MOTIF_DRAG_RECEIVER_INFO(_MOTIF_DRAG_RECEIVER_INFO) = 0x6c, 0x0, 0x5, 0x0, 0x9f, 0xe, 0xc0, 0x5, 0x0, 0x0, 0x0, 0x0, 0x10, 0x0, 0x0, 0x0
XdndAware(ATOM) = BITMAP
_NET_WM_STATE(ATOM) = _NET_WM_STATE_SKIP_TASKBAR, _NET_WM_STATE_FOCUSED
WM_HINTS(WM_HINTS):
		Client accepts input or input focus: False
		window id # of group leader: 0x5c0006c
WM_TRANSIENT_FOR(WINDOW): window id # 0x5c0006c
_NET_WM_PID(CARDINAL) = 313688
WM_CLIENT_MACHINE(STRING) = "pop-os"
WM_PROTOCOLS(ATOM): protocols  WM_DELETE_WINDOW, WM_TAKE_FOCUS
WM_CLASS(STRING) = "jetbrains-idea", "jetbrains-idea"
_NET_WM_USER_TIME_WINDOW(WINDOW): window id # 0x5c00008
WM_CLIENT_LEADER(WINDOW): window id # 0x5c00008
_NET_WM_ICON_NAME(UTF8_STRING) = "Java"
WM_ICON_NAME(STRING) = "Java"
_NET_WM_NAME(UTF8_STRING) = " "
WM_NAME(STRING) = " "
WM_NORMAL_HINTS(WM_SIZE_HINTS):
		user specified location: 2013, 1106
		program specified location: 2013, 1106
		program specified size: 1357 by 758
		program specified minimum size: 535 by 256
		window gravity: NorthWest

@lhotari
Copy link
Contributor

lhotari commented Jun 18, 2021

Switching to the wrong active window seems to be caused by this piece of code:
https://github.com/pop-os/shell/blob/master/src/extension.ts/#L629-L632

This helped find another workaround:
https://github.com/pop-os/shell/blob/master/src/extension.ts/#L720-L724

last_focused state gets cleared by switching the workspace. That's the workaround I'll use for IntelliJ until the issue gets fixed.

@lhotari
Copy link
Contributor

lhotari commented Jun 18, 2021

@mmstick I have created a PR that fixes this issue. Please review #1007 . Thanks to @sitepodmatt for pointing out the root cause of the issue.

@hoshsadiq
Copy link

Thanks @lhotari, @mmstick. That PR has fixed it the issue for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants