Skip to content

Commit

Permalink
Added reset-to-default buttons to prefs. Also:
Browse files Browse the repository at this point in the history
1) Fixed app icon having wrong y coordinate when 'offset' has non-zero
value.
2) Finer control of most range sliders in prefs.
  • Loading branch information
dsheeler committed Dec 24, 2022
1 parent a6d48de commit 9afa7c7
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 27 deletions.
31 changes: 17 additions & 14 deletions [email protected]/keybinder.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,23 +67,26 @@ var Keybinder330Api = class Keybinder330Api extends AbstractKeybinder {
Main.wm.setCustomKeybindingHandler('switch-group-backward', mode.NORMAL, Main.wm._startSwitcher.bind(Main.wm));
}

_onSettingsChanged(settings) {
_onSettingsChanged(settings, key=null) {
let Shell = imports.gi.Shell;
let mode = Shell.ActionMode ? Shell.ActionMode : Shell.KeyBindingMode;
if (settings.get_boolean('bind-to-switch-applications')) {
Main.wm.setCustomKeybindingHandler('switch-applications', mode.NORMAL, this._startAppSwitcherBind);
Main.wm.setCustomKeybindingHandler('switch-applications-backward', mode.NORMAL, this._startAppSwitcherBind);
} else {
Main.wm.setCustomKeybindingHandler('switch-applications', mode.NORMAL, Main.wm._startSwitcher.bind(Main.wm));
Main.wm.setCustomKeybindingHandler('switch-applications-backward', mode.NORMAL, Main.wm._startSwitcher.bind(Main.wm));
if (key == null || key == 'bind-to-switch-applications') {
if (settings.get_boolean('bind-to-switch-applications')) {
Main.wm.setCustomKeybindingHandler('switch-applications', mode.NORMAL, this._startAppSwitcherBind);
Main.wm.setCustomKeybindingHandler('switch-applications-backward', mode.NORMAL, this._startAppSwitcherBind);
} else {
Main.wm.setCustomKeybindingHandler('switch-applications', mode.NORMAL, Main.wm._startSwitcher.bind(Main.wm));
Main.wm.setCustomKeybindingHandler('switch-applications-backward', mode.NORMAL, Main.wm._startSwitcher.bind(Main.wm));
}
}
if (settings.get_boolean('bind-to-switch-windows')) {
log("binding to switch windows");
Main.wm.setCustomKeybindingHandler('switch-windows', mode.NORMAL, this._startAppSwitcherBind);
Main.wm.setCustomKeybindingHandler('switch-windows-backward', mode.NORMAL, this._startAppSwitcherBind);
} else {
Main.wm.setCustomKeybindingHandler('switch-windows', mode.NORMAL, Main.wm._startSwitcher.bind(Main.wm));
Main.wm.setCustomKeybindingHandler('switch-windows-backward', mode.NORMAL, Main.wm._startSwitcher.bind(Main.wm));
if (key == null || key == 'bind-to-switch-windows') {
if (settings.get_boolean('bind-to-switch-windows')) {
Main.wm.setCustomKeybindingHandler('switch-windows', mode.NORMAL, this._startAppSwitcherBind);
Main.wm.setCustomKeybindingHandler('switch-windows-backward', mode.NORMAL, this._startAppSwitcherBind);
} else {
Main.wm.setCustomKeybindingHandler('switch-windows', mode.NORMAL, Main.wm._startSwitcher.bind(Main.wm));
Main.wm.setCustomKeybindingHandler('switch-windows-backward', mode.NORMAL, Main.wm._startSwitcher.bind(Main.wm));
}
}
}
}
9 changes: 5 additions & 4 deletions [email protected]/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ var PlatformGnomeShell = class PlatformGnomeShell extends AbstractPlatform {
}

enable() {
this.disable();
//this.disable();

this._settings_changed_callbacks = [];

Expand Down Expand Up @@ -198,13 +198,14 @@ var PlatformGnomeShell = class PlatformGnomeShell extends AbstractPlatform {
];

this._connections = [];
let bind = this._onSettingsChanged.bind(this);
for (let key of keys) {
let bind = this._onSettingsChanged.bind(this, key);
this._connections.push(this._extensionSettings.connect('changed::' + key, bind));
}

this._dconnections = [];
for (let dkey of dkeys) {
let bind = this._onSettingsChanged.bind(this, dkey);
this._dconnections.push(this._desktopSettings.connect('changed::' + dkey, bind));
}

Expand Down Expand Up @@ -250,10 +251,10 @@ var PlatformGnomeShell = class PlatformGnomeShell extends AbstractPlatform {
this._settings_changed_callbacks.push(cb);
}

_onSettingsChanged() {
_onSettingsChanged(key) {
this._settings = null;
for (let cb of this._settings_changed_callbacks) {
cb(this._extensionSettings);
cb(this._extensionSettings, key);
}
}

Expand Down
70 changes: 62 additions & 8 deletions [email protected]/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
* Preferences dialog for "gnome-extensions prefs" tool
*
* Based on JustPerfection & dash2doc-lite
* Based on preferences in the following extensions: JustPerfection, dash2doc-lite, and desktop cube
*
*/
const { Adw, Gdk, GLib, Gtk } = imports.gi;
Expand Down Expand Up @@ -125,6 +125,14 @@ function getBaseString(translatedString) {
}
}

function makeResetButton() {
return new Gtk.Button({
icon_name: "edit-clear-symbolic",
tooltip_text: _("Reset to default value"),
valign: Gtk.Align.CENTER,
});
}

function fillPreferencesWindow(window) {
let general_page = new Adw.PreferencesPage({
title: _('General'),
Expand Down Expand Up @@ -209,19 +217,19 @@ function fillPreferencesWindow(window) {
});
icon_pref_group.add(buildRadioAdw("icon-style", [_("Classic"), _("Overlay")], _("Application Icon Style")));
icon_pref_group.add(buildRangeAdw("overlay-icon-size", [0, 1024, 1, [32, 64, 128, 256, 512]], _("Overlay Icon Size"), _("Set the overlay icon size in pixels."), true));
icon_pref_group.add(buildRangeAdw("overlay-icon-opacity", [0, 1, 0.01, [0.25, 0.5, 0.75]], _("Overlay Icon Opacity"), _("Set the overlay icon opacity."), true));
icon_pref_group.add(buildRangeAdw("overlay-icon-opacity", [0, 1, 0.001, [0.25, 0.5, 0.75]], _("Overlay Icon Opacity"), _("Set the overlay icon opacity."), true));
icon_pref_group.add(buildSwitcherAdw("icon-has-shadow", _("Draw Icon with a Shadow")));

let window_pref_group = new Adw.PreferencesGroup({
title: _("Window Size")
});
window_pref_group.add(buildRangeAdw("preview-to-monitor-ratio", [0, 1, 0.01, [0.250, 0.500, 0.750]], _("Preview to Monintor Ratio"), _("Maximum ratio of preview to monitor size."), true));
window_pref_group.add(buildRangeAdw("preview-scaling-factor", [0, 1, 0.01, [0.250, 0.500, 0.800]], _("Off-center Size Factor"), _("Factor by which to shrink previews off to the sides."), true));
window_pref_group.add(buildRangeAdw("preview-to-monitor-ratio", [0, 1, 0.001, [0.250, 0.500, 0.750]], _("Preview to Monintor Ratio"), _("Maximum ratio of preview to monitor size."), true));
window_pref_group.add(buildRangeAdw("preview-scaling-factor", [0, 1, 0.001, [0.250, 0.500, 0.800]], _("Off-center Size Factor"), _("Factor by which to shrink previews off to the sides."), true));

let background_pref_group = new Adw.PreferencesGroup({
title: _('Background'),
});
background_pref_group.add(buildRangeAdw("dim-factor", [0, 1, 0.01, [0.25, 0.5, 0.75]], _("Background Dim-factor"), _("Smaller means darker.")));
background_pref_group.add(buildRangeAdw("dim-factor", [0, 1, 0.001, [0.25, 0.5, 0.75]], _("Background Dim-factor"), _("Smaller means darker.")));

appearance_page.add(icon_pref_group);
appearance_page.add(window_pref_group);
Expand Down Expand Up @@ -254,6 +262,13 @@ function buildSwitcherAdw(key, title, subtitle=null) {

pref.set_activatable_widget(switcher);
pref.add_suffix(switcher);

reset_button = makeResetButton();
reset_button.connect("clicked", function(widget) {
settings.reset(key);
switcher.set_active(settings.get_boolean(key));
})
pref.add_suffix(reset_button);
return pref;
}

Expand All @@ -278,13 +293,18 @@ function buildRangeAdw(key, values, title, subtitle=null, draw_value=false) {
range.set_size_request(200, -1);

range.connect('value-changed', function(slider) {
log(key, slider.get_value());
settings.set_double(key, slider.get_value());
});

pref.set_activatable_widget(range);
pref.add_suffix(range)

reset_button = makeResetButton();
reset_button.connect("clicked", function(widget) {
settings.reset(key);
range.set_value(settings.get_double(key));
});
pref.add_suffix(reset_button);
return pref;
}

Expand All @@ -303,12 +323,13 @@ function buildRadioAdw(key, buttons, title, subtitle=null) {

let radio = new Gtk.ToggleButton();

let radio_for_button = {};
for (let button of buttons) {
radio = new Gtk.ToggleButton({group: radio, label: button});
if (getBaseString(button) == settings.get_string(key)) {
radio.set_active(true);
}

radio_for_button[button] = radio;
radio.connect('toggled', function(widget) {
if (widget.get_active()) {
settings.set_string(key, getBaseString(widget.get_label()));
Expand All @@ -317,8 +338,20 @@ function buildRadioAdw(key, buttons, title, subtitle=null) {

hbox.append(radio);
};

reset_button = makeResetButton();
reset_button.connect("clicked", function(widget) {
settings.reset(key);
for (let button of buttons) {
if (getBaseString(button) == settings.get_string(key)) {
radio_for_button[button].set_active(true);
}
}
});

pref.set_activatable_widget(hbox);
pref.add_suffix(hbox);
pref.add_suffix(reset_button);
return pref;
};

Expand All @@ -341,6 +374,15 @@ function buildSpinAdw(key, values, title, subtitle=null) {

pref.set_activatable_widget(spin);
pref.add_suffix(spin);

reset_button = makeResetButton();
reset_button.connect("clicked", function(widget) {
settings.reset(key);
spin.set_value(settings.get_int(key));
});

pref.add_suffix(reset_button);

return pref;
}

Expand Down Expand Up @@ -368,11 +410,23 @@ function buildDropDownAdw(key, values, title, subtitle=null) {
});
chooser.connect('notify::selected-item', function(c) {
let idx = c.get_selected();
print(key, values[idx].id);
settings.set_string(key, values[idx].id);
});
pref.set_activatable_widget(chooser);
pref.add_suffix(chooser);

reset_button = makeResetButton();
reset_button.connect("clicked", function(widget) {
settings.reset(key);
for (let i = 0; i < values.length; i++) {
let item = values[i];
if (item.id == settings.get_string(key)) {
chooser.set_selected(i);
break;
}
}
});
pref.add_suffix(reset_button);
return pref;
}

Expand Down
2 changes: 1 addition & 1 deletion [email protected]/switcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ var Switcher = class Switcher {
height: app_icon_size * 1.25,
opacity: (initially_opaque ? 255 * this._settings.overlay_icon_opacity : 0),
x: (monitor.width - app_icon_size * 1.25) / 2,
y: (monitor.height - app_icon_size * 1.25) / 2,
y: (monitor.height - app_icon_size * 1.25) / 2 + this._settings.offset,
});
}

Expand Down

0 comments on commit 9afa7c7

Please sign in to comment.