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

Opening new tabs in Terminal changes its position in the layout #633

Closed
ianyh opened this issue Jul 29, 2017 · 12 comments
Closed

Opening new tabs in Terminal changes its position in the layout #633

ianyh opened this issue Jul 29, 2017 · 12 comments
Assignees
Labels

Comments

@ianyh
Copy link
Owner

ianyh commented Jul 29, 2017

System

  • Amethyst version: 0.11.4b
  • macOS version: 10.13 Beta

What's the problem?

When in tall layout I had a terminal window with 2 tabs in a layout with 3 windows. It was in the first position in the secondary pane, but when adding a new tab it moved to the second position in the secondary pane.

How can it be reproduced?

What applications are involved?

Has anything fixed it, even temporarily?

dotfile (if you have one)

{

}

Screenshots

Trello Card

@ianyh ianyh added the bug label Jul 29, 2017
@ianyh
Copy link
Owner Author

ianyh commented Jul 29, 2017

This appears to actually be a pretty big issue with tabbed windows (at least in Terminal). The tabs switch between windows, but they are windows with different window ids. They appear to be fully fledged windows. Their parents are the application. Not sure how to get past this one.

@ianyh
Copy link
Owner Author

ianyh commented Jul 29, 2017

At the very least this isn't a regression (it happens in 0.11.3).

@koekeishiya
Copy link

From what I've seen, tabbed windows are also reported through the accessibility notifications.
https://github.com/koekeishiya/chunkwm/issues/80#issuecomment-309263422

An ugly workaround is to rebalance (reflow in amethyst?) the window representation after a window created / destroyed event. Interested to hear if you come up with a better solution.

@dominiklohmann
Copy link

dominiklohmann commented Aug 1, 2017

What applications are involved?

This happens to all windows that use native Cocoa tabs that were introduced in macOS 10.12 Sierra. If you use the "Show All Tabs" option it somehow resets.

Safari is not affected, its tabs are not the Cocoa defaults for whatever reason.

@selfawaresoup
Copy link

Did some testing on this (on macOS 10.13.2):

  • Finder is also not affected.
  • Terminal still is affected as described above.
  • Preview behaves weird in a different way: When I open a second document and "Merge all windows", an empty space remains for each window that just disappeared. As soon as I close even just one tab, things return to normal.

@ianfixes
Copy link
Contributor

OSX 10.13.6 (17G65):

Opening a new tab, or switching tabs within terminal causes the "empty space" issue. Minimizing and restoring the window seem to repair the issue.

@ianyh ianyh self-assigned this Mar 4, 2019
@ianyh
Copy link
Owner Author

ianyh commented Mar 4, 2019

Did a bunch of testing over the weekend. Some general notes.

  • Switching between existing tabs in a window does not seem to generate created notifications. It does generate mainWindowChanged notifications.
  • mainWindowChanged notifications are also generated when switching focus between windows. However, such events are preceded by a focusChanged notification so are relatively easy to distinguish from tab changes. I've tried a couple of time delta threshold. 1s was too much, as you would lose notifications if you switched between windows and tabs very quickly, but 0.1s seemed to be about right even for sense memory fiddling with the keyboard.
  • mainWindowChanged notifications are also generated when switching between applications. Unfortunately, the applicationActivated notification comes after mainWindowChanged. I've been able to distinguish those events based on whether or not the corresponding NSRunningApplication is active. If it is not active then this isn't a tab change and we can ignore it.
  • To actually handle tab changes I used a combination of factors to determine which "window" to swap positions with.
    • Fairly obvious ones like same application and screen.
    • Determining whether we think the window is on screen and whether it actually is. If we think it is active and it's not that means that the window disappeared, but we haven't reacted yet. In testing a few apps this seems to be consistent with native tab changes.
    • Frame comparison to make sure they are in the same place. This one required some error tolerance for Terminal windows as even switching between tabs you can get significant variation. I've been working with a 10pt tolerance which seems to be working well.
  • Some behavioral notes about closing tabs
    • This does create a destroyed notification, but the mainWindowChanged to the other tab notification precedes it. I've been able to work around this because at the main window change time the destroyed tab is already invalid—more specifically, it has null window ID. You can basically just make sure it's the right application and swap the windows out. It does require something of a leap of faith as there is no longer any frame to compare and it will no longer read as active regardless.
  • Still having some challenges with newly created tabs, but I haven't been able to work through them yet.

@ianyh
Copy link
Owner Author

ianyh commented Mar 9, 2019

Turns out my issue with new tabs was actually just needing to tolerate more height difference. Windows that go from not having tabs to having tabs can change the titlebar size which contributes to the overall differential.

@ianfixes
Copy link
Contributor

ianfixes commented Mar 9, 2019

Can you talk more about the need for height tolerance in general (like when it's used, and why)? This might be related to some other behavior I've noticed.

@ianyh
Copy link
Owner Author

ianyh commented Mar 10, 2019

@ianfixes The problem is that when you open a new tab it gets mostly treated as a new window, but the dimensions of the window can be different. This isn't true for all windows—e.g., Safari seems to not change height—but it's definitely true for Terminal windows.

@ianfixes
Copy link
Contributor

If I'm reading this correctly, you are trying to determine whether mainWindowChanged refers to a new window or an existing window, and this is technically just a guess. Is that accurate (meaning the fix is just to get better at guessing)?

@ianyh
Copy link
Owner Author

ianyh commented Mar 11, 2019

It is technically a guess, yes. For most windows there's no need for the tolerance as the tabs will be in the same frame, but some applications (e.g., Terminal) have some quirks.

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

No branches or pull requests

5 participants