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