Krolyxon
Commit 8081cbe

Branches

Refs →

nsxiv8081cbe

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.
Author
Bert Münnich
Date
2017-10-05 13:53 +0200
Committer
Bert Münnich · 2017-10-06 10:15 +0200
Parent
ee908ca
Commit
8081cbebf36e48297a589af02db400687c4ef261

+52 −34

8 files changed

  1. M Makefile +1 −1
  2. M commands.c +6 −0
  3. M commands.lst +1 −0
  4. M config.def.h +4 −10
  5. M main.c +27 −3
  6. M sxiv.1 +9 −19
  7. M types.h +2 −0
  8. M window.c +2 −1
M Makefile View
@@ -1,4 +1,4 @@
1−VERSION := git-20171005
1+VERSION := git-20171006
22
33 all: sxiv
44
M commands.c View
@@ -33,6 +33,7 @@
3333 void remove_file(int, bool);
3434 void load_image(int);
3535 void open_info(void);
36+int ptr_third_x(void);
3637 void redraw(void);
3738 void reset_cursor(void);
3839 void animate(void);
@@ -281,6 +282,11 @@ bool ci_navigate(arg_t n)
281282 }
282283 }
283284
285+bool ci_cursor_navigate(arg_t _)
286+{
287+ return ci_navigate(ptr_third_x() - 1);
288+}
289+
284290 bool ci_alternate(arg_t _)
285291 {
286292 load_image(alternate);
M commands.lst View
@@ -16,6 +16,7 @@ G_CMD(navigate_marked)
1616 G_CMD(change_gamma)
1717
1818 I_CMD(navigate)
19+I_CMD(cursor_navigate)
1920 I_CMD(alternate)
2021 I_CMD(navigate_frame)
2122 I_CMD(toggle_animation)
M config.def.h View
@@ -150,17 +150,11 @@ static const keymap_t keys[] = {
150150 /* mouse button mappings for image mode: */
151151 static const button_t buttons[] = {
152152 /* modifiers button function argument */
153− { 0, 1, i_navigate, +1 },
154− { 0, 3, i_navigate, -1 },
153+ { 0, 1, i_cursor_navigate, None },
155154 { 0, 2, i_drag, None },
156− { 0, 4, i_scroll, DIR_UP },
157− { 0, 5, i_scroll, DIR_DOWN },
158− { ShiftMask, 4, i_scroll, DIR_LEFT },
159− { ShiftMask, 5, i_scroll, DIR_RIGHT },
160− { 0, 6, i_scroll, DIR_LEFT },
161− { 0, 7, i_scroll, DIR_RIGHT },
162− { ControlMask, 4, g_zoom, +1 },
163− { ControlMask, 5, g_zoom, -1 },
155+ { 0, 3, g_switch_mode, None },
156+ { 0, 4, g_zoom, +1 },
157+ { 0, 5, g_zoom, -1 },
164158 };
165159
166160 #endif
M main.c View
@@ -98,6 +98,10 @@ timeout_t timeouts[] = {
9898 { { 0, 0 }, false, clear_resize },
9999 };
100100
101+cursor_t imgcursor[3] = {
102+ CURSOR_ARROW, CURSOR_ARROW, CURSOR_ARROW
103+};
104+
101105 void cleanup(void)
102106 {
103107 img_close(&img, false);
@@ -405,6 +409,14 @@ void update_info(void)
405409 }
406410 }
407411
412+int ptr_third_x(void)
413+{
414+ int x, y;
415+
416+ win_cursor_pos(&win, &x, &y);
417+ return MAX(0, MIN(2, (x / (win.w * 0.33))));
418+}
419+
408420 void redraw(void)
409421 {
410422 int t;
@@ -428,14 +440,18 @@ void redraw(void)
428440
429441 void reset_cursor(void)
430442 {
431− int i;
443+ int c, i;
432444 cursor_t cursor = CURSOR_NONE;
433445
434446 if (mode == MODE_IMAGE) {
435447 for (i = 0; i < ARRLEN(timeouts); i++) {
436448 if (timeouts[i].handler == reset_cursor) {
437− if (timeouts[i].active)
438− cursor = CURSOR_ARROW;
449+ if (timeouts[i].active) {
450+ c = ptr_third_x();
451+ c = MAX(fileidx > 0 ? 0 : 1, c);
452+ c = MIN(fileidx + 1 < filecnt ? 2 : 1, c);
453+ cursor = imgcursor[c];
454+ }
439455 break;
440456 }
441457 }
@@ -872,6 +888,14 @@ int main(int argc, char **argv)
872888 filecnt = fileidx;
873889 fileidx = options->startnum < filecnt ? options->startnum : 0;
874890
891+ for (i = 0; i < ARRLEN(buttons); i++) {
892+ if (buttons[i].cmd == i_cursor_navigate) {
893+ imgcursor[0] = CURSOR_LEFT;
894+ imgcursor[2] = CURSOR_RIGHT;
895+ break;
896+ }
897+ }
898+
875899 win_init(&win);
876900 img_init(&img, &win);
877901 arl_init(&arl);
M sxiv.1 View
@@ -348,37 +348,27 @@ seconds.
348348 .SH MOUSE COMMANDS
349349 The following mouse mappings are available in image mode:
350350 .TP
351+General:
352+.TP
353+.B Button3
351354 Navigate image list:
352355 .TP
353356 .B Button1
354−Go to next image.
355−.TP
356−.B Button3
357−Go to the previous image.
357+Go to the next image if the mouse cursor is in the right part of the window or
358+to the previous image if it is in the left part.
358359 .TP
359360 Panning:
360361 .TP
361362 .B Button2
362−Drag the image with the mouse while keeping this button pressed down.
363−.TP
364−.B ScrollUp
365−Scroll image up.
366−.TP
367−.B ScrollDown
368−Scroll image down.
369−.TP
370−.B Shift+ScrollUp
371−Scroll image left.
372−.TP
373−.B Shift+ScrollDown
374−Scroll image right.
363+Pan the image according to the mouse cursor position in the window while
364+keeping this button pressed down.
375365 .TP
376366 Zooming:
377367 .TP
378−.B Ctrl+ScrollUp
368+.B ScrollUp
379369 Zoom in.
380370 .TP
381−.B Ctrl+ScrollDown
371+.B ScrollDown
382372 Zoom out.
383373 .SH STATUS BAR
384374 The information displayed on the left side of the status bar can be replaced
M types.h View
@@ -67,6 +67,8 @@ typedef enum {
6767 CURSOR_ARROW,
6868 CURSOR_DRAG,
6969 CURSOR_WATCH,
70+ CURSOR_LEFT,
71+ CURSOR_RIGHT,
7072 CURSOR_NONE,
7173
7274 CURSOR_COUNT
M window.c View
@@ -39,7 +39,8 @@ static struct {
3939 int name;
4040 Cursor icon;
4141 } cursors[CURSOR_COUNT] = {
42− { XC_left_ptr }, { XC_dotbox }, { XC_watch }
42+ { XC_left_ptr }, { XC_dotbox }, { XC_watch },
43+ { XC_sb_left_arrow }, { XC_sb_right_arrow }
4344 };
4445
4546 static GC gc;