From 166a7de4cf94a78c34040b47a929a72d12f2945f Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 13 Jan 2012 07:38:40 +0100 Subject: input: allow unicode keys and reassign internal key codes 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. --- osdep/getch2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'osdep') diff --git a/osdep/getch2.c b/osdep/getch2.c index 81d13d9d7b..f421bdea7e 100644 --- a/osdep/getch2.c +++ b/osdep/getch2.c @@ -225,7 +225,7 @@ void getch2(struct mp_fifo *fifo) } if ((c == '[' || c == 'O') && getch2_len >= 3) { int c = getch2_buf[2]; - const short ctable[] = { + const int ctable[] = { KEY_UP, KEY_DOWN, KEY_RIGHT, KEY_LEFT, 0, KEY_END, KEY_PGDWN, KEY_HOME, KEY_PGUP, 0, 0, KEY_INS, 0, 0, 0, KEY_F+1, KEY_F+2, KEY_F+3, KEY_F+4}; -- cgit v1.2.3 From 7ea5c4c26c9c47639a1962385d9cacd531ba8466 Mon Sep 17 00:00:00 2001 From: wm4 Date: Fri, 13 Jan 2012 07:59:21 +0100 Subject: input: handle UTF-8 terminal input 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. --- osdep/getch2.c | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'osdep') diff --git a/osdep/getch2.c b/osdep/getch2.c index f421bdea7e..1a92866afd 100644 --- a/osdep/getch2.c +++ b/osdep/getch2.c @@ -57,6 +57,7 @@ #include #include +#include "bstr.h" #include "mp_fifo.h" #include "input/keycodes.h" #include "getch2.h" @@ -201,6 +202,16 @@ void getch2(struct mp_fifo *fifo) len = 2; } code = KEY_ENTER; + } else { + int utf8len = bstr_parse_utf8_code_length(code); + if (utf8len > 0 && utf8len <= getch2_len) { + struct bstr s = { getch2_buf, utf8len }; + int unicode = bstr_decode_utf8(s, NULL); + if (unicode > 0) { + len = utf8len; + code = unicode; + } + } } } else if (getch2_len > 1) { -- cgit v1.2.3 From 24e08eb5f2e54fce46a6ff504276aa8da4bf2fa2 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Wed, 11 Jan 2012 22:29:06 +0100 Subject: macosx_finder_args: use cocoa instead of carbon macosx_finder_args was using Carbon and wasn't usable any longer on modern versions of MacOSX. This is very useful to embed mplayer in a mac application bundle. When using application bundles, the operating system will call the main function with only one argument that identifies the process serial number (this is some additional process identifier in osx other than the pid). File open events are then dispatched to the application through events that must be handled accordingly. --- osdep/macosx_finder_args.c | 128 --------------------------------------------- osdep/macosx_finder_args.h | 8 +-- osdep/macosx_finder_args.m | 83 +++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 132 deletions(-) delete mode 100644 osdep/macosx_finder_args.c create mode 100644 osdep/macosx_finder_args.m (limited to 'osdep') diff --git a/osdep/macosx_finder_args.c b/osdep/macosx_finder_args.c deleted file mode 100644 index 6b5ef321f4..0000000000 --- a/osdep/macosx_finder_args.c +++ /dev/null @@ -1,128 +0,0 @@ -/* - * This file is part of MPlayer. - * - * MPlayer is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * MPlayer is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with MPlayer; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include -#include -#include - -#include "stream/url.h" -#include "mp_msg.h" -#include "m_option.h" -#include "m_config.h" -#include "playtree.h" -#include "macosx_finder_args.h" - -static play_tree_t *files=NULL; - -static inline void add_entry(play_tree_t **last_parentp, play_tree_t **last_entryp, play_tree_t *entry) { - - if(*last_entryp==NULL) - play_tree_set_child(*last_parentp, entry); - else - play_tree_append_entry(*last_entryp, entry); - - *last_entryp=entry; -} - -static pascal OSErr AppleEventHandlerProc(const AppleEvent *theAppleEvent, AppleEvent* reply, SInt32 handlerRefcon) { -OSErr err=errAEEventNotHandled, res=noErr; -AEDescList docList; -long itemsInList; - - AERemoveEventHandler(kCoreEventClass, kAEOpenDocuments, NULL, FALSE); - if((res=AEGetParamDesc(theAppleEvent, keyDirectObject, typeAEList, &docList))==noErr) { - if((res=AECountItems(&docList, &itemsInList))==noErr) { - Size currentSize=0; - int valid=0,i; - char *parm=NULL; - play_tree_t *last_entry=NULL; - - files=play_tree_new(); - for(i=1;i<=itemsInList;++i) { - - for(;;) { - OSErr e; - Size actualSize=0; - AEKeyword keywd; - DescType returnedType; - - if((e=AEGetNthPtr(&docList, i, typeFileURL, &keywd, &returnedType, (Ptr)parm, currentSize, &actualSize))==noErr) { - if(actualSize>=currentSize) { - currentSize=actualSize+1; - parm=realloc(parm, currentSize); - } - else { - parm[actualSize]=0; - valid=1; - break; - } - } - else { - valid=0; - break; - } - } - - if(valid) { - URL_t *url=url_new(parm); - - if(url && !strcmp(url->protocol,"file") && !strcmp(url->hostname,"localhost")) { - play_tree_t *entry=play_tree_new(); - - url_unescape_string(url->file, url->file); - play_tree_add_file(entry, url->file); - add_entry(&files, &last_entry, entry); - } - - url_free(url); - } - } - - free(parm); - - err=noErr; - } - else - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "AECountItems() error %d\n", res); - - AEDisposeDesc(&docList); - } - else - mp_msg(MSGT_CFGPARSER, MSGL_ERR, "AEGetParamDesc() error %d\n", res); - - QuitApplicationEventLoop(); - return err; -} - -play_tree_t *macosx_finder_args(m_config_t *config, int argc, char **argv) { -ProcessSerialNumber myPsn; -char myPsnStr[5+10+1+10+1]; - - GetCurrentProcess(&myPsn); - snprintf(myPsnStr, 5+10+1+10+1, "-psn_%u_%u", myPsn.highLongOfPSN, myPsn.lowLongOfPSN); - myPsnStr[5+10+1+10]=0; - - if((argc==2) && !strcmp(myPsnStr, argv[1])) { - m_config_set_option0(config, "quiet", NULL, false); - InitCursor(); - AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, NewAEEventHandlerUPP(AppleEventHandlerProc), 0, FALSE); - RunApplicationEventLoop(); - } - - return files; -} diff --git a/osdep/macosx_finder_args.h b/osdep/macosx_finder_args.h index 4f06a139a6..1f18931712 100644 --- a/osdep/macosx_finder_args.h +++ b/osdep/macosx_finder_args.h @@ -1,18 +1,18 @@ /* - * This file is part of MPlayer. + * This file is part of mplayer2. * - * MPlayer is free software; you can redistribute it and/or modify + * mplayer2 is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * - * MPlayer is distributed in the hope that it will be useful, + * mplayer2 is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License along - * with MPlayer; if not, write to the Free Software Foundation, Inc., + * with mplayer2; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ diff --git a/osdep/macosx_finder_args.m b/osdep/macosx_finder_args.m new file mode 100644 index 0000000000..cce5acbcc6 --- /dev/null +++ b/osdep/macosx_finder_args.m @@ -0,0 +1,83 @@ +/* + * This file is part of mplayer2. + * + * mplayer2 is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * mplayer2 is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with mplayer2; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#import +#import +#include +#include "macosx_finder_args.h" + +static play_tree_t *files = NULL; + +void macosx_wait_fileopen_events(void); +bool psn_matches_current_process(char *psn_arg_to_check); + +@interface FileOpenDelegate : NSObject +- (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames; +@end + +@implementation FileOpenDelegate +- (void)application:(NSApplication *)sender openFiles:(NSArray *)filenames +{ + files = play_tree_new(); + play_tree_t *last_entry = nil; + for (NSString *filename in filenames) { + play_tree_t *entry = play_tree_new(); + play_tree_add_file(entry, [filename UTF8String]); + + if (last_entry) + play_tree_append_entry(files, entry); + else + play_tree_set_child(files, entry); + + last_entry = entry; + } + [NSApp stop:nil]; // stop the runloop (give back control to mplayer2 code) +} +@end + +void macosx_wait_fileopen_events() +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSApp = [NSApplication sharedApplication]; + [NSApp setDelegate: [[[FileOpenDelegate alloc] init] autorelease]]; + [NSApp run]; // block until we recive the fileopen events + [pool release]; +} + +bool psn_matches_current_process(char *psn_arg_to_check) +{ + ProcessSerialNumber psn; + char psn_arg[5+10+1+10+1]; + + GetCurrentProcess(&psn); + snprintf(psn_arg, 5+10+1+10+1, "-psn_%u_%u", + psn.highLongOfPSN, psn.lowLongOfPSN); + psn_arg[5+10+1+10]=0; + + return strcmp(psn_arg, psn_arg_to_check) == 0; +} + +play_tree_t *macosx_finder_args(m_config_t *config, int argc, char **argv) +{ + if (argc==2 && psn_matches_current_process(argv[1])) { + m_config_set_option0(config, "quiet", NULL, false); + macosx_wait_fileopen_events(); + } + + return files; +} -- cgit v1.2.3 From ae0a38ddf8fe2b0db0dae3c072c322eaaff57dcd Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sun, 18 Mar 2012 16:06:57 +0100 Subject: macosx_finder_args: use a custom logfile instead of system.log Change the macosx_finder_args function so that when mplayer2 is invoked from the Finder in a Mac application bundle, it redirects the output to ~/Library/Logs/mplayer2.log instead of cluttering the global system.log. This doesn't affect terminal use which keeps writing to stdout and stderr. --- osdep/macosx_finder_args.m | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'osdep') diff --git a/osdep/macosx_finder_args.m b/osdep/macosx_finder_args.m index cce5acbcc6..b006f11a79 100644 --- a/osdep/macosx_finder_args.m +++ b/osdep/macosx_finder_args.m @@ -24,6 +24,7 @@ static play_tree_t *files = NULL; void macosx_wait_fileopen_events(void); +void macosx_redirect_output_to_logfile(const char *filename); bool psn_matches_current_process(char *psn_arg_to_check); @interface FileOpenDelegate : NSObject @@ -59,6 +60,16 @@ void macosx_wait_fileopen_events() [pool release]; } +void macosx_redirect_output_to_logfile(const char *filename) +{ + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + NSString *log_path = [NSHomeDirectory() stringByAppendingPathComponent: + [@"Library/Logs/" stringByAppendingFormat:@"%s.log", filename]]; + freopen([log_path fileSystemRepresentation], "a", stdout); + freopen([log_path fileSystemRepresentation], "a", stderr); + [pool release]; +} + bool psn_matches_current_process(char *psn_arg_to_check) { ProcessSerialNumber psn; @@ -75,6 +86,7 @@ bool psn_matches_current_process(char *psn_arg_to_check) play_tree_t *macosx_finder_args(m_config_t *config, int argc, char **argv) { if (argc==2 && psn_matches_current_process(argv[1])) { + macosx_redirect_output_to_logfile("mplayer2"); m_config_set_option0(config, "quiet", NULL, false); macosx_wait_fileopen_events(); } -- cgit v1.2.3