-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
activation_token: Provide GTK 4 helper
Unfortunately, `startup_notify_id` is not nullable so we do the same as GTK. See https://gitlab.gnome.org/GNOME/gtk/-/commit/6efd1a9dad49b42db778bdc07020dfcf8845e2c8
- Loading branch information
Showing
3 changed files
with
33 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
use gtk4::{glib::translate::*, prelude::*}; | ||
|
||
use crate::ActivationToken; | ||
|
||
impl ActivationToken { | ||
/// Gets an activation token from a window. | ||
pub fn from_window(widget: &impl IsA<::gtk4::Widget>) -> Option<Self> { | ||
let display = widget.as_ref().display(); | ||
let context = display.app_launch_context(); | ||
|
||
// FIXME Call the vfunc directly since | ||
// g_app_launch_context_get_startup_notify_id has NULL checks. | ||
// | ||
// See https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3933 | ||
unsafe { | ||
let klass: *mut gtk4::gio::ffi::GAppLaunchContextClass = | ||
std::ptr::addr_of!((*context.class().parent()?)) as *mut _; | ||
let get_startup_notify_id = (*klass).get_startup_notify_id.as_ref()?; | ||
|
||
from_glib_full::<_, Option<String>>(get_startup_notify_id( | ||
context.as_ptr().cast(), | ||
std::ptr::null_mut(), | ||
std::ptr::null_mut(), | ||
)) | ||
} | ||
.map(Self::from) | ||
} | ||
} |
This file contains 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