[gtk+/wip/otte/clipboard: 77/107] x11: Add gdk_x11_display_get_max_request_size()



commit 45c2e0824f16210b1f1325e0b52487a28bd90b66
Author: Benjamin Otte <otte redhat com>
Date:   Sat Nov 25 01:25:31 2017 +0100

    x11: Add gdk_x11_display_get_max_request_size()
    
    There's multiple places in the clipboard code where I need it, so make
    it a custom function.

 gdk/x11/gdkclipboard-x11.c |   10 ++--------
 gdk/x11/gdkdisplay-x11.c   |   14 ++++++++++++++
 gdk/x11/gdkdisplay-x11.h   |    1 +
 3 files changed, 17 insertions(+), 8 deletions(-)
---
diff --git a/gdk/x11/gdkclipboard-x11.c b/gdk/x11/gdkclipboard-x11.c
index ea710d5..3b7d608 100644
--- a/gdk/x11/gdkclipboard-x11.c
+++ b/gdk/x11/gdkclipboard-x11.c
@@ -54,12 +54,6 @@ struct _GdkX11ClipboardClass
 
 G_DEFINE_TYPE (GdkX11Clipboard, gdk_x11_clipboard, GDK_TYPE_CLIPBOARD)
 
-#define SELECTION_MAX_SIZE(display)                                     \
-  MIN(262144,                                                           \
-      XExtendedMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) == 0     \
-       ? XMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) - 100         \
-       : XExtendedMaxRequestSize (GDK_DISPLAY_XDISPLAY (display)) - 100)
-
 static GInputStream * 
 text_list_convert (GdkX11Clipboard *cb,
                    GInputStream    *stream,
@@ -219,7 +213,7 @@ gdk_x11_clipboard_request_targets_finish (GObject      *source_object,
   gdk_content_formats_unref (formats);
 
   g_input_stream_read_bytes_async (stream,
-                                   SELECTION_MAX_SIZE (display),
+                                   gdk_x11_display_get_max_request_size (display),
                                    G_PRIORITY_DEFAULT,
                                    NULL,
                                    gdk_x11_clipboard_request_targets_finish,
@@ -255,7 +249,7 @@ gdk_x11_clipboard_request_targets_got_stream (GObject      *source,
   display = gdk_clipboard_get_display (GDK_CLIPBOARD (cb));
 
   g_input_stream_read_bytes_async (stream,
-                                   SELECTION_MAX_SIZE (display),
+                                   gdk_x11_display_get_max_request_size (display),
                                    G_PRIORITY_DEFAULT,
                                    NULL,
                                    gdk_x11_clipboard_request_targets_finish,
diff --git a/gdk/x11/gdkdisplay-x11.c b/gdk/x11/gdkdisplay-x11.c
index 1aecc75..30f1680 100644
--- a/gdk/x11/gdkdisplay-x11.c
+++ b/gdk/x11/gdkdisplay-x11.c
@@ -3041,6 +3041,20 @@ gdk_x11_set_sm_client_id (const gchar *sm_client_id)
 
   g_slist_free (displays);
 }
+ 
+gsize
+gdk_x11_display_get_max_request_size (GdkDisplay *display)
+{
+  Display *xdisplay = GDK_DISPLAY_XDISPLAY (display);
+  gsize size;
+
+  size = XExtendedMaxRequestSize (xdisplay);
+  if (size <= 0)
+    size = XMaxRequestSize (xdisplay);
+  
+  size = MIN (262144, size - 100);
+  return size;
+}
 
 GdkX11Screen *
 gdk_x11_display_get_screen (GdkDisplay *display)
diff --git a/gdk/x11/gdkdisplay-x11.h b/gdk/x11/gdkdisplay-x11.h
index 11a32fb..dc1100e 100644
--- a/gdk/x11/gdkdisplay-x11.h
+++ b/gdk/x11/gdkdisplay-x11.h
@@ -172,6 +172,7 @@ GdkX11Screen *_gdk_x11_display_screen_for_xrootwin (GdkDisplay  *display,
                                                     Window       xrootwin);
 void       _gdk_x11_display_error_event         (GdkDisplay  *display,
                                                  XErrorEvent *error);
+gsize      gdk_x11_display_get_max_request_size (GdkDisplay *display);
 
 GdkFilterReturn _gdk_wm_protocols_filter        (GdkXEvent   *xev,
                                                  GdkEvent    *event,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]