Re: Geometry of toplevels
From: Jonathan Bromley (jonathan.bromley_at_doulos.com)
Date: 11/05/04
- Next message: Bryan Oakley: "Re: foreach {first rest} line"
- Previous message: Georgios Petasis: "Re: How to get the real tk_win of a toplevel window?"
- In reply to: Cameron Laird: "Re: Geometry of toplevels"
- Next in thread: Chris Nelson: "Re: Geometry of toplevels"
- Reply: Chris Nelson: "Re: Geometry of toplevels"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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.
- Next message: Bryan Oakley: "Re: foreach {first rest} line"
- Previous message: Georgios Petasis: "Re: How to get the real tk_win of a toplevel window?"
- In reply to: Cameron Laird: "Re: Geometry of toplevels"
- Next in thread: Chris Nelson: "Re: Geometry of toplevels"
- Reply: Chris Nelson: "Re: Geometry of toplevels"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|