Commit graph

1049 commits

Author SHA1 Message Date
WanderingPenwing cb1b6037e6 modified config.def 2024-08-05 15:36:38 +02:00
WanderingPenwing d40b6fa723 force config color 2024-08-04 11:40:07 +02:00
WanderingPenwing 9c41ea8dcc my config 2024-08-04 11:03:06 +02:00
NRK 0ddf494437 introduce parse_optional_no() 2024-08-02 11:11:44 +00:00
NRK c61b84975d add --bar to enable statusbar
ref: https://codeberg.org/nsxiv/nsxiv/issues/404
2024-08-02 11:11:42 +00:00
NRK 55d60319db allow disabling animation playback via -A 0
ref: https://codeberg.org/nsxiv/nsxiv/issues/404
2024-08-02 11:08:47 +00:00
NRK 11558c9fcf allow disabling thumbnail mode via --thumbnail=no
the short opt -t does not accept optional argument since it'd
break short option chaining.

e.g `nsxiv -tp` currently works as `nsxiv -t -p` but if `-t`
accepted optional argument then it'd stop working since "p" will
be interpreted as argument to `-t` instead of being a flag.

ref: https://codeberg.org/nsxiv/nsxiv/issues/404
2024-08-02 11:08:44 +00:00
André Marçais 3408bbcdda print help to stderr on usage error (#510)
`print_usage` is called in two cases:

1) when `-h` is given on the command line.
2) when there is a usage error.

