Skip to content

Commit f355c7f

Browse files
committed
Allow the progress API to be used on all platforms
It's visually only hooked up on Windows for now, but the API will be internally consistent on all platforms.
1 parent b45ed98 commit f355c7f

7 files changed

+60
-90
lines changed

src/test/SDL_test_common.c

+26-3
Original file line numberDiff line numberDiff line change
@@ -2457,20 +2457,42 @@ SDL_AppResult SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const
24572457
break;
24582458
case SDLK_P:
24592459
if (withAlt) {
2460-
/* Ctrl-P Cycle through progress states */
2460+
/* Alt-P cycle through progress states */
24612461
SDL_Window *window = SDL_GetWindowFromEvent(event);
24622462
if (window) {
2463-
float progress_state = SDL_GetWindowProgressState(window);
2463+
const char *name;
2464+
SDL_ProgressState progress_state = SDL_GetWindowProgressState(window);
24642465
progress_state += 1;
24652466
if (progress_state > SDL_PROGRESS_STATE_ERROR) {
24662467
progress_state = SDL_PROGRESS_STATE_NONE;
24672468
}
2469+
switch (progress_state) {
2470+
case SDL_PROGRESS_STATE_NONE:
2471+
name = "NONE";
2472+
break;
2473+
case SDL_PROGRESS_STATE_INDETERMINATE:
2474+
name = "INDETERMINATE";
2475+
break;
2476+
case SDL_PROGRESS_STATE_NORMAL:
2477+
name = "NORMAL";
2478+
break;
2479+
case SDL_PROGRESS_STATE_PAUSED:
2480+
name = "PAUSED";
2481+
break;
2482+
case SDL_PROGRESS_STATE_ERROR:
2483+
name = "ERROR";
2484+
break;
2485+
default:
2486+
name = "UNKNOWN";
2487+
break;
2488+
}
2489+
SDL_Log("Setting progress state to %s", name);
24682490
SDL_SetWindowProgressState(window, progress_state);
24692491
}
24702492
}
24712493
else if (withControl)
24722494
{
2473-
/* Alt-P Increase progress value */
2495+
/* Ctrl-P increase progress value */
24742496
SDL_Window *window = SDL_GetWindowFromEvent(event);
24752497
if (window) {
24762498
float progress_value = SDL_GetWindowProgressValue(window);
@@ -2479,6 +2501,7 @@ SDL_AppResult SDLTest_CommonEventMainCallbacks(SDLTest_CommonState *state, const
24792501
} else {
24802502
progress_value += 0.1f;
24812503
}
2504+
SDL_Log("Setting progress value to %.1f", progress_value);
24822505
SDL_SetWindowProgressValue(window, progress_value);
24832506
}
24842507
}

src/video/SDL_sysvideo.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,9 @@ struct SDL_Window
123123
SDL_HitTest hit_test;
124124
void *hit_test_data;
125125

126+
SDL_ProgressState progress_state;
127+
float progress_value;
128+
126129
SDL_PropertiesID props;
127130

128131
int num_renderers;
@@ -303,10 +306,7 @@ struct SDL_VideoDevice
303306
void (*OnWindowEnter)(SDL_VideoDevice *_this, SDL_Window *window);
304307
bool (*UpdateWindowShape)(SDL_VideoDevice *_this, SDL_Window *window, SDL_Surface *shape);
305308
bool (*FlashWindow)(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOperation operation);
306-
bool (*SetWindowProgressState)(SDL_VideoDevice *_this, SDL_Window *window, SDL_ProgressState state);
307-
SDL_ProgressState (*GetWindowProgressState)(SDL_VideoDevice *_this, SDL_Window *window);
308-
bool (*SetWindowProgressValue)(SDL_VideoDevice *_this, SDL_Window *window, float value);
309-
float (*GetWindowProgressValue)(SDL_VideoDevice *_this, SDL_Window *window);
309+
bool (*ApplyWindowProgress)(SDL_VideoDevice *_this, SDL_Window *window);
310310
bool (*SetWindowFocusable)(SDL_VideoDevice *_this, SDL_Window *window, bool focusable);
311311
bool (*SyncWindow)(SDL_VideoDevice *_this, SDL_Window *window);
312312

src/video/SDL_video.c

+20-20
Original file line numberDiff line numberDiff line change
@@ -3930,23 +3930,23 @@ bool SDL_SetWindowProgressState(SDL_Window *window, SDL_ProgressState state)
39303930
return SDL_InvalidParamError("state");
39313931
}
39323932

3933-
if (_this->SetWindowProgressState) {
3934-
return _this->SetWindowProgressState(_this, window, state);
3933+
window->progress_state = state;
3934+
3935+
if (_this->ApplyWindowProgress) {
3936+
if (!_this->ApplyWindowProgress(_this, window)) {
3937+
return false;
3938+
}
39353939
}
39363940

3937-
return SDL_Unsupported();
3941+
return true;
39383942
}
39393943

