Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Tk geometry unexpected return if window withdrawn and re-instated

by WayneRas (Acolyte)
on Aug 02, 2019 at 01:38 UTC ( [id://11103746]=perlquestion: print w/replies, xml ) Need Help??

WayneRas has asked for the wisdom of the Perl Monks concerning the following question:

Context - Ubuntu 18.04.2 LTS Gnome-Shell 3.28.3 Perl 5.26.1 Tk 804.034
Goal - on starting a new Tk based GUI app session position the window($mw for reference) where the user last left it (implicit assumption that screen dimensions don't change between sessions)!
I encountered the following challenges in doing that:
1) - $mw->rooty not readily helpful as it reflects position after decoration & Ubuntu top task bar
2) - $mw->geometry return changes once $mw->withdraw
The code below demonstrates the issue - the results I get from running in my context are at the end of the code. My question relates to (2) and simply put is it a bug or am I missing/overlooking something?
As the app I am working on may see the window withrawn, raised, possibly moved, withdrawn ... ad nauseam I have yet to determine what complications ensure. So any 'better ways' gratefully accepted.
Changing starting pos("+10+0") to away from any potential complications with System task/activity bars still reflects the issue.

#!/usr/bin/perl use strict; use Tk; my $mw = MainWindow->new(-title=>'WTF'); $mw->geometry('+10+0'); $mw->overrideredirect(0); my $lab = $mw->Label(-text=>'This is a label in the MainWindow',-font= +>'fixed 24',-border=>0)->pack(-anchor=>'w'); $mw->update; $mw->protocol('WM_DELETE_WINDOW' => sub{printf "exit geometry=%s,rootx +=%d,rooty=%d;height:%.2f\n",$mw->geometry,$mw->rootx,$mw->rooty,$mw-> +height; Tk::exit}); printf "init geometry=%s,rootx=%d,rooty=%d;height:%.2f\n",$mw->geometr +y,$mw->rootx,$mw->rooty,$mw->height; $mw->withdraw; $mw->after(2000,sub{ $mw->state('normal'); return 1; } ); # MainLoop; exit(0); __END__ init geometry=497x32+10+0,rootx=10,rooty=57;height:32.00 exit geometry=497x32+0+19,rootx=10,rooty=57;height:32.00

Replies are listed 'Best First'.
Re: Tk geometry unexpected return if window withdrawn and re-instated
by beech (Parson) on Aug 02, 2019 at 07:23 UTC

    Hi

    Which version of Tk?

    Get geometry when you bind to "<Configure>"?

    I have observed that ->rootx and ->x change when you maximize/minimize the window

    "764x480+50+50", 764, 480, 50, 50, 54, 73, "764x480+50+50", 764, 480, 50, 50, -32000, -32000, "1024x721+50+50", 1024, 721, -4, -4, 0, 19, "1024x721+50+50", 1024, 721, -4, -4, -32000, -32000,

      Thank you for your time and response.
      The first line of my post provided the context including the Tk Version(Context - Ubuntu 18.04.2 LTS Gnome-Shell 3.28.3 Perl 5.26.1 Tk 804.034)
      I will experiment with results from <Configure> binding per your suggestion.
      If I may, what flavor of Unix and Desktop interface are you using, as it appears from the results you are not encountering the geometry issue I am?

        Hi

        If I may, what flavor of Unix and Desktop interface are you using, as it appears from the results you are not encountering the geometry issue I am?

        I'm using windows :) old osname=MSWin32, osvers=6.0, Tk 804.033

        What do you get from  $mw->winfo('geometry')?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11103746]
Approved by GrandFather
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-25 22:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found