Merge lp:~mitya57/indicator-datetime/lp1502480 into lp:indicator-datetime/15.10

Proposed by Dmitry Shachnev
Status: Merged
Approved by: Sebastien Bacher
Approved revision: no longer in the source branch.
Merged at revision: 440
Proposed branch: lp:~mitya57/indicator-datetime/lp1502480
Merge into: lp:indicator-datetime/15.10
Diff against target: 56 lines (+28/-1)
2 files modified
include/datetime/actions-live.h (+1/-0)
src/actions-live.cpp (+27/-1)
To merge this branch: bzr merge lp:~mitya57/indicator-datetime/lp1502480
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
Sebastien Bacher Approve
Alkis Georgopoulos (community) Approve
Mystic-Mirage (community) Approve
Alberts Muktupāvels Approve
Ted Gould Pending
Lars Karlitski Pending
Review via email: mp+290145@code.launchpad.net

Commit message

Support multiple desktop names in $XDG_CURRENT_DESKTOP.

Description of the change

According to the Desktop Entry specification:

If $XDG_CURRENT_DESKTOP is set then it contains a colon-separated list of strings. In order, each string is considered.

This branch adds support for proper detecting of Unity-derived desktops. It is mainly needed for GNOME Flashback session, which uses unity-control-center and XDG_DESKTOP_NAME=GNOME-Flashback:Unity.

To post a comment you must log in.
Revision history for this message
Alberts Muktupāvels (muktupavels) :
review: Approve
Revision history for this message
Mystic-Mirage (mystic-mirage) :
review: Approve
Revision history for this message
Alkis Georgopoulos (alkisg) wrote :

It looks fine to me.

In shell, to avoid the loop, I do:
if echo ":$XDG_CURRENT_DESKTOP:" | grep -q ":Unity:"; then
    echo yes
else
    echo no
fi

Performance-wise it's fine, it needs only one malloc (for strcat) instead of many (for split), but I'm not sure how readable it is.

review: Approve
Revision history for this message
Sebastien Bacher (seb128) wrote :

thanks

review: Approve
Revision history for this message
Sebastien Bacher (seb128) wrote :

it might be a bit nicer to move the is_unity in a function which is what is done usually...

Revision history for this message
Charles Kerr (charlesk) wrote :

+1 on seb128's to move it into a standalone is_unity() function.

Not a dealbreaker, but I'd probably cache the flag so that we don't have to re-evaluate it every time is_unity() is called.

440. By Dmitry Shachnev

Support multiple desktop names in XDG_CURRENT_DESKTOP

Revision history for this message
Dmitry Shachnev (mitya57) wrote :

Added a standalone function and caching, please re-review.

Revision history for this message
Charles Kerr (charlesk) wrote :

LGTM. Thanks Dmitry :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/datetime/actions-live.h'
2--- include/datetime/actions-live.h 2016-03-21 17:32:39 +0000
3+++ include/datetime/actions-live.h 2016-04-05 21:02:27 +0000
4@@ -53,6 +53,7 @@
5 void set_location(const std::string& zone, const std::string& name) override;
6
7 protected:
8+ static bool is_unity();
9 virtual void execute_command(const std::string& command);
10 virtual void dispatch_url(const std::string& url);
11 };
12
13=== modified file 'src/actions-live.cpp'
14--- src/actions-live.cpp 2016-03-21 17:32:39 +0000
15+++ src/actions-live.cpp 2016-04-05 21:02:27 +0000
16@@ -61,13 +61,39 @@
17 ****
18 ***/
19
20+bool LiveActions::is_unity()
21+{
22+ static bool cached = false;
23+ static bool result;
24+
25+ if (cached) {
26+ return result;
27+ }
28+
29+ result = false;
30+ const gchar *xdg_current_desktop = g_getenv ("XDG_CURRENT_DESKTOP");
31+
32+ if (xdg_current_desktop != NULL) {
33+ gchar **desktop_names = g_strsplit (xdg_current_desktop, ":", 0);
34+ for (size_t i = 0; desktop_names[i]; ++i) {
35+ if (!g_strcmp0 (desktop_names[i], "Unity")) {
36+ result = true;
37+ break;
38+ }
39+ }
40+ g_strfreev (desktop_names);
41+ }
42+ cached = true;
43+ return result;
44+}
45+
46 void LiveActions::desktop_open_settings_app()
47 {
48 if (g_getenv ("MIR_SOCKET") != nullptr)
49 {
50 dispatch_url("settings:///system/time-date");
51 }
52- else if ((g_strcmp0 (g_getenv ("XDG_CURRENT_DESKTOP"), "Unity") == 0))
53+ else if (is_unity())
54 {
55 execute_command("unity-control-center datetime");
56 }

Subscribers

People subscribed via source and target branches