Skip to content

Commit

Permalink
Add GTK handles
Browse files Browse the repository at this point in the history
  • Loading branch information
notgull committed Dec 22, 2022
1 parent 13127ba commit 02bbb91
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 0 deletions.
100 changes: 100 additions & 0 deletions src/gtk.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
//! Handles to GTK windows and displays.

use core::ffi::c_void;
use core::ptr;

/// Raw display handle for the GTK Tool Kit version 3.
///
/// ## Construction
///
/// ```
/// # use raw_window_handle::Gtk3DisplayHandle;
/// let display_handle = Gtk3DisplayHandle::empty();
/// /* set fields */
/// ```
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Gtk3DisplayHandle {
/// A pointer to a `GtkApplication`.
pub application: *mut c_void,
}

/// Raw window handle for the GTK Tool Kit version 3.
///
/// ## Construction
///
/// ```
/// # use raw_window_handle::Gtk3WindowHandle;
/// let window_handle = Gtk3WindowHandle::empty();
/// /* set fields */
/// ```
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Gtk3WindowHandle {
/// A pointer to a `GtkWidget`.
pub window: *mut c_void,
}

/// Raw display handle for the GTK Tool Kit version 4.
///
/// ## Construction
///
/// ```
/// # use raw_window_handle::Gtk4DisplayHandle;
/// let display_handle = Gtk4DisplayHandle::empty();
/// /* set fields */
/// ```
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Gtk4DisplayHandle {
/// A pointer to a `GtkApplication`.
pub application: *mut c_void,
}

/// Raw window handle for the GTK Tool Kit version 4.
///
/// ## Construction
///
/// ```
/// # use raw_window_handle::Gtk4WindowHandle;
/// let window_handle = Gtk4WindowHandle::empty();
/// /* set fields */
/// ```
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub struct Gtk4WindowHandle {
/// A pointer to a `GtkWidget`.
pub window: *mut c_void,
}

impl Gtk3DisplayHandle {
pub fn empty() -> Self {
Self {
application: ptr::null_mut(),
}
}
}

impl Gtk3WindowHandle {
pub fn empty() -> Self {
Self {
window: ptr::null_mut(),
}
}
}

impl Gtk4DisplayHandle {
pub fn empty() -> Self {
Self {
application: ptr::null_mut(),
}
}
}

impl Gtk4WindowHandle {
pub fn empty() -> Self {
Self {
window: ptr::null_mut(),
}
}
}
26 changes: 26 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ extern crate alloc;

mod android;
mod appkit;
mod gtk;
mod haiku;
mod redox;
mod uikit;
Expand All @@ -33,6 +34,7 @@ mod windows;

pub use android::{AndroidDisplayHandle, AndroidNdkWindowHandle};
pub use appkit::{AppKitDisplayHandle, AppKitWindowHandle};
pub use gtk::{Gtk3DisplayHandle, Gtk3WindowHandle, Gtk4DisplayHandle, Gtk4WindowHandle};
pub use haiku::{HaikuDisplayHandle, HaikuWindowHandle};
pub use redox::{OrbitalDisplayHandle, OrbitalWindowHandle};
pub use uikit::{UiKitDisplayHandle, UiKitWindowHandle};
Expand Down Expand Up @@ -174,6 +176,18 @@ pub enum RawWindowHandle {
/// ## Availability Hints
/// This variant is used on HaikuOS.
Haiku(HaikuWindowHandle),
/// A raw window handle for GTK4.
///
/// ## Availability Hints
///
/// This variant is used on any system that supports the GTK toolkit.
Gtk4(Gtk4WindowHandle),
/// A raw window handle for GTK3.
///
/// ## Availability Hints
///
/// This variant is used on any system that supports the GTK toolkit.
Gtk3(Gtk3WindowHandle),
}

/// Display that wraps around a raw display handle.
Expand Down Expand Up @@ -304,4 +318,16 @@ pub enum RawDisplayHandle {
/// ## Availability Hints
/// This variant is used on HaikuOS.
Haiku(HaikuDisplayHandle),
/// A raw display handle for GTK4.
///
/// ## Availability Hints
///
/// This variant is used on any system that supports the GTK toolkit.
Gtk4(Gtk4DisplayHandle),
/// A raw display handle for GTK3.
///
/// ## Availability Hints
///
/// This variant is used on any system that supports the GTK toolkit.
Gtk3(Gtk3DisplayHandle),
}

0 comments on commit 02bbb91

Please sign in to comment.