Skip to content

Commit

Permalink
feat(core): expose gtk_window, closes #2083 (#2141)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Jul 2, 2021
1 parent 6569c2b commit e0a8e09
Show file tree
Hide file tree
Showing 7 changed files with 87 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .changes/gtk-window.md
@@ -0,0 +1,7 @@
---
"tauri": patch
"tauri-runtime": patch
"tauri-runtime-wry": patch
---

Expose `gtk_window` getter.
3 changes: 2 additions & 1 deletion core/tauri-runtime-wry/Cargo.toml
Expand Up @@ -22,8 +22,9 @@ infer = "0.4"
ico = "0.1"
winapi = "0.3"

[target."cfg(target_os = \"linux\")".dependencies]
[target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies]
png = "0.16"
gtk = { version = "0.9", features = [ "v3_16" ] }

[features]
dox = [ "wry/dox" ]
Expand Down
48 changes: 48 additions & 0 deletions core/tauri-runtime-wry/src/lib.rs
Expand Up @@ -599,6 +599,23 @@ struct Hwnd(HWND);
#[cfg(windows)]
unsafe impl Send for Hwnd {}

#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
))]
struct GtkWindow(gtk::ApplicationWindow);
#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
))]
unsafe impl Send for GtkWindow {}

#[derive(Debug, Clone)]
enum WindowMessage {
// Getters
Expand All @@ -619,6 +636,14 @@ enum WindowMessage {
AvailableMonitors(Sender<Vec<MonitorHandle>>),
#[cfg(windows)]
Hwnd(Sender<Hwnd>),
#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
))]
GtkWindow(Sender<GtkWindow>),
// Setters
Center(Sender<Result<()>>),
RequestUserAttention(Option<UserAttentionTypeWrapper>),
Expand Down Expand Up @@ -830,6 +855,18 @@ impl Dispatch for WryDispatcher {
Ok(dispatcher_getter!(self, WindowMessage::Hwnd).0)
}

/// Returns the `ApplicatonWindow` from gtk crate that is used by this window.
#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
))]
fn gtk_window(&self) -> Result<gtk::ApplicationWindow> {
Ok(dispatcher_getter!(self, WindowMessage::GtkWindow).0)
}

// Setters

fn center(&self) -> Result<()> {
Expand Down Expand Up @@ -1592,6 +1629,17 @@ fn handle_event_loop(
use wry::application::platform::windows::WindowExtWindows;
tx.send(Hwnd(window.hwnd() as HWND)).unwrap()
}
#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
))]
WindowMessage::GtkWindow(tx) => {
use wry::application::platform::unix::WindowExtUnix;
tx.send(GtkWindow(window.gtk_window().clone())).unwrap()
}
// Setters
WindowMessage::Center(tx) => {
tx.send(center_window(window)).unwrap();
Expand Down
3 changes: 3 additions & 0 deletions core/tauri-runtime/Cargo.toml
Expand Up @@ -31,6 +31,9 @@ uuid = { version = "0.8.2", features = [ "v4" ] }
[target."cfg(windows)".dependencies]
winapi = "0.3"

[target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies]
gtk = { version = "0.9", features = [ "v3_16" ] }

[features]
menu = [ ]
system-tray = [ ]
10 changes: 10 additions & 0 deletions core/tauri-runtime/src/lib.rs
Expand Up @@ -417,6 +417,16 @@ pub trait Dispatch: Clone + Send + Sized + 'static {
#[cfg(windows)]
fn hwnd(&self) -> crate::Result<HWND>;

/// Returns the `ApplicatonWindow` from gtk crate that is used by this window.
#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
))]
fn gtk_window(&self) -> crate::Result<gtk::ApplicationWindow>;

// SETTERS

/// Centers the window.
Expand Down
3 changes: 3 additions & 0 deletions core/tauri/Cargo.toml
Expand Up @@ -69,6 +69,9 @@ rfd = "0.4"
raw-window-handle = { version = "0.3.3", optional = true }
minisign-verify = { version = "0.1", optional = true }

[target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies]
gtk = { version = "0.9", features = [ "v3_16" ] }

[build-dependencies]
cfg_aliases = "0.1.1"

Expand Down
14 changes: 14 additions & 0 deletions core/tauri/src/window.rs
Expand Up @@ -511,6 +511,20 @@ impl<P: Params> Window<P> {
.map_err(Into::into)
}

/// Returns the `ApplicatonWindow` from gtk crate that is used by this window.
///
/// Note that this can only be used on the main thread.
#[cfg(any(
target_os = "linux",
target_os = "dragonfly",
target_os = "freebsd",
target_os = "netbsd",
target_os = "openbsd"
))]
pub fn gtk_window(&self) -> crate::Result<gtk::ApplicationWindow> {
self.window.dispatcher.gtk_window().map_err(Into::into)
}

// Setters

/// Centers the window.
Expand Down

0 comments on commit e0a8e09

Please sign in to comment.