~unity-team/unity/trunk

« back to all changes in this revision

Viewing changes to src/Launcher.cpp

  • Committer: macslow at bangang
  • Date: 2011-02-21 13:21:49 UTC
  • mfrom: (873 unity)
  • mto: This revision was merged to the branch mainline in revision 875.
  • Revision ID: macslow@bangang.de-20110221132149-jwv3muizq73cqzcs
Re-merge with unity trunk again... fixed merge-conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
 
56
56
int
57
57
TimeDelta (struct timespec const *x, struct timespec const *y)
58
 
 
59
58
{
60
59
  return ((x->tv_sec - y->tv_sec) * 1000) + ((x->tv_nsec - y->tv_nsec) / 1000000);
61
60
}
62
61
 
 
62
void SetTimeBack (struct timespec *timeref, int remove)
 
63
{
 
64
  timeref->tv_sec -= remove / 1000;
 
65
  remove = remove % 1000;
 
66
 
 
67
  if (remove > timeref->tv_nsec / 1000000)
 
68
  {
 
69
      timeref->tv_sec--;
 
70
      timeref->tv_nsec += 1000000000;
 
71
  }
 
72
  timeref->tv_nsec -= remove * 1000000;
 
73
}
 
74
 
 
75
 
63
76
/*
64
77
                Use this shader to pass vertices in screen coordinates in the C++ code and compute use
65
78
                the fragment shader to perform the texture perspective correct division.
447
460
float Launcher::AutohideProgress (struct timespec const &current)
448
461
{
449
462
    
450
 
    // bfb position progress
451
 
    if (_mouse_inside_trigger)
 
463
    // bfb position progress. Go from GetAutohidePositionMin() -> GetAutohidePositionMax() linearly
 
464
    if (_mouse_inside_trigger && !_mouseover_launcher_locked)
452
465
    {
453
 
        /* 
 
466
        
 
467
        // "dead" zone
 
468
        if ((_trigger_mouse_position.x < 2) && (_trigger_mouse_position.y < 2))
 
469
            return GetAutohidePositionMin ();
 
470
        
 
471
       /* 
454
472
        * most of the mouse movement should be done by the inferior part
455
473
        * of the launcher, so prioritize this one
456
474
        */
457
 
        
458
 
        if(_mouseover_launcher_locked || ((_trigger_mouse_position.x == 0) && (_trigger_mouse_position.y == 0)))
459
 
            return 0.0f;
460
 
        
 
475
                
461
476
        float _max_size_on_position;
462
477
        float position_on_border = _trigger_mouse_position.x * _trigger_height / _trigger_mouse_position.y;
463
478
        
469
484
            _max_size_on_position = pow(pow(position_on_border, 2) + pow(_trigger_width, 2), 0.5);
470
485
        }
471
486
        // only triggered on _hidden = false, no need for check
472
 
        return CLAMP (pow(pow(_trigger_mouse_position.x, 2) + pow(_trigger_mouse_position.y, 2), 0.5) / _max_size_on_position, 0.0f, 1.0f);  
 
487
        float _position_min = GetAutohidePositionMin ();
 
488
        return pow(pow(_trigger_mouse_position.x, 2) + pow(_trigger_mouse_position.y, 2), 0.5) / _max_size_on_position * (GetAutohidePositionMax () - _position_min) + _position_min;
473
489
    }
474
490
    
475
 
    // time-based progress
 
491
    // time-based progress (full scale or finish the TRIGGER_AUTOHIDE_MIN -> 0.00f on bfb)
476
492
    else
477
493
    {
478
 
        float animation_progress;    
 
494
        float animation_progress;
479
495
        animation_progress = CLAMP ((float) (TimeDelta (&current, &_times[TIME_AUTOHIDE])) / (float) ANIM_DURATION_SHORT, 0.0f, 1.0f);
480
496
        if (_hidden)
481
497
            return animation_progress;
618
634
        if (diff < sister_relation)
619
635
        {
620
636
            int remove = sister_relation - diff;
621
 
            current.tv_sec -= remove / 1000;
622
 
            remove = remove % 1000;
623
 
 
624
 
            if (remove > current.tv_nsec / 1000000)
625
 
            {
626
 
                current.tv_sec--;
627
 
                current.tv_nsec += 1000000000;
628
 
            }
629
 
            current.tv_nsec -= remove * 1000000;
 
637
            SetTimeBack (&current, remove);
630
638
        }
631
639
    }
632
640
 
633
641
    timer->tv_sec = current.tv_sec;
