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

Gen more things #239

Merged
merged 3 commits into from
Sep 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Gir.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ generate = [
"Gdk.NotifyType",
"Gdk.OwnerChange",
"Gdk.PropertyState",
"Gdk.PropMode",
"Gdk.ScrollDirection",
"Gdk.SeatCapabilities",
"Gdk.SettingAction",
Expand All @@ -67,6 +68,7 @@ manual = [
"cairo.Surface",
"Gdk.Atom",
"Gdk.Event",
"Gdk.EventAny",
"Gdk.EventButton",
"Gdk.EventConfigure",
"Gdk.EventCrossing",
Expand All @@ -77,12 +79,17 @@ manual = [
"Gdk.EventKey",
"Gdk.EventMotion",
"Gdk.EventOwnerChange",
"Gdk.EventPadAxis",
"Gdk.EventPadButton",
"Gdk.EventPadGroupMode",
"Gdk.EventProperty",
"Gdk.EventProximity",
"Gdk.EventScroll",
"Gdk.EventSelection",
"Gdk.EventSetting",
"Gdk.EventTouch",
"Gdk.EventTouchpadPinch",
"Gdk.EventTouchpadSwipe",
"Gdk.EventVisibility",
"Gdk.EventWindowState",
"Gdk.Geometry",
Expand Down Expand Up @@ -114,6 +121,10 @@ status = "generate"
# GValue initialized inside the function instead of passed as argument
ignore = true
[[object.function]]
name = "property_change"
# data parameter needed to be more
ignore = true
[[object.function]]
name = "pango_layout_get_clip_region"
ignore = true
[[object.function]]
Expand Down
2 changes: 1 addition & 1 deletion gir
61 changes: 61 additions & 0 deletions src/auto/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1791,6 +1791,67 @@ impl SetValue for OwnerChange {
}
}

#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[derive(Clone, Copy)]
pub enum PropMode {
Replace,
Prepend,
Append,
#[doc(hidden)]
__Unknown(i32),
}

#[doc(hidden)]
impl ToGlib for PropMode {
type GlibType = ffi::GdkPropMode;

fn to_glib(&self) -> ffi::GdkPropMode {
match *self {
PropMode::Replace => ffi::GDK_PROP_MODE_REPLACE,
PropMode::Prepend => ffi::GDK_PROP_MODE_PREPEND,
PropMode::Append => ffi::GDK_PROP_MODE_APPEND,
PropMode::__Unknown(value) => value
}
}
}

#[doc(hidden)]
impl FromGlib<ffi::GdkPropMode> for PropMode {
fn from_glib(value: ffi::GdkPropMode) -> Self {
skip_assert_initialized!();
match value {
0 => PropMode::Replace,
1 => PropMode::Prepend,
2 => PropMode::Append,
value => PropMode::__Unknown(value),
}
}
}

impl StaticType for PropMode {
fn static_type() -> Type {
unsafe { from_glib(ffi::gdk_prop_mode_get_type()) }
}
}

impl<'a> FromValueOptional<'a> for PropMode {
unsafe fn from_value_optional(value: &Value) -> Option<Self> {
Some(FromValue::from_value(value))
}
}

impl<'a> FromValue<'a> for PropMode {
unsafe fn from_value(value: &Value) -> Self {
from_glib(gobject_ffi::g_value_get_enum(value.to_glib_none().0))
}
}

impl SetValue for PropMode {
unsafe fn set_value(value: &mut Value, this: &Self) {
gobject_ffi::g_value_set_enum(value.to_glib_none_mut().0, this.to_glib())
}
}

#[derive(Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
#[derive(Clone, Copy)]
pub enum PropertyState {
Expand Down
4 changes: 0 additions & 4 deletions src/auto/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,6 @@ pub fn pre_parse_libgtk_only() {
}
}

//pub fn property_change(window: &Window, property: &Atom, type_: &Atom, format: i32, mode: /*Ignored*/PropMode, data: u8, nelements: i32) {
// unsafe { TODO: call ffi::gdk_property_change() }
//}

pub fn property_delete(window: &Window, property: &Atom) {
skip_assert_initialized!();
unsafe {
Expand Down
1 change: 1 addition & 0 deletions src/auto/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ pub use self::enums::InputSource;
pub use self::enums::ModifierIntent;
pub use self::enums::NotifyType;
pub use self::enums::OwnerChange;
pub use self::enums::PropMode;
pub use self::enums::PropertyState;
pub use self::enums::ScrollDirection;
pub use self::enums::SettingAction;
Expand Down
2 changes: 1 addition & 1 deletion src/auto/versions.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Generated by gir (https://github.com/gtk-rs/gir @ 464833e)
Generated by gir (https://github.com/gtk-rs/gir @ d3116ca)
from gir-files (https://github.com/gtk-rs/gir-files @ b8f5ef1)
40 changes: 40 additions & 0 deletions src/change_data.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2013-2018, The Gtk-rs Project Developers.
// 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>

use libc;

#[derive(Clone, Copy, Debug, PartialEq)]
pub enum ChangeData<'a> {
UChars(&'a [u8]),
UShorts(&'a [u16]),
ULongs(&'a [libc::c_ulong]),
UChar(u8),
UShort(u16),
ULong(libc::c_ulong),
Copy link
Member

Choose a reason for hiding this comment

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

Inner types don't need have pub ?

Copy link
Member

Choose a reason for hiding this comment

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

And here no u32 cases

Copy link
Member

Choose a reason for hiding this comment

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

u32/guint is not mentioned in the documentation of the function

Copy link
Member

Choose a reason for hiding this comment

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

Going through uses of it, there seem to be more types possible than documented though:
https://sources.debian.org/src/gtk+2.0/2.24.31-2/gtk/gtkselection.c/?hl=2466#L2466
https://sources.debian.org/src/gtk+3.0/3.24.0-1/gdk/mir/gdkmirwindowimpl.c/?hl=1934#L1934
https://sources.debian.org/src/nautilus/3.26.3.1-1/src/nautilus-canvas-dnd.c/?hl=503#L503

This seems to allow arbitrary types, I'm not sure how this function is supposed to work safely.

Copy link
Member Author

Choose a reason for hiding this comment

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

This seems to allow arbitrary types, I'm not sure how this function is supposed to work safely.

By limiting the number of entries. If we need more, we can always add them afterwards.

Inner types don't need have pub ?

Woups... Thanks!

Copy link
Member

Choose a reason for hiding this comment

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

Ok then. Do we know of any code actually using this binding? How do they use it?

Copy link
Member Author

Choose a reason for hiding this comment

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

At least I don't. I'll ask around.

}

#[doc(hidden)]
impl<'a> ChangeData<'a> {
pub fn to_glib(&'a self) -> *const u8 {
match *self {
ChangeData::UChars(d) => d.as_ptr() as *const _,
ChangeData::UShorts(d) => d.as_ptr() as *const _,
ChangeData::ULongs(d) => d.as_ptr() as *const _,
ChangeData::UChar(d) => &d as *const _ as *const _,
ChangeData::UShort(d) => &d as *const _ as *const _,
ChangeData::ULong(d) => &d as *const _ as *const _,
}
}

pub fn len(&'a self) -> usize {
match *self {
ChangeData::UChars(d) => d.len(),
ChangeData::UShorts(d) => d.len(),
ChangeData::ULongs(d) => d.len(),
ChangeData::UChar(_) |
ChangeData::UShort(_) |
ChangeData::ULong(_) => 1,
}
}
}
9 changes: 9 additions & 0 deletions src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,12 @@ pub fn setting_get(name: &str) -> Option<glib::Value> {
}
}
}

pub fn property_change(window: &super::Window, property: &super::Atom, type_: &super::Atom,
format: i32, mode: super::PropMode, data: super::ChangeData) {
skip_assert_initialized!();
let nelements = data.len();
unsafe {
ffi::gdk_property_change(window.to_glib_none().0, property.to_glib_none().0, type_.to_glib_none().0, format, mode.to_glib(), data.to_glib(), nelements as i32);
}
}
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub mod enums;

mod atom;
mod cairo_interaction;
mod change_data;
mod device;
mod device_manager;
mod drag_context;
Expand Down Expand Up @@ -112,6 +113,7 @@ pub use atom::SELECTION_TYPE_INTEGER;
pub use atom::SELECTION_TYPE_PIXMAP;
pub use atom::SELECTION_TYPE_WINDOW;
pub use atom::SELECTION_TYPE_STRING;
pub use change_data::ChangeData;
pub use event::Event;
pub use event_button::EventButton;
pub use event_configure::EventConfigure;
Expand Down