Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cppcheck style warnings #40

Merged
merged 3 commits into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions src/xsct.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#include "xsct.h"

static void usage(char * pname)
static void usage(const char *const pname)
{
printf("Xsct (%s)\n"
"Usage: %s [options] [temperature] [brightness]\n"
Expand All @@ -23,7 +23,7 @@ static void usage(char * pname)

static double DoubleTrim(double x, double a, double b)
{
double buff[3] = {a, x, b};
const double buff[3] = {a, x, b};
return buff[ (int)(x > a) + (int)(x > b) ];
}

Expand All @@ -34,10 +34,9 @@ static struct temp_status get_sct_for_screen(Display *dpy, int screen, int icrtc

int n, c;
double t = 0.0;
double gammar = 0.0, gammag = 0.0, gammab = 0.0, gammad = 0.0;
double gammar = 0.0, gammag = 0.0, gammab = 0.0;
struct temp_status temp;
temp.temp = 0;
temp.brightness = 1.0;

n = res->ncrtc;
if ((icrtc >= 0) && (icrtc < n))
Expand Down Expand Up @@ -70,7 +69,7 @@ static struct temp_status get_sct_for_screen(Display *dpy, int screen, int icrtc
temp.brightness /= BRIGHTHESS_DIV;
temp.brightness = DoubleTrim(temp.brightness, 0.0, 1.0);
if (fdebug > 0) fprintf(stderr, "DEBUG: Gamma: %f, %f, %f, brightness: %f\n", gammar, gammag, gammab, temp.brightness);
gammad = gammab - gammar;
const double gammad = gammab - gammar;
if (gammad < 0.0)
{
if (gammab > 0.0)
Expand All @@ -97,7 +96,7 @@ static struct temp_status get_sct_for_screen(Display *dpy, int screen, int icrtc

static void sct_for_screen(Display *dpy, int screen, int icrtc, struct temp_status temp, int fdebug)
{
double t = 0.0, b = 1.0, g = 0.0, gammar, gammag, gammab;
double t = 0.0, b = 1.0, gammar, gammag, gammab;
int n, c;
Window root = RootWindow(dpy, screen);
XRRScreenResources *res = XRRGetScreenResourcesCurrent(dpy, root);
Expand All @@ -109,7 +108,7 @@ static void sct_for_screen(Display *dpy, int screen, int icrtc, struct temp_stat
gammar = 1.0;
if (temp.temp > TEMPERATURE_ZERO)
{
g = log(t - TEMPERATURE_ZERO);
const double g = log(t - TEMPERATURE_ZERO);
gammag = DoubleTrim(GAMMA_K0GR + GAMMA_K1GR * g, 0.0, 1.0);
gammab = DoubleTrim(GAMMA_K0BR + GAMMA_K1BR * g, 0.0, 1.0);
}
Expand All @@ -121,7 +120,7 @@ static void sct_for_screen(Display *dpy, int screen, int icrtc, struct temp_stat
}
else
{
g = log(t - (TEMPERATURE_NORM - TEMPERATURE_ZERO));
const double g = log(t - (TEMPERATURE_NORM - TEMPERATURE_ZERO));
gammar = DoubleTrim(GAMMA_K0RB + GAMMA_K1RB * g, 0.0, 1.0);
gammag = DoubleTrim(GAMMA_K0GB + GAMMA_K1GB * g, 0.0, 1.0);
gammab = 1.0;
Expand All @@ -144,7 +143,7 @@ static void sct_for_screen(Display *dpy, int screen, int icrtc, struct temp_stat

for (i = 0; i < size; i++)
{
g = GAMMA_MULT * b * (double)i / (double)size;
const double g = GAMMA_MULT * b * (double)i / (double)size;
crtc_gamma->red[i] = (unsigned short int)(g * gammar + 0.5);
crtc_gamma->green[i] = (unsigned short int)(g * gammag + 0.5);
crtc_gamma->blue[i] = (unsigned short int)(g * gammab + 0.5);
Expand Down
2 changes: 1 addition & 1 deletion src/xsct.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ struct temp_status
double brightness;
};

static void usage(char * pname);
static void usage(const char * pname);
faf0 marked this conversation as resolved.
Show resolved Hide resolved
static double DoubleTrim(double x, double a, double b);
static struct temp_status get_sct_for_screen(Display *dpy, int screen, int icrtc, int fdebug);
static void sct_for_screen(Display *dpy, int screen, int icrtc, struct temp_status temp, int fdebug);
Expand Down