Some apps on the gnome desktop like the image viewer use a dark variation of the theme. What code is required to make my own gtk program use this dark variation of the theme?
GTK. To change the light/dark mode, you have to change the used theme. Most themes do have a dark variant and those have by convention the suffix -dark . For example the default GTK theme Adwaita has the variant Adwaita-dark .
Important: When you turn on Dark theme for your phone, many apps also use Dark theme. On your phone, open the Settings app. Tap Display. Turn Dark theme on or off.
Once installed, launch GTK Theme Preferences from Dash / the menu, make any changes you want, make sure the "Custom widgets" toggle switch is turned on (or else the changes won't be used by your GTK theme!) and click Apply. Then, you'll have to log out and log back in to see the changes.
Use the gtk-application-prefer-dark-theme
setting. This ought to do it:
g_object_set(gtk_settings_get_default(),
"gtk-application-prefer-dark-theme", TRUE,
NULL);
You may need to make sure you do it before you create any widgets.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With