use new assistive control app when using system virtual keyboard on osx >= 10.15

preferencesAboutTextFull
Clément Fauconnier 3 years ago
parent ec13aa56dc
commit 398e940c3b
  1. 2
      src/document/UBDocumentController.cpp
  2. 101
      src/frameworks/UBPlatformUtils_mac.mm

@ -664,7 +664,7 @@ QMimeData *UBDocumentTreeModel::mimeData (const QModelIndexList &indexes) const
#if defined(Q_OS_OSX)
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
if (QOperatingSystemVersion::current().minorVersion() < 15) /* < Mojave */
if (QOperatingSystemVersion::current().majorVersion() == 10 && QOperatingSystemVersion::current().minorVersion() < 15) /* <= Mojave */
mimeData->setUrls(urlList);
#endif
#else

@ -31,6 +31,7 @@
#include "core/UBApplication.h"
#include "core/UBSettings.h"
#include "frameworks/UBFileSystemUtils.h"
#include "gui/UBMainWindow.h"
#include <QWidget>
@ -622,35 +623,93 @@ void UBPlatformUtils::showFullScreen(QWidget *pWidget)
void UBPlatformUtils::showOSK(bool show)
{
@autoreleasepool {
CFDictionaryRef properties = (CFDictionaryRef)[NSDictionary
dictionaryWithObject: @"com.apple.KeyboardViewer"
forKey: (NSString *)kTISPropertyInputSourceID];
if (QOperatingSystemVersion::current().majorVersion() == 10 && QOperatingSystemVersion::current().minorVersion() < 15) /* < Catalina */
{
@autoreleasepool {
CFDictionaryRef properties = (CFDictionaryRef)[NSDictionary
dictionaryWithObject: @"com.apple.keyboardViewer"
forKey: (NSString *)kTISPropertyInputSourceID];
NSArray *sources = (NSArray *)TISCreateInputSourceList(properties, true);
NSArray *sources = (NSArray *)TISCreateInputSourceList(properties, true);
if ([sources count] > 0) {
TISInputSourceRef osk = (TISInputSourceRef)[sources objectAtIndex: 0];
if ([sources count] > 0) {
TISInputSourceRef osk = (TISInputSourceRef)[sources objectAtIndex: 0];
OSStatus result;
if (show) {
TISEnableInputSource(osk);
result = TISSelectInputSource(osk);
}
else {
TISDisableInputSource(osk);
result = TISDeselectInputSource(osk);
OSStatus result;
if (show) {
TISEnableInputSource(osk);
result = TISSelectInputSource(osk);
}
else {
TISDisableInputSource(osk);
result = TISDeselectInputSource(osk);
}
if (result == paramErr) {
qWarning() << "Unable to select input source";
UBApplication::showMessage(tr("Unable to activate system on-screen keyboard"));
}
}
if (result == paramErr) {
qWarning() << "Unable to select input source";
UBApplication::showMessage(tr("Unable to activate system on-screen keyboard"));
else {
qWarning() << "System OSK not found";
UBApplication::showMessage(tr("System on-screen keyboard not found"));
}
}
}
else
{
NSString *source =
@"tell application \"System Events\"\n\
if application process \"TextInputMenuAgent\" exists then\n\
tell application process \"TextInputMenuAgent\"\n\
tell menu bar item 1 of menu bar 2\n\
ignoring application responses\n\
click\n\
end ignoring\n\
end tell\n\
end tell\n\
end if\n\
end tell\n\
do shell script \"killall 'System Events'\"\n";
source = [source stringByAppendingString:@"if application \"Assistive Control\" is"];
if (show)
{
source = [source stringByAppendingString:@" not"];
}
else {
qWarning() << "System OSK not found";
UBApplication::showMessage(tr("System on-screen keyboard not found"));
source = [source stringByAppendingString:@" running then\n\
tell application \"System Events\"\n\
tell application process \"TextInputMenuAgent\"\n\
tell menu 1 of menu bar item 1 of menu bar 2\n\
click menu item 2\n\
end tell\n\
end tell\n\
end tell\n\
end if"];
NSAppleScript *script = [[[NSAppleScript alloc] initWithSource:source] autorelease];
NSDictionary *errorInfo = nil;
[script executeAndReturnError:&errorInfo];
if(errorInfo!=nil)
{
NSAlert *alert = [[NSAlert alloc] init];
if (alert != nil)
{
alert.messageText = errorInfo.allValues[0];
[alert runModal];
[alert release];
//restore action state to previous one as it failed
if (show)
UBApplication::mainWindow->actionVirtualKeyboard->setChecked(false);
else
UBApplication::mainWindow->actionVirtualKeyboard->setChecked(true);
}
}
}
}

Loading…
Cancel
Save