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