mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-11-13 10:03:45 +01:00
Just return a list of rectangles
Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
This commit is contained in:
parent
26333fb20c
commit
d0b7676bc3
80
synctex.c
80
synctex.c
@ -1,7 +1,6 @@
|
|||||||
/* See LICENSE file for license and copyright information */
|
/* See LICENSE file for license and copyright information */
|
||||||
|
|
||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <glib/gi18n.h>
|
|
||||||
|
|
||||||
#include "synctex.h"
|
#include "synctex.h"
|
||||||
|
|
||||||
@ -10,8 +9,6 @@
|
|||||||
#include "document.h"
|
#include "document.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
|
|
||||||
#include <girara/session.h>
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
SYNCTEX_RESULT_BEGIN = 1,
|
SYNCTEX_RESULT_BEGIN = 1,
|
||||||
SYNCTEX_RESULT_END,
|
SYNCTEX_RESULT_END,
|
||||||
@ -50,9 +47,6 @@ static GScannerConfig scanner_config = {
|
|||||||
.numbers_2_int = TRUE,
|
.numbers_2_int = TRUE,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void synctex_record_hits(zathura_t* zathura, int page_idx, girara_list_t* hits, bool first);
|
|
||||||
static double scan_float(GScanner* scanner);
|
|
||||||
|
|
||||||
void
|
void
|
||||||
synctex_edit(zathura_t* zathura, zathura_page_t* page, int x, int y)
|
synctex_edit(zathura_t* zathura, zathura_page_t* page, int x, int y)
|
||||||
{
|
{
|
||||||
@ -85,23 +79,6 @@ synctex_edit(zathura_t* zathura, zathura_page_t* page, int x, int y)
|
|||||||
g_strfreev(argv);
|
g_strfreev(argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
synctex_record_hits(zathura_t* zathura, int page_idx, girara_list_t* hits, bool first)
|
|
||||||
{
|
|
||||||
zathura_page_t* page = zathura_document_get_page(zathura->document, page_idx-1);
|
|
||||||
if (page == NULL)
|
|
||||||
return;
|
|
||||||
|
|
||||||
GtkWidget* page_widget = zathura_page_get_widget(zathura, page);
|
|
||||||
g_object_set(page_widget, "draw-links", FALSE, NULL);
|
|
||||||
g_object_set(page_widget, "search-results", hits, NULL);
|
|
||||||
|
|
||||||
if (first == true) {
|
|
||||||
page_set(zathura, zathura_page_get_index(page));
|
|
||||||
g_object_set(page_widget, "search-current", 0, NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static double
|
static double
|
||||||
scan_float(GScanner* scanner)
|
scan_float(GScanner* scanner)
|
||||||
{
|
{
|
||||||
@ -115,11 +92,11 @@ scan_float(GScanner* scanner)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
girara_list_t*
|
||||||
synctex_view(zathura_t* zathura, const char* position)
|
synctex_rectangles_from_position(const char* filename, const char* position, int* page)
|
||||||
{
|
{
|
||||||
if (zathura->document == NULL) {
|
if (filename == NULL || position == NULL || page == NULL) {
|
||||||
return false;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
char** argv = g_malloc0(sizeof(char*) * 6);
|
char** argv = g_malloc0(sizeof(char*) * 6);
|
||||||
@ -128,7 +105,7 @@ synctex_view(zathura_t* zathura, const char* position)
|
|||||||
argv[2] = g_strdup("-i");
|
argv[2] = g_strdup("-i");
|
||||||
argv[3] = g_strdup(position);
|
argv[3] = g_strdup(position);
|
||||||
argv[4] = g_strdup("-o");
|
argv[4] = g_strdup("-o");
|
||||||
argv[5] = g_strdup(zathura_document_get_path(zathura->document));
|
argv[5] = g_strdup(filename);
|
||||||
|
|
||||||
gint output;
|
gint output;
|
||||||
bool ret = g_spawn_async_with_pipes(NULL, argv, NULL,
|
bool ret = g_spawn_async_with_pipes(NULL, argv, NULL,
|
||||||
@ -170,20 +147,9 @@ synctex_view(zathura_t* zathura, const char* position)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (found_begin == true) {
|
*page = -1;
|
||||||
unsigned int number_of_pages = zathura_document_get_number_of_pages(zathura->document);
|
int current_page;
|
||||||
for (unsigned int page_id = 0; page_id < number_of_pages; ++page_id) {
|
girara_list_t* hitlist = girara_list_new2(g_free);;
|
||||||
zathura_page_t* page = zathura_document_get_page(zathura->document, page_id);
|
|
||||||
if (page == NULL) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
g_object_set(zathura_page_get_widget(zathura, page), "search-results", NULL, NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = false;
|
|
||||||
int page = -1, nextpage;
|
|
||||||
girara_list_t* hitlist = NULL;
|
|
||||||
zathura_rectangle_t* rectangle = NULL;
|
zathura_rectangle_t* rectangle = NULL;
|
||||||
|
|
||||||
while (found_end == false) {
|
while (found_end == false) {
|
||||||
@ -200,17 +166,18 @@ synctex_view(zathura_t* zathura, const char* position)
|
|||||||
|
|
||||||
case SYNCTEX_PROP_PAGE:
|
case SYNCTEX_PROP_PAGE:
|
||||||
if (g_scanner_get_next_token(scanner) == G_TOKEN_INT) {
|
if (g_scanner_get_next_token(scanner) == G_TOKEN_INT) {
|
||||||
nextpage = g_scanner_cur_value(scanner).v_int;
|
current_page = g_scanner_cur_value(scanner).v_int;
|
||||||
if (page != nextpage) {
|
if (*page == -1) {
|
||||||
if (hitlist) {
|
*page = current_page;
|
||||||
synctex_record_hits(zathura, page, hitlist, !ret);
|
|
||||||
ret = true;
|
|
||||||
}
|
|
||||||
hitlist = girara_list_new2((girara_free_function_t) g_free);
|
|
||||||
page = nextpage;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (*page == current_page && rectangle != NULL) {
|
||||||
|
girara_list_append(hitlist, rectangle);
|
||||||
|
rectangle = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_free(rectangle);
|
||||||
rectangle = g_malloc0(sizeof(zathura_rectangle_t));
|
rectangle = g_malloc0(sizeof(zathura_rectangle_t));
|
||||||
girara_list_append(hitlist, rectangle);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -237,13 +204,16 @@ synctex_view(zathura_t* zathura, const char* position)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hitlist != NULL) {
|
if (rectangle != NULL) {
|
||||||
synctex_record_hits(zathura, page, hitlist, !ret);
|
if (current_page == *page) {
|
||||||
ret = true;
|
girara_list_append(hitlist, rectangle);
|
||||||
|
} else {
|
||||||
|
g_free(rectangle);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_scanner_destroy(scanner);
|
g_scanner_destroy(scanner);
|
||||||
close(output);
|
close(output);
|
||||||
|
|
||||||
return ret;
|
return hitlist;
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,6 @@
|
|||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
void synctex_edit(zathura_t* zathura, zathura_page_t* page, int x, int y);
|
void synctex_edit(zathura_t* zathura, zathura_page_t* page, int x, int y);
|
||||||
bool synctex_view(zathura_t* zathura, const char* position);
|
girara_list_t* synctex_rectangles_from_position(const char* filename, const char* position, int* page);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -220,7 +220,6 @@ zathura_init(zathura_t* zathura)
|
|||||||
(girara_free_function_t) zathura_bookmark_free);
|
(girara_free_function_t) zathura_bookmark_free);
|
||||||
|
|
||||||
/* jumplist */
|
/* jumplist */
|
||||||
|
|
||||||
int jumplist_size = 20;
|
int jumplist_size = 20;
|
||||||
girara_setting_get(zathura->ui.session, "jumplist-size", &jumplist_size);
|
girara_setting_get(zathura->ui.session, "jumplist-size", &jumplist_size);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user