~brandontschaefer/unity/fix-915828

« back to all changes in this revision

Viewing changes to plugins/unityshell/src/LauncherIcon.cpp

  • Committer: Brandon Schaefer
  • Date: 2012-02-02 04:05:22 UTC
  • mfrom: (1827.1.59 unity)
  • Revision ID: brandontschaefer@gmail.com-20120202040522-r86246d1fxmclh4p
merged

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
#include "CairoTexture.h"
34
34
#include "LauncherIcon.h"
35
35
#include "Launcher.h"
 
36
#include "TimeUtil.h"
36
37
 
37
38
#include "QuicklistManager.h"
38
39
#include "QuicklistMenuItem.h"
69
70
 
70
71
int LauncherIcon::_current_theme_is_mono = -1;
71
72
GtkIconTheme* LauncherIcon::_unity_theme = NULL;
72
 
gboolean LauncherIcon::_skip_tooltip_delay = false;
73
73
 
74
 
LauncherIcon::LauncherIcon(Launcher* launcher)
75
 
  : _launcher(launcher)
76
 
  , _menuclient_dynamic_quicklist(nullptr)
77
 
  , _has_visible_window(false)
 
74
LauncherIcon::LauncherIcon()
 
75
  : _menuclient_dynamic_quicklist(nullptr)
78
76
  , _quicklist_is_initialized(false)
79
77
  , _remote_urgent(false)
80
78
  , _present_urgency(0)
82
80
  , _center_stabilize_handle(0)
83
81
  , _present_time_handle(0)
84
82
  , _time_delay_handle(0)
85
 
  , _tooltip_delay_handle(0)
86
 
  , _related_windows(0)
87
83
  , _sort_priority(0)
88
84
  , _background_color(nux::color::White)
89
85
  , _glow_color(nux::color::White)
90
86
  , _shortcut(0)
91
87
  , _icon_type(TYPE_NONE)
92
88
{
 
89
  _has_visible_window.resize(max_num_monitors);
 
90
  _center.resize(max_num_monitors);
 
91
  _saved_center.resize(max_num_monitors);
 
92
  _last_stable.resize(max_num_monitors);
 
93
  _parent_geo.resize(max_num_monitors);
 
94
  transform_map.resize(max_num_monitors);
 
95
 
93
96
  for (int i = 0; i < QUIRK_LAST; i++)
94
97
  {
95
98
    _quirks[i] = false;
141
144
    g_source_remove(_time_delay_handle);
142
145
  _time_delay_handle = 0;
143
146
 
144
 
  if (_tooltip_delay_handle)
145
 
    g_source_remove(_tooltip_delay_handle);
146
 
  _tooltip_delay_handle = 0;
147
147
  // clean up the whole signal-callback mess
148
148
  if (needs_redraw_connection.connected())
149
149
    needs_redraw_connection.disconnect();
168
168
}
169
169
 
170
170
const bool
171
 
LauncherIcon::HasWindowOnViewport()
 
171
LauncherIcon::WindowVisibleOnMonitor(int monitor)
172
172
{
173
 
  return _has_visible_window;
 
173
  return _has_visible_window[monitor];
174
174
}
175
175
 
176
176
std::string
183
183
LauncherIcon::AddProperties(GVariantBuilder* builder)
184
184
{
185
185
  unity::variant::BuilderWrapper(builder)
186
 
  .add("x", _center.x)
187
 
  .add("y", _center.y)
188
 
  .add("z", _center.z)
189
 
  .add("related-windows", _related_windows)
 
186
  .add("x", _center[0].x)
 
187
  .add("y", _center[0].y)
 
188
  .add("z", _center[0].z)
 
189
  .add("related-windows", (int)Windows().size())
190
190
  .add("icon-type", _icon_type)
191
191
  .add("tooltip-text", tooltip_text().c_str())
192
192
  .add("sort-priority", _sort_priority)
206
206
    WindowManager::Default()->TerminateScale();
207
207
 
208
208
  ActivateLauncherIcon(arg);
 
209
 
 
210
  UpdateQuirkTime(QUIRK_LAST_ACTION);
209
211
}
210
212
 
211
213
void
215
217
    WindowManager::Default()->TerminateScale();
216
218
 
217
219
  OpenInstanceLauncherIcon(arg);
 
220
 
 
221
  UpdateQuirkTime(QUIRK_LAST_ACTION);
218
222
}
219
223
 
