On 12.04.2017 20:51, Zakariyya Mughal wrote:
> I noticed that the methods
> 
>     $widget->set_events( ... )
>     $widget->get_events( ... )
>     $widget->add_events( ... )
> 
> did not seem to be taking a `Glib::Flags` of type `Gtk3::Gdk::EventMask`
> as would be expected by reading the documentation. Looking at the
> `gtk+-3` source code, I see that the function signatures are using
> `gint` instead of `GdkEventMask`. It looks like the type annotation
> needs to be updated.

Yes, that's the core of the problem, and the bug reports are there to
make the gtk+ devs know.

Until the issue is fixed in gtk+, we could use overrides in Gtk3 to hide
the problem.  With the helper functions I just added to G:O:I*, this can
be done with the attached patch.  The problem is that this would change
the semantics of Gtk3::Widget::get_events: it would now return a
Glib::Flags object instead of a raw integer.  Since Glib::Flags
currently does not support raw integers, comparisons like
$widget->get_events == 0 would now fail.  (The corresponding tests in
the patch fail.)

So, should we worry about this?  Or just go ahead anyway and document
the change?

*
https://git.gnome.org/browse/perl-Glib-Object-Introspection/commit/?id=15c0b5122fbcf588625b4f3c2c9135e78b7f321a
>From 672e14a932a337f33bd7e3e03ad95ac416315080 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Torsten=20Sch=C3=B6nfeld?= <kaffeeti...@gmx.de>
Date: Mon, 1 May 2017 15:11:37 +0200
Subject: [PATCH] Add overrides for Gtk3::Widget::add_events, set_events,
 get_events

FIXME: Backwards compatibility for get_events.
---
 lib/Gtk3.pm   | 28 ++++++++++++++++++++++++++++
 t/overrides.t | 24 +++++++++++++++++++++++-
 2 files changed, 51 insertions(+), 1 deletion(-)

diff --git a/lib/Gtk3.pm b/lib/Gtk3.pm
index 7471c05..fef0a0a 100644
--- a/lib/Gtk3.pm
+++ b/lib/Gtk3.pm
@@ -1892,6 +1892,34 @@ sub Gtk3::VBox::new {
     $_GTK_BASENAME, 'VBox', 'new', $class, $homogeneous, $spacing);
 }
 
+sub Gtk3::Widget::add_events {
+  my ($widget, $events) = @_;
+  eval {
+    $events = Glib::Object::Introspection->convert_sv_to_flags (
+      'Gtk3::Gdk::EventMask', $events);
+  };
+  return Glib::Object::Introspection->invoke (
+    $_GTK_BASENAME, 'Widget', 'add_events', $widget, $events);
+}
+
+sub Gtk3::Widget::set_events {
+  my ($widget, $events) = @_;
+  eval {
+    $events = Glib::Object::Introspection->convert_sv_to_flags (
+      'Gtk3::Gdk::EventMask', $events);
+  };
+  return Glib::Object::Introspection->invoke (
+    $_GTK_BASENAME, 'Widget', 'set_events', $widget, $events);
+}
+
+sub Gtk3::Widget::get_events {
+  my ($widget) = @_;
+  my $events = Glib::Object::Introspection->invoke (
+    $_GTK_BASENAME, 'Widget', 'get_events', $widget);
+  return Glib::Object::Introspection->convert_flags_to_sv (
+    'Gtk3::Gdk::EventMask', $events);
+}
+
 sub Gtk3::Widget::render_icon {
   my ($widget, $stock_id, $size, $detail) = @_;
   Glib::Object::Introspection->invoke (
diff --git a/t/overrides.t b/t/overrides.t
index 0d136c2..7339d4c 100644
--- a/t/overrides.t
+++ b/t/overrides.t
@@ -7,7 +7,7 @@ use warnings;
 use utf8;
 use Encode;
 
-plan tests => 224;
+plan tests => 229;
 
 note('Gtk3::CHECK_VERSION and check_version');
 {
@@ -600,6 +600,28 @@ SKIP: {
   isa_ok (Gtk3::Label->find_style_property('interior-focus'), 'Glib::ParamSpec');
 }
 
+{
+  my $widget = Gtk3::Label->new ("Test");
+
+  $widget->set_events ([qw/enter-notify-mask leave-notify-mask/]);
+  ok ($widget->get_events >= [qw/enter-notify-mask leave-notify-mask/],
+      '$widget->set_events|get_events');
+
+  $widget->add_events ([qw/button-press-mask/]);
+  ok ($widget->get_events >= [qw/button-press-mask enter-notify-mask leave-notify-mask/],
+      '$widget->add_events|get_events');
+
+  $widget->set_events (0);
+  ok ($widget->get_events == 0, '$widget->set_events|get_events with numeric 0');
+
+  $widget->add_events (24);
+  ok ($widget->get_events == 24, '$widget->add_events|get_events with numeric 24');
+  ok ($widget->get_events == [qw/pointer-motion-hint-mask button-motion-mask/],
+      '$widget->add_events|get_events with numeric 24');
+}
+
+exit;
+
 SKIP: {
   skip 'atom stuff; missing annotations', 2
     unless Gtk3::CHECK_VERSION(3, 2, 0);
-- 
2.11.0

_______________________________________________
gtk-perl-list mailing list
gtk-perl-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-perl-list

Reply via email to