mirror of
https://github.com/wez/wezterm.git
synced 2024-11-27 02:25:28 +03:00
macos: floating window logic cleanup
This commit is contained in:
parent
2e66a4b0df
commit
9901866962
@ -501,13 +501,20 @@ fn default_fuzzy_description() -> String {
|
||||
"Fuzzy matching: ".to_string()
|
||||
}
|
||||
|
||||
// FIXME: this is so ugly we should use `window::WindowLevel` instead
|
||||
#[derive(Debug, Clone, PartialEq, FromDynamic, ToDynamic)]
|
||||
pub enum SetWindowLevelLevel {
|
||||
Normal,
|
||||
AlwaysOnTop,
|
||||
AlwaysOnBottom,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, FromDynamic, ToDynamic)]
|
||||
pub enum KeyAssignment {
|
||||
SpawnTab(SpawnTabDomain),
|
||||
SpawnWindow,
|
||||
ToggleFullScreen,
|
||||
ToggleAlwaysOnTop,
|
||||
ToggleAlwaysOnBottom,
|
||||
SetWindowLevel(SetWindowLevelLevel),
|
||||
CopyTo(ClipboardCopyDestination),
|
||||
CopyTextTo {
|
||||
text: String,
|
||||
|
@ -681,20 +681,28 @@ pub fn derive_command_from_key_assignment(action: &KeyAssignment) -> Option<Comm
|
||||
menubar: &["View"],
|
||||
icon: Some("md_fullscreen"),
|
||||
},
|
||||
ToggleAlwaysOnTop => CommandDef {
|
||||
SetWindowLevel(SetWindowLevelLevel::AlwaysOnTop) => CommandDef {
|
||||
brief: "Always on Top".into(),
|
||||
doc: "Toggles the window between floating and non-floating states to stay on top of other windows.".into(),
|
||||
keys: vec![],
|
||||
args: &[ArgType::ActiveWindow],
|
||||
menubar: &["Window"],
|
||||
menubar: &["Window", "Level"],
|
||||
icon: None,
|
||||
},
|
||||
ToggleAlwaysOnBottom => CommandDef {
|
||||
SetWindowLevel(SetWindowLevelLevel::Normal) => CommandDef {
|
||||
brief: "Normal".into(),
|
||||
doc: "Set window level to normal".into(),
|
||||
keys: vec![],
|
||||
args: &[ArgType::ActiveWindow],
|
||||
menubar: &["Window", "Level"],
|
||||
icon: None,
|
||||
},
|
||||
SetWindowLevel(SetWindowLevelLevel::AlwaysOnBottom) => CommandDef {
|
||||
brief: "Always on Bottom".into(),
|
||||
doc: "Toggles the window to remain behind all other windows.".into(),
|
||||
keys: vec![],
|
||||
args: &[ArgType::ActiveWindow],
|
||||
menubar: &["Window"],
|
||||
menubar: &["Window", "Level"],
|
||||
icon: None,
|
||||
},
|
||||
Hide => CommandDef {
|
||||
@ -2032,8 +2040,11 @@ fn compute_default_actions() -> Vec<KeyAssignment> {
|
||||
ScrollToBottom,
|
||||
// ----------------- Window
|
||||
ToggleFullScreen,
|
||||
ToggleAlwaysOnTop,
|
||||
ToggleAlwaysOnBottom,
|
||||
|
||||
SetWindowLevel(SetWindowLevelLevel::AlwaysOnBottom),
|
||||
SetWindowLevel(SetWindowLevelLevel::Normal),
|
||||
SetWindowLevel(SetWindowLevelLevel::AlwaysOnTop),
|
||||
|
||||
Hide,
|
||||
Search(Pattern::CurrentSelectionOrEmptyString),
|
||||
PaneSelect(PaneSelectArguments {
|
||||
|
@ -30,7 +30,7 @@ use ::window::*;
|
||||
use anyhow::{anyhow, ensure, Context};
|
||||
use config::keyassignment::{
|
||||
KeyAssignment, PaneDirection, Pattern, PromptInputLine, QuickSelectArguments,
|
||||
RotationDirection, SpawnCommand, SplitSize,
|
||||
RotationDirection, SpawnCommand, SplitSize, SetWindowLevelLevel,
|
||||
};
|
||||
use config::{
|
||||
configuration, AudibleBell, ConfigHandle, Dimension, DimensionContext, FrontEndSelection,
|
||||
@ -2507,45 +2507,33 @@ impl TermWindow {
|
||||
ToggleFullScreen => {
|
||||
self.window.as_ref().unwrap().toggle_fullscreen();
|
||||
}
|
||||
// TODO: check what happens if we enable always on top when is always on bottom
|
||||
ToggleAlwaysOnBottom => {
|
||||
SetWindowLevel(level) => {
|
||||
let window = self.window.clone().unwrap();
|
||||
let is_always_on_top = self.window_state.intersects(WindowState::ALWAYS_ON_TOP);
|
||||
let is_always_on_bottom = self.window_state.intersects(WindowState::ALWAYS_ON_BOTTOM);
|
||||
|
||||
// check if always on top is enabled.
|
||||
// if it is, disable it to prevent impossible state.
|
||||
if is_always_on_top {
|
||||
self.window_state -= WindowState::ALWAYS_ON_TOP;
|
||||
}
|
||||
}
|
||||
|
||||
if is_always_on_bottom {
|
||||
window.set_window_level(WindowLevel::Normal);
|
||||
self.window_state -= WindowState::ALWAYS_ON_BOTTOM;
|
||||
} else {
|
||||
window.set_window_level(WindowLevel::AlwaysOnBottom);
|
||||
self.window_state = self.window_state | WindowState::ALWAYS_ON_BOTTOM;
|
||||
}
|
||||
|
||||
match level {
|
||||
SetWindowLevelLevel::AlwaysOnTop => {
|
||||
window.set_window_level(WindowLevel::AlwaysOnTop);
|
||||
self.window_state = self.window_state | WindowState::ALWAYS_ON_TOP;
|
||||
}
|
||||
SetWindowLevelLevel::AlwaysOnBottom => {
|
||||
window.set_window_level(WindowLevel::AlwaysOnBottom);
|
||||
self.window_state = self.window_state | WindowState::ALWAYS_ON_BOTTOM;
|
||||
}
|
||||
SetWindowLevelLevel::Normal => {
|
||||
window.set_window_level(WindowLevel::Normal);
|
||||
}
|
||||
}
|
||||
},
|
||||
ToggleAlwaysOnTop => {
|
||||
let window = self.window.clone().unwrap();
|
||||
let is_always_on_top = self.window_state.intersects(WindowState::ALWAYS_ON_TOP);
|
||||
let is_always_on_bottom = self.window_state.intersects(WindowState::ALWAYS_ON_BOTTOM);
|
||||
|
||||
// check if always on bottom is enabled.
|
||||
// if it is, disable it to prevent impossible state.
|
||||
if is_always_on_bottom {
|
||||
self.window_state -= WindowState::ALWAYS_ON_BOTTOM;
|
||||
}
|
||||
|
||||
if is_always_on_top {
|
||||
window.set_window_level(WindowLevel::Normal);
|
||||
self.window_state -= WindowState::ALWAYS_ON_TOP;
|
||||
} else {
|
||||
window.set_window_level(WindowLevel::AlwaysOnTop);
|
||||
self.window_state = self.window_state | WindowState::ALWAYS_ON_TOP;
|
||||
}
|
||||
}
|
||||
CopyTo(dest) => {
|
||||
let text = self.selection_text(pane);
|
||||
self.copy_to_clipboard(*dest, text);
|
||||
|
@ -71,6 +71,13 @@ pub enum MouseCursor {
|
||||
SizeLeftRight,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum WindowLevel {
|
||||
AlwaysOnBottom = -1,
|
||||
Normal = 0,
|
||||
AlwaysOnTop = 3,
|
||||
}
|
||||
|
||||
/// Represents the preferred appearance of the windowing
|
||||
/// environment.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
|
@ -8,7 +8,7 @@ use crate::connection::ConnectionOps;
|
||||
use crate::os::macos::menu::{MenuItem, RepresentedItem};
|
||||
use crate::parameters::{Border, Parameters, TitleBar};
|
||||
use crate::{
|
||||
Clipboard, Connection, DeadKeyStatus, Dimensions, Handled, KeyCode, KeyEvent, Modifiers,
|
||||
Clipboard, WindowLevel, Connection, DeadKeyStatus, Dimensions, Handled, KeyCode, KeyEvent, Modifiers,
|
||||
MouseButtons, MouseCursor, MouseEvent, MouseEventKind, MousePress, Point, RawKeyEvent, Rect,
|
||||
RequestedWindowGeometry, ResolvedGeometry, ScreenPoint, Size, ULength, WindowDecorations,
|
||||
WindowEvent, WindowEventSender, WindowOps, WindowState,
|
||||
@ -1078,13 +1078,6 @@ impl WindowInner {
|
||||
|
||||
/// @see https://developer.apple.com/documentation/appkit/nswindow/level
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum WindowLevel {
|
||||
AlwaysOnBottom = -1,
|
||||
Normal = 0,
|
||||
AlwaysOnTop = 3,
|
||||
}
|
||||
|
||||
|
||||
impl WindowInner {
|
||||
fn show(&mut self) {
|
||||
|
Loading…
Reference in New Issue
Block a user