Commit Graph

159 Commits

Author SHA1 Message Date
Stefano Pigozzi 48e3344f84 cocoa: don't reset window size when the video size doesn't change
Fixes #459
2014-01-06 14:19:04 +01: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 b205e63cdc Revert "cocoa: unlock on uninit"
Not sure why but this doesn't seem to be needed anymore.

This reverts commit 6ead6aa005.
2013-12-26 22:26:41 +01:00
Stefano Pigozzi a410a750c7 cocoa: sanitize window title string and guard against NULL
If the utf8 string used to create the NSString for title was invalid utf8,
-stringWithUTF8String returned nil and triggered an assertion in Cocoa's
framework code.

Sanitize the utf8 string and if the sanitation wasn't enough just avoid
crashing by not setting a title.

Fixes #406
2013-12-25 18:13:09 +01:00
11rcombs ad92c893a0 Fix OSX build; remove all remaining mpvcore references 2013-12-17 08:44:21 +01:00
agiz a066dae19e cocoa: make borderless window resizable
Fixes #399
2013-12-07 15:43:49 +01:00
Stefano Pigozzi 6ead6aa005 cocoa: unlock on uninit
NSLock should be unlocked before dealloc is called on it.
2013-11-26 20:50:35 +01:00
Stefano Pigozzi 3f594c2e84 cocoa: use window-scale to support video scaling functionality
In the cocoa backend you can use cmd+0/1/2 to scale the window. This commit
makes it use the new window-scale functionality.
2013-11-22 08:43:02 +01:00
Stefano Pigozzi ede608ed43 cocoa: implement window-scale 2013-11-22 08:41:34 +01:00
Stefano Pigozzi 3b156caf78 cocoa: set and clear gl context inside of sync sections
The code did not set and unset the current context inside sync sections. I am
not sure if this was an actual problem but this is better since the context is
linked to a single thread. In my brief tests this seems to avoid garbage to
show up in fullscreen.
2013-10-20 21:25:55 +02:00
Stefano Pigozzi 8d5f800567 cocoa: make --ontop also cover dock+menubar
This only shows any differences when mpv isn't frontmost and is in fullscreen.
Cmd+Tab overlay is still at a higher level as to avoid complete usability fail.
2013-10-12 21:02:46 +02:00
Stefano Pigozzi 89fced63b8 cocoa_common: add OS X 10.7 compatibility hacks includes
I forgot these when I split the code. They will hopefully fix compilation on
10.7.
2013-10-05 14:40:48 +02:00
Stefano Pigozzi 9d3943840c cocoa_common: call gl_clear indirectly
glClear needs GL headers and we don't want those in `cocoa_common`. Create
a callback in `gl_cocoa` and register it `cocoa_common`.

Fixes #264
2013-09-28 15:08:40 +02:00
Stefano Pigozzi 73808cd8f0 cocoa_common: fix deadlock
After rebasing my dev branch it turned out that  the code deadlocked on
recursive calls of `vo_control`. Make the locking code a little bit smarter
by making always skip locking/unlocking if we are executing a chunck of
code that is already synchronized with `dispatch_sync`.
2013-09-28 15:08:26 +02:00
Stefano Pigozzi 0ab9634eb3 cocoa_common: split the code, refactoring and cleanups
Split the code to several files. The GUI elements now each have they own files
and private state. The original code was a mess to respect the retarded mplayer
convention of having everything in a single file.

This commit also seems to fix the long running bug of artifacts showing
randomly when going fullscreen using nVidia GPUs.
2013-09-28 11:20:00 +02:00
Stefano Pigozzi bb4ea8bb3e cocoa_common: signal a mouse movement when changing window size
This is mainly to avoid spurious cursor states due to the mouse moving inside
or outside the window as a result of the window resize (with cmd-0/1/2).

