Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

take focus, at the OS level, from any other programs, on incoming call #749

Open
caver456 opened this issue Aug 19, 2024 · 4 comments
Open

Comments

@caver456
Copy link
Collaborator

e.g. if using caltopo or browsing the web, an incoming call should steal focus and raise the new entry dialog.

Also, after the new entry dialog is closed in this scenario (after taking focus from another application), seems like the radiolog main window should keep focus, rather than handing focus back to the other application. The might be subjective / debatable, but, seemed like it would be the more helpful for radiolog to keep focus during the MRA mock 8/17/24.

@caver456
Copy link
Collaborator Author

caver456 commented Sep 1, 2024

Researching before trying anything: looks like Windows has a few restrictions on this ability to 'steal' focus. Good explanations here, with details on how to work around it. Definitely worth a try!

@caver456
Copy link
Collaborator Author

caver456 commented Sep 1, 2024

(don't steal focus on mic bumps!)

@caver456
Copy link
Collaborator Author

caver456 commented Sep 1, 2024

Works well but has some massive side effects that would make this non-useful until figured out.

Starting the fsTester script then starting typing in another application (notepad, typing 'asdf' repeatedly): the radiolog main window does steal focus, but, that's probably not the right way to go - if another radiolog sub-window already has focus, then the main window shouldn't steal it, because it resulted in this (due to corresponding a, s, f hotkey actions in the main window):
image

Anyway, here are the changes made so far:

  1. in imports:
    from pynput import keyboard

  2. at the end of MyWindow init:

		#749 - see relevant code in fsParse
		self.kbd=keyboard.Controller()
		# self.windowHandle=win32gui.FindWindow('MyWindow',None)
		# self.windowHandle=win32gui.GetForegroundWindow()
		self.windowHandle=int(selfwinId())

3, in fsParse, after the entire 'for line' clause, before 'checking for existing open new entry tabs':

		# 749 - take OS focus from other applications an all incoming calls (except mic bumps, which have already been filtered by this point)
		# https://stackoverflow.com/a/73921057/3577105
		rprint('taking system focus')
		self.kbd.press(keyboard.Key.alt)
		try:
			win32gui.SetForegroundWindow(self.windowHandle)
		except:
			rprint(' failed to set foreground window')
		finally:
			self.kbd.release(keyboard.Key.alt)

@caver456
Copy link
Collaborator Author

caver456 commented Sep 1, 2024

made a branch for this issue and committed as-is. Will probably table this issue since it's not the highest priority and has potential side-effects... stealing focus seems like a mixed bag at best, and may just be a flat-out bad idea. Should probably be accompanied by some beeps and visual notification, and maybe pausing the keyboard input for a second - who knows. But, passing input to the main window seems dodgy because keys typed on auto-pilot would act as hotkeys, as above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

When branches are created from issues, their pull requests are automatically linked.

1 participant