Skip to content

Commit

Permalink
feat(core): reimplement window initial focus flag, closes #5120
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Oct 3, 2022
1 parent a4aec9f commit 9a26e0f
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 9 deletions.
7 changes: 7 additions & 0 deletions .changes/focused.md
@@ -0,0 +1,7 @@
---
"tauri": minor
"tauri-runtime": minor
"tauri-runtime-wry": minor
---

Readd the option to create an unfocused window via the `focused` method. The `focus` function has been deprecated.
3 changes: 3 additions & 0 deletions Cargo.toml
Expand Up @@ -29,3 +29,6 @@ codegen-units = 1
lto = true
incremental = false
opt-level = "s"

[patch.crates-io]
tao = { git = "https://github.com/tauri-apps/tao", branch = "window-builder-focus" }
7 changes: 3 additions & 4 deletions core/tauri-runtime-wry/src/lib.rs
Expand Up @@ -727,7 +727,7 @@ unsafe impl Send for WindowBuilderWrapper {}
impl WindowBuilderBase for WindowBuilderWrapper {}
impl WindowBuilder for WindowBuilderWrapper {
fn new() -> Self {
Default::default()
Self::default().focused(true)
}

fn with_config(config: WindowConfig) -> Self {
Expand Down Expand Up @@ -840,9 +840,8 @@ impl WindowBuilder for WindowBuilderWrapper {
self
}

/// Deprecated since 0.1.4 (noop)
/// Windows is automatically focused when created.
fn focus(self) -> Self {
fn focused(mut self, focused: bool) -> Self {
self.inner = self.inner.with_focused(focused);
self
}

Expand Down
4 changes: 2 additions & 2 deletions core/tauri-runtime/src/webview.rs
Expand Up @@ -133,9 +133,9 @@ pub trait WindowBuilder: WindowBuilderBase {
#[must_use]
fn fullscreen(self, fullscreen: bool) -> Self;

/// Whether the window will be initially hidden or focused.
/// Whether the window will be initially focused or not.
#[must_use]
fn focus(self) -> Self;
fn focused(self, focused: bool) -> Self;

/// Whether the window should be maximized upon creation.
#[must_use]
Expand Down
2 changes: 1 addition & 1 deletion core/tauri/src/test/mock_runtime.rs
Expand Up @@ -221,7 +221,7 @@ impl WindowBuilder for MockWindowBuilder {
self
}

fn focus(self) -> Self {
fn focused(self, focused: bool) -> Self {
self
}

Expand Down
15 changes: 13 additions & 2 deletions core/tauri/src/window.rs
Expand Up @@ -328,10 +328,21 @@ impl<'a, R: Runtime> WindowBuilder<'a, R> {
self
}

/// Whether the window will be initially hidden or focused.
/// Sets the window to be initially focused.
#[must_use]
#[deprecated(
since = "1.2.0",
note = "The window is automatically focused by default. This function Will be removed in 2.0.0. Use `focused` instead."
)]
pub fn focus(mut self) -> Self {
self.window_builder = self.window_builder.focus();
self.window_builder = self.window_builder.focused(true);
self
}

/// Whether the window will be initially focused or not.
#[must_use]
pub fn focused(mut self, focused: bool) -> Self {
self.window_builder = self.window_builder.focused(focused);
self
}

Expand Down

0 comments on commit 9a26e0f

Please sign in to comment.