A Simple X Image Viewer
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 
 
 
 

118 行
2.1 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. #include <stdlib.h>
  19. #include <X11/Xlib.h>
  20. #include <X11/keysym.h>
  21. #include "sxiv.h"
  22. #include "image.h"
  23. #include "options.h"
  24. #include "window.h"
  25. void on_keypress(XEvent*);
  26. void on_configurenotify(XEvent*);
  27. void on_expose(XEvent*);
  28. static void (*handler[LASTEvent])(XEvent*) = {
  29. [Expose] = on_expose,
  30. [ConfigureNotify] = on_configurenotify,
  31. [KeyPress] = on_keypress
  32. };
  33. img_t img;
  34. win_t win;
  35. unsigned int fileidx;
  36. void run() {
  37. XEvent ev;
  38. while (!XNextEvent(win.env.dpy, &ev)) {
  39. if (handler[ev.type])
  40. handler[ev.type](&ev);
  41. }
  42. }
  43. int main(int argc, char **argv) {
  44. if (parse_options(argc, argv) < 0)
  45. return 1;
  46. if (!options->filecnt) {
  47. print_usage();
  48. exit(1);
  49. }
  50. fileidx = 0;
  51. img.zoom = 1.0;
  52. img.scalemode = SCALE_MODE;
  53. win.w = WIN_WIDTH;
  54. win.h = WIN_HEIGHT;
  55. win_open(&win);
  56. imlib_init(&win);
  57. img_load(&img, options->filenames[fileidx]);
  58. img_render(&img, &win);
  59. run();
  60. cleanup();
  61. return 0;
  62. }
  63. void cleanup() {
  64. static int in = 0;
  65. if (!in++) {
  66. imlib_destroy();
  67. win_close(&win);
  68. }
  69. }
  70. void on_keypress(XEvent *ev) {
  71. KeySym keysym;
  72. if (!ev)
  73. return;
  74. keysym = XLookupKeysym(&ev->xkey, 0);
  75. switch (keysym) {
  76. case XK_Escape:
  77. cleanup();
  78. exit(1);
  79. case XK_q:
  80. cleanup();
  81. exit(0);
  82. }
  83. }
  84. void on_configurenotify(XEvent *ev) {
  85. if (!ev)
  86. return;
  87. win_configure(&win, &ev->xconfigure);
  88. }
  89. void on_expose(XEvent *ev) {
  90. }