Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Commit

Permalink
Removed missed manual duplicate modifier_type
Browse files Browse the repository at this point in the history
  • Loading branch information
EPashkin committed Mar 27, 2017
1 parent c2ab311 commit c1fba76
Showing 1 changed file with 0 additions and 24 deletions.
24 changes: 0 additions & 24 deletions src/enums.rs
Expand Up @@ -2,30 +2,6 @@
// See the COPYRIGHT file at the top-level directory of this distribution.
// Licensed under the MIT license, see the LICENSE file or <http://opensource.org/licenses/MIT>

#[allow(non_upper_case_globals)]
pub mod modifier_type {
use ffi;

pub const ShiftMask: ffi::GdkModifierType = ffi::GDK_SHIFT_MASK;
pub const LockMask: ffi::GdkModifierType = ffi::GDK_LOCK_MASK;
pub const ControlMask: ffi::GdkModifierType = ffi::GDK_CONTROL_MASK;
pub const Mod1Mask: ffi::GdkModifierType = ffi::GDK_MOD1_MASK;
pub const Mod2Mask: ffi::GdkModifierType = ffi::GDK_MOD2_MASK;
pub const Mod3Mask: ffi::GdkModifierType = ffi::GDK_MOD3_MASK;
pub const Mod4Mask: ffi::GdkModifierType = ffi::GDK_MOD4_MASK;
pub const Mod5Mask: ffi::GdkModifierType = ffi::GDK_MOD5_MASK;
pub const Button1Mask: ffi::GdkModifierType = ffi::GDK_BUTTON1_MASK;
pub const Button2Mask: ffi::GdkModifierType = ffi::GDK_BUTTON2_MASK;
pub const Button3Mask: ffi::GdkModifierType = ffi::GDK_BUTTON3_MASK;
pub const Button4Mask: ffi::GdkModifierType = ffi::GDK_BUTTON4_MASK;
pub const Button5Mask: ffi::GdkModifierType = ffi::GDK_BUTTON5_MASK;
pub const SuperMask: ffi::GdkModifierType = ffi::GDK_SUPER_MASK;
pub const HyperMask: ffi::GdkModifierType = ffi::GDK_HYPER_MASK;
pub const MetaMask: ffi::GdkModifierType = ffi::GDK_META_MASK;
pub const ReleaseMask: ffi::GdkModifierType = ffi::GDK_RELEASE_MASK;
pub const ModifierMask: ffi::GdkModifierType = ffi::GDK_MODIFIER_MASK;
}

#[allow(non_upper_case_globals)]
pub mod key {
use ffi;
Expand Down

9 comments on commit c1fba76

@cars10
Copy link

@cars10 cars10 commented on c1fba76 May 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the proposed way of migrating with this change? I was using this enum to check for ctrl key:

        if key.as_ref().state.intersects(gdk::enums::modifier_type::ControlMask) &&
            key.as_ref().keyval == 113 {
            gtk::main_quit();
        }

@EPashkin
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't check it now but something like gdk::CONTROL_MASK or gdk::auto::flags::CONTROL_MASK

@cars10
Copy link

@cars10 cars10 commented on c1fba76 May 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mh, this wont work. GdkModifierType#intersects expects an GdkModifierType as argument, the CONTORL_MASK you mentions is only an integer.

see http://gtk-rs.org/docs/gdk_sys/struct.GdkModifierType.html#method.intersects

@EPashkin
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange it must be not integer https://github.com/gtk-rs/gdk/blob/master/src/auto/flags.rs#L184-L219
Maybe you also need use to_glib()

@cars10
Copy link

@cars10 cars10 commented on c1fba76 May 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, forget the integer. I was just skimming through the code and thought its an integer because i saw a number. Playing around now i actually found gdk::CONTROL_MASK to propably do what i want, but i am still getting errors because of the wrong type:

        if key.as_ref().state.intersects(gdk::CONTROL_MASK) &&
            key.as_ref().keyval == 113 {
            gtk::main_quit();
        }
expected struct `gdk_sys::GdkModifierType`, found struct `gdk::ModifierType`

@EPashkin
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then sure .to_glib()

@EPashkin
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

key don't have function, returning gdk::ModifierType?

@EPashkin
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems have https://github.com/gtk-rs/gdk/blob/master/src/event_key.rs#L18, then you can use intersects directly

@cars10
Copy link

@cars10 cars10 commented on c1fba76 May 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! It's working now.

Complete example:

// somewhere:
extern crate glib;
use glib::translate::ToGlib;

// then to quit on CTRL+Q:
window.connect_key_press_event(|_, key| {
    if key.as_ref().state.intersects(gdk::CONTROL_MASK.to_glib()) &&
        key.as_ref().keyval == 113 {
        gtk::main_quit();
    }

    Inhibit(false)
});

Please sign in to comment.