我喜欢 Spotify 的指示菜单,只要应用程序打开,它就会展开。我不喜欢 Rhythmbox 的菜单,它总是显示所有按钮。
当应用程序处于不活动状态时,我想隐藏 Rhythmbox 的 Rew/Play/FF 按钮。
感谢您的帮助。
答案1
声音指示器,无活动播放器(仅启动器,无控制按钮)
声音指示器,带有活动播放器(完整控制按钮)
15.10
具有与 14.04 相同的构建步骤。
关闭后从菜单中删除播放器
修改菜单
src/service.vala
为desktop
HIDE_INACTIVE_PLAYERS。this.menus.insert ("desktop", new SoundMenu ("indicator.desktop-settings", SoundMenu.DisplayFlags.SHOW_MUTE|SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS));
src/sound-menu.vala
如果它未运行且设置了隐藏非活动状态,则将 add_player 函数修改为 remove_player_section。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);
关闭后从菜单中隐藏播放器控件(上一个/播放/下一个),仅保留其启动器
与 14.04 相同,没有变化。
14.04
下载构建依赖项和源代码
sudo apt-get build-dep indicator-sound apt-get source indicator-sound
选择您想要的行为:
关闭后从菜单中删除播放器
修改
src/service.vala
菜单desktop
。this.menus.insert ("desktop", new SoundMenu ("indicator.desktop-settings", SoundMenu.DisplayFlags.SHOW_MUTE | SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS));
我添加了,如果您想使用静音播放器隐藏音量控制,
| SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS
您可以将其删除。SoundMenu.DisplayFlags.SHOW_MUTE |
关闭后从菜单中隐藏播放器控件(上一个/播放/下一个),仅保留其启动器
调整
src/sound-menu.vala
HIDE_INACTIVE_PLAYERS_CONTROLS = 128
在,
上一行末尾添加新标志。public enum DisplayFlags { NONE = 0, SHOW_MUTE = 1, HIDE_INACTIVE_PLAYERS = 2, HIDE_PLAYERS = 4, HIDE_INACTIVE_PLAYERS_CONTROLS = 128 }
添加
bool hide_inactive_controls;
变量来保存标志状态bool hide_inactive; bool hide_inactive_controls; bool hide_players = false;
添加
this.hide_inactive_controls =...
行。将 SoundMenu 构造函数标志参数传递给其变量。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);
添加
if (player.is_running || !this.hide_inactive_controls) {
和}
。以包装在菜单项中创建(上一个/播放/下一个)的指令。因此,只有当播放器正在运行或隐藏标志处于非活动状态时,才会创建它们。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); }
添加
if (this.hide_inactive_controls) {
到下一个}
。当播放器状态改变时,强制重新创建播放器菜单部分is-running
。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); });
最后,修改
src/service.vala
。将我们新创建的标志添加| SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS_CONTROLS
到desktop
菜单中。this.menus.insert ("desktop", new SoundMenu ("indicator.desktop-settings", SoundMenu.DisplayFlags.SHOW_MUTE | SoundMenu.DisplayFlags.HIDE_INACTIVE_PLAYERS_CONTROLS));
构建和安装
cd indicator-sound-12.10.2+14.04.20140313/ mkdir build cd build/ cmake .. make sudo make install
现在,关闭播放器后播放器将会消失。
12.04
下载构建依赖项和源代码
sudo apt-get build-dep indicator-sound apt-get source indicator-sound
修改
src/player-controller.vala
,在两次出现中替换"rhythmbox.desktop"
为。(只是名称不同)"xrhythmbox.desktop"
构建和安装
cd indicator-sound-0.8.5.0/ ./configure make make install
笔记:这是一个简单的技巧,正确的方法可能是:
代替
this.custom_items[widget_order.TRANSPORT].property_set_bool (MENUITEM_PROP_VISIBLE, this.app_info.get_id() == "rhythmbox.desktop");
和
this.custom_items[widget_order.TRANSPORT].property_set_bool (MENUITEM_PROP_VISIBLE, false);
和
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); }
和
this.custom_items[widget_order.TRANSPORT].property_set_bool (MENUITEM_PROP_VISIBLE, true);