[GTK] Use gdk_screen_get_monitor_workarea() when available for screenAvailableRect()
https://bugs.webkit.org/show_bug.cgi?id=75435

Reviewed by Martin Robinson.

Source/WebCore:

* platform/gtk/GtkVersioning.c:
(getScreenCurrentDesktop):
(getScreenWorkArea):
(gdk_screen_get_monitor_workarea): Implement it when GTK+ < 3.3.6.
* platform/gtk/GtkVersioning.h:
* platform/gtk/PlatformScreenGtk.cpp:
(WebCore::screenAvailableRect): Use
gdk_screen_get_monitor_workarea() instead of our own
implementation.

Source/WebKit/gtk:

* GNUmakefile.am: Make sure unit tests link to X11.

Tools:

* GNUmakefile.am: Make sure DRT links to X11.
* WebKitTestRunner/GNUmakefile.am: Make sure WTR links to X11.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@103929 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/Source/WebCore/platform/gtk/PlatformScreenGtk.cpp b/Source/WebCore/platform/gtk/PlatformScreenGtk.cpp
index 6150b90..93228c3 100644
--- a/Source/WebCore/platform/gtk/PlatformScreenGtk.cpp
+++ b/Source/WebCore/platform/gtk/PlatformScreenGtk.cpp
@@ -39,11 +39,6 @@
 
 #include <gtk/gtk.h>
 
-#if PLATFORM(X11)
-#include <gdk/gdkx.h>
-#include <X11/Xatom.h>
-#endif
-
 namespace WebCore {
 
 static GtkWidget* getToplevel(GtkWidget* widget)
@@ -134,7 +129,6 @@
     if (!widget)
         return FloatRect();
 
-#if PLATFORM(X11)
     GtkWidget* container = GTK_WIDGET(widget->root()->hostWindow()->platformPageClient());
     if (container && !gtk_widget_get_realized(container))
         return screenRect(widget);
@@ -143,34 +137,13 @@
     if (!screen)
         return FloatRect();
 
-    GdkWindow* rootWindow = gdk_screen_get_root_window(screen);
-    GdkDisplay* display = gdk_window_get_display(rootWindow);
-    Atom xproperty = gdk_x11_get_xatom_by_name_for_display(display, "_NET_WORKAREA");
+    gint monitor = container ? gdk_screen_get_monitor_at_window(screen, gtk_widget_get_window(container)) : 0;
 
-    Atom retType;
-    int retFormat;
-    long *workAreaPos = NULL;
-    unsigned long retNItems;
-    unsigned long retAfter;
-    int xRes = XGetWindowProperty(GDK_DISPLAY_XDISPLAY(display), GDK_WINDOW_XWINDOW(rootWindow), xproperty,
-        0, 4, FALSE, XA_CARDINAL, &retType, &retFormat, &retNItems, &retAfter, (guchar**)&workAreaPos);
+    GdkRectangle workArea;
+    gdk_screen_get_monitor_workarea(screen, monitor, &workArea);
 
-    FloatRect rect;
-    if (xRes == Success && workAreaPos != NULL && retType == XA_CARDINAL && retNItems == 4 && retFormat == 32) {
-        rect = FloatRect(workAreaPos[0], workAreaPos[1], workAreaPos[2], workAreaPos[3]);
-        // rect contains the available space in the whole screen not just in the monitor
-        // containing the widget, so we intersect it with the monitor rectangle.
-        rect.intersect(screenRect(widget));
-    } else
-        rect = screenRect(widget);
+    return FloatRect(workArea.x, workArea.y, workArea.width, workArea.height);
 
-    if (workAreaPos)
-        XFree(workAreaPos);
-
-    return rect;
-#else
-    return screenRect(widget);
-#endif
 }
 
 } // namespace WebCore