2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 //%% (c) Copyright 1993, 1994 Hewlett-Packard Company
24 //%% (c) Copyright 1993, 1994 International Business Machines Corp.
25 //%% (c) Copyright 1993, 1994 Sun Microsystems, Inc.
26 //%% (c) Copyright 1993, 1994 Novell, Inc.
27 //%% $XConsortium: tt_Xlib.C /main/3 1995/10/23 10:36:22 rswiston $
29 * @(#)tt_Xlib.C 1.3 93/09/07
31 * Copyright 1993 Sun Microsystems, Inc. All rights reserved.
34 #include "util/tt_Xlib.h"
35 #if defined(OPT_DLOPEN_X11)
38 #include "util/tt_string.h"
39 #include "util/tt_port.h"
44 /**************************************************************************
45 * This section contains functions for dynamically loading in the
46 * necessary X11 functions. This avoids the need for applications to link
47 * in libX11. Note that all of this section is ifdefd with OPT_DLOPEN_X11 so
48 * only functions relevant to dynamic loading of X11 should be included.
49 **************************************************************************/
54 // Dlopens the X11 library and attempts to dlsym the needed functions
60 static int loaded = 0;
66 int load_xlib_fns_from_handle(void *xlib_handle);
67 int full_ldpath(_Tt_string libname, _Tt_string &path);
69 // open libX11.so and fill in _tt_xlib with pointers to
74 // first try opening the current executable to see if the
75 // functions have already been defined
76 xlib_handle = dlopen((char *)0, 1);
77 if (load_xlib_fns_from_handle(xlib_handle)) {
82 #if defined(OPT_BUG_SUNOS_4)
83 // While it's not strictly a bug that SunOS 4 doesn't do path
84 // searching right, it's certainly a pain special to 4.x.
85 // have to dlopen libX11.so from somewhere
86 if (! tt_ldpath("libX11.so", xlib_path)) {
90 // SVR4 version of dlopen does the path searching for us
92 xlib_path = "libX11.so";
95 xlib_handle = dlopen((char *)xlib_path, 1);
97 if (xlib_handle == (void *)0) {
98 _tt_syslog( 0, LOG_ERR, "dlopen( \"%s\", 1 ): %s",
99 xlib_path.operator const char *(),
104 loaded = load_xlib_fns_from_handle(xlib_handle);
106 _tt_syslog( 0, LOG_ERR, "dlsym(): %s", dlerror() );
114 static int loaded = 0;
120 int load_xt_fns_from_handle(void *xlib_handle);
121 int full_ldpath(_Tt_string libname, _Tt_string &path);
123 // open libXt.so and fill in _tt_xt with pointers to
128 // first try opening the current executable to see if the
129 // functions have already been defined
130 xt_handle = dlopen((char *)0, 1);
131 if (load_xt_fns_from_handle(xt_handle)) {
136 #if defined(OPT_BUG_SUNOS_4)
137 // While it's not strictly a bug that SunOS 4 doesn't do path
138 // searching right, it's certainly a pain special to 4.x.
139 // have to dlopen libXt.so from somewhere
140 if (! tt_ldpath("libXt.so", xt_path)) {
144 // SVR4 version of dlopen does the path searching for us
146 xt_path = "libXt.so";
149 xt_handle = dlopen((char *)xt_path, 1);
151 if (xt_handle == (void *)0) {
152 _tt_syslog( 0, LOG_ERR, "dlopen( \"%s\", 1 ): %s",
153 xt_path.operator const char *(),
158 loaded = load_xt_fns_from_handle(xt_handle);
160 _tt_syslog( 0, LOG_ERR, "dlsym(): %s", dlerror() );
167 // Dlsym the needed functions from the handle. This is done by way of a
168 // macro which will just return 0 if it fails. Note that if a new
169 // function is needed then it should be added to the _tt_xlib struct and
170 // also added below as well.
173 load_xlib_fns_from_handle(void *xlib_handle)
175 #if defined(__STDC__)
176 #define DLINK_FN(fn)\
177 _tt_xlib . fn = (_Tt_xfn_ptr)dlsym(xlib_handle, #fn); \
178 if ( _tt_xlib . fn == (_Tt_xfn_ptr)0) { \
182 #define DLINK_FN(fn)\
183 _tt_xlib . fn = (_Tt_xfn_ptr)dlsym(xlib_handle, "fn"); \
184 if ( _tt_xlib . fn == (_Tt_xfn_ptr)0) { \
187 #endif /* __STDC__ */
189 DLINK_FN(XOpenDisplay)
190 DLINK_FN(XCloseDisplay)
192 DLINK_FN(XChangeProperty)
193 DLINK_FN(XDeleteProperty)
194 DLINK_FN(XGetWindowProperty)
195 DLINK_FN(XSetIOErrorHandler)
196 DLINK_FN(XInternAtom)
198 DLINK_FN(XRefreshKeyboardMapping)
199 DLINK_FN(XGrabServer)
200 DLINK_FN(XUngrabServer)
201 DLINK_FN(XGetWindowAttributes)
202 DLINK_FN(XTranslateCoordinates)
203 DLINK_FN(XMoveResizeWindow)
204 DLINK_FN(XRaiseWindow)
205 DLINK_FN(XLowerWindow)
206 DLINK_FN(XIconifyWindow)
208 DLINK_FN(XWithdrawWindow)
210 DLINK_FN(XScreenNumberOfScreen)
218 // Dlsym the needed functions from the handle. This is done by way of a
219 // macro which will just return 0 if it fails. Note that if a new
220 // function is needed then it should be added to the _tt_xt struct and
221 // also added below as well.
224 load_xt_fns_from_handle(void *xt_handle)
226 #if defined(__STDC__)
227 #define DLINK_FN(fn)\
228 _tt_xt . fn = (_Tt_xfn_ptr)dlsym(xt_handle, #fn); \
229 if ( _tt_xt . fn == (_Tt_xfn_ptr)0) { \
233 #define DLINK_FN(fn)\
234 _tt_xt . fn = (_Tt_xfn_ptr)dlsym(xt_handle, "fn"); \
235 if ( _tt_xt . fn == (_Tt_xfn_ptr)0) { \
238 #endif /* __STDC__ */
240 DLINK_FN(XtVaGetValues)
241 DLINK_FN(XtVaSetValues)
242 DLINK_FN(XtRemoveInput)
245 DLINK_FN(XtIsRealized)
246 DLINK_FN(XtIsSubclass)
247 DLINK_FN(XtIsSensitive)
248 DLINK_FN(XtSetSensitive)
249 DLINK_FN(XtAppPending)
250 DLINK_FN(XtAppAddTimeOut)
251 DLINK_FN(XtRemoveTimeOut)
252 DLINK_FN(XtAppProcessEvent)
253 DLINK_FN(applicationShellWidgetClass)
257 #else // OPT_DLOPEN_X11
259 * Instead of putting ifdefs around every call to _tt_load_xlib and
260 * _tt_load_xt, we simply provide null versions that always return success
261 * if OPT_DLOPEN_X11 is turned off.
276 #endif // OPT_DLOPEN_X11