lua: add wezterm.gui.gui_window_for_mux_window()
This is the inverse of wezterm.mux.get_window()
This commit is contained in:
1 parent
f7848cf96d
commit
87ce88b924
4 files changed
+41
-1
No files matched your search
@@ -1,3 +1,4 @@
|
||||
use crate::scripting::guiwin::GuiWin;
|
||||
use crate::termwindow::TermWindowNotif;
|
||||
use crate::TermWindow;
|
||||
use ::window::*;
|
||||
@@ -276,6 +277,19 @@ impl GuiFrontEnd {
|
||||
pub fn is_switching_workspace(&self) -> bool {
|
||||
*self.switching_workspaces.borrow()
|
||||
}
|
||||
|
||||
pub fn gui_window_for_mux_window(&self, mux_window_id: MuxWindowId) -> Option<GuiWin> {
|
||||
let windows = self.known_windows.borrow();
|
||||
for (window, v) in windows.iter() {
|
||||
if *v == mux_window_id {
|
||||
return Some(GuiWin {
|
||||
mux_window_id,
|
||||
window: window.clone(),
|
||||
});
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
|
||||
@@ -986,6 +986,7 @@ fn run() -> anyhow::Result<()> {
|
||||
// GUI environment specific and env_bootstrap is used to setup the
|
||||
// headless mux server.
|
||||
config::lua::add_context_setup_func(window_funcs::register);
|
||||
config::lua::add_context_setup_func(crate::scripting::register);
|
||||
|
||||
stats::Stats::init()?;
|
||||
let _saver = umask::UmaskSaver::new();
|
||||
|
||||
@@ -18,7 +18,7 @@ use window::{Connection, ConnectionOps, DeadKeyStatus, WindowOps, WindowState};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct GuiWin {
|
||||
mux_window_id: MuxWindowId,
|
||||
pub mux_window_id: MuxWindowId,
|
||||
pub window: ::window::Window,
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,31 @@
|
||||
use crate::frontend::try_front_end;
|
||||
use config::lua::get_or_create_sub_module;
|
||||
use config::lua::mlua::{self, Lua};
|
||||
use mux::window::WindowId as MuxWindowId;
|
||||
|
||||
pub mod guiwin;
|
||||
pub mod pane;
|
||||
|
||||
fn luaerr(err: anyhow::Error) -> mlua::Error {
|
||||
mlua::Error::external(err)
|
||||
}
|
||||
|
||||
pub fn register(lua: &Lua) -> anyhow::Result<()> {
|
||||
let window_mod = get_or_create_sub_module(lua, "gui")?;
|
||||
|
||||
window_mod.set(
|
||||
"gui_window_for_mux_window",
|
||||
lua.create_function(|_, mux_window_id: MuxWindowId| {
|
||||
let fe =
|
||||
try_front_end().ok_or_else(|| mlua::Error::external("not called on gui thread"))?;
|
||||
let win = fe.gui_window_for_mux_window(mux_window_id).ok_or_else(|| {
|
||||
mlua::Error::external(format!(
|
||||
"mux window id {mux_window_id} is not currently associated with a gui window"
|
||||
))
|
||||
})?;
|
||||
Ok(win)
|
||||
})?,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in new issue
Block a user