Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macos: floating window support #4567

Merged
merged 31 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
e7e3938
macos: added floating window
rawnly Nov 12, 2023
9d000ac
macos: added platform checks for `ToggleFloatingWindow`
rawnly Nov 12, 2023
3a08d4b
docs: `ToggleFloatingWindow` docs
rawnly Nov 12, 2023
fe7fafe
macos: updated `WindowLevel` enum
rawnly Nov 12, 2023
8375ddc
fmt: run fmt
rawnly Nov 12, 2023
4ba147e
macos: removed `cfg` on `ToggleFloatingWindow`
Nov 27, 2023
4391a6e
macos: remove `level()` function in window
Nov 27, 2023
119a53e
macos: refactor `set_window_level`
Nov 27, 2023
4ef0dac
macos: cleanup
Nov 27, 2023
a4aeaf1
macos: save window level on window_state
rawnly Nov 30, 2023
877af4f
macos: floating window logic cleanup
rawnly Nov 30, 2023
add7b8d
fix: refactor window level + Toggle options
rawnly Dec 1, 2023
140acf3
fix: moved window level state update
rawnly Dec 2, 2023
204ee31
docs: added window level options
rawnly Dec 2, 2023
276423a
Update docs/config/lua/keyassignment/ToggleAlwaysOnTop.md
rawnly Dec 2, 2023
2e43650
Update docs/config/lua/keyassignment/ToggleAlwaysOnBottom.md
rawnly Dec 2, 2023
1fcced9
Update docs/config/lua/keyassignment/ToggleAlwaysOnBottom.md
rawnly Dec 2, 2023
1055161
Update docs/config/lua/keyassignment/SetWindowLevel.md
rawnly Dec 2, 2023
aab2918
Update docs/config/lua/keyassignment/ToggleAlwaysOnTop.md
rawnly Dec 2, 2023
c60ed22
Update docs/config/lua/keyassignment/SetWindowLevel.md
rawnly Dec 2, 2023
c0a0650
Update docs/config/lua/keyassignment/SetWindowLevel.md
rawnly Dec 2, 2023
16a35ad
macos: code cleanup
rawnly Dec 2, 2023
e0e21f7
chore: run fmt
rawnly Dec 2, 2023
e6e2da2
Update window/src/os/macos/window.rs
rawnly Dec 3, 2023
7a38c45
chore: moved comment
rawnly Dec 3, 2023
ae6f461
Merge branch 'main' of github.com:rawnly/wezterm
rawnly Dec 3, 2023
10401a9
docs: docs update with macos warning
rawnly Dec 3, 2023
94c7038
docs: fixed spacing
rawnly Dec 3, 2023
d8076f2
Update SetWindowLevel.md
rawnly Dec 4, 2023
1aba5a0
Update docs/config/lua/keyassignment/SetWindowLevel.md
rawnly Dec 4, 2023
360af06
docs: updated docs
rawnly Dec 4, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions config/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,20 @@ pub enum WindowLevel {
Normal = 0,
AlwaysOnTop = 3,
}

impl Default for WindowLevel {
fn default() -> Self {
WindowLevel::Normal
}
}

