From 32ec9b3cc3228a2d0e42f8d68785ac56c90924b2 Mon Sep 17 00:00:00 2001 From: karl Date: Fri, 17 Nov 2023 21:31:16 +0100 Subject: [PATCH] add sdl full screen option as mentioned in #531 also added quit on q or escape --- cava.c | 6 +++--- config.c | 1 + config.h | 4 ++-- example_files/config | 1 + output/sdl_cava.c | 14 +++++++++++--- output/sdl_cava.h | 2 +- output/sdl_glsl.c | 16 ++++++++++++---- output/sdl_glsl.h | 4 ++-- 8 files changed, 33 insertions(+), 15 deletions(-) diff --git a/cava.c b/cava.c index 9952c2e..2d147a0 100644 --- a/cava.c +++ b/cava.c @@ -483,15 +483,15 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co #ifdef SDL // output: start sdl mode if (output_mode == OUTPUT_SDL) { - init_sdl_window(p.sdl_width, p.sdl_height, p.sdl_x, p.sdl_y); + init_sdl_window(p.sdl_width, p.sdl_height, p.sdl_x, p.sdl_y, p.sdl_full_screen); height = p.sdl_height; width = p.sdl_width; } #endif #ifdef SDL_GLSL if (output_mode == OUTPUT_SDL_GLSL) { - init_sdl_glsl_window(p.sdl_width, p.sdl_height, p.sdl_x, p.sdl_y, p.vertex_shader, - p.fragment_shader); + init_sdl_glsl_window(p.sdl_width, p.sdl_height, p.sdl_x, p.sdl_y, p.sdl_full_screen, + p.vertex_shader, p.fragment_shader); height = p.sdl_height; width = p.sdl_width; } diff --git a/config.c b/config.c index 6f2f0fd..6274c52 100644 --- a/config.c +++ b/config.c @@ -639,6 +639,7 @@ bool load_config(char configPath[PATH_MAX], struct config_params *p, bool colors p->sdl_height = iniparser_getint(ini, "output:sdl_height", 500); p->sdl_x = iniparser_getint(ini, "output:sdl_x", -1); p->sdl_y = iniparser_getint(ini, "output:sdl_y", -1); + p->sdl_full_screen = iniparser_getint(ini, "output:sdl_full_screen", 0); if (strcmp(outputMethod, "sdl") == 0 || strcmp(outputMethod, "sdl_glsl") == 0) { free(p->color); diff --git a/config.h b/config.h index dc515ef..1e43ffe 100644 --- a/config.h +++ b/config.h @@ -98,8 +98,8 @@ struct config_params { int userEQ_keys, userEQ_enabled, col, bgcol, autobars, stereo, raw_format, ascii_range, bit_format, gradient, gradient_count, fixedbars, framerate, bar_width, bar_spacing, bar_height, autosens, overshoot, waves, fifoSample, fifoSampleBits, sleep_timer, sdl_width, - sdl_height, sdl_x, sdl_y, draw_and_quit, zero_test, non_zero_test, reverse, sync_updates, - continuous_rendering; + sdl_height, sdl_x, sdl_y, sdl_full_screen, draw_and_quit, zero_test, non_zero_test, reverse, + sync_updates, continuous_rendering; }; struct error_s { diff --git a/example_files/config b/example_files/config index 45c5e14..645dd20 100644 --- a/example_files/config +++ b/example_files/config @@ -146,6 +146,7 @@ ; sdl_height = 500 ; sdl_x = -1 ; sdl_y= -1 +; sdl_full_screen = 0 # set label on bars on the x-axis. Can be 'frequency' or 'none'. Default: 'none' # 'frequency' displays the lower cut off frequency of the bar above. diff --git a/output/sdl_cava.c b/output/sdl_cava.c index 6273993..8e501b5 100644 --- a/output/sdl_cava.c +++ b/output/sdl_cava.c @@ -35,7 +35,7 @@ static void parse_color(char *color_string, struct colors *color) { } } -void init_sdl_window(int width, int height, int x, int y) { +void init_sdl_window(int width, int height, int x, int y, int full_screen) { if (x == -1) x = SDL_WINDOWPOS_UNDEFINED; @@ -45,8 +45,12 @@ void init_sdl_window(int width, int height, int x, int y) { if (SDL_Init(SDL_INIT_VIDEO) < 0) { printf("SDL could not initialize! SDL_Error: %s\n", SDL_GetError()); } else { - gWindow = - SDL_CreateWindow("cava", x, y, width, height, SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE); + Uint32 sdl_flags = SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE; + + if (full_screen == 1) + sdl_flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; + + gWindow = SDL_CreateWindow("cava", x, y, width, height, sdl_flags); if (gWindow == NULL) { printf("Window could not be created! SDL_Error: %s\n", SDL_GetError()); } else { @@ -185,6 +189,10 @@ int draw_sdl(int bars_count, int bar_width, int bar_spacing, int remainder, int free(gradient_colors_sdl); } } + if (e.type == SDL_KEYDOWN) { + if (e.key.keysym.sym == SDLK_q || e.key.keysym.sym == SDLK_ESCAPE) + rc = -2; + } if (e.type == SDL_QUIT) rc = -2; } diff --git a/output/sdl_cava.h b/output/sdl_cava.h index 47a8166..c80a024 100644 --- a/output/sdl_cava.h +++ b/output/sdl_cava.h @@ -1,6 +1,6 @@ #include "../config.h" -void init_sdl_window(int width, int height, int x, int y); +void init_sdl_window(int width, int height, int x, int y, int full_screen); void init_sdl_surface(int *width, int *height, char *const fg_color_string, char *const bg_color_string, int gradient, int gradient_count, char **gradient_color_strings); diff --git a/output/sdl_glsl.c b/output/sdl_glsl.c index b6cd8eb..53988c9 100644 --- a/output/sdl_glsl.c +++ b/output/sdl_glsl.c @@ -41,8 +41,8 @@ const char *read_file(const char *); GLuint compile_shader(GLenum type, const char **); GLuint program_check(GLuint); -void init_sdl_glsl_window(int width, int height, int x, int y, char *const vertex_shader, - char *const fragmnet_shader) { +void init_sdl_glsl_window(int width, int height, int x, int y, int full_screen, + char *const vertex_shader, char *const fragmnet_shader) { if (x == -1) x = SDL_WINDOWPOS_UNDEFINED; @@ -60,8 +60,12 @@ void init_sdl_glsl_window(int width, int height, int x, int y, char *const verte SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); #endif - glWindow = SDL_CreateWindow("cava", x, y, width, height, - SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE); + Uint32 sdl_flags = SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE; + + if (full_screen == 1) + sdl_flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; + + glWindow = SDL_CreateWindow("cava", x, y, width, height, sdl_flags); if (glWindow == NULL) { fprintf(stderr, "Window could not be created! SDL_Error: %s\n", SDL_GetError()); exit(1); @@ -213,6 +217,10 @@ int draw_sdl_glsl(int bars_count, const float bars[], int frame_time, int re_pai glViewport(0, 0, event.window.data1, event.window.data2); rc = -1; } + if (event.type == SDL_KEYDOWN) { + if (event.key.keysym.sym == SDLK_q || event.key.keysym.sym == SDLK_ESCAPE) + rc = -2; + } if (event.type == SDL_QUIT) rc = -2; diff --git a/output/sdl_glsl.h b/output/sdl_glsl.h index 37f416a..621f1e6 100644 --- a/output/sdl_glsl.h +++ b/output/sdl_glsl.h @@ -1,7 +1,7 @@ #include "../config.h" -void init_sdl_glsl_window(int width, int height, int x, int y, char *const vertex_shader, - char *const fragment_shader); +void init_sdl_glsl_window(int width, int height, int x, int y, int full_screen, + char *const vertex_shader, char *const fragment_shader); void init_sdl_glsl_surface(int *width, int *height, char *const fg_color_string, char *const bg_color_string, int bar_width, int bar_spacing, int gradient, int gradient_count, char **gradient_color_strings);