diff options
author | Eric Williams | 2019-05-27 18:25:24 +0000 |
---|---|---|
committer | Eric Williams | 2019-06-11 19:41:28 +0000 |
commit | f7637e66ba1a0e60c7e4919d99cfaf4e62663d20 (patch) | |
tree | ed1c30057b928ff942baf08aafccf40ce6815616 /bundles | |
parent | aedb93fcdacf0c965a697676566985de1ac16f45 (diff) | |
download | eclipse.platform.swt-f7637e66ba1a0e60c7e4919d99cfaf4e62663d20.tar.gz eclipse.platform.swt-f7637e66ba1a0e60c7e4919d99cfaf4e62663d20.tar.xz eclipse.platform.swt-f7637e66ba1a0e60c7e4919d99cfaf4e62663d20.zip |
Bug 547557: [GTK] Shell.print(GC) not implemented
Implement Shell.print(GC) using a GdkPixbuf obtained from the root
GdkWindow. This only works on GTK3 + X11, Wayland and GTK4 will likely
need a different approach which will take more time to investigate.
Tested on GTK3.24 on X11, both inside a flatpak and not. Output behaves
as expected, no AllNonBrowser JUnit tests fail.
Change-Id: Ibf39d60f2e97c1ecf8e45c9cdda6da3e9d7e160e
Signed-off-by: Eric Williams <ericwill@redhat.com>
Diffstat (limited to 'bundles')
6 files changed, 49 insertions, 0 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c index f88e3fd40d..9783370d4a 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c @@ -1657,6 +1657,18 @@ JNIEXPORT jlong JNICALL GDK_NATIVE(_1gdk_1pixbuf_1get_1byte_1length) } #endif +#ifndef NO__1gdk_1pixbuf_1get_1from_1window +JNIEXPORT jlong JNICALL GDK_NATIVE(_1gdk_1pixbuf_1get_1from_1window) + (JNIEnv *env, jclass that, jlong arg0, jint arg1, jint arg2, jint arg3, jint arg4) +{ + jlong rc = 0; + GDK_NATIVE_ENTER(env, that, _1gdk_1pixbuf_1get_1from_1window_FUNC); + rc = (jlong)gdk_pixbuf_get_from_window((GdkWindow *)arg0, arg1, arg2, arg3, arg4); + GDK_NATIVE_EXIT(env, that, _1gdk_1pixbuf_1get_1from_1window_FUNC); + return rc; +} +#endif + #ifndef NO__1gdk_1pixbuf_1get_1has_1alpha JNIEXPORT jboolean JNICALL GDK_NATIVE(_1gdk_1pixbuf_1get_1has_1alpha) (JNIEnv *env, jclass that, jlong arg0) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.h index 98f86dd750..11abf15d99 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.h +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.h @@ -274,6 +274,7 @@ #define NO__1gtk_1widget_1style_1get__J_3B_3JJ #define NO__1gtk_1css_1provider_1load_1from_1data__I_3BI_3I #define NO__1gtk_1css_1provider_1load_1from_1data__J_3BJ_3J +#define NO__1gdk_1pixbuf_1get_1from_1window // Some GtkContainer functions don't exist on GTK4 #define NO__1gtk_1container_1propagate_1draw diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c index 3d9d40141a..9218cda91e 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c @@ -136,6 +136,7 @@ char * GDK_nativeFunctionNames[] = { "_1gdk_1pixbuf_1format_1get_1name", "_1gdk_1pixbuf_1get_1bits_1per_1sample", "_1gdk_1pixbuf_1get_1byte_1length", + "_1gdk_1pixbuf_1get_1from_1window", "_1gdk_1pixbuf_1get_1has_1alpha", "_1gdk_1pixbuf_1get_1height", "_1gdk_1pixbuf_1get_1n_1channels", diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h index acb253ec53..8fa62cb8c8 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h @@ -146,6 +146,7 @@ typedef enum { _1gdk_1pixbuf_1format_1get_1name_FUNC, _1gdk_1pixbuf_1get_1bits_1per_1sample_FUNC, _1gdk_1pixbuf_1get_1byte_1length_FUNC, + _1gdk_1pixbuf_1get_1from_1window_FUNC, _1gdk_1pixbuf_1get_1has_1alpha_FUNC, _1gdk_1pixbuf_1get_1height_FUNC, _1gdk_1pixbuf_1get_1n_1channels_FUNC, 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 6132c5c132..e8072b71f8 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 @@ -1548,6 +1548,19 @@ public class GDK extends OS { lock.unlock(); } } + /** + * @param window cast=(GdkWindow *) + */ + public static final native long _gdk_pixbuf_get_from_window(long window, int x, int y, int width, int height); + /** [GTK3 only, if-def'd in os.h] */ + public static final long gdk_pixbuf_get_from_window(long window, int x, int y, int width, int height) { + lock.lock(); + try { + return _gdk_pixbuf_get_from_window(window, x, y, width, height); + } finally { + lock.unlock(); + } + } /** @param pixbuf cast=(const GdkPixbuf *) */ public static final native int _gdk_pixbuf_get_height(long pixbuf); public static final int gdk_pixbuf_get_height(long pixbuf) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java index caa4466520..99f514f3f6 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java @@ -1978,6 +1978,27 @@ public boolean print (GC gc) { checkWidget (); if (gc == null) error (SWT.ERROR_NULL_ARGUMENT); if (gc.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); + // Needs to be implemented on GTK4/Wayland + if (!GTK.GTK4 && OS.isX11()) { + Rectangle clipping = gc.getClipping(); + long shellWindow = gtk_widget_get_window(shellHandle); + GdkRectangle rect = new GdkRectangle (); + GDK.gdk_window_get_frame_extents (shellWindow, rect); + if (clipping.height < rect.height || clipping.width < rect.width) { + System.err.println("Warning: the GC provided to Shell.print() has a smaller" + + " clipping than what is needed to print the Shell trimmings" + + " and content. Only the client area will be printed."); + return super.print(gc); + } + long rootWindow = GDK.gdk_get_default_root_window(); + long pixbuf = GDK.gdk_pixbuf_get_from_window(rootWindow, rect.x, rect.y, rect.width, rect.height); + if (pixbuf != 0) { + GDK.gdk_cairo_set_source_pixbuf(gc.handle, pixbuf, 0, 0); + Cairo.cairo_paint(gc.handle); + OS.g_object_unref(pixbuf); + return true; + } + } return false; } |