Author Topic: Focus moves away from editor on Linux edition  (Read 3589 times)

MrPolite

  • Community Member
  • Posts: 10
  • Hero Points: 0
Focus moves away from editor on Linux edition
« on: April 25, 2018, 09:33:52 PM »
Hello,
This has been extremely frustrating for me and I can't find a setting to control it.  ::)If I switch away from SlickEdit to another program on linux, and then switch back to SlickEdit, the focus moves away from the code editor to the project dialogue. Each time I switch back I have to click on the editor again or press Escape to bring the focus back to the editor. Is there any way to fix this?

Graeme

  • Senior Community Member
  • Posts: 2793
  • Hero Points: 347
Re: Focus moves away from editor on Linux edition
« Reply #1 on: April 26, 2018, 05:09:25 AM »
What version of SlickEdit and what OS.

[edit] oh, Linux, ok.  What version of slick?

Dan

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 2896
  • Hero Points: 153
Re: Focus moves away from editor on Linux edition
« Reply #2 on: April 26, 2018, 03:03:49 PM »
Also what flavor of Linux?

Are you switching apps using Alt+Tab?

MrPolite

  • Community Member
  • Posts: 10
  • Hero Points: 0
Re: Focus moves away from editor on Linux edition
« Reply #3 on: April 26, 2018, 08:49:32 PM »
Hi guys,
Slick Edit version:    SlickEdit Pro 2016 (v21.0.2.0 64bit)
Linux version:          Debian 4.9.82-1

Yea I'm switching using Alt + Tab

Graeme

  • Senior Community Member
  • Posts: 2793
  • Hero Points: 347
Re: Focus moves away from editor on Linux edition
« Reply #4 on: April 28, 2018, 12:08:37 AM »
You could try this - it seems to work on Windows.  Put it in a macro file and load it using the load module command on the macro menu.

Code: [Select]
#include "slick.sh"

#pragma option(strictsemicolons,on)
#pragma option(strict,on)
#pragma option(autodecl,off)
#pragma option(strictparens,on)


void _actapp_fix_focus(_str gettingFocus='')
{
   if (!gettingFocus)
      return;

   if ( !_no_child_windows() ) {
      p_window_id = _mdi.p_child;
      _set_focus();
   }
}



MrPolite

  • Community Member
  • Posts: 10
  • Hero Points: 0
Re: Focus moves away from editor on Linux edition
« Reply #5 on: May 01, 2018, 10:39:27 PM »
Thanks! didn't make a difference in this case... anyways narrowed it down a big: it seems to be a bug that's only present when the Projects (and presumably) other toolbar windows are undocked/floating. If I dock the toolbar back to the main window or close it the focus issue is gone

SimonHF

  • Community Member
  • Posts: 43
  • Hero Points: 0
Re: Focus moves away from editor on Linux edition
« Reply #6 on: December 02, 2020, 12:57:20 AM »
I have a similar issue on Linux but symptoms are a little different:

SlickEdit version: SlickEdit Pro 2019 (v24.0.0.8 64-bit)
OS: Linux
OS Version: Ubuntu 19.10
Kernel Level: 5.3.0-64-generic
Build Version: #58-Ubuntu SMP Fri Jul 10 19:33:51 UTC 2020
Processor Architecture: x86_64

If I type in e.g. 'vs foo.txt' to edit a new file or bring an existing file into focus, then it gets loaded as expected in SlickEdit, but SlickEdit does not come into focus, and the terminal is also no longer in focus. Not sure where the focus is. Then if I type alt-tab to switch to SlickEdit then it still doesn't come into focus. Only when I alt-tab a second time then will it finally comes into focus. Instead of 2x alt-tab then I can mouse click on only the top menu bar of SlickEdit to change focus with the mouse, but clicking on any other part of the SlickEdit windows seems to ignore the mouse.

After focus is finally switched to SlickEdit then I can alt-tab backwards and forwards between it and any other GUI window without issue, etc. Or I can mouse click on any other GUI window and then mouse click on any part of the SlickEdit window to get focus back. So the focus issue only seems to happen directly after typing 'vs <file>'...

Note: If I type 'vs +new <file>' or 'vs +new <file> &' then I'll get a new SlickEdit window in focus immediately, and no need to hit alt-tab, etc.

Note: All other GUI apps behave just fine with either alt-tab or the mouse clicking anywere on the window. Also, I have no SlickEdit windows 'undocked' etc; just one big window. I noticed this seems to have been an issue with SlickEdit as far back as 2007 [1] ? And again in 2009 [2] and 2010 [3].

Any ideas how to make SlickEdit behave better?

[1] https://community.slickedit.com/index.php/topic,2487.msg10324.html#msg10324
[2] https://community.slickedit.com/index.php/topic,4738.msg19813.html#msg19813
[3] https://community.slickedit.com/index.php/topic,6041.msg24951.html#msg24951
« Last Edit: December 02, 2020, 01:15:35 AM by SimonHF »

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: Focus moves away from editor on Linux edition
« Reply #7 on: December 02, 2020, 03:17:15 PM »
Are you using the default window manager for that version of Ubuntu, or something else?

I suspect some window manager specific code that went into v22 or v23.  It fixed a corner case focus problem when bringing up an existing editor with the window managers at the time. With recent window managers, it caused more focus problems than it fixed. I ended up taking it out of v25.   Depending on what window manager you're running, we might be able to disable it for v24 with an env var.




