[Libguestfs] [PATCH] p2v: use newer GTK APIs if possible
Richard W.M. Jones
rjones at redhat.com
Tue Nov 6 17:45:54 UTC 2018
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
More information about the Libguestfs
mailing list