Commit Graph

312 Commits

Author SHA1 Message Date
Diogo Franco (Kovensky) 0cfc382355 getch2: Doing it right this time
getch2_pos should be set to 1, not 0, when backtracking. Avoids the
possible infinite loop but correctly.
2013-07-25 13:29:10 -03:00
Diogo Franco (Kovensky) c36a5e0f36 Revert "getch2: Avoid possible infinite loop"
This reverts commit ba95aed6f1.
2013-07-25 13:26:19 -03:00
Diogo Franco (Kovensky) ba95aed6f1 getch2: Avoid possible infinite loop
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.
2013-07-25 13:24:22 -03:00
Diogo Franco (Kovensky) 5586b02931 getch2, mplayer: Always call load_termcap
getch2 now deals with the cases where we don't have termcap. Add a dummy
load_termcap to getch2-win so we don't get linking errors on mingw.
2013-07-25 12:23:40 -03:00
Diogo Franco (Kovensky) 19b1279bb3 getch2: Remove unused function, fix possible crash
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.
2013-07-25 12:21:22 -03:00
Diogo Franco (Kovensky) 057467f6b3 getch2: Refactor/rewrite
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.
2013-07-25 00:01:51 -03:00
Stefano Pigozzi 5f265d5930 cocoa_common: handle keyboard modifiers for mouse events 2013-07-21 10:49:27 +02:00
James Ross-Gowan 3e7d483ac8 w32: update manifest for high DPI and Windows 8.1
Since Windows Vista, when running at 144 DPI or higher with composition
switched on, applications that don't declare themselves to be DPI aware
are stretched by the window manager, kind of like low resolution apps in
OSX.

To avoid this, declare DPI awareness in the manifest. Since mpv is
practically resolution independent this shouldn't cause any trouble. The
'True/PM' value declares per-monitor DPI awareness in Windows 8.1, so
that the mpv isn't shrunk when moved from a high DPI screen to one with
a lower DPI.

Also, avoid compatibility shims by declaring compatibility with all
Windows versions from Vista to 8.1 and add the missing uiAccess
attribute to the requestedExecutionLevel element.
2013-07-14 16:10:23 +02:00
wm4 5e6b96f1ff getch2-win: uncrustify 2013-07-14 16:08:27 +02:00
wm4 659a314a19 osdep: remove unused mmap compatibility hacks
Not sure how this worked. Only af_export.c and tvi_v4l2.c were
using mmap, but they didn't include osdep/mmap.h or mmap_anon.h. In
any case, we trust that the target system is sufficiently POSIX
compliant if mmap is actually defined (as checked by configure).
2013-07-07 21:44:37 +02:00
Stefano Pigozzi 8af51bd3fe cocoa: remove usage of mp_fifo
Update Cocoa parts to remove usage of the mp_fifo internal API to send events
to the core and use the input context directly. This is to follow commits the
work in commits 70a8079c and d603e73c.
2013-07-03 22:25:45 +02:00
wm4 d603e73c24 core: cleanup more mp_fifo leftovers
Now only the OSX and Wayland parts are using this.
2013-07-02 14:11:31 +02:00
Stefano Pigozzi 0407869ae3 OSX: fix compilation with 10.7 SDK
Recent work in the OS X parts of the code started using clang's support for
Obj-C's support for Literals and Subscripting. These particular language
features remove a lot of boilerplate code and allow to interact with
collections as consicely as one would do in scripting languages like Ruby or
Python.

Even if these are compiler features, Subscripting needs some runtime support.
This is provided with libarclite (coming with the compiler), but we need to
add the proper method definitions since the 10.7 SDK headers do not include
them. That is because 10.7 shipped before this language features.

This will cause some warnings when compiling with the 10.7 SDK because the
commit also redefines BOOL to make autoboxing/unboxing of BOOL literals to
work.

If you need to test this for whatever reason on 10.8, just pass in the correct
SDK to configure's extra cflags:

  ./configure --extra-cflags='-mmacosx-version-min=10.7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.7.sdk'

