diff options
| author | nirav <nirav@teisuu.com> | 2018-10-20 18:47:23 +0530 | 
|---|---|---|
| committer | Dandelion <nirav@teisuu.com> | 2018-10-20 18:47:23 +0530 | 
| commit | f8f3159f9b98b024043bd8de2c5e15dd2adf03ca (patch) | |
| tree | 0ccaa16120845ef816199dc02f2866c4be1fbba3 | |
| parent | a7488f38fef1960086af860063f1958fb75d58f3 (diff) | |
| download | im-f8f3159f9b98b024043bd8de2c5e15dd2adf03ca.tar.gz im-f8f3159f9b98b024043bd8de2c5e15dd2adf03ca.zip | |
Switched to gtk_init and gtk_main from gtk_application
| -rw-r--r-- | src/file.c | 13 | ||||
| -rw-r--r-- | src/file.h | 2 | ||||
| -rw-r--r-- | src/image.c | 12 | ||||
| -rw-r--r-- | src/input.c | 9 | ||||
| -rw-r--r-- | src/main.c | 71 | ||||
| -rw-r--r-- | src/window.c | 13 | ||||
| -rw-r--r-- | src/window.h | 2 | 
7 files changed, 66 insertions, 56 deletions
| @@ -1,6 +1,5 @@  #define _DEFAULT_SOURCE -#include "file.h" -#include "image.h" +  #include <dirent.h>  #include <gtk-3.0/gtk/gtk.h>  #include <libgen.h> @@ -9,6 +8,9 @@  #include <string.h>  #include <sys/types.h> +#include "file.h" +#include "image.h" +  static int curr_file_index, file_list_count;  static char **file_list;  static char **extensions = NULL; @@ -69,14 +71,15 @@ int image_filter(const struct dirent *dir)      return 0;  } -int scan(const char *file_name) +void scan(const char *file_name)  {      scan_supported_formats();      struct dirent **name_list;      char *dir_name = dirname(strdup(file_name));      file_list_count = scandir(dir_name, &name_list, image_filter, alphasort);      if (file_list_count < 0) { -        return -1; +        g_printerr("failed to read direcory %s for image files", dir_name); +        return;      }      file_list = malloc(file_list_count * sizeof(char *)); @@ -90,8 +93,6 @@ int scan(const char *file_name)          i++;      }      free(name_list); - -    return 0;  }  void next_file() @@ -1,7 +1,7 @@  #ifndef __FILE_H  #define __FILE_H -int scan(const char *file_name); +void scan(const char *file_name);  void next_file();  void prev_file();  void first_file(); diff --git a/src/image.c b/src/image.c index 052f1b3..4b725e7 100644 --- a/src/image.c +++ b/src/image.c @@ -1,8 +1,9 @@ -#include "image.h" -#include "window.h"  #include <gtk-3.0/gtk/gtk.h>  #include <stdlib.h> +#include "image.h" +#include "window.h" +  static GtkWidget *image;  static GdkPixbuf *pixbuf;  static GdkPixbuf *curr_pixbuf; @@ -14,7 +15,6 @@ static int loading = 0;  static GFile *file;  static GFileInputStream *is; -static GError *error = NULL;  GtkWidget *new_image()  { @@ -29,11 +29,12 @@ void pixbuf_load_callback(GObject *source_object, GAsyncResult *res,          g_object_unref(pixbuf);      if (is != NULL)          g_object_unref(is); +    GError *error = NULL;      pixbuf = gdk_pixbuf_new_from_stream_finish(res, &error);      if (error != NULL) {          loading = 0;          g_printerr("%s\n", error->message); -        return; +        exit(EXIT_FAILURE);      }      curr_pixbuf_width = pixbuf_width = gdk_pixbuf_get_width(GDK_PIXBUF(pixbuf));      curr_pixbuf_height = pixbuf_height = @@ -49,11 +50,12 @@ void pixbuf_load_callback(GObject *source_object, GAsyncResult *res,  void file_read_callback(GObject *source_object, GAsyncResult *res,                          gpointer user_data)  { +    GError *error = NULL;      is = g_file_read_finish(file, res, &error);      if (error != NULL) {          loading = 0;          g_printerr("%s\n", error->message); -        return; +        exit(EXIT_FAILURE);      }      gdk_pixbuf_new_from_stream_async(G_INPUT_STREAM(is), NULL,                                       &pixbuf_load_callback, NULL); diff --git a/src/input.c b/src/input.c index 40a717a..0b2a6dc 100644 --- a/src/input.c +++ b/src/input.c @@ -1,14 +1,15 @@ -#include "input.h" +#include <gtk-3.0/gtk/gtk.h> +  #include "file.h"  #include "image.h" +#include "input.h"  #include "window.h" -#include <gtk-3.0/gtk/gtk.h>  #define TIMEOUT 20  #define SCROLLAMMOUNT 30 -int grabbed = 0; -gdouble start_x, start_y; +static int grabbed = 0; +static gdouble start_x, start_y;  void handle_key_press(GdkEvent *event)  { @@ -1,51 +1,56 @@ +#include <gtk-3.0/gtk/gtk.h> +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +  #include "file.h"  #include "image.h" -#include "input.h"  #include "window.h" -#include <gtk-3.0/gtk/gtk.h> -void print_help() +void print_usage()  { -    printf("usage: qwe [filename]\n"); +    printf("qwe [filename]\n");  } -static void activate(GtkApplication *app, gpointer user_data) +void print_version()  { -    print_help(); +    printf("0.01\n");  } -static void open(GApplication *app, GFile **files, gint n_files, -                 const gchar *hint) +int main(int argc, char **argv)  { -    if (n_files != 1) { -        print_help(); -        return; -    } +    gtk_init(&argc, &argv); -    create_main_window(app); +    int opt; +    while ((opt = getopt(argc, argv, "hv")) != -1) { +        switch (opt) { +        case '?': +            print_usage(); +            exit(EXIT_FAILURE); +        case 'h': +            print_usage(); +            exit(EXIT_SUCCESS); +        case 'v': +            print_version(); +            exit(EXIT_SUCCESS); +        } +    } -    char *curr_filename = g_file_get_path(files[0]); -    int i = scan(curr_filename); -    if (i < 0) { -        printf("failed to load file\n"); -        quit(); +    if (optind >= argc) { +        print_usage(); +        exit(EXIT_FAILURE);      } -    i = load_image(curr_filename); -    if (i < 0) { -        printf("failed to load file\n"); -        quit(); +    // load the specified image +    if (load_image(argv[optind])) { +        exit(EXIT_FAILURE);      } -} -int main(int argc, char *argv[]) -{ -    GtkApplication *app; -    int status; -    app = gtk_application_new("org.gtk.qwe", G_APPLICATION_HANDLES_OPEN); -    g_signal_connect(app, "activate", G_CALLBACK(activate), NULL); -    g_signal_connect(app, "open", G_CALLBACK(open), NULL); -    status = g_application_run(G_APPLICATION(app), argc, argv); -    g_object_unref(app); -    return status; +    // scan other supported image file in the same dir +    scan(argv[optind]); + +    create_main_window(); +    gtk_main(); + +    return EXIT_SUCCESS;  } diff --git a/src/window.c b/src/window.c index 1a81796..899d526 100644 --- a/src/window.c +++ b/src/window.c @@ -1,8 +1,9 @@ -#include "window.h" +#include <gtk-3.0/gtk/gtk.h> +  #include "file.h"  #include "image.h"  #include "input.h" -#include <gtk-3.0/gtk/gtk.h> +#include "window.h"  GtkWidget *window;  GtkWidget *info_panel; @@ -60,10 +61,11 @@ void load_css()      g_object_unref(provider);  } -void create_main_window(GApplication *app) +void create_main_window()  {      // root window -    window = gtk_application_window_new(GTK_APPLICATION(app)); +    window = gtk_window_new(GTK_WINDOW_TOPLEVEL); +    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);      gtk_widget_set_name(GTK_WIDGET(window), "main-window");      gtk_window_set_title(GTK_WINDOW(window), "qwe");      gtk_window_set_default_size(GTK_WINDOW(window), 800, 600); @@ -153,8 +155,7 @@ void get_curr_win_size(gint *width, gint *height)  void quit()  {      clean(); -    g_application_quit( -        G_APPLICATION(gtk_window_get_application(GTK_WINDOW(window)))); +    gtk_main_quit();  }  void toggle_fullscreen() diff --git a/src/window.h b/src/window.h index 3b344b0..c4a6339 100644 --- a/src/window.h +++ b/src/window.h @@ -3,7 +3,7 @@  #include <gtk-3.0/gtk/gtk.h> -void create_main_window(GApplication *app); +void create_main_window();  void get_curr_win_size(gint *width, gint *height);  void scroll_window(gdouble x, gdouble y);  void set_window_title(const char *title, int width, int height); | 
