Skip to content

Commit

Permalink
Revert latest PR & Add "Invert Direction" setting in the extension se…
Browse files Browse the repository at this point in the history
…ttings. (#10)

Co-authored-by: Francis Lavoie <[email protected]>
  • Loading branch information
salihefee and francislavoie authored Apr 1, 2024
1 parent c9e28b0 commit d789e3e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
17 changes: 8 additions & 9 deletions [email protected]/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export default class VolumeScrollerExtension extends Extension {
this.volume_granularity = this.settings.get_int("granularity") / 100.0;
};

const setDirection = () => {
this.direction = this.settings.get_boolean("invert-scroll");
}

this.controller = Volume.getMixerControl();
this.panel = Main.panel;

Expand All @@ -26,11 +30,13 @@ export default class VolumeScrollerExtension extends Extension {

this.volume_max = this.controller.get_vol_max_norm();
setGranularity();
setDirection();

this.scroll_binding = null;
this.sink_binding = null;

this.settings.connect("changed::granularity", setGranularity);
this.settings.connect("changed::invert-scroll", setDirection);

this.enabled = true;
this.sink = this.controller.get_default_sink();
Expand Down Expand Up @@ -62,15 +68,8 @@ export default class VolumeScrollerExtension extends Extension {
_handle_scroll(_actor, event) {
let volume = this.sink.volume;

const settings = new Gio.Settings({
schema_id: "org.gnome.desktop.peripherals.touchpad",
});

const naturalScroll = settings.get_boolean("natural-scroll");
const multiplier = naturalScroll ? -1 : 1;

const scrollDirection = event.get_scroll_direction();
switch (scrollDirection) {
const multiplier = this.direction ? -1 : 1;
switch (event.get_scroll_direction()) {
case Clutter.ScrollDirection.UP:
volume += this._get_step() * multiplier;
break;
Expand Down
34 changes: 28 additions & 6 deletions [email protected]/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ export default class VolumeScrollerExtensionPreferences extends ExtensionPrefere
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 preference rows
const granularityRow = new Adw.ActionRow({ title: 'Granularity' });
const invertScrollRow = new Adw.ActionRow({ title: 'Invert Scroll' });
group.add(granularityRow);
group.add(invertScrollRow);

// Create the value picker
const granularityEntry = new Gtk.SpinButton({
Expand All @@ -24,16 +26,36 @@ export default class VolumeScrollerExtensionPreferences extends ExtensionPrefere
valign: Gtk.Align.CENTER,
halign: Gtk.Align.CENTER,
});

// Create the direction switch
const invertScrollSwitch = new Gtk.Switch({
active: window._settings.get_boolean('invert-scroll'),
valign: Gtk.Align.CENTER,
halign: Gtk.Align.CENTER,
});

// Bind the settings
window._settings.bind(
'granularity',
granularityEntry,
'value',
Gio.SettingsBindFlags.DEFAULT
);

window._settings.bind(
'invert-scroll',
invertScrollSwitch,
'active',
Gio.SettingsBindFlags.DEFAULT
);

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

// Add the value picker to the row
row.add_suffix(granularityEntry);
row.activatable_widget = granularityEntry;
// Add the direction switch to the row
invertScrollRow.add_suffix(invertScrollSwitch);
invertScrollRow.activatable_widget = invertScrollSwitch;

// Add our page to the window
window.add(page);
Expand Down
Binary file modified [email protected]/schemas/gschemas.compiled
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@
<summary>Granularity</summary>
<description>How many percentage points to increase or decrease the volume on each scroll tick.</description>
</key>
<key name="invert-scroll" type="b">
<default>false</default>
<summary>Invert Direction</summary>
<description>Scrolling up decreases the volume, scrolling down increases it.</description>
</key>
</schema>
</schemalist>

0 comments on commit d789e3e

Please sign in to comment.