diff options
| author | Daniel Jankowski <daniel.jankowski@rub.de> | 2023-09-02 11:06:04 +0200 |
|---|---|---|
| committer | Daniel Jankowski <daniel.jankowski@rub.de> | 2023-09-02 11:06:04 +0200 |
| commit | d41e4892e7a03257167f26c0a96dde84f264e34c (patch) | |
| tree | d988962fd8cb4b950e4801694d5c9982b6d8361f /src | |
| parent | chore: simplify sessions plugin (diff) | |
| download | sl0pstatus-d41e4892e7a03257167f26c0a96dde84f264e34c.tar.gz sl0pstatus-d41e4892e7a03257167f26c0a96dde84f264e34c.tar.xz sl0pstatus-d41e4892e7a03257167f26c0a96dde84f264e34c.zip | |
fix: hide frame for single panes with multiple tabs
Diffstat (limited to 'src')
| -rw-r--r-- | src/frames.rs | 51 | ||||
| -rw-r--r-- | src/main.rs | 19 |
2 files changed, 60 insertions, 10 deletions
diff --git a/src/frames.rs b/src/frames.rs index 2a4f56f..b972728 100644 --- a/src/frames.rs +++ b/src/frames.rs @@ -1,26 +1,59 @@ use zellij_tile::prelude::*; -pub fn hide_frames_on_single_pane(tabs: Vec<TabInfo>, pane_info: PaneManifest) { - let active_tab = tabs.into_iter().find(|t| t.active); - if active_tab.is_none() { +pub fn hide_frames_on_single_pane( + tabs: Vec<TabInfo>, + pane_info: PaneManifest, + plugin_pane_id: PluginIds, +) { + let panes = get_current_panes(tabs, pane_info); + if panes.is_none() { return; } - let active_tab_id = active_tab.unwrap().position; + let panes = panes.unwrap(); - let panes = pane_info.panes.get(&active_tab_id); - if panes.is_none() { + // check if we are running for the current tab since one plugin will run for + // each tab. If we do not prevent execution, the screen will start to flicker + // 'cause every plugin will try to toggle the frames + if !is_plugin_for_current_tab(panes.clone(), plugin_pane_id) { return; } - let panes = panes.unwrap(); let panes: Vec<&PaneInfo> = panes.iter().filter(|p| !p.is_plugin).collect(); - if panes.len() == 1 && panes.first().unwrap().pane_content_x == 1 { + let first_content_pane = panes.first(); + if first_content_pane.is_none() { + return; + } + let first_pane = first_content_pane.unwrap(); + + // frame is enabled, when content does no start at [0, 0]. With default frames + // it's [1, 1] + let frame_enabled = first_pane.pane_content_x > 0; + + if panes.len() == 1 && frame_enabled { toggle_pane_frames(); } - if panes.len() > 1 && panes.first().unwrap().pane_content_x == 0 { + if panes.len() > 1 && !frame_enabled { toggle_pane_frames(); } } + +fn is_plugin_for_current_tab(panes: Vec<PaneInfo>, plugin_pane_id: PluginIds) -> bool { + let plugin_pane = panes + .iter() + .find(|p| p.is_plugin && p.id == plugin_pane_id.plugin_id); + + plugin_pane.is_some() +} + +fn get_current_panes(tabs: Vec<TabInfo>, pane_info: PaneManifest) -> Option<Vec<PaneInfo>> { + let active_tab = tabs.iter().find(|t| t.active); + let active_tab = active_tab.as_ref()?; + + pane_info + .panes + .get(&active_tab.position) + .map(|p| (*p).clone()) +} diff --git a/src/main.rs b/src/main.rs index 9fc7681..5fe34f9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -74,13 +74,30 @@ impl ZellijPlugin for State { } Event::PaneUpdate(pane_info) => { if self.module_config.hide_frame_for_single_pane { - frames::hide_frames_on_single_pane(self.state.tabs.clone(), pane_info); + frames::hide_frames_on_single_pane( + self.state.tabs.clone(), + pane_info, + get_plugin_ids(), + ); should_render = true; } } Event::SessionUpdate(session_info) => { + if self.module_config.hide_frame_for_single_pane { + let current_session = session_info.iter().find(|s| s.is_current_session); + + if let Some(current_session) = current_session { + frames::hide_frames_on_single_pane( + current_session.clone().tabs, + current_session.clone().panes, + get_plugin_ids(), + ); + } + } + self.state.sessions = session_info; + should_render = true; } Event::TabUpdate(tab_info) => { |
