BRL-CAD
query.c
Go to the documentation of this file.
1 /* Q U E R Y . C
2  * BRL-CAD
3  *
4  * Copyright (c) 2004-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 /** @file libdm/query.c
21  *
22  */
23 
24 #include "common.h"
25 
26 #include <string.h>
27 
28 #ifdef HAVE_X11_XLIB_H
29 # include <X11/Xlib.h>
30 #endif
31 
32 #include "tcl.h"
33 
34 #include "vmath.h"
35 #include "dm.h"
36 
37 int dm_validXType(char *dpy_string, char *name);
38 char *dm_bestXType(char *dpy_string);
39 
40 int
41 #if !defined(DM_WGL) && !defined(DM_RTGL) && !defined(DM_OGL) && !defined(DM_X) && !defined(DM_TK)
42 dm_validXType(char *UNUSED(dpy_string), char *name)
43 #else
44 dm_validXType(char *dpy_string, char *name)
45 #endif
46 {
47  if (BU_STR_EQUAL(name, "wgl")) {
48 #ifdef DM_WGL
49  return 1;
50 #else
51  bu_log("Specified display type [%s] is not available in this compilation.", name);
52  return 0;
53 #endif /* DM_WGL */
54  }
55 
56  if (BU_STR_EQUAL(name, "rtgl")) {
57 #ifdef DM_RTGL
58  Display *dpy;
59  int return_val;
60  if ((dpy = XOpenDisplay(dpy_string)) != NULL) {
61  if (XQueryExtension(dpy, "GLX", &return_val, &return_val, &return_val)) {
62  XCloseDisplay(dpy);
63  return 1;
64  }
65  XCloseDisplay(dpy);
66  }
67 #else
68  bu_log("Specified display type [%s] is not available in this compilation.", name);
69 #endif /* DM_RTGL */
70  return 0;
71  }
72 
73  if (BU_STR_EQUAL(name, "ogl")) {
74 #ifdef DM_OGL
75  Display *dpy;
76  int return_val;
77  if ((dpy = XOpenDisplay(dpy_string)) != NULL) {
78  if (XQueryExtension(dpy, "GLX", &return_val, &return_val, &return_val)) {
79  XCloseDisplay(dpy);
80  return 1;
81  }
82  XCloseDisplay(dpy);
83  }
84 #else
85  bu_log("Specified display type [%s] is not available in this compilation.", name);
86 #endif /* DM_OGL */
87  return 0;
88  }
89 
90  if (BU_STR_EQUAL(name, "X")) {
91 #ifdef DM_X
92  Display *dpy;
93  if ((dpy = XOpenDisplay(dpy_string)) != NULL) {
94  XCloseDisplay(dpy);
95  return 1;
96  }
97 #else
98  bu_log("Specified display type [%s] is not available in this compilation.", name);
99 #endif /* DM_X */
100  return 0;
101  }
102 
103  if (BU_STR_EQUAL(name, "tk")) {
104 #ifdef DM_TK
105  return 1;
106 #else
107  bu_log("Specified display type [%s] is not available in this compilation.", name);
108 #endif /* DM_TK */
109  return 0;
110  }
111 
112  return 0;
113 }
114 
115 /** dm_bestXType determines what mged will normally
116  * use as the default display manager
117  */
118 
119 char *
120 #if !defined(DM_WGL) && !defined(DM_RTGL) && !defined(DM_OGL) && !defined(DM_OSGL) && !defined(DM_X) && !defined(DM_TK)
121 dm_bestXType(char *UNUSED(dpy_string))
122 #else
123 dm_bestXType(char *dpy_string)
124 #endif
125 {
126 
127 #ifdef DM_OSGL
128  return "osgl";
129 #endif
130 
131 #ifdef DM_WGL
132  /* should probably make sure wgl works */
133  return "wgl";
134 #endif
135 
136 #ifdef DM_RTGL
137  {
138  Display *dpy;
139  int return_val;
140 
141  if ((dpy = XOpenDisplay(dpy_string)) != NULL) {
142  if (XQueryExtension(dpy, "GLX", &return_val, &return_val, &return_val)) {
143  XCloseDisplay(dpy);
144  return "rtgl";
145  }
146  XCloseDisplay(dpy);
147  }
148  }
149 #endif
150 
151 #ifdef DM_OGL
152  {
153  Display *dpy;
154  int return_val;
155 
156  if ((dpy = XOpenDisplay(dpy_string)) != NULL) {
157  if (XQueryExtension(dpy, "GLX", &return_val, &return_val, &return_val)) {
158  XCloseDisplay(dpy);
159  return "ogl";
160  }
161  XCloseDisplay(dpy);
162  }
163  }
164 #endif
165 
166 #ifdef DM_X
167  {
168  Display *dpy;
169  if ((dpy = XOpenDisplay(dpy_string)) != NULL) {
170  XCloseDisplay(dpy);
171  return "X";
172  }
173  }
174 #endif
175 
176 #ifdef DM_TK
177  return "tk";
178 #else
179  return "nu";
180 #endif
181 }
182 
183 /*
184  * Local Variables:
185  * mode: C
186  * tab-width: 8
187  * indent-tabs-mode: t
188  * c-file-style: "stroustrup"
189  * End:
190  * ex: shiftwidth=4 tabstop=8
191  */
char * dm_bestXType(char *dpy_string)
Definition: query.c:121
void bu_log(const char *,...) _BU_ATTR_PRINTF12
Definition: log.c:176
int dm_validXType(char *dpy_string, char *name)
Definition: query.c:42
Definition: clone.c:90
long Display
Definition: dm_xvars.h:49
Header file for the BRL-CAD common definitions.
#define UNUSED(parameter)
Definition: common.h:239
#define BU_STR_EQUAL(s1, s2)
Definition: str.h:126