This avoids complex logic and triggers a mouse move so that the player
recomputes the correct cursor state based on the autohide configuration of
the user.
2013-09-18 19:05:00 +02:00
Stefano Pigozzi a08802016d cocoa_common: override core's cursor visibility state
This keeps the state in sync with the current state in cocoa_common. Infact the
cocoa code in mpv can decide wether it really wants to hide the cursor based on
the result of the `canHideCursor` method (this is so that the cursor is only
hidden when hovering on the video window).
2013-09-18 19:05:00 +02:00
Stefano Pigozzi 49849190dd cocoa_common: remove most of the special handling for cursor autohide
This is mostly related to the fullscreen behaviour. cecbd8864 introduces an
option to make mpv behave like a OSX user would expect. This commit changes
the Cocoa parts of the code to be consistent with the behaviour on X11. Old
behaviour is still available through the option mentioned in cecbd8864.

There is still custom logic in the cocoa backend and it can probably be moved
to core:

  * Don't perform autohide if the mouse is down
  * Don't perform autohide outside of the video window

Fixes #218 (by accident)
2013-09-10 21:24:37 +02:00
Stefano Pigozzi 39a69aeb89 cocoa_common: remove unlocking from fullscreen function
This was added in the past to prevent a deadlock, but is not needed
anymore.
2013-09-02 08:35:21 +02:00
Stefano Pigozzi 694654e383 cocoa_common: avoid the opengl view to leak it's state
Just because everything is in a single file it doesn't excuse us to have high
coupling between C and ObjC code.
2013-09-02 08:21:03 +02:00
Stefano Pigozzi ddd873902a cocoa_common: enable click-through on the video view
Generate a mouse down event on the first click so that one can interact
with the OSC directly as opposed to wasting the first click in order to focus
the window.
2013-09-01 16:10:57 +02:00
Stefano Pigozzi c686e270a1 cocoa_common: track mouse move events when not focused
This is really only important with the OSC and makes the tracking code behave
more consistently with the X11 one.
2013-09-01 16:10:37 +02:00
Stefano Pigozzi d3c4ba3ab8 cocoa_common: autohide dock when autohiding menubar
A cocoa bug doesn't allow to do otherwise. Will open a radar later.
2013-08-26 20:01:20 +02:00
Stefano Pigozzi fcde6207a1 cocoa_common: avoid locking calls when not needed
cocoa_common contains some locking calls to support video outputs that support
live resizing (at this moment only vo=opengl).

These should not be used unless the VO declares it is multithreaded by
registering the resize_redraw callback used for live resizing.

Fixes #200
2013-08-23 13:58:38 +02:00
Stefano Pigozzi acbf5e826a cocoa_common: fix window positioning with `--geometry`
Regression since ff3b98d11c. The window positioning code relied on the
visibleFrame's height without taking into account the dock's presence.

Also moved the constraining code to the proper method that overrides the
original NSWindow behaviour. This avoids having to check for border since the
constraining is performed by Cocoa only for titled windows.

Fixes #190
2013-08-22 11:54:28 +02:00
Stefano Pigozzi 04cdc205bc cocoa_common: add precise scrolling support
This adds precise scrolling support. I ran some tests and it seems a little
bit smoother and well.. precise. The defaults are rebindable using: AXIS_UP,
AXIS_DOWN, AXIS_LEFT and AXIS_RIGHT.
2013-08-13 23:05:46 +02:00
Stefano Pigozzi 406241005e core: move contents to mpvcore (2/2)
Followup commit. Fixes all the files references.
2013-08-06 22:52:31 +02:00
Stefano Pigozzi 94df9ef797 cocoa_common: use new log API 2013-08-01 08:23:53 +02:00
Stefano Pigozzi ff3b98d11c cocoa_common: simplify resize code
This introduces some changes in resize behaviour. Most importantly the window
frame is not constrained to it's screen's `visibleFrame`. Anyone who still wants
that kind of behaviour when opening a video, can use `--autofit-larger`.

