Merge svn changes up to r28366
[mplayer/glamo.git] / osdep / getch2-os2.c
blob0b6e84683e48bef6982dca86b88ae7a97ffd9567
1 /*
2 * getch2-os2.c : OS/2 TermIO for MPlayer
4 * Copyright (c) 2007 KO Myung-Hun (komh@chollian.net)
6 * This file is part of MPlayer.
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.
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.
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.
23 #define INCL_KBD
24 #define INCL_VIO
25 #define INCL_DOS
26 #include <os2.h>
28 #include <stdio.h>
30 #include "config.h"
31 #include "keycodes.h"
32 #include "input/input.h"
33 #include "mp_fifo.h"
34 #include "getch2.h"
36 #if defined(HAVE_LANGINFO) && defined(CONFIG_ICONV)
37 #include <locale.h>
38 #include <langinfo.h>
39 #endif
41 int mp_input_slave_cmd_func( int fd, char *dest, int size )
43 PPIB ppib;
44 CHAR szPipeName[ 100 ];
45 HFILE hpipe;
46 ULONG ulAction;
47 ULONG cbActual;
48 ULONG rc;
50 DosGetInfoBlocks( NULL, &ppib );
52 sprintf( szPipeName, "\\PIPE\\MPLAYER\\%lx", ppib->pib_ulpid );
54 rc = DosOpen( szPipeName, &hpipe, &ulAction, 0, FILE_NORMAL,
55 OPEN_ACTION_OPEN_IF_EXISTS,
56 OPEN_SHARE_DENYREADWRITE | OPEN_ACCESS_READWRITE,
57 NULL );
58 if( rc )
59 return MP_INPUT_NOTHING;
61 rc = DosRead( hpipe, dest, size, &cbActual );
62 if( rc )
63 return MP_INPUT_NOTHING;
65 rc = cbActual;
67 // Send ACK
68 DosWrite( hpipe, &rc, sizeof( ULONG ), &cbActual );
70 DosClose( hpipe );
72 return rc;
76 int screen_width = 80;
77 int screen_height = 24;
78 char *erase_to_end_of_line = NULL;
80 void get_screen_size( void )
82 VIOMODEINFO vmi;
84 vmi.cb = sizeof( VIOMODEINFO );
86 VioGetMode( &vmi, 0 );
88 screen_width = vmi.col;
89 screen_height = vmi.row;
92 static int getch2_status = 0;
94 static int getch2_internal( void )
96 KBDKEYINFO kki;
98 if( !getch2_status )
99 return -1;
101 if( KbdCharIn( &kki, IO_NOWAIT, 0 ))
102 return -1;
104 // key pressed ?
105 if( kki.fbStatus )
107 // extended key ?
108 if(( kki.chChar == 0x00 ) || ( kki.chChar == 0xE0 ))
110 switch( kki.chScan )
112 case 0x4B : // Left
113 return KEY_LEFT;
115 case 0x48 : // Up
116 return KEY_UP;
118 case 0x4D : // Right
119 return KEY_RIGHT;
121 case 0x50 : // Down
122 return KEY_DOWN;
124 case 0x53 : // Delete
125 return KEY_DELETE;
127 case 0x52 : // Insert
128 return KEY_INSERT;
130 case 0x47 : // Home
131 return KEY_HOME;
133 case 0x4F : // End
134 return KEY_END;
136 case 0x49 : // Page Up
137 return KEY_PAGE_UP;
139 case 0x51 : // Page Down
140 return KEY_PAGE_DOWN;
143 else
145 switch( kki.chChar )
147 case 0x08 : // Backspace
148 return KEY_BS;
150 case 0x1B : // Esc
151 return KEY_ESC;
153 case 0x0D : // Enter
154 // Keypad Enter ?
155 if( kki.chScan == 0xE0 )
156 return KEY_KPENTER;
157 break;
160 return kki.chChar;
164 return -1;
167 void getch2(struct mp_fifo *fifo)
169 int key;
171 key = getch2_internal();
172 if( key != -1 )
173 mplayer_put_key(fifo, key);
176 void getch2_enable( void )
178 getch2_status = 1;
181 void getch2_disable( void )
183 getch2_status = 0;
186 #ifdef CONFIG_ICONV
187 char *get_term_charset( void )
189 char *charset = NULL;
191 #ifdef HAVE_LANGINFO
192 setlocale( LC_CTYPE, "");
193 charset = nl_langinfo( CODESET );
194 setlocale( LC_CTYPE, "C");
195 #endif
197 return charset;
199 #endif