xref: /aoo42x/main/vcl/unx/generic/app/saldata.cxx (revision 910823ae)
1c82f2877SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3c82f2877SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4c82f2877SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5c82f2877SAndrew Rist  * distributed with this work for additional information
6c82f2877SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7c82f2877SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8c82f2877SAndrew Rist  * "License"); you may not use this file except in compliance
9c82f2877SAndrew Rist  * with the License.  You may obtain a copy of the License at
10c82f2877SAndrew Rist  *
11c82f2877SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12c82f2877SAndrew Rist  *
13c82f2877SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14c82f2877SAndrew Rist  * software distributed under the License is distributed on an
15c82f2877SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16c82f2877SAndrew Rist  * KIND, either express or implied.  See the License for the
17c82f2877SAndrew Rist  * specific language governing permissions and limitations
18c82f2877SAndrew Rist  * under the License.
19c82f2877SAndrew Rist  *
20c82f2877SAndrew Rist  *************************************************************/
21c82f2877SAndrew Rist 
22c82f2877SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_vcl.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #ifdef USE_XTOOLKIT
28cdf0e10cSrcweir #  define SAL_XT
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir 
31cdf0e10cSrcweir // -=-= #includes =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <unistd.h>
34cdf0e10cSrcweir #include <fcntl.h>
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <cstdio>
37cdf0e10cSrcweir #include <cstring>
38cdf0e10cSrcweir #include <cstdlib>
39cdf0e10cSrcweir #include <stdio.h> // snprintf, seems not to be in namespace std on every platform
40cdf0e10cSrcweir #include <limits.h>
41cdf0e10cSrcweir #include <errno.h>
42cdf0e10cSrcweir #include <pthread.h>
43cdf0e10cSrcweir #include <sys/resource.h>
44cdf0e10cSrcweir #ifdef SUN
45cdf0e10cSrcweir #include <sys/systeminfo.h>
46cdf0e10cSrcweir #endif
47cdf0e10cSrcweir #ifdef AIX
48cdf0e10cSrcweir #include <strings.h>
49cdf0e10cSrcweir #endif
50cdf0e10cSrcweir #ifdef FREEBSD
51cdf0e10cSrcweir #include <sys/types.h>
52cdf0e10cSrcweir #include <sys/time.h>
53cdf0e10cSrcweir #include <unistd.h>
54cdf0e10cSrcweir #endif
55cdf0e10cSrcweir 
56cdf0e10cSrcweir #include <vos/process.hxx>
57cdf0e10cSrcweir #include <vos/mutex.hxx>
58cdf0e10cSrcweir 
59cdf0e10cSrcweir #include "unx/Xproto.h"
60cdf0e10cSrcweir #include "unx/saldisp.hxx"
61cdf0e10cSrcweir #include "unx/saldata.hxx"
62cdf0e10cSrcweir #include "unx/salframe.h"
63cdf0e10cSrcweir #include "unx/sm.hxx"
64cdf0e10cSrcweir #include "unx/i18n_im.hxx"
65cdf0e10cSrcweir #include "unx/i18n_xkb.hxx"
66cdf0e10cSrcweir #include "salinst.hxx"
67cdf0e10cSrcweir 
68cdf0e10cSrcweir #include <osl/signal.h>
69cdf0e10cSrcweir #include <osl/thread.h>
70cdf0e10cSrcweir #include <osl/process.h>
71cdf0e10cSrcweir #include <rtl/strbuf.hxx>
72cdf0e10cSrcweir #include <rtl/bootstrap.hxx>
73cdf0e10cSrcweir 
74cdf0e10cSrcweir #include <tools/debug.hxx>
75cdf0e10cSrcweir #include <vcl/svapp.hxx>
76cdf0e10cSrcweir 
77cdf0e10cSrcweir // -=-= <signal.h> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
78cdf0e10cSrcweir #ifndef UNX
79cdf0e10cSrcweir #ifndef SIGBUS
80cdf0e10cSrcweir #define SIGBUS 10
81cdf0e10cSrcweir #endif
82cdf0e10cSrcweir #ifndef SIGSEGV
83cdf0e10cSrcweir #define SIGSEGV 11
84cdf0e10cSrcweir #endif
85cdf0e10cSrcweir #ifndef SIGIOT
86cdf0e10cSrcweir #define SIGIOT SIGABRT
87cdf0e10cSrcweir #endif
88cdf0e10cSrcweir #endif
89cdf0e10cSrcweir 
90cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
91cdf0e10cSrcweir static const struct timeval noyield__ = { 0, 0 };
92cdf0e10cSrcweir static const struct timeval yield__	  = { 0, 10000 };
93cdf0e10cSrcweir 
94cdf0e10cSrcweir static const char* XRequest[] = {
95cdf0e10cSrcweir 	// see /usr/lib/X11/XErrorDB, /usr/openwin/lib/XErrorDB ...
96cdf0e10cSrcweir 	NULL,
97cdf0e10cSrcweir 	"X_CreateWindow",
98cdf0e10cSrcweir 	"X_ChangeWindowAttributes",
99cdf0e10cSrcweir 	"X_GetWindowAttributes",
100cdf0e10cSrcweir 	"X_DestroyWindow",
101cdf0e10cSrcweir 	"X_DestroySubwindows",
102cdf0e10cSrcweir 	"X_ChangeSaveSet",
103cdf0e10cSrcweir 	"X_ReparentWindow",
104cdf0e10cSrcweir 	"X_MapWindow",
105cdf0e10cSrcweir 	"X_MapSubwindows",
106cdf0e10cSrcweir 	"X_UnmapWindow",
107cdf0e10cSrcweir 	"X_UnmapSubwindows",
108cdf0e10cSrcweir 	"X_ConfigureWindow",
109cdf0e10cSrcweir 	"X_CirculateWindow",
110cdf0e10cSrcweir 	"X_GetGeometry",
111cdf0e10cSrcweir 	"X_QueryTree",
112cdf0e10cSrcweir 	"X_InternAtom",
113cdf0e10cSrcweir 	"X_GetAtomName",
114cdf0e10cSrcweir 	"X_ChangeProperty",
115cdf0e10cSrcweir 	"X_DeleteProperty",
116cdf0e10cSrcweir 	"X_GetProperty",
117cdf0e10cSrcweir 	"X_ListProperties",
118cdf0e10cSrcweir 	"X_SetSelectionOwner",
119cdf0e10cSrcweir 	"X_GetSelectionOwner",
120cdf0e10cSrcweir 	"X_ConvertSelection",
121cdf0e10cSrcweir 	"X_SendEvent",
122cdf0e10cSrcweir 	"X_GrabPointer",
123cdf0e10cSrcweir 	"X_UngrabPointer",
124cdf0e10cSrcweir 	"X_GrabButton",
125cdf0e10cSrcweir 	"X_UngrabButton",
126cdf0e10cSrcweir 	"X_ChangeActivePointerGrab",
127cdf0e10cSrcweir 	"X_GrabKeyboard",
128cdf0e10cSrcweir 	"X_UngrabKeyboard",
129cdf0e10cSrcweir 	"X_GrabKey",
130cdf0e10cSrcweir 	"X_UngrabKey",
131cdf0e10cSrcweir 	"X_AllowEvents",
132cdf0e10cSrcweir 	"X_GrabServer",
133cdf0e10cSrcweir 	"X_UngrabServer",
134cdf0e10cSrcweir 	"X_QueryPointer",
135cdf0e10cSrcweir 	"X_GetMotionEvents",
136cdf0e10cSrcweir 	"X_TranslateCoords",
137cdf0e10cSrcweir 	"X_WarpPointer",
138cdf0e10cSrcweir 	"X_SetInputFocus",
139cdf0e10cSrcweir 	"X_GetInputFocus",
140cdf0e10cSrcweir 	"X_QueryKeymap",
141cdf0e10cSrcweir 	"X_OpenFont",
142cdf0e10cSrcweir 	"X_CloseFont",
143cdf0e10cSrcweir 	"X_QueryFont",
144cdf0e10cSrcweir 	"X_QueryTextExtents",
145cdf0e10cSrcweir 	"X_ListFonts",
146cdf0e10cSrcweir 	"X_ListFontsWithInfo",
147cdf0e10cSrcweir 	"X_SetFontPath",
148cdf0e10cSrcweir 	"X_GetFontPath",
149cdf0e10cSrcweir 	"X_CreatePixmap",
150cdf0e10cSrcweir 	"X_FreePixmap",
151cdf0e10cSrcweir 	"X_CreateGC",
152cdf0e10cSrcweir 	"X_ChangeGC",
153cdf0e10cSrcweir 	"X_CopyGC",
154cdf0e10cSrcweir 	"X_SetDashes",
155cdf0e10cSrcweir 	"X_SetClipRectangles",
156cdf0e10cSrcweir 	"X_FreeGC",
157cdf0e10cSrcweir 	"X_ClearArea",
158cdf0e10cSrcweir 	"X_CopyArea",
159cdf0e10cSrcweir 	"X_CopyPlane",
160cdf0e10cSrcweir 	"X_PolyPoint",
161cdf0e10cSrcweir 	"X_PolyLine",
162cdf0e10cSrcweir 	"X_PolySegment",
163cdf0e10cSrcweir 	"X_PolyRectangle",
164cdf0e10cSrcweir 	"X_PolyArc",
165cdf0e10cSrcweir 	"X_FillPoly",
166cdf0e10cSrcweir 	"X_PolyFillRectangle",
167cdf0e10cSrcweir 	"X_PolyFillArc",
168cdf0e10cSrcweir 	"X_PutImage",
169cdf0e10cSrcweir 	"X_GetImage",
170cdf0e10cSrcweir 	"X_PolyText8",
171cdf0e10cSrcweir 	"X_PolyText16",
172cdf0e10cSrcweir 	"X_ImageText8",
173cdf0e10cSrcweir 	"X_ImageText16",
174cdf0e10cSrcweir 	"X_CreateColormap",
175cdf0e10cSrcweir 	"X_FreeColormap",
176cdf0e10cSrcweir 	"X_CopyColormapAndFree",
177cdf0e10cSrcweir 	"X_InstallColormap",
178cdf0e10cSrcweir 	"X_UninstallColormap",
179cdf0e10cSrcweir 	"X_ListInstalledColormaps",
180cdf0e10cSrcweir 	"X_AllocColor",
181cdf0e10cSrcweir 	"X_AllocNamedColor",
182cdf0e10cSrcweir 	"X_AllocColorCells",
183cdf0e10cSrcweir 	"X_AllocColorPlanes",
184cdf0e10cSrcweir 	"X_FreeColors",
185cdf0e10cSrcweir 	"X_StoreColors",
186cdf0e10cSrcweir 	"X_StoreNamedColor",
187cdf0e10cSrcweir 	"X_QueryColors",
188cdf0e10cSrcweir 	"X_LookupColor",
189cdf0e10cSrcweir 	"X_CreateCursor",
190cdf0e10cSrcweir 	"X_CreateGlyphCursor",
191cdf0e10cSrcweir 	"X_FreeCursor",
192cdf0e10cSrcweir 	"X_RecolorCursor",
193cdf0e10cSrcweir 	"X_QueryBestSize",
194cdf0e10cSrcweir 	"X_QueryExtension",
195cdf0e10cSrcweir 	"X_ListExtensions",
196cdf0e10cSrcweir 	"X_ChangeKeyboardMapping",
197cdf0e10cSrcweir 	"X_GetKeyboardMapping",
198cdf0e10cSrcweir 	"X_ChangeKeyboardControl",
199cdf0e10cSrcweir 	"X_GetKeyboardControl",
200cdf0e10cSrcweir 	"X_Bell",
201cdf0e10cSrcweir 	"X_ChangePointerControl",
202cdf0e10cSrcweir 	"X_GetPointerControl",
203cdf0e10cSrcweir 	"X_SetScreenSaver",
204cdf0e10cSrcweir 	"X_GetScreenSaver",
205cdf0e10cSrcweir 	"X_ChangeHosts",
206cdf0e10cSrcweir 	"X_ListHosts",
207cdf0e10cSrcweir 	"X_SetAccessControl",
208cdf0e10cSrcweir 	"X_SetCloseDownMode",
209cdf0e10cSrcweir 	"X_KillClient",
210cdf0e10cSrcweir 	"X_RotateProperties",
211cdf0e10cSrcweir 	"X_ForceScreenSaver",
212cdf0e10cSrcweir 	"X_SetPointerMapping",
213cdf0e10cSrcweir 	"X_GetPointerMapping",
214cdf0e10cSrcweir 	"X_SetModifierMapping",
215cdf0e10cSrcweir 	"X_GetModifierMapping",
216cdf0e10cSrcweir 	NULL,
217cdf0e10cSrcweir 	NULL,
218cdf0e10cSrcweir 	NULL,
219cdf0e10cSrcweir 	NULL,
220cdf0e10cSrcweir 	NULL,
221cdf0e10cSrcweir 	NULL,
222cdf0e10cSrcweir 	NULL,
223cdf0e10cSrcweir 	"X_NoOperation"
224cdf0e10cSrcweir };
225cdf0e10cSrcweir 
226cdf0e10cSrcweir // -=-= C statics =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
227cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
228cdf0e10cSrcweir 
229cdf0e10cSrcweir int X11SalData::XErrorHdl( Display *pDisplay, XErrorEvent *pEvent )
230cdf0e10cSrcweir {
231cdf0e10cSrcweir 	GetX11SalData()->XError( pDisplay, pEvent );
232cdf0e10cSrcweir 	return 0;
233cdf0e10cSrcweir }
234cdf0e10cSrcweir 
235cdf0e10cSrcweir int X11SalData::XIOErrorHdl( Display * )
236cdf0e10cSrcweir {
237cdf0e10cSrcweir     /*  #106197# hack: until a real shutdown procedure exists
238cdf0e10cSrcweir      *  _exit ASAP
239cdf0e10cSrcweir      */
240cdf0e10cSrcweir     if( ImplGetSVData()->maAppData.mbAppQuit )
241cdf0e10cSrcweir         _exit(1);
242cdf0e10cSrcweir 
243cdf0e10cSrcweir     // really bad hack
244cdf0e10cSrcweir     if( ! SessionManagerClient::checkDocumentsSaved() )
245cdf0e10cSrcweir         /* oslSignalAction eToDo = */ osl_raiseSignal (OSL_SIGNAL_USER_X11SUBSYSTEMERROR, NULL);
246cdf0e10cSrcweir 
247cdf0e10cSrcweir     std::fprintf( stderr, "X IO Error\n" );
248cdf0e10cSrcweir     std::fflush( stdout );
249cdf0e10cSrcweir     std::fflush( stderr );
250cdf0e10cSrcweir 
251cdf0e10cSrcweir     /*  #106197# the same reasons to use _exit instead of exit in salmain
252cdf0e10cSrcweir      *  do apply here. Since there is nothing to be done after an XIO
253cdf0e10cSrcweir      *  error we have to _exit immediately.
254cdf0e10cSrcweir      */
255cdf0e10cSrcweir 	_exit(0);
256cdf0e10cSrcweir 	return 0;
257cdf0e10cSrcweir }
258cdf0e10cSrcweir 
259cdf0e10cSrcweir // -=-= SalData =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
260cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
261cdf0e10cSrcweir #include <pthread.h>
262cdf0e10cSrcweir 
263cdf0e10cSrcweir X11SalData::X11SalData()
264cdf0e10cSrcweir {
265cdf0e10cSrcweir 	bNoExceptions_	= !!getenv( "SAL_NOSEGV" );
266cdf0e10cSrcweir 
267cdf0e10cSrcweir 	pXLib_			= NULL;
268cdf0e10cSrcweir     m_pSalDisplay	= NULL;
269cdf0e10cSrcweir 	m_pInstance		= NULL;
270cdf0e10cSrcweir     m_pPlugin		= NULL;
271cdf0e10cSrcweir 
272cdf0e10cSrcweir 	hMainThread_	= pthread_self();
273cdf0e10cSrcweir     osl_getLocalHostname( &maLocalHostName.pData );
274cdf0e10cSrcweir }
275cdf0e10cSrcweir 
276cdf0e10cSrcweir X11SalData::~X11SalData()
277cdf0e10cSrcweir {
278cdf0e10cSrcweir     DeleteDisplay();
279cdf0e10cSrcweir }
280cdf0e10cSrcweir 
281cdf0e10cSrcweir void X11SalData::DeleteDisplay()
282cdf0e10cSrcweir {
283cdf0e10cSrcweir     delete m_pSalDisplay;
284cdf0e10cSrcweir     m_pSalDisplay	= NULL;
285cdf0e10cSrcweir 	delete pXLib_;
286cdf0e10cSrcweir     pXLib_		= NULL;
287cdf0e10cSrcweir }
288cdf0e10cSrcweir 
289cdf0e10cSrcweir void X11SalData::Init()
290cdf0e10cSrcweir {
291cdf0e10cSrcweir     pXLib_ = new SalXLib();
292cdf0e10cSrcweir     pXLib_->Init();
293cdf0e10cSrcweir }
294cdf0e10cSrcweir 
295cdf0e10cSrcweir void X11SalData::initNWF( void )
296cdf0e10cSrcweir {
297cdf0e10cSrcweir }
298cdf0e10cSrcweir 
299cdf0e10cSrcweir void X11SalData::deInitNWF( void )
300cdf0e10cSrcweir {
301cdf0e10cSrcweir }
302cdf0e10cSrcweir 
303cdf0e10cSrcweir // -=-= SalXLib =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
304cdf0e10cSrcweir // -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
305cdf0e10cSrcweir SalXLib::SalXLib()
306cdf0e10cSrcweir {
307cdf0e10cSrcweir 	m_aTimeout.tv_sec 		= 0;
308cdf0e10cSrcweir 	m_aTimeout.tv_usec		= 0;
309cdf0e10cSrcweir 	m_nTimeoutMS 			= 0;
310cdf0e10cSrcweir 
311cdf0e10cSrcweir 	nFDs_					= 0;
312cdf0e10cSrcweir 	FD_ZERO( &aReadFDS_ );
313cdf0e10cSrcweir 	FD_ZERO( &aExceptionFDS_ );
314cdf0e10cSrcweir 
315cdf0e10cSrcweir 	m_pTimeoutFDS[0] = m_pTimeoutFDS[1] = -1;
316cdf0e10cSrcweir 	if (pipe (m_pTimeoutFDS) != -1)
317cdf0e10cSrcweir 	{
318cdf0e10cSrcweir 		// initialize 'wakeup' pipe.
319cdf0e10cSrcweir 		int flags;
320cdf0e10cSrcweir 
321cdf0e10cSrcweir 		// set close-on-exec descriptor flag.
322cdf0e10cSrcweir 		if ((flags = fcntl (m_pTimeoutFDS[0], F_GETFD)) != -1)
323cdf0e10cSrcweir 		{
324cdf0e10cSrcweir 			flags |= FD_CLOEXEC;
325cdf0e10cSrcweir 			fcntl (m_pTimeoutFDS[0], F_SETFD, flags);
326cdf0e10cSrcweir 		}
327cdf0e10cSrcweir 		if ((flags = fcntl (m_pTimeoutFDS[1], F_GETFD)) != -1)
328cdf0e10cSrcweir 		{
329cdf0e10cSrcweir 			flags |= FD_CLOEXEC;
330cdf0e10cSrcweir 			fcntl (m_pTimeoutFDS[1], F_SETFD, flags);
331cdf0e10cSrcweir 		}
332cdf0e10cSrcweir 
333cdf0e10cSrcweir 		// set non-blocking I/O flag.
334cdf0e10cSrcweir 		if ((flags = fcntl (m_pTimeoutFDS[0], F_GETFL)) != -1)
335cdf0e10cSrcweir 		{
336cdf0e10cSrcweir 			flags |= O_NONBLOCK;
337cdf0e10cSrcweir 			fcntl (m_pTimeoutFDS[0], F_SETFL, flags);
338cdf0e10cSrcweir 		}
339cdf0e10cSrcweir 		if ((flags = fcntl (m_pTimeoutFDS[1], F_GETFL)) != -1)
340cdf0e10cSrcweir 		{
341cdf0e10cSrcweir 			flags |= O_NONBLOCK;
342cdf0e10cSrcweir 			fcntl (m_pTimeoutFDS[1], F_SETFL, flags);
343cdf0e10cSrcweir 		}
344cdf0e10cSrcweir 
345cdf0e10cSrcweir 		// insert [0] into read descriptor set.
346cdf0e10cSrcweir 		FD_SET( m_pTimeoutFDS[0], &aReadFDS_ );
347cdf0e10cSrcweir 		nFDs_ = m_pTimeoutFDS[0] + 1;
348cdf0e10cSrcweir 	}
349cdf0e10cSrcweir 
350cdf0e10cSrcweir     m_bHaveSystemChildFrames		= false;
351cdf0e10cSrcweir     m_aOrigXIOErrorHandler = XSetIOErrorHandler	( (XIOErrorHandler)X11SalData::XIOErrorHdl );
352cdf0e10cSrcweir     PushXErrorLevel( !!getenv( "SAL_IGNOREXERRORS" ) );
353cdf0e10cSrcweir }
354cdf0e10cSrcweir 
355cdf0e10cSrcweir SalXLib::~SalXLib()
356cdf0e10cSrcweir {
357cdf0e10cSrcweir 	// close 'wakeup' pipe.
358cdf0e10cSrcweir 	close (m_pTimeoutFDS[0]);
359cdf0e10cSrcweir 	close (m_pTimeoutFDS[1]);
360cdf0e10cSrcweir 
361cdf0e10cSrcweir     PopXErrorLevel();
362cdf0e10cSrcweir     XSetIOErrorHandler (m_aOrigXIOErrorHandler);
363cdf0e10cSrcweir }
364cdf0e10cSrcweir 
365cdf0e10cSrcweir void SalXLib::PushXErrorLevel( bool bIgnore )
366cdf0e10cSrcweir {
367cdf0e10cSrcweir     m_aXErrorHandlerStack.push_back( XErrorStackEntry() );
368cdf0e10cSrcweir     XErrorStackEntry& rEnt = m_aXErrorHandlerStack.back();
369cdf0e10cSrcweir     rEnt.m_bWas = false;
370cdf0e10cSrcweir     rEnt.m_bIgnore = bIgnore;
371cdf0e10cSrcweir     rEnt.m_nLastErrorRequest = 0;
372cdf0e10cSrcweir     rEnt.m_aHandler = XSetErrorHandler( (XErrorHandler)X11SalData::XErrorHdl );
373cdf0e10cSrcweir }
374cdf0e10cSrcweir 
375cdf0e10cSrcweir void SalXLib::PopXErrorLevel()
376cdf0e10cSrcweir {
377cdf0e10cSrcweir     if( m_aXErrorHandlerStack.size() )
378cdf0e10cSrcweir     {
379cdf0e10cSrcweir         XSetErrorHandler( m_aXErrorHandlerStack.back().m_aHandler );
380cdf0e10cSrcweir         m_aXErrorHandlerStack.pop_back();
381cdf0e10cSrcweir     }
382cdf0e10cSrcweir }
383cdf0e10cSrcweir 
384cdf0e10cSrcweir void SalXLib::Init()
385cdf0e10cSrcweir {
386cdf0e10cSrcweir 	SalI18N_InputMethod* pInputMethod = new SalI18N_InputMethod;
387cdf0e10cSrcweir 	pInputMethod->SetLocale();
388cdf0e10cSrcweir 	XrmInitialize();
389cdf0e10cSrcweir 
390cdf0e10cSrcweir 	/*
391cdf0e10cSrcweir 	 * open connection to X11 Display
392cdf0e10cSrcweir 	 * try in this order:
393cdf0e10cSrcweir 	 *  o  -display command line parameter,
394cdf0e10cSrcweir 	 *  o  $DISPLAY environment variable
395cdf0e10cSrcweir 	 *  o  default display
396cdf0e10cSrcweir 	 */
397cdf0e10cSrcweir 
398cdf0e10cSrcweir 	Display *pDisp = NULL;
399cdf0e10cSrcweir 
400cdf0e10cSrcweir 	// is there a -display command line parameter?
401cdf0e10cSrcweir 	vos::OExtCommandLine aCommandLine;
402cdf0e10cSrcweir 	sal_uInt32 nParams = aCommandLine.getCommandArgCount();
403cdf0e10cSrcweir 	rtl::OUString aParam;
404cdf0e10cSrcweir 	rtl::OString aDisplay;
405cdf0e10cSrcweir 	for (sal_uInt16 i=0; i<nParams; i++)
406cdf0e10cSrcweir 	{
407cdf0e10cSrcweir 		aCommandLine.getCommandArg(i, aParam);
408cdf0e10cSrcweir 		if (aParam.equalsAscii("-display"))
409cdf0e10cSrcweir 		{
410cdf0e10cSrcweir 			aCommandLine.getCommandArg(i+1, aParam);
411cdf0e10cSrcweir 			aDisplay = rtl::OUStringToOString(
412cdf0e10cSrcweir 				   aParam, osl_getThreadTextEncoding());
413cdf0e10cSrcweir 
414cdf0e10cSrcweir 			if ((pDisp = XOpenDisplay(aDisplay.getStr()))!=NULL)
415cdf0e10cSrcweir 			{
416cdf0e10cSrcweir 				/*
417cdf0e10cSrcweir 			 	* if a -display switch was used, we need
418cdf0e10cSrcweir 			 	* to set the environment accoringly since
419cdf0e10cSrcweir 			 	* the clipboard build another connection
420cdf0e10cSrcweir 			 	* to the xserver using $DISPLAY
421cdf0e10cSrcweir 			 	*/
422cdf0e10cSrcweir 				rtl::OUString envVar(RTL_CONSTASCII_USTRINGPARAM("DISPLAY"));
423cdf0e10cSrcweir 				osl_setEnvironment(envVar.pData, aParam.pData);
424cdf0e10cSrcweir 			}
425cdf0e10cSrcweir 			break;
426cdf0e10cSrcweir 		}
427cdf0e10cSrcweir 	}
428cdf0e10cSrcweir 
429cdf0e10cSrcweir 	if (!pDisp && !aDisplay.getLength())
430cdf0e10cSrcweir 	{
431cdf0e10cSrcweir 		// Open $DISPLAY or default...
432cdf0e10cSrcweir 		char *pDisplay = getenv("DISPLAY");
433cdf0e10cSrcweir 		if (pDisplay != NULL)
434cdf0e10cSrcweir 			aDisplay = rtl::OString(pDisplay);
435cdf0e10cSrcweir 		pDisp  = XOpenDisplay(pDisplay);
436cdf0e10cSrcweir 	}
437cdf0e10cSrcweir 
438cdf0e10cSrcweir 	if ( !pDisp )
439cdf0e10cSrcweir 	{
440cdf0e10cSrcweir 	    rtl::OUString aProgramFileURL;
441cdf0e10cSrcweir         osl_getExecutableFile( &aProgramFileURL.pData );
442cdf0e10cSrcweir 	    rtl::OUString aProgramSystemPath;
443cdf0e10cSrcweir         osl_getSystemPathFromFileURL (aProgramFileURL.pData, &aProgramSystemPath.pData);
444cdf0e10cSrcweir         rtl::OString  aProgramName = rtl::OUStringToOString(
445cdf0e10cSrcweir                                             aProgramSystemPath,
446cdf0e10cSrcweir                                             osl_getThreadTextEncoding() );
447cdf0e10cSrcweir         std::fprintf( stderr, "%s X11 error: Can't open display: %s\n",
448cdf0e10cSrcweir 				aProgramName.getStr(), aDisplay.getStr());
449cdf0e10cSrcweir         std::fprintf( stderr, "   Set DISPLAY environment variable, use -display option\n");
450cdf0e10cSrcweir         std::fprintf( stderr, "   or check permissions of your X-Server\n");
451cdf0e10cSrcweir         std::fprintf( stderr, "   (See \"man X\" resp. \"man xhost\" for details)\n");
452cdf0e10cSrcweir         std::fflush( stderr );
453cdf0e10cSrcweir 		exit(0);
454cdf0e10cSrcweir 	}
455cdf0e10cSrcweir 
456cdf0e10cSrcweir 	SalDisplay *pSalDisplay = new SalX11Display( pDisp );
457cdf0e10cSrcweir 
458cdf0e10cSrcweir     pInputMethod->CreateMethod( pDisp );
459cdf0e10cSrcweir 	pInputMethod->AddConnectionWatch( pDisp, (void*)this );
460cdf0e10cSrcweir 	pSalDisplay->SetInputMethod( pInputMethod );
461cdf0e10cSrcweir 
462cdf0e10cSrcweir     PushXErrorLevel( true );
463cdf0e10cSrcweir 	SalI18N_KeyboardExtension *pKbdExtension = new SalI18N_KeyboardExtension( pDisp );
464cdf0e10cSrcweir 	XSync( pDisp, False );
465cdf0e10cSrcweir 
466cdf0e10cSrcweir 	pKbdExtension->UseExtension( ! HasXErrorOccured() );
467cdf0e10cSrcweir     PopXErrorLevel();
468cdf0e10cSrcweir 
469cdf0e10cSrcweir 	pSalDisplay->SetKbdExtension( pKbdExtension );
470cdf0e10cSrcweir }
471cdf0e10cSrcweir 
472cdf0e10cSrcweir extern "C" {
473cdf0e10cSrcweir void EmitFontpathWarning( void )
474cdf0e10cSrcweir {
475cdf0e10cSrcweir 	static Bool bOnce = False;
476cdf0e10cSrcweir 	if ( !bOnce )
477cdf0e10cSrcweir 	{
478cdf0e10cSrcweir 		bOnce = True;
479cdf0e10cSrcweir         std::fprintf( stderr, "Please verify your fontpath settings\n"
480cdf0e10cSrcweir 				"\t(See \"man xset\" for details"
481cdf0e10cSrcweir 				" or ask your system administrator)\n" );
482cdf0e10cSrcweir 	}
483cdf0e10cSrcweir }
484cdf0e10cSrcweir 
485cdf0e10cSrcweir } /* extern "C" */
486cdf0e10cSrcweir 
487cdf0e10cSrcweir static void PrintXError( Display *pDisplay, XErrorEvent *pEvent )
488cdf0e10cSrcweir {
489cdf0e10cSrcweir 	char msg[ 120 ] = "";
490cdf0e10cSrcweir #if ! ( defined LINUX && defined PPC )
491cdf0e10cSrcweir     XGetErrorText( pDisplay, pEvent->error_code, msg, sizeof( msg ) );
492cdf0e10cSrcweir #endif
493cdf0e10cSrcweir     std::fprintf( stderr, "X-Error: %s\n", msg );
494cdf0e10cSrcweir     if( pEvent->request_code < capacityof( XRequest ) )
495cdf0e10cSrcweir     {
496cdf0e10cSrcweir         const char* pName = XRequest[pEvent->request_code];
497cdf0e10cSrcweir         if( !pName )
498cdf0e10cSrcweir             pName = "BadRequest?";
499cdf0e10cSrcweir         std::fprintf( stderr, "\tMajor opcode: %d (%s)\n", pEvent->request_code, pName );
500cdf0e10cSrcweir     }
501cdf0e10cSrcweir     else
502cdf0e10cSrcweir     {
503cdf0e10cSrcweir         std::fprintf( stderr, "\tMajor opcode: %d\n", pEvent->request_code );
504cdf0e10cSrcweir         // TODO: also display extension name?
505cdf0e10cSrcweir         std::fprintf( stderr, "\tMinor opcode: %d\n", pEvent->minor_code );
506cdf0e10cSrcweir     }
507cdf0e10cSrcweir 
508cdf0e10cSrcweir     std::fprintf( stderr, "\tResource ID:  0x%lx\n",
509cdf0e10cSrcweir              pEvent->resourceid );
510cdf0e10cSrcweir     std::fprintf( stderr, "\tSerial No:    %ld (%ld)\n",
511cdf0e10cSrcweir              pEvent->serial, LastKnownRequestProcessed(pDisplay) );
512cdf0e10cSrcweir 
513cdf0e10cSrcweir     if( !getenv( "SAL_SYNCHRONIZE" ) )
514cdf0e10cSrcweir     {
515cdf0e10cSrcweir         std::fprintf( stderr, "These errors are reported asynchronously,\n");
516cdf0e10cSrcweir         std::fprintf( stderr, "set environment variable SAL_SYNCHRONIZE to 1 to help debugging\n");
517cdf0e10cSrcweir     }
518cdf0e10cSrcweir 
519cdf0e10cSrcweir     std::fflush( stdout );
520cdf0e10cSrcweir     std::fflush( stderr );
521cdf0e10cSrcweir }
522cdf0e10cSrcweir 
523cdf0e10cSrcweir void SalXLib::XError( Display *pDisplay, XErrorEvent *pEvent )
524cdf0e10cSrcweir {
525cdf0e10cSrcweir     if( m_bHaveSystemChildFrames )
526cdf0e10cSrcweir         return;
527cdf0e10cSrcweir 
528cdf0e10cSrcweir 	if( ! m_aXErrorHandlerStack.back().m_bIgnore )
529cdf0e10cSrcweir 	{
530cdf0e10cSrcweir 		if (   (pEvent->error_code   == BadAlloc)
531cdf0e10cSrcweir 			&& (pEvent->request_code == X_OpenFont) )
532cdf0e10cSrcweir 		{
533cdf0e10cSrcweir 			static Bool bOnce = False;
534cdf0e10cSrcweir 			if ( !bOnce )
535cdf0e10cSrcweir 			{
536cdf0e10cSrcweir                 std::fprintf(stderr, "X-Error occured in a request for X_OpenFont\n");
537cdf0e10cSrcweir                 EmitFontpathWarning();
538cdf0e10cSrcweir 
539cdf0e10cSrcweir 				bOnce = True ;
540cdf0e10cSrcweir 			}
541cdf0e10cSrcweir             return;
542cdf0e10cSrcweir 		}
543cdf0e10cSrcweir         /* ignore
544cdf0e10cSrcweir         * X_SetInputFocus: it's a hint only anyway
545cdf0e10cSrcweir         * X_GetProperty: this is part of the XGetWindowProperty call and will
546cdf0e10cSrcweir         *                be handled by the return value of that function
547cdf0e10cSrcweir         */
548cdf0e10cSrcweir         else if( pEvent->request_code == X_SetInputFocus ||
549cdf0e10cSrcweir                  pEvent->request_code == X_GetProperty
550cdf0e10cSrcweir             )
551cdf0e10cSrcweir             return;
552cdf0e10cSrcweir 
553cdf0e10cSrcweir 
554cdf0e10cSrcweir         if( pDisplay != GetX11SalData()->GetDisplay()->GetDisplay() )
555cdf0e10cSrcweir             return;
556cdf0e10cSrcweir 
557cdf0e10cSrcweir         PrintXError( pDisplay, pEvent );
558cdf0e10cSrcweir 
559cdf0e10cSrcweir 		oslSignalAction eToDo = osl_raiseSignal (OSL_SIGNAL_USER_X11SUBSYSTEMERROR, NULL);
560cdf0e10cSrcweir 		switch (eToDo)
561cdf0e10cSrcweir 		{
562cdf0e10cSrcweir 			case osl_Signal_ActIgnore		:
563cdf0e10cSrcweir 				return;
564cdf0e10cSrcweir 			case osl_Signal_ActAbortApp 	:
565cdf0e10cSrcweir 				abort();
566cdf0e10cSrcweir 			case osl_Signal_ActKillApp		:
567cdf0e10cSrcweir 				exit(0);
568cdf0e10cSrcweir 			case osl_Signal_ActCallNextHdl	:
569cdf0e10cSrcweir 				break;
570cdf0e10cSrcweir 			default :
571cdf0e10cSrcweir 				break;
572cdf0e10cSrcweir 		}
573cdf0e10cSrcweir 
574cdf0e10cSrcweir 	}
575cdf0e10cSrcweir 
576cdf0e10cSrcweir 	m_aXErrorHandlerStack.back().m_bWas = true;
577cdf0e10cSrcweir }
578cdf0e10cSrcweir 
579cdf0e10cSrcweir struct YieldEntry
580cdf0e10cSrcweir {
581cdf0e10cSrcweir 	YieldEntry* next;		// pointer to next entry
582cdf0e10cSrcweir 	int 		fd; 		// file descriptor for reading
583cdf0e10cSrcweir 	void*			data;		// data for predicate and callback
584cdf0e10cSrcweir 	YieldFunc		pending;	// predicate (determins pending events)
585cdf0e10cSrcweir 	YieldFunc		queued; 	// read and queue up events
586cdf0e10cSrcweir 	YieldFunc		handle; 	// handle pending events
587cdf0e10cSrcweir 
588cdf0e10cSrcweir 	inline int	HasPendingEvent()	const { return pending( fd, data ); }
589cdf0e10cSrcweir 	inline int	IsEventQueued() 	const { return queued( fd, data ); }
590cdf0e10cSrcweir 	inline void HandleNextEvent()	const { handle( fd, data ); }
591cdf0e10cSrcweir };
592cdf0e10cSrcweir 
593cdf0e10cSrcweir #define MAX_NUM_DESCRIPTORS 128
594cdf0e10cSrcweir 
595cdf0e10cSrcweir static YieldEntry yieldTable[ MAX_NUM_DESCRIPTORS ];
596cdf0e10cSrcweir 
597cdf0e10cSrcweir void SalXLib::Insert( int nFD, void* data,
598cdf0e10cSrcweir 					  YieldFunc 	pending,
599cdf0e10cSrcweir 					  YieldFunc 	queued,
600cdf0e10cSrcweir 					  YieldFunc 	handle )
601cdf0e10cSrcweir {
602cdf0e10cSrcweir 	DBG_ASSERT( nFD, "can not insert stdin descriptor" );
603cdf0e10cSrcweir 	DBG_ASSERT( !yieldTable[nFD].fd, "SalXLib::Insert fd twice" );
604cdf0e10cSrcweir 
605cdf0e10cSrcweir 	yieldTable[nFD].fd		= nFD;
606cdf0e10cSrcweir 	yieldTable[nFD].data	= data;
607cdf0e10cSrcweir 	yieldTable[nFD].pending = pending;
608cdf0e10cSrcweir 	yieldTable[nFD].queued	= queued;
609cdf0e10cSrcweir 	yieldTable[nFD].handle	= handle;
610cdf0e10cSrcweir 
611cdf0e10cSrcweir 	FD_SET( nFD, &aReadFDS_ );
612cdf0e10cSrcweir 	FD_SET( nFD, &aExceptionFDS_ );
613cdf0e10cSrcweir 
614cdf0e10cSrcweir 	if( nFD >= nFDs_ )
615cdf0e10cSrcweir 		nFDs_ = nFD + 1;
616cdf0e10cSrcweir }
617cdf0e10cSrcweir 
618cdf0e10cSrcweir void SalXLib::Remove( int nFD )
619cdf0e10cSrcweir {
620cdf0e10cSrcweir 	FD_CLR( nFD, &aReadFDS_ );
621cdf0e10cSrcweir 	FD_CLR( nFD, &aExceptionFDS_ );
622cdf0e10cSrcweir 
623cdf0e10cSrcweir 	yieldTable[nFD].fd = 0;
624cdf0e10cSrcweir 
625cdf0e10cSrcweir 	if ( nFD == nFDs_ )
626cdf0e10cSrcweir 	{
627cdf0e10cSrcweir 		for ( nFD = nFDs_ - 1;
628cdf0e10cSrcweir 			  nFD >= 0 && !yieldTable[nFD].fd;
629cdf0e10cSrcweir 			  nFD-- ) ;
630cdf0e10cSrcweir 
631cdf0e10cSrcweir 		nFDs_ = nFD + 1;
632cdf0e10cSrcweir 	}
633cdf0e10cSrcweir }
634cdf0e10cSrcweir 
635cdf0e10cSrcweir bool SalXLib::CheckTimeout( bool bExecuteTimers )
636cdf0e10cSrcweir {
637cdf0e10cSrcweir     bool bRet = false;
638cdf0e10cSrcweir 	if( m_aTimeout.tv_sec ) // timer is started
639cdf0e10cSrcweir 	{
640cdf0e10cSrcweir 		timeval aTimeOfDay;
641cdf0e10cSrcweir 		gettimeofday( &aTimeOfDay, 0 );
642cdf0e10cSrcweir 		if( aTimeOfDay >= m_aTimeout )
643cdf0e10cSrcweir 		{
644cdf0e10cSrcweir             bRet = true;
645cdf0e10cSrcweir             if( bExecuteTimers )
646cdf0e10cSrcweir             {
647cdf0e10cSrcweir                 // timed out, update timeout
648cdf0e10cSrcweir                 m_aTimeout = aTimeOfDay;
649cdf0e10cSrcweir                 /*
650cdf0e10cSrcweir                 *  #107827# autorestart immediately, will be stopped (or set
651cdf0e10cSrcweir                 *  to different value in notify hdl if necessary;
652cdf0e10cSrcweir                 *  CheckTimeout should return false while
653cdf0e10cSrcweir                 *  timers are being dispatched.
654cdf0e10cSrcweir                 */
655cdf0e10cSrcweir                 m_aTimeout += m_nTimeoutMS;
656cdf0e10cSrcweir                 // notify
657cdf0e10cSrcweir                 GetX11SalData()->Timeout();
658cdf0e10cSrcweir             }
659cdf0e10cSrcweir 		}
660cdf0e10cSrcweir 	}
661cdf0e10cSrcweir     return bRet;
662cdf0e10cSrcweir }
663cdf0e10cSrcweir 
664cdf0e10cSrcweir void SalXLib::Yield( bool bWait, bool bHandleAllCurrentEvents )
665cdf0e10cSrcweir {
666cdf0e10cSrcweir     // check for timeouts here if you want to make screenshots
667cdf0e10cSrcweir     static char* p_prioritize_timer = getenv ("SAL_HIGHPRIORITY_REPAINT");
668cdf0e10cSrcweir     if (p_prioritize_timer != NULL)
669cdf0e10cSrcweir         CheckTimeout();
670cdf0e10cSrcweir 
671cdf0e10cSrcweir     const int nMaxEvents = bHandleAllCurrentEvents ? 100 : 1;
672cdf0e10cSrcweir 
673cdf0e10cSrcweir 	// first, check for already queued events.
674cdf0e10cSrcweir 	for ( int nFD = 0; nFD < nFDs_; nFD++ )
675cdf0e10cSrcweir 	{
676cdf0e10cSrcweir 		YieldEntry* pEntry = &(yieldTable[nFD]);
677cdf0e10cSrcweir 		if ( pEntry->fd )
678cdf0e10cSrcweir 		{
679cdf0e10cSrcweir 			DBG_ASSERT( nFD == pEntry->fd, "wrong fd in Yield()" );
680cdf0e10cSrcweir 			for( int i = 0; i < nMaxEvents && pEntry->HasPendingEvent(); i++ )
681cdf0e10cSrcweir 			{
682cdf0e10cSrcweir 			    pEntry->HandleNextEvent();
683cdf0e10cSrcweir 			    if( ! bHandleAllCurrentEvents )
684cdf0e10cSrcweir 			        return;
685cdf0e10cSrcweir 			}
686cdf0e10cSrcweir 		}
687cdf0e10cSrcweir 	}
688cdf0e10cSrcweir 
689cdf0e10cSrcweir 	// next, select with or without timeout according to bWait.
690cdf0e10cSrcweir 	int      nFDs         = nFDs_;
691cdf0e10cSrcweir 	fd_set   ReadFDS      = aReadFDS_;
692cdf0e10cSrcweir 	fd_set   ExceptionFDS = aExceptionFDS_;
693cdf0e10cSrcweir 	int      nFound       = 0;
694cdf0e10cSrcweir 
695cdf0e10cSrcweir 	timeval  Timeout      = noyield__;
696cdf0e10cSrcweir 	timeval *pTimeout     = &Timeout;
697cdf0e10cSrcweir 
698cdf0e10cSrcweir 	if (bWait)
699cdf0e10cSrcweir 	{
700cdf0e10cSrcweir 		pTimeout = 0;
701cdf0e10cSrcweir 		if (m_aTimeout.tv_sec) // Timer is started.
702cdf0e10cSrcweir 		{
703cdf0e10cSrcweir 			// determine remaining timeout.
704cdf0e10cSrcweir 			gettimeofday (&Timeout, 0);
705cdf0e10cSrcweir 			Timeout = m_aTimeout - Timeout;
706cdf0e10cSrcweir 			if (yield__ >= Timeout)
707cdf0e10cSrcweir 			{
708cdf0e10cSrcweir 				// guard against micro timeout.
709cdf0e10cSrcweir 				Timeout = yield__;
710cdf0e10cSrcweir 			}
711cdf0e10cSrcweir 			pTimeout = &Timeout;
712cdf0e10cSrcweir 		}
713cdf0e10cSrcweir 	}
714cdf0e10cSrcweir 
715cdf0e10cSrcweir 	{
716cdf0e10cSrcweir 		// release YieldMutex (and re-acquire at block end)
717cdf0e10cSrcweir 		YieldMutexReleaser aReleaser;
718cdf0e10cSrcweir 		nFound = select( nFDs, &ReadFDS, NULL, &ExceptionFDS, pTimeout );
719cdf0e10cSrcweir 	}
720cdf0e10cSrcweir 	if( nFound < 0 ) // error
721cdf0e10cSrcweir 	{
722cdf0e10cSrcweir #ifdef DBG_UTIL
723cdf0e10cSrcweir         std::fprintf( stderr, "SalXLib::Yield e=%d f=%d\n", errno, nFound );
724cdf0e10cSrcweir #endif
725cdf0e10cSrcweir 		if( EINTR == errno )
726cdf0e10cSrcweir 		{
727cdf0e10cSrcweir 			errno = 0;
728cdf0e10cSrcweir 		}
729cdf0e10cSrcweir 	}
730cdf0e10cSrcweir 
731cdf0e10cSrcweir     // usually handle timeouts here (as in 5.2)
732cdf0e10cSrcweir     if (p_prioritize_timer == NULL)
733cdf0e10cSrcweir         CheckTimeout();
734cdf0e10cSrcweir 
735cdf0e10cSrcweir 	// handle wakeup events.
736cdf0e10cSrcweir 	if ((nFound > 0) && (FD_ISSET(m_pTimeoutFDS[0], &ReadFDS)))
737cdf0e10cSrcweir 	{
738cdf0e10cSrcweir 		int buffer;
739cdf0e10cSrcweir 		while (read (m_pTimeoutFDS[0], &buffer, sizeof(buffer)) > 0)
740cdf0e10cSrcweir 			continue;
741cdf0e10cSrcweir 		nFound -= 1;
742cdf0e10cSrcweir 	}
743cdf0e10cSrcweir 
744cdf0e10cSrcweir 	// handle other events.
745cdf0e10cSrcweir 	if( nFound > 0 )
746cdf0e10cSrcweir 	{
747cdf0e10cSrcweir 		// now we are in the protected section !
748cdf0e10cSrcweir 		// recall select if we have acquired fd's, ready for reading,
749cdf0e10cSrcweir 
750cdf0e10cSrcweir 		struct timeval noTimeout = { 0, 0 };
751cdf0e10cSrcweir 		nFound = select( nFDs_, &ReadFDS, NULL,
752cdf0e10cSrcweir 						 &ExceptionFDS, &noTimeout );
753cdf0e10cSrcweir 
754cdf0e10cSrcweir 		// someone-else has done the job for us
755cdf0e10cSrcweir 		if (nFound == 0)
756cdf0e10cSrcweir 			return;
757cdf0e10cSrcweir 
758cdf0e10cSrcweir 		for ( int nFD = 0; nFD < nFDs_; nFD++ )
759cdf0e10cSrcweir 		{
760cdf0e10cSrcweir 			YieldEntry* pEntry = &(yieldTable[nFD]);
761cdf0e10cSrcweir 			if ( pEntry->fd )
762cdf0e10cSrcweir 			{
763cdf0e10cSrcweir 				if ( FD_ISSET( nFD, &ExceptionFDS ) ) {
764cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
765cdf0e10cSrcweir                     std::fprintf( stderr, "SalXLib::Yield exception\n" );
766cdf0e10cSrcweir #endif
767cdf0e10cSrcweir 					nFound--;
768cdf0e10cSrcweir 				}
769cdf0e10cSrcweir 				if ( FD_ISSET( nFD, &ReadFDS ) )
770cdf0e10cSrcweir 				{
771cdf0e10cSrcweir 					for( int i = 0; pEntry->IsEventQueued() && i < nMaxEvents; i++ )
772cdf0e10cSrcweir 					{
773cdf0e10cSrcweir 						pEntry->HandleNextEvent();
774cdf0e10cSrcweir 						// if a recursive call has done the job
775cdf0e10cSrcweir 						// so abort here
776cdf0e10cSrcweir 					}
777cdf0e10cSrcweir 					nFound--;
778cdf0e10cSrcweir 				}
779cdf0e10cSrcweir 			}
780cdf0e10cSrcweir 		}
781cdf0e10cSrcweir 	}
782cdf0e10cSrcweir }
783cdf0e10cSrcweir 
784cdf0e10cSrcweir void SalXLib::Wakeup()
785cdf0e10cSrcweir {
786cdf0e10cSrcweir 	write (m_pTimeoutFDS[1], "", 1);
787cdf0e10cSrcweir }
788cdf0e10cSrcweir 
789cdf0e10cSrcweir void SalXLib::PostUserEvent()
790cdf0e10cSrcweir {
791cdf0e10cSrcweir 	Wakeup();
792cdf0e10cSrcweir }
793cdf0e10cSrcweir 
794cdf0e10cSrcweir const char* X11SalData::getFrameResName()
795cdf0e10cSrcweir {
796cdf0e10cSrcweir     /*  according to ICCCM:
797cdf0e10cSrcweir      *  first search command line for -name parameter
798cdf0e10cSrcweir      *  then try RESOURCE_NAME environment variable
799cdf0e10cSrcweir      *  then use argv[0] stripped by directories
800cdf0e10cSrcweir      */
801cdf0e10cSrcweir     static rtl::OStringBuffer aResName;
802cdf0e10cSrcweir     if( !aResName.getLength() )
803cdf0e10cSrcweir     {
804cdf0e10cSrcweir         int nArgs = osl_getCommandArgCount();
805cdf0e10cSrcweir         for( int n = 0; n < nArgs-1; n++ )
806cdf0e10cSrcweir         {
807cdf0e10cSrcweir             rtl::OUString aArg;
808cdf0e10cSrcweir             if( ! osl_getCommandArg( n, &aArg.pData ) &&
809cdf0e10cSrcweir                 aArg.equalsIgnoreAsciiCaseAscii( "-name" ) &&
810cdf0e10cSrcweir                 ! osl_getCommandArg( n+1, &aArg.pData ) )
811cdf0e10cSrcweir             {
812cdf0e10cSrcweir                 aResName.append( rtl::OUStringToOString( aArg, osl_getThreadTextEncoding() ) );
813cdf0e10cSrcweir                 break;
814cdf0e10cSrcweir             }
815cdf0e10cSrcweir         }
816cdf0e10cSrcweir         if( !aResName.getLength() )
817cdf0e10cSrcweir         {
818cdf0e10cSrcweir             const char* pEnv = getenv( "RESOURCE_NAME" );
819cdf0e10cSrcweir             if( pEnv && *pEnv )
820cdf0e10cSrcweir                 aResName.append( pEnv );
821cdf0e10cSrcweir         }
822cdf0e10cSrcweir         if( !aResName.getLength() )
823cdf0e10cSrcweir             aResName.append( "VCLSalFrame" );
824cdf0e10cSrcweir     }
825cdf0e10cSrcweir     return aResName.getStr();
826cdf0e10cSrcweir }
827cdf0e10cSrcweir 
828cdf0e10cSrcweir const char* X11SalData::getFrameClassName()
829cdf0e10cSrcweir {
830cdf0e10cSrcweir     static rtl::OStringBuffer aClassName;
831cdf0e10cSrcweir     if( !aClassName.getLength() )
832cdf0e10cSrcweir     {
833cdf0e10cSrcweir         rtl::OUString aIni, aProduct;
834*910823aeSJürgen Schmidt         rtl::Bootstrap::get( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OOO_BASE_DIR" ) ), aIni );
835cdf0e10cSrcweir         aIni += ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "/program/" SAL_CONFIGFILE( "bootstrap" ) ) );
836cdf0e10cSrcweir         rtl::Bootstrap aBootstrap( aIni );
837cdf0e10cSrcweir         aBootstrap.getFrom( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ProductKey" ) ), aProduct );
838cdf0e10cSrcweir 
839cdf0e10cSrcweir         if( aProduct.getLength() )
840cdf0e10cSrcweir             aClassName.append( rtl::OUStringToOString( aProduct, osl_getThreadTextEncoding() ) );
841cdf0e10cSrcweir         else
842cdf0e10cSrcweir             aClassName.append( "VCLSalFrame" );
843cdf0e10cSrcweir     }
844cdf0e10cSrcweir     return aClassName.getStr();
845cdf0e10cSrcweir }
846cdf0e10cSrcweir 
847cdf0e10cSrcweir rtl::OString X11SalData::getFrameResName( SalExtStyle nStyle )
848cdf0e10cSrcweir {
849cdf0e10cSrcweir     rtl::OStringBuffer aBuf( 64 );
850cdf0e10cSrcweir     aBuf.append( getFrameResName() );
851cdf0e10cSrcweir     if( (nStyle & SAL_FRAME_EXT_STYLE_DOCUMENT) )
852cdf0e10cSrcweir         aBuf.append( ".DocumentWindow" );
853cdf0e10cSrcweir 
854cdf0e10cSrcweir     return aBuf.makeStringAndClear();
855cdf0e10cSrcweir }
856