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
2929
3030 // internal values (don't modify directly!)
3131 int8_t AUD_DAT[2]; // DMA data buffer
32− const int8_t* location; // current location
32+ const int8_t *location; // current location
3333 uint16_t lengthCounter; // current length
3434 int32_t sampleCounter; // how many bytes left in AUD_DAT
3535 double dSample; // current sample point
3636
3737 // registers modified by Paula functions
38− const int8_t* AUD_LC; // location
38+ const int8_t *AUD_LC; // location
3939 uint16_t AUD_LEN; // length (in words)
4040 double AUD_PER_delta, AUD_PER_deltamul; // delta
4141 double AUD_VOL; // volume
src/pt2_header.h+1−1
@@ -14,7 +14,7 @@ · 13 unmodified lines
1414 #include "pt2_unicode.h"
1515 #include "pt2_palette.h"
1616
17−#define PROG_VER_STR "1.49"
17+#define PROG_VER_STR "1.50"
1818
1919 #ifdef _WIN32
2020 #define DIR_DELIMITER '\\'
src/pt2_keyboard.c+2−2
@@ -364,7 +364,7 @@ void keyDownHandler(SDL_Scancode scancode, SDL_Keycode keycode) · 363 unmodified lines
364364 // TOGGLE FULLSCREEN (should always react)
365365 if (scancode == SDL_SCANCODE_F11 && !keyb.leftAltPressed)
366366 {
367− toggleFullScreen();
367+ toggleFullscreen();
368368
369369 // prevent fullscreen toggle from firing twice on certain SDL2 Linux ports
370370 #ifdef __unix__
@@ -2289,7 +2289,7 @@ void keyDownHandler(SDL_Scancode scancode, SDL_Keycode keycode) · 1918 unmodified lines
22892289 #ifdef __APPLE__
22902290 if (keyb.leftCommandPressed && keyb.leftCtrlPressed)
22912291 {
2292− toggleFullScreen();
2292+ toggleFullscreen();
22932293 }
22942294 else
22952295 #endif
src/pt2_main.c+14−8
@@ -44,7 +44,7 @@ · 43 unmodified lines
4444
4545 module_t *song = NULL; // globalized
4646
47−static bool backupMadeAfterCrash;
47+static bool backupMadeAfterCrash, didDropFile;
4848
4949 #ifdef _WIN32
5050 #define SYSMSG_FILE_ARG (WM_USER + 1)
@@ -324,7 +324,7 @@ int main(int argc, char *argv[]) · 273 unmodified lines
324324 SDL_ShowWindow(video.window);
325325
326326 if (config.startInFullscreen)
327− toggleFullScreen();
327+ toggleFullscreen();
328328
329329 changePathToHome(); // set path to home/user-dir now
330330 diskOpSetInitPath(); // set path to custom path in config (if present)
@@ -400,7 +400,10 @@ static void handleInput(void) · 69 unmodified lines
400400 {
401401 loadDroppedFile(event.drop.file, (uint32_t)strlen(event.drop.file), false, true);
402402 SDL_free(event.drop.file);
403− SDL_RaiseWindow(video.window); // set window focus
403+
404+ // kludge: allow focus-clickthrough after drag-n-drop
405+ SDL_SetHint(SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH, "1");
406+ didDropFile = true;
404407 }
405408 if (event.type == SDL_QUIT)
406409 {
@@ -426,15 +429,18 @@ static void handleInput(void) · 19 unmodified lines
426429
427430 ui.introScreenShown = false;
428431 }
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+ }
429439 }
430440 else if (event.type == SDL_MOUSEBUTTONDOWN)
431441 {
432− if (ui.sampleMarkingPos == -1 &&
433− !ui.forceSampleDrag && !ui.forceVolDrag &&
434− !ui.forceSampleEdit)
435− {
442+ if (ui.sampleMarkingPos == -1 && !ui.forceSampleDrag && !ui.forceVolDrag && !ui.forceSampleEdit)
436443 mouseButtonDownHandler(event.button.button);
437− }
438444 }
439445
440446 if (ui.throwExit)
src/pt2_mouse.c+2−0
@@ -272,11 +272,13 @@ void readMouseXY(void) · 271 unmodified lines
272272
273273 // convert desktop coords to window coords
274274 SDL_GetWindowPosition(video.window, &windowX, &windowY);
275+
275276 mx -= windowX;
276277 my -= windowY;
277278 }
278279 else
279280 {
281+ // special mode for KMSDRM (XXX: Confirm that this still works...)
280282 mouse.buttonState = SDL_GetMouseState(&mx, &my);
281283 }
282284
src/pt2_visuals.c+75−52
@@ -2133,13 +2133,13 @@ void flipFrame(void) · 2132 unmodified lines
21332133 void updateSpectrumAnalyzer(int8_t vol, int16_t period)
21342134 {
21352135 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;
21372137 uint32_t scaledNote;
21382138
21392139 if (ui.visualizerMode != VISUAL_SPECTRUM || vol <= 0)
21402140 return;
21412141
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)
21432143
21442144 period = CLAMP(period, 113, 856);
21452145 period -= 113;
@@ -2149,14 +2149,14 @@ void updateSpectrumAnalyzer(int8_t vol, int16_t period) · 3 unmodified lines
21492149 scaledNote /= 25093; // scaledNote now ranges 0..22, no need to clamp
21502150
21512151 // increment main spectrum bar
2152− editor.spectrumVolumes[scaledNote] += scaledVol;
2152+ editor.spectrumVolumes[scaledNote] += (uint8_t)scaledVol;
21532153 if (editor.spectrumVolumes[scaledNote] > maxHeight)
21542154 editor.spectrumVolumes[scaledNote] = maxHeight;
21552155
21562156 // increment left side of spectrum bar with half volume
21572157 if (scaledNote > 0)
21582158 {
2159− editor.spectrumVolumes[scaledNote-1] += scaledVol >> 1;
2159+ editor.spectrumVolumes[scaledNote-1] += (uint8_t)(scaledVol >> 1);
21602160 if (editor.spectrumVolumes[scaledNote-1] > maxHeight)
21612161 editor.spectrumVolumes[scaledNote-1] = maxHeight;
21622162 }
@@ -2164,7 +2164,7 @@ void updateSpectrumAnalyzer(int8_t vol, int16_t period) · 1 unmodified line
21642164 // increment right side of spectrum bar with half volume
21652165 if (scaledNote < SPECTRUM_BAR_NUM-1)
21662166 {
2167− editor.spectrumVolumes[scaledNote+1] += scaledVol >> 1;
2167+ editor.spectrumVolumes[scaledNote+1] += (uint8_t)(scaledVol >> 1);
21682168 if (editor.spectrumVolumes[scaledNote+1] > maxHeight)
21692169 editor.spectrumVolumes[scaledNote+1] = maxHeight;
21702170 }
@@ -2202,21 +2202,24 @@ void sinkVisualizerBars(void) · 31 unmodified lines
22022202
22032203 void updateRenderSizeVars(void)
22042204 {
2205− int32_t di;
2206−#ifdef __APPLE__
2207− int32_t actualScreenW, actualScreenH;
2208− double dXUpscale, dYUpscale;
2209−#endif
22102205 float fXScale, fYScale;
2211− SDL_DisplayMode dm;
22122206
2213− di = SDL_GetWindowDisplayIndex(video.window);
2214− if (di < 0)
2215− di = 0; // return display index 0 (default) on error
2207+ if (video.useDesktopMouseCoords)
2208+ {
2209+ SDL_DisplayMode dm;
22162210
2217− SDL_GetDesktopDisplayMode(di, &dm);
2218− video.displayW = dm.w;
2219− video.displayH = dm.h;
2211+ int32_t di = SDL_GetWindowDisplayIndex(video.window);
2212+ if (di < 0)
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+ }
22202223
22212224 if (video.fullscreen)
22222225 {
@@ -2234,20 +2237,25 @@ void updateRenderSizeVars(void) · 11 unmodified lines
22342237 video.renderW = (int32_t)(SCREEN_W * fXScale);
22352238 video.renderH = (int32_t)(SCREEN_H * fYScale);
22362239
2237−#ifdef __APPLE__
2238− // retina high-DPI hackery (SDL2 is bad at reporting actual rendering sizes on macOS w/ high-DPI)
2240+ // high-DPI hackery:
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;
22392248 SDL_GL_GetDrawableSize(video.window, &actualScreenW, &actualScreenH);
2240− SDL_GetDesktopDisplayMode(0, &dm);
22412249
2242− dXUpscale = (double)actualScreenW / video.displayW;
2243− dYUpscale = (double)actualScreenH / video.displayH;
2250+ const double dXUpscale = (const double)actualScreenW / video.displayW;
2251+ const double dYUpscale = (const double)actualScreenH / video.displayH;
22442252
22452253 // downscale back to correct sizes
22462254 if (dXUpscale != 0.0) video.renderW = (int32_t)(video.renderW / dXUpscale);
22472255 if (dYUpscale != 0.0) video.renderH = (int32_t)(video.renderH / dYUpscale);
2248−#endif
2249− video.renderX = (video.displayW - video.renderW) >> 1;
2250− video.renderY = (video.displayH - video.renderH) >> 1;
2256+
2257+ video.renderX = (video.displayW - video.renderW) / 2;
2258+ video.renderY = (video.displayH - video.renderH) / 2;
22512259 }
22522260 }
22532261 else
@@ -2259,21 +2267,29 @@ void updateRenderSizeVars(void) · 5 unmodified lines
22592267 }
22602268
22612269 // for mouse cursor creation
2262− video.xScale = (int32_t)((video.renderW * (1.0 / SCREEN_W)) + 0.5);
2263− video.yScale = (int32_t)((video.renderH * (1.0 / SCREEN_H)) + 0.5);
2270+ video.xScale = (int32_t)round(video.renderW / (double)SCREEN_W);
2271+ video.yScale = (int32_t)round(video.renderH / (double)SCREEN_H);
2272+
22642273 createMouseCursors();
22652274 }
22662275
2267−void toggleFullScreen(void)
2276+void toggleFullscreen(void)
22682277 {
2269− SDL_DisplayMode dm;
2270−
22712278 video.fullscreen ^= 1;
22722279 if (video.fullscreen)
22732280 {
2281+ SDL_SetWindowFullscreen(video.window, SDL_WINDOW_FULLSCREEN_DESKTOP);
2282+
22742283 if (config.fullScreenStretch)
22752284 {
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+
22772293 SDL_RenderSetLogicalSize(video.renderer, dm.w, dm.h);
22782294 }
22792295 else
@@ -2282,8 +2298,10 @@ void toggleFullScreen(void) · 2 unmodified lines
22822298 }
22832299
22842300 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)
22862303 SDL_SetWindowGrab(video.window, SDL_TRUE);
2304+#endif
22872305 }
22882306 else
22892307 {
@@ -2291,10 +2309,13 @@ void toggleFullScreen(void) · 1 unmodified line
22912309 SDL_RenderSetLogicalSize(video.renderer, SCREEN_W, SCREEN_H);
22922310 SDL_SetWindowSize(video.window, SCREEN_W * config.videoScaleFactor, SCREEN_H * config.videoScaleFactor);
22932311
2294− // this is not sensible on a multi-monitor setup
2295− //SDL_SetWindowPosition(video.window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
2312+#ifdef __unix__ // can be required on Linux... (or else the window keeps moving down every time you leave fullscreen)
2313+ SDL_SetWindowPosition(video.window, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
2314+#endif
22962315
2316+#ifndef __unix__
22972317 SDL_SetWindowGrab(video.window, SDL_FALSE);
2318+#endif
22982319 }
22992320
23002321 updateRenderSizeVars();
@@ -2302,13 +2323,13 @@ void toggleFullScreen(void) · 1 unmodified line
23022323
23032324 if (video.fullscreen)
23042325 {
2305− mouse.setPosX = video.displayW >> 1;
2306− mouse.setPosY = video.displayH >> 1;
2326+ mouse.setPosX = video.displayW / 2;
2327+ mouse.setPosY = video.displayH / 2;
23072328 }
23082329 else
23092330 {
2310− mouse.setPosX = video.renderW >> 1;
2311− mouse.setPosY = video.renderH >> 1;
2331+ mouse.setPosX = video.renderW / 2;
2332+ mouse.setPosY = video.renderH / 2;
23122333 }
23132334
23142335 mouse.setPosFlag = true;
@@ -2316,14 +2337,10 @@ void toggleFullScreen(void) · 1 unmodified line
23162337
23172338 bool setupVideo(void)
23182339 {
2319− int32_t screenW, screenH;
2320− uint32_t rendererFlags;
2321− SDL_DisplayMode dm;
2322−
2323− screenW = SCREEN_W * config.videoScaleFactor;
2324− screenH = SCREEN_H * config.videoScaleFactor;
2340+ int32_t screenW = SCREEN_W * config.videoScaleFactor;
2341+ int32_t screenH = SCREEN_H * config.videoScaleFactor;
23252342
2326− rendererFlags = 0;
2343+ uint32_t rendererFlags = 0;
23272344
23282345 #ifdef _WIN32
23292346 #if SDL_PATCHLEVEL >= 4
@@ -2334,7 +2351,13 @@ bool setupVideo(void) · 4 unmodified lines
23342351 video.vsync60HzPresent = false;
23352352 if (!config.vsyncOff)
23362353 {
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);
23382361 if (dm.refresh_rate >= 59 && dm.refresh_rate <= 61)
23392362 {
23402363 video.vsync60HzPresent = true;
@@ -2407,6 +2430,12 @@ bool setupVideo(void) · 66 unmodified lines
24072430 // we want an aligned pointer
24082431 video.frameBuffer = (uint32_t *)ALIGN_PTR(video.frameBufferUnaligned, 256);
24092432
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+
24102439 updateRenderSizeVars();
24112440 updateMouseScaling();
24122441
@@ -2415,12 +2444,6 @@ bool setupVideo(void) · 2 unmodified lines
24152444 else
24162445 SDL_ShowCursor(SDL_FALSE);
24172446
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−
24242447 SDL_SetRenderDrawColor(video.renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
24252448 return true;
24262449 }
src/pt2_visuals.h+1−1
@@ -47,7 +47,7 @@ void sinkVisualizerBars(void); · 46 unmodified lines
4747 void updatePosEd(void);
4848 void updateVisualizer(void);
4949 void updateEditOp(void);
50−void toggleFullScreen(void);
50+void toggleFullscreen(void);
5151 void videoClose(void);
5252
5353 void 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