pwmt / zathura

Document viewer
https://pwmt.org/projects/zathura
zlib License
1.87k stars 128 forks source link

[Feature Request] Keep the `adjust_window` behavior after file reloading (and searching) #401

Open sebastinas opened 1 year ago

sebastinas commented 1 year ago

On GitLab by @oliverlew on Jun 27, 2023, 06:53


Currently, if the document is reloaded due to the file change, the adjust method of the document (adjust_window = best-fit/width) will stop working. Yes, the actual file indeed changed. But, to users this is still the same document, so I think it's a fair request.

For example, if I am editing a tex file and use zathura to preview the PDF, I expect the document to keep the behavior of adjust_window = best-fit/width after the file gets rebuilt and reloaded. Otherwise, when I switch fullscreen, I have to press a/s every time after reload, which is annoying.

Not sure if this counts as a bug, so just a feature request for now.

This can also apply to searching operation, not just file reloading. Both operations change the adjust_window behavior.

sebastinas commented 1 year ago

On GitLab by @marcoe on Jul 6, 2023, 13:53


Zathura does not store any information about adjust_mode in its database file. The current behavior is to open the document with the value of the 'adjust-open' setting IF the file hasn't been opened before, otherwise it is to open it with adjust_mode set to ZATHURA_ADJUST_NONE.

I think the only non-hacky solution is to add the adjust_mode entry to the database, which is not without its considerations obviously.

Regarding the searching operation, it is caused by functions using the input bar that set the adjust_mode as mentioned in the comment under issue #356.

sebastinas commented 12 months ago

On GitLab by @oliverlew on Jul 10, 2023, 08:45


otherwise it is to open it with adjust_mode set to ZATHURA_ADJUST_NONE

I guess that is the behavior of file reloading that I am seeing. To be honest, that is confusing. Especially when the user haven't changed the mode himself during this session, he probably won't expect the mode to change at all.

I think the only non-hacky solution is to add the adjust_mode entry to the database

Does 'database' mean some local file? Instead of that, what about just keep the "adjust_mode" variable across file reloads? Then this information is discarded after zathura quits (it's only in RAM). Next time this file is opened, it will be opened with the 'adjust-open' setting again, which is the same old behavior.

Is this "hacky" to implement?

sebastinas commented 11 months ago

On GitLab by @marcoe on Jul 12, 2023, 24:27


I have a patch that implements this behavior per your suggestion – it preserves the adjust mode between clean reloads and file deletion/creation.

You can try it out as well as a bunch of other patches that fix #356 and a few selection issues by building the "patched" branch of my fork: https://git.pwmt.org/marcoe/zathura/-/tree/patched

sebastinas commented 11 months ago

On GitLab by @oliverlew on Jul 12, 2023, 07:05


Thanks for the incredible work! I just tried the 'patched' branch, and confirm that those issues are fixed:

sebastinas commented 11 months ago

On GitLab by @oliverlew on Jul 12, 2023, 16:23


However, when I was testing the fixes, I noticed the behavior you described (this is not related to this patched branch):

The current behavior is to open the document with the value of the 'adjust-open' setting IF the file hasn't been opened before, otherwise it is to open it with adjust_mode set to ZATHURA_ADJUST_NONE.

I thought this only applies to file reloads, but it also applies between zathura processes. As a result, adjust_mode is not used starting from the second time I open the same file. By "second time", I mean first open the file, quit zathura, open the same file again

Here is what I had thought the behavior was (in my comment above):

Next time this file is opened, it will be opened with the 'adjust-open' setting again

Of course, this is off-topic. But I am curious why the adjust_mode is not used after the file has been opened once, while the current choice ZATHURA_ADJUST_NONE I guess does not make more sense.

sebastinas commented 11 months ago

On GitLab by @marcoe on Jul 12, 2023, 17:40


I thought this only applies to file reloads, but it also applies between zathura processes. As a result, adjust_mode is not used starting from the second time I open the same file.

File reloads work by just closing the document and opening it again which isn't that much different from closing the program and opening the same document again. Except for, in the latter case, we can only rely on what information is being saved about the document state in the local database file (~/.local/share/zathura/history). adjust_mode is not in the database, but zoom is, which makes it seem like the adjust_mode is being saved, but in reality it is the result of applying the adjust_mode – the zoom value.

But I am curious why the adjust_mode is not used after the file has been opened once, while the current choice ZATHURA_ADJUST_NONE I guess does not make more sense.

The current logic for applying adjustments when the document is opened (pseudo code):

if (file not in database AND adjust-open in zathurarc) {
  set `adjust_mode` to the value of adjust-open from zathurarc;
} else {
  set `adjust_mode` to `ZATHURA_ADJUST_NONE`;
}

And IMO it makes sense to do it this way currently, because we can only restore the zoom value for the document from the database and I presume it is more important to honor the state of the document as it was when last closed, rather than to honor the 'adjust-open' setting from zathurarc. Technically it would be possible to also restore the adjust_mode value from the saved zoom value, but it'd be silly and not what one might expect.

sebastinas commented 11 months ago

On GitLab by @oliverlew on Jul 13, 2023, 07:43


Thanks for the reply, now I understand.

If the adjust_mode is added into the database, the behavior might be better. However, it should be in another discussion/feature request:

if (file in database) {
  set `adjust_mode` to the value in database;
  if (`adjust_mode` is `ZATHURA_ADJUST_NONE`) {
    set zoom level to the value in database;
  }
} else if (adjust-open in zathurarc) {
  set `adjust_mode` to the value of adjust-open from zathurarc;
} else {
  set `adjust_mode` to `ZATHURA_ADJUST_NONE`;
}