Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add al_get_display_adapter #1580

Merged
merged 2 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: */
16 changes: 5 additions & 11 deletions src/win/wwindow.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down
Loading