multibar.c 30.2 KB
Newer Older
1 2 3 4
/*
 *
 *  postfish
 *    
Monty Montgomery's avatar
Monty Montgomery committed
5
 *      Copyright (C) 2002-2005 Monty
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 *  Postfish is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2, or (at your option)
 *  any later version.
 *   
 *  Postfish is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *   
 *  You should have received a copy of the GNU General Public License
 *  along with Postfish; see the file COPYING.  If not, write to the
 *  Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 * 
 */

24
#include <stdlib.h>
25
#include <math.h>
26
#include <string.h>
27
#include <gdk/gdkkeysyms.h>
28 29
#include "multibar.h"

30 31 32
static GdkBitmap *stipple=NULL;
static GdkBitmap *stippleB=NULL;

33 34 35
static float compute_dampening(float width, float target,float current,float delta,int zerodamp){
  float raw_delta=target-current;
  float testdelta=delta+(raw_delta*.2);
36

37
  if(target<0 && !zerodamp){
38 39
    if(current>0)
      raw_delta=target-current;
40
  }else if(current<0 && !zerodamp){
41 42 43 44 45
    raw_delta=target-current;
  }else if(raw_delta<0){
    if(delta>0){
      raw_delta=0.;
    }else{
46
      if(raw_delta<testdelta)raw_delta=testdelta;
47 48 49 50 51
    }
  }else{
    if(delta<0){
      raw_delta=0.;
    }else{
52
      if(raw_delta>testdelta)raw_delta=testdelta;
53 54 55 56 57 58
    }
  }
  return raw_delta;
}


59
/* call me roughly 10-20fps */
60
static void compute(Multibar *m,float *lowvals, float *highvals, int n, int draw){
61
  int i,j,xpad;
Monty Montgomery's avatar
Monty Montgomery committed
62
  GtkWidget *widget=GTK_WIDGET(m);
63
  float max=-400;
64
  int height=widget->allocation.height;
65
  int width=widget->allocation.width;
66 67 68

  /* figure out the x padding */
  if(m->thumbs<1){
69
    xpad=1;
70
  }else{
71
    xpad=height;
72
  }
73

74
  m->xpad=xpad;
75

76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
  if(m->readout){
    if(n>m->bars){
      if(!m->bartrackers)
	m->bartrackers=calloc(n,sizeof(*m->bartrackers));
      else{
	m->bartrackers=realloc(m->bartrackers,
			       n*sizeof(*m->bartrackers));
	memset(m->bartrackers+m->bars,0,
	       sizeof(*m->bartrackers)*(n-m->bars));
      }
      
      for(i=m->bars;i<n;i++){
	m->bartrackers[i].pixelposlo=-400;
	m->bartrackers[i].pixelposhi=-400;
	m->bartrackers[i].pixeldeltalo=0;
	m->bartrackers[i].pixeldeltahi=0;
      }
      
      m->bars=n;
    }else if(n<m->bars)
      m->bars=n;
    
    for(i=0;i<n;i++)
      if(highvals[i]>max)max=highvals[i];
    
    if(m->clipdelay>0)
      m->clipdelay--;
    else
      m->clipdelay=0;
    
    if(m->peakdelay>0)
      m->peakdelay--;
108
    else{
109 110 111
      m->peakdelay=0;
      m->peakdelta--;
      m->peak+=m->peakdelta;
112 113
    }
    
114 115 116 117
    if(max>m->peak){
      m->peak=max;
      m->peakdelay=15*2; /* ~2 second hold */
      m->peakdelta=0;
118 119
    }
    
120
    if(draw){
121 122 123 124 125 126 127 128
      int *pixhi=alloca(n*sizeof(*pixhi));
      int *pixlo=alloca(n*sizeof(*pixlo));
      
      for(i=0;i<n;i++){
	pixlo[i]=-1;
	for(j=0;j<=m->labels;j++)
	  if(lowvals[i]>=m->levels[j]){
	    if(lowvals[i]<=m->levels[j+1]){
129
	      float del=(lowvals[i]-m->levels[j])/(m->levels[j+1]-m->levels[j]);
130
	      pixlo[i]=(j+del)/m->labels*(widget->allocation.width-xpad*2-1)+xpad;
131 132 133 134 135
	      break;
	    }else if(j==m->labels){
	      pixlo[i]=widget->allocation.width-xpad+1;
	    }
	  }else
136
	    break;
137 138 139 140 141
	
	pixhi[i]=pixlo[i];
	for(;j<=m->labels;j++)
	  if(highvals[i]>=m->levels[j]){
	    if(highvals[i]<=m->levels[j+1]){
142
	      float del=(highvals[i]-m->levels[j])/(m->levels[j+1]-m->levels[j]);
143
	      pixhi[i]=(j+del)/m->labels*(widget->allocation.width-xpad*2-1)+xpad;
144 145 146 147 148
	      break;
	    }else if(j==m->labels){
	      pixhi[i]=widget->allocation.width-xpad+1;
	    }
	  }else
149
	    break;
150
      }
151 152 153 154
      
      /* dampen movement according to setup */
      
      for(i=0;i<n;i++){
155 156 157 158
	float trackhi=m->bartrackers[i].pixelposhi;
	float tracklo=m->bartrackers[i].pixelposlo;
	float delhi=m->bartrackers[i].pixeldeltahi;
	float dello=m->bartrackers[i].pixeldeltalo;
159 160
	
	/* hi */
161
	delhi = compute_dampening(width-xpad*2-1,pixhi[i],trackhi,delhi,m->dampen_flags & ZERO_DAMP);
162 163 164 165 166 167 168 169 170 171
	
	if(pixhi[i]>trackhi){
	  if(m->dampen_flags & HI_ATTACK)pixhi[i]=trackhi+delhi;
	}else{
	  if(m->dampen_flags & HI_DECAY)pixhi[i]=trackhi+delhi;
	}
	m->bartrackers[i].pixelposhi=pixhi[i];
	m->bartrackers[i].pixeldeltahi=delhi;
	
	/* lo */
172
	dello = compute_dampening(width-xpad*2-1,pixlo[i],tracklo,dello,m->dampen_flags & ZERO_DAMP);
173 174 175 176 177 178 179 180
	if(pixlo[i]>tracklo){
	  if(m->dampen_flags & LO_ATTACK)pixlo[i]=tracklo+dello;
	}else{
	  if(m->dampen_flags & LO_DECAY)pixlo[i]=tracklo+dello;
	}
	m->bartrackers[i].pixelposlo=pixlo[i];
	m->bartrackers[i].pixeldeltalo=dello;
	
181 182
      }
    }
183 184 185 186 187 188
  }
}

