Pino Toscano
2018-Nov-06 16:33 UTC
[Libguestfs] [PATCH] p2v: use newer GTK APIs if possible
Make use of APIs available in early GTK+ 3 versions, adding compatibility functions/macros for older GTK+ versions. There is no behaviour change, and it helps in porting to even newer GTK+ versions. --- p2v/gui-gtk3-compat.h | 16 ++++++++++++++++ p2v/gui.c | 13 +++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/p2v/gui-gtk3-compat.h b/p2v/gui-gtk3-compat.h index 8f32eadbf..04923535e 100644 --- a/p2v/gui-gtk3-compat.h +++ b/p2v/gui-gtk3-compat.h @@ -17,6 +17,18 @@ */ /* Backwards compatibility for some deprecated functions in Gtk 3. */ +#if !GTK_CHECK_VERSION(3,2,0) /* gtk < 3.2 */ +static gboolean +gdk_event_get_button (const GdkEvent *event, guint *button) +{ + if (event->type != GDK_BUTTON_PRESS) + return FALSE; + + *button = ((const GdkEventButton *) event)->button; + return TRUE; +} +#endif + #if GTK_CHECK_VERSION(3,2,0) /* gtk >= 3.2 */ #define hbox_new(box, homogeneous, spacing) \ do { \ @@ -79,6 +91,10 @@ gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (container), child) #endif +#if !GTK_CHECK_VERSION(3,10,0) /* gtk < 3.10 */ +#define gdk_event_get_event_type(event) ((event)->type) +#endif + #if GTK_CHECK_VERSION(3,10,0) /* gtk >= 3.10 */ #undef GTK_STOCK_DIALOG_WARNING #define GTK_STOCK_DIALOG_WARNING "dialog-warning" diff --git a/p2v/gui.c b/p2v/gui.c index a23d0ea53..1fd980044 100644 --- a/p2v/gui.c +++ b/p2v/gui.c @@ -1329,15 +1329,20 @@ maybe_identify_click (GtkWidget *interfaces_list, GdkEventButton *event, gpointer data) { gboolean ret = FALSE; /* Did we handle this event? */ + guint button; /* Single left click only. */ - if (event->type == GDK_BUTTON_PRESS && event->button == 1) { + if (gdk_event_get_event_type ((const GdkEvent *) event) == GDK_BUTTON_PRESS && + gdk_event_get_button ((const GdkEvent *) event, &button) && + button == 1) { GtkTreePath *path; GtkTreeViewColumn *column; + gdouble event_x, event_y; - if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (interfaces_list), - event->x, event->y, - &path, &column, NULL, NULL)) { + if (gdk_event_get_coords ((const GdkEvent *) event, &event_x, &event_y) + && gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (interfaces_list), + event_x, event_y, + &path, &column, NULL, NULL)) { GList *cols; gint column_index; -- 2.17.2
Richard W.M. Jones
2018-Nov-06 17:45 UTC
Re: [Libguestfs] [PATCH] p2v: use newer GTK APIs if possible
On Tue, Nov 06, 2018 at 05:33:41PM +0100, Pino Toscano wrote:> Make use of APIs available in early GTK+ 3 versions, adding > compatibility functions/macros for older GTK+ versions. > > There is no behaviour change, and it helps in porting to even newer GTK+ > versions. > --- > p2v/gui-gtk3-compat.h | 16 ++++++++++++++++ > p2v/gui.c | 13 +++++++++---- > 2 files changed, 25 insertions(+), 4 deletions(-) > > diff --git a/p2v/gui-gtk3-compat.h b/p2v/gui-gtk3-compat.h > index 8f32eadbf..04923535e 100644 > --- a/p2v/gui-gtk3-compat.h > +++ b/p2v/gui-gtk3-compat.h > @@ -17,6 +17,18 @@ > */ > > /* Backwards compatibility for some deprecated functions in Gtk 3. */ > +#if !GTK_CHECK_VERSION(3,2,0) /* gtk < 3.2 */ > +static gboolean > +gdk_event_get_button (const GdkEvent *event, guint *button) > +{ > + if (event->type != GDK_BUTTON_PRESS) > + return FALSE; > + > + *button = ((const GdkEventButton *) event)->button; > + return TRUE; > +} > +#endif > + > #if GTK_CHECK_VERSION(3,2,0) /* gtk >= 3.2 */ > #define hbox_new(box, homogeneous, spacing) \ > do { \ > @@ -79,6 +91,10 @@ > gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (container), child) > #endif > > +#if !GTK_CHECK_VERSION(3,10,0) /* gtk < 3.10 */ > +#define gdk_event_get_event_type(event) ((event)->type) > +#endif > + > #if GTK_CHECK_VERSION(3,10,0) /* gtk >= 3.10 */ > #undef GTK_STOCK_DIALOG_WARNING > #define GTK_STOCK_DIALOG_WARNING "dialog-warning" > diff --git a/p2v/gui.c b/p2v/gui.c > index a23d0ea53..1fd980044 100644 > --- a/p2v/gui.c > +++ b/p2v/gui.c > @@ -1329,15 +1329,20 @@ maybe_identify_click (GtkWidget *interfaces_list, GdkEventButton *event, > gpointer data) > { > gboolean ret = FALSE; /* Did we handle this event? */ > + guint button; > > /* Single left click only. */ > - if (event->type == GDK_BUTTON_PRESS && event->button == 1) { > + if (gdk_event_get_event_type ((const GdkEvent *) event) == GDK_BUTTON_PRESS && > + gdk_event_get_button ((const GdkEvent *) event, &button) && > + button == 1) { > GtkTreePath *path; > GtkTreeViewColumn *column; > + gdouble event_x, event_y; > > - if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (interfaces_list), > - event->x, event->y, > - &path, &column, NULL, NULL)) { > + if (gdk_event_get_coords ((const GdkEvent *) event, &event_x, &event_y) > + && gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (interfaces_list), > + event_x, event_y, > + &path, &column, NULL, NULL)) { > GList *cols; > gint column_index; >ACK Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-p2v converts physical machines to virtual machines. Boot with a live CD or over the network (PXE) and turn machines into KVM guests. http://libguestfs.org/virt-v2v
Possibly Parallel Threads
- [PATCH v2 3/3] p2v: Allow virt-p2v to be built with Gtk 2 or 3.
- [PATCH v2] p2v: User can click on an interface name to identify the
- [PATCH 2/2] p2v: use standard license type in about dialog
- [PATCH v3] p2v: Allow virt-p2v to be built with Gtk 2 or 3.
- [PATCH] p2v: User can click on an interface name to identify the physical interface.