sublimehq / sublime_text

Issue tracker for Sublime Text
https://www.sublimetext.com
810 stars 39 forks source link

Window focus not working when ST3 is minimized #917

Closed khung closed 1 year ago

khung commented 9 years ago

When Sublime Text 3 is minimized, opening a file that defaults to ST brings the ST window to the foreground but does not give the window focus.

Steps to reproduce:

  1. Install ST3 build 3083 64-bit on Windows 7 64-bit.
  2. Associate .txt files with ST.
  3. Open Sublime Text.
  4. Minimize the Sublime Text window.
  5. Open a .txt file.
  6. Sublime Text window will show in front, but focus will not be on the window.
FichteFoll commented 9 years ago

Not sure if this is an issue with ST or Windows, especially because I can't reproduce.

khung commented 9 years ago

I think this may be a combination of ST and Windows. I am able to reproduce the issue on a separate computer that I have set up similar to my main machine, but I am not able to reproduce it on a fresh Windows installation. This behavior does not happen with any other program that I associate with .txt files, so I don't think it's purely a Windows issue.

I'm open to any suggestions for troubleshooting this issue.

khung commented 9 years ago

After some more investigation, it looks like ST eventually calls the SetForegroundWindow function to bring the window to the front and activate it. The developer may want to look to see whether the code surrounding that works in all cases (especially minimized). For example, in Notepad++'s source code, it seems they use the ShowWindow function before SetForegroundWindow. From monitoring Sublime Text's calls, it looks like ST does it the other way around.

khung commented 7 years ago

I was recently able to test and reproduce this on another two physical machines even with clean installations of Windows and the latest build of ST 3. I have tried reproducing the issue with virtual machines but I was not able to. Here are the steps I used to reproduce:

Clean install of Windows 7 Professional 64-bit -Service Pack 1 (slipstreamed) -April 2016 Convenience Rollup (slipstreamed) Install Sublime Text 3 build 3126 64-bit -Select "Add to explorer context menu" Restart computer Start ST Open a new tab Start typing Minimize window by clicking on ST in the taskbar -minimizing through Show Desktop and the minimize button work properly Right-click on text file > Open with Sublime Text ST comes up to foreground, but input focus is not on ST If it works fine, follow these steps to retry -Close all ST tabs -Close ST -Retry from "Start ST" step

Machine configurations I tested with: Custom PC (existing installation) -reproducible 100% of the time Dell Latitude E5450 (existing installation) -reproducible 100% of the time Lenovo Thinkpad X200s (new installation) -reproducible almost 100% of the time Gigabyte BRIX GB-BSi5HA-6300 (new installation) -reproducible about 50% of the time over remote desktop. ST is not in explorer context menu. VirtualBox VM -Not reproducible, and I am not able to figure out why. It might be due to something unique in VirtualBox. The installed updates and installed software match the Thinkpad configuration after uninstalling some software from the Thinkpad. Even virtualizing the Thinkpad installation itself didn't work. ESXi VM -Also not reproducible.

UltraInstinct05 commented 1 year ago

I cannot reproduce this on a Windows 11 machine with the latest development build 4146. Open an OS file that is associated with ST, always opens it in ST (after ST has been minimized) while focusing the file & the window.

deathaxe commented 1 year ago

AFAIK, this has been fixed by ST 4068 along with adding Window.bring_to_front() API.