Xfce Forum

Sub domains
 

You are not logged in.

#1 2015-10-12 19:32:55

johnywhy
Member
Registered: 2011-10-09
Posts: 208

[Solved] Command to display "Are you sure you want to shut down?"

hi

what CLI command can i use to display the same user confirmation dialog that's displayed when you click "Shut down" from the Actions menu?

This dialog includes "shutting down in 30 seconds" countdown timer.

thx!

Last edited by johnywhy (2019-08-13 02:05:42)


ArchLabs xfce x86_64

Offline

#2 2015-10-12 21:05:21

ToZ
Moderator
From: Canada
Registered: 2011-06-02
Posts: 5,673

Re: [Solved] Command to display "Are you sure you want to shut down?"

It looks like the countdown timer is hard-coded into the Actions plugin.

You can create something like it using yad and a script like:

#!/bin/bash

ANS=$(yad --question --center --on-top --sticky --timeout=30 --timeout-indicator=bottom --image=gnome-shutdown --title "Shutdown" --text "\n Do you want to shutdown?     ") 

if [ $? -eq 0 ]; then   
    xfce4-session-logout -h
fi

exit 0

shutdown2.png

Offline

#3 2019-08-04 08:30:39

johnywhy
Member
Registered: 2011-10-09
Posts: 208

Re: [Solved] Command to display "Are you sure you want to shut down?"

another way.
This proceeds with shutdown without user- intervention.
User can interrupt it with ctrl-c, if desired.

echo -e '\e[8;10;40t\e[5;1;31;49mShutting down in 10 seconds. \nCONTROL-C to cancel. \nENTER to shutdown now.' ; read -t 10 ; shutdown now

Last edited by johnywhy (2019-08-04 08:32:43)


ArchLabs xfce x86_64

Offline

#4 2019-08-04 19:34:42

Misko_2083
Member
Registered: 2015-10-13
Posts: 115
Website

Re: [Solved] Command to display "Are you sure you want to shut down?"

ToZ wrote:

It looks like the countdown timer is hard-coded into the Actions plugin.

You can create something like it using yad and a script like:

#!/bin/bash

ANS=$(yad --question --center --on-top --sticky --timeout=30 --timeout-indicator=bottom --image=gnome-shutdown --title "Shutdown" --text "\n Do you want to shutdown?     ") 

if [ $? -eq 0 ]; then   
    xfce4-session-logout -h
fi

exit 0

http://en.zimagez.com/miniature/shutdown2.png

This is gtk way:

save next as timer.c

#include <stdio.h>
#include <string.h>
#include <gtk/gtk.h>

/* Shutdown timer */

static gboolean continue_timer = FALSE;
static gboolean start_timer = TRUE;
static int sec_expired = 30;
static gchar      *command[] = { "xfce4-session-logout -h",NULL };
GError     *error = NULL;

static void
_quit_cb (GtkWidget *button, gpointer data)
{
    (void)button; (void)data; /* Avoid compiler warnings */
    gtk_main_quit();
    return;
}

static void
shutdown (GtkWidget *button, gpointer data)
{
    (void)button; (void)data; /* Avoid compiler warnings */
    g_spawn_command_line_async(*command, &error);
    if (error != NULL) {
        g_warning("unable to launch: %s", error->message);
        }
    gtk_main_quit();
}

static gboolean
_label_update(gpointer data)
{
    GtkLabel *label = (GtkLabel*)data;
    char buf[256];
    memset(&buf, 0x0, 256);
    snprintf(buf, 255, "Turning off computer in  %d seconds.", --sec_expired);
    if (sec_expired == 0)
        {
        g_spawn_command_line_async(*command, &error);
        if (error != NULL) {
            g_warning("unable to launch: %s", error->message);
            }
        gtk_main_quit();
        }
    gtk_label_set_label(label, buf);
    return continue_timer;
}


int main(void)
{
    GtkWidget *window;
    GtkWidget *box;
    GtkWidget *boxl;
    GtkWidget *shutdown_button;
    GtkWidget *cancel_button;
    GtkWidget *label;
    GtkWidget *question;

    gtk_init(NULL, NULL);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_widget_set_size_request(window, 250, 120);
    gtk_window_set_resizable (GTK_WINDOW(window), FALSE);
    gtk_window_set_keep_above (GTK_WINDOW (window), TRUE);
    gtk_window_stick (GTK_WINDOW (window));
    gtk_window_set_skip_taskbar_hint (GTK_WINDOW (window), TRUE);
    gtk_window_set_title (GTK_WINDOW (window), "Shutdown");
    g_signal_connect (G_OBJECT (window), "destroy", 
                    G_CALLBACK (gtk_main_quit),
                    NULL);
    box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 2);
    boxl = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);

    gtk_box_set_homogeneous (GTK_BOX (box), TRUE);
    gtk_container_add(GTK_CONTAINER(window),boxl);

    question = gtk_label_new("\nAre you sure you want to shutdown?");
    label = gtk_label_new("Turning off computer in  30 seconds.");

    shutdown_button = gtk_button_new_with_label("Shutdown");
    g_signal_connect(G_OBJECT(shutdown_button), "clicked", G_CALLBACK(shutdown), shutdown_button);

    cancel_button = gtk_button_new_with_label("Cancel");
    g_signal_connect(G_OBJECT(cancel_button), "clicked", G_CALLBACK(_quit_cb), NULL);

    gtk_box_pack_start (GTK_BOX(boxl), question, TRUE, TRUE, 0);
    gtk_box_pack_start (GTK_BOX(boxl), label, TRUE, TRUE, 0);

    gtk_box_pack_start (GTK_BOX (box), cancel_button, TRUE, TRUE, 10);
    gtk_box_pack_start (GTK_BOX(box), shutdown_button, TRUE, TRUE, 10);
    gtk_box_pack_start (GTK_BOX(boxl), box, TRUE, TRUE, 10);

    gtk_widget_show_all(window);

    g_timeout_add_seconds(1, _label_update, label);
    continue_timer = TRUE;
    start_timer = TRUE;

    gtk_main();
    return 0;
}

Deps: on debian, install libgtk-3-dev
compile with:

gcc  -o timer -fPIC timer.c `pkg-config --cflags --libs gtk+-3.0`

I could make a panel plugin to launch this but I preffer it this way.

9hRjZXH.png

Offline

#5 2019-08-04 19:52:30

johnywhy
Member
Registered: 2011-10-09
Posts: 208

Re: [Solved] Command to display "Are you sure you want to shut down?"

gtk way is prettier! Tho my bash method can go right into the launcher as a one-liner smile

generally, i prefer this no-interaction approach (do nothing to accept) to the 'confirm' style. Less clicking smile

Last edited by johnywhy (2019-08-04 19:54:02)


ArchLabs xfce x86_64

Offline

#6 2019-08-08 20:59:29

Misko_2083
Member
Registered: 2015-10-13
Posts: 115
Website

Re: [Solved] Command to display "Are you sure you want to shut down?"

johnywhy wrote:

gtk way is prettier! Tho my bash method can go right into the launcher as a one-liner smile

generally, i prefer this no-interaction approach (do nothing to accept) to the 'confirm' style. Less clicking smile

but this is one liner, once you compile you get a binary and set the launcher to use that binary.
If you want less clicking you can always remove the buttons. smile

Offline

#7 2019-08-11 20:39:40

johnywhy
Member
Registered: 2011-10-09
Posts: 208

Re: [Solved] Command to display "Are you sure you want to shut down?"

Sleep is a nice touch

systemctl suspend

oKtod2K.png


ArchLabs xfce x86_64

Offline

Board footer

Powered by FluxBB