Browse Source

Fix - MacOS capture area, full screen mode, system tray area, etc

Yuriy Puchkov 4 years ago
parent
commit
293525f5b6
4 changed files with 39 additions and 7 deletions
  1. 3 0
      .gitignore
  2. 7 1
      src/core/controller.cpp
  3. 14 2
      src/utils/screengrabber.cpp
  4. 15 4
      src/widgets/capture/capturewidget.cpp

+ 3 - 0
.gitignore

@@ -63,4 +63,7 @@ data/flatpak/.flatpak-builder
 .idea/
 .run
 
+# MacOS
+.DS_Store
+
 # End of https://www.gitignore.io/api/snapcraft

+ 7 - 1
src/core/controller.cpp

@@ -150,9 +150,12 @@ void Controller::startVisualCapture(const uint id,
 
 #ifdef Q_OS_WIN
         m_captureWindow->show();
+#elif (defined(Q_OS_MAC) || defined(Q_OS_MAC64) || defined(Q_OS_MACOS) ||      \
+       defined(Q_OS_MACX))
+        m_captureWindow->show();
+        m_captureWindow->activateWindow();
 #else
         m_captureWindow->showFullScreen();
-        // m_captureWindow->show(); // Debug
 #endif
     } else {
         emit captureFailed(id);
@@ -250,12 +253,15 @@ void Controller::enableTrayIcon()
       QIcon::fromTheme("flameshot-tray", QIcon(":img/app/flameshot.png"));
     m_trayIcon->setIcon(trayicon);
 
+#if not(defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(Q_OS_MAC64) ||       \
+        defined(Q_OS_MACOS) || defined(Q_OS_MACX))
     auto trayIconActivated = [this](QSystemTrayIcon::ActivationReason r) {
         if (r == QSystemTrayIcon::Trigger) {
             startVisualCapture();
         }
     };
     connect(m_trayIcon, &QSystemTrayIcon::activated, this, trayIconActivated);
+#endif
 
 #ifdef Q_OS_WIN
     // Ensure proper removal of tray icon when program quits on Windows.

+ 14 - 2
src/utils/screengrabber.cpp

@@ -37,7 +37,18 @@ ScreenGrabber::ScreenGrabber(QObject* parent)
 QPixmap ScreenGrabber::grabEntireDesktop(bool& ok)
 {
     ok = true;
-#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
+#if (defined(Q_OS_MAC) || defined(Q_OS_MAC64) || defined(Q_OS_MACOS) ||        \
+     defined(Q_OS_MACX))
+    QScreen* currentScreen = QGuiApplication::screenAt(QCursor::pos());
+    QPixmap screenPixmap(
+      currentScreen->grabWindow(QApplication::desktop()->winId(),
+                                currentScreen->geometry().x(),
+                                currentScreen->geometry().y(),
+                                currentScreen->geometry().width(),
+                                currentScreen->geometry().height()));
+    screenPixmap.setDevicePixelRatio(currentScreen->devicePixelRatio());
+    return screenPixmap;
+#elif defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
     if (m_info.waylandDectected()) {
         QPixmap res;
         // handle screenshot based on DE
@@ -87,7 +98,7 @@ QPixmap ScreenGrabber::grabEntireDesktop(bool& ok)
         return res;
     }
 #endif
-
+#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX) || defined(Q_OS_WIN)
     QRect geometry;
     for (QScreen* const screen : QGuiApplication::screens()) {
         QRect scrRect = screen->geometry();
@@ -106,6 +117,7 @@ QPixmap ScreenGrabber::grabEntireDesktop(bool& ok)
     QScreen* screen = QApplication::screens()[screenNumber];
     p.setDevicePixelRatio(screen->devicePixelRatio());
     return p;
+#endif
 }
 
 QPixmap ScreenGrabber::grabScreen(int screenNumber, bool& ok)

+ 15 - 4
src/widgets/capture/capturewidget.cpp

@@ -85,7 +85,8 @@ CaptureWidget::CaptureWidget(const uint id,
     initContext(savePath, fullScreen);
     initShortcuts();
     m_context.circleCount = 1;
-#ifdef Q_OS_WIN
+#if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(Q_OS_MAC64) ||          \
+     defined(Q_OS_MACOS) || defined(Q_OS_MACX))
     // Top left of the whole set of screens
     QPoint topLeft(0, 0);
 #endif
@@ -99,7 +100,7 @@ CaptureWidget::CaptureWidget(const uint id,
         }
         m_context.origScreenshot = m_context.screenshot;
 
-#ifdef Q_OS_WIN
+#if defined(Q_OS_WIN)
         setWindowFlags(Qt::WindowStaysOnTopHint | Qt::FramelessWindowHint |
                        Qt::Popup);
 
@@ -111,11 +112,21 @@ CaptureWidget::CaptureWidget(const uint id,
             }
         }
         move(topLeft);
+        resize(pixmap().size());
+#elif (defined(Q_OS_MAC) || defined(Q_OS_MAC64) || defined(Q_OS_MACOS) ||      \
+       defined(Q_OS_MACX))
+        setWindowFlags(Qt::WindowStaysOnTopHint | Qt::BypassWindowManagerHint |
+                       Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint |
+                       Qt::ToolTip | Qt::Popup);
+
+        QScreen* currentScreen = QGuiApplication::screenAt(QCursor::pos());
+        move(currentScreen->geometry().x(), currentScreen->geometry().y());
+        resize(currentScreen->size());
 #else
         setWindowFlags(Qt::BypassWindowManagerHint | Qt::WindowStaysOnTopHint |
                        Qt::FramelessWindowHint | Qt::Tool);
-#endif
         resize(pixmap().size());
+#endif
     }
     // Create buttons
     m_buttonHandler = new ButtonHandler(this);
@@ -126,7 +137,7 @@ CaptureWidget::CaptureWidget(const uint id,
             QRect r = screen->geometry();
             r.moveTo(r.x() / screen->devicePixelRatio(),
                      r.y() / screen->devicePixelRatio());
-#ifdef Q_OS_WIN
+#if defined(Q_OS_WIN)
             r.moveTo(r.topLeft() - topLeft);
 #endif
             areas.append(r);