A fullscreen toplevel

MG In Tk 8.5, there's a new -fullscreen option for wm attributes which does this.

toplevel .foo
wm attributes .foo -fullscreen 1

SPB - 26 Apr 2012 - Moved MG's comment to the top, as it is now the most relevant.


alove 18 Oct 2004 - This page illustrates a couple ways to create full-screen toplevel windows. I wrote these for Windows XP, but the bottom one is confirmed to work for Linux too. If someone can tell me how to zoom a window in other OS versions, please let me know.

package require Tcl 8.4

wm title . "Full-screen with decorations"
set a [expr {int([winfo screenwidth .] * 0.5)}]
set b [expr {int([winfo screenheight .] * 0.5)}]
wm geometry . 400x300+[expr $a - 200]+[expr $b - 150]  ;# window is centered
update idletasks 
wm attributes . -topmost no
wm state . zoomed  ;# This command for Windows only

frame .x -highlightthickness 0 -bg #c8efff
place .x -x 0 -y 0 -relwidth 1 -relheight 1

bind . <KeyPress-Escape> "wm iconify ."

alove 11 Oct 2004 - This one has no decorations.

package require Tcl 8.4

wm title . "Full-screen with NO decorations"
wm overrideredirect . yes      ;# removes window decorations
wm geometry . [winfo screenwidth .]x[winfo screenheight .]+0+0
update idletasks               ;# updates the full-screen
wm attributes . -topmost yes   ;# stays on top - needed for Linux
                               ;# on Win9x, if =no, alt-tab will malfunction
frame .x -highlightthickness 0 -bg #c8efff
place .x -x 0 -y 0 -relwidth 1 -relheight 1

button .x.min -text "Minimize" -bg #ffdbff -font "arial 10 bold" \
   -command x_iconify
place  .x.min -x [expr [winfo screenwidth  .] - 140] -y 10

button .x.end -text "Close" -bg #ffdbff -font "arial 10 bold" \
   -command "destroy ."
place  .x.end -x [expr [winfo screenwidth  .] - 60] -y 10

bind . <Expose> "wm overrideredirect . yes; focus -force ."
bind . <KeyPress-Escape> x_iconify

proc x_iconify {} {
    wm overrideredirect . no
    wm iconify .
}

This one works on WindowsXP, probably Win9x, and according to rdt, now also on Linux. Just click on the "minimize" button or the <Escape> key. The trick is to use <Expose> to detect that the window is being deiconified. The "focus force ." is necessary for Windows, otherwise the <escape> doesn't work until you click on the window first.

Adam Love


rdt says on Linux, this works if the 'wm overrideredirect ...' comes before the 'wm geometry ...' if the 'wm attributes ...' is commented out it gives an error.

alove Thanks, I've corrected the code above. NOTE: If you set topmost=no, you will have problems with alt-tab on Windows - the icon will disappear and you can only close the program via the task manager (end task).

(by Andy M) window::or https://wiki.tcl-lang.org/4186 - This is a package that takes care of some nuances of going fullscreen


SC Tried this on my two-screen xinerama linux setup and of course the window spans 'both' screens. A little bit of digging reveals the culprit as the X11 WidthOfScreen macro and a little more reveals that finding the true width of the screen isn't that hard. Here's a little bit of C code as memo of how it might be done:

/* screen-info.c
  *
  * Compile with:
  *   cc -o screen-info screen-info.c -I/usr/X11R6/include -L/usr/X11R6/lib -lXinerama -lX11 -lXext
  *
  */

#include <stdio.h>
#include <unistd.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/extensions/Xinerama.h>

int main(int argc, char *argv[]) {
    Display *display;
    Screen *screen;
    int i;

    display = XOpenDisplay(NULL);
    if(!display) {
        printf("Couldn't open display %s\n",display);
    }

    if ( XineramaIsActive( display ) ) {
        int nscreens;
        XineramaScreenInfo * info = XineramaQueryScreens( display, &nscreens );

        printf("Xinerama is active\n");

        for( i = 0; i< nscreens; i++ ) {
            printf( "Screen %d: (%d) %d+%d+%dx%d\n", i, info[i].screen_number, 
                    info[i].x_org, info[i].y_org,
                    info[i].width, info[i].height );
        }
    } else {
        printf("Xinerama is not active\n");
    }

    screen = DefaultScreenOfDisplay(display);
    printf( "DefaultScreenOfDisplay, %d x %d\n", 
            WidthOfScreen(screen), HeightOfScreen(screen) );

    return(0);
}