1 // vi: et sw=2 fileencoding=utf8
4 const Mainloop = imports.mainloop;
5 const St = imports.gi.St;
6 const PopupMenu = imports.ui.popupMenu;
7 const Slider = imports.ui.slider;
8 const Pango = imports.gi.Pango;
9 const GLib = imports.gi.GLib;
10 const Gio = imports.gi.Gio;
11 const Atk = imports.gi.Atk;
12 const Clutter = imports.gi.Clutter;
13 const Lang = imports.lang;
15 const BoxPointer = imports.ui.boxpointer;
17 const Volume = imports.ui.status.volume;
20 const AppOutputStreamSlider = new Lang.Class({
21 Name: "AppOutputStreamSlider",
22 Extends: Volume.OutputStreamSlider,
24 _init: function(control, oldStyle) {
26 log("AppOutputStreamSlider");
30 this.oldStyle = oldStyle || false;
31 this.item = new PopupMenu.PopupBaseMenuItem({ activate: false });
33 this._vbox = new St.BoxLayout({vertical: true});
35 this._slider = new Slider.Slider(0);
36 this._slider.connect('value-changed', Lang.bind(this, this._sliderChanged));
37 this._slider.connect('drag-end', Lang.bind(this, this._notifyVolumeChange));
39 this._icon = new St.Icon({ style_class: 'adv-volume-icon' });
40 this._label = new St.Label({text: ""});
41 this.item.actor.add(this._icon);
42 this._vbox.add(this._label);
43 this._vbox.add(this._slider.actor);
44 this.item.actor.add(this._vbox, {expand: true});
46 this.item.actor.connect('scroll-event', Lang.bind(this._slider, this._slider._onScrollEvent));
49 setButtonPressEvent: function() {
50 this.item.actor.connect('button-press-event', Lang.bind(this, function(actor, event) {
51 // FIXME Middle click mute
52 this._slider.startDragging(event);
56 setOnlyMiddleButtonPressEvent: function() {
57 this.item.actor.connect('button-press-event', Lang.bind(this, function(actor, event) {
58 // FIXME Middle click mute
62 setKeyPressEvent: function() {
63 this.item.actor.connect('key-press-event', Lang.bind(this, function(actor, event) {
64 return this._slider.onKeyPressEvent(actor, event);
68 _updateSliderIcon: function() {
69 if (this._stream && !this.oldStyle) {
70 this._icon.gicon = this._stream.get_gicon();
75 this.emit("stream-updated");
78 _connectStream: function(stream) {
81 this._label.text = stream.get_name() || stream.get_description();
82 this._updateSliderIcon();
83 this.item.actor.stream = stream;
87 const AdvSubMenuItem = new Lang.Class({
88 Name: "AdvSubMenuItem",
89 Extends: PopupMenu.PopupSubMenuMenuItem,
91 _init: function(oldStyle) {
92 this.parent("", true);
94 //this.icon.remove_style_class_name("popup-menu-icon");
95 this.icon.set_style_class_name("adv-volume-icon");
96 this.slider = new Slider.Slider(0);
98 // Remove actors except ornament
99 this.actor.get_children().map(Lang.bind(this, function(child) {
101 if (!child.has_style_class_name("popup-menu-ornament")) {
102 this.actor.remove_actor(child);
107 this.actor.add_child(this.icon);
108 this.actor.add(this.slider.actor, {expand: true});
109 this.actor.add_child(this._triangleBin);
111 this._vbox = new St.BoxLayout({vertical: true});
112 this._hbox = new St.BoxLayout({vertical: false});
114 this._hbox.add(this.label);
115 this._hbox.add(this._triangleBin);
116 this._vbox.add(this._hbox);
117 this._vbox.add(this.slider.actor);
119 this.actor.add_child(this.icon);
120 this.actor.add_child(this._vbox);
124 _onButtonReleaseEvent: function (actor, event) {
125 if (event.get_button() != 2) {
126 this._setOpenState(!this._getOpenState());
132 const AdvOutputStreamSlider = new Lang.Class({
133 Name: "AdvOutputStreamSlider",
134 Extends: AppOutputStreamSlider,
136 _init: function(control, oldStyle) {
137 this.parent(control, oldStyle);
138 log("AdvOutputStreamSlider");
141 this.item = new AdvSubMenuItem(this.oldStyle);
143 this._slider.actor.destroy();
144 this._slider = this.item.slider;
145 this._slider.connect('value-changed', Lang.bind(this, this._sliderChanged));
146 this._slider.connect('drag-end', Lang.bind(this, this._notifyVolumeChange));
148 this._icon.destroy();
149 this._icon = this.item.icon;
150 this._label.destroy();
151 this._label = this.item.label;
153 this.item.actor.connect('scroll-event', Lang.bind(this._slider, this._slider._onScrollEvent));