Krolyxon
Commit 544fd83

Branches

Refs →

nsxivevents.c

76 lines · 1.8 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
27void on_keypress(app_t*, XEvent*);
28void on_configurenotify(app_t*, XEvent*);
29void on_expose(app_t*, XEvent*);
30
31extern Display *dpy;
32
33static void (*handler[LASTEvent])(app_t*, XEvent*) = {
34 [Expose] = on_expose,
35 [ConfigureNotify] = on_configurenotify,
36 [KeyPress] = on_keypress
37};
38
39void 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 }
46}
47
48void on_keypress(app_t *app, XEvent *ev) {
49 KeySym keysym;
50 XKeyEvent *kev;
51
52 if (!app || !ev)
53 return;
54
55 kev = &ev->xkey;
56 keysym = XKeycodeToKeysym(dpy, (KeyCode) kev->keycode, 0);
57
58 switch (keysym) {
59 case XK_Escape:
60 app_quit(app);
61 exit(1);
62 case XK_q:
63 app_quit(app);
64 exit(0);
65 }
66}
67
68void on_configurenotify(app_t *app, XEvent *ev) {
69 if (!app || !ev)
70 return;
71
72 win_configure(&app->win, &ev->xconfigure);
73}
74
75void on_expose(app_t *app, XEvent *ev) {
76}