Commit Graph

51 Commits (master)

Author SHA1 Message Date
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>
22 hours ago
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>
8 months ago
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>
8 months ago
NRK 53a43cb388 introduce img_free()
this removes some repetitive code.
9 months ago
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>
9 months ago
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>
11 months ago
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>
11 months ago
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>
1 year ago
NRK a051ad210d update copyright year 1 year ago
NRK 6ffc64a04e img_t: rename alpha -> alpha_layer for consistency 1 year ago
NRK 1f788a318b add cli flag --alpha-layer
now that we have long-opts, we don't have to worry about exhausting the
alphabet list for short-opts. so adding a cli flag to set/unset the
checker background makes sense.

ref: https://codeberg.org/nsxiv/nsxiv/issues/404
1 year ago
NRK 49d11f0d1f spawn(): improve performance and simplify API
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
1 year ago
Berke Kocaoğlu 95bc9b463b add brightness and contrast (#396)
* 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>
1 year ago
NRK daee34477a fix potential truncation of cli arguments (#367)
strtol() returns a `long`, but we're storing the result in an `int`
which might end up getting truncated. change `n` to `long` and guard
against >INT_MAX arguments in cases where it matters.

use a float for storing argument of `-S`

change `opt.slideshow` to `unsigned` similar to `img.ss.delay`

Co-authored-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/367
Reviewed-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
Reviewed-by: explosion-mental <explosion-mental@noreply.codeberg.org>
2 years ago
NRK e356add07c rename: aa -> anti_alias 2 years ago
NRK 88a480c938 allow disabling anti-aliasing via cli flag
simply running nsxiv with `--anti-alias` will enable anti-aliasing, and
running it with `--anti-alias=no` will disable it.

the cli flag will overwrite the config.h default.

Closes: https://codeberg.org/nsxiv/nsxiv/issues/349
2 years ago
NRK 94d531fd82 autoreload: simplify and cleanup (#342)
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>
2 years ago
NRK c131b1ed83 fix: -Wsign-compare warnings (#336)
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>
2 years ago
NRK b162aee497 sort and group includes
* 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.
2 years ago
NRK 6d5a04005d code-style: cleanup includes
* 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
2 years ago
NRK e9a0096d6d code-style: simplify window title related code
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.
2 years ago
NRK 810a9651a3 reduce calls to win-title
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
2 years ago
N-R-K 364c3d6f01
avoid doing dynamic allocation for bar buffers (#279)
just use a static buffer since the size is constant and doesn't change.

as opposed to using malloc, this also sets the buffer's initial memory
region to 0 by default.

also remove BAR_{L,R}_LEN from nsxiv.h, not needed after commit b4268fbf38
2 years ago
N-R-K 633a4f66d9
check_timeouts: avoid unnecessary conversions (#273)
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.
2 years ago
N-R-K 3a22e6a6c5
Declare every extern function/variable in `nsxiv.h` (#268)
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
2 years ago
N-R-K 6922d5d01b
replace select() with poll() (#270)
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.
2 years ago
NRK 700d9f46c7 fix: window title not working on certain WMs
not all WMs support `_NET_WM_NAME` and `_NET_WM_ICON_NAME`
this patch sets `WM_NAME` and `WM_ICON_NAME` inside win_set_title()

Closes: https://github.com/nsxiv/nsxiv/issues/233
2 years ago
NRK ad571e7448 always initialize window title
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.
2 years ago
NRK bdd9521bf3 code-style: slight cleanups
* put TOP_STATUSBAR under the HAVE_LIBFONTS guard
* change get_win_title param to take unsigned char ptr
* init UTF8_STRING like other atoms
2 years ago
N-R-K bda70867ac
add config.h option for top statusbar (#231)
Closes: https://github.com/nsxiv/nsxiv/issues/230
Co-authored-by: mamg22 <45301823+mamg22@users.noreply.github.com>
2 years ago
N-R-K e26c81fe9a
use win-title script for customizing window title (#213)
this removes the cli flag `-T` as well as related config.h options.

Co-authored-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
2 years ago
N-R-K ad95012be9
Add reuseable abstraction over fork/exec/dup2 (#211) 2 years ago
NRK 48343e99b8 code-style: prefer calloc over malloc+memset 2 years ago
NRK 9cdeeab9b8 update copyright year 2 years ago
Nick Hanley 2ac44709bd
Add keybind to scroll to image center (#203)
There are keybinds for scrolling to the edges of an image but there's no way back to the center. This is particularly annoying while zooming.
2 years ago
N-R-K f7145db7f8
remove unused function and typedef (#199)
byteorder_t and size_readable is not used anywhere within the code.

byteorder_t seems to be a remain from some time sxiv handled exif data itself instead of relying on a library, introduced in 691c6d7, and probably became irrelevant when libexif was added as dependency again. And size_readable from some time it displayed the file size in the window title, introduced in bad9a70.
2 years ago
N-R-K c6275374b0
mark functions and vars as static (#146)
the goal here to mark functions and variables not used outside the
translation unit as static. main reason for this is cleanliness. however
as a side-effect this can help compilers optimize better as it now has
guarantee that a certain function won't be called outside of that
translation unit.

one other side-effect of this is that accessing these vars/function from
config.h is now different.

if one wants to access a static var/func from different translation unit
in config.h, he would have to create a wrapper function under the right
ifdef. for static functions one would also need to forward declare it.
here's a dummy example of accessing the function `run_key_handler` from
config.h under _MAPPINGS_CONFIG

```
static void run_key_handler(const char *, unsigned);
bool send_with_ctrl(arg_t key) {
	run_key_handler(XKeysymToString(key), ControlMask);
	return false;
}
```
3 years ago
N-R-K 4a282da692
use dedicated function to process key/button bindings (#166)
Co-authored-by: Arthur Williams <taaparthur@gmail.com>
3 years ago
NRK d0b5005a02 -0 sends NULL separated file-list to key-handler
with this change `-0` is turned into a more generic switch which can be
used to send NULL-separated file-list to the key-handler as well.
this also means `-0` no longer implicitly enables `-o`

Closes: https://github.com/nsxiv/nsxiv/issues/140
3 years ago
N-R-K 850bc788c3
code-style: general cleanups (#137)
* tns_clean_cache: remove unused function arg

* remove malloc casting

* improve consistency

use sizeof(T) at the end

* avoid comparing integers of different signedness

* use Window type for embed and parent

* remove unnecessary comparisons

* remove cpp style comments

* improve consistency: remove comma from the end of enumerator list

* Removed useless _IMAGE_CONFIG defines

* consistency: use the same order as snprintf

* Resolve c89 warnings


Co-authored-by: uidops <uidops@protonmail.com>
Co-authored-by: Arthur Williams <taaparthur@gmail.com>
3 years ago
eylles 5b3221cfa6
update copyright notice (#139) 3 years ago
N-R-K f46d30591a
eleminate padding from struct img on 64bit systems (#136)
on 64bit systems this reduces the size of the struct from 104 bytes down
to 96 bytes.

on 32bits system this change shouldn't have any affect.
3 years ago
LuXu 57754572bc Add default key-binding for DRAG_RELATIVE (#117)
Ctrl-Button1 now has a relative drag using the XC_fleur cursor.
XC_fleur is normally the cursor for "size all" action, which has 4
arrows pointing to 4 directions.

Co-authored-by: NRK <nrk@disroot.org>
3 years ago
Arthur Williams 12efa0e3b4 Add ability to bind arbitrary functions.
Before all the predated commands where kept in an array and their
indexes were used in bindings. This meant that users couldn't add their
own functions from the config file. Now key/mouse bindings have been
changed to to store the function ptr (wrapped in a cmd_t struct to also
store the mode) directly instead.

General cleanup done in this commit:
Defined `MODE_ALL` instead of using magic number.

For example, suppose one had bindings like:
{ 0,                   XK_q,             g_quit,                     None },
{ ShitMask,            XK_q,             {quit_err},                 None }
{ ControlMask,         XK_q,             {quit_err, .mode=MODE_IMAGE}, None }

The existing binding `q` has been left unchanged and is defined the same
way. However, the new hypothetical binding `Shift-q` can be used to call
the custom function quit_err in any mode (default). `Ctrl-q` on the
other hand will be called only on image mode.

Closes #50
3 years ago
miseran cd710f583f
Fix behaviour when TrueColor / 24 bit depth is not available (#114)
* Fix regression introduced in c7ca547 which made nsxiv not start in
  non-TrueColor X server.
* Introduce a new fix for embedding into tabbed-alpha. 
* Fixes a visual glitch from original sxiv when drawing transparent images in 8
  bit depth. In 8 bit PseudoColor, `.pixel` is just an index into the 256
  defined colors and thus trying to extract rgb bits from it would result in
  visual glitch. The values `.color.red` on the other hand and so on are always
  integers between 0 and 0xFFFF representing the color as expected.
* Use XColor for win_bg/fg and mrk_fg

Co-authored-by: NRK <nrk@disroot.org>
3 years ago
Berke Kocaoğlu 1449bfc5e9
code-style: fix consistency issues all over the codebase (#94)
* remove duplicate comment
* remove empty tabs and blank lines
* move macros and globals ontop
* comment to seprate function implementation
* fix alignment
* switch to *argv[] similar to other suckless code
* kill all empty last lines
* append comment to endif
* reuse existing ARRLEN macro
* comment fall through
* use while (true) everywhere

Co-authored-by: NRK <nrk@disroot.org>
3 years ago
Arthur Williams 675db4bbb6 Make statusbar optional (#95)
libXft and libfontconfig are now optional dependencies which can be
disabled via `HAVE_LIBFONTS=0`. Disabling them means disabling the
statusbar. This also does not search for freetype2 header if disabled.

Co-authored-by: NRK <nrk@disroot.org>
3 years ago
Lu Xu a2339e70fd Use zoom steps instead of hard-coding levels (#92)
Co-authored-by: NRK <nrk@disroot.org>
Co-authored-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
3 years ago
N-R-K 63972db743
add -0 for outputting null-terminated list (#68)
* add -0 for outputting null-terminated list

this doesn't add much, if any, additional complexity to the codebase and
can be quite handy for scripting purposes.

Closes: https://github.com/nsxiv/nsxiv/issues/67

* Fix typo

Co-authored-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
3 years ago
NRK 25a5a54010 add .mark.foreground to Xresources
since we're already allowing both window and bar colors to be
customizable, it doesn't make sense to not allow so for mark color.
3 years ago