Skip to content

Commit

Permalink
Add al_get_display_adapter
Browse files Browse the repository at this point in the history
Move the docs for the new adapter from "Monitor" to "Displays".

Fixes #1578
  • Loading branch information
SiegeLordEx authored and SiegeLord committed Sep 14, 2024
1 parent 793d2af commit 4b3ad00
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 24 deletions.
27 changes: 26 additions & 1 deletion docs/src/refman/display.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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

Expand Down
20 changes: 0 additions & 20 deletions docs/src/refman/monitor.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion examples/ex_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down
1 change: 1 addition & 0 deletions include/allegro5/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
22 changes: 20 additions & 2 deletions src/display.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* ______ ___ ___
/* ______ ___ ___
* /\ _ \ /\_ \ /\_ \
* \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___
* \ \ \L\ \\//\ \ \//\ \ __ __ _ __ ___
* \ \ __ \ \ \ \ \ \ \ /'__`\ /'_ `\/\`'__\/ __`\
* \ \ \/\ \ \_\ \_ \_\ \_/\ __//\ \L\ \ \ \//\ \L\ \
* \ \_\ \_\/\____\/\____\ \____\ \____ \ \_\\ \____/
Expand Down Expand Up @@ -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: */

0 comments on commit 4b3ad00

Please sign in to comment.