Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 The Chromium OS Authors. All rights reserved. |
| 3 | * Use of this source code is governed by a BSD-style license that can be |
| 4 | * found in the LICENSE file. |
| 5 | */ |
| 6 | |
| 7 | #include <ctype.h> |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 8 | #include <fcntl.h> |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 9 | #include <libtsm.h> |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 10 | #include <stdio.h> |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 11 | #include <stdlib.h> |
Dominik Behr | 9389945 | 2014-08-18 22:16:21 -0700 | [diff] [blame] | 12 | #include <sys/select.h> |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 13 | #include <sys/stat.h> |
David Sodman | bf3f284 | 2014-11-12 08:26:58 -0800 | [diff] [blame] | 14 | #include <sys/types.h> |
| 15 | #include <sys/wait.h> |
Dominik Behr | 32680e3 | 2016-08-16 12:18:41 -0700 | [diff] [blame] | 16 | #include <unistd.h> |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 17 | |
Dominik Behr | 83864df | 2016-04-21 12:35:08 -0700 | [diff] [blame] | 18 | #include "dbus.h" |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 19 | #include "fb.h" |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 20 | #include "font.h" |
Dominik Behr | d253090 | 2016-05-05 14:01:06 -0700 | [diff] [blame] | 21 | #include "image.h" |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 22 | #include "input.h" |
Dominik Behr | 83864df | 2016-04-21 12:35:08 -0700 | [diff] [blame] | 23 | #include "main.h" |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 24 | #include "shl_pty.h" |
| 25 | #include "term.h" |
| 26 | #include "util.h" |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 27 | |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 28 | unsigned int term_num_terminals = 4; |
| 29 | static terminal_t* terminals[TERM_MAX_TERMINALS]; |
Dominik Behr | 4defb36 | 2016-01-13 12:36:14 -0800 | [diff] [blame] | 30 | static uint32_t current_terminal = 0; |
Stéphane Marchesin | 08c08e7 | 2016-01-07 16:44:08 -0800 | [diff] [blame] | 31 | |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 32 | struct term { |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 33 | struct tsm_screen* screen; |
| 34 | struct tsm_vte* vte; |
| 35 | struct shl_pty* pty; |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 36 | int pty_bridge; |
| 37 | int pid; |
| 38 | tsm_age_t age; |
Dominik Behr | bb728f3 | 2019-09-03 17:52:13 -0700 | [diff] [blame] | 39 | int w_in_char, h_in_char; |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 40 | }; |
| 41 | |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 42 | struct _terminal_t { |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 43 | unsigned vt; |
| 44 | bool active; |
Dominik Behr | da55e6c | 2017-02-28 18:12:10 -0800 | [diff] [blame] | 45 | bool input_enable; |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 46 | uint32_t background; |
| 47 | bool background_valid; |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 48 | fb_t* fb; |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 49 | struct term* term; |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 50 | char** exec; |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 51 | }; |
| 52 | |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 53 | |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 54 | static char* interactive_cmd_line[] = { |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 55 | "/sbin/agetty", |
| 56 | "-", |
| 57 | "9600", |
| 58 | "xterm", |
| 59 | NULL |
| 60 | }; |
| 61 | |
Dominik Behr | 83864df | 2016-04-21 12:35:08 -0700 | [diff] [blame] | 62 | static bool in_background = false; |
| 63 | static bool hotplug_occured = false; |
| 64 | |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 65 | |
| 66 | static void __attribute__ ((noreturn)) term_run_child(terminal_t* terminal) |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 67 | { |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 68 | /* XXX figure out how to fix "top" for xterm-256color */ |
| 69 | setenv("TERM", "xterm", 1); |
Dominik Behr | 32680e3 | 2016-08-16 12:18:41 -0700 | [diff] [blame] | 70 | if (terminal->exec) { |
| 71 | execve(terminal->exec[0], terminal->exec, environ); |
| 72 | exit(1); |
| 73 | } else { |
| 74 | while (1) |
| 75 | sleep(1000000); |
| 76 | } |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 77 | } |
| 78 | |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 79 | static int term_draw_cell(struct tsm_screen* screen, uint32_t id, |
Stéphane Marchesin | 8fc1352 | 2015-12-14 17:02:28 -0800 | [diff] [blame] | 80 | const uint32_t* ch, size_t len, |
| 81 | unsigned int cwidth, unsigned int posx, |
| 82 | unsigned int posy, |
| 83 | const struct tsm_screen_attr* attr, |
| 84 | tsm_age_t age, void* data) |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 85 | { |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 86 | terminal_t* terminal = (terminal_t*)data; |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 87 | uint32_t front_color, back_color; |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 88 | uint8_t br, bb, bg; |
Stéphane Marchesin | edece33 | 2015-12-14 15:10:58 -0800 | [diff] [blame] | 89 | uint32_t luminance; |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 90 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 91 | if (age && terminal->term->age && age <= terminal->term->age) |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 92 | return 0; |
| 93 | |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 94 | if (terminal->background_valid) { |
| 95 | br = (terminal->background >> 16) & 0xFF; |
| 96 | bg = (terminal->background >> 8) & 0xFF; |
| 97 | bb = (terminal->background) & 0xFF; |
Stéphane Marchesin | edece33 | 2015-12-14 15:10:58 -0800 | [diff] [blame] | 98 | luminance = (3 * br + bb + 4 * bg) >> 3; |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 99 | |
Stéphane Marchesin | edece33 | 2015-12-14 15:10:58 -0800 | [diff] [blame] | 100 | /* |
| 101 | * FIXME: black is chosen on a dark background, but it uses the |
| 102 | * default color for light backgrounds |
| 103 | */ |
| 104 | if (luminance > 128) { |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 105 | front_color = 0; |
| 106 | back_color = terminal->background; |
| 107 | } else { |
| 108 | front_color = (attr->fr << 16) | (attr->fg << 8) | attr->fb; |
| 109 | back_color = terminal->background; |
| 110 | } |
| 111 | } else { |
| 112 | front_color = (attr->fr << 16) | (attr->fg << 8) | attr->fb; |
| 113 | back_color = (attr->br << 16) | (attr->bg << 8) | attr->bb; |
| 114 | } |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 115 | |
| 116 | if (attr->inverse) { |
| 117 | uint32_t tmp = front_color; |
| 118 | front_color = back_color; |
| 119 | back_color = tmp; |
| 120 | } |
| 121 | |
| 122 | if (len) |
Dominik Behr | bb728f3 | 2019-09-03 17:52:13 -0700 | [diff] [blame] | 123 | font_render(terminal->fb, posx, posy, *ch, |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 124 | front_color, back_color); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 125 | else |
Dominik Behr | bb728f3 | 2019-09-03 17:52:13 -0700 | [diff] [blame] | 126 | font_fillchar(terminal->fb, posx, posy, |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 127 | front_color, back_color); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 128 | |
| 129 | return 0; |
| 130 | } |
| 131 | |
Stéphane Marchesin | e2a46cd | 2016-01-07 16:45:24 -0800 | [diff] [blame] | 132 | static void term_redraw(terminal_t* terminal) |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 133 | { |
Dominik Behr | bb728f3 | 2019-09-03 17:52:13 -0700 | [diff] [blame] | 134 | if (fb_lock(terminal->fb)) { |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 135 | terminal->term->age = |
| 136 | tsm_screen_draw(terminal->term->screen, term_draw_cell, terminal); |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 137 | fb_unlock(terminal->fb); |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 138 | } |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 139 | } |
| 140 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 141 | void term_key_event(terminal_t* terminal, uint32_t keysym, int32_t unicode) |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 142 | { |
Dominik Behr | da55e6c | 2017-02-28 18:12:10 -0800 | [diff] [blame] | 143 | if (!terminal->input_enable) |
| 144 | return; |
| 145 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 146 | if (tsm_vte_handle_keyboard(terminal->term->vte, keysym, 0, 0, unicode)) |
| 147 | tsm_screen_sb_reset(terminal->term->screen); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 148 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 149 | term_redraw(terminal); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 150 | } |
| 151 | |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 152 | static void term_read_cb(struct shl_pty* pty, char* u8, size_t len, void* data) |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 153 | { |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 154 | terminal_t* terminal = (terminal_t*)data; |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 155 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 156 | tsm_vte_input(terminal->term->vte, u8, len); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 157 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 158 | term_redraw(terminal); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 161 | static void term_write_cb(struct tsm_vte* vte, const char* u8, size_t len, |
| 162 | void* data) |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 163 | { |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 164 | struct term* term = data; |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 165 | int r; |
| 166 | |
| 167 | r = shl_pty_write(term->pty, u8, len); |
| 168 | if (r < 0) |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 169 | LOG(ERROR, "OOM in pty-write (%d)", r); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 170 | |
| 171 | shl_pty_dispatch(term->pty); |
| 172 | } |
| 173 | |
Dominik Behr | d253090 | 2016-05-05 14:01:06 -0700 | [diff] [blame] | 174 | static void term_esc_show_image(terminal_t* terminal, char* params) |
| 175 | { |
| 176 | char* tok; |
| 177 | image_t* image; |
| 178 | int status; |
| 179 | |
| 180 | image = image_create(); |
| 181 | if (!image) { |
| 182 | LOG(ERROR, "Out of memory when creating an image.\n"); |
| 183 | return; |
| 184 | } |
| 185 | for (tok = strtok(params, ";"); tok; tok = strtok(NULL, ";")) { |
| 186 | if (strncmp("file=", tok, 5) == 0) { |
| 187 | image_set_filename(image, tok + 5); |
| 188 | } else if (strncmp("location=", tok, 9) == 0) { |
| 189 | uint32_t x, y; |
| 190 | if (sscanf(tok + 9, "%u,%u", &x, &y) != 2) { |
| 191 | LOG(ERROR, "Error parsing image location.\n"); |
| 192 | goto done; |
| 193 | } |
| 194 | image_set_location(image, x, y); |
| 195 | } else if (strncmp("offset=", tok, 7) == 0) { |
| 196 | int32_t x, y; |
| 197 | if (sscanf(tok + 7, "%d,%d", &x, &y) != 2) { |
| 198 | LOG(ERROR, "Error parsing image offset.\n"); |
| 199 | goto done; |
| 200 | } |
| 201 | image_set_offset(image, x, y); |
| 202 | } else if (strncmp("scale=", tok, 6) == 0) { |
| 203 | uint32_t s; |
| 204 | if (sscanf(tok + 6, "%u", &s) != 1) { |
| 205 | LOG(ERROR, "Error parsing image scale.\n"); |
| 206 | goto done; |
| 207 | } |
| 208 | if (s == 0) |
| 209 | s = image_get_auto_scale(term_getfb(terminal)); |
| 210 | image_set_scale(image, s); |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | status = image_load_image_from_file(image); |
| 215 | if (status != 0) { |
| 216 | LOG(WARNING, "Term ESC image_load_image_from_file %s failed: %d:%s.", |
| 217 | image_get_filename(image), status, strerror(status)); |
| 218 | } else { |
| 219 | term_show_image(terminal, image); |
| 220 | } |
| 221 | done: |
| 222 | image_destroy(image); |
| 223 | } |
| 224 | |
| 225 | static void term_esc_draw_box(terminal_t* terminal, char* params) |
| 226 | { |
| 227 | char* tok; |
| 228 | uint32_t color = 0; |
| 229 | uint32_t w = 1; |
| 230 | uint32_t h = 1; |
| 231 | uint32_t locx, locy; |
| 232 | bool use_location = false; |
| 233 | int32_t offx, offy; |
| 234 | bool use_offset = false; |
| 235 | uint32_t scale = 1; |
Dominik Behr | bb728f3 | 2019-09-03 17:52:13 -0700 | [diff] [blame] | 236 | fb_stepper_t s; |
Dominik Behr | d253090 | 2016-05-05 14:01:06 -0700 | [diff] [blame] | 237 | int32_t startx, starty; |
Dominik Behr | d253090 | 2016-05-05 14:01:06 -0700 | [diff] [blame] | 238 | |
| 239 | for (tok = strtok(params, ";"); tok; tok = strtok(NULL, ";")) { |
| 240 | if (strncmp("color=", tok, 6) == 0) { |
| 241 | color = strtoul(tok + 6, NULL, 0); |
| 242 | } else if (strncmp("size=", tok, 5) == 0) { |
| 243 | if (sscanf(tok + 5, "%u,%u", &w, &h) != 2) { |
| 244 | LOG(ERROR, "Error parsing box size.\n"); |
| 245 | goto done; |
| 246 | } |
| 247 | } else if (strncmp("location=", tok, 9) == 0) { |
| 248 | if (sscanf(tok + 9, "%u,%u", &locx, &locy) != 2) { |
| 249 | LOG(ERROR, "Error parsing box location.\n"); |
| 250 | goto done; |
| 251 | } |
| 252 | use_location = true; |
| 253 | } else if (strncmp("offset=", tok, 7) == 0) { |
| 254 | if (sscanf(tok + 7, "%d,%d", &offx, &offy) != 2) { |
| 255 | LOG(ERROR, "Error parsing box offset.\n"); |
| 256 | goto done; |
| 257 | } |
| 258 | use_offset = true; |
| 259 | } else if (strncmp("scale=", tok, 6) == 0) { |
| 260 | if (sscanf(tok + 6, "%u", &scale) != 1) { |
| 261 | LOG(ERROR, "Error parsing box scale.\n"); |
| 262 | goto done; |
| 263 | } |
| 264 | if (scale == 0) |
| 265 | scale = image_get_auto_scale(term_getfb(terminal)); |
| 266 | } |
| 267 | } |
| 268 | |
| 269 | w *= scale; |
| 270 | h *= scale; |
| 271 | offx *= scale; |
| 272 | offy *= scale; |
| 273 | |
Dominik Behr | bb728f3 | 2019-09-03 17:52:13 -0700 | [diff] [blame] | 274 | if (!fb_lock(terminal->fb)) |
Dominik Behr | d253090 | 2016-05-05 14:01:06 -0700 | [diff] [blame] | 275 | goto done; |
| 276 | |
| 277 | if (use_offset && use_location) { |
| 278 | LOG(WARNING, "Box offset and location set, using location."); |
| 279 | use_offset = false; |
| 280 | } |
| 281 | |
| 282 | if (use_location) { |
| 283 | startx = locx; |
| 284 | starty = locy; |
| 285 | } else { |
Mattias Nissler | 066044c | 2017-07-04 15:23:02 +0200 | [diff] [blame] | 286 | startx = (fb_getwidth(terminal->fb) - w)/2; |
| 287 | starty = (fb_getheight(terminal->fb) - h)/2; |
Dominik Behr | d253090 | 2016-05-05 14:01:06 -0700 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | if (use_offset) { |
| 291 | startx += offx; |
| 292 | starty += offy; |
| 293 | } |
| 294 | |
Dominik Behr | bb728f3 | 2019-09-03 17:52:13 -0700 | [diff] [blame] | 295 | if (!fb_stepper_init(&s, terminal->fb, startx, starty, w, h)) |
Dominik Behr | d253090 | 2016-05-05 14:01:06 -0700 | [diff] [blame] | 296 | goto done_fb; |
Dominik Behr | d253090 | 2016-05-05 14:01:06 -0700 | [diff] [blame] | 297 | |
Dominik Behr | bb728f3 | 2019-09-03 17:52:13 -0700 | [diff] [blame] | 298 | do { |
| 299 | do { |
| 300 | } while (fb_stepper_step_x(&s, color)); |
| 301 | } while (fb_stepper_step_y(&s)); |
| 302 | |
Dominik Behr | d253090 | 2016-05-05 14:01:06 -0700 | [diff] [blame] | 303 | done_fb: |
| 304 | fb_unlock(terminal->fb); |
| 305 | done: |
| 306 | ; |
| 307 | } |
| 308 | |
Dominik Behr | da55e6c | 2017-02-28 18:12:10 -0800 | [diff] [blame] | 309 | static void term_esc_input(terminal_t* terminal, char* params) |
| 310 | { |
| 311 | if (strcmp(params, "1") == 0 || |
| 312 | strcasecmp(params, "on") == 0 || |
| 313 | strcasecmp(params, "true") == 0) |
| 314 | term_input_enable(terminal, true); |
| 315 | else if (strcmp(params, "0") == 0 || |
| 316 | strcasecmp(params, "off") == 0 || |
| 317 | strcasecmp(params, "false") == 0) |
| 318 | term_input_enable(terminal, false); |
| 319 | else |
| 320 | LOG(ERROR, "Invalid parameter for input escape.\n"); |
| 321 | } |
| 322 | |
Dominik Behr | 3a2c61c | 2017-06-22 15:13:48 -0700 | [diff] [blame] | 323 | /* |
| 324 | * Assume all one or two digit sequences followed by ; are xterm OSC escapes. |
| 325 | */ |
| 326 | static bool is_xterm_osc(char *osc) |
| 327 | { |
| 328 | if (isdigit(osc[0])) { |
| 329 | if (osc[1] == ';') |
| 330 | return true; |
| 331 | if (isdigit(osc[1]) && osc[2] == ';') |
| 332 | return true; |
| 333 | } |
| 334 | return false; |
| 335 | } |
| 336 | |
Dominik Behr | d253090 | 2016-05-05 14:01:06 -0700 | [diff] [blame] | 337 | static void term_osc_cb(struct tsm_vte *vte, const uint32_t *osc_string, |
| 338 | size_t osc_len, void *data) |
| 339 | { |
| 340 | terminal_t* terminal = (terminal_t*)data; |
| 341 | size_t i; |
| 342 | char *osc; |
| 343 | |
| 344 | for (i = 0; i < osc_len; i++) |
| 345 | if (osc_string[i] >= 128) |
| 346 | return; /* we only want to deal with ASCII */ |
| 347 | |
| 348 | osc = malloc(osc_len + 1); |
| 349 | if (!osc) { |
Dominik Behr | 3a2c61c | 2017-06-22 15:13:48 -0700 | [diff] [blame] | 350 | LOG(WARNING, "Out of memory when processing OSC.\n"); |
Dominik Behr | d253090 | 2016-05-05 14:01:06 -0700 | [diff] [blame] | 351 | return; |
| 352 | } |
| 353 | |
| 354 | for (i = 0; i < osc_len; i++) |
| 355 | osc[i] = (char)osc_string[i]; |
| 356 | osc[i] = '\0'; |
| 357 | |
| 358 | if (strncmp(osc, "image:", 6) == 0) |
| 359 | term_esc_show_image(terminal, osc + 6); |
| 360 | else if (strncmp(osc, "box:", 4) == 0) |
| 361 | term_esc_draw_box(terminal, osc + 4); |
Dominik Behr | da55e6c | 2017-02-28 18:12:10 -0800 | [diff] [blame] | 362 | else if (strncmp(osc, "input:", 6) == 0) |
| 363 | term_esc_input(terminal, osc + 6); |
Dominik Behr | 3a2c61c | 2017-06-22 15:13:48 -0700 | [diff] [blame] | 364 | else if (is_xterm_osc(osc)) |
| 365 | ; /* Ignore it. */ |
Dominik Behr | d253090 | 2016-05-05 14:01:06 -0700 | [diff] [blame] | 366 | else |
| 367 | LOG(WARNING, "Unknown OSC escape sequence \"%s\", ignoring.", osc); |
| 368 | |
| 369 | free(osc); |
| 370 | } |
| 371 | |
Dominik Behr | 0000350 | 2014-08-15 16:42:37 -0700 | [diff] [blame] | 372 | #ifdef __clang__ |
| 373 | __attribute__((__format__ (__printf__, 7, 0))) |
| 374 | #endif |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 375 | static void log_tsm(void* data, const char* file, int line, const char* fn, |
Stéphane Marchesin | 8fc1352 | 2015-12-14 17:02:28 -0800 | [diff] [blame] | 376 | const char* subs, unsigned int sev, const char* format, |
| 377 | va_list args) |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 378 | { |
Chris Morin | 255d9f0 | 2019-02-04 23:29:27 -0800 | [diff] [blame] | 379 | char buffer[KMSG_LINE_MAX]; |
| 380 | int len = snprintf(buffer, KMSG_LINE_MAX, "<%i>frecon[%d]: %s: ", sev, |
| 381 | getpid(), subs); |
| 382 | if (len < 0) |
| 383 | return; |
| 384 | if (len < KMSG_LINE_MAX - 1) |
| 385 | vsnprintf(buffer+len, KMSG_LINE_MAX - len, format, args); |
| 386 | fprintf(stderr, "%s\n", buffer); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 387 | } |
| 388 | |
Haixia Shi | 9528587 | 2016-11-08 15:26:35 -0800 | [diff] [blame] | 389 | static int term_resize(terminal_t* term, int scaling) |
Stéphane Marchesin | 7831066 | 2016-01-06 16:09:39 -0800 | [diff] [blame] | 390 | { |
| 391 | uint32_t char_width, char_height; |
| 392 | int status; |
| 393 | |
Haixia Shi | 9528587 | 2016-11-08 15:26:35 -0800 | [diff] [blame] | 394 | if (!scaling) |
| 395 | scaling = fb_getscaling(term->fb); |
| 396 | |
| 397 | font_init(scaling); |
Stéphane Marchesin | 7831066 | 2016-01-06 16:09:39 -0800 | [diff] [blame] | 398 | font_get_size(&char_width, &char_height); |
| 399 | |
Dominik Behr | bb728f3 | 2019-09-03 17:52:13 -0700 | [diff] [blame] | 400 | term->term->w_in_char = fb_getwidth(term->fb) / char_width; |
| 401 | term->term->h_in_char = fb_getheight(term->fb) / char_height; |
Stéphane Marchesin | 7831066 | 2016-01-06 16:09:39 -0800 | [diff] [blame] | 402 | |
| 403 | status = tsm_screen_resize(term->term->screen, |
Dominik Behr | bb728f3 | 2019-09-03 17:52:13 -0700 | [diff] [blame] | 404 | term->term->w_in_char, term->term->h_in_char); |
Stéphane Marchesin | 7831066 | 2016-01-06 16:09:39 -0800 | [diff] [blame] | 405 | if (status < 0) { |
| 406 | font_free(); |
| 407 | return -1; |
| 408 | } |
| 409 | |
Dominik Behr | bb728f3 | 2019-09-03 17:52:13 -0700 | [diff] [blame] | 410 | status = shl_pty_resize(term->term->pty, term->term->w_in_char, |
| 411 | term->term->h_in_char); |
Stéphane Marchesin | 7831066 | 2016-01-06 16:09:39 -0800 | [diff] [blame] | 412 | if (status < 0) { |
| 413 | font_free(); |
| 414 | return -1; |
| 415 | } |
| 416 | |
| 417 | return 0; |
| 418 | } |
| 419 | |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 420 | void term_set_num_terminals(unsigned new_num) |
| 421 | { |
| 422 | if (new_num < 1) |
| 423 | term_num_terminals = 1; |
| 424 | else if (new_num > TERM_MAX_TERMINALS) |
| 425 | term_num_terminals = TERM_MAX_TERMINALS; |
| 426 | else |
| 427 | term_num_terminals = new_num; |
| 428 | } |
| 429 | |
| 430 | static bool term_is_interactive(unsigned int vt) |
| 431 | { |
| 432 | if (command_flags.no_login) |
| 433 | return false; |
| 434 | |
| 435 | if (vt == TERM_SPLASH_TERMINAL) |
| 436 | return command_flags.enable_vt1; |
| 437 | |
| 438 | return true; |
| 439 | } |
| 440 | |
Jacek Fedorynski | 9a0c422 | 2018-11-17 19:13:01 +0100 | [diff] [blame] | 441 | /* |
| 442 | * Set the area not covered by any characters, possibly existing on the right |
| 443 | * side and bottom of the screen, to the background color. |
| 444 | */ |
| 445 | static void term_clear_border(terminal_t* terminal) |
| 446 | { |
Dominik Behr | bb728f3 | 2019-09-03 17:52:13 -0700 | [diff] [blame] | 447 | fb_stepper_t s; |
Jacek Fedorynski | 9a0c422 | 2018-11-17 19:13:01 +0100 | [diff] [blame] | 448 | uint32_t char_width, char_height; |
| 449 | font_get_size(&char_width, &char_height); |
Jacek Fedorynski | 9a0c422 | 2018-11-17 19:13:01 +0100 | [diff] [blame] | 450 | |
Dominik Behr | bb728f3 | 2019-09-03 17:52:13 -0700 | [diff] [blame] | 451 | if (!fb_lock(terminal->fb)) |
| 452 | return; |
| 453 | |
| 454 | if (fb_stepper_init(&s, terminal->fb, |
| 455 | terminal->term->w_in_char * char_width, 0, |
| 456 | fb_getwidth(terminal->fb) - terminal->term->w_in_char * char_width, terminal->term->h_in_char * char_height)) { |
| 457 | do { |
| 458 | do { |
| 459 | } while (fb_stepper_step_x(&s, terminal->background)); |
| 460 | } while (fb_stepper_step_y(&s)); |
Jacek Fedorynski | 9a0c422 | 2018-11-17 19:13:01 +0100 | [diff] [blame] | 461 | } |
Dominik Behr | bb728f3 | 2019-09-03 17:52:13 -0700 | [diff] [blame] | 462 | |
| 463 | if (fb_stepper_init(&s, terminal->fb, |
| 464 | 0, terminal->term->h_in_char * char_height, |
| 465 | fb_getwidth(terminal->fb), fb_getheight(terminal->fb) - terminal->term->h_in_char * char_height)) { |
| 466 | do { |
| 467 | do { |
| 468 | } while (fb_stepper_step_x(&s, terminal->background)); |
| 469 | } while (fb_stepper_step_y(&s)); |
| 470 | } |
| 471 | |
| 472 | fb_unlock(terminal->fb); |
Jacek Fedorynski | 9a0c422 | 2018-11-17 19:13:01 +0100 | [diff] [blame] | 473 | } |
| 474 | |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 475 | terminal_t* term_init(unsigned vt, int pts_fd) |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 476 | { |
| 477 | const int scrollback_size = 200; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 478 | int status; |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 479 | terminal_t* new_terminal; |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 480 | bool interactive = term_is_interactive(vt); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 481 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 482 | new_terminal = (terminal_t*)calloc(1, sizeof(*new_terminal)); |
David Sodman | bf3f284 | 2014-11-12 08:26:58 -0800 | [diff] [blame] | 483 | if (!new_terminal) |
| 484 | return NULL; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 485 | |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 486 | new_terminal->vt = vt; |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 487 | new_terminal->background_valid = false; |
Dominik Behr | da55e6c | 2017-02-28 18:12:10 -0800 | [diff] [blame] | 488 | new_terminal->input_enable = true; |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 489 | |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 490 | new_terminal->fb = fb_init(); |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 491 | |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 492 | if (!new_terminal->fb) { |
Dominik Behr | f932991 | 2016-08-25 17:31:52 -0700 | [diff] [blame] | 493 | LOG(ERROR, "Failed to create fb on VT%u.", vt); |
David Sodman | bf3f284 | 2014-11-12 08:26:58 -0800 | [diff] [blame] | 494 | term_close(new_terminal); |
| 495 | return NULL; |
| 496 | } |
| 497 | |
| 498 | new_terminal->term = (struct term*)calloc(1, sizeof(*new_terminal->term)); |
| 499 | if (!new_terminal->term) { |
| 500 | term_close(new_terminal); |
| 501 | return NULL; |
| 502 | } |
| 503 | |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 504 | if (interactive) |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 505 | new_terminal->exec = interactive_cmd_line; |
| 506 | else |
Dominik Behr | 32680e3 | 2016-08-16 12:18:41 -0700 | [diff] [blame] | 507 | new_terminal->exec = NULL; |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 508 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 509 | status = tsm_screen_new(&new_terminal->term->screen, |
| 510 | log_tsm, new_terminal->term); |
zhuo-hao | 471f1e2 | 2015-08-12 14:55:56 +0800 | [diff] [blame] | 511 | if (status < 0) { |
Dominik Behr | f932991 | 2016-08-25 17:31:52 -0700 | [diff] [blame] | 512 | LOG(ERROR, "Failed to create new screen on VT%u.", vt); |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 513 | term_close(new_terminal); |
| 514 | return NULL; |
| 515 | } |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 516 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 517 | tsm_screen_set_max_sb(new_terminal->term->screen, scrollback_size); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 518 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 519 | status = tsm_vte_new(&new_terminal->term->vte, new_terminal->term->screen, |
| 520 | term_write_cb, new_terminal->term, log_tsm, new_terminal->term); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 521 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 522 | if (status < 0) { |
Dominik Behr | f932991 | 2016-08-25 17:31:52 -0700 | [diff] [blame] | 523 | LOG(ERROR, "Failed to create new VT%u.", vt); |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 524 | term_close(new_terminal); |
| 525 | return NULL; |
| 526 | } |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 527 | |
Dominik Behr | da55e6c | 2017-02-28 18:12:10 -0800 | [diff] [blame] | 528 | if (command_flags.enable_osc) |
Dominik Behr | d253090 | 2016-05-05 14:01:06 -0700 | [diff] [blame] | 529 | tsm_vte_set_osc_cb(new_terminal->term->vte, term_osc_cb, (void *)new_terminal); |
| 530 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 531 | new_terminal->term->pty_bridge = shl_pty_bridge_new(); |
| 532 | if (new_terminal->term->pty_bridge < 0) { |
Dominik Behr | f932991 | 2016-08-25 17:31:52 -0700 | [diff] [blame] | 533 | LOG(ERROR, "Failed to create pty bridge on VT%u.", vt); |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 534 | term_close(new_terminal); |
| 535 | return NULL; |
| 536 | } |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 537 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 538 | status = shl_pty_open(&new_terminal->term->pty, |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 539 | term_read_cb, new_terminal, 1, 1, pts_fd); |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 540 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 541 | if (status < 0) { |
Dominik Behr | f932991 | 2016-08-25 17:31:52 -0700 | [diff] [blame] | 542 | LOG(ERROR, "Failed to open pty on VT%u.", vt); |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 543 | term_close(new_terminal); |
| 544 | return NULL; |
| 545 | } else if (status == 0) { |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 546 | term_run_child(new_terminal); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 547 | exit(1); |
| 548 | } |
| 549 | |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 550 | status = mkdir(FRECON_RUN_DIR, S_IRWXU); |
| 551 | if (status == 0 || (status < 0 && errno == EEXIST)) { |
| 552 | char path[32]; |
| 553 | snprintf(path, sizeof(path), FRECON_VT_PATH, vt); |
Dominik Behr | b23b05b | 2016-08-15 16:29:02 -0700 | [diff] [blame] | 554 | unlink(path); /* In case it already exists. Ignore return codes. */ |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 555 | if (symlink(ptsname(shl_pty_get_fd(new_terminal->term->pty)), path) < 0) |
| 556 | LOG(ERROR, "Failed to symlink pts name %s to %s, %d:%s", |
| 557 | path, |
| 558 | ptsname(shl_pty_get_fd(new_terminal->term->pty)), |
| 559 | errno, strerror(errno)); |
| 560 | } |
| 561 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 562 | status = shl_pty_bridge_add(new_terminal->term->pty_bridge, new_terminal->term->pty); |
| 563 | if (status) { |
Dominik Behr | f932991 | 2016-08-25 17:31:52 -0700 | [diff] [blame] | 564 | LOG(ERROR, "Failed to add pty bridge on VT%u.", vt); |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 565 | term_close(new_terminal); |
| 566 | return NULL; |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 567 | } |
| 568 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 569 | new_terminal->term->pid = shl_pty_get_child(new_terminal->term->pty); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 570 | |
Haixia Shi | 9528587 | 2016-11-08 15:26:35 -0800 | [diff] [blame] | 571 | status = term_resize(new_terminal, 0); |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 572 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 573 | if (status < 0) { |
Dominik Behr | f932991 | 2016-08-25 17:31:52 -0700 | [diff] [blame] | 574 | LOG(ERROR, "Failed to resize VT%u.", vt); |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 575 | term_close(new_terminal); |
| 576 | return NULL; |
| 577 | } |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 578 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 579 | return new_terminal; |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 580 | } |
| 581 | |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 582 | void term_activate(terminal_t* terminal) |
| 583 | { |
Dominik Behr | 4defb36 | 2016-01-13 12:36:14 -0800 | [diff] [blame] | 584 | term_set_current_to(terminal); |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 585 | terminal->active = true; |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 586 | fb_setmode(terminal->fb); |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 587 | term_redraw(terminal); |
| 588 | } |
| 589 | |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 590 | void term_deactivate(terminal_t* terminal) |
| 591 | { |
| 592 | if (!terminal->active) |
| 593 | return; |
| 594 | |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 595 | terminal->active = false; |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 596 | } |
| 597 | |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 598 | void term_close(terminal_t* term) |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 599 | { |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 600 | char path[32]; |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 601 | if (!term) |
| 602 | return; |
| 603 | |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 604 | snprintf(path, sizeof(path), FRECON_VT_PATH, term->vt); |
| 605 | unlink(path); |
| 606 | |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 607 | if (term->fb) { |
| 608 | fb_close(term->fb); |
| 609 | term->fb = NULL; |
David Sodman | bf3f284 | 2014-11-12 08:26:58 -0800 | [diff] [blame] | 610 | } |
| 611 | |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 612 | if (term->term) { |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 613 | if (term->term->pty) { |
| 614 | if (term->term->pty_bridge >= 0) { |
| 615 | shl_pty_bridge_remove(term->term->pty_bridge, term->term->pty); |
| 616 | shl_pty_bridge_free(term->term->pty_bridge); |
| 617 | term->term->pty_bridge = -1; |
| 618 | } |
| 619 | shl_pty_close(term->term->pty); |
| 620 | term->term->pty = NULL; |
| 621 | } |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 622 | free(term->term); |
| 623 | term->term = NULL; |
| 624 | } |
| 625 | |
Haixia Shi | 95d680e | 2015-04-27 20:29:17 -0700 | [diff] [blame] | 626 | font_free(); |
David Sodman | bbcb052 | 2014-09-19 10:34:07 -0700 | [diff] [blame] | 627 | free(term); |
Stéphane Marchesin | ae37e6c | 2014-08-08 18:19:40 -0700 | [diff] [blame] | 628 | } |
David Sodman | bf3f284 | 2014-11-12 08:26:58 -0800 | [diff] [blame] | 629 | |
| 630 | bool term_is_child_done(terminal_t* terminal) |
| 631 | { |
| 632 | int status; |
| 633 | int ret; |
| 634 | ret = waitpid(terminal->term->pid, &status, WNOHANG); |
| 635 | |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 636 | if ((ret == -1) && (errno == ECHILD)) { |
| 637 | return false; |
| 638 | } |
David Sodman | bf3f284 | 2014-11-12 08:26:58 -0800 | [diff] [blame] | 639 | return ret != 0; |
| 640 | } |
| 641 | |
| 642 | void term_page_up(terminal_t* terminal) |
| 643 | { |
| 644 | tsm_screen_sb_page_up(terminal->term->screen, 1); |
| 645 | term_redraw(terminal); |
| 646 | } |
| 647 | |
| 648 | void term_page_down(terminal_t* terminal) |
| 649 | { |
| 650 | tsm_screen_sb_page_down(terminal->term->screen, 1); |
| 651 | term_redraw(terminal); |
| 652 | } |
| 653 | |
| 654 | void term_line_up(terminal_t* terminal) |
| 655 | { |
| 656 | tsm_screen_sb_up(terminal->term->screen, 1); |
| 657 | term_redraw(terminal); |
| 658 | } |
| 659 | |
| 660 | void term_line_down(terminal_t* terminal) |
| 661 | { |
| 662 | tsm_screen_sb_down(terminal->term->screen, 1); |
| 663 | term_redraw(terminal); |
| 664 | } |
| 665 | |
| 666 | bool term_is_valid(terminal_t* terminal) |
| 667 | { |
| 668 | return ((terminal != NULL) && (terminal->term != NULL)); |
| 669 | } |
| 670 | |
| 671 | int term_fd(terminal_t* terminal) |
| 672 | { |
| 673 | if (term_is_valid(terminal)) |
| 674 | return terminal->term->pty_bridge; |
| 675 | else |
| 676 | return -1; |
| 677 | } |
| 678 | |
| 679 | void term_dispatch_io(terminal_t* terminal, fd_set* read_set) |
| 680 | { |
| 681 | if (term_is_valid(terminal)) |
| 682 | if (FD_ISSET(terminal->term->pty_bridge, read_set)) |
| 683 | shl_pty_bridge_dispatch(terminal->term->pty_bridge, 0); |
| 684 | } |
| 685 | |
| 686 | bool term_exception(terminal_t* terminal, fd_set* exception_set) |
| 687 | { |
| 688 | if (term_is_valid(terminal)) { |
| 689 | if (terminal->term->pty_bridge >= 0) { |
| 690 | return FD_ISSET(terminal->term->pty_bridge, |
| 691 | exception_set); |
| 692 | } |
| 693 | } |
| 694 | |
| 695 | return false; |
| 696 | } |
| 697 | |
| 698 | bool term_is_active(terminal_t* terminal) |
| 699 | { |
| 700 | if (term_is_valid(terminal)) |
| 701 | return terminal->active; |
| 702 | |
| 703 | return false; |
| 704 | } |
| 705 | |
Dominik Behr | b1abcba | 2016-04-14 14:57:21 -0700 | [diff] [blame] | 706 | void term_add_fds(terminal_t* terminal, fd_set* read_set, fd_set* exception_set, int* maxfd) |
David Sodman | bf3f284 | 2014-11-12 08:26:58 -0800 | [diff] [blame] | 707 | { |
| 708 | if (term_is_valid(terminal)) { |
| 709 | if (terminal->term->pty_bridge >= 0) { |
Dominik Behr | d711267 | 2016-01-20 16:59:34 -0800 | [diff] [blame] | 710 | *maxfd = MAX(*maxfd, terminal->term->pty_bridge); |
David Sodman | bf3f284 | 2014-11-12 08:26:58 -0800 | [diff] [blame] | 711 | FD_SET(terminal->term->pty_bridge, read_set); |
| 712 | FD_SET(terminal->term->pty_bridge, exception_set); |
| 713 | } |
| 714 | } |
| 715 | } |
David Sodman | 8ef2006 | 2015-01-06 09:23:40 -0800 | [diff] [blame] | 716 | |
| 717 | const char* term_get_ptsname(terminal_t* terminal) |
| 718 | { |
| 719 | return ptsname(shl_pty_get_fd(terminal->term->pty)); |
| 720 | } |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 721 | |
| 722 | void term_set_background(terminal_t* terminal, uint32_t bg) |
| 723 | { |
| 724 | terminal->background = bg; |
| 725 | terminal->background_valid = true; |
| 726 | } |
| 727 | |
| 728 | int term_show_image(terminal_t* terminal, image_t* image) |
| 729 | { |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 730 | return image_show(image, terminal->fb); |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | void term_write_message(terminal_t* terminal, char* message) |
| 734 | { |
Stéphane Marchesin | 00ff187 | 2015-12-14 13:40:09 -0800 | [diff] [blame] | 735 | FILE* fp; |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 736 | |
| 737 | fp = fopen(term_get_ptsname(terminal), "w"); |
| 738 | if (fp) { |
| 739 | fputs(message, fp); |
| 740 | fclose(fp); |
| 741 | } |
| 742 | } |
| 743 | |
Stéphane Marchesin | f75c851 | 2016-01-07 16:53:21 -0800 | [diff] [blame] | 744 | static void term_hide_cursor(terminal_t* terminal) |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 745 | { |
| 746 | term_write_message(terminal, "\033[?25l"); |
| 747 | } |
| 748 | |
Stéphane Marchesin | f75c851 | 2016-01-07 16:53:21 -0800 | [diff] [blame] | 749 | __attribute__ ((unused)) |
| 750 | static void term_show_cursor(terminal_t* terminal) |
David Sodman | f0a925a | 2015-05-04 11:19:19 -0700 | [diff] [blame] | 751 | { |
| 752 | term_write_message(terminal, "\033[?25h"); |
| 753 | } |
David Sodman | 30a94ef | 2015-07-26 17:37:12 -0700 | [diff] [blame] | 754 | |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 755 | fb_t* term_getfb(terminal_t* terminal) |
David Sodman | 30a94ef | 2015-07-26 17:37:12 -0700 | [diff] [blame] | 756 | { |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 757 | return terminal->fb; |
David Sodman | 30a94ef | 2015-07-26 17:37:12 -0700 | [diff] [blame] | 758 | } |
Stéphane Marchesin | 08c08e7 | 2016-01-07 16:44:08 -0800 | [diff] [blame] | 759 | |
| 760 | terminal_t* term_get_terminal(int num) |
| 761 | { |
| 762 | return terminals[num]; |
| 763 | } |
| 764 | |
| 765 | void term_set_terminal(int num, terminal_t* terminal) |
| 766 | { |
| 767 | terminals[num] = terminal; |
| 768 | } |
Stéphane Marchesin | f75c851 | 2016-01-07 16:53:21 -0800 | [diff] [blame] | 769 | |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 770 | int term_create_splash_term(int pts_fd) |
Stéphane Marchesin | f75c851 | 2016-01-07 16:53:21 -0800 | [diff] [blame] | 771 | { |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 772 | terminal_t* terminal = term_init(TERM_SPLASH_TERMINAL, pts_fd); |
| 773 | |
| 774 | if (!terminal) { |
| 775 | LOG(ERROR, "Could not create splash term."); |
| 776 | return -1; |
| 777 | } |
| 778 | term_set_terminal(TERM_SPLASH_TERMINAL, terminal); |
Stéphane Marchesin | f75c851 | 2016-01-07 16:53:21 -0800 | [diff] [blame] | 779 | |
| 780 | // Hide the cursor on the splash screen |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 781 | term_hide_cursor(terminal); |
| 782 | return 0; |
Stéphane Marchesin | f75c851 | 2016-01-07 16:53:21 -0800 | [diff] [blame] | 783 | } |
| 784 | |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 785 | void term_destroy_splash_term(void) |
Stéphane Marchesin | f75c851 | 2016-01-07 16:53:21 -0800 | [diff] [blame] | 786 | { |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 787 | terminal_t *terminal; |
| 788 | if (command_flags.enable_vt1) { |
| 789 | return; |
| 790 | } |
Jacek Fedorynski | 83776b7 | 2019-03-06 22:56:56 +0100 | [diff] [blame] | 791 | terminal = term_get_terminal(TERM_SPLASH_TERMINAL); |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 792 | term_set_terminal(TERM_SPLASH_TERMINAL, NULL); |
| 793 | term_close(terminal); |
Stéphane Marchesin | 92a297d | 2016-01-07 20:24:55 -0800 | [diff] [blame] | 794 | } |
Stéphane Marchesin | f75c851 | 2016-01-07 16:53:21 -0800 | [diff] [blame] | 795 | |
Dominik Behr | 4defb36 | 2016-01-13 12:36:14 -0800 | [diff] [blame] | 796 | void term_set_current(uint32_t t) |
| 797 | { |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 798 | if (t >= TERM_MAX_TERMINALS) |
| 799 | LOG(ERROR, "set_current: larger than array size"); |
| 800 | else |
| 801 | if (t >= term_num_terminals) |
| 802 | LOG(ERROR, "set_current: larger than num terminals"); |
Dominik Behr | 4defb36 | 2016-01-13 12:36:14 -0800 | [diff] [blame] | 803 | else |
| 804 | current_terminal = t; |
| 805 | } |
| 806 | |
| 807 | uint32_t term_get_current(void) |
| 808 | { |
| 809 | return current_terminal; |
| 810 | } |
| 811 | |
| 812 | terminal_t *term_get_current_terminal(void) |
| 813 | { |
| 814 | return terminals[current_terminal]; |
| 815 | } |
| 816 | |
Dominik Behr | b1abcba | 2016-04-14 14:57:21 -0700 | [diff] [blame] | 817 | void term_set_current_terminal(terminal_t* terminal) |
Dominik Behr | 4defb36 | 2016-01-13 12:36:14 -0800 | [diff] [blame] | 818 | { |
| 819 | terminals[current_terminal] = terminal; |
| 820 | } |
| 821 | |
| 822 | void term_set_current_to(terminal_t* terminal) |
| 823 | { |
| 824 | if (!terminal) { |
Haixia Shi | 9528587 | 2016-11-08 15:26:35 -0800 | [diff] [blame] | 825 | if (terminals[current_terminal]) |
| 826 | term_close(terminals[current_terminal]); |
Dominik Behr | 4defb36 | 2016-01-13 12:36:14 -0800 | [diff] [blame] | 827 | terminals[current_terminal] = NULL; |
| 828 | current_terminal = 0; |
| 829 | return; |
| 830 | } |
| 831 | |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 832 | for (unsigned i = 0; i < term_num_terminals; i++) { |
Dominik Behr | 4defb36 | 2016-01-13 12:36:14 -0800 | [diff] [blame] | 833 | if (terminal == terminals[i]) { |
| 834 | current_terminal = i; |
| 835 | return; |
| 836 | } |
| 837 | } |
| 838 | LOG(ERROR, "set_current_to: terminal not in array"); |
| 839 | } |
Dominik Behr | 01a7a58 | 2016-01-28 17:02:21 -0800 | [diff] [blame] | 840 | |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 841 | int term_switch_to(unsigned int vt) |
| 842 | { |
| 843 | terminal_t *terminal; |
| 844 | if (vt == term_get_current()) { |
| 845 | terminal = term_get_current_terminal(); |
Dominik Behr | f932991 | 2016-08-25 17:31:52 -0700 | [diff] [blame] | 846 | if (term_is_valid(terminal)) { |
| 847 | if (!term_is_active(terminal)) |
| 848 | term_activate(terminal); |
| 849 | return vt; |
| 850 | } |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 851 | } |
| 852 | |
| 853 | if (vt >= term_num_terminals) |
| 854 | return -EINVAL; |
| 855 | |
| 856 | terminal = term_get_current_terminal(); |
| 857 | if (term_is_active(terminal)) |
| 858 | term_deactivate(terminal); |
| 859 | |
| 860 | if (vt == TERM_SPLASH_TERMINAL |
| 861 | && !term_get_terminal(TERM_SPLASH_TERMINAL) |
| 862 | && !command_flags.enable_vt1) { |
| 863 | term_set_current(vt); |
| 864 | /* Splash term is already gone, returning to Chrome. */ |
Dominik Behr | 3384733 | 2016-12-12 17:27:56 -0800 | [diff] [blame] | 865 | term_background(false); |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 866 | return vt; |
| 867 | } |
| 868 | |
| 869 | term_foreground(); |
| 870 | |
| 871 | term_set_current(vt); |
| 872 | terminal = term_get_current_terminal(); |
| 873 | if (!terminal) { |
| 874 | /* No terminal where we are switching to, create new one. */ |
| 875 | term_set_current_terminal(term_init(vt, -1)); |
| 876 | terminal = term_get_current_terminal(); |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 877 | if (!term_is_valid(terminal)) { |
Dominik Behr | f932991 | 2016-08-25 17:31:52 -0700 | [diff] [blame] | 878 | LOG(ERROR, "Term init failed VT%u.", vt); |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 879 | return -1; |
| 880 | } |
Dominik Behr | f932991 | 2016-08-25 17:31:52 -0700 | [diff] [blame] | 881 | term_activate(terminal); |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 882 | } else { |
| 883 | term_activate(terminal); |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | return vt; |
| 887 | } |
| 888 | |
Dominik Behr | 01a7a58 | 2016-01-28 17:02:21 -0800 | [diff] [blame] | 889 | void term_monitor_hotplug(void) |
| 890 | { |
| 891 | unsigned int t; |
| 892 | |
Dominik Behr | 83864df | 2016-04-21 12:35:08 -0700 | [diff] [blame] | 893 | if (in_background) { |
| 894 | hotplug_occured = true; |
| 895 | return; |
| 896 | } |
| 897 | |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 898 | if (!drm_rescan()) |
| 899 | return; |
| 900 | |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 901 | for (t = 0; t < term_num_terminals; t++) { |
Dominik Behr | 01a7a58 | 2016-01-28 17:02:21 -0800 | [diff] [blame] | 902 | if (!terminals[t]) |
| 903 | continue; |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 904 | if (!terminals[t]->fb) |
Dominik Behr | 01a7a58 | 2016-01-28 17:02:21 -0800 | [diff] [blame] | 905 | continue; |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 906 | fb_buffer_destroy(terminals[t]->fb); |
Dominik Behr | a3f6571 | 2016-04-25 17:42:14 -0700 | [diff] [blame] | 907 | font_free(); |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 908 | } |
| 909 | |
Dominik Behr | da6df41 | 2016-08-02 12:56:42 -0700 | [diff] [blame] | 910 | for (t = 0; t < term_num_terminals; t++) { |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 911 | if (!terminals[t]) |
| 912 | continue; |
| 913 | if (!terminals[t]->fb) |
| 914 | continue; |
| 915 | fb_buffer_init(terminals[t]->fb); |
Haixia Shi | 9528587 | 2016-11-08 15:26:35 -0800 | [diff] [blame] | 916 | term_resize(terminals[t], 0); |
Dominik Behr | 83010f8 | 2016-03-18 18:43:08 -0700 | [diff] [blame] | 917 | if (current_terminal == t && terminals[t]->active) |
| 918 | fb_setmode(terminals[t]->fb); |
| 919 | terminals[t]->term->age = 0; |
| 920 | term_redraw(terminals[t]); |
Dominik Behr | 01a7a58 | 2016-01-28 17:02:21 -0800 | [diff] [blame] | 921 | } |
| 922 | } |
Dominik Behr | b1abcba | 2016-04-14 14:57:21 -0700 | [diff] [blame] | 923 | |
| 924 | void term_redrm(terminal_t* terminal) |
| 925 | { |
| 926 | fb_buffer_destroy(terminal->fb); |
Dominik Behr | a3f6571 | 2016-04-25 17:42:14 -0700 | [diff] [blame] | 927 | font_free(); |
Dominik Behr | b1abcba | 2016-04-14 14:57:21 -0700 | [diff] [blame] | 928 | fb_buffer_init(terminal->fb); |
Haixia Shi | 9528587 | 2016-11-08 15:26:35 -0800 | [diff] [blame] | 929 | term_resize(terminal, 0); |
Dominik Behr | b1abcba | 2016-04-14 14:57:21 -0700 | [diff] [blame] | 930 | terminal->term->age = 0; |
| 931 | term_redraw(terminal); |
| 932 | } |
| 933 | |
| 934 | void term_clear(terminal_t* terminal) |
| 935 | { |
Jacek Fedorynski | 9a0c422 | 2018-11-17 19:13:01 +0100 | [diff] [blame] | 936 | term_clear_border(terminal); |
Dominik Behr | b1abcba | 2016-04-14 14:57:21 -0700 | [diff] [blame] | 937 | tsm_screen_erase_screen(terminal->term->screen, false); |
| 938 | term_redraw(terminal); |
| 939 | } |
Dominik Behr | 83864df | 2016-04-21 12:35:08 -0700 | [diff] [blame] | 940 | |
Haixia Shi | 9528587 | 2016-11-08 15:26:35 -0800 | [diff] [blame] | 941 | void term_zoom(bool zoom_in) |
| 942 | { |
| 943 | int scaling = font_get_scaling(); |
| 944 | if (zoom_in && scaling < 4) |
| 945 | scaling++; |
| 946 | else if (!zoom_in && scaling > 1) |
| 947 | scaling--; |
| 948 | else |
| 949 | return; |
| 950 | |
| 951 | unsigned int t; |
| 952 | for (t = 0; t < term_num_terminals; t++) { |
| 953 | if (terminals[t]) |
| 954 | font_free(); |
| 955 | } |
| 956 | for (t = 0; t < term_num_terminals; t++) { |
| 957 | terminal_t* term = terminals[t]; |
| 958 | if (term) { |
| 959 | term_resize(term, scaling); |
| 960 | term->term->age = 0; |
| 961 | term_redraw(term); |
| 962 | } |
| 963 | } |
| 964 | } |
| 965 | |
Dominik Behr | 3384733 | 2016-12-12 17:27:56 -0800 | [diff] [blame] | 966 | /* |
| 967 | * Put frecon in background. Give up DRM master. |
| 968 | * onetry - if true, do not retry to notify Chrome multiple times. For use at |
| 969 | * time when Chrome may be not around yet to receive the message. |
| 970 | */ |
| 971 | void term_background(bool onetry) |
Dominik Behr | 83864df | 2016-04-21 12:35:08 -0700 | [diff] [blame] | 972 | { |
Dominik Behr | 3384733 | 2016-12-12 17:27:56 -0800 | [diff] [blame] | 973 | int retry = onetry ? 1 : 5; |
Dominik Behr | 83864df | 2016-04-21 12:35:08 -0700 | [diff] [blame] | 974 | if (in_background) |
| 975 | return; |
| 976 | in_background = true; |
Dominik Behr | da3c010 | 2016-06-08 15:05:38 -0700 | [diff] [blame] | 977 | drm_dropmaster(NULL); |
Dominik Behr | a818a1e | 2016-10-26 19:46:22 -0700 | [diff] [blame] | 978 | while (!dbus_take_display_ownership() && retry--) { |
Dominik Behr | 3384733 | 2016-12-12 17:27:56 -0800 | [diff] [blame] | 979 | if (onetry) |
| 980 | break; |
Dominik Behr | a818a1e | 2016-10-26 19:46:22 -0700 | [diff] [blame] | 981 | LOG(ERROR, "Chrome failed to take display ownership. %s", |
| 982 | retry ? "Trying again." : "Giving up, Chrome is probably dead."); |
Dominik Behr | 3384733 | 2016-12-12 17:27:56 -0800 | [diff] [blame] | 983 | if (retry > 0) |
| 984 | usleep(500 * 1000); |
Dominik Behr | a818a1e | 2016-10-26 19:46:22 -0700 | [diff] [blame] | 985 | } |
Dominik Behr | 83864df | 2016-04-21 12:35:08 -0700 | [diff] [blame] | 986 | } |
| 987 | |
| 988 | void term_foreground(void) |
| 989 | { |
Dominik Behr | da3c010 | 2016-06-08 15:05:38 -0700 | [diff] [blame] | 990 | int ret; |
Dominik Behr | 3384733 | 2016-12-12 17:27:56 -0800 | [diff] [blame] | 991 | int retry = 5; |
Dominik Behr | a818a1e | 2016-10-26 19:46:22 -0700 | [diff] [blame] | 992 | |
Dominik Behr | 83864df | 2016-04-21 12:35:08 -0700 | [diff] [blame] | 993 | if (!in_background) |
| 994 | return; |
| 995 | in_background = false; |
Dominik Behr | a818a1e | 2016-10-26 19:46:22 -0700 | [diff] [blame] | 996 | |
Dominik Behr | 57b5c72 | 2018-08-08 18:52:31 -0700 | [diff] [blame] | 997 | /* LOG(INFO, "TIMING: Console switch time start."); */ /* Keep around for timing it in the future. */ |
Dominik Behr | a818a1e | 2016-10-26 19:46:22 -0700 | [diff] [blame] | 998 | while (!dbus_release_display_ownership() && retry--) { |
| 999 | LOG(ERROR, "Chrome did not release master. %s", |
| 1000 | retry ? "Trying again." : "Frecon will steal master."); |
Dominik Behr | 3384733 | 2016-12-12 17:27:56 -0800 | [diff] [blame] | 1001 | if (retry > 0) |
| 1002 | usleep(500 * 1000); |
Dominik Behr | 83864df | 2016-04-21 12:35:08 -0700 | [diff] [blame] | 1003 | } |
Dominik Behr | da3c010 | 2016-06-08 15:05:38 -0700 | [diff] [blame] | 1004 | |
Dominik Behr | 57b5c72 | 2018-08-08 18:52:31 -0700 | [diff] [blame] | 1005 | /* LOG(INFO, "TIMING: Console switch setmaster."); */ |
Dominik Behr | da3c010 | 2016-06-08 15:05:38 -0700 | [diff] [blame] | 1006 | ret = drm_setmaster(NULL); |
Dominik Behr | da3c010 | 2016-06-08 15:05:38 -0700 | [diff] [blame] | 1007 | if (ret < 0) |
| 1008 | LOG(ERROR, "Could not set master when switching to foreground %m."); |
| 1009 | |
Dominik Behr | 83864df | 2016-04-21 12:35:08 -0700 | [diff] [blame] | 1010 | if (hotplug_occured) { |
| 1011 | hotplug_occured = false; |
| 1012 | term_monitor_hotplug(); |
| 1013 | } |
| 1014 | } |
Dominik Behr | 1883c04 | 2016-04-27 12:31:02 -0700 | [diff] [blame] | 1015 | |
| 1016 | void term_suspend_done(void* ignore) |
| 1017 | { |
| 1018 | term_monitor_hotplug(); |
| 1019 | } |
Dominik Behr | da55e6c | 2017-02-28 18:12:10 -0800 | [diff] [blame] | 1020 | |
| 1021 | void term_input_enable(terminal_t* terminal, bool input_enable) |
| 1022 | { |
| 1023 | terminal->input_enable = input_enable; |
| 1024 | } |