pwmt / zathura

Document viewer
https://pwmt.org/projects/zathura
zlib License
2.05k stars 142 forks source link

Add DBus method to execute shortcut functions - [closed] #546

Closed sebastinas closed 5 months ago

sebastinas commented 1 year ago

On GitLab by @rmorales on Sep 21, 2023, 20:37


Merges develop -> develop

The introduced changes make it possible to execute any shortcut function through the DBus interface. Here are some examples:

Navigate 1 page below.

$ pid="$(pgrep zathura)" && dbus-send --type="method_call" --dest="org.pwmt.zathura.PID-$pid" /org/pwmt/zathura org.pwmt.zathura.ExecuteShortcutFunction string:"navigate" string:"next" uint32:0

Navigate to the 10nth page below.

$ pid="$(pgrep zathura)" && dbus-send --type="method_call" --dest="org.pwmt.zathura.PID-$pid" /org/pwmt/zathura org.pwmt.zathura.ExecuteShortcutFunction string:"navigate" string:"next" uint32:10

Scroll down with a magnitude 1

$ pid="$(pgrep zathura)" && dbus-send --type="method_call" --dest="org.pwmt.zathura.PID-$pid" /org/pwmt/zathura org.pwmt.zathura.ExecuteShortcutFunction string:"scroll" string:"down" uint32:0

Scroll down with a magnitude 10

$ pid="$(pgrep zathura)" && dbus-send --type="method_call" --dest="org.pwmt.zathura.PID-$pid" /org/pwmt/zathura org.pwmt.zathura.ExecuteShortcutFunction string:"scroll" string:"down" uint32:10

Toggle the index

$ pid="$(pgrep zathura)" && dbus-send --type="method_call" --dest="org.pwmt.zathura.PID-$pid" /org/pwmt/zathura org.pwmt.zathura.ExecuteShortcutFunction string:"toggle_index" string:"" uint32:0

Navigate index (assuming that the current view has enabled the index)

$ pid="$(pgrep zathura)" && dbus-send --type="method_call" --dest="org.pwmt.zathura.PID-$pid" /org/pwmt/zathura org.pwmt.zathura.ExecuteShortcutFunction string:"navigate_index" string:"down" uint32:0
sebastinas commented 1 year ago

On GitLab by @rmorales on Sep 21, 2023, 20:58


For the project to be compiled, it is necessary to include internal.h to the list of header files in meson.build (see reasoning below) from the girara repository. I've opened a merge request in the girara repository: !11

If internal.h is not included, the compiler fails with the following error:

In file included from ../source/zathura/types.h:6,
                 from ../source/zathura/dbus-interface.h:10,
                 from ../source/zathura/dbus-interface.c:3:
../source/zathura/dbus-interface.c: In function ‘handle_execute_shortcut_function’:
../source/zathura/dbus-interface.c:456:43: error: invalid use of incomplete typedef ‘girara_session_private_t’ {aka ‘struct girara_session_private_s’}
  456 |   GIRARA_LIST_FOREACH_BODY(session_private->config.shortcut_mappings, girara_shortcut_mapping_t*, data,
      |                                           ^~
../source/zathura/dbus-interface.c:457:23: error: invalid use of incomplete typedef ‘girara_shortcut_mapping_t’ {aka ‘struct girara_shortcut_mapping_s’}
  457 |     if (g_strcmp0(data->identifier, shortcut_function_string) == 0) {
      |                       ^~
../source/zathura/dbus-interface.c:458:31: error: invalid use of incomplete typedef ‘girara_shortcut_mapping_t’ {aka ‘struct girara_shortcut_mapping_s’}
  458 |       shortcut_function = data->function;
      |                               ^~
../source/zathura/dbus-interface.c:464:43: error: invalid use of incomplete typedef ‘girara_session_private_t’ {aka ‘struct girara_session_private_s’}
  464 |   GIRARA_LIST_FOREACH_BODY(session_private->config.argument_mappings, girara_argument_mapping_t*, mapping,
      |                                           ^~
../source/zathura/dbus-interface.c:465:26: error: invalid use of incomplete typedef ‘girara_argument_mapping_t’ {aka ‘struct girara_argument_mapping_s’}
  465 |     if (g_strcmp0(mapping->identifier, argument_string) == 0) {
      |                          ^~
../source/zathura/dbus-interface.c:466:28: error: invalid use of incomplete typedef ‘girara_argument_mapping_t’ {aka ‘struct girara_argument_mapping_s’}
  466 |       argument->n = mapping->value;
sebastinas commented 1 year ago

On GitLab by @rmorales on Sep 21, 2023, 21:02


mentioned in merge request girara!11

sebastinas commented 1 year ago

I think it is best to add a new function in girara that handles the execution of the function. These are all girara internals.

sebastinas commented 5 months ago

This MR is not merge-able as is.