]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
Port X11 resolutionSet off gtk
authorOliver Kurth <okurth@vmware.com>
Fri, 15 Sep 2017 18:23:40 +0000 (11:23 -0700)
committerOliver Kurth <okurth@vmware.com>
Fri, 15 Sep 2017 18:23:40 +0000 (11:23 -0700)
Replaced gtk calls with XOpenDisplay to obtain X Display.
Also moved getting the display logic (XOpenDisplay) from
ResolutionToolkitInit to ResolutionBackendInit and
corresponding XCloseDisplay in ResolutionBackendCleanup.
ResolutionInfoX11Type is used as back-end specific handle
and canUseResolutionKMS bool variable to communicate to
loader about resolutionCheckForKMS.  Removed gtk header
from ResolutionX11.c and ResolutionRandR12.c.

open-vm-tools/services/plugins/resolutionSet/resolutionRandR12.c
open-vm-tools/services/plugins/resolutionSet/resolutionSet.c
open-vm-tools/services/plugins/resolutionSet/resolutionX11.c

index 84b788b7e7816df901d8372788429e427349183a..b5fc83507ab612324e8464ca4b5bc4e820a038ff 100644 (file)
@@ -139,7 +139,7 @@ static FILE *_ofile;
 #define LOG_STOP fclose(_ofile)
 #else
 #define LOG_START
-#include <gtk/gtk.h>
+#include <glib.h>
 #define LOG_STOP
 #endif
 
index 52e0c5ba4ad94c74fa7606337974ad8ba658eb2a..bee1fee294b3ab9f63e5ad000c15849f235377fc 100644 (file)
@@ -76,8 +76,7 @@ ResolutionInfoType resolutionInfo;
  *
  * Initialize the guest resolution library.
  *
- * @param[in] handle  Back-end specific handle, if needed.  E.g., in the X11
-                      case, this refers to the X11 display handle.
+ * @param[in] handle  Back-end specific handle, if needed.
  * @return TRUE on success, FALSE on failure
  */
 
index cec4aa287efe0f28d9bb9cfc7ce64f7a1ab5c612..d2a2a7a4066e4afc7a4be9f3ab6174161344b5de 100644 (file)
@@ -35,8 +35,6 @@
 #ifndef NO_MULTIMON
 #include <X11/extensions/Xinerama.h>
 #endif
-#include <gtk/gtk.h>
-#include <gdk/gdkx.h>
 
 #include "vmware.h"
 #include "debug.h"
@@ -62,6 +60,8 @@ typedef struct {
    Bool         canUseVMwareCtrlTopologySet;
                                 // TRUE if VMwareCtrl extension supports topology set
    Bool         canUseRandR12;  // TRUE if RandR extension >= 1.2 available
+
+   Bool         canUseResolutionKMS;    // TRUE if backing off for resolutionKMS
 } ResolutionInfoX11Type;
 
 
@@ -78,6 +78,7 @@ ResolutionInfoX11Type resolutionInfoX11;
 static Bool ResolutionCanSet(void);
 static Bool TopologyCanSet(void);
 static Bool SelectResolution(uint32 width, uint32 height);
