Bug 374009

Summary: Spectacle's Rectangular Region mode loses keyboard focus after alt-tabbing away, switching to another virtual desktop, or previously having entered Application Dashboard, making it hard to escape
Product: [Applications] Spectacle Reporter: Rajinder Yadav <rajindery>
Component: GeneralAssignee: Boudhayan Gupta <me>
Status: RESOLVED FIXED    
Severity: major CC: 4pp4, bugs.kde.org, bugs.kde.org, bugseforuns, fabrice.salvaire, irres.genie, jwringstad, langenhaun, max.blair, msch414, nate, niels, null, Paul.Hancock.17041993, tamius.han, trmdi, xgdgsc, ztchernev
Priority: NOR Keywords: usability
Version: unspecified   
Target Milestone: ---   
Platform: Kubuntu   
OS: Linux   
Latest Commit: Version Fixed In: 19.04.0
Attachments: $ qdbus org.kde.KWin /KWin org.kde.KWin.supportInformation
$ xrandr
$ glxinfo

Description Rajinder Yadav 2016-12-21 22:03:46 UTC
I am using the latest KDE from Kubuntu PPA backports, Plasama 5.8.4

Each time I use Spectacle most often than not my system will hang.

First of all, the experience is really crappy, really odd UX design.

1. Stop darkening the entire screen, the frame is good enough, doing too much increases probability of more bugs! Probably why my system hangs.

2. When I select "Rectangle region", I am forced to click twice? why.

I should be able to click once, drag the mouse to create the rectangle region of the area I want copied.

Right now, when I try to draw a rectangle region there is a lag to get going, once click to start, 2nd click some times doesn't get registered. This is really annoying,

3. Make "On Click" checkout selected by default. It's doesn't make sense when I select to copy an active window I need to make another click for the checkbox before I start. Most people will do it this way, forcing them to make an additional mouse click is just bad UX design.
Comment 1 Rajinder Yadav 2016-12-21 22:06:43 UTC
typo correction: 

3. Make "On Click" checkbox selected by default...
Comment 2 Christoph Feck 2016-12-21 22:12:34 UTC
Please report one ticket per issue. Could you clarify exactly at which point the system hangs?
Comment 3 Rajinder Yadav 2016-12-22 00:19:10 UTC
I believe the problem show up when

1. I have "On Click" checkout selected
2. Area is "Rectangular Region"

When I click on the "Take New Screenshot" button, and then click once, at t his point the screens dimmed, around this period the hang will occur.

The mouse is continue to move, screen remain dimmed. I an unable to click to start area selection. My keyboard stop functioning and I am unable to escape out of capture mode.

I am not sure if it matters that "On Click" checkout is selected, just that last time I was using the tool it was selected.

My suggestion:

* When area is "Rect. Region" selection, doesn't make sense to have option "On click" available.

* When Window under cursor is selected it make sense to click on a window, this should be implicit and not require a "On Click" option.

* Active Window doesn't make sense, the active window will be "Spectable" right and you will be forced to "click on another window", the same as my previous point.

This GUI could be simplified too many conflicting and confusing "needless" options.
Comment 4 Rajinder Yadav 2016-12-22 00:23:03 UTC
typos: checkout should be checkbox
Comment 5 Rajinder Yadav 2016-12-22 17:43:16 UTC
This just happen to me today, not sure if it's a bigger issues with KDE Plasma?

FYI: I have a fresh install of Kubuntu, using the standard Nouveau video driver, using KDE PPA.

Here is a YouTube clip: https://youtu.be/lmWZf5Rvjbc
Comment 6 Michael Schoonmaker 2017-01-31 06:07:04 UTC
This is happening to me too. I'm using the latest version of plasma on Arch Linux. For the past few weeks, anytime I try to take a screenshot with Spectacle, something odd happens. I'm not actually %100 percent sure what is happening, but the taskbar at the bottom of the screen stops responding, and I can't alt-tab to another window. The computer seems to freeze for a minute, and then I am logged out. This happens every time I try to take the screenshot, usually after it actually takes the screenshot and while I am trying to export the image to imgur.
This only happens when I click "Take new screenshot". I can start up spectacle and use the screenshot it takes when it starts up any way I want with no abnormal behavior.
Spectacle 16.12.1-1
KDE Plasma 5.8.5
KDE Frameworks 5.8.0
Comment 7 Bastian Köcher 2017-02-14 08:43:19 UTC
Yeah, I also can confirm this bug with "Rectangle region" screenshots. After pressing the "Tale a New Screenshot" button my system hangs for some seconds and then I am able to create the screenshot. I observed that this bug only occurs on my Laptop with an Intel GPU (modesetting driver). If I use my PC at home with my Nvidia GPU (official Nvidia driver), the bug does not occur.
Comment 8 stheine 2017-06-08 06:44:54 UTC
I can confirm the issue in: Kubuntu 17.04, Plasma 5.9.4, nouveau driver.

