/*
 * Copyright 1988, 1989, 1990, 1991 Massachusetts Institute of Technology
 */
#include"xpointer.h"
#include"../../Glib/Glib.h"

show_volumes(event)
XEvent event;
{
  extern Display *dpy;
  extern Window root;
  
  extern GC normtext, brighttext;
  extern XFontStruct *normfont;
  extern int cur_volume;
  extern XContext which_context;
  extern short DEBUG;
  extern Server *serv;

  GC realtext;
  int *which;

  if (event.type == EnterNotify) realtext = brighttext;
  else realtext = normtext;

  XFindContext( dpy, event.xany.window, which_context, (caddr_t *)&which);

  XDrawString(dpy, event.xany.window, realtext, 4, 
	      normfont->ascent,
	      GVolumeName(serv,*which),
	      strlen(GVolumeName(serv,*which)));
}

switch_volumes(event)
     XEvent event;
{
  extern Display *dpy;
  extern int screen;
  extern XContext which_context;
  extern Window root;
  extern Server *serv;
  extern int cur_volume, cur_mask, l_cur_volume, v_cur_volume, r_cur_volume;
  int *which;
  char temp[1024];

  XFindContext( dpy, event.xany.window, which_context, (caddr_t *)&which);

  cur_volume = *which;

  if (cur_mask & LEFT_CHAN) l_cur_volume = *which;
  if (cur_mask & VIDEO_CHAN) v_cur_volume = *which;
  if (cur_mask & RIGHT_CHAN) r_cur_volume = *which;
  draw_active();
  GSwitch(serv, GVolumeIndex(serv,cur_volume), cur_mask);
  GRelease(serv);
  set_cur_vol();
}

draw_active()
{
  extern Display *dpy;
  extern int screen;
  extern int realheight;
  extern int cur_volume, cur_mask, l_cur_volume, v_cur_volume, r_cur_volume;
  extern VolumeList *volumelist;
  extern GC normtext, red_gc, green_gc, orange_gc;

  XClearArea( dpy, root, 490, realheight + normfont->ascent + normfont->descent,
	     50, GNumberVolumes(serv)*(normfont->ascent+normfont->descent+5),
	     False);
  if (cur_mask & LEFT_CHAN) 
    XFillArc(dpy, root, green_gc, 492, 
	     realheight + 2 + (l_cur_volume+1)*(normfont->ascent + normfont->descent+2), 
	     10, 10, 0, 360*64);
  else XFillArc(dpy, root, normtext, 492, 
		realheight + 2 + (l_cur_volume+1)*(normfont->ascent+normfont->descent+2), 
		10, 10, 0, 360*64);
  if (cur_mask & VIDEO_CHAN)
    XFillArc(dpy, root, red_gc, 509, 
	     realheight + 2 + (v_cur_volume+1)*(normfont->ascent + normfont->descent+2), 
	     10, 10, 0, 360*64);
  else XFillArc(dpy, root, normtext, 509, 
		 realheight +2+(v_cur_volume+1)*(normfont->ascent+normfont->descent+2), 
		 10, 10, 0, 360*64);
  if (cur_mask & RIGHT_CHAN) 
    XFillArc(dpy, root, orange_gc, 526, 
	     realheight + 2 + (r_cur_volume+1)*(normfont->ascent + normfont->descent+2), 
	     10, 10, 0, 360*64);
  else XFillArc(dpy, root, normtext, 526, 
		realheight +2+(r_cur_volume+1)*(normfont->ascent+normfont->descent+2), 
		10, 10, 0, 360*64);

}

set_cur_vol()
{
    char *temp_str, temp[1024], *type_str;
    extern Window root;
    extern Display *dpy;
    extern int cur_volume;
    extern Server *serv;
    
    temp_str = GVolumeName(serv, cur_volume);
    if (temp_str == (char *)NULL) {
	temp_str = "No volume available";
	type_str = "";
    }
    else
	if (GVolumeType(serv, cur_volume) == INPUT_DEV)
	    type_str = "Uncontrolled Input Source";
	else
	    if (GVolumeCapabilities(serv, cur_volume) & RECORDABLE)
		type_str = "Record/Play Device";
	    else
		type_str = "Play Device";
    sprintf(temp, "gctl - %s ( %s )", temp_str, type_str);
    XStoreName(dpy, root, temp);
}
