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