It always hangs on the rectangular region screenshot.
Comment 9 Jonathan Ringstad 2017-06-10 21:34:06 UTC
I can confirm that spectacle hangs my system, on manjaro, bumblebee (proprietary nvidia + mesa intel) with kernel 4.4.70, xorg 1.19.3 and spectacle 17.04.1.

Everything becomes unresponsive, even switching to a VT becomes impossible. The mouse still moves, about once every 5-15 seconds. Clicking, dragging, pressing escape or enter does not do anything (I tried all of those + waited a couple of minutes for a reaction)

Using anything other than rectangle select does not hang the system, and even rectangle selection works without crashing the system *sometimes*, but I did not notice any obvious pattern.

Here are the relevant-looking entries from the journalctl log:

Jun 10 23:16:29 vega kdeinit5[896]: D-Bus call: "org.kde.Spectacle" : "/" : "StartAgent" : ()
Jun 10 23:16:29 vega dbus-daemon[859]: Activating service name='org.kde.Spectacle'
Jun 10 23:16:29 vega dbus-daemon[859]: Successfully activated service 'org.kde.Spectacle'
Jun 10 23:16:29 vega spectacle[8168]: WARNING: Cannot find style "org.kde.desktop" - fallback: "/usr/lib/qt/qml/QtQuick/Controls/Styles/Desktop"
Jun 10 23:16:29 vega spectacle[8168]: qrc:/JobDialog.qml:67: TypeError: Cannot read property 'Layout' of null
Jun 10 23:16:29 vega spectacle[8168]: qrc:/JobDialog.qml:66: TypeError: Cannot read property 'Layout' of null
Jun 10 23:16:33 vega kwin_x11[945]: QXcbConnection: XCB error: 3 (BadWindow), sequence: 57866, resource id: 33554646, major code: 10 (UnmapWindow), minor code: 0
Jun 10 23:16:33 vega kwin_x11[945]: QXcbConnection: XCB error: 3 (BadWindow), sequence: 57871, resource id: 33554646, major code: 4 (DestroyWindow), minor code: 0

Hope that helps, and hope this bug can be resolved quickly!
Comment 10 max blair 2017-06-18 00:58:43 UTC
See also: Bug 381232 - spectacle graphic window disappears when I take a New Screenshot.

I am new to spectacle AND Fedora 25 (long time user of Fedora 21 and ksnapshot).
spectacle graphic window appears as expected.
The spectacle graphic window disappears when I take a New Screenshot.
The process is still running in background.

I was experimenting to look for clues.
I brought up spectacle from the command line (using Konsole) and I get the following error printed out: 

[mblair@localhost 05_Business_Development]$ spectacle&
[1] 14352
[mblair@localhost 05_Business_Development]$ QPainter::begin: Paint device returned engine == 0, type: 2
QPixmap::scaled: Pixmap is a null pixmap
QPixmap::scaled: Pixmap is a null pixmap
qrc:///QuickEditor/EditorRoot.qml:75:5: QML Image: Failed to get image from provider: image://snapshot/rawimage
qrc:///QuickEditor/EditorRoot.qml:75:5: QML Image: Failed to get image from provider: image://snapshot/rawimage

In case the video driver is an issue here:

      *-display
           description: VGA compatible controller
           product: G98M [Quadro NVS 160M]
           vendor: NVIDIA Corporation
           physical id: 0
           bus info: pci@0000:01:00.0
           version: a1
           width: 64 bits
           clock: 33MHz
           capabilities: pm msi pciexpress vga_controller bus_master cap_list rom
           configuration: driver=nouveau latency=0
           resources: irq:31 memory:f5000000-f5ffffff memory:e0000000-efffffff

