[gnome-maps/wip/mlundblad/night-mode: 4/5] mapView: Set a dark view background when in dark theme mode
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/mlundblad/night-mode: 4/5] mapView: Set a dark view background when in dark theme mode
- Date: Tue, 9 Jun 2020 16:37:38 +0000 (UTC)
commit c5e308924b22428ce30a5128e22e28c7605d5b72
Author: Marcus Lundblad <ml update uu se>
Date: Mon Jun 8 23:24:21 2020 +0200
mapView: Set a dark view background when in dark theme mode
src/mapView.js | 37 +++++++++++++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
---
diff --git a/src/mapView.js b/src/mapView.js
index 1e81f169..0ebfcb9f 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -205,10 +205,47 @@ 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;
}
+ _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'))
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]