1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384
use crate::ModifierType; use glib::{ object::{IsA, ObjectType as ObjectType_}, translate::*, GString, StaticType, Value, }; use std::boxed::Box as Box_; use std::fmt; glib_wrapper! { pub struct BindingPool(Object<ffi::ClutterBindingPool, ffi::ClutterBindingPoolClass, BindingPoolClass>); match fn { get_type => || ffi::clutter_binding_pool_get_type(), } } impl BindingPool { /// Creates a new `BindingPool` that can be used to store /// key bindings for an actor. The `name` must be a unique identifier /// for the binding pool, so that `BindingPool::find` will /// be able to return the correct binding pool. /// ## `name` /// the name of the binding pool /// /// # Returns /// /// the newly created binding pool with the given /// name. Use `gobject::ObjectExt::unref` when done. pub fn new(name: &str) -> BindingPool { unsafe { from_glib_full(ffi::clutter_binding_pool_new(name.to_glib_none().0)) } } /// Activates the callback associated to the action that is /// bound to the `key_val` and `modifiers` pair. /// /// The callback has the following signature: /// /// /// ```text /// void (* callback) (GObject *gobject, /// const gchar *action_name, /// guint key_val, /// ModifierType modifiers, /// gpointer user_data); /// ``` /// /// Where the `gobject::Object` instance is `gobject` and the user data /// is the one passed when installing the action with /// `BindingPool::install_action`. /// /// If the action bound to the `key_val`, `modifiers` pair has been /// blocked using `BindingPool::block_action`, the callback /// will not be invoked, and this function will return `false`. /// ## `key_val` /// the key symbol /// ## `modifiers` /// bitmask for the modifiers /// ## `gobject` /// a `gobject::Object` /// /// # Returns /// /// `true` if an action was found and was activated pub fn activate<P: IsA<glib::Object>>( &self, key_val: u32, modifiers: ModifierType, gobject: &P, ) -> bool { unsafe { from_glib(ffi::clutter_binding_pool_activate( self.to_glib_none().0, key_val, modifiers.to_glib(), gobject.as_ref().to_glib_none().0, )) } } /// Blocks all the actions with name `action_name` inside `self`. /// ## `action_name` /// an action name pub fn block_action(&self, action_name: &str) { unsafe { ffi::clutter_binding_pool_block_action( self.to_glib_none().0, action_name.to_glib_none().0, ); } } /// Retrieves the name of the action matching the given key symbol /// and modifiers bitmask. /// ## `key_val` /// a key symbol /// ## `modifiers` /// a bitmask for the modifiers /// /// # Returns /// /// the name of the action, if found, or `None`. The /// returned string is owned by the binding pool and should never /// be modified or freed pub fn find_action(&self, key_val: u32, modifiers: ModifierType) -> Option<GString> { unsafe { from_glib_none(ffi::clutter_binding_pool_find_action( self.to_glib_none().0, key_val, modifiers.to_glib(), )) } } // /// Installs a new action inside a `BindingPool`. The action // /// is bound to `key_val` and `modifiers`. // /// // /// The same action name can be used for multiple `key_val`, `modifiers` // /// pairs. // /// // /// When an action has been activated using `BindingPool::activate` // /// the passed `callback` will be invoked (with `data`). // /// // /// Actions can be blocked with `BindingPool::block_action` // /// and then unblocked using `BindingPool::unblock_action`. // /// ## `action_name` // /// the name of the action // /// ## `key_val` // /// key symbol // /// ## `modifiers` // /// bitmask of modifiers // /// ## `callback` // /// function to be called // /// when the action is activated // /// ## `data` // /// data to be passed to `callback` // /// ## `notify` // /// function to be called when the action is removed // /// from the pool // pub fn install_action<P: Fn(&glib::Object, &str, u32, &ModifierType) -> bool + 'static>( // &self, // action_name: &str, // key_val: u32, // modifiers: ModifierType, // callback: P, // ) { // let callback_data: Box_<P> = Box_::new(callback); // unsafe extern "C" fn callback_func< // P: Fn(&glib::Object, &str, u32, &ModifierType) -> bool + 'static, // >( // gobject: *mut gobject_sys::GObject, // action_name: *const libc::c_char, // key_val: libc::c_uint, // modifiers: ffi::ClutterModifierType, // user_data: glib_sys::gpointer, // ) -> glib_sys::gboolean { // let gobject = from_glib_borrow(gobject); // let action_name: Borrowed<GString> = from_glib_borrow(action_name); // let modifiers = from_glib_borrow(modifiers); // let callback: &P = &*(user_data as *mut _); // let res = (*callback)(&gobject, action_name.as_str(), key_val, &modifiers); // res.to_glib() // } // let callback = Some(callback_func::<P> as _); // unsafe extern "C" fn notify_func< // P: Fn(&glib::Object, &str, u32, &ModifierType) -> bool + 'static, // >( // data: glib_sys::gpointer, // ) { // let _callback: Box_<P> = Box_::from_raw(data as *mut _); // } // let destroy_call6 = Some(notify_func::<P> as _); // let super_callback0: Box_<P> = callback_data; // unsafe { // ffi::clutter_binding_pool_install_action( // self.to_glib_none().0, // action_name.to_glib_none().0, // key_val, // modifiers.to_glib(), // callback, // Box_::into_raw(super_callback0) as *mut _, // destroy_call6, // ); // } // } /// A `gobject::Closure` variant of `BindingPool::install_action`. /// /// Installs a new action inside a `BindingPool`. The action /// is bound to `key_val` and `modifiers`. /// /// The same action name can be used for multiple `key_val`, `modifiers` /// pairs. /// /// When an action has been activated using `BindingPool::activate` /// the passed `closure` will be invoked. /// /// Actions can be blocked with `BindingPool::block_action` /// and then unblocked using `BindingPool::unblock_action`. /// ## `action_name` /// the name of the action /// ## `key_val` /// key symbol /// ## `modifiers` /// bitmask of modifiers /// ## `closure` /// a `gobject::Closure` pub fn install_closure( &self, action_name: &str, key_val: u32, modifiers: ModifierType, closure: &glib::Closure, ) { unsafe { ffi::clutter_binding_pool_install_closure( self.to_glib_none().0, action_name.to_glib_none().0, key_val, modifiers.to_glib(), closure.to_glib_none().0, ); } } // /// Allows overriding the action for `key_val` and `modifiers` inside a // /// `BindingPool`. See `BindingPool::install_action`. // /// // /// When an action has been activated using `BindingPool::activate` // /// the passed `callback` will be invoked (with `data`). // /// // /// Actions can be blocked with `BindingPool::block_action` // /// and then unblocked using `BindingPool::unblock_action`. // /// ## `key_val` // /// key symbol // /// ## `modifiers` // /// bitmask of modifiers // /// ## `callback` // /// function to be called when the action is activated // /// ## `data` // /// data to be passed to `callback` // /// ## `notify` // /// function to be called when the action is removed // /// from the pool // pub fn override_action<P: Fn(&glib::Object, &str, u32, &ModifierType) -> bool + 'static>( // &self, // key_val: u32, // modifiers: ModifierType, // callback: P, // ) { // let callback_data: Box_<P> = Box_::new(callback); // unsafe extern "C" fn callback_func< // P: Fn(&glib::Object, &str, u32, &ModifierType) -> bool + 'static, // >( // gobject: *mut gobject_sys::GObject, // action_name: *const libc::c_char, // key_val: libc::c_uint, // modifiers: ffi::ClutterModifierType, // user_data: glib_sys::gpointer, // ) -> glib_sys::gboolean { // let gobject = from_glib_borrow(gobject); // let action_name: Borrowed<GString> = from_glib_borrow(action_name); // let modifiers = from_glib_borrow(modifiers); // let callback: &P = &*(user_data as *mut _); // let res = (*callback)(&gobject, action_name.as_str(), key_val, &modifiers); // res.to_glib() // } // let callback = Some(callback_func::<P> as _); // unsafe extern "C" fn notify_func< // P: Fn(&glib::Object, &str, u32, &ModifierType) -> bool + 'static, // >( // data: glib_sys::gpointer, // ) { // let _callback: Box_<P> = Box_::from_raw(data as *mut _); // } // let destroy_call5 = Some(notify_func::<P> as _); // let super_callback0: Box_<P> = callback_data; // unsafe { // ffi::clutter_binding_pool_override_action( // self.to_glib_none().0, // key_val, // modifiers.to_glib(), // callback, // Box_::into_raw(super_callback0) as *mut _, // destroy_call5, // ); // } // } /// A `gobject::Closure` variant of `BindingPool::override_action`. /// /// Allows overriding the action for `key_val` and `modifiers` inside a /// `BindingPool`. See `BindingPool::install_closure`. /// /// When an action has been activated using `BindingPool::activate` /// the passed `callback` will be invoked (with `data`). /// /// Actions can be blocked with `BindingPool::block_action` /// and then unblocked using `BindingPool::unblock_action`. /// ## `key_val` /// key symbol /// ## `modifiers` /// bitmask of modifiers /// ## `closure` /// a `gobject::Closure` pub fn override_closure(&self, key_val: u32, modifiers: ModifierType, closure: &glib::Closure) { unsafe { ffi::clutter_binding_pool_override_closure( self.to_glib_none().0, key_val, modifiers.to_glib(), closure.to_glib_none().0, ); } } /// Removes the action matching the given `key_val`, `modifiers` pair, /// if any exists. /// ## `key_val` /// a key symbol /// ## `modifiers` /// a bitmask for the modifiers pub fn remove_action(&self, key_val: u32, modifiers: ModifierType) { unsafe { ffi::clutter_binding_pool_remove_action( self.to_glib_none().0, key_val, modifiers.to_glib(), ); } } /// Unblockes all the actions with name `action_name` inside `self`. /// /// Unblocking an action does not cause the callback bound to it to /// be invoked in case `BindingPool::activate` was called on /// an action previously blocked with `BindingPool::block_action`. /// ## `action_name` /// an action name pub fn unblock_action(&self, action_name: &str) { unsafe { ffi::clutter_binding_pool_unblock_action( self.to_glib_none().0, action_name.to_glib_none().0, ); } } /// The unique name of the `BindingPool`. pub fn get_property_name(&self) -> Option<GString> { unsafe { let mut value = Value::from_type(<GString as StaticType>::static_type()); gobject_sys::g_object_get_property( self.as_ptr() as *mut gobject_sys::GObject, b"name\0".as_ptr() as *const _, value.to_glib_none_mut().0, ); value .get() .expect("Return Value for property `name` getter") } } /// Finds the `BindingPool` with `name`. /// ## `name` /// the name of the binding pool to find /// /// # Returns /// /// a pointer to the `BindingPool`, or `None` pub fn find(name: &str) -> Option<BindingPool> { unsafe { from_glib_none(ffi::clutter_binding_pool_find(name.to_glib_none().0)) } } //pub fn get_for_class(klass: /*Unimplemented*/Option<Fundamental: Pointer>) -> Option<BindingPool> { // unsafe { TODO: call clutter_sys:clutter_binding_pool_get_for_class() } //} } impl fmt::Display for BindingPool { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "BindingPool") } }