static void draw(GtkWidget *widget,int n){
  int i,j,x=-1;
  Multibar *m=MULTIBAR(widget);
189 190
  int xpad=m->xpad,upad=2,lpad=2;
  int height=widget->allocation.height;
191
  GtkWidget *parent=gtk_widget_get_parent(widget);
192 193

  if(m->thumbs>0){
194
    int leftover=height-widget->requisition.height+3;
195 196 197 198 199
    if(leftover<height/4)
      lpad+=leftover;
    else
      lpad+=height/4;
  }
200 201 202 203 204

  if(!m->boxcolor){
    m->boxcolor=gdk_gc_new(m->backing);
    gdk_gc_copy(m->boxcolor,widget->style->black_gc);
  }
205
    
206
  if(m->readout && widget->state!=GTK_STATE_INSENSITIVE){
207 208 209 210 211 212 213 214 215 216 217
    /* draw the pixel positions */
    while(x<widget->allocation.width){
      int r=0xffff,g=0xffff,b=0xffff;
      GdkColor rgb={0,0,0,0};
      int next=widget->allocation.width;
      for(i=0;i<n;i++){
	if(m->bartrackers[i].pixelposlo>x && m->bartrackers[i].pixelposlo<next)
	  next=m->bartrackers[i].pixelposlo;
	if(m->bartrackers[i].pixelposhi>x && m->bartrackers[i].pixelposhi<next)
	  next=m->bartrackers[i].pixelposhi;
      }
218
      
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262
      for(i=0;i<n;i++){
	if(m->bartrackers[i].pixelposlo<=x && m->bartrackers[i].pixelposhi>=next){
	  switch(i%8){
	  case 0:
	    r*=.65;
	    g*=.65;
	    b*=.65;
	    break;
	  case 1:
	    r*=1.;
	    g*=.5;
	    b*=.5;
	    break;
	  case 2:
	    r*=.6;
	    g*=.6;
	    b*=1.;
	    break;
	  case 3:
	    r*=.4;
	    g*=.9;
	    b*=.4;
	    break;
	  case 4:
	    r*=.7;
	    g*=.6;
	    b*=.3;
	    break;
	  case 5:
	    r*=.7;
	    g*=.4;
	    b*=.8;
	    break;
	  case 6:
	    r*=.3;
	    g*=.7;
	    b*=.7;
	    break;
	  case 7:
	    r*=.4;
	    g*=.4;
	    b*=.4;
	    break;
	  }
263 264
	}
      }
265 266 267 268 269 270 271 272
      rgb.red=r;
      rgb.green=g;
      rgb.blue=b;
      gdk_gc_set_rgb_fg_color(m->boxcolor,&rgb);
      
      gdk_draw_rectangle(m->backing,m->boxcolor,1,x+1,upad+1,next-x,widget->allocation.height-lpad-upad-3);
      
      x=next;
273
    }
274
    
275 276
    gdk_draw_line (m->backing,
		   widget->style->white_gc,
277
		   xpad, widget->allocation.height-lpad-1, 
278
		   widget->allocation.width-1-xpad, 
279
		   widget->allocation.height-lpad-1);
280
    
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
    if(m->clipdelay){
      gdk_draw_line (m->backing,
		     widget->style->fg_gc[1],
		     xpad, upad, widget->allocation.width-1-xpad, upad);
      
      gdk_draw_line (m->backing,
		     widget->style->fg_gc[1],
		     xpad, widget->allocation.height-lpad-2, 
		     widget->allocation.width-1-xpad, 
		     widget->allocation.height-lpad-2);
    }else{
      gdk_draw_line (m->backing,
		     widget->style->white_gc,
		     xpad, upad, widget->allocation.width-1-xpad, upad);
      
      gdk_draw_line (m->backing,
		     widget->style->white_gc,
		     xpad, widget->allocation.height-lpad-2, 
		     widget->allocation.width-1-xpad, 
		     widget->allocation.height-lpad-2);
    }
302
    
303 304 305 306 307 308
    /* peak follower */
    if(m->dampen_flags & PEAK_FOLLOW){
      int x=-10;
      for(j=0;j<=m->labels+1;j++)
	if(m->peak>=m->levels[j]){
	  if(m->peak<=m->levels[j+1]){
309
	    float del=(m->peak-m->levels[j])/(m->levels[j+1]-m->levels[j]);
310
	    x=(j+del)/m->labels*(widget->allocation.width-xpad*2-1)+xpad;
311 312 313 314 315 316
	    break;
	  }else if (j==m->labels){
	    x=widget->allocation.width-xpad+1;
	  }
	}else
	  break;
317
      
318 319 320
      for(j=0;j<n;j++)
	if(x<m->bartrackers[j].pixelposhi)
	  x=m->bartrackers[j].pixelposhi;
321
      
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
      {
	int y=widget->allocation.height-lpad-1;
	
	gdk_draw_line(m->backing,widget->style->fg_gc[0],
		      x-3,upad,x+3,upad);
	gdk_draw_line(m->backing,widget->style->fg_gc[0],
		      x-2,upad+1,x+2,upad+1);
	gdk_draw_line(m->backing,widget->style->fg_gc[0],
		      x-1,upad+2,x+1,upad+2);
	gdk_draw_line(m->backing,widget->style->fg_gc[0],
		      x-3,y-1,x+3,y-1);
	gdk_draw_line(m->backing,widget->style->fg_gc[0],
		      x-2,y-2,x+2,y-2);
	gdk_draw_line(m->backing,widget->style->fg_gc[0],
		      x-1,y-3,x+1,y-3);
	
	gdk_draw_line(m->backing,widget->style->fg_gc[1],
		      x,upad+1,x,y-2);
      }
341
    }
342 343 344 345 346 347 348 349 350
  }else{

    int width=widget->allocation.width-xpad;
    int height=widget->allocation.height;
    GdkGC *gc=parent->style->bg_gc[0];

    /* blank scale to bg of parent */
    gdk_draw_rectangle(m->backing,gc,1,xpad,0,width-xpad+1,height-lpad);

351 352
  }

353
  for(i=0;i<=m->labels;i++){
354
    int x=rint(((float)i)/m->labels*(widget->allocation.width-xpad*2-1))+xpad;
355
    int y=widget->allocation.height-lpad-upad;
356
    int px,py;
357 358
    int gc=0;
    
359
    if(m->levels[i]>0.)gc=1;
360
    
361 362 363 364 365 366 367 368 369
    if(m->readout)
      gdk_draw_line (m->backing,
		     widget->style->text_gc[gc],
		     x, upad, x, y+upad);
    else
      gdk_draw_line (m->backing,
		     widget->style->text_gc[gc],
		     x, y/4+upad, x, y+upad);

370 371 372 373 374 375 376
    pango_layout_get_pixel_size(m->layout[i],&px,&py);

    if(i==0){
      x+=2;
      y-=py;
      y/=2;
    }else{
377 378 379 380
      x-=px+2;
      y-=py;
      y/=2;
    }
381 382 383 384 385
    gdk_draw_layout (m->backing,
		     widget->style->text_gc[gc],
		     x, y+upad,
		     m->layout[i]);

386
  }
387 388 389

  /* draw frame */
  {
390
    int width=widget->allocation.width;
391 392 393 394
    int height=widget->allocation.height;
    GdkGC *gc=parent->style->bg_gc[0];
    GdkGC *light_gc=parent->style->light_gc[0];
    GdkGC *dark_gc=parent->style->dark_gc[0];
395
    GdkGC *mid_gc=widget->style->bg_gc[GTK_STATE_ACTIVE];
396 397 398

    /* blank side padding to bg of parent */
    gdk_draw_rectangle(m->backing,gc,1,0,0,xpad,height);
399
    gdk_draw_rectangle(m->backing,gc,1,width-xpad,0,xpad,height);
400 401 402

    /* blank sides of trough */
    gdk_draw_rectangle(m->backing,gc,1,
403 404 405 406
		       0,
		       height-lpad,
		       m->thumblo_x,
		       lpad);
407
    gdk_draw_rectangle(m->backing,gc,1,
408 409 410 411
		       m->thumbhi_x+xpad+xpad,
		       height-lpad,
		       width-xpad-xpad-m->thumbhi_x,
		       lpad);
412
    
413
    /* frame */
414
    if(m->readout){
415 416 417 418
      gdk_draw_line(m->backing,dark_gc,0,0,width-2,0);
      gdk_draw_line(m->backing,dark_gc,0,0,0,height-lpad);
      gdk_draw_line(m->backing,dark_gc,1,height-lpad,width-2,height-lpad);
      gdk_draw_line(m->backing,dark_gc,width-2,height-lpad,width-2,1);
419
      
420 421 422 423 424
      gdk_draw_line(m->backing,light_gc,0,height-lpad+1,
		    width-1,height-lpad+1);
      gdk_draw_line(m->backing,light_gc,width-1,0,width-1,height-lpad+1);
      gdk_draw_line(m->backing,light_gc,1,1,width-3,1);
      gdk_draw_line(m->backing,light_gc,1,1,1,height-lpad-1);
425
    }
426 427 428


    /* dark trough */
429 430 431
    if(lpad>2 || m->readout==0){
      if(lpad>2){
	gdk_draw_rectangle(m->backing,mid_gc,1,
432 433
			   m->thumblo_x+1,height-lpad+1,
			   m->thumbhi_x-m->thumblo_x+xpad*2,lpad-1);
434 435
	
	gdk_draw_line(m->backing,dark_gc,
436 437
		      m->thumblo_x,height-lpad,
		      m->thumblo_x,height-1);
438 439
	
      }
440 441

      gdk_draw_line(m->backing,light_gc,
442 443
		    m->thumblo_x,height-1,
		    m->thumbhi_x+xpad*2,height-1);
444 445

      dark_gc=widget->style->dark_gc[GTK_STATE_ACTIVE];
446

447
      gdk_draw_line(m->backing,dark_gc,
448 449
		    m->thumblo_x,height-lpad,
		    m->thumbhi_x+xpad*2-1,height-lpad);
450
      
451 452
      if(lpad>2)
	gdk_draw_line(m->backing,light_gc,
453 454
		      m->thumbhi_x+xpad*2,height-1,
		      m->thumbhi_x+xpad*2,height-lpad+1);
455

456

457 458
      if(m->readout==0)
	gdk_draw_point(m->backing,light_gc,width-1,height-lpad);
459
    }
460
      
461 462 463 464 465

  }

  /* draw slider thumbs */
  if(m->thumbs){
466
    int height=widget->allocation.height,i,j;
467
    GdkGC *black_gc=widget->style->black_gc;
468
    int y0=height/3-1;
469
    int y1=height-3;
470

471
    int outer=height-1;
472 473 474 475 476 477
    int inner=(y1+y0)/2-y0;

    int A[3]={outer,outer,outer};
    int B[3]={inner,inner,inner};
    int C[3]={inner,inner,inner};
    int D[3]={outer,outer,outer};
478 479

    GdkColor yellow={0,0xff00,0xd000,0};
480 481 482 483 484 485

    if(m->thumbs==2){
      /* adjustment required for overlapping thumbs? */
      int mid=m->thumbpixel[1]-m->thumbpixel[0]-1;
      int midA=(mid<0?0:mid)/2;
      int midB=(mid<0?0:mid)-midA;
486
      
487 488 489 490
      if(midA<D[0])D[0]=midA;
      if(midA<C[0])C[0]=midA;
      if(midB<A[1])A[1]=midB;
      if(midB<B[1])B[1]=midB;
491
    }
492

493 494 495 496 497
    if(m->thumbs==3){
      /* adjust for 0,1 overlap if any; different from the 2 case */
      int mid=m->thumbpixel[1]-m->thumbpixel[0]-1;
      int midA=(mid<0?0:mid)/2;
      int midB=(mid<0?0:mid)-midA;
498

499 500 501 502
      if(midA<D[0])D[0]=midA;
      if(D[0]<C[0]+2)D[0]=C[0]+2;
      if(midB<A[1])A[1]=midB;
      if(A[1]<B[1]+2)A[1]=B[1]+2;
503

504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532
      /* adjust for 1,2 overlap if any */

      mid=m->thumbpixel[2]-m->thumbpixel[1]-1;
      midA=(mid<0?0:mid)/2;
      midB=(mid<0?0:mid)-midA;

      if(midA<D[1])D[1]=midA;
      if(D[1]<C[1]+2)D[1]=C[1]+2;
      if(midB<A[2])A[2]=midB;
      if(A[2]<B[2]+2)A[2]=B[2]+2;
    }
    
    for(i=0;i<m->thumbs;i++){
      if(m->thumbs==3){
	/* in the three-thumb case, the middle thumb is drawn last */
	switch(i){
	case 0:
	  j=0;
	  break;
	case 1:
	  j=2;
	  break;
	case 2:
	  j=1;
	  break;
	}
      }else
	j=i;
      
533
      {
534 535 536 537 538 539 540 541 542
	int x=m->thumbpixel[j]+xpad;
	GdkPoint p[8]={ {x+D[j],y0+C[j]},
			{x+C[j],y0+C[j]}, 
			{x     ,y0     },
			{x-B[j],y0+B[j]},
			{x-A[j],y0+B[j]},
			{x-A[j],y1+1   },
			{x+D[j],y1+1   },
			{x+D[j],y0+C[j]}};
543
	
544 545 546
	GdkPoint d[3]={ {x-A[j]+1,y1},
			{x+D[j]-1,y1},
			{x+D[j]-1,y0+C[j]+1}};
547
	
548 549 550 551 552 553 554
	GdkGC *gc=widget->style->bg_gc[m->thumbstate[j]];
	GdkGC *light_gc=widget->style->light_gc[m->thumbstate[j]];
	GdkGC *dark_gc=widget->style->dark_gc[m->thumbstate[j]];
      
	gdk_draw_polygon(m->backing,gc,TRUE,p,7);
	gdk_draw_lines(m->backing,dark_gc,d,3);
      
555
	if(m->thumbfocus==j && m->widgetfocus){
556 557 558 559
	  if(x&1)
	    gdk_gc_set_stipple(black_gc,stipple);
	  else
	    gdk_gc_set_stipple(black_gc,stippleB);
560

561
	  gdk_gc_set_fill(black_gc,GDK_STIPPLED);
562
	  gdk_draw_polygon(m->backing,black_gc,TRUE,p,7);
563 564
	  gdk_gc_set_fill(black_gc,GDK_SOLID);
	}
565
      
566 567 568
	gdk_draw_lines(m->backing,light_gc,p,6);
	gdk_draw_lines(m->backing,black_gc,p+5,3);
      
569 570 571
	gdk_gc_set_rgb_fg_color(m->boxcolor,&yellow);
	gdk_draw_line(m->backing,m->boxcolor,x,y1-1,x,0);
      }
572 573
    }
  }
574 575
}

