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. 61
      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,9 +623,11 @@ void UBPlatformUtils::showFullScreen(QWidget *pWidget)
void UBPlatformUtils::showOSK(bool show)
{
if (QOperatingSystemVersion::current().majorVersion() == 10 && QOperatingSystemVersion::current().minorVersion() < 15) /* < Catalina */
{
@autoreleasepool {
CFDictionaryRef properties = (CFDictionaryRef)[NSDictionary
dictionaryWithObject: @"com.apple.KeyboardViewer"
dictionaryWithObject: @"com.apple.keyboardViewer"
forKey: (NSString *)kTISPropertyInputSourceID];
NSArray *sources = (NSArray *)TISCreateInputSourceList(properties, true);
@ -653,4 +656,60 @@ void UBPlatformUtils::showOSK(bool show)
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"];
}
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