impl From<i64> for WindowLevel {
fn from(level: i64) -> Self {
match level {
-1 => WindowLevel::AlwaysOnBottom,
0 => WindowLevel::Normal,
3 => WindowLevel::AlwaysOnTop,
_ => panic!("Invalid window level: {}", level),
}
}
}
rawnly marked this conversation as resolved.
Show resolved Hide resolved
45 changes: 3 additions & 42 deletions wezterm-gui/src/termwindow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2514,16 +2514,9 @@ impl TermWindow {

match current_level {
WindowLevel::AlwaysOnTop => {
self.window_state -= WindowState::ALWAYS_ON_TOP;
window.set_window_level(WindowLevel::Normal);
}
WindowLevel::AlwaysOnBottom => {
self.window_state -= WindowState::ALWAYS_ON_BOTTOM;
self.window_state = self.window_state | WindowState::ALWAYS_ON_TOP;
window.set_window_level(WindowLevel::AlwaysOnTop);
}
WindowLevel::Normal => {
self.window_state = self.window_state | WindowState::ALWAYS_ON_TOP;
WindowLevel::AlwaysOnBottom | WindowLevel::Normal => {
window.set_window_level(WindowLevel::AlwaysOnTop);
}
}
Expand All @@ -2533,49 +2526,17 @@ impl TermWindow {
let current_level = self.window_state.as_window_level();

match current_level {
WindowLevel::AlwaysOnTop => {
self.window_state -= WindowState::ALWAYS_ON_TOP;
self.window_state = self.window_state | WindowState::ALWAYS_ON_BOTTOM;
window.set_window_level(WindowLevel::AlwaysOnBottom);
}
WindowLevel::AlwaysOnBottom => {
self.window_state -= WindowState::ALWAYS_ON_BOTTOM;
window.set_window_level(WindowLevel::Normal);
}
WindowLevel::Normal => {
self.window_state = self.window_state | WindowState::ALWAYS_ON_BOTTOM;
WindowLevel::AlwaysOnTop | WindowLevel::Normal => {
window.set_window_level(WindowLevel::AlwaysOnBottom);
}
}
}
SetWindowLevel(level) => {
let window = self.window.clone().unwrap();
let current_level = self.window_state.as_window_level();

// reset level state if needed
match current_level {
WindowLevel::AlwaysOnTop => {
self.window_state -= WindowState::ALWAYS_ON_TOP;
}
WindowLevel::AlwaysOnBottom => {
self.window_state -= WindowState::ALWAYS_ON_BOTTOM;
}
_ => {}
}

match level {
WindowLevel::AlwaysOnTop => {
window.set_window_level(WindowLevel::AlwaysOnTop);
self.window_state = self.window_state | WindowState::ALWAYS_ON_TOP;
}
WindowLevel::AlwaysOnBottom => {
window.set_window_level(WindowLevel::AlwaysOnBottom);
self.window_state = self.window_state | WindowState::ALWAYS_ON_BOTTOM;
}
WindowLevel::Normal => {
window.set_window_level(WindowLevel::Normal);
}
}
window.set_window_level(level.clone());
},
CopyTo(dest) => {
let text = self.selection_text(pane);
Expand Down
25 changes: 18 additions & 7 deletions window/src/os/macos/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1160,12 +1160,15 @@ impl WindowInner {
}

fn set_window_level(&mut self, level: WindowLevel) {

rawnly marked this conversation as resolved.
Show resolved Hide resolved
unsafe {
NSWindow::setLevel_(*self.window, match level {
WindowLevel::AlwaysOnBottom => -1,
WindowLevel::Normal => 0,
WindowLevel::AlwaysOnTop => 3,
});

WindowView::did_resize(&mut** self.view, sel!(windowDidResize:), nil);
}
rawnly marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down Expand Up @@ -2772,6 +2775,20 @@ impl WindowView {
unsafe { msg_send![*window, isZoomed] }
});

let window_level = inner.window.as_ref().map_or(WindowLevel::Normal, |w| unsafe { w.load().level().into() });
rawnly marked this conversation as resolved.
Show resolved Hide resolved

let level_state = match window_level {
WindowLevel::AlwaysOnBottom => WindowState::ALWAYS_ON_BOTTOM,
WindowLevel::AlwaysOnTop => WindowState::ALWAYS_ON_TOP,
WindowLevel::Normal => WindowState::default(),
};

let screen_state = match (is_full_screen, is_zoomed) {
(true, _) => WindowState::FULL_SCREEN,
(_, true) => WindowState::MAXIMIZED,
_ => WindowState::default(),
rawnly marked this conversation as resolved.
Show resolved Hide resolved
};

let dpi = inner
.window
.as_ref()
Expand All @@ -2788,13 +2805,7 @@ impl WindowView {
pixel_height: height as usize,
dpi,
},
window_state: if is_full_screen {
WindowState::FULL_SCREEN
} else if is_zoomed {
WindowState::MAXIMIZED
} else {
WindowState::default()
},
window_state: screen_state | level_state,
live_resizing,
});
}
Expand Down