mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-20 21:08:08 +01:00
util/wmiv: correct errors and warnings
This patch is correcting all errors and almost all warnings reported by checkpatch.
This commit is contained in:
committed by
Carlos R. Mafra
parent
057048e09b
commit
5ee39b7a27
90
util/wmiv.c
90
util/wmiv.c
@@ -18,7 +18,9 @@
|
|||||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#if !defined(_GNU_SOURCE)
|
||||||
#define _GNU_SOURCE
|
#define _GNU_SOURCE
|
||||||
|
#endif
|
||||||
#include <X11/keysym.h>
|
#include <X11/keysym.h>
|
||||||
#include <X11/XKBlib.h>
|
#include <X11/XKBlib.h>
|
||||||
#include <X11/Xatom.h>
|
#include <X11/Xatom.h>
|
||||||
@@ -100,7 +102,8 @@ link_t *current_link;
|
|||||||
change_title: used to change window title
|
change_title: used to change window title
|
||||||
return EXIT_SUCCESS on success, 1 on failure
|
return EXIT_SUCCESS on success, 1 on failure
|
||||||
*/
|
*/
|
||||||
int change_title(XTextProperty *prop, char *filename) {
|
int change_title(XTextProperty *prop, char *filename)
|
||||||
|
{
|
||||||
char *combined_title = NULL;
|
char *combined_title = NULL;
|
||||||
if (!asprintf(&combined_title, "%s - %u/%u - %s", APPNAME, current_index, max_index, filename))
|
if (!asprintf(&combined_title, "%s - %u/%u - %s", APPNAME, current_index, max_index, filename))
|
||||||
if (!asprintf(&combined_title, "%s - %u/%u", APPNAME, current_index, max_index))
|
if (!asprintf(&combined_title, "%s - %u/%u", APPNAME, current_index, max_index))
|
||||||
@@ -117,7 +120,8 @@ int change_title(XTextProperty *prop, char *filename) {
|
|||||||
rescale_image: used to rescale the current image based on the screen size
|
rescale_image: used to rescale the current image based on the screen size
|
||||||
return EXIT_SUCCESS on success
|
return EXIT_SUCCESS on success
|
||||||
*/
|
*/
|
||||||
int rescale_image() {
|
int rescale_image(void)
|
||||||
|
{
|
||||||
long final_width = img->width;
|
long final_width = img->width;
|
||||||
long final_height = img->height;
|
long final_height = img->height;
|
||||||
|
|
||||||
@@ -168,9 +172,11 @@ int rescale_image() {
|
|||||||
maximize_image: find the best image size for the current display
|
maximize_image: find the best image size for the current display
|
||||||
return EXIT_SUCCESS on success
|
return EXIT_SUCCESS on success
|
||||||
*/
|
*/
|
||||||
int maximize_image() {
|
int maximize_image(void)
|
||||||
|
{
|
||||||
rescale_image();
|
rescale_image();
|
||||||
XCopyArea(dpy, pix, win, ctx->copy_gc, 0, 0, img->width, img->height, max_width/2-img->width/2, max_height/2-img->height/2);
|
XCopyArea(dpy, pix, win, ctx->copy_gc, 0, 0,
|
||||||
|
img->width, img->height, max_width/2-img->width/2, max_height/2-img->height/2);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,7 +184,8 @@ int maximize_image() {
|
|||||||
merge_with_background: merge the current image with with a checkboard background
|
merge_with_background: merge the current image with with a checkboard background
|
||||||
return EXIT_SUCCESS on success, 1 on failure
|
return EXIT_SUCCESS on success, 1 on failure
|
||||||
*/
|
*/
|
||||||
int merge_with_background(RImage *i) {
|
int merge_with_background(RImage *i)
|
||||||
|
{
|
||||||
if (i) {
|
if (i) {
|
||||||
RImage *back;
|
RImage *back;
|
||||||
back = RCreateImage(i->width, i->height, True);
|
back = RCreateImage(i->width, i->height, True);
|
||||||
@@ -209,15 +216,15 @@ int merge_with_background(RImage *i) {
|
|||||||
return the image on success, NULL on failure
|
return the image on success, NULL on failure
|
||||||
|
|
||||||
*/
|
*/
|
||||||
RImage* draw_failed_image() {
|
RImage *draw_failed_image(void)
|
||||||
|
{
|
||||||
RImage *failed_image = NULL;
|
RImage *failed_image = NULL;
|
||||||
XWindowAttributes attr;
|
XWindowAttributes attr;
|
||||||
|
|
||||||
if (win && (XGetWindowAttributes(dpy, win, &attr) >= 0)) {
|
if (win && (XGetWindowAttributes(dpy, win, &attr) >= 0))
|
||||||
failed_image = RCreateImage(attr.width, attr.height, False);
|
failed_image = RCreateImage(attr.width, attr.height, False);
|
||||||
} else {
|
else
|
||||||
failed_image = RCreateImage(50, 50, False);
|
failed_image = RCreateImage(50, 50, False);
|
||||||
}
|
|
||||||
if (!failed_image)
|
if (!failed_image)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@@ -232,7 +239,8 @@ RImage* draw_failed_image() {
|
|||||||
full_screen: sending event to the window manager to switch from/to full screen mode
|
full_screen: sending event to the window manager to switch from/to full screen mode
|
||||||
return EXIT_SUCCESS on success, 1 on failure
|
return EXIT_SUCCESS on success, 1 on failure
|
||||||
*/
|
*/
|
||||||
int full_screen() {
|
int full_screen(void)
|
||||||
|
{
|
||||||
XEvent xev;
|
XEvent xev;
|
||||||
|
|
||||||
Atom wm_state = XInternAtom(dpy, "_NET_WM_STATE", True);
|
Atom wm_state = XInternAtom(dpy, "_NET_WM_STATE", True);
|
||||||
@@ -268,7 +276,8 @@ int full_screen() {
|
|||||||
arg: 1 to zoom in, 0 to zoom out
|
arg: 1 to zoom in, 0 to zoom out
|
||||||
return EXIT_SUCCESS on success, 1 on failure
|
return EXIT_SUCCESS on success, 1 on failure
|
||||||
*/
|
*/
|
||||||
int zoom_in_out(int z) {
|
int zoom_in_out(int z)
|
||||||
|
{
|
||||||
RImage *old_img = img;
|
RImage *old_img = img;
|
||||||
RImage *tmp = RLoadImage(ctx, current_link->data, 0);
|
RImage *tmp = RLoadImage(ctx, current_link->data, 0);
|
||||||
if (!tmp)
|
if (!tmp)
|
||||||
@@ -276,7 +285,8 @@ int zoom_in_out(int z) {
|
|||||||
|
|
||||||
if (z) {
|
if (z) {
|
||||||
zoom_factor += 0.2;
|
zoom_factor += 0.2;
|
||||||
img = RScaleImage(tmp, tmp->width + (int)(tmp->width * zoom_factor), tmp->height + (int)(tmp->height * zoom_factor));
|
img = RScaleImage(tmp, tmp->width + (int)(tmp->width * zoom_factor),
|
||||||
|
tmp->height + (int)(tmp->height * zoom_factor));
|
||||||
if (!img) {
|
if (!img) {
|
||||||
img = old_img;
|
img = old_img;
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@@ -313,7 +323,8 @@ int zoom_in_out(int z) {
|
|||||||
zoom_in: transitional fct used to call zoom_in_out with zoom in flag
|
zoom_in: transitional fct used to call zoom_in_out with zoom in flag
|
||||||
return EXIT_SUCCESS on success, 1 on failure
|
return EXIT_SUCCESS on success, 1 on failure
|
||||||
*/
|
*/
|
||||||
int zoom_in() {
|
int zoom_in(void)
|
||||||
|
{
|
||||||
return zoom_in_out(1);
|
return zoom_in_out(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -321,7 +332,8 @@ int zoom_in() {
|
|||||||
zoom_out: transitional fct used to call zoom_in_out with zoom out flag
|
zoom_out: transitional fct used to call zoom_in_out with zoom out flag
|
||||||
return EXIT_SUCCESS on success, 1 on failure
|
return EXIT_SUCCESS on success, 1 on failure
|
||||||
*/
|
*/
|
||||||
int zoom_out() {
|
int zoom_out(void)
|
||||||
|
{
|
||||||
return zoom_in_out(0);
|
return zoom_in_out(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -330,7 +342,8 @@ int zoom_out() {
|
|||||||
arg: way which could be PREV or NEXT constant
|
arg: way which could be PREV or NEXT constant
|
||||||
return EXIT_SUCCESS on success, 1 on failure
|
return EXIT_SUCCESS on success, 1 on failure
|
||||||
*/
|
*/
|
||||||
int change_image(int way) {
|
int change_image(int way)
|
||||||
|
{
|
||||||
if (img && current_link) {
|
if (img && current_link) {
|
||||||
int old_img_width = img->width;
|
int old_img_width = img->width;
|
||||||
int old_img_height = img->height;
|
int old_img_height = img->height;
|
||||||
@@ -358,22 +371,23 @@ int change_image(int way) {
|
|||||||
img = RLoadImage(ctx, current_link->data, 0);
|
img = RLoadImage(ctx, current_link->data, 0);
|
||||||
|
|
||||||
if (!img) {
|
if (!img) {
|
||||||
fprintf(stderr, "Error: %s %s\n", (char *)current_link->data, RMessageForError(RErrorCode));
|
fprintf(stderr, "Error: %s %s\n", (char *)current_link->data,
|
||||||
|
RMessageForError(RErrorCode));
|
||||||
img = draw_failed_image();
|
img = draw_failed_image();
|
||||||
} else {
|
} else {
|
||||||
merge_with_background(img);
|
merge_with_background(img);
|
||||||
}
|
}
|
||||||
rescale_image();
|
rescale_image();
|
||||||
if (!fullscreen_flag) {
|
if (!fullscreen_flag) {
|
||||||
if ((old_img_width != img->width) || (old_img_height != img->height)) {
|
if ((old_img_width != img->width) || (old_img_height != img->height))
|
||||||
XResizeWindow(dpy, win, img->width, img->height);
|
XResizeWindow(dpy, win, img->width, img->height);
|
||||||
} else {
|
else
|
||||||
XCopyArea(dpy, pix, win, ctx->copy_gc, 0, 0, img->width, img->height, 0, 0);
|
XCopyArea(dpy, pix, win, ctx->copy_gc, 0, 0, img->width, img->height, 0, 0);
|
||||||
}
|
|
||||||
change_title(&title_property, (char *)current_link->data);
|
change_title(&title_property, (char *)current_link->data);
|
||||||
} else {
|
} else {
|
||||||
XClearWindow(dpy, win);
|
XClearWindow(dpy, win);
|
||||||
XCopyArea(dpy, pix, win, ctx->copy_gc, 0, 0, img->width, img->height, max_width/2-img->width/2, max_height/2-img->height/2);
|
XCopyArea(dpy, pix, win, ctx->copy_gc, 0, 0,
|
||||||
|
img->width, img->height, max_width/2-img->width/2, max_height/2-img->height/2);
|
||||||
}
|
}
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
@@ -386,7 +400,8 @@ int change_image(int way) {
|
|||||||
arg: not used
|
arg: not used
|
||||||
return void
|
return void
|
||||||
*/
|
*/
|
||||||
void* diaporama(void *arg) {
|
void *diaporama(void *arg)
|
||||||
|
{
|
||||||
(void) arg;
|
(void) arg;
|
||||||
|
|
||||||
XKeyEvent event;
|
XKeyEvent event;
|
||||||
@@ -421,7 +436,8 @@ void* diaporama(void *arg) {
|
|||||||
/*
|
/*
|
||||||
linked_list_init: init the linked list
|
linked_list_init: init the linked list
|
||||||
*/
|
*/
|
||||||
void linked_list_init (linked_list_t *list) {
|
void linked_list_init(linked_list_t *list)
|
||||||
|
{
|
||||||
list->first = list->last = 0;
|
list->first = list->last = 0;
|
||||||
list->count = 0;
|
list->count = 0;
|
||||||
}
|
}
|
||||||
@@ -430,7 +446,8 @@ void linked_list_init (linked_list_t *list) {
|
|||||||
linked_list_add: add an element to the linked list
|
linked_list_add: add an element to the linked list
|
||||||
return EXIT_SUCCESS on success, 1 otherwise
|
return EXIT_SUCCESS on success, 1 otherwise
|
||||||
*/
|
*/
|
||||||
int linked_list_add (linked_list_t *list, const void *data) {
|
int linked_list_add(linked_list_t *list, const void *data)
|
||||||
|
{
|
||||||
link_t *link;
|
link_t *link;
|
||||||
|
|
||||||
/* calloc sets the "next" field to zero. */
|
/* calloc sets the "next" field to zero. */
|
||||||
@@ -456,7 +473,8 @@ int linked_list_add (linked_list_t *list, const void *data) {
|
|||||||
/*
|
/*
|
||||||
linked_list_free: deallocate the whole linked list
|
linked_list_free: deallocate the whole linked list
|
||||||
*/
|
*/
|
||||||
void linked_list_free (linked_list_t *list) {
|
void linked_list_free(linked_list_t *list)
|
||||||
|
{
|
||||||
link_t *link;
|
link_t *link;
|
||||||
link_t *next;
|
link_t *next;
|
||||||
for (link = list->first; link; link = next) {
|
for (link = list->first; link; link = next) {
|
||||||
@@ -473,7 +491,8 @@ void linked_list_free (linked_list_t *list) {
|
|||||||
arg: the directory path that contains images, the linked list where to add the new file refs
|
arg: the directory path that contains images, the linked list where to add the new file refs
|
||||||
return: the first argument of the list or NULL on failure
|
return: the first argument of the list or NULL on failure
|
||||||
*/
|
*/
|
||||||
link_t* connect_dir(char *dirpath, linked_list_t *li) {
|
link_t *connect_dir(char *dirpath, linked_list_t *li)
|
||||||
|
{
|
||||||
struct dirent **dir;
|
struct dirent **dir;
|
||||||
int dv, idx;
|
int dv, idx;
|
||||||
char path[PATH_MAX] = "";
|
char path[PATH_MAX] = "";
|
||||||
@@ -500,10 +519,9 @@ link_t* connect_dir(char *dirpath, linked_list_t *li) {
|
|||||||
snprintf(path, PATH_MAX, "%s%c%s", dirpath, FILE_SEPARATOR, dir[idx]->d_name);
|
snprintf(path, PATH_MAX, "%s%c%s", dirpath, FILE_SEPARATOR, dir[idx]->d_name);
|
||||||
|
|
||||||
free(dir[idx]);
|
free(dir[idx]);
|
||||||
if ((lstat(path, &stDirInfo) == 0) && !S_ISDIR(stDirInfo.st_mode)) {
|
if ((lstat(path, &stDirInfo) == 0) && !S_ISDIR(stDirInfo.st_mode))
|
||||||
linked_list_add(li, strdup(path));
|
linked_list_add(li, strdup(path));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
free(dir);
|
free(dir);
|
||||||
return li->first;
|
return li->first;
|
||||||
}
|
}
|
||||||
@@ -511,7 +529,8 @@ link_t* connect_dir(char *dirpath, linked_list_t *li) {
|
|||||||
/*
|
/*
|
||||||
main
|
main
|
||||||
*/
|
*/
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
int option = -1;
|
int option = -1;
|
||||||
RContextAttributes attr;
|
RContextAttributes attr;
|
||||||
XEvent e;
|
XEvent e;
|
||||||
@@ -525,8 +544,8 @@ int main(int argc, char **argv) {
|
|||||||
#ifdef USE_XPM
|
#ifdef USE_XPM
|
||||||
Pixmap icon_pixmap, icon_shape;
|
Pixmap icon_pixmap, icon_shape;
|
||||||
#endif
|
#endif
|
||||||
|
class_hints = XAllocClassHint();
|
||||||
if (!(class_hints = XAllocClassHint())) {
|
if (!class_hints) {
|
||||||
fprintf(stderr, "Error: failure allocating memory\n");
|
fprintf(stderr, "Error: failure allocating memory\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
@@ -541,7 +560,8 @@ int main(int argc, char **argv) {
|
|||||||
red.red = 255;
|
red.red = 255;
|
||||||
red.green = red.blue = 0;
|
red.green = red.blue = 0;
|
||||||
|
|
||||||
if ((option = getopt(argc, argv, "hv")) != -1) {
|
option = getopt(argc, argv, "hv");
|
||||||
|
if (option != -1) {
|
||||||
switch (option) {
|
switch (option) {
|
||||||
case 'h':
|
case 'h':
|
||||||
fprintf(stderr, "Usage: %s [image(s)|directory]\n"
|
fprintf(stderr, "Usage: %s [image(s)|directory]\n"
|
||||||
@@ -613,10 +633,12 @@ int main(int argc, char **argv) {
|
|||||||
if (DEBUG)
|
if (DEBUG)
|
||||||
fprintf(stderr, "display size: %dx%d\n", max_width, max_height);
|
fprintf(stderr, "display size: %dx%d\n", max_width, max_height);
|
||||||
|
|
||||||
win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0, img->width, img->height, 0, 0, BlackPixel(dpy, screen));
|
win = XCreateSimpleWindow(dpy, DefaultRootWindow(dpy), 0, 0,
|
||||||
|
img->width, img->height, 0, 0, BlackPixel(dpy, screen));
|
||||||
XSelectInput(dpy, win, KeyPressMask|StructureNotifyMask|ExposureMask|ButtonPressMask|FocusChangeMask);
|
XSelectInput(dpy, win, KeyPressMask|StructureNotifyMask|ExposureMask|ButtonPressMask|FocusChangeMask);
|
||||||
|
|
||||||
if (!(size_hints = XAllocSizeHints())) {
|
size_hints = XAllocSizeHints();
|
||||||
|
if (!size_hints) {
|
||||||
fprintf(stderr, "Error: failure allocating memory\n");
|
fprintf(stderr, "Error: failure allocating memory\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
@@ -764,7 +786,7 @@ int main(int argc, char **argv) {
|
|||||||
diaporama_flag = True;
|
diaporama_flag = True;
|
||||||
pthread_create(&tid, NULL, &diaporama, NULL);
|
pthread_create(&tid, NULL, &diaporama, NULL);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Can't use diaporama mode, need a picture directory\n");
|
fprintf(stderr, "Can't use diaporama mode\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user