+static int ResolutionX11ErrorHandler(Display *d, XErrorEvent *e);
 
 
 /*
@@ -89,29 +90,34 @@ static Bool SelectResolution(uint32 width, uint32 height);
  * X11 back-end initializer.  Records caller's X11 display, then determines
  * which capabilities are available.
  *
- * @param[in] handle User's X11 display
+ * @param[in] handle (ResolutionInfoX11Type is used as backend specific handle)
  * @return TRUE on success, FALSE on failure.
  */
 
 Bool
 ResolutionBackendInit(InitHandle handle)
 {
-   ResolutionInfoX11Type *resInfoX = &resolutionInfoX11;
+   ResolutionInfoX11Type *resInfoX = (ResolutionInfoX11Type *)handle;
    ResolutionInfoType *resInfo = &resolutionInfo;
    int dummy1;
    int dummy2;
 
-   memset(resInfoX, 0, sizeof *resInfoX);
+   if (resInfoX->canUseResolutionKMS == TRUE) {
+      resInfo->canSetResolution = FALSE;
+      resInfo->canSetTopology = FALSE;
+      return TRUE;
+   }
 
-   resInfoX->display = handle;
+   XSetErrorHandler(ResolutionX11ErrorHandler);
+   resInfoX->display = XOpenDisplay(NULL);
 
    if (resInfoX->display == NULL) {
+      g_error("%s: Invalid display detected.\n", __func__);
       resInfo->canSetResolution = FALSE;
       resInfo->canSetTopology = FALSE;
       return TRUE;
    }
 
-   resInfoX->display = handle;
    resInfoX->rootWindow = DefaultRootWindow(resInfoX->display);
    resInfoX->canUseVMwareCtrl = VMwareCtrl_QueryVersion(resInfoX->display, &dummy1,
                                                         &dummy2);
@@ -132,6 +138,10 @@ ResolutionBackendInit(InitHandle handle)
 void
 ResolutionBackendCleanup(void)
 {
+   ResolutionInfoX11Type *resInfoX = &resolutionInfoX11;
+   if (resInfoX->display) {
+      XCloseDisplay(resInfoX->display);
+   }
    return;
 }
 
@@ -524,7 +534,7 @@ SelectResolution(uint32 width,
       g_debug("Setting guest resolution to: %dx%d (requested: %d, %d)\n",
               xrrSizes[bestFitIndex].width, xrrSizes[bestFitIndex].height, width, height);
       rc = XRRSetScreenConfig(resInfoX->display, xrrConfig, resInfoX->rootWindow,
-                              bestFitIndex, xrrCurRotation, GDK_CURRENT_TIME);
+                              bestFitIndex, xrrCurRotation, CurrentTime);
       g_debug("XRRSetScreenConfig returned %d (result: %dx%d)\n", rc,
               xrrSizes[bestFitIndex].width, xrrSizes[bestFitIndex].height);
    } else {
@@ -574,41 +584,28 @@ ResolutionX11ErrorHandler(Display *d,      // IN: Pointer to display connection
 
 
 /**
- * Obtain a "handle", which for X11, is a display pointer. 
+ * Obtain a "handle".
  *
  * @note We will have to move this out of the resolution plugin soon, I am
- * just landing this here now for convenience as I port resolution set over 
+ * just landing this here now for convenience as I port resolution set over
  * to the new service architecture.
  *
- * @return X server display 
+ * @return ResolutionInfoX11Type as backend specific handle
  */
 
 InitHandle
 ResolutionToolkitInit(ToolsAppCtx *ctx) // IN: For config database access
 {
-   int argc = 1;
-   char *argv[] = {"", NULL};
-   GtkWidget *wnd;
-   Display *display;
+   ResolutionInfoX11Type *resInfoX = &resolutionInfoX11;
    int fd;
 
+   memset(resInfoX, 0, sizeof *resInfoX);
+
    fd = resolutionCheckForKMS(ctx);
    if (fd >= 0) {
       resolutionDRMClose(fd);
       g_message("%s: Backing off for resolutionKMS.\n", __func__);
-      return (InitHandle) 0;
+      resInfoX->canUseResolutionKMS = TRUE;
    }
-
-   XSetErrorHandler(ResolutionX11ErrorHandler);
-   gtk_init(&argc, (char ***) &argv);
-   wnd = gtk_invisible_new();
-#ifndef GTK3
-   display = GDK_WINDOW_XDISPLAY(wnd->window);
-#else
-   display = GDK_WINDOW_XDISPLAY(gtk_widget_get_window(wnd));
-#endif
-   if (!display)
-      g_error("%s: Invalid display detected.\n", __func__);
-
-   return (InitHandle) display;
+   return (InitHandle) resInfoX;
 }