Skip to content

Commit

Permalink
Add sensitiveBind field to control component sensitive
Browse files Browse the repository at this point in the history
Redesign elements of the settings window
  • Loading branch information
Qwreey committed Oct 13, 2023
1 parent e9cfd14 commit be83347
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 78 deletions.
45 changes: 41 additions & 4 deletions src/libs/prefComponents.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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
}

Expand All @@ -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,
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
50 changes: 0 additions & 50 deletions src/prefPages/mediaControl.js

This file was deleted.

59 changes: 37 additions & 22 deletions src/prefPages/notifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { gettext as _ } from "resource:///org/gnome/Shell/Extensions/js/extensio

import {
baseGTypeName,
makeRow,
makeSwitch,
makeAdjustment,
makeDropdown
Expand All @@ -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'),
Expand All @@ -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)
}
})
2 changes: 0 additions & 2 deletions src/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -11,7 +10,6 @@ var pageList = [
volumeMixerPage,
inputOutputPage,
notificationsPage,
mediaControlPage,
quickTogglesPage,
otherPage,
aboutPage
Expand Down

0 comments on commit be83347

Please sign in to comment.