Author Topic: Focus switches to floating windows  (Read 2198 times)

MrPolite

  • Community Member
  • Posts: 10
  • Hero Points: 0
Focus switches to floating windows
« on: December 07, 2018, 06:01:18 PM »
Hello,
I'm having an issue with the document focus switching to the wrong one every time I switch between SlickEdit and another app. I have a few documents floating on my second monitor, and if the document focus is on the first monitor, upon switching to another app then back to SlickEdit, the focus always goes to the floating windows on the 2nd monitor. Is there any way to fix this?

I have SlickEdit Pro 2017 (v22.0.1.0 64-bit) on Debian linux

Graeme

  • Senior Community Member
  • Posts: 2796
  • Hero Points: 347
Re: Focus switches to floating windows
« Reply #1 on: December 07, 2018, 10:42:00 PM »
You could try this code.  Functions that start with _actapp_ are automatically called when slickedit loses or gains the focus.  If you don't already have a macro file you can put it in, then record a trivial macro and vusrmac.e will be created in your config folder - then save the code in vusrmac.e, then load it using the load module command on the macro menu.

Code: [Select]
#include "slick.sh"
_str fix_focus_buffer_name;

void _actapp_fix_focus(_str gettingFocus="")
{
   if ( gettingFocus ) {
      if ( fix_focus_buffer_name == '' ) {
         return;
      }
      edit("+b " :+ maybe_quote_filename(fix_focus_buffer_name));
      message("got focus " :+ fix_focus_buffer_name);
   }
   else
   {
      if ( _no_child_windows() ) {
         fix_focus_buffer_name = '';
         return;
      }
      fix_focus_buffer_name = _mdi.p_child.p_buf_name;
      message("lost focus " :+ fix_focus_buffer_name);
   }
}


MrPolite

  • Community Member
  • Posts: 10
  • Hero Points: 0
Re: Focus switches to floating windows
« Reply #2 on: December 08, 2018, 12:44:32 AM »
thanks!
It still seems to focus on the floating window all the time. The main window gets the focus for a split second then it goes to the floating window

Graeme

  • Senior Community Member
  • Posts: 2796
  • Hero Points: 347
Re: Focus switches to floating windows
« Reply #3 on: December 08, 2018, 01:01:29 AM »
ok, I've added a one second delay.  If this doesn't work you could try xretrace and the command xretrace-cursor - it alternates between the last two cursor locations visited.  I have it bound to keypad_plus - might be quicker than using the mouse.
https://community.slickedit.com/index.php/topic,16598.0.html


Code: [Select]
static int fix_focus_timer;
static _str fix_focus_buffer_name;

static void my_fix_focus()
{
   _kill_timer(fix_focus_timer);
   if ( fix_focus_buffer_name == '' ) {
      return;
   }
   edit("+b " :+ maybe_quote_filename(fix_focus_buffer_name));
   message("got focus " :+ fix_focus_buffer_name);
}



void _actapp_fix_focus(_str gettingFocus="")
{
   if ( gettingFocus ) {
      if ( fix_focus_buffer_name == '' ) {
         return;
      }
      _set_timer( 1000, my_fix_focus);
   }
   else
   {
      if ( _no_child_windows() ) {
         fix_focus_buffer_name = '';
         return;
      }
      fix_focus_buffer_name = _mdi.p_child.p_buf_name;
      message("lost focus " :+ fix_focus_buffer_name);
   }
}

MrPolite

  • Community Member
  • Posts: 10
  • Hero Points: 0
Re: Focus switches to floating windows
« Reply #4 on: December 10, 2018, 06:14:02 PM »
thanks for spending time! still not working - will look into the xretrace link you mentioned :)

Graeme

  • Senior Community Member
  • Posts: 2796
  • Hero Points: 347
Re: Focus switches to floating windows
« Reply #5 on: December 11, 2018, 01:49:05 AM »
You could try making the time longer until it works

 _set_timer( 4000, my_fix_focus);   // 4 seconds

and check whether the message "got focus" shows up on the status bar with the correct filename.