Commit Graph

30 Commits

Author SHA1 Message Date
der richter b8f2811f8d mac: fix media key support for libmpv users
this basically moves the remote command center to our mac events instead
of keeping it our Application, which is only available when started from
mpv itself. also make it independent of the NSApplication.

this also prevents a runtime crash
2020-02-22 13:56:31 +01:00
der richter a32db637b5 mac: replace old event tap for media key support with MediaPlayer
the old event tap has several problems, like no proper priority support
or having to set accessibility permissions for mpv or the terminal.

it is now replaced by the new MediaPlayer which has proper priority
support and isn't as greedy as previously. this only includes Media Key
support and not any of the other features included in the MediaPlayer
framework, like proper Now Playing data (only set dummy data for now).
this is only available on macOS 10.12.2 and higher.

also removes some unnecessary redefines.

Fixes #6389
2019-12-15 20:07:31 +01:00
der richter c8cc203735 cocoa-cb: use m_config_cache and new VOCTRL for option handling
this removes the direct access of the mp_vo_opts stuct via the vo struct
and replaces it with the m_config_cache usage. this updates the
fullscreen and window-minimized property via m_config_cache_write_opt
instead of the old mechanism via VOCTRL and event flagging. also use the
new VOCTRL_VO_OPTS_CHANGED event for fullscreen and border changes.
2019-12-15 20:07:11 +01:00
Akemi 5865086aa8 cocoa-cb: remove pre-allocation of window, view and layer
the pre-allocation was needed because the layer allocated a opengl
context async itself and we couldn't influence that. so we had to start
the core after the context was actually allocated. furthermore a window,
view and layer hierarchy had to be created so the layer would create
a context.
now, instead of relying on the layer to create a context we do this
manually and re-use that context later when the layer wants to create
one async itself.
2018-06-12 01:51:01 +03:00
Akemi c5e4538bc4 cocoa-cb: initial implementation via opengl-cb API
this is meant to replace the old and not properly working vo_gpu/opengl
cocoa backend in the future. the problems are various shortcomings of
Apple's opengl implementation and buggy behaviour in certain
circumstances that couldn't be properly worked around. there are also
certain regressions on newer macOS versions from 10.11 onwards.

- awful opengl performance with a none layer backed context
- huge amount of dropped frames with an early context flush
- flickering of system elements like the dock or volume indicator
- double buffering not properly working with a none layer backed context
- bad performance in fullscreen because of system optimisations

all the problems were caused by using a normal opengl context, that
seems somewhat abandoned by apple, and are fixed by using a layer backed
opengl context instead. problems that couldn't be fixed could be
properly worked around.

this has all features our old backend has sans the wid embedding,
the possibility to disable the automatic GPU switching and taking
screenshots of the window content. the first was deemed unnecessary by
me for now, since i just use the libmpv API that others can use anyway.
second is technically not possible atm because we have to pre-allocate
our opengl context at a time the config isn't read yet, so we can't get
the needed property. third one is a bit tricky because of deadlocking
and it needed to be in sync, hopefully i can work around that in the
future.

this also has at least one additional feature or eye-candy. a properly
working fullscreen animation with the native fs. also since this is a
direct port of the old backend of the parts that could be used, though
with adaptions and improvements, this looks a lot cleaner and easier to
understand.

some credit goes to @pigoz for the initial swift build support which
i could improve upon.

Fixes: #5478, #5393, #5152, #5151, #4615, #4476, #3978, #3746, #3739,
#2392, #2217
2018-02-12 04:49:15 -08:00
Akemi db08e28304 osx: code cleanups and cosmetic fixes 2018-01-20 14:43:49 -08:00
Akemi e0a2d15216 osx: refactor menu bar creation
make the menu bar look more like a standard macOS menu bar, with all the
standard menu items like About, Help, Open, etc.
2017-08-18 19:20:41 +02:00
Akemi 48ab72b478 osx: move menu bar creation into its own file 2017-08-18 19:20:41 +02:00
wm4 6b303d5c3c osx: change license of OSX and cocoa files to LGPL
All authors of the current code have agreed.
2017-06-24 16:29:22 +02:00
Akemi f8a223b7ac osx: initial Touch Bar support 2017-03-26 20:26:18 +02:00
wm4 19a5b20752 cocoa: always compile OSX application code with cocoa
This unbreaks compiling command line player and libmpv at the same
time. The problem was that doing so silently disabled the OSX
application thing - but the command line player can not use the
vo_opengl Cocoa backend without it.

The OSX application code is basically dead in libmpv, but it's not
that much code anyway.

If you want a mpv binary that does not create an OSX application
singleton (and creates a menu etc.), you must disable cocoa
completely, as cocoa can't be used anyway in this case.
2015-05-02 18:09:56 +02:00
Marcin Kurczewski f43017bfe9 Update license headers
Signed-off-by: wm4 <wm4@nowhere>
2015-04-13 12:10:01 +02:00
Stefano Pigozzi fc7731983e cocoa: ignore first file open events from command line
similar to some of the code deleted in 685b8b7a but simpler
2014-12-07 21:39:26 +01:00
Stefano Pigozzi 685b8b7a00 cocoa: use --idle when running inside bundle
Previously when using the bundle we used a custom bizarro thing to wait for
events. Just use `--idle` and greatly simplify the code.
2014-12-06 14:16:13 +01:00
FRAU KOUJIRO 0be25a8dbf cocoa: move handleFilesArray: to macosx_events 2014-08-06 09:31:58 +02:00
FRAU KOUJIRO 78a266d599 cocoa: decouple events from application somewhat 2014-08-06 09:31:58 +02:00
Stefano Pigozzi 1e988c595b cocoa: handle files drag and drop on the player video view 2014-01-04 17:29:53 +01:00
Stefano Pigozzi c54a1f3e41 cocoa: fix race condition with input context creation
This seems to be a problem only in OS X 10.9. I guess they improved the
general speed of the Cocoa startup and suddenly mpv core takes more time
than the Cocoa thread to initialize.

Fixes #285

(hopefully!)
2013-10-24 00:07:05 +02:00
Stefano Pigozzi 462e6f281a cocoa: let the core handle key repeats
Report key down and key up modifiers to the core so that it can issue it's
own key repeats (instead of relying on Cocoa's ones).
2013-08-30 19:49:30 +02:00
Stefano Pigozzi 11dad6d44b macosx: remove platform specific input queue
Since last commit the input queue in the core is thread safe, so there is no
need for all this platform specific stuff anymore.
2013-08-13 23:02:43 +02:00
Stefano Pigozzi 5f265d5930 cocoa_common: handle keyboard modifiers for mouse events 2013-07-21 10:49:27 +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
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 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 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 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