Skip to content

Commit

Permalink
Misc: Qt6
Browse files Browse the repository at this point in the history
  • Loading branch information
univrsal committed Aug 26, 2022
1 parent 475cea6 commit 9c63a49
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/scrab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* licensed under the GPL v2.0
* github.com/univrsal/scrab
*/
#include "plugin-macros.generated.h"
#include "screenshot/screenshotgrabber.hpp"
#include <QDate>
#include <QDir>
Expand All @@ -19,6 +20,7 @@ OBS_MODULE_USE_DEFAULT_LOCALE("scrab", "en-US")
#define S_HOTKEY_RECAPTURE "scrab.hotkey.recapture"
#define S_CONTINOUS_MODE "continous"
#define S_PICTURE_FOLDER "image_folder"
#define S_PRIMARY_SCREEN "primary_screen"

#define T_(t) obs_module_text(t)
#define T_HOTKEY_CAPTURE_DESC T_("scrab.hotkey.capture.description")
Expand Down Expand Up @@ -77,6 +79,7 @@ void setup_config()
config_t* cfg = obs_frontend_get_global_config();
config_set_default_string(cfg, "scrab", S_PICTURE_FOLDER,
qt_to_utf8(QDir::homePath()));
config_set_default_int(cfg, "scrab", S_PRIMARY_SCREEN, -1);
config_set_default_int(cfg, "scrab", "x", 0);
config_set_default_int(cfg, "scrab", "y", 0);
config_set_default_int(cfg, "scrab", "w", 0);
Expand Down Expand Up @@ -206,6 +209,7 @@ void scrab_save(obs_data_t* save_data, bool saving, void* unused)

bool obs_module_load()
{
blog(LOG_INFO, "[%s] Loading v%s", PLUGIN_NAME, PLUGIN_VERSION);
setup_config();
capture_key = obs_hotkey_register_frontend(S_HOTKEY_CAPTURE, T_HOTKEY_CAPTURE_DESC,
capture_key_callback, nullptr);
Expand Down
14 changes: 9 additions & 5 deletions src/screenshot/screenshotgrabber.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

#include <QApplication>
#include <QDebug>
#include <QDesktopWidget>
#include <QGraphicsPixmapItem>
#include <QGraphicsRectItem>
#include <QGraphicsSceneMouseEvent>
Expand All @@ -34,12 +33,13 @@
#include <QTimer>
#include <obs-frontend-api.h>
#include <obs-module.h>
#include <util/config-file.h>

ScreenshotGrabber::ScreenshotGrabber(screenshot_callback_t* callback)
: QObject()
, mKeysBlocked(false)
, scene(nullptr)
, mcallback(callback)
, scene(nullptr)
{
window = new QGraphicsView(scene); // Top-level widget
window->setWindowFlags(Qt::FramelessWindowHint | Qt::BypassWindowManagerHint);
Expand All @@ -57,8 +57,8 @@ ScreenshotGrabber::ScreenshotGrabber(screenshot_callback_t* callback,
QRect& rect)
: QObject()
, mKeysBlocked(false)
, scene(nullptr)
, mcallback(callback)
, scene(nullptr)
, window(nullptr)
{
screenGrab = grabScreen();
Expand Down Expand Up @@ -228,12 +228,16 @@ void ScreenshotGrabber::reject()

QPixmap ScreenshotGrabber::grabScreen()
{
auto screen_id = config_get_int(obs_frontend_get_global_config(), "scrab", "primary_screen");
QPixmap map {};
QScreen* screen = QGuiApplication::primaryScreen();
if (screen_id >= 0 && screen_id < QGuiApplication::screens().length())
screen = QGuiApplication::screens().at(screen_id);
QRect rec = screen->virtualGeometry();

// Multiply by devicePixelRatio to get actual desktop size
return screen->grabWindow(QApplication::desktop()->winId(), rec.x() * pixRatio,
return screen->grabWindow(0, rec.x() * pixRatio,
rec.y() * pixRatio, rec.width() * pixRatio, rec.height() * pixRatio);
return map;
}

void ScreenshotGrabber::beginRectChooser(QGraphicsSceneMouseEvent* event)
Expand Down

0 comments on commit 9c63a49

Please sign in to comment.