Bug 483687 - [Windows] Canvas shortcuts break when other applications try steal focus or listen to global shortcuts
Summary: [Windows] Canvas shortcuts break when other applications try steal focus or l...
Status: REPORTED
Alias: None
Product: krita
Classification: Applications
Component: Shortcuts and Canvas Input Settings (show other bugs)
Version: 5.2.2
Platform: Microsoft Windows Microsoft Windows
: NOR normal
Target Milestone: ---
Assignee: Krita Bugs
URL:
Keywords:
: 449000 (view as bug list)
Depends on:
Blocks:
 
Reported: 2024-03-15 15:37 UTC by Tyson Tan
Modified: 2024-04-10 06:59 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
Krita tablet event log during the issue (535.24 KB, text/x-log)
2024-04-02 14:05 UTC, Tyson Tan
Details
Video of Krita's canvas shortcut issue (3.84 MB, video/mp4)
2024-04-02 14:20 UTC, Tyson Tan
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tyson Tan 2024-03-15 15:37:39 UTC
SUMMARY
***
Under Windows, Krita loses modifier and mouse click canvas input due to certain apps aggressively stealing focus. User would experience symptoms like "broken shortcuts" and "unable to pick color by pressing down Ctrl", "unable to call popup palette", "unable to move canvas view by middle button". But in fact, this has nothing to do with shortcuts. For example, single key shortcuts like B, E, etc are not affected. Non canvas input shortcuts with modifier (like Ctrl+S for saving document) are not affected.

I found out that this problem has something to do with certain apps aggressively stealing focus -- by them either showing persistent popups, or showing a high priority dialogue that listens to user input in real time, all time. 

If Krita's focus got stolen, I must first close those popups/dialogues, then restart Krita to get the modifiers and mouse clicks working again.
***


STEPS TO REPRODUCE
Here I will use Sogou Pinyin (搜狗拼音输入法) ( https://shurufa.sogou.com/) as example. Sogou Pinyin is a popular Chinese input app. Almost every PC in China have this app as the default input method -- meaning it will always have a toolbar on screen.

Sogou Pinyin steals focus at EITHER of the following situations:
1. Switching from other Input method to Sogou Pinyin;
2. Sogou Pinyin showing a persistent advertisement popup above its toolbar, you must click the X button to close it;
3. Sogou Pinyin's Voice Input dialogue in open (press the "microphone" button on its toolbar).

OBSERVED RESULT
If ANY of the situations above happened, Krita immediately loses its modifier key input and middle/right button input. Restarting Krita alone won't solve the issue. Sogou Pinyin's AD Popups/Voice Input dialogues must be closed before restarting Krita to solve this issue.


SOFTWARE/OS VERSIONS
Windows: Windows 11 23H2

ADDITIONAL INFORMATION
There is a KA forum discussion thread about this issue: https://krita-artists.org/t/if-i-click-away-from-krita-my-shortcuts-break-5-1-1/51977/10 Although I think their understanding was inaccurate. I was unable to reproduce any of their claims about WeChat PC client causing issues.

This issue is a very serious threat to our userbase in China, given how popular Sogou Pinyin is in this region. I began to hear about this around 2022 when Sogou Pinyin was rewritten. Many users were forced away from Krita because of this issue making them unable to use Krita, and no one seemed to know what caused it.

I have reported this issue to Sogou Pinyin. But I doubt they will do anything. 

It is worth mention that every other art apps aren't being affected like Krita. Maybe they have implemented specific workarounds for this issue.

Maybe if Krita can steal focus more aggressively, we can solve this problem.
Comment 1 Tyson Tan 2024-03-15 16:05:24 UTC
Here I will repeat the important points in Chinese, so people can find this bug report easier.

Krita 在 Windows 下面会因为某些其他程序使用激进的手段抢夺窗口焦点而导致 Krita 的画布输入失去修饰键 (Ctrl/Shift/Alt) 和鼠标中键/右键。没有经验的用户体验到的表象是“快捷键失效”、“Ctrl键按下不能拾色”、“无法打开右键弹出面板”、“无法用中键移动画布”等。然而实际上这和快捷键没有关系——单键的快捷键 (如B/E/R/V 等),带修饰键的非画布快捷键 (Ctrl+S 等) 的工作依然是正常的。

以搜狗拼音输入法为例,我的测试发现在以下的任意情况下它会积极地抢夺 Krita 的焦点:
1. 从其他输入法切换到搜狗拼音
2. 显示推广气泡 (在搜狗输入法工具栏上方偶尔出现的单行文字提示,例如推广语音输入、AI写作等功能)
3. 搜狗拼音的语音输入 (麦克风按钮) 点击后打开了语音输入框在实时监听用户输入时

必须将这些气泡、弹窗、对话框全部关闭 (不需要关闭搜狗输入法本身),然后重启 Krita,这样 Krita 的画布快捷键输入才会恢复正常。

我已经将这个问题通过搜狗输入法内建的反馈功能提交给他们了,虽然他们大概率不会做任何事情。

我记得这个问题并不是一直存在的,好象是从 2022 年左右搜狗拼音被重写时才开始陆续发现有人报告这个问题,而且当时貌似很多其他绘画软件也遇到不少奇怪的丢输入的情况。不知道是不是一回事。

虽然有人说微信可能也会导致问题,但是我测试的时候同时打开了QQ、微信、钉钉、B站、网易云音乐、百度网盘、360浏览器等这些常见软件,全部默认设置直接用,它们各自都有推送消息弹窗等,但我并没有遇到任何问题——只有搜狗拼音才会发生问题。
Comment 2 Tyson Tan 2024-04-02 01:05:15 UTC
After more investigation, I discovered some important clues that point to Krita/Qt.

1) Krita 4.2.9 was unaffected by this bug. 
2) The problem started to happen since 4.3.0beta1.
3) I tested this personally, using binaries from KDE Attic: https://download.kde.org/Attic/krita/

