jeremyletang / rgtk

GTK+ bindings and wrappers for Rust (DEPRECATED SEE https://github.com/rust-gnome )
GNU Lesser General Public License v3.0
121 stars 22 forks source link

is_modified wrong? #137

Closed buster closed 9 years ago

buster commented 9 years ago

While looking at how EventKey works i was comparing https://developer.gnome.org/gdk3/stable/gdk3-Event-Structures.html#GdkEventKey with https://github.com/jeremyletang/rgtk/blob/master/src/gdk/events.rs#L204

The official doc says that this is called "is_modifier" and it's a flag if the key is a modifier, whereas the rgtk is a u32.

GuillaumeGomez commented 9 years ago

I check it. Thx for your report.

buster commented 9 years ago

Also, how would i check if a key is pressed while CTRL is pressed? There is the state variable on the EventKey and i found ControlMask in gdk/enums.rs. How do i match those?

GuillaumeGomez commented 9 years ago

If I have time I'll check that this week-end. Let's hope @jeremyletang will take a look at it before that ! ;)

GuillaumeGomez commented 9 years ago

But the way, I modified is_modified by is_modifier, I'll check the rest tomorrow if I have time.

GuillaumeGomez commented 9 years ago

To check if CTRL is pressed while a touch is pressed, just do :

if event.state & gdk::ControlMask {
   ...
}

I couldn't find anything about the "real" type of is_modifier.

buster commented 9 years ago

Would you mind showing an exmaple for the state and value? I can't seem to figure it out.. Events.rs shows the following definition:

pub struct EventKey {
    pub _type : gdk::EventType,
    pub window : *mut gdk::Window,
    send_event : i8,

    pub time : u32,
    pub state : u32,
    pub keyval : u32,
    pub length : i32,
    pub string : *mut char,
    pub hardware_keycode : u16,
    pub group : u8,
    pub is_modifier: u32
}
buster commented 9 years ago

The reason is that i would like to get rid of comparisons with integers as shown here: https://github.com/buster/rrun/blob/master/src/main.rs#L31 and here: https://github.com/buster/rrun/blob/master/src/main.rs#L35

GuillaumeGomez commented 9 years ago

gdk::EscapeKey or something like should exist no ? All the keys should have their enum value. However, we should change the keyval type from u32 to the corresponding enum's name. @jeremyletang ?

buster commented 9 years ago

that's why i am asking, i can't seem to find the right use statement, i always get error: unresolved nameControlMask``

GuillaumeGomez commented 9 years ago

Weird. Do you get it from here ?

buster commented 9 years ago

For example, "use rgtk::gdk::enums::modifier_type::ModifierType;" doesn't work although rustc doesn't complain about an invalid use statement (which makes me think that the use statement itself finds something).

Using EscapeKey for the keypress match returns:

/src/main.rs:32:13: 32:27 error: unresolved enum variant, struct or const `EscapeKey`
/src/main.rs:32             gdk::EscapeKey => gtk::main_quit(),
GuillaumeGomez commented 9 years ago

I said EscapeKey just like that... And I was totally wrong. It's more complicated than I first thought ! I don't have time now but this link seems to be a good start for you search.

GuillaumeGomez commented 9 years ago

Or this one ! I don't think we did bind it yet.

GuillaumeGomez commented 9 years ago

Take a look at the #142 PR (and I created a Key type in the #143).

buster commented 9 years ago

Hi Guillaume, thanks for all that, but i seem to be too stupid to make use of those enums. How should the import look like?

GuillaumeGomez commented 9 years ago

Something like this if I'm not wrong :

use rgtk::gdk::key;

key::BackSpace