xref: /netbsd-src/external/bsd/nvi/dist/motif/m_cde.c (revision 8585484ef87f5a04d32332313cdb799625f4faf8)
1 /*-
2  * Copyright (c) 1996
3  *	Rob Zimmermann.  All rights reserved.
4  * Copyright (c) 1996
5  *	Keith Bostic.  All rights reserved.
6  *
7  * See the LICENSE file for redistribution information.
8  */
9 
10 #include "config.h"
11 
12 #ifndef lint
13 static const char sccsid[] = "Id: m_cde.c,v 8.11 2003/11/05 17:09:58 skimo Exp  (Berkeley) Date: 2003/11/05 17:09:58 ";
14 #endif /* not lint */
15 
16 #include <sys/types.h>
17 #include <sys/queue.h>
18 
19 #include <X11/X.h>
20 #include <X11/Xlib.h>
21 #include <X11/Xatom.h>
22 
23 #include <bitstring.h>
24 #include <stdio.h>
25 
26 #undef LOCK_SUCCESS
27 #include "../common/common.h"
28 #include "motif_extern.h"
29 
30 #if SelfTest
31 #define	_TRACE( x )	printf x
32 #else
33 #define	_TRACE( x )
34 #endif
35 
36 #define	Required	10
37 #define	Useful		3
38 #define	Present		(Required+Useful)
39 
40 static struct {
41     char	*name;
42     int		value;
43 } Atoms[] = {
44     { "_VUE_SM_WINDOW_INFO",	Required,	/* "vue" */		},
45     { "_DT_SM_WINDOW_INFO",	Required,	/* "dtwm" */		},
46     { "_SUN_WM_PROTOCOLS",	Useful,		/* "olwm" */		},
47     { "_MOTIF_WM_INFO",		Useful,		/* "mwm/dtwm" */	},
48 };
49 
50 /*
51  * is_cde --
52  *
53  * When running under CDE (or VUE on HPUX) applications should not define
54  * fallback colors (or fonts).  The only way to tell is to check the atoms
55  * attached to the server.  This routine does that.
56  *
57  * PUBLIC: int is_cde __P((Display *));
58  */
59 int
60 is_cde(Display *d)
61 {
62     int			i, r, format;
63     unsigned long	nitems, remaining;
64     unsigned char	*prop;
65     Window		root = DefaultRootWindow( d );
66     Atom		atom, type;
67     int			retval = 0;
68 
69     _TRACE( ( "Root window is 0x%x\n", root ) );
70 
71     /* create our atoms */
72     for (i=0; i< (sizeof(Atoms)/sizeof(Atoms[0])); i++ ) {
73 
74 	atom = XInternAtom( d, Atoms[i].name, True );
75 	if ( atom == None ) {
76 	    _TRACE( ( "Atom \"%s\" does not exist\n", Atoms[i].name ) );
77 	    continue;
78 	}
79 
80 	/* what is the value of the atom? */
81 	r = XGetWindowProperty( d,
82 				root,
83 				atom,
84 				0,
85 				1024,
86 				False,			/* do not delete */
87 				AnyPropertyType,	/* request type */
88 				&type,			/* actual type */
89 				&format,		/* byte size */
90 				&nitems,		/* number of items */
91 				&remaining,		/* anything left over? */
92 				&prop			/* the data itself */
93 				);
94 	if ( r != Success ) {
95 	    _TRACE( ( "Atom \"%s\" cannot be converted to string\n", Atoms[i].name ) );
96 	    continue;
97 	}
98 
99 	retval += Atoms[i].value;
100 
101 
102 #if SelfTest
103 	_TRACE( ( "Atom \"%s\"\n", Atoms[i].name ) );
104 
105 	switch ( type ) {
106 	    case 0:
107 		_TRACE( ( "\t does not exist on the root window\n", Atoms[i].name ) );
108 
109 	    case XA_ATOM:
110 		for (j=0; j<nitems; j++) {
111 		    name = XGetAtomName( d, ((Atom *) prop)[j] );
112 		    _TRACE( ( "\t[%d] = \"%s\"\n", j, name ) );
113 		    XFree( name );
114 		}
115 		break;
116 
117 	    case XA_STRING:
118 		_TRACE( ( "\t is a string\n", Atoms[i].name ) );
119 		break;
120 
121 	    default:
122 		_TRACE( ( "\tunknown type %s\n", XGetAtomName( d, type ) ) );
123 		break;
124 	}
125 #endif
126 
127 	/* done */
128 	XFree( (caddr_t) prop );
129 
130     }
131 
132     _TRACE( ( "retval = %d\n", retval ) );
133     return retval >= Present;
134 }
135 
136 #if SelfTest
137 
138 main () {
139     Display *d = XOpenDisplay( 0 );
140 
141     if ( d == 0 )
142 	printf ( "Could not open display\n" );
143     else {
144 	printf ( "_vi_is_cde() == %d\n", _vi_is_cde( d ) );
145 	XCloseDisplay( d );
146     }
147 }
148 #endif
149