From 5a8b0a111760248ef32b6a058038c1a85a311267 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20Fauconnier?= <fc86@outlook.fr>
Date: Thu, 14 Oct 2021 10:18:49 +0200
Subject: [PATCH 1/7] fixed deselect all on autosave

---
 src/board/UBBoardController.cpp   | 2 +-
 src/core/UBPersistenceManager.cpp | 5 +++--
 src/core/UBPersistenceManager.h   | 3 +--
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/board/UBBoardController.cpp b/src/board/UBBoardController.cpp
index 62dcd073..8ba62e58 100644
--- a/src/board/UBBoardController.cpp
+++ b/src/board/UBBoardController.cpp
@@ -2020,7 +2020,7 @@ void UBBoardController::persistCurrentScene(bool isAnAutomaticBackup, bool force
             && (mActiveSceneIndex >= 0) && mActiveSceneIndex != mMovingSceneIndex
             && (mActiveScene->isModified()))
     {
-        UBPersistenceManager::persistenceManager()->persistDocumentScene(selectedDocument(), mActiveScene, mActiveSceneIndex);
+        UBPersistenceManager::persistenceManager()->persistDocumentScene(selectedDocument(), mActiveScene, mActiveSceneIndex, isAnAutomaticBackup);
         updatePage(mActiveSceneIndex);
     }
 }
diff --git a/src/core/UBPersistenceManager.cpp b/src/core/UBPersistenceManager.cpp
index 70a6ceb8..a53342a4 100644
--- a/src/core/UBPersistenceManager.cpp
+++ b/src/core/UBPersistenceManager.cpp
@@ -931,11 +931,12 @@ void UBPersistenceManager::reassignDocProxy(UBDocumentProxy *newDocument, UBDocu
     return mSceneCache.reassignDocProxy(newDocument, oldDocument);
 }
 
-void UBPersistenceManager::persistDocumentScene(UBDocumentProxy* pDocumentProxy, UBGraphicsScene* pScene, const int pSceneIndex)
+void UBPersistenceManager::persistDocumentScene(UBDocumentProxy* pDocumentProxy, UBGraphicsScene* pScene, const int pSceneIndex, bool isAnAutomaticBackup)
 {
     checkIfDocumentRepositoryExists();
 
-    pScene->deselectAllItems();
+    if (!isAnAutomaticBackup)
+        pScene->deselectAllItems();
 
     generatePathIfNeeded(pDocumentProxy);
 
diff --git a/src/core/UBPersistenceManager.h b/src/core/UBPersistenceManager.h
index 93492def..8a1462ce 100644
--- a/src/core/UBPersistenceManager.h
+++ b/src/core/UBPersistenceManager.h
@@ -103,8 +103,7 @@ class UBPersistenceManager : public QObject
 
         virtual void copyDocumentScene(UBDocumentProxy *from, int fromIndex, UBDocumentProxy *to, int toIndex);
 
-        virtual void persistDocumentScene(UBDocumentProxy* pDocumentProxy,
-                UBGraphicsScene* pScene, const int pSceneIndex);
+        virtual void persistDocumentScene(UBDocumentProxy* pDocumentProxy, UBGraphicsScene* pScene, const int pSceneIndex, bool isAnAutomaticBackup = false);
 
         virtual UBGraphicsScene* createDocumentSceneAt(UBDocumentProxy* pDocumentProxy, int index, bool useUndoRedoStack = true);
 

From b43ffa46090a20994a89a2c14c90bf3ad58647ce Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20Fauconnier?= <fc86@outlook.fr>
Date: Thu, 14 Oct 2021 12:43:57 +0200
Subject: [PATCH 2/7] don't call showFullScreen if numscreens == 1 (not even
 sure why showFullScreen would have to be called here...)

---
 src/core/UBDisplayManager.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/core/UBDisplayManager.cpp b/src/core/UBDisplayManager.cpp
index cd9db4ec..f24e9211 100644
--- a/src/core/UBDisplayManager.cpp
+++ b/src/core/UBDisplayManager.cpp
@@ -180,7 +180,7 @@ void UBDisplayManager::setDisplayWidget(QWidget* pDisplayWidget)
         }
         mDisplayWidget = pDisplayWidget;
         mDisplayWidget->setGeometry(mDesktop->screenGeometry(mDisplayScreenIndex));
-        if (UBSettings::settings()->appUseMultiscreen->get().toBool())
+        if (numScreens() > 1 && UBSettings::settings()->appUseMultiscreen->get().toBool())
             UBPlatformUtils::showFullScreen(mDisplayWidget);
     }
 }

From ebae31772373bd7264a32deffc2075ccb2fe2244 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20Fauconnier?= <fc86@outlook.fr>
Date: Thu, 14 Oct 2021 15:50:32 +0200
Subject: [PATCH 3/7] change mode of magnifier on display view too

---
 src/domain/UBGraphicsScene.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/domain/UBGraphicsScene.cpp b/src/domain/UBGraphicsScene.cpp
index 5b5c59e8..0336a63c 100644
--- a/src/domain/UBGraphicsScene.cpp
+++ b/src/domain/UBGraphicsScene.cpp
@@ -2380,6 +2380,9 @@ void UBGraphicsScene::changeMagnifierMode(int mode)
 {
     if(magniferControlViewWidget)
         magniferControlViewWidget->setDrawingMode(mode);
+
+    if(magniferDisplayViewWidget)
+        magniferDisplayViewWidget->setDrawingMode(mode);
 }
 
 void UBGraphicsScene::resizedMagnifier(qreal newPercent)