576
static void draw_and_expose(GtkWidget *widget){
577
  Multibar *m=MULTIBAR(widget);
578 579 580 581
  if(!GDK_IS_DRAWABLE(m->backing))return;
  draw(widget,m->bars);
  if(!GTK_WIDGET_DRAWABLE(widget))return;
  if(!GDK_IS_DRAWABLE(widget->window))return;
582 583 584 585 586 587 588
  gdk_draw_drawable(widget->window,
		    widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
		    m->backing,
		    0, 0,
		    0, 0,
		    widget->allocation.width,		  
		    widget->allocation.height);
589 590 591 592
}

static gboolean expose( GtkWidget *widget, GdkEventExpose *event ){
  Multibar *m=MULTIBAR(widget);
593 594 595 596 597 598
  gdk_draw_drawable(widget->window,
		    widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
		    m->backing,
		    event->area.x, event->area.y,
		    event->area.x, event->area.y,
		    event->area.width, event->area.height);
599 600 601 602 603
  
  return FALSE;
}

static void size_request (GtkWidget *widget,GtkRequisition *requisition){
604
  int i,maxx=0,maxy=0,x,y,xpad;
605
  Multibar *m=MULTIBAR(widget);
606

607
  for(i=0;i<=m->labels;i++){
608 609 610 611 612 613
    pango_layout_get_pixel_size(m->layout[i],&x,&y);

    if(x>maxx)maxx=x;
    if(y>maxy)maxy=y;
  }

614 615
  maxy+=4;

616
  if(m->thumbs==0){
617
    xpad=1;
618
  }else{
619
    maxy+=3;
620
    xpad=maxy;
621 622 623
  }

  requisition->width = (maxx*1.5+2)*m->labels+xpad*2;
624
  requisition->height = maxy;
625 626 627

}

