# Binding a set\_foo function

**URL:** <https://www.ruby-forum.com/t/binding-a-set-foo-function/134190>\
**Category:** Ruby-Gnome 2\
**Created:** [April 8, 2008, 6:39pm UTC](https://www.ruby-forum.com/t/binding-a-set-foo-function/134190 "2008-04-08T18:39:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![blueprint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/cc9497/32.png) [@blueprint](https://www.ruby-forum.com/u/blueprint)\
**Post date:** [April 8, 2008, 6:39pm UTC](https://www.ruby-forum.com/t/binding-a-set-foo-function/134190/1 "2008-04-08T18:39:08Z")

</div>

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);

–  
Guillaume C. - [http://zarb.org/~gc/](http://zarb.org/~gc/)

---

<div class="post-metadata">

**Author:** ![blueprint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/cc9497/32.png) [@blueprint](https://www.ruby-forum.com/u/blueprint)\
**Post date:** [April 9, 2008, 12:00am UTC](https://www.ruby-forum.com/t/binding-a-set-foo-function/134190/2 "2008-04-09T00:00:48Z")

</div>

Hi,

In [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
“[ruby-gnome2-devel-en] binding a set\_foo function” on Tue, 8 Apr 2008  
17:41:56 +0200,  
“Guillaume C.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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);

## Thanks,

kou

---

<div class="post-metadata">

**Author:** ![blueprint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/cc9497/32.png) [@blueprint](https://www.ruby-forum.com/u/blueprint)\
**Post date:** [April 9, 2008, 12:50pm UTC](https://www.ruby-forum.com/t/binding-a-set-foo-function/134190/3 "2008-04-09T12:50:12Z")

</div>

Hi,

In [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
“Re: [ruby-gnome2-devel-en] binding a set\_foo function” on Wed, 9 Apr  
2008 10:26:31 +0900,  
“Mathieu B.” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 2008/4/9, Kouhei S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > - 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

---

<div class="post-metadata">

**Author:** ![blueprint](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/cc9497/32.png) [@blueprint](https://www.ruby-forum.com/u/blueprint)\
**Post date:** [April 9, 2008, 3:27am UTC](https://www.ruby-forum.com/t/binding-a-set-foo-function/134190/4 "2008-04-09T03:27:19Z")

</div>

2008/4/9, Kouhei S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> - 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
