Allow toggling between dark and light GTK themes (if provided).
Took me a bit to get the icon fallbacks working right. 28min.
This commit is contained in:
parent
f2d017aa15
commit
da5817e12e
Binary file not shown.
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 2.9 KiB |
BIN
data/icons/writeas-bright-dark@2x.png
Normal file
BIN
data/icons/writeas-bright-dark@2x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
@ -2,7 +2,7 @@ install_data('icons/write-as.png',
|
||||
install_dir: join_paths(get_option('datadir'), 'icons', 'hicolor', '128x128', 'apps')
|
||||
)
|
||||
install_data('icons/writeas-bright-dark.png',
|
||||
install_dir: join_paths(get_option('datadir'), 'icons', 'hicolor', '48x48', 'actions'))
|
||||
install_dir: join_paths(get_option('datadir'), 'icons', 'hicolor', '16x16', 'actions'))
|
||||
|
||||
install_data('write-as-gtk.desktop',
|
||||
install_dir: join_paths(get_option('datadir'), 'applications'))
|
||||
|
@ -2,10 +2,7 @@ public class WriteAs.MainWindow : Gtk.ApplicationWindow {
|
||||
private Gtk.TextView canvas;
|
||||
|
||||
construct {
|
||||
var header = new Gtk.HeaderBar();
|
||||
header.title = "";
|
||||
header.show_close_button = true;
|
||||
set_titlebar(header);
|
||||
construct_toolbar();
|
||||
|
||||
canvas = new Gtk.TextView();
|
||||
add(canvas);
|
||||
@ -16,4 +13,25 @@ public class WriteAs.MainWindow : Gtk.ApplicationWindow {
|
||||
|
||||
set_default_size(800, 600);
|
||||
}
|
||||
|
||||
private void construct_toolbar() {
|
||||
var header = new Gtk.HeaderBar();
|
||||
header.title = "";
|
||||
header.show_close_button = true;
|
||||
set_titlebar(header);
|
||||
|
||||
var darkmode_button = new Gtk.ToggleButton();
|
||||
// NOTE the fallback icon is a bit of a meaning stretch, but it works.
|
||||
var icon_theme = Gtk.IconTheme.get_default();
|
||||
darkmode_button.image = new Gtk.Image.from_icon_name(
|
||||
icon_theme.has_icon("writeas-bright-dark") ?
|
||||
"writeas-bright-dark" : "weather-clear-night",
|
||||
Gtk.IconSize.SMALL_TOOLBAR);
|
||||
darkmode_button.draw_indicator = false;
|
||||
var settings = Gtk.Settings.get_default();
|
||||
darkmode_button.toggled.connect(() => {
|
||||
settings.gtk_application_prefer_dark_theme = darkmode_button.active;
|
||||
});
|
||||
header.pack_end(darkmode_button);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user