pub struct Environment<E> {
    pub manager: GlobalManager,
    inner: Rc<RefCell<E>>,
}
Expand description

A Wayland Environment

This struct is generated by the environment! macro, see module-level documentation for more details about this.

This is the central point for accessing globals for your Wayland app. Any global that has previously been declared in the environment! macro can be access from this type via the get_global, required_global and get_all_globals methods.

This Environment is a handle that can be cloned.

Fields§

§manager: GlobalManager

The underlying GlobalManager, if you need to do manual interaction with the registry. See wayland-client documentation for details.

§inner: Rc<RefCell<E>>

Implementations§

source§

impl<E> Environment<E>where E: GlobalHandler<WlDataDeviceManager>,

source

pub fn new_data_source<F>( &self, mime_types: Vec<String>, callback: F ) -> DataSourcewhere F: FnMut(DataSourceEvent, DispatchData<'_>) + 'static,

Create a new data source

This data source is the basic object for offering content to other clients, be it for clipboard selection or as drag’n’drop content.

Once this source is created, you will need to give it to a DataDevice to start interaction.

source§

impl<E> Environment<E>where E: DataDeviceHandling,

source

pub fn set_data_device_callback<F: FnMut(WlSeat, DndEvent<'_>, DispatchData<'_>) + 'static>( &mut self, callback: F ) -> Result<(), MissingGlobal>

Set the data device callback

This callback will be invoked whenever some drag’n’drop action is done onto one of your surfaces.

You should set it before entering your main loop, to ensure you will not miss any events.

Returns an error if the compositor did not advertise a data device capability.

source

pub fn with_data_device<F: FnOnce(&DataDevice)>( &self, seat: &WlSeat, f: F ) -> Result<(), MissingGlobal>

Access the data device associated with a seat

Returns an error if the seat is not found (for example if it has since been removed by the server) or if the wl_data_device_manager global is missing.

source§

impl<E: InnerEnv + 'static> Environment<E>

source

pub fn new( display: &Attached<WlDisplay>, queue: &mut EventQueue, env: E ) -> Result<Environment<E>>

Create new Environment

This requires access to a wl_display attached to the event_queue. You also need to provide an instance of the inner environment type declared using the environment! macro.

If you instead used the default_environment!, then you need to initialize your Environment using the new_default_environment! macro.

std::io::Error could be returned if initial roundtrips to the server failed.

If this call indefinitely blocks when doing initial roundtrips this can only be caused by server bugs.

source

pub fn new_pending(display: &Attached<WlDisplay>, env: E) -> Environment<E>

Create new pending Environment

This requires access to a wl_display attached to an event queue (on which the main SCTK logic will be attached). You also need to provide an instance of the inner environment type declared using the environment! macro.

If you instead used the default_environment!, then you need to initialize your Environment using the new_default_environment! macro.

You should prefer to use Environment::new, unless you want to control initialization manually or you create additional environment meaning that the initialization may be fine with just dispatch_pending of the event queue, instead of two roundtrips to fully initialize environment. If you manually initialize your environment two sync roundtrips are required.

source§

impl<E> Environment<E>

source

pub fn get_global<I: Interface>(&self) -> Option<Attached<I>>where E: GlobalHandler<I>,

Access a “single” global

This method allows you to access any “single” global that has previously been declared in the environment! macro. It is forwarded to the get() method of the appropriate GlobalHandler.

It returns None if the global has not (yet) been signaled by the registry.

source

pub fn require_global<I: Interface>(&self) -> Attached<I>where E: GlobalHandler<I>,

Access a “single” global or panic

This method is similar to get_global, but will panic with a detailed error message if the requested global was not advertized by the server.

source

pub fn get_all_globals<I: Interface>(&self) -> Vec<Attached<I>>where E: MultiGlobalHandler<I>,

Access all instances of a “multi” global

This will return a Vec containing all currently existing instances of the requested “multi” global that has been previously declared in the environment! macro. It is forwarded to the get_all() method of the appropriate MultiGlobalHandler.

source

pub fn with_inner<T, F: FnOnce(&mut E) -> T>(&self, f: F) -> T

Access the inner environment

This gives your access, via a closure, to the inner type you declared via the environment! or default_environment! macro.

This method returns the return value of your closure.

source§

impl<E: OutputHandling> Environment<E>

source

pub fn listen_for_outputs<F: FnMut(WlOutput, &OutputInfo, DispatchData<'_>) + 'static>( &self, f: F ) -> OutputStatusListener

Insert a new listener for outputs

The provided closure will be invoked whenever a wl_output is created or removed.

Note that if outputs already exist when this callback is setup, it’ll not be invoked on them. For you to be notified of them as well, you need to first process them manually by calling .get_all_outputs().

The returned OutputStatusListener keeps your callback alive, dropping it will disable it.

source§

impl<E: MultiGlobalHandler<WlOutput>> Environment<E>

source

pub fn get_all_outputs(&self) -> Vec<WlOutput>

Shorthand method to retrieve the list of outputs

source§

impl<E: PrimarySelectionHandling> Environment<E>

source

pub fn get_primary_selection_manager( &self ) -> Option<PrimarySelectionDeviceManager>

Get the best available primary selection device manager protocol.

Returns None if no primary selection device manager was advertised.

source

pub fn with_primary_selection<F: FnOnce(&PrimarySelectionDevice)>( &self, seat: &WlSeat, f: F ) -> Result<(), MissingGlobal>

Access the primary selection associated with a seat.

Returns an error if the seat is not found (for example if it has since been removed by the server) of if the zwp_primary_selection_device_manager_v1 or gtk_primary_selection_device_manager globals are missing.

source

pub fn new_primary_selection_source<F>( &self, mime_types: Vec<String>, callback: F ) -> PrimarySelectionSourcewhere F: FnMut(PrimarySelectionSourceEvent, DispatchData<'_>) + 'static,

Create a new primary selection source.

This primary selection source is the basic object for offering primary selection clipboard to other clients.

Once this source is created, you will need to give it to a PrimarySelectionDevice to start interaction.

source§

impl<E: SeatHandling> Environment<E>

source

pub fn listen_for_seats<F: FnMut(Attached<WlSeat>, &SeatData, DispatchData<'_>) + 'static>( &self, f: F ) -> SeatListener

Insert a new listener for seats

The provided closure will be invoked whenever a wl_seat is made available, removed, or see its capabilities changed.

Note that if seats already exist when this callback is setup, it’ll not be invoked on them. For you to be notified of them as well, you need to first process them manually by calling .get_all_seats().

The returned SeatListener keeps your callback alive, dropping it will disable it.

source§

impl<E: MultiGlobalHandler<WlSeat>> Environment<E>

source

pub fn get_all_seats(&self) -> Vec<Attached<WlSeat>>

Shorthand method to retrieve the list of seats

source§

impl<E: ShellHandling> Environment<E>

source

pub fn get_shell(&self) -> Option<Shell>

Get the best available shell protocol

Returns None if no shell was advertised.

source

pub fn create_shell_surface<F>( &self, surface: &WlSurface, f: F ) -> Box<dyn ShellSurface>where F: FnMut(Event, DispatchData<'_>) + 'static,

Create a new shell surface for this surface

This helper abstracts over the xdg_shell protocol and its precursors (zxdg_shell_v6 and wl_shell) for retro-compatibility. It’ll attempt to use them in this order.

You need to provide a closure that will process the events generated by the shell surface.

Panic

This function will panic if no supported shell was advertised by the compositor.

source§

impl<E> Environment<E>where E: GlobalHandler<WlShm>,

source

pub fn create_simple_pool<F>(&self, callback: F) -> Result<MemPool>where F: FnMut(DispatchData<'_>) + 'static,

Create a simple memory pool

This memory pool track the usage of the buffers created from it, and invokes your callback when the compositor has finished using all of them.

source

pub fn create_double_pool<F>(&self, callback: F) -> Result<DoubleMemPool>where F: FnMut(DispatchData<'_>) + 'static,

Create a double memory pool

This can be used for double-buffered drawing. The memory pool is backed by two different SHM segments, which are used in alternance.

The provided callback is triggered when one of the pools becomes unused again after you tried to draw while both where in use.

source

pub fn create_auto_pool(&self) -> Result<AutoMemPool>

Create an automatic memory pool

This pool will allocate more memory as needed in order to satisfy buffer requests, and will return memory to the pool when the compositor has finished using the memory.

source§

impl<E> Environment<E>where E: ShmHandling,

source

pub fn shm_formats(&self) -> Vec<Format>

Access the list of SHM formats supported by the compositor

source§

impl<E> Environment<E>where E: GlobalHandler<WlCompositor> + GlobalHandler<WlSubcompositor> + GlobalHandler<WlShm> + ShellHandling + MultiGlobalHandler<WlSeat> + GlobalHandler<ZxdgDecorationManagerV1> + SeatHandling,

source

pub fn create_window<F: Frame + 'static, CB>( &self, surface: WlSurface, theme_manager: Option<ThemeManager>, initial_dims: (u32, u32), callback: CB ) -> Result<Window<F>, F::Error>where CB: FnMut(Event, DispatchData<'_>) + 'static,

Create a new window wrapping given surface

This window handles decorations for you, this includes drawing them if the compositor doe snot support them, resizing interactions and moving the window. It also provides close/maximize/minimize buttons.

Many interactions still require your input, and are given to you via the callback you need to provide.

source§

impl<E: GlobalHandler<WlCompositor>> Environment<E>

source

pub fn create_surface(&self) -> Attached<WlSurface>

Create a DPI-aware surface

This surface will track the outputs it is being displayed on, and compute the optimal scale factor for these. You can access them using get_surface_scale_factor and get_surface_outputs.

source

pub fn create_surface_with_scale_callback<F: FnMut(i32, WlSurface, DispatchData<'_>) + 'static>( &self, f: F ) -> Attached<WlSurface>

Create a DPI-aware surface with callbacks

This method is like create_surface, but the provided callback will also be notified whenever the scale factor of this surface change, if you don’t want to have to periodically check it.

Trait Implementations§

source§

impl<E> Clone for Environment<E>

source§

fn clone(&self) -> Environment<E>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<E> Debug for Environment<E>where E: Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<E> !RefUnwindSafe for Environment<E>

§

impl<E> !Send for Environment<E>

§

impl<E> !Sync for Environment<E>

§

impl<E> Unpin for Environment<E>

§

impl<E> !UnwindSafe for Environment<E>

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.