Bug 430942 - Rectangular Region mode produces black rectangles with 3 screens
Summary: Rectangular Region mode produces black rectangles with 3 screens
Status: RESOLVED FIXED
Alias: None
Product: Spectacle
Classification: Applications
Component: General (show other bugs)
Version: 20.12.0
Platform: Arch Linux Linux
: NOR critical
Target Milestone: ---
Assignee: Boudhayan Gupta
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-12-29 14:22 UTC by clyde
Modified: 2021-01-20 17:10 UTC (History)
6 users (show)

See Also:
Latest Commit:
Version Fixed In: 20.12.2


Attachments
The left half of my middle screen (54.63 KB, image/png)
2021-01-15 14:20 UTC, brainpower
Details
The whole middle screen (jpg for smaller size) (1.28 MB, image/jpeg)
2021-01-15 14:22 UTC, brainpower
Details
The whole middle screen (jpg for smaller size) (925.93 KB, image/jpeg)
2021-01-15 14:30 UTC, brainpower
Details

Note You need to log in before you can comment on or make changes to this bug.
Description clyde 2020-12-29 14:22:38 UTC
SUMMARY
spectacle-20.12.0-1-x86_64

STEPS TO REPRODUCE
select a rectangular area and take a screenshot it shows a black image

EXPECTED RESULT
bugfix

SOFTWARE/OS VERSIONS
Operating System: EndeavourOS
KDE Plasma Version: 5.20.4
KDE Frameworks Version: 5.77.0
Qt Version: 5.15.2
Kernel Version: 5.9.14
Comment 1 Norbert 2021-01-02 19:23:25 UTC
I've also experienced this one. I think it's related to the multimonitor setup somehow (It works as expected on the leftmost of my screens, but not on the middle one for example)
Comment 2 Nate Graham 2021-01-04 21:52:48 UTC
Works for me.

How many screens do you have? Are you using Wayland?
Comment 3 Norbert 2021-01-04 22:13:30 UTC
3. And no, not using Wayland.
Comment 4 Justin Zobel 2021-01-04 22:20:58 UTC
I also have 3 monitors with Plasma on X11 and I have no issues capturing rectangles.
Comment 5 Nate Graham 2021-01-04 23:51:57 UTC
Thanks for the info. Does it still happen if you disconnect 2 of the screens?
Comment 6 clyde 2021-01-05 08:10:09 UTC
3 screen setup (2x 19" & 1x 15") nvidia GPU not using wayland
it works only w/ single monitor

Operating System: EndeavourOS
KDE Plasma Version: 5.20.4
KDE Frameworks Version: 5.77.0
Qt Version: 5.15.2
Kernel Version: 5.10.4
OS Type: 64-bit
Processors: 8 × AMD FX(tm)-8350 Eight-Core Processor
Memory: 15.6 GiB of RAM
Graphics Processor: GeForce GT 630/PCIe/SSE2

I have downgraded to spectacle-20.08.3-1
Comment 7 Christoph Feck 2021-01-09 17:00:06 UTC
New information was added with comment 6; changing status for inspection.
Comment 8 clyde 2021-01-10 09:51:44 UTC
yesterday I have updated to 20.12.1-1 but it still does not work w/ rectangles, in spectacle-20.12.0-1 it shows a black image in preview and in 20.12.1-1 is no longer a preview available, it does not show a preview area anymore when rectangle mode is used.
Comment 9 brainpower 2021-01-15 14:20:09 UTC
Created attachment 134890 [details]
The left half of my middle screen
Comment 10 brainpower 2021-01-15 14:22:18 UTC
Created attachment 134891 [details]
The whole middle screen (jpg for smaller size)
Comment 11 brainpower 2021-01-15 14:24:47 UTC
This seems like som kind of offset issue.

I've added 2 files, the jpg shows the whole middle screen of mine,
the png shows a selection of the *left* half of the screen,
which should show the background, but it shows the Konsole window instead!

So the content seems moved to the left, by about the amount the leftmost screens width.
Comment 12 brainpower 2021-01-15 14:29:20 UTC
Oh, and the bug only happens with the middle screen.
There is no problem with capturing a rectangle the leftmost or rightmost screen.
Only the capture of the middle screnn is "off" ;)
Comment 13 brainpower 2021-01-15 14:30:56 UTC
Created attachment 134892 [details]
The whole middle screen (jpg for smaller size)

