aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornirav <nirav@teisuu.com>2018-09-02 17:40:59 +0530
committerDandelion <nirav@teisuu.com>2018-09-02 17:40:59 +0530
commita49ccb8c0731aa0bba767199dfee1e7e235aeb29 (patch)
tree727e8e1c2f40ad4d0683eaf52aeb2bd70b0e6b53
parent8472e02a212af0be07b19127db313e8e7523711a (diff)
downloadim-a49ccb8c0731aa0bba767199dfee1e7e235aeb29.tar.gz
im-a49ccb8c0731aa0bba767199dfee1e7e235aeb29.zip
Added option for loading first, last image, added extra key bindings
-rw-r--r--file.c22
-rw-r--r--file.h2
-rw-r--r--main.c14
3 files changed, 34 insertions, 4 deletions
diff --git a/file.c b/file.c
index eebc49d..33d326b 100644
--- a/file.c
+++ b/file.c
@@ -52,16 +52,30 @@ int scan(const char *file_name)
char *get_next_file()
{
- if (curr_file_index >= file_list_count - 1) {
+ if (curr_file_index >= file_list_count - 1)
return NULL;
- }
return file_list[++curr_file_index];
}
char *get_prev_file()
{
- if (curr_file_index <= 0) {
+ if (curr_file_index <= 0)
return NULL;
- }
return file_list[--curr_file_index];
}
+
+char *get_first_file()
+{
+ if (curr_file_index == 0)
+ return NULL;
+ curr_file_index = 0;
+ return file_list[curr_file_index];
+}
+
+char *get_last_file()
+{
+ if (curr_file_index == file_list_count - 1)
+ return NULL;
+ curr_file_index = file_list_count - 1;
+ return file_list[curr_file_index];
+}
diff --git a/file.h b/file.h
index 31f6323..b052d32 100644
--- a/file.h
+++ b/file.h
@@ -9,5 +9,7 @@ int curr_file_index, file_list_count;
int scan(const char *file_name);
char *get_next_file();
char *get_prev_file();
+char *get_first_file();
+char *get_last_file();
#endif
diff --git a/main.c b/main.c
index 3041d8a..57e84bc 100644
--- a/main.c
+++ b/main.c
@@ -25,9 +25,11 @@ static gboolean key_press(GtkWindow *window, GdkEvent *event, gpointer data)
fit_image(win_width, win_height);
return FALSE;
case GDK_KEY_plus:
+ case GDK_KEY_KP_Add:
zoom(1);
return FALSE;
case GDK_KEY_minus:
+ case GDK_KEY_KP_Subtract:
zoom(-1);
return FALSE;
case GDK_KEY_equal:
@@ -35,14 +37,26 @@ static gboolean key_press(GtkWindow *window, GdkEvent *event, gpointer data)
return FALSE;
case GDK_KEY_n:
case GDK_KEY_j:
+ case GDK_KEY_Right:
if ((name = get_next_file()) != NULL)
load_image(name, win_width, win_height);
return FALSE;
case GDK_KEY_p:
case GDK_KEY_k:
+ case GDK_KEY_Left:
if ((name = get_prev_file()) != NULL)
load_image(name, win_width, win_height);
return FALSE;
+ case GDK_KEY_g:
+ case GDK_KEY_Home:
+ if ((name = get_first_file()) != NULL)
+ load_image(name, win_width, win_height);
+ return FALSE;
+ case GDK_KEY_G:
+ case GDK_KEY_End:
+ if ((name = get_last_file()) != NULL)
+ load_image(name, win_width, win_height);
+ return FALSE;
default:
return TRUE;
}