From 8c08093768dae5fd31910e6722cde67414b605ad Mon Sep 17 00:00:00 2001 From: Lluis Sanchez Date: Mon, 26 Aug 2013 20:33:05 +0200 Subject: Sync with GtkWorkarounds in XWT --- .../Mono.TextEditor/Gui/GtkWorkarounds.cs | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'main/src') diff --git a/main/src/core/Mono.Texteditor/Mono.TextEditor/Gui/GtkWorkarounds.cs b/main/src/core/Mono.Texteditor/Mono.TextEditor/Gui/GtkWorkarounds.cs index bda3a23761..e171ce405c 100644 --- a/main/src/core/Mono.Texteditor/Mono.TextEditor/Gui/GtkWorkarounds.cs +++ b/main/src/core/Mono.Texteditor/Mono.TextEditor/Gui/GtkWorkarounds.cs @@ -1086,9 +1086,15 @@ namespace Mono.TextEditor [DllImport (PangoUtil.LIBGTK)] static extern double gtk_widget_get_scale_factor (IntPtr widget); + + [DllImport (PangoUtil.LIBGDK)] + static extern double gdk_screen_get_monitor_scale_factor (IntPtr widget, int monitor); [DllImport (PangoUtil.LIBGOBJECT)] static extern IntPtr g_object_get_data (IntPtr source, string name); + + [DllImport (PangoUtil.LIBGTK)] + static extern IntPtr gtk_icon_set_render_icon_scaled (IntPtr handle, IntPtr style, int direction, int state, int size, IntPtr widget, IntPtr intPtr, ref double scale); public static bool SetSourceScale (Gtk.IconSource source, double scale) { @@ -1155,6 +1161,41 @@ namespace Mono.TextEditor supportsHiResIcons = false; return 1; } + + public static double GetScaleFactor (this Gdk.Screen screen, int monitor) + { + if (!supportsHiResIcons) + return 1; + + try { + return gdk_screen_get_monitor_scale_factor (screen.Handle, monitor); + } catch (DllNotFoundException) { + } catch (EntryPointNotFoundException) { + } + supportsHiResIcons = false; + return 1; + } + + public static Gdk.Pixbuf RenderIcon (this Gtk.IconSet iconset, Gtk.Style style, Gtk.TextDirection direction, Gtk.StateType state, Gtk.IconSize size, Gtk.Widget widget, string detail, double scale) + { + if (scale == 1d) + return iconset.RenderIcon (style, direction, state, size, widget, detail); + + if (!supportsHiResIcons) + return null; + + try { + IntPtr intPtr = GLib.Marshaller.StringToPtrGStrdup (detail); + IntPtr o = gtk_icon_set_render_icon_scaled (iconset.Handle, (style != null) ? style.Handle : IntPtr.Zero, (int)direction, (int)state, (int)size, (widget != null) ? widget.Handle : IntPtr.Zero, intPtr, ref scale); + Gdk.Pixbuf result = (Gdk.Pixbuf) GLib.Object.GetObject (o); + GLib.Marshaller.Free (intPtr); + return result; + } catch (DllNotFoundException) { + } catch (EntryPointNotFoundException) { + } + supportsHiResIcons = false; + return null; + } } public struct KeyboardShortcut : IEquatable -- cgit v1.2.3