nsxiv544fd83
Reordered function definitions
+30 −26
2 files changed
| @@ -24,16 +24,25 @@ | |||
| 24 | 24 | #include "events.h" | |
| 25 | 25 | #include "window.h" | |
| 26 | 26 | ||
| 27 | + | void on_keypress(app_t*, XEvent*); | |
| 28 | + | void on_configurenotify(app_t*, XEvent*); | |
| 29 | + | void on_expose(app_t*, XEvent*); | |
| 30 | + | ||
| 27 | 31 | extern Display *dpy; | |
| 28 | 32 | ||
| 29 | − | void on_expose(app_t *app, XEvent *ev) { | |
| 30 | − | } | |
| 33 | + | static void (*handler[LASTEvent])(app_t*, XEvent*) = { | |
| 34 | + | [Expose] = on_expose, | |
| 35 | + | [ConfigureNotify] = on_configurenotify, | |
| 36 | + | [KeyPress] = on_keypress | |
| 37 | + | }; | |
| 31 | 38 | ||
| 32 | − | void on_configurenotify(app_t *app, XEvent *ev) { | |
| 33 | − | if (!app || !ev) | |
| 34 | − | return; | |
| 35 | − | ||
| 36 | − | win_configure(&app->win, &ev->xconfigure); | |
| 39 | + | void event_loop(app_t *app) { | |
| 40 | + | XEvent ev; | |
| 41 | + | ||
| 42 | + | while (!XNextEvent(dpy, &ev)) { | |
| 43 | + | if (handler[ev.type]) | |
| 44 | + | handler[ev.type](app, &ev); | |
| 45 | + | } | |
| 37 | 46 | } | |
| 38 | 47 | ||
| 39 | 48 | void on_keypress(app_t *app, XEvent *ev) { | |
| @@ -56,17 +65,12 @@ void on_keypress(app_t *app, XEvent *ev) { | |||
| 56 | 65 | } | |
| 57 | 66 | } | |
| 58 | 67 | ||
| 59 | − | static void (*handler[LASTEvent])(app_t*, XEvent*) = { | |
| 60 | − | [Expose] = on_expose, | |
| 61 | − | [ConfigureNotify] = on_configurenotify, | |
| 62 | − | [KeyPress] = on_keypress | |
| 63 | − | }; | |
| 64 | − | ||
| 65 | − | void event_loop(app_t *app) { | |
| 66 | − | XEvent ev; | |
| 68 | + | void on_configurenotify(app_t *app, XEvent *ev) { | |
| 69 | + | if (!app || !ev) | |
| 70 | + | return; | |
| 71 | + | ||
| 72 | + | win_configure(&app->win, &ev->xconfigure); | |
| 73 | + | } | |
| 67 | 74 | ||
| 68 | − | while (!XNextEvent(dpy, &ev)) { | |
| 69 | − | if (handler[ev.type]) | |
| 70 | − | handler[ev.type](app, &ev); | |
| 71 | − | } | |
| 75 | + | void on_expose(app_t *app, XEvent *ev) { | |
| 72 | 76 | } | |
| @@ -23,13 +23,6 @@ | |||
| 23 | 23 | ||
| 24 | 24 | app_t app; | |
| 25 | 25 | ||
| 26 | − | void cleanup() { | |
| 27 | − | static int in = 0; | |
| 28 | − | ||
| 29 | − | if (!in++) | |
| 30 | − | app_quit(&app); | |
| 31 | − | } | |
| 32 | − | ||
| 33 | 26 | int main(int argc, char **argv) { | |
| 34 | 27 | ||
| 35 | 28 | // TODO: parse cmd line arguments properly | |
| @@ -42,3 +35,10 @@ int main(int argc, char **argv) { | |||
| 42 | 35 | ||
| 43 | 36 | return 0; | |
| 44 | 37 | } | |
| 38 | + | ||
| 39 | + | void cleanup() { | |
| 40 | + | static int in = 0; | |
| 41 | + | ||
| 42 | + | if (!in++) | |
| 43 | + | app_quit(&app); | |
| 44 | + | } | |