Krita 4.3 Release Notes:
https://krita.org/en/release-notes/krita-4-3-release-notes/

Qt version difference:
Krita 4.2.9 uses Qt 5.12.7.
Krita 4.3.0beta1 uses Qt 5.12.8

Qt 5.12.8 Release Notes:
https://www.qt.io/blog/qt-5.12.8-released

Fixed bugs in Qt 5.12.8:
https://bugreports.qt.io/browse/QTBUG-79192?filter=21875
Comment 3 Tyson Tan 2024-04-02 01:29:43 UTC
To add to my discovery in Comment 3:

In my initial report Description and Comment 1 I said I was only able to reproduce the issue with Sogou Pinyin Input Method. This turned out to be inaccurate.

In reality, almost every popular Instant Messaging app in China was affected. This includes: 

1) QQ (the old 9.7.x branch)
2) Dingtalk
3) Weixin

These apps require Chinese ID to register an account, so it's not practical for the Krita team to test them. I will include what triggered the issue in these apps below.
Comment 4 Tyson Tan 2024-04-02 02:23:04 UTC
Tencent QQ (Old branch):
https://im.qq.com/
https://im.qq.com/pcqq/index.shtml
https://dldir1.qq.com/qqfile/qq/PCQQ9.7.22/QQ9.7.22.240318_01.exe

Only the old 9.7.x branch was affected. The recently rewritten 9.9.x branch is unaffected.

The old branch was written in C. The new branch is Electron based.

The Startup and Login sequence of this old QQ will break Krita's canvas shortcuts. Nothing else.
Comment 5 Tyson Tan 2024-04-02 02:26:32 UTC
Dingtalk (钉钉):
https://www.dingtalk.com/
https://page.dingtalk.com/wow/z/dingtalk/simple/ddhomedownload#/

This app seems to be Qt based. It has Qt 5.15.11 libraries in its installation directory.

The Starting up, Login Sequence, New Message Notifications seemed to break Krita's canvas shortcuts.

After turning off all of Dingtalk's global hotkeys, I was unable to reproduce this issue anymore.
Comment 6 Tyson Tan 2024-04-02 02:33:54 UTC
Weixin PC Client (微信 PC 客户端):
https://weixin.qq.com/
https://pc.weixin.qq.com/

