pub struct WindowState { /* private fields */ }Expand description
A refcounted handle to a single window’s reactive state.
Cloning gives you another handle to the same underlying state.
Widgets should store a WindowState clone when they need to read
or write window-level signals outside of a single build() call.
Implementations§
Source§impl WindowState
impl WindowState
Sourcepub fn new(init: WindowStateInit) -> Self
pub fn new(init: WindowStateInit) -> Self
Construct a new state from initial values.
Wires an observer on every signal that pushes a matching
WindowCommand onto the pending queue, guarded by
WindowStateInner::applying_from_os.
pub fn id(&self) -> TeksiloWindowId
pub fn string_id(&self) -> Option<&str>
pub fn placement(&self) -> &Signal<WindowPlacement>
pub fn title(&self) -> &Signal<String>
pub fn size(&self) -> &Signal<(u32, u32)>
pub fn position(&self) -> &Signal<(i32, i32)>
pub fn focused(&self) -> &Signal<bool>
pub fn resizable(&self) -> &Signal<bool>
pub fn always_on_top(&self) -> &Signal<bool>
Sourcepub fn caps_lock(&self) -> &Signal<bool>
pub fn caps_lock(&self) -> &Signal<bool>
Caps Lock active state. OS-driven only — the window manager
toggles it on each Key::CapsLock press. Read this (e.g. via
ctx.window()) to drive a Caps Lock warning on password fields.
Sourcepub fn alt_down(&self) -> &Signal<bool>
pub fn alt_down(&self) -> &Signal<bool>
Whether the Alt key is currently held down. OS-driven only — the
window manager flips this from winit’s ModifiersChanged, where
winit reports modifier keys. Read
this to drive mnemonic-underline visibility on menus and menubars.
See the menubar key-dispatch documentation for the full Alt-tap
/ Alt+letter / mnemonic-underline contract.
Sourcepub fn other_key_pressed_during_alt(&self) -> bool
pub fn other_key_pressed_during_alt(&self) -> bool
Read whether any non-Alt key has been pressed during the
current Alt-hold window. false means the user has not
composed a chord since pressing Alt, so the next Alt release
is a bare-Alt tap if this window saw the press (see
note_alt_key_from_os).
Install (or replace) the per-window menubar key dispatcher.
Returns a super::menubar_dispatcher::MenubarGuard that
clears the slot on drop iff it still points at this exact
dispatcher (Rc::ptr_eq).
At most one dispatcher is supported per window. A second
install while another is still live debug_assert!s and
overwrites in release. This matches the “one MenuBar per
window” invariant the framework enforces upstream.
Snapshot of the currently-installed menubar dispatcher. Used by
teksilo-app’s key-event arm to consult the menubar BEFORE
focus-based dispatch. Returns None when no MenuBar is
mounted in this window.
Sourcepub fn request_attention(&self, kind: UserAttentionKind)
pub fn request_attention(&self, kind: UserAttentionKind)
Request user attention (bouncing dock icon on macOS, flashing
taskbar on Windows). Queues a WindowCommand::RequestAttention
command for the next drain.
Sourcepub fn focus(&self)
pub fn focus(&self)
Focus this window — raise it above others and give it keyboard
focus. Queues a WindowCommand::Focus command for the next
drain, carrying (and clearing) any token set via
WindowState::set_activation_token.
Sourcepub fn set_activation_token(&self, token: String)
pub fn set_activation_token(&self, token: String)
Stash an xdg_activation_v1 token — an opaque string minted by the
focused requester and handed across a process boundary — to be consumed
by the next WindowState::focus. Only affects a Wayland raise;
ignored on every other platform, where focus() raises on its own.
Sourcepub fn close(&self)
pub fn close(&self)
Close this window. Queues a WindowCommand::Close command
for the next drain.
Source§impl WindowState
impl WindowState
Sourcepub fn drain_os_commands(&self) -> Vec<WindowCommand>
pub fn drain_os_commands(&self) -> Vec<WindowCommand>
Drain the pending OS-command queue.
Sourcepub fn set_placement_from_os(&self, p: WindowPlacement)
pub fn set_placement_from_os(&self, p: WindowPlacement)
OS-originated placement write. Observers do not push back to the OS while the guard is set.
pub fn set_title_from_os(&self, title: String)
pub fn set_size_from_os(&self, size: (u32, u32))
pub fn set_position_from_os(&self, position: (i32, i32))
pub fn set_focused_from_os(&self, focused: bool)
pub fn set_resizable_from_os(&self, resizable: bool)
pub fn set_always_on_top_from_os(&self, on_top: bool)
Sourcepub fn set_caps_lock_from_os(&self, active: bool)
pub fn set_caps_lock_from_os(&self, active: bool)
Update Caps Lock state from the OS. No observer / command is wired (the app never drives the keyboard lock), so this writes the signal directly. Idempotent: skips the write when unchanged to avoid spurious repaints on auto-repeat.
Sourcepub fn set_alt_from_os(&self, active: bool)
pub fn set_alt_from_os(&self, active: bool)
Update Alt-held state from the OS. Resets the
other_key_pressed_during_alt flag on every Alt KeyDown
edge so each Alt-hold window starts fresh. Idempotent.
Sourcepub fn note_non_alt_keydown_during_alt(&self)
pub fn note_non_alt_keydown_during_alt(&self)
Mark that a non-Alt key was pressed while Alt is currently
held. Sticky — only cleared by the next
set_alt_from_os(true) edge. No-op
when Alt is not held. Idempotent.
Sourcepub fn note_close_request_from_os(&self)
pub fn note_close_request_from_os(&self)
The OS asked to close the window. With Alt held this was Alt+F4,
whose F4 winit does not report on Windows (it leaves it to
DefWindowProc), so the hold is a chord and its release no tap. The
window stays open when an in-window modal took the request, and the
release would otherwise put its menu bar in keyboard mode.
Sourcepub fn note_alt_key_from_os(&self, pressed: bool, alone: bool) -> bool
pub fn note_alt_key_from_os(&self, pressed: bool, alone: bool) -> bool
A real press or release of an Alt key in this window, never a
synthetic one (the keys a window is told are held as it takes or
loses the focus). Returns true for the release that ends a bare Alt
tap: this window saw the press, and no other key went down before
the release.
alone is whether no other modifier (Control, Shift, Super) was
already held as Alt went down; it is read on the press only. Alt+Shift,
Ctrl+Alt and the like are chords, not the lone Alt that opens the menu
bar, even when the key that completes them never reaches the window
(an input method swallows it).