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:
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?
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
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...
It would depend on what kind of window it was