Not logged inGosu Forums
Forum back to Help Search Register Login
Up Topic Gosu / Gosu Exchange / Controlling window/application focus
- - By siebharinn Date 2016-10-12 02:28
Hey all -

I'm putting together a simple arcade machine.  I have a Gosu app that acts as a menu, which then uses Process.spawn to launch the game. It works fairly well. There is some flickering when the apps change, but I'll work on that.

But the real problem is that the menu app doesn't receive focus when the game app exits. I'm calling Process.wait and getting notified when the game exits. Is there a call I can make in the menu app to restore it to the foreground?

If it matters, I'm developing on a Mac, but plan on eventually deploying (way way down the road) to a Raspberry Pi.

Also, if anyone has a better suggestion for how to approach this, I'm listening. I originally considered a single app containing the menu and games, but I'm planning on more than ten games, and think that it could get bloated pretty quickly.
Parent - By siebharinn Date 2016-10-12 02:38
I kind of got around it by using Process.exec instead of Process.spawn. The menu app unloads when the game loads. When the game exits, it drops back to the shell. But, I'm launching with a script like this:


while [ true ]; do
  ruby main.rb
  echo "Relaunching"

This works, but is even more flickery. It might be manageable; I'll need to build a slightly bigger example to know for sure.
Parent - - By jlnr (dev) Date 2016-10-13 20:35
I don't think there's a platform-independent way to handle this. Which version of the Raspberry Pi are you deploying to? The original Pi only supports running Gosu in full-screen and is a little tricky to set up, so you might not be able to reuse the same logic as on your Mac. And the tutorial has not yet been updated for the Pi 2/3. Just a little heads-up that getting Gosu to work on the Pi is still tricky. :(
Parent - - By siebharinn Date 2016-10-15 02:21
I don't have a Pi yet, but will be ordering the 3. Unless something new gets announced in the next few months.

I'll be sure to share anything I discover in the process of getting everything to work.
Parent - By jlnr (dev) Date 2016-10-15 08:30

If the Pi 3 is running a regular Linux distro, you can use a scriptable window manager that can bring windows to the foreground if necessary. I've built a Kiosk running Gosu and a video player on Linux once and scripted Sawfish to manage windows (z-order, focus, all that):

On OS X, you should be able to do the same thing with AppleScript :) You probably have to wrap your script as an .app to do so:

osascript -e 'tell application "My App Name" to activate'
Up Topic Gosu / Gosu Exchange / Controlling window/application focus

Powered by mwForum 2.29.7 © 1999-2015 Markus Wichitill