Simplify sc_mouse_scroll

This commit is contained in:
Moritz Lipp 2012-02-15 11:48:28 +01:00
parent b815fa6ecf
commit 65d2241e06
2 changed files with 49 additions and 45 deletions

View file

@ -169,17 +169,17 @@ config_load_default(zathura_t* zathura)
girara_shortcut_add(gsession, 0, GDK_KEY_equal, NULL, sc_zoom, FULLSCREEN, ZOOM_SPECIFIC, NULL); girara_shortcut_add(gsession, 0, GDK_KEY_equal, NULL, sc_zoom, FULLSCREEN, ZOOM_SPECIFIC, NULL);
/* mouse events */ /* mouse events */
girara_mouse_event_add(gsession, 0, 0, sc_mouse_scroll, NORMAL, GIRARA_EVENT_SCROLL_UP, 0, NULL); girara_mouse_event_add(gsession, 0, 0, sc_mouse_scroll, NORMAL, GIRARA_EVENT_SCROLL_UP, UP, NULL);
girara_mouse_event_add(gsession, 0, 0, sc_mouse_scroll, FULLSCREEN, GIRARA_EVENT_SCROLL_UP, 0, NULL); girara_mouse_event_add(gsession, 0, 0, sc_mouse_scroll, FULLSCREEN, GIRARA_EVENT_SCROLL_UP, UP, NULL);
girara_mouse_event_add(gsession, 0, 0, sc_mouse_scroll, NORMAL, GIRARA_EVENT_SCROLL_DOWN, 0, NULL); girara_mouse_event_add(gsession, 0, 0, sc_mouse_scroll, NORMAL, GIRARA_EVENT_SCROLL_DOWN, DOWN, NULL);
girara_mouse_event_add(gsession, 0, 0, sc_mouse_scroll, FULLSCREEN, GIRARA_EVENT_SCROLL_DOWN, 0, NULL); girara_mouse_event_add(gsession, 0, 0, sc_mouse_scroll, FULLSCREEN, GIRARA_EVENT_SCROLL_DOWN, DOWN, NULL);
girara_mouse_event_add(gsession, GDK_CONTROL_MASK, 0, sc_mouse_zoom, NORMAL, GIRARA_EVENT_SCROLL_UP, 0, NULL); girara_mouse_event_add(gsession, GDK_CONTROL_MASK, 0, sc_mouse_zoom, NORMAL, GIRARA_EVENT_SCROLL_UP, UP, NULL);
girara_mouse_event_add(gsession, GDK_CONTROL_MASK, 0, sc_mouse_zoom, FULLSCREEN, GIRARA_EVENT_SCROLL_UP, 0, NULL); girara_mouse_event_add(gsession, GDK_CONTROL_MASK, 0, sc_mouse_zoom, FULLSCREEN, GIRARA_EVENT_SCROLL_UP, UP, NULL);
girara_mouse_event_add(gsession, GDK_CONTROL_MASK, 0, sc_mouse_zoom, NORMAL, GIRARA_EVENT_SCROLL_DOWN, 0, NULL); girara_mouse_event_add(gsession, GDK_CONTROL_MASK, 0, sc_mouse_zoom, NORMAL, GIRARA_EVENT_SCROLL_DOWN, DOWN, NULL);
girara_mouse_event_add(gsession, GDK_CONTROL_MASK, 0, sc_mouse_zoom, FULLSCREEN, GIRARA_EVENT_SCROLL_DOWN, 0, NULL); girara_mouse_event_add(gsession, GDK_CONTROL_MASK, 0, sc_mouse_zoom, FULLSCREEN, GIRARA_EVENT_SCROLL_DOWN, DOWN, NULL);
girara_mouse_event_add(gsession, 0, GIRARA_MOUSE_BUTTON2, sc_mouse_scroll, NORMAL, GIRARA_EVENT_BUTTON_PRESS, 0, NULL); girara_mouse_event_add(gsession, 0, GIRARA_MOUSE_BUTTON2, sc_mouse_scroll, NORMAL, GIRARA_EVENT_BUTTON_PRESS, 0, NULL);
girara_mouse_event_add(gsession, GDK_BUTTON2_MASK, GIRARA_MOUSE_BUTTON2, sc_mouse_scroll, NORMAL, GIRARA_EVENT_BUTTON_RELEASE, 0, NULL); girara_mouse_event_add(gsession, GDK_BUTTON2_MASK, GIRARA_MOUSE_BUTTON2, sc_mouse_scroll, NORMAL, GIRARA_EVENT_BUTTON_RELEASE, 0, NULL);
girara_mouse_event_add(gsession, GDK_BUTTON2_MASK, 0, sc_mouse_scroll, NORMAL, GIRARA_EVENT_MOTION_NOTIFY, 0, NULL); girara_mouse_event_add(gsession, GDK_BUTTON2_MASK, 0, sc_mouse_scroll, NORMAL, GIRARA_EVENT_MOTION_NOTIFY, 0, NULL);
/* define default inputbar commands */ /* define default inputbar commands */
girara_inputbar_command_add(gsession, "bmark", NULL, cmd_bookmark_create, NULL, "Add a bookmark"); girara_inputbar_command_add(gsession, "bmark", NULL, cmd_bookmark_create, NULL, "Add a bookmark");

