Skip to content

Commit

Permalink
Support gnome 45
Browse files Browse the repository at this point in the history
  • Loading branch information
thjxs committed Oct 25, 2023
1 parent 2705ea8 commit 9990c0f
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 126 deletions.
114 changes: 38 additions & 76 deletions [email protected]/extension.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
const Clutter = imports.gi.Clutter;
const Gio = imports.gi.Gio;
const Main = imports.ui.main;
const Volume = imports.ui.status.volume;
const ExtensionUtils = imports.misc.extensionUtils;

let volume_scroller = null;

const VolumeScrollerIcons =
[
'audio-volume-muted-symbolic',
'audio-volume-low-symbolic',
'audio-volume-medium-symbolic',
'audio-volume-high-symbolic'
import Clutter from "gi://Clutter";
import Gio from "gi://Gio";
import * as Main from "resource:///org/gnome/shell/ui/main.js";
import * as Volume from "resource:///org/gnome/shell/ui/status/volume.js";
import { Extension } from "resource:///org/gnome/shell/extensions/extension.js";

const VolumeScrollerIcons = [
"audio-volume-muted-symbolic",
"audio-volume-low-symbolic",
"audio-volume-medium-symbolic",
"audio-volume-high-symbolic",
];

class VolumeScroller
{
constructor()
{
this.settings = ExtensionUtils.getSettings(
'org.gnome.shell.extensions.volume-scroller');
export default class VolumeScrollerExtension extends Extension {
enable() {
this.settings = this.getSettings(
"org.gnome.shell.extensions.volume-scroller"
);
const setGranularity = () => {
this.volume_granularity = this.settings.get_int('granularity') / 100.0;
this.volume_granularity = this.settings.get_int("granularity") / 100.0;
};

this.controller = Volume.getMixerControl();
Expand All @@ -36,49 +32,36 @@ class VolumeScroller
this.scroll_binding = null;
this.sink_binding = null;

this.settings.connect('changed::granularity', setGranularity);
}

enable()
{
if (this.enabled)
{
this.disable();
}
this.settings.connect("changed::granularity", setGranularity);

this.enabled = true;
this.sink = this.controller.get_default_sink();

this.scroll_binding = this.panel.connect(
'scroll-event',
(actor, event) => this._handle_scroll(actor, event));
this.scroll_binding = this.panel.connect("scroll-event", (actor, event) =>
this._handle_scroll(actor, event)
);

this.sink_binding = this.controller.connect(
'default-sink-changed',
(controller, id) => this._handle_sink_change(controller, id));
"default-sink-changed",
(controller, id) => this._handle_sink_change(controller, id)
);
}

disable()
{
if (this.enabled)
{
this.enabled = false;
this.sink = null;
disable() {
this.enabled = false;
this.sink = null;

this.panel.disconnect(this.scroll_binding);
this.scroll_binding = null;
this.panel.disconnect(this.scroll_binding);
this.scroll_binding = null;

this.controller.disconnect(this.sink_binding);
this.sink_binding = null;
}
this.controller.disconnect(this.sink_binding);
this.sink_binding = null;
}

_handle_scroll(actor, event)
{
_handle_scroll(actor, event) {
let volume = this.sink.volume;

switch (event.get_scroll_direction())
{
switch (event.get_scroll_direction()) {
case Clutter.ScrollDirection.UP:
volume += this._get_step();
break;
Expand All @@ -102,22 +85,17 @@ class VolumeScroller
return Clutter.EVENT_STOP;
}

_handle_sink_change(controller, id)
{
_handle_sink_change(controller, id) {
this.sink = controller.lookup_stream_id(id);
}

_show_volume(volume)
{
_show_volume(volume) {
const percentage = volume / this.volume_max;
let n;

if (volume === 0)
{
if (volume === 0) {
n = 0;
}
else
{
} else {
n = parseInt(3 * percentage + 1);
n = Math.max(1, n);
n = Math.min(3, n);
Expand All @@ -130,23 +108,7 @@ class VolumeScroller
Main.osdWindowManager.show(monitor, icon, label, percentage);
}

_get_step()
{
_get_step() {
return this.volume_max * this.volume_granularity;
}
};

function enable()
{
volume_scroller = new VolumeScroller();
volume_scroller.enable();
}

function disable()
{
if (volume_scroller !== null)
{
volume_scroller.disable();
volume_scroller = null;
}
}
8 changes: 1 addition & 7 deletions [email protected]/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@
"original-author": "francislavoie",
"description": "Scroll up or down in the Top Bar to adjust volume.",
"shell-version": [
"3.36",
"3.38",
"40",
"41",
"42",
"43",
"44"
"45"
],
"url": "https://github.com/francislavoie/gnome-shell-volume-scroller",
"uuid": "[email protected]",
Expand Down
85 changes: 42 additions & 43 deletions [email protected]/prefs.js
Original file line number Diff line number Diff line change
@@ -1,44 +1,43 @@
const { Adw, Gio, Gtk } = imports.gi;

const ExtensionUtils = imports.misc.extensionUtils;
const Me = ExtensionUtils.getCurrentExtension();


function init() {
import Adw from 'gi://Adw';
import Gio from 'gi://Gio';
import Gtk from 'gi://Gtk';

import {ExtensionPreferences} from 'resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js';

export default class VolumeScrollerExtensionPreferences extends ExtensionPreferences {

fillPreferencesWindow(window) {
// Use the same GSettings schema as in `extension.js`
window._settings = this.getSettings('org.gnome.shell.extensions.volume-scroller')

// Create a preferences page and group
const page = new Adw.PreferencesPage();
const group = new Adw.PreferencesGroup();
page.add(group);

// Create a new preferences row
const row = new Adw.ActionRow({ title: 'Granularity' });
group.add(row);

// Create the value picker
const granularityEntry = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({ step_increment: 1, lower: 1, upper: 50 }),
value: window._settings.get_int('granularity'),
valign: Gtk.Align.CENTER,
halign: Gtk.Align.CENTER,
});
window._settings.bind(
'granularity',
granularityEntry,
'value',
Gio.SettingsBindFlags.DEFAULT
);

// Add the value picker to the row
row.add_suffix(granularityEntry);
row.activatable_widget = granularityEntry;

// Add our page to the window
window.add(page);
}
}

function fillPreferencesWindow(window) {
// Use the same GSettings schema as in `extension.js`
const settings = ExtensionUtils.getSettings(
'org.gnome.shell.extensions.volume-scroller');

// Create a preferences page and group
const page = new Adw.PreferencesPage();
const group = new Adw.PreferencesGroup();
page.add(group);

// Create a new preferences row
const row = new Adw.ActionRow({ title: 'Granularity' });
group.add(row);

// Create the value picker
const granularityEntry = new Gtk.SpinButton({
adjustment: new Gtk.Adjustment({ step_increment: 1, lower: 1, upper: 50 }),
value: settings.get_int('granularity'),
valign: Gtk.Align.CENTER,
halign: Gtk.Align.CENTER,
});
settings.bind(
'granularity',
granularityEntry,
'value',
Gio.SettingsBindFlags.DEFAULT
);

// Add the value picker to the row
row.add_suffix(granularityEntry);
row.activatable_widget = granularityEntry;

// Add our page to the window
window.add(page);
}

0 comments on commit 9990c0f

Please sign in to comment.