Mercurial > mplayer.hg
annotate input/input.c @ 4524:01a0cf736e0d
Fix the bugs the previous version should fix (and those introduced
by the previous version ;) )
author | albeu |
---|---|
date | Mon, 04 Feb 2002 14:19:54 +0000 |
parents | 83128eed25f1 |
children | 46c4e34b4e76 |
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> |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
12 #include <fcntl.h> |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
13 |
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 #include "input.h" |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
17 #ifdef MP_DEBUG |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
18 #include <assert.h> |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
19 #endif |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
20 #include "../linux/getch2.h" |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
21 #include "../linux/keycodes.h" |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
22 #include "../linux/timer.h" |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
23 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
24 #ifdef HAVE_JOYSTICK |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
25 #include "joystick.h" |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
26 #endif |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
27 |
4432 | 28 #ifdef HAVE_LIRC |
29 #include "lirc.h" | |
30 #endif | |
31 | |
4418
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
32 // 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
|
33 // an argument exist. |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
34 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
35 static mp_cmd_t mp_cmds[] = { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
36 { 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
|
37 { 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
|
38 { MP_CMD_QUIT, "quit", 0, { {-1,{0}} } }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
39 { MP_CMD_PAUSE, "pause", 0, { {-1,{0}} } }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
40 { 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
|
41 { 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
|
42 { 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
|
43 { 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
|
44 { 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
|
45 { 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
|
46 { 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
|
47 { 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
|
48 { 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
|
49 { 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
|
50 { 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
|
51 { 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
|
52 { 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
|
53 #ifdef USE_TV |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
54 { 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
|
55 { 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
|
56 { 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
|
57 #endif |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
58 { 0, NULL, 0, {} } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
59 }; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
60 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
61 static mp_cmd_bind_t key_names[] = { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
62 { ' ', "SPACE" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
63 { KEY_ENTER, "ENTER" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
64 { KEY_TAB, "TAB" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
65 { KEY_CTRL, "CTRL" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
66 { KEY_BACKSPACE, "BS" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
67 { KEY_DELETE, "DEL" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
68 { KEY_INSERT, "INS" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
69 { KEY_HOME, "HOME" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
70 { KEY_END, "END" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
71 { KEY_PAGE_UP, "PGUP" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
72 { KEY_PAGE_DOWN, "PGDWN" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
73 { KEY_ESC, "ESC" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
74 { KEY_RIGHT, "RIGHT" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
75 { KEY_LEFT, "LEFT" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
76 { KEY_DOWN, "DOWN" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
77 { KEY_UP, "UP" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
78 #ifdef HAVE_JOYSTICK |
4524
01a0cf736e0d
Fix the bugs the previous version should fix (and those introduced
albeu
parents:
4518
diff
changeset
|
79 { JOY_AXIS1_MINUS, "JOY_UP" }, |
01a0cf736e0d
Fix the bugs the previous version should fix (and those introduced
albeu
parents:
4518
diff
changeset
|
80 { JOY_AXIS1_PLUS, "JOY_DOWN" }, |
01a0cf736e0d
Fix the bugs the previous version should fix (and those introduced
albeu
parents:
4518
diff
changeset
|
81 { JOY_AXIS0_MINUS, "JOY_LEFT" }, |
01a0cf736e0d
Fix the bugs the previous version should fix (and those introduced
albeu
parents:
4518
diff
changeset
|
82 { JOY_AXIS0_PLUS, "JOY_RIGHT" }, |
4518
83128eed25f1
Corrected the quit bug and added support for up to 10 axis
albeu
parents:
4432
diff
changeset
|
83 |
83128eed25f1
Corrected the quit bug and added support for up to 10 axis
albeu
parents:
4432
diff
changeset
|
84 { JOY_AXIS0_PLUS, "JOY_AXIS0_PLUS" }, |
83128eed25f1
Corrected the quit bug and added support for up to 10 axis
albeu
parents:
4432
diff
changeset
|
85 { JOY_AXIS0_MINUS, "JOY_AXIS0_MINUS" }, |
83128eed25f1
Corrected the quit bug and added support for up to 10 axis
albeu
parents:
4432
diff
changeset
|
86 { JOY_AXIS1_PLUS, " JOY_AXIS1_PLUS" }, |
83128eed25f1
Corrected the quit bug and added support for up to 10 axis
albeu
parents:
4432
diff
changeset
|
87 { JOY_AXIS1_MINUS, "JOY_AXIS1_MINUS" }, |
83128eed25f1
Corrected the quit bug and added support for up to 10 axis
albeu
parents:
4432
diff
changeset
|
88 { JOY_AXIS2_PLUS, "JOY_AXIS2_PLUS" }, |
83128eed25f1
Corrected the quit bug and added support for up to 10 axis
albeu
parents:
4432
diff
changeset
|
89 { JOY_AXIS2_MINUS, "JOY_AXIS2_MINUS" }, |
83128eed25f1
Corrected the quit bug and added support for up to 10 axis
albeu
parents:
4432
diff
changeset
|
90 { JOY_AXIS3_PLUS, " JOY_AXIS3_PLUS" }, |
83128eed25f1
Corrected the quit bug and added support for up to 10 axis
albeu
parents:
4432
diff
changeset
|
91 { JOY_AXIS3_MINUS, "JOY_AXIS3_MINUS" }, |
83128eed25f1
Corrected the quit bug and added support for up to 10 axis
albeu
parents:
4432
diff
changeset
|
92 { JOY_AXIS4_PLUS, "JOY_AXIS4_PLUS" }, |
83128eed25f1
Corrected the quit bug and added support for up to 10 axis
albeu
parents:
4432
diff
changeset
|
93 { JOY_AXIS4_MINUS, "JOY_AXIS4_MINUS" }, |
83128eed25f1
Corrected the quit bug and added support for up to 10 axis
albeu
parents:
4432
diff
changeset
|
94 { JOY_AXIS5_PLUS, " JOY_AXIS5_PLUS" }, |
83128eed25f1
Corrected the quit bug and added support for up to 10 axis
albeu
parents:
4432
diff
changeset
|
95 { JOY_AXIS5_MINUS, "JOY_AXIS5_MINUS" }, |
83128eed25f1
Corrected the quit bug and added support for up to 10 axis
albeu
parents:
4432
diff
changeset
|
96 { JOY_AXIS6_PLUS, "JOY_AXIS6_PLUS" }, |
83128eed25f1
Corrected the quit bug and added support for up to 10 axis
albeu
parents:
4432
diff
changeset
|
97 { JOY_AXIS6_MINUS, "JOY_AXIS6_MINUS" }, |
83128eed25f1
Corrected the quit bug and added support for up to 10 axis
albeu
parents:
4432
diff
changeset
|
98 { JOY_AXIS7_PLUS, " JOY_AXIS7_PLUS" }, |
83128eed25f1
Corrected the quit bug and added support for up to 10 axis
albeu
parents:
4432
diff
changeset
|
99 { JOY_AXIS7_MINUS, "JOY_AXIS7_MINUS" }, |
83128eed25f1
Corrected the quit bug and added support for up to 10 axis
albeu
parents:
4432
diff
changeset
|
100 { JOY_AXIS8_PLUS, "JOY_AXIS8_PLUS" }, |
83128eed25f1
Corrected the quit bug and added support for up to 10 axis
albeu
parents:
4432
diff
changeset
|
101 { JOY_AXIS8_MINUS, "JOY_AXIS8_MINUS" }, |
83128eed25f1
Corrected the quit bug and added support for up to 10 axis
albeu
parents:
4432
diff
changeset
|
102 { JOY_AXIS9_PLUS, " JOY_AXIS9_PLUS" }, |
83128eed25f1
Corrected the quit bug and added support for up to 10 axis
albeu
parents:
4432
diff
changeset
|
103 { JOY_AXIS9_MINUS, "JOY_AXIS9_MINUS" }, |
83128eed25f1
Corrected the quit bug and added support for up to 10 axis
albeu
parents:
4432
diff
changeset
|
104 |
4418
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
105 { JOY_BTN0, "JOY_BTN0" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
106 { JOY_BTN1, "JOY_BTN1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
107 { JOY_BTN2, "JOY_BTN2" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
108 { JOY_BTN3, "JOY_BTN3" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
109 { JOY_BTN4, "JOY_BTN4" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
110 { JOY_BTN5, "JOY_BTN5" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
111 { JOY_BTN6, "JOY_BTN6" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
112 { JOY_BTN7, "JOY_BTN7" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
113 { JOY_BTN8, "JOY_BTN8" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
114 { JOY_BTN9, "JOY_BTN9" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
115 #endif |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
116 { 0, NULL } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
117 }; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
118 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
119 // 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
|
120 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
121 static mp_cmd_bind_t def_cmd_binds[] = { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
122 { KEY_RIGHT, "seek 10" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
123 { KEY_LEFT, "seek -10" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
124 { KEY_UP, "seek 60" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
125 { KEY_DOWN, "seek -60" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
126 { KEY_PAGE_UP, "seek 600" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
127 { KEY_PAGE_DOWN, "seek -600" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
128 { '+', "audio_delay 0.100" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
129 { '-', "audio_delay -0.100" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
130 { 'q', "quit" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
131 { KEY_ESC, "quit" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
132 { 'p', "pause" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
133 { ' ', "pause" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
134 { KEY_HOME, "pt_up_step 1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
135 { KEY_END, "pt_up_step -1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
136 { '>', "pt_step 1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
137 { '<', "pt_step -1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
138 { KEY_INS, "alt_src_step 1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
139 { KEY_DEL, "alt_src_step -1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
140 { 'o', "osd" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
141 { 'z', "sub_delay -0.1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
142 { 'x', "sub_delay +0.1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
143 { '9', "volume -1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
144 { '/', "volume -1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
145 { '0', "volume 1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
146 { '*', "volume 1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
147 { 'm', "use_master" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
148 { '1', "contrast -1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
149 { '2', "contrast 1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
150 { '3', "brightness -1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
151 { '4', "brightness 1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
152 { '5', "hue -1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
153 { '6', "hue 1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
154 { '7', "saturation -1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
155 { '8', "saturation 1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
156 { 'd', "frame_drop" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
157 #ifdef USE_TV |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
158 { 'h', "tv_step_channel 1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
159 { 'l', "tv_step_channel -1" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
160 { 'n', "tv_step_norm" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
161 { 'b', "tv_step_chanlist" }, |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
162 #endif |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
163 { 0, NULL } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
164 }; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
165 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
166 #ifndef MP_MAX_KEY_FD |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
167 #define MP_MAX_KEY_FD 10 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
168 #endif |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
169 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
170 #ifndef MP_MAX_CMD_FD |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
171 #define MP_MAX_CMD_FD 10 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
172 #endif |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
173 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
174 #define MP_FD_EOF (1<<0) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
175 #define MP_FD_DROP (1<<1) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
176 #define MP_FD_DEAD (1<<2) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
177 #define MP_FD_GOT_CMD (1<<3) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
178 #define MP_FD_NO_SELECT (1<<4) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
179 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
180 typedef struct mp_input_fd { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
181 int fd; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
182 void* read_func; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
183 mp_close_func_t close_func; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
184 int flags; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
185 // This fields are for the cmd fds |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
186 char* buffer; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
187 int pos,size; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
188 } mp_input_fd_t; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
189 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
190 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
191 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
|
192 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
193 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
|
194 static unsigned int num_key_fd = 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
195 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
|
196 static unsigned int num_cmd_fd = 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
197 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
198 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
|
199 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
200 static int |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
201 mp_input_default_key_func(int fd); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
202 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
203 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
204 int |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
205 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
|
206 if(num_cmd_fd == MP_MAX_CMD_FD) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
207 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
|
208 return 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
209 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
210 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
211 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
|
212 cmd_fds[num_cmd_fd].fd = fd; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
213 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
|
214 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
|
215 if(!select) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
216 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
|
217 num_cmd_fd++; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
218 if(fd > cmd_max_fd) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
219 cmd_max_fd = fd; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
220 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
221 return 1; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
222 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
223 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
224 void |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
225 mp_input_rm_cmd_fd(int fd) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
226 unsigned int i; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
227 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
228 for(i = 0; i < num_cmd_fd; i++) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
229 if(cmd_fds[i].fd == fd) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
230 break; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
231 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
232 if(i == num_cmd_fd) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
233 return; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
234 if(cmd_fds[i].close_func) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
235 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
|
236 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
237 if(i + 1 < num_cmd_fd) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
238 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
|
239 num_cmd_fd--; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
240 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
241 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
242 void |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
243 mp_input_rm_key_fd(int fd) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
244 unsigned int i; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
245 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
246 for(i = 0; i < num_key_fd; i++) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
247 if(key_fds[i].fd == fd) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
248 break; |
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 if(i == num_key_fd) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
251 return; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
252 if(key_fds[i].close_func) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
253 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
|
254 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
255 if(i + 1 < num_key_fd) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
256 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
|
257 num_key_fd--; |
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 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
260 int |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
261 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
|
262 if(num_key_fd == MP_MAX_KEY_FD) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
263 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
|
264 return 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
265 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
266 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
267 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
|
268 key_fds[num_key_fd].fd = fd; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
269 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
|
270 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
|
271 if(!select) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
272 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
|
273 num_key_fd++; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
274 if(fd > key_max_fd) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
275 key_max_fd = fd; |
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 return 1; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
278 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
279 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
280 |
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 static mp_cmd_t* |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
283 mp_input_parse_cmd(char* str) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
284 int i,l; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
285 char *ptr,*e; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
286 mp_cmd_t *cmd, *cmd_def; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
287 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
288 #ifdef MP_DEBUG |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
289 assert(str != NULL); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
290 #endif |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
291 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
292 ptr = strchr(str,' '); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
293 if(ptr) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
294 l = ptr-str; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
295 else |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
296 l = strlen(str); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
297 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
298 if(l == 0) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
299 return NULL; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
300 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
301 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
|
302 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
|
303 break; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
304 } |
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 if(mp_cmds[i].name == NULL) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
307 return NULL; |
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 cmd_def = &mp_cmds[i]; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
310 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
311 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
|
312 cmd->id = cmd_def->id; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
313 cmd->name = strdup(cmd_def->name); |
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 ptr = str; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
316 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
317 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
|
318 ptr = strchr(ptr,' '); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
319 if(!ptr) break; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
320 while(ptr[0] == ' ') ptr++; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
321 if(ptr[0] == '\0') break; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
322 switch(cmd_def->args[i].type) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
323 case MP_CMD_ARG_INT: |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
324 errno = 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
325 cmd->args[i].v.i = atoi(ptr); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
326 if(errno != 0) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
327 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
|
328 ptr = NULL; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
329 } |
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 case MP_CMD_ARG_FLOAT: |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
332 errno = 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
333 cmd->args[i].v.f = atof(ptr); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
334 if(errno != 0) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
335 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
|
336 ptr = NULL; |
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 break; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
339 case MP_CMD_ARG_STRING: |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
340 e = strchr(ptr,' '); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
341 if(!e) e = ptr+strlen(ptr); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
342 l = e-ptr; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
343 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
|
344 strncpy(cmd->args[i].v.s,ptr,l); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
345 cmd->args[i].v.s[l] = '\0'; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
346 break; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
347 case -1: |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
348 ptr = NULL; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
349 default : |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
350 printf("Unknow argument %d\n",i); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
351 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
352 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
353 cmd->nargs = i; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
354 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
355 if(cmd_def->nargs > cmd->nargs) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
356 printf("Got [%s] but\n",str); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
357 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
|
358 mp_cmd_free(cmd); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
359 return NULL; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
360 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
361 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
362 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
|
363 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
|
364 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
365 return cmd; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
366 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
367 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
368 static int |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
369 mp_input_default_key_func(int fd) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
370 int r,code=0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
371 unsigned int l; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
372 l = 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
373 while(l < sizeof(int)) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
374 r = read(fd,(&code)+l,sizeof(int)-l); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
375 if(r <= 0) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
376 break; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
377 l +=r; |
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 return code; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
380 } |
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 #define MP_CMD_MAX_SIZE 256 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
383 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
384 static int |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
385 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
|
386 char* end; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
387 (*ret) = NULL; |
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 if(!mp_fd->buffer) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
390 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
|
391 mp_fd->pos = 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
392 mp_fd->size = MP_CMD_MAX_SIZE; |
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 if(mp_fd->size - mp_fd->pos == 0) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
396 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
|
397 mp_fd->pos = 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
398 mp_fd->flags |= MP_FD_DROP; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
399 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
400 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
401 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
|
402 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
|
403 if(r < 0) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
404 if(errno == EINTR) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
405 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
406 else if(errno == EAGAIN) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
407 break; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
408 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
|
409 return MP_INPUT_ERROR; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
410 } else if(r == 0) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
411 mp_fd->flags |= MP_FD_EOF; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
412 break; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
413 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
414 mp_fd->pos += r; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
415 break; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
416 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
417 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
418 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
419 while(1) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
420 int l = 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
421 mp_fd->buffer[mp_fd->pos] = '\0'; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
422 end = strchr(mp_fd->buffer,'\n'); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
423 if(!end) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
424 break; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
425 else if((*ret)) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
426 mp_fd->flags |= MP_FD_GOT_CMD; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
427 break; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
428 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
429 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
430 l = end - mp_fd->buffer; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
431 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
432 if( ! (mp_fd->flags & MP_FD_DROP)) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
433 (*ret) = (char*)malloc((l+1)*sizeof(char)); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
434 strncpy((*ret),mp_fd->buffer,l); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
435 (*ret)[l] = '\0'; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
436 } else { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
437 mp_fd->flags &= ~MP_FD_DROP; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
438 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
439 if( mp_fd->pos - (l+1) > 0) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
440 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
|
441 mp_fd->pos -= l+1; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
442 } |
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 if(*ret) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
445 return 1; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
446 else |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
447 return MP_INPUT_NOTHING; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
448 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
449 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
450 static mp_cmd_t* |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
451 mp_input_read_keys(int time,int paused) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
452 fd_set fds; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
453 struct timeval tv; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
454 int i,n=0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
455 static int last_loop = 0; |
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 if(num_key_fd == 0) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
458 return NULL; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
459 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
460 FD_ZERO(&fds); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
461 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
|
462 if( (key_fds[i].flags & MP_FD_DEAD) ) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
463 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
|
464 i--; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
465 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
466 } 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
|
467 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
468 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
469 FD_SET(key_fds[i].fd,&fds); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
470 n++; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
471 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
472 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
473 if(n > 0 ) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
474 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
475 tv.tv_sec=time/1000; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
476 tv.tv_usec = (time%1000)*1000; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
477 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
478 while(1) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
479 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
|
480 if(errno == EINTR) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
481 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
482 printf("Select error : %s\n",strerror(errno)); |
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 break; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
485 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
486 } else { |
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 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
489 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
490 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
|
491 int code = -1,j; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
492 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
493 if((unsigned int)i >= num_key_fd) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
494 i = -1; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
495 last_loop++; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
496 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
497 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
498 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
|
499 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
500 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
|
501 code = getch2(time); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
502 if(code < 0) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
503 code = MP_INPUT_NOTHING; |
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 else |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
506 code = ((mp_key_func_t)key_fds[i].read_func)(key_fds[i].fd); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
507 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
508 if(code < 0) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
509 if(code == MP_INPUT_ERROR) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
510 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
|
511 else if(code == MP_INPUT_DEAD) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
512 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
|
513 key_fds[i].flags |= MP_FD_DEAD; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
514 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
515 continue; |
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 if(paused) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
518 return mp_input_parse_cmd("pause"); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
519 for(j = 0; cmd_binds[j].cmd != NULL; j++) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
520 if(cmd_binds[j].input == code) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
521 break; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
522 } |
4518
83128eed25f1
Corrected the quit bug and added support for up to 10 axis
albeu
parents:
4432
diff
changeset
|
523 if(cmd_binds[j].cmd == NULL) { |
83128eed25f1
Corrected the quit bug and added support for up to 10 axis
albeu
parents:
4432
diff
changeset
|
524 printf("No bind found for key %d\n",code); |
4418
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
525 continue; |
4518
83128eed25f1
Corrected the quit bug and added support for up to 10 axis
albeu
parents:
4432
diff
changeset
|
526 } |
4418
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
527 last_loop = i; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
528 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
|
529 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
530 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
531 last_loop = 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
532 return NULL; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
533 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
534 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
535 static mp_cmd_t* |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
536 mp_input_read_cmds(int time) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
537 fd_set fds; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
538 struct timeval tv; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
539 int i,n = 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
540 mp_cmd_t* ret; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
541 static int last_loop = 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
542 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
543 if(num_cmd_fd == 0) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
544 return NULL; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
545 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
546 FD_ZERO(&fds); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
547 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
|
548 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
|
549 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
|
550 i--; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
551 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
552 } 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
|
553 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
554 FD_SET(cmd_fds[i].fd,&fds); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
555 n++; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
556 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
557 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
558 if(n > 0) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
559 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
560 tv.tv_sec=time/1000; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
561 tv.tv_usec = (time%1000)*1000; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
562 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
563 while(1) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
564 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
|
565 if(i < 0) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
566 if(errno == EINTR) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
567 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
568 printf("Select error : %s\n",strerror(errno)); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
569 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
570 return NULL; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
571 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
572 break; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
573 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
574 } else { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
575 FD_ZERO(&fds); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
576 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
577 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
578 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
|
579 int r = 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
580 char* cmd; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
581 if((unsigned int)i >= num_cmd_fd) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
582 i = -1; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
583 last_loop++; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
584 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
585 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
586 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
|
587 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
588 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
589 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
|
590 if(r < 0) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
591 if(r == MP_INPUT_ERROR) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
592 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
|
593 else if(r == MP_INPUT_DEAD) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
594 cmd_fds[i].flags |= MP_FD_DEAD; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
595 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
596 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
597 ret = mp_input_parse_cmd(cmd); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
598 free(cmd); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
599 if(!ret) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
600 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
601 last_loop = i; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
602 return ret; |
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 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
605 last_loop = 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
606 return NULL; |
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 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
609 mp_cmd_t* |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
610 mp_input_get_cmd(int time, int paused) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
611 mp_cmd_t* ret; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
612 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
613 ret = mp_input_read_keys(time,paused); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
614 if(ret) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
615 return ret; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
616 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
617 return mp_input_read_cmds(time); |
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 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
620 void |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
621 mp_cmd_free(mp_cmd_t* cmd) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
622 int i; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
623 #ifdef MP_DEBUG |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
624 assert(cmd != NULL); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
625 #endif |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
626 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
627 if(cmd->name) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
628 free(cmd->name); |
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 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
|
631 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
|
632 free(cmd->args[i].v.s); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
633 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
634 free(cmd); |
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 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
637 static int |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
638 mp_input_get_key_from_name(char* name) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
639 int i,ret = 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
640 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
641 if(strlen(name) == 1) { // Direct key code |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
642 (char)ret = name[0]; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
643 return ret; |
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 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
646 for(i = 0; key_names[i].cmd != NULL; i++) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
647 if(strcasecmp(key_names[i].cmd,name) == 0) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
648 return key_names[i].input; |
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 return -1; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
652 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
653 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
654 static void |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
655 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
|
656 int i; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
657 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
658 if(!binds) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
659 return; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
660 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
661 for(i = 0; binds[i].cmd != NULL; i++) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
662 free(binds[i].cmd); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
663 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
664 free(binds); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
665 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
666 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
667 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
668 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
669 #define BS_MAX 256 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
670 #define SPACE_CHAR " \n\r\t" |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
671 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
672 static void |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
673 mp_input_parse_config(char *file) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
674 int fd,code=-1; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
675 int bs = 0,r,eof = 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
676 char *iter,*end; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
677 char buffer[BS_MAX]; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
678 int n_binds = 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
679 mp_cmd_bind_t* binds = 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 fd = open(file,O_RDONLY); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
682 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
683 if(fd < 0) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
684 printf("Can't open 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
|
685 return; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
686 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
687 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
688 printf("Parsing input config file %s\n",file); |
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 while(1) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
691 if(! eof && bs < BS_MAX-1) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
692 if(bs > 0) bs--; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
693 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
|
694 if(r < 0) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
695 if(errno == EINTR) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
696 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
697 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
|
698 mp_input_free_binds(binds); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
699 return; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
700 } else if(r == 0) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
701 eof = 1; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
702 else { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
703 bs += r+1; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
704 buffer[bs-1] = '\0'; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
705 } |
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 // Empty buffer : return |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
708 if(bs <= 1) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
709 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
|
710 if(binds) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
711 cmd_binds = binds; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
712 return; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
713 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
714 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
715 iter = buffer; |
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 // Find the wanted key |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
718 if(code < 0) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
719 // Jump beginnig space |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
720 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
|
721 /* NOTHING */; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
722 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
|
723 bs = 0; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
724 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
725 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
726 // Find the end of the key code name |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
727 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
|
728 /*NOTHING */; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
729 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
|
730 if(buffer == iter) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
731 if(eof && (buffer-iter) == bs) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
732 printf("Unfinished binding %s\n",iter); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
733 else |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
734 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
|
735 mp_input_free_binds(binds); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
736 return; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
737 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
738 memmove(buffer,iter,end-iter); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
739 bs = end-iter; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
740 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
741 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
742 { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
743 char name[end-iter+1]; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
744 strncpy(name,iter,end-iter); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
745 name[end-iter] = '\0'; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
746 code = mp_input_get_key_from_name(name); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
747 if(code < 0) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
748 printf("Unknow key %s\n",name); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
749 mp_input_free_binds(binds); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
750 return; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
751 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
752 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
753 if( bs > (end-buffer)) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
754 memmove(buffer,end,bs - (end-buffer)); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
755 bs -= end-buffer; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
756 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
757 } else { // Get the command |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
758 while(iter[0] == ' ' || iter[0] == '\t') iter++; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
759 // Found new line |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
760 if(iter[0] == '\n' || iter[0] == '\r') { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
761 printf("No command found for key (TODO)\n" /*mp_input_get_key_name(code)*/); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
762 code = -1; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
763 if(iter > buffer) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
764 memmove(buffer,iter,bs- (iter-buffer)); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
765 bs -= (iter-buffer); |
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 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
768 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
769 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
|
770 /* NOTHING */; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
771 if(end[0] == '\0' && ! (eof && (end - buffer) == bs)) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
772 if(iter == buffer) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
773 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
|
774 mp_input_free_binds(binds); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
775 return; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
776 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
777 memmove(buffer,iter,end - iter); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
778 bs = end - iter; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
779 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
780 } |
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 char cmd[end-iter+1]; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
783 strncpy(cmd,iter,end-iter); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
784 cmd[end-iter] = '\0'; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
785 //printf("Set bind %d => %s\n",code,cmd); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
786 binds = (mp_cmd_bind_t*)realloc(binds,(n_binds+2)*sizeof(mp_cmd_bind_t)); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
787 binds[n_binds].input = code; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
788 binds[n_binds].cmd = strdup(cmd); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
789 n_binds++; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
790 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
|
791 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
792 code = -1; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
793 if(bs > (end-buffer)) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
794 memmove(buffer,end,bs-(end-buffer)); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
795 bs -= (end-buffer); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
796 continue; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
797 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
798 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
799 printf("What are we doing here ?\n"); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
800 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
801 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
802 extern char *get_path(char *filename); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
803 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
804 void |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
805 mp_input_init(void) { |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
806 char* file; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
807 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
808 file = get_path("input.conf"); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
809 if(!file) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
810 return; |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
811 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
812 mp_input_parse_config(file); |
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 #ifdef HAVE_JOYSTICK |
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 int fd = mp_input_joystick_init(NULL); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
817 if(fd < 0) |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
818 printf("Can't init input joystick\n"); |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
819 else |
4524
01a0cf736e0d
Fix the bugs the previous version should fix (and those introduced
albeu
parents:
4518
diff
changeset
|
820 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
|
821 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
822 #endif |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
823 |
4432 | 824 #ifdef HAVE_LIRC |
825 { | |
826 int fd = mp_input_lirc_init(); | |
827 if(fd > 0) | |
828 mp_input_add_cmd_fd(fd,1,NULL,(mp_close_func_t)close); | |
829 } | |
830 #endif | |
831 | |
832 } | |
833 | |
834 void | |
835 mp_input_uninit(void) { | |
4518
83128eed25f1
Corrected the quit bug and added support for up to 10 axis
albeu
parents:
4432
diff
changeset
|
836 unsigned int i; |
83128eed25f1
Corrected the quit bug and added support for up to 10 axis
albeu
parents:
4432
diff
changeset
|
837 |
83128eed25f1
Corrected the quit bug and added support for up to 10 axis
albeu
parents:
4432
diff
changeset
|
838 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
|
839 if(key_fds[i].close_func) |
83128eed25f1
Corrected the quit bug and added support for up to 10 axis
albeu
parents:
4432
diff
changeset
|
840 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
|
841 } |
83128eed25f1
Corrected the quit bug and added support for up to 10 axis
albeu
parents:
4432
diff
changeset
|
842 |
83128eed25f1
Corrected the quit bug and added support for up to 10 axis
albeu
parents:
4432
diff
changeset
|
843 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
|
844 if(cmd_fds[i].close_func) |
83128eed25f1
Corrected the quit bug and added support for up to 10 axis
albeu
parents:
4432
diff
changeset
|
845 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
|
846 } |
83128eed25f1
Corrected the quit bug and added support for up to 10 axis
albeu
parents:
4432
diff
changeset
|
847 |
4432 | 848 |
849 #ifdef HAVE_LIRC | |
850 mp_input_lirc_uninit(); | |
851 #endif | |
852 | |
4418
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
853 } |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
854 |
8141d2c399e4
A new configurable input system and joystick support for this system
albeu
parents:
diff
changeset
|
855 #endif /* HAVE_NEW_INPUT */ |