Commit 8bcb79ea authored by Moritz Lipp's avatar Moritz Lipp

Update

parent 4a8f4df2
......@@ -38,14 +38,11 @@ buffer_changed(girara_session_t* session)
void
cb_view_vadjustment_value_changed(GtkAdjustment *adjustment, gpointer data)
{
g_return_if_fail(data != NULL);
zathura_t* zathura = data;
if (!zathura->document || !zathura->document->pages || !zathura->ui.page_view) {
if (!zathura || !zathura->document || !zathura->document->pages || !zathura->ui.page_view) {
return;
}
// FIXME
/* get current adjustment values */
/*gdouble lower = gtk_adjustment_get_value(adjustment);*/
......
......@@ -15,6 +15,7 @@
#include "document.h"
#include "utils.h"
#include "zathura.h"
#include "render.h"
#define LENGTH(x) (sizeof(x)/sizeof((x)[0]))
......@@ -385,6 +386,7 @@ zathura_page_get(zathura_document_t* document, unsigned int page_id)
page->rendered = false;
page->event_box = gtk_event_box_new();
page->drawing_area = gtk_drawing_area_new();
g_signal_connect(page->drawing_area, "expose-event", G_CALLBACK(page_expose_event), page);
gtk_container_add(GTK_CONTAINER(page->event_box), page->drawing_area);
......
......@@ -22,7 +22,7 @@ render_job(void* data)
g_mutex_unlock(render_thread->lock);
if (render(render_thread->zathura, page) != true) {
fprintf(stderr, "rendering failed\n");
girara_error("Rendering failed\n");
}
printf("Rendered %d\n", page->number);
......@@ -134,6 +134,10 @@ render_page(render_thread_t* render_thread, zathura_page_t* page)
bool
render(zathura_t* zathura, zathura_page_t* page)
{
if (zathura == NULL || page == NULL) {
return false;
}
gdk_threads_enter();
g_static_mutex_lock(&(page->lock));
zathura_image_buffer_t* image_buffer = zathura_page_render(page);
......@@ -198,5 +202,29 @@ render_all(zathura_t* zathura)
/* redraw current page */
GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view));
cb_view_vadjustment_value_changed(view_vadjustment, NULL);
cb_view_vadjustment_value_changed(view_vadjustment, zathura);
}
gboolean
page_expose_event(GtkWidget* widget, GdkEventExpose* event, gpointer data)
{
zathura_page_t* page = data;
g_static_mutex_lock(&(page->lock));
cairo_t* cairo = gdk_cairo_create(page->drawing_area->window);
if (cairo == NULL) {
girara_error("Could not create blank page");
g_static_mutex_unlock(&(page->lock));
return false;
}
cairo_set_source_rgb(cairo, 0, 0, 0);
cairo_rectangle(cairo, 0, 0, page->width, page->height);
cairo_fill(cairo);
cairo_destroy(cairo);
g_static_mutex_unlock(&(page->lock));
return true;
}
......@@ -53,4 +53,14 @@ bool render_page(render_thread_t* render_thread, zathura_page_t* page);
*/
void render_all(zathura_t* zathura);
/**
* Renders page
*
* @param widget Drawing area
* @param event Event
* @param data Optional data
* @return true if no error occured
*/
gboolean page_expose_event(GtkWidget* widget, GdkEventExpose* event, gpointer data);
#endif // RENDER_H
......@@ -12,6 +12,15 @@
#include "utils.h"
#include "render.h"
typedef struct zathura_document_info_s
{
zathura_t* zathura;
const char* path;
const char* password;
} zathura_document_info_t;
gboolean document_info_open(gpointer data);
/* function implementation */
zathura_t*
zathura_init(int argc, char* argv[])
......@@ -84,6 +93,17 @@ zathura_init(int argc, char* argv[])
/* configuration */
config_load_default(zathura);
if (argc > 1) {
zathura_document_info_t* document_info = malloc(sizeof(zathura_document_info_t));
if (document_info != NULL) {
document_info->zathura = zathura;
document_info->path = argv[1];
document_info->password = (argc >= 2) ? argv[2] : NULL;
g_idle_add(document_info_open, document_info);
}
}
return zathura;
error_free:
......@@ -117,6 +137,22 @@ zathura_free(zathura_t* zathura)
girara_list_free(zathura->plugins.plugins);
}
gboolean
document_info_open(gpointer data)
{
zathura_document_info_t* document_info = data;
g_return_val_if_fail(document_info != NULL, FALSE);
if (document_info->zathura == NULL || document_info->path == NULL) {
free(document_info);
return FALSE;
}
document_open(document_info->zathura, document_info->path, document_info->password);
return FALSE;
}
bool
document_open(zathura_t* zathura, const char* path, const char* password)
{
......@@ -132,11 +168,6 @@ document_open(zathura_t* zathura, const char* path, const char* password)
zathura->document = document;
/* init view */
if (create_blank_pages(zathura) == false) {
return false;
}
/* view mode */
int* value = girara_setting_get(zathura->ui.session, "pages-per-row");
int pages_per_row = (value) ? *value : 1;
......@@ -203,7 +234,7 @@ page_set(zathura_t* zathura, unsigned int page_id)
}
GtkAdjustment* view_vadjustment = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(zathura->ui.session->gtk.view));
cb_view_vadjustment_value_changed(view_vadjustment, NULL);
cb_view_vadjustment_value_changed(view_vadjustment, zathura);
/* update page number */
zathura->document->current_page_number = page_id;
......@@ -249,34 +280,6 @@ page_view_set_mode(zathura_t* zathura, unsigned int pages_per_row)
gtk_widget_show_all(zathura->ui.page_view);
}
bool
create_blank_pages(zathura_t* zathura)
{
/* create blank pages */
for (unsigned int i = 0; i < zathura->document->number_of_pages; i++)
{
zathura_page_t* page = zathura->document->pages[i];
g_static_mutex_lock(&(page->lock));
cairo_t* cairo = gdk_cairo_create(page->drawing_area->window);
if (cairo == NULL) {
girara_error("Could not create blank page");
g_static_mutex_unlock(&(page->lock));
return false;
}
cairo_set_source_rgb(cairo, 1, 1, 1);
cairo_rectangle(cairo, 0, 0, page->width, page->height);
cairo_fill(cairo);
cairo_destroy(cairo);
g_static_mutex_unlock(&(page->lock));
}
return true;
}
/* main function */
int main(int argc, char* argv[])
{
......@@ -290,13 +293,6 @@ int main(int argc, char* argv[])
return -1;
}
if (argc > 1) {
if (!document_open(zathura, argv[1], NULL)) {
printf("error: could not open document\n");
return -1;
}
}
gdk_threads_enter();
gtk_main();
gdk_threads_leave();
......
......@@ -113,12 +113,4 @@ bool page_set(zathura_t* zathura, unsigned int page_id);
*/
void page_view_set_mode(zathura_t* zathura, unsigned int pages_per_row);
/**
* Create blank pages
*
* @param zathura The zathura zathura
* @return false if an error occured, otherwise true
*/
bool create_blank_pages(zathura_t* zathura);
#endif // ZATHURA_H
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment