From 4fead3171ecdd1513d420af040c9ff75b9cefe41 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Fri, 19 Aug 2022 21:02:51 -0700 Subject: [PATCH] macos: report max_fps in ScreenInfo Other platforms can be added later --- docs/config/lua/wezterm.gui/screens.md | 2 +- lua-api-crates/window-funcs/src/lib.rs | 2 ++ window/src/os/macos/connection.rs | 4 +++- window/src/os/wayland/connection.rs | 10 +++++++++- window/src/os/wayland/output.rs | 10 +++++++++- window/src/os/windows/connection.rs | 1 + window/src/os/x11/connection.rs | 1 + window/src/screen.rs | 1 + 8 files changed, 27 insertions(+), 4 deletions(-) diff --git a/docs/config/lua/wezterm.gui/screens.md b/docs/config/lua/wezterm.gui/screens.md index 02ebd5b33..c7fd535c2 100644 --- a/docs/config/lua/wezterm.gui/screens.md +++ b/docs/config/lua/wezterm.gui/screens.md @@ -52,4 +52,4 @@ The screen information is a table with the following keys: * `name` - the name of the screen. * `x`, `y`, `width`, `height` - the bounds of this screen - +* `max_fps` - the maximum refresh rate supported by the screen, if known, or `nil` otherwise. (*Since: nightly builds only*) diff --git a/lua-api-crates/window-funcs/src/lib.rs b/lua-api-crates/window-funcs/src/lib.rs index 2367bfc23..673d2b03c 100644 --- a/lua-api-crates/window-funcs/src/lib.rs +++ b/lua-api-crates/window-funcs/src/lib.rs @@ -20,6 +20,7 @@ pub struct ScreenInfo { pub width: isize, pub height: isize, pub scale: f64, + pub max_fps: Option, } impl_lua_conversion_dynamic!(ScreenInfo); @@ -44,6 +45,7 @@ impl From for ScreenInfo { width: info.rect.width(), height: info.rect.height(), scale: info.scale, + max_fps: info.max_fps, } } } diff --git a/window/src/os/macos/connection.rs b/window/src/os/macos/connection.rs index 2e5fcbc32..0e530241c 100644 --- a/window/src/os/macos/connection.rs +++ b/window/src/os/macos/connection.rs @@ -9,7 +9,7 @@ use crate::spawn::*; use crate::Appearance; use cocoa::appkit::{NSApp, NSApplication, NSApplicationActivationPolicyRegular, NSScreen}; use cocoa::base::{id, nil}; -use cocoa::foundation::{NSArray, NSRect}; +use cocoa::foundation::{NSArray, NSInteger, NSRect}; use objc::runtime::Object; use objc::*; use std::cell::RefCell; @@ -165,10 +165,12 @@ fn nsscreen_to_screen_info(screen: *mut Object) -> ScreenInfo { frame.size.width as isize, frame.size.height as isize, ); + let max_fps: NSInteger = unsafe { msg_send!(screen, maximumFramesPerSecond) }; ScreenInfo { name, rect, scale: 1.0, + max_fps: Some(max_fps as usize), } } diff --git a/window/src/os/wayland/connection.rs b/window/src/os/wayland/connection.rs index 17c3738e7..0a671b9b4 100644 --- a/window/src/os/wayland/connection.rs +++ b/window/src/os/wayland/connection.rs @@ -480,7 +480,15 @@ impl ConnectionOps for WaylandConnection { let scale = info.scale_factor as f64; virtual_rect = virtual_rect.union(&rect); - by_name.insert(name.clone(), ScreenInfo { name, rect, scale }); + by_name.insert( + name.clone(), + ScreenInfo { + name, + rect, + scale, + max_fps: None, + }, + ); }); } diff --git a/window/src/os/wayland/output.rs b/window/src/os/wayland/output.rs index 8448dc9be..4bd31fbe2 100644 --- a/window/src/os/wayland/output.rs +++ b/window/src/os/wayland/output.rs @@ -229,7 +229,15 @@ impl OutputHandler { height as isize, ); virtual_rect = virtual_rect.union(&rect); - by_name.insert(name.clone(), ScreenInfo { name, rect, scale }); + by_name.insert( + name.clone(), + ScreenInfo { + name, + rect, + scale, + max_fps: None, + }, + ); } if by_name.is_empty() { diff --git a/window/src/os/windows/connection.rs b/window/src/os/windows/connection.rs index a54a5e03b..79a414cc6 100644 --- a/window/src/os/windows/connection.rs +++ b/window/src/os/windows/connection.rs @@ -154,6 +154,7 @@ impl ConnectionOps for Connection { mi.rcMonitor.bottom as isize - mi.rcMonitor.top as isize, ), scale: 1.0, + max_fps: None, }; info.virtual_rect = info.virtual_rect.union(&screen_info.rect); diff --git a/window/src/os/x11/connection.rs b/window/src/os/x11/connection.rs index c9c3bf302..e40e9ae92 100644 --- a/window/src/os/x11/connection.rs +++ b/window/src/os/x11/connection.rs @@ -187,6 +187,7 @@ impl ConnectionOps for XConnection { name: name.clone(), rect: bounds, scale: 1.0, + max_fps: None, }; by_name.insert(name, info); } diff --git a/window/src/screen.rs b/window/src/screen.rs index 335448e33..4ac98cd6a 100644 --- a/window/src/screen.rs +++ b/window/src/screen.rs @@ -14,4 +14,5 @@ pub struct ScreenInfo { pub name: String, pub rect: ScreenRect, pub scale: f64, + pub max_fps: Option, }