-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support switching between light and dark themes (#613)
* Support switching between light and dark themes This uses AdwStyleManager's facilities for specifying whether the light or dark variant of the system theme should be used. If the system doesn't indicate a preference, the default is to use dark. * Save the color scheme preference to the settings.
- Loading branch information
1 parent
8240fab
commit 34c0787
Showing
6 changed files
with
53 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using Gio; | ||
using Pinta.Core; | ||
|
||
namespace Pinta.Actions; | ||
|
||
internal sealed class ColorSchemeChangedAction : IActionHandler | ||
{ | ||
#region IActionHandler Members | ||
public void Initialize () | ||
{ | ||
PintaCore.Actions.View.ColorScheme.OnActivate += Activated; | ||
} | ||
|
||
public void Uninitialize () | ||
{ | ||
PintaCore.Actions.View.ColorScheme.OnActivate -= Activated; | ||
} | ||
#endregion | ||
|
||
private void Activated (SimpleAction action, SimpleAction.ActivateSignalArgs args) | ||
{ | ||
action.ChangeState (args.Parameter!); | ||
|
||
Adw.ColorScheme scheme = args.Parameter!.GetInt32 () switch { | ||
1 => Adw.ColorScheme.ForceLight, | ||
2 => Adw.ColorScheme.ForceDark, | ||
_ => Adw.ColorScheme.PreferDark, // Use dark unless the system prefers light | ||
}; | ||
|
||
Adw.StyleManager.GetDefault ().SetColorScheme (scheme); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters