Sign up

Getting position and size of windows

I can't seem to get the proper position and size of a window(the main application window).

using getPosition and getSize. It seems to return some of the values correctly some of the time.

I mainly want to save and restore the position and size of windows but nothing ever seems correct and I can't find the right place to do it(I do it after onShow and onHide.

Re: Getting position and size of windows

int x, y,w, h;
win.getPosition(x,y);
auto pw = win.getAllocatedWidth();
auto ph = win.getAllocatedHeight();
win.getSize(w,h);

win.setDefaultSize(400,400);
win.setSizeRequest(300,300);
win.resize(200,200);

win.move(30,30);

None of this code seems to do anything anywhere I place it. (addOnShow, addOnHide, addOnRealize,

Re: Getting position and size of windows

Also, I've tried some other things...

If I remove all the stuff I do the problem is that the window appears at different places. I use 4 monitors and I'm not sure if it's positioning it based on nonsense or what.

It should be something very simple like win.move(0,0) yet that positions the window off screen and I can't see squat nor get the window back on to a screen using win+arrows.

I just have no idea what is going on...

Seems like something is broke as something as move(0,0) should work yet breaks the app.

I'm thinking this is mainly an issue with the root window position and all the others work more or less(but they are relative).

What I've noticed is that the window is shifted towards the upper left then cycles back down.

It's very strange and I can almost bet that it has to do with my monitor configuration on windows.

Re: Getting position and size of windows

On 03-06-2019 03:17, Alex X wrote:

int x, y,w, h;
win.getPosition(x,y);
auto pw = win.getAllocatedWidth();
auto ph = win.getAllocatedHeight();
win.getSize(w,h);

win.setDefaultSize(400,400);
win.setSizeRequest(300,300);
win.resize(200,200);

win.move(30,30);

None of this code seems to do anything anywhere I place it. (addOnShow, addOnHide, addOnRealize,

For me it seems to be working when i put move and setDefaultSize in
the constructor for the window. Only move doesn't the the window
decorations in to account when positioning the window.

Re: Getting position and size of windows

On Mon, 3 Jun 2019 22:42:05 +0200, Mike Wey wrote:

On 03-06-2019 03:17, Alex X wrote:

int x, y,w, h;
win.getPosition(x,y);
auto pw = win.getAllocatedWidth();
auto ph = win.getAllocatedHeight();
win.getSize(w,h);

win.setDefaultSize(400,400);
win.setSizeRequest(300,300);
win.resize(200,200);

win.move(30,30);

None of this code seems to do anything anywhere I place it. (addOnShow, addOnHide, addOnRealize,

For me it seems to be working when i put move and setDefaultSize in
the constructor for the window. Only move doesn't the the window
decorations in to account when positioning the window.

Unfortunately I do not have access to the constructor ;/ I'm using glade and builder...

I wonder if a callback could be added for the constructors so I could hook in to them before I build so I may be able to get things to work? (would be a static delegate for each constructor taking this and the arguments... same thing might have to happen for destructors. Also, one would want to use an array to allow for multiple entries)

Are you implying that the code above fails if it is not in the constructor though?

I don't care too much about the exact position as long as getting and setting it produce the same result.

Re: Getting position and size of windows

On 04-06-2019 03:00, Alex X wrote:

On Mon, 3 Jun 2019 22:42:05 +0200, Mike Wey wrote:

On 03-06-2019 03:17, Alex X wrote:

int x, y,w, h;
win.getPosition(x,y);
auto pw = win.getAllocatedWidth();
auto ph = win.getAllocatedHeight();
win.getSize(w,h);

win.setDefaultSize(400,400);
win.setSizeRequest(300,300);
win.resize(200,200);

win.move(30,30);

None of this code seems to do anything anywhere I place it. (addOnShow, addOnHide, addOnRealize,

For me it seems to be working when i put move and setDefaultSize in
the constructor for the window. Only move doesn't the the window
decorations in to account when positioning the window.

Unfortunately I do not have access to the constructor ;/ I'm using glade and builder...

I wonder if a callback could be added for the constructors so I could hook in to them before I build so I may be able to get things to work? (would be a static delegate for each constructor taking this and the arguments... same thing might have to happen for destructors. Also, one would want to use an array to allow for multiple entries)

What happens when you call these functions directly on the Window
returned by Builder.getObject?

Are you implying that the code above fails if it is not in the constructor though?

I didn't try it anywhere else.

I don't care too much about the exact position as long as getting and setting it produce the same result.

Re: Getting position and size of windows

On Tue, 4 Jun 2019 19:34:54 +0200, Mike Wey wrote:

On 04-06-2019 03:00, Alex X wrote:

On Mon, 3 Jun 2019 22:42:05 +0200, Mike Wey wrote:

On 03-06-2019 03:17, Alex X wrote:

int x, y,w, h;
win.getPosition(x,y);
auto pw = win.getAllocatedWidth();
auto ph = win.getAllocatedHeight();
win.getSize(w,h);

win.setDefaultSize(400,400);
win.setSizeRequest(300,300);
win.resize(200,200);

win.move(30,30);

None of this code seems to do anything anywhere I place it. (addOnShow, addOnHide, addOnRealize,

For me it seems to be working when i put move and setDefaultSize in
the constructor for the window. Only move doesn't the the window
decorations in to account when positioning the window.

Unfortunately I do not have access to the constructor ;/ I'm using glade and builder...

I wonder if a callback could be added for the constructors so I could hook in to them before I build so I may be able to get things to work? (would be a static delegate for each constructor taking this and the arguments... same thing might have to happen for destructors. Also, one would want to use an array to allow for multiple entries)

What happens when you call these functions directly on the Window
returned by Builder.getObject?

That is what I'm doing except I do cast it to the Gtk type.

auto win = cast(gtk.Window.Window)builder.getObject("MainWin");

Re: Getting position and size of windows

On 05-06-2019 00:16, Alex X wrote:

On Tue, 4 Jun 2019 19:34:54 +0200, Mike Wey wrote:

On 04-06-2019 03:00, Alex X wrote:

On Mon, 3 Jun 2019 22:42:05 +0200, Mike Wey wrote:

On 03-06-2019 03:17, Alex X wrote:

int x, y,w, h;
win.getPosition(x,y);
auto pw = win.getAllocatedWidth();
auto ph = win.getAllocatedHeight();
win.getSize(w,h);

win.setDefaultSize(400,400);
win.setSizeRequest(300,300);
win.resize(200,200);

win.move(30,30);

None of this code seems to do anything anywhere I place it. (addOnShow, addOnHide, addOnRealize,

For me it seems to be working when i put move and setDefaultSize in
the constructor for the window. Only move doesn't the the window
decorations in to account when positioning the window.

Unfortunately I do not have access to the constructor ;/ I'm using glade and builder...

I wonder if a callback could be added for the constructors so I could hook in to them before I build so I may be able to get things to work? (would be a static delegate for each constructor taking this and the arguments... same thing might have to happen for destructors. Also, one would want to use an array to allow for multiple entries)

What happens when you call these functions directly on the Window
returned by Builder.getObject?

That is what I'm doing except I do cast it to the Gtk type.

auto win = cast(gtk.Window.Window)builder.getObject("MainWin");

There doesn't appear to be a way to do this when using gtk.Builder, as
these functions need to be called before the window is shown.

Re: Getting position and size of windows

On Wed, 5 Jun 2019 22:45:22 +0200, Mike Wey wrote:

On 05-06-2019 00:16, Alex X wrote:

On Tue, 4 Jun 2019 19:34:54 +0200, Mike Wey wrote:

On 04-06-2019 03:00, Alex X wrote:

On Mon, 3 Jun 2019 22:42:05 +0200, Mike Wey wrote:

On 03-06-2019 03:17, Alex X wrote:

int x, y,w, h;
win.getPosition(x,y);
auto pw = win.getAllocatedWidth();
auto ph = win.getAllocatedHeight();
win.getSize(w,h);

win.setDefaultSize(400,400);
win.setSizeRequest(300,300);
win.resize(200,200);

win.move(30,30);

None of this code seems to do anything anywhere I place it. (addOnShow, addOnHide, addOnRealize,

For me it seems to be working when i put move and setDefaultSize in
the constructor for the window. Only move doesn't the the window
decorations in to account when positioning the window.

Unfortunately I do not have access to the constructor ;/ I'm using glade and builder...

I wonder if a callback could be added for the constructors so I could hook in to them before I build so I may be able to get things to work? (would be a static delegate for each constructor taking this and the arguments... same thing might have to happen for destructors. Also, one would want to use an array to allow for multiple entries)

What happens when you call these functions directly on the Window
returned by Builder.getObject?

That is what I'm doing except I do cast it to the Gtk type.

auto win = cast(gtk.Window.Window)builder.getObject("MainWin");

There doesn't appear to be a way to do this when using gtk.Builder, as
these functions need to be called before the window is shown.

;/ I find it very strange that they wouldn't work after the window is shown. The size is still the same.

The inspector gets the correct sizes too so there must be something off.

I imagine that this is either buggy code/flawed design or a windows problem. Glade Designer itself has issues where it obscures the taskbar and the taskbar cannot be accessed and does weird positioning and sizing... I'm always having to mess with it as it changes a lot.