5

I like Spotify's indicator menu which expands whenever the application is open. I don't like Rhythmbox's which shows all the buttons all the time.

I'd like to hide the Rew/Play/FF buttons from Rhythmbox when the application is inactive.

Thank you for your help.

user.dz
  • 48,105
Diego-MX
  • 608

1 Answers1

4

Sound indicator, with no active player (launchers only, no control buttons)

Sound indicator, with no active player (launchers only, no control buttons)

Sound indicator, with active player (full control buttons)

Sound indicator, with active player (full control buttons)


15.10

Have same build steps as 14.04.

  • Remove player from menu after close

    Modify src/service.vala for desktop menu to HIDE_INACTIVE_PLAYERS.

    this.menus.insert ("desktop", new SoundMenu ("indicator.desktop-settings", SoundMenu.DisplayFlags.SHOW_MUTE|SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS));
    

    And modify src/sound-menu.vala for add_player function to remove_player_section if it is not running & hide inactive is set.

    public void add_player (MediaPlayer player) {
        if (this.notify_handlers.contains (player))
            return;
    
        if (player.is_running || !this.hide_inactive)
                this.insert_player_section (player);
            else         
                this.remove_player_section (player);
        this.update_playlists (player);
    
  • Hide player controls (Prev/Play/Next) from menu after close, keep only its launcher

    Same as 14.04, no change.


14.04

  1. Download build dependencies and source

    sudo apt-get build-dep indicator-sound
    apt-get source indicator-sound
    
  2. Choose the behavior you want:

    • Remove player from menu after close

      Modify src/service.vala for desktop menu.

      this.menus.insert ("desktop", new SoundMenu ("indicator.desktop-settings", SoundMenu.DisplayFlags.SHOW_MUTE | SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS));
      

      I added | SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS, You can remove SoundMenu.DisplayFlags.SHOW_MUTE | if you want hide volume control with muted players.

    • Hide player controls (Prev/Play/Next) from menu after close, keep only its launcher

      Modify src/sound-menu.vala

      1. Add new flag HIDE_INACTIVE_PLAYERS_CONTROLS = 128 with , in end of previous line.

        public enum DisplayFlags {
            NONE = 0,
            SHOW_MUTE = 1,
            HIDE_INACTIVE_PLAYERS = 2,
            HIDE_PLAYERS = 4,
            HIDE_INACTIVE_PLAYERS_CONTROLS = 128
        }
        
      2. Add bool hide_inactive_controls; variable to hold flag status

        bool hide_inactive;
        bool hide_inactive_controls;
        bool hide_players = false;
        
      3. Add this.hide_inactive_controls =... line. to pass SoundMenu constructor flag parameter to its variable.

        this.hide_inactive = (flags & DisplayFlags.HIDE_INACTIVE_PLAYERS) != 0;
        this.hide_inactive_controls = (flags & DisplayFlags.HIDE_INACTIVE_PLAYERS_CONTROLS) != 0;
        this.notify_handlers = new HashTable<MediaPlayer, ulong> (direct_hash, direct_equal);
        
      4. Add if (player.is_running || !this.hide_inactive_controls) { and }. to wrap instructions which create (prev/play/next) in menu item. So they are not created only if player is running or hide flag is inactive.

        if (player.is_running || !this.hide_inactive_controls) {
            var playback_item = new MenuItem (null, null);
            playback_item.set_attribute ("x-canonical-type", "s", "com.canonical.unity.playback-item");
            playback_item.set_attribute ("x-canonical-play-action", "s", "indicator.play." + player.id);
            playback_item.set_attribute ("x-canonical-next-action", "s", "indicator.next." + player.id);
            playback_item.set_attribute ("x-canonical-previous-action", "s", "indicator.previous." + player.id);
            section.append_item (playback_item);
        }
        
      5. Add if (this.hide_inactive_controls) { to next }. To force player menu section recreation when player is-running state changes.

        var handler_id = player.notify["is-running"].connect ( () => {
            if (this.hide_inactive) {
                if (player.is_running) {
                    this.insert_player_section (player);
                }
                else {
                    this.remove_player_section (player);
                }
            }
            if (this.hide_inactive_controls) {
                this.remove_player_section (player);
                this.insert_player_section (player);
            }
            this.update_playlists (player);
        });
        
      6. Finally, modify src/service.vala. Add our new created flag | SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS_CONTROLS to desktop menu.

        this.menus.insert ("desktop", new SoundMenu ("indicator.desktop-settings", SoundMenu.DisplayFlags.SHOW_MUTE | SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS_CONTROLS));
        
  3. Build and install

    cd indicator-sound-12.10.2+14.04.20140313/
    mkdir build
    cd build/
    cmake ..
    make
    sudo make install
    

Now, the players will disappear after closing them.


12.04

  1. Download build dependencies and source

    sudo apt-get build-dep indicator-sound
    apt-get source indicator-sound
    
  2. Modify src/player-controller.vala, Replace "rhythmbox.desktop" with "xrhythmbox.desktop" in the two occurrences. (just different name)

  3. Build and install

    cd indicator-sound-0.8.5.0/
    ./configure
    make
    make install
    

Note: That was a quick trick, the correct way may be:

  • Replace

      this.custom_items[widget_order.TRANSPORT].property_set_bool (MENUITEM_PROP_VISIBLE,
                                                              this.app_info.get_id() == "rhythmbox.desktop"); 
    

    with

      this.custom_items[widget_order.TRANSPORT].property_set_bool (MENUITEM_PROP_VISIBLE,
                                                              false); 
    
  • and

    if (this.app_info.get_id() == "rhythmbox.desktop"){
      TransportMenuitem transport = this.custom_items[widget_order.TRANSPORT] as TransportMenuitem;
      transport.handle_cached_action();
    }
    else{
      this.custom_items[widget_order.TRANSPORT].property_set_bool (MENUITEM_PROP_VISIBLE,
                                                               true);         
    }
    

    with

    this.custom_items[widget_order.TRANSPORT].property_set_bool (MENUITEM_PROP_VISIBLE,
                                                               true);
    
user.dz
  • 48,105
  • Thank you. I have two problems with this instructions:

    I didn't have the file service.vala in src. Am I suppose to create the file and include that line?

    Second, do I need to keep those folders in my home folder? (Sorry, this is my first time modifying such source files)

    – Diego-MX Mar 18 '14 at 02:27
  • 1
    This worked in 14.04, but it removed the applications completely from the menu. Is it possible to only remove the Rew,Play,FF buttons but keep the startup buttons? – Diego-MX Apr 10 '14 at 22:43
  • Thanks, that's great. By the way, if you know of a reference to learn this kind of stuff, I could also welcome that. =) – Diego-MX Apr 11 '14 at 13:20
  • This is beautiful!! I can get the code, but don't know what the objects or methods refer to. – Diego-MX Apr 11 '14 at 22:20
  • Doesn't seem to work on 15.10 anymore :( The code for indicator-sound seems to be unchanged but when building it as you suggested it doesn't start up anymore – wa4557 Nov 29 '15 at 12:52
  • @wa4557 , updated for 15.10 . No major change so i suppose it will work for 14.10 & 15.04 too, enjoy! – user.dz Nov 30 '15 at 15:11
  • 1
    @Sneetsher. Thanks! In your point 1. you're contradicting yourself. Is it HIDE_INACTIVE_PLAYERS_CONTROLS = 128 or =8? (Because there is already GREETER_PLAYERS = 8,) – wa4557 Nov 30 '15 at 21:54
  • @wa4557, ah I missed that, it is 128 (8 & 16 have been used in 15.10, so I thought going to last for a byte. You may use 32 or 64 too) . Thank you, I have updated the answer. – user.dz Nov 30 '15 at 22:02
  • @wa4557, no that was from 14.04 version, so add only lines I have added. – user.dz Nov 30 '15 at 22:07