yad icon indicating copy to clipboard operation
yad copied to clipboard

[Enhancement Request] Expand `--command` Parameter Functionality in `yad` Notifications

Open KernelGhost opened this issue 6 months ago • 2 comments

Thank you for your continued development of this amazing package!

I am currently working on a simple application that uses a yad notification. As discussed in this issue, I am trying to programmatically update the yad notification menu entries (options) immediately before displaying the menu to the user following a left-click on the yad notification icon. I understand that the code to be executed when the user left-clicks the yad notification icon can be specified using the --command argument.

According to the relevant yad documentation:

"There are two special commands - 'menu' for popup user defined menu and 'quit' for exit the program."

I have tried various combinations of commands to execute an initial command (e.g., --command="bash -c 'generate_menu_entries' && menu"), but these attempts have been unsuccessful.

The current bash code I am using to generate the yad notification is as follows:

yad --notification \
    --listen \
    --no-middle \
    --text="WinApps Launcher" \
    --image="AppIcon.svg" \
    --command="menu" <&3

The actual menu entries are determined at runtime, and are communicated to the yad notification using a pipe (e.g., echo "menu:Resume!bash -c resume_windows!${ICONS_PATH}/Resume.svg" >&3).

Upon reviewing the yad source code, particularly lines 155 to 172 of src/notification.c, it seems that the popup_menu_cb function can only be executed if --command exactly specifies "menu" (via a case-insensitive string comparison).

static gboolean
activate_cb (GtkWidget * widget, YadData * data)
{
  if ((action == NULL && !options.common_data.listen) || (action && g_ascii_strcasecmp (action, "quit") == 0))
    {
      exit_code = YAD_RESPONSE_OK;
      gtk_main_quit ();
    }
  else if (action)
    {
      if (g_ascii_strcasecmp (action, "menu") == 0)
        popup_menu_cb (GTK_STATUS_ICON (widget), 1, GDK_CURRENT_TIME, data);
      else
        run_command_async (action);
    }

  return TRUE;
}

It would be extremely helpful if the functionality of the --command parameter could be expanded to allow expressions such as --command="bash -c 'update_yad_notification_menu' && menu" (or similar syntax to achieve the desired effect). This would enable running additional functions before and/or after requesting the notification menu to be displayed.

Thank you!

KernelGhost avatar Jul 30 '24 06:07 KernelGhost