Commit fca4d040 authored by Sebastian Ramacher's avatar Sebastian Ramacher

Move synctex logic away from ZathuraPage

Also emit the D-Bus signal
parent c82bc2f0
......@@ -20,6 +20,8 @@
#include "page-widget.h"
#include "page.h"
#include "adjustment.h"
#include "synctex.h"
#include "dbus-interface.h"
gboolean
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);
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);
}
......@@ -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* data);
void cb_page_widget_scaled_button_release(ZathuraPage* page,
GdkEventButton* event, void* data);
void
cb_page_widget_link(ZathuraPage* page, void* data);
......
......@@ -13,7 +13,6 @@
#include "render.h"
#include "utils.h"
#include "shortcuts.h"
#include "synctex.h"
#include "zathura.h"
G_DEFINE_TYPE(ZathuraPage, zathura_page_widget, GTK_TYPE_DRAWING_AREA)
......@@ -96,6 +95,7 @@ enum properties_e {
enum {
TEXT_SELECTED,
IMAGE_SELECTED,
BUTTON_RELEASE,
ENTER_LINK,
LEAVE_LINK,
LAST_SIGNAL
......@@ -187,6 +187,17 @@ zathura_page_widget_class_init(ZathuraPageClass* class)
g_cclosure_marshal_generic,
G_TYPE_NONE,
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
......@@ -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(button != NULL, false);
if (button->type != GDK_BUTTON_RELEASE || button->button != 1) {
if (button->type != GDK_BUTTON_RELEASE) {
return false;
}
const int oldx = button->x;
const int oldy = button->y;
zathura_page_widget_private_t* priv = ZATHURA_PAGE_GET_PRIVATE(widget);
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 ) {
/* simple single click */
/* get links */
......@@ -716,38 +745,22 @@ cb_zathura_page_widget_button_release_event(GtkWidget* widget, GdkEventButton* b
} else {
redraw_rect(ZATHURA_PAGE(widget), &priv->mouse.selection);
bool synctex = false;
girara_setting_get(priv->zathura->ui.session, "synctex", &synctex);
zathura_rectangle_t tmp = priv->mouse.selection;
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;
double scale = zathura_document_get_scale(document);
tmp.x1 /= scale;
tmp.x2 /= scale;
tmp.y1 /= scale;
tmp.y2 /= scale;
synctex_edit(editor, priv->page, x, y);
char* text = zathura_page_get_text(priv->page, tmp, NULL);
if (text != NULL) {
if (strlen(text) > 0) {
/* emit text-selected signal */
g_signal_emit(ZATHURA_PAGE(widget), signals[TEXT_SELECTED], 0, text);
}
g_free(editor);
} else {
zathura_rectangle_t tmp = priv->mouse.selection;
double scale = zathura_document_get_scale(document);
tmp.x1 /= scale;
tmp.x2 /= scale;
tmp.y1 /= scale;
tmp.y2 /= scale;
char* text = zathura_page_get_text(priv->page, tmp, NULL);
if (text != NULL) {
if (strlen(text) > 0) {
/* emit text-selected signal */
g_signal_emit(ZATHURA_PAGE(widget), signals[TEXT_SELECTED], 0, text);
}
g_free(text);
}
g_free(text);
}
}
......@@ -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;
}
......@@ -69,7 +69,6 @@ void zathura_page_widget_draw_rectangle(ZathuraPage* widget, zathura_rectangle_t
* @param widget the widget
*/
void zathura_page_widget_clear_rectangles(ZathuraPage* widget);
/**
* 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
*/
zathura_link_t* zathura_page_widget_link_get(ZathuraPage* widget, unsigned int index);
/**
* Update the last view time of the page.
*
* @param widget the widget
*/
void zathura_page_widget_update_view_time(ZathuraPage* widget);
/**
* 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
*/
bool zathura_page_widget_have_surface(ZathuraPage* widget);
/**
* Abort outstanding render requests
*
* @param widget the 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
......@@ -791,6 +791,8 @@ document_open(zathura_t* zathura, const char* path, const char* password,
G_CALLBACK(cb_page_widget_link), (gpointer) true);
g_signal_connect(G_OBJECT(page_widget), "leave-link",
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 */
......
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