Does this help explain my problem with running spectacle?
Thank you
Comment 11 Christoph Feck 2017-12-20 03:47:09 UTC
*** Bug 386629 has been marked as a duplicate of this bug. ***
Comment 12 Nate Graham 2018-01-29 20:39:24 UTC
Is there anyone who experiences this and does NOT use NVIDIA hardware?
Comment 13 Nate Graham 2018-01-31 05:01:24 UTC
*** Bug 379145 has been marked as a duplicate of this bug. ***
Comment 14 Nate Graham 2018-01-31 05:09:04 UTC
*** Bug 372946 has been marked as a duplicate of this bug. ***
Comment 15 Paul 2018-01-31 05:17:43 UTC
bug 379145 was with AMD hardware on kubuntu 17.04
Comment 16 Nate Graham 2018-01-31 05:19:26 UTC
Thanks, that helps!
Comment 17 Niels van Mourik 2018-05-29 11:20:04 UTC
I'm changing this to CONFIRMED, I've had this issue for the past 6 months.

I am on INTEL hardware, clearly rendering this a cross-vendor bug:

# lspci -k | grep -EA3 'VGA|3D|Display'                                                                 
00:02.0 VGA compatible controller: Intel Corporation Haswell-ULT Integrated Graphics Controller (rev 0b)
        Subsystem: Lenovo Device 220c                                                                   
        Kernel driver in use: i915                                                                      
        Kernel modules: i915                                                                            

# Graphics:  Card: Intel Haswell-ULT Integrated Graphics Controller
             Display Server: x11 (X.Org 1.19.6 ) drivers: intel (unloaded: modesetting,fbdev,vesa)
             Resolution: 1920x1080@60.05hz, 1920x1080@60.00hz, 1920x1080@60.00hz
             OpenGL: renderer: Mesa DRI Intel Haswell Mobile version: 4.5 Mesa 18.0.4
Comment 18 Niels van Mourik 2018-05-29 11:23:39 UTC
I've also noticed that when the crashes start to happen and when I'm really QUICK in noticing, that killing "plasmashell" (using ctrl+alt+esc on the taskbar) breaks the death loop and allows me to still recover. On previous occasions killing "kwin_x11" achieved the same.

But in practice, in most cases this bug causes me to Alt+SysRQ my way out using a disk sync+reboot. This happens multiple times a day.

If someone could assist, I'd love to (somehow) get a BT out of this...
Comment 19 Niels van Mourik 2018-05-29 11:26:47 UTC
# kf5-config -v
Qt: 5.10.0
KDE Frameworks: 5.46.0
kf5-config: 1.0

# plasmashell -v
plasmashell 5.12.5

# kwin_x11 -v
kwin 5.12.5

# spectacle -v
spectacle 18.04.1 - A Dearth of Dank Memes

Kwin is set to "OpenGL 3.1" though 2 gives the issue too.
Comment 20 null 2018-05-31 18:59:18 UTC
I don't think Spectacle is doing anything wrong per se, as it's working fine on a bunch of systems. Still, we might be hitting a code path in Qt, X, or the graphics driver which some systems are unhappy with. (Note that in Spectacle only the fullscreen rectangular selection tool is written in QML, which makes use of OpenGL acceleration.)

It's a bit hard to debug this without being able to reproduce, but at least we can try to narrow down the nature of the problem. Could you record a video of the hang and the events leading to it? As in the comments above "hanging" is associated with multiple different issues, what are you doing exactly in your case? Also, having a look at the memory and CPU usage of all processes on the system during the hang would be great, maybe on a console or via ssh?.

> I'd love to (somehow) get a BT out of this...
Any chance you could start Spectacle through "gdb" and interrupt it with Ctrl-C while the hang occurs? Would GDB's remote debugging help, assuming the network stack is still working?

> killing "plasmashell"
> killing "kwin_x11"
Please try to reproduce running a simpler DE than Plasma, e.g. IceWM or TWM.

> Kwin is set to "OpenGL 3.1" though 2 gives the issue too.
Did you try setting it to "XRender"?

One more thing to check is that you are indeed running only a single Spectacle process (see Bug 386629 I just added some comments to).
Comment 21 Nate Graham 2018-09-13 19:29:41 UTC
*** Bug 398271 has been marked as a duplicate of this bug. ***
Comment 22 Niels van Mourik 2018-09-14 09:29:11 UTC
Over the last 4 months, I have only had 4 occurrences of this issue. Since this is a drastic reduction compared to before that, for a long while I thought it was completely gone. It isn't, but the situation improved.

