filters/gp_filter_resize_alloc: Check w and h
[gfxprim.git] / libs / input / GP_Event.c
blob960313ac638625e985d541f655f31ead1fb34f66
1 /*****************************************************************************
2 * This file is part of gfxprim library. *
3 * *
4 * Gfxprim is free software; you can redistribute it and/or *
5 * modify it under the terms of the GNU Lesser General Public *
6 * License as published by the Free Software Foundation; either *
7 * version 2.1 of the License, or (at your option) any later version. *
8 * *
9 * Gfxprim 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 GNU *
12 * Lesser General Public License for more details. *
13 * *
14 * You should have received a copy of the GNU Lesser General Public *
15 * License along with gfxprim; if not, write to the Free Software *
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, *
17 * Boston, MA 02110-1301 USA *
18 * *
19 * Copyright (C) 2009-2013 Cyril Hrubis <metan@ucw.cz> *
20 * *
21 *****************************************************************************/
23 #include <stdio.h>
24 #include <string.h>
25 #include <stdlib.h>
27 #include <core/GP_Debug.h>
28 #include <core/GP_Common.h>
30 #include <input/GP_EventQueue.h>
31 #include <input/GP_Timer.h>
32 #include <input/GP_Event.h>
34 static char *key_names[] = {
35 "Reserved", "Escape", "1", "2", "3",
36 "4", "5", "6", "7", "8",
37 "9", "0", "Minus", "Equal", "BackSpace",
38 "Tab", "Q", "W", "E", "R",
39 "T", "Y", "U", "I", "O",
40 "P", "LeftBrace", "RightBrace", "Enter", "LeftCtrl",
41 "A", "S", "D", "F", "G",
42 "H", "J", "K", "L", "Semicolon",
43 "Apostrophe", "Grave", "LeftShift", "BackSlash", "Z",
44 "X", "C", "V", "B", "N",
45 "M", "Comma", "Dot", "Slash", "RightShift",
46 "KP Asterisk", "LeftAlt", "Space", "CapsLock", "F1",
47 "F2", "F3", "F4", "F5", "F6",
48 "F7", "F8", "F9", "F10", "NumLock",
49 "ScrollLock", "KP 7", "KP 8", "KP 9", "KP Minus",
50 "KP 4", "KP 5", "KP 6", "KP Plus", "KP 1",
51 "KP 2", "KP 3", "KP 0", "KP Dot", "?",
52 "?", "?", "F11", "F12", "?",
53 "?", "?", "?", "?", "?",
54 "?", "KP Enter", "RightCtrl", "KP Slash", "SysRq",
55 "RightAlt", "?", "Home", "Up", "PageUp",
56 "Left", "Right", "End", "Down", "PageDown",
57 "Insert", "Delete", "?", "Mute", "VolumeDown",
58 "VolumeUp", "?", "KP Equal", "KP PlusMinus", "Pause",
59 "?", "KP Comma", "?", "?", "?",
60 "LeftMeta", "RightMeta", "Compose",
63 const char *gp_event_key_name(enum gp_event_key_value key)
65 if (key < GP_ARRAY_SIZE(key_names))
66 return key_names[key];
68 switch (key) {
69 case GP_BTN_LEFT:
70 return "LeftButton";
71 case GP_BTN_RIGHT:
72 return "RightButton";
73 case GP_BTN_MIDDLE:
74 return "MiddleButton";
75 case GP_BTN_PEN:
76 return "Pen";
77 case GP_KEY_NEXTSONG:
78 return "NextSong";
79 case GP_KEY_PREVIOUSSONG:
80 return "PreviousSong";
81 case GP_KEY_PLAYPAUSE:
82 return "PlayPause";
83 default:
84 return "Unknown";
88 static void dump_rel(gp_event *ev)
90 printf("Rel ");
92 switch (ev->code) {
93 case GP_EV_REL_POS:
94 printf("Position %u %u dx=%i dy=%i\n",
95 ev->cursor_x, ev->cursor_y,
96 ev->val.rel.rx, ev->val.rel.ry);
97 break;
98 case GP_EV_REL_WHEEL:
99 printf("Wheel %i\n", ev->val.val);
100 break;
104 static void dump_key(gp_event *ev)
106 const char *name = gp_event_key_name(ev->val.key.key);
108 printf("Key %i (Key%s) %s\n",
109 ev->val.key.key, name, ev->code ? "down" : "up");
112 static void dump_abs(gp_event *ev)
114 switch (ev->code) {
115 case GP_EV_ABS_POS:
116 printf("Position %u %u %u\n",
117 ev->cursor_x, ev->cursor_y, ev->val.abs.pressure);
118 break;
122 static void dump_sys(gp_event *ev)
124 switch (ev->code) {
125 case GP_EV_SYS_QUIT:
126 printf("Sys Quit\n");
127 break;
128 case GP_EV_SYS_RESIZE:
129 printf("Sys Resize %ux%u\n", ev->val.sys.w, ev->val.sys.h);
130 break;
134 void gp_event_dump(gp_event *ev)
136 printf("Event (%u) ", (unsigned int)ev->time.tv_sec % 10000);
138 switch (ev->type) {
139 case GP_EV_KEY:
140 dump_key(ev);
141 break;
142 case GP_EV_REL:
143 dump_rel(ev);
144 break;
145 case GP_EV_ABS:
146 dump_abs(ev);
147 break;
148 case GP_EV_SYS:
149 dump_sys(ev);
150 break;
151 case GP_EV_TMR:
152 printf("Timer %s expired\n", ev->val.tmr->id);
153 break;
154 default:
155 printf("Unknown %u\n", ev->type);