Exemplo n.º 1
0
/*
 * Create a new buffer and switch to it if successful.
 */
static void controller_new_buffer(void) {
	unsigned int buf_num;

	/* Find next available buffer number */
	if (GCon.buffers[0] == NULL) {
		buf_num = 0;
	} else {
		for (buf_num = 1; buf_num != 0; buf_num = (buf_num + 1) % CONTROLLER_MAX_BUFS) {
			if (GCon.buffers[buf_num] == NULL)
				break;
		}

		if (buf_num == 0) {
			NOTIFY("No free buffers found! Failed to create new buffer");
			return;
		}
	}

	GCon.buffers[buf_num] = buffer_init(buf_num, terminal_rows, terminal_cols);
	if (!GCon.buffers[buf_num]) {
		NOTIFY("Failed to create new buffer");
		return;
	}

	controller_set_current_buffer(buf_num);
	handle_sigwinch(NULL, -1);
}
Exemplo n.º 2
0
void			signal_handler(int sig)
{
	if (sig == SIGTSTP)
		handle_sigtstp();
	if (sig == SIGCONT)
		handle_sigcont();
	if (sig == SIGWINCH)
		handle_sigwinch();
}
Exemplo n.º 3
0
/*
 * Initialize the global controller, this includes the first buffer.
 *
 * Returns:
 * 0      - On success
 * ENOMEM - Failed to allocate memory to register
 */
int controller_init(void) {
	struct winsize winsize;
	int result;

	winsize = tty_get_winsize(STDIN);
	terminal_rows = winsize.ws_row;
	terminal_cols = winsize.ws_col;

	GCon.in.fd = STDIN;
	GCon.in.poll_flags = POLLIN | POLLPRI;
	GCon.in.poll_callback = controller_cb_in;

	GCon.out.fd = STDOUT;
	GCon.out.poll_flags = 0;
	GCon.out.poll_callback = controller_cb_out;

	GCon.buf_out_used = 0;

	result = loop_register((struct loop_fd *)&GCon.in);
	if (result != 0)
		return result;

	result = loop_register((struct loop_fd *)&GCon.out);
	if (result != 0)
		goto out_deregister;

	GCon.buffers[0] = buffer_init(0, terminal_rows, terminal_cols);
	if (!GCon.buffers[0]) {
		result = ENOMEM;
		goto out_deregister;
	}

	controller_set_current_buffer(0);

	for (int i = 0; i < ARRAY_SIZE(buffer_stack); i++)
		buffer_stack[i] = -1;

	loop_register_signal(SIGWINCH, handle_sigwinch);

	/* Force the window size of the slave */
	handle_sigwinch(NULL, -1);

	return 0;

out_deregister:
	loop_deregister((struct loop_fd *)&GCon.in);
	return result;
}