diff --git a/src/cpp/include/nodegui/QtGui/QScreen/qscreen_wrap.h b/src/cpp/include/nodegui/QtGui/QScreen/qscreen_wrap.h index a26898fb7..c8ddd02bc 100644 --- a/src/cpp/include/nodegui/QtGui/QScreen/qscreen_wrap.h +++ b/src/cpp/include/nodegui/QtGui/QScreen/qscreen_wrap.h @@ -30,4 +30,5 @@ class DLL_EXPORT QScreenWrap : public Napi::ObjectWrap, virtual void connectSignalsToEventEmitter(); // Wrapped methods + Napi::Value grabWindow(const Napi::CallbackInfo& info); }; diff --git a/src/cpp/include/nodegui/QtWidgets/QWidget/qwidget_macro.h b/src/cpp/include/nodegui/QtWidgets/QWidget/qwidget_macro.h index 41cad884f..c4edc7dcd 100644 --- a/src/cpp/include/nodegui/QtWidgets/QWidget/qwidget_macro.h +++ b/src/cpp/include/nodegui/QtWidgets/QWidget/qwidget_macro.h @@ -562,8 +562,8 @@ } \ Napi::Value winId(const Napi::CallbackInfo& info) { \ Napi::Env env = info.Env(); \ - int result = this->instance->winId(); \ - return Napi::Number::New(env, result); \ + WId result = this->instance->winId(); \ + return Napi::BigInt::New(env, static_cast(result)); \ } #endif // QWIDGET_WRAPPED_METHODS_DECLARATION diff --git a/src/cpp/lib/QtGui/QScreen/qscreen_wrap.cpp b/src/cpp/lib/QtGui/QScreen/qscreen_wrap.cpp index 0fcbcbd7a..24ef717b7 100644 --- a/src/cpp/lib/QtGui/QScreen/qscreen_wrap.cpp +++ b/src/cpp/lib/QtGui/QScreen/qscreen_wrap.cpp @@ -3,6 +3,7 @@ #include "Extras/Utils/nutils.h" #include "QtCore/QRect/qrect_wrap.h" #include "QtCore/QSizeF/qsizef_wrap.h" +#include "QtGui/QPixmap/qpixmap_wrap.h" Napi::FunctionReference QScreenWrap::constructor; @@ -11,7 +12,7 @@ Napi::Object QScreenWrap::init(Napi::Env env, Napi::Object exports) { char CLASSNAME[] = "QScreen"; Napi::Function func = DefineClass(env, CLASSNAME, - {// InstanceMethod("clear", &QScreenWrap::clear), + {InstanceMethod("grabWindow", &QScreenWrap::grabWindow), QOBJECT_WRAPPED_METHODS_EXPORT_DEFINE(QScreenWrap)}); constructor = Napi::Persistent(func); exports.Set(CLASSNAME, func); @@ -128,3 +129,18 @@ void QScreenWrap::connectSignalsToEventEmitter() { {Napi::String::New(env, "virtualGeometryChanged"), instance}); }); } + +Napi::Value QScreenWrap::grabWindow(const Napi::CallbackInfo& info) { + Napi::Env env = info.Env(); + bool lossless = false; + WId winId = + static_cast(info[0].As().Uint64Value(&lossless)); + int x = info[1].As().Int32Value(); + int y = info[2].As().Int32Value(); + int width = info[3].As().Int32Value(); + int height = info[4].As().Int32Value(); + QPixmap pixmap = this->instance->grabWindow(winId, x, y, width, height); + auto instance = QPixmapWrap::constructor.New( + {Napi::External::New(env, new QPixmap(pixmap))}); + return instance; +} diff --git a/src/lib/QtGui/QScreen.ts b/src/lib/QtGui/QScreen.ts index dc908bc9c..39f3611ba 100644 --- a/src/lib/QtGui/QScreen.ts +++ b/src/lib/QtGui/QScreen.ts @@ -5,6 +5,7 @@ import { QRect } from '../QtCore/QRect'; import { QSizeF } from '../QtCore/QSizeF'; import { QSize } from '../QtCore/QSize'; import { wrapperCache } from '../core/WrapperCache'; +import { QPixmap } from './QPixmap'; export class QScreen extends NodeObject { native: NativeElement; @@ -38,6 +39,9 @@ export class QScreen extends NodeObject { geometry(): QRect { return QRect.fromQVariant(this.property('geometry')); } + grabWindow(window: number, x = 0, y = 0, width = -1, height = -1): QPixmap { + return new QPixmap(this.native.grabWindow(window, x, y, width, height)); + } logicalDotsPerInch(): number { return this.property('logicalDotsPerInch').toDouble(); }