I'm on Tumbleweed so releases roll quickly, current versions:
qt: 5.11.1
kf5: 5.49.0
kwin: 5.13.5 (X11, OpenGL 2.0 now <-- so this changed)
plasmashell 5.13.5
spectacle: 18.08.1

> I don't think Spectacle ... be hitting a code path in Qt, X, or
> the graphics driver which some systems are unhappy with. (Note that in
> Spectacle only the fullscreen rectangular selection tool is written in QML,
> which makes use of OpenGL acceleration.)
I agree on this, and I'm 100% sure that the rectangular selection tool is triggering or causing this issue. When it happens, I sometimes can't even draw the rectangle anymore, on other occasions I'm drawing the rectangle and the system breaks down. To be clear, drawing rectangles now works much more often than that that it breaks.

> It's a bit hard to debug this without being able to reproduce, but at least
> we can try to narrow down the nature of the problem. Could you record a
> video of the hang and the events leading to it? As in the comments above
> "hanging" is associated with multiple different issues, what are you doing
> exactly in your case? Also, having a look at the memory and CPU usage of
> all processes on the system during the hang would be great, maybe on a
> console or via ssh?.
This one is really hard to catch now that it happens so rarely and randomly. I did notice on one occasion though, that I could recover through Alt+SysRq+f which triggers the kernels OOM killer, suggesting this is memory related. My system has 8G of RAM and no swap partition enabled.

> Any chance you could start Spectacle through "gdb" and interrupt it with
> Ctrl-C while the hang occurs? Would GDB's remote debugging help, assuming
> the network stack is still working?
It happens really fast usually, half a second could be enough to have the entire system frozen beyond repair. It definitely feels that this freeze is GPU-related, since its similar to other issues I had in the past.

Intel Corporation Haswell-ULT Integrated Graphics Controller (rev 0b)
mesa: 18.1.7
kernel module: i915

This makes screenrecording and gdb close to impossible I think. Is it possible to somehow modify Spectacle's .desktop file to have it always go through GDB and log to disk everytime I use it? So that I could identify a faulty backtrace after reboot or Alt+SysRq+f?

> One more thing to check is that you are indeed running only a single
> Spectacle process (see Bug 386629 I just added some comments to).
I can't rule this out, I sometimes make a lot of screenshots and forget that another Spectacle instance is left behind somewhere. The "cannot exit" issue 386629 also feels related.

