-
-
Save Moon-0xff/0678abbf7f87b5e7934d50a2e3cbdd5f to your computer and use it in GitHub Desktop.
Unfinished, uncommited mouse scroll code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/extension.js b/extension.js | |
index a349bfc..d44992b 100644 | |
--- a/extension.js | |
+++ b/extension.js | |
@@ -51,6 +51,7 @@ class MprisLabel extends PanelMenu.Button { | |
this.players = new Players(); | |
this.connect('button-press-event',(_a, event) => this._onClick(event)); | |
+ this.connect('scroll-event',(_a, event) => this._onScroll(event)); | |
this.settings.connect('changed::left-padding',this._onPaddingChanged.bind(this)); | |
this.settings.connect('changed::right-padding',this._onPaddingChanged.bind(this)); | |
@@ -135,6 +136,22 @@ class MprisLabel extends PanelMenu.Button { | |
} | |
} | |
+ _onScroll(event){ | |
+ switch(event.get_scroll_direction()){ | |
+ case Clutter.ScrollDirection.UP: | |
+ log("up!"); | |
+ this._activateButton('scroll-up-action'); | |
+ return Clutter.EVENT_STOP; | |
+ case Clutter.ScrollDirection.DOWN: | |
+ log("down!"); | |
+ this._activateButton('scroll-down-action'); | |
+ return Clutter.EVENT_STOP; | |
+ case Clutter.ScrollDirection.SMOOTH: | |
+ log("smooth!"); | |
+ return Clutter.EVENT_STOP; | |
+ } | |
+ } | |
+ | |
_activateButton(option) { | |
const value = this.settings.get_string(option); | |
@@ -159,6 +176,55 @@ class MprisLabel extends PanelMenu.Button { | |
this.player = this.players.next(); | |
this._refresh(); | |
break; | |
+ case 'volume-up': | |
+ log("volume up!"); | |
+ this._changeVolume(1); | |
+ break; | |
+ case 'volume-down': | |
+ log("volume down!"); | |
+ this._changeVolume(-1); | |
+ break; | |
+ } | |
+ } | |
+ | |
+ _changeVolume(delta){ | |
+ log("change volume!"); | |
+ if(!this.player) | |
+ return | |
+ | |
+ let CONTROL_SCHEME = this.settings.get_string('volume-control-scheme'); | |
+ | |
+ if(CONTROL_SCHEME == 'application'){ | |
+ let step = 0.03; | |
+ let max = 1; | |
+ let volume = this.player.getVolume(); | |
+ | |
+ let newVolume = volume + (step * delta); | |
+ | |
+ if(newVolume > 1) | |
+ newVolume = 1; | |
+ else if(newVolume < 0) | |
+ newVolume = 0; | |
+ | |
+ this.player.setVolume(newVolume); | |
+ } | |
+ else if(CONTROL_SCHEME == 'global'){ | |
+ const Volume = imports.ui.status.volume; | |
+ let mixer = Volume.getMixerControl(); | |
+ | |
+ let step = 0.03; | |
+ let max = 1; | |
+ let volume = mixer.get_default_sink().volume; | |
+ | |
+ let newVolume = volume + (step * delta); | |
+ | |
+ if(newVolume > 1) | |
+ newVolume = 1; | |
+ else if(newVolume < 0) | |
+ newVolume = 0; | |
+ | |
+ mixer.get_default_sink().volume = newVolume; | |
+ mixer.get_default_sink().push_volume(); | |
} | |
} | |
diff --git a/players.js b/players.js | |
index 5c2c21a..9e4a27a 100644 | |
--- a/players.js | |
+++ b/players.js | |
@@ -14,6 +14,7 @@ const mprisInterface = ` | |
<property name="CanGoPrevious" type="b" access="read" /> | |
<property name="Metadata" type="a{sv}" access="read"/> | |
<property name="PlaybackStatus" type="s" access="read"/> | |
+ <property name="Volume" type="d" access="readwrite"/> | |
</interface> | |
</node>` | |
@@ -242,5 +243,11 @@ class Player { | |
if (this.proxy.CanGoPrevious) | |
this.proxy.PreviousRemote() | |
} | |
+ getVolume(){ | |
+ return this.proxy.Volume; | |
+ } | |
+ setVolume(newVolume){ | |
+ this.proxy.Volume = newVolume; | |
+ } | |
} | |
diff --git a/prefs.js b/prefs.js | |
index 5aad19b..48723fe 100644 | |
--- a/prefs.js | |
+++ b/prefs.js | |
@@ -35,12 +35,6 @@ function buildPrefsWidget(){ | |
addSpinButton(panelPage,'reposition-delay','Panel reposition at startup (delay in seconds):',0,300,"Increase this value if extension index isn't respected at startup"); | |
addSwitch(panelPage,'reposition-on-button-press','Update panel position on every button press:',undefined); | |
- addSubcategoryLabel(panelPage,'Mouse controls'); | |
- let buttonActions = {'open menu':'open-menu','play/pause':'play-pause','next track':'next-track','previous track':'prev-track','next player':'next-player'}; | |
- let leftClickComboBox = addStringComboBox(panelPage,'left-click-action','Left click action:',buttonActions,undefined); | |
- let middleClickComboBox = addStringComboBox(panelPage,'middle-click-action','Middle click action:',buttonActions,undefined); | |
- let rightClickComboBox = addStringComboBox(panelPage,'right-click-action','Right click action:',buttonActions,undefined); | |
- | |
addButton(panelPage,'Reset panel settings', () => { | |
settings.reset('left-padding'); | |
settings.reset('right-padding'); | |
@@ -48,12 +42,6 @@ function buildPrefsWidget(){ | |
settings.reset('extension-place'); | |
settings.reset('reposition-delay'); | |
settings.reset('reposition-on-button-press'); | |
- settings.reset('left-click-action'); | |
- settings.reset('middle-click-action'); | |
- settings.reset('right-click-action'); | |
- leftClickComboBox.set_active_id(settings.get_string('left-click-action')); | |
- middleClickComboBox.set_active_id(settings.get_string('middle-click-action')); | |
- rightClickComboBox.set_active_id(settings.get_string('right-click-action')); | |
extensionPlaceComboBox.set_active_id(settings.get_string('extension-place')); | |
}); | |
@@ -197,6 +185,27 @@ function buildPrefsWidget(){ | |
prefsWidget.append_page(filtersPage, buildLabel('Filters')); | |
+//controls page: | |
+ let controlsPage = buildGrid(shellVersion,settings); | |
+ | |
+ position = 0; | |
+ | |
+ let buttonActions = {'open menu':'open-menu','play/pause':'play-pause','next track':'next-track','previous track':'prev-track','next player':'next-player'}; | |
+ let leftClickComboBox = addStringComboBox(controlsPage,'left-click-action','Left click action:',buttonActions,undefined); | |
+ let middleClickComboBox = addStringComboBox(controlsPage,'middle-click-action','Middle click action:',buttonActions,undefined); | |
+ let rightClickComboBox = addStringComboBox(controlsPage,'right-click-action','Right click action:',buttonActions,undefined); | |
+ | |
+ addButton(controlsPage,'Reset controls settings', () => { | |
+ settings.reset('left-click-action'); | |
+ settings.reset('middle-click-action'); | |
+ settings.reset('right-click-action'); | |
+ leftClickComboBox.set_active_id(settings.get_string('left-click-action')); | |
+ middleClickComboBox.set_active_id(settings.get_string('middle-click-action')); | |
+ rightClickComboBox.set_active_id(settings.get_string('right-click-action')); | |
+ }); | |
+ | |
+ prefsWidget.append_page(controlsPage, buildLabel('Controls')); | |
+ | |
return prefsWidget | |
} | |
diff --git a/schemas/gschemas.compiled b/schemas/gschemas.compiled | |
index a7bdff5..2ddec33 100644 | |
Binary files a/schemas/gschemas.compiled and b/schemas/gschemas.compiled differ | |
diff --git a/schemas/org.gnome.shell.extensions.mpris-label.gschema.xml b/schemas/org.gnome.shell.extensions.mpris-label.gschema.xml | |
index 529698f..34e042b 100644 | |
--- a/schemas/org.gnome.shell.extensions.mpris-label.gschema.xml | |
+++ b/schemas/org.gnome.shell.extensions.mpris-label.gschema.xml | |
@@ -98,5 +98,17 @@ | |
<default>"play-pause"</default> | |
</key> | |
+ <key name="volume-control-scheme" type="s"> | |
+ <default>"application"</default> | |
+ </key> | |
+ | |
+ <key name="scroll-up-action" type="s"> | |
+ <default>"volume-up"</default> | |
+ </key> | |
+ | |
+ <key name="scroll-down-action" type="s"> | |
+ <default>"volume-down"</default> | |
+ </key> | |
+ | |
</schema> | |
</schemalist> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment