Binding a set_foo function

Trying to bind gdk_window_set_composited, which is not defined as a
property - should it be done the following way, e.g. with explicit
duplication of code for the sake of supporting both .foo= and
set_foo()?

— gtk/src/rbgdkwindow.c (revision 3005)
+++ gtk/src/rbgdkwindow.c (working copy)
@@ -946,7 +946,23 @@
return self;
}

+#if GTK_CHECK_VERSION(2, 12, 0)
static VALUE
+gdkwin_composited_equal(VALUE self, VALUE composited)
+{

  • gdk_window_set_composited(_SELF(self), RVAL2CBOOL(composited));
  • return composited;
    +}

+static VALUE
+gdkwin_set_composited(VALUE self, VALUE composited)
+{

  • gdk_window_set_composited(_SELF(self), RVAL2CBOOL(composited));
  • return self;
    +}
    +#endif

+static VALUE
gdkwin_s_get_toplevels(self)
VALUE self;
{
@@ -1183,6 +1199,10 @@
rb_define_method(gdkWindow, “set_decorations”,
gdkwin_set_decorations, 1);
rb_define_method(gdkWindow, “decorations”, gdkwin_get_decorations,
0);
rb_define_method(gdkWindow, “set_functions”, gdkwin_set_functions,
1);
+#if GTK_CHECK_VERSION(2, 12, 0)

  • rb_define_method(gdkWindow, “composited=”, gdkwin_composited_equal,
    1);

  • rb_define_method(gdkWindow, “set_composited”,
    gdkwin_set_composited, 1);
    +#endif
    rb_define_singleton_method(gdkWindow, “toplevels”,
    gdkwin_s_get_toplevels, 0);

    rb_define_singleton_method(gdkWindow, “foreign_new”,
    gdkwin_foreign_new, -1);


Guillaume C. - http://zarb.org/~gc/

Hi,

In [email protected]
“[ruby-gnome2-devel-en] binding a set_foo function” on Tue, 8 Apr 2008
17:41:56 +0200,
“Guillaume C.” [email protected] wrote:

Trying to bind gdk_window_set_composited, which is not defined as a
property - should it be done the following way, e.g. with explicit
duplication of code for the sake of supporting both .foo= and
set_foo()?

You doesn’t need to define .foo=. .foo= will be defined from
set_foo() by G_DEF_SETTERS().

Index: test/test_gdk_window.rb

— test/test_gdk_window.rb (revision 0)
+++ test/test_gdk_window.rb (revision 0)
@@ -0,0 +1,16 @@
+class TestGdkWindow < Test::Unit::TestCase

  • def setup
  • @window = Gtk::Invisible.new.window
  • end
  • def test_set_composited
  • set_composited = Proc.new do
  •  @window.composited = false
    
  • end
  • if Gtk.check_version?(2, 12, 0)
  •  assert_nothing_raised(&set_composited)
    
  • else
  •  assert_raise(NameError, &set_composited)
    
  • end
  • end
    +end
    Index: src/rbgdkwindow.c
    ===================================================================
    — src/rbgdkwindow.c (revision 3015)
    +++ src/rbgdkwindow.c (working copy)
    @@ -946,7 +946,16 @@
    return self;
    }

+#if GTK_CHECK_VERSION(2, 12, 0)
static VALUE
+gdkwin_set_composited(VALUE self, VALUE composited)
+{

  • gdk_window_set_composited(_SELF(self), RVAL2CBOOL(composited));
  • return self;
    +}
    +#endif

+static VALUE
gdkwin_s_get_toplevels(self)
VALUE self;
{
@@ -1183,6 +1192,9 @@
rb_define_method(gdkWindow, “set_decorations”,
gdkwin_set_decorations, 1);
rb_define_method(gdkWindow, “decorations”, gdkwin_get_decorations,
0);
rb_define_method(gdkWindow, “set_functions”, gdkwin_set_functions,
1);
+#if GTK_CHECK_VERSION(2, 12, 0)

  • rb_define_method(gdkWindow, “set_composited”,
    gdkwin_set_composited, 1);
    +#endif
    rb_define_singleton_method(gdkWindow, “toplevels”,
    gdkwin_s_get_toplevels, 0);

    rb_define_singleton_method(gdkWindow, “foreign_new”,
    gdkwin_foreign_new, -1);

Thanks,

kou

Hi,

In [email protected]
“Re: [ruby-gnome2-devel-en] binding a set_foo function” on Wed, 9 Apr
2008 10:26:31 +0900,
“Mathieu B.” [email protected] wrote:

2008/4/9, Kouhei S. [email protected]:

  • if Gtk.check_version?(2, 12, 0)
  •  assert_nothing_raised(&set_composited)
    

Testing that nothing was raised is not enough, is it?

set_composited.call
assert_equal(@window.composited, false)

Unfortunately, Gdk::Window#composited doesn’t exist.

Thanks,

kou

2008/4/9, Kouhei S. [email protected]:

  • if Gtk.check_version?(2, 12, 0)
  •  assert_nothing_raised(&set_composited)
    

Testing that nothing was raised is not enough, is it?

set_composited.call
assert_equal(@window.composited, false)

Mathieu