Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve x11 startup times #5923

Merged
merged 1 commit into from
Aug 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 46 additions & 3 deletions window/src/os/x11/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,34 @@ use x11::xlib;
use xcb::x::Atom;
use xcb::{dri2, Raw, Xid};

enum ScreenResources {
Current(xcb::randr::GetScreenResourcesCurrentReply),
All(xcb::randr::GetScreenResourcesReply),
}

impl ScreenResources {
fn outputs(&self) -> &[xcb::randr::Output] {
match self {
Self::Current(cur) => cur.outputs(),
Self::All(all) => all.outputs(),
}
}

fn config_timestamp(&self) -> xcb::x::Timestamp {
match self {
Self::Current(cur) => cur.config_timestamp(),
Self::All(all) => all.config_timestamp(),
}
}

pub fn modes(&self) -> &[xcb::randr::ModeInfo] {
match self {
Self::Current(cur) => cur.modes(),
Self::All(all) => all.modes(),
}
}
}

pub struct XConnection {
pub conn: xcb::Connection,
default_dpi: RefCell<f64>,
Expand Down Expand Up @@ -236,9 +264,24 @@ impl ConnectionOps for XConnection {

let config = config::configuration();

let res = self
.send_and_wait_request(&xcb::randr::GetScreenResources { window: self.root })
.context("get_screen_resources")?;
// NOTE: GetScreenResourcesCurrent is fast, but may sometimes return nothing. In this case,
// fallback to slow GetScreenResources.
//
// references:
// - https://github.com/qt/qtbase/blob/c234700c836777d08db6229fdc997cc7c99e45fb/src/plugins/platforms/xcb/qxcbscreen.cpp#L963
// - https://github.com/qt/qtbase/blob/c234700c836777d08db6229fdc997cc7c99e45fb/src/plugins/platforms/xcb/qxcbconnection_screens.cpp#L390
//
// related issue: https://github.com/wez/wezterm/issues/5802
let res = match self
.send_and_wait_request(&xcb::randr::GetScreenResourcesCurrent { window: self.root })
.context("get_screen_resources_current")
{
Ok(cur) if cur.outputs().len() > 0 => ScreenResources::Current(cur),
_ => ScreenResources::All(
self.send_and_wait_request(&xcb::randr::GetScreenResources { window: self.root })
.context("get_screen_resources")?,
),
};

let mut virtual_rect: ScreenRect = euclid::rect(0, 0, 0, 0);
let mut by_name = HashMap::new();
Expand Down
Loading