dnkl/foot
41
2.0k
Fork
You've already forked foot
243

Add a 'wait-for-mapped' option #453

Open
opened 2021年04月22日 10:39:12 +02:00 by dnkl · 14 comments
Owner
Copy link

Add a --wait-for-mapped command line and configuration option. When used, defer spawning the client application until the window has been mapped.

This ensures the client application sees the final window size immediately.

I.e. this is a workaround for buggy applications that don't use SIGWINCH properly.

Add a `--wait-for-mapped` command line and configuration option. When used, defer spawning the client application until the window has been mapped. This ensures the client application sees the final window size immediately. I.e. this is a workaround for buggy applications that don't use `SIGWINCH` properly.
dnkl changed title from (削除) Add an (削除ここまで) to Add a 'wait-for-mapped' option 2021年04月22日 10:39:31 +02:00
Collaborator
Copy link

... buggy applications that don't use SIGWINCH properly

@dnkl Do you have a specific example of this, for reference purposes?

> ... buggy applications that don't use SIGWINCH properly @dnkl Do you have a specific example of this, for reference purposes?
Author
Owner
Copy link

@craigbarnes I don't have any code pointers, if that's what you're asking for. I was perhaps expressing myself somewhat sloppy; my guess is applications that exhibit sizing issues (like described in #723) are racy, and request the initial size before registering their SIGWINCH handler. But it's just a guess.

