A Simple X Image Viewer
 
 
 
 
 
 

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