Back to index

unity  6.0.0
LauncherHoverMachine.cpp
Go to the documentation of this file.
00001 // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
00002 /*
00003  * Copyright (C) 2011 Canonical Ltd
00004  *
00005  * This program is free software: you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License version 3 as
00007  * published by the Free Software Foundation.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016  *
00017  * Authored by: Didier Roche <didrocks@ubuntu.com>
00018  */
00019 #include <boost/lexical_cast.hpp>
00020 
00021 #include "LauncherHoverMachine.h"
00022 
00023 namespace unity
00024 {
00025 
00026 LauncherHoverMachine::LauncherHoverMachine()
00027   : _should_hover(false)
00028   , _latest_emit_should_hover(false)
00029   , _quirks(DEFAULT)
00030 {}
00031 
00032 /* == Quick Quirk Reference : please keep up to date ==
00033     DEFAULT                = 0,
00034     LAUNCHER_HIDDEN        = 1 << 0, 1
00035     MOUSE_OVER_LAUNCHER    = 1 << 1, 2
00036     MOUSE_OVER_BFB         = 1 << 2, 4
00037     SHORTCUT_KEYS_VISIBLE  = 1 << 3, 8
00038     QUICKLIST_OPEN         = 1 << 4, 16
00039     KEY_NAV_ACTIVE         = 1 << 5, 32
00040     LAUNCHER_IN_ACTION     = 1 << 6, 64
00041     PLACES_VISIBLE         = 1 << 7, 128
00042 */
00043 
00044 void
00045 LauncherHoverMachine::EnsureHoverState()
00046 {
00047   bool should_hover;
00048 
00049   if (GetQuirk(LAUNCHER_HIDDEN))
00050   {
00051     SetShouldHover(false);
00052     return;
00053   }
00054 
00055   if (GetQuirk((HoverQuirk)(MOUSE_OVER_LAUNCHER | MOUSE_OVER_BFB |
00056                             SHORTCUT_KEYS_VISIBLE | KEY_NAV_ACTIVE |
00057                             QUICKLIST_OPEN | LAUNCHER_IN_ACTION)))
00058     should_hover = true;
00059   else
00060     should_hover = false;
00061 
00062   SetShouldHover(should_hover);
00063 }
00064 
00065 void
00066 LauncherHoverMachine::SetShouldHover(bool value)
00067 {
00068   _should_hover = value;
00069 
00070   _hover_changed_emit_idle.reset(new glib::Idle(glib::Source::Priority::DEFAULT));
00071   _hover_changed_emit_idle->Run(sigc::mem_fun(this, &LauncherHoverMachine::EmitShouldHoverChanged));
00072 }
00073 
00074 bool
00075 LauncherHoverMachine::EmitShouldHoverChanged()
00076 {
00077   if (_should_hover == _latest_emit_should_hover)
00078     return false;
00079 
00080   _latest_emit_should_hover = _should_hover;
00081   should_hover_changed.emit(_should_hover);
00082 
00083   return false;
00084 }
00085 
00086 void
00087 LauncherHoverMachine::SetQuirk(LauncherHoverMachine::HoverQuirk quirk, bool active)
00088 {
00089   if (GetQuirk(quirk) == active)
00090     return;
00091 
00092   if (active)
00093     _quirks = (HoverQuirk)(_quirks | quirk);
00094   else
00095     _quirks = (HoverQuirk)(_quirks & ~quirk);
00096 
00097   EnsureHoverState();
00098 }
00099 
00100 bool
00101 LauncherHoverMachine::GetQuirk(LauncherHoverMachine::HoverQuirk quirk, bool allow_partial)
00102 {
00103   if (allow_partial)
00104     return _quirks & quirk;
00105   return (_quirks & quirk) == quirk;
00106 }
00107 
00108 std::string
00109 LauncherHoverMachine::DebugHoverQuirks()
00110 {
00111   // Although I do wonder why we are returning a string representation
00112   // of the enum value as an integer anyway.
00113   return boost::lexical_cast<std::string>(_quirks);
00114 }
00115 
00116 } //unity namespace