summaryrefslogtreecommitdiff
diff options
-rw-r--r--hud/HudController.cpp54
-rw-r--r--launcher/AbstractLauncherIcon.h3
-rw-r--r--launcher/ApplicationLauncherIcon.cpp547
-rw-r--r--launcher/ApplicationLauncherIcon.h15
-rw-r--r--launcher/CMakeLists.txt10
-rw-r--r--launcher/LauncherController.cpp81
-rw-r--r--launcher/LauncherControllerPrivate.h6
-rw-r--r--launcher/LauncherIcon.h2
-rw-r--r--launcher/LauncherModel.h3
-rw-r--r--launcher/MockLauncherIcon.h41
-rw-r--r--launcher/SoftwareCenterLauncherIcon.cpp23
-rw-r--r--launcher/SoftwareCenterLauncherIcon.h3
-rw-r--r--launcher/SwitcherController.cpp6
-rw-r--r--launcher/SwitcherModel.cpp5
-rw-r--r--plugins/unityshell/CMakeLists.txt2
-rw-r--r--tests/CMakeLists.txt2
-rw-r--r--tests/mock-application.cpp32
-rw-r--r--tests/mock-application.h42
-rw-r--r--tests/test_application_launcher_icon.cpp66
-rw-r--r--tests/test_launcher_controller.cpp71
-rw-r--r--unity-shared/ApplicationManager.cpp15
-rw-r--r--unity-shared/ApplicationManager.h6
-rw-r--r--unity-shared/BamfApplicationManager.cpp28
-rw-r--r--unity-shared/BamfApplicationManager.h8
-rw-r--r--unity-shared/BamfApplicationManagerFactory.cpp31
-rw-r--r--unity-shared/CMakeLists.txt14
-rw-r--r--unity-standalone/CMakeLists.txt1
27 files changed, 469 insertions, 648 deletions
diff --git a/hud/HudController.cpp b/hud/HudController.cpp
index 484b1ce9f..0a264e692 100644
--- a/hud/HudController.cpp
+++ b/hud/HudController.cpp
@@ -22,13 +22,14 @@
#include <Nux/HLayout.h>
#include <UnityCore/Variant.h>
+#include "unity-shared/ApplicationManager.h"
#include "unity-shared/WindowManager.h"
#include "unity-shared/PanelStyle.h"
#include "unity-shared/UBusMessages.h"
#include "unity-shared/UScreen.h"
#include "config.h"
-#include <libbamf/libbamf.h>
+
namespace unity
{
@@ -313,52 +314,15 @@ void Controller::ShowHud()
view_->ShowEmbeddedIcon(!IsLockedToLauncher(monitor_index_));
view_->AboutToShow();
- // We first want to grab the currently active window
- glib::Object<BamfMatcher> matcher(bamf_matcher_get_default());
- BamfWindow* active_win = bamf_matcher_get_active_window(matcher);
-
- Window active_xid = bamf_window_get_xid(active_win);
- std::vector<Window> const& unity_xids = nux::XInputWindow::NativeHandleList();
-
- // If the active window is an unity window, we must get the top-most valid window
- if (std::find(unity_xids.begin(), unity_xids.end(), active_xid) != unity_xids.end())
- {
- // Windows list stack for all the monitors
- GList *windows = bamf_matcher_get_window_stack_for_monitor(matcher, -1);
-
- // Reset values, in case we can't find a window ie. empty current desktop
- active_xid = 0;
- active_win = nullptr;
-
- for (GList *l = windows; l; l = l->next)
- {
- if (!BAMF_IS_WINDOW(l->data))
- continue;
-
- auto win = static_cast<BamfWindow*>(l->data);
- auto view = static_cast<BamfView*>(l->data);
- Window xid = bamf_window_get_xid(win);
-
- if (bamf_view_is_user_visible(view) && bamf_window_get_window_type(win) != BAMF_WINDOW_DOCK &&
- wm.IsWindowOnCurrentDesktop(xid) &&
- wm.IsWindowVisible(xid) &&
- std::find(unity_xids.begin(), unity_xids.end(), xid) == unity_xids.end())
- {
- active_win = win;
- active_xid = xid;
- }
- }
-
- g_list_free(windows);
- }
-
- BamfApplication* active_app = bamf_matcher_get_application_for_window(matcher, active_win);
+ ApplicationManager& app_manager = ApplicationManager::Default();
+ ApplicationPtr active_application;
+ ApplicationWindowPtr active_window = app_manager.GetActiveWindow();
+ if (active_window)
+ active_application = active_window->application();
- if (BAMF_IS_VIEW(active_app))
+ if (active_application)
{
- auto active_view = reinterpret_cast<BamfView*>(active_app);
- glib::String view_icon(bamf_view_get_icon(active_view));
- focused_app_icon_ = view_icon.Str();
+ focused_app_icon_ = active_application->icon();
}
else
{
diff --git a/launcher/AbstractLauncherIcon.h b/launcher/AbstractLauncherIcon.h
index 495317a87..936020daa 100644
--- a/launcher/AbstractLauncherIcon.h
+++ b/launcher/AbstractLauncherIcon.h
@@ -29,6 +29,7 @@
#include <libdbusmenu-glib/menuitem.h>
#include "DndData.h"
+#include <unity-shared/ApplicationManager.h>
#include "unity-shared/Introspectable.h"
#include "unity-shared/IconTextureSource.h"
#include "unity-shared/WindowManager.h"
@@ -156,7 +157,7 @@ public:
virtual int SortPriority() = 0;
- virtual std::vector<Window> Windows() = 0;
+ virtual WindowList Windows() = 0;
virtual std::vector<Window> WindowsForMonitor(int monitor) = 0;
diff --git a/launcher/ApplicationLauncherIcon.cpp b/launcher/ApplicationLauncherIcon.cpp
index b3782e256..1469ed921 100644
--- a/launcher/ApplicationLauncherIcon.cpp
+++ b/launcher/ApplicationLauncherIcon.cpp
@@ -55,59 +55,53 @@ const std::string DEFAULT_ICON = "application-default-icon";
NUX_IMPLEMENT_OBJECT_TYPE(ApplicationLauncherIcon);
-ApplicationLauncherIcon::ApplicationLauncherIcon(BamfApplication* app)
+ApplicationLauncherIcon::ApplicationLauncherIcon(ApplicationPtr const& app)
: SimpleLauncherIcon(IconType::APPLICATION)
- , _bamf_app(app, glib::AddRef())
+ , app_(app)
, use_custom_bg_color_(false)
, bg_color_(nux::color::White)
{
- g_object_set_qdata(G_OBJECT(app), g_quark_from_static_string("unity-seen"),
- GUINT_TO_POINTER(1));
- auto bamf_view = glib::object_cast<BamfView>(_bamf_app);
-
- glib::String icon(bamf_view_get_icon(bamf_view));
-
- tooltip_text = BamfName();
- icon_name = (icon ? icon.Str() : DEFAULT_ICON);
-
- SetQuirk(Quirk::VISIBLE, bamf_view_is_user_visible(bamf_view));
- SetQuirk(Quirk::ACTIVE, bamf_view_is_active(bamf_view));
- SetQuirk(Quirk::RUNNING, bamf_view_is_running(bamf_view));
-
- glib::SignalBase* sig;
-
- sig = new glib::Signal<void, BamfView*, BamfView*>(bamf_view, "child-added",
- [this] (BamfView*, BamfView*) {
- EnsureWindowState();
- UpdateMenus();
- UpdateIconGeometries(GetCenters());
- });
- _gsignals.Add(sig);
-
- sig = new glib::Signal<void, BamfView*, BamfView*>(bamf_view, "child-removed",
- [this] (BamfView*, BamfView*) { EnsureWindowState(); });
- _gsignals.Add(sig);
-
- sig = new glib::Signal<void, BamfView*, BamfView*>(bamf_view, "child-moved",
- [&] (BamfView *, BamfView *) {
- EnsureWindowState();
- });
- _gsignals.Add(sig);
-
- sig = new glib::Signal<void, BamfView*, gboolean>(bamf_view, "urgent-changed",
- [this] (BamfView*, gboolean urgent) {
+ app->seen = true;
+
+ tooltip_text = app->title();
+ std::string icon = app->icon();
+ icon_name = (icon.empty() ? DEFAULT_ICON : icon);
+
+ SetQuirk(Quirk::VISIBLE, app->visible());
+ SetQuirk(Quirk::ACTIVE, app->active());
+ SetQuirk(Quirk::RUNNING, app->running());
+ // Make sure we set the LauncherIcon stick bit too...
+ if (app->sticky())
+ SimpleLauncherIcon::Stick(false); // don't emit the signal
+
+ LOG_INFO(logger) << "Created ApplicationLauncherIcon: "
+ << tooltip_text()
+ << ", icon: " << icon_name()
+ << ", sticky: " << (app->sticky() ? "yes" : "no")
+ << ", visible: " << (app->visible() ? "yes" : "no")
+ << ", active: " << (app->active() ? "yes" : "no")
+ << ", running: " << (app->running() ? "yes" : "no");
+
+ // Lambda functions should be fine here because when the application the icon
+ // is only ever removed when the application is closed.
+ app->window_opened.connect([this](ApplicationWindow const&) {
+ EnsureWindowState();
+ UpdateMenus();
+ UpdateIconGeometries(GetCenters());
+ });
+ app->window_closed.connect([this]() { EnsureWindowState(); });
+ app->window_moved.connect([this](ApplicationWindow const&) { EnsureWindowState(); });
+
+ app->urgent.changed.connect([this](bool const& urgent) {
+ LOG_DEBUG(logger) << tooltip_text() << " urgent now " << (urgent ? "true" : "false");
SetQuirk(Quirk::URGENT, urgent);
});
- _gsignals.Add(sig);
-
- sig = new glib::Signal<void, BamfView*, gboolean>(bamf_view, "active-changed",
- [this] (BamfView*, gboolean active) {
+ app->active.changed.connect([this](bool const& active) {
+ LOG_DEBUG(logger) << tooltip_text() << " active now " << (active ? "true" : "false");
SetQuirk(Quirk::ACTIVE, active);
});
- _gsignals.Add(sig);
-
- sig = new glib::Signal<void, BamfView*, gboolean>(bamf_view, "running-changed",
- [this] (BamfView* view, gboolean running) {
+ app->running.changed.connect([this](bool const& running) {
+ LOG_DEBUG(logger) << tooltip_text() << " running now " << (running ? "true" : "false");
SetQuirk(Quirk::RUNNING, running);
if (running)
@@ -119,29 +113,24 @@ ApplicationLauncherIcon::ApplicationLauncherIcon(BamfApplication* app)
* very early, so we need to make sure that they
* are updated as soon as the view is re-opened. */
if (tooltip_text().empty())
- tooltip_text = BamfName();
+ tooltip_text = app_->title();
if (icon_name == DEFAULT_ICON)
{
- glib::String icon(bamf_view_get_icon(view));
- icon_name = (icon ? icon.Str() : DEFAULT_ICON);
+ std::string icon = app_->icon();
+ icon_name = (icon.empty() ? DEFAULT_ICON : icon);
}
EnsureWindowState();
UpdateIconGeometries(GetCenters());
}
});
- _gsignals.Add(sig);
-
- sig = new glib::Signal<void, BamfView*, gboolean>(bamf_view, "user-visible-changed",
- [this] (BamfView*, gboolean visible) {
+ app->visible.changed.connect([this](bool const& visible) {
if (!IsSticky())
SetQuirk(Quirk::VISIBLE, visible);
});
- _gsignals.Add(sig);
- sig = new glib::Signal<void, BamfView*>(bamf_view, "closed",
- [this] (BamfView*) {
+ app->closed.connect([this]() {
if (!IsSticky())
{
SetQuirk(Quirk::VISIBLE, false);
@@ -158,7 +147,6 @@ ApplicationLauncherIcon::ApplicationLauncherIcon(BamfApplication* app)
}, ICON_REMOVE_TIMEOUT);
}
});
- _gsignals.Add(sig);
WindowManager& wm = WindowManager::Default();
wm.window_minimized.connect(sigc::mem_fun(this, &ApplicationLauncherIcon::OnWindowMinimized));
@@ -177,35 +165,30 @@ ApplicationLauncherIcon::ApplicationLauncherIcon(BamfApplication* app)
ApplicationLauncherIcon::~ApplicationLauncherIcon()
{
- if (_bamf_app.IsType(BAMF_TYPE_APPLICATION))
+ if (app_)
{
- bamf_view_set_sticky(BAMF_VIEW(_bamf_app.RawPtr()), FALSE);
- g_object_set_qdata(G_OBJECT(_bamf_app.RawPtr()),
- g_quark_from_static_string("unity-seen"), nullptr);
+ app_->sticky = false;
+ app_->seen = false;
}
}
void ApplicationLauncherIcon::Remove()
{
/* Removing the unity-seen flag to the wrapped bamf application, on remove
- * request we make sure that if the bamf application is re-opened while
- * the removal process is still ongoing, the application will be shown
- * on the launcher. Disconnecting from signals and nullifying the _bamf_app
- * we make sure that this icon won't be reused (no duplicated icon). */
- _gsignals.Disconnect(_bamf_app);
- g_object_set_qdata(G_OBJECT(_bamf_app.RawPtr()),
- g_quark_from_static_string("unity-seen"), nullptr);
- _bamf_app = nullptr;
-
+ * request we make sure that if the application is re-opened while the
+ * removal process is still ongoing, the application will be shown on the
+ * launcher. Disconnecting from signals and nullifying the app we make sure
+ * that this icon won't be reused (no duplicated icon). */
+ app_->seen = false;
+ app_.reset(); // Have to be very careful here as we are breaking a class invariant (that we have an app)
SimpleLauncherIcon::Remove();
}
bool ApplicationLauncherIcon::IsSticky() const
{
- if (!BAMF_IS_VIEW(_bamf_app.RawPtr()))
- return false;
- else
- return bamf_view_is_sticky(BAMF_VIEW(_bamf_app.RawPtr()));
+ if (app_)
+ return app_->sticky();
+ return false;
}
bool ApplicationLauncherIcon::IsActive() const
@@ -227,25 +210,30 @@ void ApplicationLauncherIcon::ActivateLauncherIcon(ActionArg arg)
{
SimpleLauncherIcon::ActivateLauncherIcon(arg);
WindowManager& wm = WindowManager::Default();
- bool scaleWasActive = wm.IsScaleActive();
- bool active = IsActive();
- bool user_visible = IsRunning();
-
- if (arg.target && OwnsWindow(arg.target))
+ // This is a little awkward as the target is only set from the switcher.
+ if (arg.target)
{
+ // thumper: should we Raise too? should the WM raise?
wm.Activate(arg.target);
return;
}
+ bool scaleWasActive = wm.IsScaleActive();
+ if (scaleWasActive)
+ {
+ wm.TerminateScale();
+ }
+
+ bool active = IsActive();
+ bool user_visible = IsRunning();
/* We should check each child to see if there is
* an unmapped (!= minimized) window around and
* if so force "Focus" behaviour */
if (arg.source != ActionArg::SWITCHER)
{
- auto bamf_view = glib::object_cast<BamfView>(_bamf_app);
- user_visible = bamf_view_is_user_visible(bamf_view);
+ user_visible = app_->visible();
if (active)
{
@@ -254,21 +242,10 @@ void ApplicationLauncherIcon::ActivateLauncherIcon(ActionArg arg)
bool any_on_top = false;
bool any_on_monitor = (arg.monitor < 0);
int active_monitor = arg.monitor;
- GList* children = bamf_view_get_children(bamf_view);
- for (GList* l = children; l; l = l->next)
+ for (auto& window : app_->GetWindows())
{
- auto view = static_cast<BamfView*>(l->data);
- auto win = static_cast<BamfWindow*>(l->data);
- Window xid;
-
- if (BAMF_IS_WINDOW(l->data))
- xid = bamf_window_get_xid(static_cast<BamfWindow*>(l->data));
- else if (BAMF_IS_TAB(l->data))
- xid = bamf_tab_get_xid(static_cast<BamfTab*>(l->data));
- else
- continue;
-
+ Window xid = window->window_id();
if (!any_visible && wm.IsWindowOnCurrentDesktop(xid))
{
@@ -285,20 +262,18 @@ void ApplicationLauncherIcon::ActivateLauncherIcon(ActionArg arg)
any_on_top = true;
}
- if (!any_on_monitor && bamf_window_get_monitor(win) == arg.monitor &&
+ if (!any_on_monitor && window->monitor() == arg.monitor &&
wm.IsWindowMapped(xid) && wm.IsWindowVisible(xid))
{
any_on_monitor = true;
}
- if (bamf_view_is_active(view))
+ if (window->active())
{
- active_monitor = bamf_window_get_monitor(win);
+ active_monitor = window->monitor();
}
}
- g_list_free(children);
-
if (!any_visible || !any_mapped || !any_on_top)
active = false;
@@ -320,11 +295,6 @@ void ApplicationLauncherIcon::ActivateLauncherIcon(ActionArg arg)
if (GetQuirk(Quirk::STARTING))
return;
- if (scaleWasActive)
- {
- wm.TerminateScale();
- }
-
SetQuirk(Quirk::STARTING, true);
OpenInstanceLauncherIcon();
}
@@ -334,7 +304,6 @@ void ApplicationLauncherIcon::ActivateLauncherIcon(ActionArg arg)
{
if (scaleWasActive) // #5 above
{
- wm.TerminateScale();
Focus(arg);
}
else // #2 above
@@ -349,7 +318,6 @@ void ApplicationLauncherIcon::ActivateLauncherIcon(ActionArg arg)
{
if (scaleWasActive) // #4 above
{
- wm.TerminateScale();
Focus(arg);
if (arg.source != ActionArg::SWITCHER)
Spread(true, 0, false);
@@ -362,56 +330,39 @@ void ApplicationLauncherIcon::ActivateLauncherIcon(ActionArg arg)
}
}
-std::vector<Window> ApplicationLauncherIcon::GetWindows(WindowFilterMask filter, int monitor)
+WindowList ApplicationLauncherIcon::GetWindows(WindowFilterMask filter, int monitor)
{
WindowManager& wm = WindowManager::Default();
- std::vector<Window> results;
-
- if (!BAMF_IS_VIEW(_bamf_app.RawPtr()))
- {
- if (_bamf_app)
- {
- LOG_WARNING(logger) << "Not a view but not null.";
- }
- return results;
- }
+ WindowList results;
monitor = (filter & WindowFilter::ON_ALL_MONITORS) ? -1 : monitor;
bool mapped = (filter & WindowFilter::MAPPED);
bool user_visible = (filter & WindowFilter::USER_VISIBLE);
bool current_desktop = (filter & WindowFilter::ON_CURRENT_DESKTOP);
- GList* children = bamf_view_get_children(BAMF_VIEW(_bamf_app.RawPtr()));
- for (GList* l = children; l; l = l->next)
+ for (auto& window : app_->GetWindows())
{
- if (!BAMF_IS_WINDOW(l->data))
- continue;
-
- auto window = static_cast<BamfWindow*>(l->data);
- auto view = static_cast<BamfView*>(l->data);
-
- if ((monitor >= 0 && bamf_window_get_monitor(window) == monitor) || monitor < 0)
+ if ((monitor >= 0 && window->monitor() == monitor) || monitor < 0)
{
- if ((user_visible && bamf_view_is_user_visible(view)) || !user_visible)
+ if ((user_visible && window->visible()) || !user_visible)
{
- guint32 xid = bamf_window_get_xid(window);
+ Window xid = window->window_id();
if ((mapped && wm.IsWindowMapped(xid)) || !mapped)
{
if ((current_desktop && wm.IsWindowOnCurrentDesktop(xid)) || !current_desktop)
{
- results.push_back(xid);
+ results.push_back(window);
}
}
}
}
}
- g_list_free(children);
return results;
}
-std::vector<Window> ApplicationLauncherIcon::Windows()
+WindowList ApplicationLauncherIcon::Windows()
{
return GetWindows(WindowFilter::MAPPED|WindowFilter::ON_ALL_MONITORS);
}
@@ -424,7 +375,12 @@ std::vector<Window> ApplicationLauncherIcon::WindowsOnViewport()
filter |= WindowFilter::ON_CURRENT_DESKTOP;
filter |= WindowFilter::ON_ALL_MONITORS;
- return GetWindows(filter);
+ std::vector<Window> windows;
+ for (auto& window : GetWindows(filter))
+ {
+ windows.push_back(window->window_id());
+ }
+ return windows;
}
std::vector<Window> ApplicationLauncherIcon::WindowsForMonitor(int monitor)
@@ -434,12 +390,17 @@ std::vector<Window> ApplicationLauncherIcon::WindowsForMonitor(int monitor)
filter |= WindowFilter::USER_VISIBLE;
filter |= WindowFilter::ON_CURRENT_DESKTOP;
- return GetWindows(filter, monitor);
+ std::vector<Window> windows;
+ for (auto& window : GetWindows(filter, monitor))
+ {
+ windows.push_back(window->window_id());
+ }
+ return windows;
}
void ApplicationLauncherIcon::OnWindowMinimized(guint32 xid)
{
- if (!OwnsWindow(xid))
+ if (!app_->OwnsWindow(xid))
return;
Present(0.5f, 600);
@@ -448,7 +409,7 @@ void ApplicationLauncherIcon::OnWindowMinimized(guint32 xid)
void ApplicationLauncherIcon::OnWindowMoved(guint32 moved_win)
{
- if (!OwnsWindow(moved_win))
+ if (!app_->OwnsWindow(moved_win))
return;
_source_manager.AddTimeout(250, [&] {
@@ -461,17 +422,9 @@ void ApplicationLauncherIcon::OnWindowMoved(guint32 moved_win)
void ApplicationLauncherIcon::UpdateDesktopFile()
{
- if (!BAMF_IS_APPLICATION(_bamf_app.RawPtr()))
- {
- if (_bamf_app)
- {
- LOG_WARNING(logger) << "Not an app but not null.";
- }
- return;
- }
- const char* filename = bamf_application_get_desktop_file(_bamf_app);
+ std::string filename = app_->desktop_file();
- if (filename != nullptr && filename[0] != '\0' && _desktop_file != filename)
+ if (!filename.empty() && _desktop_file != filename)
{
_desktop_file = filename;
@@ -511,12 +464,6 @@ std::string ApplicationLauncherIcon::DesktopFile()
return _desktop_file;
}
-std::string ApplicationLauncherIcon::BamfName() const
-{
- glib::String name(bamf_view_get_name(BAMF_VIEW(_bamf_app.RawPtr())));
- return name.Str();
-}
-
void ApplicationLauncherIcon::AddProperties(GVariantBuilder* builder)
{
SimpleLauncherIcon::AddProperties(builder);
@@ -524,44 +471,18 @@ void ApplicationLauncherIcon::AddProperties(GVariantBuilder* builder)
GVariantBuilder xids_builder;
g_variant_builder_init(&xids_builder, G_VARIANT_TYPE ("au"));
- for (auto xid : GetWindows())
- g_variant_builder_add(&xids_builder, "u", xid);
+ for (auto& window : GetWindows())
+ g_variant_builder_add(&xids_builder, "u", window->window_id());
variant::BuilderWrapper(builder)
.add("desktop_file", DesktopFile())
.add("desktop_id", GetDesktopID())
- .add("application_id", GPOINTER_TO_UINT(_bamf_app.RawPtr()))
.add("xids", g_variant_builder_end(&xids_builder))
.add("sticky", IsSticky());
}
-bool ApplicationLauncherIcon::OwnsWindow(Window xid) const
-{
- GList* children, *l;
- bool owns = false;
-
- if (!xid || !_bamf_app)
- return owns;
-
- children = bamf_view_get_children(BAMF_VIEW(_bamf_app.RawPtr()));
-
- for (l = children; l; l = l->next)
- {
- if (!BAMF_IS_WINDOW(l->data))
- continue;
-
- if (bamf_window_get_xid(static_cast<BamfWindow*>(l->data)) == xid)
- {
- owns = true;
- break;
- }
- }
-
- g_list_free(children);
- return owns;
-}
-void ApplicationLauncherIcon::OpenInstanceWithUris(std::set<std::string> uris)
+void ApplicationLauncherIcon::OpenInstanceWithUris(std::set<std::string> const& uris)
{
glib::Error error;
glib::Object<GDesktopAppInfo> desktopInfo(g_desktop_app_info_new_from_filename(DesktopFile().c_str()));
@@ -596,7 +517,9 @@ void ApplicationLauncherIcon::OpenInstanceWithUris(std::set<std::string> uris)
}
if (error)
- g_warning("%s\n", error.Message().c_str());
+ {
+ LOG_WARN(logger) << error;
+ }
UpdateQuirkTime(Quirk::STARTING);
}
@@ -607,122 +530,33 @@ void ApplicationLauncherIcon::OpenInstanceLauncherIcon()
OpenInstanceWithUris(empty);
}
-std::vector<Window> ApplicationLauncherIcon::GetFocusableWindows(ActionArg arg, bool &any_visible, bool &any_urgent)
+void ApplicationLauncherIcon::Focus(ActionArg arg)
{
- bool any_user_visible = false;
- WindowManager& wm = WindowManager::Default();
-
- std::vector<Window> windows;
- GList* children;
-
- BamfView *focusable_child = BAMF_VIEW(bamf_application_get_focusable_child(_bamf_app.RawPtr()));
-
- if (focusable_child != NULL)
- {
- Window xid = 0;
-
- if (BAMF_IS_WINDOW(focusable_child))
- {
- xid = bamf_window_get_xid(BAMF_WINDOW(focusable_child));
- }
- else if (BAMF_IS_TAB(focusable_child))
- {
- BamfTab *focusable_tab = BAMF_TAB(focusable_child);
- xid = bamf_tab_get_xid(focusable_tab);
- bamf_tab_raise(focusable_tab);
- }
-
- if (xid)
- {
- windows.push_back(xid);
- return windows;
- }
- }
- else
+ ApplicationWindowPtr window = app_->GetFocusableWindow();
+ if (window)
{
- if (g_strcmp0(bamf_application_get_application_type(_bamf_app.RawPtr()), "webapp") == 0)
- {
- OpenInstanceLauncherIcon();
-
- return windows;
- }
+ // If we have a window, try to focus it.
+ if (window->Focus())
+ return;
}
-
- children = bamf_view_get_children(BAMF_VIEW(_bamf_app.RawPtr()));
-
- /* get the list of windows */
- for (GList* l = children; l; l = l->next)
+ else if (app_->type() == "webapp")
{
- if (!BAMF_IS_WINDOW(l->data))
- continue;
-
- auto view = static_cast<BamfView*>(l->data);
-
- Window xid = bamf_window_get_xid(static_cast<BamfWindow*>(l->data));
- bool urgent = bamf_view_is_urgent(view);
- bool user_visible = bamf_view_is_user_visible(view);
-
- if (any_urgent)
- {
- if (urgent)
- windows.push_back(xid);
- }
- else if (any_user_visible && !urgent)
- {
- if (user_visible)
- windows.push_back(xid);
- }
- else
- {
- if (urgent || user_visible)
- {
- windows.clear();
- any_visible = false;
- any_urgent = (any_urgent || urgent);
- any_user_visible = (any_user_visible || user_visible);
- }
-
- windows.push_back(xid);
- }
-
- if (wm.IsWindowOnCurrentDesktop(xid) && wm.IsWindowVisible(xid))
- {
- any_visible = true;
- }
+ // Webapps are again special.
+ OpenInstanceLauncherIcon();
+ return;
}
- g_list_free(children);
-
- return windows;
-
+ bool show_only_visible = arg.source == ActionArg::SWITCHER;
+ app_->Focus(show_only_visible, arg.monitor);
}
-void ApplicationLauncherIcon::Focus(ActionArg arg)
+bool ApplicationLauncherIcon::Spread(bool current_desktop, int state, bool force)
{
- bool any_visible = false, any_urgent = false;
- std::vector<Window> windows = GetFocusableWindows(arg, any_visible, any_urgent);
-
- auto visibility = WindowManager::FocusVisibility::OnlyVisible;
-
- if (arg.source != ActionArg::SWITCHER)
+ std::vector<Window> windows;
+ for (auto& window : GetWindows(current_desktop ? WindowFilter::ON_CURRENT_DESKTOP : 0))
{
- if (any_visible)
- {
- visibility = WindowManager::FocusVisibility::ForceUnminimizeInvisible;
- }
- else
- {
- visibility = WindowManager::FocusVisibility::ForceUnminimizeOnCurrentDesktop;
- }
+ windows.push_back(window->window_id());
}
-
- bool only_top_win = !any_urgent;
- WindowManager::Default().FocusWindowGroup(windows, visibility, arg.monitor, only_top_win);
-}
-
-bool ApplicationLauncherIcon::Spread(bool current_desktop, int state, bool force)
-{
- auto windows = GetWindows(current_desktop ? WindowFilter::ON_CURRENT_DESKTOP : 0);
return WindowManager::Default().ScaleWindowGroup(windows, state, force);
}
@@ -731,47 +565,24 @@ void ApplicationLauncherIcon::EnsureWindowState()
std::vector<bool> monitors;
monitors.resize(max_num_monitors);
- if (BAMF_IS_VIEW(_bamf_app.RawPtr()))
+ for (auto& window: app_->GetWindows())
{
- GList* children = bamf_view_get_children(BAMF_VIEW(_bamf_app.RawPtr()));
- for (GList* l = children; l; l = l->next)
- {
- Window xid;
+ int monitor = window->monitor();
+ Window window_id = window->window_id();
- if (BAMF_IS_TAB(l->data))
+ if (WindowManager::Default().IsWindowOnCurrentDesktop(window_id))
+ {
+ // If monitor is -1 (or negative), show on all monitors.
+ if (monitor < 0)
{
- /* BamfTab does not support the monitor interface...so a bit of a nasty hack here. */
- xid = bamf_tab_get_xid (static_cast<BamfTab*>(l->data));
-
- if (WindowManager::Default().IsWindowOnCurrentDesktop(xid) == false)
- continue;
-
for (int j = 0; j < max_num_monitors; j++)
monitors[j] = true;
-
- continue;
}
-
- if (!BAMF_IS_WINDOW(l->data))
- continue;
-
- auto window = static_cast<BamfWindow*>(l->data);
- xid = bamf_window_get_xid(window);
- int monitor = bamf_window_get_monitor(window);
-
- if (monitor >= 0 && WindowManager::Default().IsWindowOnCurrentDesktop(xid))
+ else
monitors[monitor] = true;
}
-
- g_list_free(children);
- }
- else
- {
- if (_bamf_app)
- {
- LOG_WARNING(logger) << "Not a view but not null.";
- }
}
+
for (int i = 0; i < max_num_monitors; i++)
SetWindowVisibleOnMonitor(monitors[i], i);
@@ -850,28 +661,17 @@ void ApplicationLauncherIcon::UpdateBackgroundColor()
void ApplicationLauncherIcon::UpdateMenus()
{
- GList* children, *l;
-
- children = bamf_view_get_children(BAMF_VIEW(_bamf_app.RawPtr()));
- for (l = children; l; l = l->next)
+ for (auto& app_menu : app_->GetRemoteMenus())
{
- if (!BAMF_IS_INDICATOR(l->data))
- continue;
-
- auto indicator = static_cast<BamfIndicator*>(l->data);
- std::string path = bamf_indicator_get_dbus_menu_path(indicator);
-
// we already have this
- if (_menu_clients.find(path) != _menu_clients.end())
+ if (_menu_clients.find(app_menu.path) != _menu_clients.end())
continue;
- std::string address = bamf_indicator_get_remote_address(indicator);
- glib::Object<DbusmenuClient> client(dbusmenu_client_new(address.c_str(), path.c_str()));
- _menu_clients[path] = client;
+ glib::Object<DbusmenuClient> client(dbusmenu_client_new(app_menu.remote_address.c_str(),
+ app_menu.path.c_str()));
+ _menu_clients[app_menu.path] = client;
}
- g_list_free(children);
-
// add dynamic quicklist
if (_menuclient_dynamic_quicklist && _menuclient_dynamic_quicklist.IsType(DBUSMENU_TYPE_CLIENT))
{
@@ -895,26 +695,7 @@ void ApplicationLauncherIcon::UpdateMenus()
void ApplicationLauncherIcon::Quit()
{
- GList* children, *l;
-
- children = bamf_view_get_children(BAMF_VIEW(_bamf_app.RawPtr()));
-
- for (l = children; l; l = l->next)
- {
- if (BAMF_IS_TAB (l->data))
- {
- // As Unity can not close a tab inside the provider application, we have to ask Bamf to delegate for us.
- bamf_tab_close (BAMF_TAB (l->data));
- continue;
- }
- if (!BAMF_IS_WINDOW(l->data))
- continue;
-
- Window xid = bamf_window_get_xid(static_cast<BamfWindow*>(l->data));
- WindowManager::Default().Close(xid);
- }
-
- g_list_free(children);
+ app_->Quit();
}
void ApplicationLauncherIcon::AboutToRemove()
@@ -928,8 +709,7 @@ void ApplicationLauncherIcon::Stick(bool save)
if (IsSticky())
return;
- bamf_view_set_sticky(BAMF_VIEW(_bamf_app.RawPtr()), true);
-
+ app_->sticky = true;
SimpleLauncherIcon::Stick(save);
}
@@ -940,12 +720,8 @@ void ApplicationLauncherIcon::UnStick()
if (!IsSticky())
return;
- BamfView* view = BAMF_VIEW(_bamf_app.RawPtr());
- bamf_view_set_sticky(view, false);
-
- SetQuirk(Quirk::VISIBLE, bamf_view_is_user_visible(view));
-
- if (bamf_view_is_closed(view))
+ app_->sticky = false;
+ if (!app_->running())
Remove();
}
@@ -1086,7 +862,7 @@ AbstractLauncherIcon::MenuItemsVector ApplicationLauncherIcon::GetMenus()
}
else
{
- glib::String app_name(g_markup_escape_text(BamfName().c_str(), -1));
+ glib::String app_name(g_markup_escape_text(app_->title().c_str(), -1));
std::ostringstream bold_app_name;
bold_app_name << "<b>" << app_name << "</b>";
@@ -1163,36 +939,25 @@ AbstractLauncherIcon::MenuItemsVector ApplicationLauncherIcon::GetMenus()
void ApplicationLauncherIcon::UpdateIconGeometries(std::vector<nux::Point3> center)
{
- if (!BAMF_IS_VIEW(_bamf_app.RawPtr()))
- {
- if (_bamf_app)
- {
- LOG_WARNING(logger) << "Not a view but not null.";
- }
- return;
- }
-
nux::Geometry geo;
geo.width = 48;
geo.height = 48;
- GList* children = bamf_view_get_children(BAMF_VIEW(_bamf_app.RawPtr()));
-
- for (GList* l = children; l; l = l->next)
+ for (auto& window : app_->GetWindows())
{
- if (!BAMF_IS_WINDOW(l->data))
+ // We don't deal with tabs.
+ if (window->type() == "tab")
continue;
- Window xid = bamf_window_get_xid(static_cast<BamfWindow*>(l->data));
- int monitor = bamf_window_get_monitor(static_cast<BamfWindow*>(l->data));
+ Window xid = window->window_id();
+ int monitor = window->monitor();
monitor = std::max<int>(0, std::min<int>(center.size() - 1, monitor));
+ // TODO: replace 24 with icon_size / 2;
geo.x = center[monitor].x - 24;
geo.y = center[monitor].y - 24;
WindowManager::Default().SetWindowIconGeometry(xid, geo);
}
-
- g_list_free(children);
}
void ApplicationLauncherIcon::OnCenterStabilized(std::vector<nux::Point3> center)
@@ -1324,22 +1089,17 @@ bool ApplicationLauncherIcon::ShowInSwitcher(bool current)
unsigned long long ApplicationLauncherIcon::SwitcherPriority()
{
- GList* children, *l;
unsigned long long result = 0;
+ // Webapps always go at the back.
+ if (app_->type() == "webapp")
+ return result;
- children = bamf_view_get_children(BAMF_VIEW(_bamf_app.RawPtr()));
-
- /* get the list of windows */
- for (l = children; l; l = l->next)
+ for (auto& window : app_->GetWindows())
{
- if (!BAMF_IS_WINDOW(l->data))
- continue;
-
- Window xid = bamf_window_get_xid(static_cast<BamfWindow*>(l->data));
+ Window xid = window->window_id();
result = std::max(result, WindowManager::Default().GetWindowActiveNumber(xid));
}
- g_list_free(children);
return result;
}
@@ -1354,15 +1114,10 @@ nux::Color ApplicationLauncherIcon::BackgroundColor() const
const std::set<std::string> ApplicationLauncherIcon::GetSupportedTypes()
{
std::set<std::string> supported_types;
- std::unique_ptr<gchar*[], void(*)(gchar**)> mimes(bamf_application_get_supported_mime_types(_bamf_app),
- g_strfreev);
-
- if (!mimes)
- return supported_types;
- for (int i = 0; mimes[i]; i++)
+ for (auto& type : app_->GetSupportedMimeTypes())
{
- unity::glib::String super_type(g_content_type_from_mime_type(mimes[i]));
+ unity::glib::String super_type(g_content_type_from_mime_type(type.c_str()));
supported_types.insert(super_type.Str());
}
diff --git a/launcher/ApplicationLauncherIcon.h b/launcher/ApplicationLauncherIcon.h
index 7e64df53f..ceef2323f 100644
--- a/launcher/ApplicationLauncherIcon.h
+++ b/launcher/ApplicationLauncherIcon.h
@@ -24,7 +24,6 @@
#include <UnityCore/GLibSignal.h>
#include <UnityCore/GLibWrapper.h>
-#include <libbamf/libbamf.h>
#include <libindicator/indicator-desktop-shortcuts.h>
#include "SimpleLauncherIcon.h"
@@ -40,7 +39,7 @@ class ApplicationLauncherIcon : public SimpleLauncherIcon
{
NUX_DECLARE_OBJECT_TYPE(ApplicationLauncherIcon, SimpleLauncherIcon);
public:
- ApplicationLauncherIcon(BamfApplication* app);
+ ApplicationLauncherIcon(ApplicationPtr const& app);
virtual ~ApplicationLauncherIcon();
virtual void ActivateLauncherIcon(ActionArg arg);
@@ -63,7 +62,7 @@ public:
virtual nux::Color BackgroundColor() const;
- std::vector<Window> Windows();
+ WindowList Windows();
std::vector<Window> WindowsOnViewport();
std::vector<Window> WindowsForMonitor(int monitor);
@@ -86,7 +85,6 @@ protected:
std::set<std::string> ValidateUrisForLaunch(DndData const& dnd_data);
std::string GetRemoteUri();
- std::string BamfName() const;
bool HandlesSpread() { return true; }
std::string GetName() const;
@@ -108,21 +106,18 @@ private:
void UpdateMenus();
void UpdateDesktopQuickList();
- void OpenInstanceWithUris(std::set<std::string> uris);
+ void OpenInstanceWithUris(std::set<std::string> const& uris);
void Focus(ActionArg arg);
- std::vector<Window> GetFocusableWindows(ActionArg arg, bool &any_visible, bool &any_urgent);
bool Spread(bool current_desktop, int state, bool force);
void OnWindowMinimized(guint32 xid);
void OnWindowMoved(guint32 xid);
- bool OwnsWindow(Window w) const;
-
- std::vector<Window> GetWindows(WindowFilterMask filter = 0, int monitor = -1);
+ WindowList GetWindows(WindowFilterMask filter = 0, int monitor = -1);
const std::set<std::string> GetSupportedTypes();
std::string GetDesktopID();
- glib::Object<BamfApplication> _bamf_app;
+ ApplicationPtr app_;
std::string _remote_uri;
std::string _desktop_file;
diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt
index 3917b28b7..2f621763a 100644
--- a/launcher/CMakeLists.txt
+++ b/launcher/CMakeLists.txt
@@ -97,13 +97,19 @@ set (SWITCHER_SOURCES
add_library (switcher-lib STATIC ${SWITCHER_SOURCES})
add_dependencies (switcher-lib unity-core-${UNITY_API_VERSION} unity-shared)
+set (LAUNCHER_LIBS
+ launcher-lib
+ unity-shared
+ unity-shared-bamf
+ unity-shared-standalone)
+
#
# Standalone variant
#
add_executable (launcher StandaloneLauncher.cpp)
-target_link_libraries (launcher launcher-lib unity-shared unity-shared-standalone)
+target_link_libraries (launcher ${LAUNCHER_LIBS})
if (ENABLE_X_SUPPORT)
add_executable (switcher StandaloneSwitcher.cpp)
- target_link_libraries (switcher switcher-lib launcher-lib unity-shared unity-shared-standalone)
+ target_link_libraries (switcher switcher-lib ${LAUNCHER_LIBS})
endif ()
diff --git a/launcher/LauncherController.cpp b/launcher/LauncherController.cpp
index e5c632b64..b0a69e9bc 100644
--- a/launcher/LauncherController.cpp
+++ b/launcher/LauncherController.cpp
@@ -21,7 +21,6 @@
#include "config.h"
#include <glib/gi18n-lib.h>
-#include <libbamf/libbamf.h>
#include <Nux/Nux.h>
#include <Nux/HLayout.h>
@@ -99,7 +98,6 @@ GDBusInterfaceVTable Controller::Impl::interface_vtable =
Controller::Impl::Impl(Controller* parent, XdndManager::Ptr const& xdnd_manager)
: parent_(parent)
, model_(std::make_shared<LauncherModel>())
- , matcher_(bamf_matcher_get_default())
, xdnd_manager_(xdnd_manager)
, device_section_(std::make_shared<VolumeMonitorWrapper>(), std::make_shared<DevicesSettingsImp>())
, expo_icon_(new ExpoLauncherIcon())
@@ -181,7 +179,7 @@ Controller::Impl::~Impl()
}
if (gdbus_connection_ && reg_id_)
- g_dbus_connection_unregister_object(gdbus_connection_, reg_id_);
+ g_dbus_connection_unregister_object(gdbus_connection_, reg_id_);
g_bus_unown_name(dbus_owner_);
}
@@ -769,19 +767,11 @@ int Controller::Impl::GetLastIconPriority(std::string const& favorite_uri, bool
return icon_prio;
}
-void Controller::Impl::OnViewOpened(BamfMatcher* matcher, BamfView* view)
+void Controller::Impl::OnApplicationStarted(ApplicationPtr const& app)
{
- if (!BAMF_IS_APPLICATION(view))
+ if (app->sticky() || app->seen())
return;
- BamfApplication* app = BAMF_APPLICATION(view);
-
- if (bamf_view_is_sticky(view) ||
- g_object_get_qdata(G_OBJECT(app), g_quark_from_static_string("unity-seen")))
- {
- return;
- }
-
AbstractLauncherIcon::Ptr icon(new ApplicationLauncherIcon(app));
RegisterIcon(icon, GetLastIconPriority<ApplicationLauncherIcon>(local::RUNNING_APPS_URI));
}
@@ -814,20 +804,13 @@ AbstractLauncherIcon::Ptr Controller::Impl::CreateFavoriteIcon(std::string const
if (!desktop_id.empty())
{
- BamfApplication* app;
std::string const& desktop_path = DesktopUtilities::GetDesktopPathById(desktop_id);
-
- app = bamf_matcher_get_application_for_desktop_file(matcher_, desktop_path.c_str(), true);
-
- if (!app)
+ ApplicationPtr app = ApplicationManager::Default().GetApplicationForDesktopFile(desktop_path);
+ if (!app || app->seen())
return result;
- if (g_object_get_qdata(G_OBJECT(app), g_quark_from_static_string("unity-seen")))
- {
- bamf_view_set_sticky(BAMF_VIEW(app), true);
- return result;
- }
-
+ // Sticky apps are those that are in the launcher when not running.
+ app->sticky = true;
result = AbstractLauncherIcon::Ptr(new ApplicationLauncherIcon(app));
}
else if (icon_uri.find(FavoriteStore::URI_PREFIX_DEVICE) == 0)
@@ -884,20 +867,16 @@ SoftwareCenterLauncherIcon::Ptr Controller::Impl::CreateSCLauncherIcon(std::stri
std::string const& aptdaemon_trans_id,
std::string const& icon_path)
{
- BamfApplication* app;
SoftwareCenterLauncherIcon::Ptr result;
- app = bamf_matcher_get_application_for_desktop_file(matcher_, file_path.c_str(), true);
- if (!BAMF_IS_APPLICATION(app))
+ ApplicationPtr app = ApplicationManager::Default().GetApplicationForDesktopFile(file_path);
+ if (!app)
return result;
- if (g_object_get_qdata(G_OBJECT(app), g_quark_from_static_string("unity-seen")))
- {
- bamf_view_set_sticky(BAMF_VIEW(app), true);
+ app->sticky = true;
+ if (app->seen)
return result;
- }
- bamf_view_set_sticky(BAMF_VIEW(app), true);
result = new SoftwareCenterLauncherIcon(app, aptdaemon_trans_id, icon_path);
return result;
@@ -905,20 +884,16 @@ SoftwareCenterLauncherIcon::Ptr Controller::Impl::CreateSCLauncherIcon(std::stri
void Controller::Impl::AddRunningApps()
{
- std::shared_ptr<GList> apps(bamf_matcher_get_applications(matcher_), g_list_free);
-
- for (GList *l = apps.get(); l; l = l->next)
+ for (auto& app : ApplicationManager::Default().GetRunningApplications())
{
- if (!BAMF_IS_APPLICATION(l->data))
- continue;
-
- BamfApplication* app = BAMF_APPLICATION(l->data);
-
- if (g_object_get_qdata(G_OBJECT(app), g_quark_from_static_string("unity-seen")))
- continue;
-
- AbstractLauncherIcon::Ptr icon(new ApplicationLauncherIcon(app));
- RegisterIcon(icon, ++sort_priority_);
+ LOG_INFO(logger) << "Adding running app: " << app->title()
+ << ", seen already: "
+ << (app->seen() ? "yes" : "no");
+ if (!app->seen())
+ {
+ AbstractLauncherIcon::Ptr icon(new ApplicationLauncherIcon(app));
+ RegisterIcon(icon, ++sort_priority_);
+ }
}
}
@@ -938,38 +913,50 @@ void Controller::Impl::SetupIcons()
FavoriteList const& favs = favorite_store.GetFavorites();
bool running_apps_added = false;
bool devices_added = false;
-
for (auto const& fav_uri : favs)
{
if (fav_uri == local::RUNNING_APPS_URI)
{
+ LOG_INFO(logger) << "Adding running apps";
AddRunningApps();
running_apps_added = true;
continue;
}
else if (fav_uri == local::DEVICES_URI)
{
+ LOG_INFO(logger) << "Adding devices";
AddDevices();
devices_added = true;
continue;
}
+ LOG_INFO(logger) << "Adding favourite: " << fav_uri;
RegisterIcon(CreateFavoriteIcon(fav_uri), ++sort_priority_);
}
if (!running_apps_added)
+ {
+ LOG_INFO(logger) << "Adding running apps";
AddRunningApps();
+ }
if (model_->IconIndex(expo_icon_) < 0)
+ {
+ LOG_INFO(logger) << "Adding expo icon";
RegisterIcon(CreateFavoriteIcon(expo_icon_->RemoteUri()), ++sort_priority_);
+ }
if (!devices_added)
+ {
+ LOG_INFO(logger) << "Adding devices";
AddDevices();
+ }
if (std::find(favs.begin(), favs.end(), expo_icon_->RemoteUri()) == favs.end())
SaveIconsOrder();
- view_opened_signal_.Connect(matcher_, "view-opened", sigc::mem_fun(this, &Impl::OnViewOpened));
+ ApplicationManager::Default().application_started
+ .connect(sigc::mem_fun(this, &Impl::OnApplicationStarted));
device_section_.icon_added.connect(sigc::mem_fun(this, &Impl::OnDeviceIconAdded));
favorite_store.favorite_added.connect(sigc::mem_fun(this, &Impl::OnFavoriteStoreFavoriteAdded));
favorite_store.favorite_removed.connect(sigc::mem_fun(this, &Impl::OnFavoriteStoreFavoriteRemoved));
diff --git a/launcher/LauncherControllerPrivate.h b/launcher/LauncherControllerPrivate.h
index 6e35f182e..1fda57d2c 100644
--- a/launcher/LauncherControllerPrivate.h
+++ b/launcher/LauncherControllerPrivate.h
@@ -46,7 +46,7 @@ namespace unity
namespace launcher
{
-class Controller::Impl
+class Controller::Impl : public sigc::trackable
{
public:
Impl(Controller* parent, XdndManager::Ptr const& xdnd_manager);
@@ -100,7 +100,7 @@ public:
void OnWindowFocusChanged (guint32 xid);
- void OnViewOpened(BamfMatcher* matcher, BamfView* view);
+ void OnApplicationStarted(ApplicationPtr const& app);
void ReceiveMouseDownOutsideArea(int x, int y, unsigned long button_flags, unsigned long key_flags);
@@ -126,7 +126,6 @@ public:
Controller* parent_;
LauncherModel::Ptr model_;
- glib::Object<BamfMatcher> matcher_;
nux::ObjectPtr<Launcher> launcher_;
nux::ObjectPtr<Launcher> keyboard_launcher_;
XdndManager::Ptr xdnd_manager_;
@@ -155,7 +154,6 @@ public:
GDBusConnection* gdbus_connection_;
unsigned reg_id_;
- glib::Signal<void, BamfMatcher*, BamfView*> view_opened_signal_;
glib::SourceManager sources_;
UBusManager ubus;
diff --git a/launcher/LauncherIcon.h b/launcher/LauncherIcon.h
index 0971dc3bc..b6712796c 100644
--- a/launcher/LauncherIcon.h
+++ b/launcher/LauncherIcon.h
@@ -97,7 +97,7 @@ public:
int SortPriority();
- virtual std::vector<Window> Windows() { return std::vector<Window> (); }
+ virtual WindowList Windows() { return WindowList(); }
virtual std::vector<Window> WindowsOnViewport() { return std::vector<Window> (); }
diff --git a/launcher/LauncherModel.h b/launcher/LauncherModel.h
index d093a8047..bc5c832eb 100644
--- a/launcher/LauncherModel.h
+++ b/launcher/LauncherModel.h
@@ -112,8 +112,7 @@ public:
{
std::list<AbstractLauncherIcon::Ptr> result;
- iterator it;
- for (it = begin(); it != end(); it++)
+ for (iterator it = begin(), e = end(); it != e; ++it)
{
T* var = dynamic_cast<T*>((*it).GetPointer());
diff --git a/launcher/MockLauncherIcon.h b/launcher/MockLauncherIcon.h
index d00c6c569..147b34564 100644
--- a/launcher/MockLauncherIcon.h
+++ b/launcher/MockLauncherIcon.h
@@ -32,6 +32,7 @@
#include <sigc++/sigc++.h>
#include <libdbusmenu-glib/menuitem.h>
+#include "unity-shared/ApplicationManager.h"
#include "AbstractLauncherIcon.h"
@@ -39,6 +40,24 @@ namespace unity
{
namespace launcher
{
+class MockApplicationWindow : public ApplicationWindow
+{
+public:
+ MockApplicationWindow(Window xid) : xid_(xid) {}
+
+ std::string title() const { return "MockApplicationWindow"; }
+ virtual std::string icon() const { return ""; }
+ virtual std::string type() const { return "mock"; }
+
+ virtual Window window_id() const { return xid_; }
+ virtual int monitor() const { return -1; }
+ virtual ApplicationPtr application() const { return ApplicationPtr(); }
+ virtual bool Focus() const { return false; }
+ virtual void Quit() const {}
+private:
+ Window xid_;
+};
+
class MockLauncherIcon : public AbstractLauncherIcon
{
@@ -58,7 +77,7 @@ public:
}
std::string GetName() const { return "MockLauncherIcon"; }
-
+
void AddProperties(GVariantBuilder* builder) {}
void HideTooltip() {}
@@ -70,18 +89,18 @@ public:
return 0;
}
- std::vector<Window> Windows ()
+ WindowList Windows ()
{
- std::vector<Window> result;
+ WindowList result;
- result.push_back ((100 << 16) + 200);
- result.push_back ((500 << 16) + 200);
- result.push_back ((300 << 16) + 200);
- result.push_back ((200 << 16) + 200);
- result.push_back ((300 << 16) + 200);
- result.push_back ((100 << 16) + 200);
- result.push_back ((300 << 16) + 200);
- result.push_back ((600 << 16) + 200);
+ result.push_back(std::make_shared<MockApplicationWindow>((100 << 16) + 200));
+ result.push_back(std::make_shared<MockApplicationWindow>((500 << 16) + 200));
+ result.push_back(std::make_shared<MockApplicationWindow>((300 << 16) + 200));
+ result.push_back(std::make_shared<MockApplicationWindow>((200 << 16) + 200));
+ result.push_back(std::make_shared<MockApplicationWindow>((300 << 16) + 200));
+ result.push_back(std::make_shared<MockApplicationWindow>((100 << 16) + 200));
+ result.push_back(std::make_shared<MockApplicationWindow>((300 << 16) + 200));
+ result.push_back(std::make_shared<MockApplicationWindow>((600 << 16) + 200));
return result;
}
diff --git a/launcher/SoftwareCenterLauncherIcon.cpp b/launcher/SoftwareCenterLauncherIcon.cpp
index cfd72265d..cd94f06ae 100644
--- a/launcher/SoftwareCenterLauncherIcon.cpp
+++ b/launcher/SoftwareCenterLauncherIcon.cpp
@@ -40,18 +40,19 @@ const int INSTALL_TIP_DURATION = 1500;
NUX_IMPLEMENT_OBJECT_TYPE(SoftwareCenterLauncherIcon);
-SoftwareCenterLauncherIcon::SoftwareCenterLauncherIcon(BamfApplication* app,
+SoftwareCenterLauncherIcon::SoftwareCenterLauncherIcon(ApplicationPtr const& app,
std::string const& aptdaemon_trans_id,
std::string const& icon_path)
-: ApplicationLauncherIcon(app),
- aptdaemon_trans_("org.debian.apt",
- aptdaemon_trans_id,
- "org.debian.apt.transaction",
- G_BUS_TYPE_SYSTEM,
- G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START)
-, finished_(true)
-, needs_urgent_(false)
-, aptdaemon_trans_id_(aptdaemon_trans_id)
+ : ApplicationLauncherIcon(app)
+ , aptdaemon_trans_("org.debian.apt",
+ aptdaemon_trans_id,
+ "org.debian.apt.transaction",
+ G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START)
+ , finished_(true)
+ , needs_urgent_(false)
+ , aptdaemon_trans_id_(aptdaemon_trans_id)
+ , app_title_(app->title())
{
SetQuirk(Quirk::VISIBLE, false);
aptdaemon_trans_.Connect("PropertyChanged", sigc::mem_fun(this, &SoftwareCenterLauncherIcon::OnPropertyChanged));
@@ -124,7 +125,7 @@ void SoftwareCenterLauncherIcon::OnFinished(GVariant *params)
if (exit_state.Str() == "exit-success")
{
- tooltip_text = BamfName();
+ tooltip_text = app_title_;
SetQuirk(Quirk::PROGRESS, false);
SetQuirk(Quirk::URGENT, true);
SetProgress(0.0f);
diff --git a/launcher/SoftwareCenterLauncherIcon.h b/launcher/SoftwareCenterLauncherIcon.h
index 6b586f0b9..6f0306855 100644
--- a/launcher/SoftwareCenterLauncherIcon.h
+++ b/launcher/SoftwareCenterLauncherIcon.h
@@ -38,7 +38,7 @@ class SoftwareCenterLauncherIcon : public ApplicationLauncherIcon
public:
typedef nux::ObjectPtr<SoftwareCenterLauncherIcon> Ptr;
- SoftwareCenterLauncherIcon(BamfApplication* app,
+ SoftwareCenterLauncherIcon(ApplicationPtr const& app,
std::string const& aptdaemon_trans_id,
std::string const& icon_path);
@@ -63,6 +63,7 @@ private:
bool needs_urgent_;
std::string aptdaemon_trans_id_;
+ std::string app_title_;
};
}
diff --git a/launcher/SwitcherController.cpp b/launcher/SwitcherController.cpp
index bdfb5b30c..73726ee0e 100644
--- a/launcher/SwitcherController.cpp
+++ b/launcher/SwitcherController.cpp
@@ -470,8 +470,9 @@ void Controller::SelectFirstItem()
unsigned int second_first = 0; // second icons first highest active
WindowManager& wm = WindowManager::Default();
- for (guint32 xid : first->Windows())
+ for (auto& window : first->Windows())
{
+ guint32 xid = window->window_id();
unsigned int num = wm.GetWindowActiveNumber(xid);
if (num > first_highest)
@@ -485,8 +486,9 @@ void Controller::SelectFirstItem()
}
}
- for (guint32 xid : second->Windows())
+ for (auto& window : second->Windows())
{
+ guint32 xid = window->window_id();
second_first = std::max<unsigned long long>(wm.GetWindowActiveNumber(xid), second_first);
}
diff --git a/launcher/SwitcherModel.cpp b/launcher/SwitcherModel.cpp
index 931ecb18d..b489adae8 100644
--- a/launcher/SwitcherModel.cpp
+++ b/launcher/SwitcherModel.cpp
@@ -150,7 +150,10 @@ bool WindowOnOtherViewport(Window xid)
std::vector<Window> SwitcherModel::DetailXids()
{
std::vector<Window> results;
- results = Selection()->Windows();
+ for (auto& window : Selection()->Windows())
+ {
+ results.push_back(window->window_id());
+ }
if (only_detail_on_viewport)
{
diff --git a/plugins/unityshell/CMakeLists.txt b/plugins/unityshell/CMakeLists.txt
index 36db0176c..d4d170ae2 100644
--- a/plugins/unityshell/CMakeLists.txt
+++ b/plugins/unityshell/CMakeLists.txt
@@ -11,7 +11,7 @@ compiz_plugin (unityshell
LIBDIRS "${CMAKE_BINARY_DIR}/UnityCore"
)
add_dependencies(unityshell unity-core-${UNITY_API_VERSION} dash-lib launcher-lib switcher-lib hud-lib panel-lib shortcuts-lib unity-shared unity-shared-compiz)
-target_link_libraries(unityshell unity-core-${UNITY_API_VERSION} launcher-lib dash-lib switcher-lib hud-lib panel-lib shortcuts-lib unity-shared unity-shared-compiz)
+target_link_libraries(unityshell unity-core-${UNITY_API_VERSION} launcher-lib dash-lib switcher-lib hud-lib panel-lib shortcuts-lib unity-shared unity-shared-bamf unity-shared-compiz)
set_target_properties(unityshell
PROPERTIES INSTALL_RPATH "${CACHED_UNITY_PRIVATE_DEPS_LIBRARY_DIRS}"
INSTALL_RPATH_USE_LINK_PATH TRUE)
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 548da6bcc..1127a1529 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -96,6 +96,7 @@ if (GTEST_SRC_DIR AND
# The service that provides DBus services to test against
add_executable(test-gtest-service
+ mock-application.cpp
test_service_gdbus_wrapper.c
test_service_gdbus_wrapper.h
test_service_hud.c
@@ -205,6 +206,7 @@ if (GTEST_SRC_DIR AND
if (ENABLE_X_SUPPORT)
# Tests that require X
add_executable(test-gtest
+ mock-application.cpp
logger_helper.cpp
test_main.cpp
test_application_launcher_icon.cpp
diff --git a/tests/mock-application.cpp b/tests/mock-application.cpp
new file mode 100644
index 000000000..cb42243c4
--- /dev/null
+++ b/tests/mock-application.cpp
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2012 Canonical Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3, as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 3 along with this program. If not, see
+ * <http://www.gnu.org/licenses/>
+ *
+ * Authored by: Tim Penhey <tim.penhey@canonical.com>
+ */
+
+#include "mock-application.h"
+
+
+namespace unity
+{
+// This function is used by the static Default method on the ApplicationManager
+// class, and uses link time to make sure there is a function available.
+std::shared_ptr<ApplicationManager> create_application_manager()
+{
+ return std::shared_ptr<ApplicationManager>(new testmocks::MockApplicationManager());
+}
+
+}
diff --git a/tests/mock-application.h b/tests/mock-application.h
index fb9d09279..728942cd8 100644
--- a/tests/mock-application.h
+++ b/tests/mock-application.h
@@ -19,8 +19,10 @@
#ifndef TESTS_MOCK_APPLICATION_H
#define TESTS_MOCK_APPLICATION_H
+#include <map>
#include "unity-shared/ApplicationManager.h"
+
namespace testmocks
{
class MockApplication : public unity::Application
@@ -103,6 +105,46 @@ public:
bool GetUrgent() const { return urgent_; }
};
+class MockApplicationManager : public unity::ApplicationManager
+{
+public:
+ static void StartApp(std::string const& desktop_file)
+ {
+ // We know the application manager is a mock one so we can cast it.
+ auto self = dynamic_cast<MockApplicationManager&>(unity::ApplicationManager::Default());
+ auto app = self.GetApplicationForDesktopFile(desktop_file);
+ self.application_started.emit(app);
+ }
+
+ virtual unity::ApplicationWindowPtr GetActiveWindow()
+ {
+ return unity::ApplicationWindowPtr();
+ }
+
+ unity::ApplicationPtr GetApplicationForDesktopFile(std::string const& desktop_file)
+ {
+ AppMap::iterator iter = app_map_.find(desktop_file);
+ if (iter == app_map_.end())
+ {
+ unity::ApplicationPtr app(new MockApplication(desktop_file));
+ app_map_.insert(AppMap::value_type(desktop_file, app));
+ return app;
+ }
+ else
+ {
+ return iter->second;
+ }
+ }
+
+ unity::ApplicationList GetRunningApplications()
+ {
+ return unity::ApplicationList();
+ }
+private:
+ typedef std::map<std::string, unity::ApplicationPtr> AppMap;
+ AppMap app_map_;
+};
+
}
#endif
diff --git a/tests/test_application_launcher_icon.cpp b/tests/test_application_launcher_icon.cpp
index 0ae91e76f..f409473d9 100644
--- a/tests/test_application_launcher_icon.cpp
+++ b/tests/test_application_launcher_icon.cpp
@@ -27,14 +27,15 @@
#include "ApplicationLauncherIcon.h"
#include "FavoriteStore.h"
-#include "bamf-mock-application.h"
+#include "mock-application.h"
+
using namespace unity;
+using namespace testmocks;
using namespace unity::launcher;
namespace
{
-
const std::string DEFAULT_EMPTY_ICON = "application-default-icon";
const std::string USC_DESKTOP = BUILDDIR"/tests/data/applications/ubuntu-software-center.desktop";
const std::string NO_ICON_DESKTOP = BUILDDIR"/tests/data/applications/no-icon.desktop";
@@ -44,24 +45,22 @@ class TestApplicationLauncherIcon : public testing::Test
public:
virtual void SetUp()
{
- BamfApplication* bamf_app;
- bamf_matcher = bamf_matcher_get_default();
-
- bamf_app = bamf_matcher_get_application_for_desktop_file(bamf_matcher, USC_DESKTOP.c_str(), TRUE);
- usc_icon = new launcher::ApplicationLauncherIcon(bamf_app);
+ usc_app.reset(new MockApplication(USC_DESKTOP, "softwarecenter"));
+ usc_icon = new launcher::ApplicationLauncherIcon(usc_app);
ASSERT_EQ(usc_icon->DesktopFile(), USC_DESKTOP);
- bamf_app = bamf_matcher_get_application_for_desktop_file(bamf_matcher, NO_ICON_DESKTOP.c_str(), TRUE);
- empty_icon = new launcher::ApplicationLauncherIcon(bamf_app);
+ empty_app.reset(new MockApplication(NO_ICON_DESKTOP));
+ empty_icon = new launcher::ApplicationLauncherIcon(empty_app);
ASSERT_EQ(empty_icon->DesktopFile(), NO_ICON_DESKTOP);
- mock_app = bamf_mock_application_new();
- mock_icon = new launcher::ApplicationLauncherIcon(glib::object_cast<BamfApplication>(mock_app));
+ mock_app.reset(new MockApplication(""));
+ mock_icon = new launcher::ApplicationLauncherIcon(mock_app);
ASSERT_TRUE(mock_icon->DesktopFile().empty());
}
- glib::Object<BamfMatcher> bamf_matcher;
- glib::Object<BamfMockApplication> mock_app;
+ std::shared_ptr<MockApplication> usc_app;
+ std::shared_ptr<MockApplication> empty_app;
+ std::shared_ptr<MockApplication> mock_app;
nux::ObjectPtr<launcher::ApplicationLauncherIcon> usc_icon;
nux::ObjectPtr<launcher::ApplicationLauncherIcon> empty_icon;
nux::ObjectPtr<launcher::ApplicationLauncherIcon> mock_icon;
@@ -91,53 +90,39 @@ TEST_F(TestApplicationLauncherIcon, TestDefaultIcon)
TEST_F(TestApplicationLauncherIcon, Stick)
{
- BamfView* bamf_app = BAMF_VIEW(bamf_matcher_get_application_for_desktop_file(bamf_matcher, USC_DESKTOP.c_str(), FALSE));
- ASSERT_FALSE(bamf_view_is_sticky(bamf_app));
-
bool saved = false;
usc_icon->position_saved.connect([&saved] {saved = true;});
usc_icon->Stick(false);
- EXPECT_TRUE(bamf_view_is_sticky(bamf_app));
+ EXPECT_TRUE(usc_app->sticky());
EXPECT_TRUE(usc_icon->IsSticky());
EXPECT_TRUE(usc_icon->IsVisible());
EXPECT_FALSE(saved);
usc_icon->Stick(true);
EXPECT_FALSE(saved);
- bamf_view_set_sticky(bamf_app, FALSE);
}
TEST_F(TestApplicationLauncherIcon, StickAndSave)
{
- BamfView* bamf_app = BAMF_VIEW(bamf_matcher_get_application_for_desktop_file(bamf_matcher, USC_DESKTOP.c_str(), FALSE));
- ASSERT_FALSE(bamf_view_is_sticky(bamf_app));
-
bool saved = false;
usc_icon->position_saved.connect([&saved] {saved = true;});
usc_icon->Stick(true);
- EXPECT_TRUE(bamf_view_is_sticky(bamf_app));
+ EXPECT_TRUE(usc_app->sticky());
EXPECT_TRUE(usc_icon->IsSticky());
EXPECT_TRUE(usc_icon->IsVisible());
EXPECT_TRUE(saved);
- bamf_view_set_sticky(bamf_app, FALSE);
}
TEST_F(TestApplicationLauncherIcon, Unstick)
{
- BamfView* bamf_app = BAMF_VIEW(bamf_matcher_get_application_for_desktop_file(bamf_matcher, USC_DESKTOP.c_str(), FALSE));
- ASSERT_FALSE(bamf_view_is_sticky(bamf_app));
-
bool forgot = false;
usc_icon->position_forgot.connect([&forgot] {forgot = true;});
usc_icon->Stick(false);
- ASSERT_TRUE(bamf_view_is_sticky(bamf_app));
- ASSERT_TRUE(usc_icon->IsSticky());
-
usc_icon->UnStick();
- EXPECT_FALSE(bamf_view_is_sticky(bamf_app));
+ EXPECT_FALSE(usc_app->sticky());
EXPECT_FALSE(usc_icon->IsSticky());
EXPECT_FALSE(usc_icon->IsVisible());
EXPECT_TRUE(forgot);
@@ -152,32 +137,31 @@ TEST_F(TestApplicationLauncherIcon, RemoteUri)
TEST_F(TestApplicationLauncherIcon, EmptyTooltipUpdatesOnRunning)
{
ASSERT_TRUE(mock_icon->tooltip_text().empty());
- bamf_mock_application_set_name (mock_app, "Got Name");
-
+ mock_app->title_ = "Got Name";
ASSERT_TRUE(mock_icon->tooltip_text().empty());
- bamf_mock_application_set_running(mock_app, TRUE);
+ mock_app->SetRunState(true);
EXPECT_EQ(mock_icon->tooltip_text(), "Got Name");
- bamf_mock_application_set_running(mock_app, FALSE);
- bamf_mock_application_set_name (mock_app, "New Name");
- bamf_mock_application_set_running(mock_app, TRUE);
+ mock_app->SetRunState(false);
+ mock_app->title_ = "New Name";
+ mock_app->SetRunState(true);
EXPECT_EQ(mock_icon->tooltip_text(), "Got Name");
}
TEST_F(TestApplicationLauncherIcon, InvalidIconUpdatesOnRunning)
{
ASSERT_EQ(mock_icon->icon_name(), DEFAULT_EMPTY_ICON);
- bamf_mock_application_set_icon (mock_app, "icon-name");
+ mock_app->icon_ = "icon-name";
ASSERT_EQ(mock_icon->icon_name(), DEFAULT_EMPTY_ICON);
- bamf_mock_application_set_running(mock_app, TRUE);
+ mock_app->SetRunState(true);
EXPECT_EQ(mock_icon->icon_name(), "icon-name");
- bamf_mock_application_set_running(mock_app, FALSE);
- bamf_mock_application_set_icon (mock_app, "new-icon-name");
- bamf_mock_application_set_running(mock_app, TRUE);
+ mock_app->SetRunState(false);
+ mock_app->icon_ = "new-icon-name";
+ mock_app->SetRunState(true);
EXPECT_EQ(mock_icon->icon_name(), "icon-name");
}
diff --git a/tests/test_launcher_controller.cpp b/tests/test_launcher_controller.cpp
index cf6cb1c6f..ebdb0f66f 100644
--- a/tests/test_launcher_controller.cpp
+++ b/tests/test_launcher_controller.cpp
@@ -37,8 +37,10 @@
#include "test_utils.h"
#include "test_uscreen_mock.h"
#include "test_mock_devices.h"
-#include "bamf-mock-application.h"
+#include "mock-application.h"
+
+using namespace testmocks;
using namespace unity::launcher;
using namespace testing;
@@ -134,21 +136,21 @@ struct MockApplicationLauncherIcon : public ApplicationLauncherIcon
typedef bool Fake;
MockApplicationLauncherIcon(Fake = true, std::string const& remote_uri = "")
- : ApplicationLauncherIcon(BAMF_APPLICATION(bamf_mock_application_new()))
+ : ApplicationLauncherIcon(std::make_shared<MockApplication>(""))
, remote_uri_(remote_uri)
{
InitMock();
SetQuirk(Quirk::VISIBLE, true);
}
- explicit MockApplicationLauncherIcon(BamfApplication* app)
+ explicit MockApplicationLauncherIcon(ApplicationPtr const& app)
: ApplicationLauncherIcon(app)
{
InitMock();
}
MockApplicationLauncherIcon(std::string const& desktop_file)
- : ApplicationLauncherIcon(bamf_matcher_get_application_for_desktop_file(bamf_matcher_get_default(), desktop_file.c_str(), TRUE))
+ : ApplicationLauncherIcon(std::make_shared<MockApplication>(desktop_file))
{
InitMock();
}
@@ -258,7 +260,7 @@ protected:
void DisconnectSignals()
{
- Impl()->view_opened_signal_.Disconnect();
+ // Impl()->view_opened_signal_.Disconnect();
Impl()->device_section_.icon_added.clear();
Impl()->model_->icon_removed.clear();
Impl()->model_->saved.clear();
@@ -283,7 +285,6 @@ TEST_F(TestLauncherController, Construction)
ASSERT_EQ(lc.launchers().size(), 1);
EXPECT_EQ(lc.launcher().monitor(), 0);
ASSERT_EQ(lc.Impl()->parent_, &lc);
- ASSERT_TRUE(lc.Impl()->matcher_.IsType(BAMF_TYPE_MATCHER));
ASSERT_NE(lc.Impl()->model_, nullptr);
EXPECT_EQ(lc.Impl()->expo_icon_->GetIconType(), AbstractLauncherIcon::IconType::EXPO);
EXPECT_EQ(lc.Impl()->desktop_icon_->GetIconType(), AbstractLauncherIcon::IconType::DESKTOP);
@@ -530,7 +531,7 @@ TEST_F(TestLauncherController, CreateFavoriteDesktopFile)
TEST_F(TestLauncherController, CreateFavoriteInvalidDesktopFile)
{
// This desktop file has already been added as favorite, so it is invalid
- std::string desktop_file = *(favorite_store.GetFavorites().begin());
+ std::string desktop_file = app::UBUNTU_ONE;
std::string icon_uri = FavoriteStore::URI_PREFIX_APP + desktop_file;
auto const& fav = lc.Impl()->CreateFavoriteIcon(icon_uri);
@@ -723,22 +724,15 @@ TEST_F(TestLauncherController, AddRunningApps)
lc.DisconnectSignals();
lc.Impl()->AddRunningApps();
- std::shared_ptr<GList> apps(bamf_matcher_get_applications(lc.Impl()->matcher_), g_list_free);
-
- for (GList *l = apps.get(); l; l = l->next)
+ // This test should be rewritten to not use the default application manager.
+ for (auto& app : ApplicationManager::Default().GetRunningApplications())
{
- if (!BAMF_IS_APPLICATION(l->data))
- continue;
-
- if (bamf_view_is_sticky(BAMF_VIEW(l->data)))
+ if (app->sticky())
continue;
- BamfApplication* app = BAMF_APPLICATION(l->data);
- ASSERT_NE(g_object_get_qdata(G_OBJECT(app), g_quark_from_static_string("unity-seen")), nullptr);
-
- auto desktop = bamf_application_get_desktop_file(app);
- std::string path(desktop ? desktop : "");
+ ASSERT_TRUE(app->seen());
+ auto path = app->desktop_file();
if (path.empty())
continue;
@@ -778,7 +772,6 @@ TEST_F(TestLauncherController, SetupIcons)
FavoriteStore::URI_PREFIX_APP + app::UPDATE_MANAGER });
lc.Impl()->SetupIcons();
lc.DisconnectSignals();
- std::shared_ptr<GList> apps(bamf_matcher_get_applications(lc.Impl()->matcher_), g_list_free);
auto fav = lc.Impl()->GetIconByUri(FavoriteStore::URI_PREFIX_APP + app::UBUNTU_ONE);
EXPECT_EQ(model->IconIndex(fav), icon_index);
@@ -792,23 +785,19 @@ TEST_F(TestLauncherController, SetupIcons)
fav = lc.Impl()->GetIconByUri(FavoriteStore::URI_PREFIX_APP + app::UPDATE_MANAGER);
EXPECT_EQ(model->IconIndex(fav), ++icon_index);
- for (GList *l = apps.get(); l; l = l->next)
+ for (auto& app : ApplicationManager::Default().GetRunningApplications())
{
- if (!BAMF_IS_APPLICATION(l->data))
- continue;
-
- if (bamf_view_is_sticky(BAMF_VIEW(l->data)))
+ if (app->sticky())
continue;
- auto desktop = bamf_application_get_desktop_file(BAMF_APPLICATION(l->data));
- std::string path(desktop ? desktop : "");
- ++icon_index;
+ ASSERT_TRUE(app->seen());
+ auto path = app->desktop_file();
if (path.empty())
continue;
auto icon = lc.GetIconByDesktop(path);
- ASSERT_EQ(model->IconIndex(icon), icon_index);
+ ASSERT_EQ(model->IconIndex(icon), ++icon_index);
}
ASSERT_EQ(model->IconIndex(lc.Impl()->expo_icon_), ++icon_index);
@@ -824,7 +813,6 @@ TEST_F(TestLauncherController, ResetIconPriorities)
favorite_store.AddFavorite(places::DEVICES_URI, -1);
lc.Impl()->SetupIcons();
lc.DisconnectSignals();
- std::shared_ptr<GList> apps(bamf_matcher_get_applications(lc.Impl()->matcher_), g_list_free);
favorite_store.SetFavorites({ places::DEVICES_URI,
FavoriteStore::URI_PREFIX_APP + app::SW_CENTER,
@@ -841,25 +829,19 @@ TEST_F(TestLauncherController, ResetIconPriorities)
auto fav = lc.Impl()->GetIconByUri(FavoriteStore::URI_PREFIX_APP + app::SW_CENTER);
EXPECT_EQ(model->IconIndex(fav), ++icon_index);
- for (GList *l = apps.get(); l; l = l->next)
+ for (auto& app : ApplicationManager::Default().GetRunningApplications())
{
- if (!BAMF_IS_APPLICATION(l->data))
+ if (app->sticky())
continue;
- if (bamf_view_is_sticky(BAMF_VIEW(l->data)))
- continue;
-
- auto desktop = bamf_application_get_desktop_file(BAMF_APPLICATION(l->data));
- std::string path(desktop ? desktop : "");
- ++icon_index;
+ ASSERT_TRUE(app->seen());
+ auto path = app->desktop_file();
if (path.empty())
continue;
- auto const& icon = lc.GetIconByDesktop(path);
-
- ASSERT_TRUE(icon.IsValid());
- ASSERT_EQ(model->IconIndex(icon), icon_index);
+ auto icon = lc.GetIconByDesktop(path);
+ ASSERT_EQ(model->IconIndex(icon), ++icon_index);
}
fav = lc.Impl()->GetIconByUri(FavoriteStore::URI_PREFIX_APP + app::UBUNTU_ONE);
@@ -1504,10 +1486,7 @@ TEST_F(TestLauncherController, OnViewOpened)
auto const& app_icons = lc.Impl()->model_->GetSublist<ApplicationLauncherIcon>();
auto const& last_app = *(app_icons.rbegin());
- auto app = bamf_matcher_get_application_for_desktop_file(lc.Impl()->matcher_, app::BZR_HANDLE_PATCH.c_str(), TRUE);
- g_signal_emit_by_name(lc.Impl()->matcher_, "view-opened", app);
- lc.DisconnectSignals();
-
+ testmocks::MockApplicationManager::StartApp(app::BZR_HANDLE_PATCH);
auto const& icon = lc.GetIconByDesktop(app::BZR_HANDLE_PATCH);
ASSERT_TRUE(icon.IsValid());
diff --git a/unity-shared/ApplicationManager.cpp b/unity-shared/ApplicationManager.cpp
index 401dab68f..8fe1a494b 100644
--- a/unity-shared/ApplicationManager.cpp
+++ b/unity-shared/ApplicationManager.cpp
@@ -19,6 +19,7 @@
#include "unity-shared/ApplicationManager.h"
+#include "unity-shared/WindowManager.h"
namespace unity
{
@@ -32,4 +33,18 @@ ApplicationManager& ApplicationManager::Default()
return *instance;
}
+
+namespace
+{
+// This method is needed to create an unresolved external for the
+// WindowManager::Default method. This is because it is highly likely that
+// the application manager implementations need the window manager for some
+// things, and in fact the bamf one does. In order to make the linker happy,
+// we need to make sure that we have this here.
+void dummy()
+{
+ WindowManager::Default();
+}
+}
+
} // namespace unity
diff --git a/unity-shared/ApplicationManager.h b/unity-shared/ApplicationManager.h
index cadc0e800..7ff8b0ba1 100644
--- a/unity-shared/ApplicationManager.h
+++ b/unity-shared/ApplicationManager.h
@@ -125,11 +125,11 @@ public:
static ApplicationManager& Default();
- virtual ApplicationWindowPtr GetActiveWindow() const = 0;
+ virtual ApplicationWindowPtr GetActiveWindow() = 0;
- virtual ApplicationPtr GetApplicationForDesktopFile(std::string const& desktop_file) const = 0;
+ virtual ApplicationPtr GetApplicationForDesktopFile(std::string const& desktop_file) = 0;
- virtual ApplicationList GetRunningApplications() const = 0;
+ virtual ApplicationList GetRunningApplications() = 0;
sigc::signal<void, ApplicationPtr const&> application_started;
diff --git a/unity-shared/BamfApplicationManager.cpp b/unity-shared/BamfApplicationManager.cpp
index 67e0e72ed..5fcccd8da 100644
--- a/unity-shared/BamfApplicationManager.cpp
+++ b/unity-shared/BamfApplicationManager.cpp
@@ -23,19 +23,10 @@
#include <NuxCore/Logger.h>
-
DECLARE_LOGGER(logger, "unity.appmanager.bamf");
-
namespace unity
{
-// This function is used by the static Default method on the ApplicationManager
-// class, and uses link time to make sure there is a function available.
-std::shared_ptr<ApplicationManager> create_application_manager()
-{
- return std::shared_ptr<ApplicationManager>(new bamf::Manager());
-}
-
namespace bamf
{
namespace
@@ -168,7 +159,10 @@ int AppWindow::monitor() const
ApplicationPtr AppWindow::application() const
{
- return manager_.GetApplicationForWindow(bamf_window_);
+ // Moderately evil, but better than changing the method to non-const.
+ // We know that the manager will always be able to be non-const.
+ Manager& m = const_cast<Manager&>(manager_);
+ return m.GetApplicationForWindow(bamf_window_);
}
void AppWindow::Quit() const
@@ -566,7 +560,7 @@ Manager::~Manager()
LOG_TRACE(logger) << "Manager::~Manager";
}
-ApplicationWindowPtr Manager::GetActiveWindow() const
+ApplicationWindowPtr Manager::GetActiveWindow()
{
ApplicationWindowPtr result;
// No transfer of ownership for bamf_matcher_get_active_window.
@@ -607,7 +601,7 @@ ApplicationWindowPtr Manager::GetActiveWindow() const
return result;
}
-ApplicationPtr Manager::GetApplicationForDesktopFile(std::string const& desktop_file) const
+ApplicationPtr Manager::GetApplicationForDesktopFile(std::string const& desktop_file)
{
ApplicationPtr result;
glib::Object<BamfApplication> app(bamf_matcher_get_application_for_desktop_file(
@@ -619,7 +613,7 @@ ApplicationPtr Manager::GetApplicationForDesktopFile(std::string const& desktop_
return result;
}
-ApplicationPtr Manager::GetApplicationForWindow(glib::Object<BamfWindow> const& window) const
+ApplicationPtr Manager::GetApplicationForWindow(glib::Object<BamfWindow> const& window)
{
ApplicationPtr result;
glib::Object<BamfApplication> app(bamf_matcher_get_application_for_window(matcher_, window),
@@ -629,7 +623,7 @@ ApplicationPtr Manager::GetApplicationForWindow(glib::Object<BamfWindow> const&
return result;
}
-ApplicationList Manager::GetRunningApplications() const
+ApplicationList Manager::GetRunningApplications()
{
ApplicationList result;
std::shared_ptr<GList> apps(bamf_matcher_get_applications(matcher_), g_list_free);
@@ -642,8 +636,10 @@ ApplicationList Manager::GetRunningApplications() const
continue;
}
- glib::Object<BamfApplication> app(static_cast<BamfApplication*>(l->data));
- result.push_back(ApplicationPtr(new Application(*this, app)));
+ glib::Object<BamfApplication> bamf_app(static_cast<BamfApplication*>(l->data));
+ ApplicationPtr app(new Application(*this, bamf_app));
+ result.push_back(app);
+ LOG_DEBUG(logger) << "Running app: " << app->title();
}
return result;
}
diff --git a/unity-shared/BamfApplicationManager.h b/unity-shared/BamfApplicationManager.h
index dbaf9e14c..9823c8e2e 100644
--- a/unity-shared/BamfApplicationManager.h
+++ b/unity-shared/BamfApplicationManager.h
@@ -150,14 +150,14 @@ public:
Manager();
~Manager();
- virtual ApplicationWindowPtr GetActiveWindow() const;
+ virtual ApplicationWindowPtr GetActiveWindow();
- virtual ApplicationPtr GetApplicationForDesktopFile(std::string const& desktop_file) const;
+ virtual ApplicationPtr GetApplicationForDesktopFile(std::string const& desktop_file);
- virtual ApplicationList GetRunningApplications() const;
+ virtual ApplicationList GetRunningApplications();
- virtual ApplicationPtr GetApplicationForWindow(glib::Object<BamfWindow> const& window) const;
+ virtual ApplicationPtr GetApplicationForWindow(glib::Object<BamfWindow> const& window);
private:
void OnViewOpened(BamfMatcher* matcher, BamfView* view);
diff --git a/unity-shared/BamfApplicationManagerFactory.cpp b/unity-shared/BamfApplicationManagerFactory.cpp
new file mode 100644
index 000000000..fb2c9d9ad
--- /dev/null
+++ b/unity-shared/BamfApplicationManagerFactory.cpp
@@ -0,0 +1,31 @@
+// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*-
+/*
+ * Copyright (C) 2012 Canonical Ltd
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 3 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * Authored by: Tim Penhey <tim.penhey@canonical.com>
+ */
+
+#include "unity-shared/BamfApplicationManager.h"
+
+namespace unity
+{
+// This function is used by the static Default method on the ApplicationManager
+// class, and uses link time to make sure there is a function available.
+std::shared_ptr<ApplicationManager> create_application_manager()
+{
+ return std::shared_ptr<ApplicationManager>(new bamf::Manager());
+}
+
+}
diff --git a/unity-shared/CMakeLists.txt b/unity-shared/CMakeLists.txt
index fe44bb0cb..8c5a6c202 100644
--- a/unity-shared/CMakeLists.txt
+++ b/unity-shared/CMakeLists.txt
@@ -73,7 +73,6 @@ set (UNITY_SHARED_SOURCES
if(ENABLE_X_SUPPORT)
set (UNITY_SHARED_SOURCES
- BamfApplicationManager.cpp
XKeyboardUtil.cpp
XWindowManager.cpp
${UNITY_SHARED_SOURCES}
@@ -102,6 +101,15 @@ if (ENABLE_X_SUPPORT)
target_link_libraries (unity-shared-compiz ${LIBS})
add_dependencies (unity-shared-compiz unity-shared)
+
+ # bamf application manager
+ set (UNITY_SHARED_BAMF_SOURCES
+ BamfApplicationManager.cpp
+ BamfApplicationManagerFactory.cpp
+ )
+ add_library (unity-shared-bamf STATIC ${UNITY_SHARED_BAMF_SOURCES})
+ target_link_libraries (unity-shared-bamf ${LIBS})
+ add_dependencies (unity-shared-bamf unity-shared)
endif()
# standalone
@@ -113,6 +121,6 @@ target_link_libraries (unity-shared-standalone ${LIBS})
add_dependencies (unity-shared-standalone unity-shared)
add_executable (app-manager StandaloneAppManager.cpp)
-add_dependencies (app-manager unity-shared)
-target_link_libraries (app-manager unity-shared unity-shared-standalone)
+add_dependencies (app-manager unity-shared unity-shared-bamf unity-shared-standalone)
+target_link_libraries (app-manager unity-shared unity-shared-bamf unity-shared-standalone)
diff --git a/unity-standalone/CMakeLists.txt b/unity-standalone/CMakeLists.txt
index d86a1a1e5..552f6352e 100644
--- a/unity-standalone/CMakeLists.txt
+++ b/unity-standalone/CMakeLists.txt
@@ -35,4 +35,5 @@ target_link_libraries (unity-standalone
launcher-lib
panel-lib
unity-shared
+ unity-shared-bamf
unity-shared-standalone)