View file

@ -192,47 +192,51 @@ sc_mouse_scroll(girara_session_t* session, girara_argument_t* argument, girara_e
g_return_val_if_fail(argument != NULL, false); g_return_val_if_fail(argument != NULL, false);
g_return_val_if_fail(event != NULL, false); g_return_val_if_fail(event != NULL, false);
static int x = 0;
static int y = 0;
if (zathura->document == NULL) { if (zathura->document == NULL) {
return false; return false;
} }
/* scroll event */ static int x = 0;
if (event->type == GIRARA_EVENT_SCROLL_UP) { static int y = 0;
argument->n = UP;
return sc_scroll(session, argument, NULL, t);
} else if (event->type == GIRARA_EVENT_SCROLL_DOWN) {
argument->n = DOWN;
return sc_scroll(session, argument, NULL, t);
} else if (event->type == GIRARA_EVENT_SCROLL_LEFT) {
argument->n = LEFT;
return sc_scroll(session, argument, NULL, t);
} else if (event->type == GIRARA_EVENT_SCROLL_RIGHT) {
argument->n = RIGHT;
return sc_scroll(session, argument, NULL, t);
} else if (event->type == GIRARA_EVENT_BUTTON_PRESS) {
x = event->x;
y = event->y;
} else if (event->type == GIRARA_EVENT_BUTTON_RELEASE) {
x = 0;
y = 0;
} else if (event->type == GIRARA_EVENT_MOTION_NOTIFY) {
GtkAdjustment* x_adj =
gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(session->gtk.view));
GtkAdjustment* y_adj =
gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(session->gtk.view));
if (x_adj == NULL || y_adj == NULL) { GtkAdjustment* x_adj = NULL;
return false; GtkAdjustment* y_adj = NULL;
}
set_adjustment(x_adj, gtk_adjustment_get_value(x_adj) - (event->x - x)); switch (event->type) {
set_adjustment(y_adj, gtk_adjustment_get_value(y_adj) - (event->y - y)); /* scroll */
case GIRARA_EVENT_SCROLL_UP:
case GIRARA_EVENT_SCROLL_DOWN:
case GIRARA_EVENT_SCROLL_LEFT:
case GIRARA_EVENT_SCROLL_RIGHT:
return sc_scroll(session, argument, NULL, t);
x = event->x; /* drag */
y = event->y; case GIRARA_EVENT_BUTTON_PRESS:
x = event->x;
y = event->y;
break;
case GIRARA_EVENT_BUTTON_RELEASE:
x = 0;
y = 0;
break;
case GIRARA_EVENT_MOTION_NOTIFY:
x_adj = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(session->gtk.view));
y_adj =gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(session->gtk.view));
if (x_adj == NULL || y_adj == NULL) {
return false;
}
set_adjustment(x_adj, gtk_adjustment_get_value(x_adj) - (event->x - x));
set_adjustment(y_adj, gtk_adjustment_get_value(y_adj) - (event->y - y));
x = event->x;
y = event->y;
break;
/* unhandled events */
default:
break;
} }
return false; return false;