mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2025-01-30 16:54:57 +01:00
Simplify sc_mouse_scroll
This commit is contained in:
parent
b815fa6ecf
commit
65d2241e06
2 changed files with 49 additions and 45 deletions
22
config.c
22
config.c
|
@ -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);
|
||||
|
||||
/* 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, FULLSCREEN, GIRARA_EVENT_SCROLL_UP, 0, 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, FULLSCREEN, GIRARA_EVENT_SCROLL_DOWN, 0, 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, FULLSCREEN, GIRARA_EVENT_SCROLL_UP, 0, 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, FULLSCREEN, GIRARA_EVENT_SCROLL_DOWN, 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, 0, sc_mouse_scroll, NORMAL, GIRARA_EVENT_MOTION_NOTIFY, 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, UP, 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, DOWN, 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, UP, 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, 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, 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);
|
||||
|
||||
/* define default inputbar commands */
|
||||
girara_inputbar_command_add(gsession, "bmark", NULL, cmd_bookmark_create, NULL, "Add a bookmark");
|
||||
|
|
72
shortcuts.c
72
shortcuts.c
|
@ -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(event != NULL, false);
|
||||
|
||||
static int x = 0;
|
||||
static int y = 0;
|
||||
|
||||
if (zathura->document == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* scroll event */
|
||||
if (event->type == GIRARA_EVENT_SCROLL_UP) {
|
||||
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));
|
||||
static int x = 0;
|
||||
static int y = 0;
|
||||
|
||||
if (x_adj == NULL || y_adj == NULL) {
|
||||
return false;
|
||||
}
|
||||
GtkAdjustment* x_adj = NULL;
|
||||
GtkAdjustment* y_adj = NULL;
|
||||
|
||||
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));
|
||||
switch (event->type) {
|
||||
/* 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;
|
||||
y = event->y;
|
||||
/* drag */
|
||||
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;
|
||||
|
|
Loading…
Reference in a new issue