mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-27 13:56:00 +01:00
CS
Signed-off-by: Sebastian Ramacher <sebastian+dev@ramacher.at>
This commit is contained in:
parent
ac8be2d528
commit
a45cd0a474
2 changed files with 63 additions and 54 deletions
108
dbus-interface.c
108
dbus-interface.c
|
@ -35,8 +35,7 @@ typedef struct private_s {
|
||||||
} private_t;
|
} private_t;
|
||||||
|
|
||||||
#define GET_PRIVATE(obj) \
|
#define GET_PRIVATE(obj) \
|
||||||
(G_TYPE_INSTANCE_GET_PRIVATE((obj), ZATHURA_TYPE_DBUS, \
|
(G_TYPE_INSTANCE_GET_PRIVATE((obj), ZATHURA_TYPE_DBUS, private_t))
|
||||||
private_t))
|
|
||||||
|
|
||||||
static const GDBusInterfaceVTable interface_vtable;
|
static const GDBusInterfaceVTable interface_vtable;
|
||||||
|
|
||||||
|
@ -92,12 +91,12 @@ bus_acquired(GDBusConnection* connection, const gchar* name, void* data)
|
||||||
private_t* priv = GET_PRIVATE(dbus);
|
private_t* priv = GET_PRIVATE(dbus);
|
||||||
|
|
||||||
GError* error = NULL;
|
GError* error = NULL;
|
||||||
priv->registration_id = g_dbus_connection_register_object(connection,
|
priv->registration_id = g_dbus_connection_register_object(
|
||||||
DBUS_OBJPATH, priv->introspection_data->interfaces[0],
|
connection, DBUS_OBJPATH, priv->introspection_data->interfaces[0],
|
||||||
&interface_vtable, dbus, NULL, &error);
|
&interface_vtable, dbus, NULL, &error);
|
||||||
if (priv->registration_id == 0) {
|
if (priv->registration_id == 0) {
|
||||||
girara_warning("Failed to register object on D-Bus connection: %s",
|
girara_warning("Failed to register object on D-Bus connection: %s",
|
||||||
error->message);
|
error->message);
|
||||||
g_error_free(error);
|
g_error_free(error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -107,17 +106,17 @@ bus_acquired(GDBusConnection* connection, const gchar* name, void* data)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
name_acquired(GDBusConnection* UNUSED(connection), const gchar* name,
|
name_acquired(GDBusConnection* UNUSED(connection), const gchar* name,
|
||||||
void* UNUSED(data))
|
void* UNUSED(data))
|
||||||
{
|
{
|
||||||
girara_debug("Acquired '%s' on session bus.", name);
|
girara_debug("Acquired '%s' on session bus.", name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
name_lost(GDBusConnection* UNUSED(connection), const gchar* name,
|
name_lost(GDBusConnection* UNUSED(connection), const gchar* name,
|
||||||
void* UNUSED(data))
|
void* UNUSED(data))
|
||||||
{
|
{
|
||||||
girara_debug("Lost connection or failed to acquire '%s' on session bus.",
|
girara_debug("Lost connection or failed to acquire '%s' on session bus.",
|
||||||
name);
|
name);
|
||||||
}
|
}
|
||||||
|
|
||||||
ZathuraDbus*
|
ZathuraDbus*
|
||||||
|
@ -133,7 +132,8 @@ zathura_dbus_new(zathura_t* zathura)
|
||||||
priv->zathura = zathura;
|
priv->zathura = zathura;
|
||||||
|
|
||||||
GError* error = NULL;
|
GError* error = NULL;
|
||||||
priv->introspection_data = g_dbus_node_info_new_for_xml(DBUS_INTERFACE_XML, &error);
|
priv->introspection_data = g_dbus_node_info_new_for_xml(DBUS_INTERFACE_XML,
|
||||||
|
&error);
|
||||||
if (priv->introspection_data == NULL) {
|
if (priv->introspection_data == NULL) {
|
||||||
girara_warning("Failed to parse introspection data: %s", error->message);
|
girara_warning("Failed to parse introspection data: %s", error->message);
|
||||||
g_error_free(error);
|
g_error_free(error);
|
||||||
|
@ -142,9 +142,9 @@ zathura_dbus_new(zathura_t* zathura)
|
||||||
}
|
}
|
||||||
|
|
||||||
char* well_known_name = g_strdup_printf(DBUS_NAME_TEMPLATE, getpid());
|
char* well_known_name = g_strdup_printf(DBUS_NAME_TEMPLATE, getpid());
|
||||||
priv->owner_id = g_bus_own_name(G_BUS_TYPE_SESSION,
|
priv->owner_id = g_bus_own_name(G_BUS_TYPE_SESSION, well_known_name,
|
||||||
well_known_name, G_BUS_NAME_OWNER_FLAGS_NONE, bus_acquired,
|
G_BUS_NAME_OWNER_FLAGS_NONE, bus_acquired,
|
||||||
name_acquired, name_lost, dbus, NULL);
|
name_acquired, name_lost, dbus, NULL);
|
||||||
g_free(well_known_name);
|
g_free(well_known_name);
|
||||||
|
|
||||||
return dbus;
|
return dbus;
|
||||||
|
@ -162,7 +162,7 @@ highlight_rects(zathura_t* zathura, unsigned int page,
|
||||||
GObject* widget = G_OBJECT(zathura->pages[p]);
|
GObject* widget = G_OBJECT(zathura->pages[p]);
|
||||||
|
|
||||||
g_object_set(widget, "draw-links", FALSE, "search-results", rectangles[p],
|
g_object_set(widget, "draw-links", FALSE, "search-results", rectangles[p],
|
||||||
NULL);
|
NULL);
|
||||||
if (p == page) {
|
if (p == page) {
|
||||||
g_object_set(widget, "search-current", 0, NULL);
|
g_object_set(widget, "search-current", 0, NULL);
|
||||||
}
|
}
|
||||||
|
@ -216,10 +216,10 @@ highlight_rects(zathura_t* zathura, unsigned int page,
|
||||||
|
|
||||||
static void
|
static void
|
||||||
handle_method_call(GDBusConnection* UNUSED(connection),
|
handle_method_call(GDBusConnection* UNUSED(connection),
|
||||||
const gchar* UNUSED(sender), const gchar* object_path,
|
const gchar* UNUSED(sender), const gchar* object_path,
|
||||||
const gchar* interface_name,
|
const gchar* interface_name, const gchar* method_name,
|
||||||
const gchar* method_name, GVariant* parameters,
|
GVariant* parameters, GDBusMethodInvocation* invocation,
|
||||||
GDBusMethodInvocation* invocation, void* data)
|
void* data)
|
||||||
{
|
{
|
||||||
ZathuraDbus* dbus = data;
|
ZathuraDbus* dbus = data;
|
||||||
private_t* priv = GET_PRIVATE(dbus);
|
private_t* priv = GET_PRIVATE(dbus);
|
||||||
|
@ -236,7 +236,8 @@ handle_method_call(GDBusConnection* UNUSED(connection),
|
||||||
|
|
||||||
document_close(priv->zathura, false);
|
document_close(priv->zathura, false);
|
||||||
const bool ret = document_open(priv->zathura, filename,
|
const bool ret = document_open(priv->zathura, filename,
|
||||||
strlen(password) > 0 ? password : NULL, page);
|
strlen(password) > 0 ? password : NULL,
|
||||||
|
page);
|
||||||
g_free(filename);
|
g_free(filename);
|
||||||
g_free(password);
|
g_free(password);
|
||||||
|
|
||||||
|
@ -253,7 +254,8 @@ handle_method_call(GDBusConnection* UNUSED(connection),
|
||||||
|
|
||||||
if (priv->zathura->document == NULL) {
|
if (priv->zathura->document == NULL) {
|
||||||
g_dbus_method_invocation_return_dbus_error(invocation,
|
g_dbus_method_invocation_return_dbus_error(invocation,
|
||||||
"org.pwmt.zathura.NoOpenDocumen", "No document has been opened.");
|
"org.pwmt.zathura.NoOpenDocumen",
|
||||||
|
"No document has been opened.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,7 +280,7 @@ handle_method_call(GDBusConnection* UNUSED(connection),
|
||||||
GVariantIter* iter = NULL;
|
GVariantIter* iter = NULL;
|
||||||
GVariantIter* secondary_iter = NULL;
|
GVariantIter* secondary_iter = NULL;
|
||||||
g_variant_get(parameters, "(ua(dddd)a(udddd))", &page, &iter,
|
g_variant_get(parameters, "(ua(dddd)a(udddd))", &page, &iter,
|
||||||
&secondary_iter);
|
&secondary_iter);
|
||||||
|
|
||||||
if (page >= number_of_pages) {
|
if (page >= number_of_pages) {
|
||||||
GVariant* result = g_variant_new("(b)", false);
|
GVariant* result = g_variant_new("(b)", false);
|
||||||
|
@ -312,7 +314,7 @@ handle_method_call(GDBusConnection* UNUSED(connection),
|
||||||
|
|
||||||
zathura_rectangle_t temp_rect;
|
zathura_rectangle_t temp_rect;
|
||||||
while (g_variant_iter_loop(iter, "(dddd)", &temp_rect.x1, &temp_rect.x2,
|
while (g_variant_iter_loop(iter, "(dddd)", &temp_rect.x1, &temp_rect.x2,
|
||||||
&temp_rect.y1, &temp_rect.y2)) {
|
&temp_rect.y1, &temp_rect.y2)) {
|
||||||
zathura_rectangle_t* rect = g_try_malloc0(sizeof(zathura_rectangle_t));
|
zathura_rectangle_t* rect = g_try_malloc0(sizeof(zathura_rectangle_t));
|
||||||
if (rect == NULL) {
|
if (rect == NULL) {
|
||||||
g_variant_iter_free(iter);
|
g_variant_iter_free(iter);
|
||||||
|
@ -333,9 +335,11 @@ handle_method_call(GDBusConnection* UNUSED(connection),
|
||||||
/* get secondary rectangles */
|
/* get secondary rectangles */
|
||||||
guint temp_page = 0;
|
guint temp_page = 0;
|
||||||
while (g_variant_iter_loop(secondary_iter, "(udddd)", &temp_page,
|
while (g_variant_iter_loop(secondary_iter, "(udddd)", &temp_page,
|
||||||
&temp_rect.x1, &temp_rect.x2, &temp_rect.y1, &temp_rect.y2)) {
|
&temp_rect.x1, &temp_rect.x2, &temp_rect.y1,
|
||||||
|
&temp_rect.y2)) {
|
||||||
if (temp_page >= number_of_pages) {
|
if (temp_page >= number_of_pages) {
|
||||||
/* error out here? */
|
/* error out here? */
|
||||||
|
girara_debug("Got invalid page number.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -372,9 +376,10 @@ handle_method_call(GDBusConnection* UNUSED(connection),
|
||||||
|
|
||||||
static GVariant*
|
static GVariant*
|
||||||
handle_get_property(GDBusConnection* UNUSED(connection),
|
handle_get_property(GDBusConnection* UNUSED(connection),
|
||||||
const gchar* UNUSED(sender), const gchar* UNUSED(object_path),
|
const gchar* UNUSED(sender),
|
||||||
const gchar* UNUSED(interface_name), const gchar* property_name,
|
const gchar* UNUSED(object_path),
|
||||||
GError** error, void* data)
|
const gchar* UNUSED(interface_name),
|
||||||
|
const gchar* property_name, GError** error, void* data)
|
||||||
{
|
{
|
||||||
ZathuraDbus* dbus = data;
|
ZathuraDbus* dbus = data;
|
||||||
private_t* priv = GET_PRIVATE(dbus);
|
private_t* priv = GET_PRIVATE(dbus);
|
||||||
|
@ -406,18 +411,17 @@ static const unsigned int TIMEOUT = 3000;
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
call_hightlight_rects(GDBusConnection* connection, const char* filename,
|
call_hightlight_rects(GDBusConnection* connection, const char* filename,
|
||||||
const char* name, unsigned int page, girara_list_t* rectangles,
|
const char* name, unsigned int page,
|
||||||
girara_list_t* secondary_rects)
|
girara_list_t* rectangles, girara_list_t* secondary_rects)
|
||||||
{
|
{
|
||||||
GError* error = NULL;
|
GError* error = NULL;
|
||||||
GVariant* vfilename = g_dbus_connection_call_sync(connection,
|
GVariant* vfilename = g_dbus_connection_call_sync(
|
||||||
name, DBUS_OBJPATH, "org.freedesktop.DBus.Properties",
|
connection, name, DBUS_OBJPATH, "org.freedesktop.DBus.Properties", "Get",
|
||||||
"Get", g_variant_new("(ss)", DBUS_INTERFACE, "filename"),
|
g_variant_new("(ss)", DBUS_INTERFACE, "filename"), G_VARIANT_TYPE("(v)"),
|
||||||
G_VARIANT_TYPE("(v)"), G_DBUS_CALL_FLAGS_NONE,
|
G_DBUS_CALL_FLAGS_NONE, TIMEOUT, NULL, &error);
|
||||||
TIMEOUT, NULL, &error);
|
|
||||||
if (vfilename == NULL) {
|
if (vfilename == NULL) {
|
||||||
girara_error("Failed to query 'filename' property from '%s': %s",
|
girara_error("Failed to query 'filename' property from '%s': %s",
|
||||||
name, error->message);
|
name, error->message);
|
||||||
g_error_free(error);
|
g_error_free(error);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -440,7 +444,7 @@ call_hightlight_rects(GDBusConnection* connection, const char* filename,
|
||||||
if (rectangles != NULL) {
|
if (rectangles != NULL) {
|
||||||
GIRARA_LIST_FOREACH(rectangles, zathura_rectangle_t*, iter, rect)
|
GIRARA_LIST_FOREACH(rectangles, zathura_rectangle_t*, iter, rect)
|
||||||
g_variant_builder_add(builder, "(dddd)", rect->x1, rect->x2, rect->y1,
|
g_variant_builder_add(builder, "(dddd)", rect->x1, rect->x2, rect->y1,
|
||||||
rect->y2);
|
rect->y2);
|
||||||
GIRARA_LIST_FOREACH_END(rectangles, zathura_rectangle_t*, iter, rect);
|
GIRARA_LIST_FOREACH_END(rectangles, zathura_rectangle_t*, iter, rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -448,14 +452,15 @@ call_hightlight_rects(GDBusConnection* connection, const char* filename,
|
||||||
if (secondary_rects != NULL) {
|
if (secondary_rects != NULL) {
|
||||||
GIRARA_LIST_FOREACH(secondary_rects, synctex_page_rect_t*, iter, rect)
|
GIRARA_LIST_FOREACH(secondary_rects, synctex_page_rect_t*, iter, rect)
|
||||||
g_variant_builder_add(second_builder, "(udddd)", rect->page,
|
g_variant_builder_add(second_builder, "(udddd)", rect->page,
|
||||||
rect->rect.x1, rect->rect.x2, rect->rect.y1, rect->rect.y2);
|
rect->rect.x1, rect->rect.x2, rect->rect.y1,
|
||||||
|
rect->rect.y2);
|
||||||
GIRARA_LIST_FOREACH_END(secondary_rects, synctex_page_rect_t*, iter, rect);
|
GIRARA_LIST_FOREACH_END(secondary_rects, synctex_page_rect_t*, iter, rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
GVariant* ret = g_dbus_connection_call_sync(connection,
|
GVariant* ret = g_dbus_connection_call_sync(
|
||||||
name, DBUS_OBJPATH, DBUS_INTERFACE, "HighlightRects",
|
connection, name, DBUS_OBJPATH, DBUS_INTERFACE, "HighlightRects",
|
||||||
g_variant_new("(ua(dddd)a(udddd))", page, builder, second_builder),
|
g_variant_new("(ua(dddd)a(udddd))", page, builder, second_builder),
|
||||||
G_VARIANT_TYPE("(b)"), G_DBUS_CALL_FLAGS_NONE, TIMEOUT, NULL, &error);
|
G_VARIANT_TYPE("(b)"), G_DBUS_CALL_FLAGS_NONE, TIMEOUT, NULL, &error);
|
||||||
g_variant_builder_unref(builder);
|
g_variant_builder_unref(builder);
|
||||||
if (ret == NULL) {
|
if (ret == NULL) {
|
||||||
girara_error("Failed to run HighlightRects on '%s': %s", name,
|
girara_error("Failed to run HighlightRects on '%s': %s", name,
|
||||||
|
@ -470,10 +475,9 @@ call_hightlight_rects(GDBusConnection* connection, const char* filename,
|
||||||
|
|
||||||
bool
|
bool
|
||||||
zathura_dbus_goto_page_and_highlight(const char* filename, unsigned int page,
|
zathura_dbus_goto_page_and_highlight(const char* filename, unsigned int page,
|
||||||
girara_list_t* rectangles, girara_list_t* secondary_rects, pid_t hint)
|
girara_list_t* rectangles,
|
||||||
|
girara_list_t* secondary_rects, pid_t hint)
|
||||||
{
|
{
|
||||||
/* note: page is [1, number_of_pages] here */
|
|
||||||
|
|
||||||
if (filename == NULL) {
|
if (filename == NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -490,15 +494,16 @@ zathura_dbus_goto_page_and_highlight(const char* filename, unsigned int page,
|
||||||
if (hint != -1) {
|
if (hint != -1) {
|
||||||
char* well_known_name = g_strdup_printf(DBUS_NAME_TEMPLATE, hint);
|
char* well_known_name = g_strdup_printf(DBUS_NAME_TEMPLATE, hint);
|
||||||
const bool ret = call_hightlight_rects(connection, filename,
|
const bool ret = call_hightlight_rects(connection, filename,
|
||||||
well_known_name, page, rectangles, secondary_rects);
|
well_known_name, page, rectangles,
|
||||||
|
secondary_rects);
|
||||||
g_free(well_known_name);
|
g_free(well_known_name);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
GVariant* vnames = g_dbus_connection_call_sync(connection,
|
GVariant* vnames = g_dbus_connection_call_sync(
|
||||||
"org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus",
|
connection, "org.freedesktop.DBus", "/org/freedesktop/DBus",
|
||||||
"ListNames", NULL, G_VARIANT_TYPE("(as)"), G_DBUS_CALL_FLAGS_NONE,
|
"org.freedesktop.DBus", "ListNames", NULL, G_VARIANT_TYPE("(as)"),
|
||||||
TIMEOUT, NULL, &error);
|
G_DBUS_CALL_FLAGS_NONE, TIMEOUT, NULL, &error);
|
||||||
if (vnames == NULL) {
|
if (vnames == NULL) {
|
||||||
girara_error("Could not list available names: %s", error->message);
|
girara_error("Could not list available names: %s", error->message);
|
||||||
g_error_free(error);
|
g_error_free(error);
|
||||||
|
@ -518,7 +523,7 @@ zathura_dbus_goto_page_and_highlight(const char* filename, unsigned int page,
|
||||||
girara_debug("Found name: %s", name);
|
girara_debug("Found name: %s", name);
|
||||||
|
|
||||||
if (call_hightlight_rects(connection, filename, name, page, rectangles,
|
if (call_hightlight_rects(connection, filename, name, page, rectangles,
|
||||||
secondary_rects) == true) {
|
secondary_rects) == true) {
|
||||||
found_one = true;
|
found_one = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -539,14 +544,15 @@ zathura_dbus_synctex_position(const char* filename, const char* position,
|
||||||
|
|
||||||
unsigned int page = 0;
|
unsigned int page = 0;
|
||||||
girara_list_t* secondary_rects = NULL;
|
girara_list_t* secondary_rects = NULL;
|
||||||
girara_list_t* rectangles = synctex_rectangles_from_position(filename,
|
girara_list_t* rectangles = synctex_rectangles_from_position(
|
||||||
position, &page, &secondary_rects);
|
filename, position, &page, &secondary_rects);
|
||||||
if (rectangles == NULL) {
|
if (rectangles == NULL) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool ret = zathura_dbus_goto_page_and_highlight(filename, page,
|
const bool ret = zathura_dbus_goto_page_and_highlight(filename, page,
|
||||||
rectangles, secondary_rects, hint);
|
rectangles,
|
||||||
|
secondary_rects, hint);
|
||||||
girara_list_free(rectangles);
|
girara_list_free(rectangles);
|
||||||
girara_list_free(secondary_rects);
|
girara_list_free(secondary_rects);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
9
print.c
9
print.c
|
@ -38,11 +38,13 @@ print(zathura_t* zathura)
|
||||||
gtk_print_operation_set_use_full_page(print_operation, TRUE);
|
gtk_print_operation_set_use_full_page(print_operation, TRUE);
|
||||||
|
|
||||||
if (zathura->print.settings != NULL) {
|
if (zathura->print.settings != NULL) {
|
||||||
gtk_print_operation_set_print_settings(print_operation, zathura->print.settings);
|
gtk_print_operation_set_print_settings(print_operation,
|
||||||
|
zathura->print.settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (zathura->print.page_setup != NULL) {
|
if (zathura->print.page_setup != NULL) {
|
||||||
gtk_print_operation_set_default_page_setup(print_operation, zathura->print.page_setup);
|
gtk_print_operation_set_default_page_setup(print_operation,
|
||||||
|
zathura->print.page_setup);
|
||||||
}
|
}
|
||||||
gtk_print_operation_set_embed_page_setup(print_operation, TRUE);
|
gtk_print_operation_set_embed_page_setup(print_operation, TRUE);
|
||||||
|
|
||||||
|
@ -71,7 +73,8 @@ static void
|
||||||
cb_print_end(GtkPrintOperation* UNUSED(print_operation), GtkPrintContext*
|
cb_print_end(GtkPrintOperation* UNUSED(print_operation), GtkPrintContext*
|
||||||
UNUSED(context), zathura_t* zathura)
|
UNUSED(context), zathura_t* zathura)
|
||||||
{
|
{
|
||||||
if (zathura == NULL || zathura->ui.session == NULL || zathura->document == NULL) {
|
if (zathura == NULL || zathura->ui.session == NULL ||
|
||||||
|
zathura->document == NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue