tk_focusNext(3tk)

πŸ“¦
version 9.0.4 Β· 2 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

✨ NAME ✨

tk_focusNext, tk_focusPrev, tk_focusFollowsMouse β€” the lil utility squad that handles input focus management πŸ’… (this is tk_focusNext(3tk), from the Tk Built-In Commands fam, hiii 🫢)


🌸 SYNOPSIS 🌸

tk_focusNext window
tk_focusPrev window
tk_focusFollowsMouse

πŸ¦‹ DESCRIPTION πŸ¦‹

Okay so bestie, let me put you on. tk_focusNext is a utility procedure for keyboard traversal β€” it hands you back the β€œnext” window after window in focus order. Iconic behaviour, honestly.

So how is the focus order decided? Two things, and only two: the stacking order of windows, and the structure of the window hierarchy. That's it, that's the whole vibe.

Among siblings, focus order == stacking order, and the lowest window comes first. The way that works is: if a window has children, the window itself gets visited first πŸ‘‘, then its children (recursively, yes queen, all the way down πŸŒ€), and then its next sibling. Also β€” top-level windows other than window get skipped, so tk_focusNext will never return a window in a different top-level from window. No cross-top-level shenanigans, periodt.

Once it's computed the next window, tk_focusNext peeks at that window's -takefocus option to see if it should be skipped. If it should, tk_focusNext just keeps going β€” next window in focus order, and the next, and the next β€” until it either finds a window that will actually accept the focus, or it loops all the way back to window. 🎯

tk_focusPrev? Literally the same energy, except it returns the window just before window in the focus order. Mirror version, no cap. πŸͺž


πŸŽ€ tk_focusFollowsMouse πŸŽ€

This one is a whole personality change for your app β€” it switches the focus model to an implicit one where the window under the mouse gets the focus πŸ–±οΈβœ¨.

After you call this procedure, whenever the mouse enters a window, Tk will automatically give it the input focus. You can still use the focus command to move focus to a window other than the one under the mouse β€” but the absolute second the mouse moves into a new window, the focus jumps to that one instead. It's giving very "wherever the mouse goes, I go" πŸ˜­πŸ’–

⚠️ Heads up bestie: at present there is no built-in support for returning the application to an explicit focus model. If you wanna go back, you have to write a script yourself that deletes the bindings created by tk_focusFollowsMouse. So like... choose wisely before you commit πŸ’€

πŸ‘‘ KEYWORDS πŸ‘‘

  • focus
  • keyboard traversal
  • top-level

And that's the whole page, bestie!! This lil masterpiece is from the Tk Built-In Commands, version 4.0, and the page itself is tk_focusNext(3tk) β€” go forth and traverse those windows like the main character you are πŸŒˆβ­πŸ’œ

πŸ“¦ where this page comes from