|
al_set_new_window_position / al_get_window_position mismatch |
amarillion
Member #940
January 2001
|
I noticed a funny surprise with al_set_new_window_position / al_get_window_position. I wanted to make my program save the window position at exit, so the window can be restored at the same position again the next time. // at initialization // read x, y, w, h from a config file al_set_new_display_flags(ALLEGRO_WINDOWED | ALLEGRO_RESIZABLE); al_set_new_window_position(x, y); ALLEGRO_DISPLAY *display = al_create_display(w, h); // at shutdown int x, y al_get_window_position(display, &x, &y); w = al_get_display_width(display); h = al_get_display_height(display); // write x, y, w, h to config file Full code here: https://github.com/amarillion/ex_window_pos The surprising thing is that, even if I don't move or resize the window, the coordinates returned by al_get_window_position are not the same as the ones I pass into al_set_new_window_position. The effect is different on windows and linux. Here are repeated invocations of the program without moving the window: 1On Linux:
2
3martijn@siepie:~/prg/alleg/bug-window-position$ ./ex_window_pos
4Reading window position: 2147483647,2147483647: 640x480
5Saving window position: 630,303: 640x480
6
7martijn@siepie:~/prg/alleg/bug-window-position$ ./ex_window_pos
8Reading window position: 630,303: 640x480
9Saving window position: 630,327: 640x480
10
11martijn@siepie:~/prg/alleg/bug-window-position$ ./ex_window_pos
12Reading window position: 630,327: 640x480
13Saving window position: 630,351: 640x480
14
15martijn@siepie:~/prg/alleg/bug-window-position$ ./ex_window_pos
16Reading window position: 630,351: 640x480
17Saving window position: 630,375: 640x480
18
19On Windows:
20
21Martijn@Cheshire MINGW32 /z/prg/ex_window_pos
22$ ./ex_window_pos.exe
23Reading window position: 2147483647,2147483647: 640x480
24Saving window position: 630,267: 640x480
25
26Martijn@Cheshire MINGW32 /z/prg/ex_window_pos
27$ ./ex_window_pos.exe
28Reading window position: 630,267: 640x480
29Saving window position: 620,234: 640x480
30
31Martijn@Cheshire MINGW32 /z/prg/ex_window_pos
32$ ./ex_window_pos.exe
33Reading window position: 620,234: 640x480
34Saving window position: 610,201: 640x480
35
36Martijn@Cheshire MINGW32 /z/prg/ex_window_pos
37$ ./ex_window_pos.exe
38Reading window position: 610,201: 640x480
39Saving window position: 600,168: 640x480
On windows, the window is shifted slightly up and left each time. After a while the window is created in negative territory, which is annoying because you can no longer reach the title bar to move the window. On linux, the window is shifted down each time. I assume the problem is that al_set_window_position is not properly taking into account the title bar. Is there any way to account for this difference? -- |
Aldrik
Member #16,925
December 2018
|
I have used below code in my own project before, might fix the issue. height + GetSystemMetrics(SM_CYSIZE) + GetSystemMetrics(SM_CYFRAME); https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getsystemmetrics |
amarillion
Member #940
January 2001
|
Good suggestion, thanks! I just need something similar for linux too. Wouldn't it be a good idea to build this into the al_set_new_window_position function itself? I could start working on a patch... -- |
Edgar Reynaldo
Major Reynaldo
May 2007
|
It would depend on what kind of window it was My Website! | EAGLE GUI Library Demos | My Deviant Art Gallery | Spiraloid Preview | A4 FontMaker | Skyline! (Missile Defense) Eagle and Allegro 5 binaries | Older Allegro 4 and 5 binaries | Allegro 5 compile guide |
|