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

Generate GtkStyleContext get property functions #876

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 0 additions & 3 deletions Gir.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1765,9 +1765,6 @@ status = "ignore"
[[object]]
name = "Gtk.StyleContext"
status = "generate"
[[object.function]]
pattern = "get_(style_)?property"
ignore = true
[[object.function]]
name = "get_font"
ignore = true #returning Pango.FontDescription from *const
Expand Down
28 changes: 28 additions & 0 deletions src/auto/style_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// DO NOT EDIT

use gdk;
use glib;
use glib::object::Cast;
use glib::object::IsA;
use glib::signal::connect_raw;
Expand Down Expand Up @@ -170,6 +171,8 @@ pub trait StyleContextExt: 'static {

fn get_path(&self) -> Option<WidgetPath>;

fn get_property(&self, property: &str, state: StateFlags) -> glib::Value;
Copy link
Member

Choose a reason for hiding this comment

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

And also this should be Option

Copy link
Member

Choose a reason for hiding this comment

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

This can probably be configured in the toml by marking the return type as nullable


fn get_scale(&self) -> i32;

fn get_screen(&self) -> Option<gdk::Screen>;
Expand All @@ -180,6 +183,8 @@ pub trait StyleContextExt: 'static {

//fn get_style(&self, : /*Unknown conversion*//*Unimplemented*/Fundamental: VarArgs);

fn get_style_property(&self, property_name: &str, value: &mut glib::Value);
Copy link
Member

Choose a reason for hiding this comment

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

Ah that's why it was ignored probably... this should return an Option<glib::Value>

Copy link
Member

Choose a reason for hiding this comment

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

Not sure why gir gets the other function right and this one not though...

Copy link
Member

Choose a reason for hiding this comment

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

@EPashkin any guess? :)

Copy link
Member

Choose a reason for hiding this comment

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

IMHO because parameter not marked as out

          <parameter name="value" transfer-ownership="none">
            <doc xml:space="preserve" filename="gtk/gtkstylecontext.c" line="1727">Return location for the property value</doc>
            <type name="GObject.Value" c:type="GValue*"/>
          </parameter>

Copy link
Member

Choose a reason for hiding this comment

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

That could be fixed with some addition to gir-files/fix.sh :)


//fn get_style_valist(&self, args: /*Unknown conversion*//*Unimplemented*/Unsupported);

//fn get_valist(&self, state: StateFlags, args: /*Unknown conversion*//*Unimplemented*/Unsupported);
Expand Down Expand Up @@ -365,6 +370,19 @@ impl<O: IsA<StyleContext>> StyleContextExt for O {
}
}

fn get_property(&self, property: &str, state: StateFlags) -> glib::Value {
unsafe {
let mut value = glib::Value::uninitialized();
gtk_sys::gtk_style_context_get_property(
self.as_ref().to_glib_none().0,
property.to_glib_none().0,
state.to_glib(),
value.to_glib_none_mut().0,
);
value
}
}

fn get_scale(&self) -> i32 {
unsafe { gtk_sys::gtk_style_context_get_scale(self.as_ref().to_glib_none().0) }
}
Expand Down Expand Up @@ -398,6 +416,16 @@ impl<O: IsA<StyleContext>> StyleContextExt for O {
// unsafe { TODO: call gtk_sys:gtk_style_context_get_style() }
//}

fn get_style_property(&self, property_name: &str, value: &mut glib::Value) {
unsafe {
gtk_sys::gtk_style_context_get_style_property(
self.as_ref().to_glib_none().0,
property_name.to_glib_none().0,
value.to_glib_none_mut().0,
Copy link
Member

Choose a reason for hiding this comment

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

May be this function better be manual as
fn get_style_property(&self, property_name: &str) -> glib::Value

Copy link
Member

Choose a reason for hiding this comment

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

not sure that it can return Option, same as gtk_style_context_get_property at minimum by docs

Copy link
Member

Choose a reason for hiding this comment

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

What would it return if the property name is invalid though?

Copy link
Member

Choose a reason for hiding this comment

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

Docs don't say that in both cases :(

Copy link
Member

Choose a reason for hiding this comment

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

Code says g_critical(), so we would cause memory unsafety here. We need to check the existence of the property beforehand somehow... like in Object::get_property()

Copy link
Member

Choose a reason for hiding this comment

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

We could have manual code that initializes the GValue with mem::zeroed() and afterwards checks if the type of it is still 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looking into it, this function is deprecated (though not documented as such). Maybe we could ignore this one, and fix get_property?

Copy link
Member

Choose a reason for hiding this comment

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

Sure, works for me. Since when is the other function deprecated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

get_property isn't deprecated, and I'm not sure when this one was deprecated. Someone mentioned it in IRC as deprecated, and sure enough it isn't in the GTK4 docs

Copy link
Member

Choose a reason for hiding this comment

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

Maybe they meant that it's deprecated as in "does not exist in GTK4 anymore".

I think for the "deprecated" one the way forward is to panic if it fails (the g_critical() from C is basically a panic), or otherwise make it return a Result.

The other one, if we can check beforehand then let's do that or otherwise like above.

);
}
}

//fn get_style_valist(&self, args: /*Unknown conversion*//*Unimplemented*/Unsupported) {
// unsafe { TODO: call gtk_sys:gtk_style_context_get_style_valist() }
//}
Expand Down