summaryrefslogtreecommitdiffstats
path: root/osdep/getch2.c
Commit message (Collapse)AuthorAgeFilesLines
* core: move contents to mpvcore (2/2)Stefano Pigozzi2013-08-061-4/+4
| | | | Followup commit. Fixes all the files references.
* getch2: Load the "ce", "ks" and "ke" caps into a static bufferDiogo Franco (Kovensky)2013-07-261-3/+6
| | | | | | Fixes reports of printing of garbage (or anything else) other than clearing the status line to the end of line: the buffer returned by termcap_get could get moved, and if that happened then these 3 caps pointed to garbage.
* getch2: Deactivate getch2 on SIGINT; also handle SIGQUITDiogo Franco (Kovensky)2013-07-261-0/+4
|
* getch2: Only send ESC if it was typed twiceDiogo Franco (Kovensky)2013-07-261-3/+5
| | | | Avoids quitting mpv if any unknown escape is entered.
* getch2: Handle setupterm errorsDiogo Franco (Kovensky)2013-07-261-1/+18
| | | | | | setupterm abort()s if it can't initialize the terminal and the last parameter is NULL; handle setupterm errors and retry with "ansi" if the TERM env var was unset.
* getch2: fix compilationwm42013-07-261-1/+1
|
* getch2: Support ESC keypresses againDiogo Franco (Kovensky)2013-07-251-1/+9
| | | | | | Due to the termcap matching and the hardcoded fallbacks, the ESC keypress has to be followed by another non-matching keypress (such as another ESC) for it to be accepted. We drop the second ESC in case it was typed twice.
* getch2: Doing it right this timeDiogo Franco (Kovensky)2013-07-251-1/+1
| | | | | getch2_pos should be set to 1, not 0, when backtracking. Avoids the possible infinite loop but correctly.
* Revert "getch2: Avoid possible infinite loop"Diogo Franco (Kovensky)2013-07-251-4/+4
| | | | This reverts commit ba95aed6f1067dc577d8813625233982157167d9.
* getch2: Avoid possible infinite loopDiogo Franco (Kovensky)2013-07-251-4/+4
| | | | | | If the first character is not a valid UTF-8 start code nor is in termcap, getch2 would enter an infinite loop. Always walk 1 byte in the UTF-8 case unless it's a valid start code.
* getch2: Remove unused function, fix possible crashDiogo Franco (Kovensky)2013-07-251-25/+19
| | | | | | | | | If we still haven't read the full key from the input but it's regardless a unique match in the database, we could receive a NULL keycode from keys_search (it's not a full match after all) and proceed to use it. Don't disable the keycode matching code if we don't have termcap as we can still match against the hardcoded sequences.
* getch2: Refactor/rewriteDiogo Franco (Kovensky)2013-07-251-192/+344
| | | | | | | | | | | | | | | | | | | | | | Still uses termcap, but uses terminfo for loading the termcap database if possible. Adds configure test to find terminfo; skips the termcap test if terminfo is found since terminfo provides termcap. Use termcap completely for special keys; if we can't get it from termcap and it isn't one of the known fallbacks, we ignore its specialness and treat as a sequence of UTF-8 codes. Further hardcoded fallbacks can be added by calling keys_push_once in load_termcap; there is no limit to the amount of keys pushed. Uses the "ke" and "ks" capabilities to start / exit application mode, which is necessary on vt100 emulators (including screen, xterm and all terminals that emulate either of those) to correctly receive arrow keys. It's now possible to compile getch2 even without termcap, though it won't be of much use since it'll be unable to detect special keys. Converted to 4 spaces per tab, prettified some statements.
* core: cleanup more mp_fifo leftoverswm42013-07-021-3/+2
| | | | Now only the OSX and Wayland parts are using this.
* mp_msg: fix status output disappearing when redirecting INPUT.Rudolf Polzer2013-03-181-2/+2
| | | | | Instead, we now check stderr's destination against the foreground tty for deciding whether we want status output or not.
* Prefix keycode defines with MP_wm42013-02-121-38/+38
| | | | | | | | | | Do this to reduce conflicts with <linux/input.h>, which contains some conflicting defines. This changes the meaning of MP_KEY_DOWN: KEY_DOWN is renamed to MP_KEY_DOWN (cursor down key) MP_KEY_DOWN is renamed to MP_KEY_STATE_DOWN (modifier for key down state)
* mp_msg, getch2: unix tty background supportRudolf Polzer2013-01-231-16/+97
| | | | | | | | Now, when backgrounded, mpv plays and outputs messages to stdout, but statusline is not output. Background<->foreground transitions are detected by signals and polling the process groups.
* Rename directories, move files (step 2 of 2)wm42012-11-121-3/+3
| | | | | | | | | | | | Finish renaming directories and moving files. Adjust all include statements to make the previous commit compile. The two commits are separate, because git is bad at tracking renames and content changes at the same time. Also take this as an opportunity to remove the separation between "common" and "mplayer" sources in the Makefile. ("common" used to be shared between mplayer and mencoder.)
* getch2: request at least 1 byte of input each readRudolf Polzer2012-09-191-1/+1
| | | | | | | | fixes issue with | less, where mplayer broke less's terminal expectations and made less quit Note this means that read() will be blocking again. Should be ok, as we always check via select() before reading.
* mp_msg: remove filename_recodewm42012-07-311-18/+0
| | | | | | | | | | This was intended for translating filenames from filesystem charset to the terminal charset. Modern sane platforms use UTF-8 for everything, and on Windows we use unicode APIs, so this is not needed anymore. Remove filename_recode, all uses of it, options and configure checks related to terminal output charset, and code that tries to determine the same.
* Merge remote-tracking branch 'origin/master'wm42012-04-131-3/+10
|\ | | | | | | | | Conflicts: libvo/vo_kva.c
| * build: remove OS/2 supportUoti Urpala2012-04-061-1/+1
| |
| * input: stop trying to read terminal input on EOFUoti Urpala2012-04-061-2/+9
| | | | | | | | | | | | | | | | | | | | | | | | Stop trying to read terminal input if a read attempt returns EOF. The most important case where this matters is when someone runs the player with stdin redirected from /dev/null and without specifying --no-consolecontrols. This used to cause 100% CPU load while paused, as select() would continuously trigger on stdin (the need for --no-consolecontrols was not apparent to people with older mplayer versions, as input reading was less efficient and latencies like hardcoded sleeps kept CPU use well below 100%). Now this will only cause a "Dead key input" error message.
| * input: handle UTF-8 terminal inputwm42012-03-251-0/+11
| | | | | | | | | | | | | | | | | | | | | | This assumes the terminal uses UTF-8. If invalid UTF-8 is encountered (for example because the terminal uses a legacy encoding), the code falls back to the old method and feeds each byte as key code to the input code. In theory, UTF-8 input could randomly fail, because the code in getch2.c doesn't try to fill the input buffer correctly with input sequences longer than a byte. This is a problem with the design of the existing code.
| * input: allow unicode keys and reassign internal key codeswm42012-03-251-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This moves all key codes above the highest valid unicode code point (which is 0x10FFFF). All key codes below MP_KEY_BASE now directly map to unicode (KEY_ENTER is 13, carriage return). Configuration files (input.conf) can contain unicode characters in UTF-8 to map non-ASCII characters/keys. This shouldn't change anything user visible, except that "direct key codes" (as used in input.conf) will change their meaning. Parts of the bstr functions taken from libavutil's GET_UTF8 and slightly modified.
* | input: restore terminal attributes after resumewm42012-02-251-6/+21
| | | | | | | | | | | | | | | | | | | | Install a signal handler on SIGCONT, and restore the terminal attributes with tcsetattr() if it happens. This is needed with some shells (such as tcsh) that don't restore the terminal attributes set by mplayer. Without this, terminal I/O doesn't work as intended after resume with these shells. Fixes #155.
* | input: fix "enter" on consolewm42012-02-191-8/+9
| | | | | | | | | | | | | | The commit "input: handle UTF-8 terminal input" accidentally messed up the handling of certain special keys. Apparently only KEY_ENTER was affected by this, because the code was valid UTF-8, but didn't directly map to the keycode.
* | input: handle UTF-8 terminal inputwm42012-01-181-0/+10
| | | | | | | | | | | | | | | | | | | | | | This assumes the terminal uses UTF-8. If invalid UTF-8 is encountered (for example because the terminal uses a legacy encoding), the code falls back to the old method and feeds each byte as key code to the input code. In theory, UTF-8 input could randomly fail, because the code in getch2.c doesn't try to fill the input buffer correctly with input sequences longer than a byte. This is a problem with the design of the existing code.
* | input: allow unicode keys and reassign internal key codeswm42012-01-181-1/+1
|/ | | | | | | | | | This moves all key codes above the highest valid unicode code point (which is 0x10FFFF). All key codes below MP_KEY_BASE now directly map to unicode. Configuration files (input.conf) can contain unicode characters in UTF-8 to map non-ASCII characters/keys. This shouldn't change anything user visible, except that "direct key codes" (as used in input.conf) will change their meaning.
* getch2.c: fix negative keycodes returned for non-asciiUoti Urpala2011-10-031-1/+1
| | | | | | | | | | | | | | | | | | getch2.c read data into a "char" array, and returned values other than escape sequences directly from there. This meant that it could return negative values (except on platforms where "char" is unsigned) if the input contained bytes >= 128. This would break later parsing in input.c as the values would be interpreted as having the MP_KEY_DOWN flag set, which would make the key binding code think a key is held down (and never released). Fix by changing the buffer type to unsigned char. The bug itself was very old, but started triggering visible breakage more easily after commit 82b8f89baea ("input: rework event reading and command queuing"). Before that the key values would be passed through the input.c "key read function" interface, which (mis)interpreted the negative values as errors from the function, and in most cases discarded them without much visible effect.
* input: don't make fd 0 nonblockingUoti Urpala2011-07-171-5/+0
| | | | | | | | | | | | | | | Setting O_NONBLOCK on a file descriptor also affects all other fds that share the same underlying open file description, and in case of stdin such sharing is likely. Making stdin nonblocking can also make stdout nonblocking (they may be the same connection to a terminal), and it can also affect other processes (in "program1 | program2", the shell may give the same terminal connection to program1 as stdin and to program2 as stdout, thus program1 making its stdin nonblocking also turns program2's stdout nonblocking). To avoid these problems stop making fd 0 nonblocking. After the previous commit this should no longer cause problems as long as select() does not spuriously report the fd as readable.
* input: move all key code lists to input/keycodes.hUoti Urpala2011-05-021-1/+1
| | | | | | | | | | | | | Move the definitions of all special key codes (those not passed by ASCII value) to input/keycodes.h. Before they were spread between osdep/keycodes.h, input/joystick.h, input/mouse.h and input/ar.h, plus some special values in input.h. This was especially inconvenient as the codes had to be coordinated to not conflict between the files. The change requires a bit of ugliness as appleir.c includes <linux/input.h> which contains various conflicting KEY_* definitions. Work around this by adding a special preprocessor variable which can be used to avoid defining these in keycodes.h.
* input: make stdin non-blocking for terminal inputUoti Urpala2011-04-281-1/+7
| | | | | | | getch2.c did not make stdin non-blocking, and relied on only being called after select() had shown readability. Stop relying on that assumption and set stdin to non-blocking mode. Hopefully no relevant platform has problems with this...
* Merge svn changes up to r29412Uoti Urpala2009-07-071-1/+1
|\
| * Use a malloced string for the get_term_charset return value.reimar2009-05-311-1/+1
| | | | | | | | | | | | | | | | This is necessary at least on POSIX systems since the buffer returned by nl_langinfo may change its contents with e.g. each setlocale call. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@29332 b3059339-0415-0410-9bf9-f77b7e298cf2
* | Remove trailing whitespace from most filesUoti Urpala2009-07-071-1/+0
| |
* | Merge svn changes up to r28862Uoti Urpala2009-03-071-1/+22
|\|
| * Add standard license headers to files.diego2009-03-011-1/+22
| | | | | | | | git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@28779 b3059339-0415-0410-9bf9-f77b7e298cf2
* | Merge svn changes up to r28087Uoti Urpala2008-12-041-4/+4
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: command.c libao2/ao_ivtv.c libao2/ao_v4l2.c libmpcodecs/dec_video.h libvo/aspect.h libvo/sub.c libvo/sub.h libvo/vo_directx.c libvo/vo_macosx.m libvo/vo_quartz.c mp_core.h mplayer.c mplayer.h osdep/getch2.h osdep/timer.h
| * Get rid of pointless 'extern' keywords.diego2008-12-031-4/+4
| | | | | | | | git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@28085 b3059339-0415-0410-9bf9-f77b7e298cf2
* | Use correct terminal "clear line" codeUoti Urpala2008-08-131-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The "erase_to_end_of_line" string used to clear the terminal status line was initialized with the termcap id "cd", which means to clear all lines below the cursor. Change it to the correct "ce" to clear the current line. Usually the status line is on the bottommost line of the terminal so the behaviour wouldn't differ much. However it did make a difference when I tested starting MPlayer at the top of a huge gnome-terminal window so the status line was not at the bottom; in that case clearing just the current line used less CPU than clearing the part of the huge window below the status line.
* | Merge svn changes up to r27441Uoti Urpala2008-08-081-2/+2
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: cfg-common-opts.h command.c configure input/input.c libmpcodecs/dec_video.c libmpcodecs/vd.c libmpdemux/stheader.h libvo/sub.c libvo/video_out.c libvo/vo_xv.c libvo/vosub_vidix.c libvo/x11_common.c libvo/x11_common.h mp_core.h mplayer.c stream/stream.h
| * Rename font-related preprocessor directives.diego2008-08-071-2/+2
| | | | | | | | | | | | | | Switch them from a HAVE_ to a CONFIG_ prefix. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@27425 b3059339-0415-0410-9bf9-f77b7e298cf2
* | Merge svn changes up to r27399Uoti Urpala2008-08-021-5/+5
|\| | | | | | | | | | | | | | | | | | | Conflicts: libmpcodecs/vd.c libmpcodecs/ve_raw.c libvo/video_out.c libvo/x11_common.c mplayer.c
| * Rename some preprocessor directives from CONFIG_* to HAVE_* where appropriate;diego2008-08-011-5/+5
| | | | | | | | | | | | | | CONFIG_ prefix for configurable options, HAVE_ for system-dependent stuff. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@27391 b3059339-0415-0410-9bf9-f77b7e298cf2
* | Merge svn changes up to r27374Uoti Urpala2008-07-301-8/+8
|\| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Conflicts: cfg-common-opts.h cfg-mplayer.h command.c configure libmpcodecs/dec_video.c libmpcodecs/vd.c libmpcodecs/vf_vo.c libmpdemux/demuxer.h libmpdemux/stheader.h mp_core.h mplayer.c stream/stream_radio.c
| * Start unifying names of internal preprocessor directives.diego2008-07-301-8/+8
| | | | | | | | | | | | | | | | Replace all USE_ prefixes by CONFIG_ prefixes to indicate options which are configurable. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@27373 b3059339-0415-0410-9bf9-f77b7e298cf2
* | Add a context for mp_fifoUoti Urpala2008-04-291-2/+2
| | | | | | | | | | Store data in an allocated context and take it as an argument instead of using static variables.
* | mp_fifo.c, osdep/: Include corresponding .h in .c filesUoti Urpala2008-04-291-0/+1
|/
* getch2: Fix incorrect testuau2007-09-151-1/+1
| | | | | | | | | | | Keycode length wasn't checked in one case because of missing parentheses. This was accidentally broken in my previous commit to the file. Most likely the error had no practical effect; the length checks are unreliable in any case as they can be satisfied by unrelated data corresponding to other keypresses. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@24535 b3059339-0415-0410-9bf9-f77b7e298cf2
* Clean up getch2() code somewhatuau2007-08-251-69/+102
| | | | git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@24150 b3059339-0415-0410-9bf9-f77b7e298cf2
* Make terminal input work more like VO key inputuau2007-08-251-14/+8
| | | | | | | | | | | | | | | | | The Unix version of getch2() could either return an internally buffered key or do a second-level select() in addition to the input.c one and then read more data. Change getch2() to always add all read keys with mplayer_put_key() (like video output window keyboard input does) and remove the internal select() from the Unix version. Make input.c call mplayer_get_key() directly. The primary motivation for this change is to make combining multiple event sources under one select() easier. Now getch2() only needs to be called when the corresponding fd is readable, and it will be possible to handle events from X-based VOs with the same code. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@24149 b3059339-0415-0410-9bf9-f77b7e298cf2
* "()" to "(void)" function param list fixesuau2007-04-011-1/+1
| | | | | | | patch from Stefan Huehner, stefan huehner org git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@22904 b3059339-0415-0410-9bf9-f77b7e298cf2
* Add code to detect and convert to console codepage on Windows.reimar2007-03-041-0/+18
| | | | | | |