* THE SOFTWARE.
*/
#include "qemu/osdep.h"
-#include <curses.h>
#ifndef _WIN32
#include <sys/ioctl.h>
#include "ui/input.h"
#include "sysemu/sysemu.h"
+/* KEY_EVENT is defined in wincon.h and in curses.h. Avoid redefinition. */
+#undef KEY_EVENT
+#include <curses.h>
+#undef KEY_EVENT
+
#define FONT_HEIGHT 16
#define FONT_WIDTH 8
static int width, height, gwidth, gheight, invalidate;
static int px, py, sminx, sminy, smaxx, smaxy;
-chtype vga_to_curses[256];
+static chtype vga_to_curses[256];
static void curses_update(DisplayChangeListener *dcl,
int x, int y, int w, int h)
{
- chtype *line;
-
- line = ((chtype *) screen) + y * width;
- for (h += y; y < h; y ++, line += width)
- mvwaddchnstr(screenpad, y, 0, line, width);
+ console_ch_t *line;
+ chtype curses_line[width];
+
+ 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);
+ }
pnoutrefresh(screenpad, py, px, sminy, sminx, smaxy - 1, smaxx - 1);
refresh();
static void curses_refresh(DisplayChangeListener *dcl)
{
- int chr, nextchr, keysym, keycode, keycode_alt;
+ int chr, keysym, keycode, keycode_alt;
curses_winch_check();
graphic_hw_text_update(NULL, screen);
- nextchr = ERR;
while (1) {
/* while there are any pending key strokes to process */
- if (nextchr == ERR)
- chr = getch();
- else {
- chr = nextchr;
- nextchr = ERR;
- }
+ chr = getch();
if (chr == ERR)
break;
/* alt key */
if (keycode == 1) {
- nextchr = getch();
+ int nextchr = getch();
if (nextchr != ERR) {
chr = nextchr;
keycode_alt = ALT;
- keycode = curses2keycode[nextchr];
- nextchr = ERR;
+ keycode = curses2keycode[chr];
if (keycode != -1) {
keycode |= ALT;
keysym = chr;
}
- keycode = keysym2scancode(kbd_layout, keysym & KEYSYM_MASK);
+ keycode = keysym2scancode(kbd_layout, keysym & KEYSYM_MASK,
+ false, false, false);
if (keycode == 0)
continue;
qemu_input_event_send_key_delay(0);
}
} else {
- keysym = curses2qemu[chr];
+ keysym = -1;
+ if (chr < CURSES_KEYS) {
+ keysym = curses2qemu[chr];
+ }
if (keysym == -1)
keysym = chr;
/* ACS_* is not constant. So, we can't initialize statically. */
vga_to_curses['\0'] = ' ';
vga_to_curses[0x04] = ACS_DIAMOND;
- vga_to_curses[0x0a] = ACS_RARROW;
- vga_to_curses[0x0b] = ACS_LARROW;
vga_to_curses[0x18] = ACS_UARROW;
vga_to_curses[0x19] = ACS_DARROW;
+ vga_to_curses[0x1a] = ACS_RARROW;
+ vga_to_curses[0x1b] = ACS_LARROW;
vga_to_curses[0x9c] = ACS_STERLING;
vga_to_curses[0xb0] = ACS_BOARD;
vga_to_curses[0xb1] = ACS_CKBOARD;
.dpy_text_cursor = curses_cursor_position,
};
-void curses_display_init(DisplayState *ds, int full_screen)
+static void curses_display_init(DisplayState *ds, DisplayOptions *opts)
{
#ifndef _WIN32
if (!isatty(1)) {
invalidate = 1;
}
+
+static QemuDisplay qemu_display_curses = {
+ .type = DISPLAY_TYPE_CURSES,
+ .init = curses_display_init,
+};
+
+static void register_curses(void)
+{
+ qemu_display_register(&qemu_display_curses);
+}
+
+type_init(register_curses);