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

Terminal cursor displaced after minimize #3085

Open
RenzoGerritzen opened this issue Mar 18, 2024 · 12 comments
Open

Terminal cursor displaced after minimize #3085

RenzoGerritzen opened this issue Mar 18, 2024 · 12 comments
Labels
A-terminal Area: integrated terminal A-ui Area: UI rendering and interactions C-bug Category: bug - something isn't working as it's supposed to

Comments

@RenzoGerritzen
Copy link

RenzoGerritzen commented Mar 18, 2024

Lapce Version

0.3.1

System information

Windows 11

Describe the bug

If the content viewer has a file or tab opened of which the contents are taller than the view height, then you minimize the window, the cursor of the terminal will be in te wrong location.

Additional information

Before minimizing:
Screenshot 2024-03-18 143629

After minimizing and opening:
Screenshot 2024-03-18 143635

After typing:
Screenshot 2024-03-18 143639

Based on the small flickering of the window upon opening it, i think it might have something to do with a re-drawing of the element. As it only seems to be happening when you press the minimize button and not when activating another window, it might have something to do with a state change when ghe minimizing happens.

Is it alright if i pick up the issue and see if i can fix it?

@RenzoGerritzen RenzoGerritzen added the C-bug Category: bug - something isn't working as it's supposed to label Mar 18, 2024
@MinusGix MinusGix added A-ui Area: UI rendering and interactions A-terminal Area: integrated terminal labels Mar 20, 2024
@MinusGix
Copy link
Member

MinusGix commented Mar 20, 2024

Is it alright if i pick up the issue and see if i can fix it?

Feel free to try fixing it!
You'd want to look at lapce-app/src/terminal/view.rs and probably the wheel_scroll function in terminal/data.rs, since it seems like some issue with scroll changing but possibly not getting sent to the terminal? Unsure.

@RenzoGerritzen
Copy link
Author

Thank you! I'll get started on it in a few days and i will keep you updated! Great work on the editor by the way. It seems to run smoothly and i can only imagine the amount of time and effort to get to this point

@RenzoGerritzen
Copy link
Author

RenzoGerritzen commented Mar 22, 2024

I found out that when the application is minimized, the view buffer of the window only shows a small portion of the titlebar. This can be seen for a split second when you open the application.
image

This caused the terminals size to become 0 or less, causing it to move the cursor to the incorrect location. When the window is opened, the terminal is resized again and the cursor is moved again, causing it to render at the wrong location. I have validated this by forcing the terminals size to 1200x200 and the bug stopped appearing.

Is the scaling of the application intentional to save performance? As this is a pretty minor bug i want to make sure the fix will not break more important components.

@MinusGix
Copy link
Member

I'm unsure as to the answer here. It might be something done in floem?

@RenzoGerritzen
Copy link
Author

I am not sure myself to be honest. I'm looking into it, but if it is something caused by floem it might have to take the problem upstream.

@Long0x0
Copy link
Contributor

Long0x0 commented Mar 24, 2024

On Windows, minimize means resize. We need a patch for the WM_SIZE event in the upstream winit crate.

See:

@RenzoGerritzen
Copy link
Author

Thank you kindly! I will see if i can get some kind of workaround

@RenzoGerritzen
Copy link
Author

It seems the only way to really stop the cursor from displacing is to keep the width and height of the element when there is a drastic change in the size or to check for the exact size the window is when minimized, but this seems quite hacky an unreliable. I am not entirely sure how to proceed, but i think trying to solve the problem in lapce itself might not be a great idea. I'll keep the issue opened for a while to see if anyone else has some ideas, but i will close the issue soon

@MinusGix
Copy link
Member

MinusGix commented Mar 25, 2024

(The issue should remain open even if we can't fix it right now — thank you for trying at it! — because it would still be a bug)
I think ideally this is something fixed, or given a workaround, in floem. So we could have a change in our winit fork to support knowing when the window was minimized and ignore size changes with that.

@RenzoGerritzen
Copy link
Author

Good point. I didn't know lapce used a custom winit fork, I'll give it a go

@RenzoGerritzen
Copy link
Author

After some diffing i found out that while there is a resize event taking place when minimizing, it does not seem to be manually called. The winit crate seems to simply set a flag to the window and windows does the rest. Even if i could capture the minimizing event and bypass the size change somehow, the bug still happens when the window is made very small.

The only solutions i can think of are a minimum size or bypassing the size setting when checking the percentage of window scaling. Both solutions don't seem reliable. If anyone has any ideas i am glad to try them, but for now i am not sure how to proceed.

@Long0x0
Copy link
Contributor

Long0x0 commented Apr 15, 2024

I created a PR for winit lapce/winit#6 to fix the issue when minimizing. But it doesn't work when manually resizing to a small size.

I believe that's a bug in ConPTY, as window terminal, vscode integrated terminal, and alacritty have similar issues.

https://github.com/microsoft/terminal/issues?q=is%3Aissue+is%3Aopen+label%3AProduct-Conpty+resize

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-terminal Area: integrated terminal A-ui Area: UI rendering and interactions C-bug Category: bug - something isn't working as it's supposed to
Projects
None yet
Development

No branches or pull requests

3 participants