mirror of
https://git.jami.net/savoirfairelinux/jami-client-qt.git
synced 2025-09-10 12:03:18 +02:00
avadapter: consider devicePixelRatio and screen layout when sharing screens
Gitlab: #395 Change-Id: Ic34a084fb9dc5a6605e3242ae7823db35e01a0d8
This commit is contained in:
parent
eb2eb786be
commit
2ae9521558
2 changed files with 52 additions and 17 deletions
|
@ -80,6 +80,39 @@ AvAdapter::onVideoContextMenuDeviceItemClicked(const QString& deviceName)
|
|||
lrcInstance_->avModel().switchInputTo(deviceId, getCurrentCallId());
|
||||
}
|
||||
|
||||
// The top left corner of primary screen is (0, 0).
|
||||
// For Qt, QScreen geometry contains x, y location relative to primary screen.
|
||||
// The purpose of the function is to use calculate a boundingRect for virtual desktop
|
||||
// to help screen sharing.
|
||||
const QRect
|
||||
AvAdapter::getAllScreensBoundingRect()
|
||||
{
|
||||
auto screens = QGuiApplication::screens();
|
||||
|
||||
// p0 is for x axis, p1 is for y axis,
|
||||
// points contain values that are the maximum positive and negative domain value
|
||||
QPoint p0(0, 0), p1(0, 0);
|
||||
|
||||
for (auto scr : screens) {
|
||||
auto devicePixelRatio = scr->devicePixelRatio();
|
||||
auto screenRect = scr->geometry();
|
||||
|
||||
if (screenRect.y() < 0 && p1.y() < abs(screenRect.y()))
|
||||
p1.setY(abs(screenRect.y()));
|
||||
else if (screenRect.y() >= 0
|
||||
&& p1.x() < screenRect.y() + screenRect.height() * devicePixelRatio)
|
||||
p1.setX(screenRect.y() + screenRect.height() * devicePixelRatio);
|
||||
|
||||
if (screenRect.x() < 0 && p0.y() < abs(screenRect.x()))
|
||||
p0.setY(abs(screenRect.x()));
|
||||
else if (screenRect.x() >= 0
|
||||
&& p0.x() < screenRect.x() + screenRect.width() * devicePixelRatio)
|
||||
p0.setX(screenRect.x() + screenRect.width() * devicePixelRatio);
|
||||
}
|
||||
|
||||
return QRect(-p0.y(), -p1.y(), p0.y() + p0.x(), p1.y() + p1.x());
|
||||
}
|
||||
|
||||
void
|
||||
AvAdapter::shareEntireScreen(int screenNumber)
|
||||
{
|
||||
|
@ -91,24 +124,22 @@ AvAdapter::shareEntireScreen(int screenNumber)
|
|||
lrcInstance_->avModel().setDisplay(getScreenNumber(),
|
||||
rect.x(),
|
||||
rect.y(),
|
||||
rect.width(),
|
||||
rect.height(),
|
||||
rect.width() * screen->devicePixelRatio(),
|
||||
rect.height() * screen->devicePixelRatio(),
|
||||
getCurrentCallId());
|
||||
}
|
||||
|
||||
void
|
||||
AvAdapter::shareAllScreens()
|
||||
{
|
||||
auto screens = QGuiApplication::screens();
|
||||
const auto arrangementRect = getAllScreensBoundingRect();
|
||||
|
||||
int width = 0, height = 0;
|
||||
for (auto scr : screens) {
|
||||
width += scr->geometry().width();
|
||||
if (height < scr->geometry().height())
|
||||
height = scr->geometry().height();
|
||||
}
|
||||
|
||||
lrcInstance_->avModel().setDisplay(getScreenNumber(), 0, 0, width, height, getCurrentCallId());
|
||||
lrcInstance_->avModel().setDisplay(getScreenNumber(),
|
||||
arrangementRect.x(),
|
||||
arrangementRect.y(),
|
||||
arrangementRect.width(),
|
||||
arrangementRect.height(),
|
||||
getCurrentCallId());
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -142,9 +173,10 @@ AvAdapter::captureAllScreens()
|
|||
|
||||
for (auto scr : screens) {
|
||||
QPixmap pix = scr->grabWindow(0);
|
||||
width += pix.width();
|
||||
if (height < pix.height())
|
||||
height = pix.height();
|
||||
auto devicePixelRatio = scr->devicePixelRatio();
|
||||
width += scr->geometry().width() * devicePixelRatio;
|
||||
if (height < scr->geometry().height() * devicePixelRatio)
|
||||
height = scr->geometry().height() * devicePixelRatio;
|
||||
scrs << pix;
|
||||
}
|
||||
|
||||
|
@ -153,7 +185,7 @@ AvAdapter::captureAllScreens()
|
|||
final.fill(Qt::black);
|
||||
|
||||
for (auto scr : scrs) {
|
||||
painter.drawPixmap(QPoint(currentPoint, 0), scr);
|
||||
painter.drawPixmap(currentPoint, 0, scr.width(), scr.height(), scr);
|
||||
currentPoint += scr.width();
|
||||
}
|
||||
|
||||
|
|
|
@ -70,6 +70,9 @@ protected:
|
|||
Q_INVOKABLE void stopAudioMeter(bool async);
|
||||
|
||||
private:
|
||||
// Get screens arrangement rect relative to primary screen.
|
||||
const QRect getAllScreensBoundingRect();
|
||||
|
||||
// Get current callId from current selected conv id.
|
||||
QString getCurrentCallId();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue