Tidying style

This commit is contained in:
bakkeby 2019-11-21 12:09:05 +01:00
parent 42b66d4b29
commit 5fa724da0d
3 changed files with 37 additions and 23 deletions

View File

@ -8,12 +8,13 @@
#define MPDHOST "localhost" #define MPDHOST "localhost"
#define MPDPORT 6600 #define MPDPORT 6600
struct mpd_connection *get_conn(){ struct mpd_connection *get_conn()
{
struct mpd_connection *conn; struct mpd_connection *conn;
conn = mpd_connection_new(MPDHOST, MPDPORT, 1000); conn = mpd_connection_new(MPDHOST, MPDPORT, 1000);
if(mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS){ if (mpd_connection_get_error(conn) != MPD_ERROR_SUCCESS) {
fprintf(stderr, "Could not connect to mpd: %s\n", mpd_connection_get_error_message(conn)); fprintf(stderr, "Could not connect to mpd: %s\n", mpd_connection_get_error_message(conn));
mpd_connection_free(conn); mpd_connection_free(conn);
@ -23,26 +24,28 @@ struct mpd_connection *get_conn(){
return conn; return conn;
} }
void mpdchange(const Arg *direction){ void mpdchange(const Arg *direction)
{
struct mpd_connection *conn; struct mpd_connection *conn;
conn = get_conn(); conn = get_conn();
if(conn == NULL){ if (conn == NULL) {
return; return;
} }
if(direction->i > 0){ if (direction->i > 0) {
mpd_run_next(conn); mpd_run_next(conn);
} }
else{ else {
mpd_run_previous(conn); mpd_run_previous(conn);
} }
mpd_connection_free(conn); mpd_connection_free(conn);
} }
char *get_regerror(int errcode, regex_t *compiled){ char *get_regerror(int errcode, regex_t *compiled)
{
size_t length = regerror(errcode, compiled, NULL, 0); size_t length = regerror(errcode, compiled, NULL, 0);
char *buffer = malloc(length); char *buffer = malloc(length);
(void) regerror(errcode, compiled, buffer, length); (void) regerror(errcode, compiled, buffer, length);
@ -50,7 +53,8 @@ char *get_regerror(int errcode, regex_t *compiled){
return buffer; return buffer;
} }
void mpdcontrol(){ void mpdcontrol()
{
struct mpd_connection *conn; struct mpd_connection *conn;
struct mpd_status *status; struct mpd_status *status;
struct mpd_song *song; struct mpd_song *song;
@ -62,13 +66,13 @@ void mpdcontrol(){
conn = get_conn(); conn = get_conn();
if(conn == NULL){ if (conn == NULL) {
return; return;
} }
status = mpd_run_status(conn); status = mpd_run_status(conn);
if(status == NULL){ if (status == NULL) {
fprintf(stderr, "Could not get mpd status: %s\n", mpd_status_get_error(status)); fprintf(stderr, "Could not get mpd status: %s\n", mpd_status_get_error(status));
mpd_status_free(status); mpd_status_free(status);
@ -78,15 +82,15 @@ void mpdcontrol(){
state = mpd_status_get_state(status); state = mpd_status_get_state(status);
if(state == MPD_STATE_STOP || state == MPD_STATE_PAUSE){ if (state == MPD_STATE_STOP || state == MPD_STATE_PAUSE) {
mpd_run_play(conn); mpd_run_play(conn);
mpd_status_free(status); mpd_status_free(status);
mpd_connection_free(conn); mpd_connection_free(conn);
} }
else if(state != MPD_STATE_UNKNOWN){ //playing some music else if (state != MPD_STATE_UNKNOWN) { //playing some music
song = mpd_run_current_song(conn); song = mpd_run_current_song(conn);
if(song == NULL){ if (song == NULL){
fprintf(stderr, "Error fetching current song!\n"); fprintf(stderr, "Error fetching current song!\n");
mpd_song_free(song); mpd_song_free(song);
@ -98,7 +102,7 @@ void mpdcontrol(){
filename = mpd_song_get_uri(song); filename = mpd_song_get_uri(song);
int errcode = regcomp(&expr, "^[[:alnum:]]+://", REG_EXTENDED|REG_NOSUB); int errcode = regcomp(&expr, "^[[:alnum:]]+://", REG_EXTENDED|REG_NOSUB);
if(errcode != 0){ if (errcode != 0) {
char *err = get_regerror(errcode, &expr); char *err = get_regerror(errcode, &expr);
fprintf(stderr, "Could not compile regexp: %s\n", err); fprintf(stderr, "Could not compile regexp: %s\n", err);
@ -112,20 +116,20 @@ void mpdcontrol(){
int matchcode = regexec(&expr, filename, 0, NULL, 0); int matchcode = regexec(&expr, filename, 0, NULL, 0);
if(matchcode == 0){ if (matchcode == 0) {
if(strstr(filename, "file://") == filename){ //match just at the start of the filename if (strstr(filename, "file://") == filename) { //match just at the start of the filename
//this means that mpd is playing a file outside the music_dir, //this means that mpd is playing a file outside the music_dir,
//but on disk, so we can safely pause //but on disk, so we can safely pause
mpd_run_toggle_pause(conn); mpd_run_toggle_pause(conn);
} }
else{ else {
mpd_run_stop(conn); mpd_run_stop(conn);
} }
} }
else if(matchcode == REG_NOMATCH){ else if (matchcode == REG_NOMATCH) {
mpd_run_toggle_pause(conn); mpd_run_toggle_pause(conn);
} }
else{ else {
char *err = get_regerror(matchcode, &expr); char *err = get_regerror(matchcode, &expr);
fprintf(stderr, "Error while matching regexp: %s\n", err); fprintf(stderr, "Error while matching regexp: %s\n", err);

View File

@ -14,10 +14,10 @@ void drawtaggrid(Monitor *m, int *x_pos, unsigned int occ)
XFillRectangle(dpy, drw->drawable, drw->gc, x, y, h*columns + 1, bh); XFillRectangle(dpy, drw->drawable, drw->gc, x, y, h*columns + 1, bh);
/* We will draw LENGTH(tags) squares in tagraws raws. */ /* We will draw LENGTH(tags) squares in tagraws raws. */
for (j = 0, i= 0; j < tagrows; j++) { for (j = 0, i= 0; j < tagrows; j++) {
x = *x_pos; x = *x_pos;
for (k = 0; k < columns && i < LENGTH(tags); k++, i++) { for (k = 0; k < columns && i < LENGTH(tags); k++, i++) {
invert = m->tagset[m->seltags] & 1 << i ? 0 : 1; invert = m->tagset[m->seltags] & 1 << i ? 0 : 1;
/* Select active color for current square */ /* Select active color for current square */
XSetForeground(drw->dpy, drw->gc, !invert ? scheme[SchemeSel][ColBg].pixel : XSetForeground(drw->dpy, drw->gc, !invert ? scheme[SchemeSel][ColBg].pixel :
@ -31,7 +31,7 @@ void drawtaggrid(Monitor *m, int *x_pos, unsigned int occ)
XFillRectangle(dpy, drw->drawable, drw->gc, x + 1, y + 1, XFillRectangle(dpy, drw->drawable, drw->gc, x + 1, y + 1,
h / 2, h / 2); h / 2, h / 2);
} }
x += h; x += h;
if (x > max_x) { if (x > max_x) {
max_x = x; max_x = x;
} }

View File

@ -1,7 +1,17 @@
void void
togglefullscreen(const Arg *arg) { togglefullscreen(const Arg *arg)
{
if (!selmon->sel) if (!selmon->sel)
return; return;
#if FAKEFULLSCREEN_CLIENT_PATCH
if (selmon->sel->fakefullscreen) {
selmon->sel->fakefullscreen = 0;
if (selmon->sel->isfullscreen) {
selmon->sel->isfullscreen = 0;
}
}
#endif // FAKEFULLSCREEN_CLIENT_PATCH
setfullscreen(selmon->sel, !selmon->sel->isfullscreen); setfullscreen(selmon->sel, !selmon->sel->isfullscreen);
} }