628
static int transition_thumbfocus=0;
629 630 631 632 633 634
static gboolean multibar_focus (GtkWidget         *widget,
				GtkDirectionType   direction){
  Multibar *m=MULTIBAR(widget);
  int ret=TRUE;

  if(m->thumbs==0)return FALSE;
635
  if(!m->widgetfocus)m->thumbfocus=-1;
636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658

  switch(direction){
  case GTK_DIR_TAB_FORWARD:
  case GTK_DIR_RIGHT:
    if(m->thumbfocus+1>=m->thumbs){
      m->thumbfocus=-1;
      ret=FALSE;
    }else
      m->thumbfocus++;
    break;

  case GTK_DIR_TAB_BACKWARD:
  case GTK_DIR_LEFT:
    if(m->thumbfocus==-1)
      m->thumbfocus=m->thumbs-1;
    else{
      if(m->thumbfocus-1<0){
	m->thumbfocus=-1;
	ret=FALSE;
      }else
	m->thumbfocus--;
    }
    break;
659 660 661 662 663 664 665 666 667 668 669

  case GTK_DIR_UP:
  case GTK_DIR_DOWN:
    if(m->thumbfocus==-1){
      if(transition_thumbfocus>=0 && transition_thumbfocus<m->thumbs)
	m->thumbfocus=transition_thumbfocus;
      else
	m->thumbfocus=0;
      ret=TRUE;
    }else{
      transition_thumbfocus=m->thumbfocus;
670
      m->thumbfocus=-1;
671 672 673 674
      ret=FALSE;
    }
    break;

675
  default:
676
    m->thumbfocus=-1;
677 678 679 680 681
    ret=FALSE;
  }

  if(ret==TRUE) gtk_widget_grab_focus(widget);
  draw_and_expose(widget);
682

683 684 685
  return ret;
}

