proton_screen_monitor

Native screen and display queries plus hot-plug events for MoonBit on Windows, Linux, and macOS.

screen
display
monitor
native
windows
linux
macos
moon add moonbit-community/proton_screen_monitor@0.2.2
Download zip
Version
0.2.2
License
Apache-2.0
Last updated
4 hours ago
Downloads
5
README

#proton_screen_monitor

Native screen and display queries plus hot-plug events for MoonBit on Windows, Linux, and macOS.

The module mirrors Electron's screen module:

  • ScreenMonitor::displays()screen.getAllDisplays()
  • ScreenMonitor::primary_display()screen.getPrimaryDisplay()
  • ScreenMonitor::display_nearest_point(x, y)screen.getDisplayNearestPoint(...)
  • ScreenMonitor::cursor_point()screen.getCursorScreenPoint()
  • DisplayAdded / DisplayRemoved / DisplayMetricsChanged events — screen.on('display-added' | 'display-removed' | 'display-metrics-changed')

Coordinates are physical pixels in a top-left origin. On Linux the backend uses X11 + RandR; a Wayland-only session reports BackendUnavailable for watching while polling queries remain available through XWayland when present. The module is published on Proton's shared workspace version.

#
ScreenMonitorError

pub(all) suberror ScreenMonitorError {
BackendUnavailable(detail~ : String)
OperationFailed(operation~ : String, detail~ : String)
Empty
} derive(Eq)

#
ScreenMonitorError::equal

#
ScreenMonitorError::not_equal

#
ScreenMonitorError::output

fn ScreenMonitorError::output(self : ScreenMonitorError, logger : &Logger) -> Unit

#
ScreenMonitorError::to_string

fn ScreenMonitorError::to_string(self : ScreenMonitorError) -> String

#
DisplayInfo

pub struct DisplayInfo {
id : Int
bounds : Rect
work_area : Rect
scale_factor : Double
is_primary : Bool
} derive(Eq,
Debug
)

A display geometry snapshot mirroring Electron's Display.

#
DisplayInfo::equal

fn DisplayInfo::equal(DisplayInfo, DisplayInfo) -> Bool

#
DisplayInfo::not_equal

fn DisplayInfo::not_equal(x : DisplayInfo, y : DisplayInfo) -> Bool

#
DisplaysWire

type DisplaysWire derive(
FromJson
)

Wire shapes produced by the native backend's JSON payloads.

#
Point

pub struct Point {
x : Int
y : Int
} derive(Eq,
Debug
)

A point in the root (physical pixel) coordinate space.

#
Point::equal

fn Point::equal(Point, Point) -> Bool

#
Point::not_equal

fn Point::not_equal(x : Point, y : Point) -> Bool

#
Point::to_repr

#
Rect

pub struct Rect {
x : Int
y : Int
width : Int
height : Int
} derive(Eq,
Debug
)

A rectangle in physical pixel coordinates with the top-left origin shared across the facade.

#
Rect::equal

fn Rect::equal(Rect, Rect) -> Bool

#
Rect::not_equal

fn Rect::not_equal(x : Rect, y : Rect) -> Bool

#
Rect::to_repr

#
ScreenMonitor

pub struct ScreenMonitor {
// private fields
}

#
ScreenMonitor::ScreenMonitor

fn ScreenMonitor::ScreenMonitor() -> ScreenMonitor raise ScreenMonitorError

Creates a new screen monitor handle. The native backend is verified during creation so an unavailable platform surfaces immediately as BackendUnavailable.

#
ScreenMonitor::cursor_point

fn ScreenMonitor::cursor_point(self : ScreenMonitor) -> Point raise ScreenMonitorError

Returns the current cursor position in physical pixels with the top-left origin. Corresponds to Electron's screen.getCursorScreenPoint().

#
ScreenMonitor::destroy

fn ScreenMonitor::destroy(self : ScreenMonitor) -> Unit

Releases the native backend and tears the watch thread down. Idempotent.

#
ScreenMonitor::display_nearest_point

fn ScreenMonitor::display_nearest_point(self : ScreenMonitor, x : Int, y : Int) -> DisplayInfo raise ScreenMonitorError

Returns the display that is nearest to the given point, preferring a display that actually contains the point. Corresponds to Electron's screen.getDisplayNearestPoint(point).

#
ScreenMonitor::displays

Returns every connected display, with the primary display listed first. Corresponds to Electron's screen.getAllDisplays().

#
ScreenMonitor::drain_events

Drains every pending event from the queue. Returns an empty array when no event is pending; never raises for an empty queue.

#
ScreenMonitor::primary_display

fn ScreenMonitor::primary_display(self : ScreenMonitor) -> DisplayInfo raise ScreenMonitorError

Returns the primary display. Corresponds to Electron's screen.getPrimaryDisplay(); raises Empty when no display is connected.

#
ScreenMonitor::start_watching

fn ScreenMonitor::start_watching(self : ScreenMonitor) -> Unit raise ScreenMonitorError

Starts the event watch backend. The backend is best-effort: a platform that cannot watch (for example Linux without an X11 display or RandR) records the failure on the native side and returns BackendUnavailable, leaving polling queries fully usable.

#
ScreenMonitor::stop_watching

fn ScreenMonitor::stop_watching(self : ScreenMonitor) -> Unit raise ScreenMonitorError

Stops the event watch backend and joins its thread. Idempotent.

#
ScreenMonitorEvent

pub enum ScreenMonitorEvent {
DisplayAdded
DisplayRemoved
DisplayMetricsChanged
} derive(Eq,
Debug
)

Display topology events delivered by the watch backend, mirroring Electron's screen module events.

#
ScreenMonitorEvent::equal

#
ScreenMonitorEvent::not_equal

#
State

pub type State