1/*	$NetBSD: m_cde.c,v 1.1.1.2 2008/05/18 14:31:25 aymeric Exp $ */
2
3/*-
4 * Copyright (c) 1996
5 *	Rob Zimmermann.  All rights reserved.
6 * Copyright (c) 1996
7 *	Keith Bostic.  All rights reserved.
8 *
9 * See the LICENSE file for redistribution information.
10 */
11
12#include "config.h"
13
14#ifndef lint
15static 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
18#include <sys/types.h>
19#include <sys/queue.h>
20
21#include <X11/X.h>
22#include <X11/Xlib.h>
23#include <X11/Xatom.h>
24
25#include <bitstring.h>
26#include <stdio.h>
27
28#undef LOCK_SUCCESS
29#include "../common/common.h"
30#include "extern.h"
31
32#if SelfTest
33#define	_TRACE( x )	printf x
34#else
35#define	_TRACE( x )
36#endif
37
38#define	Required	10
39#define	Useful		3
40#define	Present		(Required+Useful)
41
42static 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" */	},
50};
51
52/*
53 * is_cde --
54 *
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.
58 *
59 * PUBLIC: int is_cde __P((Display *));
60 */
61int
62is_cde(Display *d)
63{
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;
70
71    _TRACE( ( "Root window is 0x%x\n", root ) );
72
73    /* create our atoms */
74    for (i=0; i< (sizeof(Atoms)/sizeof(Atoms[0])); i++ ) {
75
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;
80	}
81
82	/* what is the value of the atom? */
83	r = XGetWindowProperty( d,
84				root,
85				atom,
86				0,
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 */
95				);
96	if ( r != Success ) {
97	    _TRACE( ( "Atom \"%s\" cannot be converted to string\n", Atoms[i].name ) );
98	    continue;
99	}
100
101	retval += Atoms[i].value;
102
103
104#if SelfTest
105	_TRACE( ( "Atom \"%s\"\n", Atoms[i].name ) );
106
107	switch ( type ) {
108	    case 0:
109		_TRACE( ( "\t does not exist on the root window\n", Atoms[i].name ) );
110
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 );
116		}
117		break;
118
119	    case XA_STRING:
120		_TRACE( ( "\t is a string\n", Atoms[i].name ) );
121		break;
122
123	    default:
124		_TRACE( ( "\tunknown type %s\n", XGetAtomName( d, type ) ) );
125		break;
126	}
127#endif
128
129	/* done */
130	XFree( (caddr_t) prop );
131
132    }
133
134    _TRACE( ( "retval = %d\n", retval ) );
135    return retval >= Present;
136}
137
138#if SelfTest
139
140main () {
141    Display *d = XOpenDisplay( 0 );
142
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 );
148    }
149}
150#endif
151