mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-29 11:16:00 +01:00
Use new foreach macros
Also fixes some memory leaks.
This commit is contained in:
parent
93336db1b5
commit
abd52e45fa
10 changed files with 269 additions and 266 deletions
|
@ -108,9 +108,9 @@ cmd_bookmark_open(girara_session_t* session, girara_list_t* argument_list)
|
|||
if (argc != 1) {
|
||||
GString* string = g_string_new(NULL);
|
||||
|
||||
GIRARA_LIST_FOREACH(zathura->bookmarks.bookmarks, zathura_bookmark_t*, iter, bookmark)
|
||||
GIRARA_LIST_FOREACH_BODY(zathura->bookmarks.bookmarks, zathura_bookmark_t*, bookmark,
|
||||
g_string_append_printf(string, "<b>%s</b>: %u\n", bookmark->id, bookmark->page);
|
||||
GIRARA_LIST_FOREACH_END(zathura->bookmarks.bookmarks, zathura_bookmark_t*, iter, bookmark);
|
||||
);
|
||||
|
||||
if (strlen(string->str) > 0) {
|
||||
g_string_erase(string, strlen(string->str) - 1, 1);
|
||||
|
@ -190,15 +190,15 @@ cmd_info(girara_session_t* session, girara_list_t* UNUSED(argument_list))
|
|||
|
||||
GString* string = g_string_new(NULL);
|
||||
|
||||
GIRARA_LIST_FOREACH(information, zathura_document_information_entry_t*, iter, entry)
|
||||
if (entry != NULL) {
|
||||
for (unsigned int i = 0; i < LENGTH(meta_fields); i++) {
|
||||
if (meta_fields[i].field == entry->type) {
|
||||
g_string_append_printf(string, "<b>%s:</b> %s\n", meta_fields[i].name, entry->value);
|
||||
GIRARA_LIST_FOREACH_BODY(information, zathura_document_information_entry_t*, entry,
|
||||
if (entry != NULL) {
|
||||
for (unsigned int i = 0; i < LENGTH(meta_fields); i++) {
|
||||
if (meta_fields[i].field == entry->type) {
|
||||
g_string_append_printf(string, "<b>%s:</b> %s\n", meta_fields[i].name, entry->value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
GIRARA_LIST_FOREACH_END(information, zathura_document_information_entry_t*, iter, entry);
|
||||
);
|
||||
|
||||
if (strlen(string->str) > 0) {
|
||||
g_string_erase(string, strlen(string->str) - 1, 1);
|
||||
|
@ -535,7 +535,7 @@ cmd_exec(girara_session_t* session, girara_list_t* argument_list)
|
|||
if (zathura->document != NULL) {
|
||||
const char* path = zathura_document_get_path(zathura->document);
|
||||
|
||||
GIRARA_LIST_FOREACH(argument_list, char*, iter, value)
|
||||
GIRARA_LIST_FOREACH_BODY_WITH_ITER(argument_list, char*, iter, value,
|
||||
char* r = girara_replace_substring(value, "$FILE", path);
|
||||
|
||||
if (r != NULL) {
|
||||
|
@ -546,7 +546,7 @@ cmd_exec(girara_session_t* session, girara_list_t* argument_list)
|
|||
girara_list_iterator_set(iter, s);
|
||||
}
|
||||
}
|
||||
GIRARA_LIST_FOREACH_END(argument_list, char*, iter, value);
|
||||
);
|
||||
}
|
||||
|
||||
return girara_exec_with_argument_list(session, argument_list);
|
||||
|
|
|
@ -184,9 +184,9 @@ list_files_for_cc(zathura_t* zathura, const char* input, bool check_file_ext, in
|
|||
goto error_free;
|
||||
}
|
||||
|
||||
GIRARA_LIST_FOREACH(names, const char*, iter, file)
|
||||
girara_completion_group_add_element(group, file, NULL);
|
||||
GIRARA_LIST_FOREACH_END(names, const char*, iter, file);
|
||||
GIRARA_LIST_FOREACH_BODY(names, const char*, file,
|
||||
girara_completion_group_add_element(group, file, NULL);
|
||||
);
|
||||
girara_list_free(names);
|
||||
}
|
||||
|
||||
|
@ -197,10 +197,10 @@ list_files_for_cc(zathura_t* zathura, const char* input, bool check_file_ext, in
|
|||
}
|
||||
|
||||
if (girara_list_size(recent_files) != 0) {
|
||||
GIRARA_LIST_FOREACH(recent_files, const char*, iter, file)
|
||||
GIRARA_LIST_FOREACH_BODY(recent_files, const char*, file,
|
||||
girara_debug("adding %s (recent file)", file);
|
||||
girara_completion_group_add_element(history_group, file, NULL);
|
||||
GIRARA_LIST_FOREACH_END(recent_files, const char*, iter, file);
|
||||
);
|
||||
girara_list_free(recent_files);
|
||||
} else {
|
||||
girara_completion_group_free(history_group);
|
||||
|
@ -278,13 +278,13 @@ cc_bookmarks(girara_session_t* session, const char* input)
|
|||
}
|
||||
|
||||
const size_t input_length = strlen(input);
|
||||
GIRARA_LIST_FOREACH(zathura->bookmarks.bookmarks, zathura_bookmark_t*, iter, bookmark)
|
||||
if (input_length <= strlen(bookmark->id) && !strncmp(input, bookmark->id, input_length)) {
|
||||
gchar* paged = g_strdup_printf(_("Page %d"), bookmark->page);
|
||||
girara_completion_group_add_element(group, bookmark->id, paged);
|
||||
g_free(paged);
|
||||
}
|
||||
GIRARA_LIST_FOREACH_END(zathura->bookmarks.bookmarks, zathura_bookmark_t*, iter, bookmark);
|
||||
GIRARA_LIST_FOREACH_BODY(zathura->bookmarks.bookmarks, zathura_bookmark_t*, bookmark,
|
||||
if (input_length <= strlen(bookmark->id) && !strncmp(input, bookmark->id, input_length)) {
|
||||
gchar* paged = g_strdup_printf(_("Page %d"), bookmark->page);
|
||||
girara_completion_group_add_element(group, bookmark->id, paged);
|
||||
g_free(paged);
|
||||
}
|
||||
);
|
||||
|
||||
girara_completion_add_group(completion, group);
|
||||
|
||||
|
@ -334,14 +334,14 @@ cc_export(girara_session_t* session, const char* input)
|
|||
if (attachments != NULL) {
|
||||
bool added = false;
|
||||
|
||||
GIRARA_LIST_FOREACH(attachments, const char*, iter, attachment)
|
||||
if (input_length <= strlen(attachment) && !strncmp(input, attachment, input_length)) {
|
||||
char* attachment_string = g_strdup_printf("attachment-%s", attachment);
|
||||
girara_completion_group_add_element(attachment_group, attachment_string, NULL);
|
||||
g_free(attachment_string);
|
||||
added = true;
|
||||
}
|
||||
GIRARA_LIST_FOREACH_END(zathura->bookmarks.bookmarks, zathura_bookmark_t*, iter, bookmark);
|
||||
GIRARA_LIST_FOREACH_BODY(attachments, const char*, attachment,
|
||||
if (input_length <= strlen(attachment) && !strncmp(input, attachment, input_length)) {
|
||||
char* attachment_string = g_strdup_printf("attachment-%s", attachment);
|
||||
girara_completion_group_add_element(attachment_group, attachment_string, NULL);
|
||||
g_free(attachment_string);
|
||||
added = true;
|
||||
}
|
||||
);
|
||||
|
||||
if (added == true) {
|
||||
girara_completion_add_group(completion, attachment_group);
|
||||
|
@ -371,14 +371,14 @@ cc_export(girara_session_t* session, const char* input)
|
|||
girara_list_t* images = zathura_page_images_get(page, NULL);
|
||||
if (images != NULL) {
|
||||
unsigned int image_number = 1;
|
||||
GIRARA_LIST_FOREACH(images, zathura_image_t*, iter, UNUSED(image))
|
||||
char* image_string = g_strdup_printf("image-p%d-%d", page_id + 1, image_number);
|
||||
girara_completion_group_add_element(image_group, image_string, NULL);
|
||||
g_free(image_string);
|
||||
GIRARA_LIST_FOREACH_BODY(images, zathura_image_t*, UNUSED(image),
|
||||
char* image_string = g_strdup_printf("image-p%d-%d", page_id + 1, image_number);
|
||||
girara_completion_group_add_element(image_group, image_string, NULL);
|
||||
g_free(image_string);
|
||||
|
||||
added = true;
|
||||
image_number++;
|
||||
GIRARA_LIST_FOREACH_END(images, zathura_image_t*, iter, image);
|
||||
added = true;
|
||||
image_number++;
|
||||
);
|
||||
girara_list_free(images);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -518,7 +518,7 @@ plain_save_jumplist(zathura_database_t* db, const char* file, girara_list_t* jum
|
|||
|
||||
GString* str_val = g_string_new(NULL);
|
||||
|
||||
GIRARA_LIST_FOREACH(jumplist, zathura_jump_t*, iter, jump)
|
||||
GIRARA_LIST_FOREACH_BODY(jumplist, zathura_jump_t*, jump,
|
||||
char buffer[G_ASCII_DTOSTR_BUF_SIZE] = { '\0' };
|
||||
|
||||
g_string_append_printf(str_val, "%d ", jump->page);
|
||||
|
@ -526,7 +526,7 @@ plain_save_jumplist(zathura_database_t* db, const char* file, girara_list_t* jum
|
|||
g_string_append_c(str_val, ' ');
|
||||
g_string_append(str_val, g_ascii_dtostr(buffer, G_ASCII_DTOSTR_BUF_SIZE, jump->y));
|
||||
g_string_append_c(str_val, ' ');
|
||||
GIRARA_LIST_FOREACH_END(jumplist, zathura_jump_t*, iter, jump);
|
||||
);
|
||||
|
||||
zathura_plaindatabase_private_t* priv = ZATHURA_PLAINDATABASE_GET_PRIVATE(db);
|
||||
|
||||
|
|
|
@ -158,35 +158,35 @@ cmd_marks_delete(girara_session_t* session, girara_list_t* argument_list)
|
|||
return false;
|
||||
}
|
||||
|
||||
GIRARA_LIST_FOREACH(argument_list, char*, iter, key_string)
|
||||
if (key_string == NULL) {
|
||||
girara_list_iterator_next(iter);
|
||||
continue;
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < strlen(key_string); i++) {
|
||||
char key = key_string[i];
|
||||
if (((key >= 0x41 && key <= 0x5A) || (key >=
|
||||
0x61 && key <= 0x7A)) == false) {
|
||||
GIRARA_LIST_FOREACH_BODY_WITH_ITER(argument_list, char*, iter, key_string,
|
||||
if (key_string == NULL) {
|
||||
girara_list_iterator_next(iter);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* search for existing mark */
|
||||
girara_list_iterator_t* mark_iter = girara_list_iterator(zathura->global.marks);
|
||||
do {
|
||||
zathura_mark_t* mark = (zathura_mark_t*) girara_list_iterator_data(mark_iter);
|
||||
if (mark == NULL) {
|
||||
for (unsigned int i = 0; i < strlen(key_string); i++) {
|
||||
char key = key_string[i];
|
||||
if (((key >= 0x41 && key <= 0x5A) || (key >=
|
||||
0x61 && key <= 0x7A)) == false) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mark->key == key) {
|
||||
girara_list_remove(zathura->global.marks, mark);
|
||||
continue;
|
||||
}
|
||||
} while (girara_list_iterator_next(mark_iter) != NULL);
|
||||
girara_list_iterator_free(mark_iter);
|
||||
}
|
||||
GIRARA_LIST_FOREACH_END(argument_list, char*, iter, key_string);
|
||||
/* search for existing mark */
|
||||
girara_list_iterator_t* mark_iter = girara_list_iterator(zathura->global.marks);
|
||||
do {
|
||||
zathura_mark_t* mark = (zathura_mark_t*) girara_list_iterator_data(mark_iter);
|
||||
if (mark == NULL) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mark->key == key) {
|
||||
girara_list_remove(zathura->global.marks, mark);
|
||||
continue;
|
||||
}
|
||||
} while (girara_list_iterator_next(mark_iter) != NULL);
|
||||
girara_list_iterator_free(mark_iter);
|
||||
}
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -205,15 +205,16 @@ mark_add(zathura_t* zathura, int key)
|
|||
double scale = zathura_document_get_scale(zathura->document);
|
||||
|
||||
/* search for existing mark */
|
||||
GIRARA_LIST_FOREACH(zathura->global.marks, zathura_mark_t*, iter, mark)
|
||||
if (mark->key == key) {
|
||||
mark->page = page_id;
|
||||
mark->position_x = position_x;
|
||||
mark->position_y = position_y;
|
||||
mark->scale = scale;
|
||||
return;
|
||||
}
|
||||
GIRARA_LIST_FOREACH_END(zathura->global.marks, zathura_mark_t*, iter, mark);
|
||||
GIRARA_LIST_FOREACH_BODY_WITH_ITER(zathura->global.marks, zathura_mark_t*, iter, mark,
|
||||
if (mark->key == key) {
|
||||
mark->page = page_id;
|
||||
mark->position_x = position_x;
|
||||
mark->position_y = position_y;
|
||||
mark->scale = scale;
|
||||
girara_list_iterator_free(iter);
|
||||
return;
|
||||
}
|
||||
);
|
||||
|
||||
/* add new mark */
|
||||
zathura_mark_t* mark = g_try_malloc0(sizeof(zathura_mark_t));
|
||||
|
@ -238,20 +239,20 @@ mark_evaluate(zathura_t* zathura, int key)
|
|||
}
|
||||
|
||||
/* search for existing mark */
|
||||
GIRARA_LIST_FOREACH(zathura->global.marks, zathura_mark_t*, iter, mark)
|
||||
if (mark != NULL && mark->key == key) {
|
||||
zathura_document_set_scale(zathura->document,
|
||||
zathura_correct_scale_value(zathura->ui.session, mark->scale));
|
||||
render_all(zathura);
|
||||
GIRARA_LIST_FOREACH_BODY(zathura->global.marks, zathura_mark_t*, mark,
|
||||
if (mark != NULL && mark->key == key) {
|
||||
zathura_document_set_scale(zathura->document,
|
||||
zathura_correct_scale_value(zathura->ui.session, mark->scale));
|
||||
render_all(zathura);
|
||||
|
||||
zathura_jumplist_add(zathura);
|
||||
page_set(zathura, mark->page);
|
||||
position_set(zathura, mark->position_x, mark->position_y);
|
||||
zathura_jumplist_add(zathura);
|
||||
zathura_jumplist_add(zathura);
|
||||
page_set(zathura, mark->page);
|
||||
position_set(zathura, mark->position_x, mark->position_y);
|
||||
zathura_jumplist_add(zathura);
|
||||
|
||||
return;
|
||||
}
|
||||
GIRARA_LIST_FOREACH_END(zathura->global.marks, zathura_mark_t*, iter, mark);
|
||||
break;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -401,18 +401,18 @@ zathura_page_widget_set_property(GObject* object, guint prop_id, const GValue* v
|
|||
/* get size of text that should be large enough for every link hint */
|
||||
text = get_text_extents("888", priv->zathura, CAIRO_FONT_WEIGHT_BOLD);
|
||||
|
||||
GIRARA_LIST_FOREACH(priv->links.list, zathura_link_t*, iter, link)
|
||||
if (link != NULL) {
|
||||
/* redraw link area */
|
||||
zathura_rectangle_t rectangle = recalc_rectangle(priv->page, zathura_link_get_position(link));
|
||||
redraw_rect(pageview, &rectangle);
|
||||
GIRARA_LIST_FOREACH_BODY(priv->links.list, zathura_link_t*, link,
|
||||
if (link != NULL) {
|
||||
/* redraw link area */
|
||||
zathura_rectangle_t rectangle = recalc_rectangle(priv->page, zathura_link_get_position(link));
|
||||
redraw_rect(pageview, &rectangle);
|
||||
|
||||
/* also redraw area for link hint */
|
||||
rectangle.x2 = rectangle.x1 + text.width;
|
||||
rectangle.y1 = rectangle.y2 - text.height;
|
||||
redraw_rect(pageview, &rectangle);
|
||||
}
|
||||
GIRARA_LIST_FOREACH_END(priv->links.list, zathura_link_t*, iter, link);
|
||||
/* also redraw area for link hint */
|
||||
rectangle.x2 = rectangle.x1 + text.width;
|
||||
rectangle.y1 = rectangle.y2 - text.height;
|
||||
redraw_rect(pageview, &rectangle);
|
||||
}
|
||||
);
|
||||
}
|
||||
break;
|
||||
case PROP_LINKS_OFFSET:
|
||||
|
@ -589,46 +589,46 @@ zathura_page_widget_draw(GtkWidget* widget, cairo_t* cairo)
|
|||
|
||||
if (priv->links.draw == true && priv->links.n != 0) {
|
||||
unsigned int link_counter = 0;
|
||||
GIRARA_LIST_FOREACH(priv->links.list, zathura_link_t*, iter, link)
|
||||
if (link != NULL) {
|
||||
zathura_rectangle_t rectangle = recalc_rectangle(priv->page, zathura_link_get_position(link));
|
||||
GIRARA_LIST_FOREACH_BODY(priv->links.list, zathura_link_t*, link,
|
||||
if (link != NULL) {
|
||||
zathura_rectangle_t rectangle = recalc_rectangle(priv->page, zathura_link_get_position(link));
|
||||
|
||||
/* draw position */
|
||||
const GdkRGBA color = priv->zathura->ui.colors.highlight_color;
|
||||
cairo_set_source_rgba(cairo, color.red, color.green, color.blue, transparency);
|
||||
cairo_rectangle(cairo, rectangle.x1, rectangle.y1,
|
||||
(rectangle.x2 - rectangle.x1), (rectangle.y2 - rectangle.y1));
|
||||
cairo_fill(cairo);
|
||||
/* draw position */
|
||||
const GdkRGBA color = priv->zathura->ui.colors.highlight_color;
|
||||
cairo_set_source_rgba(cairo, color.red, color.green, color.blue, transparency);
|
||||
cairo_rectangle(cairo, rectangle.x1, rectangle.y1,
|
||||
(rectangle.x2 - rectangle.x1), (rectangle.y2 - rectangle.y1));
|
||||
cairo_fill(cairo);
|
||||
|
||||
/* draw text */
|
||||
cairo_set_source_rgba(cairo, 0, 0, 0, 1);
|
||||
cairo_move_to(cairo, rectangle.x1 + 1, rectangle.y2 - 1);
|
||||
char* link_number = g_strdup_printf("%i", priv->links.offset + ++link_counter);
|
||||
cairo_show_text(cairo, link_number);
|
||||
g_free(link_number);
|
||||
}
|
||||
GIRARA_LIST_FOREACH_END(priv->links.list, zathura_link_t*, iter, link);
|
||||
/* draw text */
|
||||
cairo_set_source_rgba(cairo, 0, 0, 0, 1);
|
||||
cairo_move_to(cairo, rectangle.x1 + 1, rectangle.y2 - 1);
|
||||
char* link_number = g_strdup_printf("%i", priv->links.offset + ++link_counter);
|
||||
cairo_show_text(cairo, link_number);
|
||||
g_free(link_number);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/* draw search results */
|
||||
if (priv->search.list != NULL && priv->search.draw == true) {
|
||||
int idx = 0;
|
||||
GIRARA_LIST_FOREACH(priv->search.list, zathura_rectangle_t*, iter, rect)
|
||||
zathura_rectangle_t rectangle = recalc_rectangle(priv->page, *rect);
|
||||
GIRARA_LIST_FOREACH_BODY(priv->search.list, zathura_rectangle_t*, rect,
|
||||
zathura_rectangle_t rectangle = recalc_rectangle(priv->page, *rect);
|
||||
|
||||
/* draw position */
|
||||
if (idx == priv->search.current) {
|
||||
const GdkRGBA color = priv->zathura->ui.colors.highlight_color_active;
|
||||
cairo_set_source_rgba(cairo, color.red, color.green, color.blue, transparency);
|
||||
} else {
|
||||
const GdkRGBA color = priv->zathura->ui.colors.highlight_color;
|
||||
cairo_set_source_rgba(cairo, color.red, color.green, color.blue, transparency);
|
||||
}
|
||||
cairo_rectangle(cairo, rectangle.x1, rectangle.y1,
|
||||
(rectangle.x2 - rectangle.x1), (rectangle.y2 - rectangle.y1));
|
||||
cairo_fill(cairo);
|
||||
++idx;
|
||||
GIRARA_LIST_FOREACH_END(priv->search.list, zathura_rectangle_t*, iter, rect);
|
||||
/* draw position */
|
||||
if (idx == priv->search.current) {
|
||||
const GdkRGBA color = priv->zathura->ui.colors.highlight_color_active;
|
||||
cairo_set_source_rgba(cairo, color.red, color.green, color.blue, transparency);
|
||||
} else {
|
||||
const GdkRGBA color = priv->zathura->ui.colors.highlight_color;
|
||||
cairo_set_source_rgba(cairo, color.red, color.green, color.blue, transparency);
|
||||
}
|
||||
cairo_rectangle(cairo, rectangle.x1, rectangle.y1,
|
||||
(rectangle.x2 - rectangle.x1), (rectangle.y2 - rectangle.y1));
|
||||
cairo_fill(cairo);
|
||||
++idx;
|
||||
);
|
||||
}
|
||||
/* draw selection */
|
||||
if (priv->mouse.selection.y2 != -1 && priv->mouse.selection.x2 != -1) {
|
||||
|
@ -860,10 +860,10 @@ redraw_all_rects(ZathuraPage* widget, girara_list_t* rectangles)
|
|||
{
|
||||
zathura_page_widget_private_t* priv = ZATHURA_PAGE_GET_PRIVATE(widget);
|
||||
|
||||
GIRARA_LIST_FOREACH(rectangles, zathura_rectangle_t*, iter, rect)
|
||||
GIRARA_LIST_FOREACH_BODY(rectangles, zathura_rectangle_t*, rect,
|
||||
zathura_rectangle_t rectangle = recalc_rectangle(priv->page, *rect);
|
||||
redraw_rect(widget, &rectangle);
|
||||
GIRARA_LIST_FOREACH_END(rectangles, zathura_recantgle_t*, iter, rect);
|
||||
);
|
||||
}
|
||||
|
||||
zathura_link_t*
|
||||
|
@ -963,13 +963,13 @@ cb_zathura_page_widget_button_release_event(GtkWidget* widget, GdkEventButton* b
|
|||
}
|
||||
|
||||
if (priv->links.list != NULL && priv->links.n > 0) {
|
||||
GIRARA_LIST_FOREACH(priv->links.list, zathura_link_t*, iter, link)
|
||||
zathura_rectangle_t rect = recalc_rectangle(priv->page, zathura_link_get_position(link));
|
||||
if (rect.x1 <= button->x && rect.x2 >= button->x
|
||||
&& rect.y1 <= button->y && rect.y2 >= button->y) {
|
||||
zathura_link_evaluate(priv->zathura, link);
|
||||
}
|
||||
GIRARA_LIST_FOREACH_END(priv->links.list, zathura_link_t*, iter, link);
|
||||
GIRARA_LIST_FOREACH_BODY(priv->links.list, zathura_link_t*, link,
|
||||
const zathura_rectangle_t rect = recalc_rectangle(priv->page, zathura_link_get_position(link));
|
||||
if (rect.x1 <= button->x && rect.x2 >= button->x
|
||||
&& rect.y1 <= button->y && rect.y2 >= button->y) {
|
||||
zathura_link_evaluate(priv->zathura, link);
|
||||
}
|
||||
);
|
||||
}
|
||||
} else {
|
||||
redraw_rect(ZATHURA_PAGE(widget), &priv->mouse.selection);
|
||||
|
@ -1017,12 +1017,13 @@ cb_zathura_page_widget_motion_notify(GtkWidget* widget, GdkEventMotion* event)
|
|||
|
||||
if (priv->links.list != NULL && priv->links.n > 0) {
|
||||
bool over_link = false;
|
||||
GIRARA_LIST_FOREACH(priv->links.list, zathura_link_t*, iter, link)
|
||||
GIRARA_LIST_FOREACH_BODY(priv->links.list, zathura_link_t*, link,
|
||||
zathura_rectangle_t rect = recalc_rectangle(priv->page, zathura_link_get_position(link));
|
||||
if (rect.x1 <= event->x && rect.x2 >= event->x && rect.y1 <= event->y && rect.y2 >= event->y) {
|
||||
over_link = true;
|
||||
break;
|
||||
}
|
||||
GIRARA_LIST_FOREACH_END(priv->links.list, zathura_link_t*, iter, link);
|
||||
);
|
||||
|
||||
if (priv->mouse.over_link != over_link) {
|
||||
if (over_link == true) {
|
||||
|
@ -1096,12 +1097,12 @@ zathura_page_widget_popup_menu(GtkWidget* widget, GdkEventButton* event)
|
|||
|
||||
/* search for underlaying image */
|
||||
zathura_image_t* image = NULL;
|
||||
GIRARA_LIST_FOREACH(priv->images.list, zathura_image_t*, iter, image_it)
|
||||
GIRARA_LIST_FOREACH_BODY(priv->images.list, zathura_image_t*, image_it,
|
||||
zathura_rectangle_t rect = recalc_rectangle(priv->page, image_it->position);
|
||||
if (rect.x1 <= event->x && rect.x2 >= event->x && rect.y1 <= event->y && rect.y2 >= event->y) {
|
||||
image = image_it;
|
||||
}
|
||||
GIRARA_LIST_FOREACH_END(priv->images.list, zathura_image_t*, iter, image_it);
|
||||
);
|
||||
|
||||
if (image == NULL) {
|
||||
return;
|
||||
|
@ -1184,13 +1185,13 @@ cb_menu_image_save(GtkMenuItem* item, ZathuraPage* page)
|
|||
unsigned int page_id = zathura_page_get_index(priv->page) + 1;
|
||||
unsigned int image_id = 1;
|
||||
|
||||
GIRARA_LIST_FOREACH(priv->images.list, zathura_image_t*, iter, image_it)
|
||||
GIRARA_LIST_FOREACH_BODY(priv->images.list, zathura_image_t*, image_it,
|
||||
if (image_it == priv->images.current) {
|
||||
break;
|
||||
}
|
||||
|
||||
image_id++;
|
||||
GIRARA_LIST_FOREACH_END(priv->images.list, zathura_image_t*, iter, image_it);
|
||||
);
|
||||
|
||||
/* set command */
|
||||
char* export_command = g_strdup_printf(":export image-p%d-%d ", page_id, image_id);
|
||||
|
|
208
zathura/plugin.c
208
zathura/plugin.c
|
@ -100,104 +100,104 @@ zathura_plugin_manager_load(zathura_plugin_manager_t* plugin_manager)
|
|||
return;
|
||||
}
|
||||
|
||||
GIRARA_LIST_FOREACH(plugin_manager->path, char*, iter, plugindir)
|
||||
/* read all files in the plugin directory */
|
||||
GDir* dir = g_dir_open(plugindir, 0, NULL);
|
||||
if (dir == NULL) {
|
||||
girara_error("could not open plugin directory: %s", plugindir);
|
||||
girara_list_iterator_next(iter);
|
||||
continue;
|
||||
}
|
||||
|
||||
char* name = NULL;
|
||||
while ((name = (char*) g_dir_read_name(dir)) != NULL) {
|
||||
char* path = g_build_filename(plugindir, name, NULL);
|
||||
if (g_file_test(path, G_FILE_TEST_IS_REGULAR) == 0) {
|
||||
girara_debug("%s is not a regular file. Skipping.", path);
|
||||
g_free(path);
|
||||
GIRARA_LIST_FOREACH_BODY_WITH_ITER(plugin_manager->path, char*, iter, plugindir,
|
||||
/* read all files in the plugin directory */
|
||||
GDir* dir = g_dir_open(plugindir, 0, NULL);
|
||||
if (dir == NULL) {
|
||||
girara_error("could not open plugin directory: %s", plugindir);
|
||||
girara_list_iterator_next(iter);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (check_suffix(path) == false) {
|
||||
girara_debug("%s is not a plugin file. Skipping.", path);
|
||||
g_free(path);
|
||||
continue;
|
||||
}
|
||||
char* name = NULL;
|
||||
while ((name = (char*) g_dir_read_name(dir)) != NULL) {
|
||||
char* path = g_build_filename(plugindir, name, NULL);
|
||||
if (g_file_test(path, G_FILE_TEST_IS_REGULAR) == 0) {
|
||||
girara_debug("%s is not a regular file. Skipping.", path);
|
||||
g_free(path);
|
||||
continue;
|
||||
}
|
||||
|
||||
zathura_plugin_t* plugin = NULL;
|
||||
if (check_suffix(path) == false) {
|
||||
girara_debug("%s is not a plugin file. Skipping.", path);
|
||||
g_free(path);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* load plugin */
|
||||
GModule* handle = g_module_open(path, G_MODULE_BIND_LOCAL);
|
||||
if (handle == NULL) {
|
||||
girara_error("could not load plugin %s (%s)", path, g_module_error());
|
||||
g_free(path);
|
||||
continue;
|
||||
}
|
||||
zathura_plugin_t* plugin = NULL;
|
||||
|
||||
/* resolve symbols and check API and ABI version*/
|
||||
const zathura_plugin_definition_t* plugin_definition = NULL;
|
||||
if (g_module_symbol(handle, G_STRINGIFY(ZATHURA_PLUGIN_DEFINITION_SYMBOL), (void**) &plugin_definition) == FALSE ||
|
||||
plugin_definition == NULL) {
|
||||
girara_error("could not find '%s' in plugin %s - is not a plugin or needs to be rebuilt", G_STRINGIFY(ZATHURA_PLUGIN_DEFINITION_SYMBOL), path);
|
||||
g_free(path);
|
||||
g_module_close(handle);
|
||||
continue;
|
||||
}
|
||||
/* load plugin */
|
||||
GModule* handle = g_module_open(path, G_MODULE_BIND_LOCAL);
|
||||
if (handle == NULL) {
|
||||
girara_error("could not load plugin %s (%s)", path, g_module_error());
|
||||
g_free(path);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* check name */
|
||||
if (plugin_definition->name == NULL) {
|
||||
girara_error("plugin has no name");
|
||||
g_free(path);
|
||||
g_free(plugin);
|
||||
g_module_close(handle);
|
||||
continue;
|
||||
}
|
||||
/* resolve symbols and check API and ABI version*/
|
||||
const zathura_plugin_definition_t* plugin_definition = NULL;
|
||||
if (g_module_symbol(handle, G_STRINGIFY(ZATHURA_PLUGIN_DEFINITION_SYMBOL), (void**) &plugin_definition) == FALSE ||
|
||||
plugin_definition == NULL) {
|
||||
girara_error("could not find '%s' in plugin %s - is not a plugin or needs to be rebuilt", G_STRINGIFY(ZATHURA_PLUGIN_DEFINITION_SYMBOL), path);
|
||||
g_free(path);
|
||||
g_module_close(handle);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* check mime type */
|
||||
if (plugin_definition->mime_types == NULL || plugin_definition->mime_types_size == 0) {
|
||||
girara_error("plugin has no mime_types");
|
||||
g_free(path);
|
||||
g_free(plugin);
|
||||
g_module_close(handle);
|
||||
continue;
|
||||
}
|
||||
/* check name */
|
||||
if (plugin_definition->name == NULL) {
|
||||
girara_error("plugin has no name");
|
||||
g_free(path);
|
||||
g_free(plugin);
|
||||
g_module_close(handle);
|
||||
continue;
|
||||
}
|
||||
|
||||
plugin = g_try_malloc0(sizeof(zathura_plugin_t));
|
||||
if (plugin == NULL) {
|
||||
girara_error("Failed to allocate memory for plugin.");
|
||||
g_free(path);
|
||||
g_module_close(handle);
|
||||
continue;
|
||||
}
|
||||
/* check mime type */
|
||||
if (plugin_definition->mime_types == NULL || plugin_definition->mime_types_size == 0) {
|
||||
girara_error("plugin has no mime_types");
|
||||
g_free(path);
|
||||
g_free(plugin);
|
||||
g_module_close(handle);
|
||||
continue;
|
||||
}
|
||||
|
||||
plugin->definition = plugin_definition;
|
||||
plugin->functions = plugin_definition->functions;
|
||||
plugin->content_types = girara_list_new2(g_free);
|
||||
plugin->handle = handle;
|
||||
plugin->path = path;
|
||||
plugin = g_try_malloc0(sizeof(zathura_plugin_t));
|
||||
if (plugin == NULL) {
|
||||
girara_error("Failed to allocate memory for plugin.");
|
||||
g_free(path);
|
||||
g_module_close(handle);
|
||||
continue;
|
||||
}
|
||||
|
||||
// register mime types
|
||||
for (size_t s = 0; s != plugin_definition->mime_types_size; ++s) {
|
||||
zathura_plugin_add_mimetype(plugin, plugin_definition->mime_types[s]);
|
||||
}
|
||||
// register functions
|
||||
if (plugin->definition->register_function != NULL) {
|
||||
plugin->definition->register_function(&(plugin->functions));
|
||||
}
|
||||
plugin->definition = plugin_definition;
|
||||
plugin->functions = plugin_definition->functions;
|
||||
plugin->content_types = girara_list_new2(g_free);
|
||||
plugin->handle = handle;
|
||||
plugin->path = path;
|
||||
|
||||
bool ret = register_plugin(plugin_manager, plugin);
|
||||
if (ret == false) {
|
||||
girara_error("could not register plugin %s", path);
|
||||
zathura_plugin_free(plugin);
|
||||
} else {
|
||||
girara_debug("successfully loaded plugin from %s", path);
|
||||
girara_debug("plugin %s: version %u.%u.%u", plugin_definition->name,
|
||||
plugin_definition->version.major, plugin_definition->version.minor,
|
||||
plugin_definition->version.rev);
|
||||
// register mime types
|
||||
for (size_t s = 0; s != plugin_definition->mime_types_size; ++s) {
|
||||
zathura_plugin_add_mimetype(plugin, plugin_definition->mime_types[s]);
|
||||
}
|
||||
// register functions
|
||||
if (plugin->definition->register_function != NULL) {
|
||||
plugin->definition->register_function(&(plugin->functions));
|
||||
}
|
||||
|
||||
bool ret = register_plugin(plugin_manager, plugin);
|
||||
if (ret == false) {
|
||||
girara_error("could not register plugin %s", path);
|
||||
zathura_plugin_free(plugin);
|
||||
} else {
|
||||
girara_debug("successfully loaded plugin from %s", path);
|
||||
girara_debug("plugin %s: version %u.%u.%u", plugin_definition->name,
|
||||
plugin_definition->version.major, plugin_definition->version.minor,
|
||||
plugin_definition->version.rev);
|
||||
}
|
||||
}
|
||||
}
|
||||
g_dir_close(dir);
|
||||
GIRARA_LIST_FOREACH_END(zathura->plugins.path, char*, iter, plugindir);
|
||||
g_dir_close(dir);
|
||||
);
|
||||
}
|
||||
|
||||
zathura_plugin_t*
|
||||
|
@ -208,12 +208,12 @@ zathura_plugin_manager_get_plugin(zathura_plugin_manager_t* plugin_manager, cons
|
|||
}
|
||||
|
||||
zathura_plugin_t* plugin = NULL;
|
||||
GIRARA_LIST_FOREACH(plugin_manager->type_plugin_mapping, zathura_type_plugin_mapping_t*, iter, mapping)
|
||||
if (g_content_type_equals(type, mapping->type)) {
|
||||
plugin = mapping->plugin;
|
||||
break;
|
||||
}
|
||||
GIRARA_LIST_FOREACH_END(plugin_manager->type_plugin_mapping, zathura_type_plugin_mapping_t*, iter, mapping);
|
||||
GIRARA_LIST_FOREACH_BODY(plugin_manager->type_plugin_mapping, zathura_type_plugin_mapping_t*, mapping,
|
||||
if (g_content_type_equals(type, mapping->type)) {
|
||||
plugin = mapping->plugin;
|
||||
break;
|
||||
}
|
||||
);
|
||||
|
||||
return plugin;
|
||||
}
|
||||
|
@ -262,13 +262,13 @@ register_plugin(zathura_plugin_manager_t* plugin_manager, zathura_plugin_t* plug
|
|||
}
|
||||
|
||||
bool at_least_one = false;
|
||||
GIRARA_LIST_FOREACH(plugin->content_types, gchar*, iter, type)
|
||||
if (plugin_mapping_new(plugin_manager, type, plugin) == false) {
|
||||
girara_error("plugin: already registered for filetype %s\n", type);
|
||||
} else {
|
||||
at_least_one = true;
|
||||
}
|
||||
GIRARA_LIST_FOREACH_END(plugin->content_types, gchar*, iter, type);
|
||||
GIRARA_LIST_FOREACH_BODY(plugin->content_types, gchar*, type,
|
||||
if (plugin_mapping_new(plugin_manager, type, plugin) == false) {
|
||||
girara_error("plugin: already registered for filetype %s\n", type);
|
||||
} else {
|
||||
at_least_one = true;
|
||||
}
|
||||
);
|
||||
|
||||
if (at_least_one == true) {
|
||||
girara_list_append(plugin_manager->plugins, plugin);
|
||||
|
@ -284,12 +284,12 @@ plugin_mapping_new(zathura_plugin_manager_t* plugin_manager, const gchar* type,
|
|||
g_return_val_if_fail(type != NULL, false);
|
||||
g_return_val_if_fail(plugin != NULL, false);
|
||||
|
||||
GIRARA_LIST_FOREACH(plugin_manager->type_plugin_mapping, zathura_type_plugin_mapping_t*, iter, mapping)
|
||||
if (g_content_type_equals(type, mapping->type)) {
|
||||
girara_list_iterator_free(iter);
|
||||
return false;
|
||||
}
|
||||
GIRARA_LIST_FOREACH_END(plugin_manager->type_plugin_mapping, zathura_type_plugin_mapping_t*, iter, mapping);
|
||||
GIRARA_LIST_FOREACH_BODY_WITH_ITER(plugin_manager->type_plugin_mapping, zathura_type_plugin_mapping_t*, iter, mapping,
|
||||
if (g_content_type_equals(type, mapping->type)) {
|
||||
girara_list_iterator_free(iter);
|
||||
return false;
|
||||
}
|
||||
);
|
||||
|
||||
zathura_type_plugin_mapping_t* mapping = g_try_malloc0(sizeof(zathura_type_plugin_mapping_t));
|
||||
if (mapping == NULL) {
|
||||
|
|
|
@ -438,11 +438,12 @@ zathura_render_request(ZathuraRenderRequest* request, gint64 last_view_time)
|
|||
|
||||
bool unfinished_jobs = false;
|
||||
/* check if there are any active jobs left */
|
||||
GIRARA_LIST_FOREACH(request_priv->active_jobs, render_job_t*, iter, job)
|
||||
GIRARA_LIST_FOREACH_BODY(request_priv->active_jobs, render_job_t*, job,
|
||||
if (job->aborted == false) {
|
||||
unfinished_jobs = true;
|
||||
break;
|
||||
}
|
||||
GIRARA_LIST_FOREACH_END(request_priv->active_jobs, render_job_t*, iter, job);
|
||||
);
|
||||
|
||||
/* only add a new job if there are no active ones left */
|
||||
if (unfinished_jobs == false) {
|
||||
|
@ -471,9 +472,9 @@ zathura_render_request_abort(ZathuraRenderRequest* request)
|
|||
|
||||
request_private_t* request_priv = REQUEST_GET_PRIVATE(request);
|
||||
g_mutex_lock(&request_priv->jobs_mutex);
|
||||
GIRARA_LIST_FOREACH(request_priv->active_jobs, render_job_t*, iter, job)
|
||||
GIRARA_LIST_FOREACH_BODY(request_priv->active_jobs, render_job_t*, job,
|
||||
job->aborted = true;
|
||||
GIRARA_LIST_FOREACH_END(request_priv->active_jobs, render_job_t*, iter, job);
|
||||
);
|
||||
g_mutex_unlock(&request_priv->jobs_mutex);
|
||||
}
|
||||
|
||||
|
@ -632,14 +633,14 @@ recolor(private_t* priv, zathura_page_t* page, unsigned int page_width,
|
|||
|
||||
if (found_images == true) {
|
||||
/* Get images bounding boxes */
|
||||
GIRARA_LIST_FOREACH(images, zathura_image_t*, iter, image_it)
|
||||
GIRARA_LIST_FOREACH_BODY(images, zathura_image_t*, image_it,
|
||||
zathura_rectangle_t* rect = g_try_malloc(sizeof(zathura_rectangle_t));
|
||||
if (rect == NULL) {
|
||||
break;
|
||||
}
|
||||
*rect = recalc_rectangle(page, image_it->position);
|
||||
girara_list_append(rectangles, rect);
|
||||
GIRARA_LIST_FOREACH_END(images, zathura_image_t*, iter, image_it);
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -650,13 +651,13 @@ recolor(private_t* priv, zathura_page_t* page, unsigned int page_width,
|
|||
/* Check if the pixel belongs to an image when in reverse video mode*/
|
||||
if (priv->recolor.reverse_video == true && found_images == true){
|
||||
bool inside_image = false;
|
||||
GIRARA_LIST_FOREACH(rectangles, zathura_rectangle_t*, iter, rect_it)
|
||||
GIRARA_LIST_FOREACH_BODY(rectangles, zathura_rectangle_t*, rect_it,
|
||||
if (rect_it->x1 <= x && rect_it->x2 >= x &&
|
||||
rect_it->y1 <= y && rect_it->y2 >= y) {
|
||||
inside_image = true;
|
||||
break;
|
||||
}
|
||||
GIRARA_LIST_FOREACH_END(rectangles, zathura_rectangle_t*, iter, rect_it);
|
||||
);
|
||||
/* If it's inside and image don't recolor */
|
||||
if (inside_image == true) {
|
||||
continue;
|
||||
|
|
|
@ -355,13 +355,13 @@ synctex_view(zathura_t* zathura, const char* input_file,
|
|||
}
|
||||
|
||||
if (secondary_rects != NULL) {
|
||||
GIRARA_LIST_FOREACH(secondary_rects, synctex_page_rect_t*, iter, rect)
|
||||
GIRARA_LIST_FOREACH_BODY(secondary_rects, synctex_page_rect_t*, rect,
|
||||
zathura_rectangle_t* newrect = g_try_malloc0(sizeof(zathura_rectangle_t));
|
||||
if (newrect != NULL) {
|
||||
*newrect = rect->rect;
|
||||
girara_list_append(all_rectangles[rect->page], newrect);
|
||||
}
|
||||
GIRARA_LIST_FOREACH_END(secondary_rects, synctex_page_rect_t*, iter, rect);
|
||||
);
|
||||
}
|
||||
|
||||
synctex_highlight_rects(zathura, page, all_rectangles);
|
||||
|
|
|
@ -69,7 +69,7 @@ document_index_build(GtkTreeModel* model, GtkTreeIter* parent,
|
|||
{
|
||||
girara_list_t* list = girara_node_get_children(tree);
|
||||
|
||||
GIRARA_LIST_FOREACH(list, girara_tree_node_t*, iter, node) {
|
||||
GIRARA_LIST_FOREACH_BODY(list, girara_tree_node_t*, node,
|
||||
zathura_index_element_t* index_element = (zathura_index_element_t*)girara_node_get_data(node);
|
||||
|
||||
zathura_link_type_t type = zathura_link_get_type(index_element->link);
|
||||
|
@ -93,7 +93,7 @@ document_index_build(GtkTreeModel* model, GtkTreeIter* parent,
|
|||
if (girara_node_get_num_children(node) > 0) {
|
||||
document_index_build(model, &tree_iter, node);
|
||||
}
|
||||
} GIRARA_LIST_FOREACH_END(list, gchar*, iter, name);
|
||||
);
|
||||
}
|
||||
|
||||
zathura_rectangle_t
|
||||
|
@ -201,7 +201,7 @@ zathura_get_version_string(zathura_t* zathura, bool markup)
|
|||
/* plugin information */
|
||||
girara_list_t* plugins = zathura_plugin_manager_get_plugins(zathura->plugins.manager);
|
||||
if (plugins != NULL) {
|
||||
GIRARA_LIST_FOREACH(plugins, zathura_plugin_t*, iter, plugin) {
|
||||
GIRARA_LIST_FOREACH_BODY(plugins, zathura_plugin_t*, plugin,
|
||||
const char* name = zathura_plugin_get_name(plugin);
|
||||
zathura_plugin_version_t version = zathura_plugin_get_version(plugin);
|
||||
g_string_append_printf(string, format,
|
||||
|
@ -210,7 +210,7 @@ zathura_get_version_string(zathura_t* zathura, bool markup)
|
|||
version.minor,
|
||||
version.rev,
|
||||
zathura_plugin_get_path(plugin));
|
||||
} GIRARA_LIST_FOREACH_END(plugins, zathura_plugin_t*, iter, plugin);
|
||||
);
|
||||
}
|
||||
|
||||
char* version = string->str;
|
||||
|
|
|
@ -506,16 +506,16 @@ zathura_set_plugin_dir(zathura_t* zathura, const char* dir)
|
|||
|
||||
if (dir != NULL) {
|
||||
girara_list_t* paths = girara_split_path_array(dir);
|
||||
GIRARA_LIST_FOREACH(paths, char*, iter, path)
|
||||
zathura_plugin_manager_add_dir(zathura->plugins.manager, path);
|
||||
GIRARA_LIST_FOREACH_END(paths, char*, iter, path);
|
||||
GIRARA_LIST_FOREACH_BODY(paths, char*, path,
|
||||
zathura_plugin_manager_add_dir(zathura->plugins.manager, path);
|
||||
);
|
||||
girara_list_free(paths);
|
||||
} else {
|
||||
#ifdef ZATHURA_PLUGINDIR
|
||||
girara_list_t* paths = girara_split_path_array(ZATHURA_PLUGINDIR);
|
||||
GIRARA_LIST_FOREACH(paths, char*, iter, path)
|
||||
zathura_plugin_manager_add_dir(zathura->plugins.manager, path);
|
||||
GIRARA_LIST_FOREACH_END(paths, char*, iter, path);
|
||||
GIRARA_LIST_FOREACH_BODY(paths, char*, path,
|
||||
zathura_plugin_manager_add_dir(zathura->plugins.manager, path);
|
||||
);
|
||||
girara_list_free(paths);
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue