After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 747132 - use the inverted view for "night mode"
use the inverted view for "night mode"
Status: RESOLVED FIXED
Product: gnome-documents
Classification: Core
Component: general
3.16.x
Other Linux
: Normal normal
: ---
Assigned To: GNOME documents maintainer(s)
GNOME documents maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2015-03-31 18:28 UTC by Jakub Steiner
Modified: 2015-04-11 09:38 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
preview: implement dark-mode in the content (1.10 KB, patch)
2015-04-01 19:58 UTC, Alessandro Bono
none Details | Review
preview: implement dark-mode in the content (1.47 KB, patch)
2015-04-02 16:01 UTC, Alessandro Bono
none Details | Review
preview: implement dark-mode in the content (2.71 KB, patch)
2015-04-09 20:44 UTC, Alessandro Bono
needs-work Details | Review
application: Simplify the night-mode state changes (969 bytes, patch)
2015-04-10 17:06 UTC, Debarshi Ray
committed Details | Review
application: Compare boolean values (1007 bytes, patch)
2015-04-10 18:57 UTC, Alessandro Bono
committed Details | Review
preview: Implement dark-mode in the content (2.00 KB, patch)
2015-04-10 18:58 UTC, Alessandro Bono
none Details | Review
preview: Implement dark-mode in the content (1.87 KB, patch)
2015-04-10 22:01 UTC, Alessandro Bono
committed Details | Review

Description Jakub Steiner 2015-03-31 18:28:43 UTC
Currenly Documents will switch the chrome to use Adwaita:dark, but keep the content intact. With the content highly likely being black text on white background, it just creates extra contrast between chrome and the content and doesn't really achieve the "night reading" experience it aims for. Evince has a simple inverted mode (Ctrl+I) we should peruse for this context.
Comment 1 Debarshi Ray 2015-04-01 13:50:47 UTC
ev_document_model_set_inverted_colors is what we want.
Comment 2 Alessandro Bono 2015-04-01 19:58:51 UTC
Created attachment 300776 [details] [review]
preview: implement dark-mode in the content
Comment 3 Debarshi Ray 2015-04-02 08:25:33 UTC
Review of attachment 300776 [details] [review]:

Thanks for the patch, Alessandro.

::: src/preview.js
@@ +548,3 @@
+
+            let settings = Application.settings;
+            settings.connect('changed::night-mode', Lang.bind(this,

We need to keep the connection ID so that we can disconnect the signal later when the view is destroyed because the Application will live longer than the view. Look for _viewSettingsId in src/mainToolbar.js for an example.

Also, you can use Application.settings directly instead of putting it in a variable.

@@ +550,3 @@
+            settings.connect('changed::night-mode', Lang.bind(this,
+                function () {
+                    state = settings.get_value('night-mode');

Don't you need a 'let' when using 'state' for the first time?

@@ +554,3 @@
+                }));
+            let state = settings.get_value('night-mode');
+            this._model.set_inverted_colors(state.get_boolean());

Better to wrap these two lines in a function, which you can connect to the signal and also call here. See src/mainToolbar.js for an example.
Comment 4 Debarshi Ray 2015-04-02 08:32:14 UTC
Review of attachment 300776 [details] [review]:

::: src/preview.js
@@ +554,3 @@
+                }));
+            let state = settings.get_value('night-mode');
+            this._model.set_inverted_colors(state.get_boolean());