220
224
nux::Color LauncherIcon::BackgroundColor()
479
483
}
480
484
 
481
485
void
482
 
LauncherIcon::SetSkipTooltipDelay(gboolean skip_tooltip_delay)
483
 
{
484
 
  _skip_tooltip_delay = skip_tooltip_delay;
485
 
}
486
 
 
487
 
gboolean
488
 
LauncherIcon::OnTooltipTimeout(gpointer data)
489
 
{
490
 
  LauncherIcon* self = (LauncherIcon*) data;
491
 
 
492
 
  if (!self->_launcher)
493
 
    return FALSE;
494
 
 
495
 
  nux::Geometry geo = self->_launcher->GetAbsoluteGeometry();
496
 
  int tip_x = geo.x + geo.width + 1;
497
 
  int tip_y = geo.y + self->_center.y;
498
 
 
499
 
  self->_tooltip->ShowTooltipWithTipAt(tip_x, tip_y);
500
 
 
501
 
  if (!self->_quicklist->IsVisible())
 
486
LauncherIcon::ShowTooltip()
 
487
{
 
488
  if (_quicklist->IsVisible())
 
489
    return;
 
490
 
 
491
  int tip_x = 100;
 
492
  int tip_y = 100;
 
493
  if (_last_monitor >= 0)
502
494
  {
503
 
    self->_tooltip->ShowWindow(!self->tooltip_text().empty());
504
 
    _skip_tooltip_delay = TRUE;
 
495
    nux::Geometry geo = _parent_geo[_last_monitor];
 
496
    tip_x = geo.x + geo.width + 1;
 
497
    tip_y = geo.y + _center[_last_monitor].y;
505
498
  }
506
499
 
507
 
  self->_tooltip_delay_handle = 0;
508
 
  return FALSE;
 
500
  _tooltip->ShowTooltipWithTipAt(tip_x, tip_y);
 
501
  _tooltip->ShowWindow(!tooltip_text().empty());
509
502
}
510
503
 
511
504
void
512
 
LauncherIcon::RecvMouseEnter()
 
505
LauncherIcon::RecvMouseEnter(int monitor)
513
506
{
 
507
  _last_monitor = monitor;
514
508
  if (QuicklistManager::Default()->Current())
515
509
  {
516
510
    // A quicklist is active
517
511
    return;
518
512
  }
519
513
 
520
 
  if (!_skip_tooltip_delay)
521
 
    _tooltip_delay_handle = g_timeout_add(500, &LauncherIcon::OnTooltipTimeout, this);
522
 
  else
523
 
    OnTooltipTimeout(this);
 
514
  ShowTooltip();
524
515
}
525
516
 
526
 
void LauncherIcon::RecvMouseLeave()
 
517
void LauncherIcon::RecvMouseLeave(int monitor)
527
518
{
528
 
  if (_tooltip_delay_handle)
529
 
    g_source_remove(_tooltip_delay_handle);
530
 
  _tooltip_delay_handle = 0;
 
519
  _last_monitor = -1;
531
520
 
532
521
  _tooltip->ShowWindow(false);
533
522
}
534
523
 
535
 
bool LauncherIcon::OpenQuicklist(bool default_to_first_item)
 
524
bool LauncherIcon::OpenQuicklist(bool default_to_first_item, int monitor)
536
525
{
537
526
  std::list<DbusmenuMenuitem*> menus = Menus();
538
527
 
539
528
  if (menus.empty())
540
529
    return false;
541
530
 
542
 
  if (_tooltip_delay_handle)
543
 
    g_source_remove(_tooltip_delay_handle);
544
 
  _tooltip_delay_handle = 0;
545
 
  _skip_tooltip_delay = false;
546
 
 
547
531
  _tooltip->ShowWindow(false);
548
532
  _quicklist->RemoveAllMenuItem();
549
533
 
582
566
  if (default_to_first_item)
583
567
    _quicklist->DefaultToFirstItem();
584
568
 
585
 
  int tip_x, tip_y;
586
 
  if (_launcher)
587
 
  {
588
 
    nux::Geometry geo = _launcher->GetAbsoluteGeometry();
589
 
    tip_x = geo.x + geo.width + 1;
590
 
    tip_y = geo.y + _center.y;
591
 
  }
592
 
  else
593
 
  {
594
 
    tip_x = 0;
595
 
    tip_y = _center.y;
596
 
  }
 
569
  if (monitor < 0)
 
570
  {
 
571
    if (_last_monitor >= 0)
 
572
      monitor = _last_monitor;
 
573
    else
 
574
      monitor = 0;
 
575
  }
 
576
 
 
577
  nux::Geometry geo = _parent_geo[monitor];
 
578
  int tip_x = geo.x + geo.width + 1;
 
579
  int tip_y = geo.y + _center[monitor].y; 
597
580
 
598
581
  auto win_manager = WindowManager::Default();
599
582
 
617
600
  return true;
618
601
}
619
602
 
620
 
void LauncherIcon::RecvMouseDown(int button)
 
603
void LauncherIcon::RecvMouseDown(int button, int monitor)
621
604
{
622
605
  if (button == 3)
623
606
    OpenQuicklist();
624
607
}
625
608
 
626
 
void LauncherIcon::RecvMouseUp(int button)
 
609
void LauncherIcon::RecvMouseUp(int button, int monitor)
627
610
{
628
611
  if (button == 3)
629
612
  {
632
615
  }
633
616
}
634
617
 
635
 
void LauncherIcon::RecvMouseClick(int button)
 
618
void LauncherIcon::RecvMouseClick(int button, int monitor)
636
619
{
637
620
  ActionArg arg(ActionArg::LAUNCHER, button);
 
621
  arg.monitor = monitor;
 
622
  
638
623
  if (button == 1)
639
624
    Activate(arg);
640
625
  else if (button == 2)
643
628
 
644
629
void LauncherIcon::HideTooltip()
645
630
{
646
 
  if (_tooltip_delay_handle)
647
 
    g_source_remove(_tooltip_delay_handle);
648
 
  _tooltip_delay_handle = 0;
649
 
  _skip_tooltip_delay = false;
650
 
 
651
631
  _tooltip->ShowWindow(false);
652
632
}
653
633
 
656
636
{
657
637
  LauncherIcon* self = (LauncherIcon*)data;
658
638
 
659
 
  if (self->_last_stable != self->_center)
 
639
  if (!std::equal(self->_center.begin(), self->_center.end(), self->_last_stable.begin()))
660
640
  {
661
641
    self->OnCenterStabilized(self->_center);
662
642
    self->_last_stable = self->_center;
667
647
}
668
648
 
669
649
void
670
 
LauncherIcon::SetCenter(nux::Point3 center)
 
650
LauncherIcon::SetCenter(nux::Point3 center, int monitor, nux::Geometry geo)
671
651
{
672
 
  _center = center;
 
652
  _center[monitor] = center;
 
653
  _parent_geo[monitor] = geo;
673
654
 
674
 
  int tip_x, tip_y;
675
 
  if (_launcher)
 
655
  if (monitor == _last_monitor)
676
656
  {
677
 
    nux::Geometry geo = _launcher->GetAbsoluteGeometry();
 
657
    int tip_x, tip_y;
678
658
    tip_x = geo.x + geo.width + 1;
679
 
    tip_y = geo.y + _center.y;
680
 
  }
681
 
  else
682
 
  {
683
 
    tip_x = 0;
684
 
    tip_y = _center.y;
685
 
  }
 
659
    tip_y = geo.y + _center[monitor].y;
686
660
 
687
 
  if (_quicklist->IsVisible())
688
 
    QuicklistManager::Default()->ShowQuicklist(_quicklist, tip_x, tip_y);
689
 
  else if (_tooltip->IsVisible())
690
 
    _tooltip->ShowTooltipWithTipAt(tip_x, tip_y);
 
661
    if (_quicklist->IsVisible())
 
662
      QuicklistManager::Default()->ShowQuicklist(_quicklist, tip_x, tip_y);
 
663
    else if (_tooltip->IsVisible())
 
664
      _tooltip->ShowTooltipWithTipAt(tip_x, tip_y);
 
665
  }
691
666
 
692
667
  if (_center_stabilize_handle)
693
668
    g_source_remove(_center_stabilize_handle);
696
671
}
697
672
 
698
673
nux::Point3
699
 
LauncherIcon::GetCenter()
 
674
LauncherIcon::GetCenter(int monitor)
 
675
{
 
676
  return _center[monitor];
 
677
}
 
678
 
 
679
nux::Point3
 
680
LauncherIcon::GetSavedCenter(int monitor)
 
681
{
 
682
  return _saved_center[monitor];
 
683
}
 
684
 
 
685
std::vector<nux::Point3> LauncherIcon::GetCenters()
700
686
{
701
687
  return _center;
702
688
}
709
695
}
710
696
 
711
697
void
712
 
LauncherIcon::SetHasWindowOnViewport(bool val)
 
698
LauncherIcon::SetWindowVisibleOnMonitor(bool val, int monitor)
713
699
{
714
 
  if (_has_visible_window == val)
 
700
  if (_has_visible_window[monitor] == val)
715
701
    return;
716
702
 
717
 
  _has_visible_window = val;
 
703
  _has_visible_window[monitor] = val;
718
704
  needs_redraw.emit(this);
719
705
}
720
706
 
763
749
}
764
750
 
