Skip to content

Commit

Permalink
add sdl full screen option as mentioned in #531
Browse files Browse the repository at this point in the history
also added quit on q or escape
  • Loading branch information
karlstav committed Nov 17, 2023
1 parent a69fb03 commit 32ec9b3
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 15 deletions.
6 changes: 3 additions & 3 deletions cava.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions example_files/config
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 11 additions & 3 deletions output/sdl_cava.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 {
Expand Down Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion output/sdl_cava.h
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
16 changes: 12 additions & 4 deletions output/sdl_glsl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions output/sdl_glsl.h
Original file line number Diff line number Diff line change
@@ -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);
Expand Down

0 comments on commit 32ec9b3

Please sign in to comment.