Merge pull request #634 from a-kenji/fix/quick-tabs-621

Fix plugin attribute update on inactive tab
This commit is contained in:
a-kenji 2021-08-01 17:47:51 +02:00 committed by GitHub
commit 4417263ce4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 65 additions and 30 deletions

View file

@ -56,10 +56,10 @@ pub(crate) enum ScreenInstruction {
ClearScroll, ClearScroll,
CloseFocusedPane, CloseFocusedPane,
ToggleActiveTerminalFullscreen, ToggleActiveTerminalFullscreen,
SetSelectable(PaneId, bool), SetSelectable(PaneId, bool, usize),
SetFixedHeight(PaneId, usize), SetFixedHeight(PaneId, usize, usize),
SetFixedWidth(PaneId, usize), SetFixedWidth(PaneId, usize, usize),
SetInvisibleBorders(PaneId, bool), SetInvisibleBorders(PaneId, bool, usize),
ClosePane(PaneId), ClosePane(PaneId),
ApplyLayout(Layout, Vec<RawFd>), ApplyLayout(Layout, Vec<RawFd>),
NewTab(RawFd), NewTab(RawFd),
@ -337,6 +337,11 @@ impl Screen {
} }
} }
/// Returns a mutable reference to this [`Screen`]'s indexed [`Tab`].
pub fn get_indexed_tab_mut(&mut self, tab_index: usize) -> Option<&mut Tab> {
self.get_tabs_mut().get_mut(&tab_index)
}
/// Creates a new [`Tab`] in this [`Screen`], applying the specified [`Layout`] /// Creates a new [`Tab`] in this [`Screen`], applying the specified [`Layout`]
/// and switching to it. /// and switching to it.
pub fn apply_layout(&mut self, layout: Layout, new_pids: Vec<RawFd>) { pub fn apply_layout(&mut self, layout: Layout, new_pids: Vec<RawFd>) {
@ -355,7 +360,7 @@ impl Screen {
self.colors, self.colors,
self.session_state.clone(), self.session_state.clone(),
); );
tab.apply_layout(layout, new_pids); tab.apply_layout(layout, new_pids, tab_index);
self.active_tab_index = Some(tab_index); self.active_tab_index = Some(tab_index);
self.tabs.insert(tab_index, tab); self.tabs.insert(tab_index, tab);
self.update_tabs(); self.update_tabs();
@ -599,29 +604,53 @@ pub(crate) fn screen_thread_main(
screen.get_active_tab_mut().unwrap().close_focused_pane(); screen.get_active_tab_mut().unwrap().close_focused_pane();
screen.render(); screen.render();
} }
ScreenInstruction::SetSelectable(id, selectable) => { ScreenInstruction::SetSelectable(id, selectable, tab_index) => {
screen screen.get_indexed_tab_mut(tab_index).map_or_else(
.get_active_tab_mut() || {
.unwrap() log::warn!(
.set_pane_selectable(id, selectable); "Tab index #{} not found, could not set selectable for plugin #{:?}.",
tab_index,
id
)
},
|tab| tab.set_pane_selectable(id, selectable),
);
} }
ScreenInstruction::SetFixedHeight(id, fixed_height) => { ScreenInstruction::SetFixedHeight(id, fixed_height, tab_index) => {
screen screen.get_indexed_tab_mut(tab_index).map_or_else(
.get_active_tab_mut() || {
.unwrap() log::warn!(
.set_pane_fixed_height(id, fixed_height); "Tab index #{} not found, could not set fixed height for plugin #{:?}.",
tab_index,
id
)
},
|tab| tab.set_pane_fixed_height(id, fixed_height),
);
} }
ScreenInstruction::SetFixedWidth(id, fixed_width) => { ScreenInstruction::SetFixedWidth(id, fixed_width, tab_index) => {
screen screen.get_indexed_tab_mut(tab_index).map_or_else(
.get_active_tab_mut() || {
.unwrap() log::warn!(
.set_pane_fixed_width(id, fixed_width); "Tab index #{} not found, could not set fixed width for plugin #{:?}.",
tab_index,
id
)
},
|tab| tab.set_pane_fixed_width(id, fixed_width),
);
} }
ScreenInstruction::SetInvisibleBorders(id, invisible_borders) => { ScreenInstruction::SetInvisibleBorders(id, invisible_borders, tab_index) => {
screen screen.get_indexed_tab_mut(tab_index).map_or_else(
.get_active_tab_mut() || {
.unwrap() log::warn!(
.set_pane_invisible_borders(id, invisible_borders); r#"Tab index #{} not found, could not set invisible borders for plugin #{:?}."#,
tab_index,
id
)
},
|tab| tab.set_pane_invisible_borders(id, invisible_borders),
);
screen.render(); screen.render();
} }
ScreenInstruction::ClosePane(id) => { ScreenInstruction::ClosePane(id) => {

View file

@ -301,7 +301,7 @@ impl Tab {
} }
} }
pub fn apply_layout(&mut self, layout: Layout, new_pids: Vec<RawFd>) { pub fn apply_layout(&mut self, layout: Layout, new_pids: Vec<RawFd>, tab_index: usize) {
// TODO: this should be an attribute on Screen instead of full_screen_ws // TODO: this should be an attribute on Screen instead of full_screen_ws
let free_space = PositionAndSize { let free_space = PositionAndSize {
x: 0, x: 0,
@ -340,7 +340,7 @@ impl Tab {
if let Some(Run::Plugin(Some(plugin))) = &layout.run { if let Some(Run::Plugin(Some(plugin))) = &layout.run {
let (pid_tx, pid_rx) = channel(); let (pid_tx, pid_rx) = channel();
self.senders self.senders
.send_to_plugin(PluginInstruction::Load(pid_tx, plugin.clone())) .send_to_plugin(PluginInstruction::Load(pid_tx, plugin.clone(), tab_index))
.unwrap(); .unwrap();
let pid = pid_rx.recv().unwrap(); let pid = pid_rx.recv().unwrap();
let new_plugin = PluginPane::new( let new_plugin = PluginPane::new(

View file

@ -28,8 +28,8 @@ use zellij_utils::{input::command::TerminalAction, serde, zellij_tile};
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub(crate) enum PluginInstruction { pub(crate) enum PluginInstruction {
Load(Sender<u32>, PathBuf), Load(Sender<u32>, PathBuf, usize), // tx_pid, path_of_plugin , tab_index
Update(Option<u32>, Event), // Focused plugin / broadcast, event data Update(Option<u32>, Event), // Focused plugin / broadcast, event data
Render(Sender<String>, u32, usize, usize), // String buffer, plugin id, rows, cols Render(Sender<String>, u32, usize, usize), // String buffer, plugin id, rows, cols
Unload(u32), Unload(u32),
Exit, Exit,
@ -50,6 +50,7 @@ impl From<&PluginInstruction> for PluginContext {
#[derive(WasmerEnv, Clone)] #[derive(WasmerEnv, Clone)]
pub(crate) struct PluginEnv { pub(crate) struct PluginEnv {
pub plugin_id: u32, pub plugin_id: u32,
pub tab_index: usize,
pub senders: ThreadSenders, pub senders: ThreadSenders,
pub wasi_env: WasiEnv, pub wasi_env: WasiEnv,
pub subscriptions: Arc<Mutex<HashSet<EventType>>>, pub subscriptions: Arc<Mutex<HashSet<EventType>>>,
@ -64,7 +65,7 @@ pub(crate) fn wasm_thread_main(bus: Bus<PluginInstruction>, store: Store, data_d
let (event, mut err_ctx) = bus.recv().expect("failed to receive event on channel"); let (event, mut err_ctx) = bus.recv().expect("failed to receive event on channel");
err_ctx.add_call(ContextType::Plugin((&event).into())); err_ctx.add_call(ContextType::Plugin((&event).into()));
match event { match event {
PluginInstruction::Load(pid_tx, path) => { PluginInstruction::Load(pid_tx, path, tab_index) => {
let plugin_dir = data_dir.join("plugins/"); let plugin_dir = data_dir.join("plugins/");
let wasm_bytes = fs::read(&path) let wasm_bytes = fs::read(&path)
.or_else(|_| fs::read(&path.with_extension("wasm"))) .or_else(|_| fs::read(&path.with_extension("wasm")))
@ -100,6 +101,7 @@ pub(crate) fn wasm_thread_main(bus: Bus<PluginInstruction>, store: Store, data_d
let plugin_env = PluginEnv { let plugin_env = PluginEnv {
plugin_id, plugin_id,
tab_index,
senders: bus.senders.clone(), senders: bus.senders.clone(),
wasi_env, wasi_env,
subscriptions: Arc::new(Mutex::new(HashSet::new())), subscriptions: Arc::new(Mutex::new(HashSet::new())),
@ -193,6 +195,7 @@ fn host_set_selectable(plugin_env: &PluginEnv, selectable: i32) {
.send_to_screen(ScreenInstruction::SetSelectable( .send_to_screen(ScreenInstruction::SetSelectable(
PaneId::Plugin(plugin_env.plugin_id), PaneId::Plugin(plugin_env.plugin_id),
selectable, selectable,
plugin_env.tab_index,
)) ))
.unwrap() .unwrap()
} }
@ -204,6 +207,7 @@ fn host_set_fixed_height(plugin_env: &PluginEnv, fixed_height: i32) {
.send_to_screen(ScreenInstruction::SetFixedHeight( .send_to_screen(ScreenInstruction::SetFixedHeight(
PaneId::Plugin(plugin_env.plugin_id), PaneId::Plugin(plugin_env.plugin_id),
fixed_height, fixed_height,
plugin_env.tab_index,
)) ))
.unwrap() .unwrap()
} }
@ -215,6 +219,7 @@ fn host_set_fixed_width(plugin_env: &PluginEnv, fixed_width: i32) {
.send_to_screen(ScreenInstruction::SetFixedWidth( .send_to_screen(ScreenInstruction::SetFixedWidth(
PaneId::Plugin(plugin_env.plugin_id), PaneId::Plugin(plugin_env.plugin_id),
fixed_width, fixed_width,
plugin_env.tab_index,
)) ))
.unwrap() .unwrap()
} }
@ -226,6 +231,7 @@ fn host_set_invisible_borders(plugin_env: &PluginEnv, invisible_borders: i32) {
.send_to_screen(ScreenInstruction::SetInvisibleBorders( .send_to_screen(ScreenInstruction::SetInvisibleBorders(
PaneId::Plugin(plugin_env.plugin_id), PaneId::Plugin(plugin_env.plugin_id),
invisible_borders, invisible_borders,
plugin_env.tab_index,
)) ))
.unwrap() .unwrap()
} }