Fixes #117
2013-06-19 21:24:26 +02:00
wm4 171d1ef7fe osdep: remove shmem wrapper
This is unused now that the cache is always threaded.
2013-06-18 02:19:15 +02:00
Stefano Pigozzi e8a6e1a201 macosx_events: handle key modifiers with media keys
This was overlooked in the previous inplementation. Adding it required some
refactoring of the `handleKeyDown:` method in order to extract common parts
with `handleMediaKey:`.
2013-06-06 21:33:31 +02:00
Stefano Pigozzi 6619905902 macosx_events: DRY up key lookup over dictionary
Two methods duplicated very similar behaviour. Extract method with the common
behaviour.
2013-06-05 21:39:59 +02:00
Stefano Pigozzi 85c2a4a1d2 macosx_events: make remote property an instance variable
There was no reason for it to be public.
2013-06-05 00:02:29 +02:00
Stefano Pigozzi 213ad5d6c4 osx: improve Media Keys support
This commit addresses some issues with the users had with the previous
implementation in commit c39efb9. Here's the changes:

  * Use Quartz Event Taps to remove Media Key events mpv handles from
    the global OS X queue. This prevents conflicts with iTunes. I did this on
    the main thread since it is mostly idling. It's the playloop thread that
    actually does all the work so there is no danger of blocking the event tap
    callback.
  * Introduce `--no-media-keys` switch so that users can disable all of mpv's
    media key handling at runtime (some prefer iTunes for example).
  * Use mpv's bindings so that users can customize what the media keys do via
    input.conf. Current bindings are:

      MK_PLAY cycle pause
      MK_PREV playlist_prev
      MK_NEXT playlist_next

An additional benefit of this implementation is that it is completly handled
by the `macosx_events` file instead of `macosx_application` making the
project organization more straightforward.
2013-06-04 23:02:23 +02:00
Stefano Pigozzi 72f2942dfa osx: add Apple Remote support
After killing the non functional AR support in c8fd9e5 I got much complaints so
this adds AR support back in (and it works). I am using the HIDRemote class by
Felix Schwarz and that part of the code is under the BSD license. I slightly
modified it replacing [NSApplication sharedApplication] with NSApp. The code
of the class is quite complex (probably because it had to deal with all the
edge cases with IOKit) but it works nicely as a black box.

In a later commit I'll remove the deprecation warnings caused by HIDRemote's
usage of Gestalt.

Check out `etc/input.conf` for the default bindings.

Apple Remote functionality is automatically compiled in when cocoa is enabled.
It can be disabled at runtime with the `--no-ar` option.
2013-06-03 22:35:47 +02:00
Stefano Pigozzi c39efb96d1 osx: implement media keys
Media keys are pretty handy if you use mpv as a music player (yes I'm one of
those people that do).

These are the bindings (which lead to the same behaviour as iTunes):
  * NX_KEYTYPE_PLAY   -> MP_KEY_PLAY
  * NX_KEYTYPE_FAST   -> MP_KEY_NEXT
  * NX_KEYTYPE_REWIND -> MP_KEY_PREV

I just handled these ones as the volume one would be pretty invasive. I could
maybe change it to increase the application's volume instead of system volume
only when mpv is frontmost (iTunes does this), but some users would probably
hate it.
2013-06-03 22:31:14 +02:00
Stefano Pigozzi d67b687530 macosx_events: send all queued events
Seeking feels a little faster or it may be self suggestion. There's really no
reason to just send only one event at a time.
2013-06-03 22:31:13 +02:00
Stefano Pigozzi f0d2120347 osx: cocoa_common: use default wakeup period
Now that Cocoa's input handling is done on a separate thread from the playloop
it is ridicolously simple to have longer asynchronous sleeps when paused.
2013-06-03 22:31:13 +02:00
Stefano Pigozzi f13f0db33a osx: create macosx_events to deal with keyDown events
On OSX with Cocoa enabled keyDown events are now handled with
addLocalMonitorForEventsMatchingMask:handler:. This allows to respond to
events even when there is no VO initialized but the GUI is focused.
2013-06-03 22:31:13 +02:00
Stefano Pigozzi a31422bbfe macosx_application: refactor psn matching code
Objective-C is shorter / more readable than snprintf.
2013-05-30 23:03:20 +02:00
Stefano Pigozzi 8b40494e93 macosx_application: refactor filename escape
Use Objective-C's new literal syntax to make the code simpler.
2013-05-30 23:03:20 +02:00
Stefano Pigozzi 1d11db6596 macosx_application: use @autoreleasepool
I don't even want to know how this worked. It scares me a lot.
2013-05-30 23:01:12 +02:00
Stefano Pigozzi 3396e0565b macosx_application: move escape_loadfile_name in this file
This allows to move back osx_common to raw C.
2013-05-30 23:01:12 +02:00
Stefano Pigozzi 41e6c922a5 macosx_application: fix menu 'ghosting'
This fixes a bug that caused the application to never leave it's frontmost
position.

