| @@ -255,13 +255,21 @@ void read_dir_rec(const char *dirname) { |
| 255 | 255 | | /* event handling */ |
| 256 | 256 | | |
| 257 | 257 | | int timeout; |
| 258 | + | unsigned char hidecur; |
| 259 | + | |
| 258 | 260 | | int mox, moy; |
| 261 | + | unsigned char drag; |
| 259 | 262 | | |
| 260 | 263 | | void redraw() { |
| 261 | | − | if (mode == MODE_NORMAL) |
| 264 | + | if (mode == MODE_NORMAL) { |
| 265 | + | if (!drag && hidecur) { |
| 266 | + | win_set_cursor(&win, CURSOR_NONE); |
| 267 | + | hidecur = 0; |
| 268 | + | } |
| 262 | 269 | | img_render(&img, &win); |
| 263 | | − | else |
| 270 | + | } else { |
| 264 | 271 | | tns_render(&tns, &win); |
| 272 | + | } |
| 265 | 273 | | update_title(); |
| 266 | 274 | | timeout = 0; |
| 267 | 275 | | } |
| @@ -377,11 +385,12 @@ void on_keypress(XKeyEvent *kev) { |
| 377 | 385 | | } |
| 378 | 386 | | break; |
| 379 | 387 | | |
| 380 | | − | /* switch to thumnail mode */ |
| 388 | + | /* switch to thumbnail mode */ |
| 381 | 389 | | case XK_Return: |
| 382 | 390 | | if (!tns.thumbs) |
| 383 | 391 | | tns_init(&tns, filecnt); |
| 384 | 392 | | mode = MODE_THUMBS; |
| 393 | + | win_set_cursor(&win, CURSOR_ARROW); |
| 385 | 394 | | tns.sel = fileidx; |
| 386 | 395 | | changed = tns.dirty = 1; |
| 387 | 396 | | break; |
| @@ -403,7 +412,7 @@ void on_keypress(XKeyEvent *kev) { |
| 403 | 412 | | fileidx = tns.sel; |
| 404 | 413 | | load_image(); |
| 405 | 414 | | mode = MODE_NORMAL; |
| 406 | | − | win_set_cursor(&win, CURSOR_ARROW); |
| 415 | + | win_set_cursor(&win, CURSOR_NONE); |
| 407 | 416 | | changed = 1; |
| 408 | 417 | | break; |
| 409 | 418 | | |
| @@ -479,6 +488,8 @@ void on_buttonpress(XButtonEvent *bev) { |
| 479 | 488 | | mox = bev->x; |
| 480 | 489 | | moy = bev->y; |
| 481 | 490 | | win_set_cursor(&win, CURSOR_HAND); |
| 491 | + | hidecur = 0; |
| 492 | + | drag = 1; |
| 482 | 493 | | break; |
| 483 | 494 | | case Button3: |
| 484 | 495 | | if (fileidx > 0) { |
| @@ -518,7 +529,7 @@ void on_buttonpress(XButtonEvent *bev) { |
| 518 | 529 | | fileidx = tns.sel; |
| 519 | 530 | | load_image(); |
| 520 | 531 | | mode = MODE_NORMAL; |
| 521 | | − | win_set_cursor(&win, CURSOR_ARROW); |
| 532 | + | win_set_cursor(&win, CURSOR_NONE); |
| 522 | 533 | | } else { |
| 523 | 534 | | tns_highlight(&tns, &win, tns.sel, False); |
| 524 | 535 | | tns_highlight(&tns, &win, sel, True); |
| @@ -542,7 +553,7 @@ void on_buttonpress(XButtonEvent *bev) { |
| 542 | 553 | | } |
| 543 | 554 | | |
| 544 | 555 | | void on_motionnotify(XMotionEvent *mev) { |
| 545 | | − | if (!mev || mode != MODE_NORMAL) |
| 556 | + | if (!mev) |
| 546 | 557 | | return; |
| 547 | 558 | | |
| 548 | 559 | | if (mev->x >= 0 && mev->x <= win.w && mev->y >= 0 && mev->y <= win.h) { |
| @@ -560,7 +571,12 @@ void run() { |
| 560 | 571 | | struct timeval t, t0; |
| 561 | 572 | | XEvent ev; |
| 562 | 573 | | |
| 563 | | − | timeout = 0; |
| 574 | + | drag = timeout = 0; |
| 575 | + | |
| 576 | + | if (mode == MODE_NORMAL) { |
| 577 | + | hidecur = 1; |
| 578 | + | timeout = 1500000; |
| 579 | + | } |
| 564 | 580 | | |
| 565 | 581 | | while (1) { |
| 566 | 582 | | if (mode == MODE_THUMBS && tns.cnt < filecnt) { |
| @@ -582,15 +598,21 @@ void run() { |
| 582 | 598 | | timeout = 75000; |
| 583 | 599 | | } |
| 584 | 600 | | } else if (timeout) { |
| 585 | | − | t.tv_sec = 0; |
| 586 | | − | t.tv_usec = timeout; |
| 601 | + | t.tv_sec = timeout / 1000000; |
| 602 | + | t.tv_usec = timeout % 1000000; |
| 587 | 603 | | xfd = ConnectionNumber(win.env.dpy); |
| 588 | 604 | | FD_ZERO(&fds); |
| 589 | 605 | | FD_SET(xfd, &fds); |
| 590 | 606 | | |
| 591 | | − | if (!XPending(win.env.dpy) && !select(xfd + 1, &fds, 0, 0, &t)) |
| 607 | + | if (!XPending(win.env.dpy) && !select(xfd + 1, &fds, 0, 0, &t)) { |
| 592 | 608 | | /* timeout fired */ |
| 593 | | − | redraw(); |
| 609 | + | if (hidecur) { |
| 610 | + | win_set_cursor(&win, CURSOR_NONE); |
| 611 | + | hidecur = 0; |
| 612 | + | } else { |
| 613 | + | redraw(); |
| 614 | + | } |
| 615 | + | } |
| 594 | 616 | | } |
| 595 | 617 | | |
| 596 | 618 | | if (!XNextEvent(win.env.dpy, &ev)) { |
| @@ -602,11 +624,25 @@ void run() { |
| 602 | 624 | | on_buttonpress(&ev.xbutton); |
| 603 | 625 | | break; |
| 604 | 626 | | case ButtonRelease: |
| 605 | | − | if (ev.xbutton.button == Button2) |
| 606 | | − | win_set_cursor(&win, CURSOR_ARROW); |
| 627 | + | if (ev.xbutton.button == Button2) { |
| 628 | + | drag = 0; |
| 629 | + | if (mode == MODE_NORMAL) { |
| 630 | + | win_set_cursor(&win, CURSOR_ARROW); |
| 631 | + | hidecur = 1; |
| 632 | + | timeout = 1500000; |
| 633 | + | } |
| 634 | + | } |
| 607 | 635 | | break; |
| 608 | 636 | | case MotionNotify: |
| 609 | | − | on_motionnotify(&ev.xmotion); |
| 637 | + | if (drag) { |
| 638 | + | on_motionnotify(&ev.xmotion); |
| 639 | + | } else if (mode == MODE_NORMAL) { |
| 640 | + | if (!hidecur) { |
| 641 | + | win_set_cursor(&win, CURSOR_ARROW); |
| 642 | + | hidecur = 1; |
| 643 | + | } |
| 644 | + | timeout = 1500000; |
| 645 | + | } |
| 610 | 646 | | break; |
| 611 | 647 | | case ConfigureNotify: |
| 612 | 648 | | if (win_configure(&win, &ev.xconfigure)) { |