39403944
SDL_ProgressState SDL_GetWindowProgressState(SDL_Window *window)
39413945
{
3942-
CHECK_WINDOW_MAGIC(window, false);
3943-
CHECK_WINDOW_NOT_POPUP(window, false);
3944-
3945-
if (_this->GetWindowProgressState) {
3946-
return _this->GetWindowProgressState(_this, window);
3947-
}
3946+
CHECK_WINDOW_MAGIC(window, SDL_PROGRESS_STATE_INVALID);
3947+
CHECK_WINDOW_NOT_POPUP(window, SDL_PROGRESS_STATE_INVALID);
39483948

3949-
return SDL_Unsupported();
3949+
return window->progress_state;
39503950
}
39513951

39523952
bool SDL_SetWindowProgressValue(SDL_Window *window, float value)
@@ -3956,23 +3956,23 @@ bool SDL_SetWindowProgressValue(SDL_Window *window, float value)
39563956

39573957
value = SDL_clamp(value, 0.0f, 1.f);
39583958

3959-
if (_this->SetWindowProgressValue) {
3960-
return _this->SetWindowProgressValue(_this, window, value);
3959+
window->progress_value = value;
3960+
3961+
if (_this->ApplyWindowProgress) {
3962+
if (!_this->ApplyWindowProgress(_this, window)) {
3963+
return false;
3964+
}
39613965
}
39623966

3963-
return SDL_Unsupported();
3967+
return true;
39643968
}
39653969

39663970
float SDL_GetWindowProgressValue(SDL_Window *window)
39673971
{
3968-
CHECK_WINDOW_MAGIC(window, false);
3969-
CHECK_WINDOW_NOT_POPUP(window, false);
3970-
3971-
if (_this->GetWindowProgressValue) {
3972-
return _this->GetWindowProgressValue(_this, window);
3973-
}
3972+
CHECK_WINDOW_MAGIC(window, -1.0f);
3973+
CHECK_WINDOW_NOT_POPUP(window, -1.0f);
39743974

3975-
return SDL_Unsupported();
3975+
return window->progress_value;
39763976
}
39773977

39783978
void SDL_OnWindowShown(SDL_Window *window)

src/video/windows/SDL_windowsevents.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -2437,9 +2437,8 @@ LRESULT CALLBACK WIN_WindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara
24372437

24382438
#ifdef HAVE_SHOBJIDL_CORE_H
24392439
if (msg == data->videodata->WM_TASKBAR_BUTTON_CREATED) {
2440-
SDL_Window *window = data->window;
2441-
window->internal->taskbar_button_created = true;
2442-
WIN_ApplyWindowProgress(window);
2440+
data->taskbar_button_created = true;
2441+
WIN_ApplyWindowProgress(SDL_GetVideoDevice(), data->window);
24432442
}
24442443
#endif
24452444

src/video/windows/SDL_windowsvideo.c

+1-4
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,7 @@ static SDL_VideoDevice *WIN_CreateDevice(void)
272272
device->SetWindowHitTest = WIN_SetWindowHitTest;
273273
device->AcceptDragAndDrop = WIN_AcceptDragAndDrop;
274274
device->FlashWindow = WIN_FlashWindow;
275-
device->SetWindowProgressState = WIN_SetWindowProgressState;
276-
device->GetWindowProgressState = WIN_GetWindowProgressState;
277-
device->SetWindowProgressValue = WIN_SetWindowProgressValue;
278-
device->GetWindowProgressValue = WIN_GetWindowProgressValue;
275+
device->ApplyWindowProgress = WIN_ApplyWindowProgress;
279276
device->ShowWindowSystemMenu = WIN_ShowWindowSystemMenu;
280277
device->SetWindowFocusable = WIN_SetWindowFocusable;
281278
device->UpdateWindowShape = WIN_UpdateWindowShape;

src/video/windows/SDL_windowswindow.c

+6-49
Original file line numberDiff line numberDiff line change
@@ -2245,11 +2245,9 @@ bool WIN_FlashWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOperat
22452245
return true;
22462246
}
22472247

