aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBert Münnich <ber.t@posteo.de>2017-10-16 21:10:35 +0200
committerBert Münnich <ber.t@posteo.de>2017-10-16 21:10:35 +0200
commit148026007cae3b97d39d2cfee7562c139eb486b2 (patch)
tree7cc8f8ffaaf7e34756b8550593f3e4999fd6490c
parent4af189e7d9851f56a5d42a1d42658e8e47320f90 (diff)
One header file for type definitions and function declarations
-rw-r--r--autoreload.h36
-rw-r--r--autoreload_inotify.c5
-rw-r--r--autoreload_nop.c2
-rw-r--r--commands.c13
-rw-r--r--commands.h59
-rw-r--r--image.c11
-rw-r--r--image.h98
-rw-r--r--main.c19
-rw-r--r--options.c15
-rw-r--r--options.h63
-rw-r--r--sxiv.h451
-rw-r--r--thumbs.c12
-rw-r--r--thumbs.h77
-rw-r--r--types.h100
-rw-r--r--util.c5
-rw-r--r--util.h80
-rw-r--r--window.c13
-rw-r--r--window.h111
18 files changed, 483 insertions, 687 deletions
diff --git a/autoreload.h b/autoreload.h
deleted file mode 100644
index bb30eb6..0000000
--- a/autoreload.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/* Copyright 2017 Max Voit
- *
- * This file is part of sxiv.
- *
- * sxiv is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2 of the License,
- * or (at your option) any later version.
- *
- * sxiv is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with sxiv. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef AUTORELOAD_H
-#define AUTORELOAD_H
-
-#include "types.h"
-
-typedef struct {
- int fd;
- int wd_dir;
- int wd_file;
- char *filename;
-} arl_t;
-
-void arl_init(arl_t*);
-void arl_cleanup(arl_t*);
-void arl_setup(arl_t*, const char* /* result of realpath(3) */);
-bool arl_handle(arl_t*);
-
-#endif /* AUTORELOAD_H */
diff --git a/autoreload_inotify.c b/autoreload_inotify.c
index 77dfa83..de9cdf8 100644
--- a/autoreload_inotify.c
+++ b/autoreload_inotify.c
@@ -16,15 +16,14 @@
* along with sxiv. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "sxiv.h"
+
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/inotify.h>
-#include "util.h"
-#include "autoreload.h"
-
void arl_init(arl_t *arl)
{
arl->fd = inotify_init1(IN_CLOEXEC | IN_NONBLOCK);
diff --git a/autoreload_nop.c b/autoreload_nop.c
index 48b7f8f..75532cd 100644
--- a/autoreload_nop.c
+++ b/autoreload_nop.c
@@ -16,7 +16,7 @@
* along with sxiv. If not, see <http://www.gnu.org/licenses/>.
*/
-#include "autoreload.h"
+#include "sxiv.h"
void arl_init(arl_t *arl)
{
diff --git a/commands.c b/commands.c
index 6c5fb1a..966ee4c 100644
--- a/commands.c
+++ b/commands.c
@@ -16,20 +16,15 @@
* along with sxiv. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "sxiv.h"
+#define _IMAGE_CONFIG
+#include "config.h"
+
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/wait.h>
-#include "commands.h"
-#include "image.h"
-#include "options.h"
-#include "thumbs.h"
-#include "util.h"
-
-#define _IMAGE_CONFIG
-#include "config.h"
-
void remove_file(int, bool);
void load_image(int);
void open_info(void);
diff --git a/commands.h b/commands.h
deleted file mode 100644
index 07c1dd8..0000000
--- a/commands.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/* Copyright 2011, 2014 Bert Muennich
- *
- * This file is part of sxiv.
- *
- * sxiv is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2 of the License,
- * or (at your option) any later version.
- *
- * sxiv is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with sxiv. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef COMMANDS_H
-#define COMMANDS_H
-
-#include <X11/Xlib.h>
-
-#include "types.h"
-
-typedef int arg_t;
-typedef bool (*cmd_f)(arg_t);
-
-#define G_CMD(c) g_##c,
-#define I_CMD(c) i_##c,
-#define T_CMD(c) t_##c,
-
-typedef enum {
-#include "commands.lst"
- CMD_COUNT
-} cmd_id_t;
-
-typedef struct {
- int mode;
- cmd_f func;
-} cmd_t;
-
-typedef struct {
- unsigned int mask;
- KeySym ksym;
- cmd_id_t cmd;
- arg_t arg;
-} keymap_t;
-
-typedef struct {
- unsigned int mask;
- unsigned int button;
- cmd_id_t cmd;
- arg_t arg;
-} button_t;
-
-const extern cmd_t cmds[CMD_COUNT];
-
-#endif /* COMMANDS_H */
diff --git a/image.c b/image.c
index 5d7f5cf..75dc346 100644
--- a/image.c
+++ b/image.c
@@ -16,6 +16,10 @@
* along with sxiv. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "sxiv.h"
+#define _IMAGE_CONFIG
+#include "config.h"
+
#include <errno.h>
#include <stdlib.h>
#include <string.h>
@@ -23,13 +27,6 @@
#include <sys/types.h>
#include <unistd.h>
-#include "image.h"
-#include "options.h"
-#include "util.h"
-
-#define _IMAGE_CONFIG
-#include "config.h"
-
#if HAVE_LIBEXIF
#include <libexif/exif-data.h>
#endif
diff --git a/image.h b/image.h
deleted file mode 100644
index 37bc4a2..0000000
--- a/image.h
+++ /dev/null
@@ -1,98 +0,0 @@
-/* Copyright 2011 Bert Muennich
- *
- * This file is part of sxiv.
- *
- * sxiv is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2 of the License,
- * or (at your option) any later version.
- *
- * sxiv is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with sxiv. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef IMAGE_H
-#define IMAGE_H
-
-#include <Imlib2.h>
-
-#include "types.h"
-#include "window.h"
-
-typedef struct {
- Imlib_Image im;
- unsigned int delay;
-} img_frame_t;
-
-typedef struct {
- img_frame_t *frames;
- int cap;
- int cnt;
- int sel;
- bool animate;
- int framedelay;
- int length;
-} multi_img_t;
-
-typedef struct {
- Imlib_Image im;
- int w;
- int h;
-
- win_t *win;
- float x;
- float y;
-
- scalemode_t scalemode;
- float zoom;
-
- bool checkpan;
- bool dirty;
- bool aa;
- bool alpha;
-
- Imlib_Color_Modifier cmod;
- int gamma;
-
- struct {
- bool on;
- int delay;
- } ss;
-
- multi_img_t multi;
-} img_t;
-
-void img_init(img_t*, win_t*);
-
-bool img_load(img_t*, const fileinfo_t*);
-CLEANUP void img_close(img_t*, bool);
-
-void img_render(img_t*);
-
-bool img_fit_win(img_t*, scalemode_t);
-
-bool img_zoom(img_t*, float);
-bool img_zoom_in(img_t*);
-bool img_zoom_out(img_t*);
-
-bool img_pos(img_t*, float, float);
-bool img_move(img_t*, float, float);
-bool img_pan(img_t*, direction_t, int);
-bool img_pan_edge(img_t*, direction_t);
-
-void img_rotate(img_t*, degree_t);
-void img_flip(img_t*, flipdir_t);
-
-void img_toggle_antialias(img_t*);
-
-bool img_change_gamma(img_t*, int);
-
-bool img_frame_navigate(img_t*, int);
-bool img_frame_animate(img_t*);
-
-#endif /* IMAGE_H */
diff --git a/main.c b/main.c
index 406c2b9..9f0b84f 100644
--- a/main.c
+++ b/main.c
@@ -16,9 +16,11 @@
* along with sxiv. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "sxiv.h"
+#define _MAPPINGS_CONFIG
+#include "config.h"
+
#include <stdlib.h>
-#include <stdio.h>
-#include <stdarg.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
@@ -26,24 +28,11 @@
#include <signal.h>
#include <sys/select.h>
#include <sys/stat.h>
-#include <sys/time.h>
#include <sys/wait.h>
#include <time.h>
#include <X11/keysym.h>
#include <X11/XF86keysym.h>
-#include "types.h"
-#include "commands.h"
-#include "image.h"
-#include "options.h"
-#include "thumbs.h"
-#include "util.h"
-#include "window.h"
-#include "autoreload.h"
-
-#define _MAPPINGS_CONFIG
-#include "config.h"
-
typedef struct {
struct timeval when;
bool active;
diff --git a/options.c b/options.c
index 66cfcc5..6b3599c 100644
--- a/options.c
+++ b/options.c
@@ -16,19 +16,16 @@
* along with sxiv. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "sxiv.h"
+#define _IMAGE_CONFIG
+#include "config.h"
+
#include <stdlib.h>
#include <string.h>
-#include <stdio.h>
#include <unistd.h>
-#include "options.h"
-#include "util.h"
-
-#define _IMAGE_CONFIG
-#include "config.h"
-
-options_t _options;
-const options_t *options = (const options_t*) &_options;
+opt_t _options;
+const opt_t *options = (const opt_t*) &_options;
void print_usage(void)
{
diff --git a/options.h b/options.h
deleted file mode 100644
index 53153da..0000000
--- a/options.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/* Copyright 2011 Bert Muennich
- *
- * This file is part of sxiv.
- *
- * sxiv is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2 of the License,
- * or (at your option) any later version.
- *
- * sxiv is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with sxiv. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef OPTIONS_H
-#define OPTIONS_H
-
-#include "types.h"
-#include "image.h"
-
-typedef struct {
- /* file list: */
- char **filenames;
- bool from_stdin;
- bool to_stdout;
- bool recursive;
- int filecnt;
- int startnum;
-
- /* image: */
- scalemode_t scalemode;
- float zoom;
- bool animate;
- int gamma;
- int slideshow;
- int framerate;
-
- /* window: */
- bool fullscreen;
- bool hide_bar;
- long embed;
- char *geometry;
- char *res_name;
-
- /* misc flags: */
- bool quiet;
- bool thumb_mode;
- bool clean_cache;
- bool private_mode;
-} options_t;
-
-extern const options_t *options;
-
-void print_usage(void);
-void print_version(void);
-
-void parse_options(int, char**);
-
-#endif /* OPTIONS_H */
diff --git a/sxiv.h b/sxiv.h
new file mode 100644
index 0000000..25443ea
--- /dev/null
+++ b/sxiv.h
@@ -0,0 +1,451 @@
+/* Copyright 2011 Bert Muennich
+ *
+ * This file is part of sxiv.
+ *
+ * sxiv is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2 of the License,
+ * or (at your option) any later version.
+ *
+ * sxiv is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with sxiv. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef SXIV_H
+#define SXIV_H
+
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <Imlib2.h>
+#include <X11/Xlib.h>
+
+/*
+ * Annotation for functions called in cleanup().
+ * These functions are not allowed to call error(!0, ...) or exit().
+ */
+#define CLEANUP
+
+#ifndef MIN
+#define MIN(a,b) ((a) < (b) ? (a) : (b))
+#endif
+#ifndef MAX
+#define MAX(a,b) ((a) > (b) ? (a) : (b))
+#endif
+
+#define ARRLEN(a) (sizeof(a) / sizeof((a)[0]))
+
+#define STREQ(s1,s2) (strcmp((s1), (s2)) == 0)
+
+#define TV_DIFF(t1,t2) (((t1)->tv_sec - (t2)->tv_sec ) * 1000 + \
+ ((t1)->tv_usec - (t2)->tv_usec) / 1000)
+
+#define TV_SET_MSEC(tv,t) { \
+ (tv)->tv_sec = (t) / 1000; \
+ (tv)->tv_usec = (t) % 1000 * 1000; \
+}
+
+#define TV_ADD_MSEC(tv,t) { \
+ (tv)->tv_sec += (t) / 1000; \
+ (tv)->tv_usec += (t) % 1000 * 1000; \
+}
+
+typedef enum {
+ BO_BIG_ENDIAN,
+ BO_LITTLE_ENDIAN
+} byteorder_t;
+
+typedef enum {
+ MODE_IMAGE,
+ MODE_THUMB
+} appmode_t;
+
+typedef enum {
+ DIR_LEFT = 1,
+ DIR_RIGHT = 2,
+ DIR_UP = 4,
+ DIR_DOWN = 8
+} direction_t;
+
+typedef enum {
+ DEGREE_90 = 1,
+ DEGREE_180 = 2,
+ DEGREE_270 = 3
+} degree_t;
+
+typedef enum {
+ FLIP_HORIZONTAL = 1,
+ FLIP_VERTICAL = 2
+} flipdir_t;
+
+typedef enum {
+ SCALE_DOWN,
+ SCALE_FIT,
+ SCALE_WIDTH,
+ SCALE_HEIGHT,
+ SCALE_ZOOM
+} scalemode_t;
+
+typedef enum {
+ CURSOR_ARROW,
+ CURSOR_DRAG,
+ CURSOR_WATCH,
+ CURSOR_LEFT,
+ CURSOR_RIGHT,
+ CURSOR_NONE,
+
+ CURSOR_COUNT
+} cursor_t;
+
+typedef enum {
+ FF_WARN = 1,
+ FF_MARK = 2,
+ FF_TN_INIT = 4
+} fileflags_t;
+
+typedef struct {
+ const char *name; /* as given by user */
+ const char *path; /* always absolute */
+ const char *base;
+ fileflags_t flags;
+} fileinfo_t;
+
+/* timeouts in milliseconds: */
+enum {
+ TO_REDRAW_RESIZE = 75,
+ TO_REDRAW_THUMBS = 200,
+ TO_CURSOR_HIDE = 1200,
+ TO_DOUBLE_CLICK = 300
+};
+
+typedef void (*timeout_f)(void);
+
+typedef struct arl arl_t;
+typedef struct img img_t;
+typedef struct opt opt_t;
+typedef struct tns tns_t;
+typedef struct win win_t;
+
+
+/* autoreload.c */
+
+struct arl {
+ int fd;
+ int wd_dir;
+ int wd_file;
+ char *filename;
+};
+
+void arl_init(arl_t*);
+void arl_cleanup(arl_t*);
+void arl_setup(arl_t*, const char* /* result of realpath(3) */);
+bool arl_handle(arl_t*);
+
+
+/* commands.c */
+
+typedef int arg_t;
+typedef bool (*cmd_f)(arg_t);
+
+#define G_CMD(c) g_##c,
+#define I_CMD(c) i_##c,
+#define T_CMD(c) t_##c,
+
+typedef enum {
+#include "commands.lst"
+ CMD_COUNT
+} cmd_id_t;
+
+typedef struct {
+ int mode;
+ cmd_f func;
+} cmd_t;
+
+typedef struct {
+ unsigned int mask;
+ KeySym ksym;
+ cmd_id_t cmd;
+ arg_t arg;
+} keymap_t;
+
+typedef struct {
+ unsigned int mask;
+ unsigned int button;
+ cmd_id_t cmd;
+ arg_t arg;
+} button_t;
+
+extern const cmd_t cmds[CMD_COUNT];
+
+
+/* image.c */
+
+typedef struct {
+ Imlib_Image im;
+ unsigned int delay;
+} img_frame_t;
+
+typedef struct {
+ img_frame_t *frames;
+ int cap;
+ int cnt;
+ int sel;
+ bool animate;
+ int framedelay;
+ int length;
+} multi_img_t;
+
+struct img {
+ Imlib_Image im;
+ int w;
+ int h;
+
+ win_t *win;
+ float x;
+ float y;
+
+ scalemode_t scalemode;
+ float zoom;
+
+ bool checkpan;
+ bool dirty;
+ bool aa;
+ bool alpha;
+
+ Imlib_Color_Modifier cmod;
+ int gamma;
+
+ struct {
+ bool on;
+ int delay;
+ } ss;
+
+ multi_img_t multi;
+};
+
+void img_init(img_t*, win_t*);
+bool img_load(img_t*, const fileinfo_t*);
+CLEANUP void img_close(img_t*, bool);
+void img_render(img_t*);
+bool img_fit_win(img_t*, scalemode_t);
+bool img_zoom(img_t*, float);
+bool img_zoom_in(img_t*);
+bool img_zoom_out(img_t*);
+bool img_pos(img_t*, float, float);
+bool img_move(img_t*, float, float);
+bool img_pan(img_t*, direction_t, int);
+bool img_pan_edge(img_t*, direction_t);
+void img_rotate(img_t*, degree_t);
+void img_flip(img_t*, flipdir_t);
+void img_toggle_antialias(img_t*);
+bool img_change_gamma(img_t*, int);
+bool img_frame_navigate(img_t*, int);
+bool img_frame_animate(img_t*);
+
+
+/* options.c */
+
+struct opt {
+ /* file list: */
+ char **filenames;
+ bool from_stdin;
+ bool to_stdout;
+ bool recursive;
+ int filecnt;
+ int startnum;
+
+ /* image: */
+ scalemode_t scalemode;
+ float zoom;
+ bool animate;
+ int gamma;
+ int slideshow;
+ int framerate;
+
+ /* window: */
+ bool fullscreen;
+ bool hide_bar;
+ long embed;
+ char *geometry;
+ char *res_name;
+
+ /* misc flags: */
+ bool quiet;
+ bool thumb_mode;
+ bool clean_cache;
+ bool private_mode;
+};
+
+extern const opt_t *options;
+
+void print_usage(void);
+void print_version(void);
+void parse_options(int, char**);
+
+
+/* thumbs.c */
+
+typedef struct {
+ Imlib_Image im;
+ int w;
+ int h;
+ int x;
+ int y;
+} thumb_t;
+
+struct tns {
+ fileinfo_t *files;
+ thumb_t *thumbs;
+ const int *cnt;
+ int *sel;
+ int initnext;
+ int loadnext;
+ int first, end;
+ int r_first, r_end;
+
+ win_t *win;
+ int x;
+ int y;
+ int cols;
+ int rows;
+ int zl;
+ int bw;
+ int dim;
+
+ bool dirty;
+};
+
+void tns_clean_cache(tns_t*);
+void tns_init(tns_t*, fileinfo_t*, const int*, int*, win_t*);
+CLEANUP void tns_free(tns_t*);
+bool tns_load(tns_t*, int, bool, bool);
+void tns_unload(tns_t*, int);
+void tns_render(tns_t*);
+void tns_mark(tns_t*, int, bool);
+void tns_highlight(tns_t*, int, bool);
+bool tns_move_selection(tns_t*, direction_t, int);
+bool tns_scroll(tns_t*, direction_t, bool);
+bool tns_zoom(tns_t*, int);
+int tns_translate(tns_t*, int, int);
+
+
+/* util.c */
+
+#include <dirent.h>
+
+typedef struct {
+ DIR *dir;
+ char *name;
+ int d;
+ bool recursive;
+
+ char **stack;
+ int stcap;
+ int stlen;
+} r_dir_t;
+
+extern const char *progname;
+
+void* emalloc(size_t);
+void* erealloc(void*, size_t);
+char* estrdup(const char*);
+void error(int, int, const char*, ...);
+void size_readable(float*, const char**);
+int r_opendir(r_dir_t*, const char*, bool);
+int r_closedir(r_dir_t*);
+char* r_readdir(r_dir_t*);
+int r_mkdir(char*);
+
+
+/* window.c */
+
+#include <X11/Xutil.h>
+#include <X11/Xft/Xft.h>
+
+enum {
+ BAR_L_LEN = 512,
+ BAR_R_LEN = 64
+};
+
+enum {
+ ATOM_WM_DELETE_WINDOW,
+ ATOM__NET_WM_NAME,
+ ATOM__NET_WM_ICON_NAME,
+ ATOM__NET_WM_ICON,
+ ATOM__NET_WM_STATE,
+ ATOM__NET_WM_STATE_FULLSCREEN,
+ ATOM__NET_SUPPORTED,
+ ATOM_COUNT
+};
+
+typedef struct {
+ Display *dpy;
+ int scr;
+ int scrw, scrh;
+ Visual *vis;
+ Colormap cmap;
+ int depth;
+} win_env_t;
+
+typedef struct {
+ size_t size;
+ char *p;
+ char *buf;
+} win_bar_t;
+
+struct win {
+ Window xwin;
+ win_env_t env;
+
+ XftColor bgcol;
+ XftColor fscol;
+ XftColor selcol;
+
+ int x;
+ int y;
+ unsigned int w;
+ unsigned int h; /* = win height - bar height */
+ unsigned int bw;
+
+ bool fullscreen;
+
+ struct {
+ int w;
+ int h;
+ Pixmap pm;
+ } buf;
+
+ struct {
+ unsigned int h;
+ win_bar_t l;
+ win_bar_t r;
+ XftColor bgcol;
+ XftColor fgcol;
+ } bar;
+};
+
+extern Atom atoms[ATOM_COUNT];
+
+void win_init(win_t*);
+void win_open(win_t*);
+CLEANUP void win_close(win_t*);
+bool win_configure(win_t*, XConfigureEvent*);
+void win_toggle_fullscreen(win_t*);
+void win_toggle_bar(win_t*);
+void win_clear(win_t*);
+void win_draw(win_t*);
+void win_draw_rect(win_t*, int, int, int, int, bool, int, unsigned long);
+int win_textwidth(const win_env_t*, const char*, unsigned int, bool);
+void win_set_title(win_t*, const char*);
+void win_set_cursor(win_t*, cursor_t);
+void win_cursor_pos(win_t*, int*, int*);
+
+#endif /* SXIV_H */
+
diff --git a/thumbs.c b/thumbs.c
index a9f4fe0..a99c764 100644
--- a/thumbs.c
+++ b/thumbs.c
@@ -16,8 +16,11 @@
* along with sxiv. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "sxiv.h"
+#define _THUMBS_CONFIG
+#include "config.h"
+
#include <errno.h>
-#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
@@ -25,13 +28,6 @@
#include <unistd.h>
#include <utime.h>
-#include "options.h"
-#include "thumbs.h"
-#include "util.h"
-
-#define _THUMBS_CONFIG
-#include "config.h"
-
#if HAVE_LIBEXIF
#include <libexif/exif-data.h>
void exif_auto_orientate(const fileinfo_t*);
diff --git a/thumbs.h b/thumbs.h
deleted file mode 100644
index 7b9987e..0000000
--- a/thumbs.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/* Copyright 2011 Bert Muennich
- *
- * This file is part of sxiv.
- *
- * sxiv is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2 of the License,
- * or (at your option) any later version.
- *
- * sxiv is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with sxiv. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef THUMBS_H
-#define THUMBS_H
-
-#include <X11/Xlib.h>
-#include <Imlib2.h>
-
-#include "types.h"
-#include "window.h"
-
-typedef struct {
- Imlib_Image im;
- int w;
- int h;
- int x;
- int y;
-} thumb_t;
-
-typedef struct {
- fileinfo_t *files;
- thumb_t *thumbs;
- const int *cnt;
- int *sel;
- int initnext;
- int loadnext;
- int first, end;
- int r_first, r_end;
-
- win_t *win;
- int x;
- int y;
- int cols;
- int rows;
- int zl;
- int bw;
- int dim;
-
- bool dirty;
-} tns_t;
-
-void tns_clean_cache(tns_t*);
-
-void tns_init(tns_t*, fileinfo_t*, const int*, int*, win_t*);
-CLEANUP void tns_free(tns_t*);
-
-bool tns_load(tns_t*, int, bool, bool);
-void tns_unload(tns_t*, int);
-
-void tns_render(tns_t*);
-void tns_mark(tns_t*, int, bool);
-void tns_highlight(tns_t*, int, bool);
-
-bool tns_move_selection(tns_t*, direction_t, int);
-bool tns_scroll(tns_t*, direction_t, bool);
-
-bool tns_zoom(tns_t*, int);
-
-int tns_translate(tns_t*, int, int);
-
-#endif /* THUMBS_H */
diff --git a/types.h b/types.h
deleted file mode 100644
index 6c3fb3d..0000000
--- a/types.h
+++ /dev/null
@@ -1,100 +0,0 @@
-/* Copyright 2011 Bert Muennich
- *
- * This file is part of sxiv.
- *
- * sxiv is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2 of the License,
- * or (at your option) any later version.
- *
- * sxiv is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with sxiv. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef TYPES_H
-#define TYPES_H
-
-#include <stdbool.h>
-
-/*
- * Annotation for functions called in cleanup().
- * These functions are not allowed to call error(!0, ...) or exit().
- */
-#define CLEANUP
-
-typedef enum {
- BO_BIG_ENDIAN,
- BO_LITTLE_ENDIAN
-} byteorder_t;
-
-typedef enum {
- MODE_IMAGE,
- MODE_THUMB
-} appmode_t;
-
-typedef enum {
- DIR_LEFT = 1,
- DIR_RIGHT = 2,
- DIR_UP = 4,
- DIR_DOWN = 8
-} direction_t;
-
-typedef enum {
- DEGREE_90 = 1,
- DEGREE_180 = 2,
- DEGREE_270 = 3
-} degree_t;
-
-typedef enum {
- FLIP_HORIZONTAL = 1,
- FLIP_VERTICAL = 2
-} flipdir_t;
-
-typedef enum {
- SCALE_DOWN,
- SCALE_FIT,
- SCALE_WIDTH,
- SCALE_HEIGHT,
- SCALE_ZOOM
-} scalemode_t;
-
-typedef enum {
- CURSOR_ARROW,
- CURSOR_DRAG,
- CURSOR_WATCH,
- CURSOR_LEFT,
- CURSOR_RIGHT,
- CURSOR_NONE,
-
- CURSOR_COUNT
-} cursor_t;
-
-typedef enum {
- FF_WARN = 1,
- FF_MARK = 2,
- FF_TN_INIT = 4
-} fileflags_t;
-
-typedef struct {
- const char *name; /* as given by user */
- const char *path; /* always absolute */
- const char *base;
- fileflags_t flags;
-} fileinfo_t;
-
-/* timeouts in milliseconds: */
-enum {
- TO_REDRAW_RESIZE = 75,
- TO_REDRAW_THUMBS = 200,
- TO_CURSOR_HIDE = 1200,
- TO_DOUBLE_CLICK = 300
-};
-
-typedef void (*timeout_f)(void);
-
-#endif /* TYPES_H */
diff --git a/util.c b/util.c
index 395a345..6a236c6 100644
--- a/util.c
+++ b/util.c
@@ -16,6 +16,8 @@
* along with sxiv. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "sxiv.h"
+
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
@@ -23,9 +25,6 @@
#include <unistd.h>
#include <errno.h>
-#include "options.h"
-#include "util.h"
-
const char *progname;
void* emalloc(size_t size)
diff --git a/util.h b/util.h
deleted file mode 100644
index 8918f75..0000000
--- a/util.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/* Copyright 2011 Bert Muennich
- *
- * This file is part of sxiv.
- *
- * sxiv is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2 of the License,
- * or (at your option) any later version.
- *
- * sxiv is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with sxiv. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef UTIL_H
-#define UTIL_H
-
-#include <stdio.h>
-#include <stdarg.h>
-#include <dirent.h>
-#include <sys/time.h>
-#include <sys/types.h>
-
-#include "types.h"
-
-#ifndef MIN
-#define MIN(a,b) ((a) < (b) ? (a) : (b))
-#endif
-#ifndef MAX
-#define MAX(a,b) ((a) > (b) ? (a) : (b))
-#endif
-
-#define ARRLEN(a) (sizeof(a) / sizeof((a)[0]))
-
-#define STREQ(s1,s2) (strcmp((s1), (s2)) == 0)
-
-#define TV_DIFF(t1,t2) (((t1)->tv_sec - (t2)->tv_sec ) * 1000 + \
- ((t1)->tv_usec - (t2)->tv_usec) / 1000)
-
-#define TV_SET_MSEC(tv,t) { \
- (tv)->tv_sec = (t) / 1000; \
- (tv)->tv_usec = (t) % 1000 * 1000; \
-}
-
-#define TV_ADD_MSEC(tv,t) { \
- (tv)->tv_sec += (t) / 1000; \
- (tv)->tv_usec += (t) % 1000 * 1000; \
-}
-
-typedef struct {
- DIR *dir;
- char *name;
- int d;
- bool recursive;
-
- char **stack;
- int stcap;
- int stlen;
-} r_dir_t;
-
-extern const char *progname;
-
-void* emalloc(size_t);
-void* erealloc(void*, size_t);
-char* estrdup(const char*);
-
-void error(int, int, const char*, ...);
-
-void size_readable(float*, const char**);
-
-int r_opendir(r_dir_t*, const char*, bool);
-int r_closedir(r_dir_t*);
-char* r_readdir(r_dir_t*);
-int r_mkdir(char*);
-
-#endif /* UTIL_H */
diff --git a/window.c b/window.c
index 463e52a..71d439f 100644
--- a/window.c
+++ b/window.c
@@ -16,20 +16,17 @@
* along with sxiv. If not, see <http://www.gnu.org/licenses/>.
*/
+#include "sxiv.h"
+#define _WINDOW_CONFIG
+#include "config.h"
+#include "icon/data.h"
+
#include <stdlib.h>
#include <string.h>
#include <locale.h>
#include <X11/cursorfont.h>
#include <X11/Xatom.h>
-#include "options.h"
-#include "util.h"
-#include "window.h"
-#include "icon/data.h"
-
-#define _WINDOW_CONFIG
-#include "config.h"
-
enum {
H_TEXT_PAD = 5,
V_TEXT_PAD = 1
diff --git a/window.h b/window.h
deleted file mode 100644
index 1bf62ec..0000000
--- a/window.h
+++ /dev/null
@@ -1,111 +0,0 @@
-/* Copyright 2011 Bert Muennich
- *
- * This file is part of sxiv.
- *
- * sxiv is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published
- * by the Free Software Foundation; either version 2 of the License,
- * or (at your option) any later version.
- *
- * sxiv is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with sxiv. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef WINDOW_H
-#define WINDOW_H
-
-#include <X11/Xlib.h>
-#include <X11/Xutil.h>
-#include <X11/Xft/Xft.h>
-
-#include "types.h"
-
-enum {
- BAR_L_LEN = 512,
- BAR_R_LEN = 64
-};
-
-enum {
- ATOM_WM_DELETE_WINDOW,
- ATOM__NET_WM_NAME,
- ATOM__NET_WM_ICON_NAME,
- ATOM__NET_WM_ICON,
- ATOM__NET_WM_STATE,
- ATOM__NET_WM_STATE_FULLSCREEN,
- ATOM__NET_SUPPORTED,
- ATOM_COUNT
-};
-
-typedef struct {
- Display *dpy;
- int scr;
- int scrw, scrh;
- Visual *vis;
- Colormap cmap;
- int depth;
-} win_env_t;
-
-typedef struct {
- size_t size;
- char *p;
- char *buf;
-} win_bar_t;
-
-typedef struct {
- Window xwin;
- win_env_t env;
-
- XftColor bgcol;
- XftColor fscol;
- XftColor selcol;
-
- int x;
- int y;
- unsigned int w;
- unsigned int h; /* = win height - bar height */
- unsigned int bw;
-
- bool fullscreen;
-
- struct {
- int w;
- int h;
- Pixmap pm;
- } buf;
-
- struct {
- unsigned int h;
- win_bar_t l;
- win_bar_t r;
- XftColor bgcol;
- XftColor fgcol;
- } bar;
-} win_t;
-
-extern Atom atoms[ATOM_COUNT];
-
-void win_init(win_t*);
-void win_open(win_t*);
-CLEANUP void win_close(win_t*);
-
-bool win_configure(win_t*, XConfigureEvent*);
-
-void win_toggle_fullscreen(win_t*);
-void win_toggle_bar(win_t*);
-
-void win_clear(win_t*);
-void win_draw(win_t*);
-void win_draw_rect(win_t*, int, int, int, int, bool, int, unsigned long);
-
-int win_textwidth(const win_env_t*, const char*, unsigned int, bool);
-
-void win_set_title(win_t*, const char*);
-void win_set_cursor(win_t*, cursor_t);
-void win_cursor_pos(win_t*, int*, int*);
-
-#endif /* WINDOW_H */