]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
GHI/X11: Move "DetectDesktopEnv" to lib/xdg.
authorVMware, Inc <>
Thu, 18 Nov 2010 22:03:34 +0000 (14:03 -0800)
committerMarcelo Vanzin <mvanzin@vmware.com>
Thu, 18 Nov 2010 22:03:34 +0000 (14:03 -0800)
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 <mvanzin@vmware.com>
open-vm-tools/configure.ac
open-vm-tools/lib/Makefile.am
open-vm-tools/lib/include/xdg.h [moved from open-vm-tools/services/plugins/unity/ghIntegration/ghiX11.h with 84% similarity]
open-vm-tools/lib/xdg/Makefile.am [new file with mode: 0644]
open-vm-tools/lib/xdg/xdg.c [new file with mode: 0644]
open-vm-tools/scripts/common/vmware-xdg-detect-de [new file with mode: 0644]
open-vm-tools/services/plugins/unity/Makefile.am
open-vm-tools/services/plugins/unity/ghIntegration/icon.cc
open-vm-tools/services/plugins/unity/ghIntegration/platform.cc
open-vm-tools/toolbox/Makefile.am

index 2d9333413acdbe9f04922764f1d6c1a40feb4235..8134e0ef08dc6156ebc853bd1bc49b31f97a0fb2 100644 (file)
@@ -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           \
index 77cfe9add6fae99b8ccd02cb14d4c7c24375589c..f1d08fe7f76b3e1888df5cb8bbab3ffe7997efa0 100644 (file)
@@ -68,3 +68,4 @@ SUBDIRS += user
 SUBDIRS += vmCheck
 SUBDIRS += vmSignal
 SUBDIRS += wiper
+SUBDIRS += xdg
similarity index 84%
rename from open-vm-tools/services/plugins/unity/ghIntegration/ghiX11.h
rename to open-vm-tools/lib/include/xdg.h
index 07d77e9edfcd7bc69dbb173bb51fa61c568b326a..bee740cc4c55c606328c7dcc268f9e76a50ef65d 100644 (file)
  *********************************************************/
 
 /*
- * 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 (file)
index 0000000..a756f27
--- /dev/null
@@ -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 (file)
index 0000000..f014017
--- /dev/null
@@ -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 <sys/types.h>
+#include <sys/wait.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#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 (file)
index 0000000..357d10e
--- /dev/null
@@ -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 <fabo@freedesktop.org>
+#   Copyright 2009-2010, Rex Dieter <rdieter@fedoraproject.org>
+#   Copyright 2006, Kevin Krammer <kevin.krammer@gmx.at>
+#   Copyright 2006, Jeremy White <jwhite@codeweavers.com>
+#
+#   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
index d110a9bb984346bf675ffe32b5fa2bd6eeec5208..eafa5328b4c328e0a154701b68b0ef1f71401dce 100644 (file)
@@ -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 =
 
index c90d636ed85ae294f1f2d6611630e2bb10881f0b..c55b29fb6eb39f48129e3359fef4bbdc60888833 100644 (file)
@@ -32,7 +32,6 @@ extern "C" {
 #include "vmware.h"
 }
 
-#include "ghiX11.h"
 #include "ghiX11icon.h"
 
 
index af61516ac9982905e700130894408cc0320aa30f..c6a24151cb98b83cba64540bf719184af7b2d66d 100644 (file)
@@ -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<Glib::ustring> 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;
-}
-
-
 /*
  *-----------------------------------------------------------------------------
  *
index a994334ced36357164cedd6e29c205b431a772cb..0cae1b9aa184afc6b0e48b86aea4c385fa0b9004 100644 (file)
@@ -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