mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2025-02-27 11:14:40 +01:00
Implemented auto reload basics
This commit is contained in:
parent
59e36d84ae
commit
30f62a1f3a
4 changed files with 83 additions and 23 deletions
14
callbacks.c
14
callbacks.c
|
@ -211,3 +211,17 @@ error_ret:
|
|||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
cb_file_monitor(GFileMonitor* monitor, GFile* file, GFile* UNUSED(other_file), GFileMonitorEvent event, girara_session_t* session)
|
||||
{
|
||||
g_return_if_fail(monitor != NULL);
|
||||
g_return_if_fail(file != NULL);
|
||||
g_return_if_fail(session != NULL);
|
||||
|
||||
if (event != G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT) {
|
||||
return;
|
||||
}
|
||||
|
||||
sc_reload(session, NULL, NULL, 0);
|
||||
}
|
||||
|
|
13
callbacks.h
13
callbacks.h
|
@ -7,6 +7,8 @@
|
|||
#include <girara/types.h>
|
||||
#include <girara/macros.h>
|
||||
|
||||
#include "document.h"
|
||||
|
||||
/**
|
||||
* Quits the current zathura session
|
||||
*
|
||||
|
@ -60,4 +62,15 @@ void cb_index_row_activated(GtkTreeView* tree_view, GtkTreePath* path,
|
|||
*/
|
||||
bool cb_sc_follow(GtkEntry* entry, girara_session_t* session);
|
||||
|
||||
/**
|
||||
* Emitted when file has been changed
|
||||
*
|
||||
* @param monitor The file monitor
|
||||
* @param file The file
|
||||
* @param other_file A file or NULL
|
||||
* @param event The monitor event
|
||||
* @param session The girara session
|
||||
*/
|
||||
void cb_file_monitor(GFileMonitor* monitor, GFile* file, GFile* other_file, GFileMonitorEvent event, girara_session_t* session);
|
||||
|
||||
#endif // CALLBACKS_H
|
||||
|
|
35
document.c
35
document.c
|
@ -214,6 +214,8 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* password
|
|||
return NULL;
|
||||
}
|
||||
|
||||
char* file_uri = NULL;
|
||||
|
||||
/* determine real path */
|
||||
long path_max;
|
||||
#ifdef PATH_MAX
|
||||
|
@ -268,8 +270,11 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* password
|
|||
document->scale = 1;
|
||||
}
|
||||
|
||||
if (plugin->open_function != NULL) {
|
||||
if (plugin->open_function(document) == true) {
|
||||
if (plugin->open_function == NULL || plugin->open_function(document) == false) {
|
||||
girara_error("could not open file\n");
|
||||
goto error_free;
|
||||
}
|
||||
|
||||
/* update statusbar */
|
||||
girara_statusbar_item_set_text(zathura->ui.session, zathura->ui.statusbar.file, real_path);
|
||||
|
||||
|
@ -288,14 +293,34 @@ zathura_document_open(zathura_t* zathura, const char* path, const char* password
|
|||
document->pages[page_id] = page;
|
||||
}
|
||||
|
||||
return document;
|
||||
}
|
||||
/* install file monitor */
|
||||
file_uri = g_filename_to_uri(real_path, NULL, NULL);
|
||||
if (file_uri == NULL) {
|
||||
goto error_free;
|
||||
}
|
||||
|
||||
girara_error("could not open file\n");
|
||||
document->file_monitor.file = g_file_new_for_uri(file_uri);
|
||||
if (document->file_monitor.file == NULL) {
|
||||
goto error_free;
|
||||
}
|
||||
|
||||
document->file_monitor.monitor = g_file_monitor_file(document->file_monitor.file, G_FILE_MONITOR_NONE, NULL, NULL);
|
||||
if (document->file_monitor.monitor == NULL) {
|
||||
goto error_free;
|
||||
}
|
||||
|
||||
g_signal_connect(G_OBJECT(document->file_monitor.monitor), "changed", G_CALLBACK(cb_file_monitor), document);
|
||||
|
||||
g_free(file_uri);
|
||||
|
||||
return document;
|
||||
|
||||
error_free:
|
||||
|
||||
if (file_uri != NULL) {
|
||||
g_free(file_uri);
|
||||
}
|
||||
|
||||
free(real_path);
|
||||
|
||||
if (document != NULL && document->pages != NULL) {
|
||||
|
|
|
@ -261,6 +261,14 @@ struct zathura_document_s
|
|||
* Document pages
|
||||
*/
|
||||
zathura_page_t** pages;
|
||||
|
||||
/**
|
||||
* File monitor
|
||||
*/
|
||||
struct {
|
||||
GFileMonitor* monitor; /**< File monitor */
|
||||
GFile* file; /**< File for file monitor */
|
||||
} file_monitor;
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue