Commit Graph

340 Commits

Author SHA1 Message Date
NRK
b11384a694 code-style: misc changes (#374)
* 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-10-19 14:46:22 +02:00
NRK
7e3e6008fe remove some hardcoded "nsxiv", use progname instead 2022-09-05 03:52:51 +02:00
explosion-mental
0f0c49a630 code-style: don't indent switch cases (#358)
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-16 10:54:31 +02:00
NRK
6578e6eb65 code-style: various cleanups (#356)
* 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-08-16 10:53:05 +02:00
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>
2022-07-30 10:05:10 +02:00
NRK
dd0b3cb163 fix: stale statusbar when started in thumbnail mode (#341)
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-26 07:20:39 +02:00
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>
2022-07-15 22:46:23 +02:00
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.
2022-06-28 21:28:06 +02:00
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
2022-06-28 21:28:06 +02:00
NRK
b28449e10c fix: don't use reserved identifiers
identifiers beginning with an underscore is reserved by the C standard.
2022-06-25 08:27:01 +02:00
NRK
658a935c04 fix: potentially printing wrong error message (#321)
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-25 08:21:05 +02:00
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.
2022-06-02 08:09:51 +00:00
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
2022-06-02 08:09:51 +00:00
N-R-K
450797c573
fix: broken slideshow if redraw takes too long (#282)
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-28 06:48:44 +00:00
NRK
b4268fbf38 fix: broken statusbar after key-handler cancellation
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-19 11:44:30 +00:00
NRK
f255e1cc12 fix: don't override statusbar if info script doesn't exist
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-19 11:44:30 +00:00
NRK
3bf198ecd3 fix: broken thumbnail statusbar after running keyhandler 2022-05-19 11:44:30 +00:00
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.
2022-05-12 14:47:46 +00:00
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
2022-05-03 15:36:57 +00:00
N-R-K
591be8cecf
Add thumb-info (#265)
Closes: https://github.com/nsxiv/nsxiv/issues/88
Closes: https://github.com/nsxiv/nsxiv/pull/253
2022-05-03 15:34:23 +00:00
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.
2022-04-28 03:12:15 +00:00
N-R-K
bf6c062779
fix: thumbnail memory leak when removing file (#247) 2022-03-27 09:34:44 +00:00
N-R-K
1ef0c1f152
fix: close the file descriptor in get_win_title() (#245)
this would eventually end up opening too many fds and erroring out with
"too many open files".
2022-03-17 19:18:22 +00:00
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.
2022-03-02 09:32:35 +00:00
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
2022-03-02 09:32:35 +00:00
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>
2022-02-23 09:23:22 +00:00
N-R-K
ad95012be9
Add reuseable abstraction over fork/exec/dup2 (#211) 2022-02-20 15:54:29 +00:00
NRK
79556e9b02 declare internal variables as static 2022-02-17 06:16:19 +00:00
NRK
48343e99b8 code-style: prefer calloc over malloc+memset 2022-02-17 06:16:19 +00:00
NRK
9cdeeab9b8 update copyright year 2022-02-13 19:35:58 +03:00
N-R-K
7a75c42b37
make thumbnail bindings configureable via config.h (#167)
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-10 16:52:06 +00:00
NRK
90bec70e7f fix -Wshadow related warnings
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.
2022-01-06 17:53:02 +00:00
N-R-K
1a18523772
fix: reset statusbar after failed keyhandler (#191)
currently if the keyhandler invocation fails, for example due to it not
being present, the statusbar does not reset and stays on "getting
keyhandler input" message.

now the return value from run_key_handler() is used to determine if the
function was successful or not. and if the function failed, we call
handle_key_handler() with false which resets the statusbar.

we also no longer call redraw() within run_key_handler() and instead assign
it's return value to dirty which does a redraw if true.
2022-01-03 09:24:26 +00:00
N-R-K
0f3766eaab
fix: animation slowdown when zoomed in (#200)
rendering is a pretty expensive operation, especially when scaling with
anti-aliasing. by waiting for the image to render before setting
timeout, the actual timeout ends up being (render time + actual delay).

this pretty much fixes the slowdown entirely on all the images i've
tested. it should also improve things noticeably even in cases where
the delay between frames is shorter than how fast we can render.
although on such images, the issue may not be fixed entirely.

Closes: https://github.com/nsxiv/nsxiv/issues/70
2022-01-03 02:07:43 +06:00
N-R-K
ff88908531
specify func argument and related cleanup (#183)
* specifies the function argument type in commands.h compared to leaving
  it unspecified. all the functions in cmd_t must have arg_t as it's
  argument.
* changes to commands.h will now trigger a rebuild - this restores old
  behavior prior to 12efa0e
* cg_quit now uses it's argument as exit status
* DestroyNotify invokes cg_quit rather than calling exit directly.
* Explicitly pass EXIT_SUCCESS to cgquit in keybinding

Co-authored-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
2021-12-19 23:05:35 +06:00
N-R-K
3bc7082f4e
fix: send implicit_mod to process_bindings (#176)
* fix: send implicit_mod to process_bindings

this solves the edge case where someone might have `ShiftMask + A` in
their keybindings compared to a plain `A`.

Closes: https://github.com/nsxiv/nsxiv/pull/166#issuecomment-978853136

* code-style: smuggle small style fix in

win_draw_bar now mimics autoreload_nop.c functions
2021-12-01 05:41:22 +06:00
N-R-K
4396031233
switch back to whitelisting modifers (#150)
* Revert "Allow any set of modifiers to be used in keybindings"

this keeps things equal with sxiv while giving users possibility to
customize USED_MODMASK if they wish.

This reverts commit 3234b0e521.

Closes: https://github.com/nsxiv/nsxiv/issues/149
Closes: https://github.com/nsxiv/nsxiv/issues/123

Co-authored-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
2021-11-24 11:44:05 +00:00
N-R-K
0262988671
rename: keyhandler_abort -> KEYHANDLER_ABORT (#172)
with the exception of arrays, all other var names in config.h are in ALL
CAPS. since keyhandler_abort is an unreleased feature, it should be okay
to rename it for consistency.

though.. in the future we should be more careful about naming when
adding new vars to config.h (or the codebase in general.)
2021-11-24 14:38:25 +03:00
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;
}
```
2021-11-20 03:51:49 +00:00
NRK
43fcd2e02e set env var NSXIV_USING_NULL for key-handler and update docs
Co-authored-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
2021-11-19 17:02:50 +06:00
NRK
2df33208d7 apply -0 to stdin/-i as well
while i was initially against this since it can be done via `xargs -0`.
the problem with this approach is that there's a limit to how many args
a command can recieve, leading to problem like this [0] when opening
large (1k~) amount of images.

there's no limit on how big stdin can be, so being able to read a
null-separated list from stdin doesn't have this problem.

[0]: https://github.com/ranger/ranger/pull/2307#issuecomment-818683515
2021-11-19 17:02:50 +06:00
N-R-K
4a282da692
use dedicated function to process key/button bindings (#166)
Co-authored-by: Arthur Williams <taaparthur@gmail.com>
2021-11-19 05:49:42 +00:00
LuXu
36f42081d0
make width of navigation area configurable (#155)
this allows users to configure navigation width from config.h. it also
allows disabling the navigation function entirely by using a 0 width.

one extra functionality this adds is being able to define an absolute
width (in pixels) instead of just percentage via `NAV_IS_REL`.

Co-authored-by: NRK <nrk@disroot.org>
2021-11-04 04:20:28 +00:00
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
2021-10-29 17:45:55 -06:00
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>
2021-10-29 02:00:53 +06:00
eylles
5b3221cfa6
update copyright notice (#139) 2021-10-28 16:41:16 +06:00
javad
bbebd45ce6 code-style: remove extra casts (#130)
Co-authored-by: N-R-K <79544946+N-R-K@users.noreply.github.com>
2021-10-24 06:41:17 +06:00
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
2021-10-13 06:05:00 +06:00
Arthur Williams
5c6947c1c6 Make imgcursor a config variable.
Previously, the value of imgcursor was determined by where a pointer
binding was set to a ci_cursor_navigate. If it was then the pointer
would change to left/right arrows depending on the position relative to
the window. Now the user has full control of over it which also allows
them to preserve the behavior in case they wrap the function.
2021-10-13 06:05:00 +06:00
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>
2021-10-11 09:07:18 +06:00