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

[Bug] GetPropertyType incorrectly holds a u8 instead of a u32 #92

Open
Jeansidharta opened this issue Aug 2, 2023 · 2 comments
Open

Comments

@Jeansidharta
Copy link

My Specific case

I'm writing a program that reads the current focused window title. For that, I'm trying to read the WM_NAME property of my focused window. By using the xprop command, I can see the atom type of the WM_NAME is UTF8_STRING, and by using the command xlsatoms | grep UTF8_STRING, I can see it's id is 408. Therefore, I tried writing this code:

const UTF8_STRING_ATOM: u32 = 408;
let window_title = {
    let cookie = connection.get_property(
        false,
        focused_window,
        wm_name_atom,
        UTF8_STRING_ATOM,
        0,
        1024,
    )?;
    connection.wait_for_reply(cookie)?
};

However, I'm getting this compiler error:

UTF8_STRING_ATOM,
^^^^^^^^^^^^^^^^ the trait `From<u32>` is not implemented for `GetPropertyType`

The Problem

The struct GetPropertyType internally holds a u8 instead of a u32, and therefore, when calling connection.get_property, the atom type can only be up to 255.

This does not conform to the X11 specification, which states that the type argument is of type ATOM, which is a 32 bit value.

Proposed Solution

Change the internal value of GetPropertyType to be a u32, and implement the trait From<u32>.

Workarounds

Instead of using the correct type in the function get_property, using the breadx::protocol::xproto::AtomEnum::ANY type works. Example:

let any_type_atom: u8 = breadx::protocol::xproto::AtomEnum::ANY.into();
let window_title = {
    let cookie = connection.get_property(
        false,
        focused_window,
        wm_name_atom,
        any_type_atom,
        0,
        1024,
    )?;
    connection.wait_for_reply(cookie)?
};
@Jeansidharta
Copy link
Author

Jeansidharta commented Aug 2, 2023

I just realized the GetPropertyType is not defined in this crate. It's defined in the x11rb crate. However, the GetPropertyType struct doesn't seem to be used anywhere in the x11rb crate.

In x11rb, the get_property function is defined here, and the GetPropertyRequest struct is defined here. In both instances, the type can be supplied with a u32.

Maybe the solution then would be to not use the GetPropertyType struct at all, and replace all instances of impl Into<GetPropertyType> (such as in here) with impl Into<Atom>?

@notgull
Copy link
Member

notgull commented Aug 2, 2023

Yeah, using a less strict option would probably work in this case.

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

No branches or pull requests

2 participants