# Window Postition question

**URL:** <https://discourse.libsdl.org/t/window-postition-question/7236>\
**Category:** SDL Development\
**Created:** [August 11, 2002, 4:58pm UTC](https://discourse.libsdl.org/t/window-postition-question/7236 "2002-08-11T16:58:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jason\_Farmer](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/j/a88e57/32.png) [@Jason\_Farmer](https://discourse.libsdl.org/u/Jason_Farmer)\
**Post date:** [August 11, 2002, 4:58pm UTC](https://discourse.libsdl.org/t/window-postition-question/7236/1 "2002-08-11T16:58:00Z")

</div>

Hi all,

I have a simple question.  
How do I programatically set the position of my SDL window?

I’m writing an editor for my game that uses the game engine to display the  
levels. I’ve got other forms that surround the form for tools and so on

But the SDL window seems to appear at random co-ordinates each time I run it.  
Is there anyway I can fix its position?

Thanks in advance

Later

Jason

---

<div class="post-metadata">

**Author:** ![Jan\_Kratochvil](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/j/9e8a1a/32.png) [@Jan\_Kratochvil](https://discourse.libsdl.org/u/Jan_Kratochvil)\
**Post date:** [August 12, 2002, 1:37am UTC](https://discourse.libsdl.org/t/window-postition-question/7236/2 "2002-08-12T01:37:00Z")

</div>

> But the SDL window seems to appear at random co-ordinates each time I run it.  
> Is there anyway I can fix its position?

i am not sure but i think that this depend on window manager so you can do  
it as platform specific code i.e for windows or for KDE.  
Am i right?

---

<div class="post-metadata">

**Author:** ![Jason\_Farmer](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/j/a88e57/32.png) [@Jason\_Farmer](https://discourse.libsdl.org/u/Jason_Farmer)\
**Post date:** [August 12, 2002, 3:48pm UTC](https://discourse.libsdl.org/t/window-postition-question/7236/3 "2002-08-12T15:48:01Z")

</div>

Well, I’m actually looking for a cross platform and window manager independent  
method of programatically controlling the window position.

If I’ve got to code separate Win32 API calls for windows and Xwindows calls  
for Linux then so be it, but I certainly don’t want to have to code for every  
window manager as well. KDE is one thing, but Gnome can use loads of  
different window managers if I remember correctly.

Has anyone else done this?

has anyone got any code?  
I work in Pascal, but I’m fluent enough in C to convert it.

Cheers

Jason\> \> But the SDL window seems to appear at random co-ordinates each time I run

> > it. Is there anyway I can fix its position?
> 
> i am not sure but i think that this depend on window manager so you can do  
> it as platform specific code i.e for windows or for KDE.  
> Am i right?
> 
> * * *
> 
> SDL mailing list  
> SDL at [libsdl.org](http://libsdl.org)  
> [http://www.libsdl.org/mailman/listinfo/sdl](http://www.libsdl.org/mailman/listinfo/sdl)

---

<div class="post-metadata">

**Author:** ![Stephen\_Anthony](https://discourse.libsdl.org/user_avatar/discourse.libsdl.org/stephen_anthony/32/2866_2.png) [@Stephen\_Anthony](https://discourse.libsdl.org/u/Stephen_Anthony)\
**Post date:** [August 12, 2002, 4:01pm UTC](https://discourse.libsdl.org/t/window-postition-question/7236/4 "2002-08-12T16:01:01Z")

</div>

> Well, I’m actually looking for a cross platform and window manager  
> independent method of programatically controlling the window position.
> 
> If I’ve got to code separate Win32 API calls for windows and Xwindows  
> calls for Linux then so be it, but I certainly don’t want to have to  
> code for every window manager as well. KDE is one thing, but Gnome can  
> use loads of different window managers if I remember correctly.
> 
> Has anyone else done this?
> 
> has anyone got any code?  
> I work in Pascal, but I’m fluent enough in C to convert it.

> From the Stella source code (originally from some example on the SDL  
> page):

SDL\_SysWMinfo info;

SDL\_VERSION(&info.version);  
if(SDL\_GetWMInfo(&info) \> 0)  
if(info.subsystem == SDL\_SYSWM\_X11)  
x11Available = true;

int x, y, w, h;  
info.info.x11.lock\_func();  
theX11Display = info.info.x11.display;  
theX11Window = info.info.x11.wmwindow;  
theX11Screen = DefaultScreen(theX11Display);

w = DisplayWidth(theX11Display, theX11Screen);  
h = DisplayHeight(theX11Display, theX11Screen);  
x = (w - screen-\>w)/2;  
y = (h - screen-\>h)/2;

XMoveWindow(theX11Display, theX11Window, x, y);  
info.info.x11.unlock\_func();

This code actually centers the window onscreen. You can use it to place  
the window whereever you want.

Of course, this only works under X11 in Linux. Don’t know about other  
windowing systems.

SteveOn August 12, 2002 09:12 pm, Jason Farmer wrote:
