mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-11-14 07:43:45 +01:00
Cancel the search thread
Do not cancel the search thread if it is not possible
This commit is contained in:
parent
5b918ca16e
commit
488b7f1c33
37
zathura.c
37
zathura.c
@ -183,6 +183,12 @@ struct
|
|||||||
pthread_mutex_t viewport_lock;
|
pthread_mutex_t viewport_lock;
|
||||||
} Lock;
|
} Lock;
|
||||||
|
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
pthread_t search_thread;
|
||||||
|
gboolean search_thread_running;
|
||||||
|
} Thread;
|
||||||
|
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
char* filename;
|
char* filename;
|
||||||
@ -198,7 +204,6 @@ struct
|
|||||||
int number_of_pages;
|
int number_of_pages;
|
||||||
int scale;
|
int scale;
|
||||||
int rotate;
|
int rotate;
|
||||||
pthread_t search_thread;
|
|
||||||
cairo_surface_t *surface;
|
cairo_surface_t *surface;
|
||||||
} PDF;
|
} PDF;
|
||||||
|
|
||||||
@ -761,22 +766,30 @@ switch_view(GtkWidget* widget)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* thread implementation */
|
/* thread implementation */
|
||||||
void* search(void* parameter)
|
void*
|
||||||
|
search(void* parameter)
|
||||||
{
|
{
|
||||||
|
Zathura.Thread.search_thread_running = TRUE;
|
||||||
Argument* argument = (Argument*) parameter;
|
Argument* argument = (Argument*) parameter;
|
||||||
|
|
||||||
static char* search_item;
|
static char* search_item;
|
||||||
static int direction;
|
static int direction;
|
||||||
|
static int next_page = 0;
|
||||||
int page_counter;
|
int page_counter;
|
||||||
int next_page;
|
|
||||||
GList* results;
|
GList* results;
|
||||||
GList* list;
|
GList* list;
|
||||||
|
int ov;
|
||||||
|
|
||||||
|
pthread_mutex_unlock(&(Zathura.PDF.pages[next_page]->lock));
|
||||||
|
|
||||||
if(argument->data)
|
if(argument->data)
|
||||||
search_item = g_strdup((char*) argument->data);
|
search_item = g_strdup((char*) argument->data);
|
||||||
|
|
||||||
if(!Zathura.PDF.document || !search_item || !strlen(search_item))
|
if(!Zathura.PDF.document || !search_item || !strlen(search_item))
|
||||||
|
{
|
||||||
|
Zathura.Thread.search_thread_running = FALSE;
|
||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
/* search document */
|
/* search document */
|
||||||
if(argument->n)
|
if(argument->n)
|
||||||
@ -787,9 +800,11 @@ void* search(void* parameter)
|
|||||||
next_page = (Zathura.PDF.number_of_pages + Zathura.PDF.page_number +
|
next_page = (Zathura.PDF.number_of_pages + Zathura.PDF.page_number +
|
||||||
page_counter * direction) % Zathura.PDF.number_of_pages;
|
page_counter * direction) % Zathura.PDF.number_of_pages;
|
||||||
|
|
||||||
|
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &ov);
|
||||||
pthread_mutex_lock(&(Zathura.PDF.pages[next_page]->lock));
|
pthread_mutex_lock(&(Zathura.PDF.pages[next_page]->lock));
|
||||||
results = poppler_page_find_text(Zathura.PDF.pages[next_page]->page, search_item);
|
results = poppler_page_find_text(Zathura.PDF.pages[next_page]->page, search_item);
|
||||||
pthread_mutex_unlock(&(Zathura.PDF.pages[next_page]->lock));
|
pthread_mutex_unlock(&(Zathura.PDF.pages[next_page]->lock));
|
||||||
|
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &ov);
|
||||||
|
|
||||||
if(results)
|
if(results)
|
||||||
break;
|
break;
|
||||||
@ -799,15 +814,22 @@ void* search(void* parameter)
|
|||||||
if(results)
|
if(results)
|
||||||
{
|
{
|
||||||
for(list = results; list && list->data; list = g_list_next(list))
|
for(list = results; list && list->data; list = g_list_next(list))
|
||||||
|
{
|
||||||
|
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &ov);
|
||||||
highlight_result(next_page, (PopplerRectangle*) list->data);
|
highlight_result(next_page, (PopplerRectangle*) list->data);
|
||||||
|
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &ov);
|
||||||
|
}
|
||||||
|
|
||||||
|
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &ov);
|
||||||
set_page(next_page);
|
set_page(next_page);
|
||||||
|
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &ov);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("Nothing found for %s\n", search_item);
|
printf("Nothing found for %s\n", search_item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Zathura.Thread.search_thread_running = FALSE;
|
||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -914,10 +936,13 @@ void
|
|||||||
sc_search(Argument* argument)
|
sc_search(Argument* argument)
|
||||||
{
|
{
|
||||||
pthread_mutex_lock(&(Zathura.Lock.search_lock));
|
pthread_mutex_lock(&(Zathura.Lock.search_lock));
|
||||||
if(Zathura.PDF.search_thread)
|
if(Zathura.Thread.search_thread_running)
|
||||||
pthread_cancel(Zathura.PDF.search_thread);
|
{
|
||||||
|
pthread_cancel(Zathura.Thread.search_thread);
|
||||||
|
Zathura.Thread.search_thread_running = FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
pthread_create(&(Zathura.PDF.search_thread), NULL, search, (gpointer) argument);
|
pthread_create(&(Zathura.Thread.search_thread), NULL, search, (gpointer) argument);
|
||||||
pthread_mutex_unlock(&(Zathura.Lock.search_lock));
|
pthread_mutex_unlock(&(Zathura.Lock.search_lock));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user