Krolyxon
Commit b5526c9

Branches

Refs →

nsxivevents.c

69 lines · 1.6 KB · C

1/* sxiv: events.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
19#include <stdlib.h>
20
21#include <X11/Xlib.h>
22#include <X11/keysym.h>
23
24#include "events.h"
25#include "window.h"
26
27extern Display *dpy;
28
29void on_expose(app_t *app, XEvent *ev) {
30}
31
32void on_configurenotify(app_t *app, XEvent *ev) {
33 if (app == NULL || ev == NULL)
34 return;
35
36 win_configure(&app->win, &ev->xconfigure);
37}
38
39void on_keypress(app_t *app, XEvent *ev) {
40 KeySym keysym;
41 XKeyEvent *kev;
42
43 if (app == NULL || ev == NULL)
44 return;
45
46 kev = &ev->xkey;
47 keysym = XKeycodeToKeysym(dpy, (KeyCode) kev->keycode, 0);
48
49 switch (keysym) {
50 case XK_q:
51 app_quit(app);
52 exit(0);
53 }
54}
55
56static void (*handler[LASTEvent])(app_t*, XEvent*) = {
57 [Expose] = on_expose,
58 [ConfigureNotify] = on_configurenotify,
59 [KeyPress] = on_keypress
60};
61
62void event_loop(app_t *app) {
63 XEvent ev;
64
65 while (!XNextEvent(dpy, &ev)) {
66 if (handler[ev.type])
67 handler[ev.type](app, &ev);
68 }
69}