about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-01-31 22:00:22 +0000
committerJames Booth <boothj5@gmail.com>2015-01-31 22:00:22 +0000
commit28dd5458777a7655a558c14e17d79464c8ab4324 (patch)
treee707f28653165d6abcc9d8f7a615710cdd9a6490 /src
parente6f27de55221f0f41362b81ca927d5d55682d14f (diff)
downloadprofani-tty-28dd5458777a7655a558c14e17d79464c8ab4324.tar.gz
Added paging handlers
Diffstat (limited to 'src')
-rw-r--r--src/ui/core.c28
-rw-r--r--src/ui/inputwin.c149
-rw-r--r--src/ui/ui.h5
-rw-r--r--src/ui/window.c159
-rw-r--r--src/ui/window.h7
5 files changed, 279 insertions, 69 deletions
diff --git a/src/ui/core.c b/src/ui/core.c
index 254dd554..5b9970fc 100644
--- a/src/ui/core.c
+++ b/src/ui/core.c
@@ -209,6 +209,34 @@ ui_readline(void)
 }
 
 void
+ui_page_up(void)
+{
+    ProfWin *current = wins_get_current();
+    win_page_up(current);
+}
+
+void
+ui_page_down(void)
+{
+    ProfWin *current = wins_get_current();
+    win_page_down(current);
+}
+
+void
+ui_subwin_page_up(void)
+{
+    ProfWin *current = wins_get_current();
+    win_sub_page_up(current);
+}
+
+void
+ui_subwin_page_down(void)
+{
+    ProfWin *current = wins_get_current();
+    win_sub_page_down(current);
+}
+
+void
 ui_input_clear(void)
 {
     inp_win_clear();
diff --git a/src/ui/inputwin.c b/src/ui/inputwin.c
index 627f9da7..c6d15dce 100644
--- a/src/ui/inputwin.c
+++ b/src/ui/inputwin.c
@@ -88,6 +88,12 @@ cb_linehandler(char *line)
     free(line);
 }
 
+void
+resize_signal_handler(int signal)
+{
+    ui_resize();
+}
+
 int
 tab_handler(int count, int key)
 {
@@ -114,10 +120,144 @@ tab_handler(int count, int key)
     return 0;
 }
 
-void
-resize_signal_handler(int signal)
+int
+alt1_handler(int count, int key)
 {
-    ui_resize();
+    ui_switch_win(1);
+    return 0;
+}
+
+int
+alt2_handler(int count, int key)
+{
+    ui_switch_win(2);
+    return 0;
+}
+
+int
+alt3_handler(int count, int key)
+{
+    ui_switch_win(3);
+    return 0;
+}
+
+int
+alt4_handler(int count, int key)
+{
+    ui_switch_win(4);
+    return 0;
+}
+
+int
+alt5_handler(int count, int key)
+{
+    ui_switch_win(5);
+    return 0;
+}
+
+int
+alt6_handler(int count, int key)
+{
+    ui_switch_win(6);
+    return 0;
+}
+
+int
+alt7_handler(int count, int key)
+{
+    ui_switch_win(7);
+    return 0;
+}
+
+int
+alt8_handler(int count, int key)
+{
+    ui_switch_win(8);
+    return 0;
+}
+
+int
+alt9_handler(int count, int key)
+{
+    ui_switch_win(9);
+    return 0;
+}
+
+int
+alt0_handler(int count, int key)
+{
+    ui_switch_win(0);
+    return 0;
+}
+
+int
+altleft_handler(int count, int key)
+{
+    ui_previous_win();
+    return 0;
+}
+
+int
+altright_handler(int count, int key)
+{
+    ui_next_win();
+    return 0;
+}
+
+int
+pageup_handler(int count, int key)
+{
+    ui_page_up();
+    return 0;
+}
+
+int
+pagedown_handler(int count, int key)
+{
+    ui_page_down();
+    return 0;
+}
+
+int
+altpageup_handler(int count, int key)
+{
+    ui_subwin_page_up();
+    return 0;
+}
+
+int
+altpagedown_handler(int count, int key)
+{
+    ui_subwin_page_down();
+    return 0;
+}
+
+int
+startup_hook(void)
+{
+    rl_bind_keyseq("\\e1", alt1_handler);
+    rl_bind_keyseq("\\e2", alt2_handler);
+    rl_bind_keyseq("\\e3", alt3_handler);
+    rl_bind_keyseq("\\e4", alt4_handler);
+    rl_bind_keyseq("\\e5", alt5_handler);
+    rl_bind_keyseq("\\e6", alt6_handler);
+    rl_bind_keyseq("\\e7", alt7_handler);
+    rl_bind_keyseq("\\e8", alt8_handler);
+    rl_bind_keyseq("\\e9", alt9_handler);
+    rl_bind_keyseq("\\e0", alt0_handler);
+
+    rl_bind_keyseq("\\e[1;3D", altleft_handler);
+    rl_bind_keyseq("\\e[1;3C", altright_handler);
+
+    rl_bind_keyseq("\\e[5~", pageup_handler);
+    rl_bind_keyseq("\\e[6~", pagedown_handler);
+
+    rl_bind_keyseq("\\e[5;3~", altpageup_handler);
+    rl_bind_keyseq("\\e[6;3~", altpagedown_handler);
+
+    rl_bind_key('\t', tab_handler);
+
+    return 0;
 }
 
 void
