Blob Blame History Raw
From 1af3e80a6134579bffd802f6855a5f368f75d99d Mon Sep 17 00:00:00 2001
From: David King <amigadave@amigadave.com>
Date: Thu, 19 Jan 2017 12:01:21 +0000
Subject: [PATCH 1/7] Avoid gtk_label_set_xalign()

Depend against GTK+ versions older than 3.16.
---
 src/access.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/access.c b/src/access.c
index f67e06c..f469dba 100644
--- a/src/access.c
+++ b/src/access.c
@@ -329,7 +329,15 @@ handle_access_dialog (XdpImplAccess *object,
       body_label = gtk_label_new (arg_body);
       gtk_widget_set_halign (body_label, GTK_ALIGN_START);
       g_object_set (body_label, "margin-top", 10, NULL);
+#if GTK_CHECK_VERSION (3,16,0)
       gtk_label_set_xalign (GTK_LABEL (body_label), 0);
+#else
+G_GNUC_BEGIN_IGNORE_DEPRECATIONS
+      /* This is deprecated in 3.14, but gtk_label_set_xalign() is not
+       * available until 3.16. */
+      gtk_misc_set_alignment (GTK_MISC (body_label), 0.0, 0.5);
+G_GNUC_END_IGNORE_DEPRECATIONS
+#endif
       gtk_label_set_line_wrap (GTK_LABEL (body_label), TRUE);
       gtk_label_set_max_width_chars (GTK_LABEL (body_label), 50);
       gtk_widget_show (body_label);
-- 
2.9.3


From d7e23b9c3017467f0edfe7c9b127befe85aae2c6 Mon Sep 17 00:00:00 2001
From: David King <amigadave@amigadave.com>
Date: Thu, 19 Jan 2017 14:14:55 +0000
Subject: [PATCH 2/7] Avoid G_DECLARE_* macros

Using the new G_DECLARE_FINAL_TYPE and G_DECLARE_DERIVABLE_TYPE means
that GTK+ types must support g_autoptr(), which was only added in GTK+
3.16.
---
 src/accountdialog.h          |  6 +++++-
 src/appchooserdialog.h       |  6 +++++-
 src/appchooserrow.h          |  7 ++++++-
 src/externalwindow-wayland.c |  5 +++++
 src/externalwindow-wayland.h |  7 +++++--
 src/externalwindow-x11.c     |  5 +++++
 src/externalwindow-x11.h     |  7 +++++--
 src/externalwindow.h         | 14 ++++++++++++--
 src/screenshotdialog.h       |  6 +++++-
 9 files changed, 53 insertions(+), 10 deletions(-)

diff --git a/src/accountdialog.h b/src/accountdialog.h
index 1005e74..e209343 100644
--- a/src/accountdialog.h
+++ b/src/accountdialog.h
@@ -1,6 +1,10 @@
 #include <gtk/gtk.h>
 
-G_DECLARE_FINAL_TYPE (AccountDialog, account_dialog, ACCOUNT, DIALOG, GtkWindow)
+#define ACCOUNT_TYPE_DIALOG (account_dialog_get_type ())
+#define ACCOUNT_DIALOG(object) (G_TYPE_CHECK_INSTANCE_CAST (object, ACCOUNT_TYPE_DIALOG, AccountDialog))
+
+typedef struct _AccountDialog AccountDialog;
+typedef struct _AccountDialogClass AccountDialogClass;
 
 AccountDialog * account_dialog_new (const char *app_id,
                                     const char *user_name,
diff --git a/src/appchooserdialog.h b/src/appchooserdialog.h
index 2e1ba62..c9a6ea8 100644
--- a/src/appchooserdialog.h
+++ b/src/appchooserdialog.h
@@ -22,7 +22,11 @@
 
 #include <gtk/gtk.h>
 
-G_DECLARE_FINAL_TYPE (AppChooserDialog, app_chooser_dialog, APP, CHOOSER_DIALOG, GtkWindow)
+#define APP_TYPE_CHOOSER_DIALOG (app_chooser_dialog_get_type ())
+#define APP_CHOOSER_DIALOG(object) (G_TYPE_CHECK_INSTANCE_CAST (object, APP_TYPE_CHOOSER_DIALOG, AppChooserDialog))
+
+typedef struct _AppChooserDialog AppChooserDialog;
+typedef struct _AppChooserDialogClass AppChooserDialogClass;
 
 AppChooserDialog * app_chooser_dialog_new (const char **app_ids,
                                            const char *default_id,
diff --git a/src/appchooserrow.h b/src/appchooserrow.h
index 162f1e8..23ee2e4 100644
--- a/src/appchooserrow.h
+++ b/src/appchooserrow.h
@@ -22,8 +22,13 @@
 
 #include <gtk/gtk.h>
 
-G_DECLARE_FINAL_TYPE (AppChooserRow, app_chooser_row, APP, CHOOSER_ROW, GtkListBox)
+#define APP_TYPE_CHOOSER_ROW (app_chooser_row_get_type ())
+#define APP_CHOOSER_ROW(object) (G_TYPE_CHECK_INSTANCE_CAST (object, APP_TYPE_CHOOSER_ROW, AppChooserRow))
 
+typedef struct _AppChooserRow AppChooserRow;
+typedef struct _AppChooserRowClass AppChooserRowClass;
+
+GType app_chooser_row_get_type (void);
 AppChooserRow *app_chooser_row_new (GAppInfo *info);
 void app_chooser_row_set_selected (AppChooserRow *row,
                                    gboolean selected);
diff --git a/src/externalwindow-wayland.c b/src/externalwindow-wayland.c
index cb6510c..c3c7820 100644
--- a/src/externalwindow-wayland.c
+++ b/src/externalwindow-wayland.c
@@ -34,6 +34,11 @@ struct _ExternalWindowWayland
   char *handle_str;
 };
 
+struct _ExternalWindowWaylandClass
+{
+  ExternalWindowClass parent_class;
+};
+
 G_DEFINE_TYPE (ExternalWindowWayland, external_window_wayland,
                EXTERNAL_TYPE_WINDOW)
 
diff --git a/src/externalwindow-wayland.h b/src/externalwindow-wayland.h
index 5009244..ede29ef 100644
--- a/src/externalwindow-wayland.h
+++ b/src/externalwindow-wayland.h
@@ -25,7 +25,10 @@
 #include "externalwindow.h"
 
 #define EXTERNAL_TYPE_WINDOW_WAYLAND (external_window_wayland_get_type ())
-G_DECLARE_FINAL_TYPE (ExternalWindowWayland, external_window_wayland,
-		      EXTERNAL, WINDOW_WAYLAND, ExternalWindow)
+#define EXTERNAL_WINDOW_WAYLAND(object) (G_TYPE_CHECK_INSTANCE_CAST (object, EXTERNAL_TYPE_WINDOW_WAYLAND, ExternalWindowWayland))
 
+typedef struct _ExternalWindowWayland ExternalWindowWayland;
+typedef struct _ExternalWindowWaylandClass ExternalWindowWaylandClass;
+
+GType external_window_wayland_get_type (void);
 ExternalWindowWayland *external_window_wayland_new (const char *handle_str);
diff --git a/src/externalwindow-x11.c b/src/externalwindow-x11.c
index bc8e199..a61b124 100644
--- a/src/externalwindow-x11.c
+++ b/src/externalwindow-x11.c
@@ -37,6 +37,11 @@ struct _ExternalWindowX11
   GdkWindow *foreign_gdk_window;
 };
 
+struct _ExternalWindowX11Class
+{
+  ExternalWindowClass parent_class;
+};
+
 G_DEFINE_TYPE (ExternalWindowX11, external_window_x11,
                EXTERNAL_TYPE_WINDOW)
 
diff --git a/src/externalwindow-x11.h b/src/externalwindow-x11.h
index 9cb9c6d..d380a3d 100644
--- a/src/externalwindow-x11.h
+++ b/src/externalwindow-x11.h
@@ -26,7 +26,10 @@
 
 
 #define EXTERNAL_TYPE_WINDOW_X11 (external_window_x11_get_type ())
-G_DECLARE_FINAL_TYPE (ExternalWindowX11, external_window_x11,
-		      EXTERNAL, WINDOW_X11, ExternalWindow)
+#define EXTERNAL_WINDOW_X11(object) (G_TYPE_CHECK_INSTANCE_CAST (object, EXTERNAL_TYPE_WINDOW_X11, ExternalWindowX11))
 
+typedef struct _ExternalWindowX11 ExternalWindowX11;
+typedef struct _ExternalWindowX11Class ExternalWindowX11Class;
+
+GType external_window_get_type (void);
 ExternalWindowX11 *external_window_x11_new (const char *handle_str);
diff --git a/src/externalwindow.h b/src/externalwindow.h
index 0ad09ee..8282fc2 100644
--- a/src/externalwindow.h
+++ b/src/externalwindow.h
@@ -25,8 +25,17 @@
 
 
 #define EXTERNAL_TYPE_WINDOW (external_window_get_type ())
-G_DECLARE_DERIVABLE_TYPE (ExternalWindow, external_window,
-			  EXTERNAL, WINDOW, GObject)
+#define EXTERNAL_WINDOW(object) (G_TYPE_CHECK_INSTANCE_CAST (object, EXTERNAL_TYPE_WINDOW, ExternalWindow))
+#define EXTERNAL_WINDOW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST (klass, EXTERNAL_TYPE_WINDOW, ExternalWindowClass))
+#define EXTERNAL_WINDOW_GET_CLASS(klass) (G_TYPE_INSTANCE_GET_CLASS (klass, EXTERNAL_TYPE_WINDOW, ExternalWindowClass))
+
+typedef struct _ExternalWindow ExternalWindow;
+typedef struct _ExternalWindowClass ExternalWindowClass;
+
+struct _ExternalWindow
+{
+  GObject parent_instance;
+};
 
 struct _ExternalWindowClass
 {
@@ -36,6 +45,7 @@ struct _ExternalWindowClass
                          GdkWindow      *child_window);
 };
 