Monty Montgomery's avatar
Monty Montgomery committed
686 687
static gint determine_thumb(Multibar *m,int ix, int iy){
  GtkWidget *widget=GTK_WIDGET(m);
688
  int max=widget->allocation.height;
689
  float distances[3]={-1,-1,-1};
690 691
  int thumb=-1;

692
  /* center thumb */
693 694
  if(m->thumbs==1 || m->thumbs>2){
    int num=(m->thumbs==1?0:1);
695 696
    int x= m->thumbpixel[num]-ix;
    distances[num]=fabs(x);
697 698 699 700
  }

  /* left thumb */
  if(m->thumbs>1){
701 702
    int x= m->thumbpixel[0]-ix;
    distances[0]=fabs(x-.1);
703 704 705 706 707
  }
  
  /* right thumb */
  if(m->thumbs>1){
    int num=(m->thumbs==2?1:2);
708 709 710
    int x= m->thumbpixel[num]-ix;
    distances[num]=fabs(x+.1);
   }
711
  
712 713
  if(m->thumbs && distances[0]<max)thumb=0;
  if(m->thumbs>1 && distances[1]<max)
714
    if(thumb == -1 || distances[1]<distances[0])thumb=1;
715
  if(m->thumbs>2 && distances[2]<max)
716 717
    if(thumb == -1 || (distances[2]<distances[0] && 
		       distances[2]<distances[1]))thumb=2;
718 719
  if(m->thumbs>2 && distances[1]<max/2)thumb=1;

720 721 722
  return thumb;
}

Monty Montgomery's avatar
Monty Montgomery committed
723 724
static int pixel_bound(Multibar *m,int x){
  GtkWidget *w=GTK_WIDGET(m);
725
  if(x<0)return 0;
726 727
  if(x>w->allocation.width-m->xpad*2-1)
    return w->allocation.width-m->xpad*2-1;
728 729 730
  return x;
}

731
static float pixel_to_val(Multibar *m,int x){
Monty Montgomery's avatar
Monty Montgomery committed
732
  GtkWidget *w=GTK_WIDGET(m);
733 734 735
  int j;

  for(j=0;j<=m->labels;j++){
736 737
    int pixlo=rint((float)j/m->labels*(w->allocation.width-m->xpad*2-1));
    int pixhi=rint((float)(j+1)/m->labels*(w->allocation.width-m->xpad*2-1));
738 739 740

    if(x>=pixlo && x<=pixhi){
      if(pixlo==pixhi)return m->levels[j];
741
      float del=(float)(x-pixlo)/(pixhi-pixlo);
742 743 744 745 746 747
      return (1.-del)*m->levels[j] + del*m->levels[j+1];
    }
  }
  return 0.;
}

748
static int val_to_pixel(Multibar *m,float v){
Monty Montgomery's avatar
Monty Montgomery committed
749
  GtkWidget *w=GTK_WIDGET(m);
750 751 752 753 754
  int j,ret=0;

  if(v<m->levels[0]){
    ret=0;
  }else if(v>m->levels[m->labels]){
755
    ret=w->allocation.width-m->xpad*2-1;
756 757 758
  }else{
    for(j=0;j<=m->labels;j++){
      if(v>=m->levels[j] && v<=m->levels[j+1]){
759
	float del=(v-m->levels[j])/(m->levels[j+1]-m->levels[j]);
760 761
	int pixlo=rint((float)j/m->labels*(w->allocation.width-m->xpad*2-1));
	int pixhi=rint((float)(j+1)/m->labels*(w->allocation.width-m->xpad*2-1));
762 763 764 765 766 767
	ret=rint(pixlo*(1.-del)+pixhi*del);
	break;
      }
    }
  }

Monty Montgomery's avatar
Monty Montgomery committed
768
  ret=pixel_bound(m,ret);
769 770 771 772 773 774 775 776
  return ret;
}

static gboolean configure(GtkWidget *widget, GdkEventConfigure *event){
  Multibar *m=MULTIBAR(widget);
  int i;
  
  if (m->backing)
777
    g_object_unref(m->backing);
778 779 780 781 782 783 784 785
  
  m->backing = gdk_pixmap_new(widget->window,
			      widget->allocation.width,
			      widget->allocation.height,
			      -1);
  gdk_draw_rectangle(m->backing,widget->style->white_gc,1,0,0,widget->allocation.width,
		     widget->allocation.height);
  
786
  compute(m,0,0,0,1);
787
  for(i=0;i<m->thumbs;i++)
Monty Montgomery's avatar
Monty Montgomery committed
788 789 790
    m->thumbpixel[i]=val_to_pixel(m,m->thumbval[i]);
  m->thumblo_x=val_to_pixel(m,m->thumblo);
  m->thumbhi_x=val_to_pixel(m,m->thumbhi);
791

792
  draw_and_expose(widget);
793

794 795 796
  return TRUE;
}

797
static void partial_vals_bound(Multibar *m){
798
  int i;
Monty Montgomery's avatar
Monty Montgomery committed
799 800 801 802 803

  if(m->thumbsmall>0 && m->thumblarge>0)
    for(i=0;i<m->thumbs;i++)
      m->thumbval[i]=rint(m->thumbval[i]/m->thumbsmall)*m->thumbsmall;

804
  for(i=0;i<m->thumbs;i++){
Monty Montgomery's avatar
Monty Montgomery committed
805 806 807
    if(m->thumbval[i]<m->thumblo)m->thumbval[i]=m->thumblo;
    if(m->thumbval[i]>m->thumbhi)m->thumbval[i]=m->thumbhi;
    m->thumbpixel[i]=val_to_pixel(m,m->thumbval[i]);
808
  }
809 810 811 812
}