From ec13aa56dca82d335dbff3291414596ca7bbc1c5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20Fauconnier?= <fc86@outlook.fr>
Date: Tue, 2 Nov 2021 16:40:40 +0100
Subject: [PATCH 4/7] ignore .qmake.stash file

---
 .qmake.stash | 23 -----------------------
 1 file changed, 23 deletions(-)
 delete mode 100644 .qmake.stash

diff --git a/.qmake.stash b/.qmake.stash
deleted file mode 100644
index d6e97efd..00000000
--- a/.qmake.stash
+++ /dev/null
@@ -1,23 +0,0 @@
-QMAKE_CXX.QT_COMPILER_STDCXX = 201402L
-QMAKE_CXX.QMAKE_GCC_MAJOR_VERSION = 9
-QMAKE_CXX.QMAKE_GCC_MINOR_VERSION = 3
-QMAKE_CXX.QMAKE_GCC_PATCH_VERSION = 0
-QMAKE_CXX.COMPILER_MACROS = \
-    QT_COMPILER_STDCXX \
-    QMAKE_GCC_MAJOR_VERSION \
-    QMAKE_GCC_MINOR_VERSION \
-    QMAKE_GCC_PATCH_VERSION
-QMAKE_CXX.INCDIRS = \
-    /usr/include/c++/9 \
-    /usr/include/x86_64-linux-gnu/c++/9 \
-    /usr/include/c++/9/backward \
-    /usr/lib/gcc/x86_64-linux-gnu/9/include \
-    /usr/local/include \
-    /usr/include/x86_64-linux-gnu \
-    /usr/include
-QMAKE_CXX.LIBDIRS = \
-    /usr/lib/gcc/x86_64-linux-gnu/9 \
-    /usr/lib/x86_64-linux-gnu \
-    /usr/lib \
-    /lib/x86_64-linux-gnu \
-    /lib

From 50b1b3af8a4e7a56de51664a7f297ff6bea31890 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20Fauconnier?= <fc86@outlook.fr>
Date: Wed, 3 Nov 2021 10:29:37 +0100
Subject: [PATCH 5/7] don't reload thumbnails every time a thumbnail is added

---
 src/document/UBDocumentContainer.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/document/UBDocumentContainer.cpp b/src/document/UBDocumentContainer.cpp
index 456c37a7..481a415a 100644
--- a/src/document/UBDocumentContainer.cpp
+++ b/src/document/UBDocumentContainer.cpp
@@ -106,7 +106,6 @@ void UBDocumentContainer::addPage(int index)
 void UBDocumentContainer::addPixmapAt(const QPixmap *pix, int index)
 {
     mDocumentThumbs.insert(index, pix);
-    emit documentThumbnailsUpdated(this);
 }
 
 

From d8c9ebf46f6c685139ef74b854c01a33f26897a1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20Fauconnier?= <fc86@outlook.fr>
Date: Wed, 3 Nov 2021 10:30:48 +0100
Subject: [PATCH 6/7] call treeViewSelectionChanged just once

---
 src/document/UBDocumentController.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/document/UBDocumentController.cpp b/src/document/UBDocumentController.cpp
index dffa1be2..fbd1e03c 100644
--- a/src/document/UBDocumentController.cpp
+++ b/src/document/UBDocumentController.cpp
@@ -1548,7 +1548,6 @@ void UBDocumentTreeView::dropEvent(QDropEvent *event)
                 const QPixmap *pix = new QPixmap(thumbTmp);
                 UBDocumentController *ctrl = UBApplication::documentController;
                 ctrl->addPixmapAt(pix, toIndex);
-                ctrl->TreeViewSelectionChanged(ctrl->firstSelectedTreeIndex(), QModelIndex());
             }
 
             QApplication::restoreOverrideCursor();
@@ -1557,6 +1556,8 @@ void UBDocumentTreeView::dropEvent(QDropEvent *event)
             docModel->setHighLighted(QModelIndex());
         }
 
+        UBApplication::documentController->TreeViewSelectionChanged(UBApplication::documentController->firstSelectedTreeIndex(), QModelIndex());
+
     }
     else
     {

From 398e940c3baa086e7839defc6d1e162221043cbf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20Fauconnier?= <fc86@outlook.fr>
Date: Wed, 3 Nov 2021 12:54:01 +0100
Subject: [PATCH 7/7] use new assistive control app when using system virtual
 keyboard on osx >= 10.15

---
 src/document/UBDocumentController.cpp |   2 +-
 src/frameworks/UBPlatformUtils_mac.mm | 101 ++++++++++++++++++++------
 2 files changed, 81 insertions(+), 22 deletions(-)

diff --git a/src/document/UBDocumentController.cpp b/src/document/UBDocumentController.cpp
index dffa1be2..b0f27721 100644
--- a/src/document/UBDocumentController.cpp
+++ b/src/document/UBDocumentController.cpp
@@ -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
diff --git a/src/frameworks/UBPlatformUtils_mac.mm b/src/frameworks/UBPlatformUtils_mac.mm
index ae5c5956..fa43bcb1 100644
--- a/src/frameworks/UBPlatformUtils_mac.mm
+++ b/src/frameworks/UBPlatformUtils_mac.mm
@@ -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);
+            }
         }
     }
 }