In the first case, the help message should go to stdout. In the second case,
it is an error, and should go to stderr.

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/510
Reviewed-by: NRK <nrk@disroot.org>
Co-authored-by: André Marçais <pex@marcais.net>
Co-committed-by: André Marçais <pex@marcais.net>
2024-08-02 11:05:05 +00:00
NRK 9406e7ea7c statusbar: print ellipsis when text is truncated (#501)
currently, there's no feedback on when the statusbar text is
getting truncated due to insufficient space. this prints an
ellipsis if the text wouldn't be able to fit inside the given
width to indicate truncation.

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/501
Reviewed-by: eylles <eylles@noreply.codeberg.org>
2024-06-27 15:54:08 +00:00
NRK 99e941271d use compression level 8 when writing png thumbnails (#505)
by default imlib2 uses a compression level of 2 for writing
pngs, which is rather low.

a compression level of 8 should result in slightly lower
thumbnail filesizes without affecting the encoding speed too
much (since these thumbnails are very small already).

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/505
Reviewed-by: eylles <eylles@noreply.codeberg.org>
2024-06-27 12:38:49 +00:00
NRK b3eab414dd add a migration document (#507)
this should've been added ages ago back when `nsxiv` was first
released. but even now, there's still plently of people who
might be looking to migrate.

so add a simple MIGRATION.md which covers some of the
differences to be aware of when migrating.

this does not cover patches and `config.h` since any conflicts
in patches would be evident anyways.

ref: https://codeberg.org/nsxiv/nsxiv/issues/369
ref: https://codeberg.org/nsxiv/nsxiv/issues/506
ref: https://codeberg.org/nsxiv/nsxiv/issues/420

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/507
Reviewed-by: eylles <eylles@noreply.codeberg.org>
2024-06-27 08:07:44 +00:00
NRK 0620d473c2 allow {white,black}listing thumbnail cache dirs (#461)
this adds the cli flags --cache-{allow,deny} along with
corresponding config.h vars which allows the user to control
which directories will have thumbnail cache written.

this is a more general version of the `cache-whitelist` patch
that existed in the nsxiv-extra repo:
https://codeberg.org/nsxiv/nsxiv-extra/src/commit/21cb27cee7/patches/cache-whitelist

Closes: https://codeberg.org/nsxiv/nsxiv/issues/454
2024-06-20 10:50:19 +00:00
NRK 9b8cdcff48 some minor comment nitpick 2024-06-18 15:11:36 +00:00
NRK 1fbff6d539 win_draw_bar: simplify logic a bit 2024-06-18 15:11:36 +00:00
NRK b6d9e7d24f fix: crash when cache directory is not present
to reproduce:

	( unset HOME XDG_CACHE_HOME; nsxiv -t ~/pictures; )

the code never really worked without a cache_dir going back to
original sxiv. so just fatally error out instead of crashing
with a null pointer dereference.
2024-06-18 15:11:36 +00:00
NRK 36d5b27fff fix: -A not working (#503)
the imlib2 based multi-frame loader has not respected -A setting
since it's introduction in commit 76c2b81b.

also change multi.framedelay to `int` to avoid signedness change
warning.

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/503
Reviewed-by: eylles <eylles@noreply.codeberg.org>
2024-06-18 15:08:37 +00:00
NRK faf67fcc62 fix: autoreload when directory is root (#498)
for cases like "/file", `base - filepath` will result in 0
instead of 1.

regression introduced in: 94d531fd82

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/498
Reviewed-by: eylles <eylles@noreply.codeberg.org>
2024-06-16 21:07:33 +00:00
NRK 420a0a2455 ci: fix macos build
for whatever reason, the path where homebrew installs headers
and libraries are no longer being searched by default. work
around it by manually specifying them with -I and -L.
2024-06-06 10:50:15 +00:00
NRK 2a62683e60 fix: missing include in 65acb98
caught by the github CI.
the woodpecker CI somehow missed this.

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/497
2024-06-05 21:02:02 +00:00
NRK 931912dcf6 make pipes non-blocking and read output on POLLHUP (#490)
this makes it so that script outputs are read when the script
actually finishes. one objection to reading on POLLHUP was that
the script might fill up the pipe and get stuck. we already mark
the read-end as non-blocking on our end so might as well make
the write-end non-blocking as well which avoids the script
getting blocked after (and if) it fills up the pipe.

ref: https://codeberg.org/nsxiv/nsxiv/pulls/334
Closes: https://codeberg.org/nsxiv/nsxiv/issues/377

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/490
Reviewed-by: eylles <eylles@noreply.codeberg.org>
2024-06-05 19:40:58 +00:00
NRK 65acb98396 fix: unresponsive UI when animation is too fast (#489)
the previous check_timeouts() logic tried to greedily handle as
many timeouts as possible until there are no more active
timeouts left. this caused a number of issues such as:

https://codeberg.org/nsxiv/nsxiv/issues/439
https://codeberg.org/nsxiv/nsxiv-record/issues/281

the new logic relaxes this and only does a single iteration.
any remaining active timeout will be picked up by the next
iteration instead.

Fixes: https://codeberg.org/nsxiv/nsxiv/issues/439
2024-06-05 19:37:46 +00:00
e5150 a581cd6344 fix: image placement when rotating (#493)
When rotating a partially shown image (i.e. image size * zoom >
window size) the image is panned to top or left (if `win->w` or
`win->h` is greatest, respectively). Seems to be due to
unsignedness of `win->[wh]`, when taking the difference between
them in `img_rotate` either `img->[xy]` ends up being close to
`UINT_MAX` and the image is panned to top or left edge.

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/493
Reviewed-by: NRK <nrk@disroot.org>
Co-authored-by: e5150 <e5150@noreply.codeberg.org>
Co-committed-by: e5150 <e5150@noreply.codeberg.org>
2024-04-23 06:47:09 +00:00
fxdn 437e060021 document Xresources application namespace explicitly (#488)
A decent amount of users have been confused by this.
So make it more explicit to avoid confusion.

Co-authored-by: NRK <nrk@disroot.org>
Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/488
Reviewed-by: NRK <nrk@disroot.org>
Co-authored-by: fxdn <fxdn@noreply.codeberg.org>
Co-committed-by: fxdn <fxdn@noreply.codeberg.org>
2024-02-17 08:14:05 +00:00
NRK 6cc1225fef free cache_tmpfile in tns_free (#485)
doesn't really matter since the process is about to exit
anyways, but makes it consistent with everything else.

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/485
2024-02-12 22:00:31 +00:00
NRK 0faff1866d ci: adjust clang-tidy checks
disable misc-include-cleaner, it nags about "directly" including
things like "stdbool.h" instead of relying on "nsxiv.h" for it.

also disable bugprone-switch-missing-default-case which nags
about missing `default` switch cases.
2024-02-09 01:55:53 +00:00
NRK add12ecdfd README: fix typo 2024-02-08 17:57:33 +00:00
NRK bed596bf47 move key-handler prompts to the right bar (#481)
this makes it more consistent with e4fceab by moving the key-handler
related messages to the right side as well.

additionally this fixes a regression introduced by 3659361 where the
left statusbar would remain at "Running key-handler..." if the image
didn't change.

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/481
Reviewed-by: eylles <eylles@noreply.codeberg.org>
2023-11-13 10:45:49 +00:00
NRK 70cbe59daa ci: various fixes (#478)
- "branches" option got removed, change to "when -> branches"
- "pipeline" option got removed, change to "steps"
- install codespell in a virtual-env since alpine complains otherwise
2023-10-02 09:43:46 +00:00
NRK a9e13042d4 Release version 32 2023-10-01 17:32:32 +06:00
NRK 48d1afd50a inline img_multiframe_context_set()
no longer needs to be a separate function now that the legacy loaders
are removed.

also remove a NOLINT comment and use `(void)var` to silence warning.
2023-10-01 17:30:15 +06:00
NRK e1b851c488 remove legacy multi-frame loaders
this removes the legacy gif and webp loaders. moving forward
multi-frame/animated images will be loaded by imlib2 itself.

Closes: https://codeberg.org/nsxiv/nsxiv/issues/397
2023-10-01 17:30:15 +06:00
NRK 1fc28278b5 add option to update cache in a background process
the cli flag is undocumented for now, since it's experimental.

Closes: https://codeberg.org/nsxiv/nsxiv/issues/416
Closes: https://codeberg.org/nsxiv/nsxiv/pulls/425
Co-authored-by: explosion-mental <explosion0mental@gmail.com>
2023-10-01 17:23:29 +06:00
NRK 2093f36661 make thumbnail caching safer against concurrent writes
by writing to a tmpfile first, and then renaming it to the desired
target - multiple nsxiv instances writing thumbnail at the same time are
guaranteed not to stomp over one another.

rename() is guaranteed to be atomic by POSIX. however, it can fail with
EXDEV if both the files don't reside in the same filesystem. and so we
cannot make the tmpfile something like "/tmp/nsxiv-XXXXXX".

instead, create the tmpfile inside the cache_dir to reduce chances of
EXDEV occuring.
2023-10-01 17:02:35 +06:00
NRK 3659361e76 centralize script handling logic (#477)
currently the logic of when to open/close script is scattered around the
entire code-base which is both ugly and error-prone.

this patch centralizes script handling by remembering the relevant
information on each redraw and then comparing it with the previous
information to figure out whether something changed or not.

this also fixes a bug where scripts weren't being called in thumbnail
mode when mouse was used for selecting a different image.

Closes: https://codeberg.org/nsxiv/nsxiv/issues/475

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/477
Reviewed-by: eylles <eylles@noreply.codeberg.org>
2023-09-30 08:53:32 +00:00
NRK 80a71315de fix: re-loading stale multi-frame images
4b67816 only partially fixed this issue. because imlib2's cache may not
have sub-second granularity, there still exists a time-frame while the
`mtime` has not yet been updated but we might be trying to reload the
image due to receiving an inotify event in which case imlib2 will end up
giving us the old frame.

imlib2 v1.12.0 adds a function that allows us to decache any frames
associated with a filename. this allows us to invalidate the cache
manually instead of relying on `mtime`.

but if that's not available due to older imlib2, then forcefully reload
the raw frames and decache them. this has the unfortunate cost that if
`mtime` *was* updated properly then we'll end up loading that image
twice.

fixes: https://codeberg.org/nsxiv/nsxiv/issues/456
2023-09-20 22:54:41 +00:00
NRK 53a43cb388 introduce img_free()
this removes some repetitive code.
2023-09-20 22:54:41 +00:00
NRK 69d4957a92 remove faulty assertions
these assertions did not hold true in practice when the underlying file
ends up changing during load.
2023-09-20 22:54:41 +00:00
NRK d19924f288 various README nits (#470)
don't capitalize "berg" in "Codeberg" spelling. Codeberg's official
sites does not seem to do so.

switch from "GPLv2" to "GPL-2.0-or-later" according to the spdx short
identifier: https://spdx.org/licenses/GPL-2.0-or-later.html

explicitly mention that Imlib2 needs to be built with X11 support.

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/470
Reviewed-by: explosion-mental <explosion-mental@noreply.codeberg.org>
2023-08-31 18:06:43 +00:00
David Gowers 10a6228538 set autoreload timeout based on the latest event (#459)
currently the autoreload feature of nsxiv is a bit unreliable because we
try to load at the very first event we received. however, the writer
might not be done writing and so we might try to load a truncated image
(and fail).

in the following ascii diagram, function S represents sleep and `+` sign
represents writes by the writer. because we set the sleep (of 10ms) at
the first event, subsequent writes by the writer doesn't influence our
reload logic:

       S(10)                   load()
nsxiv        |                       |
writer       +           +           +           + (done)
time(ms):   00          05          10          15

after this patch, (assuming function T (re)sets a timeout), we will keep
(re)setting a timeout on new events giving the writer more time to
finish:

       T(10)       T(10)       T(10)       T(10)                   load()
nsxiv        |           |           |           |                       |
writer       +           +           +           + (done)
time(ms):   00          05          10          15          20          25

while this patch makes things significantly more robust, the problem
here is inherently unsolvable since there's no way to tell whether the
writer is done writing or not.

for example, if user does something like `curl 'some.png' > test.png`
then curl might stop for a second or two in the middle of writing due to
internet issues - which will make nsxiv drop the image.

this patch also increases the autoreload delay from 10ms to now 128ms
instead to decrease chances of false failures.

ref: 6ae2df6ed5
partially-fixes: https://codeberg.org/nsxiv/nsxiv/issues/456
commit-message-by: NRK
Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/459
Reviewed-by: eylles <eylles@noreply.codeberg.org>
2023-08-28 16:31:09 +06:00
padv cc132dd365 fix: brightness keybindings on manpage (#467)
Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/467
Reviewed-by: NRK <nrk@disroot.org>
Reviewed-by: explosion-mental <explosion-mental@noreply.codeberg.org>
Co-authored-by: padv <pascal.devuyst@gmail.com>
Co-committed-by: padv <pascal.devuyst@gmail.com>
2023-08-22 18:08:29 +00:00
NRK 112ba3a2fc config.mk: do not explicitly set CC (#455)
1. `c99` doesn't exist on openbsd
2. `c99` behaves weirdly on macos (doesn't support -Wall)

since make will already set CC (required by POSIX if the implementation
supports C, see `man 1p make`) to something appropriate (or it might be
set in the environment) go ahead and remove explicitly setting it on our
end.

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/455
Reviewed-by: TAAPArthur <taaparthur@noreply.codeberg.org>
2023-07-16 18:16:23 +00:00
NRK c1b36b8f09 add some upgrade comments (#457)
these document improvements and/or removal of unnecessary code for when
we will require a higher minimum version of Imlib2.

all the comments have been prefixed with "UPGRADE: " for easy grepping.

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/457
Reviewed-by: explosion-mental <explosion-mental@noreply.codeberg.org>
2023-07-08 07:05:57 +00:00
NRK 9b122c82fa add compiled features into --version output (#462)
a lot of application which allow selecting features at build time seem
to output the build config with `--version` or similar (e.g ffmpeg).

aside from giving the user information about the feature set the binary
was compiled with (in case the user didn't compile it themselves, e.g on
a binary distro) it can also (possibly) help when submitting bug
reports.

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/462
Reviewed-by: explosion-mental <explosion-mental@noreply.codeberg.org>
2023-07-08 06:53:57 +00:00
NRK bfab3a76a4 config.mk: update openbsd configuration (#453)
based on the openbsd port:
cf3cdaf092/graphics/nsxiv/Makefile

Tested-by: Seninha
Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/453
2023-06-29 23:40:52 +00:00
NRK 6185bcb441 config.h: allow all values to be NULL
might as well make things consistent instead of having certain values
that can be NULL and certain that cannot.

some of the default values are still kept in config.h for example
reasons.
2023-06-23 22:10:27 +06:00
explosion-mental 3097037624 make xresources class name configurable in config.h 2023-06-23 22:08:51 +06:00
NRK 28018e92d3 CI: misc cleanups + faster analysis (#449)
* switch to git ls-files to avoid picking up any other local .c files
* enable assertions during static analysis since we used some assertions to
  disable/silence certain warnings.
* update TCC commit hash to a more recent one
* parallelize static analysis

cppcheck already has -j argument to parallelize it's analysis and
provide results faster, clang-tidy unfortunately doesn't.

so use xargs -P to archive parallel execution. on my system this brings
down the analysis time from ~27s to ~5s.
2023-06-15 15:25:54 +00:00
NRK c03ec39437 update documentation (#448)
the fedora copr repo is no longer being updated since the maintainer of
it, mamg22, no longer uses nsxiv in his daily setup (and thus stopped
contributing to nsxiv as well).

he has requested the repo and his email to be removed from the project.
so go ahead and honor that request.

also take this as an opportunity to remove some long inactive
maintainers from the CURRENT MAINTAINERS section of the manpage.

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/448
Reviewed-by: explosion-mental <explosion-mental@noreply.codeberg.org>
2023-05-28 06:49:07 +00:00
NRK 40480596ca make assertions opt-in (#447)
slight addendum to 657080a7e5

instead of disabling asserts by adding -DNDEBUG to config.mk, this
disables asserts by default in the source code itself. this way, if
someone compiles with `make CFLAGS="-O3 -march=native"` without knowing
about asserts/-DNDEBUG then he won't accidentally get a build with
assertions in it.

this basically makes the assertions opt-in, if someone wants it, he'll
need to *explicitly* set `-DDEBUG` to get it. so that it's not possible
to accidentally end up with assertions enabled.

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/447
Reviewed-by: TAAPArthur <taaparthur@noreply.codeberg.org>
2023-05-26 07:06:17 +00:00
NRK 0e1bc3c045 set a default delay if delay is 0 (#445)
gif spec [0] doesn't mention what to do when "Delay Time" is 0.

apng spec [1] states:

| If the the value of the numerator is 0 the decoder should render the
| next frame as quickly as possible, though viewers may impose a
| reasonable lower bound.

webp spec [2]:

| the interpretation of frame duration of 0 (and often <= 10) is
| implementation defined.

so it seems that it's safe to set a default delay for 0 delay frames,
which is what the older gif and webp loaders were already doing. do the
same for the imlib2 multi-frame loader as well.

[0]: https://www.w3.org/Graphics/GIF/spec-gif89a.txt
[1]: https://wiki.mozilla.org/APNG_Specification
[2]: https://developers.google.com/speed/webp/docs/riff_container#animation

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/445
Reviewed-by: eylles <eylles@noreply.codeberg.org>
2023-05-23 11:36:41 +00:00