static void vals_bound(Multibar *m){
  partial_vals_bound(m);
813

Monty Montgomery's avatar
Monty Montgomery committed
814
  if(m->thumbfocus>=0){
815
    float v=m->thumbval[m->thumbfocus];
Monty Montgomery's avatar
Monty Montgomery committed
816
    int    x=m->thumbpixel[m->thumbfocus];
817
    
Monty Montgomery's avatar
Monty Montgomery committed
818
    if(m->thumbfocus==2){
819 820 821 822 823 824 825 826 827
      if(m->thumbpixel[1]>x){
	m->thumbpixel[1]=x;
	m->thumbval[1]=v;
      }
      if(m->thumbpixel[0]>x){
	m->thumbpixel[0]=x;
	m->thumbval[0]=v;
      }
    }
Monty Montgomery's avatar
Monty Montgomery committed
828 829
    
    if(m->thumbfocus==1){
830 831 832 833 834 835 836 837 838
      if(m->thumbpixel[2]<x){
	m->thumbpixel[2]=x;
	m->thumbval[2]=v;
      }
      if(m->thumbpixel[0]>x){
	m->thumbpixel[0]=x;
	m->thumbval[0]=v;
      }
    }
Monty Montgomery's avatar
Monty Montgomery committed
839 840
    
    if(m->thumbfocus==0){
841 842 843 844 845 846 847 848 849
      if(m->thumbpixel[2]<x){
	m->thumbpixel[2]=x;
	m->thumbval[2]=v;
      }
      if(m->thumbpixel[1]<x){
	m->thumbpixel[1]=x;
	m->thumbval[1]=v;
      }
    }
Monty Montgomery's avatar
Monty Montgomery committed
850
  }
851
}
Monty Montgomery's avatar
Monty Montgomery committed
852

853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871
static gint lightme(GtkWidget *w,gint x,gint y){
  Multibar *m=MULTIBAR(w);
  int thumb=determine_thumb(m,x,y);
  GtkStateType thumbstate[3];
  thumbstate[0]=GTK_STATE_NORMAL;
  thumbstate[1]=GTK_STATE_NORMAL;
  thumbstate[2]=GTK_STATE_NORMAL;
  if(thumb>=0)thumbstate[thumb]=GTK_STATE_PRELIGHT;
  
  if(thumbstate[0]!=m->thumbstate[0] ||
     thumbstate[1]!=m->thumbstate[1] ||
     thumbstate[2]!=m->thumbstate[2]){
    m->thumbstate[0]=thumbstate[0];
    m->thumbstate[1]=thumbstate[1];
    m->thumbstate[2]=thumbstate[2];
    
    draw_and_expose(w);
  }
  return TRUE;
Monty Montgomery's avatar
Monty Montgomery committed
872 873 874 875 876
}

static gint multibar_motion(GtkWidget        *w,
			    GdkEventMotion   *event){
  Multibar *m=MULTIBAR(w);
877
  
Monty Montgomery's avatar
Monty Montgomery committed
878 879 880 881
  /* is a thumb already grabbed? */
  if(m->thumbgrab>=0){
    
    int x=event->x+m->thumbx;
882
    float v;
883
    
Monty Montgomery's avatar
Monty Montgomery committed
884 885 886 887 888
    x=pixel_bound(m,x);
    m->thumbval[m->thumbgrab]=pixel_to_val(m,x);
    vals_bound(m);
    v=m->thumbval[m->thumbgrab];
    x=m->thumbpixel[m->thumbgrab]=val_to_pixel(m,v);
889
    
890 891
    if(m->callback)m->callback(GTK_WIDGET(m),m->callbackp);
    draw_and_expose(w);
892
    
893 894
  }else{
    /* nothing grabbed right now; determine if we're in a a thumb's area */
895
    lightme(w,event->x-m->xpad,event->y);
896
  }
897 898 899 900 901 902 903 904

  return TRUE;
}

static gint multibar_enter(GtkWidget        *w,
			   GdkEventCrossing *event){
  Multibar *m=MULTIBAR(w);
  lightme(w,event->x-m->xpad,event->y);
905 906 907 908 909 910 911 912
  return TRUE;
}

static gint multibar_leave(GtkWidget        *widget,
			   GdkEventCrossing *event){
  Multibar *m=MULTIBAR(widget);

  if(m->thumbgrab<0){
913 914 915
    if(m->thumbstate[0] ||
       m->thumbstate[1] ||
       m->thumbstate[2]){
916 917 918 919 920 921 922 923 924 925
      m->thumbstate[0]=0;
      m->thumbstate[1]=0;
      m->thumbstate[2]=0;
      
      draw_and_expose(widget);
    }
  }
  return TRUE;
}

926
static gboolean button_press   (GtkWidget        *widget,
927 928
			    GdkEventButton   *event){
  Multibar *m=MULTIBAR(widget);
929 930 931
  int thumb=determine_thumb(m,event->x-m->xpad,event->y);

  if(thumb==0){
932
    gtk_widget_grab_focus(widget);
933
    m->thumbgrab=m->thumbfocus=0;
934
    m->thumbx=m->thumbpixel[0]-event->x;
935
  }else if(thumb==1){
936
    gtk_widget_grab_focus(widget);
937
    m->thumbgrab=m->thumbfocus=1;
938
    m->thumbx=m->thumbpixel[1]-event->x;
939
  }else if(thumb==2){
940
    gtk_widget_grab_focus(widget);
941
    m->thumbgrab=m->thumbfocus=2;
942 943 944
    m->thumbx=m->thumbpixel[2]-event->x;
  }
  draw_and_expose(widget);
945
  return TRUE;
946 947
}