@@ -130,8 +270,8 @@ create_input_window(void)
 #endif
 	p_rl_timeout.tv_sec = 0;
     p_rl_timeout.tv_usec = inp_timeout * 1000;
+    rl_startup_hook = startup_hook;
     rl_callback_handler_install(NULL, cb_linehandler);
-    rl_bind_key('\t', tab_handler);
 
     signal(SIGWINCH, resize_signal_handler);
 
@@ -140,6 +280,7 @@ create_input_window(void)
     keypad(inp_win, TRUE);
     wmove(inp_win, 0, 0);
 
+
     _inp_win_update_virtual();
 }
 
diff --git a/src/ui/ui.h b/src/ui/ui.h
index 2cfb6e6e..5008593f 100644
--- a/src/ui/ui.h
+++ b/src/ui/ui.h
@@ -218,6 +218,11 @@ void ui_tidy_wins(void);
 void ui_prune_wins(void);
 gboolean ui_swap_wins(int source_win, int target_win);
 
+void ui_page_up(void);
+void ui_page_down(void);
+void ui_subwin_page_up(void);
+void ui_subwin_page_down(void);
+
 void ui_auto_away(void);
 void ui_end_auto_away(void);
 void ui_titlebar_presence(contact_presence_t presence);
diff --git a/src/ui/window.c b/src/ui/window.c
index dfec5aab..915acb3c 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -358,7 +358,101 @@ win_free(ProfWin* window)
 }
 
 void
-win_handle_page(ProfWin *window, const wint_t ch, const int result)
+win_page_up(ProfWin *window)
+{
+    int rows = getmaxy(stdscr);
+    int y = getcury(window->layout->win);
+    int page_space = rows - 4;
+    int *page_start = &(window->layout->y_pos);
+
+    *page_start -= page_space;
+
+    // went past beginning, show first page
+    if (*page_start < 0)
+        *page_start = 0;
+
+    window->layout->paged = 1;
+    win_update_virtual(window);
+
+    // switch off page if last line and space line visible
+    if ((y) - *page_start == page_space) {
+        window->layout->paged = 0;
+    }
+}
+
+void
+win_page_down(ProfWin *window)
+{
+    int rows = getmaxy(stdscr);
+    int y = getcury(window->layout->win);
+    int page_space = rows - 4;
+    int *page_start = &(window->layout->y_pos);
+
+    *page_start += page_space;
+
+    // only got half a screen, show full screen
+    if ((y - (*page_start)) < page_space)
+        *page_start = y - page_space;
+
+    // went past end, show full screen
+    else if (*page_start >= y)
+        *page_start = y - page_space - 1;
+
+    window->layout->paged = 1;
+    win_update_virtual(window);
+
+    // switch off page if last line and space line visible
+    if ((y) - *page_start == page_space) {
+        window->layout->paged = 0;
+    }
+}
+
+void
+win_sub_page_down(ProfWin *window)
+{
+
+    if (window->layout->type == LAYOUT_SPLIT) {
+        int rows = getmaxy(stdscr);
+        int page_space = rows - 4;
+        ProfLayoutSplit *split_layout = (ProfLayoutSplit*)window->layout;
+        int sub_y = getcury(split_layout->subwin);
+        int *sub_y_pos = &(split_layout->sub_y_pos);
+
+        *sub_y_pos += page_space;
+
+        // only got half a screen, show full screen
+        if ((sub_y- (*sub_y_pos)) < page_space)
+            *sub_y_pos = sub_y - page_space;
+
+        // went past end, show full screen
+        else if (*sub_y_pos >= sub_y)
+            *sub_y_pos = sub_y - page_space - 1;
+
+        win_update_virtual(window);
+    }
+}
+
+void
+win_sub_page_up(ProfWin *window)
+{
+    if (window->layout->type == LAYOUT_SPLIT) {
+        int rows = getmaxy(stdscr);
+        int page_space = rows - 4;
+        ProfLayoutSplit *split_layout = (ProfLayoutSplit*)window->layout;
+        int *sub_y_pos = &(split_layout->sub_y_pos);
+
+        *sub_y_pos -= page_space;
+
+        // went past beginning, show first page
+        if (*sub_y_pos < 0)
+            *sub_y_pos = 0;
+
+        win_update_virtual(window);
+    }
+}
+
+void
+win_mouse(ProfWin *window, const wint_t ch, const int result)
 {
     int rows = getmaxy(stdscr);
     int y = getcury(window->layout->win);
@@ -402,69 +496,6 @@ win_handle_page(ProfWin *window, const wint_t ch, const int result)
             }
         }
     }
