Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/feh.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include <X11/extensions/Xinerama.h>
#include <X11/X.h>
#endif /* HAVE_LIBXINERAMA */

/* Globals for passing key event info into actions (%k / %K in feh_printf) */
extern KeySym feh_current_action_keysym;
extern unsigned int feh_current_action_state;
extern unsigned int feh_current_action_button;






#include <stdio.h>
#include <string.h>
#include <stdlib.h>
Expand Down
17 changes: 17 additions & 0 deletions src/keyevents.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ struct __fehkey keys[EVENT_LIST_END];
struct termios old_term_settings;
unsigned char control_via_stdin = 0;

KeySym feh_current_action_keysym = 0;
unsigned int feh_current_action_state = 0;
unsigned int feh_current_action_button = 0;


void setup_stdin(void) {
struct termios ctrl;

Expand Down Expand Up @@ -478,6 +483,11 @@ void feh_event_handle_generic(winwidget winwid, unsigned int state, KeySym keysy
return;
}

feh_current_action_keysym = keysym;
feh_current_action_state = state;
feh_current_action_button = button;


if (feh_is_kp(EVENT_next_img, state, keysym, button)) {
if (opt.slideshow)
slideshow_change_image(winwid, SLIDE_NEXT, 1);
Expand Down Expand Up @@ -805,5 +815,12 @@ void feh_event_handle_generic(winwidget winwid, unsigned int state, KeySym keysy
}
winwidget_render_image(winwid, 1, 0);
}

feh_current_action_keysym = 0;
feh_current_action_state = 0;
feh_current_action_button = 0;



return;
}
31 changes: 31 additions & 0 deletions src/slideshow.c
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,37 @@ char *feh_printf(char *str, feh_file * file, winwidget winwid)
strncat(ret, buf, sizeof(ret) - strlen(ret) - 1);
}
break;

case 'k': {
if (feh_current_action_keysym) {
char *name = XKeysymToString(feh_current_action_keysym);
if (name)
strncat(ret, name, sizeof(ret) - strlen(ret) - 1);
}
break;
}
case 'K': {
char combo[64] = "";
if (feh_current_action_state & ControlMask)
strcat(combo, "C-");
if (feh_current_action_state & Mod1Mask)
strcat(combo, "M-"); // Alt
if (feh_current_action_state & ShiftMask)
strcat(combo, "S-");
if (feh_current_action_state & Mod4Mask)
strcat(combo, "Super-");

if (feh_current_action_keysym) {
char *name = XKeysymToString(feh_current_action_keysym);
if (name)
strncat(combo, name, sizeof(combo) - strlen(combo) - 1);
}

strncat(ret, combo, sizeof(ret) - strlen(ret) - 1);
break;
}


case 'l':
snprintf(buf, sizeof(buf), "%d", gib_list_length(filelist));
strncat(ret, buf, sizeof(ret) - strlen(ret) - 1);
Expand Down