Kaydet (Commit) 038d13ef authored tarafından Tor Lillqvist's avatar Tor Lillqvist

Introduce vcl::IsWindowSystemAvailable()

Change-Id: I6e3f804833db7487ddf7ba75c43d15017dcbe1ba
üst 3d177c7b
......@@ -1706,6 +1706,13 @@ inline void Application::EndYield()
PostUserEvent( Link() );
}
namespace vcl
{
VCL_DLLPUBLIC bool IsWindowSystemAvailable();
}
#endif // _APP_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
/* -*- 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: */
......@@ -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: */
......@@ -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 )
{
......
......@@ -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: */
......@@ -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: */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment