I have a legacy carbon app that used MPRemoteCall to show an assert dialog when something bad happens on the main thread of the app. Sometimes an assert happens in a worker thread that shouldn't be doing UI stuff. However it's deprecated a long time ago and I was wondering what the replacement API is?
Thursday, August 10, 2017
Thursday, April 28, 2016
Register for global file drag events in Cocoa
I'm trying to be notified when a OS X user is dragging any file in OS X, not only in my app.
My current approach was using addGlobalMonitorForEventsMatchingMask:handler: on NSEvent, as follows:
[NSEvent addGlobalMonitorForEventsMatchingMask:NSLeftMouseDraggedMask handler:^(NSEvent* event) { NSPasteboard* pb = [NSPasteboard pasteboardWithName:NSDragPboard]; NSLog(@"%@", [pb propertyListForType:NSFilenamesPboardType]); }]; This works partially - the handler is being called when I start dragging a file from my desktop or Finder, however it also is being called when I perform every other operation that contains a left-mouse-drag, e.g. moving a window. The issue is that the NSDragPboard still seems to contain the latest dragged file URL e.g. when I let off the file and start moving a window, which makes it hard to distinguish between these operations.
TL;DR - I am interested in file drag operations system-wide. I do not need any information about the dragged file itself, just the information that a file drag operation has been started or stopped. I would appreciate any hint to a possible solution for this question.
1 Answers
Answers 1
After having talked to Apple DTS, this is most likely a bug. I have filed rdar://25892115 for this issue. There currently seems to be no way to solve my original question with the given API.
To solve my problem, I am now using the Accessibility API to figure out if the item below the cursor is a file (kAXFilenameAttribute is not NULL).
Saturday, April 9, 2016
bringing up a InputWindow on OSX for text input while typing text with asian laguage
I am working on a text editor written with C++ engine and Qt for UI. I want to allow the user to write with any of the input source ( keyboard of any language ). It was all good till the time I was supporting languages which has 1-1 keyboard mapping ( e.g. French/Russian keyboard ). I had an eventFilter installed on my Qwidget on which I was rendering the text and was capturing the keyboard inputs in QEvent::InputMethod
But when I started up with Asian languages ( like japanese/chinese ) I am not able to support all the features required for text editing with such language, a typical example of such case is the split underline when user writes some text with Japanese( Hiragana IME ) and presses space key which helps user in determining what all characters are to be replaced with the content on prediction dialog.See Image below: :
after struggling a while I figured out that Qt does not provide enough information about the splits or length of the string which is being replaced and I give up the idea to create all these visual appearance myself.
But then I discovered that some of the applications uses some OS specific input method to handle such complex text. An example is the OSX Finder, if we change the input method to Japanese ( Hiragana ) and start typing when a finder window is in focus, it pops up a floating window which accepts all my inputs and passes it to finder. See the image below
I dig more and I figured out that there was such a framework which was available earlier as Text Services Manager with a lot of documentation ( "http://mirror.informatimago.com/next/developer.apple.com/technotes/te/te_27.html#Downloads" ) which could have done this trick very easily for me BUT this API has been deprecated and no more available.
What I am looking for now is an alternative for this deprecated API. Does any body know whether we have a cocoa API which can help me with bringing this operating system input method component for the easy text input.
Any help/suggestions are welcome.
1 Answers
Answers 1
Ok, I found the solution. I was ignorant to say that Qt does not provide enough information about these splits, Qt has a way to provide this support by using the caret position. So to conclude, the information of the text to be displayed can be easily retrieved by:
for( auto value : inEvent->attributes() ) { if( value.type == QInputMethodEvent::Cursor ) { std::cout<<" length "<< value.length; std::cout<<" start "<< value.start; } } here start is the position of the cursor, once this position is clear it is easy to determine how much length of text should be underlined so as to give clear indication to the user.