Re: Geometry of toplevels

From: Jonathan Bromley (jonathan.bromley_at_doulos.com)
Date: 11/05/04


Date: Fri, 05 Nov 2004 14:55:43 +0000

On Fri, 05 Nov 2004 14:08:17 GMT, claird@lairds.us
(Cameron Laird) wrote:

>In article <9ctjo0tqgjm2iaj7v5rkq9o67qeqfijvat@4ax.com>,
>Jonathan Bromley <jonathan.bromley@doulos.com> wrote:
                .
>>How may I discover the size of the toplevel's border (window
>>decorations) in a reliable, portable way? I need this to do
> .
> [yucky details]

>I know of no better way (and in fact suspect there's a WM I use
>that violates your assumptions). I think there's a consensus
>that this is a hard area. If you make your solution available,
>though, I'm confident several others of us will try it out and
>help you refine it.

> Myself, I even think there's potentially a TIP in this.
> WM is an area where Tcl can add significant value.

It already adds immense value. I don't understand enough of
the details of how Tcl interacts with X and the window managers
to be able to offer much implementation help, so I am
reluctant to instigate a TIP myself. Perhaps I can help
simply by articulating the problem...

Here's the solution I'm currently using to a very specific,
very simple problem: Make a toplevel window exactly fill
the bottom third of the screen. It's merely a fully-worked
version of the sketch I presented in the original post.
Absolutely no claims are made for perfection, reliability
or portability, but absolutely any suggestion for
improvement will be welcomed. Flaws that I'm already
aware of include:
* on Windows, [winfo screenheight] returns the total screen
  height, whereas the available screen height should be reduced
  to take account of the task bar and other paraphernalia at
  the bottom of the screen
* I correctly calculate the width of the left-hand border,
  but then am obliged to assume that the right-hand and bottom
  borders are the same width - in particular, this will be quite
  wrong if the window manager provides a status bar or similar
  at the bottom of the window
However, it works tolerably well on the systems I use.

Given a toplevel whose name is stored in variable "tw":

  # Find its dimensions
  #
  regexp {^(\d+)x(\d+)\+(\d+)\+(\d+)$} [wm geometry $tw] -> \
     client_w client_h scr_x scr_y

  # Find dimensions of the screen we're displayed on
  #
  set scr_w [winfo screenwidth $tw]
  set scr_h [winfo screenheight $tw]

  # Work out the window's border dimensions by comparing
  # top-left coordinates of the client area with top-left
  # coordinates of the toplevel (decorated) window:
  #
  set border_w [expr { [winfo rootx $tw] - $scr_x }]
  set title_h [expr { [winfo rooty $tw] - $scr_y }]

  # now we know all we need, so we can choose dimensions...
  #
  # total window height should be 1/3 of screen height
  set win_h [expr {$scr_h/3}]
  #
  # client height ASSUMES bottom border same width as left
  set client_h [expr {$win_h - ($border_w + $title_h)}]
  #
  # client width to make window occupy full screen width,
  # ASSUMING right-hand border is same width as left
  set client_w [expr {$scr_w - 2*$border_w}]
  #
  # find Y coordinate for top of window, ASSUMES that
  # [winfo screenheight] takes account of taskbars etc etc
  set scr_y [expr {$scr_h - $win_h}]

  # now set geometry as required
  #
  wm geometry $tw ${client_w}x${client_h}+0+$scr_y

Thanks in advance for any improvements

-- 
Jonathan Bromley, Consultant
DOULOS - Developing Design Know-how
VHDL, Verilog, SystemC, Perl, Tcl/Tk, Verification, Project Services
Doulos Ltd. Church Hatch, 22 Market Place, Ringwood, BH24 1AW, UK
Tel: +44 (0)1425 471223          mail:jonathan.bromley@doulos.com
Fax: +44 (0)1425 471573                Web: http://www.doulos.com
The contents of this message may contain personal views which 
are not the views of Doulos Ltd., unless specifically stated.


Relevant Pages

  • windows XP home service pack 2 caused a problem
    ... which is near the bottom of the window. ... the border to reveal the chess clock. ...
    (microsoft.public.windowsxp.basics)
  • Re: Task manager
    ... Double click on the border at the top. ... the only thing on my window is at ... > the bottom, the end task etc. ... How do I get the title bar back and all the tabs? ...
    (microsoft.public.windowsxp.help_and_support)
  • Re: Unwanted tablelist scrolling during cellconfigure
    ... explicitly call the 'see' command, ... It also doesn't happen for a partially visible row at the bottom of the ... I haven't been able to reproduce your problem. ... I am also somewhat surprised to hear that the topmost row in the window gets partially obscured. ...
    (comp.lang.tcl)
  • Re: shrunk roman shades :o(
    ... I made Roman shades for my son's townhouse. ... that comes in at the bottom window. ... plan to add a folded piece along the bottom. ... >from now when I decide to wash them... ...
    (rec.crafts.textiles.quilting)
  • Re: How do you activate the commentaries at the bottom of each page of a presentation
    ... But if you need to change it to ALL slides' notes pages, then do it in the Notes Master View. ... If you type something in the placeholder where it says "Click to edit Master Text styles," what you type won't show up in the individual slide notes pane in Normal View. ... To open that extra pane at the bottom of each slide, just drag the edge of the pane. ... Most of them have this extra window at the bottom and I can get into that but only one window at a time ...
    (microsoft.public.powerpoint)