@@ -15,6 +15,7 @@ const BrightnessBusName = "org.cinnamon.SettingsDaemon.Power.Screen";
1515const KeyboardBusName = "org.cinnamon.SettingsDaemon.Power.Keyboard" ;
1616
1717const CSD_BACKLIGHT_NOT_SUPPORTED_CODE = 1 ;
18+ const CSD_SCHEMA = "org.cinnamon.settings-daemon.plugins.power" ;
1819
1920const PANEL_EDIT_MODE_KEY = "panel-edit-mode" ;
2021
@@ -256,7 +257,33 @@ class CinnamonPowerApplet extends Applet.TextIconApplet {
256257 this . brightness = new BrightnessSlider ( this , _ ( "Brightness" ) , "display-brightness" , BrightnessBusName , 0 ) ;
257258 this . keyboard = new BrightnessSlider ( this , _ ( "Keyboard backlight" ) , "keyboard-brightness" , KeyboardBusName , 0 ) ;
258259 this . menu . addMenuItem ( this . brightness ) ;
260+
261+ this . _ambientItem = new PopupMenu . PopupSwitchMenuItem ( _ ( "Adjust automatically" ) , false ) ;
262+ this . _ambientItem . actor . hide ( ) ;
263+ this . menu . addMenuItem ( this . _ambientItem ) ;
264+
265+ this . _brightnessSection = new PopupMenu . PopupSeparatorMenuItem ( ) ;
266+ this . _brightnessSection . actor . hide ( ) ;
267+ this . menu . addMenuItem ( this . _brightnessSection ) ;
268+
259269 this . menu . addMenuItem ( this . keyboard ) ;
270+ this . _csdSettings = new Gio . Settings ( { schema_id : CSD_SCHEMA } ) ;
271+ this . _ambientItem . setToggleState ( this . _csdSettings . get_boolean ( "ambient-enabled" ) ) ;
272+ this . _ambientItem . connect ( "toggled" , ( item ) => {
273+ this . _csdSettings . set_boolean ( "ambient-enabled" , item . state ) ;
274+ } ) ;
275+ this . _csdSettings . connect ( "changed::ambient-enabled" , ( ) => {
276+ this . _ambientItem . setToggleState ( this . _csdSettings . get_boolean ( "ambient-enabled" ) ) ;
277+ } ) ;
278+
279+ this . keyboard . actor . connect ( "notify::visible" , ( ) => this . _updateBrightnessSeparator ( ) ) ;
280+
281+ Interfaces . getDBusProxyAsync ( BrightnessBusName , ( proxy , error ) => {
282+ if ( error ) return ;
283+ this . _screenProxy = proxy ;
284+ this . _updateAmbientVisibility ( ) ;
285+ this . _screenProxy . connect ( "g-properties-changed" , ( ) => this . _updateAmbientVisibility ( ) ) ;
286+ } ) ;
260287
261288 try {
262289 // Hadess interface
@@ -340,6 +367,23 @@ class CinnamonPowerApplet extends Applet.TextIconApplet {
340367 this . set_show_label_in_vertical_panels ( false ) ;
341368 }
342369
370+ _updateAmbientVisibility ( ) {
371+ if ( this . _screenProxy && this . _screenProxy . AmbientLightSupported ) {
372+ this . _ambientItem . actor . show ( ) ;
373+ } else {
374+ this . _ambientItem . actor . hide ( ) ;
375+ }
376+ this . _updateBrightnessSeparator ( ) ;
377+ }
378+
379+ _updateBrightnessSeparator ( ) {
380+ if ( this . _ambientItem . actor . visible && this . keyboard . actor . visible ) {
381+ this . _brightnessSection . actor . show ( ) ;
382+ } else {
383+ this . _brightnessSection . actor . hide ( ) ;
384+ }
385+ }
386+
343387 _onPanelEditModeChanged ( ) {
344388 if ( global . settings . get_boolean ( PANEL_EDIT_MODE_KEY ) ) {
345389 if ( ! this . actor . visible ) {
0 commit comments