Skip to main content

Monitor

Struct Monitor 

Source
pub struct Monitor<T> { /* private fields */ }
Expand description

Represents a connected display monitor with its own OpenGL ES rendering context.

Each monitor manages:

  • DRM resources (connector, CRTC, planes)
  • Display mode configuration with 3-state tracking
  • Independent OpenGL ES context
  • Render state tracking

§Display Modes (3-State System)

  • default_mode: The optimal mode for this monitor (highest resolution + refresh rate)
    • e.g., 4K@120Hz for a high-end monitor
    • This is the fallback when no custom mode is requested
  • requested_mode: The mode the user wants to use
    • None means use the optimal default mode
    • Some(mode) means use a custom mode (e.g., 1080p@60Hz)
  • current_mode: The mode currently set in hardware
    • None if no mode has been set yet (new monitor) or TTY lost focus
    • Some(mode) is the last mode successfully committed to DRM
    • Compared against requested_mode each frame to trigger mode sets

§Rendering Flow

ⓘ
if monitor.can_render() {
    monitor.make_current()?;
    // OpenGL rendering calls here...
    gl::Clear(gl::COLOR_BUFFER_BIT);
}
// EasyDRM::swap_buffers() will orchestrate the monitor swaps

Implementations§

Source§

impl<T> Monitor<T>

Source

pub fn context(&self) -> &T

Get a reference to the user context

Source

pub fn context_mut(&mut self) -> &mut T

Get a mutable reference to the user context

Source

pub fn can_render(&self) -> bool

Returns whether this monitor is ready to be rendered to.

This is updated by poll_events() based on page flip completion and VBlank timing. Only render to monitors where this returns true to avoid frame drops.

Source

pub fn make_current(&mut self) -> Result<(), GlesContextError>

Makes this monitor’s OpenGL context current for rendering.

Call this before any OpenGL rendering operations. Automatically marks this monitor as having been drawn to for this frame.

§Errors

Returns an error if the EGL context cannot be made current.

§Example
ⓘ
if monitor.can_render() {
    monitor.make_current()?;
    gl::ClearColor(0.0, 0.0, 0.0, 1.0);
    gl::Clear(gl::COLOR_BUFFER_BIT);
}
Source

pub fn gl(&self) -> &Gles2

Gets a reference to the OpenGL ES bindings.

This provides direct access to all OpenGL ES functions for this monitor. The GL context is automatically initialized when the monitor is created.

§Example
ⓘ
monitor.make_current()?;
let gl = monitor.gl();
unsafe {
    gl.ClearColor(0.0, 0.0, 0.0, 1.0);
    gl.Clear(gl::COLOR_BUFFER_BIT);
}
Source

pub fn get_proc_address(&self, symbol: &str) -> *const c_void

Gets a function pointer for loading OpenGL functions.

This is provided for compatibility with external libraries that need to load their own GL function pointers. Most users should use gl() instead.

§Example
ⓘ
// For use with external libraries
external_lib::load_with(|symbol| monitor.get_proc_address(symbol));
Source

pub fn connector_id(&self) -> Handle

Returns the DRM connector handle for this monitor.

Source

pub fn crtc(&self) -> &Info

Returns the CRTC information for this monitor.

Source

pub fn default_mode(&self) -> &Mode

Returns the optimal display mode for this monitor.

This is the preferred mode reported by the monitor (typically the highest resolution and refresh rate supported, e.g., 4K@120Hz).

Source

pub fn current_mode(&self) -> Option<&Mode>

Returns the mode currently set in hardware.

Returns None if no mode has been set yet (new monitor or after TTY focus loss). Returns Some(&Mode) if a mode has been successfully committed to DRM.

This may differ from requested_mode() briefly during mode transitions.

Source

pub fn requested_mode(&self) -> Option<&Mode>

Returns the mode that should be used for rendering.

Returns None if the optimal default mode should be used. Returns Some(&Mode) if a custom mode has been requested (e.g., downscaled to 1080p or lower refresh rate).

Source

pub fn set_mode(&mut self, mode: Option<Mode>)

Sets the requested display mode for this monitor.

This allows using a different mode than the optimal default (e.g., lower resolution or refresh rate for compatibility).

The mode change will take effect on the next swap_buffers() call if it differs from the current hardware state.

§Arguments
  • mode - The new display mode, or None to revert to the optimal default
§Example
ⓘ
// Use 1080p@60Hz instead of the default 4K@120Hz
let mode_1080p = find_mode_by_resolution(monitor, 1920, 1080);
monitor.set_mode(Some(mode_1080p));

// Revert to optimal default
monitor.set_mode(None);
Source

pub fn active_mode(&self) -> &Mode

Returns the effective display mode for rendering.

This is a convenience method that returns the requested mode if set, otherwise returns the optimal default mode.

Use this to determine what resolution/refresh rate to render at.

§Example
ⓘ
let active = monitor.active_mode();
println!("Rendering at {}x{} @ {}Hz",
    active.size().0, active.size().1, active.vrefresh());
Source

pub fn primary_plane(&self) -> Handle

Returns the handle to the primary plane used for scanout.

Source

pub fn cursor_plane(&self) -> Option<Handle>

Returns the handle to the cursor plane, if available.

Some GPUs (especially virtual ones like virtio-gpu) don’t expose a separate cursor plane.

Source

pub fn size(&self) -> (u16, u16)

Returns the current resolution as (width, height).

Uses the requested mode if one has been set, otherwise returns the optimal default mode’s resolution.

Trait Implementations§

Source§

impl<T> Drop for Monitor<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<T> Eq for Monitor<T>

Source§

impl<T> Hash for Monitor<T>

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T> PartialEq for Monitor<T>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for Monitor<T>

§

impl<T> !Send for Monitor<T>

§

impl<T> !Sync for Monitor<T>

§

impl<T> !UnwindSafe for Monitor<T>

§

impl<T> Freeze for Monitor<T>
where T: Freeze,

§

impl<T> Unpin for Monitor<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Monitor<T>
where T: UnsafeUnpin,

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.