~thomir-deactivatedaccount/unity/switcher-autopilot-test

« back to all changes in this revision

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

  • Committer: Didier Roche
  • Date: 2012-03-13 11:57:33 UTC
  • mto: This revision was merged to the branch mainline in revision 2126.
  • Revision ID: didier.roche@canonical.com-20120313115733-c85oulbsszhg2hmp
Xfixes.h is used by plugins/unityshell/src/PointerBarrier* but wasn't listed in the pc file configuration. It was picked by chance by another dep

Show diffs side-by-side

added added

removed removed

Lines of Context:
81
81
 
82
82
UnityScreen* uScreen = 0;
83
83
 
84
 
void reset_glib_logging();
85
84
void configure_logging();
86
85
void capture_g_log_calls(const gchar* log_domain,
87
86
                         GLogLevelFlags log_level,
114
113
  , _in_paint(false)
115
114
  , relayoutSourceId(0)
116
115
  , _redraw_handle(0)
 
116
  , alt_tap_timeout_id_(0)
117
117
  , newFocusedWindow(nullptr)
118
118
  , doShellRepaint(false)
119
119
  , allowWindowPaint(false)
127
127
  , grab_index_ (0)
128
128
  , painting_tray_ (false)
129
129
  , last_scroll_event_(0)
130
 
  , hud_keypress_time_(0)
 
130
  , last_hud_show_time_(0)
131
131
{
132
132
  Timer timer;
133
133
  gfloat version;
378
378
  if (relayoutSourceId != 0)
379
379
    g_source_remove(relayoutSourceId);
380
380
 
381
 
  if (_redraw_handle)
382
 
    g_source_remove(_redraw_handle);
 
381
  if (alt_tap_timeout_id_)
 
382
    g_source_remove(alt_tap_timeout_id_);
383
383
 
384
384
  ::unity::ui::IconRenderer::DestroyTextures();
385
385
  QuicklistManager::Destroy();
386
 
  // We need to delete the launchers before the window thread.
387
 
  launcher_controller_.reset();
 
386
 
388
387
  delete wt;
389
 
  reset_glib_logging();
390
388
}
391
389
 
392
390
void UnityScreen::initAltTabNextWindow()
884
882
  {
885
883
    /* Create a new keybinding for the Escape key and the current modifiers,
886
884
     * compiz will take of the ref-counting of the repeated actions */
887
 
    KeyCode escape = XKeysymToKeycode(screen->dpy(), XStringToKeysym("Escape"));
888
 
    CompAction::KeyBinding binding(escape, modifiers);
 
885
    CompAction::KeyBinding binding(9, modifiers);
889
886
 
890
887
    CompActionPtr &escape_action = _escape_actions[target];
891
888
    escape_action = CompActionPtr(new CompAction());
1375
1372
      KeySym key_sym;
1376
1373
      char key_string[2];
1377
1374
      int result = XLookupString(&(event->xkey), key_string, 2, &key_sym, 0);
1378
 
 
1379
 
      if (launcher_controller_->KeyNavIsActive())
1380
 
      {
1381
 
        if (key_sym == XK_Up)
1382
 
        {
1383
 
          launcher_controller_->KeyNavPrevious();
1384
 
          break;
1385
 
        }
1386
 
        else if (key_sym == XK_Down)
1387
 
        {
1388
 
          launcher_controller_->KeyNavNext();
1389
 
          break;
1390
 
        }
1391
 
      }
1392
 
 
1393
1375
      if (result > 0)
1394
1376
      {
1395
1377
        // NOTE: does this have the potential to do an invalid write?  Perhaps
1396
1378
        // we should just say "key_string[1] = 0" because that is the only
1397
1379
        // thing that could possibly make sense here.
1398
1380
        key_string[result] = 0;
1399
 
 
1400
1381
        if (super_keypressed_)
1401
1382
        {
1402
1383
          if (key_sym != XK_Escape || (key_sym == XK_Escape && !launcher_controller_->KeyNavIsActive()))
1537
1518
    action->setState(action->state() | CompAction::StateTermKey);
1538
1519
 
1539
1520
  super_keypressed_ = true;
1540
 
  int when = options[7].value().i();  // XEvent time in millisec
1541
 
  launcher_controller_->HandleLauncherKeyPress(when);
 
1521
  launcher_controller_->HandleLauncherKeyPress();
1542
1522
  EnsureSuperKeybindings ();
1543
1523
 
1544
1524
  if (!shortcut_controller_->Visible() && shortcut_controller_->IsEnabled())
1581
1561
    return false;
1582
1562
 
1583
1563
  bool was_tap = state & CompAction::StateTermTapped;
1584
 
  LOG_DEBUG(logger) << "Super released: " << (was_tap ? "tapped" : "released");
1585
 
  int when = options[7].value().i();  // XEvent time in millisec
1586
 
 
1587
1564
  super_keypressed_ = false;
1588
1565
  launcher_controller_->KeyNavTerminate(true);
1589
 
  launcher_controller_->HandleLauncherKeyRelease(was_tap, when);
 
1566
  launcher_controller_->HandleLauncherKeyRelease(was_tap);
1590
1567
  EnableCancelAction(CancelActionTarget::LAUNCHER_SWITCHER, false);
1591
1568
 
1592
1569
  shortcut_controller_->SetEnabled(enable_shortcut_overlay_);
1668
1645
  if (!grab_index_)
1669
1646
    return false;
1670
1647
 
 
1648
  if (alt_tap_timeout_id_)
 
1649
  {
 
1650
    g_source_remove(alt_tap_timeout_id_);
 
1651
    alt_tap_timeout_id_ = 0;
 
1652
  }
 
1653
 
1671
1654
  screen->addAction(&optionGetAltTabRight());
1672
1655
  screen->addAction(&optionGetAltTabDetailStart());
1673
1656
  screen->addAction(&optionGetAltTabDetailStop());
1767
1750
bool UnityScreen::altTabPrevAllInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options)
1768
1751
{
1769
1752
  if (switcher_controller_->Visible())
1770
 
  {
1771
1753
    switcher_controller_->Prev();
1772
 
    return true;
1773
 
  }
1774
1754
 
1775
 
  return false;
 
1755
  return true;
1776
1756
}
1777
1757
 
1778
1758
bool UnityScreen::altTabPrevInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options)
1779
1759
{
1780
1760
  if (switcher_controller_->Visible())
1781
 
  {
1782
1761
    switcher_controller_->Prev();
1783
 
    return true;
1784
 
  }
1785
1762
 
1786
 
  return false;
 
1763
  return true;
1787
1764
}
1788
1765
 
1789
1766
bool UnityScreen::altTabDetailStartInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options)
1790
1767
{
1791
1768
  if (switcher_controller_->Visible())
1792
 
  {
1793
1769
    switcher_controller_->SetDetail(true);
1794
 
    return true;
1795
 
  }
1796
1770
 
1797
 
  return false;
 
1771
  return true;
1798
1772
}
1799
1773
 
1800
1774
bool UnityScreen::altTabDetailStopInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options)
1801
1775
{
1802
1776
  if (switcher_controller_->Visible())
1803
 
  {
1804
1777
    switcher_controller_->SetDetail(false);
1805
 
    return true;
1806
 
  }
1807
1778
 
1808
 
  return false;
 
1779
  return true;
1809
1780
}
1810
1781
 
