~oubiwann/libgrip/671558-pygrip

« back to all changes in this revision

Viewing changes to src/gropegesturemanager.c

  • Committer: Duncan McGreggor
  • Date: 2010-11-10 21:04:53 UTC
  • mfrom: (1.2.5 trunk)
  • Revision ID: duncan@ubuntu.com-20101110210453-meve3zlxvc2i00ao
Merged from trunk (gobject introspection).

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
#include <gdk/gdkx.h>
29
29
#include <geis/geis.h>
30
30
 
31
 
#include <grail-types.h>
32
 
 
33
31
typedef struct _GropeGestureRegistration GropeGestureRegistration;
34
32
typedef struct _GropeGestureBinding      GropeGestureBinding;
35
33
 
40
38
 
41
39
struct _GropeGestureBinding
42
40
{
43
 
  GropeGestureType     type;
44
 
  gint                 touches;
45
 
  GropeGestureCallback start;
46
 
  GropeGestureCallback update;
47
 
  GropeGestureCallback end;
 
41
  GropeGestureType      type;
 
42
  gint                  touches;
 
43
  GropeGestureCallback  start;
 
44
  GropeGestureCallback  update;
 
45
  GropeGestureCallback  end;
 
46
  gpointer              data;
 
47
  GDestroyNotify        destroy;
48
48
};
49
49
 
50
50
struct _GropeGestureRegistration
352
352
  for (l = reg->bindings; l != NULL; l = l->next)
