Skip to content

Commit e0a8e09

Browse files
authored
feat(core): expose gtk_window, closes #2083 (#2141)
1 parent 6569c2b commit e0a8e09

File tree

7 files changed

+87
-1
lines changed

7 files changed

+87
-1
lines changed

.changes/gtk-window.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"tauri": patch
3+
"tauri-runtime": patch
4+
"tauri-runtime-wry": patch
5+
---
6+
7+
Expose `gtk_window` getter.

core/tauri-runtime-wry/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ infer = "0.4"
2222
ico = "0.1"
2323
winapi = "0.3"
2424

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

2829
[features]
2930
dox = [ "wry/dox" ]

core/tauri-runtime-wry/src/lib.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,23 @@ struct Hwnd(HWND);
599599
#[cfg(windows)]
600600
unsafe impl Send for Hwnd {}
601601

602+
#[cfg(any(
603+
target_os = "linux",
604+
target_os = "dragonfly",
605+
target_os = "freebsd",
606+
target_os = "netbsd",
607+
target_os = "openbsd"
608+
))]
609+
struct GtkWindow(gtk::ApplicationWindow);
610+
#[cfg(any(
611+
target_os = "linux",
612+
target_os = "dragonfly",
613+
target_os = "freebsd",
614+
target_os = "netbsd",
615+
target_os = "openbsd"
616+
))]
617+
unsafe impl Send for GtkWindow {}
618+
602619
#[derive(Debug, Clone)]
603620
enum WindowMessage {
604621
// Getters
@@ -619,6 +636,14 @@ enum WindowMessage {
619636
AvailableMonitors(Sender<Vec<MonitorHandle>>),
620637
#[cfg(windows)]
621638
Hwnd(Sender<Hwnd>),
639+
#[cfg(any(
640+
target_os = "linux",
641+
target_os = "dragonfly",
642+
target_os = "freebsd",
643+
target_os = "netbsd",
644+
target_os = "openbsd"
645+
))]
646+
GtkWindow(Sender<GtkWindow>),
622647
// Setters
623648
Center(Sender<Result<()>>),
624649
RequestUserAttention(Option<UserAttentionTypeWrapper>),
@@ -830,6 +855,18 @@ impl Dispatch for WryDispatcher {
830855
Ok(dispatcher_getter!(self, WindowMessage::Hwnd).0)
831856
}
832857

858+
/// Returns the `ApplicatonWindow` from gtk crate that is used by this window.
859+
#[cfg(any(
860+
target_os = "linux",
861+
target_os = "dragonfly",
862+
target_os = "freebsd",
863+
target_os = "netbsd",
864+
target_os = "openbsd"
865+
))]
866+
fn gtk_window(&self) -> Result<gtk::ApplicationWindow> {
867+
Ok(dispatcher_getter!(self, WindowMessage::GtkWindow).0)
868+
}
869+
833870
// Setters
834871

835872
fn center(&self) -> Result<()> {
@@ -1592,6 +1629,17 @@ fn handle_event_loop(
15921629
use wry::application::platform::windows::WindowExtWindows;
15931630
tx.send(Hwnd(window.hwnd() as HWND)).unwrap()
15941631
}
1632+
#[cfg(any(
1633+
target_os = "linux",
1634+
target_os = "dragonfly",
1635+
target_os = "freebsd",
1636+
target_os = "netbsd",
1637+
target_os = "openbsd"
1638+
))]
1639+
WindowMessage::GtkWindow(tx) => {
1640+
use wry::application::platform::unix::WindowExtUnix;
1641+
tx.send(GtkWindow(window.gtk_window().clone())).unwrap()
1642+
}
15951643
// Setters
15961644
WindowMessage::Center(tx) => {
15971645
tx.send(center_window(window)).unwrap();

core/tauri-runtime/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ uuid = { version = "0.8.2", features = [ "v4" ] }
3131
[target."cfg(windows)".dependencies]
3232
winapi = "0.3"
3333

34+
[target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies]
35+
gtk = { version = "0.9", features = [ "v3_16" ] }
36+
3437
[features]
3538
menu = [ ]
3639
system-tray = [ ]

core/tauri-runtime/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,16 @@ pub trait Dispatch: Clone + Send + Sized + 'static {
417417
#[cfg(windows)]
418418
fn hwnd(&self) -> crate::Result<HWND>;
419419

420+
/// Returns the `ApplicatonWindow` from gtk crate that is used by this window.
421+
#[cfg(any(
422+
target_os = "linux",
423+
target_os = "dragonfly",
424+
target_os = "freebsd",
425+
target_os = "netbsd",
426+
target_os = "openbsd"
427+
))]
428+
fn gtk_window(&self) -> crate::Result<gtk::ApplicationWindow>;
429+
420430
// SETTERS
421431

422432
/// Centers the window.

core/tauri/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ rfd = "0.4"
6969
raw-window-handle = { version = "0.3.3", optional = true }
7070
minisign-verify = { version = "0.1", optional = true }
7171

72+
[target."cfg(any(target_os = \"linux\", target_os = \"dragonfly\", target_os = \"freebsd\", target_os = \"openbsd\", target_os = \"netbsd\"))".dependencies]
73+
gtk = { version = "0.9", features = [ "v3_16" ] }
74+
7275
[build-dependencies]
7376
cfg_aliases = "0.1.1"
7477

core/tauri/src/window.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -511,6 +511,20 @@ impl<P: Params> Window<P> {
511511
.map_err(Into::into)
512512
}
513513

514+
/// Returns the `ApplicatonWindow` from gtk crate that is used by this window.
515+
///
516+
/// Note that this can only be used on the main thread.
517+
#[cfg(any(
518+
target_os = "linux",
519+
target_os = "dragonfly",
520+
target_os = "freebsd",
521+
target_os = "netbsd",
522+
target_os = "openbsd"
523+
))]
524+
pub fn gtk_window(&self) -> crate::Result<gtk::ApplicationWindow> {
525+
self.window.dispatcher.gtk_window().map_err(Into::into)
526+
}
527+
514528
// Setters
515529

516530
/// Centers the window.

0 commit comments

Comments
 (0)