diff --git a/docs/src/refman/display.txt b/docs/src/refman/display.txt index 9daacf0eb..7d81d4da2 100644 --- a/docs/src/refman/display.txt +++ b/docs/src/refman/display.txt @@ -425,6 +425,25 @@ The default setting is zero (don't care). See also: [al_get_new_display_refresh_rate] +### API: al_get_new_display_adapter + +Gets the video adapter index where new displays +will be created by the calling thread, if previously set with +[al_set_new_display_adapter]. +Otherwise returns `ALLEGRO_DEFAULT_DISPLAY_ADAPTER`. + +See also: [al_set_new_display_adapter] + +### API: al_set_new_display_adapter + +Sets the adapter to use for new displays created by the calling thread. +The adapter has a monitor attached to it. Information +about the monitor can be gotten using [al_get_num_video_adapters] +and [al_get_monitor_info]. + +To return to the default behaviour, pass `ALLEGRO_DEFAULT_DISPLAY_ADAPTER`. + +See also: [al_get_num_video_adapters], [al_get_monitor_info] ## Display operations @@ -610,7 +629,7 @@ to new sizes to conform constraints in next cases: * The specified display is resizable, not maximized and is not in fullscreen mode. -* If the appropriate current display size (width or height) is less +* If the appropriate current display size (width or height) is less than the value of constraint. Applied to minimum constraints. * If the appropriate current display size (width or height) is greater than the value of constraint. Applied to maximum constraints. @@ -627,6 +646,12 @@ If disabled, the specified display will stop using constraints. See also: [al_get_window_constraints], [al_set_window_constraints] +### API: al_get_display_adapter + +Returns which adapter the window is currently placed on. Returns -1 if there +was an error in determining the adapter. + +Since: 5.2.10 ## Display settings diff --git a/docs/src/refman/monitor.txt b/docs/src/refman/monitor.txt index 5f911e892..2a7dec8df 100644 --- a/docs/src/refman/monitor.txt +++ b/docs/src/refman/monitor.txt @@ -28,26 +28,6 @@ typedef struct ALLEGRO_MONITOR_INFO See also: [al_get_monitor_info] -## API: al_get_new_display_adapter - -Gets the video adapter index where new displays -will be created by the calling thread, if previously set with -[al_set_new_display_adapter]. -Otherwise returns `ALLEGRO_DEFAULT_DISPLAY_ADAPTER`. - -See also: [al_set_new_display_adapter] - -## API: al_set_new_display_adapter - -Sets the adapter to use for new displays created by the calling thread. -The adapter has a monitor attached to it. Information -about the monitor can be gotten using [al_get_num_video_adapters] -and [al_get_monitor_info]. - -To return to the default behaviour, pass `ALLEGRO_DEFAULT_DISPLAY_ADAPTER`. - -See also: [al_get_num_video_adapters], [al_get_monitor_info] - ## API: al_get_monitor_info Get information about a monitor's position on the desktop. diff --git a/examples/ex_windows.c b/examples/ex_windows.c index dd8698cdd..44da6e59d 100644 --- a/examples/ex_windows.c +++ b/examples/ex_windows.c @@ -103,7 +103,8 @@ int main(int argc, char **argv) al_get_window_position(displays[i], &dx, &dy); dw = al_get_display_width(displays[i]); dh = al_get_display_height(displays[i]); - al_draw_textf(myfont, al_map_rgb(0, 0, 0), dw / 2, dh / 2 - 30, ALLEGRO_ALIGN_CENTRE, "Location: %d %d", dx, dy); + al_draw_textf(myfont, al_map_rgb(0, 0, 0), dw / 2, dh / 2 - 30, ALLEGRO_ALIGN_CENTRE, "Location: %d %d (adapter %d)", + dx, dy, al_get_display_adapter(displays[i])); if (jump_x[i] != INT_MAX && jump_y[i] != INT_MAX) { al_draw_textf(myfont, al_map_rgb(0, 0, 0), dw / 2, dh / 2 - 15, ALLEGRO_ALIGN_CENTRE, "Last jumped to: %d %d (adapter %d)", jump_x[i], jump_y[i], jump_adapter[i]); diff --git a/include/allegro5/display.h b/include/allegro5/display.h index ba5a577e7..4170061a2 100644 --- a/include/allegro5/display.h +++ b/include/allegro5/display.h @@ -157,6 +157,7 @@ AL_FUNC(void, al_set_display_icons, (ALLEGRO_DISPLAY *display, int num_icons, AL /* Stuff for multihead/window management */ AL_FUNC(int, al_get_new_display_adapter, (void)); AL_FUNC(void, al_set_new_display_adapter, (int adapter)); +AL_FUNC(int, al_get_display_adapter, (ALLEGRO_DISPLAY *display)); AL_FUNC(void, al_set_new_window_position, (int x, int y)); AL_FUNC(void, al_get_new_window_position, (int *x, int *y)); AL_FUNC(void, al_set_window_position, (ALLEGRO_DISPLAY *display, int x, int y)); diff --git a/src/display.c b/src/display.c index 7947425a9..12ab292ef 100644 --- a/src/display.c +++ b/src/display.c @@ -1,6 +1,6 @@ -/* ______ ___ ___ +/* ______ ___ ___ * /\ _ \ /\_ \ /\_ \ - * \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___ + * \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___ * \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\ * \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \ * \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/ @@ -667,4 +667,22 @@ void al_apply_window_constraints(ALLEGRO_DISPLAY *display, bool onoff) display->vt->apply_window_constraints(display, onoff); } +/* Function: al_get_display_adapter + */ +int al_get_display_adapter(ALLEGRO_DISPLAY *display) +{ + int x, y, adapter, num_adapters; + al_get_window_position(display, &x, &y); + num_adapters = al_get_num_video_adapters(); + for (adapter = 0; adapter < num_adapters; adapter++) { + ALLEGRO_MONITOR_INFO mi; + al_get_monitor_info(adapter, &mi); + if (x >= mi.x1 && x < mi.x2 && y >= mi.y1 && y < mi.y2) { + return adapter; + } + } + return -1; +} + + /* vim: set sts=3 sw=3 et: */ diff --git a/src/win/wwindow.c b/src/win/wwindow.c index f114c08e7..904b5749b 100644 --- a/src/win/wwindow.c +++ b/src/win/wwindow.c @@ -1239,17 +1239,11 @@ void _al_win_get_window_position(HWND window, int *x, int *y) static void update_adapter(ALLEGRO_DISPLAY *display) { ALLEGRO_DISPLAY_WIN *win_display = (void*)display; - int x, y, adapter, num_adapters; - al_get_window_position(display, &x, &y); - num_adapters = al_get_num_video_adapters(); - for (adapter = 0; adapter < num_adapters; adapter++) { - ALLEGRO_MONITOR_INFO mi; - al_get_monitor_info(adapter, &mi); - if (x >= mi.x1 && x < mi.x2 && y >= mi.y1 && y < mi.y2) { - win_display->adapter = adapter; - break; - } - } + int adapter = al_get_display_adapter(display); + if (adapter >= 0) + win_display->adapter = adapter; + else + win_display->adapter = 0; }