The idea is stolen from @donmelton who used it in MPlayerShell. Thanks!
2013-05-26 23:46:50 +02:00
wm4 f44a242258 Replace calls to usec_sleep()
This is just dumb sed replacement to mp_sleep_us().

Also remove the now unused usec_sleep() wrapper.
2013-05-26 16:44:20 +02:00
wm4 e56d8a200d Replace all calls to GetTimer()/GetTimerMS()
GetTimer() is generally replaced with mp_time_us(). Both calls return
microseconds, but the latter uses int64_t, us defined to never wrap,
and never returns 0 or negative values.

GetTimerMS() has no direct replacement. Instead the other functions are
used.

For some code, switch to mp_time_sec(), which returns the time as double
float value in seconds. The returned time is offset to program start
time, so there is enough precision left to deliver microsecond
resolution for at least 100 years. Unless it's casted to a float
(or the CPU reduces precision), which is why we still use mp_time_us()
out of paranoia in places where precision is clearly needed.

Always switch to the correct time. The whole point of the new timer
calls is that they don't wrap, and storing microseconds in unsigned int
variables would negate this.

In some cases, remove wrap-around handling for time values.
2013-05-26 16:44:20 +02:00
wm4 561aab2d77 timer: use gettimeofday() on Windows
MinGW-w64 emulates this via GetSystemTimeAsFileTime(), which has
supposedly the best and most stable timer source out of most others.

http://mingw-w64.svn.sourceforge.net/viewvc/mingw-w64/trunk/mingw-w64-crt/misc/gettimeofday.c
2013-05-26 16:44:20 +02:00
wm4 81439c5f35 timer: refactor, add 64 bit timer function
Make OS specific timer code export a mp_raw_time_us() function, and
add generic implementations of GetTimer()/GetTimerMS() using this
function. New mpv code is supposed to call mp_time_us() in situations
where precision is absolutely needed, or mp_time_s() otherwise.

Make it so that mp_time_us() will return a value near program start.
We don't set it to 0 though to avoid confusion with relative vs.
absolute time. Instead, pick an arbitrary offset.

Move the test program in timer-darwin.c to timer.c, and modify it to
work with the generic timer functions.
2013-05-26 16:44:20 +02:00
Stefano Pigozzi 29f5429223 macosx_application: implement "Quit & remember position"
Add a menu item to quit and save the current playback position using the code
added with commit ce9a854.

Fixes #85
2013-05-23 20:07:14 +02:00
wm4 58cc0f637f input: do property expansion for all input command string arguments
Also add a "raw" prefix for commands, which prevents property expansion.
The idea is that if the commands are generated by a program, it doesn't
have to know whether the command expands properties or not.
2013-05-18 17:45:55 +02:00
Stefano Pigozzi 6a83ef1552 macosx_application: fix crash when quitting player
mpv crashed on quit when it was run using the bundle functionality and started
without any files thus waiting for file open events. In that case, since there
is no key_fifo initialized yet, short circuit to `terminate_cocoa_application()`
which is generally called from `exit_player()` during normal lifecycle.

Fixes bug report from user `eng` on IRC.
2013-05-12 20:29:23 +02:00
Stefano Pigozzi 6a14dd593f macosx_application: add menu item for hide operation
Fixes #35
2013-05-12 15:27:54 +02:00
Stefano Pigozzi 134f3e97bf OSX: run native event loop in a separate thread
This commit is a followup on the previous one and uses a solution I like more
since it totally decouples the Cocoa code from mpv's core and tries to emulate
a generic Cocoa application's lifecycle as much as possible without fighting
the framework.

mpv's main is executed in a pthread while the main thread runs the native cocoa
event loop.

All of the thread safety is mainly accomplished with additional logic in
cocoa_common as to not increase complexity on the crossplatform parts of the
code.
2013-05-12 15:27:54 +02:00
Stefano Pigozzi afdc9c4ae2 OSX: use native Cocoa's event loop
Schedule mpv's playloop as a high frequency timer inside the main Cocoa event
loop. This has the benefit to allow accessing menus as well as resizing the
window without the playback being blocked and allows to remove countless hacks
from the code that involved manually pumping the event loop as well simulating
manually some of the Cocoa default behaviours.

A huge improvement consists in removing NSApplicationLoad. This is a C function
defined in the Cocoa header and implements a minimal OSX application under ther
hood so that you can use the Cocoa GUI toolkit from C/C++ without having to
respect the Cocoa standards in terms of application initialization. This was
bad because the behaviour implemented by NSApplicationLoad was hard to customize
and had several gotchas especially in the menu department.

mpv was changed to be just a nib-less application. All the Cocoa part is still
generated in code but the event handling is now not dissimilar to what is
present in a stock Mac application.

As a part of reviewing the initialization process, I also removed all of
`osdep/macosx_finder_args`. The useful parts of the code were moved to
`osdep/macosx_appication` which has the broaded responsibility of managing the
full lifecycle of the Cocoa application. By consequence the
`--enable-macosx-finder` configure switch was killed as well, as this feature
is always enabled.

Another change the users will notice is that when using a bundle the `--quiet`
option will be inserted much earlier in the initializaion process. This results
in mpv not spamming mpv.log anymore with all the initialization outputs.
2013-05-12 15:27:54 +02:00
Rudolf Polzer b1ae33a355 mp_msg: fix status output disappearing when redirecting INPUT.
Instead, we now check stderr's destination against the foreground tty
for deciding whether we want status output or not.
2013-03-18 20:33:29 +01:00
wm4 75e6584ab3 Prefix keycode defines with MP_
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)
2013-02-12 10:27:00 +01:00
Stefano Pigozzi 68fa3c49db cocoa_events: remove this functionality
This functionality looked smart but created problems with some kinds of
multi touch events. Moreover some events coming from the windows server – like
hovering a corner for window resize – didn't cause the player to wake up
immediately.

The "correct" non hacky way to implement async event polling with cocoa would
be having the vanilla cocoa event loop driving the player and setting up mpv's
terminal FDs as event sources for the cocoa event loop.

Fixes #20
2013-02-02 14:36:05 +01:00
Rudolf Polzer 3b22404e07 mp_msg, getch2: unix tty background support
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.
2013-01-23 18:05:34 +01:00
wm4 20c9dfa616 Replace strsep() uses
This function sucks and apparently is not very portable (at least on
mingw, the configure check fails). Also remove the emulation of that
function from osdep/strsep*, and remove the configure check.
2013-01-13 17:32:39 +01:00
wm4 cbdee50f29 windows support: fix _wstat misusage
I have no idea when or how this broke, but _wstati64() is the function
we want anyway (64 bit filesize). Possibly this was a mingw-w64 bug.
It's unknown why "wstat()" just doesn't work in this case, as it's not
defined by MSDN and could be defined by mingw as it needs.
2013-01-13 17:32:39 +01:00
wm4 41dbf07fc5 osdep: remove gettimeofday() emulation
Guaranteed by POSIX, and mingw provides it as well.
2013-01-13 17:32:39 +01:00
wm4 a96788fe57 osdep: remove setenv() emulation
mpv doesn't use setenv() anymore. The configure check was actually
removed earlier; maybe it was forgotten to remove this completely.
2013-01-13 17:31:22 +01:00
wm4 b87b0ef5ec osdep: remove broken vsscanf() emulation
vsscanf() is in POSIX, C99, mingw, etc. Further, the implementation in
osdep/vsscanf.c was completely broken, and if it worked, it worked only
by chance.
2013-01-13 14:27:10 +01:00
wm4 f394a25e7b Update copyright year 2013-01-04 15:23:23 +01:00
Stefano Pigozzi fab9febdc3 path: add mp_find_config_file and reorganize some of the code
Add `mp_find_config_file` to search different known paths and use that in
ass_mp to look for the fontconfig configuration file.

Some incidental changes spawned by this feature where:

 * Buffer allocation for the strings containing the paths is now performed
   with talloc. All of the allocations are done on a NULL context, but it still
   improves readability of the code.
 * Move the OSX function for lookup inside of a bundle: this code path was
   currently not used by the bundle generated with `make osxbundle`. The plan
   is to use it again in a future commit to get a fontconfig config file.
2012-12-15 17:38:00 +01:00
wm4 4873b32c59 Rename directories, move files (step 2 of 2)
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.)
2012-11-12 20:08:18 +01:00