Even though the size of the window is not constrained, it's position is, so
that the titlebar will always be visible. When using `--no-border` even the
position will not be constrained in any way.
2013-07-30 20:02:48 +02:00
Stefano Pigozzi 644451f4d9 cocoa_common: fix regression in draggable state computation
Regression introduced in 8fb064de5. Prevented the OSC from working correctly.
2013-07-21 21:02:44 +02:00
Stefano Pigozzi 73cd78f8c5 cocoa_common: fix style 2013-07-21 21:02:43 +02:00
Stefano Pigozzi 7c1d707f45 cocoa_common: move tracking area setup to updateTrackingAreas
This makes the tracking area work when going in and out of fullscreen.
2013-07-21 21: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 7088fe3fec cocoa_common: make the fullscreen transition only when necessary
This makes the cocoa backend follow more closely the new fullscreen semantics
added in c4b08a9a.
2013-07-20 12:08:14 +02:00
Stefano Pigozzi 8fb064de58 cocoa_common: use a tracking area to handle mouse events
This change which also flipse the coordinate system of the view, greatly
simplifies the mouse event handling code.

There are still some uglities mostly related to the cursor visibility
code. For instance the core doesn't show the cursor when it receives a mouse
leave event.
2013-07-20 11:45:32 +02:00
Stefano Pigozzi 2765153214 cocoa_common: fix typo in comment
Surely it's copy pasta's fault.
2013-07-20 11:44:06 +02:00
Stefano Pigozzi 20c0231f02 cocoa_common: implement MP_MOUSE_LEAVE notifications
This is needed for the OSC. At the moment I'm sending a notification for any
mouse movement outside of the video surface. This might be overkill.
2013-07-20 11:44:06 +02:00
Stefano Pigozzi 891e092669 cocoa_common: implement conditional video dragging
This was more roundabout than expected, since it looks like the framework
caches isMovabileByWindowBackground so in mpv's case it's needed to set it
with setMovableByWindowBackground.
2013-07-20 11:44:06 +02:00
wm4 c4b08a9a11 video: remove fullscreen flags chaos
There was a MPOpts fullscreen field, a mp_vo_opts.fs field, and
VOFLAG_FULLSCREEN. Remove all these and introduce a
mp_vo_opts.fullscreen flag instead.

When VOs receive VOCTRL_FULLSCREEN, they are supposed to set the
current fullscreen mode to the state in mp_vo_opts.fullscreen. They
also should do this implicitly on config().

VOs which are capable of doing so can update the mp_vo_opts.fullscreen
if the actual fullscreen mode changes (e.g. if the user uses the
window manager controls). If fullscreen mode switching fails, they
can also set mp_vo_opts.fullscreen to the actual state.

Note that the X11 backend does almost none of this, and it has a
private fs flag to store the fullscreen flag, instead of getting it
from the WM. (Possibly because it has to deal with broken WMs.)

The fullscreen option has to be checked on config() to deal with
the -fs option, especially with something like:

   mpv --fs file1.mkv --{ --no-fs file2.mkv --}

(It should start in fullscreen mode, but go to windowed mode when
playing file2.mkv.)

Wayland changes by: Alexander Preisinger <alexander.preisinger@gmail.com>
Cocoa changes by: Stefano Pigozzi <stefano.pigozzi@gmail.com>
2013-07-18 14:07:21 +02:00
Stefano Pigozzi b0932ecbb6 cocoa_common: change video size when changing screen DPI
This improves the situation when moving a window from screens with different
DPIs.
2013-07-10 22:22:08 +02:00
wm4 d084f72a6c core: remove mp_fifo leftovers 2013-07-04 17:53:30 +02:00
wm4 c4766dc3c6 input: require VOs to send key up events, redo input key lookup
Making key up events implicit was sort-of a nice idea, but it's too
tricky and unreliable and makes the key lookup code (interpret_keys())
hard to reason about. See e.g. previous commit for subtle bugs and
issues this caused.

