History

Fullscreen bugfixes + others + cleanup

Olav Sørensen committed 4 years ago

Commit fc625eb1 parent c5819c67 files · +97 −66Browse files

Unified · Split

7 files
  1. src/pt2_audio.h +2 −2
  2. src/pt2_header.h +1 −1
  3. src/pt2_keyboard.c +2 −2
  4. src/pt2_main.c +14 −8
  5. src/pt2_mouse.c +2 −0
  6. src/pt2_visuals.c +75 −52
  7. src/pt2_visuals.h +1 −1
src/pt2_audio.h+2−2
@@ -29,13 +29,13 @@ typedef struct voice_t · 28 unmodified lines
29 29
30 // internal values (don't modify directly!)30 // internal values (don't modify directly!)
31 int8_t AUD_DAT[2]; // DMA data buffer31 int8_t AUD_DAT[2]; // DMA data buffer
32 const int8_t* location; // current location32 const int8_t *location; // current location
33 uint16_t lengthCounter; // current length33 uint16_t lengthCounter; // current length
34 int32_t sampleCounter; // how many bytes left in AUD_DAT34 int32_t sampleCounter; // how many bytes left in AUD_DAT
35 double dSample; // current sample point35 double dSample; // current sample point
36 36
37 // registers modified by Paula functions37 // registers modified by Paula functions
38 const int8_t* AUD_LC; // location38 const int8_t *AUD_LC; // location
39 uint16_t AUD_LEN; // length (in words)39 uint16_t AUD_LEN; // length (in words)
40 double AUD_PER_delta, AUD_PER_deltamul; // delta40 double AUD_PER_delta, AUD_PER_deltamul; // delta
41 double AUD_VOL; // volume41 double AUD_VOL; // volume
src/pt2_header.h+1−1
@@ -14,7 +14,7 @@ · 13 unmodified lines
14#include "pt2_unicode.h"14#include "pt2_unicode.h"
15#include "pt2_palette.h"15#include "pt2_palette.h"
16 16
17#define PROG_VER_STR "1.49"17#define PROG_VER_STR "1.50"
18 18
19#ifdef _WIN3219#ifdef _WIN32
20#define DIR_DELIMITER '\\'20#define DIR_DELIMITER '\\'
src/pt2_keyboard.c+2−2
@@ -364,7 +364,7 @@ void keyDownHandler(SDL_Scancode scancode, SDL_Keycode keycode) · 363 unmodified lines
364 // TOGGLE FULLSCREEN (should always react)364 // TOGGLE FULLSCREEN (should always react)
365 if (scancode == SDL_SCANCODE_F11 && !keyb.leftAltPressed)365 if (scancode == SDL_SCANCODE_F11 && !keyb.leftAltPressed)
366 {366 {
367 toggleFullScreen();367 toggleFullscreen();
368 368
369 // prevent fullscreen toggle from firing twice on certain SDL2 Linux ports369 // prevent fullscreen toggle from firing twice on certain SDL2 Linux ports
370#ifdef __unix__370#ifdef __unix__
@@ -2289,7 +2289,7 @@ void keyDownHandler(SDL_Scancode scancode, SDL_Keycode keycode) · 1918 unmodified lines
2289#ifdef __APPLE__2289#ifdef __APPLE__
2290 if (keyb.leftCommandPressed && keyb.leftCtrlPressed)2290 if (keyb.leftCommandPressed && keyb.leftCtrlPressed)
2291 {2291 {
2292 toggleFullScreen();2292 toggleFullscreen();
2293 }2293 }
2294 else2294 else
2295#endif2295#endif
src/pt2_main.c+14−8
@@ -44,7 +44,7 @@ · 43 unmodified lines
44 44
45module_t *song = NULL; // globalized45module_t *song = NULL; // globalized
46 46
47static bool backupMadeAfterCrash;47static bool backupMadeAfterCrash, didDropFile;
48 48
49#ifdef _WIN3249#ifdef _WIN32
50#define SYSMSG_FILE_ARG (WM_USER + 1)50#define SYSMSG_FILE_ARG (WM_USER + 1)
@@ -324,7 +324,7 @@ int main(int argc, char *argv[]) · 273 unmodified lines
324 SDL_ShowWindow(video.window);324 SDL_ShowWindow(video.window);
325 325
326 if (config.startInFullscreen)326 if (config.startInFullscreen)
327 toggleFullScreen();327 toggleFullscreen();
328 328
329 changePathToHome(); // set path to home/user-dir now329 changePathToHome(); // set path to home/user-dir now
330 diskOpSetInitPath(); // set path to custom path in config (if present)330 diskOpSetInitPath(); // set path to custom path in config (if present)
@@ -400,7 +400,10 @@ static void handleInput(void) · 69 unmodified lines
400 {400 {
401 loadDroppedFile(event.drop.file, (uint32_t)strlen(event.drop.file), false, true);401 loadDroppedFile(event.drop.file, (uint32_t)strlen(event.drop.file), false, true);
402 SDL_free(event.drop.file);402 SDL_free(event.drop.file);
403 SDL_RaiseWindow(video.window); // set window focus403
404 // kludge: allow focus-clickthrough after drag-n-drop
405 SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1");
406 didDropFile = true;
404 }407 }
405 if (event.type == SDL_QUIT)408 if (event.type == SDL_QUIT)
406 {409 {
@@ -426,15 +429,18 @@ static void handleInput(void) · 19 unmodified lines
426 429
427 ui.introScreenShown = false;430 ui.introScreenShown = false;
428 }431 }
432
433 // kludge: we drag-n-dropped a file before this mouse click release, restore focus-clickthrough mode
434 if (didDropFile)
435 {
436 didDropFile = false;
437 SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "0");
438 }
429 }439 }
430 else if (event.type == SDL_MOUSEBUTTONDOWN)440 else if (event.type == SDL_MOUSEBUTTONDOWN)
431 {441 {
432 if (ui.sampleMarkingPos == -1 &&442 if (ui.sampleMarkingPos == -1 && !ui.forceSampleDrag && !ui.forceVolDrag && !ui.forceSampleEdit)
433 !ui.forceSampleDrag && !ui.forceVolDrag &&
434 !ui.forceSampleEdit)
435 {
436 mouseButtonDownHandler(event.button.button);443 mouseButtonDownHandler(event.button.button);
437 }
438 }444 }
439 445
440 if (ui.throwExit)446 if (ui.throwExit)
src/pt2_mouse.c+2−0
@@ -272,11 +272,13 @@ void readMouseXY(void) · 271 unmodified lines
272 272
273 // convert desktop coords to window coords273 // convert desktop coords to window coords
274 SDL_GetWindowPosition(video.window, &windowX, &windowY);274 SDL_GetWindowPosition(video.window, &windowX, &windowY);
275
275 mx -= windowX;276 mx -= windowX;
276 my -= windowY;277 my -= windowY;
277 }278 }
278 else279 else
279 {280 {
281 // special mode for KMSDRM (XXX: Confirm that this still works...)
280 mouse.buttonState = SDL_GetMouseState(&mx, &my);282 mouse.buttonState = SDL_GetMouseState(&mx, &my);
281 }283 }
282 284
src/pt2_visuals.c+75−52
@@ -2133,13 +2133,13 @@ void flipFrame(void) · 2132 unmodified lines
2133void updateSpectrumAnalyzer(int8_t vol, int16_t period)2133void updateSpectrumAnalyzer(int8_t vol, int16_t period)
2134{2134{
2135 const uint8_t maxHeight = SPECTRUM_BAR_HEIGHT + 1; // +1 because of audio latency - allows full height to be seen2135 const uint8_t maxHeight = SPECTRUM_BAR_HEIGHT + 1; // +1 because of audio latency - allows full height to be seen
2136 uint8_t scaledVol;2136 uint16_t scaledVol;
2137 uint32_t scaledNote;2137 uint32_t scaledNote;
2138 2138
2139 if (ui.visualizerMode != VISUAL_SPECTRUM || vol <= 0)2139 if (ui.visualizerMode != VISUAL_SPECTRUM || vol <= 0)
2140 return;2140 return;
2141 2141
2142 scaledVol = (vol * 24600L) >> 16; // scaledVol = (vol * 256) / 682 = (x / 2.66)2142 scaledVol = ((uint16_t)vol * 24576) >> 16; // scaledVol = vol / 2.66667 (0..64 -> 0..24)
2143 2143
2144 period = CLAMP(period, 113, 856);2144 period = CLAMP(period, 113, 856);
2145 period -= 113;2145 period -= 113;
@@ -2149,14 +2149,14 @@ void updateSpectrumAnalyzer(int8_t vol, int16_t period) · 3 unmodified lines
2149 scaledNote /= 25093; // scaledNote now ranges 0..22, no need to clamp2149 scaledNote /= 25093; // scaledNote now ranges 0..22, no need to clamp
2150 2150
2151 // increment main spectrum bar2151 // increment main spectrum bar
2152 editor.spectrumVolumes[scaledNote] += scaledVol;2152 editor.spectrumVolumes[scaledNote] += (uint8_t)scaledVol;
2153 if (editor.spectrumVolumes[scaledNote] > maxHeight)2153 if (editor.spectrumVolumes[scaledNote] > maxHeight)
2154 editor.spectrumVolumes[scaledNote] = maxHeight;2154 editor.spectrumVolumes[scaledNote] = maxHeight;
2155 2155
2156 // increment left side of spectrum bar with half volume2156 // increment left side of spectrum bar with half volume
2157 if (scaledNote > 0)2157 if (scaledNote > 0)
2158 {2158 {
2159 editor.spectrumVolumes[scaledNote-1] += scaledVol >> 1;2159 editor.spectrumVolumes[scaledNote-1] += (uint8_t)(scaledVol >> 1);
2160 if (editor.spectrumVolumes[scaledNote-1] > maxHeight)2160 if (editor.spectrumVolumes[scaledNote-1] > maxHeight)
2161 editor.spectrumVolumes[scaledNote-1] = maxHeight;2161 editor.spectrumVolumes[scaledNote-1] = maxHeight;
2162 }2162 }
@@ -2164,7 +2164,7 @@ void updateSpectrumAnalyzer(int8_t vol, int16_t period) · 1 unmodified line
2164 // increment right side of spectrum bar with half volume2164 // increment right side of spectrum bar with half volume
2165 if (scaledNote < SPECTRUM_BAR_NUM-1)2165 if (scaledNote < SPECTRUM_BAR_NUM-1)
2166 {2166 {
2167 editor.spectrumVolumes[scaledNote+1] += scaledVol >> 1;2167 editor.spectrumVolumes[scaledNote+1] += (uint8_t)(scaledVol >> 1);
2168 if (editor.spectrumVolumes[scaledNote+1] > maxHeight)2168 if (editor.spectrumVolumes[scaledNote+1] > maxHeight)
2169 editor.spectrumVolumes[scaledNote+1] = maxHeight;2169 editor.spectrumVolumes[scaledNote+1] = maxHeight;
2170 }2170 }
@@ -2202,21 +2202,24 @@ void sinkVisualizerBars(void) · 31 unmodified lines
2202 2202
2203void updateRenderSizeVars(void)2203void updateRenderSizeVars(void)
2204{2204{
2205 int32_t di;
2206#ifdef __APPLE__
2207 int32_t actualScreenW, actualScreenH;
2208 double dXUpscale, dYUpscale;
2209#endif
2210 float fXScale, fYScale;2205 float fXScale, fYScale;
2211 SDL_DisplayMode dm;
2212 2206
2213 di = SDL_GetWindowDisplayIndex(video.window);2207 if (video.useDesktopMouseCoords)
2214 if (di < 0)2208 {
2215 di = 0; // return display index 0 (default) on error2209 SDL_DisplayMode dm;
2216 2210
2217 SDL_GetDesktopDisplayMode(di, &dm);2211 int32_t di = SDL_GetWindowDisplayIndex(video.window);
2218 video.displayW = dm.w;2212 if (di < 0)
2219 video.displayH = dm.h;2213 di = 0; // return display index 0 (default) on error
2214
2215 SDL_GetDesktopDisplayMode(di, &dm);
2216 video.displayW = dm.w;
2217 video.displayH = dm.h;
2218 }
2219 else
2220 {
2221 SDL_GetWindowSize(video.window, &video.displayW, &video.displayH);
2222 }
2220 2223
2221 if (video.fullscreen)2224 if (video.fullscreen)
2222 {2225 {
@@ -2234,20 +2237,25 @@ void updateRenderSizeVars(void) · 11 unmodified lines
2234 video.renderW = (int32_t)(SCREEN_W * fXScale);2237 video.renderW = (int32_t)(SCREEN_W * fXScale);
2235 video.renderH = (int32_t)(SCREEN_H * fYScale);2238 video.renderH = (int32_t)(SCREEN_H * fYScale);
2236 2239
2237#ifdef __APPLE__2240 // high-DPI hackery:
2238 // retina high-DPI hackery (SDL2 is bad at reporting actual rendering sizes on macOS w/ high-DPI)2241 // On high-DPI systems, the display w/h are given in logical pixels,
2242 // but the renderer size is given in physical pixels. Since our internal
2243 // render{X,Y,W,H} variables need to be in logical coordinates, as that's
2244 // what mouse input uses, scale them by the screen's DPI scale factor,
2245 // which is the physical (renderer) size / the logical (window) size.
2246 // On non high-DPI systems, this is effectively a no-op.
2247 int32_t actualScreenW, actualScreenH;
2239 SDL_GL_GetDrawableSize(video.window, &actualScreenW, &actualScreenH);2248 SDL_GL_GetDrawableSize(video.window, &actualScreenW, &actualScreenH);
2240 SDL_GetDesktopDisplayMode(0, &dm);
2241 2249
2242 dXUpscale = (double)actualScreenW / video.displayW;2250 const double dXUpscale = (const double)actualScreenW / video.displayW;
2243 dYUpscale = (double)actualScreenH / video.displayH;2251 const double dYUpscale = (const double)actualScreenH / video.displayH;
2244 2252
2245 // downscale back to correct sizes2253 // downscale back to correct sizes
2246 if (dXUpscale != 0.0) video.renderW = (int32_t)(video.renderW / dXUpscale);2254 if (dXUpscale != 0.0) video.renderW = (int32_t)(video.renderW / dXUpscale);
2247 if (dYUpscale != 0.0) video.renderH = (int32_t)(video.renderH / dYUpscale);2255 if (dYUpscale != 0.0) video.renderH = (int32_t)(video.renderH / dYUpscale);
2248#endif2256
2249 video.renderX = (video.displayW - video.renderW) >> 1;2257 video.renderX = (video.displayW - video.renderW) / 2;
2250 video.renderY = (video.displayH - video.renderH) >> 1;2258 video.renderY = (video.displayH - video.renderH) / 2;
2251 }2259 }
2252 }2260 }
2253 else2261 else
@@ -2259,21 +2267,29 @@ void updateRenderSizeVars(void) · 5 unmodified lines
2259 }2267 }
2260 2268
2261 // for mouse cursor creation2269 // for mouse cursor creation
2262 video.xScale = (int32_t)((video.renderW * (1.0 / SCREEN_W)) + 0.5);2270 video.xScale = (int32_t)round(video.renderW / (double)SCREEN_W);
2263 video.yScale = (int32_t)((video.renderH * (1.0 / SCREEN_H)) + 0.5);2271 video.yScale = (int32_t)round(video.renderH / (double)SCREEN_H);
2272
2264 createMouseCursors();2273 createMouseCursors();
2265}2274}
2266 2275
2267void toggleFullScreen(void)2276void toggleFullscreen(void)
2268{2277{
2269 SDL_DisplayMode dm;
2270
2271 video.fullscreen ^= 1;2278 video.fullscreen ^= 1;
2272 if (video.fullscreen)2279 if (video.fullscreen)
2273 {2280 {
2281 SDL_SetWindowFullscreen(video.window, SDL_WINDOW_FULLSCREEN_DESKTOP);
2282
2274 if (config.fullScreenStretch)2283 if (config.fullScreenStretch)
2275 {2284 {
2276 SDL_GetDesktopDisplayMode(0, &dm);2285 SDL_DisplayMode dm;
2286
2287 int32_t di = SDL_GetWindowDisplayIndex(video.window);
2288 if (di < 0)
2289 di = 0; // return display index 0 (default) on error
2290
2291 SDL_GetDesktopDisplayMode(di, &dm);
2292
2277 SDL_RenderSetLogicalSize(video.renderer, dm.w, dm.h);2293 SDL_RenderSetLogicalSize(video.renderer, dm.w, dm.h);
2278 }2294 }
2279 else2295 else
@@ -2282,8 +2298,10 @@ void toggleFullScreen(void) · 2 unmodified lines
2282 }2298 }
2283 2299
2284 SDL_SetWindowSize(video.window, SCREEN_W, SCREEN_H);2300 SDL_SetWindowSize(video.window, SCREEN_W, SCREEN_H);
2285 SDL_SetWindowFullscreen(video.window, SDL_WINDOW_FULLSCREEN_DESKTOP);2301
2302#ifndef __unix__ // can be severely buggy on Linux... (at least when used like this)
2286 SDL_SetWindowGrab(video.window, SDL_TRUE);2303 SDL_SetWindowGrab(video.window, SDL_TRUE);
2304#endif
2287 }2305 }
2288 else2306 else
2289 {2307 {
@@ -2291,10 +2309,13 @@ void toggleFullScreen(void) · 1 unmodified line
2291 SDL_RenderSetLogicalSize(video.renderer, SCREEN_W, SCREEN_H);2309 SDL_RenderSetLogicalSize(video.renderer, SCREEN_W, SCREEN_H);
2292 SDL_SetWindowSize(video.window, SCREEN_W * config.videoScaleFactor, SCREEN_H * config.videoScaleFactor);2310 SDL_SetWindowSize(video.window, SCREEN_W * config.videoScaleFactor, SCREEN_H * config.videoScaleFactor);
2293 2311
2294 // this is not sensible on a multi-monitor setup2312#ifdef __unix__ // can be required on Linux... (or else the window keeps moving down every time you leave fullscreen)
2295 //SDL_SetWindowPosition(video.window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);2313 SDL_SetWindowPosition(video.window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
2314#endif
2296 2315
2316#ifndef __unix__
2297 SDL_SetWindowGrab(video.window, SDL_FALSE);2317 SDL_SetWindowGrab(video.window, SDL_FALSE);
2318#endif
2298 }2319 }
2299 2320
2300 updateRenderSizeVars();2321 updateRenderSizeVars();
@@ -2302,13 +2323,13 @@ void toggleFullScreen(void) · 1 unmodified line
2302 2323
2303 if (video.fullscreen)2324 if (video.fullscreen)
2304 {2325 {
2305 mouse.setPosX = video.displayW >> 1;2326 mouse.setPosX = video.displayW / 2;
2306 mouse.setPosY = video.displayH >> 1;2327 mouse.setPosY = video.displayH / 2;
2307 }2328 }
2308 else2329 else
2309 {2330 {
2310 mouse.setPosX = video.renderW >> 1;2331 mouse.setPosX = video.renderW / 2;
2311 mouse.setPosY = video.renderH >> 1;2332 mouse.setPosY = video.renderH / 2;
2312 }2333 }
2313 2334
2314 mouse.setPosFlag = true;2335 mouse.setPosFlag = true;
@@ -2316,14 +2337,10 @@ void toggleFullScreen(void) · 1 unmodified line
2316 2337
2317bool setupVideo(void)2338bool setupVideo(void)
2318{2339{
2319 int32_t screenW, screenH;2340 int32_t screenW = SCREEN_W * config.videoScaleFactor;
2320 uint32_t rendererFlags;2341 int32_t screenH = SCREEN_H * config.videoScaleFactor;
2321 SDL_DisplayMode dm;
2322
2323 screenW = SCREEN_W * config.videoScaleFactor;
2324 screenH = SCREEN_H * config.videoScaleFactor;
2325 2342
2326 rendererFlags = 0;2343 uint32_t rendererFlags = 0;
2327 2344
2328#ifdef _WIN322345#ifdef _WIN32
2329#if SDL_PATCHLEVEL >= 42346#if SDL_PATCHLEVEL >= 4
@@ -2334,7 +2351,13 @@ bool setupVideo(void) · 4 unmodified lines
2334 video.vsync60HzPresent = false;2351 video.vsync60HzPresent = false;
2335 if (!config.vsyncOff)2352 if (!config.vsyncOff)
2336 {2353 {
2337 SDL_GetDesktopDisplayMode(0, &dm);2354 SDL_DisplayMode dm;
2355
2356 int32_t di = SDL_GetWindowDisplayIndex(video.window);
2357 if (di < 0)
2358 di = 0; // return display index 0 (default) on error
2359
2360 SDL_GetDesktopDisplayMode(di, &dm);
2338 if (dm.refresh_rate >= 59 && dm.refresh_rate <= 61)2361 if (dm.refresh_rate >= 59 && dm.refresh_rate <= 61)
2339 {2362 {
2340 video.vsync60HzPresent = true;2363 video.vsync60HzPresent = true;
@@ -2407,6 +2430,12 @@ bool setupVideo(void) · 66 unmodified lines
2407 // we want an aligned pointer2430 // we want an aligned pointer
2408 video.frameBuffer = (uint32_t *)ALIGN_PTR(video.frameBufferUnaligned, 256);2431 video.frameBuffer = (uint32_t *)ALIGN_PTR(video.frameBufferUnaligned, 256);
2409 2432
2433 // Workaround: SDL_GetGlobalMouseState() doesn't work with KMSDRM/Wayland
2434 video.useDesktopMouseCoords = true;
2435 const char *videoDriver = SDL_GetCurrentVideoDriver();
2436 if (videoDriver != NULL && (strcmp("KMSDRM", videoDriver) == 0 || strcmp("wayland", videoDriver) == 0))
2437 video.useDesktopMouseCoords = false;
2438
2410 updateRenderSizeVars();2439 updateRenderSizeVars();
2411 updateMouseScaling();2440 updateMouseScaling();
2412 2441
@@ -2415,12 +2444,6 @@ bool setupVideo(void) · 2 unmodified lines
2415 else2444 else
2416 SDL_ShowCursor(SDL_FALSE);2445 SDL_ShowCursor(SDL_FALSE);
2417 2446
2418 // Workaround: SDL_GetGlobalMouseState() doesn't work with KMSDRM/Wayland
2419 video.useDesktopMouseCoords = true;
2420 const char *videoDriver = SDL_GetCurrentVideoDriver();
2421 if (videoDriver != NULL && (strcmp("KMSDRM", videoDriver) == 0 || strcmp("wayland", videoDriver) == 0))
2422 video.useDesktopMouseCoords = false;
2423
2424 SDL_SetRenderDrawColor(video.renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);2447 SDL_SetRenderDrawColor(video.renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
2425 return true;2448 return true;
2426}2449}
src/pt2_visuals.h+1−1
@@ -47,7 +47,7 @@ void sinkVisualizerBars(void); · 46 unmodified lines
47void updatePosEd(void);47void updatePosEd(void);
48void updateVisualizer(void);48void updateVisualizer(void);
49void updateEditOp(void);49void updateEditOp(void);
50void toggleFullScreen(void);50void toggleFullscreen(void);
51void videoClose(void);51void videoClose(void);
52 52
53void displayMainScreen(void);53void displayMainScreen(void);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t