mirror of https://github.com/libsdl-org/SDL.git
Added SDL_EVENT_DISPLAY_DESKTOP_MODE_CHANGED and SDL_EVENT_DISPLAY_CURRENT_MODE_CHANGED
This commit is contained in:
parent
3f446a12df
commit
1162a1cb8e
|
|
@ -115,6 +115,8 @@ typedef enum SDL_EventType
|
||||||
SDL_EVENT_DISPLAY_ADDED, /**< Display has been added to the system */
|
SDL_EVENT_DISPLAY_ADDED, /**< Display has been added to the system */
|
||||||
SDL_EVENT_DISPLAY_REMOVED, /**< Display has been removed from the system */
|
SDL_EVENT_DISPLAY_REMOVED, /**< Display has been removed from the system */
|
||||||
SDL_EVENT_DISPLAY_MOVED, /**< Display has changed position */
|
SDL_EVENT_DISPLAY_MOVED, /**< Display has changed position */
|
||||||
|
SDL_EVENT_DISPLAY_DESKTOP_MODE_CHANGED, /**< Display has changed desktop mode */
|
||||||
|
SDL_EVENT_DISPLAY_CURRENT_MODE_CHANGED, /**< Display has changed current mode */
|
||||||
SDL_EVENT_DISPLAY_CONTENT_SCALE_CHANGED, /**< Display has changed content scale */
|
SDL_EVENT_DISPLAY_CONTENT_SCALE_CHANGED, /**< Display has changed content scale */
|
||||||
SDL_EVENT_DISPLAY_FIRST = SDL_EVENT_DISPLAY_ORIENTATION,
|
SDL_EVENT_DISPLAY_FIRST = SDL_EVENT_DISPLAY_ORIENTATION,
|
||||||
SDL_EVENT_DISPLAY_LAST = SDL_EVENT_DISPLAY_CONTENT_SCALE_CHANGED,
|
SDL_EVENT_DISPLAY_LAST = SDL_EVENT_DISPLAY_CONTENT_SCALE_CHANGED,
|
||||||
|
|
@ -281,6 +283,7 @@ typedef struct SDL_DisplayEvent
|
||||||
Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
|
Uint64 timestamp; /**< In nanoseconds, populated using SDL_GetTicksNS() */
|
||||||
SDL_DisplayID displayID;/**< The associated display */
|
SDL_DisplayID displayID;/**< The associated display */
|
||||||
Sint32 data1; /**< event dependent data */
|
Sint32 data1; /**< event dependent data */
|
||||||
|
Sint32 data2; /**< event dependent data */
|
||||||
} SDL_DisplayEvent;
|
} SDL_DisplayEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -991,7 +991,7 @@ JNIEXPORT void JNICALL SDL_JAVA_INTERFACE(onNativeRotationChanged)(
|
||||||
|
|
||||||
if (Android_Window) {
|
if (Android_Window) {
|
||||||
SDL_VideoDisplay *display = SDL_GetVideoDisplay(SDL_GetPrimaryDisplay());
|
SDL_VideoDisplay *display = SDL_GetVideoDisplay(SDL_GetPrimaryDisplay());
|
||||||
SDL_SendDisplayEvent(display, SDL_EVENT_DISPLAY_ORIENTATION, displayCurrentOrientation);
|
SDL_SendDisplayEvent(display, SDL_EVENT_DISPLAY_ORIENTATION, displayCurrentOrientation, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_UnlockMutex(Android_ActivityMutex);
|
SDL_UnlockMutex(Android_ActivityMutex);
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,7 @@
|
||||||
|
|
||||||
#include "SDL_events_c.h"
|
#include "SDL_events_c.h"
|
||||||
|
|
||||||
int SDL_SendDisplayEvent(SDL_VideoDisplay *display, SDL_EventType displayevent, int data1)
|
int SDL_SendDisplayEvent(SDL_VideoDisplay *display, SDL_EventType displayevent, int data1, int data2)
|
||||||
{
|
{
|
||||||
int posted;
|
int posted;
|
||||||
|
|
||||||
|
|
@ -50,6 +50,7 @@ int SDL_SendDisplayEvent(SDL_VideoDisplay *display, SDL_EventType displayevent,
|
||||||
event.common.timestamp = 0;
|
event.common.timestamp = 0;
|
||||||
event.display.displayID = display->id;
|
event.display.displayID = display->id;
|
||||||
event.display.data1 = data1;
|
event.display.data1 = data1;
|
||||||
|
event.display.data2 = data2;
|
||||||
posted = (SDL_PushEvent(&event) > 0);
|
posted = (SDL_PushEvent(&event) > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,6 @@
|
||||||
#ifndef SDL_displayevents_c_h_
|
#ifndef SDL_displayevents_c_h_
|
||||||
#define SDL_displayevents_c_h_
|
#define SDL_displayevents_c_h_
|
||||||
|
|
||||||
extern int SDL_SendDisplayEvent(SDL_VideoDisplay *display, SDL_EventType displayevent, int data1);
|
extern int SDL_SendDisplayEvent(SDL_VideoDisplay *display, SDL_EventType displayevent, int data1, int data2);
|
||||||
|
|
||||||
#endif /* SDL_displayevents_c_h_ */
|
#endif /* SDL_displayevents_c_h_ */
|
||||||
|
|
|
||||||
|
|
@ -285,13 +285,15 @@ static void SDL_LogEvent(const SDL_Event *event)
|
||||||
#define SDL_DISPLAYEVENT_CASE(x) \
|
#define SDL_DISPLAYEVENT_CASE(x) \
|
||||||
case x: \
|
case x: \
|
||||||
SDL_strlcpy(name, #x, sizeof(name)); \
|
SDL_strlcpy(name, #x, sizeof(name)); \
|
||||||
(void)SDL_snprintf(details, sizeof(details), " (timestamp=%u display=%u event=%s data1=%d)", \
|
(void)SDL_snprintf(details, sizeof(details), " (timestamp=%u display=%u event=%s data1=%d, data2=%d)", \
|
||||||
(uint)event->display.timestamp, (uint)event->display.displayID, name, (int)event->display.data1); \
|
(uint)event->display.timestamp, (uint)event->display.displayID, name, (int)event->display.data1, (int)event->display.data2); \
|
||||||
break
|
break
|
||||||
SDL_DISPLAYEVENT_CASE(SDL_EVENT_DISPLAY_ORIENTATION);
|
SDL_DISPLAYEVENT_CASE(SDL_EVENT_DISPLAY_ORIENTATION);
|
||||||
SDL_DISPLAYEVENT_CASE(SDL_EVENT_DISPLAY_ADDED);
|
SDL_DISPLAYEVENT_CASE(SDL_EVENT_DISPLAY_ADDED);
|
||||||
SDL_DISPLAYEVENT_CASE(SDL_EVENT_DISPLAY_REMOVED);
|
SDL_DISPLAYEVENT_CASE(SDL_EVENT_DISPLAY_REMOVED);
|
||||||
SDL_DISPLAYEVENT_CASE(SDL_EVENT_DISPLAY_MOVED);
|
SDL_DISPLAYEVENT_CASE(SDL_EVENT_DISPLAY_MOVED);
|
||||||
|
SDL_DISPLAYEVENT_CASE(SDL_EVENT_DISPLAY_DESKTOP_MODE_CHANGED);
|
||||||
|
SDL_DISPLAYEVENT_CASE(SDL_EVENT_DISPLAY_CURRENT_MODE_CHANGED);
|
||||||
SDL_DISPLAYEVENT_CASE(SDL_EVENT_DISPLAY_CONTENT_SCALE_CHANGED);
|
SDL_DISPLAYEVENT_CASE(SDL_EVENT_DISPLAY_CONTENT_SCALE_CHANGED);
|
||||||
#undef SDL_DISPLAYEVENT_CASE
|
#undef SDL_DISPLAYEVENT_CASE
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1563,7 +1563,7 @@ static void SDLTest_PrintEvent(const SDL_Event *event)
|
||||||
{
|
{
|
||||||
switch (event->type) {
|
switch (event->type) {
|
||||||
case SDL_EVENT_SYSTEM_THEME_CHANGED:
|
case SDL_EVENT_SYSTEM_THEME_CHANGED:
|
||||||
SDL_Log("SDL EVENT: System theme changed to %s\n", SystemThemeName());
|
SDL_Log("SDL EVENT: System theme changed to %s", SystemThemeName());
|
||||||
break;
|
break;
|
||||||
case SDL_EVENT_DISPLAY_ADDED:
|
case SDL_EVENT_DISPLAY_ADDED:
|
||||||
SDL_Log("SDL EVENT: Display %" SDL_PRIu32 " attached",
|
SDL_Log("SDL EVENT: Display %" SDL_PRIu32 " attached",
|
||||||
|
|
@ -1576,6 +1576,14 @@ static void SDLTest_PrintEvent(const SDL_Event *event)
|
||||||
event->display.displayID, (int)(scale * 100.0f));
|
event->display.displayID, (int)(scale * 100.0f));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case SDL_EVENT_DISPLAY_DESKTOP_MODE_CHANGED:
|
||||||
|
SDL_Log("SDL EVENT: Display %" SDL_PRIu32 " desktop mode changed to %" SDL_PRIs32 "x%" SDL_PRIs32,
|
||||||
|
event->display.displayID, event->display.data1, event->display.data2);
|
||||||
|
break;
|
||||||
|
case SDL_EVENT_DISPLAY_CURRENT_MODE_CHANGED:
|
||||||
|
SDL_Log("SDL EVENT: Display %" SDL_PRIu32 " current mode changed to %" SDL_PRIs32 "x%" SDL_PRIs32,
|
||||||
|
event->display.displayID, event->display.data1, event->display.data2);
|
||||||
|
break;
|
||||||
case SDL_EVENT_DISPLAY_MOVED:
|
case SDL_EVENT_DISPLAY_MOVED:
|
||||||
SDL_Log("SDL EVENT: Display %" SDL_PRIu32 " changed position",
|
SDL_Log("SDL EVENT: Display %" SDL_PRIu32 " changed position",
|
||||||
event->display.displayID);
|
event->display.displayID);
|
||||||
|
|
|
||||||
|
|
@ -791,7 +791,7 @@ SDL_DisplayID SDL_AddVideoDisplay(const SDL_VideoDisplay *display, SDL_bool send
|
||||||
SDL_UpdateDesktopBounds();
|
SDL_UpdateDesktopBounds();
|
||||||
|
|
||||||
if (send_event) {
|
if (send_event) {
|
||||||
SDL_SendDisplayEvent(new_display, SDL_EVENT_DISPLAY_ADDED, 0);
|
SDL_SendDisplayEvent(new_display, SDL_EVENT_DISPLAY_ADDED, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
|
|
@ -823,7 +823,7 @@ void SDL_DelVideoDisplay(SDL_DisplayID displayID, SDL_bool send_event)
|
||||||
display = _this->displays[display_index];
|
display = _this->displays[display_index];
|
||||||
|
|
||||||
if (send_event) {
|
if (send_event) {
|
||||||
SDL_SendDisplayEvent(display, SDL_EVENT_DISPLAY_REMOVED, 0);
|
SDL_SendDisplayEvent(display, SDL_EVENT_DISPLAY_REMOVED, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_DestroyProperties(display->props);
|
SDL_DestroyProperties(display->props);
|
||||||
|
|
@ -1044,7 +1044,7 @@ void SDL_SetDisplayContentScale(SDL_VideoDisplay *display, float scale)
|
||||||
SDL_Window *window;
|
SDL_Window *window;
|
||||||
|
|
||||||
display->content_scale = scale;
|
display->content_scale = scale;
|
||||||
SDL_SendDisplayEvent(display, SDL_EVENT_DISPLAY_CONTENT_SCALE_CHANGED, 0);
|
SDL_SendDisplayEvent(display, SDL_EVENT_DISPLAY_CONTENT_SCALE_CHANGED, 0, 0);
|
||||||
|
|
||||||
/* Check the windows on this display */
|
/* Check the windows on this display */
|
||||||
for (window = _this->windows; window; window = window->next) {
|
for (window = _this->windows; window; window = window->next) {
|
||||||
|
|
@ -1310,14 +1310,34 @@ const SDL_DisplayMode *SDL_GetClosestFullscreenDisplayMode(SDL_DisplayID display
|
||||||
return closest;
|
return closest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static SDL_bool DisplayModeChanged(const SDL_DisplayMode *old, const SDL_DisplayMode *new)
|
||||||
|
{
|
||||||
|
return ((old->displayID && old->displayID != new->displayID) ||
|
||||||
|
(old->format && old->format != new->format) ||
|
||||||
|
(old->w && old->h && (old->w != new->w ||old->h != new->h)) ||
|
||||||
|
(old->pixel_density != 0.0f && old->pixel_density != new->pixel_density) ||
|
||||||
|
(old->refresh_rate != 0.0f && old->refresh_rate != new->refresh_rate));
|
||||||
|
}
|
||||||
|
|
||||||
void SDL_SetDesktopDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode)
|
void SDL_SetDesktopDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode)
|
||||||
{
|
{
|
||||||
|
SDL_DisplayMode last_mode;
|
||||||
|
|
||||||
|
SDL_copyp(&last_mode, &display->desktop_mode);
|
||||||
|
|
||||||
if (display->desktop_mode.driverdata) {
|
if (display->desktop_mode.driverdata) {
|
||||||
SDL_free(display->desktop_mode.driverdata);
|
SDL_free(display->desktop_mode.driverdata);
|
||||||
}
|
}
|
||||||
SDL_memcpy(&display->desktop_mode, mode, sizeof(*mode));
|
SDL_copyp(&display->desktop_mode, mode);
|
||||||
display->desktop_mode.displayID = display->id;
|
display->desktop_mode.displayID = display->id;
|
||||||
SDL_FinalizeDisplayMode(&display->desktop_mode);
|
SDL_FinalizeDisplayMode(&display->desktop_mode);
|
||||||
|
|
||||||
|
if (DisplayModeChanged(&last_mode, &display->desktop_mode)) {
|
||||||
|
SDL_SendDisplayEvent(display, SDL_EVENT_DISPLAY_DESKTOP_MODE_CHANGED, mode->w, mode->h);
|
||||||
|
if (display->current_mode == &display->desktop_mode) {
|
||||||
|
SDL_SendDisplayEvent(display, SDL_EVENT_DISPLAY_CURRENT_MODE_CHANGED, mode->w, mode->h);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const SDL_DisplayMode *SDL_GetDesktopDisplayMode(SDL_DisplayID displayID)
|
const SDL_DisplayMode *SDL_GetDesktopDisplayMode(SDL_DisplayID displayID)
|
||||||
|
|
@ -1331,7 +1351,19 @@ const SDL_DisplayMode *SDL_GetDesktopDisplayMode(SDL_DisplayID displayID)
|
||||||
|
|
||||||
void SDL_SetCurrentDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode)
|
void SDL_SetCurrentDisplayMode(SDL_VideoDisplay *display, const SDL_DisplayMode *mode)
|
||||||
{
|
{
|
||||||
|
SDL_DisplayMode last_mode;
|
||||||
|
|
||||||
|
if (display->current_mode) {
|
||||||
|
SDL_copyp(&last_mode, display->current_mode);
|
||||||
|
} else {
|
||||||
|
SDL_zero(last_mode);
|
||||||
|
}
|
||||||
|
|
||||||
display->current_mode = mode;
|
display->current_mode = mode;
|
||||||
|
|
||||||
|
if (DisplayModeChanged(&last_mode, mode)) {
|
||||||
|
SDL_SendDisplayEvent(display, SDL_EVENT_DISPLAY_CURRENT_MODE_CHANGED, mode->w, mode->h);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const SDL_DisplayMode *SDL_GetCurrentDisplayMode(SDL_DisplayID displayID)
|
const SDL_DisplayMode *SDL_GetCurrentDisplayMode(SDL_DisplayID displayID)
|
||||||
|
|
|
||||||
|
|
@ -534,7 +534,7 @@ void SDL_OnApplicationDidChangeStatusBarOrientation(void)
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
SDL_SendDisplayEvent(display, SDL_EVENT_DISPLAY_ORIENTATION, orientation);
|
SDL_SendDisplayEvent(display, SDL_EVENT_DISPLAY_ORIENTATION, orientation, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif /* !SDL_PLATFORM_TVOS */
|
#endif /* !SDL_PLATFORM_TVOS */
|
||||||
|
|
|
||||||
|
|
@ -905,7 +905,7 @@ static void display_handle_done(void *data,
|
||||||
SDL_zero(driverdata->placeholder);
|
SDL_zero(driverdata->placeholder);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
SDL_SendDisplayEvent(dpy, SDL_EVENT_DISPLAY_ORIENTATION, driverdata->orientation);
|
SDL_SendDisplayEvent(dpy, SDL_EVENT_DISPLAY_ORIENTATION, driverdata->orientation, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -538,9 +538,9 @@ static void WIN_AddDisplay(SDL_VideoDevice *_this, HMONITOR hMonitor, const MONI
|
||||||
SDL_copyp(&driverdata->bounds, &bounds);
|
SDL_copyp(&driverdata->bounds, &bounds);
|
||||||
}
|
}
|
||||||
if (moved || changed_bounds) {
|
if (moved || changed_bounds) {
|
||||||
SDL_SendDisplayEvent(existing_display, SDL_EVENT_DISPLAY_MOVED, 0);
|
SDL_SendDisplayEvent(existing_display, SDL_EVENT_DISPLAY_MOVED, 0, 0);
|
||||||
}
|
}
|
||||||
SDL_SendDisplayEvent(existing_display, SDL_EVENT_DISPLAY_ORIENTATION, current_orientation);
|
SDL_SendDisplayEvent(existing_display, SDL_EVENT_DISPLAY_ORIENTATION, current_orientation, 0);
|
||||||
SDL_SetDisplayContentScale(existing_display, content_scale);
|
SDL_SetDisplayContentScale(existing_display, content_scale);
|
||||||
#ifdef HAVE_DXGI1_6_H
|
#ifdef HAVE_DXGI1_6_H
|
||||||
SDL_HDROutputProperties HDR;
|
SDL_HDROutputProperties HDR;
|
||||||
|
|
@ -832,7 +832,7 @@ void WIN_RefreshDisplays(SDL_VideoDevice *_this)
|
||||||
SDL_VideoDisplay *display = _this->displays[i];
|
SDL_VideoDisplay *display = _this->displays[i];
|
||||||
SDL_DisplayData *driverdata = display->driverdata;
|
SDL_DisplayData *driverdata = display->driverdata;
|
||||||
if (driverdata->state == DisplayAdded) {
|
if (driverdata->state == DisplayAdded) {
|
||||||
SDL_SendDisplayEvent(display, SDL_EVENT_DISPLAY_ADDED, 0);
|
SDL_SendDisplayEvent(display, SDL_EVENT_DISPLAY_ADDED, 0, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue