comparison osdep/getch2-os2.c @ 26016:528bdf17dd8a

OS/2 getch2() support patch by KO Myung-Hun, komh chollian net
author diego
date Thu, 21 Feb 2008 16:20:33 +0000
parents
children e7c989f7a7c9
comparison
equal deleted inserted replaced
26015:f222f84f2072 26016:528bdf17dd8a
1 /*
2 * getch2-os2.c : OS/2 TermIO for MPlayer
3 *
4 * Copyright (c) 2007 KO Myung-Hun (komh@chollian.net)
5 *
6 * This file is part of MPlayer.
7 *
8 * MPlayer is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * MPlayer is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
23 #define INCL_KBD
24 #define INCL_VIO
25 #define INCL_DOS
26 #include <os2.h>
27
28 #include <stdio.h>
29
30 #include "config.h"
31 #include "keycodes.h"
32 #include "input/input.h"
33 #include "mp_fifo.h"
34
35 #if defined( USE_LANGINFO ) && defined( USE_ICONV )
36 #include <locale.h>
37 #include <langinfo.h>
38 #endif
39
40 int mp_input_slave_cmd_func( int fd, char *dest, int size )
41 {
42 PPIB ppib;
43 CHAR szPipeName[ 100 ];
44 HFILE hpipe;
45 ULONG ulAction;
46 ULONG cbActual;
47 ULONG rc;
48
49 DosGetInfoBlocks( NULL, &ppib );
50
51 sprintf( szPipeName, "\\PIPE\\MPLAYER\\%lx", ppib->pib_ulpid );
52
53 rc = DosOpen( szPipeName, &hpipe, &ulAction, 0, FILE_NORMAL,
54 OPEN_ACTION_OPEN_IF_EXISTS,
55 OPEN_SHARE_DENYREADWRITE | OPEN_ACCESS_READWRITE,
56 NULL );
57 if( rc )
58 return MP_INPUT_NOTHING;
59
60 rc = DosRead( hpipe, dest, size, &cbActual );
61 if( rc )
62 return MP_INPUT_NOTHING;
63
64 rc = cbActual;
65
66 // Send ACK
67 DosWrite( hpipe, &rc, sizeof( ULONG ), &cbActual );
68
69 DosClose( hpipe );
70
71 return rc;
72 }
73
74
75 int screen_width = 80;
76 int screen_height = 24;
77 char *erase_to_end_of_line = NULL;
78
79 void get_screen_size( void )
80 {
81 VIOMODEINFO vmi;
82
83 vmi.cb = sizeof( VIOMODEINFO );
84
85 VioGetMode( &vmi, 0 );
86
87 screen_width = vmi.col;
88 screen_height = vmi.row;
89 }
90
91 static int getch2_status = 0;
92
93 static int getch2_internal( void )
94 {
95 KBDKEYINFO kki;
96
97 if( !getch2_status )
98 return -1;
99
100 if( KbdCharIn( &kki, IO_NOWAIT, 0 ))
101 return -1;
102
103 // key pressed ?
104 if( kki.fbStatus )
105 {
106 // extended key ?
107 if(( kki.chChar == 0x00 ) || ( kki.chChar == 0xE0 ))
108 {
109 switch( kki.chScan )
110 {
111 case 0x4B : // Left
112 return KEY_LEFT;
113
114 case 0x48 : // Up
115 return KEY_UP;
116
117 case 0x4D : // Right
118 return KEY_RIGHT;
119
120 case 0x50 : // Down
121 return KEY_DOWN;
122
123 case 0x53 : // Delete
124 return KEY_DELETE;
125
126 case 0x52 : // Insert
127 return KEY_INSERT;
128
129 case 0x47 : // Home
130 return KEY_HOME;
131
132 case 0x4F : // End
133 return KEY_END;
134
135 case 0x49 : // Page Up
136 return KEY_PAGE_UP;
137
138 case 0x51 : // Page Down
139 return KEY_PAGE_DOWN;
140 }
141 }
142 else
143 {
144 switch( kki.chChar )
145 {
146 case 0x08 : // Backspace
147 return KEY_BS;
148
149 case 0x1B : // Esc
150 return KEY_ESC;
151
152 case 0x0D : // Enter
153 // Keypad Enter ?
154 if( kki.chScan == 0xE0 )
155 return KEY_KPENTER;
156 break;
157 }
158
159 return kki.chChar;
160 }
161 }
162
163 return -1;
164 }
165
166 void getch2( void )
167 {
168 int key;
169
170 key = getch2_internal();
171 if( key != -1 )
172 mplayer_put_key( key );
173 }
174
175 void getch2_enable( void )
176 {
177 getch2_status = 1;
178 }
179
180 void getch2_disable( void )
181 {
182 getch2_status = 0;
183 }
184
185 #ifdef USE_ICONV
186 char *get_term_charset( void )
187 {
188 char *charset = NULL;
189
190 #ifdef USE_LANGINFO
191 setlocale( LC_CTYPE, "");
192 charset = nl_langinfo( CODESET );
193 setlocale( LC_CTYPE, "C");
194 #endif
195
196 return charset;
197 }
198 #endif
199