184d9c625SLionel Sambuc /*-
284d9c625SLionel Sambuc * Copyright (c) 1996
384d9c625SLionel Sambuc * Rob Zimmermann. All rights reserved.
484d9c625SLionel Sambuc * Copyright (c) 1996
584d9c625SLionel Sambuc * Keith Bostic. All rights reserved.
684d9c625SLionel Sambuc *
784d9c625SLionel Sambuc * See the LICENSE file for redistribution information.
884d9c625SLionel Sambuc */
984d9c625SLionel Sambuc
1084d9c625SLionel Sambuc #include "config.h"
1184d9c625SLionel Sambuc
12*0a6a1f1dSLionel Sambuc #include <sys/cdefs.h>
13*0a6a1f1dSLionel Sambuc #if 0
1484d9c625SLionel Sambuc #ifndef lint
1584d9c625SLionel Sambuc 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 ";
1684d9c625SLionel Sambuc #endif /* not lint */
17*0a6a1f1dSLionel Sambuc #else
18*0a6a1f1dSLionel Sambuc __RCSID("$NetBSD: m_cde.c,v 1.3 2014/01/26 21:43:45 christos Exp $");
19*0a6a1f1dSLionel Sambuc #endif
2084d9c625SLionel Sambuc
2184d9c625SLionel Sambuc #include <sys/types.h>
2284d9c625SLionel Sambuc #include <sys/queue.h>
2384d9c625SLionel Sambuc
2484d9c625SLionel Sambuc #include <X11/X.h>
2584d9c625SLionel Sambuc #include <X11/Xlib.h>
2684d9c625SLionel Sambuc #include <X11/Xatom.h>
2784d9c625SLionel Sambuc
2884d9c625SLionel Sambuc #include <bitstring.h>
2984d9c625SLionel Sambuc #include <stdio.h>
3084d9c625SLionel Sambuc
3184d9c625SLionel Sambuc #undef LOCK_SUCCESS
3284d9c625SLionel Sambuc #include "../common/common.h"
3384d9c625SLionel Sambuc #include "motif_extern.h"
3484d9c625SLionel Sambuc
3584d9c625SLionel Sambuc #if SelfTest
3684d9c625SLionel Sambuc #define _TRACE( x ) printf x
3784d9c625SLionel Sambuc #else
3884d9c625SLionel Sambuc #define _TRACE( x )
3984d9c625SLionel Sambuc #endif
4084d9c625SLionel Sambuc
4184d9c625SLionel Sambuc #define Required 10
4284d9c625SLionel Sambuc #define Useful 3
4384d9c625SLionel Sambuc #define Present (Required+Useful)
4484d9c625SLionel Sambuc
4584d9c625SLionel Sambuc static struct {
4684d9c625SLionel Sambuc char *name;
4784d9c625SLionel Sambuc int value;
4884d9c625SLionel Sambuc } Atoms[] = {
4984d9c625SLionel Sambuc { "_VUE_SM_WINDOW_INFO", Required, /* "vue" */ },
5084d9c625SLionel Sambuc { "_DT_SM_WINDOW_INFO", Required, /* "dtwm" */ },
5184d9c625SLionel Sambuc { "_SUN_WM_PROTOCOLS", Useful, /* "olwm" */ },
5284d9c625SLionel Sambuc { "_MOTIF_WM_INFO", Useful, /* "mwm/dtwm" */ },
5384d9c625SLionel Sambuc };
5484d9c625SLionel Sambuc
5584d9c625SLionel Sambuc /*
5684d9c625SLionel Sambuc * is_cde --
5784d9c625SLionel Sambuc *
5884d9c625SLionel Sambuc * When running under CDE (or VUE on HPUX) applications should not define
5984d9c625SLionel Sambuc * fallback colors (or fonts). The only way to tell is to check the atoms
6084d9c625SLionel Sambuc * attached to the server. This routine does that.
6184d9c625SLionel Sambuc *
6284d9c625SLionel Sambuc * PUBLIC: int is_cde __P((Display *));
6384d9c625SLionel Sambuc */
6484d9c625SLionel Sambuc int
is_cde(Display * d)6584d9c625SLionel Sambuc is_cde(Display *d)
6684d9c625SLionel Sambuc {
6784d9c625SLionel Sambuc int i, r, format;
6884d9c625SLionel Sambuc unsigned long nitems, remaining;
6984d9c625SLionel Sambuc unsigned char *prop;
7084d9c625SLionel Sambuc Window root = DefaultRootWindow( d );
7184d9c625SLionel Sambuc Atom atom, type;
7284d9c625SLionel Sambuc int retval = 0;
7384d9c625SLionel Sambuc
7484d9c625SLionel Sambuc _TRACE( ( "Root window is 0x%x\n", root ) );
7584d9c625SLionel Sambuc
7684d9c625SLionel Sambuc /* create our atoms */
7784d9c625SLionel Sambuc for (i=0; i< (sizeof(Atoms)/sizeof(Atoms[0])); i++ ) {
7884d9c625SLionel Sambuc
7984d9c625SLionel Sambuc atom = XInternAtom( d, Atoms[i].name, True );
8084d9c625SLionel Sambuc if ( atom == None ) {
8184d9c625SLionel Sambuc _TRACE( ( "Atom \"%s\" does not exist\n", Atoms[i].name ) );
8284d9c625SLionel Sambuc continue;
8384d9c625SLionel Sambuc }
8484d9c625SLionel Sambuc
8584d9c625SLionel Sambuc /* what is the value of the atom? */
8684d9c625SLionel Sambuc r = XGetWindowProperty( d,
8784d9c625SLionel Sambuc root,
8884d9c625SLionel Sambuc atom,
8984d9c625SLionel Sambuc 0,
9084d9c625SLionel Sambuc 1024,
9184d9c625SLionel Sambuc False, /* do not delete */
9284d9c625SLionel Sambuc AnyPropertyType, /* request type */
9384d9c625SLionel Sambuc &type, /* actual type */
9484d9c625SLionel Sambuc &format, /* byte size */
9584d9c625SLionel Sambuc &nitems, /* number of items */
9684d9c625SLionel Sambuc &remaining, /* anything left over? */
9784d9c625SLionel Sambuc &prop /* the data itself */
9884d9c625SLionel Sambuc );
9984d9c625SLionel Sambuc if ( r != Success ) {
10084d9c625SLionel Sambuc _TRACE( ( "Atom \"%s\" cannot be converted to string\n", Atoms[i].name ) );
10184d9c625SLionel Sambuc continue;
10284d9c625SLionel Sambuc }
10384d9c625SLionel Sambuc
10484d9c625SLionel Sambuc retval += Atoms[i].value;
10584d9c625SLionel Sambuc
10684d9c625SLionel Sambuc
10784d9c625SLionel Sambuc #if SelfTest
10884d9c625SLionel Sambuc _TRACE( ( "Atom \"%s\"\n", Atoms[i].name ) );
10984d9c625SLionel Sambuc
11084d9c625SLionel Sambuc switch ( type ) {
11184d9c625SLionel Sambuc case 0:
11284d9c625SLionel Sambuc _TRACE( ( "\t does not exist on the root window\n", Atoms[i].name ) );
11384d9c625SLionel Sambuc
11484d9c625SLionel Sambuc case XA_ATOM:
11584d9c625SLionel Sambuc for (j=0; j<nitems; j++) {
11684d9c625SLionel Sambuc name = XGetAtomName( d, ((Atom *) prop)[j] );
11784d9c625SLionel Sambuc _TRACE( ( "\t[%d] = \"%s\"\n", j, name ) );
11884d9c625SLionel Sambuc XFree( name );
11984d9c625SLionel Sambuc }
12084d9c625SLionel Sambuc break;
12184d9c625SLionel Sambuc
12284d9c625SLionel Sambuc case XA_STRING:
12384d9c625SLionel Sambuc _TRACE( ( "\t is a string\n", Atoms[i].name ) );
12484d9c625SLionel Sambuc break;
12584d9c625SLionel Sambuc
12684d9c625SLionel Sambuc default:
12784d9c625SLionel Sambuc _TRACE( ( "\tunknown type %s\n", XGetAtomName( d, type ) ) );
12884d9c625SLionel Sambuc break;
12984d9c625SLionel Sambuc }
13084d9c625SLionel Sambuc #endif
13184d9c625SLionel Sambuc
13284d9c625SLionel Sambuc /* done */
13384d9c625SLionel Sambuc XFree( (caddr_t) prop );
13484d9c625SLionel Sambuc
13584d9c625SLionel Sambuc }
13684d9c625SLionel Sambuc
13784d9c625SLionel Sambuc _TRACE( ( "retval = %d\n", retval ) );
13884d9c625SLionel Sambuc return retval >= Present;
13984d9c625SLionel Sambuc }
14084d9c625SLionel Sambuc
14184d9c625SLionel Sambuc #if SelfTest
14284d9c625SLionel Sambuc
main()14384d9c625SLionel Sambuc main () {
14484d9c625SLionel Sambuc Display *d = XOpenDisplay( 0 );
14584d9c625SLionel Sambuc
14684d9c625SLionel Sambuc if ( d == 0 )
14784d9c625SLionel Sambuc printf ( "Could not open display\n" );
14884d9c625SLionel Sambuc else {
14984d9c625SLionel Sambuc printf ( "_vi_is_cde() == %d\n", _vi_is_cde( d ) );
15084d9c625SLionel Sambuc XCloseDisplay( d );
15184d9c625SLionel Sambuc }
15284d9c625SLionel Sambuc }
15384d9c625SLionel Sambuc #endif
154