mirror of
https://github.com/wez/wezterm.git
synced 2024-12-22 12:51:31 +03:00
add window:is_focused() method
refs: https://github.com/wez/wezterm/discussions/2537
This commit is contained in:
parent
c91d6c396c
commit
9a7aad0200
@ -34,6 +34,9 @@ As features stabilize some brief notes about them will accumulate here.
|
||||
* [wezterm cli activate-pane-direction](cli/cli/activate-pane-direction.md)
|
||||
command. Thanks to [@abusch](https://github.com/abusch)!
|
||||
[#2526](https://github.com/wez/wezterm/pull/2526)
|
||||
* [window:is_focused()](config/lua/window/is_focused.md) method for testing
|
||||
whether a GUI window has focus.
|
||||
[#2537](https://github.com/wez/wezterm/discussions/2537)
|
||||
|
||||
#### Fixed
|
||||
* Wayland: key repeat gets stuck after pressing two keys in quick succession.
|
||||
|
26
docs/config/lua/window/is_focused.md
Normal file
26
docs/config/lua/window/is_focused.md
Normal file
@ -0,0 +1,26 @@
|
||||
# wezterm:is_focused()
|
||||
|
||||
*Since: nightly builds only*
|
||||
|
||||
Returns `true` if the window has focus.
|
||||
|
||||
The `update-status` event is fired when the focus state changes.
|
||||
|
||||
This example changes the color scheme based on the focus state:
|
||||
|
||||
```lua
|
||||
local wezterm = require 'wezterm'
|
||||
|
||||
wezterm.on('update-status', function(window, pane)
|
||||
local overrides = window:get_config_overrides() or {}
|
||||
if window:is_focused() then
|
||||
overrides.color_scheme = 'nordfox'
|
||||
else
|
||||
overrides.color_scheme = 'nightfox'
|
||||
end
|
||||
window:set_config_overrides(overrides)
|
||||
end)
|
||||
|
||||
return {}
|
||||
```
|
||||
|
@ -184,6 +184,20 @@ impl UserData for GuiWin {
|
||||
.notify(TermWindowNotif::SetConfigOverrides(value));
|
||||
Ok(())
|
||||
});
|
||||
methods.add_async_method("is_focused", |_, this, _: ()| async move {
|
||||
let (tx, rx) = smol::channel::bounded(1);
|
||||
this.window
|
||||
.notify(TermWindowNotif::Apply(Box::new(move |term_window| {
|
||||
tx.try_send(term_window.focused.is_some()).ok();
|
||||
})));
|
||||
let result = rx
|
||||
.recv()
|
||||
.await
|
||||
.map_err(|e| anyhow::anyhow!("{:#}", e))
|
||||
.map_err(luaerr)?;
|
||||
|
||||
Ok(result)
|
||||
});
|
||||
methods.add_async_method("leader_is_active", |_, this, _: ()| async move {
|
||||
let (tx, rx) = smol::channel::bounded(1);
|
||||
this.window
|
||||
|
@ -351,7 +351,7 @@ pub struct TermWindow {
|
||||
pub config_overrides: wezterm_dynamic::Value,
|
||||
os_parameters: Option<parameters::Parameters>,
|
||||
/// When we most recently received keyboard focus
|
||||
focused: Option<Instant>,
|
||||
pub focused: Option<Instant>,
|
||||
fonts: Rc<FontConfiguration>,
|
||||
/// Window dimensions and dpi
|
||||
pub dimensions: Dimensions,
|
||||
@ -525,6 +525,8 @@ impl TermWindow {
|
||||
if let Some(pane) = self.get_active_pane_or_overlay() {
|
||||
pane.focus_changed(focused);
|
||||
}
|
||||
|
||||
self.update_title();
|
||||
}
|
||||
|
||||
fn created(
|
||||
|
Loading…
Reference in New Issue
Block a user