annotate input/input.c @ 4598:badb76094897

setting vo_fps, required for vo_yuv4mpeg
author arpi
date Sat, 09 Feb 2002 01:29:11 +0000
parents 4ce20c55a18a
children 610a11e4db36
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4418
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
1 #include "../config.h"
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
2
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
3 #ifdef HAVE_NEW_INPUT
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
4
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
5 #include <stdlib.h>
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
6 #include <string.h>
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
7 #include <stdio.h>
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
8 #include <unistd.h>
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
9 #include <errno.h>
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
10 #include <signal.h>
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
11 #include <sys/types.h>
4525
46c4e34b4e76 Tell the user when we fallback on default config.
albeu
parents: 4524
diff changeset
12 #include <sys/time.h>
4418
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
13 #include <fcntl.h>
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
14
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
15
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
16
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
17 #include "input.h"
4589
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
18 #include "mouse.h"
4418
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
19 #ifdef MP_DEBUG
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
20 #include <assert.h>
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
21 #endif
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
22 #include "../linux/getch2.h"
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
23 #include "../linux/keycodes.h"
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
24 #include "../linux/timer.h"
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
25
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
26 #ifdef HAVE_JOYSTICK
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
27 #include "joystick.h"
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
28 #endif
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
29
4432
5105f5da01d6 Added lirc support in input
albeu
parents: 4418
diff changeset
30 #ifdef HAVE_LIRC
5105f5da01d6 Added lirc support in input
albeu
parents: 4418
diff changeset
31 #include "lirc.h"
5105f5da01d6 Added lirc support in input
albeu
parents: 4418
diff changeset
32 #endif
5105f5da01d6 Added lirc support in input
albeu
parents: 4418
diff changeset
33
4418
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
34 // If the args field is not NULL, the command will only be passed if
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
35 // an argument exist.
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
36
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
37 static mp_cmd_t mp_cmds[] = {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
38 { MP_CMD_SEEK, "seek", 1, { {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
39 { MP_CMD_AUDIO_DELAY, "audio_delay", 1, { {MP_CMD_ARG_FLOAT,{0}}, {-1,{0}} } },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
40 { MP_CMD_QUIT, "quit", 0, { {-1,{0}} } },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
41 { MP_CMD_PAUSE, "pause", 0, { {-1,{0}} } },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
42 { MP_CMD_GRAB_FRAMES, "grap_frames",0, { {-1,{0}} } },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
43 { MP_CMD_PLAY_TREE_STEP, "pt_step",1, { { MP_CMD_ARG_INT ,{0}}, {-1,{0}} } },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
44 { MP_CMD_PLAY_TREE_UP_STEP, "pt_up_step",1, { { MP_CMD_ARG_INT,{0} }, {-1,{0}} } },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
45 { MP_CMD_PLAY_ALT_SRC_STEP, "alt_src_step",1, { { MP_CMD_ARG_INT,{0} }, {-1,{0}} } },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
46 { MP_CMD_SUB_DELAY, "sub_delay",1, { {MP_CMD_ARG_FLOAT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
47 { MP_CMD_OSD, "osd",0, { {MP_CMD_ARG_INT,{-1}}, {-1,{0}} } },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
48 { MP_CMD_VOLUME, "volume", 1, { { MP_CMD_ARG_INT,{0} }, {-1,{0}} } },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
49 { MP_CMD_MIXER_USEMASTER, "use_master", 0, { {-1,{0}} } },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
50 { MP_CMD_CONTRAST, "contrast",1, { {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
51 { MP_CMD_BRIGHTNESS, "brightness",1, { {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
52 { MP_CMD_HUE, "hue",1, { {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
53 { MP_CMD_SATURATION, "saturation",1, { {MP_CMD_ARG_INT,{0}}, {MP_CMD_ARG_INT,{0}}, {-1,{0}} } },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
54 { MP_CMD_FRAMEDROPPING, "frame_drop",0, { { MP_CMD_ARG_INT,{-1} }, {-1,{0}} } },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
55 #ifdef USE_TV
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
56 { MP_CMD_TV_STEP_CHANNEL, "tv_step_channel", 1, { { MP_CMD_ARG_INT ,{0}}, {-1,{0}} }},
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
57 { MP_CMD_TV_STEP_NORM, "tv_step_norm",0, { {-1,{0}} } },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
58 { MP_CMD_TV_STEP_CHANNEL_LIST, "tv_step_chanlist", 0, { {-1,{0}} } },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
59 #endif
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
60 { 0, NULL, 0, {} }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
61 };
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
62
4589
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
63 static mp_key_name_t key_names[] = {
4418
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
64 { ' ', "SPACE" },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
65 { KEY_ENTER, "ENTER" },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
66 { KEY_TAB, "TAB" },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
67 { KEY_CTRL, "CTRL" },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
68 { KEY_BACKSPACE, "BS" },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
69 { KEY_DELETE, "DEL" },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
70 { KEY_INSERT, "INS" },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
71 { KEY_HOME, "HOME" },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
72 { KEY_END, "END" },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
73 { KEY_PAGE_UP, "PGUP" },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
74 { KEY_PAGE_DOWN, "PGDWN" },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
75 { KEY_ESC, "ESC" },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
76 { KEY_RIGHT, "RIGHT" },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
77 { KEY_LEFT, "LEFT" },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
78 { KEY_DOWN, "DOWN" },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
79 { KEY_UP, "UP" },
4589
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
80 { MOUSE_BTN0, "MOUSE_BTN0" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
81 { MOUSE_BTN1, "MOUSE_BTN1" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
82 { MOUSE_BTN2, "MOUSE_BTN2" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
83 { MOUSE_BTN3, "MOUSE_BTN3" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
84 { MOUSE_BTN4, "MOUSE_BTN4" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
85 { MOUSE_BTN5, "MOUSE_BTN5" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
86 { MOUSE_BTN6, "MOUSE_BTN6" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
87 { MOUSE_BTN7, "MOUSE_BTN7" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
88 { MOUSE_BTN8, "MOUSE_BTN8" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
89 { MOUSE_BTN9, "MOUSE_BTN9" },
4418
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
90 #ifdef HAVE_JOYSTICK
4524
01a0cf736e0d Fix the bugs the previous version should fix (and those introduced
albeu
parents: 4518
diff changeset
91 { JOY_AXIS1_MINUS, "JOY_UP" },
01a0cf736e0d Fix the bugs the previous version should fix (and those introduced
albeu
parents: 4518
diff changeset
92 { JOY_AXIS1_PLUS, "JOY_DOWN" },
01a0cf736e0d Fix the bugs the previous version should fix (and those introduced
albeu
parents: 4518
diff changeset
93 { JOY_AXIS0_MINUS, "JOY_LEFT" },
01a0cf736e0d Fix the bugs the previous version should fix (and those introduced
albeu
parents: 4518
diff changeset
94 { JOY_AXIS0_PLUS, "JOY_RIGHT" },
4518
83128eed25f1 Corrected the quit bug and added support for up to 10 axis
albeu
parents: 4432
diff changeset
95
83128eed25f1 Corrected the quit bug and added support for up to 10 axis
albeu
parents: 4432
diff changeset
96 { JOY_AXIS0_PLUS, "JOY_AXIS0_PLUS" },
83128eed25f1 Corrected the quit bug and added support for up to 10 axis
albeu
parents: 4432
diff changeset
97 { JOY_AXIS0_MINUS, "JOY_AXIS0_MINUS" },
83128eed25f1 Corrected the quit bug and added support for up to 10 axis
albeu
parents: 4432
diff changeset
98 { JOY_AXIS1_PLUS, " JOY_AXIS1_PLUS" },
83128eed25f1 Corrected the quit bug and added support for up to 10 axis
albeu
parents: 4432
diff changeset
99 { JOY_AXIS1_MINUS, "JOY_AXIS1_MINUS" },
83128eed25f1 Corrected the quit bug and added support for up to 10 axis
albeu
parents: 4432
diff changeset
100 { JOY_AXIS2_PLUS, "JOY_AXIS2_PLUS" },
83128eed25f1 Corrected the quit bug and added support for up to 10 axis
albeu
parents: 4432
diff changeset
101 { JOY_AXIS2_MINUS, "JOY_AXIS2_MINUS" },
83128eed25f1 Corrected the quit bug and added support for up to 10 axis
albeu
parents: 4432
diff changeset
102 { JOY_AXIS3_PLUS, " JOY_AXIS3_PLUS" },
83128eed25f1 Corrected the quit bug and added support for up to 10 axis
albeu
parents: 4432
diff changeset
103 { JOY_AXIS3_MINUS, "JOY_AXIS3_MINUS" },
83128eed25f1 Corrected the quit bug and added support for up to 10 axis
albeu
parents: 4432
diff changeset
104 { JOY_AXIS4_PLUS, "JOY_AXIS4_PLUS" },
83128eed25f1 Corrected the quit bug and added support for up to 10 axis
albeu
parents: 4432
diff changeset
105 { JOY_AXIS4_MINUS, "JOY_AXIS4_MINUS" },
83128eed25f1 Corrected the quit bug and added support for up to 10 axis
albeu
parents: 4432
diff changeset
106 { JOY_AXIS5_PLUS, " JOY_AXIS5_PLUS" },
83128eed25f1 Corrected the quit bug and added support for up to 10 axis
albeu
parents: 4432
diff changeset
107 { JOY_AXIS5_MINUS, "JOY_AXIS5_MINUS" },
83128eed25f1 Corrected the quit bug and added support for up to 10 axis
albeu
parents: 4432
diff changeset
108 { JOY_AXIS6_PLUS, "JOY_AXIS6_PLUS" },
83128eed25f1 Corrected the quit bug and added support for up to 10 axis
albeu
parents: 4432
diff changeset
109 { JOY_AXIS6_MINUS, "JOY_AXIS6_MINUS" },
83128eed25f1 Corrected the quit bug and added support for up to 10 axis
albeu
parents: 4432
diff changeset
110 { JOY_AXIS7_PLUS, " JOY_AXIS7_PLUS" },
83128eed25f1 Corrected the quit bug and added support for up to 10 axis
albeu
parents: 4432
diff changeset
111 { JOY_AXIS7_MINUS, "JOY_AXIS7_MINUS" },
83128eed25f1 Corrected the quit bug and added support for up to 10 axis
albeu
parents: 4432
diff changeset
112 { JOY_AXIS8_PLUS, "JOY_AXIS8_PLUS" },
83128eed25f1 Corrected the quit bug and added support for up to 10 axis
albeu
parents: 4432
diff changeset
113 { JOY_AXIS8_MINUS, "JOY_AXIS8_MINUS" },
83128eed25f1 Corrected the quit bug and added support for up to 10 axis
albeu
parents: 4432
diff changeset
114 { JOY_AXIS9_PLUS, " JOY_AXIS9_PLUS" },
83128eed25f1 Corrected the quit bug and added support for up to 10 axis
albeu
parents: 4432
diff changeset
115 { JOY_AXIS9_MINUS, "JOY_AXIS9_MINUS" },
83128eed25f1 Corrected the quit bug and added support for up to 10 axis
albeu
parents: 4432
diff changeset
116
4418
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
117 { JOY_BTN0, "JOY_BTN0" },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
118 { JOY_BTN1, "JOY_BTN1" },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
119 { JOY_BTN2, "JOY_BTN2" },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
120 { JOY_BTN3, "JOY_BTN3" },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
121 { JOY_BTN4, "JOY_BTN4" },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
122 { JOY_BTN5, "JOY_BTN5" },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
123 { JOY_BTN6, "JOY_BTN6" },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
124 { JOY_BTN7, "JOY_BTN7" },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
125 { JOY_BTN8, "JOY_BTN8" },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
126 { JOY_BTN9, "JOY_BTN9" },
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
127 #endif
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
128 { 0, NULL }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
129 };
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
130
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
131 // This is the default binding we use when no config file is here
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
132
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
133 static mp_cmd_bind_t def_cmd_binds[] = {
4589
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
134 { { KEY_RIGHT, 0 }, "seek 10" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
135 { { KEY_LEFT, 0 }, "seek -10" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
136 { { KEY_UP, 0 }, "seek 60" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
137 { { KEY_DOWN, 0 }, "seek -60" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
138 { { KEY_PAGE_UP, 0 }, "seek 600" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
139 { { KEY_PAGE_DOWN, 0 }, "seek -600" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
140 { { '+', 0 }, "audio_delay 0.100" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
141 { { '-', 0 }, "audio_delay -0.100" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
142 { { 'q', 0 }, "quit" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
143 { { KEY_ESC, 0 }, "quit" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
144 { { 'p', 0 }, "pause" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
145 { { ' ', 0 }, "pause" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
146 { { KEY_HOME, 0 }, "pt_up_step 1" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
147 { { KEY_END, 0 }, "pt_up_step -1" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
148 { { '>', 0 }, "pt_step 1" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
149 { { '<', 0 }, "pt_step -1" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
150 { { KEY_INS, 0 }, "alt_src_step 1" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
151 { { KEY_DEL, 0 }, "alt_src_step -1" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
152 { { 'o', 0 }, "osd" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
153 { { 'z', 0 }, "sub_delay -0.1" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
154 { { 'x', 0 }, "sub_delay +0.1" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
155 { { '9', 0 }, "volume -1" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
156 { { '/', 0 }, "volume -1" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
157 { { '0', 0 }, "volume 1" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
158 { { '*', 0 }, "volume 1" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
159 { { 'm', 0 }, "use_master" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
160 { { '1', 0 }, "contrast -1" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
161 { { '2', 0 }, "contrast 1" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
162 { { '3', 0 }, "brightness -1" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
163 { { '4', 0 }, "brightness 1" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
164 { { '5', 0 }, "hue -1" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
165 { { '6', 0 }, "hue 1" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
166 { { '7', 0 }, "saturation -1" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
167 { { '8', 0 }, "saturation 1" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
168 { { 'd', 0 }, "frame_drop" },
4418
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
169 #ifdef USE_TV
4589
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
170 { { 'h', 0 }, "tv_step_channel 1" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
171 { { 'l', 0 }, "tv_step_channel -1" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
172 { { 'n', 0 }, "tv_step_norm" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
173 { { 'b', 0 }, "tv_step_chanlist" },
4418
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
174 #endif
4525
46c4e34b4e76 Tell the user when we fallback on default config.
albeu
parents: 4524
diff changeset
175 #ifdef HAVE_JOYSTICK
4589
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
176 { { JOY_AXIS0_PLUS, 0 }, "seek 10" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
177 { { JOY_AXIS0_MINUS, 0 }, "seek -10" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
178 { { JOY_AXIS1_MINUS, 0 }, "seek 60" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
179 { { JOY_AXIS1_PLUS, 0 }, "seek -60" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
180 { { JOY_BTN0, 0 }, "pause" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
181 { { JOY_BTN1, 0 }, "osd" },
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
182 { { JOY_BTN2, 0 }, "volume 1"},
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
183 { { JOY_BTN3, 0 }, "volume -1"},
4525
46c4e34b4e76 Tell the user when we fallback on default config.
albeu
parents: 4524
diff changeset
184 #endif
4589
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
185 { { 0 }, NULL }
4418
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
186 };
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
187
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
188 #ifndef MP_MAX_KEY_FD
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
189 #define MP_MAX_KEY_FD 10
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
190 #endif
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
191
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
192 #ifndef MP_MAX_CMD_FD
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
193 #define MP_MAX_CMD_FD 10
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
194 #endif
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
195
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
196 #define MP_FD_EOF (1<<0)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
197 #define MP_FD_DROP (1<<1)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
198 #define MP_FD_DEAD (1<<2)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
199 #define MP_FD_GOT_CMD (1<<3)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
200 #define MP_FD_NO_SELECT (1<<4)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
201
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
202 typedef struct mp_input_fd {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
203 int fd;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
204 void* read_func;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
205 mp_close_func_t close_func;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
206 int flags;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
207 // This fields are for the cmd fds
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
208 char* buffer;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
209 int pos,size;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
210 } mp_input_fd_t;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
211
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
212
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
213 static mp_cmd_bind_t* cmd_binds = def_cmd_binds;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
214
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
215 static mp_input_fd_t key_fds[MP_MAX_KEY_FD];
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
216 static unsigned int num_key_fd = 0;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
217 static mp_input_fd_t cmd_fds[MP_MAX_CMD_FD];
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
218 static unsigned int num_cmd_fd = 0;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
219
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
220 static int key_max_fd = -1, cmd_max_fd = -1;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
221
4589
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
222 // this is the key currently down
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
223 static int key_down[MP_MAX_KEY_DOWN];
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
224 static unsigned int num_key_down = 0;
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
225 static short last_key_down = 0,key_was_down = 0;
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
226
4418
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
227 static int
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
228 mp_input_default_key_func(int fd);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
229
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
230
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
231 int
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
232 mp_input_add_cmd_fd(int fd, int select, mp_cmd_func_t read_func, mp_close_func_t close_func) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
233 if(num_cmd_fd == MP_MAX_CMD_FD) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
234 printf("Too much command fd, unable to register fd %d\n",fd);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
235 return 0;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
236 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
237
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
238 memset(&cmd_fds[num_cmd_fd],0,sizeof(mp_input_fd_t));
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
239 cmd_fds[num_cmd_fd].fd = fd;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
240 cmd_fds[num_cmd_fd].read_func = read_func ? read_func : (mp_cmd_func_t)read;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
241 cmd_fds[num_cmd_fd].close_func = close_func;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
242 if(!select)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
243 cmd_fds[num_cmd_fd].flags = MP_FD_NO_SELECT;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
244 num_cmd_fd++;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
245 if(fd > cmd_max_fd)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
246 cmd_max_fd = fd;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
247
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
248 return 1;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
249 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
250
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
251 void
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
252 mp_input_rm_cmd_fd(int fd) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
253 unsigned int i;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
254
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
255 for(i = 0; i < num_cmd_fd; i++) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
256 if(cmd_fds[i].fd == fd)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
257 break;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
258 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
259 if(i == num_cmd_fd)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
260 return;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
261 if(cmd_fds[i].close_func)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
262 cmd_fds[i].close_func(cmd_fds[i].fd);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
263
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
264 if(i + 1 < num_cmd_fd)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
265 memmove(&cmd_fds[i],&cmd_fds[i+1],(num_cmd_fd - i - 1)*sizeof(mp_input_fd_t));
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
266 num_cmd_fd--;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
267 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
268
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
269 void
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
270 mp_input_rm_key_fd(int fd) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
271 unsigned int i;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
272
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
273 for(i = 0; i < num_key_fd; i++) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
274 if(key_fds[i].fd == fd)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
275 break;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
276 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
277 if(i == num_key_fd)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
278 return;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
279 if(key_fds[i].close_func)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
280 key_fds[i].close_func(key_fds[i].fd);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
281
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
282 if(i + 1 < num_key_fd)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
283 memmove(&key_fds[i],&key_fds[i+1],(num_key_fd - i - 1)*sizeof(mp_input_fd_t));
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
284 num_key_fd--;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
285 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
286
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
287 int
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
288 mp_input_add_key_fd(int fd, int select, mp_key_func_t read_func, mp_close_func_t close_func) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
289 if(num_key_fd == MP_MAX_KEY_FD) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
290 printf("Too much key fd, unable to register fd %d\n",fd);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
291 return 0;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
292 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
293
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
294 memset(&key_fds[num_key_fd],0,sizeof(mp_input_fd_t));
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
295 key_fds[num_key_fd].fd = fd;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
296 key_fds[num_key_fd].read_func = read_func ? read_func : mp_input_default_key_func;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
297 key_fds[num_key_fd].close_func = close_func;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
298 if(!select)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
299 key_fds[num_key_fd].flags |= MP_FD_NO_SELECT;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
300 num_key_fd++;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
301 if(fd > key_max_fd)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
302 key_max_fd = fd;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
303
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
304 return 1;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
305 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
306
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
307
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
308
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
309 static mp_cmd_t*
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
310 mp_input_parse_cmd(char* str) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
311 int i,l;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
312 char *ptr,*e;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
313 mp_cmd_t *cmd, *cmd_def;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
314
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
315 #ifdef MP_DEBUG
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
316 assert(str != NULL);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
317 #endif
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
318
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
319 ptr = strchr(str,' ');
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
320 if(ptr)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
321 l = ptr-str;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
322 else
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
323 l = strlen(str);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
324
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
325 if(l == 0)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
326 return NULL;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
327
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
328 for(i=0; mp_cmds[i].name != NULL; i++) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
329 if(strncasecmp(mp_cmds[i].name,str,l) == 0)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
330 break;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
331 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
332
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
333 if(mp_cmds[i].name == NULL)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
334 return NULL;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
335
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
336 cmd_def = &mp_cmds[i];
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
337
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
338 cmd = (mp_cmd_t*)malloc(sizeof(mp_cmd_t));
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
339 cmd->id = cmd_def->id;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
340 cmd->name = strdup(cmd_def->name);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
341
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
342 ptr = str;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
343
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
344 for(i=0; ptr && i < MP_CMD_MAX_ARGS; i++) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
345 ptr = strchr(ptr,' ');
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
346 if(!ptr) break;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
347 while(ptr[0] == ' ') ptr++;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
348 if(ptr[0] == '\0') break;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
349 switch(cmd_def->args[i].type) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
350 case MP_CMD_ARG_INT:
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
351 errno = 0;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
352 cmd->args[i].v.i = atoi(ptr);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
353 if(errno != 0) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
354 printf("Command %s : argument %d isn't an integer\n",cmd_def->name,i+1);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
355 ptr = NULL;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
356 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
357 break;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
358 case MP_CMD_ARG_FLOAT:
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
359 errno = 0;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
360 cmd->args[i].v.f = atof(ptr);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
361 if(errno != 0) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
362 printf("Command %s : argument %d isn't a float\n",cmd_def->name,i+1);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
363 ptr = NULL;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
364 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
365 break;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
366 case MP_CMD_ARG_STRING:
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
367 e = strchr(ptr,' ');
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
368 if(!e) e = ptr+strlen(ptr);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
369 l = e-ptr;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
370 cmd->args[i].v.s = (char*)malloc((l+1)*sizeof(char));
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
371 strncpy(cmd->args[i].v.s,ptr,l);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
372 cmd->args[i].v.s[l] = '\0';
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
373 break;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
374 case -1:
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
375 ptr = NULL;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
376 default :
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
377 printf("Unknow argument %d\n",i);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
378 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
379 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
380 cmd->nargs = i;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
381
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
382 if(cmd_def->nargs > cmd->nargs) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
383 printf("Got [%s] but\n",str);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
384 printf("Command %s require at least %d arguments, we found only %d so far\n",cmd_def->name,cmd_def->nargs,cmd->nargs);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
385 mp_cmd_free(cmd);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
386 return NULL;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
387 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
388
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
389 for( ; i < MP_CMD_MAX_ARGS && cmd_def->args[i].type != -1 ; i++)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
390 memcpy(&cmd->args[i].v,&cmd_def->args[i].v,sizeof(mp_cmd_arg_value_t));
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
391
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
392 return cmd;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
393 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
394
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
395 static int
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
396 mp_input_default_key_func(int fd) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
397 int r,code=0;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
398 unsigned int l;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
399 l = 0;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
400 while(l < sizeof(int)) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
401 r = read(fd,(&code)+l,sizeof(int)-l);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
402 if(r <= 0)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
403 break;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
404 l +=r;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
405 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
406 return code;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
407 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
408
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
409 #define MP_CMD_MAX_SIZE 256
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
410
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
411 static int
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
412 mp_input_read_cmd(mp_input_fd_t* mp_fd, char** ret) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
413 char* end;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
414 (*ret) = NULL;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
415
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
416 if(!mp_fd->buffer) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
417 mp_fd->buffer = (char*)malloc(MP_CMD_MAX_SIZE*sizeof(char));
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
418 mp_fd->pos = 0;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
419 mp_fd->size = MP_CMD_MAX_SIZE;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
420 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
421
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
422 if(mp_fd->size - mp_fd->pos == 0) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
423 printf("Cmd buffer of fd %d is full : dropping content\n",mp_fd->fd);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
424 mp_fd->pos = 0;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
425 mp_fd->flags |= MP_FD_DROP;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
426 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
427
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
428 while( !(mp_fd->flags & MP_FD_EOF) && (mp_fd->size - mp_fd->pos > 1) ) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
429 int r = ((mp_cmd_func_t)mp_fd->read_func)(mp_fd->fd,mp_fd->buffer+mp_fd->pos,mp_fd->size - 1 - mp_fd->pos);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
430 if(r < 0) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
431 if(errno == EINTR)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
432 continue;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
433 else if(errno == EAGAIN)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
434 break;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
435 printf("Error while reading cmd fd %d : %s\n",mp_fd->fd,strerror(errno));
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
436 return MP_INPUT_ERROR;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
437 } else if(r == 0) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
438 mp_fd->flags |= MP_FD_EOF;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
439 break;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
440 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
441 mp_fd->pos += r;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
442 break;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
443 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
444
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
445
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
446 while(1) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
447 int l = 0;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
448 mp_fd->buffer[mp_fd->pos] = '\0';
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
449 end = strchr(mp_fd->buffer,'\n');
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
450 if(!end)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
451 break;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
452 else if((*ret)) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
453 mp_fd->flags |= MP_FD_GOT_CMD;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
454 break;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
455 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
456
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
457 l = end - mp_fd->buffer;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
458
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
459 if( ! (mp_fd->flags & MP_FD_DROP)) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
460 (*ret) = (char*)malloc((l+1)*sizeof(char));
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
461 strncpy((*ret),mp_fd->buffer,l);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
462 (*ret)[l] = '\0';
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
463 } else {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
464 mp_fd->flags &= ~MP_FD_DROP;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
465 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
466 if( mp_fd->pos - (l+1) > 0)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
467 memmove(mp_fd->buffer,end,mp_fd->pos-(l+1));
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
468 mp_fd->pos -= l+1;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
469 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
470
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
471 if(*ret)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
472 return 1;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
473 else
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
474 return MP_INPUT_NOTHING;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
475 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
476
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
477 static mp_cmd_t*
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
478 mp_input_read_keys(int time,int paused) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
479 fd_set fds;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
480 struct timeval tv;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
481 int i,n=0;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
482 static int last_loop = 0;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
483
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
484 if(num_key_fd == 0)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
485 return NULL;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
486
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
487 FD_ZERO(&fds);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
488 for(i = 0; (unsigned int)i < num_key_fd; i++) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
489 if( (key_fds[i].flags & MP_FD_DEAD) ) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
490 mp_input_rm_key_fd(key_fds[i].fd);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
491 i--;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
492 continue;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
493 } else if(key_fds[i].flags & MP_FD_NO_SELECT)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
494 continue;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
495
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
496 FD_SET(key_fds[i].fd,&fds);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
497 n++;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
498 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
499
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
500 if(n > 0 ) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
501
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
502 tv.tv_sec=time/1000;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
503 tv.tv_usec = (time%1000)*1000;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
504
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
505 while(1) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
506 if(select(key_max_fd+1,&fds,NULL,NULL,&tv) < 0) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
507 if(errno == EINTR)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
508 continue;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
509 printf("Select error : %s\n",strerror(errno));
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
510 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
511 break;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
512 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
513 } else {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
514 FD_ZERO(&fds);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
515 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
516
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
517 for(i = last_loop + 1 ; i != last_loop ; i++) {
4589
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
518 int code = -1;
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
519 unsigned int j;
4418
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
520
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
521 if((unsigned int)i >= num_key_fd) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
522 i = -1;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
523 last_loop++;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
524 continue;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
525 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
526 if(! (key_fds[i].flags & MP_FD_NO_SELECT) && ! FD_ISSET(key_fds[i].fd,&fds))
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
527 continue;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
528 if(key_fds[i].fd == 0) { // stdin is handled by getch2
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
529 code = getch2(time);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
530 if(code < 0)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
531 code = MP_INPUT_NOTHING;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
532 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
533 else
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
534 code = ((mp_key_func_t)key_fds[i].read_func)(key_fds[i].fd);
4589
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
535 if((code & ~MP_KEY_DOWN) < 0) {
4418
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
536 if(code == MP_INPUT_ERROR)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
537 printf("Error on key input fd %d\n",key_fds[i].fd);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
538 else if(code == MP_INPUT_DEAD) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
539 printf("Dead key input on fd %d\n",key_fds[i].fd);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
540 key_fds[i].flags |= MP_FD_DEAD;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
541 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
542 continue;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
543 }
4589
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
544 if(code & MP_KEY_DOWN) { // key pushed
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
545 if(num_key_down > MP_MAX_KEY_DOWN) {
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
546 printf("Too much key down at the same time\n");
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
547 continue;
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
548 }
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
549 code &= ~MP_KEY_DOWN;
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
550 key_down[num_key_down] = code;
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
551 num_key_down++;
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
552 last_key_down = 1;
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
553 continue;
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
554 }
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
555 key_was_down = 0;
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
556 if(num_key_down > 0) { // key released
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
557 for(j = 0; j < num_key_down; j++) {
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
558 if(key_down[j] == code) { // Remove the key from the current combination
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
559 if(j+1 < num_key_down)
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
560 memmove(&key_down[j],&key_down[j+1],(num_key_down-(j+1))*sizeof(int));
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
561 num_key_down--;
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
562 key_was_down = 1;
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
563 break;
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
564 }
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
565 }
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
566 if(key_was_down && !last_key_down) // Ignore relaesing key part of the combination
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
567 continue;
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
568 last_key_down = 0;
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
569 }
4418
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
570 if(paused)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
571 return mp_input_parse_cmd("pause");
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
572 for(j = 0; cmd_binds[j].cmd != NULL; j++) {
4589
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
573 if(num_key_down > 0) {
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
574 unsigned int found = 1,s;
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
575 for(s = 0; cmd_binds[j].input[s+1] != 0; s++) {
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
576 if(cmd_binds[j].input[s] != key_down[s]) {
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
577 found = 0;
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
578 break;
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
579 }
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
580 }
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
581 if(found && s == num_key_down && cmd_binds[j].input[s] == code && cmd_binds[j].input[s+1] == 0)
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
582 break;
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
583 continue;
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
584 } else {
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
585 if(cmd_binds[j].input[0] == code && cmd_binds[j].input[1] == 0)
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
586 break;
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
587 }
4418
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
588 }
4518
83128eed25f1 Corrected the quit bug and added support for up to 10 axis
albeu
parents: 4432
diff changeset
589 if(cmd_binds[j].cmd == NULL) {
4589
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
590 printf("No bind found for key %d",num_key_down > 0 ? key_down[0] : code);
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
591 if(num_key_down > 0) {
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
592 unsigned int s;
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
593 for(s=1; s < num_key_down; s++)
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
594 printf("-%d",key_down[s]);
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
595 printf("-%d",code);
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
596 }
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
597 printf(" \n");
4418
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
598 continue;
4518
83128eed25f1 Corrected the quit bug and added support for up to 10 axis
albeu
parents: 4432
diff changeset
599 }
4418
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
600 last_loop = i;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
601 return mp_input_parse_cmd(cmd_binds[j].cmd);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
602 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
603
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
604 last_loop = 0;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
605 return NULL;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
606 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
607
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
608 static mp_cmd_t*
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
609 mp_input_read_cmds(int time) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
610 fd_set fds;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
611 struct timeval tv;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
612 int i,n = 0;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
613 mp_cmd_t* ret;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
614 static int last_loop = 0;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
615
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
616 if(num_cmd_fd == 0)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
617 return NULL;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
618
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
619 FD_ZERO(&fds);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
620 for(i = 0; (unsigned int)i < num_cmd_fd ; i++) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
621 if( (cmd_fds[i].flags & MP_FD_DEAD) || (cmd_fds[i].flags & MP_FD_EOF) ) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
622 mp_input_rm_cmd_fd(cmd_fds[i].fd);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
623 i--;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
624 continue;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
625 } else if(cmd_fds[i].flags & MP_FD_NO_SELECT)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
626 continue;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
627 FD_SET(cmd_fds[i].fd,&fds);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
628 n++;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
629 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
630
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
631 if(n > 0) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
632
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
633 tv.tv_sec=time/1000;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
634 tv.tv_usec = (time%1000)*1000;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
635
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
636 while(1) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
637 if((i = select(cmd_max_fd+1,&fds,NULL,NULL,&tv)) <= 0) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
638 if(i < 0) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
639 if(errno == EINTR)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
640 continue;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
641 printf("Select error : %s\n",strerror(errno));
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
642 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
643 return NULL;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
644 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
645 break;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
646 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
647 } else {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
648 FD_ZERO(&fds);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
649 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
650
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
651 for(i = last_loop + 1; i != last_loop ; i++) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
652 int r = 0;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
653 char* cmd;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
654 if((unsigned int)i >= num_cmd_fd) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
655 i = -1;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
656 last_loop++;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
657 continue;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
658 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
659 if( ! (cmd_fds[i].flags & MP_FD_NO_SELECT) && ! FD_ISSET(cmd_fds[i].fd,&fds) && ! (cmd_fds[i].flags & MP_FD_GOT_CMD) )
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
660 continue;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
661
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
662 r = mp_input_read_cmd(&cmd_fds[i],&cmd);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
663 if(r < 0) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
664 if(r == MP_INPUT_ERROR)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
665 printf("Error on cmd fd %d\n",cmd_fds[i].fd);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
666 else if(r == MP_INPUT_DEAD)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
667 cmd_fds[i].flags |= MP_FD_DEAD;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
668 continue;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
669 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
670 ret = mp_input_parse_cmd(cmd);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
671 free(cmd);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
672 if(!ret)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
673 continue;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
674 last_loop = i;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
675 return ret;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
676 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
677
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
678 last_loop = 0;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
679 return NULL;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
680 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
681
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
682 mp_cmd_t*
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
683 mp_input_get_cmd(int time, int paused) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
684 mp_cmd_t* ret;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
685
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
686 ret = mp_input_read_keys(time,paused);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
687 if(ret)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
688 return ret;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
689
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
690 return mp_input_read_cmds(time);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
691 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
692
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
693 void
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
694 mp_cmd_free(mp_cmd_t* cmd) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
695 int i;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
696 #ifdef MP_DEBUG
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
697 assert(cmd != NULL);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
698 #endif
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
699
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
700 if(cmd->name)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
701 free(cmd->name);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
702
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
703 for(i=0; i < MP_CMD_MAX_ARGS && cmd->args[i].type != -1; i++) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
704 if(cmd->args[i].type == MP_CMD_ARG_STRING)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
705 free(cmd->args[i].v.s);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
706 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
707 free(cmd);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
708 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
709
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
710 static int
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
711 mp_input_get_key_from_name(char* name) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
712 int i,ret = 0;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
713 if(strlen(name) == 1) { // Direct key code
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
714 (char)ret = name[0];
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
715 return ret;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
716 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
717
4589
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
718 for(i = 0; key_names[i].name != NULL; i++) {
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
719 if(strcasecmp(key_names[i].name,name) == 0)
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
720 return key_names[i].key;
4418
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
721 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
722
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
723 return -1;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
724 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
725
4589
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
726 static int
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
727 mp_input_get_input_from_name(char* name,int* keys) {
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
728 char *end,*ptr;
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
729 int n=0;
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
730
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
731 ptr = name;
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
732 n = 0;
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
733 for(end = strchr(ptr,'-') ; ptr != NULL ; end = strchr(ptr,'-')) {
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
734 if(end && end[1] != '\0') {
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
735 if(end[1] == '-')
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
736 end = &end[1];
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
737 end[0] = '\0';
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
738 }
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
739 keys[n] = mp_input_get_key_from_name(ptr);
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
740 if(keys[n] < 0) {
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
741 return 0;
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
742 }
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
743 n++;
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
744 if(end && end[1] != '\0' && n < MP_MAX_KEY_DOWN)
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
745 ptr = &end[1];
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
746 else
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
747 break;
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
748 }
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
749 keys[n] = 0;
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
750 return 1;
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
751 }
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
752
4418
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
753 static void
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
754 mp_input_free_binds(mp_cmd_bind_t* binds) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
755 int i;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
756
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
757 if(!binds)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
758 return;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
759
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
760 for(i = 0; binds[i].cmd != NULL; i++)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
761 free(binds[i].cmd);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
762
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
763 free(binds);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
764
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
765 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
766
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
767
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
768 #define BS_MAX 256
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
769 #define SPACE_CHAR " \n\r\t"
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
770
4525
46c4e34b4e76 Tell the user when we fallback on default config.
albeu
parents: 4524
diff changeset
771 static int
4418
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
772 mp_input_parse_config(char *file) {
4589
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
773 int fd;
4418
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
774 int bs = 0,r,eof = 0;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
775 char *iter,*end;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
776 char buffer[BS_MAX];
4589
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
777 int n_binds = 0, keys[MP_MAX_KEY_DOWN+1] = { 0 };
4418
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
778 mp_cmd_bind_t* binds = NULL;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
779
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
780 fd = open(file,O_RDONLY);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
781
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
782 if(fd < 0) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
783 printf("Can't open input config file %s : %s\n",file,strerror(errno));
4525
46c4e34b4e76 Tell the user when we fallback on default config.
albeu
parents: 4524
diff changeset
784 return 0;
4418
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
785 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
786
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
787 printf("Parsing input config file %s\n",file);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
788
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
789 while(1) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
790 if(! eof && bs < BS_MAX-1) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
791 if(bs > 0) bs--;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
792 r = read(fd,buffer+bs,BS_MAX-1-bs);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
793 if(r < 0) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
794 if(errno == EINTR)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
795 continue;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
796 printf("Error while reading input config file %s : %s\n",file,strerror(errno));
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
797 mp_input_free_binds(binds);
4525
46c4e34b4e76 Tell the user when we fallback on default config.
albeu
parents: 4524
diff changeset
798 return 0;
4418
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
799 } else if(r == 0)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
800 eof = 1;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
801 else {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
802 bs += r+1;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
803 buffer[bs-1] = '\0';
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
804 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
805 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
806 // Empty buffer : return
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
807 if(bs <= 1) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
808 printf("Input config file %s parsed : %d binds\n",file,n_binds);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
809 if(binds)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
810 cmd_binds = binds;
4525
46c4e34b4e76 Tell the user when we fallback on default config.
albeu
parents: 4524
diff changeset
811 return 1;
4418
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
812 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
813
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
814 iter = buffer;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
815
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
816 // Find the wanted key
4589
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
817 if(keys[0] == 0) {
4418
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
818 // Jump beginnig space
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
819 for( ; iter[0] != '\0' && strchr(SPACE_CHAR,iter[0]) != NULL ; iter++)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
820 /* NOTHING */;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
821 if(iter[0] == '\0') { // Buffer was full of space char
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
822 bs = 0;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
823 continue;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
824 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
825 // Find the end of the key code name
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
826 for(end = iter; end[0] != '\0' && strchr(SPACE_CHAR,end[0]) == NULL ; end++)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
827 /*NOTHING */;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
828 if(end[0] == '\0') { // Key name don't fit in the buffer
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
829 if(buffer == iter) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
830 if(eof && (buffer-iter) == bs)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
831 printf("Unfinished binding %s\n",iter);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
832 else
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
833 printf("Buffer is too small for this key name : %s\n",iter);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
834 mp_input_free_binds(binds);
4525
46c4e34b4e76 Tell the user when we fallback on default config.
albeu
parents: 4524
diff changeset
835 return 0;
4418
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
836 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
837 memmove(buffer,iter,end-iter);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
838 bs = end-iter;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
839 continue;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
840 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
841 {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
842 char name[end-iter+1];
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
843 strncpy(name,iter,end-iter);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
844 name[end-iter] = '\0';
4589
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
845 if(! mp_input_get_input_from_name(name,keys)) {
4418
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
846 printf("Unknow key %s\n",name);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
847 mp_input_free_binds(binds);
4525
46c4e34b4e76 Tell the user when we fallback on default config.
albeu
parents: 4524
diff changeset
848 return 0;
4418
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
849 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
850 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
851 if( bs > (end-buffer))
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
852 memmove(buffer,end,bs - (end-buffer));
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
853 bs -= end-buffer;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
854 continue;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
855 } else { // Get the command
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
856 while(iter[0] == ' ' || iter[0] == '\t') iter++;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
857 // Found new line
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
858 if(iter[0] == '\n' || iter[0] == '\r') {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
859 printf("No command found for key (TODO)\n" /*mp_input_get_key_name(code)*/);
4589
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
860 keys[0] = 0;
4418
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
861 if(iter > buffer) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
862 memmove(buffer,iter,bs- (iter-buffer));
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
863 bs -= (iter-buffer);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
864 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
865 continue;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
866 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
867 for(end = iter ; end[0] != '\n' && end[0] != '\r' && end[0] != '\0' ; end++)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
868 /* NOTHING */;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
869 if(end[0] == '\0' && ! (eof && (end - buffer) == bs)) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
870 if(iter == buffer) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
871 printf("Buffer is too small for command %s\n",buffer);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
872 mp_input_free_binds(binds);
4525
46c4e34b4e76 Tell the user when we fallback on default config.
albeu
parents: 4524
diff changeset
873 return 0;
4418
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
874 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
875 memmove(buffer,iter,end - iter);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
876 bs = end - iter;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
877 continue;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
878 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
879 {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
880 char cmd[end-iter+1];
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
881 strncpy(cmd,iter,end-iter);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
882 cmd[end-iter] = '\0';
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
883 //printf("Set bind %d => %s\n",code,cmd);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
884 binds = (mp_cmd_bind_t*)realloc(binds,(n_binds+2)*sizeof(mp_cmd_bind_t));
4589
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
885 memcpy(&binds[n_binds].input,keys,MP_MAX_KEY_DOWN+1);
4418
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
886 binds[n_binds].cmd = strdup(cmd);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
887 n_binds++;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
888 memset(&binds[n_binds],0,sizeof(mp_cmd_bind_t));
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
889 }
4589
4ce20c55a18a Added support for key combination and mouse buttons key code
albeu
parents: 4525
diff changeset
890 keys[0] = 0;
4418
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
891 if(bs > (end-buffer))
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
892 memmove(buffer,end,bs-(end-buffer));
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
893 bs -= (end-buffer);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
894 continue;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
895 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
896 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
897 printf("What are we doing here ?\n");
4525
46c4e34b4e76 Tell the user when we fallback on default config.
albeu
parents: 4524
diff changeset
898 return 0;
4418
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
899 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
900
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
901 extern char *get_path(char *filename);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
902
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
903 void
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
904 mp_input_init(void) {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
905 char* file;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
906
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
907 file = get_path("input.conf");
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
908 if(!file)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
909 return;
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
910
4525
46c4e34b4e76 Tell the user when we fallback on default config.
albeu
parents: 4524
diff changeset
911 if(! mp_input_parse_config(file))
46c4e34b4e76 Tell the user when we fallback on default config.
albeu
parents: 4524
diff changeset
912 printf("Falling back on default (hardcoded) config\n");
4418
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
913
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
914 #ifdef HAVE_JOYSTICK
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
915 {
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
916 int fd = mp_input_joystick_init(NULL);
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
917 if(fd < 0)
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
918 printf("Can't init input joystick\n");
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
919 else
4524
01a0cf736e0d Fix the bugs the previous version should fix (and those introduced
albeu
parents: 4518
diff changeset
920 mp_input_add_key_fd(fd,1,mp_input_joystick_read,(mp_close_func_t)close);
4418
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
921 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
922 #endif
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
923
4432
5105f5da01d6 Added lirc support in input
albeu
parents: 4418
diff changeset
924 #ifdef HAVE_LIRC
5105f5da01d6 Added lirc support in input
albeu
parents: 4418
diff changeset
925 {
5105f5da01d6 Added lirc support in input
albeu
parents: 4418
diff changeset
926 int fd = mp_input_lirc_init();
5105f5da01d6 Added lirc support in input
albeu
parents: 4418
diff changeset
927 if(fd > 0)
5105f5da01d6 Added lirc support in input
albeu
parents: 4418
diff changeset
928 mp_input_add_cmd_fd(fd,1,NULL,(mp_close_func_t)close);
5105f5da01d6 Added lirc support in input
albeu
parents: 4418
diff changeset
929 }
5105f5da01d6 Added lirc support in input
albeu
parents: 4418
diff changeset
930 #endif
5105f5da01d6 Added lirc support in input
albeu
parents: 4418
diff changeset
931
5105f5da01d6 Added lirc support in input
albeu
parents: 4418
diff changeset
932 }
5105f5da01d6 Added lirc support in input
albeu
parents: 4418
diff changeset
933
5105f5da01d6 Added lirc support in input
albeu
parents: 4418
diff changeset
934 void
5105f5da01d6 Added lirc support in input
albeu
parents: 4418
diff changeset
935 mp_input_uninit(void) {
4518
83128eed25f1 Corrected the quit bug and added support for up to 10 axis
albeu
parents: 4432
diff changeset
936 unsigned int i;
83128eed25f1 Corrected the quit bug and added support for up to 10 axis
albeu
parents: 4432
diff changeset
937
83128eed25f1 Corrected the quit bug and added support for up to 10 axis
albeu
parents: 4432
diff changeset
938 for(i=0; i < num_key_fd; i++) {
83128eed25f1 Corrected the quit bug and added support for up to 10 axis
albeu
parents: 4432
diff changeset
939 if(key_fds[i].close_func)
83128eed25f1 Corrected the quit bug and added support for up to 10 axis
albeu
parents: 4432
diff changeset
940 key_fds[i].close_func(key_fds[i].fd);
83128eed25f1 Corrected the quit bug and added support for up to 10 axis
albeu
parents: 4432
diff changeset
941 }
83128eed25f1 Corrected the quit bug and added support for up to 10 axis
albeu
parents: 4432
diff changeset
942
83128eed25f1 Corrected the quit bug and added support for up to 10 axis
albeu
parents: 4432
diff changeset
943 for(i=0; i < num_cmd_fd; i++) {
83128eed25f1 Corrected the quit bug and added support for up to 10 axis
albeu
parents: 4432
diff changeset
944 if(cmd_fds[i].close_func)
83128eed25f1 Corrected the quit bug and added support for up to 10 axis
albeu
parents: 4432
diff changeset
945 cmd_fds[i].close_func(cmd_fds[i].fd);
83128eed25f1 Corrected the quit bug and added support for up to 10 axis
albeu
parents: 4432
diff changeset
946 }
83128eed25f1 Corrected the quit bug and added support for up to 10 axis
albeu
parents: 4432
diff changeset
947
4432
5105f5da01d6 Added lirc support in input
albeu
parents: 4418
diff changeset
948
5105f5da01d6 Added lirc support in input
albeu
parents: 4418
diff changeset
949 #ifdef HAVE_LIRC
5105f5da01d6 Added lirc support in input
albeu
parents: 4418
diff changeset
950 mp_input_lirc_uninit();
5105f5da01d6 Added lirc support in input
albeu
parents: 4418
diff changeset
951 #endif
5105f5da01d6 Added lirc support in input
albeu
parents: 4418
diff changeset
952
4418
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
953 }
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
954
8141d2c399e4 A new configurable input system and joystick support for this system
albeu
parents:
diff changeset
955 #endif /* HAVE_NEW_INPUT */