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

Wont compile without -lX11 #94

Open
ghost opened this issue Jan 20, 2019 · 4 comments
Open

Wont compile without -lX11 #94

ghost opened this issue Jan 20, 2019 · 4 comments

Comments

@ghost
Copy link

ghost commented Jan 20, 2019

I am attempting to make a function that get the resolution and refresh rate of the monitor(only figured out resolution so far) and I can only compile it atm by running the function in its on project and building it with cargo rustc -- -lX11

My Code

use std::ptr;
use x11::xlib::{XCloseDisplay, XOpenDisplay, XScreenCount, XScreenOfDisplay};

pub fn resolution() {
    unsafe {
        // open a display
        let display = XOpenDisplay(ptr::null());
        // return the number of available screens
        let count_screens = XScreenCount(display);

        println!("Number of screens: {}", count_screens);
        for i in 0..count_screens {
            let screen = *XScreenOfDisplay(display, i);
            println!("\tScreen {}: {}x{}", i + 1, screen.width, screen.height);
        }
        // close the display
        XCloseDisplay(display);
    }
}

pub fn main() {
    resolution();
}

This my Cargo.toml

[package]
edition = "2018"
 
[dependencies]
libc = "0.2"
x11 = "2.18.1"

Am I doing something wrong? Is there anyway I can run this from with a project with multiple file inside the src directory?

@ghost
Copy link
Author

ghost commented Jan 26, 2019

It adds -lX11 when the xlib feature is enabled. It was left off by default for those who want to use the other libraries but not libX11.

[dependencies]
x11 = { version = "2.18.1", features = ["xlib"] }

@ghost
Copy link
Author

ghost commented Jan 26, 2019

Oh my mistake, that makes a lot of sense.

Is it possible to get screen resolution and refresh rate using your library without using the xlib for wayland systems?

@ghost
Copy link

ghost commented Nov 10, 2020

Thanks I didnt even know there were feature flags

@ids1024
Copy link

ids1024 commented Aug 24, 2021

The bindings for xlib functions probably shouldn't be complied in when that feature isn't used.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants