summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorTor Lillqvist <tml@collabora.com>2015-03-30 13:12:34 +0300
committerTor Lillqvist <tml@collabora.com>2015-03-30 16:01:38 +0300
commit038d13ef848e0c773d531048637d760395a56d9f (patch)
tree2b6a5e97c5894f41802a642e7090f4b2fe7c3046 /vcl
parent3d177c7b6dae0af7d2e4822b3812757c9f65a0c3 (diff)
Introduce vcl::IsWindowSystemAvailable()
Change-Id: I6e3f804833db7487ddf7ba75c43d15017dcbe1ba
Diffstat (limited to 'vcl')
-rw-r--r--vcl/inc/unx/x11/x11display.hxx25
-rw-r--r--vcl/osx/salinst.cxx11
-rw-r--r--vcl/unx/generic/app/saldata.cxx52
-rw-r--r--vcl/unx/generic/gdi/x11windowprovider.cxx72
-rw-r--r--vcl/win/source/app/saldata.cxx11
5 files changed, 121 insertions, 50 deletions
diff --git a/vcl/inc/unx/x11/x11display.hxx b/vcl/inc/unx/x11/x11display.hxx
new file mode 100644
index 000000000000..8da1c5295c81
--- /dev/null
+++ b/vcl/inc/unx/x11/x11display.hxx
@@ -0,0 +1,25 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_VCL_INC_UNX_X11_X11DISPLAY_HXX
+#define INCLUDED_VCL_INC_UNX_X11_X11DISPLAY_HXX
+
+#include <prex.h>
+#include <X11/Xproto.h>
+#include <postx.h>
+
+#include <rtl/string.hxx>
+
+#include <vcl/dllapi.h>
+
+Display* VCL_DLLPUBLIC OpenX11Display(OString& rDisplay);
+
+#endif // INCLUDED_VCL_INC_UNX_X11_X11DISPLAY_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/osx/salinst.cxx b/vcl/osx/salinst.cxx
index 105a9a914553..fc8e9e474f66 100644
--- a/vcl/osx/salinst.cxx
+++ b/vcl/osx/salinst.cxx
@@ -1070,4 +1070,15 @@ NSImage* CreateNSImage( const Image& rImage )
return pImage;
}
+namespace vcl
+{
+
+bool IsWindowSystemAvailable()
+{
+ // Yes I know the parens are not needed. I like them in cases like this. So sue me.
+ return ([NSScreen screens] != nil && [[NSScreen screens] count] > 0);
+}
+
+} // namespace vcl
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/unx/generic/app/saldata.cxx b/vcl/unx/generic/app/saldata.cxx
index 2a90eb7dc49d..bbb9aba7c2e0 100644
--- a/vcl/unx/generic/app/saldata.cxx
+++ b/vcl/unx/generic/app/saldata.cxx
@@ -39,10 +39,6 @@
#include <sys/time.h>
#endif
-#include <prex.h>
-#include <X11/Xproto.h>
-#include <postx.h>
-
#include <osl/process.h>
#include <osl/mutex.hxx>
@@ -52,6 +48,7 @@
#include "unx/sm.hxx"
#include "unx/i18n_im.hxx"
#include "unx/i18n_xkb.hxx"
+#include "unx/x11/x11display.hxx"
#include "salinst.hxx"
#include <osl/signal.h>
@@ -395,53 +392,8 @@ void SalXLib::Init()
pInputMethod->SetLocale();
XrmInitialize();
- /*
- * open connection to X11 Display
- * try in this order:
- * o -display command line parameter,
- * o $DISPLAY environment variable
- * o default display
- */
-
- Display *pDisp = NULL;
-
- // is there a -display command line parameter?
-
- sal_uInt32 nParams = osl_getCommandArgCount();
- OUString aParam;
OString aDisplay;
- for (sal_uInt16 i=0; i<nParams; i++)
- {
- osl_getCommandArg(i, &aParam.pData);
- if ( aParam == "-display" )
- {
- osl_getCommandArg(i+1, &aParam.pData);
- aDisplay = OUStringToOString(
- aParam, osl_getThreadTextEncoding());
-
- if ((pDisp = XOpenDisplay(aDisplay.getStr()))!=NULL)
- {
- /*
- * if a -display switch was used, we need
- * to set the environment accoringly since
- * the clipboard build another connection
- * to the xserver using $DISPLAY
- */
- OUString envVar("DISPLAY");
- osl_setEnvironment(envVar.pData, aParam.pData);
- }
- break;
- }
- }
-
- if (!pDisp && aDisplay.isEmpty())
- {
- // Open $DISPLAY or default...
- char *pDisplay = getenv("DISPLAY");
- if (pDisplay != NULL)
- aDisplay = OString(pDisplay);
- pDisp = XOpenDisplay(pDisplay);
- }
+ Display *pDisp = OpenX11Display(aDisplay);
if ( !pDisp )
{
diff --git a/vcl/unx/generic/gdi/x11windowprovider.cxx b/vcl/unx/generic/gdi/x11windowprovider.cxx
index 5eaa3f612c45..03a7adfe18de 100644
--- a/vcl/unx/generic/gdi/x11windowprovider.cxx
+++ b/vcl/unx/generic/gdi/x11windowprovider.cxx
@@ -7,10 +7,82 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
+#include <vcl/svapp.hxx>
+
#include "unx/x11windowprovider.hxx"
+#include "unx/x11/x11display.hxx"
X11WindowProvider::~X11WindowProvider()
{
}
+Display *OpenX11Display(OString& rDisplay)
+{
+ /*
+ * open connection to X11 Display
+ * try in this order:
+ * o -display command line parameter,
+ * o $DISPLAY environment variable
+ * o default display
+ */
+
+ Display *pDisp = NULL;
+
+ // is there a -display command line parameter?
+
+ sal_uInt32 nParams = osl_getCommandArgCount();
+ OUString aParam;
+ for (sal_uInt16 i=0; i<nParams; i++)
+ {
+ osl_getCommandArg(i, &aParam.pData);
+ if ( aParam == "-display" )
+ {
+ osl_getCommandArg(i+1, &aParam.pData);
+ rDisplay = OUStringToOString(
+ aParam, osl_getThreadTextEncoding());
+
+ if ((pDisp = XOpenDisplay(rDisplay.getStr()))!=NULL)
+ {
+ /*
+ * if a -display switch was used, we need
+ * to set the environment accoringly since
+ * the clipboard build another connection
+ * to the xserver using $DISPLAY
+ */
+ OUString envVar("DISPLAY");
+ osl_setEnvironment(envVar.pData, aParam.pData);
+ }
+ break;
+ }
+ }
+
+ if (!pDisp && rDisplay.isEmpty())
+ {
+ // Open $DISPLAY or default...
+ char *pDisplay = getenv("DISPLAY");
+ if (pDisplay != NULL)
+ rDisplay = OString(pDisplay);
+ pDisp = XOpenDisplay(pDisplay);
+ }
+
+ return pDisp;
+}
+
+namespace vcl
+{
+
+bool IsWindowSystemAvailable()
+{
+ Display *pDisp;
+ OString aDisplay;
+
+ pDisp = OpenX11Display(aDisplay);
+ if (pDisp)
+ XCloseDisplay(pDisp);
+
+ return (pDisp != nullptr);
+}
+
+} // namespace vcl
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/win/source/app/saldata.cxx b/vcl/win/source/app/saldata.cxx
index 821790beb0e9..7c70bfa17319 100644
--- a/vcl/win/source/app/saldata.cxx
+++ b/vcl/win/source/app/saldata.cxx
@@ -74,4 +74,15 @@ int ImplSalWICompareAscii( const wchar_t* pStr1, const char* pStr2 )
return nRet;
}
+namespace vcl
+{
+
+bool IsWindowSystemAvailable()
+{
+ return true; // FIXME: we want this to return false if logged in
+ // to some Cygwin ssh session for instance
+}
+
+} // namespace vcl
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */