applets/mediacontroller: several fixes and improvements to keyboard navigation
Reason for the change
- applets/mediacontroller: fix backtab in standalone widget
In the standalone version, backtab gets stuck on the tabbar. Because of the KeyNavigation.tab set on the representation, backtab on the tabbar tries to go there, but it does not itself have a backtab target set and can't itself take focus, so it ends up stuck. In the tray version, this is resolved by the tray setting a backtab target there that goes to the tray header items (pin button etc.)
Instead, set a backtab target on the TabBar explicitly, targeting the other end of the applet's tab chain if there's no backtab target set on the representation.
- applets/mediacontroller: keep model and TabBar index in sync
The TabBar's currentIndex is bound to the mpris model's current index. They can still go out of sync though, in at least two instances: one is when the user presses left or right arrow keys on the tab bar; in contrast to other TabBars in Plasma applets (like Weather or Volume), the content does not automatically update when the tab is selected, but only when it is clicked or space is pressed after clicking it. The other happens in particular during startup if players are already running. As players get added, the currentIndex may change from the single player to the default player, and TabBar "helpfully" notices this and updates its own index to keep the current one active, breaking the sync. This happens after the binding is computed, so will remain broken until the model's currentIndex is updated independently. These two are somewhat at odds with each other: in case the user changes the TabBar's current index, we want the model's currentIndex to follow, but in the case of TabBar changing the index on its own, we want to leave it at "automatic" so it shows the application playing media right now (unless the user specified an application manually)
So we need to separate the two cases. We handle arrow keys by explicitly setting setting the model's currentIndex, and letting the property binding handle the tab bar. If the tabbar's currentIndex becomes different from the models, we force it to stay with the model instead.
- applets/mediacontroller: allow tab changes with Alt+number
Alt+1 to Alt+0 are a common shortcut in KDE Applications such as Kate and Dolphin to switch between the first 10 tabs. The media controller applet has potentially many tabs from different media players, browsers, KDE Connect devices etc., but does not support these shortcuts.
This change adds support for Alt+1 to Alt+0.
- applets/mediacontroller: make ctrl-tab work better
Mediacontroller has mcuh of its keybaord behavior in a onReleased handler to have better seeking behavior. This creates a conflict between the Ctrl+Tab tab switching and KeyNavigation.Tab handler, as that trigger is on press and so gets activated before the tab-switching code does. As a consequence, Ctrl+Tab only works every other press, which combined with duplicated content (from the "Choose Automatically" button) and a lack of visual feedback makes for a rather awkward experience. Ctrl+Backtab also does not work at all, as backtab from the tab bar is itself broken and interferes with Ctrl+Backtab.
Instead, we move Ctrl+(Back)tab handling into the onPressed trigger, which solves the issue and makes at least Ctrl+Backtab work.
Test plan
Should be clear from the descriptions I hope.
Screenshots or screen recordings
N/A
Bugs fixed
BUG: 501174 FIXED-IN: 6.4.0