Ruby Forum Ruby-Gnome 2 > binding a set_foo function

Posted by Guillaume Cottenceau (Guest)
on 08.04.2008 18:39
(Received via mailing list)
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 Cottenceau - http://zarb.org/~gc/
Posted by Kouhei Sutou (Guest)
on 09.04.2008 00:00
(Received via mailing list)
Hi,

In <dc3bf8580804080841l12125337r6b36ddbab27fd7ca@mail.gmail.com>
  "[ruby-gnome2-devel-en] binding a set_foo function" on Tue, 8 Apr 2008 
17:41:56 +0200,
  "Guillaume Cottenceau" <gcottenc@gmail.com> 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
Posted by Mathieu Blondel (Guest)
on 09.04.2008 03:27
(Received via mailing list)
2008/4/9, Kouhei Sutou <kou@cozmixng.org>:

>  +    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
Posted by Kouhei Sutou (Guest)
on 09.04.2008 12:50
(Received via mailing list)
Hi,

In <7e1472660804081826p28bcba7bq9548a0276649f467@mail.gmail.com>
  "Re: [ruby-gnome2-devel-en] binding a set_foo function" on Wed, 9 Apr 
2008 10:26:31 +0900,
  "Mathieu Blondel" <mblondel@rubyforge.org> wrote:

> 2008/4/9, Kouhei Sutou <kou@cozmixng.org>:
> 
> >  +    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