From: VMware, Inc <> Date: Thu, 18 Nov 2010 22:03:34 +0000 (-0800) Subject: GHI/X11: Move "DetectDesktopEnv" to lib/xdg. X-Git-Tag: 2010.11.17-327185~46 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ca030dffff3c226ddefc40e6b0e2a7e18cc6f6de;p=thirdparty%2Fopen-vm-tools.git GHI/X11: Move "DetectDesktopEnv" to lib/xdg. This takes the static deskeop environment detection logic out of lib/ ghIntegration and places it a shell script and wrapper in lib/xdg. We'll now distribute with Tools a vmware-xdg-detect-de which contains the "detectDE" routine used in many of Portland's xdg-* scripts. Keeping this logic in a script has a few motivations: 1. No D-Bus (or similar) dependency added to library code. 2. Allows users to hack as time goes on in case any of the methods currently employed stop working. Signed-off-by: Marcelo Vanzin --- diff --git a/open-vm-tools/configure.ac b/open-vm-tools/configure.ac index 2d9333413..8134e0ef0 100644 --- a/open-vm-tools/configure.ac +++ b/open-vm-tools/configure.ac @@ -1196,6 +1196,7 @@ AC_CONFIG_FILES([ \ lib/vmCheck/Makefile \ lib/vmSignal/Makefile \ lib/wiper/Makefile \ + lib/xdg/Makefile \ services/Makefile \ services/vmtoolsd/Makefile \ services/plugins/Makefile \ diff --git a/open-vm-tools/lib/Makefile.am b/open-vm-tools/lib/Makefile.am index 77cfe9add..f1d08fe7f 100644 --- a/open-vm-tools/lib/Makefile.am +++ b/open-vm-tools/lib/Makefile.am @@ -68,3 +68,4 @@ SUBDIRS += user SUBDIRS += vmCheck SUBDIRS += vmSignal SUBDIRS += wiper +SUBDIRS += xdg diff --git a/open-vm-tools/services/plugins/unity/ghIntegration/ghiX11.h b/open-vm-tools/lib/include/xdg.h similarity index 84% rename from open-vm-tools/services/plugins/unity/ghIntegration/ghiX11.h rename to open-vm-tools/lib/include/xdg.h index 07d77e9ed..bee740cc4 100644 --- a/open-vm-tools/services/plugins/unity/ghIntegration/ghiX11.h +++ b/open-vm-tools/lib/include/xdg.h @@ -17,17 +17,17 @@ *********************************************************/ /* - * ghiX11.h + * xdg.h -- * - * Declarations specific to GHI/X11. + * vmware-xdg-* script wrapper library. */ -#ifndef _GHIX11_H_ -#define _GHIX11_H_ +#ifndef _VMWARE_XDG_H_ +#define _VMWARE_XDG_H_ #define INCLUDE_ALLOW_USERLEVEL #include "includeCheck.h" -const char *GHIX11DetectDesktopEnv(void); +extern const char *Xdg_DetectDesktopEnv(void); -#endif // ifndef _GHIX11_H_ +#endif // ifndef _VMWARE_XDG_H_ diff --git a/open-vm-tools/lib/xdg/Makefile.am b/open-vm-tools/lib/xdg/Makefile.am new file mode 100644 index 000000000..a756f275f --- /dev/null +++ b/open-vm-tools/lib/xdg/Makefile.am @@ -0,0 +1,21 @@ +################################################################################ +### Copyright 2010 VMware, Inc. All rights reserved. +### +### This program is free software; you can redistribute it and/or modify +### it under the terms of version 2 of the GNU General Public License as +### published by the Free Software Foundation. +### +### This program is distributed in the hope that it will be useful, +### but WITHOUT ANY WARRANTY; without even the implied warranty of +### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +### GNU General Public License for more details. +### +### You should have received a copy of the GNU General Public License +### along with this program; if not, write to the Free Software +### Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +################################################################################ + +noinst_LTLIBRARIES = libXdg.la + +libXdg_la_SOURCES = +libXdg_la_SOURCES += xdg.c diff --git a/open-vm-tools/lib/xdg/xdg.c b/open-vm-tools/lib/xdg/xdg.c new file mode 100644 index 000000000..f01401742 --- /dev/null +++ b/open-vm-tools/lib/xdg/xdg.c @@ -0,0 +1,109 @@ +/********************************************************* + * Copyright (C) 2010 VMware, Inc. All rights reserved. + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published + * by the Free Software Foundation version 2.1 and no later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the Lesser GNU General Public + * License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + *********************************************************/ + +/* + * xdg.c -- + * + * vmware-xdg-* script wrapper library. + */ + +#include +#include + +#include +#include + +#include "vmware.h" +#include "vmstdio.h" +#include "xdg.h" + + +/* + * Local data + */ + + +/* Name of helper script used by Xdg_DetectDesktopEnv. */ +static const char xdgDetectDEExec[] = "vmware-xdg-detect-de"; + + +/* + * Global functions + */ + + +/* + *----------------------------------------------------------------------------- + * + * Xdg_DetectDesktopEnv -- + * + * Captures output from external vmware-xdg-detect-de script to determine + * which desktop environment we're running under. + * + * Results: + * Returns a pointer to a string specifying the desktop environment on + * success or NULL on failure. + * + * This function only guarantees that the returned string matches the + * pattern ^[A-Z]*$. + * + * Side effects: + * Allocates memory for outbuf on first call for duration of program. + * Uses popen(), relying on $PATH, to find and execute xdgDetectDeExec. + * Caller must not modify returned string. + * + *----------------------------------------------------------------------------- + */ + +const char * +Xdg_DetectDesktopEnv(void) +{ + static char *outbuf = NULL; + + if (outbuf == NULL) { + FILE *cmdPipe = popen(xdgDetectDEExec, "r"); + + if (cmdPipe) { + static const size_t maxSize = sizeof "TEHLONGISTDESKTOPENVEVAR"; + size_t outLen; // Doesn't include NUL. + int status; + + if (StdIO_ReadNextLine(cmdPipe, &outbuf, maxSize, &outLen) + == StdIO_Success) { + char *i; + + for (i = outbuf; i < &outbuf[outLen]; i++) { + /* We expect a string in all capitals. */ + if (*i < 'A' || *i > 'Z') { + free(outbuf); + outbuf = NULL; + break; + } + } + } + + status = pclose(cmdPipe); + if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { + free(outbuf); + outbuf = NULL; + } + } + } + + return outbuf; +} diff --git a/open-vm-tools/scripts/common/vmware-xdg-detect-de b/open-vm-tools/scripts/common/vmware-xdg-detect-de new file mode 100644 index 000000000..357d10e8b --- /dev/null +++ b/open-vm-tools/scripts/common/vmware-xdg-detect-de @@ -0,0 +1,59 @@ +#!/bin/sh +# +# vmware-xdg-detect-de -- +# +# Determines which Freedesktop.Org compliant desktop environment we're +# running under. +# +# usage: vmware-xdg-detect-de +# +# Simply prints the detected environment (GNOME, KDE, or XFCE). Shamelessly +# lifted from detectDE() routine found in many Portland xdg-* scripts. +# + +# Copyright 2009-2010, Fathi Boudra +# Copyright 2009-2010, Rex Dieter +# Copyright 2006, Kevin Krammer +# Copyright 2006, Jeremy White +# +# LICENSE: +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR +# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. +# +#--------------------------------------------- + +#-------------------------------------- +# Checks for known desktop environments +# set variable DE to the desktop environments name, lowercase + +if [ x"$KDE_FULL_SESSION" = x"true" ]; then + DE=KDE; +elif [ x"$GNOME_DESKTOP_SESSION_ID" != x"" ]; then + DE=GNOME; +elif `dbus-send --print-reply --dest=org.freedesktop.DBus /org/freedesktop/DBus org.freedesktop.DBus.GetNameOwner string:org.gnome.SessionManager >/dev/null 2>&1` ; then + DE=GNOME; +elif xprop -root _DT_SAVE_MODE 2> /dev/null | grep ' = \"xfce4\"$' >/dev/null 2>&1; then + DE=XFCE; +fi + +if [ x"$DE" = x ]; then + exit 1 +fi + +echo $DE diff --git a/open-vm-tools/services/plugins/unity/Makefile.am b/open-vm-tools/services/plugins/unity/Makefile.am index d110a9bb9..eafa5328b 100644 --- a/open-vm-tools/services/plugins/unity/Makefile.am +++ b/open-vm-tools/services/plugins/unity/Makefile.am @@ -47,6 +47,7 @@ libunity_la_LIBADD += $(top_builddir)/lib/appUtil/libAppUtil.la libunity_la_LIBADD += $(top_builddir)/lib/image/libImage.la libunity_la_LIBADD += $(top_builddir)/lib/raster/libRaster.la libunity_la_LIBADD += $(top_builddir)/lib/region/libRegion.la +libunity_la_LIBADD += $(top_builddir)/lib/xdg/libXdg.la libunity_la_SOURCES = diff --git a/open-vm-tools/services/plugins/unity/ghIntegration/icon.cc b/open-vm-tools/services/plugins/unity/ghIntegration/icon.cc index c90d636ed..c55b29fb6 100644 --- a/open-vm-tools/services/plugins/unity/ghIntegration/icon.cc +++ b/open-vm-tools/services/plugins/unity/ghIntegration/icon.cc @@ -32,7 +32,6 @@ extern "C" { #include "vmware.h" } -#include "ghiX11.h" #include "ghiX11icon.h" diff --git a/open-vm-tools/services/plugins/unity/ghIntegration/platform.cc b/open-vm-tools/services/plugins/unity/ghIntegration/platform.cc index af61516ac..c6a24151c 100644 --- a/open-vm-tools/services/plugins/unity/ghIntegration/platform.cc +++ b/open-vm-tools/services/plugins/unity/ghIntegration/platform.cc @@ -77,6 +77,7 @@ extern "C" { #include "mntinfo.h" #include "guest_msg_def.h" #include "Uri.h" +#include "xdg.h" }; #define URI_TEXTRANGE_EQUAL(textrange, str) \ @@ -86,7 +87,6 @@ extern "C" { #include "appUtil.h" #include "ghIntegration.h" #include "ghIntegrationInt.h" -#include "ghiX11.h" #include "ghiX11icon.h" #ifdef REDIST_GMENU @@ -237,7 +237,8 @@ static bool AppInfoLaunchEnv(GHIPlatform* ghip, GAppInfo* appInfo); Bool GHIPlatformIsSupported(void) { - return GHIX11DetectDesktopEnv() != NULL; + const char *desktopEnv = Xdg_DetectDesktopEnv(); + return (strcmp(desktopEnv, "GNOME") == 0) || (strcmp(desktopEnv, "KDE") == 0); } @@ -278,7 +279,7 @@ GHIPlatformInit(GMainLoop *mainLoop, // IN ghip->nativeEnviron.push_back(*tmp); } - desktopEnv = GHIX11DetectDesktopEnv(); + desktopEnv = Xdg_DetectDesktopEnv(); g_desktop_app_info_set_desktop_env(desktopEnv); #ifdef REDIST_GMENU @@ -1458,7 +1459,7 @@ GHIPlatformShellOpen(GHIPlatform *ghip, // IN } } else { std::vector argv; - Glib::ustring de = GHIX11DetectDesktopEnv(); + Glib::ustring de = Xdg_DetectDesktopEnv(); // XXX Really we should just use xdg-open exclusively, but xdg-open // as shipped with xdg-utils 1.0.2 is broken. It is fixed // in portland CVS, but we need to import into modsource and @@ -1944,48 +1945,6 @@ tryagain: } -/* - *----------------------------------------------------------------------------- - * - * GHIX11DetectDesktopEnv -- - * - * Query environment and/or root window properties to determine if we're - * under GNOME or KDE. - * - * XXX Consider moving this to another library. - * XXX Investigate whether this requires legal review, since it's cribbed - * from xdg-utils' detectDE subroutine (MIT license). - * XXX Add the _DT_SESSION bit for XFCE detection. - * - * Results: - * Pointer to a valid string on success, NULL on failure. - * - * Side effects: - * None. - * - *----------------------------------------------------------------------------- - */ - -const char * -GHIX11DetectDesktopEnv(void) -{ - static const char *desktopEnvironment = NULL; - const char *tmp; - - if (desktopEnvironment) { - return desktopEnvironment; - } - - if (g_strcmp0(g_getenv("KDE_FULL_SESSION"), "true") == 0) { - desktopEnvironment = "KDE"; - } else if ((tmp = g_getenv("GNOME_DESKTOP_SESSION_ID")) && *tmp) { - desktopEnvironment = "GNOME"; - } - - return desktopEnvironment; -} - - /* *----------------------------------------------------------------------------- * diff --git a/open-vm-tools/toolbox/Makefile.am b/open-vm-tools/toolbox/Makefile.am index a994334ce..0cae1b9aa 100644 --- a/open-vm-tools/toolbox/Makefile.am +++ b/open-vm-tools/toolbox/Makefile.am @@ -93,6 +93,8 @@ endif $(INSTALL) -d $(DESTDIR)/usr/share/pixmaps/vmware $(INSTALL) -m 644 bigIcon.xpm \ $(DESTDIR)/usr/share/pixmaps/vmware/vmware-toolbox.xpm + $(INSTALL) -m 755 ../scripts/common/vmware-xdg-detect-de \ + $(DESTDIR)$(bindir) uninstall-hook: rm -f $(DESTDIR)$(datadir)/share/applications/vmware-toolbox.desktop rm -rf $(DESTDIR)/usr/share/pixmaps/vmware