yad icon indicating copy to clipboard operation
yad copied to clipboard

would like a button to run a function on being pressed and run the function again on being released?

Open manoflinux opened this issue 2 years ago • 3 comments

I am not sure there is a way to do this with yad in its current state so I am putting in this request. Using xdotool I made a script that sends a mute toggle to a piece of meeting software I use(its just a keyboard shortcut), and its currently its linked to an icon on my taskbar but what I would rather have is an instance of yad with a button called "push to talk" so it starts muted, and then when I press the button it unmutes it until I release the button and then it mutes it again. I poked around and didn't see how to do it. I know it probably wont work with dialog buttons because they seem to result in yad ending, but would it be possible with an addition to how the form buttons work? Or would this require a new dialog type?

Also would just like to say yad is such a useful tool and have written 3 system tray apps using it so far, an audio note maker, something to give you file dates and something else. .

manoflinux avatar Aug 24 '22 14:08 manoflinux

or script and they could be two different scripts, it just makes sense for my application to use the same one.

manoflinux avatar Aug 24 '22 22:08 manoflinux

It is already possible with changed action and check button. With the latest version even with switch.

yad --form --field="Check":CHK --field="Switch":SW --field="Switch 2":SW "FALSE" "TRUE" "TRUE" --changed-action 'yad --text="%1 %2 %3"'

Misko-2083 avatar Jan 13 '23 05:01 Misko-2083

Now when you mentioned this, even button-press and release events would work on a label too. All we would need is an event box

#include <gtk/gtk.h>

static gboolean
button_press_event_cb( GtkWidget *widget, GdkEvent *event )
{
    g_return_val_if_fail ( GTK_IS_LABEL ( widget ), FALSE );

    switch ( event->type )
    {
        case GDK_BUTTON_PRESS :
            printf ( "Button Pressed\n" );
            return TRUE;

        case GDK_BUTTON_RELEASE :
            printf ( "Button Released\n" );
            return TRUE;

        default:
            return FALSE;
    }

    return FALSE;
}

int main ( void )
{
    GtkWidget *window;
    GtkWidget *label;
    GtkWidget *event_box;

    gtk_init ( NULL, NULL );

    window = gtk_window_new ( GTK_WINDOW_TOPLEVEL );
    gtk_window_set_default_size ( GTK_WINDOW ( window ), 200, 200 );
    g_signal_connect ( window, "delete-event", G_CALLBACK ( gtk_main_quit ), NULL );

    event_box = gtk_event_box_new();
    gtk_container_add ( GTK_CONTAINER ( window ), event_box );

    label = gtk_label_new ( "Click Here!" );
    gtk_container_add ( GTK_CONTAINER ( event_box ), label );

    g_signal_connect_swapped ( event_box, "button-press-event",   G_CALLBACK ( button_press_event_cb ), label );
    g_signal_connect_swapped ( event_box, "button-release-event", G_CALLBACK ( button_press_event_cb ), label );

    gtk_widget_show_all ( window );

    gtk_main ();
}

Though not sure about the usefulness of such new field.

Misko-2083 avatar Jan 13 '23 06:01 Misko-2083