From be83347f258b45153b7094a1d3d4291e33b655f1 Mon Sep 17 00:00:00 2001 From: Qwreey Date: Sat, 14 Oct 2023 07:24:11 +0900 Subject: [PATCH] Add sensitiveBind field to control component sensitive Redesign elements of the settings window --- src/libs/prefComponents.js | 45 +++++++++++++++++++++++--- src/prefPages/mediaControl.js | 50 ---------------------------- src/prefPages/notifications.js | 59 +++++++++++++++++++++------------- src/prefs.js | 2 -- 4 files changed, 78 insertions(+), 78 deletions(-) delete mode 100644 src/prefPages/mediaControl.js diff --git a/src/libs/prefComponents.js b/src/libs/prefComponents.js index 88c1228..8c283ad 100644 --- a/src/libs/prefComponents.js +++ b/src/libs/prefComponents.js @@ -6,7 +6,7 @@ import GObject from "gi://GObject" export const baseGTypeName = "qwreey.quick-settings-tweaks.prefs." -export function makeRow(options={parent: null,title: null, subtitle: null,uri: null}) { +export function makeRow(options={parent: null,title: null, subtitle: null,uri: null, sensitiveBind: null}) { const row = new Adw.ActionRow({ title: options.title, subtitle: options.subtitle || null @@ -31,10 +31,18 @@ export function makeRow(options={parent: null,title: null, subtitle: null,uri: n if (options.prefix) { row.add_prefix(options.prefix) } + if (options.sensitiveBind) { + options.sensitiveBind[0].bind( + options.sensitiveBind[1], + row,'sensitive', + Gio.SettingsBindFlags.DEFAULT + ) + row.sensitive = options.sensitiveBind[0].get_boolean(options.sensitiveBind[1]) + } return row } -export function makeSwitch(options={bind: null,parent: null,value: false,title: "default",subtitle: null,action: null}) { +export function makeSwitch(options={bind: null,parent: null,value: false,title: "default",subtitle: null,action: null,sensitiveBind:null}) { const row = new Adw.SwitchRow({ title: options.title, subtitle: options.subtitle || null, @@ -59,6 +67,15 @@ export function makeSwitch(options={bind: null,parent: null,value: false,title: ) } + if (options.sensitiveBind) { + options.sensitiveBind[0].bind( + options.sensitiveBind[1], + row,'sensitive', + Gio.SettingsBindFlags.DEFAULT + ) + row.sensitive = options.sensitiveBind[0].get_boolean(options.sensitiveBind[1]) + } + return row } @@ -71,7 +88,8 @@ export function makeAdjustment(options={ value: 1, title: "default", subtitle: null, - action: null + action: null, + sensitiveBind: null, }) { const row = new Adw.SpinRow({ title: options.title, @@ -101,6 +119,15 @@ export function makeAdjustment(options={ ) } + if (options.sensitiveBind) { + options.sensitiveBind[0].bind( + options.sensitiveBind[1], + row,'sensitive', + Gio.SettingsBindFlags.DEFAULT + ) + row.sensitive = options.sensitiveBind[0].get_boolean(options.sensitiveBind[1]) + } + return row } @@ -128,7 +155,8 @@ export function makeDropdown(options={ title: "default", subtitle: null, action: null, - type: null + type: null, + sensitiveBind: null, }) { let filterModeModel = new Gio.ListStore({ item_type: DropdownItems }) for (const item of options.items) { @@ -167,5 +195,14 @@ export function makeDropdown(options={ }) } + if (options.sensitiveBind) { + options.sensitiveBind[0].bind( + options.sensitiveBind[1], + filterModeRow,'sensitive', + Gio.SettingsBindFlags.DEFAULT + ) + filterModeRow.sensitive = options.sensitiveBind[0].get_boolean(options.sensitiveBind[1]) + } + return filterModeRow } diff --git a/src/prefPages/mediaControl.js b/src/prefPages/mediaControl.js deleted file mode 100644 index e823e7e..0000000 --- a/src/prefPages/mediaControl.js +++ /dev/null @@ -1,50 +0,0 @@ -import Adw from "gi://Adw" -import GObject from "gi://GObject" - -import { gettext as _ } from "resource:///org/gnome/Shell/Extensions/js/extensions/prefs.js" - -import { - baseGTypeName, - makeRow, - makeSwitch -} from "../libs/prefComponents.js" - -export const mediaControlPage = GObject.registerClass({ - GTypeName: baseGTypeName+'mediaControlPage', -}, class mediaControlPage extends Adw.PreferencesPage { - constructor(settings) { - // group config - super({ - name: 'mediaControl', - title: _('Media Controls'), - iconName: 'folder-music-symbolic' - }) - - // description / enable - const descriptionGroup = new Adw.PreferencesGroup() - makeRow({ - parent: descriptionGroup, - title: _("Add Media Controls widget"), - subtitle: _("Reference from https://github.com/Aylur/gnome-extensions\nSource code of that is not used on this extension") - }) - makeSwitch({ - parent: descriptionGroup, - title: _("Visible"), - subtitle: _("Turn on to make the Media Control widget visible on the Quick Settings panel"), - value: settings.get_boolean("media-control-enabled"), - bind: [settings, "media-control-enabled"] - }) - this.add(descriptionGroup) - - // general - const generalGroup = new Adw.PreferencesGroup({ title: _("General") }) - this.add(generalGroup) - makeSwitch({ - parent: generalGroup, - title: _("Compact Mode"), - subtitle: _("Make Media Controls widget smaller\nMake it more similar in size to the notification message"), - value: settings.get_boolean("media-control-compact-mode"), - bind: [settings, "media-control-compact-mode"] - }) - } -}) \ No newline at end of file diff --git a/src/prefPages/notifications.js b/src/prefPages/notifications.js index 2a14329..ec402d0 100644 --- a/src/prefPages/notifications.js +++ b/src/prefPages/notifications.js @@ -5,7 +5,6 @@ import { gettext as _ } from "resource:///org/gnome/Shell/Extensions/js/extensio import { baseGTypeName, - makeRow, makeSwitch, makeAdjustment, makeDropdown @@ -18,39 +17,50 @@ export const notificationsPage = GObject.registerClass({ // group config super({ name: 'notifications', - title: _('Notifications'), + title: _('Noti&Media'), iconName: 'user-available-symbolic', }) - // description / enable - const descriptionGroup = new Adw.PreferencesGroup() - makeRow({ - parent: descriptionGroup, - title: _("Add notifications widget"), - subtitle: _("Reference from https://github.com/Aylur/gnome-extensions\nSource code of that is not used on this extension"), + // media + const mediaGroup = new Adw.PreferencesGroup({ + title: "Media Controls widget", + headerSuffix: makeSwitch({ + parent: descriptionGroup, + value: settings.get_boolean("media-control-enabled"), + bind: [settings, "media-control-enabled"] + }), + description: _("Turn on to make the Media Control widget visible on the Quick Settings panel\nReference from https://github.com/Aylur/gnome-extensions\nSource code of that is not used on this extension"), }) makeSwitch({ - parent: descriptionGroup, - title: _("Visible"), - subtitle: _("Turn on to make the notification widget visible on the Quick Settings panel"), - value: settings.get_boolean("notifications-enabled"), - bind: [settings, "notifications-enabled"], + parent: mediaGroup, + title: _("Compact Mode"), + subtitle: _("Make Media Controls widget smaller\nMake it more similar in size to the notification message"), + value: settings.get_boolean("media-control-compact-mode"), + bind: [settings, "media-control-compact-mode"], + sensitiveBind: [settings, "media-control-enabled"], }) - this.add(descriptionGroup) + this.add(mediaGroup) - // general - const generalGroup = new Adw.PreferencesGroup({ title: _("General") }) - this.add(generalGroup) + // notification + const notificationGroup = new Adw.PreferencesGroup({ + title: _("Notification Widget"), + headerSuffix: makeSwitch({ + value: settings.get_boolean("notifications-enabled"), + bind: [settings, "notifications-enabled"], + }), + description: _("Turn on to make the notification widget visible on the Quick Settings panel\nReference from https://github.com/Aylur/gnome-extensions\nSource code of that is not used on this extension"), + }) makeAdjustment({ - parent: generalGroup, + parent: notificationGroup, max: 1280, title: _("Max height"), subtitle: _("Set maximum height of the Notifications widget. default is 292"), value: settings.get_int("notifications-max-height"), bind: [settings, "notifications-max-height"], + sensitiveBind: [settings, "notifications-enabled"], }) makeDropdown({ - parent: generalGroup, + parent: notificationGroup, title: _("Position"), subtitle: _("Set Notifications widget position"), value: settings.get_string('notifications-position'), @@ -60,27 +70,32 @@ export const notificationsPage = GObject.registerClass({ {name: _("Top"), value: "top"}, {name: _("Bottom"), value: "bottom"}, ], + sensitiveBind: [settings, "notifications-enabled"], }) makeSwitch({ - parent: generalGroup, + parent: notificationGroup, title: _("Attach to QS panel"), subtitle: _("Do not separate Quick Settings and Notifications widgets, \byou should enable this option because separated panels can make many visual bugs\n(such as margin or padding not matching with the theme)"), value: settings.get_boolean("notifications-integrated"), bind: [settings, "notifications-integrated"], + sensitiveBind: [settings, "notifications-enabled"], }) makeSwitch({ - parent: generalGroup, + parent: notificationGroup, title: _("Auto Hide"), subtitle: _("Hide the Notifications widget when have no notifications"), value: settings.get_boolean("notifications-hide-when-no-notifications"), bind: [settings, "notifications-hide-when-no-notifications"], + sensitiveBind: [settings, "notifications-enabled"], }) makeSwitch({ - parent: generalGroup, + parent: notificationGroup, title: _("Use native controls"), subtitle: _("Use native dnd switch and clear button"), value: settings.get_boolean("notifications-use-native-controls"), bind: [settings, "notifications-use-native-controls"], + sensitiveBind: [settings, "notifications-enabled"], }) + this.add(descriptionGroup) } }) diff --git a/src/prefs.js b/src/prefs.js index 1d4f79d..d4e588b 100644 --- a/src/prefs.js +++ b/src/prefs.js @@ -2,7 +2,6 @@ import { ExtensionPreferences } from "resource:///org/gnome/Shell/Extensions/js/ import { volumeMixerPage } from "./prefPages/volumeMixer.js" import { inputOutputPage } from "./prefPages/inputOutput.js" import { notificationsPage } from "./prefPages/notifications.js" -import { mediaControlPage } from "./prefPages/mediaControl.js" import { quickTogglesPage } from "./prefPages/quickToggles.js" import { otherPage } from "./prefPages/other.js" import { aboutPage } from "./prefPages/about.js" @@ -11,7 +10,6 @@ var pageList = [ volumeMixerPage, inputOutputPage, notificationsPage, - mediaControlPage, quickTogglesPage, otherPage, aboutPage