htop icon indicating copy to clipboard operation
htop copied to clipboard

focus in/out causes process list to be temporarily unsorted

Open pobrn opened this issue 2 years ago • 8 comments

Steps to reproduce

  1. start a terminal emulator that sends XTERM focus in/out reports (e.g. gnome-terminal)
  2. start htop
  3. select the process list view and sort by e.g. CPU usage
  4. 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

pobrn avatar Jun 11 '23 01:06 pobrn

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

russelltg avatar Jun 13 '23 21:06 russelltg

With gnome-terminal, it also happens when htop is started.

pobrn avatar Jun 13 '23 21:06 pobrn

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.

BenBE avatar Jun 14 '23 08:06 BenBE

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.

pobrn avatar Jun 15 '23 00:06 pobrn

I am seeing the exact same behavior in Konsole.

SnipeXandrej avatar Jun 17 '23 15:06 SnipeXandrej

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.

pakettiale avatar Jul 19 '23 09:07 pakettiale

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.

BenBE avatar Jul 19 '23 11:07 BenBE

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.

pakettiale avatar Jul 20 '23 13:07 pakettiale