i3lock issue

asked 2014-12-31 02:30:39 +0000

Nietzsche gravatar image

updated 2014-12-31 02:34:02 +0000

I made a little C program to act as shutdown/reboot/lock menu (and to have fun) that works perfectly when called in a running term emulator, but the lock function does not when launched like this: "urxvt -e program". Any idea why?

#include <ncurses.h>
#include <string.h>
#include <unistd.h>

int main()
{
    initscr(); keypad(stdscr, TRUE); noecho(); curs_set(0);
    int i, choice = 0, c = 0;
    const char *options[]=
    {
        "Poweroff",
        "Reboot",
        "Lock",
        0
    };

    for(i = 0; options[i]; ++i)
        mvaddstr(i, 0, options[i]);

    move(0, 0);
    do
    {
        mvchgat(choice, 0, strlen(options[choice]), A_NORMAL, 0, NULL);
        if(c == KEY_DOWN && choice < 2)
            ++choice;
        else if(c == KEY_UP && choice)
            --choice;
        mvchgat(choice, 0, strlen(options[choice]), A_REVERSE, 0, NULL);
    }
    while((c = getch()) != '\n');

    switch(choice)
    {
        case 0:
            system("mpd --kill && systemctl poweroff");

        case 1:
            system("mpd --kill && systemctl reboot");

        case 2:
            system("/home/user/Scripts/lock.sh");
    }
    curs_set(1);
    endwin();
    return 0;
}

It "works" if I don't close the program, e.g. add something like a getch() before the return. i don't understand why since system and i3lock fork.

Content of lock.sh if it can help:

#!/bin/bash
IMAGE=/tmp/lockpic.png

import -window root $IMAGE
convert $IMAGE -blur '0x5' $IMAGE
i3lock -i $IMAGE
edit retag flag offensive close merge delete