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

Fix and publish X11 screen id #2

Open
wants to merge 2 commits into
base: 0.27.x
Choose a base branch
from
Open
Show file tree
Hide file tree
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
18 changes: 12 additions & 6 deletions examples/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,28 @@ use simple_logger::SimpleLogger;
use winit::{
event::{Event, WindowEvent},
event_loop::EventLoop,
platform::unix::WindowBuilderExtUnix,
window::WindowBuilder,
};

fn main() {
SimpleLogger::new().init().unwrap();
let screen_number = std::env::args()
.nth(1)
.expect("please specify screen number to run on as first commandline argument")
.parse()
.expect("could not parse first commandline argument as i32");

SimpleLogger::new().env().init().unwrap();
let event_loop = EventLoop::new();

let window = WindowBuilder::new()
let window_builder = WindowBuilder::new()
.with_title("A fantastic window!")
.with_inner_size(winit::dpi::LogicalSize::new(128.0, 128.0))
.build(&event_loop)
.unwrap();
.with_inner_size(winit::dpi::LogicalSize::new(500.0, 500.0))
.with_x11_screen(screen_number);
let window = window_builder.build(&event_loop).unwrap();

event_loop.run(move |event, _, control_flow| {
control_flow.set_wait();
println!("{:?}", event);

match event {
Event::WindowEvent {
Expand Down
5 changes: 4 additions & 1 deletion src/platform_impl/linux/x11/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,10 @@ impl UnownedWindow {
pl_attribs: PlatformSpecificWindowBuilderAttributes,
) -> Result<UnownedWindow, RootOsError> {
let xconn = &event_loop.xconn;
let root = event_loop.root;
let root = match pl_attribs.screen_id {
Some(screen_id) => unsafe { (xconn.xlib.XRootWindow)(xconn.display, screen_id) },
None => event_loop.root,
};

let mut monitors = xconn.available_monitors();
let guessed_monitor = if monitors.is_empty() {
Expand Down
2 changes: 1 addition & 1 deletion src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ pub struct WindowBuilder {
pub(crate) window: WindowAttributes,

// Platform-specific configuration.
pub(crate) platform_specific: platform_impl::PlatformSpecificWindowBuilderAttributes,
pub platform_specific: platform_impl::PlatformSpecificWindowBuilderAttributes,
}

impl fmt::Debug for WindowBuilder {
Expand Down
Loading