Merge lp:~3v1n0/unity/application-manager-new into lp:unity

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Christopher Townsend
Approved revision: no longer in the source branch.
Merged at revision: 3975
Proposed branch: lp:~3v1n0/unity/application-manager-new
Merge into: lp:unity
Prerequisite: lp:~3v1n0/unity/lim-everywhere
Diff against target: 2037 lines (+583/-507)
15 files modified
launcher/ApplicationLauncherIcon.cpp (+11/-11)
launcher/MockLauncherIcon.h (+1/-1)
panel/CMakeLists.txt (+1/-1)
panel/PanelMenuView.cpp (+102/-251)
panel/PanelMenuView.h (+11/-21)
tests/mock-application.h (+15/-7)
tests/test_application_launcher_icon.cpp (+5/-2)
tests/test_panel_menu_view.cpp (+1/-8)
tests/test_switcher_controller.h (+1/-1)
tests/test_switcher_controller_class.cpp (+1/-1)
unity-shared/ApplicationManager.cpp (+19/-0)
unity-shared/ApplicationManager.h (+64/-6)
unity-shared/BamfApplicationManager.cpp (+215/-145)
unity-shared/BamfApplicationManager.h (+36/-18)
unity-shared/StandaloneAppManager.cpp (+100/-34)
To merge this branch: bzr merge lp:~3v1n0/unity/application-manager-new
Reviewer Review Type Date Requested Status
Christopher Townsend Approve
PS Jenkins bot (community) continuous-integration Approve
Stephen M. Webb (community) Needs Fixing
Review via email: mp+248778@code.launchpad.net

Commit message

ApplicationManager: add missing features, keep a copy of views around

Use this in PanelMenuView, getting rid of the BAMF internal at this level.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Christopher Townsend (townsend) wrote :

LGTM

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Stephen M. Webb (bregma) wrote :

One of the commits made after this MP was reviewd and approved cause unit test failures.

review: Needs Fixing
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Christopher Townsend (townsend) wrote :