1811
1782
bool UnityScreen::altTabNextWindowInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options)
1825
1796
bool UnityScreen::altTabPrevWindowInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options)
1826
1797
{
1827
1798
  if (switcher_controller_->Visible())
1828
 
  {
1829
1799
    switcher_controller_->PrevDetail();
1830
 
    return true;
1831
 
  }
1832
1800
 
1833
 
  return false;
 
1801
  return true;
1834
1802
}
1835
1803
 
1836
1804
bool UnityScreen::launcherSwitcherForwardInitiate(CompAction* action, CompAction::State state, CompOption::Vector& options)
1837
1805
{
1838
1806
  if (!launcher_controller_->KeyNavIsActive())
1839
1807
  {
1840
 
    int modifiers = action->key().modifiers();
1841
 
 
1842
1808
    launcher_controller_->KeyNavActivate();
1843
 
 
1844
 
    EnableCancelAction(CancelActionTarget::LAUNCHER_SWITCHER, true, modifiers);
1845
 
 
1846
 
    KeyCode down_key = XKeysymToKeycode(screen->dpy(), XStringToKeysym("Down"));
1847
 
    KeyCode up_key = XKeysymToKeycode(screen->dpy(), XStringToKeysym("Up"));
1848
 
 
1849
 
    CompAction down_action;
1850
 
    down_action.setKey(CompAction::KeyBinding(down_key, modifiers));
1851
 
    screen->addAction(&down_action);
1852
 
 
1853
 
    CompAction up_action;
1854
 
    up_action.setKey(CompAction::KeyBinding(up_key, modifiers));
1855
 
    screen->addAction(&up_action);
 
1809
    EnableCancelAction(CancelActionTarget::LAUNCHER_SWITCHER, true, action->key().modifiers());
1856
1810
  }
1857
1811
  else
1858
1812
  {
1874
1828
  launcher_controller_->KeyNavTerminate(accept_state);
1875
1829
 
1876
1830
  EnableCancelAction(CancelActionTarget::LAUNCHER_SWITCHER, false);
1877
 
 
1878
 
  KeyCode down_key = XKeysymToKeycode(screen->dpy(), XStringToKeysym("Down"));
1879
 
  KeyCode up_key = XKeysymToKeycode(screen->dpy(), XStringToKeysym("Up"));
1880
 
 
1881
 
  CompAction down_action;
1882
 
  down_action.setKey(CompAction::KeyBinding(down_key, action->key().modifiers()));
1883
 
  screen->removeAction(&down_action);
1884
 
 
1885
 
  CompAction up_action;
1886
 
  up_action.setKey(CompAction::KeyBinding(up_key, action->key().modifiers()));
1887
 
  screen->removeAction(&up_action);
1888
 
 
1889
1831
  action->setState (action->state() & (unsigned)~(CompAction::StateTermKey));
1890
1832
  return true;
1891
1833
}
1917
1859
  // to receive the Terminate event
1918
1860
  if (state & CompAction::StateInitKey)
1919
1861
    action->setState(action->state() | CompAction::StateTermKey);
1920
 
  hud_keypress_time_ = options[7].value().i();  // XEvent time in millisec
 
1862
  last_hud_show_time_ = g_get_monotonic_time();
 
1863
 
 
1864
  /* Workaround to fix #943194 */
 
1865
  alt_tap_timeout_id_ = g_timeout_add(local::ALT_TAP_DURATION, [] (gpointer data) -> gboolean {
 
1866
    auto self = static_cast<UnityScreen*>(data);
 
1867
 
 
1868
    if (!self->switcher_controller_->Visible())
 
1869
    {
 
1870
      XUngrabKeyboard(self->screen->dpy(), CurrentTime);
 
1871
    }
 
1872
 
 
1873
    self->alt_tap_timeout_id_ = 0;
 
1874
    return FALSE;
 
1875
  }, this);
1921
1876
 
1922
1877
  // pass key through
1923
1878
  return false;
1938
1893
  if (!(state & CompAction::StateTermTapped))
1939
1894
    return false;
1940
1895
 
1941
 
  int release_time = options[7].value().i();  // XEvent time in millisec
1942
 
  int tap_duration = release_time - hud_keypress_time_;
1943
 
  if (tap_duration > local::ALT_TAP_DURATION)
 
1896
  if (alt_tap_timeout_id_)
 
1897
  {
 
1898
    g_source_remove(alt_tap_timeout_id_);
 
1899
    alt_tap_timeout_id_ = 0;
 
1900
  }
 
1901
 
 
1902
  gint64 current_time = g_get_monotonic_time();
 
1903
  if (current_time - last_hud_show_time_ > (local::ALT_TAP_DURATION * 1000))
1944
1904
  {
1945
1905
    LOG_DEBUG(logger) << "Tap too long";
1946
1906
    return false;
1958
1918
  }
1959
1919
  else
1960
1920
  {
1961
 
    // Handles closing KeyNav (Alt+F1) if the hud is about to show
1962
 
    if (launcher_controller_->KeyNavIsActive())
1963
 
    {
1964
 
      launcher_controller_->KeyNavTerminate(false);
1965
 
    }
1966
1921
    hud_controller_->ShowHud();
1967
1922
  }
1968
1923
 
2772
2727
  // TODO move category text into a vector...
2773
2728
  
2774
2729
  // Launcher...
2775
 
  std::string const launcher(_("Launcher"));
 
2730
  std::string const launcher = _("Launcher");
2776
2731
  
2777
2732
  hints_.push_back(new shortcut::Hint(launcher, "", _(" (Press)"), _("Open Launcher, displays shortcuts."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "show_launcher" ));
2778
2733
  hints_.push_back(new shortcut::Hint(launcher, "", "", _("Open Launcher keyboard navigation mode."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "keyboard_focus"));
2779
 
  hints_.push_back(new shortcut::Hint(launcher, "", "", _("Switch applications via Launcher."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "launcher_switcher_forward"));
 
2734
  hints_.push_back(new shortcut::Hint(launcher, "", "", _("Switch applications via Launcher."), shortcut::HARDCODED_OPTION, _("Super + Tab")));
2780
2735
  hints_.push_back(new shortcut::Hint(launcher, "", _(" + 1 to 9"), _("Same as clicking on a Launcher icon."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "show_launcher"));
2781
2736
  hints_.push_back(new shortcut::Hint(launcher, "", _(" + Shift + 1 to 9"), _("Open new window of the app."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "show_launcher"));
2782
2737
  hints_.push_back(new shortcut::Hint(launcher, "", " + T", _("Open the Trash."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "show_launcher")); 
2783
2738
 
2784
2739
  // Dash...
2785
 
  std::string const dash( _("Dash"));
 
2740
  std::string const dash = _("Dash");
2786
2741
 
2787
2742
  hints_.push_back(new shortcut::Hint(dash, "", _(" (Tap)"), _("Open the Dash Home."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "show_launcher"));
2788
2743
  hints_.push_back(new shortcut::Hint(dash, "", " + A", _("Open the Dash App Lens."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "show_launcher"));
2791
2746
  hints_.push_back(new shortcut::Hint(dash, "", "", _("Switches between Lenses."), shortcut::HARDCODED_OPTION, _("Ctrl + Tab")));
2792
2747
  hints_.push_back(new shortcut::Hint(dash, "", "", _("Moves the focus."), shortcut::HARDCODED_OPTION, _("Cursor Keys")));
2793
2748
  hints_.push_back(new shortcut::Hint(dash, "", "", _("Open currently focused item."), shortcut::HARDCODED_OPTION, _("Enter & Return")));
 
2749
  hints_.push_back(new shortcut::Hint(dash, "", "", _("'Run Command' mode."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "execute_command"));
2794
2750
 
2795
2751
  // Menu Bar
2796
 
  std::string const menubar(_("HUD & Menu Bar"));
2797
 
 
2798
 
  hints_.push_back(new shortcut::Hint(menubar, "", " (Tap)", _("Open the HUD."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "show_hud"));
2799
 
  hints_.push_back(new shortcut::Hint(menubar, "", " (Press)", _("Reveals application menu."), shortcut::HARDCODED_OPTION, "Alt"));
 
2752
  std::string const menubar = _("Menu Bar");
 
2753
  
 
2754
  hints_.push_back(new shortcut::Hint(menubar, "", "", _("Reveals application menu."), shortcut::HARDCODED_OPTION, "Alt"));
2800
2755
  hints_.push_back(new shortcut::Hint(menubar, "", "", _("Opens the indicator menu."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "panel_first_menu"));
2801
2756
  hints_.push_back(new shortcut::Hint(menubar, "", "", _("Moves focus between indicators."), shortcut::HARDCODED_OPTION, _("Cursor Left or Right")));
2802
2757
 
2803
2758
  // Switching
2804
 
  std::string const switching(_("Switching"));
 
2759
  std::string const switching = _("Switching");
2805
2760
  
2806
2761
  hints_.push_back(new shortcut::Hint(switching, "", "", _("Switch between applications."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "alt_tab_forward"));
2807
2762
  hints_.push_back(new shortcut::Hint(switching, "", "", _("Switch windows of current application."), shortcut::COMPIZ_KEY_OPTION, "unityshell", "alt_tab_next_window"));
2808
2763
  hints_.push_back(new shortcut::Hint(switching, "", "", _("Moves the focus."), shortcut::HARDCODED_OPTION, _("Cursor Left or Right")));
2809
2764
 
2810
2765
  // Workspaces
2811
 
  std::string const workspaces(_("Workspaces"));
2812
 
 
 
2766
  std::string const workspaces = _("Workspaces");
2813
2767
  hints_.push_back(new shortcut::Hint(workspaces, "", "", _("Spread workspaces."), shortcut::COMPIZ_KEY_OPTION, "expo", "expo_key"));
2814
 
  hints_.push_back(new shortcut::Hint(workspaces, "",  _(" + Cursor Keys"), _("Switch workspaces."), shortcut::COMPIZ_METAKEY_OPTION, "wall", "left_key"));
2815
 
  hints_.push_back(new shortcut::Hint(workspaces, "",  _(" + Cursor Keys"), _("Move focused window to different workspace."), shortcut::COMPIZ_METAKEY_OPTION, "wall", "left_window_key"));
 
2768
  hints_.push_back(new shortcut::Hint(workspaces, "", "", _("Switch workspaces."), shortcut::HARDCODED_OPTION, _("Control + Alt + Cursor Keys")));
 
2769
  hints_.push_back(new shortcut::Hint(workspaces, "", "", _("Move focused window to different workspace."), shortcut::HARDCODED_OPTION, _("Control + Alt + Shift + Cursor Keys")));
2816
2770
 
2817
2771
  // Windows
2818
 
  std::string const windows(_("Windows"));
 
2772
  std::string const windows = _("Windows");
2819
2773
  hints_.push_back(new shortcut::Hint(windows, "", "", _("Spreads all windows in the current workspace."), shortcut::COMPIZ_KEY_OPTION, "scale", "initiate_all_key"));
2820
2774
  hints_.push_back(new shortcut::Hint(windows, "", "", _("Minimises all windows."), shortcut::COMPIZ_KEY_OPTION, "core", "show_desktop_key"));
2821
2775
  hints_.push_back(new shortcut::Hint(windows, "", "", _("Maximises the current window."), shortcut::COMPIZ_KEY_OPTION, "core", "maximize_window_key"));
2948
2902
namespace
2949
2903
{
2950
2904
 
2951
 
void reset_glib_logging()
2952
 
{
2953
 
  // Reinstate the default glib logger.
2954
 
  g_log_set_default_handler(g_log_default_handler, NULL);
2955
 
}
2956
 
 
2957
2905
void configure_logging()
2958
2906
{
2959
2907
  // The default behaviour of the logging infrastructure is to send all output