Also remember that this._model can be null.
Comment 5 Alessandro Bono 2015-04-02 16:01:38 UTC
Created attachment 300840 [details] [review]
preview: implement dark-mode in the content
Comment 6 Alessandro Bono 2015-04-02 16:13:18 UTC
I have some trouble:
I'm not sure that we should keep the connection ID to disconnect it later. PreviewView seems to be never destroyed, instead is reset when necessary. There is also a connection to 'action-state-changed::present-current' that is never disconnected.
If we listen for the action will be activated when someone modify gsettings with: "gsettings set org.gnome.documents night-mode [true|false]"?
Currently it is listening for the action, but in the callback I can't call "get_state()" on the action parameter: it says that isn't a function, but in application.js is used. Any idea why?
Comment 7 Debarshi Ray 2015-04-09 12:13:04 UTC
(In reply to Alessandro Bono from comment #6)
> I'm not sure that we should keep the connection ID to disconnect it later.
> PreviewView seems to be never destroyed, instead is reset when necessary.

Why do you think it is never destroyed? Widgets are usually destroyed when their parents are destroyed. In this case PreviewView.widget gets destroyed when the top level window is closed. If you connect to the 'destroy' signal and you will see your handler getting called.

> There is also a connection to 'action-state-changed::present-current' that
> is never disconnected.

Yes, there are some cases like that. I think we should disconnect those too. Please use a separate patch if you do that.

> If we listen for the action will be activated when someone modify gsettings
> with: "gsettings set org.gnome.documents night-mode [true|false]"?

Yes, it should.

> Currently it is listening for the action, but in the callback I can't call
> "get_state()" on the action parameter: it says that isn't a function, but in
> application.js is used. Any idea why?

That is because in application.js, the handler is connected to GSimpleAction::activate, while you are listening to GActionGroup::action-state-changed. The parameters passed to those handlers are different. See _onPresentStateChanged for an example of what you want.
Comment 8 Alessandro Bono 2015-04-09 20:44:19 UTC
Created attachment 301238 [details] [review]
preview: implement dark-mode in the content
Comment 9 Debarshi Ray 2015-04-10 17:04:54 UTC
Review of attachment 301238 [details] [review]:

::: src/application.js
@@ +205,3 @@
             function() {
                 let state = settings.get_value('night-mode');
+                if (state.get_boolean() != action.state.get_boolean())

Could you please put this in a separate patch and note that it is a fall out from bd6ce176d055e23b8f4aaf0ed42c5fb542640aa3

::: src/preview.js
@@ +53,3 @@
         this._model = null;
         this._jobFind = null;
+        this._nightModeId = 0;

This doesn't need to be a instance variable. Nor does it need to be initialized.

@@ +150,3 @@
                                             Lang.bind(this, this._onLoadError));
+        this._nightModeId = Application.application.connect('action-state-changed::night-mode',
+                                            Lang.bind(this, this._updateNightMode));

Please move it above the present-current block, and the align the Lang.bind as is done for _onPresentStateChanged.

@@ +154,3 @@
+        this.widget.connect('destroy', Lang.bind(this,
+            function() {
+                if (this._nightModeId != 0) {

No need for this check, or setting it to 0 afterwards. It can't be 0 and the handler will be called only once.

@@ +563,3 @@
+
+    _updateNightMode: function(source, actionName, state) {
+        if(this._model) {

Missing white space after 'if'.

@@ +565,3 @@
+        if(this._model) {
+            if(state == null) {
+                state = Application.settings.get_value('night-mode');

Becomes simpler if you use:
let nightMode = Application.settings.get_boolean('night-mode');

@@ +570,1 @@
         }

I pushed a patch to make this even simpler. No need for accepting any arguments. Just directly read the setting. See _updateTypeForSettings for an example.
Comment 10 Debarshi Ray 2015-04-10 17:06:18 UTC
Created attachment 301307 [details] [review]
application: Simplify the night-mode state changes
Comment 11 Alessandro Bono 2015-04-10 18:57:38 UTC
Created attachment 301315 [details] [review]
application: Compare boolean values

Fall out from bd6ce176d055e23b8f4aaf0ed42c5fb542640aa3
Comment 12 Alessandro Bono 2015-04-10 18:58:06 UTC
Created attachment 301316 [details] [review]
preview: Implement dark-mode in the content
Comment 13 Debarshi Ray 2015-04-10 21:52:45 UTC
Review of attachment 301315 [details] [review]:

Perfect. Thanks, Alessandro.
Comment 14 Debarshi Ray 2015-04-10 21:54:24 UTC
Review of attachment 301316 [details] [review]:

Perfect. However, it needs to be rebased after the patches in bug 747506
Comment 15 Alessandro Bono 2015-04-10 22:01:04 UTC
Created attachment 301325 [details] [review]
preview: Implement dark-mode in the content
Comment 16 Debarshi Ray 2015-04-11 09:37:49 UTC
Review of attachment 301325 [details] [review]:

I attributed the patch to "Alessandro Bono <shadow@openaliasbox.org>" so that we have a full name and proper email address.