Make key-up events explicit instead. Add key up events to all VOs.
Any time MP_KEY_STATE_DOWN is used, the matching key up event must
use MP_KEY_STATE_UP.

Rewrite the key lookup code. It should be simpler and more robust now.
(Even though the LOC increases, because the new code is less "compact".)
2013-07-02 12:19:16 +02:00
Stefano Pigozzi fd7dd83e28 cocoa_common: uninit fs window properly
In fullscreen `s->window` is the windowed window. So freeing that didn't get
rid of the FS window and OpenGL view.

Fixes #122
[ci skip]
2013-06-29 22:55:15 +02:00
Stefano Pigozzi 6669366280 cocoa_common: schedule a redraw frame after a non live resize
A redraw forces recalculation of panscan and other stuff not accounted for in
the resize_redraw codepath. This is actually a hack but works really well in
my tests.

Thanks @wm4 and @Cpuroast for the idea.

Fixes #86
[ci skip]
2013-06-25 22:13:48 +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
Stefano Pigozzi de63e1d15e cocoa_common: implement VOCTRL_UPDATE_WINDOW_TITLE
Unfortunately this backend creates the window lazily and a call to
`cocoa_set_window_title` is needed inside config.
2013-06-16 11:00:20 +02:00
Stefano Pigozzi 3c12148668 cocoa_common: remove play/pause VOCTRL functions
Make VOCTRL_RESTORE_SCREENSAVER / VOCTRL_KILL_SCREENSAVER use the power
management functions directly.
2013-06-14 07:34:47 +02:00
wm4 648c3d790a core: introduce separate VOCTRLs for screensaver stop/resume
This is slightly better because VOCTRL_RESUME/VOCTRL_PAUSE are usually
needed by VOs to know whether video is actually being played (for
whatever reason), and they wouldn't be passed to the backend's VOCTRL
handler, like vo_x11_control().

Also try to make sure that these flags (both pause state and screensaver
state) are set consistently in some corner cases. For example, it seems
enabling video in the middle of playing a file while the player is
paused would not set the paused flag.

If codec initialization fails, destroy the VO instead of keeping it
around to make sure the state is consistent.

Framestepping is implemented by unpausing the player for the duration of
a frame. Remove the special handling of VOCTRL_PAUSE/RESUME in these
cases. It was most likely needed because these VOCTRLs used to be
important for screen redrawing (blatant guess), which is now handled
completely differently. The only potentially bad side-effect is that the
screensaver will be disabled/reenabled for the duration of one frame.
2013-06-14 00:37:39 +02:00
Stefano Pigozzi 4ffaf4868e cocoa_common: fix ontop switching when fullscreen
`enterFullScreenMode:withOptions:` creates another window so set the level on
both the windowed window and current window.

Also remove NSFullScreenModeWindowLevel as it seems to be superfluous.
2013-06-11 21:20:46 +02:00
Stefano Pigozzi fbca1b179a cocoa_common: fix window level when going fullscreen
This is a regression introduced by 0057aa4769. Fix it so that the fullscreen
window uses the correct window level.

[ci skip]

Fixes #106
2013-06-10 20:42:39 +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 57571b5da3 cocoa_common: autohide dock/menubar on fs only if on same screen
Autohide the menubar and/or dock only if they are present in the screen the
player is going to go fullscreen into. I thought the GUI would handle this for
me when I switched 0057aa476 but lack of hardware to test made me embarass
myself yet again.

I reimplemented this feature with nicer code and behaviour. The code checks
separately wether to hide menubar and dock separatly, while the old code used
a single check possibly hiding stuff without need.

Added the key checks as a some category additions to NSScreen for readability.
2013-06-01 22:52:21 +02:00
Stefano Pigozzi f4dcb93be1 cocoa_common: don't autohide mouse on mousedown
Previews code allowed to click the same spot for a long time and the cursor
would autohide. No more!
2013-06-01 17:58:08 +02:00
Stefano Pigozzi db7835f5d7 cocoa_common: avoid window creation with VOFLAG_HIDDEN
This takes an approach similar to the wayland OpenGL backend. VOFLAG_HIDDEN
flag semantics doesn't mean "hide the window" but is simply ever used only to
do detection of available OpenGL extensions. On OSX it's possibile to
accomplish this task just by creating the OpenGL context without attaching
it to a drawable.
2013-06-01 12:12:17 +02:00
Stefano Pigozzi 109158603d cocoa_common: dehack mouse autohide by clipping view bounds to visible screen
This prevents the mouse to autohide when hovering the dock/menubar without any
particular hack and seems to finally cover all edge cases.
2013-06-01 02:10:41 +02:00
Stefano Pigozzi 25ae58fbbe cocoa_common: fix mouse autohide on MenuBar/Dock interaction
This is needed after last commit. A bug within a bug (yo dawg)! Serious
explaination in the source code comment so that it's not forgotten.
2013-05-31 14:16:27 +02:00
Stefano Pigozzi 2c4f5b75c0 cocoa_common: fix empty window when going fs on different screen
Using `enterFullScreenMode:withOptions:` with a screen handle than the current
screen doesn't hide the current window in the current screen. This is a bug in
Cocoa (preparing an isolated test case and sending the rdar later).

To work around this, manually hide/show the window that the toolkit should
hide/show for us.
2013-05-31 12:58:54 +02:00
Stefano Pigozzi bf21ed0102 cocoa_common: fix mouse hiding outside of player view
This bug was the result of crappy position detection in the previous code
combined with the commits moving autohide delay out of the cocoa backend and
into the core.

The hit detection was improved and now takes also account of interactions with
the Dock and Menubar. Moreover VOCTRL_SET_CURSOR_VISIBILITY now has an effect
only if the mouse position matches with this improved hit detection. This means
that both interaction with the Dock and Menubar are considered as well as
moving the mouse inside another screen.
2013-05-30 23:03:21 +02:00
Stefano Pigozzi 68c3e2aabb cocoa_common: refactor fullscreen code for readability
Break up the code into several methods and reduce code duplication. Also add
comments to make the intention of all this clearer.
2013-05-30 23:03:20 +02:00
Stefano Pigozzi 0aac8bc5ad cocoa_common: fix native-fs state saving
`opts->fs = VO_FALSE` was forgotten
2013-05-30 23:03:20 +02:00
Stefano Pigozzi 3789e1bebf cocoa_common: fix a bug in window initialization error
We didn't bail out soon enough. Bug was introduced by 134f3e97.
2013-05-30 23:02:56 +02:00
Stefano Pigozzi 0057aa4769 cocoa_common: use cocoa APIs to go fullscreen
This removes a bit of ugly code and bookeeping which is never bad. `drawRect`
needs to guard against different window instances since in fullscreen the view
is wrapped in a fullscreen window provided by the toolkit (a instance of
NSFullScreenWindow to be precise).

The event handling was moved to the view so that it can still get all the
events when in the fullscreen window. Ideally these should be moved to
some NSResponder subclass within macosx_application and made available even
when no window is present. I refrained from this because "small steps".
2013-05-30 23:01:12 +02:00
Stefano Pigozzi 14ff6bbf7c cocoa_common: use better power management activity description
Now one might actually undestand why this power management assertion is used
in the first place.
2013-05-30 23:01:12 +02:00
Stefano Pigozzi ae1fa639e0 osx: remove compatibility conditionals for 10.6
At this point 10.6 is pretty old and we don't want to supporting old platforms.
I'm killing all the 10.6 compatibility code before doing more refactorings.

Next commits will also use newer Objective-C syntax such as literals and
@autoreleasepool.
2013-05-30 22:57:35 +02:00
Stefano Pigozzi 25d66f526e cocoa_common: send mouse moved events to core when dragging
This change fixes mouse autohide when dragging mouse.
2013-05-26 16:44:20 +02:00
Stefano Pigozzi e6a225d57a cocoa_common: implement VOCTRL_SET_CURSOR_VISIBILITY
Pass along cursor visibility hints to be more consistent with OSX's behaviour.
2013-05-26 16:44:19 +02:00
Stefano Pigozzi ea8a8af3ec cocoa_common: implement mouse movement notifications
Notify the core of mouse movement events. The coordinates are converted to a
coordinate system with the origin in upper left corner, since Cocoa has it in
the lower left corner.
2013-05-26 16:44:19 +02:00
wm4 bf10a4fdfa video/out: introduce vo_control for gl_common based VOs
Instead of having separate callbacks for each backend-handled feature
(like MPGLContext.fullscreen, MPGLContext.border, etc.), pass the
VOCTRL responsible for this directly to the backend. This allows
removing a bunch of callbacks, that currently must be set even for
optional/lesser features (like VOCTRL_BORDER).

This requires changes to all VOs using gl_common, as well as all
backends that support gl_common.

Also introduce VOCTRL_CHECK_EVENTS. vo.check_events is now optional.
VO backends can use VOCTRL_CHECK_EVENTS instead to implementing
check_events. This has the advantage that the event handling code in
VOs doesn't have to be duplicated if vo_control() is used.
2013-05-26 16:44:18 +02:00
Stefano Pigozzi 8db90e18d3 cocoa_common: authohide menu/dock in fullscreen
This simple fix makes it possible to access the MainManu and Dock when in
fullscreen when not using `--native-fs`.
2013-05-26 11:34:35 +02:00
Stefano Pigozzi f9ed43077f cocoa_common: vo_corevideo: fix window initialization
vo_corevideo doesn't create a hidden window to perform OpenGL extensions
detection. This caused the window to always stay close.
2013-05-16 23:46:31 +02:00
Stefano Pigozzi 647291bab2 cocoa_common: order front window only when invisible [2]
Followup to 8df7127. This refines the condition for front ordering the
condition to account for minimized or hidden state where the window should go
to the front only as a consequnce of user interaction.
2013-05-14 00:16:57 +02:00
Stefano Pigozzi 8df712781c cocoa_common: order front window only when invisible
Window creation code always made mpv the front window. Fix it to make it front
only if the window is currently invisible.

Fixes #84
2013-05-13 23:49:00 +02:00
Stefano Pigozzi d2960d2e96 cocoa_common: don't use recursive locking
This was in the original change set for the threadsafety changes but I forgot
to squash it in.
2013-05-13 23:41:03 +02:00
Stefano Pigozzi 4878be02ad cocoa_common: remove pointless locking when using -fs
When using --fs `vo_cocoa_fullscreen` was called from the primary thread. This
occurred inside `vo_cocoa_config_window` which is scheduled for excution on the
primary thread with libdispatch).

All of this caused spam from NSRecursiveLock in standard output.
2013-05-13 23:41:03 +02:00
Stefano Pigozzi 4ce808cc2c cocoa_common: fix a bug in window dragging state
When going in and going out of full screen the player lost information on the
movableByWindowBackground behaviour. There were some hacks in place to fix it
but they were broken with the recent native fullscreen changes in 74c15ec6.

This commit removes the problem at the root and removes the hacks. The delegate
method `isMovableByWindowBackground` seems to be called after setFrame and
setPresentationOptions so change fs state in opts before that.

Fixes #83
2013-05-13 23:41:03 +02:00
Stefano Pigozzi 35c8f7b608 cocoa_common: fix deadlock when calling resize_redraw
Fixes #82
2013-05-12 23:51:58 +02:00
Stefano Pigozzi 74c15ec696 cocoa_common: add native OSX fullscreen support
This adds Mission Control fullscreen functionality to mpv. Since this doesn't
play well with many of mpv's features disable it by default. Users can activate
this feature by using `--native-fs` when starting mpv.

