Commit Graph

167 Commits (a581cd6344717551c9bacae58809d83ae6979220)

Author SHA1 Message Date
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
4 months ago
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.
9 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>
9 months ago
NRK 53a43cb388 introduce img_free()
this removes some repetitive code.
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>
12 months ago
NRK f2f4903de4 apply clang-format
minus the bogus changes

Co-authored-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
1 year ago
NRK a051ad210d update copyright year 1 year ago
NRK 01f3cf2e47 use assertions instead of ignoring bogus arguments (#406)
instead of silently ignoring bogus arguments (i.e programming errors),
which can make debugging harder, it's better to assert them so that they
get caught faster in debug builds.

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/406
Reviewed-by: explosion-mental <explosion-mental@noreply.codeberg.org>
1 year ago
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>
2 years ago
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>
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 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 b28449e10c fix: don't use reserved identifiers
identifiers beginning with an underscore is reserved by the C standard.
2 years ago
NRK 9812d601c1 r_mkdir: don't truncate the path on error (#322)
currently, in case of error, r_mkdir will leave the path at a truncated
state.

a7d39b0ab8 is the commit that introduced this change, and in it the
error printing is moved from r_mkdir to the caller, which makes me think
it was probably intentional.

make it so that the function itself prints the error/warning
message and returns the path back to the caller unharmed.

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/322
Reviewed-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
Reviewed-by: TAAPArthur <taaparthur@noreply.codeberg.org>
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 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 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
NRK 48343e99b8 code-style: prefer calloc over malloc+memset 2 years ago
NRK 9cdeeab9b8 update copyright year 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 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
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
N-R-K 80c5a1cd9f
fix: crashing on bad exif thumbnail (#75)
this does not need to be a fatal error.
if im is NULL we're going to load it with imlib2 anyways.

one other problem this solves is that before, due to the fatal error,
the tmpfile opened under /tmp wouldn't get cleaned up.

Closes: https://github.com/nsxiv/nsxiv/issues/69
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
Berke Kocaoğlu 7cce7ea857 Rename, Update Docs and Prepare for Release (#9)
Co-authored-by: Guilherme Rugai Freire <41879254+GRFreire@users.noreply.github.com>
Co-authored-by: N-R-K <79544946+N-R-K@users.noreply.github.com>
Co-authored-by: NRK <nrk@disroot.org>
Co-authored-by: Arthur Williams <taaparthur@gmail.com>
Co-authored-by: eylles <ed.ylles1997@gmail.com>
3 years ago
qsmodo 156a53780c set title based on prefix and suffix (#23)
Co-authored-by: Guilherme Rugai Freire <41879254+GRFreire@users.noreply.github.com>
Co-authored-by: NRK <nrk@disroot.org>
Co-authored-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
3 years ago
Guilherme Freire f7557c55b5 Custom bar colors (#10)
* set bar and text colors independently

* change xresources to Program.class.resource

* rename color variables to win/bar_bg/fg

* change default bar colors to match window colors
3 years ago
Bert Münnich 28868767e6 Use normal win colors in fullscreen mode
Fixes issues #361 and #367
5 years ago
Bert Münnich 7b813ea06d Fix comparison broken by signedness
Warning generated on MacOS, reported in issue #350.
5 years ago
Bert Münnich 919ada1123 Align compile-time color options with X resource colors
Two colors are more than enough!
5 years ago
Kacper Gutowski e648c11899 Respect updated path format when cleaning cache
Since d8114e8 the file name is used for caching as-is without adding
.jpg at the end, but sxiv -c still expected old format causing it to
remove all fresh thumbnails.
6 years ago
Kacper Gutowski e6c9218319 Don't skip dot files when cleaning cache 6 years ago
Bert Münnich f02661879f Reject text files resembling TGA images
Fixes issue #295

The imlib2 TGA loader returns an imlib image handle without any actual data
when given a text file like this:

    T
    Content-Type: application/javascript
    Content-Length: 3836
    Last-Modified: Wed, 23 Sep 2015 12:25:47 GMT
    Etag: "56029a4b-efc"
    Expires: Sat, 20 Aug 2016 15:14:33 GMT
    Cache-Control: max-age=604800, public
    Accept-Ranges: bytes

Fortunately, `imlib_image_get_data()` returns NULL in this case, so that we can
use it as an additional check when opening files.
7 years ago
Bert Münnich 148026007c One header file for type definitions and function declarations 7 years ago
Antti Korpi ecc363ec10 Add -p flag to disable writing of cache and temporary files
Closes #285.
7 years ago
Bert Münnich 1c260e701b Fix unused-variable warnings in conditionally compiled code 8 years ago
Bert Münnich 878d97068c Only open regular files; fixes issue #252 8 years ago
Paride Legovini 86dc6860f9 Allow opening directories non-recursively 8 years ago
Bert Münnich c280129cef Use Xft for font loading and text drawing 8 years ago
Bert Münnich de4649fc28 Build-time option for default thumbnail size; fixes issue #207 9 years ago
Bert Münnich a7d39b0ab8 Simplified r_mkdir() 9 years ago
Bert Münnich d3a70a285d Revised error handling
- Functions warn() and die() replaced by GNU-like error(3) function
- Register cleanup() with atexit(3)
- Functions called by cleanup() are marked with CLEANUP and are not allowed to
  call exit(3)
9 years ago
Bert Münnich 851e4288c1 Prefix safe allocation functions with 'e' instead of 's_' 9 years ago
Bert Münnich e574a6d0dd Removed feature test macro definitions from source files 9 years ago
Bert Münnich e0e96977b3 Removed overcautious parameter checks 9 years ago
Bert Münnich d8114e841c Thumbnail cache file format depending on existance of alpha layer
Use PNG if image has alpha layer, JPG if not. Fixes issue #209
9 years ago