353
353
    {
354
354
      GropeGestureBinding *binding = (GropeGestureBinding *)l->data;
355
 
      GropeEventGestureDrag drag;
356
 
      GropeEventGesturePinch pinch;
357
 
      GropeEventGestureRotate rotate;
358
355
 
359
 
      if (type == GEIS_TYPE_DRAG)
 
356
      if (binding->type == type)
360
357
        {
361
 
          drag.id      = id;
362
 
          gint fingers = drag_gesture_handle_properties (&drag,
363
 
                                                         attr_count,
364
 
                                                         attrs);
365
 
 
366
 
          switch (fingers)
367
 
            {
368
 
            case 1:
369
 
              drag.type = GROPE_GESTURE_DRAG1;
370
 
              break;
371
 
 
372
 
            case 2:
373
 
              drag.type = GROPE_GESTURE_DRAG2;
374
 
              break;
375
 
 
376
 
            case 3:
377
 
              drag.type = GROPE_GESTURE_DRAG3;
378
 
              break;
379
 
 
380
 
            case 4:
381
 
              drag.type = GROPE_GESTURE_DRAG4;
382
 
              break;
383
 
 
384
 
            case 5:
385
 
              drag.type = GROPE_GESTURE_DRAG5;
386
 
              break;
387
 
 
388
 
            default:
389
 
              break;
390
 
            }
391
 
 
392
 
          if (fingers == binding->touches)
393
 
            {
394
 
              binding->start (reg->window,
395
 
                              type,
396
 
                              ((GropeGestureEvent*)&drag));
397
 
            }
398
 
 
399
 
          break;
400
 
        }
401
 
      else if (type == GEIS_TYPE_PINCH)
402
 
        {
403
 
          pinch.id      = id;
404
 
 
405
 
          gint fingers = pinch_gesture_handle_properties (&pinch,
406
 
                                                          attr_count,
407
 
                                                          attrs);
408
 
 
409
 
          switch (fingers)
410
 
            {
411
 
            case 1:
412
 
              pinch.type = GROPE_GESTURE_PINCH1;
413
 
              break;
414
 
 
415
 
            case 2:
416
 
              pinch.type = GROPE_GESTURE_PINCH2;
417
 
              break;
418
 
 
419
 
            case 3:
420
 
              pinch.type = GROPE_GESTURE_PINCH3;
421
 
              break;
422
 
 
423
 
            case 4:
424
 
              pinch.type = GROPE_GESTURE_PINCH4;
425
 
              break;
426
 
 
427
 
            case 5:
428
 
              pinch.type = GROPE_GESTURE_PINCH5;
429
 
              break;
430
 
 
431
 
            default:
432
 
              break;
433
 
            }
434
 
 
435
 
          if (fingers == binding->touches)
436
 
            {
437
 
              binding->start (reg->window,
438
 
                              type,
439
 
                              ((GropeGestureEvent*)&pinch));
440
 
            }
441
 
          break;
442
 
        }
443
 
      else if (type == GEIS_TYPE_ROTATE)
444
 
        {
445
 
          rotate.id = id;
446
 
 
447
 
          gint fingers = rotate_gesture_handle_properties (&rotate,
448
 
                                                           attr_count,
449
 
                                                           attrs);
450
 
 
451
 
          switch (fingers)
452
 
            {
453
 
            case 1:
454
 
              rotate.type = GROPE_GESTURE_ROTATE1;
455
 
              break;
456
 
 
457
 
            case 2:
458
 
              rotate.type = GROPE_GESTURE_ROTATE2;
459
 
              break;
460
 
 
461
 
            case 3:
462
 
              rotate.type = GROPE_GESTURE_ROTATE3;
463
 
              break;
464
 
 
465
 
            case 4:
466
 
              rotate.type = GROPE_GESTURE_ROTATE4;
467
 
              break;
468
 
 
469
 
            case 5:
470
 
              rotate.type = GROPE_GESTURE_ROTATE5;
471
 
              break;
472
 
 
473
 
            default:
474
 
              break;
475
 
            }
476
 
 
477
 
          if (fingers == binding->touches)
478
 
            {
479
 
              binding->start (reg->window,
480
 
                              type,
481
 
                              ((GropeGestureEvent*)&rotate));
482
 
            }
 
358
          if (type == GROPE_GESTURE_DRAG)
 
359
            {
 
360
              GropeEventGestureDrag drag;
 
361
 
 
362
              drag.type    = type;
 
363
              drag.id      = id;
 
364
              drag.fingers = drag_gesture_handle_properties (&drag,
 
365
                                                             attr_count,
 
366
                                                             attrs);
 
367
 
 
368
              if (drag.fingers == binding->touches)
 
369
                {
 
370
                  binding->start (reg->window,
 
371
                                  ((GropeGestureEvent*)&drag),
 
372
                                  binding->data);
 
373
                }
 
374
            }
 
375
          else if (type == GROPE_GESTURE_PINCH)
 
376
            {
 
377
              GropeEventGesturePinch pinch;
 
378
 
 
379
              pinch.type    = type;
 
380
              pinch.id      = id;
 
381
              pinch.fingers = pinch_gesture_handle_properties (&pinch,
 
382
                                                               attr_count,
 
383
                                                               attrs);
 
384
 
 
385
              if (pinch.fingers == binding->touches)
 
386
                {
 
387
                  binding->start (reg->window,
 
388
                                  ((GropeGestureEvent*)&pinch),
 
389
                                  binding->data);
 
390
                }
 
391
            }
 
392
          else if (type == GROPE_GESTURE_ROTATE)
 
393
            {
 
394
              GropeEventGestureRotate rotate;
 
395
 
 
396
              rotate.type    = type;
 
397
              rotate.id      = id;
 
398
              rotate.fingers = rotate_gesture_handle_properties (&rotate,
 
399
                                                                 attr_count,
 
400
                                                                 attrs);
 
401
 
 
402
              if (rotate.fingers == binding->touches)
 
403
                {
 
404
                  binding->start (reg->window,
 
405
                                  ((GropeGestureEvent*)&rotate),
 
406
                                  binding->data);
 
407
                }
 
408
            }
 
409
 
 
410
          return;
483
411
        }
484
412
    }
485
413
}
497
425
  for (l = reg->bindings; l != NULL; l = l->next)
498
426
    {
499
427
      GropeGestureBinding *binding = (GropeGestureBinding *)l->data;
500
 
      GropeEventGestureDrag drag;
501
 
      GropeEventGesturePinch pinch;
502
 
      GropeEventGestureRotate rotate;
503
428
 
504
 
      if (type == GEIS_TYPE_DRAG)
 
429
      if (binding->type == type)
505
430
        {
506
 
          drag.id   = id;
507
 
          gint fingers = drag_gesture_handle_properties (&drag,
508
 
                                                         attr_count,
509
 
                                                         attrs);
510
 
 
511
 
          switch (fingers)
512
 
            {
513
 
            case 1:
514
 
              drag.type = GROPE_GESTURE_DRAG1;
515
 
              break;
516
 
 
517
 
            case 2:
518
 
              drag.type = GROPE_GESTURE_DRAG2;
519
 
              break;
520
 
 
521
 
            case 3:
522
 
              drag.type = GROPE_GESTURE_DRAG3;
523
 
              break;
524
 
 
525
 
            case 4:
526
 
              drag.type = GROPE_GESTURE_DRAG4;
527
 
              break;
528
 
 
529
 
            case 5:
530
 
              drag.type = GROPE_GESTURE_DRAG5;
531
 
              break;
532
 
 
533
 
            default:
534
 
              break;
535
 
            }
536
 
 
537
 
          if (fingers == binding->touches)
538
 
            {
539
 
              binding->update (reg->window,
540
 
                               drag.type,
541
 
                               ((GropeGestureEvent*)&drag));
542
 
            }
543
 
        }
544
 
      else if (type == GEIS_TYPE_PINCH)
545
 
        {
546
 
          pinch.id      = id;
547
 
          gint fingers = pinch_gesture_handle_properties (&pinch,
548
 
                                                          attr_count,
549
 
                                                          attrs);
550
 
 
551
 
          switch (fingers)
552
 
            {
553
 
            case 1:
554
 
              pinch.type = GROPE_GESTURE_PINCH1;
555
 
              break;
556
 
 
557
 
            case 2:
558
 
              pinch.type = GROPE_GESTURE_PINCH2;
559
 
              break;
560
 
 
561
 
            case 3:
562
 
              pinch.type = GROPE_GESTURE_PINCH3;
563
 
              break;
564
 
 
565
 
            case 4:
566
 
              pinch.type = GROPE_GESTURE_PINCH4;
567
 
              break;
568
 
 
569
 
            case 5:
570
 
              pinch.type = GROPE_GESTURE_PINCH5;
571
 
              break;
572
 
 
573
 
            default:
574
 
              break;
575
 
            }
576
 
 
577
 
          if (fingers == binding->touches)
578
 
            {
579
 
              binding->update (reg->window,
580
 
                               pinch.type,
581
 
                               ((GropeGestureEvent*)&pinch));
582
 
            }
583
 
        }
584
 
      else if (type == GRAIL_TYPE_ROTATE1)
585
 
        {
586
 
          rotate.id      = id;
587
 
          gint fingers = rotate_gesture_handle_properties (&rotate,
588
 
                                                           attr_count,
589
 
                                                           attrs);
590
 
 
591
 
          switch (fingers)
592
 
            {
593
 
            case 1:
594
 
              rotate.type = GROPE_GESTURE_ROTATE1;
595
 
              break;
596
 
 
597
 
            case 2:
598
 
              rotate.type = GROPE_GESTURE_ROTATE2;
599
 
              break;
600
 
 
601
 
            case 3:
602
 
              rotate.type = GROPE_GESTURE_ROTATE3;
603
 
              break;
604
 
 
605
 
            case 4:
606
 
              rotate.type = GROPE_GESTURE_ROTATE4;
607
 
              break;
608
 
 
609
 
            case 5:
610
 
              rotate.type = GROPE_GESTURE_ROTATE5;
611
 
              break;
612
 
 
613
 
            default:
614
 
              break;
615
 
            }
616
 
 
617
 
          if (fingers == binding->touches)
618
 
            {
619
 
              binding->update (reg->window,
620
 
                               rotate.type,
621
 
                               ((GropeGestureEvent*)&rotate));
622
 
            }
 
431
          if (type == GROPE_GESTURE_DRAG)
 
432
            {
 
433
              GropeEventGestureDrag drag;
 
434
 
 
435
              drag.type    = type;
 
436
              drag.id      = id;
 
437
              drag.fingers = drag_gesture_handle_properties (&drag,
 
438
                                                             attr_count,
 
439
                                                             attrs);
 
440
 
 
441
              if (drag.fingers == binding->touches)
 
442
                {
 
443
                  binding->update (reg->window,
 
444
                                   ((GropeGestureEvent*)&drag),
 
445
                                   binding->data);
 
446
                }
 
447
            }
 
448
          else if (type == GROPE_GESTURE_PINCH)
 
449
            {
 
450
              GropeEventGesturePinch pinch;
 
451
 
 
452
              pinch.type    = type;
 
453
              pinch.id      = id;
 
454
              pinch.fingers = pinch_gesture_handle_properties (&pinch,
 
455
                                                               attr_count,
 
456
                                                               attrs);
 
457
 
 
458
              if (pinch.fingers == binding->touches)
 
459
                {
 
460
                  binding->update (reg->window,
 
461
                                   ((GropeGestureEvent*)&pinch),
 
462
                                   binding->data);
 
463
                }
 
464
            }
 
465
          else if (type == GROPE_GESTURE_ROTATE)
 
466
            {
 
467
              GropeEventGestureRotate rotate;
 
468
 
 
469
              rotate.type    = type;
 
470
              rotate.id      = id;
 
471
              rotate.fingers = rotate_gesture_handle_properties (&rotate,
 
472
                                                                 attr_count,
 
473
                                                                 attrs);
 
474
 
 
475
              if (rotate.fingers == binding->touches)
 
476
                {
 
477
                  binding->update (reg->window,
 
478
                                   ((GropeGestureEvent*)&rotate),
 
479
                                   binding->data);
 
480
                }
 
481
            }
623
482
        }
624
483
    }
625
484
}
637
496
  for (l = reg->bindings; l != NULL; l = l->next)
638
497
    {
639
498
      GropeGestureBinding *binding = (GropeGestureBinding *)l->data;
640
 
      GropeEventGestureDrag drag;
641
 
      GropeEventGesturePinch pinch;
642
 
      GropeEventGestureRotate rotate;
643
499
 
644
 
      if (type == GEIS_TYPE_DRAG)
 
500
      if (binding->type == type)
645
501
        {
646
 
          drag.type = type;
647
 
          drag.id = id;
648
 
          drag.fingers = drag_gesture_handle_properties (&drag, attr_count, attrs);
649
 
 
650
 
          if (drag.fingers == binding->touches)
651
 
            {
652
 
              binding->end (reg->window,
653
 
                            type,
654
 
                            ((GropeGestureEvent*)&drag));
655
 
            }
656
 
        }
657
 
      else if (type == GEIS_TYPE_PINCH)
658
 
        {
659
 
          pinch.type    = type;
660
 
          pinch.id      = id;
661
 
          pinch.fingers = pinch_gesture_handle_properties (&pinch,
662
 
                                                           attr_count,
663
 
                                                           attrs);
664
 
 
665
 
          if (pinch.fingers == binding->touches)
666
 
            {
667
 
              binding->end (reg->window,
668
 
                            type,
669
 
                            ((GropeGestureEvent*)&pinch));
670
 
            }
671
 
        }
672
 
      else if (type == GEIS_TYPE_ROTATE)
673
 
        {
674
 
          rotate.type    = type;
675
 
          rotate.id      = id;
676
 
          rotate.fingers = rotate_gesture_handle_properties (&rotate,
677
 
                                                             attr_count,
678
 
                                                             attrs);
679
 
 
680
 
          if (rotate.fingers == binding->touches)
681
 
            {
682
 
              binding->end (reg->window,
683
 
                            type,
684
 
                            ((GropeGestureEvent*)&rotate));
685
 
            }
 
502
          if (type == GROPE_GESTURE_DRAG)
 
503
            {
 
504
              GropeEventGestureDrag drag;
 
505
 
 
506
              drag.type    = type;
 
507
              drag.id      = id;
 
508
              drag.fingers = drag_gesture_handle_properties (&drag,
 
509
                                                             attr_count,
 
510
                                                             attrs);
 
511
 
 
512
              if (drag.fingers == binding->touches)
 
513
                {
 
514
                  binding->end (reg->window,
 
515
                                ((GropeGestureEvent*)&drag),
 
516
                                binding->data);
 
517
                }
 
518
            }
 
519
          else if (type == GROPE_GESTURE_PINCH)
 
520
            {
 
521
              GropeEventGesturePinch pinch;
 
522
 
 
523
              pinch.type    = type;
 
524
              pinch.id      = id;
 
525
              pinch.fingers = pinch_gesture_handle_properties (&pinch,
 
526
                                                               attr_count,
 
527
                                                               attrs);
 
528
 
 
529
              if (pinch.fingers == binding->touches)
 
530
                {
 
531
                  binding->end (reg->window,
 
532
                                ((GropeGestureEvent*)&pinch),
 
533
                                binding->data);
 
534
                }
 
535
            }
 
536
          else if (type == GROPE_GESTURE_ROTATE)
 
537
            {
 
538
              GropeEventGestureRotate rotate;
 
539
 
 
540
              rotate.type    = type;
 
541
              rotate.id      = id;
 
542
              rotate.fingers = rotate_gesture_handle_properties (&rotate,
 
543
                                                                 attr_count,
 
544
                                                                 attrs);
 
545
 
 
546
              if (rotate.fingers == binding->touches)
 
547
                {
 
548
                  binding->end (reg->window,
 
549
                                ((GropeGestureEvent*)&rotate),
 
550
                                binding->data);
 
551
                }
 
552
            }
686
553
        }
687
554
    }
