Merge lp:~3v1n0/unity/static-quicklist-startup-notification into lp:unity

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Łukasz Zemczak
Approved revision: no longer in the source branch.
Merged at revision: 3293
Proposed branch: lp:~3v1n0/unity/static-quicklist-startup-notification
Merge into: lp:unity
Diff against target: 185 lines (+58/-21)
6 files modified
launcher/ApplicationLauncherIcon.cpp (+6/-2)
launcher/QuicklistMenuItem.cpp (+5/-3)
launcher/QuicklistMenuItem.h (+1/-0)
tests/autopilot/unity/tests/__init__.py (+8/-0)
tests/autopilot/unity/tests/launcher/test_icon_behavior.py (+0/-6)
tests/autopilot/unity/tests/test_quicklist.py (+38/-10)
To merge this branch: bzr merge lp:~3v1n0/unity/static-quicklist-startup-notification
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Łukasz Zemczak autopilot Approve
Brandon Schaefer (community) Approve
Andrea Azzarone (community) unity code Approve
Thomi Richards autopilot Pending
Review via email: mp+157934@code.launchpad.net

Commit message

ApplicationLauncherIcon: use GAppLaunchContext to open indicator shortcuts

Using the new indicator_desktop_shortcuts_nick_exec_with_context passing to it
the context containing the timestamp of the quicklist activation event.

Description of the change

Using indicator_desktop_shortcuts_nick_exec_with_context to open unity static quicklist with proper timestamp, so that startup-notify will work as expected (and also the compiz Focus Stealing prevention).

Added an autopilot test, also fixed the test_quicklist_actions so that it works with any locale now.

PS: make sure to use lp:~3v1n0/libindicator/shortcut-nicks-startup-notify-13.04 or the test won't pass.

To post a comment you must log in.
Revision history for this message
Andrea Azzarone (azzar1) wrote :

lgtm

review: Approve (unity code)
Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

Test pass for me, LGTM

review: Approve
Revision history for this message
Łukasz Zemczak (sil2100) wrote :

Test wise the code looks ok. As mentioned already, good to know DesktopEntry has so many convenient methods!

