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