Move synctex logic away from ZathuraPage

Also emit the D-Bus signal
This commit is contained in:
Sebastian Ramacher 2014-08-22 20:42:33 +02:00
parent c82bc2f0d4
commit fca4d040a4
5 changed files with 99 additions and 34 deletions

View file

@ -20,6 +20,8 @@
#include "page-widget.h" #include "page-widget.h"
#include "page.h" #include "page.h"
#include "adjustment.h" #include "adjustment.h"
#include "synctex.h"
#include "dbus-interface.h"
gboolean gboolean
cb_destroy(GtkWidget* UNUSED(widget), zathura_t* zathura) cb_destroy(GtkWidget* UNUSED(widget), zathura_t* zathura)
@ -602,3 +604,38 @@ cb_page_widget_link(ZathuraPage* page, void* data)
gdk_window_set_cursor(window, cursor); gdk_window_set_cursor(window, cursor);
g_object_unref(cursor); g_object_unref(cursor);
} }
void
cb_page_widget_scaled_button_release(ZathuraPage* page_widget, GdkEventButton* event,
void* data)
{
if (event->button != 1 || !(event->state & GDK_CONTROL_MASK)) {
return;
}
zathura_t* zathura = data;
bool synctex = false;
girara_setting_get(zathura->ui.session, "synctex", &synctex);
if (synctex == false) {
return;
}
zathura_page_t* page = zathura_page_widget_get_page(page_widget);
if (zathura->dbus != NULL) {
zathura_dbus_edit(zathura->dbus, zathura_page_get_index(page), event->x, event->y);
}
char* editor = NULL;
girara_setting_get(zathura->ui.session, "synctex-editor-command", &editor);
if (editor == NULL || *editor == '\0') {
g_free(editor);
return;
}
synctex_edit(editor, page, event->x, event->y);
g_free(editor);
}

View file

@ -200,6 +200,9 @@ void cb_page_widget_text_selected(ZathuraPage* page, const char* text,
void cb_page_widget_image_selected(ZathuraPage* page, GdkPixbuf* pixbuf, void cb_page_widget_image_selected(ZathuraPage* page, GdkPixbuf* pixbuf,
void* data); void* data);
void cb_page_widget_scaled_button_release(ZathuraPage* page,
GdkEventButton* event, void* data);
void void
cb_page_widget_link(ZathuraPage* page, void* data); cb_page_widget_link(ZathuraPage* page, void* data);

View file

@ -13,7 +13,6 @@
#include "render.h" #include "render.h"
#include "utils.h" #include "utils.h"
#include "shortcuts.h" #include "shortcuts.h"
#include "synctex.h"
#include "zathura.h" #include "zathura.h"
G_DEFINE_TYPE(ZathuraPage, zathura_page_widget, GTK_TYPE_DRAWING_AREA) G_DEFINE_TYPE(ZathuraPage, zathura_page_widget, GTK_TYPE_DRAWING_AREA)
@ -96,6 +95,7 @@ enum properties_e {
enum { enum {
TEXT_SELECTED, TEXT_SELECTED,
IMAGE_SELECTED, IMAGE_SELECTED,
BUTTON_RELEASE,
ENTER_LINK, ENTER_LINK,
LEAVE_LINK, LEAVE_LINK,
LAST_SIGNAL LAST_SIGNAL
@ -187,6 +187,17 @@ zathura_page_widget_class_init(ZathuraPageClass* class)
g_cclosure_marshal_generic, g_cclosure_marshal_generic,
G_TYPE_NONE, G_TYPE_NONE,
0); 0);
signals[BUTTON_RELEASE] = g_signal_new("scaled-button-release",
ZATHURA_TYPE_PAGE,
G_SIGNAL_RUN_LAST,
0,
NULL,
NULL,
g_cclosure_marshal_generic,
G_TYPE_NONE,
1,
G_TYPE_POINTER);
} }
static void static void
@ -688,13 +699,31 @@ cb_zathura_page_widget_button_release_event(GtkWidget* widget, GdkEventButton* b
{ {
g_return_val_if_fail(widget != NULL, false); g_return_val_if_fail(widget != NULL, false);
g_return_val_if_fail(button != NULL, false); g_return_val_if_fail(button != NULL, false);
if (button->type != GDK_BUTTON_RELEASE || button->button != 1) {
if (button->type != GDK_BUTTON_RELEASE) {
return false; return false;
} }
const int oldx = button->x;
const int oldy = button->y;
zathura_page_widget_private_t* priv = ZATHURA_PAGE_GET_PRIVATE(widget); zathura_page_widget_private_t* priv = ZATHURA_PAGE_GET_PRIVATE(widget);
zathura_document_t* document = zathura_page_get_document(priv->page); zathura_document_t* document = zathura_page_get_document(priv->page);
const double scale = zathura_document_get_scale(document);
button->x /= scale;
button->y /= scale;
g_signal_emit(ZATHURA_PAGE(widget), signals[BUTTON_RELEASE], 0, button);
button->x = oldx;
button->y = oldy;
if (button->button != 1) {
return false;
}
if (priv->mouse.selection.y2 == -1 && priv->mouse.selection.x2 == -1 ) { if (priv->mouse.selection.y2 == -1 && priv->mouse.selection.x2 == -1 ) {
/* simple single click */ /* simple single click */
/* get links */ /* get links */
@ -716,21 +745,6 @@ cb_zathura_page_widget_button_release_event(GtkWidget* widget, GdkEventButton* b
} else { } else {
redraw_rect(ZATHURA_PAGE(widget), &priv->mouse.selection); redraw_rect(ZATHURA_PAGE(widget), &priv->mouse.selection);
bool synctex = false;
girara_setting_get(priv->zathura->ui.session, "synctex", &synctex);
if (synctex == true && button->state & GDK_CONTROL_MASK) {
/* synctex backwards sync */
char* editor = NULL;
girara_setting_get(priv->zathura->ui.session, "synctex-editor-command", &editor);
if (editor != NULL && *editor != '\0') {
double scale = zathura_document_get_scale(document);
int x = button->x / scale, y = button->y / scale;
synctex_edit(editor, priv->page, x, y);
}
g_free(editor);
} else {
zathura_rectangle_t tmp = priv->mouse.selection; zathura_rectangle_t tmp = priv->mouse.selection;
double scale = zathura_document_get_scale(document); double scale = zathura_document_get_scale(document);
@ -749,7 +763,6 @@ cb_zathura_page_widget_button_release_event(GtkWidget* widget, GdkEventButton* b
g_free(text); g_free(text);
} }
} }
}
priv->mouse.selection_basepoint.x = -1; priv->mouse.selection_basepoint.x = -1;
priv->mouse.selection_basepoint.y = -1; priv->mouse.selection_basepoint.y = -1;
@ -999,3 +1012,10 @@ zathura_page_widget_abort_render_request(ZathuraPage* widget)
} }
} }
zathura_page_t*
zathura_page_widget_get_page(ZathuraPage* widget) {
g_return_val_if_fail(ZATHURA_IS_PAGE(widget), NULL);
zathura_page_widget_private_t* priv = ZATHURA_PAGE_GET_PRIVATE(widget);
return priv->page;
}

