Example #1
0
static void sighandler(int sig) {
	(void)sig;
    restore_stdin();

    // Assume we'll only be called before death
    // See note before sigaction() in set_stdin_raw()
    //
    // Now, close all standard I/O to cause the pumps
    // to exit so we can continue and retrieve the exit
    // code
    close(STDIN_FILENO);
    close(STDOUT_FILENO);
    close(STDERR_FILENO);

    // Put back all the default handlers
    struct sigaction act;
    int i;

    memset(&act, '\0', sizeof(act));
    act.sa_handler = SIG_DFL;
    for (i = 0; quit_signals[i]; i++) {
        if (sigaction(quit_signals[i], &act, NULL) < 0) {
            PLOGE("Error removing signal handler");
            continue;
        }
    }
}
Example #2
0
void feh_event_handle_stdin()
{
	char stdin_buf[2];
	static char is_esc = 0;
	KeySym keysym = NoSymbol;
	if (read(STDIN_FILENO, &stdin_buf, 1) == -1) {
		control_via_stdin = 0;
		if (isatty(STDIN_FILENO) && getpgrp() == (tcgetpgrp(STDIN_FILENO))) {
			weprintf("reading a command from stdin failed - disabling control via stdin");
			restore_stdin();
		}
		return;
	}
	stdin_buf[1] = '\0';

	// escape?
	if (stdin_buf[0] == 0x1b) {
		is_esc = 1;
		return;
	}
	if ((is_esc == 1) && (stdin_buf[0] == '[')) {
		is_esc = 2;
		return;
	}

	if (stdin_buf[0] == ' ')
		keysym = XK_space;
	else if (stdin_buf[0] == '\n')
		keysym = XK_Return;
	else if ((stdin_buf[0] == '\b') || (stdin_buf[0] == 127))
		keysym = XK_BackSpace;
	else if (is_esc == 2) {
		if (stdin_buf[0] == 'A')
			keysym = XK_Up;
		else if (stdin_buf[0] == 'B')
			keysym = XK_Down;
		else if (stdin_buf[0] == 'C')
			keysym = XK_Right;
		else if (stdin_buf[0] == 'D')
			keysym = XK_Left;
		is_esc = 0;
	}
	else
		keysym = XStringToKeysym(stdin_buf);

	if (window_num)
		feh_event_handle_generic(windows[0], is_esc * Mod1Mask, keysym, 0);

	is_esc = 0;
}