Page Menu
Home
Musing Studio
Search
Configure Global Search
Log In
Files
F13826331
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Subscribers
None
View Options
diff --git a/src/window.vala b/src/window.vala
index a3a6bfc..f98298e 100644
--- a/src/window.vala
+++ b/src/window.vala
@@ -1,66 +1,67 @@
public class WriteAs.MainWindow : Gtk.ApplicationWindow {
private Gtk.TextView canvas;
private bool dark_mode = false;
construct {
construct_toolbar();
canvas = new Gtk.TextView();
+ canvas.margin = 20;
add(canvas);
}
public MainWindow(Gtk.Application app) {
set_application(app);
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;
dark_mode = darkmode_button.active;
adjust_text_style();
});
header.pack_end(darkmode_button);
}
private Gtk.CssProvider cur_styles = null;
private void adjust_text_style() {
try {
var styles = canvas.get_style_context();
if (cur_styles != null) styles.remove_provider(cur_styles);
var css = "";
if (dark_mode) {
// Try to detect whether the system provided a better dark mode.
var text_color = styles.get_color(Gtk.StateFlags.ACTIVE);
double h, s, v;
Gtk.rgb_to_hsv(text_color.red, text_color.green, text_color.blue,
out h, out s, out v);
if (v < 0.5) css = "* {background: black; color: white;}";
}
cur_styles = new Gtk.CssProvider();
cur_styles.load_from_data(css);
styles.add_provider(cur_styles, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION);
} catch (Error e) {
warning(e.message);
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Thu, Feb 19, 12:37 AM (1 d, 16 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3631584
Attached To
rWAGTK writeas-gtk
Event Timeline
Log In to Comment