/* $Id: shXchange.c,v 1.1 91/04/25 15:32:35 sao Exp $ */

/*
 * Copyright (C) 1990 by Digital Equipment Corporation.
 * 
 * Author: Michael P. Altenhofen, CEC Karlsruhe e-mail:
 * Altenhofen@kampus.enet.dec.com
 * 
 * This file ist part of Shared X
 * 
 * Permission to use, copy, modify, and distribute this software and its
 * documentation without fee is hereby granted, but only for non-profit  use
 * and distribution,  and provided  that the copyright notice and this notice
 * is preserved on all copies.
 * 
 * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
 * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
 * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 * SOFTWARE.
 */

#include "XmuX.h"
#include <stdio.h>
#include <strings.h>
/*#include <stdlib.h>*/
/*#include <malloc.h>*/
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <X11/cursorfont.h>

int
XmuXSetHints (dpy, target, hints)
  Display *dpy;
  Window target;
  XmuXHints *hints;
{
  Atom atom;

  if (hints->type == XMUXProperty) {
    if (!hints->u.strings[XMUXType] || !hints->u.strings[XMUXSubtype]) {
      printf ("Invalid data! \n");
      return (BadValue);
    }
    atom = XInternAtom (dpy, hints->u.strings[XMUXType], True);
    if (!atom) {
      printf ("Atom %s not valid!\n", hints->u.strings[XMUXType]);
      return (BadAtom);
    }
/*
    printf ("Change property on window 0x%lx , value = %s (%d)\n",
	    target, hints->u.strings[XMUXSubtype],
	    strlen (hints->u.strings[XMUXSubtype]));
*/
    XChangeProperty (dpy, target, atom, XA_STRING, 8,
		     PropModeReplace, hints->u.strings[XMUXSubtype],
		     strlen (hints->u.strings[XMUXSubtype]) + 1);
  }
  else {
    XEvent message;

    message.type = ClientMessage;
    message.xclient.display = dpy;
    message.xclient.window = target;
    atom = XInternAtom (dpy, XMUX_MESSAGE_NAME, False);
    if (!atom) {
      printf ("Atom %s not valid!\n", XMUX_MESSAGE_NAME);
      return (BadAtom);
    }
    message.xclient.message_type = atom;
    message.xclient.format = XMUX_MESSAGE_FORMAT;
    message.xclient.data.l[XMUXType] = hints->u.mess[XMUXType];
    message.xclient.data.l[XMUXSubtype] = hints->u.mess[XMUXSubtype];
    message.xclient.data.l[XMUXDetail] = hints->u.mess[XMUXDetail];
/*
    printf ("Send event w =  0x%lx , atom = %d", target, atom);
    if (hints->u.mess[XMUXSubtype] == XMUXPassChalk)
      printf ("message = pass chalk\n");
*/
    XSendEvent (dpy, target, False, PropertyChangeMask, &message);
  }
  XFlush (dpy);
  return (Success);
}
