Skip to content

Commit

Permalink
Implement window borders on Windows and treat window position as refe…
Browse files Browse the repository at this point in the history
…rring to the client area.

It seems unlike GTK, the menu is counted as part of the border.
  • Loading branch information
SiegeLordEx authored and SiegeLord committed Nov 7, 2023
1 parent 549f189 commit 2d1c487
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
1 change: 1 addition & 0 deletions include/allegro5/platform/aintwin.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ void _al_win_destroy_display_icons(ALLEGRO_DISPLAY *display);
/* window decorations */
void _al_win_set_window_position(HWND window, int x, int y);
void _al_win_get_window_position(HWND window, int *x, int *y);
bool _al_win_get_window_borders(ALLEGRO_DISPLAY *display, int *left, int *top, int *right, int *bottom);
bool _al_win_set_window_constraints(ALLEGRO_DISPLAY *display, int min_w, int min_h, int max_w, int max_h);
bool _al_win_get_window_constraints(ALLEGRO_DISPLAY *display, int *min_w, int *min_h, int *max_w, int *max_h);
void _al_win_apply_window_constraints(ALLEGRO_DISPLAY *display, bool onoff);
Expand Down
1 change: 1 addition & 0 deletions src/win/d3d_disp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2919,6 +2919,7 @@ ALLEGRO_DISPLAY_INTERFACE *_al_display_d3d_driver(void)
vt->set_icons = _al_win_set_display_icons;
vt->set_window_position = d3d_set_window_position;
vt->get_window_position = d3d_get_window_position;
vt->get_window_borders = _al_win_get_window_borders;
vt->set_window_constraints = _al_win_set_window_constraints;
vt->get_window_constraints = _al_win_get_window_constraints;
vt->apply_window_constraints = _al_win_apply_window_constraints;
Expand Down
1 change: 1 addition & 0 deletions src/win/wgl_disp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1563,6 +1563,7 @@ ALLEGRO_DISPLAY_INTERFACE *_al_display_wgl_driver(void)
vt.set_icons = _al_win_set_display_icons;
vt.set_window_position = wgl_set_window_position;
vt.get_window_position = wgl_get_window_position;
vt.get_window_borders = _al_win_get_window_borders;
vt.set_window_constraints = _al_win_set_window_constraints;
vt.get_window_constraints = _al_win_get_window_constraints;
vt.apply_window_constraints = _al_win_apply_window_constraints;
Expand Down
40 changes: 36 additions & 4 deletions src/win/wwindow.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,10 @@ HWND _al_win_create_window(ALLEGRO_DISPLAY *display, int width, int height, int
width+lsize+rsize,
height+tsize+bsize,
SWP_NOZORDER | SWP_NOMOVE);
SetWindowPos(my_window, 0, pos_x-lsize, pos_y-tsize,
0, 0,
SWP_NOZORDER | SWP_NOSIZE);


if (flags & ALLEGRO_FRAMELESS) {
SetWindowLong(my_window, GWL_STYLE, WS_VISIBLE);
Expand Down Expand Up @@ -1192,13 +1196,25 @@ void _al_win_destroy_display_icons(ALLEGRO_DISPLAY *display)
DestroyIcon(old_icon);
}

static void get_top_left_border(HWND window, int *left, int *top)
{
WINDOWINFO wi;
wi.cbSize = sizeof(WINDOWINFO);
GetWindowInfo(window, &wi);

*left = (wi.rcClient.left - wi.rcWindow.left);
*top = (wi.rcClient.top - wi.rcWindow.top);
}

void _al_win_set_window_position(HWND window, int x, int y)
{
int left, top;
get_top_left_border(window, &left, &top);
SetWindowPos(
window,
HWND_TOP,
x,
y,
x - left,
y - top,
0,
0,
SWP_NOSIZE | SWP_NOZORDER);
Expand All @@ -1207,13 +1223,15 @@ void _al_win_set_window_position(HWND window, int x, int y)
void _al_win_get_window_position(HWND window, int *x, int *y)
{
RECT r;
int left, top;
get_top_left_border(window, &left, &top);
GetWindowRect(window, &r);

if (x) {
*x = r.left;
*x = r.left + left;
}
if (y) {
*y = r.top;
*y = r.top + top;
}
}

Expand Down Expand Up @@ -1465,6 +1483,20 @@ int _al_win_determine_adapter(void)
return a;
}

bool _al_win_get_window_borders(ALLEGRO_DISPLAY *display, int *left, int *top, int *right, int *bottom)
{
ALLEGRO_DISPLAY_WIN *win_display = (ALLEGRO_DISPLAY_WIN *)display;
WINDOWINFO wi;
wi.cbSize = sizeof(WINDOWINFO);
GetWindowInfo(win_display->window, &wi);

if (left) *left = (wi.rcClient.left - wi.rcWindow.left);
if (top) *top = (wi.rcClient.top - wi.rcWindow.top);
if (right) *right = (wi.rcWindow.right - wi.rcClient.right);
if (bottom) *bottom = (wi.rcWindow.bottom - wi.rcClient.bottom);
return true;
}

/* Function: al_win_add_window_callback
*/
bool al_win_add_window_callback(ALLEGRO_DISPLAY *display,
Expand Down

0 comments on commit 2d1c487

Please sign in to comment.