summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcus Lundblad <ml@update.uu.se>2020-06-08 23:24:21 +0200
committerMarcus Lundblad <ml@update.uu.se>2020-06-14 23:28:10 +0200
commit116becd70e52ebdacbb788c0ae0d247346aa9c4a (patch)
tree3ecc5b0ad8a7a550bc793d743242177afb2627cc
parent3662429c5b26b883cc0bcc85bc7981a803556867 (diff)
downloadgnome-maps-116becd70e52ebdacbb788c0ae0d247346aa9c4a.tar.gz
mapView: Set a dark view background when in dark theme mode
-rw-r--r--src/mapView.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/mapView.js b/src/mapView.js
index 1e81f169..544ef46a 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -205,10 +205,51 @@ var MapView = GObject.registerClass({
this._onNightModeChanged.bind(this));
}
+ this._gtkSettings = Gtk.Settings.get_default();
+ this._gtkSettings.connect('notify::gtk-application-prefer-dark-theme',
+ this._onPreferDarkThemeChanged.bind(this));
+ // set dark background if we start up in dark theme
+ if (this._gtkSettings.gtk_application_prefer_dark_theme) {
+ if (!this._darkBackgroud)
+ this._createDarkBackground();
+ view.set_background_pattern(this._darkBackground);
+ }
+
this._initScale(view);
return view;
}
+ /* handler to draw background for dark theme,
+ * theese three functions should not be needed later with a native GTK
+ * widget (Shumate)
+ */
+ _drawDarkBackground(canvas, cr, width, height) {
+ // set this arbitrarily to try to match the typical dark tile set
+ cr.setSourceRGB(0.2, 0.2, 0.2);
+ cr.rectangle(0, 0, width, height);
+ cr.fillPreserve();
+
+ return true;
+ }
+
+ _createDarkBackground() {
+ this._darkBackground = new Clutter.Canvas();
+ this._darkBackground.set_size(512, 512);
+ this._darkBackground.connect('draw',
+ this._drawDarkBackground.bind(this));
+ this._darkBackground.invalidate();
+ }
+
+ _onPreferDarkThemeChanged() {
+ if (this._gtkSettings.gtk_application_prefer_dark_theme) {
+ if (!this._darkBackgroud)
+ this._createDarkBackground();
+ this.view.set_background_pattern(this._darkBackground);
+ } else {
+ this.view.background_pattern = null;
+ }
+ }
+
_onNightModeChanged() {
if (this._mapType === MapType.STREET) {
if (Application.settings.get('night-mode'))