-
-    // page up
-    if (ch == KEY_PPAGE) {
-        *page_start -= page_space;
-
-        // went past beginning, show first page
-        if (*page_start < 0)
-            *page_start = 0;
-
-        window->layout->paged = 1;
-        win_update_virtual(window);
-
-    // page down
-    } else if (ch == KEY_NPAGE) {
-        *page_start += page_space;
-
-        // only got half a screen, show full screen
-        if ((y - (*page_start)) < page_space)
-            *page_start = y - page_space;
-
-        // went past end, show full screen
-        else if (*page_start >= y)
-            *page_start = y - page_space - 1;
-
-        window->layout->paged = 1;
-        win_update_virtual(window);
-    }
-
-    // switch off page if last line and space line visible
-    if ((y) - *page_start == page_space) {
-        window->layout->paged = 0;
-    }
-
-    if (window->layout->type == LAYOUT_SPLIT) {
-        ProfLayoutSplit *split_layout = (ProfLayoutSplit*)window->layout;
-        int sub_y = getcury(split_layout->subwin);
-        int *sub_y_pos = &(split_layout->sub_y_pos);
-
-        // alt up arrow
-        if ((result == KEY_CODE_YES) && ((ch == 565) || (ch == 337))) {
-            *sub_y_pos -= page_space;
-
-            // went past beginning, show first page
-            if (*sub_y_pos < 0)
-                *sub_y_pos = 0;
-
-            win_update_virtual(window);
-
-        // alt down arrow
-        } else if ((result == KEY_CODE_YES) && ((ch == 524) || (ch == 336))) {
-            *sub_y_pos += page_space;
-
-            // only got half a screen, show full screen
-            if ((sub_y- (*sub_y_pos)) < page_space)
-                *sub_y_pos = sub_y - page_space;
-
-            // went past end, show full screen
-            else if (*sub_y_pos >= sub_y)
-                *sub_y_pos = sub_y - page_space - 1;
-
-            win_update_virtual(window);
-        }
-    }
 }
 
 void
diff --git a/src/ui/window.h b/src/ui/window.h
index fd10a1d7..66e4a5f2 100644
--- a/src/ui/window.h
+++ b/src/ui/window.h
@@ -178,9 +178,14 @@ void win_show_subwin(ProfWin *window);
 int win_roster_cols(void);
 int win_occpuants_cols(void);
 void win_printline_nowrap(WINDOW *win, char *msg);
-void win_handle_page(ProfWin *current, const wint_t ch, const int result);
+void win_mouse(ProfWin *current, const wint_t ch, const int result);
 
 int win_unread(ProfWin *window);
 gboolean win_has_active_subwin(ProfWin *window);
 
+void win_page_up(ProfWin *window);
+void win_page_down(ProfWin *window);
+void win_sub_page_down(ProfWin *window);
+void win_sub_page_up(ProfWin *window);
+
 #endif