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

Proposed by Dmitry Shachnev
Status: Merged
Approved by: Sebastien Bacher
Approved revision: 536
Merged at revision: 536
Proposed branch: lp:~mitya57/indicator-sound/lp1502480
Merge into: lp:indicator-sound/15.10
Diff against target: 53 lines (+22/-6)
1 file modified
src/service.vala (+22/-6)
To merge this branch: bzr merge lp:~mitya57/indicator-sound/lp1502480
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
Alkis Georgopoulos (community) Approve
Mystic-Mirage (community) Approve
Alberts Muktupāvels Approve
Sebastien Bacher Pending
Ted Gould Pending
Lars Karlitski Pending
Review via email: mp+290144@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
Charles Kerr (charlesk) wrote :

Not a blocker, but I think the standalone ``is_unity()'' function makes sense here as well as in indicator-datetime.

Two reasons:
1. readability: (is_unity() && (Environment.find_program_in_path ("unity-control-center") != null))
2. the ability of is_unity() to cache its value s.t. it doesn't have to re-evaluate each time it's called

review: Approve
537. By Dmitry Shachnev

Move Unity detection into a separate function, and add caching

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

Splitted the code into a separate function and added caching, please check. I'm not fluent in Vala, so if that could be done simplier, please let me know.

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

LGTM.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/service.vala'
2--- src/service.vala 2016-03-16 14:00:47 +0000
3+++ src/service.vala 2016-04-05 21:55:32 +0000
4@@ -206,6 +206,7 @@
5 private VolumeWarning _volume_warning;
6 private IndicatorSound.InfoNotification _info_notification = new IndicatorSound.InfoNotification();
7 private AccountsServiceAccess _accounts_service_access;
8+ bool? is_unity = null;
9
10 const double volume_step_percentage = 0.06;
11
12@@ -224,6 +225,24 @@
13 }
14 }
15
16+ private bool desktop_is_unity() {
17+ if (is_unity != null) {
18+ return is_unity;
19+ }
20+
21+ is_unity = false;
22+ unowned string desktop = Environment.get_variable ("XDG_CURRENT_DESKTOP");
23+
24+ foreach (var name in desktop.split(":")) {
25+ if (name == "Unity") {
26+ is_unity = true;
27+ break;
28+ }
29+ }
30+
31+ return is_unity;
32+ }
33+
34 void activate_desktop_settings (SimpleAction action, Variant? param) {
35 unowned string env = Environment.get_variable ("DESKTOP_SESSION");
36 string cmd;
37@@ -238,13 +257,10 @@
38 cmd = "pavucontrol";
39 else if (env == "mate")
40 cmd = "mate-volume-control";
41+ else if (desktop_is_unity() && Environment.find_program_in_path ("unity-control-center") != null)
42+ cmd = "unity-control-center sound";
43 else
44- {
45- if (Environment.get_variable ("XDG_CURRENT_DESKTOP") == "Unity" && Environment.find_program_in_path ("unity-control-center") != null)
46- cmd = "unity-control-center sound";
47- else
48- cmd = "gnome-control-center sound";
49- }
50+ cmd = "gnome-control-center sound";
51
52 try {
53 Process.spawn_command_line_async (cmd);

Subscribers

People subscribed via source and target branches