balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 1 | /* |
| 2 | * QEMU curses/ncurses display driver |
| 3 | * |
| 4 | * Copyright (c) 2005 Andrzej Zaborowski <balrog@zabor.org> |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to deal |
| 8 | * in the Software without restriction, including without limitation the rights |
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | * copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | * THE SOFTWARE. |
| 23 | */ |
Peter Maydell | e16f4c8 | 2016-01-29 17:49:51 +0000 | [diff] [blame] | 24 | #include "qemu/osdep.h" |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 25 | |
| 26 | #ifndef _WIN32 |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 27 | #include <sys/ioctl.h> |
| 28 | #include <termios.h> |
| 29 | #endif |
Samuel Thibault | 2f8b7cd | 2019-03-11 14:51:27 +0100 | [diff] [blame] | 30 | #include <locale.h> |
| 31 | #include <wchar.h> |
| 32 | #include <langinfo.h> |
| 33 | #include <iconv.h> |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 34 | |
Fei Li | ab4f931 | 2018-10-17 10:26:50 +0200 | [diff] [blame] | 35 | #include "qapi/error.h" |
blueswir1 | 511d2b1 | 2009-03-07 15:32:56 +0000 | [diff] [blame] | 36 | #include "qemu-common.h" |
Paolo Bonzini | 28ecbae | 2012-11-28 12:06:30 +0100 | [diff] [blame] | 37 | #include "ui/console.h" |
Gerd Hoffmann | cd10032 | 2013-12-04 13:40:20 +0100 | [diff] [blame] | 38 | #include "ui/input.h" |
Paolo Bonzini | 9c17d61 | 2012-12-17 18:20:04 +0100 | [diff] [blame] | 39 | #include "sysemu/sysemu.h" |
blueswir1 | 511d2b1 | 2009-03-07 15:32:56 +0000 | [diff] [blame] | 40 | |
Gerd Hoffmann | e2f82e9 | 2017-09-27 12:38:11 +0200 | [diff] [blame] | 41 | /* KEY_EVENT is defined in wincon.h and in curses.h. Avoid redefinition. */ |
| 42 | #undef KEY_EVENT |
| 43 | #include <curses.h> |
| 44 | #undef KEY_EVENT |
| 45 | |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 46 | #define FONT_HEIGHT 16 |
| 47 | #define FONT_WIDTH 8 |
| 48 | |
Samuel Thibault | 459a707 | 2019-03-04 22:05:32 +0100 | [diff] [blame] | 49 | enum maybe_keycode { |
| 50 | CURSES_KEYCODE, |
| 51 | CURSES_CHAR, |
| 52 | CURSES_CHAR_OR_KEYCODE, |
| 53 | }; |
| 54 | |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 55 | static DisplayChangeListener *dcl; |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 56 | static console_ch_t screen[160 * 100]; |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 57 | static WINDOW *screenpad = NULL; |
| 58 | static int width, height, gwidth, gheight, invalidate; |
| 59 | static int px, py, sminx, sminy, smaxx, smaxy; |
| 60 | |
Samuel Thibault | 2f8b7cd | 2019-03-11 14:51:27 +0100 | [diff] [blame] | 61 | static const char *font_charset = "CP437"; |
| 62 | static cchar_t vga_to_curses[256]; |
OGAWA Hirofumi | e2368dc | 2015-10-19 21:23:46 +0900 | [diff] [blame] | 63 | |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 64 | static void curses_update(DisplayChangeListener *dcl, |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 65 | int x, int y, int w, int h) |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 66 | { |
Gerd Hoffmann | e2f82e9 | 2017-09-27 12:38:11 +0200 | [diff] [blame] | 67 | console_ch_t *line; |
Samuel Thibault | 2f8b7cd | 2019-03-11 14:51:27 +0100 | [diff] [blame] | 68 | cchar_t curses_line[width]; |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 69 | |
Gerd Hoffmann | e2f82e9 | 2017-09-27 12:38:11 +0200 | [diff] [blame] | 70 | line = screen + y * width; |
| 71 | for (h += y; y < h; y ++, line += width) { |
| 72 | for (x = 0; x < width; x++) { |
| 73 | chtype ch = line[x] & 0xff; |
| 74 | chtype at = line[x] & ~0xff; |
Samuel Thibault | 2f8b7cd | 2019-03-11 14:51:27 +0100 | [diff] [blame] | 75 | if (vga_to_curses[ch].chars[0]) { |
| 76 | curses_line[x] = vga_to_curses[ch]; |
| 77 | } else { |
| 78 | curses_line[x].chars[0] = ch; |
| 79 | curses_line[x].chars[1] = 0; |
| 80 | curses_line[x].attr = 0; |
Gerd Hoffmann | e2f82e9 | 2017-09-27 12:38:11 +0200 | [diff] [blame] | 81 | } |
Samuel Thibault | 2f8b7cd | 2019-03-11 14:51:27 +0100 | [diff] [blame] | 82 | curses_line[x].attr |= at; |
Gerd Hoffmann | e2f82e9 | 2017-09-27 12:38:11 +0200 | [diff] [blame] | 83 | } |
Samuel Thibault | 2f8b7cd | 2019-03-11 14:51:27 +0100 | [diff] [blame] | 84 | mvwadd_wchnstr(screenpad, y, 0, curses_line, width); |
Gerd Hoffmann | e2f82e9 | 2017-09-27 12:38:11 +0200 | [diff] [blame] | 85 | } |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 86 | |
| 87 | pnoutrefresh(screenpad, py, px, sminy, sminx, smaxy - 1, smaxx - 1); |
| 88 | refresh(); |
| 89 | } |
| 90 | |
| 91 | static void curses_calc_pad(void) |
| 92 | { |
Gerd Hoffmann | 81c0d5a | 2013-03-14 14:27:08 +0100 | [diff] [blame] | 93 | if (qemu_console_is_fixedsize(NULL)) { |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 94 | width = gwidth; |
| 95 | height = gheight; |
| 96 | } else { |
| 97 | width = COLS; |
| 98 | height = LINES; |
| 99 | } |
| 100 | |
| 101 | if (screenpad) |
| 102 | delwin(screenpad); |
| 103 | |
| 104 | clear(); |
| 105 | refresh(); |
| 106 | |
| 107 | screenpad = newpad(height, width); |
| 108 | |
| 109 | if (width > COLS) { |
| 110 | px = (width - COLS) / 2; |
| 111 | sminx = 0; |
| 112 | smaxx = COLS; |
| 113 | } else { |
| 114 | px = 0; |
| 115 | sminx = (COLS - width) / 2; |
| 116 | smaxx = sminx + width; |
| 117 | } |
| 118 | |
| 119 | if (height > LINES) { |
| 120 | py = (height - LINES) / 2; |
| 121 | sminy = 0; |
| 122 | smaxy = LINES; |
| 123 | } else { |
| 124 | py = 0; |
| 125 | sminy = (LINES - height) / 2; |
| 126 | smaxy = sminy + height; |
| 127 | } |
| 128 | } |
| 129 | |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 130 | static void curses_resize(DisplayChangeListener *dcl, |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 131 | int width, int height) |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 132 | { |
Gerd Hoffmann | a93a4a2 | 2012-09-28 15:02:08 +0200 | [diff] [blame] | 133 | if (width == gwidth && height == gheight) { |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 134 | return; |
Gerd Hoffmann | a93a4a2 | 2012-09-28 15:02:08 +0200 | [diff] [blame] | 135 | } |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 136 | |
Gerd Hoffmann | a93a4a2 | 2012-09-28 15:02:08 +0200 | [diff] [blame] | 137 | gwidth = width; |
| 138 | gheight = height; |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 139 | |
| 140 | curses_calc_pad(); |
| 141 | } |
| 142 | |
Gerd Hoffmann | 032ac6f | 2013-11-22 15:35:03 +0100 | [diff] [blame] | 143 | #if !defined(_WIN32) && defined(SIGWINCH) && defined(KEY_RESIZE) |
| 144 | static volatile sig_atomic_t got_sigwinch; |
| 145 | static void curses_winch_check(void) |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 146 | { |
| 147 | struct winsize { |
| 148 | unsigned short ws_row; |
| 149 | unsigned short ws_col; |
| 150 | unsigned short ws_xpixel; /* unused */ |
| 151 | unsigned short ws_ypixel; /* unused */ |
| 152 | } ws; |
| 153 | |
Gerd Hoffmann | 032ac6f | 2013-11-22 15:35:03 +0100 | [diff] [blame] | 154 | if (!got_sigwinch) { |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 155 | return; |
Gerd Hoffmann | 032ac6f | 2013-11-22 15:35:03 +0100 | [diff] [blame] | 156 | } |
| 157 | got_sigwinch = false; |
| 158 | |
| 159 | if (ioctl(1, TIOCGWINSZ, &ws) == -1) { |
| 160 | return; |
| 161 | } |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 162 | |
| 163 | resize_term(ws.ws_row, ws.ws_col); |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 164 | invalidate = 1; |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 165 | } |
Gerd Hoffmann | 032ac6f | 2013-11-22 15:35:03 +0100 | [diff] [blame] | 166 | |
| 167 | static void curses_winch_handler(int signum) |
| 168 | { |
| 169 | got_sigwinch = true; |
| 170 | } |
| 171 | |
| 172 | static void curses_winch_init(void) |
| 173 | { |
| 174 | struct sigaction old, winch = { |
| 175 | .sa_handler = curses_winch_handler, |
| 176 | }; |
| 177 | sigaction(SIGWINCH, &winch, &old); |
| 178 | } |
| 179 | #else |
| 180 | static void curses_winch_check(void) {} |
| 181 | static void curses_winch_init(void) {} |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 182 | #endif |
| 183 | |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 184 | static void curses_cursor_position(DisplayChangeListener *dcl, |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 185 | int x, int y) |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 186 | { |
| 187 | if (x >= 0) { |
| 188 | x = sminx + x - px; |
| 189 | y = sminy + y - py; |
| 190 | |
| 191 | if (x >= 0 && y >= 0 && x < COLS && y < LINES) { |
| 192 | move(y, x); |
| 193 | curs_set(1); |
| 194 | /* it seems that curs_set(1) must always be called before |
| 195 | * curs_set(2) for the latter to have effect */ |
Gerd Hoffmann | 81c0d5a | 2013-03-14 14:27:08 +0100 | [diff] [blame] | 196 | if (!qemu_console_is_graphic(NULL)) { |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 197 | curs_set(2); |
Gerd Hoffmann | 81c0d5a | 2013-03-14 14:27:08 +0100 | [diff] [blame] | 198 | } |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 199 | return; |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | curs_set(0); |
| 204 | } |
| 205 | |
| 206 | /* generic keyboard conversion */ |
| 207 | |
| 208 | #include "curses_keys.h" |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 209 | |
Anthony Liguori | c227f09 | 2009-10-01 16:12:16 -0500 | [diff] [blame] | 210 | static kbd_layout_t *kbd_layout = NULL; |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 211 | |
Samuel Thibault | 459a707 | 2019-03-04 22:05:32 +0100 | [diff] [blame] | 212 | static wint_t console_getch(enum maybe_keycode *maybe_keycode) |
| 213 | { |
| 214 | wint_t ret; |
| 215 | switch (get_wch(&ret)) { |
| 216 | case KEY_CODE_YES: |
| 217 | *maybe_keycode = CURSES_KEYCODE; |
| 218 | break; |
| 219 | case OK: |
| 220 | *maybe_keycode = CURSES_CHAR; |
| 221 | break; |
| 222 | case ERR: |
| 223 | ret = -1; |
| 224 | break; |
| 225 | } |
| 226 | return ret; |
| 227 | } |
| 228 | |
| 229 | static int curses2foo(const int _curses2foo[], const int _curseskey2foo[], |
| 230 | int chr, enum maybe_keycode maybe_keycode) |
| 231 | { |
| 232 | int ret = -1; |
| 233 | if (maybe_keycode == CURSES_CHAR) { |
| 234 | if (chr < CURSES_CHARS) { |
| 235 | ret = _curses2foo[chr]; |
| 236 | } |
| 237 | } else { |
| 238 | if (chr < CURSES_KEYS) { |
| 239 | ret = _curseskey2foo[chr]; |
| 240 | } |
| 241 | if (ret == -1 && maybe_keycode == CURSES_CHAR_OR_KEYCODE && |
| 242 | chr < CURSES_CHARS) { |
| 243 | ret = _curses2foo[chr]; |
| 244 | } |
| 245 | } |
| 246 | return ret; |
| 247 | } |
| 248 | |
| 249 | #define curses2keycode(chr, maybe_keycode) \ |
| 250 | curses2foo(_curses2keycode, _curseskey2keycode, chr, maybe_keycode) |
| 251 | #define curses2keysym(chr, maybe_keycode) \ |
| 252 | curses2foo(_curses2keysym, _curseskey2keysym, chr, maybe_keycode) |
| 253 | #define curses2qemu(chr, maybe_keycode) \ |
| 254 | curses2foo(_curses2qemu, _curseskey2qemu, chr, maybe_keycode) |
| 255 | |
Gerd Hoffmann | bc2ed97 | 2013-03-01 13:03:04 +0100 | [diff] [blame] | 256 | static void curses_refresh(DisplayChangeListener *dcl) |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 257 | { |
Peter Maydell | 99a9ef4 | 2016-08-11 15:23:27 +0100 | [diff] [blame] | 258 | int chr, keysym, keycode, keycode_alt; |
Samuel Thibault | 459a707 | 2019-03-04 22:05:32 +0100 | [diff] [blame] | 259 | enum maybe_keycode maybe_keycode; |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 260 | |
Gerd Hoffmann | 032ac6f | 2013-11-22 15:35:03 +0100 | [diff] [blame] | 261 | curses_winch_check(); |
| 262 | |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 263 | if (invalidate) { |
| 264 | clear(); |
| 265 | refresh(); |
| 266 | curses_calc_pad(); |
Gerd Hoffmann | 1dbfa00 | 2013-03-12 13:44:38 +0100 | [diff] [blame] | 267 | graphic_hw_invalidate(NULL); |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 268 | invalidate = 0; |
| 269 | } |
| 270 | |
Gerd Hoffmann | 1dbfa00 | 2013-03-12 13:44:38 +0100 | [diff] [blame] | 271 | graphic_hw_text_update(NULL, screen); |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 272 | |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 273 | while (1) { |
| 274 | /* while there are any pending key strokes to process */ |
Samuel Thibault | 459a707 | 2019-03-04 22:05:32 +0100 | [diff] [blame] | 275 | chr = console_getch(&maybe_keycode); |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 276 | |
Samuel Thibault | 459a707 | 2019-03-04 22:05:32 +0100 | [diff] [blame] | 277 | if (chr == -1) |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 278 | break; |
| 279 | |
balrog | b1314cf | 2008-02-22 18:21:28 +0000 | [diff] [blame] | 280 | #ifdef KEY_RESIZE |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 281 | /* this shouldn't occur when we use a custom SIGWINCH handler */ |
Samuel Thibault | 459a707 | 2019-03-04 22:05:32 +0100 | [diff] [blame] | 282 | if (maybe_keycode != CURSES_CHAR && chr == KEY_RESIZE) { |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 283 | clear(); |
| 284 | refresh(); |
| 285 | curses_calc_pad(); |
Gerd Hoffmann | bc2ed97 | 2013-03-01 13:03:04 +0100 | [diff] [blame] | 286 | curses_update(dcl, 0, 0, width, height); |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 287 | continue; |
| 288 | } |
balrog | b1314cf | 2008-02-22 18:21:28 +0000 | [diff] [blame] | 289 | #endif |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 290 | |
Samuel Thibault | 459a707 | 2019-03-04 22:05:32 +0100 | [diff] [blame] | 291 | keycode = curses2keycode(chr, maybe_keycode); |
Samuel Thibault | 44bb61c | 2010-02-28 21:03:00 +0100 | [diff] [blame] | 292 | keycode_alt = 0; |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 293 | |
Samuel Thibault | 633786f | 2019-03-03 18:25:57 +0100 | [diff] [blame] | 294 | /* alt or esc key */ |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 295 | if (keycode == 1) { |
Samuel Thibault | 459a707 | 2019-03-04 22:05:32 +0100 | [diff] [blame] | 296 | enum maybe_keycode next_maybe_keycode; |
| 297 | int nextchr = console_getch(&next_maybe_keycode); |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 298 | |
Samuel Thibault | 459a707 | 2019-03-04 22:05:32 +0100 | [diff] [blame] | 299 | if (nextchr != -1) { |
Samuel Thibault | 44bb61c | 2010-02-28 21:03:00 +0100 | [diff] [blame] | 300 | chr = nextchr; |
Samuel Thibault | 459a707 | 2019-03-04 22:05:32 +0100 | [diff] [blame] | 301 | maybe_keycode = next_maybe_keycode; |
Samuel Thibault | 44bb61c | 2010-02-28 21:03:00 +0100 | [diff] [blame] | 302 | keycode_alt = ALT; |
Samuel Thibault | 459a707 | 2019-03-04 22:05:32 +0100 | [diff] [blame] | 303 | keycode = curses2keycode(chr, maybe_keycode); |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 304 | |
Samuel Thibault | 44bb61c | 2010-02-28 21:03:00 +0100 | [diff] [blame] | 305 | if (keycode != -1) { |
| 306 | keycode |= ALT; |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 307 | |
Samuel Thibault | 44bb61c | 2010-02-28 21:03:00 +0100 | [diff] [blame] | 308 | /* process keys reserved for qemu */ |
| 309 | if (keycode >= QEMU_KEY_CONSOLE0 && |
| 310 | keycode < QEMU_KEY_CONSOLE0 + 9) { |
| 311 | erase(); |
| 312 | wnoutrefresh(stdscr); |
| 313 | console_select(keycode - QEMU_KEY_CONSOLE0); |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 314 | |
Samuel Thibault | 44bb61c | 2010-02-28 21:03:00 +0100 | [diff] [blame] | 315 | invalidate = 1; |
| 316 | continue; |
| 317 | } |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 318 | } |
| 319 | } |
| 320 | } |
| 321 | |
Samuel Thibault | 44bb61c | 2010-02-28 21:03:00 +0100 | [diff] [blame] | 322 | if (kbd_layout) { |
Samuel Thibault | 459a707 | 2019-03-04 22:05:32 +0100 | [diff] [blame] | 323 | keysym = curses2keysym(chr, maybe_keycode); |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 324 | |
Samuel Thibault | 44bb61c | 2010-02-28 21:03:00 +0100 | [diff] [blame] | 325 | if (keysym == -1) { |
Samuel Thibault | d03703c | 2010-10-19 19:48:20 +0200 | [diff] [blame] | 326 | if (chr < ' ') { |
| 327 | keysym = chr + '@'; |
| 328 | if (keysym >= 'A' && keysym <= 'Z') |
| 329 | keysym += 'a' - 'A'; |
| 330 | keysym |= KEYSYM_CNTRL; |
| 331 | } else |
Samuel Thibault | 44bb61c | 2010-02-28 21:03:00 +0100 | [diff] [blame] | 332 | keysym = chr; |
| 333 | } |
| 334 | |
Gerd Hoffmann | abb4f2c | 2018-02-22 08:05:13 +0100 | [diff] [blame] | 335 | keycode = keysym2scancode(kbd_layout, keysym & KEYSYM_MASK, |
Gerd Hoffmann | 19c1b9f | 2019-01-22 10:28:14 +0100 | [diff] [blame] | 336 | NULL, false); |
Samuel Thibault | 44bb61c | 2010-02-28 21:03:00 +0100 | [diff] [blame] | 337 | if (keycode == 0) |
| 338 | continue; |
| 339 | |
| 340 | keycode |= (keysym & ~KEYSYM_MASK) >> 16; |
| 341 | keycode |= keycode_alt; |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 342 | } |
| 343 | |
Samuel Thibault | 44bb61c | 2010-02-28 21:03:00 +0100 | [diff] [blame] | 344 | if (keycode == -1) |
| 345 | continue; |
| 346 | |
Gerd Hoffmann | 81c0d5a | 2013-03-14 14:27:08 +0100 | [diff] [blame] | 347 | if (qemu_console_is_graphic(NULL)) { |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 348 | /* since terminals don't know about key press and release |
| 349 | * events, we need to emit both for each key received */ |
Gerd Hoffmann | cd10032 | 2013-12-04 13:40:20 +0100 | [diff] [blame] | 350 | if (keycode & SHIFT) { |
| 351 | qemu_input_event_send_key_number(NULL, SHIFT_CODE, true); |
Gerd Hoffmann | 5a16566 | 2014-05-28 13:05:04 +0200 | [diff] [blame] | 352 | qemu_input_event_send_key_delay(0); |
Samuel Thibault | 44bb61c | 2010-02-28 21:03:00 +0100 | [diff] [blame] | 353 | } |
Gerd Hoffmann | cd10032 | 2013-12-04 13:40:20 +0100 | [diff] [blame] | 354 | if (keycode & CNTRL) { |
| 355 | qemu_input_event_send_key_number(NULL, CNTRL_CODE, true); |
Gerd Hoffmann | 5a16566 | 2014-05-28 13:05:04 +0200 | [diff] [blame] | 356 | qemu_input_event_send_key_delay(0); |
Samuel Thibault | 44bb61c | 2010-02-28 21:03:00 +0100 | [diff] [blame] | 357 | } |
Gerd Hoffmann | cd10032 | 2013-12-04 13:40:20 +0100 | [diff] [blame] | 358 | if (keycode & ALT) { |
| 359 | qemu_input_event_send_key_number(NULL, ALT_CODE, true); |
Gerd Hoffmann | 5a16566 | 2014-05-28 13:05:04 +0200 | [diff] [blame] | 360 | qemu_input_event_send_key_delay(0); |
Gerd Hoffmann | cd10032 | 2013-12-04 13:40:20 +0100 | [diff] [blame] | 361 | } |
| 362 | if (keycode & ALTGR) { |
| 363 | qemu_input_event_send_key_number(NULL, GREY | ALT_CODE, true); |
Gerd Hoffmann | 5a16566 | 2014-05-28 13:05:04 +0200 | [diff] [blame] | 364 | qemu_input_event_send_key_delay(0); |
Gerd Hoffmann | cd10032 | 2013-12-04 13:40:20 +0100 | [diff] [blame] | 365 | } |
| 366 | |
Andrew Oates | f5c0ab1 | 2014-05-23 20:16:09 -0400 | [diff] [blame] | 367 | qemu_input_event_send_key_number(NULL, keycode & KEY_MASK, true); |
Gerd Hoffmann | 5a16566 | 2014-05-28 13:05:04 +0200 | [diff] [blame] | 368 | qemu_input_event_send_key_delay(0); |
Andrew Oates | f5c0ab1 | 2014-05-23 20:16:09 -0400 | [diff] [blame] | 369 | qemu_input_event_send_key_number(NULL, keycode & KEY_MASK, false); |
Gerd Hoffmann | 5a16566 | 2014-05-28 13:05:04 +0200 | [diff] [blame] | 370 | qemu_input_event_send_key_delay(0); |
Gerd Hoffmann | cd10032 | 2013-12-04 13:40:20 +0100 | [diff] [blame] | 371 | |
| 372 | if (keycode & ALTGR) { |
| 373 | qemu_input_event_send_key_number(NULL, GREY | ALT_CODE, false); |
Gerd Hoffmann | 5a16566 | 2014-05-28 13:05:04 +0200 | [diff] [blame] | 374 | qemu_input_event_send_key_delay(0); |
Gerd Hoffmann | cd10032 | 2013-12-04 13:40:20 +0100 | [diff] [blame] | 375 | } |
| 376 | if (keycode & ALT) { |
| 377 | qemu_input_event_send_key_number(NULL, ALT_CODE, false); |
Gerd Hoffmann | 5a16566 | 2014-05-28 13:05:04 +0200 | [diff] [blame] | 378 | qemu_input_event_send_key_delay(0); |
Gerd Hoffmann | cd10032 | 2013-12-04 13:40:20 +0100 | [diff] [blame] | 379 | } |
| 380 | if (keycode & CNTRL) { |
| 381 | qemu_input_event_send_key_number(NULL, CNTRL_CODE, false); |
Gerd Hoffmann | 5a16566 | 2014-05-28 13:05:04 +0200 | [diff] [blame] | 382 | qemu_input_event_send_key_delay(0); |
Gerd Hoffmann | cd10032 | 2013-12-04 13:40:20 +0100 | [diff] [blame] | 383 | } |
| 384 | if (keycode & SHIFT) { |
| 385 | qemu_input_event_send_key_number(NULL, SHIFT_CODE, false); |
Gerd Hoffmann | 5a16566 | 2014-05-28 13:05:04 +0200 | [diff] [blame] | 386 | qemu_input_event_send_key_delay(0); |
Gerd Hoffmann | cd10032 | 2013-12-04 13:40:20 +0100 | [diff] [blame] | 387 | } |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 388 | } else { |
Samuel Thibault | 459a707 | 2019-03-04 22:05:32 +0100 | [diff] [blame] | 389 | keysym = curses2qemu(chr, maybe_keycode); |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 390 | if (keysym == -1) |
| 391 | keysym = chr; |
| 392 | |
| 393 | kbd_put_keysym(keysym); |
| 394 | } |
| 395 | } |
| 396 | } |
| 397 | |
Blue Swirl | aaf12c2 | 2010-03-21 19:44:06 +0000 | [diff] [blame] | 398 | static void curses_atexit(void) |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 399 | { |
| 400 | endwin(); |
| 401 | } |
| 402 | |
Samuel Thibault | 2f8b7cd | 2019-03-11 14:51:27 +0100 | [diff] [blame] | 403 | /* Setup wchar glyph for one UCS-2 char */ |
| 404 | static void convert_ucs(int glyph, uint16_t ch, iconv_t conv) |
| 405 | { |
| 406 | wchar_t wch; |
| 407 | char *pch, *pwch; |
| 408 | size_t sch, swch; |
| 409 | |
| 410 | pch = (char *) &ch; |
| 411 | pwch = (char *) &wch; |
| 412 | sch = sizeof(ch); |
| 413 | swch = sizeof(wch); |
| 414 | |
| 415 | if (iconv(conv, &pch, &sch, &pwch, &swch) == (size_t) -1) { |
| 416 | fprintf(stderr, "Could not convert 0x%04x from UCS-2 to WCHAR_T: %s\n", |
| 417 | ch, strerror(errno)); |
| 418 | } else { |
| 419 | vga_to_curses[glyph].chars[0] = wch; |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | /* Setup wchar glyph for one font character */ |
| 424 | static void convert_font(unsigned char ch, iconv_t conv) |
| 425 | { |
| 426 | wchar_t wch; |
| 427 | char *pch, *pwch; |
| 428 | size_t sch, swch; |
| 429 | |
| 430 | pch = (char *) &ch; |
| 431 | pwch = (char *) &wch; |
| 432 | sch = sizeof(ch); |
| 433 | swch = sizeof(wch); |
| 434 | |
| 435 | if (iconv(conv, &pch, &sch, &pwch, &swch) == (size_t) -1) { |
| 436 | fprintf(stderr, "Could not convert 0x%02x from %s to WCHAR_T: %s\n", |
| 437 | ch, font_charset, strerror(errno)); |
| 438 | } else { |
| 439 | vga_to_curses[ch].chars[0] = wch; |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | /* Convert one wchar to UCS-2 */ |
| 444 | static uint16_t get_ucs(wchar_t wch, iconv_t conv) |
| 445 | { |
| 446 | uint16_t ch; |
| 447 | char *pch, *pwch; |
| 448 | size_t sch, swch; |
| 449 | |
| 450 | pch = (char *) &ch; |
| 451 | pwch = (char *) &wch; |
| 452 | sch = sizeof(ch); |
| 453 | swch = sizeof(wch); |
| 454 | |
| 455 | if (iconv(conv, &pwch, &swch, &pch, &sch) == (size_t) -1) { |
| 456 | fprintf(stderr, "Could not convert 0x%02x from WCHAR_T to UCS-2: %s\n", |
| 457 | wch, strerror(errno)); |
| 458 | return 0xFFFD; |
| 459 | } |
| 460 | |
| 461 | return ch; |
| 462 | } |
| 463 | |
| 464 | /* |
| 465 | * Setup mapping for vga to curses line graphics. |
| 466 | */ |
| 467 | static void font_setup(void) |
| 468 | { |
| 469 | /* |
| 470 | * Control characters are normally non-printable, but VGA does have |
| 471 | * well-known glyphs for them. |
| 472 | */ |
| 473 | static uint16_t control_characters[0x20] = { |
| 474 | 0x0020, |
| 475 | 0x263a, |
| 476 | 0x263b, |
| 477 | 0x2665, |
| 478 | 0x2666, |
| 479 | 0x2663, |
| 480 | 0x2660, |
| 481 | 0x2022, |
| 482 | 0x25d8, |
| 483 | 0x25cb, |
| 484 | 0x25d9, |
| 485 | 0x2642, |
| 486 | 0x2640, |
| 487 | 0x266a, |
| 488 | 0x266b, |
| 489 | 0x263c, |
| 490 | 0x25ba, |
| 491 | 0x25c4, |
| 492 | 0x2195, |
| 493 | 0x203c, |
| 494 | 0x00b6, |
| 495 | 0x00a7, |
| 496 | 0x25ac, |
| 497 | 0x21a8, |
| 498 | 0x2191, |
| 499 | 0x2193, |
| 500 | 0x2192, |
| 501 | 0x2190, |
| 502 | 0x221f, |
| 503 | 0x2194, |
| 504 | 0x25b2, |
| 505 | 0x25bc |
| 506 | }; |
| 507 | |
| 508 | iconv_t ucs_to_wchar_conv; |
| 509 | iconv_t wchar_to_ucs_conv; |
| 510 | iconv_t font_conv; |
| 511 | int i; |
| 512 | |
| 513 | ucs_to_wchar_conv = iconv_open("WCHAR_T", "UCS-2"); |
| 514 | if (ucs_to_wchar_conv == (iconv_t) -1) { |
| 515 | fprintf(stderr, "Could not convert font glyphs from UCS-2: '%s'\n", |
| 516 | strerror(errno)); |
| 517 | exit(1); |
| 518 | } |
| 519 | |
| 520 | wchar_to_ucs_conv = iconv_open("UCS-2", "WCHAR_T"); |
| 521 | if (wchar_to_ucs_conv == (iconv_t) -1) { |
| 522 | fprintf(stderr, "Could not convert font glyphs to UCS-2: '%s'\n", |
| 523 | strerror(errno)); |
| 524 | exit(1); |
| 525 | } |
| 526 | |
| 527 | font_conv = iconv_open("WCHAR_T", font_charset); |
| 528 | if (font_conv == (iconv_t) -1) { |
| 529 | fprintf(stderr, "Could not convert font glyphs from %s: '%s'\n", |
| 530 | font_charset, strerror(errno)); |
| 531 | exit(1); |
| 532 | } |
| 533 | |
| 534 | /* Control characters */ |
| 535 | for (i = 0; i <= 0x1F; i++) { |
| 536 | convert_ucs(i, control_characters[i], ucs_to_wchar_conv); |
| 537 | } |
| 538 | |
| 539 | for (i = 0x20; i <= 0xFF; i++) { |
| 540 | convert_font(i, font_conv); |
| 541 | } |
| 542 | |
| 543 | /* DEL */ |
| 544 | convert_ucs(0x7F, 0x2302, ucs_to_wchar_conv); |
| 545 | |
| 546 | if (strcmp(nl_langinfo(CODESET), "UTF-8")) { |
| 547 | /* Non-Unicode capable, use termcap equivalents for those available */ |
| 548 | for (i = 0; i <= 0xFF; i++) { |
| 549 | switch (get_ucs(vga_to_curses[i].chars[0], wchar_to_ucs_conv)) { |
| 550 | case 0x00a3: |
| 551 | vga_to_curses[i] = *WACS_STERLING; |
| 552 | break; |
| 553 | case 0x2591: |
| 554 | vga_to_curses[i] = *WACS_BOARD; |
| 555 | break; |
| 556 | case 0x2592: |
| 557 | vga_to_curses[i] = *WACS_CKBOARD; |
| 558 | break; |
| 559 | case 0x2502: |
| 560 | vga_to_curses[i] = *WACS_VLINE; |
| 561 | break; |
| 562 | case 0x2524: |
| 563 | vga_to_curses[i] = *WACS_RTEE; |
| 564 | break; |
| 565 | case 0x2510: |
| 566 | vga_to_curses[i] = *WACS_URCORNER; |
| 567 | break; |
| 568 | case 0x2514: |
| 569 | vga_to_curses[i] = *WACS_LLCORNER; |
| 570 | break; |
| 571 | case 0x2534: |
| 572 | vga_to_curses[i] = *WACS_BTEE; |
| 573 | break; |
| 574 | case 0x252c: |
| 575 | vga_to_curses[i] = *WACS_TTEE; |
| 576 | break; |
| 577 | case 0x251c: |
| 578 | vga_to_curses[i] = *WACS_LTEE; |
| 579 | break; |
| 580 | case 0x2500: |
| 581 | vga_to_curses[i] = *WACS_HLINE; |
| 582 | break; |
| 583 | case 0x253c: |
| 584 | vga_to_curses[i] = *WACS_PLUS; |
| 585 | break; |
| 586 | case 0x256c: |
| 587 | vga_to_curses[i] = *WACS_LANTERN; |
| 588 | break; |
| 589 | case 0x256a: |
| 590 | vga_to_curses[i] = *WACS_NEQUAL; |
| 591 | break; |
| 592 | case 0x2518: |
| 593 | vga_to_curses[i] = *WACS_LRCORNER; |
| 594 | break; |
| 595 | case 0x250c: |
| 596 | vga_to_curses[i] = *WACS_ULCORNER; |
| 597 | break; |
| 598 | case 0x2588: |
| 599 | vga_to_curses[i] = *WACS_BLOCK; |
| 600 | break; |
| 601 | case 0x03c0: |
| 602 | vga_to_curses[i] = *WACS_PI; |
| 603 | break; |
| 604 | case 0x00b1: |
| 605 | vga_to_curses[i] = *WACS_PLMINUS; |
| 606 | break; |
| 607 | case 0x2265: |
| 608 | vga_to_curses[i] = *WACS_GEQUAL; |
| 609 | break; |
| 610 | case 0x2264: |
| 611 | vga_to_curses[i] = *WACS_LEQUAL; |
| 612 | break; |
| 613 | case 0x00b0: |
| 614 | vga_to_curses[i] = *WACS_DEGREE; |
| 615 | break; |
| 616 | case 0x25a0: |
| 617 | vga_to_curses[i] = *WACS_BULLET; |
| 618 | break; |
| 619 | case 0x2666: |
| 620 | vga_to_curses[i] = *WACS_DIAMOND; |
| 621 | break; |
| 622 | case 0x2192: |
| 623 | vga_to_curses[i] = *WACS_RARROW; |
| 624 | break; |
| 625 | case 0x2190: |
| 626 | vga_to_curses[i] = *WACS_LARROW; |
| 627 | break; |
| 628 | case 0x2191: |
| 629 | vga_to_curses[i] = *WACS_UARROW; |
| 630 | break; |
| 631 | case 0x2193: |
| 632 | vga_to_curses[i] = *WACS_DARROW; |
| 633 | break; |
| 634 | case 0x23ba: |
| 635 | vga_to_curses[i] = *WACS_S1; |
| 636 | break; |
| 637 | case 0x23bb: |
| 638 | vga_to_curses[i] = *WACS_S3; |
| 639 | break; |
| 640 | case 0x23bc: |
| 641 | vga_to_curses[i] = *WACS_S7; |
| 642 | break; |
| 643 | case 0x23bd: |
| 644 | vga_to_curses[i] = *WACS_S9; |
| 645 | break; |
| 646 | } |
| 647 | } |
| 648 | } |
| 649 | } |
| 650 | |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 651 | static void curses_setup(void) |
| 652 | { |
| 653 | int i, colour_default[8] = { |
OGAWA Hirofumi | 4083733 | 2015-11-29 22:28:24 +0900 | [diff] [blame] | 654 | [QEMU_COLOR_BLACK] = COLOR_BLACK, |
| 655 | [QEMU_COLOR_BLUE] = COLOR_BLUE, |
| 656 | [QEMU_COLOR_GREEN] = COLOR_GREEN, |
| 657 | [QEMU_COLOR_CYAN] = COLOR_CYAN, |
| 658 | [QEMU_COLOR_RED] = COLOR_RED, |
| 659 | [QEMU_COLOR_MAGENTA] = COLOR_MAGENTA, |
| 660 | [QEMU_COLOR_YELLOW] = COLOR_YELLOW, |
| 661 | [QEMU_COLOR_WHITE] = COLOR_WHITE, |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 662 | }; |
| 663 | |
| 664 | /* input as raw as possible, let everything be interpreted |
| 665 | * by the guest system */ |
| 666 | initscr(); noecho(); intrflush(stdscr, FALSE); |
| 667 | nodelay(stdscr, TRUE); nonl(); keypad(stdscr, TRUE); |
| 668 | start_color(); raw(); scrollok(stdscr, FALSE); |
Samuel Thibault | 633786f | 2019-03-03 18:25:57 +0100 | [diff] [blame] | 669 | set_escdelay(25); |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 670 | |
OGAWA Hirofumi | 4083733 | 2015-11-29 22:28:24 +0900 | [diff] [blame] | 671 | /* Make color pair to match color format (3bits bg:3bits fg) */ |
OGAWA Hirofumi | 615220d | 2015-10-19 21:23:10 +0900 | [diff] [blame] | 672 | for (i = 0; i < 64; i++) { |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 673 | init_pair(i, colour_default[i & 7], colour_default[i >> 3]); |
OGAWA Hirofumi | 615220d | 2015-10-19 21:23:10 +0900 | [diff] [blame] | 674 | } |
OGAWA Hirofumi | 4083733 | 2015-11-29 22:28:24 +0900 | [diff] [blame] | 675 | /* Set default color for more than 64 for safety. */ |
OGAWA Hirofumi | 615220d | 2015-10-19 21:23:10 +0900 | [diff] [blame] | 676 | for (i = 64; i < COLOR_PAIRS; i++) { |
| 677 | init_pair(i, COLOR_WHITE, COLOR_BLACK); |
| 678 | } |
OGAWA Hirofumi | e2368dc | 2015-10-19 21:23:46 +0900 | [diff] [blame] | 679 | |
Samuel Thibault | 2f8b7cd | 2019-03-11 14:51:27 +0100 | [diff] [blame] | 680 | font_setup(); |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 681 | } |
| 682 | |
| 683 | static void curses_keyboard_setup(void) |
| 684 | { |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 685 | #if defined(__APPLE__) |
| 686 | /* always use generic keymaps */ |
| 687 | if (!keyboard_layout) |
| 688 | keyboard_layout = "en-us"; |
| 689 | #endif |
| 690 | if(keyboard_layout) { |
Fei Li | ab4f931 | 2018-10-17 10:26:50 +0200 | [diff] [blame] | 691 | kbd_layout = init_keyboard_layout(name2keysym, keyboard_layout, |
| 692 | &error_fatal); |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 693 | } |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 694 | } |
| 695 | |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 696 | static const DisplayChangeListenerOps dcl_ops = { |
| 697 | .dpy_name = "curses", |
| 698 | .dpy_text_update = curses_update, |
| 699 | .dpy_text_resize = curses_resize, |
| 700 | .dpy_refresh = curses_refresh, |
| 701 | .dpy_text_cursor = curses_cursor_position, |
| 702 | }; |
| 703 | |
Gerd Hoffmann | b076661 | 2018-03-01 11:05:38 +0100 | [diff] [blame] | 704 | static void curses_display_init(DisplayState *ds, DisplayOptions *opts) |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 705 | { |
| 706 | #ifndef _WIN32 |
| 707 | if (!isatty(1)) { |
| 708 | fprintf(stderr, "We need a terminal output\n"); |
| 709 | exit(1); |
| 710 | } |
| 711 | #endif |
| 712 | |
Samuel Thibault | 2f8b7cd | 2019-03-11 14:51:27 +0100 | [diff] [blame] | 713 | setlocale(LC_CTYPE, ""); |
| 714 | if (opts->u.curses.charset) { |
| 715 | font_charset = opts->u.curses.charset; |
| 716 | } |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 717 | curses_setup(); |
| 718 | curses_keyboard_setup(); |
Anthony Liguori | 2869548 | 2010-03-21 14:13:02 -0500 | [diff] [blame] | 719 | atexit(curses_atexit); |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 720 | |
Gerd Hoffmann | 032ac6f | 2013-11-22 15:35:03 +0100 | [diff] [blame] | 721 | curses_winch_init(); |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 722 | |
Markus Armbruster | fedf0d3 | 2015-11-03 17:12:03 +0100 | [diff] [blame] | 723 | dcl = g_new0(DisplayChangeListener, 1); |
Gerd Hoffmann | 7c20b4a | 2012-11-13 14:51:41 +0100 | [diff] [blame] | 724 | dcl->ops = &dcl_ops; |
Gerd Hoffmann | 5209089 | 2013-04-23 15:44:31 +0200 | [diff] [blame] | 725 | register_displaychangelistener(dcl); |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 726 | |
| 727 | invalidate = 1; |
balrog | 4d3b6f6 | 2008-02-10 16:33:14 +0000 | [diff] [blame] | 728 | } |
Gerd Hoffmann | b076661 | 2018-03-01 11:05:38 +0100 | [diff] [blame] | 729 | |
| 730 | static QemuDisplay qemu_display_curses = { |
| 731 | .type = DISPLAY_TYPE_CURSES, |
| 732 | .init = curses_display_init, |
| 733 | }; |
| 734 | |
| 735 | static void register_curses(void) |
| 736 | { |
| 737 | qemu_display_register(&qemu_display_curses); |
| 738 | } |
| 739 | |
| 740 | type_init(register_curses); |