summaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
authorBert <ber.t@gmx.com>2011-01-19 14:07:45 +0100
committerBert <ber.t@gmx.com>2011-01-19 14:07:45 +0100
commita7e30bb081ab0a27147f97b8851d7bb76c39c51b (patch)
treed56d33272e11a27e9a5523bcbb2556745b7c6e1a /main.c
parent79c7e6178e9b577158408157ec23a477556ecf16 (diff)
downloadnsxiv-a7e30bb081ab0a27147f97b8851d7bb76c39c51b.tar.zst
Option handling, merged app.c & events.c into main.c
Diffstat (limited to 'main.c')
-rw-r--r--main.c93
1 files changed, 83 insertions, 10 deletions
diff --git a/main.c b/main.c
index 9959657..6c3c2f3 100644
--- a/main.c
+++ b/main.c
@@ -18,20 +18,63 @@
#include <stdlib.h>
+#include <X11/Xlib.h>
+#include <X11/keysym.h>
+
#include "sxiv.h"
-#include "app.h"
+#include "image.h"
+#include "options.h"
+#include "window.h"
+
+void on_keypress(XEvent*);
+void on_configurenotify(XEvent*);
+void on_expose(XEvent*);
+
+static void (*handler[LASTEvent])(XEvent*) = {
+ [Expose] = on_expose,
+ [ConfigureNotify] = on_configurenotify,
+ [KeyPress] = on_keypress
+};
+
+img_t img;
+win_t win;
+unsigned int fileidx;
+
+void run() {
+ XEvent ev;
-app_t app;
+ while (!XNextEvent(win.env.dpy, &ev)) {
+ if (handler[ev.type])
+ handler[ev.type](&ev);
+ }
+}
int main(int argc, char **argv) {
+ if (parse_options(argc, argv) < 0)
+ return 1;
+
+ if (!options->filecnt) {
+ print_usage();
+ exit(1);
+ }
+
+ fileidx = 0;
+
+ img.zoom = 1.0;
+ img.scalemode = SCALE_MODE;
+
+ win.w = WIN_WIDTH;
+ win.h = WIN_HEIGHT;
- // TODO: parse cmd line arguments properly
- app.filenames = argv + 1;
- app.filecnt = argc - 1;
+ win_open(&win);
+ imlib_init(&win);
- app_init(&app);
- app_run(&app);
- app_quit(&app);
+ img_load(&img, options->filenames[fileidx]);
+ img_render(&img, &win);
+
+ run();
+
+ cleanup();
return 0;
}
@@ -39,6 +82,36 @@ int main(int argc, char **argv) {
void cleanup() {
static int in = 0;
- if (!in++)
- app_quit(&app);
+ if (!in++) {
+ imlib_destroy();
+ win_close(&win);
+ }
+}
+
+void on_keypress(XEvent *ev) {
+ KeySym keysym;
+
+ if (!ev)
+ return;
+
+ keysym = XLookupKeysym(&ev->xkey, 0);
+
+ switch (keysym) {
+ case XK_Escape:
+ cleanup();
+ exit(1);
+ case XK_q:
+ cleanup();
+ exit(0);
+ }
+}
+
+void on_configurenotify(XEvent *ev) {
+ if (!ev)
+ return;
+
+ win_configure(&win, &ev->xconfigure);
+}
+
+void on_expose(XEvent *ev) {
}