diff options
author | Paul D'Pong | 2020-10-21 14:30:55 +0000 |
---|---|---|
committer | Alexander Kurtakov | 2020-10-31 06:48:32 +0000 |
commit | b5d91f0b82dd0dc9973ae6f3cad056f2f88d84ce (patch) | |
tree | 0f151c42014f4663f75a6472a1fcb05258ed587c | |
parent | 2be98b4d55220d48e05332a65d2fc7ad7624723f (diff) | |
download | eclipse.platform.swt-b5d91f0b82dd0dc9973ae6f3cad056f2f88d84ce.tar.gz eclipse.platform.swt-b5d91f0b82dd0dc9973ae6f3cad056f2f88d84ce.tar.xz eclipse.platform.swt-b5d91f0b82dd0dc9973ae6f3cad056f2f88d84ce.zip |
Bug 568073 - [GTK4] Port Cursor snippets
- Allows for Snippet 92, 119 to run
- Assumes that GTK4 supports colored cursor by default
- Adapted gdk_cursor_new_from_pixbuf to gdk_cursor_new_from_texture
Change-Id: I06ce6d60cf50f47ad8673236429358ac6c16938a
Signed-off-by: Paul D'Pong <sdamrong@redhat.com>
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GDK.java | 21 | ||||
-rw-r--r-- | bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Cursor.java | 22 |
2 files changed, 29 insertions, 14 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GDK.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GDK.java index 8789304c44..1cf72e6088 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GDK.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/GDK.java @@ -384,34 +384,37 @@ public class GDK extends OS { */ /* [GTK3 only, if-def'd in os.h] */ public static final native void gdk_cairo_set_source_window(long cairo, long window, int x, int y); + + + /* GdkCursor [GTK3 only] */ /** * @param display cast=(GdkDisplay *) * @param cursor_name cast=(const gchar *) */ - /* [GTK3 only, if-def'd in os.h] */ public static final native long gdk_cursor_new_from_name(long display, String cursor_name); /** - * @param cursor_name cast=(const gchar *) - * @param fallback cast=(GdkCursor *) - */ - /* [GTK4 only, if-def'd in os.h] */ - public static final native long gdk_cursor_new_from_name(String cursor_name, long fallback); - /** * @param display cast=(GdkDisplay *) * @param pixbuf cast=(GdkPixbuf *) * @param x cast=(gint) * @param y cast=(gint) */ - /* [GTK3 only, if-def'd in os.h] */ public static final native long gdk_cursor_new_from_pixbuf(long display, long pixbuf, int x, int y); + + /* GdkCursor [GTK4 only] */ + /** + * @param cursor_name cast=(const gchar *) + * @param fallback cast=(GdkCursor *) + */ + public static final native long gdk_cursor_new_from_name(String cursor_name, long fallback); /** * @param texture cast=(GdkTexture *) * @param x cast=(gint) * @param y cast=(gint) * @param fallback cast=(GdkCursor *) */ - /* [GTK4 only, if-def'd in os.h] */ public static final native long gdk_cursor_new_from_texture(long texture, int x, int y, long fallback); + + /** * @param device cast=(GdkDevice *) * @param screen cast=(GdkScreen *) diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Cursor.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Cursor.java index 5e3e1be0b3..7aae3a6b53 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Cursor.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Cursor.java @@ -277,8 +277,10 @@ public Cursor(Device device, ImageData source, int hotspotX, int hotspotY) { hotspotY >= source.height || hotspotY < 0) { SWT.error(SWT.ERROR_INVALID_ARGUMENT); } - long display = 0; - if (GDK.gdk_display_supports_cursor_color(display = GDK.gdk_display_get_default ())) { + + long display = GDK.gdk_display_get_default(); + boolean supportsColorCursor = GTK.GTK4 || GDK.gdk_display_supports_cursor_color(display); + if (supportsColorCursor) { int width = source.width; int height = source.height; PaletteData palette = source.palette; @@ -343,7 +345,14 @@ public Cursor(Device device, ImageData source, int hotspotX, int hotspotY) { } } C.memmove(data, buffer, stride * height); - handle = GDK.gdk_cursor_new_from_pixbuf(display, pixbuf, hotspotX, hotspotY); + + if (GTK.GTK4) { + long texture = GDK.gdk_texture_new_for_pixbuf(pixbuf); + handle = GDK.gdk_cursor_new_from_texture(texture, hotspotX, hotspotY, 0); + OS.g_object_unref(texture); + } else { + handle = GDK.gdk_cursor_new_from_pixbuf(display, pixbuf, hotspotX, hotspotY); + } OS.g_object_unref(pixbuf); } else { @@ -477,14 +486,17 @@ long createCursor(byte[] sourceData, byte[] maskData, int width, int height, int int stride = GDK.gdk_pixbuf_get_rowstride(pixbuf); long pixels = GDK.gdk_pixbuf_get_pixels(pixbuf); C.memmove(pixels, data, stride * height); + long cursor; if (GTK.GTK4) { - long texture = GDK.gdk_texture_new_for_pixbuf (pixbuf); - cursor = GDK.gdk_cursor_new_from_texture (texture, hotspotX, hotspotY, 0); + long texture = GDK.gdk_texture_new_for_pixbuf(pixbuf); + cursor = GDK.gdk_cursor_new_from_texture(texture, hotspotX, hotspotY, 0); + OS.g_object_unref(texture); } else { cursor = GDK.gdk_cursor_new_from_pixbuf(GDK.gdk_display_get_default(), pixbuf, hotspotX, hotspotY); } OS.g_object_unref(pixbuf); + return cursor; } |