SimonHF

  • Community Member
  • Posts: 43
  • Hero Points: 0
Re: Focus moves away from editor on Linux edition
« Reply #8 on: December 02, 2020, 05:23:37 PM »
Thanks for the quick reply.

It's a stock Ubuntu with default Window manager.

What's the next step to debug and come up with a workaround?

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: Focus moves away from editor on Linux edition
« Reply #9 on: December 02, 2020, 06:40:31 PM »
Ok.  We can try setting XDG_CURRENT_DESKTOP to something different to see if this code is the problem. 

It needs to be set for the running instance of SlickEdit, not the second invocation where you're just sending a file to the existing editor.  So exit out of SlickEdit, and then restart it from a terminal like this:  XDG_CURRENT_DESKTOP=none vs +new

And then try opening a file from a terminal without the +new like you normally do a couple of times, and see if the focus behavior is different.

SimonHF

  • Community Member
  • Posts: 43
  • Hero Points: 0
Re: Focus moves away from editor on Linux edition
« Reply #10 on: December 02, 2020, 07:01:23 PM »
Okay, so I shut down SlickEdit via File, Exit.

Next I tried starting it as suggested with: XDG_CURRENT_DESKTOP=none vs &

Then I can switch back to the terminal and try editing <file> which is a file already opened for editing: vs <file>

What I found is that with XDG_CURRENT_DESKTOP=none then I only have to press alt-tab once to switch to SlickEdit from the terminal after trying to edit <file>, whereas without XDG_CURRENT_DESKTOP=none then I need to press alt-tab twice. I repeated starting SlickEdit with and without several times and the behavior is consistent.

Also, interesting is that when SlickEdit is started with XDG_CURRENT_DESKTOP=none and I type vs <file> then although it doesn't get focus, I can use the mouse to click on any part of its window to bring it into focus.

All in all, XDG_CURRENT_DESKTOP=none does take a step closer to normal and expected behavior but focus is still not working :-(

Any other ideas?

SimonHF

  • Community Member
  • Posts: 43
  • Hero Points: 0
Re: Focus moves away from editor on Linux edition
« Reply #11 on: December 02, 2020, 07:24:44 PM »
Hmmm... so armed with 'XDG_CURRENT_DESKTOP' I Googled for other things to try and set it to, e.g. Unity, Compiz, GNOME, etc. But none of them worked.

However, while Googling, I came across this Linux tool called wmctrl (which lets any window by brought into focus via a script) and noticed that even if I leave out XDG_CURRENT_DESKTOP, but add this line to the bottom of the vs script, then focusing just seems to work :-)

$ diff /opt/slickedit-pro2019/bin//vs /opt/slickedit-pro2019/bin//vs.orig       
52d51
< wmctrl -a SlickEdit

It's a bit of a hack but until the SlickEdit dev wizards get this issue under control then maybe it might be of use to desperate users like me :-) If I discover any issues with it then I'll update here...
« Last Edit: December 02, 2020, 07:26:32 PM by SimonHF »

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: Focus moves away from editor on Linux edition
« Reply #12 on: December 02, 2020, 07:33:44 PM »
So that code I took out of v25 is the cause of the weird focus state at least.

The remaining news is probably not so good.

That window manager (along with most of the "mainstream" window managers) implement something called focus stealing prevention.  So when you have app A that has focus, and app B tries to switch focus to itself, the window manager won't allow it.  Some of the window managers will also pop up a little toast notification that says something to the effect "App B Needs Something", and maybe make the icon in the dock/status-bar blink.

So that's probably what's happening in your case.  Starting a new application isn't considered focus stealing, so you get the right focus when you start SlickEdit.  When you try to activate the existing SlickEdit, the terminal app has focus, and the window manager doesn't want SlickEdit to take focus away from the terminal.  It used to be you could turn off that feature with gnome-tweak-tool or something similar, but I think that's no longer the case. 

I'll switch to that window manager later this afternoon though, and check to see if I'm missing anything else.  Focus issues can be tricky, and I have mistaken other things for focus stealing prevention problems before. 

That wmctrl trick is interesting.  It says it's doing standard EWMH communication with the window manager.  It makes me wonder if there's something I've missed in Qt that would allow us to do the same just for the file activation case.  I'll have to take a closer look at how they're doing that.

SimonHF

  • Community Member
  • Posts: 43
  • Hero Points: 0
Re: Focus moves away from editor on Linux edition
« Reply #13 on: December 02, 2020, 08:16:36 PM »
Thanks for the update and glad I could 'help' with that wmctrl info.

So are you saying that v25 will just work? I'm reluctant to upgrade as if it doesn't work still, and doesn't work with wmctrl then I'm back to square one :-) And it's been a horrible year of v24 and the alt-tab key... :-)

patrick

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 1818
  • Hero Points: 151
Re: Focus moves away from editor on Linux edition
« Reply #14 on: December 02, 2020, 08:37:46 PM »
No. V25 doesn't have the bug that you worked around with the env var, with the focus not on the terminal or SlickEdit.  But it's still under the same WM rules with no other workarounds, so no changes from v24 there.

If looking at Qt/wmctrl gives me a new idea of how to handle this case, it might be something that could go into the v25.0.2 point release.  Even assuming an easy change, I doubt it could make it for the 25.0.1 point release coming probably this month.  But I'll update the thread with what I find out.