634
642
    timer->tv_nsec = current.tv_nsec;
635
643
}
 
644
/* Min is when you lock the trigger */
 
645
float Launcher::GetAutohidePositionMin ()
 
646
{
 
647
    if (_autohide_animation == SLIDE_ONLY)
 
648
        return 0.55f;
 
649
    else
 
650
        return 0.25f;
 
651
}
 
652
/* Max is the initial state */
 
653
float Launcher::GetAutohidePositionMax ()
 
654
{
 
655
    if (_autohide_animation == SLIDE_ONLY)
 
656
        return 1.00f;
 
657
    else
 
658
        return 0.75f;
 
659
}
 
660
 
636
661
 
637
662
float IconVisibleProgress (LauncherIcon *icon, struct timespec const &current)
638
663
{
1070
1095
 
1071
1096
        if (_autohide_animation == FADE_ONLY
1072
1097
            || (_autohide_animation == FADE_SLIDE && _mouse_inside_trigger))
1073
 
        {
1074
 
            if (autohide_progress > 0.0f)
1075
 
            {    
1076
 
                if (_mouse_inside_trigger)
1077
 
                {
1078
 
                    if (!_mouseover_launcher_locked)
1079
 
                        *launcher_alpha = 1.0f - (autohide_progress / 1.5f);
1080
 
                }
1081
 
                else
1082
 
                    *launcher_alpha = 1.0f - autohide_progress;
1083
 
            }
1084
 
        }
 
1098
            *launcher_alpha = 1.0f - autohide_progress;
1085
1099
        else
1086
1100
        {
1087
1101
            if (autohide_progress > 0.0f)
1091
1105
        * as we can go back and for. We have to lock the launcher manually changing
1092
1106
        * the _hidden state then
1093
1107
        */
1094
 
        if (autohide_progress == 0.0f && _mouse_inside_trigger && !_mouseover_launcher_locked)
 
1108
        float _position_min = GetAutohidePositionMin ();
 
1109
        if (autohide_progress == _position_min && _mouse_inside_trigger && !_mouseover_launcher_locked)
 
1110
        {
1095
1111
            ForceHiddenState (false); // lock the launcher
 
1112
            _times[TIME_AUTOHIDE] = current;
 
1113
            SetTimeBack (&_times[TIME_AUTOHIDE], ANIM_DURATION_SHORT * _position_min);
 
1114
            SetTimeStruct (&_times[TIME_AUTOHIDE], &_times[TIME_AUTOHIDE], ANIM_DURATION_SHORT); // finish the animation 
 
1115
        }
1096
1116
    }
1097
1117
    
1098
1118
    float drag_hide_progress = DragHideProgress (current);
2380
2400
}
2381
2401
 
2382
2402
void
 
2403
Launcher::CheckSuperShortcutPressed (unsigned int key_sym,
 
2404
                                     unsigned long key_code,
 
2405
                                     unsigned long key_state)
 
2406
{
 
2407
  if (_super_show_launcher)
 
2408
    RecvKeyPressed (key_sym, key_code, key_state);
 
2409
}
 
2410
 
 
2411
void
2383
2412
Launcher::RecvKeyPressed (unsigned int  key_sym,
2384
2413
                          unsigned long key_code,
2385
2414
                          unsigned long key_state)