with xrandr output
Comment 14 brainpower 2021-01-15 14:56:49 UTC
Reverting https://invent.kde.org/graphics/spectacle/-/commit/4a3cb5140cc58d73b1f0f0083d7f24f9f3a40b2a 

fixes the issue, so it's something that changed with that commit... which is a lot... :S
Comment 15 brainpower 2021-01-15 16:02:46 UTC
Found the issue:

If I add a few qDebug:

--- a/src/QuickEditor/QuickEditor.cpp
+++ b/src/QuickEditor/QuickEditor.cpp
@@ -116,8 +116,12 @@ QuickEditor::QuickEditor(const QMap<ComparableQPoint, QImage> &images, KWayland:
         input.insert(pos, QPair<qreal, QSize>(screenImage.width() / static_cast<qreal>(screen->size().width()), screenImage.size()));
     }
     const auto pointsTranslationMap = computeCoordinatesAfterScaling(input);
+    qDebug() << "pointsTranslationMap:       " << pointsTranslationMap;
+    qDebug() << "pointsTranslationMap.keys():" << pointsTranslationMap.keys();
     QPainter painter(&mPixmap);
     for (auto it = mImages.constBegin(); it != mImages.constEnd(); it ++) {
+        qDebug() << "it.key() == QPoint(1680,0) ->" << (it.key() == ComparableQPoint(QPoint(1680,0)));
+        qDebug() << "it.key():" << it.key() << "\t translated:" << pointsTranslationMap.value(it.key());
         painter.drawImage(pointsTranslationMap.value(it.key()), it.value());
     }
     painter.end();


I get:

% build/bin/spectacle
pointsTranslationMap:        QMap((QPoint(1680,0), QPoint(1680,0))(QPoint(0,195), QPoint(0,195))(QPoint(4240,0), QPoint(4240,0)))
pointsTranslationMap.keys(): (QPoint(1680,0), QPoint(0,195), QPoint(4240,0))
it.key() == QPoint(1680,0) -> true
it.key(): QPoint(1680,0)         translated: QPoint(0,0)
it.key() == QPoint(1680,0) -> false
it.key(): QPoint(0,195)          translated: QPoint(0,195)
it.key() == QPoint(1680,0) -> false
it.key(): QPoint(4240,0)         translated: QPoint(4240,0)


But it should be 

it.key(): QPoint(1680,0)         translated: QPoint(1680,0)

instad of

it.key(): QPoint(1680,0)         translated: QPoint(0,0)

I have no idea why the QMap::value() returns the defaultValue here instead of the value the key should map to...
it seems to exist correctly in the pointsTranslationMap after all...
Comment 16 brainpower 2021-01-15 16:33:26 UTC
Insertion order seems to matter:

https://invent.kde.org/brainpower/spectacle/-/snippets/1456

So question is: Is this a bug in QMap or wrong usage of QMap?
Comment 17 Bug Janitor Service 2021-01-16 14:50:03 UTC
A possibly relevant merge request was started @ https://invent.kde.org/graphics/spectacle/-/merge_requests/48
Comment 18 Méven Car 2021-01-20 16:51:23 UTC
Git commit e1fc5c40c572e3e827e2488fedae856bd8a2927d by Méven Car, on behalf of Franz Baumgärtner.
Committed on 20/01/2021 at 08:29.
Pushed by meven into branch 'master'.

fix lookup of ComparableQPoint keys in QMap

QMap::value() failed to find existing keys in some edge cases.
Which lead to problems when translating points using a QMap.

This commit improves the operator<() to fix that.

M  +1    -1    src/QuickEditor/ComparableQPoint.h

https://invent.kde.org/graphics/spectacle/commit/e1fc5c40c572e3e827e2488fedae856bd8a2927d
Comment 19 Nate Graham 2021-01-20 17:10:19 UTC
Git commit 2ca0ba662673928598776b65ab5d62ad00c244fd by Nate Graham, on behalf of Franz Baumgärtner.
Committed on 20/01/2021 at 17:10.
Pushed by ngraham into branch 'release/20.12'.

fix lookup of ComparableQPoint keys in QMap

QMap::value() failed to find existing keys in some edge cases.
Which lead to problems when translating points using a QMap.

This commit improves the operator<() to fix that.


(cherry picked from commit e1fc5c40c572e3e827e2488fedae856bd8a2927d)

M  +1    -1    src/QuickEditor/ComparableQPoint.h

https://invent.kde.org/graphics/spectacle/commit/2ca0ba662673928598776b65ab5d62ad00c244fd