Skip to content

Commit d3dc994

Browse files
authored
Merge pull request #1694 from pjungkamp/gio/application-command-line
gio: Return `glib::ExitCode` from `gio::Application` signal handlers
2 parents dfd1468 + 218ed47 commit d3dc994

File tree

22 files changed

+204
-122
lines changed

22 files changed

+204
-122
lines changed

.github/workflows/CI.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- stable
1919
- beta
2020
- nightly
21-
- "1.80.0"
21+
- "1.83.0"
2222
conf:
2323
- { name: "cairo", features: "png,pdf,svg,ps,use_glib,v1_18,freetype,script,xcb,xlib,win32-surface", nightly: "--features 'png,pdf,svg,ps,use_glib,v1_18,freetype,script,xcb,xlib,win32-surface'", test_sys: true }
2424
- { name: "gdk-pixbuf", features: "v2_42", nightly: "--all-features", test_sys: true }
@@ -104,7 +104,7 @@ jobs:
104104
- stable
105105
- beta
106106
- nightly
107-
- "1.80.0"
107+
- "1.83.0"
108108
steps:
109109
- uses: actions/checkout@v4
110110
- uses: actions-rs/toolchain@v1

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ repository = "https://github.com/gtk-rs/gtk-rs-core"
3232
license = "MIT"
3333
exclude = ["gir-files/*"]
3434
edition = "2021"
35-
rust-version = "1.80"
35+
rust-version = "1.83"
3636

3737
[workspace.dependencies]
3838
libc = "0.2"

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ information about each crate, please refer to their `README.md` file in their di
88

99
## Minimum supported Rust version
1010

11-
Currently, the minimum supported Rust version is `1.80.0`.
11+
Currently, the minimum supported Rust version is `1.83.0`.
1212

1313
## Documentation
1414

cairo/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Cairo __1.14__ is the lowest supported version for the underlying library.
88

99
## Minimum supported Rust version
1010

11-
Currently, the minimum supported Rust version is `1.80.0`.
11+
Currently, the minimum supported Rust version is `1.83.0`.
1212

1313
## Default-on features
1414

gdk-pixbuf/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ GDK-PixBuf __2.36.8__ is the lowest supported version for the underlying library
66

77
## Minimum supported Rust version
88

9-
Currently, the minimum supported Rust version is `1.80.0`.
9+
Currently, the minimum supported Rust version is `1.83.0`.
1010

1111
## Documentation
1212

gio/Gir.toml

+8
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,14 @@ generate_builder = true
310310
name = "open"
311311
manual = true
312312
doc_trait_name = "ApplicationExtManual"
313+
[[object.signal]]
314+
name = "command-line"
315+
manual = true
316+
doc_trait_name = "ApplicationExtManual"
317+
[[object.signal]]
318+
name = "handle-local-options"
319+
manual = true
320+
doc_trait_name = "ApplicationExtManual"
313321
[[object.function]]
314322
name = "run"
315323
manual = true

gio/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ GIO __2.56__ is the lowest supported version for the underlying library.
66

77
## Minimum supported Rust version
88

9-
Currently, the minimum supported Rust version is `1.80.0`.
9+
Currently, the minimum supported Rust version is `1.83.0`.
1010

1111
## Documentation
1212

gio/src/application.rs

+76-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Take a look at the license at the top of the repository in the LICENSE file.
22

3-
use std::{boxed::Box as Box_, mem::transmute};
3+
use std::{boxed::Box as Box_, mem::transmute, ops::ControlFlow};
44

55
use glib::{
66
prelude::*,
@@ -9,22 +9,25 @@ use glib::{
99
ExitCode, GString,
1010
};
1111

12-
use crate::{ffi, Application, File};
12+
use crate::{ffi, Application, ApplicationCommandLine, File};
1313

1414
pub trait ApplicationExtManual: IsA<Application> {
1515
#[doc(alias = "g_application_run")]
1616
fn run(&self) -> ExitCode {
1717
self.run_with_args(&std::env::args().collect::<Vec<_>>())
1818
}
19+
1920
#[doc(alias = "g_application_run")]
2021
fn run_with_args<S: AsRef<str>>(&self, args: &[S]) -> ExitCode {
2122
let argv: Vec<&str> = args.iter().map(|a| a.as_ref()).collect();
2223
let argc = argv.len() as i32;
2324
let exit_code = unsafe {
2425
ffi::g_application_run(self.as_ref().to_glib_none().0, argc, argv.to_glib_none().0)
2526
};
26-
ExitCode::from(exit_code)
27+
ExitCode::try_from(exit_code).unwrap()
2728
}
29+
30+
#[doc(alias = "open")]
2831
fn connect_open<F: Fn(&Self, &[File], &str) + 'static>(&self, f: F) -> SignalHandlerId {
2932
unsafe extern "C" fn open_trampoline<P, F: Fn(&P, &[File], &str) + 'static>(
3033
this: *mut ffi::GApplication,
@@ -56,6 +59,76 @@ pub trait ApplicationExtManual: IsA<Application> {
5659
}
5760
}
5861

62+
#[doc(alias = "command-line")]
63+
fn connect_command_line<F: Fn(&Self, &ApplicationCommandLine) -> ExitCode + 'static>(
64+
&self,
65+
f: F,
66+
) -> SignalHandlerId {
67+
unsafe extern "C" fn command_line_trampoline<
68+
P: IsA<Application>,
69+
F: Fn(&P, &ApplicationCommandLine) -> ExitCode + 'static,
70+
>(
71+
this: *mut ffi::GApplication,
72+
command_line: *mut ffi::GApplicationCommandLine,
73+
f: glib::ffi::gpointer,
74+
) -> std::ffi::c_int {
75+
let f: &F = &*(f as *const F);
76+
f(
77+
Application::from_glib_borrow(this).unsafe_cast_ref(),
78+
&from_glib_borrow(command_line),
79+
)
80+
.into()
81+
}
82+
unsafe {
83+
let f: Box_<F> = Box_::new(f);
84+
connect_raw(
85+
self.as_ptr() as *mut _,
86+
c"command-line".as_ptr() as *const _,
87+
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
88+
command_line_trampoline::<Self, F> as *const (),
89+
)),
90+
Box_::into_raw(f),
91+
)
92+
}
93+
}
94+
95+
#[doc(alias = "handle-local-options")]
96+
fn connect_handle_local_options<
97+
F: Fn(&Self, &glib::VariantDict) -> ControlFlow<ExitCode> + 'static,
98+
>(
99+
&self,
100+
f: F,
101+
) -> SignalHandlerId {
102+
unsafe extern "C" fn handle_local_options_trampoline<
103+
P: IsA<Application>,
104+
F: Fn(&P, &glib::VariantDict) -> ControlFlow<ExitCode> + 'static,
105+
>(
106+
this: *mut ffi::GApplication,
107+
options: *mut glib::ffi::GVariantDict,
108+
f: glib::ffi::gpointer,
109+
) -> std::ffi::c_int {
110+
let f: &F = &*(f as *const F);
111+
f(
112+
Application::from_glib_borrow(this).unsafe_cast_ref(),
113+
&from_glib_borrow(options),
114+
)
115+
.break_value()
116+
.map(i32::from)
117+
.unwrap_or(-1)
118+
}
119+
unsafe {
120+
let f: Box_<F> = Box_::new(f);
121+
connect_raw(
122+
self.as_ptr() as *mut _,
123+
c"handle-local-options".as_ptr() as *const _,
124+
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
125+
handle_local_options_trampoline::<Self, F> as *const (),
126+
)),
127+
Box_::into_raw(f),
128+
)
129+
}
130+
}
131+
59132
#[doc(alias = "g_application_hold")]
60133
fn hold(&self) -> ApplicationHoldGuard {
61134
unsafe {

gio/src/auto/application.rs

+1-66
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
// DO NOT EDIT
44

55
use crate::{
6-
ffi, ActionGroup, ActionMap, ApplicationCommandLine, ApplicationFlags, Cancellable,
7-
DBusConnection, File, Notification,
6+
ffi, ActionGroup, ActionMap, ApplicationFlags, Cancellable, DBusConnection, File, Notification,
87
};
98
use glib::{
109
object::ObjectType as _,
@@ -464,70 +463,6 @@ pub trait ApplicationExt: IsA<Application> + 'static {
464463
}
465464
}
466465

467-
#[doc(alias = "command-line")]
468-
fn connect_command_line<F: Fn(&Self, &ApplicationCommandLine) -> i32 + 'static>(
469-
&self,
470-
f: F,
471-
) -> SignalHandlerId {
472-
unsafe extern "C" fn command_line_trampoline<
473-
P: IsA<Application>,
474-
F: Fn(&P, &ApplicationCommandLine) -> i32 + 'static,
475-
>(
476-
this: *mut ffi::GApplication,
477-
command_line: *mut ffi::GApplicationCommandLine,
478-
f: glib::ffi::gpointer,
479-
) -> std::ffi::c_int {
480-
let f: &F = &*(f as *const F);
481-
f(
482-
Application::from_glib_borrow(this).unsafe_cast_ref(),
483-
&from_glib_borrow(command_line),
484-
)
485-
}
486-
unsafe {
487-
let f: Box_<F> = Box_::new(f);
488-
connect_raw(
489-
self.as_ptr() as *mut _,
490-
c"command-line".as_ptr() as *const _,
491-
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
492-
command_line_trampoline::<Self, F> as *const (),
493-
)),
494-
Box_::into_raw(f),
495-
)
496-
}
497-
}
498-
499-
#[doc(alias = "handle-local-options")]
500-
fn connect_handle_local_options<F: Fn(&Self, &glib::VariantDict) -> i32 + 'static>(
501-
&self,
502-
f: F,
503-
) -> SignalHandlerId {
504-
unsafe extern "C" fn handle_local_options_trampoline<
505-
P: IsA<Application>,
506-
F: Fn(&P, &glib::VariantDict) -> i32 + 'static,
507-
>(
508-
this: *mut ffi::GApplication,
509-
options: *mut glib::ffi::GVariantDict,
510-
f: glib::ffi::gpointer,
511-
) -> std::ffi::c_int {
512-
let f: &F = &*(f as *const F);
513-
f(
514-
Application::from_glib_borrow(this).unsafe_cast_ref(),
515-
&from_glib_borrow(options),
516-
)
517-
}
518-
unsafe {
519-
let f: Box_<F> = Box_::new(f);
520-
connect_raw(
521-
self.as_ptr() as *mut _,
522-
c"handle-local-options".as_ptr() as *const _,
523-
Some(std::mem::transmute::<*const (), unsafe extern "C" fn()>(
524-
handle_local_options_trampoline::<Self, F> as *const (),
525-
)),
526-
Box_::into_raw(f),
527-
)
528-
}
529-
}
530-
531466
#[cfg(feature = "v2_60")]
532467
#[cfg_attr(docsrs, doc(cfg(feature = "v2_60")))]
533468
#[doc(alias = "name-lost")]

gio/src/gio_future.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ where
115115
&& self
116116
.receiver
117117
.as_ref()
118-
.map_or(true, |receiver| receiver.is_terminated())
118+
.is_none_or(|receiver| receiver.is_terminated())
119119
}
120120
}
121121

0 commit comments

Comments
 (0)