resize window . width 170 height 123resize window .l width 170 height 56
* Mark Summerfield <m.n.summerfield@gmail.com>
| I'm developing a Tcl/Tk 9 app on Linux with menus and toolbars.
| The toolbars use a grid layout and I have a refresh_toolbars
| method for redoing the layout when the user resizes the
| window:
| bind . <Configure> [callback on_window_state_change]
--<snip-snip>--
| This works fine (if a bit flickery), but the binding is
| _not_ called when the maximize/restore button is clicked.
| Can this button be detected?
My guess would be to check the <Map> and <Unmap> events...
HTH
R'
I'm developing a Tcl/Tk 9 app on Linux with menus and toolbars.
The toolbars use a grid layout and I have a refresh_toolbars
method for redoing the layout when the user resizes the
window:
bind . <Configure> [callback on_window_state_change]
oo::define App method on_window_state_change {} {
if {$WindowWidth > 1} {
set height [winfo height .]
set width [winfo width .]
if {abs($WindowWidth - $width) > $::ICON_SIZE ||
abs($WindowHeight - $height) > $::ICON_SIZE} {
set WindowWidth $width
set WindowHeight $height
after idle [callback refresh_toolbars]
}
}
}
This works fine (if a bit flickery), but the binding is
_not_ called when the maximize/restore button is clicked.
Can this button be detected?
The problem was in my code. I _am_ getting the resize events
on maximize/restore.
And so I've simplified to:
oo::define App method on_window_state_change window {
if {$window eq "."} { after 100 [callback refresh_toolbars] }
}
But unfortunately this is also triggered by window _move_.
Is it possible to distinguish between a move event and a resize
event?
* Mark Summerfield <m.n.summerfield@gmail.com>
--<snip-snip>--
| <Configure> binding
| But unfortunately this is also triggered by window _move_.
| Is it possible to distinguish between a move event and a resize
| event?
man bind:
Configure
A Configure event is sent to a window whenever its size, position,
or border width changes, and sometimes when it has changed posi-
tion in the stacking order.
So I guess you would need to remember the width/height of your toplevel,
add %w %h to the binding, and detect changes in width/height in the
binding callback.
R'
On Thu, 30 Oct 2025 13:58:14 +0100, Ralf Fassel wrote:
* Mark Summerfield <m.n.summerfield@gmail.com>
--<snip-snip>--
| <Configure> binding
| But unfortunately this is also triggered by window _move_.
| Is it possible to distinguish between a move event and a resize
| event?
man bind:
Configure
A Configure event is sent to a window whenever its size, position,
or border width changes, and sometimes when it has changed posi-
tion in the stacking order.
So I guess you would need to remember the width/height of your toplevel,
add %w %h to the binding, and detect changes in width/height in the
binding callback.
R'
I finally got it to ignore moves & not to flicker.
I have to keep track of 3 variables:
# at startup
set RefreshingToolbars false
set MainX [winfo x .]
set MainWidth [winfo width .]
oo::define App method refresh_toolbars {} {
if {$RefreshingToolbars} { return }
set RefreshingToolbars true
try {
update
set main_x [winfo x .]
set main_width [winfo width .]
if {$MainX != $main_x && $MainWidth == $main_width} { return }
set MainX $main_x
set MainWidth $main_width
# grid toolbars user wants to see
# ...
} finally {
set RefreshingToolbars false
}
}
When I try it, resizing the main window triggers the configuration event
on the toolbar, moving the main window doesn't (because the tool bar
itself does not move inside the main window)
Christian
* Mark Summerfield <m.n.summerfield@gmail.com>
| I've now made the code specific to my toolbar & the only flicker
| is when I change width because then of course the toolbar re-grids.
This could probably be improved by only calling the actual callback only once. I think you are trying to do that via 'RefreshingToolbars', but
this does not work as expected (put a 'puts' in the callback to see that
it triggers *and* works repeatedly).
I'd cancel any still pending invocation instead:
- set up a class var after_id to remember the ticket for the 'after' event
| oo::define App method on_toolbar_resized_width {} {
after cancel $after_id
set after_id [after 100 [callback refresh_toolbars]]
| }
This way only the final callback is done when you're done resizing the window.
R'
| Sysop: | DaiTengu |
|---|---|
| Location: | Appleton, WI |
| Users: | 1,089 |
| Nodes: | 10 (0 / 10) |
| Uptime: | 153:53:20 |
| Calls: | 13,921 |
| Calls today: | 2 |
| Files: | 187,021 |
| D/L today: |
3,760 files (944M bytes) |
| Messages: | 2,457,163 |