Version 3 of Total Window Geometry

Updated 2004-04-23 02:07:08

Vince wrote: What is the right (x-platform) way to find the size/position of a toplevel window, including all window-manager decorations (so that I can position two windows without their wm borders overlapping)?

Testing on Windows shows that

wm geometry . returns contentswidthxcontentsheight+decorationTop+decorationLeftEdge.

and

winfo rooty . returns contentsTop

winfo rootx . returns contentsLeftEdge

So, we have the (x,y) of the wm decoration from wm geometry, and we can get the titlebar/border height with contentsTop - decorationTop, and the left decoration thickness with contentsLeftEdge - decorationLeftEdge. But how do I get the thickness of the right-edge and bottom-edge decoration? I can assume it's the same as the left edge decoration, I suppose.

Is the above true cross-platform? Is there a better way of doing this? Does it work if the toplevel now has . configure -menu applied?

Peter Newman 22 April 2004: In Centering a window, Martin Lemburg asked a similar question (and got no answer). winfo provides lots of useful information. But it doesn't provide that. But whether that's because 1) it's impossible to provide that info. in a cross-platform way, 2) it's un-necessary, because your assumption that it's alway left = right = bottom is always correct, or 3) winfos authors never though of it, who knows? On my Windows 95, I've never seen an app that doesn't do this. Nor on any Windows or Linux screen dump I've seen on the Net. Maybe there's some Linux and Mac users out there can tell us if that's true for them. I think you have to assume that it is. And I've never experienced . configure -menu changing this.

Vince adds then, that this proc works for windows:

    proc totalGeometry {{w .}} {
        set geom [wm geometry $w]
        regexp -- {([0-9]+)x([0-9]+)\+([0-9]+)\+([0-9]+)} $geom -> \
          width height decorationLeft decorationTop
        set contentsTop [winfo rooty $w]
        set contentsLeft [winfo rootx $w]

        # Measure left edge, and assume all edges except top are the
        # same thickness
        set decorationThickness [expr {$contentsLeft - $decorationLeft}]

        # Find titlebar and menubar thickness
        set menubarThickness [expr {$contentsTop - $decorationTop}]

        incr width [expr {2 * $decorationThickness}]
        incr height $decorationThickness
        incr height $menubarThickness

        return [list $width $height $decorationLeft $decorationTop]
    }

But can anyone test it on other platforms, please?


22 apr 2004 dk -- it appears to work under OS X (mac)


Category Porting