Commit Graph

169 Commits (master)

Author SHA1 Message Date
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.
11 months ago
explosion-mental 3097037624 make xresources class name configurable in config.h 11 months ago
blk_750 824b2cb885 fix: memory leak in `win_draw_bar` (#444)
Closes: https://codeberg.org/nsxiv/nsxiv/issues/410
Co-authored-by: blk_750 <blk_750@protonmail.com>
Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/444
Reviewed-by: NRK <nrk@disroot.org>
Co-authored-by: blk_750 <blk_750@noreply.codeberg.org>
Co-committed-by: blk_750 <blk_750@noreply.codeberg.org>
1 year 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 2434e83807 make some changes prepping for clang-format
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
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>
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 5cab2fb525 reject empty xresources (#340)
currently, in case of an empty xresources we would fail to init:

	nsxiv: Error allocating color ''

instead, just reject empty value and use the fallback.

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

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/340
Reviewed-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
Co-authored-by: NRK <nrk@disroot.org>
Co-committed-by: NRK <nrk@disroot.org>
2 years ago
NRK 51d4c8dd4f check for utf8_decode errors (#327)
utf8_decode() may return an errors, in which case the returned codepoint
might be garbage. the issue can be tested by adding the following to
`image-info` which produces invalid utf8 sequences:

	base64 -d << EOF
	9JCAgPSQgIH0kICC9JCAg/SQgIT0kICF9JCAhvSQgIf0kICI9JCAifSQgIr0kICL9JCAjPSQgI30
	kICO9JCAj/SQgJD0kICR9JCAkvSQgJP0kICU9JCAlfSQgJb0kICX9JCAmPSQgJn0kICa9JCAm/SQ
	gJz0kICd9JCAnvSQgJ8=
	EOF

on my system, this leads to the statusbar being filled with empty boxes.

check for returned error and skip the iteration.

Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/327
Reviewed-by: Berke Kocaoğlu <berke.kocaoglu@metu.edu.tr>
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 b28449e10c fix: don't use reserved identifiers
identifiers beginning with an underscore is reserved by the C standard.
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
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 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 ec5a51d798
fix: correctly close the font (#250)
currently we immediately close the font on win_init_font(), which was
introduced in 0d8dcfd. this was probably not correct since we use `font`
later in win_draw_text().

instead, the font should be closed at exit/cleanup.
2 years ago
Kim Woelders 14e9c34ecc Improve starting in fullscreen mode
Instead of effectively first mapping the window at regular size and then
fullscreening it, tell the WM to map the window at fullscreen size by
setting _NET_WM_STATE_FULLSCREEN before mapping the window.
2 years ago
Kim Woelders e9468d3d36 Correct setting of _NET_WM_PID
The property _NET_WM_PID is a CARDINAL which per definition has format
32, whatever the size of pid_t may be.
CARDINALS (and other format 32 items) must always be passed to Xlib in
long's, whatever the size of long may be.
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
NRK 9cdeeab9b8 update copyright year 2 years ago
NRK 8cc5cee08f fix -Wwrite-strings related warnings 2 years ago
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
3 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
Arthur Williams 8934744c60 Add colors and fonts to config.h (#115)
Adds a set of config vars to control window fg/bg, bar fg/bg, mark
color and bar font. This allows everything that can be done from
.Xresources to be configurable from config.h.

Co-authored-by: N-R-K <79544946+N-R-K@users.noreply.github.com>
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 7e7eaf08f1
fix: memory leak due to not destroying XrmDatabase (#134) 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
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 c093eae971
code-style: use constant length array (#79)
currently the code-base doesn't make use of variable length array
despite being -std=c99. it was irresponsible of me to introduce VLA in
here.

since this function will be called quite often, i did not want to make
calls to malloc and free as they have some overhead.

512 should be sufficient enough and probably is far bigger than any
window title bar can display anyways.
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
Sam Whitehead 0d8dcfd521
Fix font memory leak. (#57)
* Fix font memory leak.

This memory leak has always been present in sxiv.

The font opened on window.c:58 was never closed, so I closed it, fixing a 2kB memory leak.

* document changes

Co-authored-by: NRK <nrk@disroot.org>
3 years ago
N-R-K 0b20783164 change .font to .bar.font for consistency (#48) 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
eylles d8ec6f91a9 Set the _NET_WM_PID and WM_CLIENT_MACHINE X properties (#13)
Set the _NET_WM_PID and WM_CLIENT_MACHINE X properties

Co-authored-by: Leon Kowarschick <lkowarschick@gmail.com>
Co-authored-by: Kian Kasad <kian@kasad.com>
Co-authored-by: NRK <nrk@disroot.org>
3 years ago
Berke Kocaoğlu c7ca547b55 Fix in tabbed with alpha patch (#3)
* Fix in tabbed with alpha patch

Co-authored-by: Jared Forrest <jared_forrest@mailbox.org>
3 years ago
Arthur Williams ba0d87fadf Added ICCCM WM_HINTS
When the window is mapped, some ICCCM WM_HINTS are set.
The input field is set to true and state is set to NormalState.

To quote the spec, "The input field is used to communicate to the window
manager the input focus model used by the client" and "[c]lients with
the Passive and Locally Active models should set the input flag to
True". sxiv falls under the Passive Input model, since it expects keyboard
input, but only listens for key events on its single, top-level window instead
of subordinate windows (Locally Active) or the root window (Globally Active).

From the end users prospective, all EWMH/ICCCM compliant WMs (especially
the minimalistic ones) will allow the user to focus sxiv, which will
allow sxiv to receive key events. If the input field is not set, WMs are
allowed to assume that sxiv doesn't require focus.
3 years ago
Bert Münnich d9e60cb4c0 Fix memory leak in win_res()
Fixes issue #372.
4 years ago
Bert Münnich 07300da7df Do not keep track of fullscreen state
There is no more need for this after the removal of the special color handling
for fullscreen mode in commit 2886876.
5 years ago
Bert Münnich 28868767e6 Use normal win colors in fullscreen mode
Fixes issues #361 and #367
5 years ago