Weixin PC Client appears to be Electron based.

The following behaviors break Krita's canvas shortcuts:

1) The Login of Weixin PC Client bringing up its main window above other apps.
2) The chat dialogue has an "Emotion" button. Clicking this icon to open the Emotion GIF list.
3) Clicking "Mini Programs (小程序)" icon on its Left sidebar opens a special dialogue window.
4) Clicking "Channels (视频号)" icon on its Left sidebar opens a special dialogue window.

There is no known workaround for Weixin except avoiding the actions above.
Comment 7 Tyson Tan 2024-04-02 02:39:00 UTC
On another note, I've also discovered a workaround inside Krita.

Whenever Krita lost its Canvas Shortcuts:

1) Click "Choose Workspace" button on the right of Krita's toolbar.
2) Change to another Workspace and back.
3) Krita's Canvas shortcuts is restored temporarily.

However, if the upper mentioned 3rd party apps trigger the issue again, Krita will lose its Canvas Shortcuts again.
Comment 8 Tyson Tan 2024-04-02 02:40:38 UTC
Additionally, when Krita's Canvas Shortcuts are broken:

Mouse wheel Up/Down to Zoom is also broken. 

Possibly because it's also a Canvas Shortcut?
Comment 9 Tyson Tan 2024-04-02 02:52:11 UTC
I also traced back this issue to a Krita-Artist forum post:
https://krita-artists.org/t/4-3-beta-1-certain-keyboard-shortcuts-not-working/7027/9

This user is not Chinese, so this issue is not China specific.

And the post is 4.3.0beta1 related.
Comment 10 Tyson Tan 2024-04-02 02:54:09 UTC
To sum the important new findings up:

1) Something happened between Krita 4.2.9 and 4.3.0beta1 caused this issue.
2) Or maybe something happened between Qt 5.12.7 and 5.12.8 caused it.
3) This is not China specific.
4) Changing Krita's workspace restores Canvas Shortcuts temporarily.

Therefore, I think this is indeed a Krita problem.

Maybe since 4.3.0beta1, Krita 's canvas focus restore mechanism has been broken.
Comment 11 Liang Qi 2024-04-02 07:27:30 UTC
Better to have a minimal example(about the Canvas Shortcuts) to reproduce the bug?

And the steps.
Comment 12 Tyson Tan 2024-04-02 07:33:15 UTC
I can try to record a video with Key stroke visualization, if that's what you mean. I will do it later tonight.
Comment 13 Liang Qi 2024-04-02 07:37:14 UTC
I mean code example if possible, Krita is too huge for a qt dev to recompile when trying a "git bisect".
Comment 14 Tyson Tan 2024-04-02 07:41:01 UTC
I don't think I have the knowledge to do that. Maybe a Krita dev knows how. 

I will first try to investigate this with the Krita devs, and get back to you if what we found was indeed a Qt bug.
Comment 15 Tyson Tan 2024-04-02 12:27:07 UTC
Maybe this bug is related to:
https://bugs.kde.org/show_bug.cgi?id=462768
Comment 16 Tyson Tan 2024-04-02 14:05:16 UTC
Created attachment 168054 [details]
Krita tablet event log during the issue

This tablet event log ended with a suspicious message:

WARNING: modifiers state became inconsistent! Trying to fix that...
     inputEvent->modifiers() = QFlags<Qt::KeyboardModifier>(NoModifier)
     d->matcher.debugPressedKeys() = QVector(Qt::Key_Shift, Qt::Key_Control, Qt::Key_T, Qt::Key_F22)

It has "modifiers state inconsistant" and the repeatedly reported "F22" key like many other users reported.
Comment 17 Tyson Tan 2024-04-02 14:20:01 UTC
Created attachment 168055 [details]
Video of Krita's canvas shortcut issue
Comment 18 Tyson Tan 2024-04-10 06:59:18 UTC
*** Bug 449000 has been marked as a duplicate of this bug. ***