Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Taskbar Entry for Perl/Tk Fullscreen Windows

Graphical User Interface (GUI)

Taskbar Entry for Perl/Tk Fullscreen Windows

by  Kirsle  Posted    (Edited  )
If you're creating a Perl/Tk app that will open a fullscreen window (for example, if you're writing a game or just want to cover the whole screen with an introduction sequence or something), this little trick will help when users Alt+Tab away from your fullscreen window.

Typically, if you want a fullscreen window, you'll call overrideredirect(1) to remove the window chrome (the title bar and borders), and then position it in the corner of the screen while resizing it to the screen's width and height:

Code:
use Tk;

my $main = MainWindow->new (
    -title => 'My Fullscreen Window',
    -background => 'black',
);

my $w = $main->screenwidth;
my $h = $main->screenheight;
$main->overrideredirect (1);
$main->MoveToplevelWindow (0,0);
$main->geometry (join('x',$w,$h));

Now, when your code runs, this window should pop up and cover the entire screen. But if a user Alt+Tab's away from the window to bring up another window, it's difficult for them to return to your fullscreen window.

When you call overrideredirect to remove the window chrome, you also remove the window's entry on the task bar (the bar that the Start button is on), and it also loses its entry in the "Alt+Tab" list, so you can't Alt+Tab back to the window.

So this becomes a problem, especially if it gets hidden beneath some other maximized windows. The only way to refocus the window is for the user to click somewhere inside the window; it can't just be switched back to.

So here's the workaround:

You create a new Toplevel window to be a control window. This is just a normal, empty window that's hidden off the screen. So, being a normal window, this one has its task bar entry and can be switched to like a normal window.

When this "control window" is focused, it should send focus back to the main (fullscreen) window, bringing it back to the top to cover the screen once again.

Here's the code for such a control window:
Code:
# Create a "control window"
my $control = $main->Toplevel (
    -title => 'FS Window',
);
$control->geometry ("50x50");
$control->MoveToplevelWindow(-150,-150);

# Bind FocusIn on the control window
$control->bind ('<FocusIn>', sub {
    $main->focusForce;
});

So with this code, your fullscreen window can be switched back to if the user Alt+Tabs away from it.
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top