Ok, all good now.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'launcher/ApplicationLauncherIcon.cpp'
--- launcher/ApplicationLauncherIcon.cpp 2015-03-25 14:59:04 +0000
+++ launcher/ApplicationLauncherIcon.cpp 2015-05-22 16:04:25 +0000
@@ -156,13 +156,14 @@
156{156{
157 // Lambda functions should be fine here because when the application the icon157 // Lambda functions should be fine here because when the application the icon
158 // is only ever removed when the application is closed.158 // is only ever removed when the application is closed.
159 signals_conn_.Add(app_->window_opened.connect([this](ApplicationWindow const&) {159 signals_conn_.Add(app_->window_opened.connect([this](ApplicationWindowPtr const&) {
160 EnsureWindowState();160 EnsureWindowState();
161 UpdateIconGeometries(GetCenters());161 UpdateIconGeometries(GetCenters());
162 }));162 }));
163163
164 signals_conn_.Add(app_->window_closed.connect(sigc::mem_fun(this, &ApplicationLauncherIcon::EnsureWindowState)));164 auto ensure_windows_cb = sigc::hide(sigc::mem_fun(this, &ApplicationLauncherIcon::EnsureWindowState));
165 signals_conn_.Add(app_->window_moved.connect(sigc::hide(sigc::mem_fun(this, &ApplicationLauncherIcon::EnsureWindowState))));165 signals_conn_.Add(app_->window_closed.connect(ensure_windows_cb));
166 signals_conn_.Add(app_->window_moved.connect(ensure_windows_cb));
166167
167 signals_conn_.Add(app_->urgent.changed.connect([this](bool const& urgent) {168 signals_conn_.Add(app_->urgent.changed.connect([this](bool const& urgent) {
168 LOG_DEBUG(logger) << tooltip_text() << " urgent now " << (urgent ? "true" : "false");169 LOG_DEBUG(logger) << tooltip_text() << " urgent now " << (urgent ? "true" : "false");
@@ -235,7 +236,7 @@
235 if (!SimpleLauncherIcon::GetQuirk(Quirk::ACTIVE, monitor))236 if (!SimpleLauncherIcon::GetQuirk(Quirk::ACTIVE, monitor))
236 return false;237 return false;
237238
238 if (app_->type() == "webapp")239 if (app_->type() == AppType::WEBAPP)
239 return true;240 return true;
240241
241 // Sometimes BAMF is not fast enough to update the active application242 // Sometimes BAMF is not fast enough to update the active application
@@ -702,7 +703,7 @@
702 if (window->Focus())703 if (window->Focus())
703 return;704 return;
704 }705 }
705 else if (app_->type() == "webapp")706 else if (app_->type() == AppType::WEBAPP)
706 {707 {
707 // Webapps are again special.708 // Webapps are again special.
708 OpenInstanceLauncherIcon(arg.timestamp);709 OpenInstanceLauncherIcon(arg.timestamp);
@@ -837,8 +838,6 @@
837 if (windows.size() < 2)838 if (windows.size() < 2)
838 return;839 return;
839840
840 Window active = WindowManager::Default().GetActiveWindow();
841
842 // add menu items for all open windows841 // add menu items for all open windows
843 for (auto const& w : windows)842 for (auto const& w : windows)
844 {843 {
@@ -862,7 +861,7 @@
862 wm.Raise(xid);861 wm.Raise(xid);
863 });862 });
864863
865 if (xid == active)864 if (w->active())
866 {865 {
867 dbusmenu_menuitem_property_set(menu_item, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE, DBUSMENU_MENUITEM_TOGGLE_RADIO);866 dbusmenu_menuitem_property_set(menu_item, DBUSMENU_MENUITEM_PROP_TOGGLE_TYPE, DBUSMENU_MENUITEM_TOGGLE_RADIO);
868 dbusmenu_menuitem_property_set_int(menu_item, DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED);867 dbusmenu_menuitem_property_set_int(menu_item, DBUSMENU_MENUITEM_PROP_TOGGLE_STATE, DBUSMENU_MENUITEM_TOGGLE_STATE_CHECKED);
@@ -1113,7 +1112,7 @@
11131112
1114void ApplicationLauncherIcon::UpdateIconGeometries(std::vector<nux::Point3> const& centers)1113void ApplicationLauncherIcon::UpdateIconGeometries(std::vector<nux::Point3> const& centers)
1115{1114{
1116 if (app_->type() == "webapp")1115 if (app_->type() == AppType::WEBAPP)
1117 return;1116 return;
11181117
1119 nux::Geometry geo(0, 0, icon_size, icon_size);1118 nux::Geometry geo(0, 0, icon_size, icon_size);
@@ -1189,6 +1188,7 @@
1189 auto const& desktop_file = DesktopFile();1188 auto const& desktop_file = DesktopFile();
11901189
1191 return boost::algorithm::ends_with(desktop_file, "org.gnome.Nautilus.desktop") ||1190 return boost::algorithm::ends_with(desktop_file, "org.gnome.Nautilus.desktop") ||
1191 boost::algorithm::ends_with(desktop_file, "nautilus.desktop") ||
1192 boost::algorithm::ends_with(desktop_file, "nautilus-folder-handler.desktop") ||1192 boost::algorithm::ends_with(desktop_file, "nautilus-folder-handler.desktop") ||
1193 boost::algorithm::ends_with(desktop_file, "nautilus-home.desktop");1193 boost::algorithm::ends_with(desktop_file, "nautilus-home.desktop");
1194}1194}
@@ -1264,14 +1264,14 @@
12641264
1265bool ApplicationLauncherIcon::AllowDetailViewInSwitcher() const1265bool ApplicationLauncherIcon::AllowDetailViewInSwitcher() const
1266{1266{
1267 return app_->type() != "webapp";1267 return app_->type() != AppType::WEBAPP;
1268}1268}
12691269
1270uint64_t ApplicationLauncherIcon::SwitcherPriority()1270uint64_t ApplicationLauncherIcon::SwitcherPriority()
1271{1271{
1272 uint64_t result = 0;1272 uint64_t result = 0;
1273 // Webapps always go at the back.1273 // Webapps always go at the back.
1274 if (app_->type() == "webapp")1274 if (app_->type() == AppType::WEBAPP)
1275 return result;1275 return result;
12761276
1277 for (auto& window : app_->GetWindows())1277 for (auto& window : app_->GetWindows())
12781278
=== modified file 'launcher/MockLauncherIcon.h'
--- launcher/MockLauncherIcon.h 2015-03-20 16:23:04 +0000
+++ launcher/MockLauncherIcon.h 2015-05-22 16:04:25 +0000
@@ -52,7 +52,7 @@
52 icon.SetGetterFunction([this] { return ""; });52 icon.SetGetterFunction([this] { return ""; });
53 }53 }
5454
55 virtual std::string type() const { return "mock"; }55 virtual WindowType type() const { return WindowType::UNKNOWN; }
5656
57 virtual Window window_id() const { return xid_; }57 virtual Window window_id() const { return xid_; }
58 virtual int monitor() const { return -1; }58 virtual int monitor() const { return -1; }
5959
=== modified file 'panel/CMakeLists.txt'
--- panel/CMakeLists.txt 2014-02-12 07:13:01 +0000
+++ panel/CMakeLists.txt 2015-05-22 16:04:25 +0000
@@ -36,4 +36,4 @@
36#36#
37add_executable (panel StandalonePanel.cpp)37add_executable (panel StandalonePanel.cpp)
38find_library (COMPIZ_LIB compiz_core ${COMPIZ_LIBDIR})38find_library (COMPIZ_LIB compiz_core ${COMPIZ_LIBDIR})
39target_link_libraries (panel panel-lib unity-shared unity-shared-standalone ${COMPIZ_LIB})39target_link_libraries (panel panel-lib unity-shared unity-shared-standalone unity-shared-bamf ${COMPIZ_LIB})
4040
=== modified file 'panel/PanelMenuView.cpp'
--- panel/PanelMenuView.cpp 2015-02-19 14:19:44 +0000
+++ panel/PanelMenuView.cpp 2015-05-22 16:04:25 +0000
@@ -20,6 +20,7 @@
2020
21#include <Nux/Nux.h>21#include <Nux/Nux.h>
22#include <NuxCore/Logger.h>22#include <NuxCore/Logger.h>
23#include <UnityCore/GLibWrapper.h>
23#include <boost/algorithm/string/erase.hpp>24#include <boost/algorithm/string/erase.hpp>
2425
25#include "PanelMenuView.h"26#include "PanelMenuView.h"
@@ -87,13 +88,11 @@
87 , maximized_window(0)88 , maximized_window(0)
88 , focused(true)89 , focused(true)
89 , menu_manager_(menus)90 , menu_manager_(menus)
90 , matcher_(bamf_matcher_get_default())
91 , is_inside_(false)91 , is_inside_(false)
92 , is_grabbed_(false)92 , is_grabbed_(false)
93 , is_maximized_(false)93 , is_maximized_(false)
94 , is_desktop_focused_(false)94 , is_desktop_focused_(false)
95 , last_active_view_(nullptr)95 , last_active_view_(nullptr)
96 , new_application_(nullptr)
97 , switcher_showing_(false)96 , switcher_showing_(false)
98 , spread_showing_(false)97 , spread_showing_(false)
99 , launcher_keynav_(false)98 , launcher_keynav_(false)
@@ -105,9 +104,8 @@
105 , always_show_menus_(menu_manager_->always_show_menus())104 , always_show_menus_(menu_manager_->always_show_menus())
106 , desktop_name_(get_current_desktop())105 , desktop_name_(get_current_desktop())
107{106{
108 BamfWindow* active_win = bamf_matcher_get_active_window(matcher_);107 if (ApplicationWindowPtr const& win = ApplicationManager::Default().GetActiveWindow())
109 if (BAMF_IS_WINDOW(active_win))108 active_window = win->window_id();
110 active_window = bamf_window_get_xid(active_win);
111109
112 SetupWindowButtons();110 SetupWindowButtons();
113 SetupTitlebarGrabArea();111 SetupTitlebarGrabArea();
@@ -117,8 +115,7 @@
117115
118 opacity = 0.0f;116 opacity = 0.0f;
119117
120 if (Refresh())118 RefreshAndRedraw();
121 FullRedraw();
122}119}
123120
124PanelMenuView::~PanelMenuView()121PanelMenuView::~PanelMenuView()
@@ -144,14 +141,11 @@
144141
145void PanelMenuView::SetupPanelMenuViewSignals()142void PanelMenuView::SetupPanelMenuViewSignals()
146{143{
147 active_win_changed_signal_.Connect(matcher_, "active-window-changed",144 auto& am = ApplicationManager::Default();
148 sigc::mem_fun(this, &PanelMenuView::OnActiveWindowChanged));145 am.active_window_changed.connect(sigc::mem_fun(this, &PanelMenuView::OnActiveWindowChanged));
149 active_app_changed_signal_.Connect(matcher_, "active-application-changed",146 am.active_application_changed.connect(sigc::mem_fun(this, &PanelMenuView::OnActiveAppChanged));
150 sigc::mem_fun(this, &PanelMenuView::OnActiveAppChanged));147 am.application_started.connect(sigc::mem_fun(this, &PanelMenuView::OnApplicationStarted));
151 view_opened_signal_.Connect(matcher_, "view-opened",148 am.application_stopped.connect(sigc::mem_fun(this, &PanelMenuView::OnApplicationClosed));
152 sigc::mem_fun(this, &PanelMenuView::OnViewOpened));
153 view_closed_signal_.Connect(matcher_, "view-closed",
154 sigc::mem_fun(this, &PanelMenuView::OnViewClosed));
155149
156 mouse_enter.connect(sigc::mem_fun(this, &PanelMenuView::OnPanelViewMouseEnter));150 mouse_enter.connect(sigc::mem_fun(this, &PanelMenuView::OnPanelViewMouseEnter));
157 mouse_leave.connect(sigc::mem_fun(this, &PanelMenuView::OnPanelViewMouseLeave));151 mouse_leave.connect(sigc::mem_fun(this, &PanelMenuView::OnPanelViewMouseLeave));
@@ -232,9 +226,9 @@
232 wm.window_resized.connect(sigc::mem_fun(this, &PanelMenuView::OnWindowMoved));226 wm.window_resized.connect(sigc::mem_fun(this, &PanelMenuView::OnWindowMoved));
233 wm.initiate_spread.connect(sigc::mem_fun(this, &PanelMenuView::OnSpreadInitiate));227 wm.initiate_spread.connect(sigc::mem_fun(this, &PanelMenuView::OnSpreadInitiate));
234 wm.terminate_spread.connect(sigc::mem_fun(this, &PanelMenuView::OnSpreadTerminate));228 wm.terminate_spread.connect(sigc::mem_fun(this, &PanelMenuView::OnSpreadTerminate));
235 wm.initiate_expo.connect(sigc::mem_fun(this, &PanelMenuView::OnExpoInitiate));229 wm.initiate_expo.connect(sigc::mem_fun(this, &PanelMenuView::RefreshAndRedraw));
236 wm.terminate_expo.connect(sigc::mem_fun(this, &PanelMenuView::OnExpoTerminate));230 wm.terminate_expo.connect(sigc::mem_fun(this, &PanelMenuView::RefreshAndRedraw));
237 wm.screen_viewport_switch_ended.connect(sigc::mem_fun(this, &PanelMenuView::OnExpoTerminate));231 wm.screen_viewport_switch_ended.connect(sigc::mem_fun(this, &PanelMenuView::RefreshAndRedraw));
238}232}
239233
240void PanelMenuView::SetupUBusManagerInterests()234void PanelMenuView::SetupUBusManagerInterests()
@@ -300,7 +294,7 @@
300void PanelMenuView::OnLIMChanged(bool lim)294void PanelMenuView::OnLIMChanged(bool lim)
301{295{
302 integrated_menus_ = lim;296 integrated_menus_ = lim;
303 new_application_ = nullptr;297 new_application_.reset();
304298
305 if (!integrated_menus_)299 if (!integrated_menus_)
306 {300 {
@@ -321,7 +315,7 @@
321 if (!always_show_menus_)315 if (!always_show_menus_)
322 CheckMouseInside();316 CheckMouseInside();
323317
324 FullRedraw();318 QueueDraw();
325}319}
326320
327nux::Area* PanelMenuView::FindAreaUnderMouse(const nux::Point& mouse_position, nux::NuxEventType event_type)321nux::Area* PanelMenuView::FindAreaUnderMouse(const nux::Point& mouse_position, nux::NuxEventType event_type)
@@ -762,41 +756,13 @@
762std::string PanelMenuView::GetActiveViewName(bool use_appname) const756std::string PanelMenuView::GetActiveViewName(bool use_appname) const
763{757{
764 std::string label;758 std::string label;
765 BamfWindow* window;759 auto& am = ApplicationManager::Default();
766760
767 window = bamf_matcher_get_active_window(matcher_);761 if (ApplicationWindowPtr const& window = am.GetActiveWindow())
768
769 if (BAMF_IS_WINDOW(window))
770 {762 {
771 BamfView *view = reinterpret_cast<BamfView*>(window);763 Window window_xid = window->window_id();
772 Window window_xid = bamf_window_get_xid(window);764
773765 if (window->type() == WindowType::DESKTOP)
774 if (bamf_window_get_window_type(window) == BAMF_WINDOW_DOCK)
775 {
776 auto panel = const_cast<PanelMenuView*>(this)->GetTopLevelViewWindow();
777 if (static_cast<nux::BaseWindow*>(panel)->GetInputWindowId() == window_xid)
778 return desktop_name_;
779
780 std::vector<Window> const& our_xids = nux::XInputWindow::NativeHandleList();
781
782 if (std::find(our_xids.begin(), our_xids.end(), window_xid) != our_xids.end())
783 {
784 /* If the active window is an unity window, we need to fallback to the
785 * top one, anyway we should always avoid to focus unity internal windows */
786 BamfWindow* top_win = GetBamfWindowForXid(GetTopWindow());
787
788 if (top_win && top_win != window)
789 {
790 window = top_win;
791 }
792 else
793 {
794 return "";
795 }
796 }
797 }
798
799 if (bamf_window_get_window_type(window) == BAMF_WINDOW_DESKTOP)
800 {766 {
801 label = desktop_name_;767 label = desktop_name_;
802 }768 }
@@ -806,27 +772,16 @@
806 }772 }
807773
808 if (WindowManager::Default().IsWindowMaximized(window_xid) && !use_appname)774 if (WindowManager::Default().IsWindowMaximized(window_xid) && !use_appname)
809 {775 label = window->title();
810 label = glib::String(bamf_view_get_name(view)).Str();776
811 }777 if (label.empty())
812778 {
813 if (label.empty())779 if (ApplicationPtr const& app = am.GetActiveApplication())
814 {780 label = app->title();
815 BamfApplication* app;781 }
816 app = bamf_matcher_get_application_for_window(matcher_, window);782
817783 if (label.empty())
818 if (BAMF_IS_APPLICATION(app))784 label = window->title();
819 {
820 view = reinterpret_cast<BamfView*>(app);
821 label = glib::String(bamf_view_get_name(view)).Str();
822 }
823 }
824
825 if (label.empty())
826 {
827 view = reinterpret_cast<BamfView*>(window);
828 label = glib::String(bamf_view_get_name(view)).Str();
829 }
830 }785 }
831786
832 return label;787 return label;
@@ -835,24 +790,16 @@
835std::string PanelMenuView::GetMaximizedViewName(bool use_appname) const790std::string PanelMenuView::GetMaximizedViewName(bool use_appname) const
836{791{
837 Window maximized = maximized_window();792 Window maximized = maximized_window();
838 BamfWindow* window = nullptr;
839 std::string label;793 std::string label;
840794
841 window = GetBamfWindowForXid(maximized);795 if (ApplicationWindowPtr const& window = ApplicationManager::Default().GetWindowForId(maximized))
842
843 if (BAMF_IS_WINDOW(window))
844 {796 {
845 BamfView* view = reinterpret_cast<BamfView*>(window);797 label = window->title();
846 label = glib::String(bamf_view_get_name(view)).Str();
847798
848 if (use_appname || label.empty())799 if (use_appname || label.empty())
849 {800 {
850 BamfApplication* app = bamf_matcher_get_application_for_window(matcher_, window);801 if (ApplicationPtr const& app = window->application())
851802 label = app->title();
852 if (BAMF_IS_APPLICATION(app))
853 view = reinterpret_cast<BamfView*>(app);
854
855 label = glib::String(bamf_view_get_name(view)).Str();
856 }803 }
857 }804 }
858805
@@ -963,6 +910,12 @@
963 return true;910 return true;
964}911}
965912
913void PanelMenuView::RefreshAndRedraw()
914{
915 if (Refresh())
916 QueueDraw();
917}
918
966void PanelMenuView::OnActiveChanged(PanelIndicatorEntryView* view, bool is_active)919void PanelMenuView::OnActiveChanged(PanelIndicatorEntryView* view, bool is_active)
967{920{
968 if (is_active)921 if (is_active)
@@ -977,8 +930,7 @@
977 }930 }
978 }931 }
979932
980 if (Refresh())933 RefreshAndRedraw();
981 FullRedraw();
982}934}
983935
984void PanelMenuView::OnEntryAdded(indicator::Entry::Ptr const& entry)936void PanelMenuView::OnEntryAdded(indicator::Entry::Ptr const& entry)
@@ -1012,22 +964,13 @@
1012 }964 }
1013}965}
1014966
1015void PanelMenuView::OnNameChanged(BamfView* bamf_view, gchar* new_name, gchar* old_name)
1016{
1017 if (Refresh())
1018 FullRedraw();
1019}
1020
1021bool PanelMenuView::OnNewAppShow()967bool PanelMenuView::OnNewAppShow()
1022{968{
1023 BamfApplication* active_app = bamf_matcher_get_active_application(matcher_);969 new_application_ = ApplicationManager::Default().GetActiveApplication();
1024 new_application_ = glib::Object<BamfApplication>(active_app, glib::AddRef());
1025 QueueDraw();970 QueueDraw();
1026971
1027 if (sources_.GetSource(NEW_APP_HIDE_TIMEOUT))972 if (sources_.GetSource(NEW_APP_HIDE_TIMEOUT))
1028 {
1029 new_app_menu_shown_ = false;973 new_app_menu_shown_ = false;
1030 }
1031974
1032 auto cb_func = sigc::mem_fun(this, &PanelMenuView::OnNewAppHide);975 auto cb_func = sigc::mem_fun(this, &PanelMenuView::OnNewAppHide);
1033 sources_.AddTimeoutSeconds(menu_manager_->discovery(), cb_func, NEW_APP_HIDE_TIMEOUT);976 sources_.AddTimeoutSeconds(menu_manager_->discovery(), cb_func, NEW_APP_HIDE_TIMEOUT);
@@ -1044,69 +987,51 @@
1044 return false;987 return false;
1045}988}
1046989
1047void PanelMenuView::OnViewOpened(BamfMatcher *matcher, BamfView *view)990void PanelMenuView::OnApplicationStarted(ApplicationPtr const& app)
1048{991{
1049 /* FIXME: here we should also check for if the view is also user_visible992 /* FIXME: here we should also check for if the view is also user_visible
1050 * but it seems that BAMF doesn't handle this correctly after some993 * but it seems that BAMF doesn't handle this correctly after some
1051 * stress tests (repeated launches). */994 * stress tests (repeated launches). */
1052 if (!BAMF_IS_APPLICATION(view) || integrated_menus_)995 if (integrated_menus_)
1053 return;996 return;
1054997
1055 new_apps_.push_front(glib::Object<BamfApplication>(BAMF_APPLICATION(view), glib::AddRef()));998 new_apps_.push_front(app);
1056}999}
10571000
1058void PanelMenuView::OnApplicationClosed(BamfApplication* app)1001void PanelMenuView::OnApplicationClosed(ApplicationPtr const& app)
1059{1002{
1060 if (BAMF_IS_APPLICATION(app) && !integrated_menus_)1003 if (app && !integrated_menus_)
1061 {1004 {
1062 if (std::find(new_apps_.begin(), new_apps_.end(), app) != new_apps_.end())1005 if (std::find(new_apps_.begin(), new_apps_.end(), app) != new_apps_.end())
1063 {1006 {
1064 new_apps_.remove(glib::Object<BamfApplication>(app, glib::AddRef()));1007 new_apps_.remove(app);
1065 }1008 }
1066 else if (new_apps_.empty())1009 else if (new_apps_.empty())
1067 {1010 {
1068 new_application_ = nullptr;1011 new_application_.reset();
1069 }1012 }
1070 }1013 }
10711014
1072 if (app == new_application_)1015 if (app == new_application_)
1073 {1016 {
1074 new_application_ = nullptr;1017 new_application_.reset();
1075 }1018 }
1076}1019}
10771020
1078void PanelMenuView::OnViewClosed(BamfMatcher *matcher, BamfView *view)1021void PanelMenuView::OnWindowClosed(ApplicationWindowPtr const& win)
1079{1022{
1080 if (reinterpret_cast<BamfView*>(view_name_changed_signal_.object()) == view)1023 /* FIXME, this can be removed when window_unmapped WindowManager signal
1081 {1024 * will emit the proper xid */
1082 view_name_changed_signal_.Disconnect();1025 OnWindowUnmapped(win->window_id());
1083 }1026}
10841027
1085 if (BAMF_IS_APPLICATION(view))1028void PanelMenuView::OnActiveAppChanged(ApplicationPtr const& new_app)
1086 {1029{
1087 OnApplicationClosed(reinterpret_cast<BamfApplication*>(view));1030 if (new_app)
1088 }1031 {
1089 else if (reinterpret_cast<BamfApplication*>(view) == new_application_)1032 app_name_changed_conn_ = new_app->title.changed.connect([this] (std::string const&t) {
1090 {1033 RefreshAndRedraw();
1091 new_application_ = nullptr;1034 });
1092 }
1093 else if (BAMF_IS_WINDOW(view))
1094 {
1095 /* FIXME, this can be removed when window_unmapped WindowManager signal
1096 * will emit the proper xid */
1097 Window xid = bamf_window_get_xid(reinterpret_cast<BamfWindow*>(view));
1098 OnWindowUnmapped(xid);
1099 }
1100}
1101
1102void PanelMenuView::OnActiveAppChanged(BamfMatcher *matcher,
1103 BamfApplication* old_app,
1104 BamfApplication* new_app)
1105{
1106 if (BAMF_IS_APPLICATION(new_app))
1107 {
1108 app_name_changed_signal_.Connect(BAMF_VIEW(new_app), "name-changed",
1109 sigc::mem_fun(this, &PanelMenuView::OnNameChanged));
11101035
1111 if (integrated_menus_ || always_show_menus_)1036 if (integrated_menus_ || always_show_menus_)
1112 return;1037 return;
@@ -1140,7 +1065,7 @@
1140 }1065 }
1141}1066}
11421067
1143void PanelMenuView::OnActiveWindowChanged(BamfMatcher *matcher, BamfView* old_view, BamfView* new_view)1068void PanelMenuView::OnActiveWindowChanged(ApplicationWindowPtr const& new_win)
1144{1069{
1145 show_now_activated_ = false;1070 show_now_activated_ = false;
1146 is_maximized_ = false;1071 is_maximized_ = false;
@@ -1149,13 +1074,12 @@
11491074
1150 sources_.Remove(WINDOW_MOVED_TIMEOUT);1075 sources_.Remove(WINDOW_MOVED_TIMEOUT);
11511076
1152 if (BAMF_IS_WINDOW(new_view))1077 if (new_win)
1153 {1078 {
1154 BamfWindow* window = reinterpret_cast<BamfWindow*>(new_view);1079 active_xid = new_win->window_id();
1155 active_xid = bamf_window_get_xid(window);1080 is_maximized_ = new_win->maximized();
1156 is_maximized_ = (bamf_window_maximized(window) == BAMF_WINDOW_MAXIMIZED);
11571081
1158 if (bamf_window_get_window_type(window) == BAMF_WINDOW_DESKTOP)1082 if (new_win->type() == WindowType::DESKTOP)
1159 {1083 {
1160 is_desktop_focused_ = !maximized_window();1084 is_desktop_focused_ = !maximized_window();
1161 we_control_active_ = true;1085 we_control_active_ = true;
@@ -1173,14 +1097,13 @@
1173 }1097 }
11741098
1175 // register callback for new view1099 // register callback for new view
1176 view_name_changed_signal_.Connect(new_view, "name-changed",1100 win_name_changed_conn_ = new_win->title.changed.connect([this] (std::string const& t) {
1177 sigc::mem_fun(this, &PanelMenuView::OnNameChanged));1101 RefreshAndRedraw();
1102 });
1178 }1103 }
11791104
1180 active_window = active_xid;1105 active_window = active_xid;
11811106 RefreshAndRedraw();
1182 if (Refresh())
1183 FullRedraw();
1184}1107}
11851108
1186void PanelMenuView::OnSpreadInitiate()1109void PanelMenuView::OnSpreadInitiate()
@@ -1195,18 +1118,6 @@
1195 QueueDraw();1118 QueueDraw();
1196}1119}
11971120
1198void PanelMenuView::OnExpoInitiate()
1199{
1200 if (Refresh())
1201 QueueDraw();
1202}
1203
1204void PanelMenuView::OnExpoTerminate()
1205{
1206 if (Refresh())
1207 QueueDraw();
1208}
1209
1210void PanelMenuView::OnWindowMinimized(Window xid)1121void PanelMenuView::OnWindowMinimized(Window xid)
1211{1122{
1212 maximized_wins_.erase(std::remove(maximized_wins_.begin(), maximized_wins_.end(), xid), maximized_wins_.end());1123 maximized_wins_.erase(std::remove(maximized_wins_.begin(), maximized_wins_.end(), xid), maximized_wins_.end());
@@ -1214,13 +1125,11 @@
12141125
1215 if (xid == active_window())1126 if (xid == active_window())
1216 {1127 {
1217 if (Refresh())1128 RefreshAndRedraw();
1218 QueueDraw();
1219 }1129 }
1220 else if (integrated_menus_ && window_buttons_->controlled_window == xid)1130 else if (integrated_menus_ && window_buttons_->controlled_window == xid)
1221 {1131 {
1222 if (Refresh())1132 RefreshAndRedraw();
1223 QueueDraw();
1224 }1133 }
1225}1134}
12261135
@@ -1234,8 +1143,7 @@
1234 UpdateMaximizedWindow();1143 UpdateMaximizedWindow();
1235 }1144 }
12361145
1237 if (Refresh())1146 RefreshAndRedraw();
1238 QueueDraw();
1239 }1147 }
1240 else1148 else
1241 {1149 {
@@ -1247,8 +1155,7 @@
12471155
1248 if (integrated_menus_ && IsWindowUnderOurControl(xid))1156 if (integrated_menus_ && IsWindowUnderOurControl(xid))
1249 {1157 {
1250 if (Refresh())1158 RefreshAndRedraw();
1251 QueueDraw();
1252 }1159 }
1253 }1160 }
1254}1161}
@@ -1262,13 +1169,11 @@
12621169
1263 if (xid == active_window())1170 if (xid == active_window())
1264 {1171 {
1265 if (Refresh())1172 RefreshAndRedraw();
1266 QueueDraw();
1267 }1173 }
1268 else if (integrated_menus_ && window_buttons_->controlled_window == xid)1174 else if (integrated_menus_ && window_buttons_->controlled_window == xid)
1269 {1175 {
1270 if (Refresh())1176 RefreshAndRedraw();
1271 QueueDraw();
1272 }1177 }
1273}1178}
12741179
@@ -1281,8 +1186,7 @@
1281 maximized_wins_.push_front(xid);1186 maximized_wins_.push_front(xid);
1282 UpdateMaximizedWindow();1187 UpdateMaximizedWindow();
12831188
1284 if (Refresh())1189 RefreshAndRedraw();
1285 QueueDraw();
1286 }1190 }
1287 else1191 else
1288 {1192 {
@@ -1303,8 +1207,7 @@
1303 CheckMouseInside();1207 CheckMouseInside();
1304 is_maximized_ = true;1208 is_maximized_ = true;
13051209
1306 if (Refresh())1210 RefreshAndRedraw();
1307 FullRedraw();
1308 }1211 }
1309 else1212 else
1310 {1213 {
@@ -1313,8 +1216,7 @@
13131216
1314 if (integrated_menus_ && IsWindowUnderOurControl(xid))1217 if (integrated_menus_ && IsWindowUnderOurControl(xid))
1315 {1218 {
1316 if (Refresh())1219 RefreshAndRedraw();
1317 QueueDraw();
1318 }1220 }
1319 }1221 }
1320}1222}
@@ -1328,14 +1230,11 @@
1328 {1230 {
1329 is_maximized_ = false;1231 is_maximized_ = false;
1330 is_grabbed_ = false;1232 is_grabbed_ = false;
13311233 RefreshAndRedraw();
1332 if (Refresh())
1333 FullRedraw();
1334 }1234 }
1335 else if (integrated_menus_ && window_buttons_->controlled_window == xid)1235 else if (integrated_menus_ && window_buttons_->controlled_window == xid)
1336 {1236 {
1337 if (Refresh())1237 RefreshAndRedraw();
1338 QueueDraw();
1339 }1238 }
1340}1239}
13411240
@@ -1350,8 +1249,7 @@
1350 if (HasVisibleMenus())1249 if (HasVisibleMenus())
1351 on_indicator_updated.emit();1250 on_indicator_updated.emit();
13521251
1353 if (Refresh())1252 RefreshAndRedraw();
1354 QueueDraw();
1355 }1253 }
13561254
1357 return false;1255 return false;
@@ -1436,55 +1334,20 @@
1436Window PanelMenuView::GetTopWindow() const1334Window PanelMenuView::GetTopWindow() const
1437{1335{
1438 Window window_xid = 0;1336 Window window_xid = 0;
1439 GList* windows = bamf_matcher_get_window_stack_for_monitor(matcher_, monitor_);
14401337
1441 for (GList* l = windows; l; l = l->next)1338 for (auto const& win : ApplicationManager::Default().GetWindowsForMonitor(monitor_))
1442 {1339 {
1443 if (!BAMF_IS_WINDOW(l->data))1340 Window xid = win->window_id();
1444 continue;1341
14451342 if (win->visible() && IsValidWindow(xid))
1446 Window xid = bamf_window_get_xid(static_cast<BamfWindow*>(l->data));
1447 bool visible = bamf_view_is_user_visible(static_cast<BamfView*>(l->data));
1448
1449 if (visible && IsValidWindow(xid))
1450 {1343 {
1451 window_xid = xid;1344 window_xid = xid;
1452 }1345 }
1453 }1346 }
14541347
1455 g_list_free(windows);
1456
1457 return window_xid;1348 return window_xid;
1458}1349}
14591350
1460BamfWindow* PanelMenuView::GetBamfWindowForXid(Window xid) const
1461{
1462 BamfWindow* window = nullptr;
1463
1464 if (xid != 0)
1465 {
1466 GList* windows = bamf_matcher_get_windows(matcher_);
1467
1468 for (GList* l = windows; l; l = l->next)
1469 {
1470 if (!BAMF_IS_WINDOW(l->data))
1471 continue;
1472
1473 auto win = static_cast<BamfWindow*>(l->data);
1474
1475 if (bamf_window_get_xid(win) == xid)
1476 {
1477 window = win;
1478 break;
1479 }
1480 }
1481
1482 g_list_free(windows);
1483 }
1484
1485 return window;
1486}
1487
1488void PanelMenuView::ActivateIntegratedMenus(nux::Point const& click)1351void PanelMenuView::ActivateIntegratedMenus(nux::Point const& click)
1489{1352{
1490 if (!layout_->GetAbsoluteGeometry().IsInside(click))1353 if (!layout_->GetAbsoluteGeometry().IsInside(click))
@@ -1679,8 +1542,7 @@
16791542
1680 is_inside_ = true;1543 is_inside_ = true;
1681 is_grabbed_ = true;1544 is_grabbed_ = true;
1682 if (Refresh())1545 RefreshAndRedraw();
1683 FullRedraw();
16841546
1685 /* Ungrab the pointer and start the X move, to make the decorator handle it */1547 /* Ungrab the pointer and start the X move, to make the decorator handle it */
1686 titlebar_grab_area_->SetGrabbed(false);1548 titlebar_grab_area_->SetGrabbed(false);
@@ -1700,8 +1562,7 @@
1700 if (!is_inside_)1562 if (!is_inside_)
1701 is_grabbed_ = false;1563 is_grabbed_ = false;
17021564
1703 if (Refresh())1565 RefreshAndRedraw();
1704 FullRedraw();
1705}1566}
17061567
1707// Introspectable1568// Introspectable
@@ -1763,8 +1624,7 @@
1763 show_now_activated_ = false;1624 show_now_activated_ = false;
1764 }1625 }
17651626
1766 if (Refresh())1627 RefreshAndRedraw();
1767 QueueDraw();
1768}1628}
17691629
1770void PanelMenuView::OnLauncherKeyNavStarted(GVariant* data)1630void PanelMenuView::OnLauncherKeyNavStarted(GVariant* data)
@@ -1785,9 +1645,7 @@
17851645
1786 launcher_keynav_ = false;1646 launcher_keynav_ = false;
1787 CheckMouseInside();1647 CheckMouseInside();
17881648 RefreshAndRedraw();
1789 if (Refresh())
1790 QueueDraw();
1791}1649}
17921650
1793void PanelMenuView::OnLauncherSelectionChanged(GVariant* data)1651void PanelMenuView::OnLauncherSelectionChanged(GVariant* data)
@@ -1854,23 +1712,17 @@
18541712
1855 maximized_wins_.clear();1713 maximized_wins_.clear();
1856 monitor_geo_ = UScreen::GetDefault()->GetMonitorGeometry(monitor_);1714 monitor_geo_ = UScreen::GetDefault()->GetMonitorGeometry(monitor_);
1857 GList* windows = bamf_matcher_get_window_stack_for_monitor(matcher_, monitor_);
18581715
1859 for (GList* l = windows; l; l = l->next)1716 for (auto const& win : ApplicationManager::Default().GetWindowsForMonitor(monitor_))
1860 {1717 {
1861 if (!BAMF_IS_WINDOW(l->data))1718 auto xid = win->window_id();
1862 continue;1719
18631720 if (win->active())
1864 auto window = static_cast<BamfWindow*>(l->data);
1865 auto view = static_cast<BamfView*>(l->data);
1866 auto xid = bamf_window_get_xid(window);
1867
1868 if (bamf_view_is_active(view))
1869 active_window = xid;1721 active_window = xid;
18701722
1871 if (bamf_window_maximized(window) == BAMF_WINDOW_MAXIMIZED)1723 if (win->maximized())
1872 {1724 {
1873 if (xid == active_window())1725 if (win->active())
1874 maximized_wins_.push_front(xid);1726 maximized_wins_.push_front(xid);
1875 else1727 else
1876 maximized_wins_.push_back(xid);1728 maximized_wins_.push_back(xid);
@@ -1881,7 +1733,6 @@
1881 UpdateMaximizedWindow();1733 UpdateMaximizedWindow();
18821734
1883 OnStyleChanged();1735 OnStyleChanged();
1884 g_list_free(windows);
1885}1736}
18861737
1887bool PanelMenuView::HasMenus() const1738bool PanelMenuView::HasMenus() const
18881739
=== modified file 'panel/PanelMenuView.h'
--- panel/PanelMenuView.h 2015-02-04 09:54:49 +0000
+++ panel/PanelMenuView.h 2015-05-22 16:04:25 +0000
@@ -22,12 +22,11 @@
22#define PANEL_MENU_VIEW_H22#define PANEL_MENU_VIEW_H
2323
24#include <NuxCore/Animation.h>24#include <NuxCore/Animation.h>
25#include <UnityCore/GLibWrapper.h>
26#include <UnityCore/GLibSignal.h>25#include <UnityCore/GLibSignal.h>
27#include <libbamf/libbamf.h>
2826
29#include "PanelIndicatorsView.h"27#include "PanelIndicatorsView.h"
30#include "PanelTitlebarGrabAreaView.h"28#include "PanelTitlebarGrabAreaView.h"
29#include "unity-shared/ApplicationManager.h"
31#include "unity-shared/MenuManager.h"30#include "unity-shared/MenuManager.h"
32#include "unity-shared/StaticCairoText.h"31#include "unity-shared/StaticCairoText.h"
33#include "unity-shared/WindowButtons.h"32#include "unity-shared/WindowButtons.h"
@@ -88,20 +87,17 @@
8887
89 void OnActiveChanged(PanelIndicatorEntryView* view, bool is_active);88 void OnActiveChanged(PanelIndicatorEntryView* view, bool is_active);
90 void OnEntryViewAdded(PanelIndicatorEntryView* view);89 void OnEntryViewAdded(PanelIndicatorEntryView* view);
91 void OnViewOpened(BamfMatcher* matcher, BamfView* view);90 void OnApplicationStarted(ApplicationPtr const&);
92 void OnViewClosed(BamfMatcher* matcher, BamfView* view);91 void OnApplicationClosed(ApplicationPtr const&);
93 void OnApplicationClosed(BamfApplication* app);92 void OnWindowClosed(ApplicationWindowPtr const&);
94 void OnActiveWindowChanged(BamfMatcher* matcher, BamfView* old_view, BamfView* new_view);93 void OnActiveWindowChanged(ApplicationWindowPtr const&);
95 void OnActiveAppChanged(BamfMatcher* matcher, BamfApplication* old_app, BamfApplication* new_app);94 void OnActiveAppChanged(ApplicationPtr const&);
96 void OnNameChanged(BamfView* bamf_view, gchar* new_name, gchar* old_name);
97 void OnStyleChanged();95 void OnStyleChanged();
98 void OnLIMChanged(bool);96 void OnLIMChanged(bool);
99 void OnAlwaysShowMenusChanged(bool);97 void OnAlwaysShowMenusChanged(bool);
10098
101 void OnSpreadInitiate();99 void OnSpreadInitiate();
102 void OnSpreadTerminate();100 void OnSpreadTerminate();
103 void OnExpoInitiate();
104 void OnExpoTerminate();
105 void OnWindowMinimized(Window xid);101 void OnWindowMinimized(Window xid);
106 void OnWindowUnminimized(Window xid);102 void OnWindowUnminimized(Window xid);
107 void OnWindowUnmapped(Window xid);103 void OnWindowUnmapped(Window xid);
@@ -122,6 +118,7 @@
122 void FullRedraw();118 void FullRedraw();
123 std::string GetCurrentTitle() const;119 std::string GetCurrentTitle() const;
124 bool Refresh(bool force = false);120 bool Refresh(bool force = false);
121 void RefreshAndRedraw();
125122
126 void UpdateTitleTexture(nux::Geometry const&, std::string const& label);123 void UpdateTitleTexture(nux::Geometry const&, std::string const& label);
127 void UpdateLastGeometry(nux::Geometry const& geo);124 void UpdateLastGeometry(nux::Geometry const& geo);
@@ -131,8 +128,6 @@
131 void OnPanelViewMouseEnter(int x, int y, unsigned long mouse_button_state, unsigned long special_keys_state);128 void OnPanelViewMouseEnter(int x, int y, unsigned long mouse_button_state, unsigned long special_keys_state);
132 void OnPanelViewMouseLeave(int x, int y, unsigned long mouse_button_state, unsigned long special_keys_state);129 void OnPanelViewMouseLeave(int x, int y, unsigned long mouse_button_state, unsigned long special_keys_state);
133130
134 BamfWindow* GetBamfWindowForXid(Window xid) const;
135
136 void OnSwitcherShown(GVariant* data);131 void OnSwitcherShown(GVariant* data);
137 void OnLauncherKeyNavStarted(GVariant* data);132 void OnLauncherKeyNavStarted(GVariant* data);
138 void OnLauncherKeyNavEnded(GVariant* data);133 void OnLauncherKeyNavEnded(GVariant* data);
@@ -164,7 +159,6 @@
164 void ActivateIntegratedMenus(nux::Point const&);159 void ActivateIntegratedMenus(nux::Point const&);
165160
166 menu::Manager::Ptr menu_manager_;161 menu::Manager::Ptr menu_manager_;
167 glib::Object<BamfMatcher> matcher_;
168162
169 nux::TextureLayer* title_layer_;163 nux::TextureLayer* title_layer_;
170 nux::ObjectPtr<WindowButtons> window_buttons_;164 nux::ObjectPtr<WindowButtons> window_buttons_;
@@ -179,8 +173,8 @@
179173
180 PanelIndicatorEntryView* last_active_view_;174 PanelIndicatorEntryView* last_active_view_;
181 std::deque<Window> maximized_wins_;175 std::deque<Window> maximized_wins_;
182 glib::Object<BamfApplication> new_application_;176 ApplicationPtr new_application_;
183 std::list<glib::Object<BamfApplication>> new_apps_;177 std::list<ApplicationPtr> new_apps_;
184 std::string panel_title_;178 std::string panel_title_;
185 nux::Geometry last_geo_;179 nux::Geometry last_geo_;
186 nux::Geometry title_geo_;180 nux::Geometry title_geo_;
@@ -198,12 +192,8 @@
198 nux::Geometry monitor_geo_;192 nux::Geometry monitor_geo_;
199 const std::string desktop_name_;193 const std::string desktop_name_;
200194
201 glib::Signal<void, BamfMatcher*, BamfView*> view_opened_signal_;195 connection::Wrapper app_name_changed_conn_;
202 glib::Signal<void, BamfMatcher*, BamfView*> view_closed_signal_;196 connection::Wrapper win_name_changed_conn_;
203 glib::Signal<void, BamfMatcher*, BamfView*, BamfView*> active_win_changed_signal_;
204 glib::Signal<void, BamfMatcher*, BamfApplication*, BamfApplication*> active_app_changed_signal_;
205 glib::Signal<void, BamfView*, gchar*, gchar*> view_name_changed_signal_;
206 glib::Signal<void, BamfView*, gchar*, gchar*> app_name_changed_signal_;
207197
208 UBusManager ubus_manager_;198 UBusManager ubus_manager_;
209 glib::SourceManager sources_;199 glib::SourceManager sources_;
210200
=== modified file 'tests/mock-application.h'
--- tests/mock-application.h 2015-02-03 09:46:48 +0000
+++ tests/mock-application.h 2015-05-22 16:04:25 +0000
@@ -40,8 +40,8 @@
40 MockApplicationWindow(Window xid)40 MockApplicationWindow(Window xid)
41 : xid_(xid)41 : xid_(xid)
42 , monitor_(0)42 , monitor_(0)
43 , type_(unity::WindowType::MOCK)
43 , title_("MockApplicationWindow "+std::to_string(xid_))44 , title_("MockApplicationWindow "+std::to_string(xid_))
44 , type_("window")
45 , visible_(true)45 , visible_(true)
46 , active_(false)46 , active_(false)
47 , urgent_(false)47 , urgent_(false)
@@ -61,26 +61,28 @@
6161
62 Window xid_;62 Window xid_;
63 int monitor_;63 int monitor_;
64 unity::WindowType type_;
64 std::string title_;65 std::string title_;
65 std::string icon_;66 std::string icon_;
66 std::string type_;
6767
68 bool visible_;68 bool visible_;
69 bool active_;69 bool active_;
70 bool urgent_;70 bool urgent_;
7171
72 MOCK_CONST_METHOD0(type, std::string());72 MOCK_CONST_METHOD0(type, unity::WindowType());
73 MOCK_CONST_METHOD0(window_id, Window());73 MOCK_CONST_METHOD0(window_id, Window());
74 MOCK_CONST_METHOD0(monitor, int());74 MOCK_CONST_METHOD0(monitor, int());
75 MOCK_CONST_METHOD0(application, unity::ApplicationPtr());75 MOCK_CONST_METHOD0(application, unity::ApplicationPtr());
76 MOCK_CONST_METHOD0(Focus, bool());76 MOCK_CONST_METHOD0(Focus, bool());
77 MOCK_CONST_METHOD0(Quit, void());77 MOCK_CONST_METHOD0(Quit, void());
7878
79 virtual bool LocalFocus() const79 bool LocalFocus()
80 {80 {
81 auto& wm = unity::WindowManager::Default();81 auto& wm = unity::WindowManager::Default();
82 wm.Raise(xid_);82 wm.Raise(xid_);
83 wm.Activate(xid_);83 wm.Activate(xid_);
84 active_ = true;
85 active.changed.emit(active_);
84 return true;86 return true;
85 }87 }
8688
@@ -124,7 +126,7 @@
124 , active_(false)126 , active_(false)
125 , running_(false)127 , running_(false)
126 , urgent_(false)128 , urgent_(false)
127 , type_("mock")129 , type_(unity::AppType::MOCK)
128 {130 {
129 seen.SetSetterFunction(sigc::mem_fun(this, &MockApplication::SetSeen));131 seen.SetSetterFunction(sigc::mem_fun(this, &MockApplication::SetSeen));
130 sticky.SetSetterFunction(sigc::mem_fun(this, &MockApplication::SetSticky));132 sticky.SetSetterFunction(sigc::mem_fun(this, &MockApplication::SetSticky));
@@ -159,10 +161,10 @@
159 bool running_;161 bool running_;
160 bool urgent_;162 bool urgent_;
161 unity::WindowList windows_;163 unity::WindowList windows_;
162 std::string type_;164 unity::AppType type_;
163 std::vector<std::pair<unity::ApplicationEventType, unity::ApplicationSubjectPtr>> actions_log_;165 std::vector<std::pair<unity::ApplicationEventType, unity::ApplicationSubjectPtr>> actions_log_;
164166
165 MOCK_CONST_METHOD0(type, std::string());167 MOCK_CONST_METHOD0(type, unity::AppType());
166 MOCK_CONST_METHOD0(repr, std::string());168 MOCK_CONST_METHOD0(repr, std::string());
167 MOCK_CONST_METHOD0(desktop_id, std::string());169 MOCK_CONST_METHOD0(desktop_id, std::string());
168 MOCK_CONST_METHOD0(GetWindows, unity::WindowList());170 MOCK_CONST_METHOD0(GetWindows, unity::WindowList());
@@ -306,6 +308,9 @@
306 ON_CALL(*this, GetActiveWindow()).WillByDefault(Invoke([this] { return unity::ApplicationWindowPtr(); } ));308 ON_CALL(*this, GetActiveWindow()).WillByDefault(Invoke([this] { return unity::ApplicationWindowPtr(); } ));
307 ON_CALL(*this, GetRunningApplications()).WillByDefault(Invoke([this] { return unity::ApplicationList(); } ));309 ON_CALL(*this, GetRunningApplications()).WillByDefault(Invoke([this] { return unity::ApplicationList(); } ));
308 ON_CALL(*this, GetApplicationForWindow(_)).WillByDefault(Invoke([this] (Window) { return unity::ApplicationPtr(); } ));310 ON_CALL(*this, GetApplicationForWindow(_)).WillByDefault(Invoke([this] (Window) { return unity::ApplicationPtr(); } ));
311 ON_CALL(*this, GetActiveApplication()).WillByDefault(Invoke([this] { return unity::ApplicationPtr(); } ));
312 ON_CALL(*this, GetWindowsForMonitor(_)).WillByDefault(Invoke([this] (Window) { return unity::WindowList(); } ));
313 ON_CALL(*this, GetWindowForId(_)).WillByDefault(Invoke([this] (int) { return unity::ApplicationWindowPtr(); } ));
309 }314 }
310315
311 static void StartApp(std::string const& desktop_file)316 static void StartApp(std::string const& desktop_file)
@@ -322,6 +327,9 @@
322 MOCK_CONST_METHOD1(GetApplicationForDesktopFile, unity::ApplicationPtr(std::string const&));327 MOCK_CONST_METHOD1(GetApplicationForDesktopFile, unity::ApplicationPtr(std::string const&));
323 MOCK_CONST_METHOD0(GetRunningApplications, unity::ApplicationList());328 MOCK_CONST_METHOD0(GetRunningApplications, unity::ApplicationList());
324 MOCK_CONST_METHOD1(GetApplicationForWindow, unity::ApplicationPtr(Window));329 MOCK_CONST_METHOD1(GetApplicationForWindow, unity::ApplicationPtr(Window));
330 MOCK_CONST_METHOD0(GetActiveApplication, unity::ApplicationPtr());
331 MOCK_CONST_METHOD1(GetWindowsForMonitor, unity::WindowList(int));
332 MOCK_CONST_METHOD1(GetWindowForId, unity::ApplicationWindowPtr(Window));
325333
326 unity::ApplicationPtr LocalGetApplicationForDesktopFile(std::string const& desktop_file)334 unity::ApplicationPtr LocalGetApplicationForDesktopFile(std::string const& desktop_file)
327 {335 {
328336
=== modified file 'tests/test_application_launcher_icon.cpp'
--- tests/test_application_launcher_icon.cpp 2015-03-30 15:48:38 +0000
+++ tests/test_application_launcher_icon.cpp 2015-05-22 16:04:25 +0000
@@ -775,7 +775,10 @@
775 mock_app->windows_ = { win1, win2 };775 mock_app->windows_ = { win1, win2 };
776 WM->AddStandaloneWindow(wm_win1);776 WM->AddStandaloneWindow(wm_win1);
777 WM->AddStandaloneWindow(wm_win2);777 WM->AddStandaloneWindow(wm_win2);
778
779 win2->Focus();
778 ASSERT_TRUE(wm_win2->active());780 ASSERT_TRUE(wm_win2->active());
781 ASSERT_TRUE(win2->active());
779782
780 auto const& menus = mock_icon->Menus();783 auto const& menus = mock_icon->Menus();
781 auto const& menu1 = GetMenuItemWithLabel(menus, win1->title());784 auto const& menu1 = GetMenuItemWithLabel(menus, win1->title());
@@ -1121,10 +1124,10 @@
11211124
1122TEST_F(TestApplicationLauncherIcon, AllowDetailViewInSwitcher)1125TEST_F(TestApplicationLauncherIcon, AllowDetailViewInSwitcher)
1123{1126{
1124 mock_app->type_ = "mock";1127 mock_app->type_ = AppType::NORMAL;
1125 EXPECT_TRUE(mock_icon->AllowDetailViewInSwitcher());1128 EXPECT_TRUE(mock_icon->AllowDetailViewInSwitcher());
11261129
1127 mock_app->type_ = "webapp";1130 mock_app->type_ = AppType::WEBAPP;
1128 EXPECT_FALSE(mock_icon->AllowDetailViewInSwitcher());1131 EXPECT_FALSE(mock_icon->AllowDetailViewInSwitcher());
1129}1132}
11301133
11311134
=== modified file 'tests/test_panel_menu_view.cpp'
--- tests/test_panel_menu_view.cpp 2015-03-13 13:49:16 +0000
+++ tests/test_panel_menu_view.cpp 2015-05-22 16:04:25 +0000
@@ -45,13 +45,7 @@
45 {45 {
46 MockPanelMenuView(menu::Manager::Ptr const& menu_manager)46 MockPanelMenuView(menu::Manager::Ptr const& menu_manager)
47 : PanelMenuView(menu_manager)47 : PanelMenuView(menu_manager)
48 {48 {}
49 view_opened_signal_.Disconnect();
50 active_win_changed_signal_.Disconnect();
51 active_app_changed_signal_.Disconnect();
52 view_closed_signal_.Disconnect();
53 maximized_wins_.clear();
54 }
5549
56 MOCK_METHOD0(QueueDraw, void());50 MOCK_METHOD0(QueueDraw, void());
57 MOCK_CONST_METHOD1(GetActiveViewName, std::string(bool));51 MOCK_CONST_METHOD1(GetActiveViewName, std::string(bool));
@@ -81,7 +75,6 @@
81 panel_win->ComputeContentSize();75 panel_win->ComputeContentSize();
8276
83 menu_view.SetMonitor(monitor);77 menu_view.SetMonitor(monitor);
84 menu_view.maximized_wins_.clear();
8578
86 return panel_win;79 return panel_win;
87 }80 }
8881
=== modified file 'tests/test_switcher_controller.h'
--- tests/test_switcher_controller.h 2014-03-21 04:40:12 +0000
+++ tests/test_switcher_controller.h 2015-05-22 16:04:25 +0000
@@ -54,7 +54,7 @@
54 FakeApplicationWindow(Window xid, uint64_t active_number = 0);54 FakeApplicationWindow(Window xid, uint64_t active_number = 0);
55 ~FakeApplicationWindow();55 ~FakeApplicationWindow();
5656
57 virtual std::string type() const;57 virtual WindowType type() const;
5858
59 virtual Window window_id() const;59 virtual Window window_id() const;
60 virtual int monitor() const;60 virtual int monitor() const;
6161
=== modified file 'tests/test_switcher_controller_class.cpp'
--- tests/test_switcher_controller_class.cpp 2013-10-14 17:36:51 +0000
+++ tests/test_switcher_controller_class.cpp 2015-05-22 16:04:25 +0000
@@ -41,7 +41,7 @@
41 testwrapper::StandaloneWM::Get()->Close(xid_);41 testwrapper::StandaloneWM::Get()->Close(xid_);
42}42}
4343
44std::string FakeApplicationWindow::type() const { return "mock"; }44WindowType FakeApplicationWindow::type() const { return WindowType::MOCK; }
4545
46Window FakeApplicationWindow::window_id() const { return xid_; }46Window FakeApplicationWindow::window_id() const { return xid_; }
47int FakeApplicationWindow::monitor() const { return -1; }47int FakeApplicationWindow::monitor() const { return -1; }
4848
=== modified file 'unity-shared/ApplicationManager.cpp'
--- unity-shared/ApplicationManager.cpp 2012-11-29 09:25:50 +0000
+++ unity-shared/ApplicationManager.cpp 2015-05-22 16:04:25 +0000
@@ -33,6 +33,25 @@
33 return *instance;33 return *instance;
34}34}
3535
36bool operator==(ApplicationPtr const& lhs, ApplicationPtr const& rhs)
37{
38 return (lhs.get() == rhs.get() || (lhs && rhs && *lhs == *rhs));
39}
40
41bool operator!=(ApplicationPtr const& lhs, ApplicationPtr const& rhs)
42{
43 return !(lhs == rhs);
44}
45
46bool operator==(ApplicationWindowPtr const& lhs, ApplicationWindowPtr const& rhs)
47{
48 return (lhs.get() == rhs.get() || (lhs && rhs && *lhs == *rhs));
49}
50
51bool operator!=(ApplicationWindowPtr const& lhs, ApplicationWindowPtr const& rhs)
52{
53 return !(lhs == rhs);
54}
3655
37// This method is needed to create an unresolved external for the56// This method is needed to create an unresolved external for the
38// WindowManager::Default method. This is because it is highly likely that57// WindowManager::Default method. This is because it is highly likely that
3958
=== modified file 'unity-shared/ApplicationManager.h'
--- unity-shared/ApplicationManager.h 2013-09-11 09:11:30 +0000
+++ unity-shared/ApplicationManager.h 2015-05-22 16:04:25 +0000
@@ -50,13 +50,35 @@
50 LEAVE50 LEAVE
51};51};
5252
53enum class AppType
54{
55 NORMAL,
56 WEBAPP,
57 MOCK,
58 UNKNOWN
59};
60
61enum class WindowType
62{
63 NORMAL,
64 DESKTOP,
65 DOCK,
66 DIALOG,
67 TOOLBAR,
68 MENU,
69 UTILITY,
70 SPLASHSCREEN,
71 TAB,
72 MOCK,
73 UNKNOWN
74};
75
53class ApplicationWindow76class ApplicationWindow
54{77{
55public:78public:
56 virtual ~ApplicationWindow() = default;79 virtual ~ApplicationWindow() = default;
5780
58 virtual std::string type() const = 0; // 'window' or 'tab'81 virtual WindowType type() const = 0;
59
60 virtual Window window_id() const = 0;82 virtual Window window_id() const = 0;
61 virtual int monitor() const = 0;83 virtual int monitor() const = 0;
6284
@@ -69,20 +91,32 @@
69 // Closes the window, or the browser tab if a webapp.91 // Closes the window, or the browser tab if a webapp.
70 virtual void Quit() const = 0;92 virtual void Quit() const = 0;
7193
94 virtual bool operator==(ApplicationWindow const& other) const
95 {
96 return (window_id() == other.window_id());
97 }
98
99 virtual bool operator!=(ApplicationWindow const& other) const
100 {
101 return !(operator==(other));
102 }
103
72 nux::ROProperty<std::string> title;104 nux::ROProperty<std::string> title;
73 nux::ROProperty<std::string> icon;105 nux::ROProperty<std::string> icon;
74106
75 nux::ROProperty<bool> visible;107 nux::ROProperty<bool> visible;
76 nux::ROProperty<bool> active;108 nux::ROProperty<bool> active;
77 nux::ROProperty<bool> urgent;109 nux::ROProperty<bool> urgent;
110 nux::ROProperty<bool> maximized;
78};111};
79112
113
80class Application114class Application
81{115{
82public:116public:
83 virtual ~Application() = default;117 virtual ~Application() = default;
84118
85 virtual std::string type() const = 0;119 virtual AppType type() const = 0;
86120
87 // A string representation of the object.121 // A string representation of the object.
88 virtual std::string repr() const = 0;122 virtual std::string repr() const = 0;
@@ -102,6 +136,17 @@
102 virtual void LogEvent(ApplicationEventType, ApplicationSubjectPtr const&) const = 0;136 virtual void LogEvent(ApplicationEventType, ApplicationSubjectPtr const&) const = 0;
103137
104 virtual std::string desktop_id() const = 0;138 virtual std::string desktop_id() const = 0;
139
140 virtual bool operator==(Application const& other) const
141 {
142 return (!desktop_id().empty() && (desktop_id() == other.desktop_id()));
143 }
144
145 virtual bool operator!=(Application const& other) const
146 {
147 return !(operator==(other));
148 }
149
105 nux::ROProperty<std::string> desktop_file;150 nux::ROProperty<std::string> desktop_file;
106 nux::ROProperty<std::string> title;151 nux::ROProperty<std::string> title;
107 nux::ROProperty<std::string> icon;152 nux::ROProperty<std::string> icon;
@@ -117,11 +162,12 @@
117162
118 sigc::signal<void> closed;163 sigc::signal<void> closed;
119164
120 sigc::signal<void, ApplicationWindow const&> window_opened;165 sigc::signal<void, ApplicationWindowPtr const&> window_opened;
121 sigc::signal<void, ApplicationWindow const&> window_moved;166 sigc::signal<void, ApplicationWindowPtr const&> window_moved;
122 sigc::signal<void> window_closed;167 sigc::signal<void, ApplicationWindowPtr const&> window_closed;
123};168};
124169
170
125class ApplicationSubject171class ApplicationSubject
126{172{
127public:173public:
@@ -165,16 +211,28 @@
165 static ApplicationManager& Default();211 static ApplicationManager& Default();
166212
167 virtual ApplicationPtr GetUnityApplication() const = 0;213 virtual ApplicationPtr GetUnityApplication() const = 0;
214 virtual ApplicationPtr GetActiveApplication() const = 0;
168 virtual ApplicationWindowPtr GetActiveWindow() const = 0;215 virtual ApplicationWindowPtr GetActiveWindow() const = 0;
169 virtual ApplicationPtr GetApplicationForDesktopFile(std::string const& desktop_file) const = 0;216 virtual ApplicationPtr GetApplicationForDesktopFile(std::string const& desktop_file) const = 0;
170 virtual ApplicationList GetRunningApplications() const = 0;217 virtual ApplicationList GetRunningApplications() const = 0;
218 virtual WindowList GetWindowsForMonitor(int monitor = -1) const = 0;
171 virtual ApplicationPtr GetApplicationForWindow(Window xid) const = 0;219 virtual ApplicationPtr GetApplicationForWindow(Window xid) const = 0;
220 virtual ApplicationWindowPtr GetWindowForId(Window xid) const = 0;
172221
173 sigc::signal<void, ApplicationPtr const&> application_started;222 sigc::signal<void, ApplicationPtr const&> application_started;
223 sigc::signal<void, ApplicationPtr const&> application_stopped;
174 sigc::signal<void, ApplicationPtr const&> active_application_changed;224 sigc::signal<void, ApplicationPtr const&> active_application_changed;
225 sigc::signal<void, ApplicationWindowPtr const&> window_opened;
226 sigc::signal<void, ApplicationWindowPtr const&> window_closed;
175 sigc::signal<void, ApplicationWindowPtr const&> active_window_changed;227 sigc::signal<void, ApplicationWindowPtr const&> active_window_changed;
176};228};
177229
230
231bool operator==(ApplicationPtr const&, ApplicationPtr const&);
232bool operator!=(ApplicationPtr const&, ApplicationPtr const&);
233bool operator==(ApplicationWindowPtr const&, ApplicationWindowPtr const&);
234bool operator!=(ApplicationWindowPtr const&, ApplicationWindowPtr const&);
235
178}236}
179237
180#endif // UNITYSHARED_APPLICATION_MANAGER_H238#endif // UNITYSHARED_APPLICATION_MANAGER_H
181239
=== modified file 'unity-shared/BamfApplicationManager.cpp'
--- unity-shared/BamfApplicationManager.cpp 2013-10-03 22:39:01 +0000
+++ unity-shared/BamfApplicationManager.cpp 2015-05-22 16:04:25 +0000
@@ -34,7 +34,47 @@
34namespace34namespace
35{35{
36const char* UNSEEN_QUARK = "unity-unseen";36const char* UNSEEN_QUARK = "unity-unseen";
37}37
38namespace pool
39{
40// We keep a cache on views here, it would be nice to clean these on BAMF reload
41std::unordered_map<BamfView*, ApplicationPtr> apps_;
42std::unordered_map<BamfView*, ApplicationWindowPtr> wins_;
43
44ApplicationPtr EnsureApplication(ApplicationManager const& manager, BamfView* view)
45{
46 if (!BAMF_IS_APPLICATION(view))
47 return nullptr;
48
49 auto it = apps_.find(view);
50
51 if (it != apps_.end())
52 return it->second;
53
54 glib::Object<BamfApplication> bamfapp(reinterpret_cast<BamfApplication*>(view), glib::AddRef());
55 auto const& app = std::make_shared<Application>(manager, bamfapp);
56 apps_.insert({view, app});
57 return app;
58}
59
60ApplicationWindowPtr EnsureWindow(ApplicationManager const& manager, BamfView* view)
61{
62 if (!BAMF_IS_WINDOW(view))
63 return nullptr;
64
65 auto it = wins_.find(view);
66
67 if (it != wins_.end())
68 return it->second;
69
70 glib::Object<BamfWindow> bamfwin(reinterpret_cast<BamfWindow*>(view), glib::AddRef());
71 auto const& win = std::make_shared<AppWindow>(manager, bamfwin);
72 wins_.insert({view, win});
73 return win;
74}
75
76} // pool namespace
77} // anonymous namespace
3878
3979
40// Due to the way glib handles object inheritance, we need to cast between pointer types.80// Due to the way glib handles object inheritance, we need to cast between pointer types.
@@ -54,11 +94,6 @@
54 return glib::String(bamf_view_get_icon(bamf_view_)).Str();94 return glib::String(bamf_view_get_icon(bamf_view_)).Str();
55}95}
5696
57std::string View::type() const
58{
59 return glib::gchar_to_string(bamf_view_get_view_type(bamf_view_));
60}
61
62bool View::GetVisible() const97bool View::GetVisible() const
63{98{
64 return bamf_view_is_user_visible(bamf_view_);99 return bamf_view_is_user_visible(bamf_view_);
@@ -80,11 +115,6 @@
80}115}
81116
82117
83std::string WindowBase::type() const
84{
85 return View::type();
86}
87
88WindowBase::WindowBase(ApplicationManager const& manager,118WindowBase::WindowBase(ApplicationManager const& manager,
89 glib::Object<BamfView> const& window)119 glib::Object<BamfView> const& window)
90 : View(manager, window)120 : View(manager, window)
@@ -122,13 +152,10 @@
122 Window xid = window_id();152 Window xid = window_id();
123 if (xid)153 if (xid)
124 {154 {
125 std::vector<Window> windows = { xid };155 auto& wm = WindowManager::Default();
126 // TODO: we should simplify the use case of focusing one window.156 wm.UnMinimize(xid);
127 // Somewhat outside the scope of these changes however.157 wm.Raise(xid);
128 WindowManager::Default().FocusWindowGroup(158 wm.Activate(xid);
129 windows,
130 WindowManager::FocusVisibility::ForceUnminimizeInvisible,
131 monitor(),true);
132 return true;159 return true;
133 }160 }
134 return false;161 return false;
@@ -136,14 +163,25 @@
136163
137164
138AppWindow::AppWindow(ApplicationManager const& manager, glib::Object<BamfWindow> const& window)165AppWindow::AppWindow(ApplicationManager const& manager, glib::Object<BamfWindow> const& window)
139 : WindowBase(manager, glib::object_cast<BamfView>(window))166 : AppWindow(manager, glib::object_cast<BamfView>(window))
140 , bamf_window_(window)
141{}167{}
142168
143AppWindow::AppWindow(ApplicationManager const& manager, glib::Object<BamfView> const& window)169AppWindow::AppWindow(ApplicationManager const& manager, glib::Object<BamfView> const& window)
144 : WindowBase(manager, window)170 : WindowBase(manager, window)
145 , bamf_window_(glib::object_cast<BamfWindow>(window))171 , bamf_window_(glib::object_cast<BamfWindow>(window))
146{}172{
173 maximized.SetGetterFunction(std::bind(&AppWindow::GetMaximized, this));
174 signals_.Add<void, BamfWindow*, gint, gint>(bamf_window_, "maximized-changed",
175 [this] (BamfWindow*, gint old_state, gint state) {
176 if ((old_state == BAMF_WINDOW_MAXIMIZED) != (state == BAMF_WINDOW_MAXIMIZED))
177 this->maximized.changed.emit(state == BAMF_WINDOW_MAXIMIZED);
178 });
179}
180
181bool AppWindow::GetMaximized() const
182{
183 return bamf_window_maximized(bamf_window_) == BAMF_WINDOW_MAXIMIZED;
184}
147185
148Window AppWindow::window_id() const186Window AppWindow::window_id() const
149{187{
@@ -155,6 +193,31 @@
155 return bamf_window_get_monitor(bamf_window_);193 return bamf_window_get_monitor(bamf_window_);
156}194}
157195
196WindowType AppWindow::type() const
197{
198 switch (bamf_window_get_window_type(bamf_window_))
199 {
200 case BAMF_WINDOW_NORMAL:
201 return WindowType::NORMAL;
202 case BAMF_WINDOW_DESKTOP:
203 return WindowType::DESKTOP;
204 case BAMF_WINDOW_DOCK:
205 return WindowType::DOCK;
206 case BAMF_WINDOW_DIALOG:
207 return WindowType::DIALOG;
208 case BAMF_WINDOW_TOOLBAR:
209 return WindowType::TOOLBAR;
210 case BAMF_WINDOW_MENU:
211 return WindowType::MENU;
212 case BAMF_WINDOW_UTILITY:
213 return WindowType::UTILITY;
214 case BAMF_WINDOW_SPLASHSCREEN:
215 return WindowType::SPLASHSCREEN;
216 default:
217 return WindowType::UNKNOWN;
218 }
219}
220
158ApplicationPtr AppWindow::application() const221ApplicationPtr AppWindow::application() const
159{222{
160 // Moderately evil, but better than changing the method to non-const.223 // Moderately evil, but better than changing the method to non-const.
@@ -183,6 +246,11 @@
183 return bamf_tab_get_xid(bamf_tab_);246 return bamf_tab_get_xid(bamf_tab_);
184}247}
185248
249WindowType Tab::type() const
250{
251 return WindowType::TAB;
252}
253
186int Tab::monitor() const254int Tab::monitor() const
187{255{
188 // TODO, we could find the real window for the window_id, and get the monitor for that.256 // TODO, we could find the real window for the window_id, and get the monitor for that.
@@ -208,37 +276,14 @@
208 bamf_tab_close(bamf_tab_);276 bamf_tab_close(bamf_tab_);
209}277}
210278
211// Being brutal with this function.
212ApplicationWindowPtr create_window(ApplicationManager const& manager, glib::Object<BamfView> const& view)
213{
214 if (view.IsType(BAMF_TYPE_WINDOW))
215 {
216 return std::make_shared<AppWindow>(manager, view);
217 }
218 else if (view.IsType(BAMF_TYPE_TAB))
219 {
220 return std::make_shared<Tab>(manager, view);
221 }
222 // We don't handle applications here.
223 return nullptr;
224}
225
226Application::Application(ApplicationManager const& manager, glib::Object<BamfView> const& app)279Application::Application(ApplicationManager const& manager, glib::Object<BamfView> const& app)
227 : View(manager, app)280 : Application(manager, glib::object_cast<BamfApplication>(app))
228 , bamf_app_(glib::object_cast<BamfApplication>(app))281{}
229{
230 HookUpEvents();
231}
232282
233Application::Application(ApplicationManager const& manager, glib::Object<BamfApplication> const& app)283Application::Application(ApplicationManager const& manager, glib::Object<BamfApplication> const& app)
234 : View(manager, glib::object_cast<BamfView>(app))284 : View(manager, glib::object_cast<BamfView>(app))
235 , bamf_app_(app)285 , bamf_app_(app)
236{286{
237 HookUpEvents();
238}
239
240void Application::HookUpEvents()
241{
242 // Hook up the property set/get functions287 // Hook up the property set/get functions
243 using namespace std::placeholders;288 using namespace std::placeholders;
244 desktop_file.SetGetterFunction(std::bind(&Application::GetDesktopFile, this));289 desktop_file.SetGetterFunction(std::bind(&Application::GetDesktopFile, this));
@@ -292,24 +337,21 @@
292 signals_.Add<void, BamfView*, BamfView*>(bamf_view_, "child-added",337 signals_.Add<void, BamfView*, BamfView*>(bamf_view_, "child-added",
293 [this] (BamfView*, BamfView* child) {338 [this] (BamfView*, BamfView* child) {
294 // Ownership is not passed on signals339 // Ownership is not passed on signals
295 glib::Object<BamfView> view(child, glib::AddRef());340 if (ApplicationWindowPtr const& win = pool::EnsureWindow(manager_, child))
296 ApplicationWindowPtr const& win = create_window(this->manager_, view);341 this->window_opened.emit(win);
297 if (win)
298 this->window_opened.emit(*win);
299 });342 });
300343
301 signals_.Add<void, BamfView*, BamfView*>(bamf_view_, "child-removed",344 signals_.Add<void, BamfView*, BamfView*>(bamf_view_, "child-removed",
302 [this] (BamfView*, BamfView* child) {345 [this] (BamfView*, BamfView* child) {
303 this->window_closed.emit();346 if (ApplicationWindowPtr const& win = pool::EnsureWindow(manager_, child))
347 this->window_closed.emit(win);
304 });348 });
305349
306 signals_.Add<void, BamfView*, BamfView*>(bamf_view_, "child-moved",350 signals_.Add<void, BamfView*, BamfView*>(bamf_view_, "child-moved",
307 [this] (BamfView*, BamfView* child) {351 [this] (BamfView*, BamfView* child) {
308 // Ownership is not passed on signals352 // Ownership is not passed on signals
309 glib::Object<BamfView> view(child, glib::AddRef());353 if (ApplicationWindowPtr const& win = pool::EnsureWindow(manager_, child))
310 ApplicationWindowPtr const& win = create_window(this->manager_, view);354 this->window_moved.emit(win);
311 if (win)
312 this->window_moved.emit(*win);
313 });355 });
314}356}
315357
@@ -318,16 +360,21 @@
318 return glib::gchar_to_string(bamf_application_get_desktop_file(bamf_app_));360 return glib::gchar_to_string(bamf_application_get_desktop_file(bamf_app_));
319}361}
320362
321std::string Application::type() const363AppType Application::type() const
322{364{
323 // Can't determine the type of a non-running app.365 // Can't determine the type of a non-running app.
324 std::string result = "unknown";
325 if (running())366 if (running())
326 {367 {
327 const gchar* type = bamf_application_get_application_type(bamf_app_);368 auto type = glib::gchar_to_string(bamf_application_get_application_type(bamf_app_));
328 if (type) result = type;369
370 if (type == "system")
371 return AppType::NORMAL;
372
373 if (type == "webapp")
374 return AppType::WEBAPP;
329 }375 }
330 return result;376
377 return AppType::UNKNOWN;
331}378}
332379
333std::string Application::repr() const380std::string Application::repr() const
@@ -347,9 +394,7 @@
347 std::shared_ptr<GList> children(bamf_view_get_children(bamf_view_), g_list_free);394 std::shared_ptr<GList> children(bamf_view_get_children(bamf_view_), g_list_free);
348 for (GList* l = children.get(); l; l = l->next)395 for (GList* l = children.get(); l; l = l->next)
349 {396 {
350 glib::Object<BamfView> view(BAMF_VIEW(l->data), glib::AddRef());397 if (ApplicationWindowPtr const& window = pool::EnsureWindow(manager_, static_cast<BamfView*>(l->data)))
351 ApplicationWindowPtr const& window(create_window(manager_, view));
352 if (window)
353 result.push_back(window);398 result.push_back(window);
354 }399 }
355 return result;400 return result;
@@ -389,9 +434,7 @@
389434
390ApplicationWindowPtr Application::GetFocusableWindow() const435ApplicationWindowPtr Application::GetFocusableWindow() const
391{436{
392 glib::Object<BamfView> view(bamf_application_get_focusable_child(bamf_app_),437 return pool::EnsureWindow(manager_, bamf_application_get_focusable_child(bamf_app_));
393 glib::AddRef());
394 return create_window(manager_, view);
395}438}
396439
397void Application::Focus(bool show_only_visible, int monitor) const440void Application::Focus(bool show_only_visible, int monitor) const
@@ -507,29 +550,19 @@
507 LOG_TRACE(logger) << "Create BAMF Application Manager";550 LOG_TRACE(logger) << "Create BAMF Application Manager";
508 signals_.Add<void, BamfMatcher*, BamfView*> (matcher_, "view-opened",551 signals_.Add<void, BamfMatcher*, BamfView*> (matcher_, "view-opened",
509 sigc::mem_fun(this, &Manager::OnViewOpened));552 sigc::mem_fun(this, &Manager::OnViewOpened));
553 signals_.Add<void, BamfMatcher*, BamfView*> (matcher_, "view-closed",
554 sigc::mem_fun(this, &Manager::OnViewClosed));
510555
511 signals_.Add<void, BamfMatcher*, BamfView*, BamfView*>(matcher_, "active-window-changed",556 signals_.Add<void, BamfMatcher*, BamfView*, BamfView*>(matcher_, "active-window-changed",
512 [this](BamfMatcher*, BamfView* /* from */, BamfView* to) {557 [this](BamfMatcher*, BamfView* /* from */, BamfView* to) {
513 // Ownership is not passed on signals558 if (ApplicationWindowPtr const& win = pool::EnsureWindow(*this, to))
514 glib::Object<BamfView> view(to, glib::AddRef());
515 ApplicationWindowPtr const& win = create_window(*this, view);
516 if (win)
517 this->active_window_changed.emit(win);559 this->active_window_changed.emit(win);
518 });560 });
519561
520 signals_.Add<void, BamfMatcher*, BamfApplication*, BamfApplication*> (matcher_, "active-application-changed",562 signals_.Add<void, BamfMatcher*, BamfApplication*, BamfApplication*> (matcher_, "active-application-changed",
521 [this](BamfMatcher*, BamfApplication* /* from */, BamfApplication* to) {563 [this](BamfMatcher*, BamfApplication* /* from */, BamfApplication* to) {
522 if (to)564 auto const& app = pool::EnsureApplication(*this, reinterpret_cast<BamfView*>(to));
523 {565 this->active_application_changed.emit(app);
524 // Ownership is not passed on signals
525 glib::Object<BamfApplication> bamf_app(to, glib::AddRef());
526 auto app = std::make_shared<Application>(*this, bamf_app);
527 this->active_application_changed.emit(app);
528 }
529 else
530 {
531 this->active_application_changed.emit(nullptr);
532 }
533 });566 });
534}567}
535568
@@ -546,81 +579,79 @@
546 {579 {
547 auto *app_ptr = bamf_matcher_get_application_for_xid(matcher_, xid);580 auto *app_ptr = bamf_matcher_get_application_for_xid(matcher_, xid);
548581
549 if (BAMF_IS_APPLICATION(app_ptr))582 if (ApplicationPtr const& app = pool::EnsureApplication(*this, reinterpret_cast<BamfView*>(app_ptr)))
550 {583 return app;
551 glib::Object<BamfApplication> app(app_ptr, glib::AddRef());
552 return std::make_shared<Application>(*this, app);
553 }
554 }584 }
555585
556 return GetApplicationForDesktopFile(DesktopUtilities::GetDesktopPathById("compiz.desktop"));586 return GetApplicationForDesktopFile(DesktopUtilities::GetDesktopPathById("compiz.desktop"));
557}587}
558588
589ApplicationPtr Manager::GetActiveApplication() const
590{
591 auto *app_ptr = bamf_matcher_get_active_application(matcher_);
592 return pool::EnsureApplication(*this, reinterpret_cast<BamfView*>(app_ptr));
593}
594
559ApplicationWindowPtr Manager::GetActiveWindow() const595ApplicationWindowPtr Manager::GetActiveWindow() const
560{596{
561 // No transfer of ownership for bamf_matcher_get_active_window.597 if (BamfWindow* active_win = bamf_matcher_get_active_window(matcher_))
562 BamfWindow* active_win = bamf_matcher_get_active_window(matcher_);598 {
563599 if (bamf_window_get_window_type(active_win) != BAMF_WINDOW_DOCK)
564 if (!active_win)600 return pool::EnsureWindow(*this, reinterpret_cast<BamfView*>(active_win));
565 return nullptr;601 }
566602
567 // If the active window is a dock type, then we want the first visible, non-dock type.603 // If the active window is a dock type, then we want the first visible, non-dock type.
568 if (bamf_window_get_window_type(active_win) == BAMF_WINDOW_DOCK)604 LOG_DEBUG(logger) << "Is a dock, looking at the window stack.";
605
606 auto const& wins = GetWindowsForMonitor();
607 WindowManager& wm = WindowManager::Default();
608
609 for (auto it = wins.rbegin(); it != wins.rend(); ++it)
569 {610 {
570 LOG_DEBUG(logger) << "Is a dock, looking at the window stack.";611 auto const& win = *it;
571612 auto xid = win->window_id();
572 std::shared_ptr<GList> windows(bamf_matcher_get_window_stack_for_monitor(matcher_, -1), g_list_free);613
573 WindowManager& wm = WindowManager::Default();614 if (win->visible() &&
574 active_win = nullptr;615 win->type() != WindowType::DOCK &&
575616 wm.IsWindowOnCurrentDesktop(xid) &&
576 for (GList *l = windows.get(); l; l = l->next)617 wm.IsWindowVisible(xid))
577 {618 {
578 if (!BAMF_IS_WINDOW(l->data))619 return win;
579 {
580 LOG_DEBUG(logger) << "Window stack returned something not a window, WTF?";
581 continue;
582 }
583
584 auto win = static_cast<BamfWindow*>(l->data);
585 auto view = static_cast<BamfView*>(l->data);
586 auto xid = bamf_window_get_xid(win);
587
588 if (bamf_view_is_user_visible(view) &&
589 bamf_window_get_window_type(win) != BAMF_WINDOW_DOCK &&
590 wm.IsWindowOnCurrentDesktop(xid) &&
591 wm.IsWindowVisible(xid))
592 {
593 active_win = win;
594 }
595 }620 }
596 }621 }
597622
598 if (active_win)
599 {
600 glib::Object<BamfWindow> win(active_win, glib::AddRef());
601 return std::make_shared<AppWindow>(*this, win);
602 }
603
604 return nullptr;623 return nullptr;
605}624}
606625
607ApplicationPtr Manager::GetApplicationForDesktopFile(std::string const& desktop_file) const626ApplicationPtr Manager::GetApplicationForDesktopFile(std::string const& desktop_file) const
608{627{
609 glib::Object<BamfApplication> app(bamf_matcher_get_application_for_desktop_file(628 auto* app = bamf_matcher_get_application_for_desktop_file(matcher_, desktop_file.c_str(), TRUE);
610 matcher_, desktop_file.c_str(), TRUE), glib::AddRef());629 return pool::EnsureApplication(*this, reinterpret_cast<BamfView*>(app));
611
612 if (app)
613 return std::make_shared<Application>(*this, app);
614
615 return nullptr;
616}630}
617631
618ApplicationPtr Manager::GetApplicationForWindow(Window xid) const632ApplicationPtr Manager::GetApplicationForWindow(Window xid) const
619{633{
620 glib::Object<BamfApplication> app(bamf_matcher_get_application_for_xid(matcher_, xid),634 auto* app = bamf_matcher_get_application_for_xid(matcher_, xid);
621 glib::AddRef());635 return pool::EnsureApplication(*this, reinterpret_cast<BamfView*>(app));
622 if (app)636}
623 return std::make_shared<Application>(*this, app);637
638ApplicationWindowPtr Manager::GetWindowForId(Window xid) const
639{
640 if (xid == 0)
641 return nullptr;
642
643 std::shared_ptr<GList> windows(bamf_matcher_get_windows(matcher_), g_list_free);
644
645 for (GList* l = windows.get(); l; l = l->next)
646 {
647 if (!BAMF_IS_WINDOW(l->data))
648 continue;
649
650 auto win = static_cast<BamfWindow*>(l->data);
651
652 if (bamf_window_get_xid(win) == xid)
653 return pool::EnsureWindow(*this, static_cast<BamfView*>(l->data));
654 }
624655
625 return nullptr;656 return nullptr;
626}657}
@@ -638,26 +669,65 @@
638 continue;669 continue;
639 }670 }
640671
641 glib::Object<BamfApplication> bamf_app(static_cast<BamfApplication*>(l->data), glib::AddRef());672 result.push_back(pool::EnsureApplication(*this, static_cast<BamfView*>(l->data)));
642 auto app = std::make_shared<Application>(*this, bamf_app);
643 result.push_back(app);
644 LOG_DEBUG(logger) << "Running app: " << app->title();
645 }673 }
646 return result;674 return result;
647}675}
648676
677WindowList Manager::GetWindowsForMonitor(int monitor) const
678{
679 WindowList wins;
680 std::shared_ptr<GList> windows(bamf_matcher_get_window_stack_for_monitor(matcher_, monitor), g_list_free);
681
682 for (GList *l = windows.get(); l; l = l->next)
683 {
684 if (!BAMF_IS_WINDOW(l->data))
685 {
686 LOG_DEBUG(logger) << "Window stack returned something not a window, WTF?";
687 continue;
688 }
689
690 auto bamf_win = static_cast<BamfWindow*>(l->data);
691
692 if (bamf_window_get_window_type(bamf_win) != BAMF_WINDOW_DOCK)
693 wins.push_back(pool::EnsureWindow(*this, static_cast<BamfView*>(l->data)));
694 }
695
696 return wins;
697}
649698
650void Manager::OnViewOpened(BamfMatcher* matcher, BamfView* view)699void Manager::OnViewOpened(BamfMatcher* matcher, BamfView* view)
651{700{
652 LOG_TRACE_BLOCK(logger);701 LOG_TRACE_BLOCK(logger);
653 if (!BAMF_IS_APPLICATION(view))702 if (BAMF_IS_APPLICATION(view))
654 {703 {
655 LOG_DEBUG(logger) << "view is not an app";704 if (ApplicationPtr const& app = pool::EnsureApplication(*this, view))
656 return;705 application_started.emit(app);
657 }706 }
658707 else if (BAMF_IS_WINDOW(view))
659 glib::Object<BamfView> app(view, glib::AddRef());708 {
660 application_started.emit(std::make_shared<Application>(*this, app));709 if (ApplicationWindowPtr const& win = pool::EnsureWindow(*this, view))
710 window_opened.emit(win);
711 }
712}
713
714void Manager::OnViewClosed(BamfMatcher* matcher, BamfView* view)
715{
716 LOG_TRACE_BLOCK(logger);
717 if (BAMF_IS_APPLICATION(view))
718 {
719 if (ApplicationPtr const& app = pool::EnsureApplication(*this, view))
720 application_stopped.emit(app);
721
722 pool::apps_.erase(view);
723 }
724 else if (BAMF_IS_WINDOW(view))
725 {
726 if (ApplicationWindowPtr const& win = pool::EnsureWindow(*this, view))
727 window_closed.emit(win);
728
729 pool::wins_.erase(view);
730 }
661}731}
662732
663} // namespace bamf733} // namespace bamf
664734
=== modified file 'unity-shared/BamfApplicationManager.h'
--- unity-shared/BamfApplicationManager.h 2013-09-04 19:38:19 +0000
+++ unity-shared/BamfApplicationManager.h 2015-05-22 16:04:25 +0000
@@ -20,6 +20,7 @@
20#ifndef UNITYSHARED_BAMF_APPLICATION_MANAGER_H20#ifndef UNITYSHARED_BAMF_APPLICATION_MANAGER_H
21#define UNITYSHARED_BAMF_APPLICATION_MANAGER_H21#define UNITYSHARED_BAMF_APPLICATION_MANAGER_H
2222
23#include <unordered_map>
23#include <libbamf/libbamf.h>24#include <libbamf/libbamf.h>
24#include <UnityCore/GLibWrapper.h>25#include <UnityCore/GLibWrapper.h>
25#include <UnityCore/GLibSignal.h>26#include <UnityCore/GLibSignal.h>
@@ -39,7 +40,6 @@
3940
40 std::string GetTitle() const;41 std::string GetTitle() const;
41 std::string GetIcon() const;42 std::string GetIcon() const;
42 std::string type() const;
4343
44 bool GetVisible() const;44 bool GetVisible() const;
45 bool GetActive() const;45 bool GetActive() const;
@@ -59,11 +59,15 @@
59 glib::Object<BamfView> const& window);59 glib::Object<BamfView> const& window);
6060
61public:61public:
62 virtual std::string type() const; // 'window' or 'tab'62 bool Focus() const override;
6363
64 virtual bool Focus() const;64 bool operator==(unity::ApplicationWindow const& other) const override
6565 {
66private:66 return static_cast<WindowBase const*>(this)->bamf_view_ == static_cast<WindowBase const&>(other).bamf_view_;
67 }
68 bool operator!=(unity::ApplicationWindow const& other) const override { return !(operator==(other)); }
69
70protected:
67 glib::SignalManager signals_;71 glib::SignalManager signals_;
68};72};
6973
@@ -76,10 +80,12 @@
76 AppWindow(ApplicationManager const& manager,80 AppWindow(ApplicationManager const& manager,
77 glib::Object<BamfView> const& window);81 glib::Object<BamfView> const& window);
7882
79 virtual Window window_id() const;83 WindowType type() const override;
80 virtual int monitor() const;84 Window window_id() const override;
81 virtual ApplicationPtr application() const;85 int monitor() const override;
82 virtual void Quit() const;86 ApplicationPtr application() const override;
87 void Quit() const override;
88 bool GetMaximized() const;
8389
84private:90private:
85 glib::Object<BamfWindow> bamf_window_;91 glib::Object<BamfWindow> bamf_window_;
@@ -93,11 +99,12 @@
93 Tab(ApplicationManager const& manager,99 Tab(ApplicationManager const& manager,
94 glib::Object<BamfView> const& tab);100 glib::Object<BamfView> const& tab);
95101
96 virtual Window window_id() const;102 WindowType type() const override;
97 virtual int monitor() const;103 Window window_id() const override;
98 virtual ApplicationPtr application() const;104 int monitor() const override;
99 virtual bool Focus() const;105 ApplicationPtr application() const override;
100 virtual void Quit() const;106 bool Focus() const override;
107 void Quit() const override;
101108
102private:109private:
103 glib::Object<BamfTab> bamf_tab_;110 glib::Object<BamfTab> bamf_tab_;
@@ -112,7 +119,7 @@
112 Application(ApplicationManager const& manager,119 Application(ApplicationManager const& manager,
113 glib::Object<BamfView> const& app);120 glib::Object<BamfView> const& app);
114121
115 virtual std::string type() const;122 virtual AppType type() const;
116123
117 virtual WindowList GetWindows() const;124 virtual WindowList GetWindows() const;
118 virtual bool OwnsWindow(Window window_id) const;125 virtual bool OwnsWindow(Window window_id) const;
@@ -128,9 +135,13 @@
128135
129 virtual std::string repr() const;136 virtual std::string repr() const;
130137
138 bool operator==(unity::Application const& other) const override
139 {
140 return static_cast<Application const*>(this)->bamf_app_ == static_cast<Application const&>(other).bamf_app_;
141 }
142 bool operator!=(unity::Application const& other) const override { return !(operator==(other)); }
143
131private: // Property getters and setters144private: // Property getters and setters
132 void HookUpEvents();
133
134 std::string GetDesktopFile() const;145 std::string GetDesktopFile() const;
135146
136 bool GetSeen() const;147 bool GetSeen() const;
@@ -152,13 +163,20 @@
152 ~Manager();163 ~Manager();
153164
154 ApplicationPtr GetUnityApplication() const override;165 ApplicationPtr GetUnityApplication() const override;
166 ApplicationPtr GetActiveApplication() const override;
155 ApplicationWindowPtr GetActiveWindow() const override;167 ApplicationWindowPtr GetActiveWindow() const override;
156 ApplicationPtr GetApplicationForDesktopFile(std::string const& desktop_file) const override;168 ApplicationPtr GetApplicationForDesktopFile(std::string const& desktop_file) const override;
157 ApplicationList GetRunningApplications() const override;169 ApplicationList GetRunningApplications() const override;
170 WindowList GetWindowsForMonitor(int monitor = -1) const override;
158 ApplicationPtr GetApplicationForWindow(Window xid) const override;171 ApplicationPtr GetApplicationForWindow(Window xid) const override;
172 ApplicationWindowPtr GetWindowForId(Window xid) const override;
173
174 ApplicationPtr EnsureApplication(BamfView*) const;
175 ApplicationWindowPtr EnsureWindow(BamfView*) const;
159176
160private:177private:
161 void OnViewOpened(BamfMatcher* matcher, BamfView* view);178 void OnViewOpened(BamfMatcher* matcher, BamfView* view);
179 void OnViewClosed(BamfMatcher* matcher, BamfView* view);
162180
163private:181private:
164 glib::Object<BamfMatcher> matcher_;182 glib::Object<BamfMatcher> matcher_;
165183
=== modified file 'unity-shared/StandaloneAppManager.cpp'
--- unity-shared/StandaloneAppManager.cpp 2014-07-30 00:49:35 +0000
+++ unity-shared/StandaloneAppManager.cpp 2015-05-22 16:04:25 +0000
@@ -33,6 +33,54 @@
3333
34GMainLoop *loop;34GMainLoop *loop;
3535
36std::ostream& operator<<(std::ostream &os, AppType at)
37{
38 switch (at)
39 {
40 case AppType::NORMAL:
41 return os << "NORMAL";
42 case AppType::WEBAPP:
43 return os << "WEBAPP";
44 case AppType::MOCK:
45 return os << "MOCK";
46 case AppType::UNKNOWN:
47 return os << "UNKNOWN";
48 }
49
50 return os;
51}
52
53std::ostream& operator<<(std::ostream &os, WindowType wt)
54{
55 switch (wt)
56 {
57 case WindowType::NORMAL:
58 return os << "NORMAL";
59 case WindowType::DESKTOP:
60 return os << "DESKTOP";
61 case WindowType::DOCK:
62 return os << "DOCK";
63 case WindowType::DIALOG:
64 return os << "DIALOG";
65 case WindowType::TOOLBAR:
66 return os << "TOOLBAR";
67 case WindowType::MENU:
68 return os << "MENU";
69 case WindowType::UTILITY:
70 return os << "UTILITY";
71 case WindowType::SPLASHSCREEN:
72 return os << "SPLASHSCREEN";
73 case WindowType::TAB:
74 return os << "TAB";
75 case WindowType::MOCK:
76 return os << "MOCK";
77 case WindowType::UNKNOWN:
78 return os << "UNKNOWN";
79 }
80
81 return os;
82}
83
36void dump_app(ApplicationPtr const& app, std::string const& prefix = "")84void dump_app(ApplicationPtr const& app, std::string const& prefix = "")
37{85{
38 if (app)86 if (app)
@@ -55,6 +103,7 @@
55 std::cout << " Window: " << win->title()103 std::cout << " Window: " << win->title()
56 << ", window_id: " << win->window_id()104 << ", window_id: " << win->window_id()
57 << ", monitor: " << win->monitor()105 << ", monitor: " << win->monitor()
106 << ", maximized: " << win->maximized()
58 << ", type: " << win->type()107 << ", type: " << win->type()
59 << endl;108 << endl;
60 }109 }
@@ -65,6 +114,8 @@
65 }114 }
66}115}
67116
117std::vector<std::string> names;
118
68void connect_events(ApplicationPtr const& app)119void connect_events(ApplicationPtr const& app)
69{120{
70 if (app->seen())121 if (app->seen())
@@ -72,42 +123,57 @@
72 cout << "Already seen " << app->title() << ", skipping event connection.\n";123 cout << "Already seen " << app->title() << ", skipping event connection.\n";
73 return;124 return;
74 }125 }
75 std::string app_name = app->title();126
76 app->title.changed.connect([&app_name](std::string const& value) {127 auto idx = names.empty() ? 0 : names.size()-1;
77 cout << app_name << " changed name to: " << value << endl;128 names.push_back(app->title());
78 app_name = value;129 app->title.changed.connect([idx](std::string const& value) {
79 });130 cout << names[idx] << " changed name to: " << value << endl;
80 app->icon.changed.connect([&app_name](std::string const& value) {131 names[idx] = value;
81 cout << app_name << " icon changed: " << value << endl;132 });
82 });133 app->icon.changed.connect([idx](std::string const& value) {
83 app->desktop_file.changed.connect([&app_name](std::string const& value) {134 cout << names[idx] << " icon changed: " << value << endl;
84 cout << app_name << " desktop file changed: " << value << endl;135 });
85 });136 app->desktop_file.changed.connect([idx](std::string const& value) {
86 app->visible.changed.connect([&app_name](bool value) {137 cout << names[idx] << " desktop file changed: " << value << endl;
87 cout << app_name << " visibility changed: " << (value ? "yes" : "no") << endl;138 });
88 });139 app->visible.changed.connect([idx](bool value) {
89 app->running.changed.connect([&app_name](bool value) {140 cout << names[idx] << " visibility changed: " << (value ? "yes" : "no") << endl;
90 cout << app_name << " running changed: " << (value ? "yes" : "no") << endl;141 });
91 });142 app->running.changed.connect([idx](bool value) {
92 app->active.changed.connect([&app_name](bool value) {143 cout << names[idx] << " running changed: " << (value ? "yes" : "no") << endl;
93 cout << app_name << " active changed: " << (value ? "yes" : "no") << endl;144 });
94 });145 app->active.changed.connect([idx](bool value) {
95 app->urgent.changed.connect([&app_name](bool value) {146 cout << names[idx] << " active changed: " << (value ? "yes" : "no") << endl;
96 cout << app_name << " urgent changed: " << (value ? "yes" : "no") << endl;147 });
97 });148 app->urgent.changed.connect([idx](bool value) {
98 app->closed.connect([&app_name]() {149 cout << names[idx] << " urgent changed: " << (value ? "yes" : "no") << endl;
99 cout << app_name << " closed." << endl;150 });
100 });151 app->closed.connect([idx]() {
101 app->window_opened.connect([&app_name](ApplicationWindow const& window) {152 cout << names[idx] << " closed." << endl;
102 cout << "** " << app_name << " window opened: " << window.title() << endl;153 });
103 });154 app->window_opened.connect([idx](ApplicationWindowPtr const& window) {
104 app->window_closed.connect([&app_name]() {155 cout << "** " << names[idx] << " window opened: " << window->title() << endl;
105 cout << "** " << app_name << " window closed" << endl;156 });
106 });157 app->window_closed.connect([idx](ApplicationWindowPtr const& window) {
107 app->window_moved.connect([&app_name](ApplicationWindow const& window) {158 cout << "** " << names[idx] << " window closed: " << window->title() << endl;
108 cout << "** " << app_name << " window moved: " << window.title() << endl;159 });
160 app->window_moved.connect([idx](ApplicationWindowPtr const& window) {
161 cout << "** " << names[idx] << " window moved: " << window->title() << endl;
109 });162 });
110 app->seen = true;163 app->seen = true;
164
165 for (auto win : app->GetWindows())
166 {
167 win->title.changed.connect([win] (std::string const& t) {
168 std::cout << "Window "<< win->window_id()<< " title changed to "<< t << endl;
169 });
170 win->maximized.changed.connect([win] (bool m) {
171 std::cout << "Window "<< win->window_id()<< " maximized changed to "<< m << endl;
172 });
173 win->active.changed.connect([win] (bool a) {
174 std::cout << "Window "<< win->window_id()<< " active changed to "<< a << endl;
175 });
176 }
111}177}
112178
113179