Sync usage with man page.
[netbsd-mini2440.git] / dist / nvi / motif / m_cde.c
blob5e64cc7afe8523951561b585b46fcfd90500f9f2
1 /* $NetBSD$ */
3 /*-
4 * Copyright (c) 1996
5 * Rob Zimmermann. All rights reserved.
6 * Copyright (c) 1996
7 * Keith Bostic. All rights reserved.
9 * See the LICENSE file for redistribution information.
12 #include "config.h"
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 */
18 #include <sys/types.h>
19 #include <sys/queue.h>
21 #include <X11/X.h>
22 #include <X11/Xlib.h>
23 #include <X11/Xatom.h>
25 #include <bitstring.h>
26 #include <stdio.h>
28 #undef LOCK_SUCCESS
29 #include "../common/common.h"
30 #include "extern.h"
32 #if SelfTest
33 #define _TRACE( x ) printf x
34 #else
35 #define _TRACE( x )
36 #endif
38 #define Required 10
39 #define Useful 3
40 #define Present (Required+Useful)
42 static struct {
43 char *name;
44 int value;
45 } Atoms[] = {
46 { "_VUE_SM_WINDOW_INFO", Required, /* "vue" */ },
47 { "_DT_SM_WINDOW_INFO", Required, /* "dtwm" */ },
48 { "_SUN_WM_PROTOCOLS", Useful, /* "olwm" */ },
49 { "_MOTIF_WM_INFO", Useful, /* "mwm/dtwm" */ },
53 * is_cde --
55 * When running under CDE (or VUE on HPUX) applications should not define
56 * fallback colors (or fonts). The only way to tell is to check the atoms
57 * attached to the server. This routine does that.
59 * PUBLIC: int is_cde __P((Display *));
61 int
62 is_cde(Display *d)
64 int i, r, format;
65 unsigned long nitems, remaining;
66 unsigned char *prop;
67 Window root = DefaultRootWindow( d );
68 Atom atom, type;
69 int retval = 0;
71 _TRACE( ( "Root window is 0x%x\n", root ) );
73 /* create our atoms */
74 for (i=0; i< (sizeof(Atoms)/sizeof(Atoms[0])); i++ ) {
76 atom = XInternAtom( d, Atoms[i].name, True );
77 if ( atom == None ) {
78 _TRACE( ( "Atom \"%s\" does not exist\n", Atoms[i].name ) );
79 continue;
82 /* what is the value of the atom? */
83 r = XGetWindowProperty( d,
84 root,
85 atom,
87 1024,
88 False, /* do not delete */
89 AnyPropertyType, /* request type */
90 &type, /* actual type */
91 &format, /* byte size */
92 &nitems, /* number of items */
93 &remaining, /* anything left over? */
94 &prop /* the data itself */
96 if ( r != Success ) {
97 _TRACE( ( "Atom \"%s\" cannot be converted to string\n", Atoms[i].name ) );
98 continue;
101 retval += Atoms[i].value;
104 #if SelfTest
105 _TRACE( ( "Atom \"%s\"\n", Atoms[i].name ) );
107 switch ( type ) {
108 case 0:
109 _TRACE( ( "\t does not exist on the root window\n", Atoms[i].name ) );
111 case XA_ATOM:
112 for (j=0; j<nitems; j++) {
113 name = XGetAtomName( d, ((Atom *) prop)[j] );
114 _TRACE( ( "\t[%d] = \"%s\"\n", j, name ) );
115 XFree( name );
117 break;
119 case XA_STRING:
120 _TRACE( ( "\t is a string\n", Atoms[i].name ) );
121 break;
123 default:
124 _TRACE( ( "\tunknown type %s\n", XGetAtomName( d, type ) ) );
125 break;
127 #endif
129 /* done */
130 XFree( (caddr_t) prop );
134 _TRACE( ( "retval = %d\n", retval ) );
135 return retval >= Present;
138 #if SelfTest
140 main () {
141 Display *d = XOpenDisplay( 0 );
143 if ( d == 0 )
144 printf ( "Could not open display\n" );
145 else {
146 printf ( "_vi_is_cde() == %d\n", _vi_is_cde( d ) );
147 XCloseDisplay( d );
150 #endif