Skip to main content

Module focus_mode

Module focus_mode 

Source
Expand description

Whether the pointer gives the keyboard: as the window manager does between windows (system), or as the user chose (click, hover).

Experimental: may change in any release (docs/stability.md).

In click mode the keyboard goes where the user clicks (or tabs). In hover mode, moving the pointer over a surface (a focus scope: a panel, an editor) gives it the keys, and a text field the pointer moves over takes the keyboard (see follow_pointer); never while a button is held, a drag is in progress or an overlay (a popup, a menu, a dialog) is open.

The window manager’s way is read once, at start (read_system):

  • GNOME: gsettings get org.gnome.desktop.wm.preferences focus-mode (click, or sloppy and mouse for hover);
  • KDE: kreadconfig6 (or 5) --file kwinrc --group Windows --key FocusPolicy (ClickToFocus, or FocusFollowsMouse, FocusUnderMouse, FocusStrictlyUnderMouse for hover);
  • Windows: nothing read here, click. Spawning reg query flashed a console window at every start, and this crate has no registry access (no unsafe code, no Windows dependency). The registry is read in-process by egui_pop_platform::focus (the active window tracking bit of UserPreferencesMask, as SPI_GETACTIVEWINDOWTRACKING reports it, mapped by windows_mask): give its read() to AppBuilder::system_focus, or install its FocusModePlugin;
  • macOS and anything else: click.

The environment variable ENV (click or hover) stands in for the system, for tests and for users whose desktop is not read.

use egui_pop_core::focus_mode::{self, FocusMode, Preference, SystemFocus};

let ctx = egui::Context::default();
let modes = focus_mode::get(&ctx);
modes.set_system(SystemFocus { mode: FocusMode::Hover, from: Some("test") });
assert_eq!(modes.mode(), FocusMode::Hover);
modes.set_preference(Preference::Click);
assert_eq!(modes.mode(), FocusMode::Click);

Structs§

FocusModes
The focus mode of an application: the system’s way and the user’s choice. Cheap to clone (shared); the application provides it as a service, and a context uses one (get, set).
Report
What the debug bridge shows.
SystemFocus
The window manager’s way, as read, and where it was read.

Enums§

FocusMode
Whether the pointer gives the keyboard.
Preference
What the user chose.

Constants§

ENV
The environment variable standing in for the system: click or hover (GNOME’s sloppy and mouse are read as hover).

Functions§

follow_pointer
In hover mode, gives the keyboard to a widget (a text field) when the pointer moves over it. Call it with the widget’s response.
get
The context’s focus modes (created on first use: the system not read, click).
gnome
GNOME’s focus-mode as gsettings prints it: 'click', 'sloppy', 'mouse'.
kde
KDE’s FocusPolicy (kwinrc, group Windows); none written is a click.
mode
The mode in force in a context.
pointer_may_focus
Whether the pointer may move the keyboard focus in this pass: hover mode, the pointer moved, no button held, no drag, no overlay open.
read_system
The window manager’s way, read now (a short subprocess on Linux; click on Windows, macOS and the web: egui_pop_platform::focus::read reads Windows’ registry in-process).
read_system_with
The window manager’s way from what a reader would see: the environment variable ENV, the desktop (XDG_CURRENT_DESKTOP), and run (a program and its arguments, its output when it succeeds).
set
Makes a context use these focus modes.
windows
Windows’ UserPreferencesMask as reg query prints it (see windows_mask). Nothing here runs reg any more; kept for readers of a saved reg query output.
windows_mask
Windows’ UserPreferencesMask from its first byte: the lowest bit is active window tracking (hover), what SPI_GETACTIVEWINDOWTRACKING reports.