View file

@ -69,7 +69,6 @@ void zathura_page_widget_draw_rectangle(ZathuraPage* widget, zathura_rectangle_t
* @param widget the widget * @param widget the widget
*/ */
void zathura_page_widget_clear_rectangles(ZathuraPage* widget); void zathura_page_widget_clear_rectangles(ZathuraPage* widget);
/** /**
* Returns the zathura link object at the given index * Returns the zathura link object at the given index
* *
@ -78,14 +77,12 @@ void zathura_page_widget_clear_rectangles(ZathuraPage* widget);
* @return Link object or NULL if an error occured * @return Link object or NULL if an error occured
*/ */
zathura_link_t* zathura_page_widget_link_get(ZathuraPage* widget, unsigned int index); zathura_link_t* zathura_page_widget_link_get(ZathuraPage* widget, unsigned int index);
/** /**
* Update the last view time of the page. * Update the last view time of the page.
* *
* @param widget the widget * @param widget the widget
*/ */
void zathura_page_widget_update_view_time(ZathuraPage* widget); void zathura_page_widget_update_view_time(ZathuraPage* widget);
/** /**
* Check if we have a surface. * Check if we have a surface.
* *
@ -93,12 +90,18 @@ void zathura_page_widget_update_view_time(ZathuraPage* widget);
* @returns true if the widget has a surface, false otherwise * @returns true if the widget has a surface, false otherwise
*/ */
bool zathura_page_widget_have_surface(ZathuraPage* widget); bool zathura_page_widget_have_surface(ZathuraPage* widget);
/** /**
* Abort outstanding render requests * Abort outstanding render requests
* *
* @param widget the widget * @param widget the widget
*/ */
void zathura_page_widget_abort_render_request(ZathuraPage* widget); void zathura_page_widget_abort_render_request(ZathuraPage* widget);
/**
* Get underlying page
*
* @param widget the widget
* @return underlying zathura_page_t instance
*/
zathura_page_t* zathura_page_widget_get_page(ZathuraPage* widget);
#endif #endif

View file

@ -791,6 +791,8 @@ document_open(zathura_t* zathura, const char* path, const char* password,
G_CALLBACK(cb_page_widget_link), (gpointer) true); G_CALLBACK(cb_page_widget_link), (gpointer) true);
g_signal_connect(G_OBJECT(page_widget), "leave-link", g_signal_connect(G_OBJECT(page_widget), "leave-link",
G_CALLBACK(cb_page_widget_link), (gpointer) false); G_CALLBACK(cb_page_widget_link), (gpointer) false);
g_signal_connect(G_OBJECT(page_widget), "scaled-button-release",
G_CALLBACK(cb_page_widget_scaled_button_release), zathura);
} }
/* view mode */ /* view mode */