Fixes #34
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
Stefano Pigozzi 7a42df8712 cocoa_common: fix window sizing
The code was attempting to get the ceiling of the double. Too bad NSSize has
floats inside of it and the int cast is nowhere to be seen. This caused
rounding errors by one pixel in the window size.
2013-04-28 09:55:06 +02:00
Stefano Pigozzi 9a6e6b2fc2 cocoa_common: keep aspect ratio when clipping window
With commit 33ffc283 resizing to double size would cause the window to lose
aspect ratio. This commit fixes this bug.
2013-04-17 21:22:22 +02:00
Stefano Pigozzi 22d53fb97c change reverse DNS strings to io.mpv.*
fixes #60
2013-04-16 23:34:58 +02:00
Stefano Pigozzi 33ffc28373 cocoa_common: refactor centered resize
This refactor makes the code easier to understand. Also corrects a bug that
caused the window to move to the left when the new size was bigger than the
visible frame.
2013-04-16 22:51:01 +02:00
Stefano Pigozzi ad000fb916 cocoa_common: fix regression when changing videos in fullscreen
I introuced this regression in 8fc0b618d5. The backend would go into
incosistent state caused by calling `vo_cocoa_fullscreen` where it wasn't
needed.

Fixes #44
2013-03-15 22:48:57 +01:00
Stefano Pigozzi 89aae59e89 cocoa_common: fix window position when bigger than display
Fix a regression introduced in commit 979ce46c64 causing a window to take up
more space than what the display allows.

Add keepCentered:YES, so that the video area is always clipped to the current
visible frame (even when using scale).

Fixes #38.
2013-03-10 17:27:43 +01:00
Alexander Preisinger 1198c031e4 vo: Separate vo options from MPOpts
Separate the video output options from the big MPOpts structure and also only
pass the new mp_vo_opts structure to the vo backend.

Move video_driver_list into mp_vo_opts
2013-03-04 23:32:47 +01:00
Stefano Pigozzi 39824c071e cocoa_common: fix crash 2013-03-04 23:23:12 +01:00
Stefano Pigozzi a453a0a57b cocoa_common: fix compilation
7686cd7f broke some stuff
2013-03-04 22:51:43 +01:00
Alexander Preisinger 7686cd7f04 vo: remove and cleanup globals
Removes almost every global variabel in vo.h and puts them in a special struct
in MPOpts for video output related options.

Also we completly remove the options/globals pts and refresh rate because
they were unused.
2013-03-04 17:40:21 +01:00
Stefano Pigozzi 8fc0b618d5 cocoa_common: make windows appear again
Commit 9efe32120 stops recreating the hidden window used for OpenGL's
extensions autodetection. The `cocoa_common` code assumed the hidden flag could
only come when creating a window which is now not true anymore.

Move some code around so that hidden, fullscreen and window position are
respected on subsequent calls of config.
2013-03-03 21:52:58 +01:00
wm4 423c0b13c4 video/out: rename create_window to config_window
create_window is really bad naming, because this function can be called
multiple times, while the name implies that it always creates a new
window. At least the name config_window is not actively misleading.
2013-02-26 02:01:48 +01:00
wm4 c61f1ff61b gl_common: simplify window/context creation
Allow the backend code to create a GL context on best effort basis,
instead of having to implement separate functions for each variation.
This means there's only a single create_window callback now. Also,
getFunctions() doesn't have the gl3 parameter anymore, which was
confusing and hard to explain.

create_window() tries to create a GL context of any version. The field
MPGLContext.requested_gl_version is taken as a hint whether a GL3 or a
legacy context is preferred. (This should be easy on all platforms.)

The cocoa part always assumes that GL 3 is always available on
OSX 10.7.0 and higher, and miserably fails if it's not. One could try
to put more effort into probing the context, but apparently this
situation never happens, so don't bother. (And even if, mpv should be
able to fall back to vo_corevideo.)

