A Simple X Image Viewer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

815 lines
17 KiB

  1. /* sxiv: main.c
  2. * Copyright (c) 2011 Bert Muennich <muennich at informatik.hu-berlin.de>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  17. */
  18. #define _XOPEN_SOURCE 700
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21. #include <string.h>
  22. #include <sys/select.h>
  23. #include <sys/stat.h>
  24. #include <sys/time.h>
  25. #include <sys/wait.h>
  26. #include <unistd.h>
  27. #include <X11/Xlib.h>
  28. #include <X11/Xutil.h>
  29. #include <X11/keysym.h>
  30. #include "image.h"
  31. #include "options.h"
  32. #include "thumbs.h"
  33. #include "util.h"
  34. #include "window.h"
  35. #define FNAME_CNT 1024
  36. #define TITLE_LEN 256
  37. typedef enum {
  38. MODE_NORMAL = 0,
  39. MODE_THUMBS
  40. } appmode_t;
  41. typedef struct {
  42. KeySym ksym;
  43. Bool reload;
  44. const char *cmdline;
  45. } command_t;
  46. #define MAIN_C
  47. #include "config.h"
  48. void run();
  49. appmode_t mode;
  50. img_t img;
  51. tns_t tns;
  52. win_t win;
  53. char **filenames;
  54. int filecnt, fileidx;
  55. size_t filesize;
  56. char win_title[TITLE_LEN];
  57. void cleanup() {
  58. static int in = 0;
  59. if (!in++) {
  60. img_close(&img, 0);
  61. tns_free(&tns);
  62. win_close(&win);
  63. }
  64. }
  65. void remove_file(int n, unsigned char silent) {
  66. if (n < 0 || n >= filecnt)
  67. return;
  68. if (filecnt == 1) {
  69. if (!silent)
  70. fprintf(stderr, "sxiv: no more files to display, aborting\n");
  71. cleanup();
  72. exit(!silent);
  73. }
  74. if (n + 1 < filecnt)
  75. memmove(filenames + n, filenames + n + 1, (filecnt - n - 1) *
  76. sizeof(char*));
  77. if (n + 1 < tns.cnt) {
  78. memmove(tns.thumbs + n, tns.thumbs + n + 1, (tns.cnt - n - 1) *
  79. sizeof(thumb_t));
  80. memset(tns.thumbs + tns.cnt - 1, 0, sizeof(thumb_t));
  81. }
  82. --filecnt;
  83. if (n < tns.cnt)
  84. --tns.cnt;
  85. }
  86. int load_image(int new) {
  87. struct stat fstats;
  88. if (new >= 0 && new < filecnt) {
  89. win_set_cursor(&win, CURSOR_WATCH);
  90. img_close(&img, 0);
  91. while (!img_load(&img, filenames[new])) {
  92. remove_file(new, 0);
  93. if (new >= filecnt)
  94. new = filecnt - 1;
  95. }
  96. fileidx = new;
  97. if (!stat(filenames[new], &fstats))
  98. filesize = fstats.st_size;
  99. else
  100. filesize = 0;
  101. /* cursor is reset in redraw() */
  102. }
  103. return 1;
  104. }
  105. void update_title() {
  106. int n;
  107. float size;
  108. const char *unit;
  109. if (mode == MODE_THUMBS) {
  110. n = snprintf(win_title, TITLE_LEN, "sxiv: [%d/%d] %s",
  111. tns.cnt ? tns.sel + 1 : 0, tns.cnt,
  112. tns.cnt ? filenames[tns.sel] : "");
  113. } else {
  114. size = filesize;
  115. size_readable(&size, &unit);
  116. n = snprintf(win_title, TITLE_LEN,
  117. "sxiv: [%d/%d] <%d%%> <%dx%d> (%.2f%s) %s",
  118. fileidx + 1, filecnt, (int) (img.zoom * 100.0), img.w, img.h,
  119. size, unit, filenames[fileidx]);
  120. }
  121. if (n >= TITLE_LEN) {
  122. win_title[TITLE_LEN - 2] = '.';
  123. win_title[TITLE_LEN - 3] = '.';
  124. win_title[TITLE_LEN - 4] = '.';
  125. }
  126. win_set_title(&win, win_title);
  127. }
  128. int check_append(char *filename) {
  129. if (!filename)
  130. return 0;
  131. if (access(filename, R_OK)) {
  132. warn("could not open file: %s", filename);
  133. return 0;
  134. } else {
  135. if (fileidx == filecnt) {
  136. filecnt *= 2;
  137. filenames = (char**) s_realloc(filenames, filecnt * sizeof(char*));
  138. }
  139. filenames[fileidx++] = filename;
  140. return 1;
  141. }
  142. }
  143. int fncmp(const void *a, const void *b) {
  144. return strcoll(*((char* const*) a), *((char* const*) b));
  145. }
  146. int main(int argc, char **argv) {
  147. int i, len, start;
  148. size_t n;
  149. char *filename = NULL;
  150. struct stat fstats;
  151. r_dir_t dir;
  152. parse_options(argc, argv);
  153. if (options->clean_cache) {
  154. tns_init(&tns, 0);
  155. tns_clean_cache(&tns);
  156. exit(0);
  157. }
  158. if (!options->filecnt) {
  159. print_usage();
  160. exit(1);
  161. }
  162. if (options->recursive || options->from_stdin)
  163. filecnt = FNAME_CNT;
  164. else
  165. filecnt = options->filecnt;
  166. filenames = (char**) s_malloc(filecnt * sizeof(char*));
  167. fileidx = 0;
  168. if (options->from_stdin) {
  169. while ((len = getline(&filename, &n, stdin)) > 0) {
  170. if (filename[len-1] == '\n')
  171. filename[len-1] = '\0';
  172. if (!*filename || !check_append(filename))
  173. free(filename);
  174. filename = NULL;
  175. }
  176. } else {
  177. for (i = 0; i < options->filecnt; ++i) {
  178. filename = options->filenames[i];
  179. if (stat(filename, &fstats) || !S_ISDIR(fstats.st_mode)) {
  180. check_append(filename);
  181. } else {
  182. if (!options->recursive) {
  183. warn("ignoring directory: %s", filename);
  184. continue;
  185. }
  186. if (r_opendir(&dir, filename)) {
  187. warn("could not open directory: %s", filename);
  188. continue;
  189. }
  190. start = fileidx;
  191. while ((filename = r_readdir(&dir))) {
  192. if (!check_append(filename))
  193. free((void*) filename);
  194. }
  195. r_closedir(&dir);
  196. if (fileidx - start > 1)
  197. qsort(filenames + start, fileidx - start, sizeof(char*), fncmp);
  198. }
  199. }
  200. }
  201. if (!fileidx) {
  202. fprintf(stderr, "sxiv: no valid image file given, aborting\n");
  203. exit(1);
  204. }
  205. filecnt = fileidx;
  206. fileidx = options->startnum < filecnt ? options->startnum : filecnt - 1;
  207. win_init(&win);
  208. img_init(&img, &win);
  209. if (options->thumbnails) {
  210. mode = MODE_THUMBS;
  211. tns_init(&tns, filecnt);
  212. while (!tns_load(&tns, 0, filenames[0], 0))
  213. remove_file(0, 0);
  214. tns.cnt = 1;
  215. } else {
  216. mode = MODE_NORMAL;
  217. tns.thumbs = NULL;
  218. load_image(fileidx);
  219. }
  220. win_open(&win);
  221. run();
  222. cleanup();
  223. return 0;
  224. }
  225. #if EXT_COMMANDS
  226. int run_command(const char *cline, Bool reload) {
  227. int fncnt, fnlen;
  228. char *cn, *cmdline;
  229. const char *co, *fname;
  230. pid_t pid;
  231. int ret, status;
  232. if (!cline || !*cline)
  233. return 0;
  234. fncnt = 0;
  235. co = cline - 1;
  236. while ((co = strchr(co + 1, '#')))
  237. ++fncnt;
  238. if (!fncnt)
  239. return 0;
  240. ret = 0;
  241. fname = filenames[mode == MODE_NORMAL ? fileidx : tns.sel];
  242. fnlen = strlen(fname);
  243. cn = cmdline = (char*) s_malloc((strlen(cline) + fncnt * (fnlen + 2)) *
  244. sizeof(char));
  245. /* replace all '#' with filename */
  246. for (co = cline; *co; ++co) {
  247. if (*co == '#') {
  248. *cn++ = '"';
  249. strcpy(cn, fname);
  250. cn += fnlen;
  251. *cn++ = '"';
  252. } else {
  253. *cn++ = *co;
  254. }
  255. }
  256. *cn = '\0';
  257. if ((pid = fork()) == 0) {
  258. execlp("/bin/sh", "/bin/sh", "-c", cmdline, NULL);
  259. warn("could not exec: /bin/sh");
  260. exit(1);
  261. } else if (pid < 0) {
  262. warn("could not fork. command line was: %s", cmdline);
  263. } else if (reload) {
  264. waitpid(pid, &status, 0);
  265. if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
  266. ret = 1;
  267. else
  268. warn("child exited with non-zero return value: %d. command line was: %s",
  269. WEXITSTATUS(status), cmdline);
  270. }
  271. free(cmdline);
  272. return ret;
  273. }
  274. #endif /* EXT_COMMANDS */
  275. /* event handling */
  276. #define TO_WIN_RESIZE 75000
  277. #define TO_IMAGE_DRAG 1000
  278. #define TO_CURSOR_HIDE 1500000
  279. #define TO_THUMBS_LOAD 75000
  280. int timo_cursor;
  281. int timo_redraw;
  282. unsigned char drag;
  283. int mox, moy;
  284. void redraw() {
  285. if (mode == MODE_NORMAL) {
  286. img_render(&img, &win);
  287. if (timo_cursor)
  288. win_set_cursor(&win, CURSOR_ARROW);
  289. else if (!drag)
  290. win_set_cursor(&win, CURSOR_NONE);
  291. } else {
  292. tns_render(&tns, &win);
  293. }
  294. update_title();
  295. timo_redraw = 0;
  296. }
  297. void on_keypress(XKeyEvent *kev) {
  298. int x, y;
  299. unsigned int w, h;
  300. char key;
  301. KeySym ksym;
  302. int changed, ctrl;
  303. if (!kev)
  304. return;
  305. XLookupString(kev, &key, 1, &ksym, NULL);
  306. changed = 0;
  307. ctrl = CLEANMASK(kev->state) & ControlMask;
  308. #if EXT_COMMANDS
  309. /* external commands from commands.h */
  310. if (ctrl) {
  311. for (x = 0; x < LEN(commands); ++x) {
  312. if (commands[x].ksym == ksym) {
  313. win_set_cursor(&win, CURSOR_WATCH);
  314. if (run_command(commands[x].cmdline, commands[x].reload)) {
  315. if (mode == MODE_NORMAL) {
  316. if (fileidx < tns.cnt)
  317. tns_load(&tns, fileidx, filenames[fileidx], 1);
  318. img_close(&img, 1);
  319. load_image(fileidx);
  320. } else {
  321. if (!tns_load(&tns, tns.sel, filenames[tns.sel], 0)) {
  322. remove_file(tns.sel, 0);
  323. tns.dirty = 1;
  324. if (tns.sel >= tns.cnt)
  325. tns.sel = tns.cnt - 1;
  326. }
  327. }
  328. redraw();
  329. }
  330. if (mode == MODE_THUMBS)
  331. win_set_cursor(&win, CURSOR_ARROW);
  332. else if (!timo_cursor)
  333. win_set_cursor(&win, CURSOR_NONE);
  334. return;
  335. }
  336. }
  337. }
  338. #endif
  339. if (mode == MODE_NORMAL) {
  340. switch (ksym) {
  341. /* navigate image list */
  342. case XK_n:
  343. case XK_space:
  344. if (fileidx + 1 < filecnt)
  345. changed = load_image(fileidx + 1);
  346. break;
  347. case XK_p:
  348. case XK_BackSpace:
  349. if (fileidx > 0)
  350. changed = load_image(fileidx - 1);
  351. break;
  352. case XK_bracketleft:
  353. if (fileidx != 0)
  354. changed = load_image(MAX(0, fileidx - 10));
  355. break;
  356. case XK_bracketright:
  357. if (fileidx != filecnt - 1)
  358. changed = load_image(MIN(fileidx + 10, filecnt - 1));
  359. break;
  360. case XK_g:
  361. if (fileidx != 0)
  362. changed = load_image(0);
  363. break;
  364. case XK_G:
  365. if (fileidx != filecnt - 1)
  366. changed = load_image(filecnt - 1);
  367. break;
  368. /* zooming */
  369. case XK_plus:
  370. case XK_equal:
  371. changed = img_zoom_in(&img, &win);
  372. break;
  373. case XK_minus:
  374. changed = img_zoom_out(&img, &win);
  375. break;
  376. case XK_0:
  377. changed = img_zoom(&img, &win, 1.0);
  378. break;
  379. case XK_w:
  380. if ((changed = img_fit_win(&img, &win)))
  381. img_center(&img, &win);
  382. break;
  383. /* panning */
  384. case XK_h:
  385. case XK_Left:
  386. changed = img_pan(&img, &win, PAN_LEFT, ctrl);
  387. break;
  388. case XK_j:
  389. case XK_Down:
  390. changed = img_pan(&img, &win, PAN_DOWN, ctrl);
  391. break;
  392. case XK_k:
  393. case XK_Up:
  394. changed = img_pan(&img, &win, PAN_UP, ctrl);
  395. break;
  396. case XK_l:
  397. case XK_Right:
  398. changed = img_pan(&img, &win, PAN_RIGHT, ctrl);
  399. break;
  400. case XK_Prior:
  401. changed = img_pan(&img, &win, PAN_UP, 1);
  402. break;
  403. case XK_Next:
  404. changed = img_pan(&img, &win, PAN_DOWN, 1);
  405. break;
  406. case XK_H:
  407. changed = img_pan_edge(&img, &win, PAN_LEFT);
  408. break;
  409. case XK_J:
  410. changed = img_pan_edge(&img, &win, PAN_DOWN);
  411. break;
  412. case XK_K:
  413. changed = img_pan_edge(&img, &win, PAN_UP);
  414. break;
  415. case XK_L:
  416. changed = img_pan_edge(&img, &win, PAN_RIGHT);
  417. break;
  418. /* rotation */
  419. case XK_less:
  420. img_rotate_left(&img, &win);
  421. changed = 1;
  422. break;
  423. case XK_greater:
  424. img_rotate_right(&img, &win);
  425. changed = 1;
  426. break;
  427. /* control window */
  428. case XK_W:
  429. x = MAX(0, win.x + img.x);
  430. y = MAX(0, win.y + img.y);
  431. w = img.w * img.zoom;
  432. h = img.h * img.zoom;
  433. if ((changed = win_moveresize(&win, x, y, w, h))) {
  434. img.x = x - win.x;
  435. img.y = y - win.y;
  436. }
  437. break;
  438. /* switch to thumbnail mode */
  439. case XK_Return:
  440. if (!tns.thumbs)
  441. tns_init(&tns, filecnt);
  442. img_close(&img, 0);
  443. mode = MODE_THUMBS;
  444. win_set_cursor(&win, CURSOR_ARROW);
  445. timo_cursor = 0;
  446. tns.sel = fileidx;
  447. changed = tns.dirty = 1;
  448. break;
  449. /* miscellaneous */
  450. case XK_a:
  451. img_toggle_antialias(&img);
  452. changed = 1;
  453. break;
  454. case XK_A:
  455. img.alpha ^= 1;
  456. changed = 1;
  457. break;
  458. case XK_D:
  459. remove_file(fileidx, 1);
  460. changed = load_image(fileidx >= filecnt ? filecnt - 1 : fileidx);
  461. break;
  462. case XK_r:
  463. changed = load_image(fileidx);
  464. break;
  465. }
  466. } else {
  467. /* thumbnail mode */
  468. switch (ksym) {
  469. /* open selected image */
  470. case XK_Return:
  471. load_image(tns.sel);
  472. mode = MODE_NORMAL;
  473. changed = 1;
  474. break;
  475. /* move selection */
  476. case XK_h:
  477. case XK_Left:
  478. changed = tns_move_selection(&tns, &win, TNS_LEFT);
  479. break;
  480. case XK_j:
  481. case XK_Down:
  482. changed = tns_move_selection(&tns, &win, TNS_DOWN);
  483. break;
  484. case XK_k:
  485. case XK_Up:
  486. changed = tns_move_selection(&tns, &win, TNS_UP);
  487. break;
  488. case XK_l:
  489. case XK_Right:
  490. changed = tns_move_selection(&tns, &win, TNS_RIGHT);
  491. break;
  492. case XK_g:
  493. if (tns.sel != 0) {
  494. tns.sel = 0;
  495. changed = tns.dirty = 1;
  496. }
  497. break;
  498. case XK_G:
  499. if (tns.sel != tns.cnt - 1) {
  500. tns.sel = tns.cnt - 1;
  501. changed = tns.dirty = 1;
  502. }
  503. break;
  504. /* miscellaneous */
  505. case XK_D:
  506. if (tns.sel < tns.cnt) {
  507. remove_file(tns.sel, 1);
  508. changed = tns.dirty = 1;
  509. if (tns.sel >= tns.cnt)
  510. tns.sel = tns.cnt - 1;
  511. }
  512. break;
  513. }
  514. }
  515. /* common key mappings */
  516. switch (ksym) {
  517. case XK_q:
  518. cleanup();
  519. exit(0);
  520. case XK_f:
  521. win_toggle_fullscreen(&win);
  522. if (mode == MODE_NORMAL)
  523. img.checkpan = 1;
  524. else
  525. tns.dirty = 1;
  526. timo_redraw = TO_WIN_RESIZE;
  527. break;
  528. }
  529. if (changed)
  530. redraw();
  531. }
  532. void on_buttonpress(XButtonEvent *bev) {
  533. int changed, sel;
  534. unsigned int mask;
  535. if (!bev)
  536. return;
  537. mask = CLEANMASK(bev->state);
  538. changed = 0;
  539. if (mode == MODE_NORMAL) {
  540. if (!drag) {
  541. win_set_cursor(&win, CURSOR_ARROW);
  542. timo_cursor = TO_CURSOR_HIDE;
  543. }
  544. switch (bev->button) {
  545. case Button1:
  546. if (fileidx + 1 < filecnt)
  547. changed = load_image(fileidx + 1);
  548. break;
  549. case Button2:
  550. mox = bev->x;
  551. moy = bev->y;
  552. win_set_cursor(&win, CURSOR_HAND);
  553. timo_cursor = 0;
  554. drag = 1;
  555. break;
  556. case Button3:
  557. if (fileidx > 0)
  558. changed = load_image(fileidx - 1);
  559. break;
  560. case Button4:
  561. if (mask == ControlMask)
  562. changed = img_zoom_in(&img, &win);
  563. else if (mask == ShiftMask)
  564. changed = img_pan(&img, &win, PAN_LEFT, 0);
  565. else
  566. changed = img_pan(&img, &win, PAN_UP, 0);
  567. break;
  568. case Button5:
  569. if (mask == ControlMask)
  570. changed = img_zoom_out(&img, &win);
  571. else if (mask == ShiftMask)
  572. changed = img_pan(&img, &win, PAN_RIGHT, 0);
  573. else
  574. changed = img_pan(&img, &win, PAN_DOWN, 0);
  575. break;
  576. case 6:
  577. changed = img_pan(&img, &win, PAN_LEFT, 0);
  578. break;
  579. case 7:
  580. changed = img_pan(&img, &win, PAN_RIGHT, 0);
  581. break;
  582. }
  583. } else {
  584. /* thumbnail mode */
  585. switch (bev->button) {
  586. case Button1:
  587. if ((sel = tns_translate(&tns, bev->x, bev->y)) >= 0) {
  588. if (sel == tns.sel) {
  589. load_image(tns.sel);
  590. mode = MODE_NORMAL;
  591. timo_cursor = TO_CURSOR_HIDE;
  592. } else {
  593. tns_highlight(&tns, &win, tns.sel, False);
  594. tns_highlight(&tns, &win, sel, True);
  595. tns.sel = sel;
  596. }
  597. changed = 1;
  598. break;
  599. }
  600. break;
  601. case Button4:
  602. changed = tns_scroll(&tns, TNS_UP);
  603. break;
  604. case Button5:
  605. changed = tns_scroll(&tns, TNS_DOWN);
  606. break;
  607. }
  608. }
  609. if (changed)
  610. redraw();
  611. }
  612. void on_motionnotify(XMotionEvent *mev) {
  613. if (!mev)
  614. return;
  615. if (mev->x >= 0 && mev->x <= win.w && mev->y >= 0 && mev->y <= win.h) {
  616. if (img_move(&img, &win, mev->x - mox, mev->y - moy))
  617. timo_redraw = TO_IMAGE_DRAG;
  618. mox = mev->x;
  619. moy = mev->y;
  620. }
  621. }
  622. void run() {
  623. int xfd, timeout;
  624. fd_set fds;
  625. struct timeval tt, t0, t1;
  626. XEvent ev;
  627. drag = 0;
  628. timo_cursor = mode == MODE_NORMAL ? TO_CURSOR_HIDE : 0;
  629. redraw();
  630. while (1) {
  631. if (mode == MODE_THUMBS && tns.cnt < filecnt) {
  632. win_set_cursor(&win, CURSOR_WATCH);
  633. gettimeofday(&t0, 0);
  634. while (tns.cnt < filecnt && !XPending(win.env.dpy)) {
  635. if (tns_load(&tns, tns.cnt, filenames[tns.cnt], 0))
  636. ++tns.cnt;
  637. else
  638. remove_file(tns.cnt, 0);
  639. gettimeofday(&t1, 0);
  640. if (TV_TO_DOUBLE(t1) - TV_TO_DOUBLE(t0) >= 0.25)
  641. break;
  642. }
  643. if (tns.cnt == filecnt)
  644. win_set_cursor(&win, CURSOR_ARROW);
  645. if (!XPending(win.env.dpy)) {
  646. redraw();
  647. continue;
  648. } else {
  649. timo_redraw = TO_THUMBS_LOAD;
  650. }
  651. } else if (timo_cursor || timo_redraw) {
  652. gettimeofday(&t0, 0);
  653. if (timo_cursor && timo_redraw)
  654. timeout = MIN(timo_cursor, timo_redraw);
  655. else if (timo_cursor)
  656. timeout = timo_cursor;
  657. else
  658. timeout = timo_redraw;
  659. tt.tv_sec = timeout / 1000000;
  660. tt.tv_usec = timeout % 1000000;
  661. xfd = ConnectionNumber(win.env.dpy);
  662. FD_ZERO(&fds);
  663. FD_SET(xfd, &fds);
  664. if (!XPending(win.env.dpy))
  665. select(xfd + 1, &fds, 0, 0, &tt);
  666. gettimeofday(&t1, 0);
  667. timeout = MIN((TV_TO_DOUBLE(t1) - TV_TO_DOUBLE(t0)) * 1000000, timeout);
  668. /* timeouts fired? */
  669. if (timo_cursor) {
  670. timo_cursor = MAX(0, timo_cursor - timeout);
  671. if (!timo_cursor)
  672. win_set_cursor(&win, CURSOR_NONE);
  673. }
  674. if (timo_redraw) {
  675. timo_redraw = MAX(0, timo_redraw - timeout);
  676. if (!timo_redraw)
  677. redraw();
  678. }
  679. if (!XPending(win.env.dpy) && (timo_cursor || timo_redraw))
  680. continue;
  681. }
  682. if (!XNextEvent(win.env.dpy, &ev)) {
  683. switch (ev.type) {
  684. case KeyPress:
  685. on_keypress(&ev.xkey);
  686. break;
  687. case ButtonPress:
  688. on_buttonpress(&ev.xbutton);
  689. break;
  690. case ButtonRelease:
  691. if (ev.xbutton.button == Button2) {
  692. drag = 0;
  693. if (mode == MODE_NORMAL) {
  694. win_set_cursor(&win, CURSOR_ARROW);
  695. timo_cursor = TO_CURSOR_HIDE;
  696. }
  697. }
  698. break;
  699. case MotionNotify:
  700. if (drag) {
  701. on_motionnotify(&ev.xmotion);
  702. } else if (mode == MODE_NORMAL) {
  703. if (!timo_cursor)
  704. win_set_cursor(&win, CURSOR_ARROW);
  705. timo_cursor = TO_CURSOR_HIDE;
  706. }
  707. break;
  708. case ConfigureNotify:
  709. if (win_configure(&win, &ev.xconfigure)) {
  710. timo_redraw = TO_WIN_RESIZE;
  711. if (mode == MODE_NORMAL)
  712. img.checkpan = 1;
  713. else
  714. tns.dirty = 1;
  715. }
  716. break;
  717. case ClientMessage:
  718. if ((Atom) ev.xclient.data.l[0] == wm_delete_win)
  719. return;
  720. break;
  721. }
  722. }
  723. }
  724. }