948
static gboolean button_release   (GtkWidget        *widget,
949 950 951 952
			    GdkEventButton   *event){
  Multibar *m=MULTIBAR(widget);
  m->thumbgrab=-1;
  draw_and_expose(widget);
953
  return TRUE;
954 955 956 957 958
}

static gboolean unfocus(GtkWidget        *widget,
			GdkEventFocus       *event){
  Multibar *m=MULTIBAR(widget);
959
  m->widgetfocus=0;
960
  draw_and_expose(widget);
961
  return TRUE;
962 963 964 965 966
}

static gboolean refocus(GtkWidget        *widget,
			GdkEventFocus       *event){
  Multibar *m=MULTIBAR(widget);
967
  m->widgetfocus=1;
968
  draw_and_expose(widget);
969
  return TRUE;
970 971
}

972 973 974 975 976 977 978
gboolean key_press(GtkWidget *w,GdkEventKey *event){
  Multibar *m=MULTIBAR(w);
  int x;
  if(event->state&GDK_MOD1_MASK) return FALSE;
  if(event->state&GDK_CONTROL_MASK) return FALSE;

  if(m->thumbfocus>=0){
Monty Montgomery's avatar
Monty Montgomery committed
979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026
    if(m->thumbsmall>0 && m->thumblarge>0){

      switch(event->keyval){
      case GDK_minus:
	m->thumbval[m->thumbfocus]-=m->thumbsmall;
	break;
      case GDK_underscore:
	m->thumbval[m->thumbfocus]-=m->thumblarge;
	break;
      case GDK_equal:
	m->thumbval[m->thumbfocus]+=m->thumbsmall;
	break;
      case GDK_plus:
	m->thumbval[m->thumbfocus]+=m->thumblarge;
	break;
      default:
	return FALSE;
      }

      vals_bound(m);
      x=val_to_pixel(m,m->thumbval[m->thumbfocus]);
      x=pixel_bound(m,x);
      m->thumbpixel[m->thumbfocus]=x;

    }else{

      switch(event->keyval){
      case GDK_minus:
	x=m->thumbpixel[m->thumbfocus]-1;
	break;
      case GDK_underscore:
	x=m->thumbpixel[m->thumbfocus]-10;
	break;
      case GDK_equal:
	x=m->thumbpixel[m->thumbfocus]+1;
	break;
      case GDK_plus:
	x=m->thumbpixel[m->thumbfocus]+10;
	break;
      default:
	return FALSE;
      }

      x=pixel_bound(m,x);
      m->thumbpixel[m->thumbfocus]=x;
      m->thumbval[m->thumbfocus]=pixel_to_val(m,x);
      vals_bound(m);

1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037
    }

    if(m->callback)m->callback(GTK_WIDGET(m),m->callbackp);

    draw_and_expose(w);
    return TRUE;
  }
  return FALSE;
}


Monty Montgomery's avatar
Monty Montgomery committed
1038 1039
static GtkDrawingAreaClass *parent_class = NULL;

1040 1041 1042 1043 1044

static void state_changed(GtkWidget *w,GtkStateType ps){
  draw_and_expose(w);
}

1045
static void multibar_class_init (MultibarClass *class){
1046
  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
Monty Montgomery's avatar
Monty Montgomery committed
1047 1048
  parent_class = g_type_class_peek_parent (class);

1049 1050 1051
  widget_class->expose_event = expose;
  widget_class->configure_event = configure;
  widget_class->size_request = size_request;
1052 1053 1054 1055
  widget_class->focus=multibar_focus;
  widget_class->key_press_event = key_press;
  widget_class->button_press_event = button_press;
  widget_class->button_release_event = button_release;
1056
  widget_class->enter_notify_event = multibar_enter;
1057 1058 1059 1060
  widget_class->leave_notify_event = multibar_leave;
  widget_class->motion_notify_event = multibar_motion;
  widget_class->focus_out_event = unfocus;
  widget_class->focus_in_event = refocus;
1061
  widget_class->state_changed = state_changed;
1062 1063 1064 1065

  stipple=gdk_bitmap_create_from_data(NULL,"\125\352",2,2);
  stippleB=gdk_bitmap_create_from_data(NULL,"\352\125",2,2);

1066 1067 1068 1069
}

static void multibar_init (Multibar *m){
  m->layout=0;
1070 1071 1072
  m->peakdelay=0;
  m->clipdelay=0;
  m->peak=-400;
1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096
}

GType multibar_get_type (void){
  static GType m_type = 0;
  if (!m_type){
    static const GTypeInfo m_info={
      sizeof (MultibarClass),
      NULL, /* base_init */
      NULL, /* base_finalize */
      (GClassInitFunc) multibar_class_init,
      NULL, /* class_finalize */
      NULL, /* class_data */
      sizeof (Multibar),
      0,
      (GInstanceInitFunc) multibar_init,
      0
    };
    
    m_type = g_type_register_static (GTK_TYPE_DRAWING_AREA, "Multibar", &m_info, 0);
  }

  return m_type;
}

1097
GtkWidget* multibar_new (int n, char **labels, float *levels, int thumbs,
1098
			 int flags){
1099 1100 1101 1102 1103 1104
  int i;
  GtkWidget *ret= GTK_WIDGET (g_object_new (multibar_get_type (), NULL));
  Multibar *m=MULTIBAR(ret);

  /* not the *proper* way to do it, but this is a one-shot */
  m->levels=calloc((n+1),sizeof(*m->levels));
1105 1106
  m->labels=n-1;
  memcpy(m->levels,levels,n*sizeof(*levels));
1107

1108 1109
  m->layout=calloc(n,sizeof(*m->layout));
  for(i=0;i<n;i++)
1110 1111
    m->layout[i]=gtk_widget_create_pango_layout(ret,labels[i]);

1112
  m->dampen_flags=flags;
1113 1114 1115
  m->thumbfocus=-1;
  m->thumbgrab=-1;
  m->thumblo=levels[0];
1116
  m->thumbhi=levels[n-1];
Monty Montgomery's avatar
Monty Montgomery committed
1117 1118
  m->thumblo_x=val_to_pixel(m,m->thumblo);
  m->thumbhi_x=val_to_pixel(m,m->thumbhi);
1119

1120 1121 1122 1123 1124
  if(thumbs<0)thumbs=0;
  if(thumbs>3)thumbs=3;
  m->thumbs=thumbs;
  if(m->thumbs!=0)  GTK_WIDGET_SET_FLAGS (m, GTK_CAN_FOCUS);

1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137
  {
    int events=gtk_widget_get_events(ret);
    gtk_widget_set_events(ret,              events|
			  GDK_POINTER_MOTION_MASK|
			  GDK_BUTTON_PRESS_MASK	 |
			  GDK_BUTTON_RELEASE_MASK|
			  GDK_KEY_PRESS_MASK     |
			  GDK_KEY_RELEASE_MASK   |
			  GDK_ENTER_NOTIFY_MASK  |
			  GDK_LEAVE_NOTIFY_MASK  |
			  GDK_FOCUS_CHANGE_MASK  );
  }

1138 1139 1140 1141
  m->readout=1;
  return ret;
}

