Bug 354572

Summary: Applications launch in background when opened from custom keyboard shortcuts
Product: [Plasma] kwin Reporter: Matt Ruffalo <matt.ruffalo>
Component: generalAssignee: KWin default assignee <kwin-bugs-null>
Status: RESOLVED FIXED    
Severity: normal CC: illumilore
Priority: NOR    
Version First Reported In: 5.4.2   
Target Milestone: ---   
Platform: Kubuntu   
OS: Linux   
Latest Commit: Version Fixed/Implemented In:
Sentry Crash Report:

Description Matt Ruffalo 2015-10-29 17:33:55 UTC
When launching applications via custom keyboard shortcuts, the window of a newly-opened application will be placed behind windows that are already open, unless another window from the same application already has focus.

For example, I have Firefox open, and the window has focus since I'm typing this description. If I invoke the custom keyboard shortcut I created to launch Konsole (meta-T), the new Konsole window appears as the bottom window (at least according to the order of windows in the Flip Switch effect).

If a Konsole window has focus, however, opening a new window with meta-T causes the newly-opened window to receive focus as expected.

Reproducible: Always

Steps to Reproduce:
1. Install Kubuntu 15.10 and install all available updates (as of 2015-10-29)
2. Create custom keyboard shortcut to launch Konsole: System Settings -> Shortcuts -> Custom Shortcuts -> New -> Global Shortcut -> Command/URL
3. Assign meta-T as the key combination, "konsole" as the command
4. Apply changes, verify that System Settings window still has focus
5. Press meta-T, verify that Konsole is launched

Actual Results:  
Konsole is launched, its window does not have focus. The new window is placed behind all existing windows if there is insufficient screen space for it.

Expected Results:  
Konsole is launched, its window should be above all others, and its window should have focus. (This is the behavior in Plasma 4.13 in Kubuntu 14.04.)
Comment 1 Thomas Lübking 2015-10-29 17:43:37 UTC
a) what focus prevention stealing level (kcmshell5 kwinoptions)

b) Is this:
> I have Firefox open, and the window has focus
mandatory (because of "If a Konsole window has focus" and I cannot reproduce it)

Ie. does it matter what *has* the focus when invoking the shortcut?
Comment 2 Matt Ruffalo 2015-10-29 17:51:10 UTC
(In reply to Thomas Lübking from comment #1)
> a) what focus prevention stealing level (kcmshell5 kwinoptions)

The default: "Low".

> b) Is this:
> > I have Firefox open, and the window has focus
> mandatory (because of "If a Konsole window has focus" and I cannot reproduce
> it)
> 
> Ie. does it matter what *has* the focus when invoking the shortcut?

Hmm, perhaps this is specific to Konsole. I have similar custom keyboard shortcuts set up for Dolphin, Firefox, and Konsole, but it seems that only Konsole behaves in this way. I could have sworn that it was consistent across all applications, and would have probably filed this bug specifically for Konsole if I had realized that.
Comment 3 Thomas Lübking 2015-10-29 17:53:33 UTC
what happens if you replace "konsole" by "kstart konsole"?
Comment 4 Matt Ruffalo 2015-10-29 17:58:28 UTC
Then I encounter another bug that I haven't yet entered or searched for: that updating the "Command/URL" of a custom keyboard shortcut has no effect :)

System Settings -> Shortcuts -> Custom Shortcuts -> edit my Konsole shortcut to have "kstart konsole" as the "Command/URL", click Apply, verify that the Apply button is now disabled since there are no changes.

Close System Settings, reopen system settings, and view the command/URL of that custom shortcut. It has stayed as "konsole".

I deleted the old keyboard shortcut and recreated it with "kstart konsole", and new Konsole windows now behave as I expect.
Comment 5 Thomas Lübking 2015-10-29 18:07:10 UTC
(In reply to Matt Ruffalo from comment #4)
> Then I encounter another bug that I haven't yet entered or searched for:

Save your time ;-)

https://git.reviewboard.kde.org/r/125769/
https://git.reviewboard.kde.org/r/125630/
https://git.reviewboard.kde.org/r/125607/

> I deleted the old keyboard shortcut and recreated it with "kstart konsole",
> and new Konsole windows now behave as I expect.

Seems krun invokes konsole as binary rather than as service, causing a dated (or no) start time hint (leading KWin to the assumption that you're currently doing sth. different)

I'm not sure why that would happen (or why it doesn't here - I run https://git.reviewboard.kde.org/r/124130/, but doubt that this could *ease* the condition in this case)
Comment 6 Matt Ruffalo 2015-10-29 18:07:32 UTC
Thank you for the suggestion/fix. Has this always been the recommended way to start Konsole via a keyboard shortcut, or is launching via 'kstart' new in Plasma 5?

I ask because I can't be the only person who has set up a similar keyboard shortcut to launch Konsole, and even though it's a small/minor issue, it's the small things that make Plasma 5 seem less polished than it is. Many people are probably still running Kubuntu 14.04; the upcoming 16.04 may be their first exposure to Plasma 5 and it seems worth it to make sure many of these small annoyances are fixed to give a good impression :)
Comment 7 Matt Ruffalo 2015-10-29 18:12:02 UTC
Ah, thank you - I didn't see your comment before posting mine. I am perfectly happy to have keyboard shortcuts that launch Konsole as a service, but the obvious (to me) way of launching the binary works well in KDE 4 but not Plasma 5.

I wonder if this is worth investigating further, and if not, if there is a good way to document this so that others don't attempt to set things up in a way that previously worked but now is slightly annoying.
Comment 8 Thomas Lübking 2015-10-29 18:39:47 UTC
it should not be necessary to invoke kstart - but i've no idea why it is.
=> you'd have to strace kded5 and see what files are opened when running "plain" konsole.

wild guess: run "kbuildsycoca5" from konsole and watch error messages.
Comment 9 Martin Flöser 2016-08-29 11:16:08 UTC
I know that I fixed some issues related to timestamps in KRun and kglobalaccel - though just now I don't find them. Given that I assume it's fixed. If not, please reopen.
Comment 10 Martin Flöser 2016-08-29 11:29:26 UTC
*** Bug 341427 has been marked as a duplicate of this bug. ***