Skip to content

Commit

Permalink
Remove function prototypes and obvious comments
Browse files Browse the repository at this point in the history
bgs is so small that prototyping isn't really neccessary.
  • Loading branch information
Klemens Nanni committed Oct 27, 2016
1 parent cf58a63 commit 6536bfd
Showing 1 changed file with 35 additions and 43 deletions.
78 changes: 35 additions & 43 deletions bgs.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,30 +12,18 @@
#include <X11/extensions/Xinerama.h>
#endif

/* macros */
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define LENGTH(x) (sizeof x / sizeof x[0])

/* image modes */
enum { ModeCenter, ModeZoom, ModeScale, ModeLast };

/* structs */
struct Monitor {
int x, y, w, h;
};

/* function declarations */
static void cleanup(void); /* frees images before exit. */
static void die(const char *errstr); /* prints errstr to strerr and exits. */
static void drawbg(void); /* draws background to root. */
static void run(void); /* main loop */
static void setup(char *paths[], int c, const char *col); /* sets up imlib and X */
static void updategeom(void); /* updates screen and/or Xinerama
dimensions */

/* variables */
static int sx, sy, sw, sh; /* geometry of the screen */
static int sx, sy, sw, sh; /* screen geometry */
static unsigned int mode = ModeScale; /* image mode */
static Bool rotate = True;
static Bool running = False;
Expand All @@ -46,7 +34,7 @@ static int nmonitor, nimage; /* Amount of monitors/available background
static struct Monitor monitors[8];
static Imlib_Image images[LENGTH(monitors)];

/* function implementations */
/* free images before exit */
void
cleanup(void) {
int i;
Expand All @@ -63,6 +51,7 @@ die(const char *errstr) {
exit(EXIT_FAILURE);
}

/* draw background to root */
void
drawbg(void) {
int i, w, h, nx, ny, nh, nw, tmp;
Expand Down Expand Up @@ -136,6 +125,36 @@ drawbg(void) {
XFreePixmap(dpy, pm);
}

/* update screen and/or Xinerama dimensions */
void
updategeom(void) {
#ifdef XINERAMA
int i;
XineramaScreenInfo *info = NULL;

if(XineramaIsActive(dpy) &&
(info = XineramaQueryScreens(dpy, &nmonitor))) {
nmonitor = MIN(nmonitor, LENGTH(monitors));
for(i = 0; i < nmonitor; i++) {
monitors[i].x = info[i].x_org;
monitors[i].y = info[i].y_org;
monitors[i].w = info[i].width;
monitors[i].h = info[i].height;
}
XFree(info);
}
else
#endif
{
nmonitor = 1;
monitors[0].x = sx;
monitors[0].y = sy;
monitors[0].w = sw;
monitors[0].h = sh;
}
}

/* main loop */
void
run(void) {
XEvent ev;
Expand All @@ -155,6 +174,7 @@ run(void) {
}
}

/* set up imlib and X */
void
setup(char *paths[], int c, const char *col) {
Visual *vis;
Expand Down Expand Up @@ -195,34 +215,6 @@ setup(char *paths[], int c, const char *col) {
imlib_context_set_color(color.red, color.green, color.blue, 255);
}

void
updategeom(void) {
#ifdef XINERAMA
int i;
XineramaScreenInfo *info = NULL;

if(XineramaIsActive(dpy) &&
(info = XineramaQueryScreens(dpy, &nmonitor))) {
nmonitor = MIN(nmonitor, LENGTH(monitors));
for(i = 0; i < nmonitor; i++) {
monitors[i].x = info[i].x_org;
monitors[i].y = info[i].y_org;
monitors[i].w = info[i].width;
monitors[i].h = info[i].height;
}
XFree(info);
}
else
#endif
{
nmonitor = 1;
monitors[0].x = sx;
monitors[0].y = sy;
monitors[0].w = sw;
monitors[0].h = sh;
}
}

int
main(int argc, char *argv[]) {
int opt;
Expand All @@ -249,7 +241,7 @@ main(int argc, char *argv[]) {
case 'z':
mode = ModeZoom;
break;
default: /* Fallthrough */
default:
die("usage: bgs [-v] [-c] [-C hex] [-z] [-R] [-x] [IMAGE]...\n");
}
argc -= optind;
Expand Down

0 comments on commit 6536bfd

Please sign in to comment.