Skip to content

Commit c6e539b

Browse files
committed
Use new helper functions
1 parent 9af6233 commit c6e539b

File tree

1 file changed

+64
-55
lines changed

1 file changed

+64
-55
lines changed

zathura/zathura.c

Lines changed: 64 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,11 @@ void zathura_update_view_ppi(zathura_t* zathura) {
197197
}
198198
#endif
199199

200-
const double current_ppi = zathura_document_get_viewport_ppi(zathura->document);
200+
zathura_document_t* document = zathura_get_document(zathura);
201+
const double current_ppi = zathura_document_get_viewport_ppi(document);
201202
if (fabs(ppi - current_ppi) > DBL_EPSILON) {
202203
girara_debug("monitor width: %d mm, pixels: %d, ppi: %0.2f", width_mm, monitor_geom.width, ppi);
203-
zathura_document_set_viewport_ppi(zathura->document, ppi);
204+
zathura_document_set_viewport_ppi(document, ppi);
204205
adjust_view(zathura);
205206
render_all(zathura);
206207
refresh_view(zathura);
@@ -803,12 +804,13 @@ static gboolean document_info_open(gpointer data) {
803804
}
804805

805806
char* get_formatted_filename(zathura_t* zathura, bool statusbar) {
806-
bool basename_only = false;
807-
const char* file_path = NULL;
808-
if (zathura->document != NULL) {
809-
file_path = zathura_document_get_uri(zathura->document);
807+
bool basename_only = false;
808+
const char* file_path = NULL;
809+
zathura_document_t* document = zathura_get_document(zathura);
810+
if (document != NULL) {
811+
file_path = zathura_document_get_uri(document);
810812
if (file_path == NULL) {
811-
file_path = zathura_document_get_path(zathura->document);
813+
file_path = zathura_document_get_path(document);
812814
}
813815
}
814816
if (statusbar == true) {
@@ -843,7 +845,7 @@ char* get_formatted_filename(zathura_t* zathura, bool statusbar) {
843845
return g_strdup(file_path);
844846
}
845847
} else {
846-
const char* basename = zathura_document_get_basename(zathura->document);
848+
const char* basename = zathura_document_get_basename(document);
847849
return g_strdup(basename);
848850
}
849851
}
@@ -1101,9 +1103,9 @@ bool document_open(zathura_t* zathura, const char* path, const char* uri, const
11011103
GtkAdjustment* vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view));
11021104

11031105
const unsigned int view_width = floor(gtk_adjustment_get_page_size(hadjustment));
1104-
zathura_document_set_viewport_width(zathura->document, view_width);
1106+
zathura_document_set_viewport_width(document, view_width);
11051107
const unsigned int view_height = floor(gtk_adjustment_get_page_size(vadjustment));
1106-
zathura_document_set_viewport_height(zathura->document, view_height);
1108+
zathura_document_set_viewport_height(document, view_height);
11071109

11081110
zathura_update_view_ppi(zathura);
11091111

@@ -1112,7 +1114,7 @@ bool document_open(zathura_t* zathura, const char* path, const char* uri, const
11121114

11131115
/* get initial device scale */
11141116
const int device_factor = gtk_widget_get_scale_factor(zathura->ui.session->gtk.view);
1115-
zathura_document_set_device_factors(zathura->document, device_factor, device_factor);
1117+
zathura_document_set_device_factors(document, device_factor, device_factor);
11161118

11171119
/* create blank pages */
11181120
zathura->pages = calloc(number_of_pages, sizeof(GtkWidget*));
@@ -1182,7 +1184,7 @@ bool document_open(zathura_t* zathura, const char* path, const char* uri, const
11821184
page_right_to_left = file_info.page_right_to_left;
11831185

11841186
page_widget_set_mode(zathura, page_padding, pages_per_row, first_page_column, page_right_to_left);
1185-
zathura_document_set_page_layout(zathura->document, page_padding, pages_per_row, first_page_column);
1187+
zathura_document_set_page_layout(document, page_padding, pages_per_row, first_page_column);
11861188

11871189
girara_set_view(zathura->ui.session, zathura->ui.page_widget);
11881190

@@ -1320,14 +1322,14 @@ void document_open_idle(zathura_t* zathura, const char* path, const char* passwo
13201322
}
13211323

13221324
bool document_save(zathura_t* zathura, const char* path, bool overwrite) {
1323-
g_return_val_if_fail(zathura, false);
1324-
g_return_val_if_fail(zathura->document, false);
1325+
zathura_document_t* document = zathura_get_document(zathura);
1326+
g_return_val_if_fail(document, false);
13251327
g_return_val_if_fail(path, false);
13261328

13271329
gchar* file_path = girara_fix_path(path);
13281330
/* use current basename if path points to a directory */
13291331
if (g_file_test(file_path, G_FILE_TEST_IS_DIR) == TRUE) {
1330-
char* basename = g_path_get_basename(zathura_document_get_path(zathura->document));
1332+
char* basename = g_path_get_basename(zathura_document_get_path(document));
13311333
char* tmp = file_path;
13321334
file_path = g_build_filename(file_path, basename, NULL);
13331335
g_free(tmp);
@@ -1341,7 +1343,7 @@ bool document_save(zathura_t* zathura, const char* path, bool overwrite) {
13411343
return false;
13421344
}
13431345

1344-
const zathura_error_t error = zathura_document_save_as(zathura->document, file_path);
1346+
const zathura_error_t error = zathura_document_save_as(document, file_path);
13451347
g_free(file_path);
13461348

13471349
if (error != ZATHURA_ERROR_OK) {
@@ -1380,16 +1382,17 @@ static zathura_fileinfo_t zathura_get_document_fileinfo(zathura_t* zathura, zath
13801382
}
13811383

13821384
zathura_fileinfo_t zathura_get_fileinfo(zathura_t* zathura) {
1383-
return zathura_get_document_fileinfo(zathura, zathura->document);
1385+
return zathura_get_document_fileinfo(zathura, zathura_get_document(zathura));
13841386
}
13851387

13861388
zathura_fileinfo_t zathura_get_prefileinfo(zathura_t* zathura) {
13871389
return zathura_get_document_fileinfo(zathura, zathura->predecessor_document);
13881390
}
13891391

13901392
static void save_fileinfo_to_db(zathura_t* zathura) {
1391-
const char* path = zathura_document_get_path(zathura->document);
1392-
const uint8_t* file_hash = zathura_document_get_hash(zathura->document);
1393+
zathura_document_t* document = zathura_get_document(zathura);
1394+
const char* path = zathura_document_get_path(document);
1395+
const uint8_t* file_hash = zathura_document_get_hash(document);
13931396

13941397
zathura_fileinfo_t file_info = zathura_get_fileinfo(zathura);
13951398

@@ -1427,7 +1430,7 @@ bool document_predecessor_free(zathura_t* zathura) {
14271430
}
14281431

14291432
bool document_close(zathura_t* zathura, bool keep_monitor) {
1430-
if (zathura == NULL || zathura->document == NULL) {
1433+
if (zathura_has_document(zathura)) {
14311434
return false;
14321435
}
14331436

@@ -1475,11 +1478,12 @@ bool document_close(zathura_t* zathura, bool keep_monitor) {
14751478
g_clear_object(&zathura->sync.render_thread);
14761479

14771480
/* keep the current state to prevent flicker? */
1478-
bool override_predecessor = keep_monitor;
1481+
bool override_predecessor = keep_monitor;
1482+
zathura_document_t* document = zathura_get_document(zathura);
14791483

14801484
if (override_predecessor) {
14811485
/* do not override predecessor buffer with empty pages */
1482-
unsigned int cur_page_num = zathura_document_get_current_page_number(zathura->document);
1486+
unsigned int cur_page_num = zathura_document_get_current_page_number(document);
14831487
ZathuraPage* cur_page = ZATHURA_PAGE(zathura->pages[cur_page_num]);
14841488
if (!zathura_page_widget_have_surface(cur_page)) {
14851489
override_predecessor = false;
@@ -1503,7 +1507,7 @@ bool document_close(zathura_t* zathura, bool keep_monitor) {
15031507
gtk_container_foreach(GTK_CONTAINER(zathura->ui.page_widget), remove_page_from_table, NULL);
15041508

15051509
if (!override_predecessor) {
1506-
for (unsigned int i = 0; i < zathura_document_get_number_of_pages(zathura->document); i++) {
1510+
for (unsigned int i = 0; i < zathura_document_get_number_of_pages(document); i++) {
15071511
g_object_unref(zathura->pages[i]);
15081512
}
15091513
free(zathura->pages);
@@ -1547,16 +1551,17 @@ bool document_close(zathura_t* zathura, bool keep_monitor) {
15471551
}
15481552

15491553
bool page_set(zathura_t* zathura, unsigned int page_id) {
1550-
if (zathura == NULL || zathura->document == NULL) {
1554+
if (zathura_has_document(zathura) == false) {
15511555
goto error_out;
15521556
}
15531557

1554-
zathura_page_t* page = zathura_document_get_page(zathura->document, page_id);
1558+
zathura_document_t* document = zathura_get_document(zathura);
1559+
zathura_page_t* page = zathura_document_get_page(document, page_id);
15551560
if (page == NULL) {
15561561
goto error_out;
15571562
}
15581563

1559-
zathura_document_set_current_page_number(zathura->document, page_id);
1564+
zathura_document_set_current_page_number(document, page_id);
15601565

15611566
bool continuous_hist_save = false;
15621567
girara_setting_get(zathura->ui.session, "continuous-hist-save", &continuous_hist_save);
@@ -1576,12 +1581,13 @@ void statusbar_page_number_update(zathura_t* zathura) {
15761581
return;
15771582
}
15781583

1579-
unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document);
1580-
unsigned int current_page_number = zathura_document_get_current_page_number(zathura->document);
1581-
unsigned int page_number_percent = number_of_pages ? 100 * (current_page_number + 1) / number_of_pages : 0;
1584+
zathura_document_t* document = zathura_get_document(zathura);
1585+
if (document != NULL) {
1586+
unsigned int number_of_pages = zathura_document_get_number_of_pages(document);
1587+
unsigned int current_page_number = zathura_document_get_current_page_number(document);
1588+
unsigned int page_number_percent = number_of_pages ? 100 * (current_page_number + 1) / number_of_pages : 0;
15821589

1583-
if (zathura->document != NULL) {
1584-
zathura_page_t* page = zathura_document_get_page(zathura->document, current_page_number);
1590+
zathura_page_t* page = zathura_document_get_page(document, current_page_number);
15851591
const char* page_label = zathura_page_get_label(page, NULL);
15861592

15871593
bool show_percent = false;
@@ -1624,6 +1630,11 @@ void statusbar_page_number_update(zathura_t* zathura) {
16241630

16251631
void page_widget_set_mode(zathura_t* zathura, unsigned int page_padding, unsigned int pages_per_row,
16261632
unsigned int first_page_column, bool page_right_to_left) {
1633+
zathura_document_t* document = zathura_get_document(zathura);
1634+
if (document == NULL) {
1635+
return;
1636+
}
1637+
16271638
/* show at least one page */
16281639
if (pages_per_row == 0) {
16291640
pages_per_row = 1;
@@ -1637,13 +1648,9 @@ void page_widget_set_mode(zathura_t* zathura, unsigned int page_padding, unsigne
16371648
first_page_column = ((first_page_column - 1) % pages_per_row) + 1;
16381649
}
16391650

1640-
if (zathura->document == NULL) {
1641-
return;
1642-
}
1643-
16441651
gtk_container_foreach(GTK_CONTAINER(zathura->ui.page_widget), remove_page_from_table, NULL);
16451652

1646-
unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document);
1653+
unsigned int number_of_pages = zathura_document_get_number_of_pages(document);
16471654

16481655
gtk_grid_set_row_spacing(GTK_GRID(zathura->ui.page_widget), page_padding);
16491656
gtk_grid_set_column_spacing(GTK_GRID(zathura->ui.page_widget), page_padding);
@@ -1664,27 +1671,28 @@ void page_widget_set_mode(zathura_t* zathura, unsigned int page_padding, unsigne
16641671
}
16651672

16661673
bool position_set(zathura_t* zathura, double position_x, double position_y) {
1667-
if (zathura == NULL || zathura->document == NULL) {
1674+
zathura_document_t* document = zathura_get_document(zathura);
1675+
if (document == NULL) {
16681676
return false;
16691677
}
16701678

16711679
double comppos_x, comppos_y;
1672-
const unsigned int page_id = zathura_document_get_current_page_number(zathura->document);
1680+
const unsigned int page_id = zathura_document_get_current_page_number(document);
16731681

16741682
bool vertical_center = false;
16751683
girara_setting_get(zathura->ui.session, "vertical-center", &vertical_center);
16761684

16771685
/* xalign = 0.5: center horizontally (with the page, not the document) */
16781686
if (vertical_center == true) {
16791687
/* yalign = 0.5: center vertically */
1680-
page_number_to_position(zathura->document, page_id, 0.5, 0.5, &comppos_x, &comppos_y);
1688+
page_number_to_position(document, page_id, 0.5, 0.5, &comppos_x, &comppos_y);
16811689
} else {
16821690
/* yalign = 0.0: align page and viewport edges at the top */
1683-
page_number_to_position(zathura->document, page_id, 0.5, 0.0, &comppos_x, &comppos_y);
1691+
page_number_to_position(document, page_id, 0.5, 0.0, &comppos_x, &comppos_y);
16841692
}
16851693

16861694
/* automatic horizontal adjustment */
1687-
zathura_adjust_mode_t adjust_mode = zathura_document_get_adjust_mode(zathura->document);
1695+
zathura_adjust_mode_t adjust_mode = zathura_document_get_adjust_mode(document);
16881696

16891697
/* negative position_x mean: use the computed value */
16901698
if (position_x < 0) {
@@ -1703,8 +1711,8 @@ bool position_set(zathura_t* zathura, double position_x, double position_y) {
17031711
}
17041712

17051713
/* set the position */
1706-
zathura_document_set_position_x(zathura->document, position_x);
1707-
zathura_document_set_position_y(zathura->document, position_y);
1714+
zathura_document_set_position_x(document, position_x);
1715+
zathura_document_set_position_y(document, position_y);
17081716

17091717
/* trigger a 'change' event for both adjustments */
17101718
refresh_view(zathura);
@@ -1721,12 +1729,12 @@ void refresh_view(zathura_t* zathura) {
17211729

17221730
bool adjust_view(zathura_t* zathura) {
17231731
g_return_val_if_fail(zathura != NULL, false);
1724-
1725-
if (zathura->ui.page_widget == NULL || zathura->document == NULL) {
1732+
zathura_document_t* document = zathura_get_document(zathura);
1733+
if (zathura->ui.page_widget == NULL || document == NULL) {
17261734
goto error_ret;
17271735
}
17281736

1729-
zathura_adjust_mode_t adjust_mode = zathura_document_get_adjust_mode(zathura->document);
1737+
zathura_adjust_mode_t adjust_mode = zathura_document_get_adjust_mode(document);
17301738
if (adjust_mode == ZATHURA_ADJUST_NONE) {
17311739
/* there is nothing todo */
17321740
goto error_ret;
@@ -1736,17 +1744,17 @@ bool adjust_view(zathura_t* zathura) {
17361744
unsigned int document_height = 0, document_width = 0;
17371745
unsigned int view_height = 0, view_width = 0;
17381746

1739-
zathura_document_get_cell_size(zathura->document, &cell_height, &cell_width);
1740-
zathura_document_get_document_size(zathura->document, &document_height, &document_width);
1741-
zathura_document_get_viewport_size(zathura->document, &view_height, &view_width);
1747+
zathura_document_get_cell_size(document, &cell_height, &cell_width);
1748+
zathura_document_get_document_size(document, &document_height, &document_width);
1749+
zathura_document_get_viewport_size(document, &view_height, &view_width);
17421750

17431751
if (view_height == 0 || view_width == 0 || cell_height == 0 || cell_width == 0 || document_width == 0) {
17441752
goto error_ret;
17451753
}
17461754

17471755
double page_ratio = (double)cell_height / (double)document_width;
17481756
double view_ratio = (double)view_height / (double)view_width;
1749-
double zoom = zathura_document_get_zoom(zathura->document);
1757+
double zoom = zathura_document_get_zoom(document);
17501758
double newzoom = zoom;
17511759

17521760
if (adjust_mode == ZATHURA_ADJUST_WIDTH || (adjust_mode == ZATHURA_ADJUST_BESTFIT && page_ratio < view_ratio)) {
@@ -1758,9 +1766,9 @@ bool adjust_view(zathura_t* zathura) {
17581766
}
17591767

17601768
/* save new zoom and recompute cell size */
1761-
zathura_document_set_zoom(zathura->document, newzoom);
1769+
zathura_document_set_zoom(document, newzoom);
17621770
unsigned int new_cell_height = 0, new_cell_width = 0;
1763-
zathura_document_get_cell_size(zathura->document, &new_cell_height, &new_cell_width);
1771+
zathura_document_get_cell_size(document, &new_cell_height, &new_cell_width);
17641772

17651773
/*
17661774
* XXX requiring a larger difference apparently circumvents #94 for some users; this is not a
@@ -1774,7 +1782,7 @@ bool adjust_view(zathura_t* zathura) {
17741782
refresh_view(zathura);
17751783
} else {
17761784
/* otherwise set the old zoom and leave */
1777-
zathura_document_set_zoom(zathura->document, zoom);
1785+
zathura_document_set_zoom(document, zoom);
17781786
}
17791787

17801788
error_ret:
@@ -1793,15 +1801,16 @@ static gboolean zathura_signal_sigterm(gpointer data) {
17931801
#endif
17941802

17951803
void zathura_show_signature_information(zathura_t* zathura, bool show) {
1796-
if (zathura->document == NULL) {
1804+
zathura_document_t* document = zathura_get_document(zathura);
1805+
if (document == NULL) {
17971806
return;
17981807
}
17991808

18001809
GValue show_sig_info_value = {0};
18011810
g_value_init(&show_sig_info_value, G_TYPE_BOOLEAN);
18021811
g_value_set_boolean(&show_sig_info_value, show);
18031812

1804-
const unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document);
1813+
const unsigned int number_of_pages = zathura_document_get_number_of_pages(document);
18051814
for (unsigned int page = 0; page != number_of_pages; ++page) {
18061815
// draw signature info
18071816
g_object_set_property(G_OBJECT(zathura->pages[page]), "draw-signatures", &show_sig_info_value);

0 commit comments

Comments
 (0)