2386
2415
{
2387
2416
 
 
2417
  LauncherModel::iterator it;
 
2418
  
2388
2419
  switch (key_sym)
2389
2420
  {
2390
2421
    // up (move selection up or go to global-menu if at top-most icon)
2420
2451
      if (key_state & NUX_STATE_SHIFT)
2421
2452
      {
2422
2453
        {
2423
 
          LauncherModel::iterator it;
2424
 
          int i;
2425
 
 
2426
2454
          // open quicklist of currently selected icon
2427
 
          for (it = _model->begin (), i = 0; it != _model->end (); it++, i++)
2428
 
            if (i == _current_icon_index)
2429
 
              (*it)->OpenQuicklist (true);
 
2455
          it = _model->at (_current_icon_index);
 
2456
          if (it != (LauncherModel::iterator)NULL)
 
2457
            (*it)->OpenQuicklist (true);
2430
2458
        }
2431
2459
        leaveKeyNavMode ();
2432
2460
      }
2434
2462
 
2435
2463
    case NUX_VK_RIGHT:
2436
2464
      {
2437
 
        LauncherModel::iterator it;
2438
 
        int i;
2439
 
 
2440
2465
        // open quicklist of currently selected icon
2441
 
        for (it = _model->begin (), i = 0; it != _model->end (); it++, i++)
2442
 
          if (i == _current_icon_index)
2443
 
            (*it)->OpenQuicklist (true);
 
2466
        it = _model->at (_current_icon_index);
 
2467
        if (it != (LauncherModel::iterator)NULL)
 
2468
          (*it)->OpenQuicklist (true);
2444
2469
      }
2445
2470
      leaveKeyNavMode ();
2446
2471
    break;
2448
2473
    // <SPACE> (open a new instance)
2449
2474
    case NUX_VK_SPACE:
2450
2475
      {
2451
 
        LauncherModel::iterator it;
2452
 
        int i;
2453
 
 
2454
2476
        // start currently selected icon
2455
 
        for (it = _model->begin (), i = 0; it != _model->end (); it++, i++)
2456
 
          if (i == _current_icon_index)
2457
 
            (*it)->OpenInstance ();
 
2477
        it = _model->at (_current_icon_index);
 
2478
        if (it != (LauncherModel::iterator)NULL)
 
2479
          (*it)->OpenInstance ();
2458
2480
      }
2459
2481
      leaveKeyNavMode ();
2460
2482
      break;
2462
2484
    // <RETURN> (start/activate currently selected icon)
2463
2485
    case NUX_VK_ENTER:
2464
2486
      {
2465
 
        LauncherModel::iterator it;
2466
 
        int i;
2467
 
 
2468
2487
        // start currently selected icon
2469
 
        for (it = _model->begin (), i = 0; it != _model->end (); it++, i++)
2470
 
          if (i == _current_icon_index)
2471
 
            (*it)->Activate ();
 
2488
        it = _model->at (_current_icon_index);
 
2489
        if (it != (LauncherModel::iterator)NULL)
 
2490
          (*it)->Activate ();
2472
2491
      }
2473
2492
      leaveKeyNavMode ();
2474
2493
    break;
2475
2494
 
 
2495
    // Shortcuts to launch applications
 
2496
    case XK_0:
 
2497
      {
 
2498
        it = _model->at (9);
 
2499
        if (it != (LauncherModel::iterator)NULL)
 
2500
          (*it)->Activate ();
 
2501
        break;
 
2502
      }
 
2503
    case XK_1:
 
2504
      {
 
2505
        it = _model->at (0);
 
2506
        if (it != (LauncherModel::iterator)NULL)
 
2507
          (*it)->Activate ();
 
2508
        break;
 
2509
      }
 
2510
    case XK_2:
 
2511
      {
 
2512
        it = _model->at (1);
 
2513
        if (it != (LauncherModel::iterator)NULL)
 
2514
          (*it)->Activate ();
 
2515
        break;
 
2516
      }
 
2517
    case XK_3:
 
2518
      {
 
2519
        it = _model->at (2);
 
2520
        if (it != (LauncherModel::iterator)NULL)
 
2521
          (*it)->Activate ();
 
2522
        break;
 
2523
      }
 
2524
    case XK_4:
 
2525
      {
 
2526
        it = _model->at (3);
 
2527
        if (it != (LauncherModel::iterator)NULL)
 
2528
          (*it)->Activate ();
 
2529
        break;
 
2530
      }
 
2531
    case XK_5:
 
2532
      {
 
2533
        it = _model->at (4);
 
2534
        if (it != (LauncherModel::iterator)NULL)
 
2535
          (*it)->Activate ();
 
2536
        break;
 
2537
      }
 
2538
    case XK_6:
 
2539
      {
 
2540
        it = _model->at (5);
 
2541
        if (it != (LauncherModel::iterator)NULL)
 
2542
          (*it)->Activate ();
 
2543
        break;
 
2544
      }
 
2545
    case XK_7:
 
2546
      {
 
2547
        it = _model->at (6);
 
2548
        if (it != (LauncherModel::iterator)NULL)
 
2549
          (*it)->Activate ();
 
2550
        break;
 
2551
      }
 
2552
    case XK_8:
 
2553
      {
 
2554
        it = _model->at (7);
 
2555
        if (it != (LauncherModel::iterator)NULL)
 
2556
          (*it)->Activate ();
 
2557
        break;
 
2558
      }
 
2559
    case XK_9:
 
2560
      {
 
2561
        it = _model->at (8);
 
2562
        if (it != (LauncherModel::iterator)NULL)
 
2563
          (*it)->Activate ();
 
2564
        break;
 
2565
      }
 
2566
      
2476
2567
    default:
2477
2568
    break;
2478
2569
  }