Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Xenos2015-05-07 21:03:20 +0000
committerArun Thondapu2015-05-11 14:44:51 +0000
commit35e16e89ccce91ccd7ae7405a9aa8da00d9bc86a (patch)
treee61628a22c08cae51116807def0c57e76c29ef7b
parent7ce594b4bb9c7af0245cbdcabf2b4eb3444323e4 (diff)
downloadeclipse.platform.swt-35e16e89ccce91ccd7ae7405a9aa8da00d9bc86a.tar.gz
eclipse.platform.swt-35e16e89ccce91ccd7ae7405a9aa8da00d9bc86a.tar.xz
eclipse.platform.swt-35e16e89ccce91ccd7ae7405a9aa8da00d9bc86a.zip
Bug 466112 - Use the correct GDK calls to
compute the client area for the monitors Change-Id: I4d94860d40d2726e98c2416a50c8bc72fa9d9286 Signed-off-by: Stefan Xenos <sxenos@google.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c22
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h1
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c1
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h1
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java16
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java44
6 files changed, 75 insertions, 10 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 f16748c0c7..14c8a5d58f 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
@@ -7443,6 +7443,28 @@ JNIEXPORT jint JNICALL OS_NATIVE(_1gdk_1screen_1get_1monitor_1width_1mm)
}
#endif
+#ifndef NO__1gdk_1screen_1get_1monitor_1workarea
+JNIEXPORT void JNICALL OS_NATIVE(_1gdk_1screen_1get_1monitor_1workarea)
+ (JNIEnv *env, jclass that, jintLong arg0, jint arg1, jobject arg2)
+{
+ GdkRectangle _arg2, *lparg2=NULL;
+ OS_NATIVE_ENTER(env, that, _1gdk_1screen_1get_1monitor_1workarea_FUNC);
+ if (arg2) if ((lparg2 = &_arg2) == NULL) goto fail;
+/*
+ gdk_screen_get_monitor_workarea((GdkScreen *)arg0, arg1, lparg2);
+*/
+ {
+ OS_LOAD_FUNCTION(fp, gdk_screen_get_monitor_workarea)
+ if (fp) {
+ ((void (CALLING_CONVENTION*)(GdkScreen *, jint, GdkRectangle *))fp)((GdkScreen *)arg0, arg1, lparg2);
+ }
+ }
+fail:
+ if (arg2 && lparg2) setGdkRectangleFields(env, arg2, lparg2);
+ OS_NATIVE_EXIT(env, that, _1gdk_1screen_1get_1monitor_1workarea_FUNC);
+}
+#endif
+
#ifndef NO__1gdk_1screen_1get_1n_1monitors
JNIEXPORT jint JNICALL OS_NATIVE(_1gdk_1screen_1get_1n_1monitors)
(JNIEnv *env, jclass that, jintLong arg0)
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h
index 0d3a411445..88015a8a01 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h
@@ -508,6 +508,7 @@
#define gtk_style_context_invalidate_LIB LIB_GTK
#define gtk_hsv_to_rgb_LIB LIB_GTK
#define gtk_rgb_to_hsv_LIB LIB_GTK
+#define gdk_screen_get_monitor_workarea_LIB LIB_GDK
#define gdk_window_set_background_pattern_LIB LIB_GTK
#define gtk_widget_input_shape_combine_region_LIB LIB_GTK
#define gtk_entry_set_placeholder_text_LIB LIB_GTK
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 5b8b2ceb58..157145a6c0 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
@@ -559,6 +559,7 @@ char * OS_nativeFunctionNames[] = {
"_1gdk_1screen_1get_1monitor_1at_1window",
"_1gdk_1screen_1get_1monitor_1geometry",
"_1gdk_1screen_1get_1monitor_1width_1mm",
+ "_1gdk_1screen_1get_1monitor_1workarea",
"_1gdk_1screen_1get_1n_1monitors",
"_1gdk_1screen_1get_1primary_1monitor",
"_1gdk_1screen_1height",
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 cba5bbc91f..05432e91b2 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
@@ -569,6 +569,7 @@ typedef enum {
_1gdk_1screen_1get_1monitor_1at_1window_FUNC,
_1gdk_1screen_1get_1monitor_1geometry_FUNC,
_1gdk_1screen_1get_1monitor_1width_1mm_FUNC,
+ _1gdk_1screen_1get_1monitor_1workarea_FUNC,
_1gdk_1screen_1get_1n_1monitors_FUNC,
_1gdk_1screen_1get_1primary_1monitor_FUNC,
_1gdk_1screen_1height_FUNC,
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java
index 97b8d52d23..4114367e95 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java
@@ -5497,6 +5497,22 @@ public static final void gdk_screen_get_monitor_geometry (long /*int*/ screen, i
lock.unlock();
}
}
+
+/**
+ * @method flags=dynamic
+ * @param screen cast=(GdkScreen *)
+ * @param dest flags=no_in
+ */
+public static final native void _gdk_screen_get_monitor_workarea (long /*int*/ screen, int monitor_num, GdkRectangle dest);
+public static final void gdk_screen_get_monitor_workarea (long /*int*/ screen, int monitor_num, GdkRectangle dest) {
+ lock.lock();
+ try {
+ _gdk_screen_get_monitor_workarea(screen, monitor_num, dest);
+ } finally {
+ lock.unlock();
+ }
+}
+
/**
* @method flags=dynamic
* @param screen cast=(GdkScreen *)
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java
index 6afbc710d1..0967eb5d96 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java
@@ -1931,7 +1931,7 @@ Rectangle getWorkArea() {
public Monitor [] getMonitors () {
checkDevice ();
Monitor [] monitors = null;
- Rectangle workArea = getWorkArea();
+ Rectangle workArea = getWorkArea ();
long /*int*/ screen = OS.gdk_screen_get_default ();
if (screen != 0) {
int monitorCount = OS.gdk_screen_get_n_monitors (screen);
@@ -1946,16 +1946,40 @@ public Monitor [] getMonitors () {
monitor.y = dest.y;
monitor.width = dest.width;
monitor.height = dest.height;
- if (i == 0 && workArea != null) {
- monitor.clientX = workArea.x;
- monitor.clientY = workArea.y;
- monitor.clientWidth = workArea.width;
- monitor.clientHeight = workArea.height;
+
+ if (OS.GTK_VERSION >= OS.VERSION (3, 4, 0)) {
+ // workarea was defined in GTK 3.4. If present, it will return the best results
+ // since it takes into account per-monitor trim
+ OS.gdk_screen_get_monitor_workarea (screen, i, dest);
+ monitor.clientX = dest.x;
+ monitor.clientY = dest.y;
+ monitor.clientWidth = dest.width;
+ monitor.clientHeight = dest.height;
} else {
- monitor.clientX = monitor.x;
- monitor.clientY = monitor.y;
- monitor.clientWidth = monitor.width;
- monitor.clientHeight = monitor.height;
+ // If we're on an older version of gtk without the workarea function, see if we can use
+ // the getWorkArea function. In the case of multi-monitors, this will return something that
+ // is approximately a bounding rectangle for the work areas of all the monitors, so intersecting
+ // that rectangle with the monitor boundaries will provide an approximation of the per-monitor
+ // work area.
+ if (workArea != null) {
+ monitor.clientX = Math.max (monitor.x, workArea.x);
+ monitor.clientY = Math.max (monitor.y, workArea.y);
+ monitor.clientHeight = Math
+ .max(Math.min (monitor.y + monitor.height, workArea.y + workArea.height)
+ - monitor.clientY, 0);
+ monitor.clientWidth = Math.max (
+ Math.min (monitor.x + monitor.width, workArea.x + workArea.width) - monitor.clientX,
+ 0);
+ }
+
+ // If getWorkArea is not available or it did not return a rectangle that intersects the monitor
+ // bounds, then use the monitor bounds itself as the work area.
+ if (workArea == null || monitor.clientWidth == 0 || monitor.clientHeight == 0) {
+ monitor.clientX = monitor.x;
+ monitor.clientY = monitor.y;
+ monitor.clientHeight = monitor.height;
+ monitor.clientWidth = monitor.width;
+ }
}
monitors [i] = monitor;
}

Back to the top