Commit Graph

358 Commits (master)

Author SHA1 Message Date
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.
2 years ago
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
3 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>
3 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 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>
3 years ago
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.)
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
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>
3 years ago
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
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
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
javad bbebd45ce6 code-style: remove extra casts (#130)
Co-authored-by: N-R-K <79544946+N-R-K@users.noreply.github.com>
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
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.
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
N-R-K 0c66c0e25f
make ten_ms local to run (#101)
ten_ms needed to be a global but after the following commit
3724d3fc17 this no longer holds true.
it can simply be local to run, as it's not used anywhere else.
3 years ago
NRK 4ec8fd5377 make keyhandler abort key configurable via config.h 3 years ago
NRK 3bec517655 fix: unable to bind anything to XK_Escape 3 years ago
Arthur Williams 3234b0e521 Allow any set of modifiers to be used in keybindings
Previous the code only allowed ShiftMask,ControlMask or Mod1Mask to be
used in keybindings and the presence of any others modifiers would be
ignored. Most problems generally allow certain modifiers to be be
ignored but not most and certainly don't allow Super-A to be treated
like A.
Now users can use any modifiers they want in keybindings and can also
ignore any modifiers they want. By default only ModMask2 (commonly
numlock is ignored)

Co-authored-by: N-R-K <79544946+N-R-K@users.noreply.github.com>
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
Arthur Williams 9c73646d9c Exit when window is destroyed
If the user closed our window, the program won't automatically be die.
It may look dead as there would be no graphical indication that it was
running, but it still would be using/wasting the same resources.
Now the program will abruptly exit when its window is killed.
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
Bert Münnich 55777ba9f4 Fix indentation 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 674f69f2c9 Fix file list indexes when deleting last image
Fixes issue #331
6 years ago
Bert Münnich 0bf3265430 Set window title only once at startup
Putting image info in the title predates the info bar; it no longer seems
necessary.

Fixes issue #318.
6 years ago
Kacper Gutowski e6c9218319 Don't skip dot files when cleaning cache 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 5367b75867 (Un)mark thumbnails while holding Button3 down 6 years ago
Bert Münnich 87a1ace8a1 (Un)mark single image through generic function 6 years ago
Bert Münnich a1165df878 Rename variable toggledidx to markidx 6 years ago
Bert Münnich 1e5cc7e382 Fix cg_mark_range after removing images from file list 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 09b04d7aef Revise waiting for child processes 6 years ago
Bert Münnich 762420cdf1 Close image-info explicitly 6 years ago
Bert Münnich 4124857137 Skip imlib cache when reloading due to inotify event 6 years ago
Bert Münnich 8017b75de4 Refactoring 7 years ago
Hyleus 6d261b4e7a Fix a potential uninitialized variable 7 years ago
Bert Münnich 8a9e3ea43e Separate bar fields only by spaces 7 years ago
Bert Münnich 30e2356622 Remove obsolete files[].base 7 years ago
Bert Münnich 004fcd5c5b Left bar shows file name as given by user 7 years ago
Squibby eb96c71725 Try to match a fallback font if needed
Fixes #276

Instead of rendering the entire filename at once, Xft will let us do it
character by character. This will allow sxiv to query fontconfig for
a font that can provide any missing codepoints, if needed.

A known issue of this patch is that the "..." dots rendering will not
work properly for very long multibyte filenames. That is because we
cannot easily predict the final width of the rendered filename before
drawing it. I couldn't figure out a clean way to deal with this, so I
ended up just truncating the offending filenames.
7 years ago
Bert Münnich 64b885b6a9 Fix navigating from last to previous image over invalid files 7 years ago
Bert Münnich 2d34c4b9bf Set LC_COLLATE for -r file list sorting
Fixes issue #293.
7 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 e310136e02 Mouse drag translates pointer position to image area
This makes mouse panning more direct and faster.
7 years ago
Bert Münnich a20173a42d Detect all file overwrites in autoreload_inotify
mv(1) inside the same filesystem was not detected.

Supporting this case made it necessary to always watch the directory. Turns out
the logic and state keeping between arl_setup() and arl_handle() is easier,
when using different watch descriptors for the file and the directory and not
using a oneshot descriptor for the file.

Requiring an absolute canonical path for arl_setup() simplifies dir and base
name splitting. No need for dirname(3) and basename(3) anymore.
7 years ago
Bert Münnich 3724d3fc17 Revised autoreload interface
Make the header only contain the public interface and nothing from the
implementation. All functions get a handle to their self object, like the img_
and tns_ and win_ functions. All necessary data (file path) is also passed as
an argument, so that no extern redeclarations are needed.

Make arl_setup_dir() private, it's not called outside the module.

Make arl_handle() return true if the file has changed, so that the reloading of
the file can be done by the caller.
7 years ago
Max Voit edb117e3bd Add autoreload support by inotify (and dummy backend nop) 7 years ago
Bert Münnich 1fb3ec576c Properly quit when window gets closed; fixes issue #27 7 years ago
Jakub Wilk c313edc0ad Fix typo 7 years ago
Bert Münnich 5c607ad495 Pass given file names to key-handler instead of real paths
Misbehaving command lines in the key-handler that rewrite the given files and
thus replace symbolic links instead of their targets shall call realpath(1).

Fixes issue #205 and reverts commit 92e3b578.
8 years ago
Bert Münnich ff2ce99bf7 Merge djhejna/floatdelay 8 years ago
Bert Münnich 9a85dd41d8 Ignore button and key events while key-handler is running
Related to issue #253, which originally asked for a non-blocking key-handler.
8 years ago
Don Hejna 27bbaab976 Support for DELAY as a floating point number including less than 1
second while maintaining backward compatibiitiy with integer
arguments.
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 aabc2bddbd Provide image width and height to image-info script; fixes issue #159 8 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 b096cbd536 Removed unnecessary buffer size constants 9 years ago
Bert Münnich 9a7e97cd89 Use XSI realpath(3) 9 years ago
Bert Münnich 66c3c55759 Use POSIX.1-2008 getline(3) 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 a3838c1984 Always run image-info script after key-handler in image mode; fixes issue #213 9 years ago
Bert Münnich 92e3b57816 Pass real paths to key handler instead of the paths provided by the user
Programs called by the key handler might replace symlinks instead of their
targets.
10 years ago
Bert Münnich 47af0dd7b5 Cache out of view thumbnails in the background 10 years ago
Bert Münnich 9b9294bae6 Use bit-field for boolean flags in fileinfo struct 10 years ago
Bert Münnich 6216bf6c2d Ignore SIGPIPE, caused by key handler exiting before all files got printed, fixes issue #188 10 years ago
Bert Münnich 216ad81b59 Pass file paths to key handler via stdin; fixes issue #187 10 years ago
Bert Münnich 51854c6148 Fixed leakage of pipe descriptors in case of failing fork 10 years ago
Bert Münnich 93e2a757d4 Do not print could-not-open-warnings for files found by directory traversal 10 years ago
Bert Münnich c33f2ad355 Corrected & refactored handling of window bar content...
Old snprintf calls could have overflowed the buffers.
10 years ago
Bert Münnich 8db3191f04 Fixed segfault on image removal with uninitialized thumbnails; fixes issue #177 10 years ago
Bert Münnich ddd028eb3e Unified file count variable for image & thumbnail mode 10 years ago
Bert Münnich b2dbd2fed3 Changed image mark in thumbnail view to small rectangle 10 years ago
Bert Münnich 5fce009b73 Refactored main loop; properly fixes startup issue 10 years ago
Bert Münnich c1e084357c Fixed startup in thumbnail mode with floating window 10 years ago
Bert Münnich eaa269b6cb Revised thumbnail loading...
- Only load the thumbnails that are currently visible in the window
- Unload thumbnails that are leaving the visible area
- Much less memory needed, but scrolling is now slower
- This also unintentionally fixes issue #86
10 years ago
Bert Münnich 52e56c8924 Fixed segfault caused by image removal in thumbnail mode 10 years ago
Bert Münnich 2fbc21a205 Simplified img_frame_animate 10 years ago
Bert Münnich f478385d59 Corrected i_alternate, fixes issue #171 10 years ago
Markus Elfring 0f6cb93a09 Bug #165: Deletion of unnecessary null pointer checks
The function "free" performs input parameter validation.
http://pubs.opengroup.org/onlinepubs/9699919799/functions/free.html

It is therefore not needed to check a passed pointer before this function call.
A corresponding update suggestion was generated by the software "Coccinelle"
from the following semantic patch approach.
http://coccinelle.lip6.fr/

@Remove_unnecessary_pointer_checks1@
expression x;
@@
-if (x != \(0 \| NULL\))
    free(x);

@Remove_unnecessary_pointer_checks2@
expression x;
@@
-if (x != \(0 \| NULL\)) {
    free(x);
    x = \(0 \| NULL\);
-}

@Remove_unnecessary_pointer_checks3@
expression a, b;
@@
-if (a != \(0 \| NULL\) && b != \(0 \| NULL\))
+if (a)
    free(b);

@Remove_unnecessary_pointer_checks4@
expression a, b;
@@
-if (a != \(0 \| NULL\) && b != \(0 \| NULL\)) {
+if (a) {
    free(b);
    b = \(0 \| NULL\);
 }

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
10 years ago
Bert Münnich fe3a1e326f Further simplified thumbnail marks 10 years ago
Bert Münnich 50652f63d9 Full redraw when removing files during thumbnail reloading; fixes issue #164 10 years ago
Bert Münnich e49d38d6f9 Fixed wrong thumbnail-to-file mappings caused by file deletions 10 years ago
Bert Münnich e267dc7793 Pass marked files to external key handler in thumbnail mode; fixes issue #135 10 years ago
Bert Münnich 284be74927 Count number of marked files 10 years ago
Bert Münnich 5b01c15176 Unified file index variable for image & thumbnail mode 10 years ago
Bert Münnich 61f61cae5f Generalized thumbnail loading, allows easier reloading of thumbnails later on 10 years ago
Bert Münnich bb6721549b Overhauled window drawing, yet again; fixes issue #155
- Buffer for window content is bigger than the window, minimizes artifacts
  when window is resized
- Back to using XSetWindowBackgroundPixmap() instead of XCopyArea(),
  no need to handle exposure events; X server can show gray background directly
  after resize event before sxiv redraws the window contents
10 years ago
Bert Münnich 9c92de8584 Added support for multiple commands per key/button mapping; elegant fix for issue #150 10 years ago