Repository navigation
[Window State] implement fullscreen & minimized logic #3398
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
Open
polarove
wants to merge
7
commits into
tauri-apps:v2
Choose a base branch
from
polarove:fullscreen
base: v2
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0e6a258
implement fullscreen & minimized
polarove 0877342
Merge branch 'tauri-apps:v2' into fullscreen
polarove 48476ee
Sign my commits
polarove 451d85b
Merge branch 'fullscreen' of https://github.com/polarove/plugins-work…
polarove 0251023
Merge remote-tracking branch 'origin/v2' into fullscreen
lucasfernog 3b482e5
fix(window-state): restore flags independently, make MINIMIZED opt-in
lucasfernog 13cd21f
chore(window-state): split fullscreen size change file
lucasfernog File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -56,6 +56,7 @@ bitflags! { | |
| const VISIBLE = 1 << 3; | ||
| const DECORATIONS = 1 << 4; | ||
| const FULLSCREEN = 1 << 5; | ||
| const MINIMIZED = 1 << 6; | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -84,6 +85,7 @@ struct WindowState { | |
| prev_x: i32, | ||
| prev_y: i32, | ||
| maximized: bool, | ||
| minimized: bool, | ||
| visible: bool, | ||
| decorated: bool, | ||
| fullscreen: bool, | ||
|
|
@@ -99,6 +101,7 @@ impl Default for WindowState { | |
| prev_x: Default::default(), | ||
| prev_y: Default::default(), | ||
| maximized: Default::default(), | ||
| minimized: Default::default(), | ||
| visible: true, | ||
| decorated: true, | ||
| fullscreen: Default::default(), | ||
|
|
@@ -216,12 +219,13 @@ impl<R: Runtime> WindowExt for Window<R> { | |
| })?; | ||
| } | ||
|
|
||
| if flags.contains(StateFlags::MAXIMIZED) && state.maximized { | ||
| // fullscreen > maximized > minimized | ||
| if flags.contains(StateFlags::FULLSCREEN) && state.fullscreen { | ||
| self.set_fullscreen(true)?; | ||
| } else if flags.contains(StateFlags::MAXIMIZED) && state.maximized { | ||
| self.maximize()?; | ||
| } | ||
|
|
||
| if flags.contains(StateFlags::FULLSCREEN) { | ||
| self.set_fullscreen(state.fullscreen)?; | ||
| } else if flags.contains(StateFlags::MINIMIZED) && state.minimized { | ||
| self.minimize()?; | ||
| } | ||
|
|
||
| should_show = state.visible; | ||
|
|
@@ -240,10 +244,6 @@ impl<R: Runtime> WindowExt for Window<R> { | |
| metadata.y = pos.y; | ||
| } | ||
|
|
||
| if flags.contains(StateFlags::MAXIMIZED) { | ||
| metadata.maximized = self.is_maximized()?; | ||
| } | ||
|
|
||
| if flags.contains(StateFlags::VISIBLE) { | ||
| metadata.visible = self.is_visible()?; | ||
| } | ||
|
|
@@ -256,9 +256,23 @@ impl<R: Runtime> WindowExt for Window<R> { | |
| metadata.fullscreen = self.is_fullscreen()?; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we already have fullscreen implemented? |
||
| } | ||
|
|
||
| if flags.contains(StateFlags::MINIMIZED) { | ||
| metadata.minimized = self.is_minimized()?; | ||
| } | ||
|
|
||
| if flags.contains(StateFlags::MAXIMIZED) { | ||
| metadata.maximized = self.is_maximized()?; | ||
| } | ||
|
|
||
| c.insert(label.into(), metadata); | ||
| } | ||
|
|
||
| // this actually overrides | ||
| // { | ||
| // "visible": false | ||
| // } | ||
| // in tauri.config.json | ||
| // if you want to control the visibility, don't pass StateFlags::VISIBLE in. | ||
| if flags.contains(StateFlags::VISIBLE) && should_show { | ||
| self.show()?; | ||
| self.set_focus()?; | ||
|
|
@@ -280,18 +294,33 @@ impl<R: Runtime> WindowExtInternal for WebviewWindow<R> { | |
|
|
||
| impl<R: Runtime> WindowExtInternal for Window<R> { | ||
| fn update_state(&self, state: &mut WindowState, flags: StateFlags) -> tauri::Result<()> { | ||
| let is_maximized = flags | ||
| .intersects(StateFlags::MAXIMIZED | StateFlags::POSITION | StateFlags::SIZE) | ||
| && self.is_maximized()?; | ||
| let is_minimized = | ||
| flags.intersects(StateFlags::POSITION | StateFlags::SIZE) && self.is_minimized()?; | ||
| let concern_flags = StateFlags::MAXIMIZED | ||
| | StateFlags::MINIMIZED | ||
| | StateFlags::POSITION | ||
| | StateFlags::SIZE | ||
| | StateFlags::FULLSCREEN; | ||
|
|
||
| let is_concern = flags.intersects(concern_flags); | ||
|
|
||
| let is_maximized = is_concern && self.is_maximized()?; | ||
|
|
||
| let is_minimized = is_concern && self.is_minimized()?; | ||
|
|
||
| let is_fullscreen = is_concern && self.is_fullscreen()?; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this change is correct |
||
|
|
||
| // window can be maximized manually && programatically | ||
| if flags.contains(StateFlags::MAXIMIZED) { | ||
| state.maximized = is_maximized; | ||
| } | ||
|
|
||
| // window can be minimized manually && programatically | ||
| if flags.contains(StateFlags::MINIMIZED) { | ||
| state.minimized = is_minimized; | ||
| } | ||
|
|
||
| // window can be fullscreen manually && programatically | ||
| if flags.contains(StateFlags::FULLSCREEN) { | ||
| state.fullscreen = self.is_fullscreen()?; | ||
| state.fullscreen = is_fullscreen; | ||
| } | ||
|
|
||
| if flags.contains(StateFlags::DECORATIONS) { | ||
|
|
@@ -487,12 +516,29 @@ impl Builder { | |
| window_clone.is_maximized().unwrap_or_default() | ||
| }; | ||
|
|
||
| if !window_clone.is_minimized().unwrap_or_default() && !is_maximized { | ||
| let mut c = cache.lock().unwrap(); | ||
| if let Some(state) = c.get_mut(&label) { | ||
| let is_minimized = window_clone.is_minimized().unwrap_or_default(); | ||
| let is_fullscreen = window_clone.is_fullscreen().unwrap_or_default(); | ||
|
|
||
| let mut cache_lock = cache.lock().unwrap(); | ||
| let state = cache_lock.get_mut(&label); | ||
|
|
||
| if let Some(state) = state { | ||
| // save height & width only when the window is not maximized && minimized && fullscreen | ||
| // leaving their own function -> is_maximized() & is_minimized() & is_fullscreen() handle its functionality | ||
| if !is_maximized && !is_minimized && !is_fullscreen { | ||
| state.width = size.width; | ||
| state.height = size.height; | ||
| } | ||
|
|
||
| // save minimized & maximized & fullscreen at any time | ||
| // so we can restore them accurately | ||
|
|
||
| // minimized -> window is invisible but app icon is visible in taskbar (not tray_icon) | ||
| state.minimized = is_minimized; | ||
| // maximized -> window is visible at the most possible scale of selected monitor, the app icon is visible as well in taskbar (not tray_icon) | ||
| state.maximized = is_maximized; | ||
| // fullscreen -> system taskbar & window decoration are invisible, leaving only webview is visible and it takes the whole screen of the selected monitor | ||
| state.fullscreen = is_fullscreen; | ||
| } | ||
| } | ||
| } | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These 3 can co-exist.