688
555
}
722
589
    {
723
590
      GropeGestureBinding *binding = (GropeGestureBinding *)list->data;
724
591
 
 
592
      if (binding->destroy)
 
593
        {
 
594
          GDestroyNotify d = binding->destroy;
 
595
 
 
596
          d (binding->data);
 
597
        }
 
598
 
725
599
      g_free (binding);
726
600
    }
727
601
 
743
617
  return g_object_new (GROPE_TYPE_GESTURE_MANAGER, NULL);
744
618
}
745
619
 
746
 
static int
747
 
bit_count (unsigned int u)
748
 
{
749
 
  unsigned int uCount;
750
 
 
751
 
  uCount = u - ((u >> 1) & 033333333333) - ((u >> 2) & 011111111111);
752
 
  return ((uCount + (uCount >> 3)) & 030707070707) % 63;
753
 
}
754
 
 
755
 
 
756
620
/**
757
621
 * grope_gesture_manager_register_window:
758
622
 * @window: A #GtkWindow to register the gesture event for.
761
625
 * @start: Called when a user initiates a gesture.
762
626
 * @update: Called each time the user updates the gesture.
763
627
 * @end: Called when the user ends the gesture.
 
628
 * @user_data: User data
 
629
 * @destroy: Destroy callback for user data.
764
630
 *
765
631
 * Registers a toplevel window to receive gesture events.
766
632
 * The callback parameters provided will be called by the
771
637
grope_gesture_manager_register_window (GropeGestureManager *manager,
772
638
                                       GtkWindow           *window,
773
639
                                       GropeGestureType     gesture_type,
 
640
                                       gint                 touch_points,
774
641
                                       GropeGestureCallback start,
775
642
                                       GropeGestureCallback update,
776
 
                                       GropeGestureCallback end)
 
643
                                       GropeGestureCallback end,
 
644
                                       gpointer             user_data,
 
645
                                       GDestroyNotify       destroy)
777
646
{
778
647
  GropeGestureManagerPrivate *priv;
779
648
  GropeGestureRegistration *reg;
780
649
  GropeGestureBinding *binding;
781
 
  gint i;
782
650
 
783
651
  g_return_if_fail (GROPE_IS_GESTURE_MANAGER (manager));
784
652
  g_return_if_fail (GTK_IS_WINDOW (window));
847
715
      reg->iochannel = iochannel;
848
716
    }
849
717
 
850
 
  for (i = 0; i < bit_count (gesture_type); i++)
851
 
    {
852
 
      binding = g_new0 (GropeGestureBinding, 1);
853
 
 
854
 
      binding->start   = start;
855
 
      binding->update  = update;
856
 
      binding->end     = end;
857
 
 
858
 
      if (gesture_type & GROPE_GESTURE_DRAG1)
859
 
        {
860
 
          binding->type    = GEIS_TYPE_DRAG;
861
 
          binding->touches = 1;
862
 
        }
863
 
      else if (gesture_type & GROPE_GESTURE_DRAG2)
864
 
        {
865
 
          gesture_type ^= GROPE_GESTURE_DRAG2;
866
 
          binding->type    = GEIS_TYPE_DRAG;
867
 
          binding->touches = 2;
868
 
        }
869
 
      else if (gesture_type & GROPE_GESTURE_DRAG3)
870
 
        {
871
 
          binding->type    = GEIS_TYPE_DRAG;
872
 
          binding->touches = 3;
873
 
        }
874
 
      else if (gesture_type & GROPE_GESTURE_DRAG4)
875
 
        {
876
 
          binding->type    = GEIS_TYPE_DRAG;
877
 
          binding->touches = 4;
878
 
        }
879
 
      else if (gesture_type & GROPE_GESTURE_DRAG5)
880
 
        {
881
 
          binding->type    = GEIS_TYPE_DRAG;
882
 
          binding->touches = 5;
883
 
        }
884
 
      else if (gesture_type & GROPE_GESTURE_PINCH1)
885
 
        {
886
 
          binding->type    = GEIS_TYPE_PINCH;
887
 
          binding->touches = 1;
888
 
        }
889
 
      else if (gesture_type & GROPE_GESTURE_PINCH2)
890
 
        {
891
 
          gesture_type ^= GROPE_GESTURE_PINCH2;
892
 
          binding->type    = GEIS_TYPE_PINCH;
893
 
          binding->touches = 2;
894
 
        }
895
 
      else if (gesture_type & GROPE_GESTURE_PINCH3)
896
 
        {
897
 
          binding->type    = GEIS_TYPE_PINCH;
898
 
          binding->touches = 3;
899
 
        }
900
 
      else if (gesture_type & GROPE_GESTURE_PINCH4)
901
 
        {
902
 
          binding->type    = GEIS_TYPE_PINCH;
903
 
          binding->touches = 4;
904
 
        }
905
 
      else if (gesture_type & GROPE_GESTURE_PINCH5)
906
 
        {
907
 
          binding->type    = GEIS_TYPE_PINCH;
908
 
          binding->touches = 5;
909
 
        }
910
 
      else if (gesture_type & GROPE_GESTURE_ROTATE1)
911
 
        {
912
 
          binding->type    = GEIS_TYPE_ROTATE;
913
 
          binding->touches = 1;
914
 
        }
915
 
      else if (gesture_type & GROPE_GESTURE_ROTATE2)
916
 
        {
917
 
          gesture_type ^= GROPE_GESTURE_ROTATE2;
918
 
          binding->type    = GEIS_TYPE_ROTATE;
919
 
          binding->touches = 2;
920
 
        }
921
 
      else if (gesture_type & GROPE_GESTURE_ROTATE3)
922
 
        {
923
 
          binding->type    = GEIS_TYPE_ROTATE;
924
 
          binding->touches = 3;
925
 
        }
926
 
      else if (gesture_type & GROPE_GESTURE_ROTATE4)
927
 
        {
928
 
          binding->type    = GEIS_TYPE_ROTATE;
929
 
          binding->touches = 4;
930
 
        }
931
 
      else if (gesture_type & GROPE_GESTURE_ROTATE5)
932
 
        {
933
 
          binding->type    = GEIS_TYPE_ROTATE;
934
 
          binding->touches = 5;
935
 
        }
936
 
 
937
 
      /* XXX - check for duplicates in reg->bindings first */
938
 
 
939
 
      reg->bindings = g_list_append (reg->bindings, binding);
940
 
 
941
 
      g_hash_table_insert (priv->hash,
942
 
                           window,
943
 
                           reg);
944
 
    }
 
718
  /* XXX - check for duplicates in reg->bindings first */
 
719
  binding = g_new0 (GropeGestureBinding, 1);
 
720
 
 
721
  binding->type    = gesture_type;
 
722
  binding->touches = touch_points;
 
723
  binding->start   = start;
 
724
  binding->update  = update;
 
725
  binding->end     = end;
 
726
  binding->data    = user_data;
 
727
  binding->destroy = destroy;
 
728
 
 
729
  reg->bindings = g_list_append (reg->bindings, binding);
 
730
 
 
731
  g_hash_table_insert (priv->hash,
 
732
                       window,
 
733
                       reg);
945
734
}