×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Graphical User Interface (GUI)

Taskbar Entry for Perl/Tk Fullscreen Windows by Kirsle
Posted: 28 Mar 06

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.

Back to Perl FAQ Index
Back to Perl Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close