From b0485d66a69701cbc7d3a5316142ee599ef3db19 Mon Sep 17 00:00:00 2001 From: John Anthony Date: Sat, 15 Jun 2013 20:42:22 +0100 Subject: More minor tweaking --- Makefile | 4 ++-- list.h | 75 +++++++++++++++++++++++++++++++++++++--------------------------- nyan.c | 15 +++++++------ 3 files changed, 54 insertions(+), 40 deletions(-) diff --git a/Makefile b/Makefile index 01047d7..8abb154 100644 --- a/Makefile +++ b/Makefile @@ -1,14 +1,14 @@ RES = /usr/share/nyancat BIN = /usr/bin/nyancat LIBS = -lSDL -lSDL_image -lSDL_mixer -lX11 -FLAGS = -pedantic -Wall -O2 -std=gnu99 -D_GNU_SOURCE +FLAGS = -pedantic -Wall -O2 -std=gnu99 INCS = -I. -I/usr/include ${XINERAMAINC} XINERAMAINC = -I/usr/X11R6/include XINERAMALIBS = -L/usr/X11R6/lib -lXinerama XINERAMAFLAGS = -DXINERAMA -nyancat: nyan.c +nyancat: nyan.c list.h cc -g nyan.c -o nyancat ${LIBS} ${XINERAMALIBS} ${XINERAMAINC} ${FLAGS} ${XINERAMAFLAGS} install: diff --git a/list.h b/list.h index 132070d..060d02e 100644 --- a/list.h +++ b/list.h @@ -180,62 +180,75 @@ list_splice_init(struct list_head *list, struct list_head *head) { /** * list_entry - get the struct for this entry - * @ptr: the &struct list_head pointer. - * @type: the type of the struct this is embedded in. - * @member: the name of the list_struct within the struct. + * @ptr: the &struct list_head pointer. + * @type: the type of the struct this is embedded in. + * @member: the name of the list_struct within the struct. */ #define list_entry(ptr, type, member) \ ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member))) /** - * list_for_each - iterate over a list - * @pos: the &struct list_head to use as a loop counter. - * @head: the head for your list. + * list_for_each - iterate over a list + * @pos: the &struct list_head to use as a loop counter. + * @head: the head for your list. */ #define list_for_each(pos, head) \ for (pos = (head)->next; pos != (head); \ pos = pos->next) /** - * list_for_each_prev - iterate over a list backwards - * @pos: the &struct list_head to use as a loop counter. - * @head: the head for your list. + * list_for_each_reverse - iterate over a list backwards + * @pos: the &struct list_head to use as a loop counter. + * @head: the head for your list. */ -#define list_for_each_prev(pos, head) \ +#define list_for_each_reverse(pos, head) \ for (pos = (head)->prev; pos != (head); \ pos = pos->prev) /** - * list_for_each_safe - iterate over a list safe against removal - * @pos: the &struct list_head to use as a loop counter. - * @n: another &struct list_head to use as temporary storage - * @head: the head for your list. + * list_for_each_safe - iterate over a list safe against removal + * @pos: the &struct list_head to use as a loop counter. + * @n: another &struct list_head to use as temporary storage + * @head: the head for your list. */ #define list_for_each_safe(pos, n, head) \ for (pos = (head)->next, n = pos->next; pos != (head); \ pos = n, n = pos->next) /** - * list_for_each_entry - iterate over list of given type - * @pos: the type * to use as a loop counter. - * @head: the head for your list. - * @member: the name of the list_struct within the struct. - */ -#define list_for_each_entry(pos, head, member) \ - for (pos = list_entry((head)->next, typeof(*pos), member); \ - &pos->member != (head); \ + * list_for_each_entry - iterate over list of given type + * @pos: the type * to use as a loop counter. + * @head: the head for your list. + * @member: the name of the list_struct within the struct. + */ +#define list_for_each_entry(pos, head, member) \ + for (pos = list_entry((head)->next, typeof(*pos), member); \ + &pos->member != (head); \ pos = list_entry(pos->member.next, typeof(*pos), member)) /** * list_for_each_entry_safe - iterate list entries safe against removal - * @pos: the type * to use as a loop counter. - * @n: another type * to use as temporary storage - * @head: the head for your list. - * @member: the name of the list_struct within the struct. - */ -#define list_for_each_entry_safe(pos, n, head, member) \ - for (pos = list_entry((head)->next, typeof(*pos), member), \ - n = list_entry(pos->member.next, typeof(*pos), member); \ - &pos->member != (head); \ + * @pos: the type * to use as a loop counter. + * @n: another type * to use as temporary storage + * @head: the head for your list. + * @member: the name of the list_struct within the struct. + */ +#define list_for_each_entry_safe(pos, n, head, member) \ + for (pos = list_entry((head)->next, typeof(*pos), member), \ + n = list_entry(pos->member.next, typeof(*pos), member); \ + &pos->member != (head); \ pos = n, n = list_entry(n->member.next, typeof(*n), member)) +/** + * list_for_each_entry_safe_reverse - as above but reverse iteration + * @pos: the type * to use as a loop counter. + * @n: another type * to use as temporary storage + * @head: the head for your list. + * @member: the name of the list_struct within the struct. + */ +#define list_for_each_entry_safe_reverse(pos, n, head, member) \ + for (pos = list_entry((head)->prev, typeof(*pos), member), \ + n = list_entry(pos->member.prev, typeof(*pos), member); \ + &pos->member != (head); \ + pos = n, n = list_entry(n->member.prev, typeof(*n), member)) + #endif diff --git a/nyan.c b/nyan.c index 5613f6d..8411c5f 100644 --- a/nyan.c +++ b/nyan.c @@ -447,10 +447,8 @@ load_resource_data(void) { if (!f) errout("Error opening resource data file"); - fgets(buffer, BUF_SZ, f); - ANIM_FRAMES_FG = atoi(buffer); - fgets(buffer, BUF_SZ, f); - ANIM_FRAMES_BG = atoi(buffer); + ANIM_FRAMES_FG = atoi(fgets(buffer, BUF_SZ, f)); + ANIM_FRAMES_BG = atoi(fgets(buffer, BUF_SZ, f)); if (!ANIM_FRAMES_FG || !ANIM_FRAMES_BG) errout("Error reading resource data file."); @@ -583,13 +581,16 @@ xinerama_add_cats(void) { int i, nn; XineramaScreenInfo* info = XineramaQueryScreens(dpy, &nn); - for (i = 0; i < nn; ++i) - if(fullscreen) + for (i = 0; i < nn; ++i) { + if(fullscreen) { add_cat(info[i].x_org + ((info[i].width - image_set[0]->w) / 2), info[i].y_org + ((info[i].height - image_set[0]->h) / 2)); - else + } + else { add_cat((SCREEN_WIDTH - image_set[0]->w) / 2, (SCREEN_HEIGHT - image_set[0]->h) / 2); + } + } XFree(info); } -- cgit v1.2.3