Пример #1
0
int main(int argc, char **argv) {
	slog_init("dash", "slog.cfg", 400, 500, 1);
	slog(400, SLOG_INFO, "Starting arcs-dash");

	r_args = calloc(1, sizeof(struct runtime_args));
	parse_args(r_args, argc, argv);
	bool valid_viewer = r_args->r_viewer_ip != NULL;

	mode = MODE_DISABLED;

	screen_init();
	kb_connect();
	connect_comms();

	char *js = found_js();
	if (js != NULL) {
		js_connect(js);
	}

	struct iface_args *props = calloc(1, sizeof(struct iface_args));
	props->js = (js == NULL) ? "Not found" : js;

	while (true) {
		if (props->jsstat.btn_guide) {
			slog(400, SLOG_INFO, "Quit due to guide button press");
			break;
		}
		pthread_mutex_lock(&kb_lock);
		if (get_kb_status()->close_request) {
			slog(400, SLOG_INFO, "Quit due to keyboard press");
			break;
		}
		pthread_mutex_unlock(&kb_lock);
		usleep(10000);
		pthread_mutex_lock(&js_lock);
		props->jsstat = get_js_state();
		props->remote = addrstr();
		props->mode = mode;
		props->use_viewer = valid_viewer && get_kb_status()->use_viewer;
		props->viewer_ip = valid_viewer ? r_args->r_viewer_ip : "NULL";
		redraw(props);

		update_comms(get_js_state(), mode,
					 valid_viewer && get_kb_status()->use_viewer,
					 r_args->r_viewer_ip);

		pthread_mutex_unlock(&js_lock);
	}
	slog(400, SLOG_INFO, "Exiting");

	free(props);
	free(r_args);
	screen_close();
	disconnect_comms();
	return 0;
}
Пример #2
0
// 初始化窗口并设置标题
int screen_init(int w, int h, const TCHAR *title) {
	WNDCLASS wc = { CS_BYTEALIGNCLIENT, (WNDPROC)screen_events, 0, 0, 0,
		NULL, NULL, NULL, NULL, _T("SCREEN3.1415926") };
	BITMAPINFO bi = { { sizeof(BITMAPINFOHEADER), w, -h, 1, 32, BI_RGB,
		w * h * 4, 0, 0, 0, 0 } };
	RECT rect = { 0, 0, w, h };
	int wx, wy, sx, sy;
	LPVOID ptr;
	HDC hDC;

	screen_close();

	wc.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
	wc.hInstance = GetModuleHandle(NULL);
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	if (!RegisterClass(&wc)) return -1;

	screen_handle = CreateWindow(_T("SCREEN3.1415926"), title,
		WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
		0, 0, 0, 0, NULL, NULL, wc.hInstance, NULL);
	if (screen_handle == NULL) return -2;

	screen_exit = 0;
	hDC = GetDC(screen_handle);
	screen_dc = CreateCompatibleDC(hDC);
	ReleaseDC(screen_handle, hDC);

	screen_hb = CreateDIBSection(screen_dc, &bi, DIB_RGB_COLORS, &ptr, 0, 0);
	if (screen_hb == NULL) return -3;

	screen_ob = (HBITMAP)SelectObject(screen_dc, screen_hb);
	screen_fb = (unsigned char*)ptr;
	screen_w = w;
	screen_h = h;
	screen_pitch = w * 4;

	AdjustWindowRect(&rect, GetWindowLong(screen_handle, GWL_STYLE), 0);
	wx = rect.right - rect.left;
	wy = rect.bottom - rect.top;
	sx = (GetSystemMetrics(SM_CXSCREEN) - wx) / 2;
	sy = (GetSystemMetrics(SM_CYSCREEN) - wy) / 2;
	if (sy < 0) sy = 0;
	SetWindowPos(screen_handle, NULL, sx, sy, wx, wy, (SWP_NOCOPYBITS | SWP_NOZORDER | SWP_SHOWWINDOW));
	SetForegroundWindow(screen_handle);

	ShowWindow(screen_handle, SW_NORMAL);
	screen_dispatch();

	memset(screen_keys, 0, sizeof(int)* 512);
	memset(screen_fb, 0, w * h * 4);

	return 0;
}
Пример #3
0
void screen_init(int top, int left, int bottom, int right)
{
    screen_close();				/* make sure "old" screen is closed	*/

    if (scroll_mode == 0)			/* if slow scrolling enabled...		*/
	return;					/* ...now using non-screen output form	*/

    get_screen_size(&max_rows, &max_cols);

    origin_y = top;				/* this is (1,1) of the history area	*/
    origin_x = left;

    /* The width (columns) assumes a worse possible (actually impossible) case where 	*/
    /* there were nothing but a line of xterm cursor positioning controls, i.e.,	*/
    /* "\033[r;cH" where r and c are the row and column screen coordinates and each is	*/
    /* a 3-digit number.  That's 10 bytes per column.					*/

    max_y = max_rows;				/* this many rows			*/
    max_x = max_cols + 10*max_cols;		/* worse possible case for width	*/

    screen       = gdb_malloc(max_y * max_x);	/* allocate the screen buffers...	*/
    prev_screen  = gdb_malloc(max_y * max_x);

    row_len	 = gdb_malloc(max_y * sizeof(int)); /* allocate the row size arrays...	*/
    prev_row_len = gdb_malloc(max_y * sizeof(int));

    memset(screen,      ' ', max_y * max_x);	/* init the screens to all blanks...	*/
    memset(prev_screen, ' ', max_y * max_x);

    memset(row_len,     0, max_y * sizeof(int));/* init the row sizes to all 0's	*/
    memset(prev_row_len,0, max_y * sizeof(int));

    cursor_y = bottom;				/* position the cursor just in case	*/
    cursor_x = left;

    #define TRY_SETVBUF 0
    #if TRY_SETVBUF
    stdout_fd = dup(STDOUT_FILENO);
    if (stdout_fd >= 0) {
	screen_stdout = fdopen(stdout_fd, "a");
	if (!screen_stdout) {
	    screen_stdout = stdout;
	    //close(stdout_fd); // ??
	    stdout_fd = -1;
	} else
	    //setvbuf(screen_stdout, NULL, _IOFBF, BUFSIZE);
	    //setvbuf(screen_stdout, NULL, _IOFBF, 2800);
	    setvbuf(screen_stdout, NULL, _IOFBF, 200);
    }
    #else
    screen_stdout = stdout;
    #endif
}