More evidence needed...
Comment 23 AppAraat 2018-09-24 21:51:19 UTC
Created attachment 115211 [details]
$ qdbus org.kde.KWin /KWin org.kde.KWin.supportInformation
Comment 24 AppAraat 2018-09-24 21:54:30 UTC
(Sorry, didn't mean to just send an attachment like this)

So it seems I can repro this.
Warning: After this you may need to enter into one of the ttys and manually kill Spectacle (killall spectacle)

Steps:
1. Open Spectacle using a shortcut (I invoke it using PrtScn) and in Capture Mode -> Area: Select "Rectangular Region"
2. Press "Take New Screenshot"
3. During the selection dialog ("Click anywhere to start drawing..."), simply Alt+Tab or switch virtual desktops.

Result: The darkened selection dialog stays on the foreground constantly. Desktop Switch OSD is visible when I switch virtual desktops, however, I can't switch to anything other than the spectacle selection dialog. Only solution seems to kill spectacle.

Information:
KDE Neon UE (Plasma 5.13.5, KDE Frameworks 5.50.0, Qt 5.11.1)
Kernel: Linux neon_UE 4.15.0-34-generic #37~16.04.1-Ubuntu SMP Tue Aug 28 10:44:06 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

Intel i7-2640M
16 GB RAM
512GB SSD

Graphics stack:
Intel HD3000
Rendering backend: OpenGL 3.1

You can find more verbose information about my system in the attachments.
Comment 25 AppAraat 2018-09-24 21:55:14 UTC
Created attachment 115212 [details]
$ xrandr
Comment 26 AppAraat 2018-09-24 21:55:40 UTC
Created attachment 115213 [details]
$ glxinfo
Comment 27 Nate Graham 2018-09-24 23:30:50 UTC
Thank you for the detailed information and steps to reproduce, AppArat! I can confirm that on Neon Dev unstable (everything KDE from git master, Qt 5.11.2), if I enter Rectangular Region mode and then Alt-ab to another app, the darkened overlay remains visible. I can also confirm that once this happens, the keyboard shortcuts deactivate, i.e. I can't exit with Esc, Enter or Return. However I can get out of this stuck mode by dragging a selection box and double-clicking inside it. Can you confirm this?
Comment 28 Paul 2018-09-25 03:18:47 UTC
from my memory of the issue occurring that reproduction makes sense as it forces a keyboard context removal, which in turn results in a soft-lock as the window is forced above everything else, but it's in theory behind another window/UI.

Any other circumstance where another window or UI wants to remain on top, or some form of other bug occurs that takes the current context, would also result in this soft-lock. 

And yes, in some cases profusely clicking at the selection can bring back the context and allow you to escape. Later updates improved this a fraction I believe, though I've been out of the linux space for a while due to having a different laptop that's not currently compatible with regular linux... (nvidia 10 series...)
Comment 29 Nate Graham 2018-09-25 03:34:38 UTC
Cool, now that it seems we know what the problem is, I think we can have a go at fixing it. Unfortunately Spectacle's a bit low on developers right now, so if any of you following this ticket would like to have a go at the issue, I'd be happy to offer guidance through the process.

Here's the relevant documentation:
- https://community.kde.org/Get_Involved/development
- https://community.kde.org/Guidelines_and_HOWTOs/Build_from_source
- https://community.kde.org/Infrastructure/Phabricator
Comment 30 AppAraat 2018-09-25 12:04:08 UTC
(In reply to Nate Graham from comment #27)
> However I can get out of this stuck mode by dragging a selection box and double-clicking inside it. Can you confirm this?

Thanks!

Yes, I can confirm this as well.
Comment 31 Nate Graham 2018-10-20 05:07:13 UTC
*** Bug 398389 has been marked as a duplicate of this bug. ***
Comment 32 Nate Graham 2018-10-20 05:14:06 UTC
*** Bug 386629 has been marked as a duplicate of this bug. ***
Comment 33 Nate Graham 2018-10-20 05:14:08 UTC
*** Bug 379145 has been marked as a duplicate of this bug. ***
Comment 34 Nate Graham 2018-10-26 20:11:30 UTC
*** Bug 400339 has been marked as a duplicate of this bug. ***
Comment 35 Nate Graham 2018-10-26 20:12:51 UTC
From Bug 400339, another trivial way to reproduce this: take a delayed rectangular region screenshot, and open the full-screen Application Dashboard during the delay.
Comment 36 Nate Graham 2018-11-27 20:55:54 UTC
*** Bug 401451 has been marked as a duplicate of this bug. ***
Comment 37 Nate Graham 2018-12-17 15:30:49 UTC
Git commit 958fdc0a2532e30e7edfd1ec71f63fd3c87b5d35 by Nate Graham, on behalf of Ambareesh  Balaji.
Committed on 17/12/2018 at 15:30.
Pushed by ngraham into branch 'master'.

Port QML Rectangle cropper to QWidget + QPainter

Summary:
1. Port QML canvas based screenshot cropper to QWidget + QPainter based cropper
2. Fix minor bugs with cropper while porting, like system font not being set for size indicator
3. "Include mouse pointer" setting now blends the cursor into the screenshot right away, letting the user see it while cropping, rather than blending it in after cropping

Before:
{F5830086}
{F5830115}
After:
{F5830100}
{F5830117}
Related: bug 394503

Test Plan: Compare with original cropper and check if I missed something

Reviewers: #spectacle, broulik, ngraham, alexeymin

Reviewed By: #spectacle, broulik, ngraham, alexeymin

Subscribers: alexeymin, kpiwowarski, broulik, sharvey, guotao, ngraham, rkflx, #spectacle

Tags: #spectacle

Differential Revision: https://phabricator.kde.org/D12626

M  +0    -1    src/CMakeLists.txt
M  +3    -3    src/Gui/KSMainWindow.cpp
M  +3    -7    src/PlatformBackends/X11ImageGrabber.cpp
M  +1    -1    src/PlatformBackends/X11ImageGrabber.h
D  +0    -615  src/QuickEditor/EditorRoot.qml
D  +0    -7    src/QuickEditor/QmlResources.qrc
M  +711  -89   src/QuickEditor/QuickEditor.cpp
M  +94   -16   src/QuickEditor/QuickEditor.h
D  +0    -360  src/QuickEditor/SelectionRectangle.qml

https://commits.kde.org/spectacle/958fdc0a2532e30e7edfd1ec71f63fd3c87b5d35