2008-02-11 00:33:14 +08:00
|
|
|
/*
|
|
|
|
* QEMU curses/ncurses display driver
|
|
|
|
*
|
|
|
|
* Copyright (c) 2005 Andrzej Zaborowski <balrog@zabor.org>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
2016-01-30 01:49:51 +08:00
|
|
|
#include "qemu/osdep.h"
|
2008-02-11 00:33:14 +08:00
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <termios.h>
|
|
|
|
#endif
|
|
|
|
|
2009-03-07 23:32:56 +08:00
|
|
|
#include "qemu-common.h"
|
2012-11-28 19:06:30 +08:00
|
|
|
#include "ui/console.h"
|
2013-12-04 20:40:20 +08:00
|
|
|
#include "ui/input.h"
|
2012-12-18 01:20:04 +08:00
|
|
|
#include "sysemu/sysemu.h"
|
2009-03-07 23:32:56 +08:00
|
|
|
|
2017-09-27 18:38:11 +08:00
|
|
|
/* KEY_EVENT is defined in wincon.h and in curses.h. Avoid redefinition. */
|
|
|
|
#undef KEY_EVENT
|
|
|
|
#include <curses.h>
|
|
|
|
#undef KEY_EVENT
|
|
|
|
|
2008-02-11 00:33:14 +08:00
|
|
|
#define FONT_HEIGHT 16
|
|
|
|
#define FONT_WIDTH 8
|
|
|
|
|
2012-11-13 21:51:41 +08:00
|
|
|
static DisplayChangeListener *dcl;
|
2009-10-02 05:12:16 +08:00
|
|
|
static console_ch_t screen[160 * 100];
|
2008-02-11 00:33:14 +08:00
|
|
|
static WINDOW *screenpad = NULL;
|
|
|
|
static int width, height, gwidth, gheight, invalidate;
|
|
|
|
static int px, py, sminx, sminy, smaxx, smaxy;
|
|
|
|
|
2017-09-27 18:38:11 +08:00
|
|
|
static chtype vga_to_curses[256];
|
2015-10-19 20:23:46 +08:00
|
|
|
|
2012-11-13 21:51:41 +08:00
|
|
|
static void curses_update(DisplayChangeListener *dcl,
|
|
|
|
int x, int y, int w, int h)
|
2008-02-11 00:33:14 +08:00
|
|
|
{
|
2017-09-27 18:38:11 +08:00
|
|
|
console_ch_t *line;
|
|
|
|
chtype curses_line[width];
|
2008-02-11 00:33:14 +08:00
|
|
|
|
2017-09-27 18:38:11 +08:00
|
|
|
line = screen + y * width;
|
|
|
|
for (h += y; y < h; y ++, line += width) {
|
|
|
|
for (x = 0; x < width; x++) {
|
|
|
|
chtype ch = line[x] & 0xff;
|
|
|
|
chtype at = line[x] & ~0xff;
|
|
|
|
if (vga_to_curses[ch]) {
|
|
|
|
ch = vga_to_curses[ch];
|
|
|
|
}
|
|
|
|
curses_line[x] = ch | at;
|
|
|
|
}
|
|
|
|
mvwaddchnstr(screenpad, y, 0, curses_line, width);
|
|
|
|
}
|
2008-02-11 00:33:14 +08:00
|
|
|
|
|
|
|
pnoutrefresh(screenpad, py, px, sminy, sminx, smaxy - 1, smaxx - 1);
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void curses_calc_pad(void)
|
|
|
|
{
|
2013-03-14 21:27:08 +08:00
|
|
|
if (qemu_console_is_fixedsize(NULL)) {
|
2008-02-11 00:33:14 +08:00
|
|
|
width = gwidth;
|
|
|
|
height = gheight;
|
|
|
|
} else {
|
|
|
|
width = COLS;
|
|
|
|
height = LINES;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (screenpad)
|
|
|
|
delwin(screenpad);
|
|
|
|
|
|
|
|
clear();
|
|
|
|
refresh();
|
|
|
|
|
|
|
|
screenpad = newpad(height, width);
|
|
|
|
|
|
|
|
if (width > COLS) {
|
|
|
|
px = (width - COLS) / 2;
|
|
|
|
sminx = 0;
|
|
|
|
smaxx = COLS;
|
|
|
|
} else {
|
|
|
|
px = 0;
|
|
|
|
sminx = (COLS - width) / 2;
|
|
|
|
smaxx = sminx + width;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (height > LINES) {
|
|
|
|
py = (height - LINES) / 2;
|
|
|
|
sminy = 0;
|
|
|
|
smaxy = LINES;
|
|
|
|
} else {
|
|
|
|
py = 0;
|
|
|
|
sminy = (LINES - height) / 2;
|
|
|
|
smaxy = sminy + height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-13 21:51:41 +08:00
|
|
|
static void curses_resize(DisplayChangeListener *dcl,
|
|
|
|
int width, int height)
|
2008-02-11 00:33:14 +08:00
|
|
|
{
|
2012-09-28 21:02:08 +08:00
|
|
|
if (width == gwidth && height == gheight) {
|
2008-02-11 00:33:14 +08:00
|
|
|
return;
|
2012-09-28 21:02:08 +08:00
|
|
|
}
|
2008-02-11 00:33:14 +08:00
|
|
|
|
2012-09-28 21:02:08 +08:00
|
|
|
gwidth = width;
|
|
|
|
gheight = height;
|
2008-02-11 00:33:14 +08:00
|
|
|
|
|
|
|
curses_calc_pad();
|
|
|
|
}
|
|
|
|
|
2013-11-22 22:35:03 +08:00
|
|
|
#if !defined(_WIN32) && defined(SIGWINCH) && defined(KEY_RESIZE)
|
|
|
|
static volatile sig_atomic_t got_sigwinch;
|
|
|
|
static void curses_winch_check(void)
|
2008-02-11 00:33:14 +08:00
|
|
|
{
|
|
|
|
struct winsize {
|
|
|
|
unsigned short ws_row;
|
|
|
|
unsigned short ws_col;
|
|
|
|
unsigned short ws_xpixel; /* unused */
|
|
|
|
unsigned short ws_ypixel; /* unused */
|
|
|
|
} ws;
|
|
|
|
|
2013-11-22 22:35:03 +08:00
|
|
|
if (!got_sigwinch) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
got_sigwinch = false;
|
|
|
|
|
|
|
|
if (ioctl(1, TIOCGWINSZ, &ws) == -1) {
|
2008-02-11 00:33:14 +08:00
|
|
|
return;
|
2013-11-22 22:35:03 +08:00
|
|
|
}
|
2008-02-11 00:33:14 +08:00
|
|
|
|
|
|
|
resize_term(ws.ws_row, ws.ws_col);
|
|
|
|
invalidate = 1;
|
2013-11-22 22:35:03 +08:00
|
|
|
}
|
2008-02-11 00:33:14 +08:00
|
|
|
|
2013-11-22 22:35:03 +08:00
|
|
|
static void curses_winch_handler(int signum)
|
|
|
|
{
|
|
|
|
got_sigwinch = true;
|
2008-02-11 00:33:14 +08:00
|
|
|
}
|
2013-11-22 22:35:03 +08:00
|
|
|
|
|
|
|
static void curses_winch_init(void)
|
|
|
|
{
|
|
|
|
struct sigaction old, winch = {
|
|
|
|
.sa_handler = curses_winch_handler,
|
|
|
|
};
|
|
|
|
sigaction(SIGWINCH, &winch, &old);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static void curses_winch_check(void) {}
|
|
|
|
static void curses_winch_init(void) {}
|
2008-02-11 00:33:14 +08:00
|
|
|
#endif
|
|
|
|
|
2012-11-13 21:51:41 +08:00
|
|
|
static void curses_cursor_position(DisplayChangeListener *dcl,
|
|
|
|
int x, int y)
|
2008-02-11 00:33:14 +08:00
|
|
|
{
|
|
|
|
if (x >= 0) {
|
|
|
|
x = sminx + x - px;
|
|
|
|
y = sminy + y - py;
|
|
|
|
|
|
|
|
if (x >= 0 && y >= 0 && x < COLS && y < LINES) {
|
|
|
|
move(y, x);
|
|
|
|
curs_set(1);
|
|
|
|
/* it seems that curs_set(1) must always be called before
|
|
|
|
* curs_set(2) for the latter to have effect */
|
2013-03-14 21:27:08 +08:00
|
|
|
if (!qemu_console_is_graphic(NULL)) {
|
2008-02-11 00:33:14 +08:00
|
|
|
curs_set(2);
|
2013-03-14 21:27:08 +08:00
|
|
|
}
|
2008-02-11 00:33:14 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
curs_set(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* generic keyboard conversion */
|
|
|
|
|
|
|
|
#include "curses_keys.h"
|
|
|
|
|
2009-10-02 05:12:16 +08:00
|
|
|
static kbd_layout_t *kbd_layout = NULL;
|
2008-02-11 00:33:14 +08:00
|
|
|
|
2013-03-01 20:03:04 +08:00
|
|
|
static void curses_refresh(DisplayChangeListener *dcl)
|
2008-02-11 00:33:14 +08:00
|
|
|
{
|
2016-08-11 22:23:27 +08:00
|
|
|
int chr, keysym, keycode, keycode_alt;
|
2008-02-11 00:33:14 +08:00
|
|
|
|
2013-11-22 22:35:03 +08:00
|
|
|
curses_winch_check();
|
|
|
|
|
2008-02-11 00:33:14 +08:00
|
|
|
if (invalidate) {
|
|
|
|
clear();
|
|
|
|
refresh();
|
|
|
|
curses_calc_pad();
|
2013-03-12 20:44:38 +08:00
|
|
|
graphic_hw_invalidate(NULL);
|
2008-02-11 00:33:14 +08:00
|
|
|
invalidate = 0;
|
|
|
|
}
|
|
|
|
|
2013-03-12 20:44:38 +08:00
|
|
|
graphic_hw_text_update(NULL, screen);
|
2008-02-11 00:33:14 +08:00
|
|
|
|
|
|
|
while (1) {
|
|
|
|
/* while there are any pending key strokes to process */
|
2016-08-11 22:23:27 +08:00
|
|
|
chr = getch();
|
2008-02-11 00:33:14 +08:00
|
|
|
|
|
|
|
if (chr == ERR)
|
|
|
|
break;
|
|
|
|
|
2008-02-23 02:21:28 +08:00
|
|
|
#ifdef KEY_RESIZE
|
2008-02-11 00:33:14 +08:00
|
|
|
/* this shouldn't occur when we use a custom SIGWINCH handler */
|
|
|
|
if (chr == KEY_RESIZE) {
|
|
|
|
clear();
|
|
|
|
refresh();
|
|
|
|
curses_calc_pad();
|
2013-03-01 20:03:04 +08:00
|
|
|
curses_update(dcl, 0, 0, width, height);
|
2008-02-11 00:33:14 +08:00
|
|
|
continue;
|
|
|
|
}
|
2008-02-23 02:21:28 +08:00
|
|
|
#endif
|
2008-02-11 00:33:14 +08:00
|
|
|
|
|
|
|
keycode = curses2keycode[chr];
|
2010-03-01 04:03:00 +08:00
|
|
|
keycode_alt = 0;
|
2008-02-11 00:33:14 +08:00
|
|
|
|
|
|
|
/* alt key */
|
|
|
|
if (keycode == 1) {
|
2016-08-11 22:23:27 +08:00
|
|
|
int nextchr = getch();
|
2008-02-11 00:33:14 +08:00
|
|
|
|
|
|
|
if (nextchr != ERR) {
|
2010-03-01 04:03:00 +08:00
|
|
|
chr = nextchr;
|
|
|
|
keycode_alt = ALT;
|
2016-08-11 22:23:27 +08:00
|
|
|
keycode = curses2keycode[chr];
|
2008-02-11 00:33:14 +08:00
|
|
|
|
2010-03-01 04:03:00 +08:00
|
|
|
if (keycode != -1) {
|
|
|
|
keycode |= ALT;
|
2008-02-11 00:33:14 +08:00
|
|
|
|
2010-03-01 04:03:00 +08:00
|
|
|
/* process keys reserved for qemu */
|
|
|
|
if (keycode >= QEMU_KEY_CONSOLE0 &&
|
|
|
|
keycode < QEMU_KEY_CONSOLE0 + 9) {
|
|
|
|
erase();
|
|
|
|
wnoutrefresh(stdscr);
|
|
|
|
console_select(keycode - QEMU_KEY_CONSOLE0);
|
2008-02-11 00:33:14 +08:00
|
|
|
|
2010-03-01 04:03:00 +08:00
|
|
|
invalidate = 1;
|
|
|
|
continue;
|
|
|
|
}
|
2008-02-11 00:33:14 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-01 04:03:00 +08:00
|
|
|
if (kbd_layout) {
|
|
|
|
keysym = -1;
|
|
|
|
if (chr < CURSES_KEYS)
|
|
|
|
keysym = curses2keysym[chr];
|
|
|
|
|
|
|
|
if (keysym == -1) {
|
2010-10-20 01:48:20 +08:00
|
|
|
if (chr < ' ') {
|
|
|
|
keysym = chr + '@';
|
|
|
|
if (keysym >= 'A' && keysym <= 'Z')
|
|
|
|
keysym += 'a' - 'A';
|
|
|
|
keysym |= KEYSYM_CNTRL;
|
|
|
|
} else
|
2010-03-01 04:03:00 +08:00
|
|
|
keysym = chr;
|
|
|
|
}
|
2008-02-11 00:33:14 +08:00
|
|
|
|
2010-03-01 04:03:00 +08:00
|
|
|
keycode = keysym2scancode(kbd_layout, keysym & KEYSYM_MASK);
|
|
|
|
if (keycode == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
keycode |= (keysym & ~KEYSYM_MASK) >> 16;
|
|
|
|
keycode |= keycode_alt;
|
2008-02-11 00:33:14 +08:00
|
|
|
}
|
|
|
|
|
2010-03-01 04:03:00 +08:00
|
|
|
if (keycode == -1)
|
|
|
|
continue;
|
|
|
|
|
2013-03-14 21:27:08 +08:00
|
|
|
if (qemu_console_is_graphic(NULL)) {
|
2008-02-11 00:33:14 +08:00
|
|
|
/* since terminals don't know about key press and release
|
|
|
|
* events, we need to emit both for each key received */
|
2013-12-04 20:40:20 +08:00
|
|
|
if (keycode & SHIFT) {
|
|
|
|
qemu_input_event_send_key_number(NULL, SHIFT_CODE, true);
|
2014-05-28 19:05:04 +08:00
|
|
|
qemu_input_event_send_key_delay(0);
|
2013-12-04 20:40:20 +08:00
|
|
|
}
|
|
|
|
if (keycode & CNTRL) {
|
|
|
|
qemu_input_event_send_key_number(NULL, CNTRL_CODE, true);
|
2014-05-28 19:05:04 +08:00
|
|
|
qemu_input_event_send_key_delay(0);
|
2013-12-04 20:40:20 +08:00
|
|
|
}
|
|
|
|
if (keycode & ALT) {
|
|
|
|
qemu_input_event_send_key_number(NULL, ALT_CODE, true);
|
2014-05-28 19:05:04 +08:00
|
|
|
qemu_input_event_send_key_delay(0);
|
2013-12-04 20:40:20 +08:00
|
|
|
}
|
2010-03-01 04:03:00 +08:00
|
|
|
if (keycode & ALTGR) {
|
2013-12-04 20:40:20 +08:00
|
|
|
qemu_input_event_send_key_number(NULL, GREY | ALT_CODE, true);
|
2014-05-28 19:05:04 +08:00
|
|
|
qemu_input_event_send_key_delay(0);
|
2010-03-01 04:03:00 +08:00
|
|
|
}
|
2013-12-04 20:40:20 +08:00
|
|
|
|
2014-05-24 08:16:09 +08:00
|
|
|
qemu_input_event_send_key_number(NULL, keycode & KEY_MASK, true);
|
2014-05-28 19:05:04 +08:00
|
|
|
qemu_input_event_send_key_delay(0);
|
2014-05-24 08:16:09 +08:00
|
|
|
qemu_input_event_send_key_number(NULL, keycode & KEY_MASK, false);
|
2014-05-28 19:05:04 +08:00
|
|
|
qemu_input_event_send_key_delay(0);
|
2013-12-04 20:40:20 +08:00
|
|
|
|
2010-03-01 04:03:00 +08:00
|
|
|
if (keycode & ALTGR) {
|
2013-12-04 20:40:20 +08:00
|
|
|
qemu_input_event_send_key_number(NULL, GREY | ALT_CODE, false);
|
2014-05-28 19:05:04 +08:00
|
|
|
qemu_input_event_send_key_delay(0);
|
2013-12-04 20:40:20 +08:00
|
|
|
}
|
|
|
|
if (keycode & ALT) {
|
|
|
|
qemu_input_event_send_key_number(NULL, ALT_CODE, false);
|
2014-05-28 19:05:04 +08:00
|
|
|
qemu_input_event_send_key_delay(0);
|
2013-12-04 20:40:20 +08:00
|
|
|
}
|
|
|
|
if (keycode & CNTRL) {
|
|
|
|
qemu_input_event_send_key_number(NULL, CNTRL_CODE, false);
|
2014-05-28 19:05:04 +08:00
|
|
|
qemu_input_event_send_key_delay(0);
|
2013-12-04 20:40:20 +08:00
|
|
|
}
|
|
|
|
if (keycode & SHIFT) {
|
|
|
|
qemu_input_event_send_key_number(NULL, SHIFT_CODE, false);
|
2014-05-28 19:05:04 +08:00
|
|
|
qemu_input_event_send_key_delay(0);
|
2010-03-01 04:03:00 +08:00
|
|
|
}
|
2008-02-11 00:33:14 +08:00
|
|
|
} else {
|
2016-08-11 22:23:26 +08:00
|
|
|
keysym = -1;
|
|
|
|
if (chr < CURSES_KEYS) {
|
|
|
|
keysym = curses2qemu[chr];
|
|
|
|
}
|
2008-02-11 00:33:14 +08:00
|
|
|
if (keysym == -1)
|
|
|
|
keysym = chr;
|
|
|
|
|
|
|
|
kbd_put_keysym(keysym);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-22 03:44:06 +08:00
|
|
|
static void curses_atexit(void)
|
2008-02-11 00:33:14 +08:00
|
|
|
{
|
|
|
|
endwin();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void curses_setup(void)
|
|
|
|
{
|
|
|
|
int i, colour_default[8] = {
|
2015-11-29 21:28:24 +08:00
|
|
|
[QEMU_COLOR_BLACK] = COLOR_BLACK,
|
|
|
|
[QEMU_COLOR_BLUE] = COLOR_BLUE,
|
|
|
|
[QEMU_COLOR_GREEN] = COLOR_GREEN,
|
|
|
|
[QEMU_COLOR_CYAN] = COLOR_CYAN,
|
|
|
|
[QEMU_COLOR_RED] = COLOR_RED,
|
|
|
|
[QEMU_COLOR_MAGENTA] = COLOR_MAGENTA,
|
|
|
|
[QEMU_COLOR_YELLOW] = COLOR_YELLOW,
|
|
|
|
[QEMU_COLOR_WHITE] = COLOR_WHITE,
|
2008-02-11 00:33:14 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/* input as raw as possible, let everything be interpreted
|
|
|
|
* by the guest system */
|
|
|
|
initscr(); noecho(); intrflush(stdscr, FALSE);
|
|
|
|
nodelay(stdscr, TRUE); nonl(); keypad(stdscr, TRUE);
|
|
|
|
start_color(); raw(); scrollok(stdscr, FALSE);
|
|
|
|
|
2015-11-29 21:28:24 +08:00
|
|
|
/* Make color pair to match color format (3bits bg:3bits fg) */
|
2015-10-19 20:23:10 +08:00
|
|
|
for (i = 0; i < 64; i++) {
|
2008-02-11 00:33:14 +08:00
|
|
|
init_pair(i, colour_default[i & 7], colour_default[i >> 3]);
|
2015-10-19 20:23:10 +08:00
|
|
|
}
|
2015-11-29 21:28:24 +08:00
|
|
|
/* Set default color for more than 64 for safety. */
|
2015-10-19 20:23:10 +08:00
|
|
|
for (i = 64; i < COLOR_PAIRS; i++) {
|
|
|
|
init_pair(i, COLOR_WHITE, COLOR_BLACK);
|
|
|
|
}
|
2015-10-19 20:23:46 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup mapping for vga to curses line graphics.
|
|
|
|
* FIXME: for better font, have to use ncursesw and setlocale()
|
|
|
|
*/
|
|
|
|
#if 0
|
|
|
|
/* FIXME: map from where? */
|
|
|
|
ACS_S1;
|
|
|
|
ACS_S3;
|
|
|
|
ACS_S7;
|
|
|
|
ACS_S9;
|
|
|
|
#endif
|
|
|
|
/* ACS_* is not constant. So, we can't initialize statically. */
|
|
|
|
vga_to_curses['\0'] = ' ';
|
|
|
|
vga_to_curses[0x04] = ACS_DIAMOND;
|
|
|
|
vga_to_curses[0x18] = ACS_UARROW;
|
|
|
|
vga_to_curses[0x19] = ACS_DARROW;
|
2016-10-16 03:53:04 +08:00
|
|
|
vga_to_curses[0x1a] = ACS_RARROW;
|
|
|
|
vga_to_curses[0x1b] = ACS_LARROW;
|
2015-10-19 20:23:46 +08:00
|
|
|
vga_to_curses[0x9c] = ACS_STERLING;
|
|
|
|
vga_to_curses[0xb0] = ACS_BOARD;
|
|
|
|
vga_to_curses[0xb1] = ACS_CKBOARD;
|
|
|
|
vga_to_curses[0xb3] = ACS_VLINE;
|
|
|
|
vga_to_curses[0xb4] = ACS_RTEE;
|
|
|
|
vga_to_curses[0xbf] = ACS_URCORNER;
|
|
|
|
vga_to_curses[0xc0] = ACS_LLCORNER;
|
|
|
|
vga_to_curses[0xc1] = ACS_BTEE;
|
|
|
|
vga_to_curses[0xc2] = ACS_TTEE;
|
|
|
|
vga_to_curses[0xc3] = ACS_LTEE;
|
|
|
|
vga_to_curses[0xc4] = ACS_HLINE;
|
|
|
|
vga_to_curses[0xc5] = ACS_PLUS;
|
|
|
|
vga_to_curses[0xce] = ACS_LANTERN;
|
|
|
|
vga_to_curses[0xd8] = ACS_NEQUAL;
|
|
|
|
vga_to_curses[0xd9] = ACS_LRCORNER;
|
|
|
|
vga_to_curses[0xda] = ACS_ULCORNER;
|
|
|
|
vga_to_curses[0xdb] = ACS_BLOCK;
|
|
|
|
vga_to_curses[0xe3] = ACS_PI;
|
|
|
|
vga_to_curses[0xf1] = ACS_PLMINUS;
|
|
|
|
vga_to_curses[0xf2] = ACS_GEQUAL;
|
|
|
|
vga_to_curses[0xf3] = ACS_LEQUAL;
|
|
|
|
vga_to_curses[0xf8] = ACS_DEGREE;
|
|
|
|
vga_to_curses[0xfe] = ACS_BULLET;
|
2008-02-11 00:33:14 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void curses_keyboard_setup(void)
|
|
|
|
{
|
|
|
|
#if defined(__APPLE__)
|
|
|
|
/* always use generic keymaps */
|
|
|
|
if (!keyboard_layout)
|
|
|
|
keyboard_layout = "en-us";
|
|
|
|
#endif
|
|
|
|
if(keyboard_layout) {
|
2009-03-07 04:27:10 +08:00
|
|
|
kbd_layout = init_keyboard_layout(name2keysym, keyboard_layout);
|
2008-02-11 00:33:14 +08:00
|
|
|
if (!kbd_layout)
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-11-13 21:51:41 +08:00
|
|
|
static const DisplayChangeListenerOps dcl_ops = {
|
|
|
|
.dpy_name = "curses",
|
|
|
|
.dpy_text_update = curses_update,
|
|
|
|
.dpy_text_resize = curses_resize,
|
|
|
|
.dpy_refresh = curses_refresh,
|
|
|
|
.dpy_text_cursor = curses_cursor_position,
|
|
|
|
};
|
|
|
|
|
2018-02-02 19:10:18 +08:00
|
|
|
void curses_display_init(DisplayState *ds, DisplayOptions *opts)
|
2008-02-11 00:33:14 +08:00
|
|
|
{
|
|
|
|
#ifndef _WIN32
|
|
|
|
if (!isatty(1)) {
|
|
|
|
fprintf(stderr, "We need a terminal output\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
curses_setup();
|
|
|
|
curses_keyboard_setup();
|
2010-03-22 03:13:02 +08:00
|
|
|
atexit(curses_atexit);
|
2008-02-11 00:33:14 +08:00
|
|
|
|
2013-11-22 22:35:03 +08:00
|
|
|
curses_winch_init();
|
2008-02-11 00:33:14 +08:00
|
|
|
|
2015-11-04 00:12:03 +08:00
|
|
|
dcl = g_new0(DisplayChangeListener, 1);
|
2012-11-13 21:51:41 +08:00
|
|
|
dcl->ops = &dcl_ops;
|
2013-04-23 21:44:31 +08:00
|
|
|
register_displaychangelistener(dcl);
|
2008-02-11 00:33:14 +08:00
|
|
|
|
|
|
|
invalidate = 1;
|
|
|
|
}
|