diff options
| author | luigi1111 <luigi1111w@gmail.com> | 2021-01-20 22:40:14 -0500 |
|---|---|---|
| committer | luigi1111 <luigi1111w@gmail.com> | 2021-01-20 22:40:14 -0500 |
| commit | ec7bc577d69efbef1056b0f04320b0fa853b1e84 (patch) | |
| tree | e713121e3c8f7d330af6bef0b1dcfeabad8323c9 /src/qt | |
| parent | 3f4de99be457255a323f6be5e3be9ffdb93d304d (diff) | |
| parent | e9b894da1601473eca7706acdb2f8cbb8a7fb12b (diff) | |
| download | monzero-gui-ec7bc577d69efbef1056b0f04320b0fa853b1e84.tar.gz monzero-gui-ec7bc577d69efbef1056b0f04320b0fa853b1e84.tar.xz monzero-gui-ec7bc577d69efbef1056b0f04320b0fa853b1e84.zip | |
Merge pull request #3292
e9b894d Transfer: implement 'Grab QR code from screen' functionality (xiphon)
Diffstat (limited to 'src/qt')
| -rw-r--r-- | src/qt/macoshelper.h | 3 | ||||
| -rw-r--r-- | src/qt/macoshelper.mm | 39 |
2 files changed, 42 insertions, 0 deletions
diff --git a/src/qt/macoshelper.h b/src/qt/macoshelper.h index e8dabfbe..c8e86b05 100644 --- a/src/qt/macoshelper.h +++ b/src/qt/macoshelper.h @@ -29,6 +29,8 @@ #ifndef MACOSHELPER_H #define MACOSHELPER_H +#include <QPixmap> + class MacOSHelper { MacOSHelper() {} @@ -36,6 +38,7 @@ class MacOSHelper public: static bool isCapsLock(); static bool openFolderAndSelectItem(const QUrl &path); + static QPixmap screenshot(); static QString bundlePath(); }; diff --git a/src/qt/macoshelper.mm b/src/qt/macoshelper.mm index 8f7b4b0f..1d3b812a 100644 --- a/src/qt/macoshelper.mm +++ b/src/qt/macoshelper.mm @@ -26,6 +26,8 @@ // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +#include <unordered_set> + #include <QtCore> #include <QtGui> #include <QtMac> @@ -37,6 +39,8 @@ #include <ApplicationServices/ApplicationServices.h> #include <Availability.h> +#include "ScopeGuard.h" + bool MacOSHelper::isCapsLock() { #ifdef __MAC_10_12 @@ -56,6 +60,41 @@ bool MacOSHelper::openFolderAndSelectItem(const QUrl &path) return true; } +QPixmap MacOSHelper::screenshot() +{ + std::unordered_set<uintptr_t> appWindowIds; + for (NSWindow *window in [NSApp windows]) + { + appWindowIds.insert((uintptr_t)[window windowNumber]); + } + + CFArrayRef onScreenWindows = CGWindowListCreate(kCGWindowListOptionOnScreenOnly, kCGNullWindowID); + const auto onScreenWindowsClenaup = sg::make_scope_guard([&onScreenWindows]() { + CFRelease(onScreenWindows); + }); + + CFMutableArrayRef foreignWindows = CFArrayCreateMutable(NULL, CFArrayGetCount(onScreenWindows), NULL); + const auto foreignWindowsClenaup = sg::make_scope_guard([&foreignWindows]() { + CFRelease(foreignWindows); + }); + + for (CFIndex index = 0, count = CFArrayGetCount(onScreenWindows); index < count; ++index) + { + const uintptr_t windowId = reinterpret_cast<const uintptr_t>(CFArrayGetValueAtIndex(onScreenWindows, index)); + if (appWindowIds.find(windowId) == appWindowIds.end()) + { + CFArrayAppendValue(foreignWindows, reinterpret_cast<const void *>(windowId)); + } + } + + CGImageRef image = CGWindowListCreateImageFromArray(CGRectInfinite, foreignWindows, kCGWindowListOptionAll); + const auto imageClenaup = sg::make_scope_guard([&image]() { + CFRelease(image); + }); + + return QtMac::fromCGImageRef(image); +} + QString MacOSHelper::bundlePath() { NSBundle *main = [NSBundle mainBundle]; |
