aboutsummaryrefslogtreecommitdiffstats
path: root/main.c
AgeCommit message (Collapse)Author
2024-06-18some minor comment nitpickNRK
2024-06-05fix: missing include in 65acb98NRK
caught by the github CI. the woodpecker CI somehow missed this. Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/497
2024-06-05make pipes non-blocking and read output on POLLHUP (#490)NRK
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-05fix: unresponsive UI when animation is too fast (#489)NRK
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
2023-11-13move key-handler prompts to the right bar (#481)NRK
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-10-01add option to update cache in a background processNRK
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-09-30centralize script handling logic (#477)NRK
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-08-28set autoreload timeout based on the latest event (#459)David Gowers
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: https://github.com/0ion9/sxiv/commit/6ae2df6ed549c2cc119bd7d235b75154fc042d2d 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-05-23move load/cache messages to right side (#446)a1337xyz
this avoids overwriting the left side bar, which might contain more important information, for e.g output of the thumb-info script. Co-authored-by: A1337Xyz <blindwizard@tutanota.com> Co-authored-by: NRK <nrk@disroot.org> Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/446 Reviewed-by: eylles <eylles@noreply.codeberg.org> Reviewed-by: NRK <nrk@disroot.org> Co-authored-by: a1337xyz <a1337xyz@noreply.codeberg.org> Co-committed-by: a1337xyz <a1337xyz@noreply.codeberg.org>
2023-03-11apply clang-formatNRK
minus the bogus changes Co-authored-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
2023-03-11make some changes prepping for clang-formatNRK
Co-authored-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
2023-03-04fix: thumbnail leak when removing the last file (#423)NRK
bf6c062 tried to fixed the thumbnail leak, but it was done inside a `if (n+1 < filecnt)` branch, meaning the thumbnail was still leaking away whenever the last file was removed. we need to unload the thumb regardless of whether it's in the middle or not. this bug was caught due to the recent `assert`s that were added in 01f3cf2. Closes: https://codeberg.org/nsxiv/nsxiv/issues/422 Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/423 Reviewed-by: eylles <eylles@noreply.codeberg.org> Reviewed-by: explosion-mental <explosion-mental@noreply.codeberg.org>
2023-01-28update copyright yearNRK
2023-01-26don't spoil errno in sig handler (#411)NRK
reported by thread-sanitizer. the sighandler's spoiled `errno` was causing xlib to incorrectly assume some error occurred and thus causing the crash described in #391. to reproduce: * Open an nsxiv window * Open another terminal and run the following: var=$(pidof nsxiv); while :; do kill -s SIGCHLD $var; done putting the `pid` into a variable is actually important because doing `$(pidof nsxiv)` inside the loop makes it really hard to reproduce the issue, I presume because of the extra process invocation it was sending less SIGCHLD and so putting it into a variable avoids that overhead and is able to generate more signals. instead of reaping the zombies manually, we now pass the `SA_NOCLDSTOP|SA_NOCLDWAIT` for SIGCHLD instead so that the zombies are reaped automatically. Closes: https://codeberg.org/nsxiv/nsxiv/issues/391 Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/411 Reviewed-by: explosion-mental <explosion-mental@noreply.codeberg.org>
2023-01-09read win-title in non-blocking manner (#314)NRK
Closes: https://codeberg.org/nsxiv/nsxiv/issues/313 Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/314 Reviewed-by: eylles <eylles@noreply.codeberg.org>
2023-01-09spawn(): improve performance and simplify APINRK
posix_spawn() is designed especially for this purpose, and thus it's much more lightweight and efficient than manually fork/dup/exec-ing. on my system, it improves the performance of spawn() by about 10x. given that we make frequent calls to potentially multiple scripts, the increased efficiency will add up overtime. using posix_spawn() also simplifies the logic quite a bit, despite the very verbose function names. however it does make cleanup a bit more complicated. this patch uses the linux kernel style cleanup strategy [0] (which I'm personally not a huge fan of, but it fits this situation quite nicely) with a "stack-like" unwinding via `goto`-s. additionally simplify the spawn() API by taking in {read,write}fd pointers and returning the pid instead of using some custom struct. this coincidently also fixes #299 [0]: https://www.kernel.org/doc/html/v4.10/process/coding-style.html?highlight=goto#centralized-exiting-of-functions
2022-12-22add brightness and contrast (#396)Berke Kocaoğlu
* Imlib2 supports modifying gamma, brightness and contrast directly while sxiv only supports gamma. Makes sense to extend it to brightness and contrast as well. * Since color corrections need to be aware of each other, they have been refactored into one centralized function. * This also makes the code more hackable as it makes it easier to add more color correction functions without them interfering with each other. Co-authored-by: 0ion9 <finticemo@gmail.com> Co-authored-by: NRK <nrk@disroot.org> Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/396 Reviewed-by: NRK <nrk@disroot.org> Reviewed-by: TAAPArthur <taaparthur@noreply.codeberg.org> Co-authored-by: Berke Kocaoğlu <kberke@metu.edu.tr> Co-committed-by: Berke Kocaoğlu <kberke@metu.edu.tr>
2022-10-30accept directory via stdin (-i) (#383)NRK
this basically just extracts the logic that was previously inside `main()` into a seperate function `add_entry()` so that it can be used for accepting entries form stdin as well. Closes: https://codeberg.org/nsxiv/nsxiv/issues/382 Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/383 Reviewed-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
2022-10-19code-style: misc changes (#374)NRK
* ensure static variables comes after non-static ones * remove depreciated DATA32 type * prefer `sizeof(expression)` over `sizeof(Type)`. * silence a -Wsign warning * {gif,webp} loader: use a pointer to reduce code-noise * gif loader: allocate in one place Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/374 Reviewed-by: TAAPArthur <taaparthur@noreply.codeberg.org>
2022-09-05remove some hardcoded "nsxiv", use progname insteadNRK
2022-08-16code-style: don't indent switch cases (#358)explosion-mental
The suckless coding style [^0] and the linux coding style [^1] both recommends not indenting switch cases. And it helps out people with lower resolution monitors. [^0]: https://suckless.org/coding_style/ [^1]: https://www.kernel.org/doc/html/v5.10/process/coding-style.html#indentation Co-authored-by: explosion-mental <explosion0mental@gmail.com> Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/358 Reviewed-by: NRK <nrk@disroot.org> Co-authored-by: explosion-mental <explosion-mental@noreply.codeberg.org> Co-committed-by: explosion-mental <explosion-mental@noreply.codeberg.org>
2022-08-16code-style: various cleanups (#356)NRK
* run_key_handler: make the logic easier to follow * remove timeout_t the typedef is not needed. inline the declaration similar to the other static structs. * simplify estrdup reuse emalloc, instead of calling malloc and null-checking. * win_clear: initialize `e` right away * process_bindings: explicitly check against NULL most pointer checks in the codebase do explicit check. * use a named constant instead of magic number also changes the padding from 3 to 4 bytes according to [0]. but i couldn't find any situtation where this mattered, so perhaps the current padding is enough. but doesn't hurt adding one more byte. [0]: https://nullprogram.com/blog/2017/10/06/ Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/356 Reviewed-by: explosion-mental <explosion-mental@noreply.codeberg.org>
2022-07-30autoreload: simplify and cleanup (#342)NRK
the current code is quite hacky and complex as it mixes multiple pointers. all of this complexity is unnecessary. drop it by introducing an explicit scratch buffer instead of implicitly abusing `arl->filename` as one. this also reduces some unnecessary allocation overhead. additionally, the argument to arl_setup must be the result of `realpath(3)` (as commented in `nsxiv.h`). instead of commenting it, assert it. and lastly, rename `arl_setup` to `arl_add` since it's not doing any "setup" but rather *adding* a file to watch. Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/342 Reviewed-by: explosion-mental <explosion-mental@noreply.codeberg.org>
2022-07-26fix: stale statusbar when started in thumbnail mode (#341)NRK
this was one of the cases which got missed in 591be8c, if someone starts with `-t` the statusbar will remain at "Loading ...". Once we're done loading all the thumbnail, make sure to open_info() so that `thumb-info` gets called. Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/341 Reviewed-by: explosion-mental <explosion-mental@noreply.codeberg.org>
2022-07-15fix: -Wsign-compare warnings (#336)NRK
mixing signed and unsigned types in comparison can end up having unintended results. for example: if (-1 < 1U) printf("true\n"); else printf("false\n"); previously we silenced these warnings, instead just fix them properly via necessary casting, and in cases where the value cannot be negative (e.g width/height members) make them unsigned. Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/336 Reviewed-by: explosion-mental <explosion-mental@noreply.codeberg.org>
2022-06-28sort and group includesNRK
* includes are sorted alphabetically * their grouping and layout is the following: - nsxiv.h will be the first include - followed by any internal headers (e.g "commands.h" "config.h") - followed by system headers (<stdlib.h> etc) - followed by third party headers (X.h libwebp etc) * also add `llvm-include-order` check to clang-tidy so that it can catch unsorted includes during CI.
2022-06-28code-style: cleanup includesNRK
* rm unused include <sys/types.h> * move <sys/time.h> to main.c, it's the only file that needs it. * move TV_* macros to main.c * let *.c files explicitly include what they need instead of including them at nsxiv.h
2022-06-25fix: don't use reserved identifiersNRK
identifiers beginning with an underscore is reserved by the C standard.
2022-06-25fix: potentially printing wrong error message (#321)NRK
it's possible for the close() calls to override the errno resulting in incorrect error message being printed. call error() immediately to avoid such possibilities. also refactor a couple conditions to avoid doing multiple checks. Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/321 Reviewed-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
2022-06-02code-style: simplify window title related codeNRK
instead of dancing around with some `init` parameter, directly give `win_set_title()` what it needs. `get_win_title()` now also does *just* what the name says. this simplifies things quite a bit and the functions now do what their name implies more closely instead of doing some `init` dance internally.
2022-06-02reduce calls to win-titleNRK
rather than calling the script unconditionally per redraw, we now have a `title_dirty` flag and keep track of when any of the relavent information changes. Co-authored-by: Arthur Williams <taaparthur@gmail.com> Partially fixes: https://github.com/nsxiv/nsxiv/issues/258
2022-05-28fix: broken slideshow if redraw takes too long (#282)N-R-K
currently the way check_timeout() is implemented, animate has higher priority than slideshow. so if doing a redraw takes longer than the frame delay of the animated image then it's going to continuously keep animating and never reliably get to slideshow. this issue can occur if the animated image has too fast of a delay or if nsxiv is being run on a slow system where doing redraw takes too long. the issue can be emulated by artificially slowing down img_render by sticking a sleep in there. diff --git a/main.c b/main.c index 5dc52d4..0580011 100644 --- a/main.c +++ b/main.c @@ -441,6 +441,7 @@ void redraw(void) if (mode == MODE_IMAGE) { img_render(&img); + nanosleep(&(struct timespec){0, 62000000}, NULL); /* 62ms */ if (img.ss.on) { t = img.ss.delay * 100; if (img.multi.cnt > 0 && img.multi.animate) make it so that slideshow has higher priority than animate to fix the issue. Closes: https://github.com/nsxiv/nsxiv/issues/281
2022-05-19fix: broken statusbar after key-handler cancellationNRK
to reproduce: 1. have an image-info script 2. invoke the key-handler 3. cancle invocation by pressing `escape` at this point, the statusbar ends up being empty. the regression seems to be caused by 6922d5d (changing select to poll), unsure why that is. in any case, this simplifies read_info quite a bit and solves the regression as well. in short: * read straight into the statusbar buffer * if read succeeds, make sure buffer is null terminated and replace any newline with space * close the script
2022-05-19fix: don't override statusbar if info script doesn't existNRK
this happens when the keyhandler is invoked while viewing an animated image. if {image,thumb}-info scripts exists, everything works as expected. but if they don't, then update_info will override the statusbar.
2022-05-19fix: broken thumbnail statusbar after running keyhandlerNRK
2022-05-12check_timeouts: avoid unnecessary conversions (#273)N-R-K
before we were using select, which expected `struct timeval` as arg. so we needed to do ms -> timeval conversions. but now since we're using poll, which accepts milisec as arg, there's no need to do ms -> timeval -> ms. instead have check_timeouts directly return ms.
2022-05-03Declare every extern function/variable in `nsxiv.h` (#268)N-R-K
with a couple exceptions as they cause too many -Wshadow warnings. also moves the `extcmd_t` typedef on top for cosmetic purposes. also enable `-Wmissing-prototypes` in the ci
2022-05-03Add thumb-info (#265)N-R-K
Closes: https://github.com/nsxiv/nsxiv/issues/88 Closes: https://github.com/nsxiv/nsxiv/pull/253
2022-04-28replace select() with poll() (#270)N-R-K
usage of select (3) in modern programs is typically discouraged. this simply replaces the select call with poll (3) instead. and since poll conveniently ignores negative fds, this also reduces needs for some special casing. this also handles error if they occur, while old implementation didn't. other than the error handling, no change in functionality should occur.
2022-03-27fix: thumbnail memory leak when removing file (#247)N-R-K
2022-03-17fix: close the file descriptor in get_win_title() (#245)N-R-K
this would eventually end up opening too many fds and erroring out with "too many open files".
2022-03-02always initialize window titleNRK
before if exec/win-title didn't exist then window title wouldn't be set. this patch makes it so window title is always set to something.
2022-03-02code-style: slight cleanupsNRK
* put TOP_STATUSBAR under the HAVE_LIBFONTS guard * change get_win_title param to take unsigned char ptr * init UTF8_STRING like other atoms
2022-02-23use win-title script for customizing window title (#213)N-R-K
this removes the cli flag `-T` as well as related config.h options. Co-authored-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
2022-02-20Add reuseable abstraction over fork/exec/dup2 (#211)N-R-K
2022-02-17declare internal variables as staticNRK
2022-02-17code-style: prefer calloc over malloc+memsetNRK
2022-02-13update copyright yearNRK
2022-01-10make thumbnail bindings configureable via config.h (#167)N-R-K
this allows for configuring thumbnail mode mouse bindings similar to image mode bindings. however we can't put the thumbnails bindings into the existing buttons[] array due to fallthrough. For example M3 would switch mode and then end up selecting an image. which is why thumbnail bindings have been put into it's own array `buttons_tns[]` and `buttons[]` has been renamed to `buttons_img[]` for consistency. Closes: https://github.com/nsxiv/nsxiv/issues/131
2022-01-06fix -Wshadow related warningsNRK
fixes all -Wshadow related warnings (on gcc). this would allow us to use `-Wshadow` in github workflow (https://github.com/nsxiv/nsxiv/pull/195). i've thought about adding `-Wshadow` to our Makefile as well, but decided against it to keep the Makefile CFLAGS barebore/minimal.