diff options
author | Martin Herkt <lachs0r@srsfckn.biz> | 2016-10-19 19:09:00 +0200 |
---|---|---|
committer | Martin Herkt <lachs0r@srsfckn.biz> | 2016-10-19 19:09:00 +0200 |
commit | 5d74fa7dc0fa1617d1d11b69769423b1387ec785 (patch) | |
tree | 882752015b3500c91b8ab3a4d669696f23feb817 /osdep | |
parent | c226bc7616ab2ae9de6172660e9cf727f07dc374 (diff) | |
parent | a2fa0d0b68ce200598122145254f56ae1adff91e (diff) | |
download | mpv-5d74fa7dc0fa1617d1d11b69769423b1387ec785.tar.bz2 mpv-5d74fa7dc0fa1617d1d11b69769423b1387ec785.tar.xz |
Merge branch 'master' into release/current
Diffstat (limited to 'osdep')
-rw-r--r-- | osdep/atomic.h (renamed from osdep/atomics.h) | 47 | ||||
-rw-r--r-- | osdep/macosx_compat.h | 25 | ||||
-rw-r--r-- | osdep/macosx_events.m | 18 | ||||
-rw-r--r-- | osdep/macosx_versions.h | 8 | ||||
-rw-r--r-- | osdep/main-fn-win.c | 6 | ||||
-rw-r--r-- | osdep/path-win.c | 1 | ||||
-rw-r--r-- | osdep/subprocess-win.c | 2 | ||||
-rw-r--r-- | osdep/terminal-unix.c | 16 | ||||
-rw-r--r-- | osdep/terminal-win.c | 95 |
9 files changed, 147 insertions, 71 deletions
diff --git a/osdep/atomics.h b/osdep/atomic.h index bfcaa38977..9028a504eb 100644 --- a/osdep/atomics.h +++ b/osdep/atomic.h @@ -16,8 +16,8 @@ * License along with mpv. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef MP_ATOMICS_H -#define MP_ATOMICS_H +#ifndef MP_ATOMIC_H +#define MP_ATOMIC_H #include <inttypes.h> #include "config.h" @@ -80,6 +80,49 @@ typedef struct { volatile unsigned long long v; } atomic_ullong; if (!ok_) *(old) = val_; \ ok_; }) +#elif defined(__GNUC__) + +#include <pthread.h> + +extern pthread_mutex_t mp_atomic_mutex; + +#define atomic_load(p) \ + ({ __typeof__(p) p_ = (p); \ + pthread_mutex_lock(&mp_atomic_mutex); \ + __typeof__(p_->v) v = p_->v; \ + pthread_mutex_unlock(&mp_atomic_mutex); \ + v; }) +#define atomic_store(p, val) \ + ({ __typeof__(val) val_ = (val); \ + __typeof__(p) p_ = (p); \ + pthread_mutex_lock(&mp_atomic_mutex); \ + p_->v = val_; \ + pthread_mutex_unlock(&mp_atomic_mutex); }) +#define atomic_fetch_op(a, b, op) \ + ({ __typeof__(a) a_ = (a); \ + __typeof__(b) b_ = (b); \ + pthread_mutex_lock(&mp_atomic_mutex); \ + __typeof__(a_->v) v = a_->v; \ + a_->v = v op b_; \ + pthread_mutex_unlock(&mp_atomic_mutex); \ + v; }) +#define atomic_fetch_add(a, b) atomic_fetch_op(a, b, +) +#define atomic_fetch_and(a, b) atomic_fetch_op(a, b, &) +#define atomic_fetch_or(a, b) atomic_fetch_op(a, b, |) +#define atomic_compare_exchange_strong(p, old, new) \ + ({ __typeof__(p) p_ = (p); \ + __typeof__(old) old_ = (old); \ + __typeof__(new) new_ = (new); \ + pthread_mutex_lock(&mp_atomic_mutex); \ + int res = p_->v == *old_; \ + if (res) { \ + p_->v = new_; \ + } else { \ + *old_ = p_->v; \ + } \ + pthread_mutex_unlock(&mp_atomic_mutex); \ + res; }) + #else # error "this should have been a configuration error, report a bug please" #endif /* no atomics */ diff --git a/osdep/macosx_compat.h b/osdep/macosx_compat.h index 9775529bc6..76308c6f98 100644 --- a/osdep/macosx_compat.h +++ b/osdep/macosx_compat.h @@ -24,6 +24,31 @@ #import <Cocoa/Cocoa.h> #include "osdep/macosx_versions.h" +#if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_12) +typedef NSUInteger NSWindowStyleMask; +static const NSWindowStyleMask NSWindowStyleMaskClosable = NSClosableWindowMask; +static const NSWindowStyleMask NSWindowStyleMaskTitled = NSTitledWindowMask; +static const NSWindowStyleMask NSWindowStyleMaskMiniaturizable = NSMiniaturizableWindowMask; +static const NSWindowStyleMask NSWindowStyleMaskResizable = NSResizableWindowMask; +static const NSWindowStyleMask NSWindowStyleMaskBorderless = NSBorderlessWindowMask; + +static const NSEventType NSEventTypeSystemDefined = NSSystemDefined; +static const NSEventType NSEventTypeKeyDown = NSKeyDown; +static const NSEventType NSEventTypeKeyUp = NSKeyUp; + +static const NSEventMask NSEventMaskKeyDown = NSKeyDownMask; +static const NSEventMask NSEventMaskKeyUp = NSKeyUpMask; + +#if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_10) +typedef NSUInteger NSEventModifierFlags; +#endif + +static const NSEventModifierFlags NSEventModifierFlagShift = NSShiftKeyMask; +static const NSEventModifierFlags NSEventModifierFlagControl = NSControlKeyMask; +static const NSEventModifierFlags NSEventModifierFlagCommand = NSCommandKeyMask; +static const NSEventModifierFlags NSEventModifierFlagOption = NSAlternateKeyMask; +#endif + #if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_8) @interface NSArray (SubscriptingAdditions) - (id)objectAtIndexedSubscript:(NSUInteger)index; diff --git a/osdep/macosx_events.m b/osdep/macosx_events.m index 6090a1937e..6ad22584dc 100644 --- a/osdep/macosx_events.m +++ b/osdep/macosx_events.m @@ -60,8 +60,8 @@ @end -#define NSLeftAlternateKeyMask (0x000020 | NSAlternateKeyMask) -#define NSRightAlternateKeyMask (0x000040 | NSAlternateKeyMask) +#define NSLeftAlternateKeyMask (0x000020 | NSEventModifierFlagOption) +#define NSRightAlternateKeyMask (0x000040 | NSEventModifierFlagOption) static bool LeftAltPressed(int mask) { @@ -163,7 +163,7 @@ static CGEventRef tap_event_callback(CGEventTapProxy proxy, CGEventType type, NSEvent *nse = [NSEvent eventWithCGEvent:event]; - if ([nse type] != NSSystemDefined || [nse subtype] != 8) + if ([nse type] != NSEventTypeSystemDefined || [nse subtype] != 8) // This is not a media key return event; @@ -285,7 +285,7 @@ void cocoa_set_input_context(struct input_ctx *input_context) - (void)startEventMonitor { - [NSEvent addLocalMonitorForEventsMatchingMask:NSKeyDownMask|NSKeyUpMask + [NSEvent addLocalMonitorForEventsMatchingMask:NSEventMaskKeyDown|NSEventMaskKeyUp handler:^(NSEvent *event) { BOOL equivalent = [[NSApp mainMenu] performKeyEquivalent:event]; if (equivalent) { @@ -395,14 +395,14 @@ void cocoa_set_input_context(struct input_ctx *input_context) - (int)mapKeyModifiers:(int)cocoaModifiers { int mask = 0; - if (cocoaModifiers & NSShiftKeyMask) + if (cocoaModifiers & NSEventModifierFlagShift) mask |= MP_KEY_MODIFIER_SHIFT; - if (cocoaModifiers & NSControlKeyMask) + if (cocoaModifiers & NSEventModifierFlagControl) mask |= MP_KEY_MODIFIER_CTRL; if (LeftAltPressed(cocoaModifiers) || (RightAltPressed(cocoaModifiers) && ![self useAltGr])) mask |= MP_KEY_MODIFIER_ALT; - if (cocoaModifiers & NSCommandKeyMask) + if (cocoaModifiers & NSEventModifierFlagCommand) mask |= MP_KEY_MODIFIER_META; return mask; } @@ -410,8 +410,8 @@ void cocoa_set_input_context(struct input_ctx *input_context) - (int)mapTypeModifiers:(NSEventType)type { NSDictionary *map = @{ - @(NSKeyDown) : @(MP_KEY_STATE_DOWN), - @(NSKeyUp) : @(MP_KEY_STATE_UP), + @(NSEventTypeKeyDown) : @(MP_KEY_STATE_DOWN), + @(NSEventTypeKeyUp) : @(MP_KEY_STATE_UP), }; return [map[@(type)] intValue]; } diff --git a/osdep/macosx_versions.h b/osdep/macosx_versions.h index 83bcf5ddd7..f4c49ab4e3 100644 --- a/osdep/macosx_versions.h +++ b/osdep/macosx_versions.h @@ -26,4 +26,12 @@ # define MAC_OS_X_VERSION_10_9 1090 #endif +#if !defined(MAC_OS_X_VERSION_10_10) +# define MAC_OS_X_VERSION_10_10 101000 +#endif + +#if !defined(MAC_OS_X_VERSION_10_12) +# define MAC_OS_X_VERSION_10_12 101200 +#endif + #endif /* MPV_MACOSX_VERSIONS */ diff --git a/osdep/main-fn-win.c b/osdep/main-fn-win.c index 84a77a3903..f003a5502b 100644 --- a/osdep/main-fn-win.c +++ b/osdep/main-fn-win.c @@ -67,8 +67,10 @@ int wmain(int argc, wchar_t *argv[]) // Build mpv's UTF-8 argv, and add the pseudo-GUI profile if necessary if (argv[0]) MP_TARRAY_APPEND(NULL, argv_u8, argv_len, mp_to_utf8(argv_u8, argv[0])); - if (gui) - MP_TARRAY_APPEND(NULL, argv_u8, argv_len, "--profile=pseudo-gui"); + if (gui) { + MP_TARRAY_APPEND(NULL, argv_u8, argv_len, + "--player-operation-mode=pseudo-gui"); + } for (int i = 1; i < argc; i++) MP_TARRAY_APPEND(NULL, argv_u8, argv_len, mp_to_utf8(argv_u8, argv[i])); MP_TARRAY_APPEND(NULL, argv_u8, argv_len, NULL); diff --git a/osdep/path-win.c b/osdep/path-win.c index de7c0936f7..8f289ff83a 100644 --- a/osdep/path-win.c +++ b/osdep/path-win.c @@ -17,7 +17,6 @@ #include <windows.h> #include <shlobj.h> -#include <initguid.h> #include <knownfolders.h> #include <pthread.h> diff --git a/osdep/subprocess-win.c b/osdep/subprocess-win.c index 614cae663f..3ac0c397aa 100644 --- a/osdep/subprocess-win.c +++ b/osdep/subprocess-win.c @@ -21,7 +21,7 @@ #include "osdep/subprocess.h" #include "osdep/io.h" -#include "osdep/atomics.h" +#include "osdep/atomic.h" #include "mpv_talloc.h" #include "common/common.h" diff --git a/osdep/terminal-unix.c b/osdep/terminal-unix.c index e62903055a..9b4e5709cc 100644 --- a/osdep/terminal-unix.c +++ b/osdep/terminal-unix.c @@ -378,7 +378,7 @@ static void quit_request_sighandler(int signum) { do_deactivate_getch2(); - (void)write(death_pipe[1], &(char){0}, 1); + (void)write(death_pipe[1], &(char){1}, 1); } static void *terminal_thread(void *ptr) @@ -397,20 +397,22 @@ static void *terminal_thread(void *ptr) if (fds[1].revents) stdin_ok = getch2(input_ctx); } + char c; + bool quit = read(death_pipe[0], &c, 1) == 1 && c == 1; // Important if we received SIGTERM, rather than regular quit. - struct mp_cmd *cmd = mp_input_parse_cmd(input_ctx, bstr0("quit 4"), ""); - if (cmd) - mp_input_queue_cmd(input_ctx, cmd); + if (quit) { + struct mp_cmd *cmd = mp_input_parse_cmd(input_ctx, bstr0("quit 4"), ""); + if (cmd) + mp_input_queue_cmd(input_ctx, cmd); + } return NULL; } void terminal_setup_getch(struct input_ctx *ictx) { - if (!getch2_enabled) + if (!getch2_enabled || input_ctx) return; - assert(!input_ctx); // already setup - if (mp_make_wakeup_pipe(death_pipe) < 0) return; diff --git a/osdep/terminal-win.c b/osdep/terminal-win.c index cda9e69040..c75fe68761 100644 --- a/osdep/terminal-win.c +++ b/osdep/terminal-win.c @@ -18,10 +18,6 @@ * with mpv. If not, see <http://www.gnu.org/licenses/>. */ -// See http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/WinUI/WindowsUserInterface/UserInput/VirtualKeyCodes.asp -// for additional virtual keycodes - - #include "config.h" #include <fcntl.h> #include <stdio.h> @@ -70,81 +66,82 @@ void terminal_get_size(int *w, int *h) } } -static void read_input(void) +static bool has_input_events(HANDLE h) { - DWORD retval; - HANDLE in = GetStdHandle(STD_INPUT_HANDLE); + DWORD num_events; + if (!GetNumberOfConsoleInputEvents(h, &num_events)) + return false; + return !!num_events; +} - /*check if there are input events*/ - if (!GetNumberOfConsoleInputEvents(in, &retval)) - return; - if (!retval) - return; +static void read_input(HANDLE in) +{ + // Process any input events in the buffer + while (has_input_events(in)) { + INPUT_RECORD event; + if (!ReadConsoleInputW(in, &event, 1, &(DWORD){0})) + break; - /*read all events*/ - INPUT_RECORD eventbuffer[128]; - if (!ReadConsoleInput(in, eventbuffer, MP_ARRAY_SIZE(eventbuffer), &retval)) - return; + // Only key-down events are interesting to us + if (event.EventType != KEY_EVENT) + continue; + KEY_EVENT_RECORD *record = &event.Event.KeyEvent; + if (!record->bKeyDown) + continue; - /*filter out keyevents*/ - for (int i = 0; i < retval; i++) { - switch (eventbuffer[i].EventType) { - case KEY_EVENT: { - KEY_EVENT_RECORD *record = &eventbuffer[i].Event.KeyEvent; + UINT vkey = record->wVirtualKeyCode; + bool ext = record->dwControlKeyState & ENHANCED_KEY; - /*only a pressed key is interesting for us*/ - if (record->bKeyDown) { - UINT vkey = record->wVirtualKeyCode; - bool ext = record->dwControlKeyState & ENHANCED_KEY; + int mods = 0; + if (record->dwControlKeyState & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED)) + mods |= MP_KEY_MODIFIER_ALT; + if (record->dwControlKeyState & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED)) + mods |= MP_KEY_MODIFIER_CTRL; + if (record->dwControlKeyState & SHIFT_PRESSED) + mods |= MP_KEY_MODIFIER_SHIFT; - int mpkey = mp_w32_vkey_to_mpkey(vkey, ext); - if (mpkey) { - mp_input_put_key(input_ctx, mpkey); - } else { - /*only characters should be remaining*/ - int c = record->uChar.UnicodeChar; - if (c > 0) - mp_input_put_key(input_ctx, c); - } - } - break; - } - case MOUSE_EVENT: - case WINDOW_BUFFER_SIZE_EVENT: - case FOCUS_EVENT: - case MENU_EVENT: - default: - break; + int mpkey = mp_w32_vkey_to_mpkey(vkey, ext); + if (mpkey) { + mp_input_put_key(input_ctx, mpkey | mods); + } else { + // Only characters should be remaining + int c = record->uChar.UnicodeChar; + // The ctrl key always produces control characters in the console. + // Shift them back up to regular characters. + if (c > 0 && c < 0x20 && (mods & MP_KEY_MODIFIER_CTRL)) + c += (mods & MP_KEY_MODIFIER_SHIFT) ? 0x40 : 0x60; + if (c >= 0x20) + mp_input_put_key(input_ctx, c | mods); } } - return; } static void *input_thread_fn(void *ptr) { mpthread_set_name("terminal"); - HANDLE in = GetStdHandle(STD_INPUT_HANDLE); + HANDLE in = ptr; HANDLE stuff[2] = {in, death}; while (1) { DWORD r = WaitForMultipleObjects(2, stuff, FALSE, INFINITE); if (r != WAIT_OBJECT_0) break; - read_input(); + read_input(in); } return NULL; } void terminal_setup_getch(struct input_ctx *ictx) { - assert(!running); + if (running) + return; HANDLE in = GetStdHandle(STD_INPUT_HANDLE); if (GetNumberOfConsoleInputEvents(in, &(DWORD){0})) { input_ctx = ictx; - death = CreateEvent(NULL, TRUE, FALSE, NULL); + death = CreateEventW(NULL, TRUE, FALSE, NULL); if (!death) return; - if (pthread_create(&input_thread, NULL, input_thread_fn, NULL)) { + if (pthread_create(&input_thread, NULL, input_thread_fn, in)) { CloseHandle(death); return; } |