+GType external_window_get_type (void);
 ExternalWindow *create_external_window_from_handle (const char *handle_str);
 
 void external_window_set_parent_of (ExternalWindow *external_window,
diff --git a/src/screenshotdialog.h b/src/screenshotdialog.h
index c9d15cc..b7b19d0 100644
--- a/src/screenshotdialog.h
+++ b/src/screenshotdialog.h
@@ -1,6 +1,10 @@
 #include <gtk/gtk.h>
 
-G_DECLARE_FINAL_TYPE (ScreenshotDialog, screenshot_dialog, SCREENSHOT, DIALOG, GtkWindow)
+#define SCREENSHOT_TYPE_DIALOG (screenshot_dialog_get_type ())
+#define SCREENSHOT_DIALOG(object) (G_TYPE_CHECK_INSTANCE_CAST ((object, SCREENSHOT_TYPE_DIALOG, ScreenshotDialog)))
+
+typedef struct _ScreenshotDialog ScreenshotDialog;
+typedef struct _ScreenshotDialogClass ScreenshotDialogClass;
 
 ScreenshotDialog * screenshot_dialog_new (const char *app_id,
                                           const char *filename);
-- 
2.9.3


From e440d6927849195ba2443d4f460b1e1ffbda4d76 Mon Sep 17 00:00:00 2001
From: David King <amigadave@amigadave.com>
Date: Thu, 19 Jan 2017 15:04:11 +0000
Subject: [PATCH 3/7] Avoid gtk_css_provider_load_from_resource()

Use gtk_css_provider_load_from_path() instead.
---
 src/appchooserdialog.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/appchooserdialog.c b/src/appchooserdialog.c
index 11b3a48..149d3d0 100644
--- a/src/appchooserdialog.c
+++ b/src/appchooserdialog.c
@@ -241,7 +241,7 @@ app_chooser_dialog_new (const char **choices,
   if (provider == NULL)
     {
       provider = gtk_css_provider_new ();
-      gtk_css_provider_load_from_resource (provider, "/org/freedesktop/portal/desktop/gtk/appchooserdialog.css");
+      gtk_css_provider_load_from_path (provider, "resource:///org/freedesktop/portal/desktop/gtk/appchooserdialog.css", NULL);
       gtk_style_context_add_provider_for_screen (gdk_screen_get_default (),
                                                  GTK_STYLE_PROVIDER (provider),
                                                  GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
-- 
2.9.3


From e1cfee3c947aaa3b4f244484f3b953ec89398d62 Mon Sep 17 00:00:00 2001
From: David King <amigadave@amigadave.com>
Date: Thu, 19 Jan 2017 17:11:44 +0000
Subject: [PATCH 4/7] Avoid gtk_entry_grab_focus_without_selecting()

It was not added until GTK+ 3.16.
---
 src/appchooserdialog.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/appchooserdialog.c b/src/appchooserdialog.c
index 149d3d0..0550e40 100644
--- a/src/appchooserdialog.c
+++ b/src/appchooserdialog.c
@@ -181,7 +181,12 @@ search_toggled (GtkToggleButton *button,
       show_all (dialog);
       gtk_list_box_set_filter_func (GTK_LIST_BOX (dialog->list),
                                     filter_func, dialog, NULL);
+#if GTK_CHECK_VERSION (3, 16, 0)
       gtk_entry_grab_focus_without_selecting (GTK_ENTRY (dialog->search_entry));
+#else
+      gtk_widget_grab_focus (dialog->search_entry);
+      gtk_editable_set_position (GTK_EDITABLE (dialog->search_entry), -1);
+#endif
     }
   else
     {
-- 
2.9.3


From 1a5a2b0fa182022c558310e82621063ef33c8a3e Mon Sep 17 00:00:00 2001
From: David King <amigadave@amigadave.com>
Date: Thu, 19 Jan 2017 17:12:29 +0000
Subject: [PATCH 5/7] Avoid gtk_search_entry_handle_event()

Copy the necessary code from GTK+.
---
 src/appchooserdialog.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/src/appchooserdialog.c b/src/appchooserdialog.c
index 0550e40..9254c20 100644
--- a/src/appchooserdialog.c
+++ b/src/appchooserdialog.c
@@ -144,6 +144,57 @@ search_changed (GtkSearchEntry *entry,
   gtk_list_box_invalidate_filter (GTK_LIST_BOX (dialog->list));
 }
 
+/* gtk_search_entry_handle_event() was not added until GTK+ 3.16. */
+#if !GTK_CHECK_VERSION (3, 16, 0)
+static gboolean
+gtk_search_entry_is_keynav_event (GdkEvent *event)
+{
+  GdkModifierType state = 0;
+  guint keyval;
+
+  if (!gdk_event_get_keyval (event, &keyval))
+    return FALSE;
+
+  gdk_event_get_state (event, &state);
+
+  if (keyval == GDK_KEY_Tab       || keyval == GDK_KEY_KP_Tab ||
+      keyval == GDK_KEY_Up        || keyval == GDK_KEY_KP_Up ||
+      keyval == GDK_KEY_Down      || keyval == GDK_KEY_KP_Down ||
+      keyval == GDK_KEY_Left      || keyval == GDK_KEY_KP_Left ||
+      keyval == GDK_KEY_Right     || keyval == GDK_KEY_KP_Right ||
+      keyval == GDK_KEY_Home      || keyval == GDK_KEY_KP_Home ||
+      keyval == GDK_KEY_End       || keyval == GDK_KEY_KP_End ||
+      keyval == GDK_KEY_Page_Up   || keyval == GDK_KEY_KP_Page_Up ||
+      keyval == GDK_KEY_Page_Down || keyval == GDK_KEY_KP_Page_Down ||
+      ((state & (GDK_CONTROL_MASK | GDK_MOD1_MASK)) != 0))
+        return TRUE;
+
+  /* Other navigation events should get automatically
+   * ignored as they will not change the content of the entry
+   */
+  return FALSE;
+}
+
+static gboolean
+gtk_search_entry_handle_event (GtkSearchEntry *entry,
+                               GdkEvent       *event)
+{
+  gboolean handled;
+
+  if (!gtk_widget_get_realized (GTK_WIDGET (entry)))
+    gtk_widget_realize (GTK_WIDGET (entry));
+
+  if (gtk_search_entry_is_keynav_event (event) ||
+      event->key.keyval == GDK_KEY_space ||
+      event->key.keyval == GDK_KEY_Menu)
+    return GDK_EVENT_PROPAGATE;
+
+  handled = gtk_widget_event (GTK_WIDGET (entry), event);
+
+  return handled ? GDK_EVENT_STOP : GDK_EVENT_PROPAGATE;
+}
+#endif
+
 static gboolean
 app_chooser_dialog_key_press (GtkWidget *widget,
                               GdkEventKey *event)
-- 
2.9.3


From 436dff61282f7756e33d89564a694bc407d1158c Mon Sep 17 00:00:00 2001
From: David King <amigadave@amigadave.com>
Date: Thu, 19 Jan 2017 17:26:46 +0000
Subject: [PATCH 6/7] Avoid g_autoptr() with GtkPrint types

Support was not added until GTK+ 3.16.
---
 src/print.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/print.c b/src/print.c
index 51004e0..06b9df2 100644
--- a/src/print.c
+++ b/src/print.c
@@ -176,7 +176,7 @@ print_file (int fd,
             GtkPageSetup *page_setup,
             GError **error)
 {
-  g_autoptr(GtkPrintJob) job = NULL;
+  GtkPrintJob *job;
   g_autofree char *title = NULL;
 
   title = g_strdup_printf ("Document from %s", app_id);
@@ -184,9 +184,13 @@ print_file (int fd,
   job = gtk_print_job_new (title, printer, settings, page_setup);
 
   if (!gtk_print_job_set_source_fd (job, fd, error))
-    return FALSE;
+    {
+      g_object_unref (job);
+      return FALSE;
+    }
 
   gtk_print_job_send (job, NULL, NULL, NULL);
+  g_object_unref (job);
 
   return TRUE;
 }
@@ -215,7 +219,7 @@ handle_print_response (GtkDialog *dialog,
     case GTK_RESPONSE_OK:
       {
         GtkPrinter *printer;
-        g_autoptr(GtkPrintSettings) settings = NULL;
+        GtkPrintSettings *settings;
         GtkPageSetup *page_setup;
 
         printer = gtk_print_unix_dialog_get_selected_printer (GTK_PRINT_UNIX_DIALOG (handle->dialog));
@@ -231,6 +235,8 @@ handle_print_response (GtkDialog *dialog,
           handle->response = 2;
         else
           handle->response = 0;
+
+        g_object_unref (settings);
       }
       break;
     }
-- 
2.9.3


From dfc24b7418a1ab92b0a29ec485a1795775db3aca Mon Sep 17 00:00:00 2001
From: David King <amigadave@amigadave.com>
Date: Mon, 23 Jan 2017 11:39:02 +0000
Subject: [PATCH 7/7] Avoid gtk_print_job_set_source_fd()

On older versions of GTK+ than 3.22, use gtk_print_job_set_source_file()
with a temporary file instead.
---
 src/print.c | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/src/print.c b/src/print.c
index 06b9df2..57b1e45 100644
--- a/src/print.c
+++ b/src/print.c
@@ -29,6 +29,8 @@
 
 #include <gio/gio.h>
 #include <gio/gunixfdlist.h>
+#include <gio/gunixinputstream.h>
+#include <gio/gunixoutputstream.h>
 
 #include "xdg-desktop-portal-dbus.h"
 
@@ -178,16 +180,54 @@ print_file (int fd,
 {
   GtkPrintJob *job;
   g_autofree char *title = NULL;
+#if !GTK_CHECK_VERSION (3, 22, 0)
+  g_autofree char *filename = NULL;
+  g_autoptr(GUnixInputStream) istream = NULL;
+  g_autoptr(GUnixOutputStream) ostream = NULL;
+  int fd2;
+#endif
 
   title = g_strdup_printf ("Document from %s", app_id);
 
   job = gtk_print_job_new (title, printer, settings, page_setup);
 
+#if GTK_CHECK_VERSION (3, 22, 0)
   if (!gtk_print_job_set_source_fd (job, fd, error))
     {
       g_object_unref (job);
       return FALSE;
     }
+#else
+  istream = g_unix_input_stream_new (fd, FALSE);
+
+  if ((fd2 = g_file_open_tmp (PACKAGE_NAME "XXXXXX", &filename, error)) == -1)
+    {
+      g_object_unref (job);
+      return FALSE;
+    }
+
+  ostream = g_unix_output_stream_new (fd2, TRUE);
+
+  if (g_output_stream_splice (G_OUTPUT_STREAM (ostream),
+                              G_INPUT_STREAM (istream),
+                              G_OUTPUT_STREAM_SPLICE_NONE,
+                              NULL,
+                              error) == -1)
+    {
+      g_object_unref (job);
+      return FALSE;
+    }
+
+  if (!gtk_print_job_set_source_file (job, filename, error))
+    {
+      g_object_unref (job);
+      return FALSE;
+    }
+
+  /* The file will be removed when the GtkPrintJob closes it (once the job is
+   * complete). */
+  unlink (filename);
+#endif
 
   gtk_print_job_send (job, NULL, NULL, NULL);
   g_object_unref (job);
-- 
2.9.3