aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore2
-rw-r--r--Makefile14
-rw-r--r--README.md13
-rw-r--r--main.c72
4 files changed, 101 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..6809670
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+imv
+*.o
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..87b2fb1
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,14 @@
+.PHONY: clean
+
+CFLAGS = -g -W -Wall -std=c11 `sdl2-config --cflags`
+LDFLAGS = `sdl2-config --libs`
+
+TARGET = imv
+SOURCES = $(wildcard *.c)
+OBJECTS = $(SOURCES:%.c=%.o)
+
+$(TARGET): $(OBJECTS)
+ $(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)
+
+clean:
+ $(RM) $(TARGET) $(OBJECTS)
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..ecf536c
--- /dev/null
+++ b/README.md
@@ -0,0 +1,13 @@
+imv - Image Viewer
+==================
+
+imv is a command line image viewer intended for use with tiling window managers.
+
+This software is currently in alpha and supports little to no file formats.
+
+The long term goal is to support the following formats:
+
+* PNG
+* JPEG(2000)
+* GIF
+* and more
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..cd87c75
--- /dev/null
+++ b/main.c
@@ -0,0 +1,72 @@
+#include <stdio.h>
+#include <SDL2/SDL.h>
+
+int main(int argc, char** argv)
+{
+ if(argc < 2) {
+ fprintf(stderr, "Usage: %s <image_file> <...>\n", argv[0]);
+ exit(1);
+ }
+
+ if(SDL_Init(SDL_INIT_VIDEO) != 0) {
+ fprintf(stderr, "SDL Failed to Init: %s\n", SDL_GetError());
+ exit(1);
+ }
+
+ const int width = 1280;
+ const int height = 720;
+
+ SDL_Window *window = SDL_CreateWindow(
+ "imv",
+ SDL_WINDOWPOS_CENTERED,
+ SDL_WINDOWPOS_CENTERED,
+ width, height,
+ SDL_WINDOW_RESIZABLE);
+
+ SDL_Renderer *renderer =
+ SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
+
+ int quit = 0;
+ int redraw = 1;
+ while(!quit) {
+
+ SDL_Event e;
+ while(!quit && SDL_PollEvent(&e)) {
+ switch(e.type) {
+ case SDL_QUIT:
+ quit = 1;
+ break;
+ case SDL_KEYDOWN:
+ if(e.key.keysym.sym == SDLK_q) {
+ quit = 1;
+ }
+ break;
+ case SDL_WINDOWEVENT:
+ if(e.window.event == SDL_WINDOWEVENT_SIZE_CHANGED
+ || e.window.event == SDL_WINDOWEVENT_RESIZED) {
+ redraw = 1;
+ }
+ break;
+ }
+ }
+
+ if(quit) {
+ break;
+ }
+
+ if(redraw) {
+ SDL_RenderClear(renderer);
+ //SDL_RenderCopy(renderer, tex, srcrect, dstrect);
+
+ SDL_RenderPresent(renderer);
+ redraw = 0;
+ }
+ SDL_Delay(10);
+ }
+
+ SDL_DestroyRenderer(renderer);
+ SDL_DestroyWindow(window);
+ SDL_Quit();
+
+ return 0;
+}