765
751
void
766
 
LauncherIcon::SetRelatedWindows(int windows)
767
 
{
768
 
  if (_related_windows == windows)
769
 
    return;
770
 
 
771
 
  _related_windows = windows;
772
 
  needs_redraw.emit(this);
773
 
}
774
 
 
775
 
void
776
752
LauncherIcon::Remove()
777
753
{
778
754
  if (_quicklist->IsVisible())
817
793
{
818
794
  if (_quirks[quirk] == value)
819
795
    return;
820
 
      
821
 
  if (quirk == QUIRK_PULSE_ONCE)
822
 
    _launcher->HideMachine()->SetQuirk(LauncherHideMachine::LAUNCHER_PULSE, value);
823
796
  
824
797
  _quirks[quirk] = value;
825
798
  if (quirk == QUIRK_VISIBLE)
826
 
    Launcher::SetTimeStruct(&(_quirk_times[quirk]), &(_quirk_times[quirk]), ANIM_DURATION_SHORT);
 
799
    TimeUtil::SetTimeStruct(&(_quirk_times[quirk]), &(_quirk_times[quirk]), ANIM_DURATION_SHORT);
827
800
  else
828
801
    clock_gettime(CLOCK_MONOTONIC, &(_quirk_times[quirk]));
829
802
  needs_redraw.emit(this);
887
860
  return _quirk_times[quirk];
888
861
}
889
862
 
890
 
int
891
 
LauncherIcon::RelatedWindows()
892
 
{
893
 
  return _related_windows;
894
 
}
895
 
 
896
863
void
897
864
LauncherIcon::SetProgress(float progress)
898
865
{
949
916
}
950
917
 
951
918
std::vector<nux::Vector4> &
952
 
LauncherIcon::GetTransform(TransformIndex index)
 
919
LauncherIcon::GetTransform(TransformIndex index, int monitor)
953
920
{
954
 
  auto iter = transform_map.find(index);
955
 
  if (iter == transform_map.end())
 
921
  auto iter = transform_map[monitor].find(index);
 
922
  if (iter == transform_map[monitor].end())
956
923
  {
957
 
    auto iter2 = transform_map.insert(std::map<TransformIndex, std::vector<nux::Vector4> >::value_type(index, std::vector<nux::Vector4>(4)));
 
924
    auto iter2 = transform_map[monitor].insert(std::map<TransformIndex, std::vector<nux::Vector4> >::value_type(index, std::vector<nux::Vector4>(4)));
958
925
    return iter2.first->second;
959
926
  }
960
927