Window

Struct Window 

Source
pub struct Window<'dpy>(/* private fields */);
Expand description

The closest possible representation of a desktop window.

Such a concept might not exist on some platforms, in which case, the single window you “create” actually returns an abstraction over the “canvas” or “screen space” you’re allowed to draw to.

See Display to see how to create them.

Implementations§

Source§

impl<'a, 'b: 'a, 'dpy: 'b> Window<'dpy>

Source

pub fn get_capabilities(&self) -> Capabilities

Source

pub fn show(&self) -> WindowOpResult

A window won’t appear until this method is called.

Examples found in repository?
examples/window.rs (line 11)
7fn main() {
8    let display = Display::open().expect("Could not open display!");
9    let window = display.create_window(&Default::default()).expect("Couldn't create window!");
10    window.set_title("Three");
11    window.show();
12    sleep(Duration::from_secs(1));
13    window.set_title("Two");
14    sleep(Duration::from_secs(1));
15    window.set_title("One");
16    sleep(Duration::from_secs(1));
17}
Source

pub fn hide(&self) -> WindowOpResult

The obvious reciprocal of show().

Source

pub fn set_title(&self, title: &str) -> WindowOpResult

Sets the window’s title.

Examples found in repository?
examples/window.rs (line 10)
7fn main() {
8    let display = Display::open().expect("Could not open display!");
9    let window = display.create_window(&Default::default()).expect("Couldn't create window!");
10    window.set_title("Three");
11    window.show();
12    sleep(Duration::from_secs(1));
13    window.set_title("Two");
14    sleep(Duration::from_secs(1));
15    window.set_title("One");
16    sleep(Duration::from_secs(1));
17}
Source

pub fn set_icon<I: Into<Option<Icon>>>(&self, icon: I) -> WindowOpResult

Source

pub fn set_style(&self, style: &Style) -> WindowOpResult

Attempts to set the window’s borders.

Source

pub fn recenter(&self) -> WindowOpResult

Centers a window relatively to the space it is in, with regards to its size.

Source

pub fn set_opacity(&self, opacity: f32) -> WindowOpResult

Sets the window’s opacity, provided the window was created with the fully_opaque flag set to false.

Valid values for opacity range from 0 to 1 (both inclusive).
You’re expected to clamp the value yourself if needed.

Source

pub unsafe fn get_internal(&'b self) -> &'a Window<'_>

Retrieves the window’s internal implementation details, if you need to work around missing features.

If that happens, you are welcome to report an issue!

Source

pub unsafe fn get_internal_mut(&'dpy mut self) -> &'a mut Window<'_>

Retrieves the window’s internal implementation details, if you need to work around missing features.

If that happens, you are welcome to report an issue!

Source

pub fn create_child( &'b mut self, settings: &Settings, ) -> Result<Window<'a>, Error>

Attempts to create a child window.

The definition of “child window” may vary slightly from platform to platform, but it’s almost always just another window which is closed when its parent gets closed.

Source

pub fn query_screenspace_size(&self) -> Extent2<u32>

The window’s size, in screen coordinates.

You should not rely on this being equal to its size in raster-space coordinates.
If you’re interested in the “canvas”’s dimensions, use the query_canvas_size() method instead.

The query() part means that the operation is possibly heavy and the result is not implicitly cached:
it’s your responsibility to do so if this is what you want.

Source

pub fn query_canvas_size(&self) -> Extent2<u32>

The window’s size, in raster-space coordinates.

On High-DPI-enabled windows, it should be bigger than the size in screen-coordinates.
This is what you should use for pixel-perfect rendering.

The query() part means that the operation is possibly heavy and the result is not implicitly cached:
it’s your responsibility to do so if this is what you want.

Source

pub fn maximize(&self) -> WindowOpResult

Attempts to maximize the window (as in, take as much space as possible).

Source

pub fn minimize(&self) -> WindowOpResult

Attempts to minimize the window (as in, minimize to task bar).

Source

pub fn restore(&self) -> WindowOpResult

The reciprocal of minimize().

Source

pub fn raise(&self) -> WindowOpResult

Attempts to set the window on top of the stack and request focus.

Source

pub fn enter_fullscreen(&self) -> WindowOpResult

Attempts to go full-screen.

The Window struct doesn’t keep track of an is_fullscreen boolean: it is yours to manage if you need one. This method won’t perform the checks for you. However, for convenience, it saves the window’s current size to automatically restore it whenever leaving full-screen mode.

Source

pub fn leave_fullscreen(&self) -> WindowOpResult

Attempts to leave full-screen mode.

See enter_fullscreen().

Source

pub fn set_minimum_size(&self, size: Extent2<u32>) -> WindowOpResult

Unconditionnally prevents the window’s size from going below the given threshold.

Source

pub fn set_maximum_size(&self, size: Extent2<u32>) -> WindowOpResult

Unconditionnally prevents the window’s size from going above the given threshold.

Source

pub fn move_absolute(&self, pos: Extent2<u32>) -> WindowOpResult

Moves the window to the given absolute position in desktop-space.

The anchor is the window’s top-left corner.

Source

pub fn move_relative_to_self(&self, pos: Extent2<u32>) -> WindowOpResult

Moves the window relatively to itself in desktop-space.

The anchor is the window’s top-left corner.

Source

pub fn move_relative_to_parent(&self, pos: Extent2<u32>) -> WindowOpResult

Moves the window relatively to its parent, if any.
Otherwise, this is resolves to move_absolute().

The anchor is the window’s top-left corner.

Source

pub fn resize(&self, size: Extent2<u32>) -> WindowOpResult

Attempts to set the window’s screen-space size.

Trait Implementations§

Source§

impl<'dpy> Debug for Window<'dpy>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'dpy> Freeze for Window<'dpy>

§

impl<'dpy> RefUnwindSafe for Window<'dpy>

§

impl<'dpy> !Send for Window<'dpy>

§

impl<'dpy> !Sync for Window<'dpy>

§

impl<'dpy> Unpin for Window<'dpy>

§

impl<'dpy> UnwindSafe for Window<'dpy>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where 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 T
where 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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 T
where U: TryFrom<T>,

Source§

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.