Others purposely ignores some of the initial resize events, like neovim (https://github.com/neovim/neovim/issues/11330)

I don't usually start applications directly in a new terminal window, and thus I don't really notice these issues. With that said, I have seen it it neovim and top (not htop).

@craigbarnes I don't have any code pointers, if that's what you're asking for. I was perhaps expressing myself somewhat sloppy; my guess is applications that exhibit sizing issues (like described in https://codeberg.org/dnkl/foot/issues/723) are racy, and request the initial size before registering their `SIGWINCH` handler. But it's just a guess. Others purposely ignores some of the initial resize events, like neovim (https://github.com/neovim/neovim/issues/11330) I don't usually start applications directly in a new terminal window, and thus I don't really notice these issues. With that said, I have seen it it neovim and top (not htop).
Collaborator
Copy link

... my guess is applications that exhibit sizing issues (like described in #723) are racy, and request the initial size before registering their SIGWINCH handler.

Ah yeah, that makes sense. I was trying to imagine what kind of patterns might cause/worsen the problem, but my brain was running on empty.

Possibly relevant vim issues:

> ... my guess is applications that exhibit sizing issues (like described in #723) are racy, and request the initial size before registering their SIGWINCH handler. Ah yeah, that makes sense. I was trying to imagine what kind of patterns might cause/worsen the problem, but my brain was running on empty. Possibly relevant vim issues: * https://github.com/vim/vim/issues/424 * https://github.com/tmux/tmux/issues/2064#issuecomment-597726208
Contributor
Copy link

Oh my - I've been running into this race for years :) I encounter it with some curses-like programs such as vim and neomutt. It's gotten to the point that I have shortcuts that spawn those programs in a terminal like:

foot bash -c "sleep 0.1; exec vim Documents/TODO.txt"

A flag to do this waiting for me would be absolutely wonderful.

Oh my - I've been running into this race for *years* :) I encounter it with some curses-like programs such as vim and neomutt. It's gotten to the point that I have shortcuts that spawn those programs in a terminal like: foot bash -c "sleep 0.1; exec vim Documents/TODO.txt" A flag to do this waiting for me would be absolutely wonderful.
Collaborator
Copy link

I'm not sure how reliable it'll be, but I've just thrown this together as an alternative to sleep 0.1. It seems to reduce flickering somewhat and might help to avoid some resizing bugs in certain apps (but seemingly not mtm for some reason).

I'm not sure how reliable it'll be, but I've just thrown [this](https://codeberg.org/craigbarnes/waitwinch) together as an alternative to `sleep 0.1`. It seems to reduce flickering somewhat and might help to avoid some resizing bugs in certain apps (but seemingly not `mtm` for some reason).
Author
Owner
Copy link

Depending on compositor, there may be multiple SIGWINCH signals at startup.

On Sway (at least older versions), there will be two. First, Sway asks us to size ourselves. This leads to a transition from the hardcoded 80x24 size to the by-user configured size (default: 700x500), and the first SIGWINCH. Then (after we've been mapped?) Sway tiles us, and we get a new size from Sway, leading to the second SIGWINCH.

Thus, waiting for the first SIGWINCH may not be enough, if the client application has racy check-size-then-register-sigwinch behavior.

Depending on compositor, there may be multiple `SIGWINCH` signals at startup. On Sway (at least older versions), there will be two. First, Sway asks us to size ourselves. This leads to a transition from the hardcoded 80x24 size to the by-user configured size (default: 700x500), and the first `SIGWINCH`. Then (after we've been mapped?) Sway tiles us, and we get a new size from Sway, leading to the second `SIGWINCH`. Thus, waiting for the first `SIGWINCH` may not be enough, if the client application has racy check-size-then-register-sigwinch behavior.
Contributor
Copy link

@dnkl if it sounds wrong for Sway to send two signals, should we file a bug?

Also, if waiting for one signal may not be enough, what other mechanism do you think we could use? Does foot itself know when it has been mapped?

@dnkl if it sounds wrong for Sway to send two signals, should we file a bug? Also, if waiting for one signal may not be enough, what other mechanism do you think we could use? Does foot itself know when it has been mapped?
Author
Owner
Copy link

if it sounds wrong for Sway to send two signals, should we file a bug?

This is a known "feature", but don't know if a bug has been filed already or not. But yes, might make sense to do that.

Also, if waiting for one signal may not be enough, what other mechanism do you think we could use? Does foot itself know when it has been mapped?

Yes, we know when we've been mapped. Implementing the --wait-for-mapped option would, of course, need to know that (fixing this bug/feature shouldn't be that hard - might even be a first-easy-one for new contributors).

But, for those waiting for this to get implemented; it may not entirely solve the problem - if the second resize happens after we've been mapped (which I'm fairly sure is the case), then we might still trip up buggy clients. But with a lower probability than today.

> if it sounds wrong for Sway to send two signals, should we file a bug? This is a known "feature", but don't know if a bug has been filed already or not. But yes, might make sense to do that. > Also, if waiting for one signal may not be enough, what other mechanism do you think we could use? Does foot itself know when it has been mapped? Yes, we know when we've been mapped. Implementing the `--wait-for-mapped` option would, of course, need to know that (fixing this bug/feature shouldn't be that hard - might even be a first-easy-one for new contributors). But, for those waiting for this to get implemented; it _may_ not entirely solve the problem - if the second resize happens after we've been mapped (which I'm fairly sure is the case), then we might _still_ trip up buggy clients. But with a lower probability than today.
Author
Owner
Copy link

if it sounds wrong for Sway to send two signals, should we file a bug?

This is a known "feature", but don't know if a bug has been filed already or not. But yes, might make sense to do that.

https://github.com/swaywm/sway/issues/2176

> > if it sounds wrong for Sway to send two signals, should we file a bug? > This is a known "feature", but don't know if a bug has been filed already or not. But yes, might make sense to do that. https://github.com/swaywm/sway/issues/2176
Collaborator
Copy link

On Sway (at least older versions), there will be two. First, Sway asks us to size ourselves. This leads to a transition from the hardcoded 80x24 size to the by-user configured size (default: 700x500), and the first SIGWINCH. Then (after we've been mapped?) Sway tiles us, and we get a new size from Sway, leading to the second SIGWINCH.

@dnkl Thanks for the info. I think I saw you mention that in one of the other issues a while back, but it must have slipped my mind.

I've changed waitwinch to wait for the second SIGWINCH and it seems to prevent the mtm prompt issue now (under Sway). It's a bit of an over-engineered workaround compared to sleep 0.1, but it seems to lower the added startup latency to about (削除) 10ms (削除ここまで) 3ms.

> On Sway (at least older versions), there will be two. First, Sway asks us to size ourselves. This leads to a transition from the hardcoded 80x24 size to the by-user configured size (default: 700x500), and the first `SIGWINCH`. Then (after we've been mapped?) Sway tiles us, and we get a new size from Sway, leading to the second `SIGWINCH`. @dnkl Thanks for the info. I think I saw you mention that in one of the other issues a while back, but it must have slipped my mind. I've changed [waitwinch](https://codeberg.org/craigbarnes/waitwinch) to wait for the second `SIGWINCH` and it seems to prevent the mtm prompt [issue](https://codeberg.org/dnkl/foot/issues/904) now (under Sway). It's a bit of an over-engineered workaround compared to `sleep 0.1`, but it seems to lower the added startup latency to about ~~10ms~~ 3ms.
Collaborator
Copy link

For anyone interested, there's now a demo program in the waitwinch repo, which can be used to visually reproduce the kind of problem seen in buggy clients (e.g. #723).

Usage example:

git clone https://codeberg.org/craigbarnes/waitwinch.git
cd waitwinch
make
# Run demo program *without* waitwinch
foot --hold ./wwdemo
footclient --hold ./wwdemo
# Run demo program *with* waitwinch
foot --hold ./waitwinch -v ./wwdemo
footclient --hold ./waitwinch -v ./wwdemo

FWIW, I've been using shell = sh -c 'exec $(command -v waitwinch) ${SHELL:-sh}' (as mentioned here) in my foot.ini for quite a while now (as well as in some wrapper scripts) and I haven't had any issues. The measured latency shown by e.g. footclient waitwinch -v bash is about 3ms (as opposed to the 100ms you'd get for sleep 0.1).

For anyone interested, there's now a [demo program](https://codeberg.org/craigbarnes/waitwinch/src/branch/master/wwdemo.c) in the [waitwinch](https://codeberg.org/craigbarnes/waitwinch) repo, which can be used to visually reproduce the kind of problem seen in buggy clients (e.g. #723). Usage example: ```sh git clone https://codeberg.org/craigbarnes/waitwinch.git cd waitwinch make # Run demo program *without* waitwinch foot --hold ./wwdemo footclient --hold ./wwdemo # Run demo program *with* waitwinch foot --hold ./waitwinch -v ./wwdemo footclient --hold ./waitwinch -v ./wwdemo ``` FWIW, I've been using `shell = sh -c 'exec $(command -v waitwinch) ${SHELL:-sh}'` (as mentioned [here](https://codeberg.org/craigbarnes/waitwinch#usage-in-foot-ini)) in my `foot.ini` for quite a while now (as well as in some wrapper scripts) and I haven't had any issues. The measured latency shown by e.g. `footclient waitwinch -v bash` is about 3ms (as opposed to the 100ms you'd get for `sleep 0.1`).
Author
Owner
Copy link

@craigbarnes that's pretty cool! Though the colors are... hard to read, to say the least, with my color theme :)

foot-waitwinch-demo.png

@craigbarnes that's pretty cool! Though the colors are... hard to read, to say the least, with my color theme :) ![foot-waitwinch-demo.png](/attachments/0d11909c-ea8a-4bb3-b1e7-ea12caa89dfb)
Collaborator
Copy link

@dnkl Thanks for the feedback! craigbarnes/waitwinch@7dc4d8e331 should hopefully make it a little more readable.

@dnkl Thanks for the feedback! https://codeberg.org/craigbarnes/waitwinch/commit/7dc4d8e331d15b0c86f1440d45930beeb1f3f924 should hopefully make it a little more readable.
Author
Owner
Copy link

Better, thanks!

Better, thanks!
Sign in to join this conversation.
No Branch/Tag specified
master
osc-5522
sixel-heap-buffer-overflow
releases/1.27
releases/1.26
releases/1.25
releases/1.24
multi-cursor
releases/1.23
pixman-16f-2
releases/1.22
releases/1.21
releases/1.20
releases/1.19
releases/1.18
releases/1.17
releases/1.16
releases/1.15
releases/1.14
releases/1.13
releases/1.12
releases/1.11
releases/1.10
releases/1.9
releases/1.8
releases/1.7
releases/1.6
releases/1.5
releases/1.4
releases/1.3
releases/1.2
releases/1.1
releases/1.0
1.27.0
1.26.1
1.26.0
1.25.0
1.24.0
1.23.1
1.23.0
1.22.3
1.22.2
1.22.1
1.22.0
1.21.0
1.20.2
1.20.1
1.20.0
1.19.0
1.18.1
1.18.0
1.17.2
1.17.1
1.17.0
1.16.2
1.16.1
1.16.0
1.15.3
1.15.2
1.15.1
1.15.0
1.14.0
1.13.1
1.13.0
1.12.1
1.12.0
1.11.0
1.10.3
1.10.2
1.10.1
1.10.0
1.9.2
1.9.1
1.9.0
1.8.2
1.8.1
1.8.0
1.7.2
1.7.1
1.7.0
1.6.4
1.6.3
1.6.2
1.6.1
1.6.0
1.5.4
1.5.3
1.5.2
1.5.1
1.5.0
1.4.4
1.4.3
1.4.2
1.4.1
1.4.0
1.3.0
1.2.3
1.2.2
1.2.1
1.2.0
1.1.0
1.0.0
0.9.0
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
dnkl/foot#453
Reference in a new issue
dnkl/foot
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?