clients/view: Add mousewheel and arrow keys

dev
Tim Wiederhake 14 years ago committed by Kristian Høgsberg
parent 7e182ef13b
commit 655467a5d2
  1. 68
      clients/view.c

@ -106,39 +106,73 @@ redraw_handler(struct window *window, void *data)
view_draw(view); view_draw(view);
} }
static void
view_page_up(struct view *view)
{
if(view->page <= 0)
return;
view->page--;
window_schedule_redraw(view->window);
}
static void
view_page_down(struct view *view)
{
if(view->page >= poppler_document_get_n_pages(view->document) - 1)
return;
view->page++;
window_schedule_redraw(view->window);
}
static void
button_handler(struct window *window, struct input *input, uint32_t time,
int button, int state, void *data)
{
struct view *view = data;
if(!state)
return;
switch(button) {
case 275:
view_page_up(view);
break;
case 276:
view_page_down(view);
break;
default:
break;
}
}
static void static void
key_handler(struct window *window, struct input *input, uint32_t time, key_handler(struct window *window, struct input *input, uint32_t time,
uint32_t key, uint32_t unicode, uint32_t state, void *data) uint32_t key, uint32_t unicode, uint32_t state, void *data)
{ {
struct view *view = data; struct view *view = data;
if(!state)
return;
switch (key) { switch (key) {
case KEY_F11: case KEY_F11:
if (!state)
break;
view->fullscreen ^= 1; view->fullscreen ^= 1;
window_set_fullscreen(window, view->fullscreen); window_set_fullscreen(window, view->fullscreen);
window_schedule_redraw(view->window); window_schedule_redraw(view->window);
break; break;
case KEY_SPACE: case KEY_SPACE:
case KEY_PAGEDOWN: case KEY_PAGEDOWN:
if (!state) case KEY_RIGHT:
break; case KEY_DOWN:
view_page_down(view);
if (view->page + 1 < poppler_document_get_n_pages(view->document))
view->page++;
window_schedule_redraw(view->window);
break; break;
case KEY_BACKSPACE: case KEY_BACKSPACE:
case KEY_PAGEUP: case KEY_PAGEUP:
if (!state) case KEY_LEFT:
break; case KEY_UP:
view_page_up(view);
if(view->page > 0)
view->page--;
window_schedule_redraw(view->window);
break; break;
default: default:
break; break;
@ -179,7 +213,7 @@ view_create(struct display *display, uint32_t key, const char *filename)
window_set_key_handler(view->window, key_handler); window_set_key_handler(view->window, key_handler);
window_set_keyboard_focus_handler(view->window, window_set_keyboard_focus_handler(view->window,
keyboard_focus_handler); keyboard_focus_handler);
window_set_button_handler(view->window, button_handler);
view->document = poppler_document_new_from_file(filename, view->document = poppler_document_new_from_file(filename,
NULL, &error); NULL, &error);
view->page = 0; view->page = 0;

Loading…
Cancel
Save