Krolyxon
Commit 544fd83

Branches

Refs →

nsxiv544fd83

Reordered function definitions

Author
Bert
Date
2011-01-18 15:33 +0100
Parent
2f4399d
Commit
544fd8371854dcfd51c92f5ae1da7a8c3085156f

+30 −26

2 files changed

  1. M events.c +23 −19
  2. M main.c +7 −7
M events.c View
@@ -24,16 +24,25 @@
2424 #include "events.h"
2525 #include "window.h"
2626
27+void on_keypress(app_t*, XEvent*);
28+void on_configurenotify(app_t*, XEvent*);
29+void on_expose(app_t*, XEvent*);
30+
2731 extern Display *dpy;
2832
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+};
3138
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+ }
3746 }
3847
3948 void on_keypress(app_t *app, XEvent *ev) {
@@ -56,17 +65,12 @@ void on_keypress(app_t *app, XEvent *ev) {
5665 }
5766 }
5867
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+}
6774
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) {
7276 }
M main.c View
@@ -23,13 +23,6 @@
2323
2424 app_t app;
2525
26−void cleanup() {
27− static int in = 0;
28−
29− if (!in++)
30− app_quit(&app);
31−}
32−
3326 int main(int argc, char **argv) {
3427
3528 // TODO: parse cmd line arguments properly
@@ -42,3 +35,10 @@ int main(int argc, char **argv) {
4235
4336 return 0;
4437 }
38+
39+void cleanup() {
40+ static int in = 0;
41+
42+ if (!in++)
43+ app_quit(&app);
44+}