mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-29 15:56:00 +01:00
Move static variables to zathura instance
Fixes another memory leak. Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
This commit is contained in:
parent
4f6bd04f23
commit
4a1852b02c
3 changed files with 48 additions and 24 deletions
|
@ -268,9 +268,6 @@ sc_mouse_scroll(girara_session_t* session, girara_argument_t* argument, girara_e
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int x = 0;
|
|
||||||
static int y = 0;
|
|
||||||
|
|
||||||
GtkAdjustment* x_adj = NULL;
|
GtkAdjustment* x_adj = NULL;
|
||||||
GtkAdjustment* y_adj = NULL;
|
GtkAdjustment* y_adj = NULL;
|
||||||
|
|
||||||
|
@ -285,12 +282,12 @@ sc_mouse_scroll(girara_session_t* session, girara_argument_t* argument, girara_e
|
||||||
|
|
||||||
/* drag */
|
/* drag */
|
||||||
case GIRARA_EVENT_BUTTON_PRESS:
|
case GIRARA_EVENT_BUTTON_PRESS:
|
||||||
x = event->x;
|
zathura->shortcut.mouse.x = event->x;
|
||||||
y = event->y;
|
zathura->shortcut.mouse.y = event->y;
|
||||||
break;
|
break;
|
||||||
case GIRARA_EVENT_BUTTON_RELEASE:
|
case GIRARA_EVENT_BUTTON_RELEASE:
|
||||||
x = 0;
|
zathura->shortcut.mouse.x = 0;
|
||||||
y = 0;
|
zathura->shortcut.mouse.y = 0;
|
||||||
break;
|
break;
|
||||||
case GIRARA_EVENT_MOTION_NOTIFY:
|
case GIRARA_EVENT_MOTION_NOTIFY:
|
||||||
x_adj = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(session->gtk.view));
|
x_adj = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(session->gtk.view));
|
||||||
|
@ -301,9 +298,9 @@ sc_mouse_scroll(girara_session_t* session, girara_argument_t* argument, girara_e
|
||||||
}
|
}
|
||||||
|
|
||||||
zathura_adjustment_set_value(x_adj,
|
zathura_adjustment_set_value(x_adj,
|
||||||
gtk_adjustment_get_value(x_adj) - (event->x - x));
|
gtk_adjustment_get_value(x_adj) - (event->x - zathura->shortcut.mouse.x));
|
||||||
zathura_adjustment_set_value(y_adj,
|
zathura_adjustment_set_value(y_adj,
|
||||||
gtk_adjustment_get_value(y_adj) - (event->y - y));
|
gtk_adjustment_get_value(y_adj) - (event->y - zathura->shortcut.mouse.y));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* unhandled events */
|
/* unhandled events */
|
||||||
|
@ -1223,12 +1220,11 @@ sc_toggle_page_mode(girara_session_t* session, girara_argument_t*
|
||||||
int pages_per_row = 1;
|
int pages_per_row = 1;
|
||||||
girara_setting_get(zathura->ui.session, "pages-per-row", &pages_per_row);
|
girara_setting_get(zathura->ui.session, "pages-per-row", &pages_per_row);
|
||||||
|
|
||||||
static int tmp = 2;
|
|
||||||
int value = 1;
|
int value = 1;
|
||||||
if (pages_per_row == 1) {
|
if (pages_per_row == 1) {
|
||||||
value = tmp;
|
value = zathura->shortcut.toggle_page_mode.pages;
|
||||||
} else {
|
} else {
|
||||||
tmp = pages_per_row;
|
zathura->shortcut.toggle_page_mode.pages = pages_per_row;
|
||||||
}
|
}
|
||||||
|
|
||||||
girara_setting_set(zathura->ui.session, "pages-per-row", &value);
|
girara_setting_set(zathura->ui.session, "pages-per-row", &value);
|
||||||
|
@ -1277,18 +1273,14 @@ sc_toggle_presentation(girara_session_t* session, girara_argument_t*
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int pages_per_row = 1;
|
|
||||||
static char* first_page_column_list = NULL;
|
|
||||||
static double zoom = 1.0;
|
|
||||||
|
|
||||||
const girara_mode_t old_mode = girara_mode_get(session);
|
const girara_mode_t old_mode = girara_mode_get(session);
|
||||||
if (old_mode == zathura->modes.presentation) {
|
if (old_mode == zathura->modes.presentation) {
|
||||||
/* reset pages per row */
|
/* reset pages per row */
|
||||||
girara_setting_set(session, "pages-per-row", &pages_per_row);
|
girara_setting_set(session, "pages-per-row", &zathura->shortcut.toggle_presentation_mode.pages);
|
||||||
|
|
||||||
/* reset first page column */
|
/* reset first page column */
|
||||||
if (first_page_column_list != NULL) {
|
if (zathura->shortcut.toggle_presentation_mode.first_page_column_list != NULL) {
|
||||||
girara_setting_set(session, "first-page-column", first_page_column_list);
|
girara_setting_set(session, "first-page-column", zathura->shortcut.toggle_presentation_mode.first_page_column_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* show status bar */
|
/* show status bar */
|
||||||
|
@ -1298,7 +1290,7 @@ sc_toggle_presentation(girara_session_t* session, girara_argument_t*
|
||||||
gtk_window_unfullscreen(GTK_WINDOW(session->gtk.window));
|
gtk_window_unfullscreen(GTK_WINDOW(session->gtk.window));
|
||||||
|
|
||||||
/* reset scale */
|
/* reset scale */
|
||||||
zathura_document_set_scale(zathura->document, zoom);
|
zathura_document_set_scale(zathura->document, zathura->shortcut.toggle_presentation_mode.zoom);
|
||||||
render_all(zathura);
|
render_all(zathura);
|
||||||
refresh_view(zathura);
|
refresh_view(zathura);
|
||||||
|
|
||||||
|
@ -1306,19 +1298,20 @@ sc_toggle_presentation(girara_session_t* session, girara_argument_t*
|
||||||
girara_mode_set(session, zathura->modes.normal);
|
girara_mode_set(session, zathura->modes.normal);
|
||||||
} else if (old_mode == zathura->modes.normal) {
|
} else if (old_mode == zathura->modes.normal) {
|
||||||
/* backup pages per row */
|
/* backup pages per row */
|
||||||
girara_setting_get(session, "pages-per-row", &pages_per_row);
|
girara_setting_get(session, "pages-per-row", &zathura->shortcut.toggle_presentation_mode.pages);
|
||||||
|
|
||||||
/* backup first page column */
|
/* backup first page column */
|
||||||
g_free(first_page_column_list);
|
g_free(zathura->shortcut.toggle_presentation_mode.first_page_column_list);
|
||||||
|
zathura->shortcut.toggle_presentation_mode.first_page_column_list = NULL;
|
||||||
/* this will leak. we need to move the values somewhere else */
|
/* this will leak. we need to move the values somewhere else */
|
||||||
girara_setting_get(session, "first-page-column", &first_page_column_list);
|
girara_setting_get(session, "first-page-column", &zathura->shortcut.toggle_presentation_mode.first_page_column_list);
|
||||||
|
|
||||||
/* set single view */
|
/* set single view */
|
||||||
int int_value = 1;
|
int int_value = 1;
|
||||||
girara_setting_set(session, "pages-per-row", &int_value);
|
girara_setting_set(session, "pages-per-row", &int_value);
|
||||||
|
|
||||||
/* back up zoom */
|
/* back up zoom */
|
||||||
zoom = zathura_document_get_scale(zathura->document);
|
zathura->shortcut.toggle_presentation_mode.zoom = zathura_document_get_scale(zathura->document);
|
||||||
|
|
||||||
/* adjust window */
|
/* adjust window */
|
||||||
girara_argument_t argument = { ZATHURA_ADJUST_BESTFIT, NULL };
|
girara_argument_t argument = { ZATHURA_ADJUST_BESTFIT, NULL };
|
||||||
|
|
|
@ -278,6 +278,16 @@ zathura_init(zathura_t* zathura)
|
||||||
girara_template_set_base(csstemplate, css);
|
girara_template_set_base(csstemplate, css);
|
||||||
g_free(css);
|
g_free(css);
|
||||||
|
|
||||||
|
/* Shortcut helpers */
|
||||||
|
zathura->shortcut.mouse.x = 0;
|
||||||
|
zathura->shortcut.mouse.y = 0;
|
||||||
|
|
||||||
|
zathura->shortcut.toggle_page_mode.pages = 2;
|
||||||
|
|
||||||
|
zathura->shortcut.toggle_presentation_mode.pages = 1;
|
||||||
|
zathura->shortcut.toggle_presentation_mode.first_page_column_list = NULL;
|
||||||
|
zathura->shortcut.toggle_presentation_mode.zoom = 1.0;
|
||||||
|
|
||||||
/* Start D-Bus service */
|
/* Start D-Bus service */
|
||||||
bool dbus = true;
|
bool dbus = true;
|
||||||
girara_setting_get(zathura->ui.session, "dbus-service", &dbus);
|
girara_setting_get(zathura->ui.session, "dbus-service", &dbus);
|
||||||
|
@ -315,6 +325,9 @@ zathura_free(zathura_t* zathura)
|
||||||
girara_session_destroy(zathura->ui.session);
|
girara_session_destroy(zathura->ui.session);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* shortcut */
|
||||||
|
g_free(zathura->shortcut.toggle_presentation_mode.first_page_column_list);
|
||||||
|
|
||||||
/* stdin support */
|
/* stdin support */
|
||||||
if (zathura->stdin_support.file != NULL) {
|
if (zathura->stdin_support.file != NULL) {
|
||||||
g_unlink(zathura->stdin_support.file);
|
g_unlink(zathura->stdin_support.file);
|
||||||
|
|
|
@ -204,6 +204,24 @@ struct zathura_s
|
||||||
unsigned int start; /**< Bisection range - start */
|
unsigned int start; /**< Bisection range - start */
|
||||||
unsigned int end; /**< Bisection range - end */
|
unsigned int end; /**< Bisection range - end */
|
||||||
} bisect;
|
} bisect;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Storage for shortcuts.
|
||||||
|
*/
|
||||||
|
struct {
|
||||||
|
struct {
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
} mouse;
|
||||||
|
struct {
|
||||||
|
int pages;
|
||||||
|
} toggle_page_mode;
|
||||||
|
struct {
|
||||||
|
int pages;
|
||||||
|
char* first_page_column_list;
|
||||||
|
double zoom;
|
||||||
|
} toggle_presentation_mode;
|
||||||
|
} shortcut;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue