diff --git a/src/compositor.rs b/src/compositor.rs index 0957cbdc..ff990de8 100644 --- a/src/compositor.rs +++ b/src/compositor.rs @@ -14,7 +14,7 @@ use wlroots_sys::{wlr_backend_destroy, wlr_backend_start, use {backend::{self, UnsafeRenderSetupFunction, Backend, Session}, data_device, - extensions::{server_decoration, gamma_control, screencopy, screenshooter, idle}, + extensions::{server_decoration, gamma_control, screencopy, screenshooter, idle, gtk_primary_selection}, surface::{self, Surface, InternalSurface}, input, output, @@ -117,6 +117,8 @@ pub struct Compositor { pub gamma_control_manager: Option, /// Optional idle manager extension. pub idle_manager: Option, + /// Optional GTK primary selection manager + pub gtk_primary_selection_manager: Option, /// Optional screencopy manager extension pub screencopy_manager: Option, /// Optional screenshooter manager extension @@ -150,6 +152,7 @@ pub struct Builder { server_decoration_manager: bool, gamma_control_manager: bool, idle_manager: bool, + gtk_primary_selection_manager: bool, screencopy_manager: bool, screenshooter: bool, wayland_remote: Option, @@ -259,6 +262,13 @@ impl Builder { self } + /// Decide whether or not to enable the GTK primary selection manager protocol + /// extension. + pub fn gtk_primary_selection_manager(mut self, gtk_primary_selection_manager: bool) -> Self { + self.gtk_primary_selection_manager = gtk_primary_selection_manager; + self + } + /// Decide whether or not to enable the screencopy protocol /// extension. pub fn screencopy_manager(mut self, screencopy_manager: bool) -> Self { @@ -439,6 +449,11 @@ impl Builder { } else { None }; + let gtk_primary_selection_manager = if self.gtk_primary_selection_manager { + gtk_primary_selection::Manager::new(display) + } else { + None + }; let screencopy_manager = if self.screencopy_manager { screencopy::ZManagerV1::new(display) } else { @@ -552,6 +567,7 @@ impl Builder { server_decoration_manager, gamma_control_manager, idle_manager, + gtk_primary_selection_manager, screencopy_manager, screenshooter, renderer, diff --git a/src/extensions/gtk_primary_selection.rs b/src/extensions/gtk_primary_selection.rs new file mode 100644 index 00000000..a747ceeb --- /dev/null +++ b/src/extensions/gtk_primary_selection.rs @@ -0,0 +1,30 @@ +//! Support for the GTK Primary Selection Protocol + +use wayland_sys::server::wl_display as wl_server_display; +use wlroots_sys::{wl_display, wlr_gtk_primary_selection_device_manager, wlr_gtk_primary_selection_device_manager_create, + wlr_gtk_primary_selection_device_manager_destroy}; + +#[derive(Debug)] +/// Manager that implements GTK primary selection +pub struct Manager { + manager: *mut wlr_gtk_primary_selection_device_manager +} + +impl Manager { + pub(crate) unsafe fn new(display: *mut wl_server_display) -> Option { + let manager_raw = wlr_gtk_primary_selection_device_manager_create(display as *mut wl_display); + + if !manager_raw.is_null() { + Some(Manager { manager: manager_raw }) + } else { + None + } + } + +} + +impl Drop for Manager { + fn drop(&mut self) { + unsafe { wlr_gtk_primary_selection_device_manager_destroy(self.manager) } + } +} diff --git a/src/extensions/mod.rs b/src/extensions/mod.rs index 88e28b22..bee82392 100644 --- a/src/extensions/mod.rs +++ b/src/extensions/mod.rs @@ -3,3 +3,4 @@ pub mod gamma_control; pub mod screenshooter; pub mod screencopy; pub mod idle; +pub mod gtk_primary_selection; diff --git a/wlroots-sys/src/wlroots.h b/wlroots-sys/src/wlroots.h index 4aae6ce0..da64406f 100644 --- a/wlroots-sys/src/wlroots.h +++ b/wlroots-sys/src/wlroots.h @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include