The X11 part doesn't change much, but moving these functions around
makes the diff bigger.

Note about some corner cases:

This doesn't handle CONTEXT_FORWARD_COMPATIBLE_BIT_ARB on OpenGL 3.0
correctly. This was the one thing getFunctions() actually needed the
gl3 parameter, and we just make sure we never use forward compatible
contexts on 3.0. It should work with any version above (e.g. 3.1, 3.2
and 3.3 should be fine). This is because the GL_ARB_compatibility
extension is specified for 3.1 and up only. There doesn't seem to be
any way to detect presence of legacy GL on 3.0 with a forward
compatible context. As a counter measure, remove the FORWARD_COMPATIBLE
flags from the win32 code. Maybe this will go wrong. (Should this
happen, the flag has the be added back, and the win32 will have to
explicitly check for GL 3.0 and add "GL_ARB_compatibility" to the extra
extension string.)

Note about GLX:

Probing GL versions by trying to create a context on an existing window
was (probably) not always possible. Old code used GLX 1.2 to create
legacy contexts, and it required code different from GLX 1.3 even before
creation of the X window (the problem was selections of the X Visual).
That's why there were two functions for window creation (create_window_old
and create_window_gl3). However, the legacy context creation code was
updated to GLX 1.3 in commit b3b20cc, so having different functions for
window creation is not needed anymore.
2013-02-26 02:00:53 +01:00
Stefano Pigozzi e540e5d4da core: add fs-screen option for fullscreen display selection
`--fs-screen` allows to decide what display to go fullscreen into. The
semantics of `--screen` changed and now it is only used to select the windowed
display when starting the application.

This is useful for people using mpv with an external TV. They will start
windowed on their laptop's screen and switch to fullscreen on the TV.

@wm4 worked on the x11 and w32 parts of the code. All is squashed in one
commit for history clarity.
2013-02-21 22:23:08 +01:00
Stefano Pigozzi 41c1749f46 core: move `xineramascreen` to `MPOpts` as `vo_screen_id`
This is a small cleanup in preparation for the next commit.
2013-02-21 22:23:08 +01:00
Stefano Pigozzi 145c965135 cocoa_common: fix crash with dead key input and simplify related code
Fixes #29. When a user used dead input keys (like the accent key), `mpv`
crashed because the code tried to access the 0 element of a characters array
(which was empty).

While I was closing this bug, I refactored some related conditionals to
make the code more readable.
2013-02-19 21:21:50 +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 37c83abe61 cocoa_common: fix `--ontop` behaviour when windowed
Apply setLevel hacks for fullscreen switching with ontop active only in
fullscreen. This keeps the window correctly on top even when losing focus.

Fixes #21

I also reverted NSScreenSaverWindowLevel to NSNormalWindowLevel + 1, so that
the cmd-tab UI is visible
2013-02-03 14:04:13 +01:00
Stefano Pigozzi 530036e5b3 cocoa_common: fix focus with --ontop and space switching
The main problem this commit addresses is when you switched spaced back and
forth with `--ontop` active the video window didn't recive focus again.

Turns out that setting a normal window level just before conceding focus to
other apps / spaces fixes the problem. I think Cocoa is misbehaving here, and
should probably file a radar.

I found 3 related improvements while fixing this:
 *  fullscreen_window_level is a dead body from an older implementation.
 *  Use NSScreenSaverWindowLevel for ontop. This should be a really high window
    level. Definitely higher than NSNormalWindowLevel + 1.
 *  The window level was set correctly only when out of fullscreen.
2013-02-03 11:39:30 +01:00
Stefano Pigozzi ce29e58fe3 cocoa_common: make the resize window menu items use video size
Make the window resizing menu items calculate the new window size based on the
video size and not the current window size.

This only makes a difference when using `--autofit`.
2013-02-03 10:18:55 +01:00