@@ -118,7 +118,9 @@ fn with_daemon<F: Fn(Rc<dyn Daemon>)>(f: F) {
118
118
119
119
#[ cfg( target_os = "macos" ) ]
120
120
fn macos_init ( ) {
121
+ use gtk:: SettingsExt ;
121
122
use std:: { env, process} ;
123
+ let mut prefer_dark = false ;
122
124
// This command returns Dark if we should use the dark theme
123
125
// defaults read -g AppleInterfaceStyle
124
126
if let Ok ( output) = process:: Command :: new ( "defaults" )
@@ -127,40 +129,45 @@ fn macos_init() {
127
129
. arg ( "AppleInterfaceStyle" )
128
130
. output ( )
129
131
{
130
- if output. stdout . starts_with ( b"Dark" ) {
131
- let _ = env:: set_var ( "GTK_THEME" , "Adwaita:dark" ) ;
132
- }
132
+ prefer_dark = output. stdout . starts_with ( b"Dark" ) ;
133
+ }
134
+
135
+ if let Some ( settings) = gtk:: Settings :: get_default ( ) {
136
+ settings. set_property_gtk_application_prefer_dark_theme ( prefer_dark) ;
133
137
}
134
138
}
135
139
136
140
#[ cfg( target_os = "windows" ) ]
137
141
fn windows_init ( ) {
138
- use std:: env;
139
142
// This is a dword with a value of 0 if we should use the dark theme:
140
143
// HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize\AppsUseLightTheme
144
+ use gtk:: SettingsExt ;
141
145
use winreg:: RegKey ;
146
+ let mut prefer_dark = false ;
142
147
let hkcu = RegKey :: predef ( winreg:: enums:: HKEY_CURRENT_USER ) ;
143
148
if let Ok ( subkey) = hkcu. open_subkey ( "Software\\ Microsoft\\ Windows\\ CurrentVersion\\ Themes\\ Personalize" ) {
144
149
if let Ok ( dword) = subkey. get_value :: < u32 , _ > ( "AppsUseLightTheme" ) {
145
- if dword == 0 {
146
- let _ = env:: set_var ( "GTK_THEME" , "Adwaita:dark" ) ;
147
- }
150
+ prefer_dark = ( dword == 0 ) ;
148
151
}
149
152
}
153
+
154
+ if let Some ( settings) = gtk:: Settings :: get_default ( ) {
155
+ settings. set_property_gtk_application_prefer_dark_theme ( prefer_dark) ;
156
+ }
150
157
}
151
158
152
159
pub fn run ( args : Vec < String > ) -> i32 {
153
- #[ cfg( target_os = "macos" ) ]
154
- macos_init ( ) ;
155
-
156
- #[ cfg( target_os = "windows" ) ]
157
- windows_init ( ) ;
158
-
159
160
let application =
160
161
gtk:: Application :: new ( Some ( "com.system76.keyboard-layout" ) , Default :: default ( ) )
161
162
. expect ( "Failed to create gtk::Application" ) ;
162
163
163
164
application. connect_activate ( move |app| {
165
+ #[ cfg( target_os = "macos" ) ]
166
+ macos_init ( ) ;
167
+
168
+ #[ cfg( target_os = "windows" ) ]
169
+ windows_init ( ) ;
170
+
164
171
if let Some ( window) = app. get_active_window ( ) {
165
172
//TODO
166
173
eprintln ! ( "Focusing current window" ) ;
0 commit comments