2248-
bool WIN_ApplyWindowProgress(SDL_Window* window)
2248+
bool WIN_ApplyWindowProgress(SDL_VideoDevice *_this, SDL_Window* window)
22492249
{
2250-
#ifndef HAVE_SHOBJIDL_CORE_H
2251-
return false;
2252-
#else
2250+
#ifdef HAVE_SHOBJIDL_CORE_H
22532251
SDL_WindowData *data = window->internal;
22542252
if (!data->taskbar_button_created) {
22552253
return true;
@@ -2261,7 +2259,7 @@ bool WIN_ApplyWindowProgress(SDL_Window* window)
22612259
}
22622260

22632261
TBPFLAG tbpFlags;
2264-
switch (data->progress_state) {
2262+
switch (window->progress_state) {
22652263
case SDL_PROGRESS_STATE_NONE:
22662264
tbpFlags = TBPF_NOPROGRESS;
22672265
break;
@@ -2286,55 +2284,14 @@ bool WIN_ApplyWindowProgress(SDL_Window* window)
22862284
return WIN_SetErrorFromHRESULT("ITaskbarList3::SetProgressState()", ret);
22872285
}
22882286

2289-
if (data->progress_state >= SDL_PROGRESS_STATE_NORMAL) {
2290-
ret = taskbar_list->lpVtbl->SetProgressValue(taskbar_list, data->hwnd, (ULONGLONG)(data->progress_value * 10000.f), 10000);
2287+
if (window->progress_state >= SDL_PROGRESS_STATE_NORMAL) {
2288+
ret = taskbar_list->lpVtbl->SetProgressValue(taskbar_list, data->hwnd, (ULONGLONG)(window->progress_value * 10000.f), 10000);
22912289
if (FAILED(ret)) {
22922290
return WIN_SetErrorFromHRESULT("ITaskbarList3::SetProgressValue()", ret);
22932291
}
22942292
}
2295-
2296-
return true;
2297-
#endif
2298-
}
2299-
2300-
bool WIN_SetWindowProgressState(SDL_VideoDevice *_this, SDL_Window *window, SDL_ProgressState state)
2301-
{
2302-
#ifndef HAVE_SHOBJIDL_CORE_H
2303-
return SDL_Unsupported();
2304-
#else
2305-
window->internal->progress_state = state;
2306-
return WIN_ApplyWindowProgress(window);
2307-
#endif
2308-
}
2309-
2310-
SDL_ProgressState WIN_GetWindowProgressState(SDL_VideoDevice *_this, SDL_Window *window)
2311-
{
2312-
#ifndef HAVE_SHOBJIDL_CORE_H
2313-
SDL_Unsupported();
2314-
return SDL_PROGRESS_STATE_INVALID;
2315-
#else
2316-
return window->internal->progress_state;
2317-
#endif // HAVE_SHOBJIDL_CORE_H
2318-
}
2319-
2320-
bool WIN_SetWindowProgressValue(SDL_VideoDevice *_this, SDL_Window *window, float value)
2321-
{
2322-
#ifndef HAVE_SHOBJIDL_CORE_H
2323-
return SDL_Unsupported();
2324-
#else
2325-
window->internal->progress_value = value;
2326-
return WIN_ApplyWindowProgress(window);
23272293
#endif
2328-
}
2329-
2330-
float WIN_GetWindowProgressValue(SDL_VideoDevice *_this, SDL_Window *window)
2331-
{
2332-
#ifndef HAVE_SHOBJIDL_CORE_H
2333-
SDL_Unsupported();
2334-
return -1.0f;
2335-
#else
2336-
return window->internal->progress_value;
2337-
#endif // HAVE_SHOBJIDL_CORE_H
2294+
return true;
23382295
}
23392296

23402297
void WIN_ShowWindowSystemMenu(SDL_Window *window, int x, int y)

src/video/windows/SDL_windowswindow.h

+1-7
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,6 @@ struct SDL_WindowData
9494
SDL_Window *keyboard_focus;
9595
SDL_WindowEraseBackgroundMode hint_erase_background_mode;
9696
bool taskbar_button_created;
97-
SDL_ProgressState progress_state;
98-
float progress_value;
9997
struct SDL_VideoData *videodata;
10098
#ifdef SDL_VIDEO_OPENGL_EGL
10199
EGLSurface egl_surface;
@@ -136,11 +134,7 @@ extern void WIN_UnclipCursorForWindow(SDL_Window *window);
136134
extern bool WIN_SetWindowHitTest(SDL_Window *window, bool enabled);
137135
extern void WIN_AcceptDragAndDrop(SDL_Window *window, bool accept);
138136
extern bool WIN_FlashWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOperation operation);
139-
extern bool WIN_ApplyWindowProgress(SDL_Window *window);
140-
extern bool WIN_SetWindowProgressState(SDL_VideoDevice *_this, SDL_Window *window, SDL_ProgressState state);
141-
extern SDL_ProgressState WIN_GetWindowProgressState(SDL_VideoDevice *_this, SDL_Window *window);
142-
extern bool WIN_SetWindowProgressValue(SDL_VideoDevice *_this, SDL_Window *window, float value);
143-
extern float WIN_GetWindowProgressValue(SDL_VideoDevice *_this, SDL_Window *window);
137+
extern bool WIN_ApplyWindowProgress(SDL_VideoDevice *_this, SDL_Window *window);
144138
extern void WIN_UpdateDarkModeForHWND(HWND hwnd);
145139
extern bool WIN_SetWindowPositionInternal(SDL_Window *window, UINT flags, SDL_WindowRect rect_type);
146140
extern void WIN_ShowWindowSystemMenu(SDL_Window *window, int x, int y);

0 commit comments

Comments
 (0)