Skip to content
This repository was archived by the owner on Nov 2, 2020. It is now read-only.

Commit

Permalink
Merge pull request #27 from TimurKiyivinski/brightness-lock
Browse files Browse the repository at this point in the history
feat(indicator): sync with brightness slider
  • Loading branch information
kiyui authored May 13, 2018
2 parents 8af8698 + 664a0a6 commit a5d5ce9
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 6 deletions.
10 changes: 9 additions & 1 deletion [email protected]/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const NightLightSlider = new Lang.Class({
this._schema.set_uint('night-light-temperature', temperature)

this._listeners.forEach(callback => {
callback(temperature)
callback(temperature, value)
})
},
_onSliderChanged: function (callback) {
Expand Down Expand Up @@ -203,6 +203,14 @@ const NightLightExtension = new Lang.Class({
// Update view once on init
updateView()
})

// Event hooks
this._indicator._onSliderChanged((temperature, value) => {
// Set up night light to sync with brightness if changed
if (settings.get_boolean('brightness-sync')) {
Main.panel.statusArea.aggregateMenu._brightness._slider.emit('value-changed', value)
}
})
},
disable: function () {
// Run deconstruct function
Expand Down
31 changes: 26 additions & 5 deletions [email protected]/prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ function buildPrefsWidget () { // eslint-disable-line no-unused-vars
const minimumDescription = schema.settings_schema.get_key('minimum').get_description()
const maximumName = schema.settings_schema.get_key('maximum').get_summary()
const maximumDescription = schema.settings_schema.get_key('maximum').get_description()
const brightnessSyncName = schema.settings_schema.get_key('brightness-sync').get_summary()
const brightnessSyncDescription = schema.settings_schema.get_key('brightness-sync').get_description()

// Create children objects
const widgets = [
Expand Down Expand Up @@ -80,19 +82,38 @@ function buildPrefsWidget () { // eslint-disable-line no-unused-vars
}
}
},
{
type: 'Label',
params: { label: `${brightnessSyncName}: ` },
tooltip: brightnessSyncDescription,
align: Gtk.Align.END,
attach: [0, 4, 1, 1]
},
{
type: 'Switch',
params: { active: schema.get_boolean('brightness-sync') },
tooltip: brightnessSyncDescription,
align: Gtk.Align.START,
attach: [1, 4, 1, 1],
connect: {
'state-set': self => {
schema.set_boolean('brightness-sync', self.active)
}
}
},
{
type: 'Label',
params: { label: `${minimumName}: ` },
tooltip: minimumDescription,
align: Gtk.Align.END,
attach: [0, 4, 1, 1]
attach: [0, 5, 1, 1]
},
{
type: 'Entry',
params: { text: schema.get_int('minimum').toString() },
tooltip: minimumDescription,
align: Gtk.Align.START,
attach: [1, 4, 1, 1],
attach: [1, 5, 1, 1],
connect: {
'changed': self => {
schema.set_int('minimum', parseInt(self.text))
Expand All @@ -104,14 +125,14 @@ function buildPrefsWidget () { // eslint-disable-line no-unused-vars
params: { label: `${maximumName}: ` },
tooltip: maximumDescription,
align: Gtk.Align.END,
attach: [0, 5, 1, 1]
attach: [0, 6, 1, 1]
},
{
type: 'Entry',
params: { text: schema.get_int('maximum').toString() },
tooltip: maximumDescription,
align: Gtk.Align.START,
attach: [1, 5, 1, 1],
attach: [1, 6, 1, 1],
connect: {
'changed': self => {
schema.set_int('maximum', parseInt(self.text))
Expand All @@ -123,7 +144,7 @@ function buildPrefsWidget () { // eslint-disable-line no-unused-vars
params: { label: 'Changes require restarting shell (logging in and out) to take place.' },
tooltip: showAlwaysDescription,
align: Gtk.Align.CENTER,
attach: [0, 6, 2, 1]
attach: [0, 7, 2, 1]
}
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,10 @@
<summary>Maximum value</summary>
<description>Maximum night light slider value</description>
</key>
<key name="brightness-sync" type="b">
<default>false</default>
<summary>Brightness sync</summary>
<description>Sync brightness slider with night light slider</description>
</key>
</schema>
</schemalist>

0 comments on commit a5d5ce9

Please sign in to comment.