Commit Graph

132 Commits (master)

Author SHA1 Message Date
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
eylles 733916ad70 add a pick quit keybind (#432)
The last time[0] this was discussed, no-one was against it but no-one
was confident in it either and so it was added to nsxiv-extra as a
patch.

But now that enough time has passed, it seems like there's a pretty high
demand for something like this because there's plenty of use-cases that
use nsxiv as a "picker" where it's meant to quickly pick a single file.

And so add this as a convenient default key-bind.

[0]: https://codeberg.org/nsxiv/nsxiv-record/pulls/42

Co-authored-by: eylles <ed.ylles1997@gmail.com>
Co-authored-by: NRK <nrk@disroot.org>
Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/432
Reviewed-by: NRK <nrk@disroot.org>
Co-authored-by: eylles <eylles@noreply.codeberg.org>
Co-committed-by: eylles <eylles@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 6ffc64a04e img_t: rename alpha -> alpha_layer for consistency 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 3804b50656 compress duplicated logic into a function (#384)
Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/384
Reviewed-by: TAAPArthur <taaparthur@noreply.codeberg.org>
2 years ago
NRK 8dc126194f fix: statusbar not updating when switching bar (#353)
Closes: https://codeberg.org/nsxiv/nsxiv/issues/352
Reviewed-on: https://codeberg.org/nsxiv/nsxiv/pulls/353
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 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 591be8cecf
Add thumb-info (#265)
Closes: https://github.com/nsxiv/nsxiv/issues/88
Closes: https://github.com/nsxiv/nsxiv/pull/253
2 years ago
N-R-K 29c6b1456e
code-style: reduce some unnecessary if-elses (#261)
also change the condition inside img_frame_animate() to check for
positive value rather than comparing against 0.
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 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
2 years ago
NRK 80ada33c66 fix tcc warning 2 years ago
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.
2 years ago
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>
2 years ago
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>
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
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
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
N-R-K 6ce94e3e3b
add statusbar message upon key-hander activation (#98)
Currently when running the key-handler the statusbar shows a
"Running key-handler..." message, but there's no indication of the prefix key
being pressed.

There's a slight functional benefit of this patch in the sense
that users can visually tell if the key-handler is listening on input or if the
key-handler has been aborted or not.
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
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
Bert Münnich 1613b42411 Simplify cg_mark_range further 6 years ago
Bert Münnich 1de5f06f83 Set global markidx whenever a single img is (un)marked
This also sets *markidx* when using the right mouse button in thumbnail mode.
6 years ago
Bert Münnich 87a1ace8a1 (Un)mark single image through generic function 6 years ago
Bert Münnich 1892ed9fd7 Simplify cg_mark_range 6 years ago
Bert Münnich a1165df878 Rename variable toggledidx to markidx 6 years ago
Bert Münnich cc476be7cc Remove unnecessary special cases in cg_mark_range 6 years ago
Daniel Lublin 6e696ba98c Add mark range function
Sets the marked state of all images ranging from the latest marked/unmarked
image to the current image, to the state of that latest toggled image.
6 years ago
Bert Münnich 762420cdf1 Close image-info explicitly 6 years ago
phi d5c5708110 Use argument to select between two drag methods 6 years ago
Bert Münnich 148026007c One header file for type definitions and function declarations 7 years ago
Bert Münnich 8081cbebf3 Improve mouse support
None of the mouse mappings uses a keyboard modifier, making it possible to
access the most basic features by only using the mouse.

Next/previous image with left button depending on cursor position, middle
button for dragging, right button for switching to thumnail mode and wheel for
zooming.

Users can keep the old behaviour by simply not adapting the changes to the
buttons array in config.def.h to their config.h file.
7 years ago
Bert Münnich ee908ca0a1 Simplify cursor reset in image mode
No need to give cursor name. reset_cursor() is now the only place to decide
what cursor to fall back to.
7 years ago
Bert Münnich d81442f55d Own win method for mouse cursor location 7 years ago
Bert Münnich e310136e02 Mouse drag translates pointer position to image area
This makes mouse panning more direct and faster.
7 years ago
Bert Münnich ff2ce99bf7 Merge djhejna/floatdelay 8 years ago
Bert Münnich f75fa78eca Make navigate_frame command respect a count prefix 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