Set the window position

Hello. I’m programming on window XP service pack 2.
I need to create a window(using SDL), in (x,y) coordinates(not at random).
I have read the SDL API documentation but I can’t find any functions.

There is a solution?

Please not answer me there is a solution in X11…etc.

according to others there isa a putenv( VARIABLE ); that will do it;
but there are problems as SDL inherits the enviorment as-was when the
program is loaded. to make it work you nedd a program that will put
the variable there first or to run a batch fiel which will set the
variable and run the .exe

sorry, but i forget the name of the variable.

try the wiki.

BTW, i get the feeling the downloadable documentation is not up to
date. is this true, and if so can the updated docs be downloaded
easily?

Yes, there is a problem. I have looked into this extensively. There
is no way to position the window in a Windows™ environment once
your program has started to run. The only way to do it is to set the
environment variables before your program starts to run.

In order to do window positioning, I had to modify and recompile the source.

I hope in the next version of SDL they have the facility to set a
window position on at least create, and a function to read the window
position so it can be saved when the program quits. It is very rude
behavior in a windowed app to not remember the position the user moved
the window to.

I am guessing that most people using SDL do full-screen, and this is
why this is low priority.

Unfortunately, the lack of this one feature will probably require that
I abandon SDL for my project.

TankkoOn 5/10/05, Brian Barrett <brian.ripoff at gmail.com> wrote:

according to others there isa a putenv( VARIABLE ); that will do it;
but there are problems as SDL inherits the enviorment as-was when the
program is loaded. to make it work you nedd a program that will put
the variable there first or to run a batch fiel which will set the
variable and run the .exe

sorry, but i forget the name of the variable.

try the wiki.

BTW, i get the feeling the downloadable documentation is not up to
date. is this true, and if so can the updated docs be downloaded
easily?


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Hi

I’ve been looking at this, cannot you not use SDL_GetWMInfo to retrieve the
window manager info (which includes the handle) and then use the standard
GetWindowPos and SetWindowPos to positon the screen. I tested this on my
Windows XP machine and it works…

Dean> ----- Original Message -----

From: tankko@gmail.com (Tankko Omaskio)
To:
Sent: Wednesday, May 18, 2005 5:01 PM
Subject: Re: [SDL] Set the window position

Yes, there is a problem. I have looked into this extensively. There
is no way to position the window in a Windows™ environment once
your program has started to run. The only way to do it is to set the
environment variables before your program starts to run.

In order to do window positioning, I had to modify and recompile the source.

I hope in the next version of SDL they have the facility to set a
window position on at least create, and a function to read the window
position so it can be saved when the program quits. It is very rude
behavior in a windowed app to not remember the position the user moved
the window to.

I am guessing that most people using SDL do full-screen, and this is
why this is low priority.

Unfortunately, the lack of this one feature will probably require that
I abandon SDL for my project.

Tankko

On 5/10/05, Brian Barrett <brian.ripoff at gmail.com> wrote:

according to others there isa a putenv( VARIABLE ); that will do it;
but there are problems as SDL inherits the enviorment as-was when the
program is loaded. to make it work you nedd a program that will put
the variable there first or to run a batch fiel which will set the
variable and run the .exe

sorry, but i forget the name of the variable.

try the wiki.

BTW, i get the feeling the downloadable documentation is not up to
date. is this true, and if so can the updated docs be downloaded
easily?


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

is there something similar for linux. if i want to use this i’d love a
linux version aswell…

thanks,
brian

Try something like this (untested):

int x = 0, y = 0;

SDL_SysWMinfo info;
SDL_VERSION(&info.version);

if (SDL_GetWMInfo(&info) > 0 ) {
if (info.subsystem == SDL_SYSWM_X11) {
XMoveWindow(info.info.x11.display, info.info.x11.window, x, y);
}
}

You might add #if 's for your desired platforms.

Regards,
Johannes

< http://libufo.sourceforge.net > The OpenGL GUI ToolkitAm Donnerstag 19 Mai 2005 12:16 schrieb Brian Barrett:

is there something similar for linux. if i want to use this i’d love a
linux version aswell…

Johannes Schmidt wrote:> Am Donnerstag 19 Mai 2005 12:16 schrieb Brian Barrett:

is there something similar for linux. if i want to use this i’d love a
linux version aswell…

Try something like this (untested):

int x = 0, y = 0;

SDL_SysWMinfo info;
SDL_VERSION(&info.version);

if (SDL_GetWMInfo(&info) > 0 ) {
if (info.subsystem == SDL_SYSWM_X11) {
XMoveWindow(info.info.x11.display, info.info.x11.window, x, y);
}
}

You might add #if 's for your desired platforms.

You should lock the X display before moving the window (or doing
anything else with X), like this:

if (info.subsystem == SDL_SYSWM_X11) {
info.info.x11.lock_func();
XMoveWindow(info.info.x11.display, info.info.x11.window, x, y);
info.info.x11.unlock_func();
}

For getting the current x and y position you can use XGetWindowAttributes:

{
XWindowAttributes attr;
info.info.x11.lock_func();
XGetWindowAttributes(info.info.x11.display, info.info.x11.window,
&attr);
info.info.x11.unlock_func();
}

Window position is now in attr.x and attr.y. (There’s a whole bunch of
other stuff in there as well, see its man page for more info).

  • Gerry

You should lock the X display before moving the window (or doing
anything else with X), like this:

if (info.subsystem == SDL_SYSWM_X11) {
info.info.x11.lock_func();
XMoveWindow(info.info.x11.display, info.info.x11.window, x, y);
info.info.x11.unlock_func();
}

You should also use wmwindow, not window, as SDL uses 2 windows on X11,
one for window management, and one for graphics output.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment