Browse Source

Allow toggling between dark and light GTK themes (if provided).

Took me a bit to get the icon fallbacks working right.

28min.
tags/v1.0.0
Adrian Cochrane 6 years ago
parent
commit
da5817e12e
4 changed files with 23 additions and 5 deletions
  1. BIN
      data/icons/writeas-bright-dark.png
  2. BIN
      data/icons/writeas-bright-dark@2x.png
  3. +1
    -1
      data/meson.build
  4. +22
    -4
      src/window.vala

BIN
data/icons/writeas-bright-dark.png View File

Before After
Width: 48  |  Height: 48  |  Size: 3.1 KiB Width: 16  |  Height: 16  |  Size: 2.9 KiB

BIN
data/icons/writeas-bright-dark@2x.png View File

Before After
Width: 32  |  Height: 32  |  Size: 3.1 KiB

+ 1
- 1
data/meson.build View File

@@ -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'))


+ 22
- 4
src/window.vala View File

@@ -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…
Cancel
Save