htop
htop copied to clipboard
focus in/out causes process list to be temporarily unsorted
Steps to reproduce
- start a terminal emulator that sends XTERM focus in/out reports (e.g.
gnome-terminal) - start
htop - select the process list view and sort by e.g. CPU usage
- focus a different window
Actual behaviour
Observe that process list will not be sorted for the next 4 updates.
Expected behaviour
The process list continues to be sorted.
Cause
This is because VTE (that gnome-terminal uses) sends XTERM focus in/out reports (588 and 589 as returned by Panel_getCh(), respectively), and those are handled in the default branch of switch case at ScreenManager.c:412, where sortTimeout is set to 5.
More info about these "keys": https://github.com/vim/vim/blob/10e8ff9b26078994cae57c2422b145d37aaf714e/src/term.c#L2220
I think I'm running into this issue--i'm not 100% what triggers it but definitely running into an issue where sort is incorrect for several seconds (but then it recovers--in this video I force a resort with t t)
https://github.com/htop-dev/htop/assets/7105082/96c3ce52-13da-4f74-b47f-b046637b4a79
With gnome-terminal, it also happens when htop is started.
There is a feature in htop that disables sorting, when an input is made. This is in order to allow properly selecting a process even on somewhat busy systems.
That's reasonable, but focus in/out probably shouldn't be considered "input" the same way as a mouse click, arrows, or other key presses. Unfortunately there don't seem to be named constants for these two "keys" in ncurses, so I don't know what would be the best way to handle them.
I am seeing the exact same behavior in Konsole.
In sway htop window becoming focused causes the sorting direction to change. So by repeatedly moving cursor in and out of the window in can change sort direction up and down. Direction does NOT reset after some updates.
In sway htop window becoming focused causes the sorting direction to change. So by repeatedly moving cursor in and out of the window in can change sort direction up and down. Direction does NOT reset after some updates.
If the focus change modifies the sorting direction in htop you should check your terminal for the proper key mapping. On a low level there's not much that can be done when the key codes are mapped incorrectly by your terminal.
If the focus change modifies the sorting direction in htop you should check your terminal for the proper key mapping. On a low level there's not much that can be done when the key codes are mapped incorrectly by your terminal.
Looks like ncurses broke the terminfo file that I'm using.