From: Oliver Kurth Date: Fri, 15 Sep 2017 18:23:40 +0000 (-0700) Subject: Port X11 resolutionSet off gtk X-Git-Tag: stable-10.2.0~204 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=45c2246c6c84ff1923ac3f33d884b124530db8e6;p=thirdparty%2Fopen-vm-tools.git Port X11 resolutionSet off gtk 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. --- diff --git a/open-vm-tools/services/plugins/resolutionSet/resolutionRandR12.c b/open-vm-tools/services/plugins/resolutionSet/resolutionRandR12.c index 84b788b7e..b5fc83507 100644 --- a/open-vm-tools/services/plugins/resolutionSet/resolutionRandR12.c +++ b/open-vm-tools/services/plugins/resolutionSet/resolutionRandR12.c @@ -139,7 +139,7 @@ static FILE *_ofile; #define LOG_STOP fclose(_ofile) #else #define LOG_START -#include +#include #define LOG_STOP #endif diff --git a/open-vm-tools/services/plugins/resolutionSet/resolutionSet.c b/open-vm-tools/services/plugins/resolutionSet/resolutionSet.c index 52e0c5ba4..bee1fee29 100644 --- a/open-vm-tools/services/plugins/resolutionSet/resolutionSet.c +++ b/open-vm-tools/services/plugins/resolutionSet/resolutionSet.c @@ -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 */ diff --git a/open-vm-tools/services/plugins/resolutionSet/resolutionX11.c b/open-vm-tools/services/plugins/resolutionSet/resolutionX11.c index cec4aa287..d2a2a7a40 100644 --- a/open-vm-tools/services/plugins/resolutionSet/resolutionX11.c +++ b/open-vm-tools/services/plugins/resolutionSet/resolutionX11.c @@ -35,8 +35,6 @@ #ifndef NO_MULTIMON #include #endif -#include -#include #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; }