1142
GtkWidget* multibar_slider_new (int n, char **labels, float *levels, 
1143 1144 1145 1146 1147 1148
				int thumbs){
  GtkWidget *ret= multibar_new(n,labels,levels,thumbs,0);
  Multibar *m=MULTIBAR(ret);
  m->readout=0;
  gtk_widget_set_name(ret,"Multislide");

1149 1150 1151
  return ret;
}

1152
void multibar_set(Multibar *m,float *lo, float *hi, int n, int draw){
1153
  GtkWidget *widget=GTK_WIDGET(m);
1154
  compute(m,lo,hi,n,draw);
1155
  if(draw)draw_and_expose(widget);
1156
}
1157

1158
void multibar_thumb_set(Multibar *m,float v, int n){
1159
  GtkWidget *w=GTK_WIDGET(m);
Monty Montgomery's avatar
Monty Montgomery committed
1160
  int x;
1161 1162

  if(n<0)return;
1163
  if(n>=m->thumbs)return;
1164 1165

  {
Monty Montgomery's avatar
Monty Montgomery committed
1166
    m->thumbval[n]=v;
1167
    partial_vals_bound(m);
Monty Montgomery's avatar
Monty Montgomery committed
1168 1169
    v=m->thumbval[n];
    x=m->thumbpixel[n]=val_to_pixel(m,v);
1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206
    m->thumbval[n]=v;
  
    if(n==0){
      if(m->thumbpixel[1]<x){
	m->thumbval[1]=v;
	m->thumbpixel[1]=x;
      }
      if(m->thumbpixel[2]<x){
	m->thumbval[2]=v;
	m->thumbpixel[2]=x;
      }
    }

    if(n==1){
      if(m->thumbpixel[0]>x){
	m->thumbval[0]=v;
	m->thumbpixel[0]=x;
      }
      if(m->thumbpixel[2]<x){
	m->thumbval[2]=v;
	m->thumbpixel[2]=x;
      }
    }

    if(n==2){
      if(m->thumbpixel[0]>x){
	m->thumbval[0]=v;
	m->thumbpixel[0]=x;
      }
      if(m->thumbpixel[1]>x){
	m->thumbval[1]=v;
	m->thumbpixel[1]=x;
      }
    }
  }
  if(m->callback)m->callback(GTK_WIDGET(m),m->callbackp);
  draw_and_expose(w);
1207
}
1208 1209 1210 1211 1212 1213

void multibar_reset(Multibar *m){
  m->peak=-400;
  m->peakdelta=0;
  m->peakdelay=0;
  m->clipdelay=0;
1214
  multibar_set(m,NULL,NULL,0,1);
1215
}
1216

1217
void multibar_setwarn(Multibar *m,int draw){
1218 1219 1220 1221
  GtkWidget *widget=GTK_WIDGET(m);
  if(!m->clipdelay){
    m->clipdelay=15*10;

1222
    if(draw)draw_and_expose(widget);
1223 1224 1225
  }else
    m->clipdelay=15*10; /* ~ ten second hold */
}
1226 1227 1228 1229 1230 1231 1232 1233

/* because closures are ludicrously complex for doing something this simple */
void multibar_callback(Multibar *m,void (*callback)(GtkWidget *,gpointer),
		       gpointer p){
  m->callback=callback;
  m->callbackp=p;
}
  
1234
float multibar_get_value(Multibar *m,int n){
1235 1236 1237 1238 1239
  if(n<0)return 0.;
  if(n>m->thumbs)return 0.;
  return m->thumbval[n];
}

1240
void multibar_thumb_bounds(Multibar *m,float lo, float hi){
1241 1242
  GtkWidget *w=GTK_WIDGET(m);
  if(lo>hi)return;
1243 1244 1245 1246 1247 1248

  if(lo<m->levels[0])lo=m->levels[0];
  if(hi<m->levels[0])hi=m->levels[0];
  if(lo>m->levels[m->labels])lo=m->levels[m->labels];
  if(hi>m->levels[m->labels])hi=m->levels[m->labels];

1249 1250 1251
  m->thumblo=lo;
  m->thumbhi=hi;

Monty Montgomery's avatar
Monty Montgomery committed
1252 1253 1254 1255 1256 1257 1258 1259
  m->thumblo_x=val_to_pixel(m,lo);
  m->thumbhi_x=val_to_pixel(m,hi);

  vals_bound(m);
  if(m->callback)m->callback(GTK_WIDGET(m),m->callbackp);
  draw_and_expose(w);
}

1260
void multibar_thumb_increment(Multibar *m,float small, float large){
Monty Montgomery's avatar
Monty Montgomery committed
1261 1262 1263 1264 1265
  GtkWidget *w=GTK_WIDGET(m);
  if(small>large)return;

  m->thumbsmall=small;
  m->thumblarge=large;
1266

1267 1268 1269 1270 1271
  vals_bound(m);
  if(m->callback)m->callback(GTK_WIDGET(m),m->callbackp);
  draw_and_expose(w);
}

1272 1273 1274 1275 1276 1277 1278
int multibar_thumb_grab_p(Multibar *m){
  return m->widgetfocus;
}

int multibar_thumb_focus(Multibar *m){
  return m->thumbfocus;
}