review: Approve (autopilot)
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'launcher/ApplicationLauncherIcon.cpp'
2--- launcher/ApplicationLauncherIcon.cpp 2013-04-08 18:19:46 +0000
3+++ launcher/ApplicationLauncherIcon.cpp 2013-04-09 18:46:26 +0000
4@@ -731,8 +731,12 @@
5 std::string nick(nicks[index]);
6
7 _gsignals.Add<void, DbusmenuMenuitem*, gint>(item, DBUSMENU_MENUITEM_SIGNAL_ITEM_ACTIVATED,
8- [this, nick] (DbusmenuMenuitem* item, unsigned) {
9- indicator_desktop_shortcuts_nick_exec(_desktop_shortcuts, nick.c_str());
10+ [this, nick] (DbusmenuMenuitem* item, unsigned timestamp) {
11+ GdkDisplay* display = gdk_display_get_default();
12+ glib::Object<GdkAppLaunchContext> context(gdk_display_get_app_launch_context(display));
13+ gdk_app_launch_context_set_timestamp(context, timestamp);
14+ auto gcontext = glib::object_cast<GAppLaunchContext>(context);
15+ indicator_desktop_shortcuts_nick_exec_with_context(_desktop_shortcuts, nick.c_str(), gcontext);
16 });
17
18 dbusmenu_menuitem_child_append(_menu_desktop_shortcuts, item);
19
20=== modified file 'launcher/QuicklistMenuItem.cpp'
21--- launcher/QuicklistMenuItem.cpp 2013-03-19 18:47:01 +0000
22+++ launcher/QuicklistMenuItem.cpp 2013-04-09 18:46:26 +0000
23@@ -39,6 +39,7 @@
24 : nux::View(NUX_FILE_LINE_PARAM)
25 , _item_type(type)
26 , _menu_item(item)
27+ , _activate_timestamp(0)
28 , _prelight(false)
29 {
30 mouse_up.connect(sigc::mem_fun(this, &QuicklistMenuItem::RecvMouseUp));
31@@ -134,8 +135,8 @@
32 if (!_menu_item || !GetSelectable())
33 return;
34
35- auto event_time = nux::GetGraphicsDisplay()->GetCurrentEvent().x11_timestamp;
36- dbusmenu_menuitem_handle_event(_menu_item, "clicked", nullptr, event_time);
37+ _activate_timestamp = nux::GetGraphicsDisplay()->GetCurrentEvent().x11_timestamp;
38+ dbusmenu_menuitem_handle_event(_menu_item, "clicked", nullptr, _activate_timestamp);
39
40 if (!IsOverlayQuicklist())
41 {
42@@ -434,7 +435,8 @@
43 .add("active", GetActive())
44 .add("visible", GetVisible())
45 .add("selectable", GetSelectable())
46- .add("selected", _prelight);
47+ .add("selected", _prelight)
48+ .add("activate_timestamp", _activate_timestamp);
49 }
50
51 } //NAMESPACE
52
53=== modified file 'launcher/QuicklistMenuItem.h'
54--- launcher/QuicklistMenuItem.h 2013-02-08 14:33:35 +0000
55+++ launcher/QuicklistMenuItem.h 2013-04-09 18:46:26 +0000
56@@ -123,6 +123,7 @@
57 nux::ObjectPtr<nux::BaseTexture> _prelightTexture[2];
58 QuicklistMenuItemType _item_type;
59 glib::Object<DbusmenuMenuitem> _menu_item;
60+ mutable Time _activate_timestamp;
61 bool _prelight;
62 int _pre_layout_width;
63 int _pre_layout_height;
64
65=== modified file 'tests/autopilot/unity/tests/__init__.py'
66--- tests/autopilot/unity/tests/__init__.py 2013-04-05 15:21:12 +0000
67+++ tests/autopilot/unity/tests/__init__.py 2013-04-09 18:46:26 +0000
68@@ -40,6 +40,9 @@
69 Unity
70 )
71
72+from Xlib import display
73+from Xlib import Xutil
74+
75
76 log = getLogger(__name__)
77
78@@ -228,3 +231,8 @@
79 def register_nautilus(self):
80 self.addCleanup(self.unregister_known_application, "Nautilus")
81 self.register_known_application("Nautilus", "nautilus.desktop", "nautilus")
82+
83+ def get_startup_notification_timestamp(self, bamf_window):
84+ atom = display.Display().intern_atom('_NET_WM_USER_TIME')
85+ atom_type = display.Display().intern_atom('CARDINAL')
86+ return bamf_window.x_win.get_property(atom, atom_type, 0, 1024).value[0]
87
88=== modified file 'tests/autopilot/unity/tests/launcher/test_icon_behavior.py'
89--- tests/autopilot/unity/tests/launcher/test_icon_behavior.py 2013-04-05 15:22:02 +0000
90+++ tests/autopilot/unity/tests/launcher/test_icon_behavior.py 2013-04-09 18:46:26 +0000
91@@ -19,7 +19,6 @@
92 from unity.emulators.launcher import IconDragType
93 from unity.tests.launcher import LauncherTestCase, _make_scenarios
94
95-from Xlib import display
96 from Xlib import Xutil
97
98 logger = logging.getLogger(__name__)
99@@ -60,11 +59,6 @@
100 self.assertThat(lambda: self.app_is_running("Calculator"), Eventually(Equals(False)))
101 return calc_icon
102
103- def get_startup_notification_timestamp(self, bamf_window):
104- atom = display.Display().intern_atom('_NET_WM_USER_TIME')
105- atom_type = display.Display().intern_atom('CARDINAL')
106- return bamf_window.x_win.get_property(atom, atom_type, 0, 1024).value[0]
107-
108 def test_bfb_tooltip_disappear_when_dash_is_opened(self):
109 """Tests that the bfb tooltip disappear when the dash is opened."""
110 bfb = self.unity.launcher.model.get_bfb_icon()
111
112=== modified file 'tests/autopilot/unity/tests/test_quicklist.py'
113--- tests/autopilot/unity/tests/test_quicklist.py 2013-02-04 04:38:46 +0000
114+++ tests/autopilot/unity/tests/test_quicklist.py 2013-04-09 18:46:26 +0000
115@@ -38,32 +38,60 @@
116 self.assertThat(launcher_icon.get_quicklist, Eventually(NotEquals(None)))
117 return launcher_icon.get_quicklist()
118
119+ def get_desktop_entry(self, application):
120+ # load the desktop file from disk:
121+ desktop_id = self.KNOWN_APPS[application]['desktop-file']
122+ desktop_file = os.path.join('/usr/share/applications', desktop_id)
123+ return DesktopEntry(desktop_file)
124+
125 def test_quicklist_actions(self):
126 """Test that all actions present in the destop file are shown in the quicklist."""
127- self.start_app(self.app_name)
128+ app = self.start_app(self.app_name)
129
130- # load the desktop file from disk:
131- desktop_id = self.KNOWN_APPS[self.app_name]['desktop-file']
132- desktop_file = os.path.join('/usr/share/applications', desktop_id)
133- de = DesktopEntry(desktop_file)
134 # get the launcher icon from the launcher:
135- launcher_icon = self.unity.launcher.model.get_icon(desktop_id=desktop_id)
136+ launcher_icon = self.unity.launcher.model.get_icon(desktop_id=app.desktop_file)
137 self.assertThat(launcher_icon, NotEquals(None))
138
139 # open the icon quicklist, and get all the text labels:
140+ de = self.get_desktop_entry(self.app_name)
141 ql = self.open_quicklist_for_icon(launcher_icon)
142 ql_item_texts = [i.text for i in ql.items if type(i) is QuicklistMenuItemLabel]
143
144 # iterate over all the actions from the desktop file, make sure they're
145 # present in the quicklist texts.
146- # FIXME, this doesn't work using a locale other than English.
147- actions = de.getActions()
148- for action in actions:
149+ for action in de.getActions():
150 key = 'Desktop Action ' + action
151 self.assertThat(de.content, Contains(key))
152- name = de.content[key]['Name']
153+ name = de.get('Name', group=key, locale=True)
154 self.assertThat(ql_item_texts, Contains(name))
155
156+ def test_quicklist_action_uses_startup_notification(self):
157+ """Tests that quicklist uses startup notification protocol."""
158+ self.register_nautilus()
159+ self.addCleanup(self.close_all_windows, "Nautilus")
160+
161+ self.start_app_window("Calculator")
162+ self.start_app(self.app_name)
163+
164+ nautilus_icon = self.unity.launcher.model.get_icon(desktop_id="nautilus.desktop")
165+ ql = self.open_quicklist_for_icon(nautilus_icon)
166+ de = self.get_desktop_entry("Nautilus")
167+
168+ new_window_action_name = de.get("Name", group="Desktop Action Window", locale=True)
169+ self.assertThat(new_window_action_name, NotEquals(None))
170+ new_win_ql_item_fn = lambda : ql.get_quicklist_item_by_text(new_window_action_name)
171+ self.assertThat(new_win_ql_item_fn, Eventually(NotEquals(None)))
172+ new_win_ql_item = new_win_ql_item_fn()
173+
174+ ql.click_item(new_win_ql_item)
175+
176+ nautilus_windows_fn = lambda: self.get_open_windows_by_application("Nautilus")
177+ self.assertThat(lambda: len(nautilus_windows_fn()), Eventually(Equals(1)))
178+ [nautilus_window] = nautilus_windows_fn()
179+
180+ self.assertThat(lambda: self.get_startup_notification_timestamp(nautilus_window),
181+ Eventually(Equals(new_win_ql_item.activate_timestamp)))
182+
183 def test_quicklist_application_item_focus_last_active_window(self):
184 """This tests shows that when you activate a quicklist application item
185 only the last focused instance of that application is rasied.