Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Server-side console management |
| 3 | * |
| 4 | * Copyright (C) 1998 Alexandre Julliard |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 5 | * 2001 Eric Pouech |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 6 | * |
Alexandre Julliard | 0799c1a | 2002-03-09 23:29:33 +0000 | [diff] [blame] | 7 | * |
| 8 | * This library is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU Lesser General Public |
| 10 | * License as published by the Free Software Foundation; either |
| 11 | * version 2.1 of the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This library is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * Lesser General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Lesser General Public |
| 19 | * License along with this library; if not, write to the Free Software |
Jonathan Ernst | 360a3f9 | 2006-05-18 14:49:52 +0200 | [diff] [blame] | 20 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 21 | */ |
| 22 | |
Patrik Stridvall | 9633632 | 1999-10-24 22:13:47 +0000 | [diff] [blame] | 23 | #include "config.h" |
Alexandre Julliard | 5769d1d | 2002-04-26 19:05:15 +0000 | [diff] [blame] | 24 | #include "wine/port.h" |
Patrik Stridvall | 9633632 | 1999-10-24 22:13:47 +0000 | [diff] [blame] | 25 | |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 26 | #include <assert.h> |
Alexandre Julliard | 0562539 | 1999-01-03 11:55:56 +0000 | [diff] [blame] | 27 | #include <string.h> |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 28 | #include <stdio.h> |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 29 | #include <unistd.h> |
Eric Pouech | 93bfa0d | 2002-06-02 21:22:22 +0000 | [diff] [blame] | 30 | #include <signal.h> |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 31 | |
Ge van Geldorp | 1a1583a | 2005-11-28 17:32:54 +0100 | [diff] [blame] | 32 | #include "ntstatus.h" |
| 33 | #define WIN32_NO_STATUS |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 34 | #include "handle.h" |
| 35 | #include "process.h" |
Alexandre Julliard | 5bc7808 | 1999-06-22 17:26:53 +0000 | [diff] [blame] | 36 | #include "request.h" |
Eric Pouech | 465f3d1 | 2010-08-28 13:14:43 +0200 | [diff] [blame] | 37 | #include "file.h" |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 38 | #include "unicode.h" |
Alexandre Julliard | 627ca40 | 2007-05-11 12:46:32 +0200 | [diff] [blame] | 39 | #include "wincon.h" |
Ge van Geldorp | 1a1583a | 2005-11-28 17:32:54 +0100 | [diff] [blame] | 40 | #include "winternl.h" |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 41 | |
Alexandre Julliard | 627ca40 | 2007-05-11 12:46:32 +0200 | [diff] [blame] | 42 | struct screen_buffer; |
| 43 | struct console_input_events; |
| 44 | |
| 45 | struct console_input |
| 46 | { |
| 47 | struct object obj; /* object header */ |
| 48 | int num_proc; /* number of processes attached to this console */ |
| 49 | struct thread *renderer; /* console renderer thread */ |
| 50 | int mode; /* input mode */ |
| 51 | struct screen_buffer *active; /* active screen buffer */ |
| 52 | int recnum; /* number of input records */ |
| 53 | INPUT_RECORD *records; /* input records */ |
| 54 | struct console_input_events *evt; /* synchronization event with renderer */ |
| 55 | WCHAR *title; /* console title */ |
| 56 | WCHAR **history; /* lines history */ |
| 57 | int history_size; /* number of entries in history array */ |
| 58 | int history_index; /* number of used entries in history array */ |
| 59 | int history_mode; /* mode of history (non zero means remove doubled strings */ |
| 60 | int edition_mode; /* index to edition mode flavors */ |
| 61 | int input_cp; /* console input codepage */ |
| 62 | int output_cp; /* console output codepage */ |
Kirill K. Smirnov | f3e1317 | 2007-08-23 19:17:17 +0400 | [diff] [blame] | 63 | user_handle_t win; /* window handle if backend supports it */ |
Alexandre Julliard | 627ca40 | 2007-05-11 12:46:32 +0200 | [diff] [blame] | 64 | struct event *event; /* event to wait on for input queue */ |
Eric Pouech | b39a8d9 | 2010-08-30 22:18:44 +0200 | [diff] [blame] | 65 | struct fd *fd; /* for bare console, attached input fd */ |
Alexandre Julliard | 627ca40 | 2007-05-11 12:46:32 +0200 | [diff] [blame] | 66 | }; |
| 67 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 68 | static void console_input_dump( struct object *obj, int verbose ); |
| 69 | static void console_input_destroy( struct object *obj ); |
Eric Pouech | b39a8d9 | 2010-08-30 22:18:44 +0200 | [diff] [blame] | 70 | static struct fd *console_input_get_fd( struct object *obj ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 71 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 72 | static const struct object_ops console_input_ops = |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 73 | { |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 74 | sizeof(struct console_input), /* size */ |
| 75 | console_input_dump, /* dump */ |
Alexandre Julliard | 8382eb0 | 2007-12-05 18:16:42 +0100 | [diff] [blame] | 76 | no_get_type, /* get_type */ |
Eric Pouech | 412d37f | 2003-06-21 02:07:10 +0000 | [diff] [blame] | 77 | no_add_queue, /* add_queue */ |
| 78 | NULL, /* remove_queue */ |
| 79 | NULL, /* signaled */ |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 80 | no_satisfied, /* satisfied */ |
Mike McCormack | f92fff6 | 2005-04-24 17:35:52 +0000 | [diff] [blame] | 81 | no_signal, /* signal */ |
Eric Pouech | b39a8d9 | 2010-08-30 22:18:44 +0200 | [diff] [blame] | 82 | console_input_get_fd, /* get_fd */ |
Eric Pouech | 465f3d1 | 2010-08-28 13:14:43 +0200 | [diff] [blame] | 83 | default_fd_map_access, /* map_access */ |
Rob Shearman | c1707d8 | 2007-10-03 13:10:37 +0100 | [diff] [blame] | 84 | default_get_sd, /* get_sd */ |
| 85 | default_set_sd, /* set_sd */ |
Vitaliy Margolen | baffcb9 | 2005-11-22 14:55:42 +0000 | [diff] [blame] | 86 | no_lookup_name, /* lookup_name */ |
Alexandre Julliard | 7e71c1d | 2007-03-22 11:44:29 +0100 | [diff] [blame] | 87 | no_open_file, /* open_file */ |
Alexandre Julliard | b9b1ea9 | 2005-06-09 15:39:52 +0000 | [diff] [blame] | 88 | no_close_handle, /* close_handle */ |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 89 | console_input_destroy /* destroy */ |
| 90 | }; |
| 91 | |
| 92 | static void console_input_events_dump( struct object *obj, int verbose ); |
| 93 | static void console_input_events_destroy( struct object *obj ); |
| 94 | static int console_input_events_signaled( struct object *obj, struct thread *thread ); |
| 95 | |
Vincent BĂ©ron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 96 | struct console_input_events |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 97 | { |
| 98 | struct object obj; /* object header */ |
| 99 | int num_alloc; /* number of allocated events */ |
| 100 | int num_used; /* number of actually used events */ |
| 101 | struct console_renderer_event* events; |
| 102 | }; |
| 103 | |
| 104 | static const struct object_ops console_input_events_ops = |
| 105 | { |
| 106 | sizeof(struct console_input_events), /* size */ |
| 107 | console_input_events_dump, /* dump */ |
Alexandre Julliard | 8382eb0 | 2007-12-05 18:16:42 +0100 | [diff] [blame] | 108 | no_get_type, /* get_type */ |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 109 | add_queue, /* add_queue */ |
| 110 | remove_queue, /* remove_queue */ |
| 111 | console_input_events_signaled, /* signaled */ |
| 112 | no_satisfied, /* satisfied */ |
Mike McCormack | f92fff6 | 2005-04-24 17:35:52 +0000 | [diff] [blame] | 113 | no_signal, /* signal */ |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 114 | no_get_fd, /* get_fd */ |
Eric Pouech | 465f3d1 | 2010-08-28 13:14:43 +0200 | [diff] [blame] | 115 | default_fd_map_access, /* map_access */ |
Rob Shearman | c1707d8 | 2007-10-03 13:10:37 +0100 | [diff] [blame] | 116 | default_get_sd, /* get_sd */ |
| 117 | default_set_sd, /* set_sd */ |
Vitaliy Margolen | baffcb9 | 2005-11-22 14:55:42 +0000 | [diff] [blame] | 118 | no_lookup_name, /* lookup_name */ |
Alexandre Julliard | 7e71c1d | 2007-03-22 11:44:29 +0100 | [diff] [blame] | 119 | no_open_file, /* open_file */ |
Alexandre Julliard | b9b1ea9 | 2005-06-09 15:39:52 +0000 | [diff] [blame] | 120 | no_close_handle, /* close_handle */ |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 121 | console_input_events_destroy /* destroy */ |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 122 | }; |
| 123 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 124 | struct screen_buffer |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 125 | { |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 126 | struct object obj; /* object header */ |
Alexandre Julliard | b2eff1c | 2005-02-25 21:06:11 +0000 | [diff] [blame] | 127 | struct list entry; /* entry in list of all screen buffers */ |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 128 | struct console_input *input; /* associated console input */ |
| 129 | int mode; /* output mode */ |
| 130 | int cursor_size; /* size of cursor (percentage filled) */ |
| 131 | int cursor_visible;/* cursor visibility flag */ |
| 132 | int cursor_x; /* position of cursor */ |
| 133 | int cursor_y; /* position of cursor */ |
| 134 | int width; /* size (w-h) of the screen buffer */ |
| 135 | int height; |
| 136 | int max_width; /* size (w-h) of the window given font size */ |
| 137 | int max_height; |
| 138 | char_info_t *data; /* the data for each cell - a width x height matrix */ |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 139 | unsigned short attr; /* default attribute for screen buffer */ |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 140 | rectangle_t win; /* current visible window on the screen buffer * |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 141 | * as seen in wineconsole */ |
Eric Pouech | 6f32644 | 2010-08-30 22:18:52 +0200 | [diff] [blame] | 142 | struct fd *fd; /* for bare console, attached output fd */ |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 143 | }; |
| 144 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 145 | static void screen_buffer_dump( struct object *obj, int verbose ); |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 146 | static void screen_buffer_destroy( struct object *obj ); |
Eric Pouech | 6f32644 | 2010-08-30 22:18:52 +0200 | [diff] [blame] | 147 | static struct fd *screen_buffer_get_fd( struct object *obj ); |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 148 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 149 | static const struct object_ops screen_buffer_ops = |
| 150 | { |
Alexandre Julliard | 1dca5e2 | 2000-01-01 00:56:27 +0000 | [diff] [blame] | 151 | sizeof(struct screen_buffer), /* size */ |
| 152 | screen_buffer_dump, /* dump */ |
Alexandre Julliard | 8382eb0 | 2007-12-05 18:16:42 +0100 | [diff] [blame] | 153 | no_get_type, /* get_type */ |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 154 | no_add_queue, /* add_queue */ |
| 155 | NULL, /* remove_queue */ |
| 156 | NULL, /* signaled */ |
| 157 | NULL, /* satisfied */ |
Mike McCormack | f92fff6 | 2005-04-24 17:35:52 +0000 | [diff] [blame] | 158 | no_signal, /* signal */ |
Eric Pouech | 6f32644 | 2010-08-30 22:18:52 +0200 | [diff] [blame] | 159 | screen_buffer_get_fd, /* get_fd */ |
Eric Pouech | 465f3d1 | 2010-08-28 13:14:43 +0200 | [diff] [blame] | 160 | default_fd_map_access, /* map_access */ |
Rob Shearman | c1707d8 | 2007-10-03 13:10:37 +0100 | [diff] [blame] | 161 | default_get_sd, /* get_sd */ |
| 162 | default_set_sd, /* set_sd */ |
Vitaliy Margolen | baffcb9 | 2005-11-22 14:55:42 +0000 | [diff] [blame] | 163 | no_lookup_name, /* lookup_name */ |
Alexandre Julliard | 7e71c1d | 2007-03-22 11:44:29 +0100 | [diff] [blame] | 164 | no_open_file, /* open_file */ |
Alexandre Julliard | b9b1ea9 | 2005-06-09 15:39:52 +0000 | [diff] [blame] | 165 | no_close_handle, /* close_handle */ |
Alexandre Julliard | 1dca5e2 | 2000-01-01 00:56:27 +0000 | [diff] [blame] | 166 | screen_buffer_destroy /* destroy */ |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 167 | }; |
| 168 | |
Eric Pouech | b39a8d9 | 2010-08-30 22:18:44 +0200 | [diff] [blame] | 169 | static enum server_fd_type console_get_fd_type( struct fd *fd ); |
| 170 | |
| 171 | static const struct fd_ops console_fd_ops = |
| 172 | { |
| 173 | default_fd_get_poll_events, /* get_poll_events */ |
| 174 | default_poll_event, /* poll_event */ |
| 175 | no_flush, /* flush */ |
| 176 | console_get_fd_type, /* get_fd_type */ |
| 177 | default_fd_ioctl, /* ioctl */ |
| 178 | default_fd_queue_async, /* queue_async */ |
| 179 | default_fd_reselect_async, /* reselect_async */ |
| 180 | default_fd_cancel_async /* cancel_async */ |
| 181 | }; |
| 182 | |
Alexandre Julliard | b2eff1c | 2005-02-25 21:06:11 +0000 | [diff] [blame] | 183 | static struct list screen_buffer_list = LIST_INIT(screen_buffer_list); |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 184 | |
Eric Pouech | a908756 | 2002-01-02 21:45:47 +0000 | [diff] [blame] | 185 | static const char_info_t empty_char_info = { ' ', 0x000f }; /* white on black space */ |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 186 | |
Eric Pouech | 4fdcdef | 2010-08-30 22:19:00 +0200 | [diff] [blame] | 187 | static int console_input_is_bare( struct console_input* cin ) |
| 188 | { |
| 189 | return cin->evt == NULL; |
| 190 | } |
| 191 | |
Eric Pouech | b39a8d9 | 2010-08-30 22:18:44 +0200 | [diff] [blame] | 192 | static struct fd *console_input_get_fd( struct object* obj ) |
| 193 | { |
| 194 | struct console_input *console_input = (struct console_input*)obj; |
| 195 | assert( obj->ops == &console_input_ops ); |
| 196 | return console_input->fd ? (struct fd*)grab_object( console_input->fd ) : NULL; |
| 197 | } |
| 198 | |
| 199 | static enum server_fd_type console_get_fd_type( struct fd *fd ) |
| 200 | { |
| 201 | return FD_TYPE_CHAR; |
| 202 | } |
| 203 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 204 | /* dumps the renderer events of a console */ |
| 205 | static void console_input_events_dump( struct object *obj, int verbose ) |
| 206 | { |
| 207 | struct console_input_events *evts = (struct console_input_events *)obj; |
| 208 | assert( obj->ops == &console_input_events_ops ); |
Vincent BĂ©ron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 209 | fprintf( stderr, "Console input events: %d/%d events\n", |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 210 | evts->num_used, evts->num_alloc ); |
| 211 | } |
| 212 | |
| 213 | /* destroys the renderer events of a console */ |
| 214 | static void console_input_events_destroy( struct object *obj ) |
| 215 | { |
| 216 | struct console_input_events *evts = (struct console_input_events *)obj; |
| 217 | assert( obj->ops == &console_input_events_ops ); |
| 218 | free( evts->events ); |
| 219 | } |
| 220 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 221 | /* the renderer events list is signaled when it's not empty */ |
| 222 | static int console_input_events_signaled( struct object *obj, struct thread *thread ) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 223 | { |
| 224 | struct console_input_events *evts = (struct console_input_events *)obj; |
| 225 | assert( obj->ops == &console_input_events_ops ); |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 226 | return (evts->num_used != 0); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 227 | } |
| 228 | |
| 229 | /* add an event to the console's renderer events list */ |
Eric Pouech | 2f7af56 | 2010-08-30 22:19:06 +0200 | [diff] [blame] | 230 | static void console_input_events_append( struct console_input* console, |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 231 | struct console_renderer_event* evt) |
| 232 | { |
Eric Pouech | 2f7af56 | 2010-08-30 22:19:06 +0200 | [diff] [blame] | 233 | struct console_input_events* evts; |
Eric Pouech | f4b298b | 2003-01-05 01:07:34 +0000 | [diff] [blame] | 234 | int collapsed = FALSE; |
| 235 | |
Eric Pouech | 2f7af56 | 2010-08-30 22:19:06 +0200 | [diff] [blame] | 236 | if (!(evts = console->evt)) return; |
Eric Pouech | b39a8d9 | 2010-08-30 22:18:44 +0200 | [diff] [blame] | 237 | /* to be done even when evt has been generated by the renderer ? */ |
Eric Pouech | f4b298b | 2003-01-05 01:07:34 +0000 | [diff] [blame] | 238 | |
| 239 | /* try to collapse evt into current queue's events */ |
| 240 | if (evts->num_used) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 241 | { |
Eric Pouech | f4b298b | 2003-01-05 01:07:34 +0000 | [diff] [blame] | 242 | struct console_renderer_event* last = &evts->events[evts->num_used - 1]; |
| 243 | |
| 244 | if (last->event == CONSOLE_RENDERER_UPDATE_EVENT && |
| 245 | evt->event == CONSOLE_RENDERER_UPDATE_EVENT) |
| 246 | { |
| 247 | /* if two update events overlap, collapse them into a single one */ |
| 248 | if (last->u.update.bottom + 1 >= evt->u.update.top && |
| 249 | evt->u.update.bottom + 1 >= last->u.update.top) |
| 250 | { |
| 251 | last->u.update.top = min(last->u.update.top, evt->u.update.top); |
| 252 | last->u.update.bottom = max(last->u.update.bottom, evt->u.update.bottom); |
| 253 | collapsed = TRUE; |
| 254 | } |
| 255 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 256 | } |
Eric Pouech | f4b298b | 2003-01-05 01:07:34 +0000 | [diff] [blame] | 257 | if (!collapsed) |
| 258 | { |
| 259 | if (evts->num_used == evts->num_alloc) |
| 260 | { |
| 261 | evts->num_alloc += 16; |
| 262 | evts->events = realloc( evts->events, evts->num_alloc * sizeof(*evt) ); |
| 263 | assert(evts->events); |
| 264 | } |
| 265 | evts->events[evts->num_used++] = *evt; |
| 266 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 267 | wake_up( &evts->obj, 0 ); |
| 268 | } |
| 269 | |
| 270 | /* retrieves events from the console's renderer events list */ |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 271 | static void console_input_events_get( struct console_input_events* evts ) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 272 | { |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 273 | data_size_t num = get_reply_max_size() / sizeof(evts->events[0]); |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 274 | |
| 275 | if (num > evts->num_used) num = evts->num_used; |
| 276 | set_reply_data( evts->events, num * sizeof(evts->events[0]) ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 277 | if (num < evts->num_used) |
| 278 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 279 | memmove( &evts->events[0], &evts->events[num], |
| 280 | (evts->num_used - num) * sizeof(evts->events[0]) ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 281 | } |
| 282 | evts->num_used -= num; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | static struct console_input_events *create_console_input_events(void) |
| 286 | { |
| 287 | struct console_input_events* evt; |
| 288 | |
Alexandre Julliard | e66207e | 2003-02-19 00:33:32 +0000 | [diff] [blame] | 289 | if (!(evt = alloc_object( &console_input_events_ops ))) return NULL; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 290 | evt->num_alloc = evt->num_used = 0; |
| 291 | evt->events = NULL; |
| 292 | return evt; |
| 293 | } |
| 294 | |
Eric Pouech | b39a8d9 | 2010-08-30 22:18:44 +0200 | [diff] [blame] | 295 | static struct object *create_console_input( struct thread* renderer, int fd ) |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 296 | { |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 297 | struct console_input *console_input; |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 298 | |
Alexandre Julliard | e66207e | 2003-02-19 00:33:32 +0000 | [diff] [blame] | 299 | if (!(console_input = alloc_object( &console_input_ops ))) return NULL; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 300 | console_input->renderer = renderer; |
| 301 | console_input->mode = ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT | |
| 302 | ENABLE_ECHO_INPUT | ENABLE_MOUSE_INPUT; |
| 303 | console_input->num_proc = 0; |
| 304 | console_input->active = NULL; |
| 305 | console_input->recnum = 0; |
| 306 | console_input->records = NULL; |
Eric Pouech | b39a8d9 | 2010-08-30 22:18:44 +0200 | [diff] [blame] | 307 | console_input->evt = renderer ? create_console_input_events() : NULL; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 308 | console_input->title = NULL; |
| 309 | console_input->history_size = 50; |
| 310 | console_input->history = calloc( console_input->history_size, sizeof(WCHAR*) ); |
| 311 | console_input->history_index = 0; |
| 312 | console_input->history_mode = 0; |
Eric Pouech | fa8b85a | 2003-01-09 06:01:32 +0000 | [diff] [blame] | 313 | console_input->edition_mode = 0; |
Kirill K. Smirnov | 9d74661 | 2007-05-10 21:19:47 +0400 | [diff] [blame] | 314 | console_input->input_cp = 0; |
| 315 | console_input->output_cp = 0; |
Kirill K. Smirnov | f3e1317 | 2007-08-23 19:17:17 +0400 | [diff] [blame] | 316 | console_input->win = 0; |
Rob Shearman | dd9e392 | 2007-10-24 16:04:42 +0100 | [diff] [blame] | 317 | console_input->event = create_event( NULL, NULL, 0, 1, 0, NULL ); |
Eric Pouech | b39a8d9 | 2010-08-30 22:18:44 +0200 | [diff] [blame] | 318 | console_input->fd = NULL; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 319 | |
Eric Pouech | b39a8d9 | 2010-08-30 22:18:44 +0200 | [diff] [blame] | 320 | if (!console_input->history || (renderer && !console_input->evt) || !console_input->event) |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 321 | { |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 322 | release_object( console_input ); |
| 323 | return NULL; |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 324 | } |
Eric Pouech | b39a8d9 | 2010-08-30 22:18:44 +0200 | [diff] [blame] | 325 | if (fd != -1) /* bare console */ |
| 326 | { |
Eric Pouech | b39a8d9 | 2010-08-30 22:18:44 +0200 | [diff] [blame] | 327 | if (!(console_input->fd = create_anonymous_fd( &console_fd_ops, fd, &console_input->obj, |
| 328 | FILE_SYNCHRONOUS_IO_NONALERT ))) |
| 329 | { |
| 330 | release_object( console_input ); |
| 331 | return NULL; |
| 332 | } |
Eric Pouech | b39a8d9 | 2010-08-30 22:18:44 +0200 | [diff] [blame] | 333 | allow_fd_caching( console_input->fd ); |
| 334 | } |
| 335 | |
Alexandre Julliard | 1dca5e2 | 2000-01-01 00:56:27 +0000 | [diff] [blame] | 336 | return &console_input->obj; |
Alexandre Julliard | 5bc7808 | 1999-06-22 17:26:53 +0000 | [diff] [blame] | 337 | } |
| 338 | |
Kirill K. Smirnov | 6e76cc7 | 2007-12-18 03:03:11 +0300 | [diff] [blame] | 339 | static void generate_sb_initial_events( struct console_input *console_input ) |
| 340 | { |
| 341 | struct screen_buffer *screen_buffer = console_input->active; |
| 342 | struct console_renderer_event evt; |
| 343 | |
| 344 | evt.event = CONSOLE_RENDERER_ACTIVE_SB_EVENT; |
| 345 | memset(&evt.u, 0, sizeof(evt.u)); |
Eric Pouech | 2f7af56 | 2010-08-30 22:19:06 +0200 | [diff] [blame] | 346 | console_input_events_append( console_input, &evt ); |
Kirill K. Smirnov | 6e76cc7 | 2007-12-18 03:03:11 +0300 | [diff] [blame] | 347 | |
| 348 | evt.event = CONSOLE_RENDERER_SB_RESIZE_EVENT; |
| 349 | evt.u.resize.width = screen_buffer->width; |
| 350 | evt.u.resize.height = screen_buffer->height; |
Eric Pouech | 2f7af56 | 2010-08-30 22:19:06 +0200 | [diff] [blame] | 351 | console_input_events_append( console_input, &evt ); |
Kirill K. Smirnov | 6e76cc7 | 2007-12-18 03:03:11 +0300 | [diff] [blame] | 352 | |
| 353 | evt.event = CONSOLE_RENDERER_DISPLAY_EVENT; |
| 354 | evt.u.display.left = screen_buffer->win.left; |
| 355 | evt.u.display.top = screen_buffer->win.top; |
| 356 | evt.u.display.width = screen_buffer->win.right - screen_buffer->win.left + 1; |
| 357 | evt.u.display.height = screen_buffer->win.bottom - screen_buffer->win.top + 1; |
Eric Pouech | 2f7af56 | 2010-08-30 22:19:06 +0200 | [diff] [blame] | 358 | console_input_events_append( console_input, &evt ); |
Kirill K. Smirnov | 6e76cc7 | 2007-12-18 03:03:11 +0300 | [diff] [blame] | 359 | |
| 360 | evt.event = CONSOLE_RENDERER_UPDATE_EVENT; |
| 361 | evt.u.update.top = 0; |
| 362 | evt.u.update.bottom = screen_buffer->height - 1; |
Eric Pouech | 2f7af56 | 2010-08-30 22:19:06 +0200 | [diff] [blame] | 363 | console_input_events_append( console_input, &evt ); |
Kirill K. Smirnov | 6e76cc7 | 2007-12-18 03:03:11 +0300 | [diff] [blame] | 364 | |
| 365 | evt.event = CONSOLE_RENDERER_CURSOR_GEOM_EVENT; |
| 366 | evt.u.cursor_geom.size = screen_buffer->cursor_size; |
| 367 | evt.u.cursor_geom.visible = screen_buffer->cursor_visible; |
Eric Pouech | 2f7af56 | 2010-08-30 22:19:06 +0200 | [diff] [blame] | 368 | console_input_events_append( console_input, &evt ); |
Kirill K. Smirnov | 6e76cc7 | 2007-12-18 03:03:11 +0300 | [diff] [blame] | 369 | |
| 370 | evt.event = CONSOLE_RENDERER_CURSOR_POS_EVENT; |
| 371 | evt.u.cursor_pos.x = screen_buffer->cursor_x; |
| 372 | evt.u.cursor_pos.y = screen_buffer->cursor_y; |
Eric Pouech | 2f7af56 | 2010-08-30 22:19:06 +0200 | [diff] [blame] | 373 | console_input_events_append( console_input, &evt ); |
Kirill K. Smirnov | 6e76cc7 | 2007-12-18 03:03:11 +0300 | [diff] [blame] | 374 | } |
| 375 | |
Eric Pouech | 6f32644 | 2010-08-30 22:18:52 +0200 | [diff] [blame] | 376 | static struct screen_buffer *create_console_output( struct console_input *console_input, int fd ) |
Alexandre Julliard | 5bc7808 | 1999-06-22 17:26:53 +0000 | [diff] [blame] | 377 | { |
Alexandre Julliard | 5bc7808 | 1999-06-22 17:26:53 +0000 | [diff] [blame] | 378 | struct screen_buffer *screen_buffer; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 379 | int i; |
Alexandre Julliard | 5bc7808 | 1999-06-22 17:26:53 +0000 | [diff] [blame] | 380 | |
Alexandre Julliard | e66207e | 2003-02-19 00:33:32 +0000 | [diff] [blame] | 381 | if (!(screen_buffer = alloc_object( &screen_buffer_ops ))) return NULL; |
Alexandre Julliard | 1dca5e2 | 2000-01-01 00:56:27 +0000 | [diff] [blame] | 382 | screen_buffer->mode = ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT; |
| 383 | screen_buffer->input = console_input; |
| 384 | screen_buffer->cursor_size = 100; |
| 385 | screen_buffer->cursor_visible = 1; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 386 | screen_buffer->width = 80; |
| 387 | screen_buffer->height = 150; |
| 388 | screen_buffer->max_width = 80; |
| 389 | screen_buffer->max_height = 25; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 390 | screen_buffer->cursor_x = 0; |
| 391 | screen_buffer->cursor_y = 0; |
Eric Pouech | a908756 | 2002-01-02 21:45:47 +0000 | [diff] [blame] | 392 | screen_buffer->attr = 0x0F; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 393 | screen_buffer->win.left = 0; |
| 394 | screen_buffer->win.right = screen_buffer->max_width - 1; |
| 395 | screen_buffer->win.top = 0; |
| 396 | screen_buffer->win.bottom = screen_buffer->max_height - 1; |
Eric Pouech | 6f32644 | 2010-08-30 22:18:52 +0200 | [diff] [blame] | 397 | if (fd == -1) |
| 398 | screen_buffer->fd = NULL; |
| 399 | else |
| 400 | { |
| 401 | if (!(screen_buffer->fd = create_anonymous_fd( &console_fd_ops, fd, &screen_buffer->obj, |
| 402 | FILE_SYNCHRONOUS_IO_NONALERT ))) |
| 403 | { |
| 404 | release_object( screen_buffer ); |
| 405 | return NULL; |
| 406 | } |
| 407 | allow_fd_caching(screen_buffer->fd); |
| 408 | } |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 409 | |
Alexandre Julliard | b2eff1c | 2005-02-25 21:06:11 +0000 | [diff] [blame] | 410 | list_add_head( &screen_buffer_list, &screen_buffer->entry ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 411 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 412 | if (!(screen_buffer->data = malloc( screen_buffer->width * screen_buffer->height * |
| 413 | sizeof(*screen_buffer->data) ))) |
| 414 | { |
| 415 | release_object( screen_buffer ); |
| 416 | return NULL; |
| 417 | } |
| 418 | /* clear the first row */ |
| 419 | for (i = 0; i < screen_buffer->width; i++) screen_buffer->data[i] = empty_char_info; |
| 420 | /* and copy it to all other rows */ |
| 421 | for (i = 1; i < screen_buffer->height; i++) |
| 422 | memcpy( &screen_buffer->data[i * screen_buffer->width], screen_buffer->data, |
| 423 | screen_buffer->width * sizeof(char_info_t) ); |
| 424 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 425 | if (!console_input->active) |
Alexandre Julliard | 039aa42 | 1999-06-11 18:31:22 +0000 | [diff] [blame] | 426 | { |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 427 | console_input->active = (struct screen_buffer*)grab_object( screen_buffer ); |
Kirill K. Smirnov | 6e76cc7 | 2007-12-18 03:03:11 +0300 | [diff] [blame] | 428 | generate_sb_initial_events( console_input ); |
Alexandre Julliard | 039aa42 | 1999-06-11 18:31:22 +0000 | [diff] [blame] | 429 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 430 | return screen_buffer; |
Alexandre Julliard | 039aa42 | 1999-06-11 18:31:22 +0000 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | /* free the console for this process */ |
| 434 | int free_console( struct process *process ) |
| 435 | { |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 436 | struct console_input* console = process->console; |
| 437 | |
Eric Pouech | b39a8d9 | 2010-08-30 22:18:44 +0200 | [diff] [blame] | 438 | if (!console) return 0; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 439 | |
| 440 | process->console = NULL; |
Eric Pouech | b39a8d9 | 2010-08-30 22:18:44 +0200 | [diff] [blame] | 441 | if (--console->num_proc == 0 && console->renderer) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 442 | { |
| 443 | /* all processes have terminated... tell the renderer to terminate too */ |
| 444 | struct console_renderer_event evt; |
| 445 | evt.event = CONSOLE_RENDERER_EXIT_EVENT; |
Eric Pouech | 2e0b533 | 2006-01-27 16:17:51 +0100 | [diff] [blame] | 446 | memset(&evt.u, 0, sizeof(evt.u)); |
Eric Pouech | 2f7af56 | 2010-08-30 22:19:06 +0200 | [diff] [blame] | 447 | console_input_events_append( console, &evt ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 448 | } |
| 449 | release_object( console ); |
| 450 | |
Alexandre Julliard | 039aa42 | 1999-06-11 18:31:22 +0000 | [diff] [blame] | 451 | return 1; |
| 452 | } |
| 453 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 454 | /* let process inherit the console from parent... this handle two cases : |
| 455 | * 1/ generic console inheritance |
| 456 | * 2/ parent is a renderer which launches process, and process should attach to the console |
| 457 | * renderered by parent |
| 458 | */ |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 459 | void inherit_console(struct thread *parent_thread, struct process *process, obj_handle_t hconin) |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 460 | { |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 461 | int done = 0; |
Eric Pouech | 3940d8a | 2001-12-04 20:17:43 +0000 | [diff] [blame] | 462 | struct process* parent = parent_thread->process; |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 463 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 464 | /* if parent is a renderer, then attach current process to its console |
| 465 | * a bit hacky.... |
| 466 | */ |
| 467 | if (hconin) |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 468 | { |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 469 | struct console_input* console; |
| 470 | |
Eric Pouech | 449d10f | 2003-08-19 01:05:17 +0000 | [diff] [blame] | 471 | /* FIXME: should we check some access rights ? */ |
| 472 | if ((console = (struct console_input*)get_handle_obj( parent, hconin, |
| 473 | 0, &console_input_ops ))) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 474 | { |
Eric Pouech | 449d10f | 2003-08-19 01:05:17 +0000 | [diff] [blame] | 475 | if (console->renderer == parent_thread) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 476 | { |
| 477 | process->console = (struct console_input*)grab_object( console ); |
| 478 | process->console->num_proc++; |
| 479 | done = 1; |
| 480 | } |
| 481 | release_object( console ); |
| 482 | } |
Alexandre Julliard | 01caa5e | 2005-07-12 20:27:09 +0000 | [diff] [blame] | 483 | else clear_error(); /* ignore error */ |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 484 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 485 | /* otherwise, if parent has a console, attach child to this console */ |
| 486 | if (!done && parent->console) |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 487 | { |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 488 | process->console = (struct console_input*)grab_object( parent->console ); |
| 489 | process->console->num_proc++; |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 490 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 491 | } |
| 492 | |
Alexandre Julliard | 627ca40 | 2007-05-11 12:46:32 +0200 | [diff] [blame] | 493 | struct thread *console_get_renderer( struct console_input *console ) |
| 494 | { |
| 495 | return console->renderer; |
| 496 | } |
| 497 | |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 498 | static struct console_input* console_input_get( obj_handle_t handle, unsigned access ) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 499 | { |
Robert Shearman | c516571 | 2005-05-25 18:41:09 +0000 | [diff] [blame] | 500 | struct console_input* console = NULL; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 501 | |
| 502 | if (handle) |
| 503 | console = (struct console_input *)get_handle_obj( current->process, handle, |
| 504 | access, &console_input_ops ); |
| 505 | else if (current->process->console) |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 506 | { |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 507 | console = (struct console_input *)grab_object( current->process->console ); |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 508 | } |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 509 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 510 | if (!console && !get_error()) set_error(STATUS_INVALID_PARAMETER); |
| 511 | return console; |
| 512 | } |
Alexandre Julliard | 57e1131 | 1999-05-16 16:59:38 +0000 | [diff] [blame] | 513 | |
Eric Pouech | 440ad8c | 2004-09-08 01:25:05 +0000 | [diff] [blame] | 514 | struct console_signal_info |
| 515 | { |
Eric Pouech | 93bfa0d | 2002-06-02 21:22:22 +0000 | [diff] [blame] | 516 | struct console_input *console; |
Alexandre Julliard | 54f2287 | 2002-10-03 19:54:57 +0000 | [diff] [blame] | 517 | process_id_t group; |
Eric Pouech | 93bfa0d | 2002-06-02 21:22:22 +0000 | [diff] [blame] | 518 | int signal; |
| 519 | }; |
| 520 | |
| 521 | static int propagate_console_signal_cb(struct process *process, void *user) |
| 522 | { |
| 523 | struct console_signal_info* csi = (struct console_signal_info*)user; |
| 524 | |
| 525 | if (process->console == csi->console && process->running_threads && |
Alexandre Julliard | 54f2287 | 2002-10-03 19:54:57 +0000 | [diff] [blame] | 526 | (!csi->group || process->group_id == csi->group)) |
Eric Pouech | 93bfa0d | 2002-06-02 21:22:22 +0000 | [diff] [blame] | 527 | { |
Eric Pouech | 440ad8c | 2004-09-08 01:25:05 +0000 | [diff] [blame] | 528 | /* find a suitable thread to signal */ |
| 529 | struct thread *thread; |
Alexandre Julliard | 0502638 | 2005-03-01 10:56:18 +0000 | [diff] [blame] | 530 | LIST_FOR_EACH_ENTRY( thread, &process->thread_list, struct thread, proc_entry ) |
Eric Pouech | 93bfa0d | 2002-06-02 21:22:22 +0000 | [diff] [blame] | 531 | { |
Eric Pouech | 440ad8c | 2004-09-08 01:25:05 +0000 | [diff] [blame] | 532 | if (send_thread_signal( thread, csi->signal )) break; |
Eric Pouech | 93bfa0d | 2002-06-02 21:22:22 +0000 | [diff] [blame] | 533 | } |
| 534 | } |
| 535 | return FALSE; |
| 536 | } |
| 537 | |
Andreas Mohr | 17a2fe0 | 2002-07-01 23:22:48 +0000 | [diff] [blame] | 538 | static void propagate_console_signal( struct console_input *console, |
Alexandre Julliard | 54f2287 | 2002-10-03 19:54:57 +0000 | [diff] [blame] | 539 | int sig, process_id_t group_id ) |
Eric Pouech | 93bfa0d | 2002-06-02 21:22:22 +0000 | [diff] [blame] | 540 | { |
| 541 | struct console_signal_info csi; |
| 542 | |
| 543 | if (!console) |
| 544 | { |
| 545 | set_error( STATUS_INVALID_PARAMETER ); |
| 546 | return; |
| 547 | } |
| 548 | /* FIXME: should support the other events (like CTRL_BREAK) */ |
| 549 | if (sig != CTRL_C_EVENT) |
| 550 | { |
| 551 | set_error( STATUS_NOT_IMPLEMENTED ); |
| 552 | return; |
| 553 | } |
| 554 | csi.console = console; |
| 555 | csi.signal = SIGINT; |
| 556 | csi.group = group_id; |
| 557 | |
| 558 | enum_processes(propagate_console_signal_cb, &csi); |
| 559 | } |
| 560 | |
Eric Pouech | 4fdcdef | 2010-08-30 22:19:00 +0200 | [diff] [blame] | 561 | static int get_console_mode( obj_handle_t handle, int *bare ) |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 562 | { |
| 563 | struct object *obj; |
| 564 | int ret = 0; |
| 565 | |
Eric Pouech | 465f3d1 | 2010-08-28 13:14:43 +0200 | [diff] [blame] | 566 | if ((obj = get_handle_obj( current->process, handle, FILE_READ_PROPERTIES, NULL ))) |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 567 | { |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 568 | if (obj->ops == &console_input_ops) |
Eric Pouech | 4fdcdef | 2010-08-30 22:19:00 +0200 | [diff] [blame] | 569 | { |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 570 | ret = ((struct console_input *)obj)->mode; |
Eric Pouech | 4fdcdef | 2010-08-30 22:19:00 +0200 | [diff] [blame] | 571 | *bare = console_input_is_bare((struct console_input *)obj); |
| 572 | } |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 573 | else if (obj->ops == &screen_buffer_ops) |
Eric Pouech | 4fdcdef | 2010-08-30 22:19:00 +0200 | [diff] [blame] | 574 | { |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 575 | ret = ((struct screen_buffer *)obj)->mode; |
Eric Pouech | 4fdcdef | 2010-08-30 22:19:00 +0200 | [diff] [blame] | 576 | *bare = console_input_is_bare(((struct screen_buffer *)obj)->input); |
| 577 | } |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 578 | else |
Alexandre Julliard | cb1fc73 | 2000-01-24 21:58:06 +0000 | [diff] [blame] | 579 | set_error( STATUS_OBJECT_TYPE_MISMATCH ); |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 580 | release_object( obj ); |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 581 | } |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 582 | return ret; |
| 583 | } |
| 584 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 585 | /* changes the mode of either a console input or a screen buffer */ |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 586 | static int set_console_mode( obj_handle_t handle, int mode ) |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 587 | { |
| 588 | struct object *obj; |
| 589 | int ret = 0; |
| 590 | |
Eric Pouech | 465f3d1 | 2010-08-28 13:14:43 +0200 | [diff] [blame] | 591 | if (!(obj = get_handle_obj( current->process, handle, FILE_WRITE_PROPERTIES, NULL ))) |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 592 | return 0; |
| 593 | if (obj->ops == &console_input_ops) |
| 594 | { |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 595 | /* FIXME: if we remove the edit mode bits, we need (???) to clean up the history */ |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 596 | ((struct console_input *)obj)->mode = mode; |
| 597 | ret = 1; |
| 598 | } |
| 599 | else if (obj->ops == &screen_buffer_ops) |
| 600 | { |
| 601 | ((struct screen_buffer *)obj)->mode = mode; |
| 602 | ret = 1; |
| 603 | } |
Alexandre Julliard | cb1fc73 | 2000-01-24 21:58:06 +0000 | [diff] [blame] | 604 | else set_error( STATUS_OBJECT_TYPE_MISMATCH ); |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 605 | release_object( obj ); |
| 606 | return ret; |
| 607 | } |
| 608 | |
Alexandre Julliard | 4b46112 | 1999-01-31 19:04:30 +0000 | [diff] [blame] | 609 | /* add input events to a console input queue */ |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 610 | static int write_console_input( struct console_input* console, int count, |
| 611 | const INPUT_RECORD *records ) |
Alexandre Julliard | 4b46112 | 1999-01-31 19:04:30 +0000 | [diff] [blame] | 612 | { |
| 613 | INPUT_RECORD *new_rec; |
Alexandre Julliard | 4b46112 | 1999-01-31 19:04:30 +0000 | [diff] [blame] | 614 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 615 | if (!count) return 0; |
Alexandre Julliard | 4b46112 | 1999-01-31 19:04:30 +0000 | [diff] [blame] | 616 | if (!(new_rec = realloc( console->records, |
| 617 | (console->recnum + count) * sizeof(INPUT_RECORD) ))) |
| 618 | { |
Alexandre Julliard | cb1fc73 | 2000-01-24 21:58:06 +0000 | [diff] [blame] | 619 | set_error( STATUS_NO_MEMORY ); |
Alexandre Julliard | 4b46112 | 1999-01-31 19:04:30 +0000 | [diff] [blame] | 620 | release_object( console ); |
| 621 | return -1; |
| 622 | } |
| 623 | console->records = new_rec; |
| 624 | memcpy( new_rec + console->recnum, records, count * sizeof(INPUT_RECORD) ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 625 | |
Eric Pouech | 93bfa0d | 2002-06-02 21:22:22 +0000 | [diff] [blame] | 626 | if (console->mode & ENABLE_PROCESSED_INPUT) |
| 627 | { |
| 628 | int i = 0; |
| 629 | while (i < count) |
| 630 | { |
Andreas Mohr | 17a2fe0 | 2002-07-01 23:22:48 +0000 | [diff] [blame] | 631 | if (records[i].EventType == KEY_EVENT && |
Eric Pouech | 93bfa0d | 2002-06-02 21:22:22 +0000 | [diff] [blame] | 632 | records[i].Event.KeyEvent.uChar.UnicodeChar == 'C' - 64 && |
| 633 | !(records[i].Event.KeyEvent.dwControlKeyState & ENHANCED_KEY)) |
| 634 | { |
| 635 | if (i != count - 1) |
Andreas Mohr | 17a2fe0 | 2002-07-01 23:22:48 +0000 | [diff] [blame] | 636 | memcpy( &console->records[console->recnum + i], |
| 637 | &console->records[console->recnum + i + 1], |
Eric Pouech | 93bfa0d | 2002-06-02 21:22:22 +0000 | [diff] [blame] | 638 | (count - i - 1) * sizeof(INPUT_RECORD) ); |
| 639 | count--; |
| 640 | if (records[i].Event.KeyEvent.bKeyDown) |
| 641 | { |
| 642 | /* send SIGINT to all processes attached to this console */ |
Alexandre Julliard | 54f2287 | 2002-10-03 19:54:57 +0000 | [diff] [blame] | 643 | propagate_console_signal( console, CTRL_C_EVENT, 0 ); |
Eric Pouech | 93bfa0d | 2002-06-02 21:22:22 +0000 | [diff] [blame] | 644 | } |
| 645 | } |
| 646 | else i++; |
| 647 | } |
| 648 | } |
Eric Pouech | a86a289 | 2003-06-23 03:37:14 +0000 | [diff] [blame] | 649 | if (!console->recnum && count) set_event( console->event ); |
Eric Pouech | 93bfa0d | 2002-06-02 21:22:22 +0000 | [diff] [blame] | 650 | console->recnum += count; |
Alexandre Julliard | 4b46112 | 1999-01-31 19:04:30 +0000 | [diff] [blame] | 651 | return count; |
| 652 | } |
| 653 | |
| 654 | /* retrieve a pointer to the console input records */ |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 655 | static int read_console_input( obj_handle_t handle, int count, int flush ) |
Alexandre Julliard | 4b46112 | 1999-01-31 19:04:30 +0000 | [diff] [blame] | 656 | { |
| 657 | struct console_input *console; |
| 658 | |
| 659 | if (!(console = (struct console_input *)get_handle_obj( current->process, handle, |
Eric Pouech | 465f3d1 | 2010-08-28 13:14:43 +0200 | [diff] [blame] | 660 | FILE_READ_DATA, &console_input_ops ))) |
Alexandre Julliard | 4b46112 | 1999-01-31 19:04:30 +0000 | [diff] [blame] | 661 | return -1; |
Alexandre Julliard | 9264300 | 2000-08-31 01:59:51 +0000 | [diff] [blame] | 662 | |
| 663 | if (!count) |
| 664 | { |
| 665 | /* special case: do not retrieve anything, but return |
| 666 | * the total number of records available */ |
| 667 | count = console->recnum; |
| 668 | } |
| 669 | else |
| 670 | { |
| 671 | if (count > console->recnum) count = console->recnum; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 672 | set_reply_data( console->records, count * sizeof(INPUT_RECORD) ); |
Alexandre Julliard | 9264300 | 2000-08-31 01:59:51 +0000 | [diff] [blame] | 673 | } |
Alexandre Julliard | 4b46112 | 1999-01-31 19:04:30 +0000 | [diff] [blame] | 674 | if (flush) |
| 675 | { |
| 676 | int i; |
| 677 | for (i = count; i < console->recnum; i++) |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 678 | console->records[i-count] = console->records[i]; |
Alexandre Julliard | 4b46112 | 1999-01-31 19:04:30 +0000 | [diff] [blame] | 679 | if ((console->recnum -= count) > 0) |
| 680 | { |
| 681 | INPUT_RECORD *new_rec = realloc( console->records, |
| 682 | console->recnum * sizeof(INPUT_RECORD) ); |
| 683 | if (new_rec) console->records = new_rec; |
| 684 | } |
| 685 | else |
| 686 | { |
| 687 | free( console->records ); |
| 688 | console->records = NULL; |
Eric Pouech | a86a289 | 2003-06-23 03:37:14 +0000 | [diff] [blame] | 689 | reset_event( console->event ); |
Alexandre Julliard | 4b46112 | 1999-01-31 19:04:30 +0000 | [diff] [blame] | 690 | } |
| 691 | } |
| 692 | release_object( console ); |
| 693 | return count; |
| 694 | } |
| 695 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 696 | /* set misc console input information */ |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 697 | static int set_console_input_info( const struct set_console_input_info_request *req, |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 698 | const WCHAR *title, data_size_t len ) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 699 | { |
| 700 | struct console_input *console; |
| 701 | struct console_renderer_event evt; |
| 702 | |
Eric Pouech | 465f3d1 | 2010-08-28 13:14:43 +0200 | [diff] [blame] | 703 | if (!(console = console_input_get( req->handle, FILE_WRITE_PROPERTIES ))) goto error; |
Eric Pouech | daaee9e | 2010-08-30 22:19:12 +0200 | [diff] [blame] | 704 | if (console_input_is_bare(console) && |
| 705 | (req->mask & (SET_CONSOLE_INPUT_INFO_ACTIVE_SB| |
| 706 | SET_CONSOLE_INPUT_INFO_WIN))) |
| 707 | { |
| 708 | set_error( STATUS_UNSUCCESSFUL ); |
| 709 | goto error; |
| 710 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 711 | |
Eric Pouech | 2e0b533 | 2006-01-27 16:17:51 +0100 | [diff] [blame] | 712 | memset(&evt.u, 0, sizeof(evt.u)); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 713 | if (req->mask & SET_CONSOLE_INPUT_INFO_ACTIVE_SB) |
| 714 | { |
| 715 | struct screen_buffer *screen_buffer; |
| 716 | |
Vincent BĂ©ron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 717 | screen_buffer = (struct screen_buffer *)get_handle_obj( current->process, req->active_sb, |
Eric Pouech | 465f3d1 | 2010-08-28 13:14:43 +0200 | [diff] [blame] | 718 | FILE_WRITE_PROPERTIES, &screen_buffer_ops ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 719 | if (!screen_buffer || screen_buffer->input != console) |
| 720 | { |
Kirill K. Smirnov | 545d7f1 | 2007-05-09 20:56:29 +0400 | [diff] [blame] | 721 | set_error( STATUS_INVALID_HANDLE ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 722 | if (screen_buffer) release_object( screen_buffer ); |
| 723 | goto error; |
| 724 | } |
| 725 | |
| 726 | if (screen_buffer != console->active) |
| 727 | { |
| 728 | if (console->active) release_object( console->active ); |
| 729 | console->active = screen_buffer; |
Kirill K. Smirnov | 6e76cc7 | 2007-12-18 03:03:11 +0300 | [diff] [blame] | 730 | generate_sb_initial_events( console ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 731 | } |
| 732 | else |
| 733 | release_object( screen_buffer ); |
| 734 | } |
| 735 | if (req->mask & SET_CONSOLE_INPUT_INFO_TITLE) |
| 736 | { |
| 737 | WCHAR *new_title = mem_alloc( len + sizeof(WCHAR) ); |
| 738 | if (new_title) |
| 739 | { |
Eric Pouech | 5871174 | 2003-02-19 23:27:49 +0000 | [diff] [blame] | 740 | memcpy( new_title, title, len ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 741 | new_title[len / sizeof(WCHAR)] = 0; |
Michael Stefaniuc | 5ceccec | 2006-10-09 23:34:36 +0200 | [diff] [blame] | 742 | free( console->title ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 743 | console->title = new_title; |
Eric Pouech | 47205b8 | 2002-05-11 22:53:56 +0000 | [diff] [blame] | 744 | evt.event = CONSOLE_RENDERER_TITLE_EVENT; |
Eric Pouech | 2f7af56 | 2010-08-30 22:19:06 +0200 | [diff] [blame] | 745 | console_input_events_append( console, &evt ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 746 | } |
| 747 | } |
| 748 | if (req->mask & SET_CONSOLE_INPUT_INFO_HISTORY_MODE) |
| 749 | { |
| 750 | console->history_mode = req->history_mode; |
| 751 | } |
Vincent BĂ©ron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 752 | if ((req->mask & SET_CONSOLE_INPUT_INFO_HISTORY_SIZE) && |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 753 | console->history_size != req->history_size) |
| 754 | { |
| 755 | WCHAR** mem = NULL; |
| 756 | int i; |
| 757 | int delta; |
| 758 | |
| 759 | if (req->history_size) |
| 760 | { |
| 761 | mem = mem_alloc( req->history_size * sizeof(WCHAR*) ); |
| 762 | if (!mem) goto error; |
| 763 | memset( mem, 0, req->history_size * sizeof(WCHAR*) ); |
| 764 | } |
| 765 | |
Vincent BĂ©ron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 766 | delta = (console->history_index > req->history_size) ? |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 767 | (console->history_index - req->history_size) : 0; |
| 768 | |
| 769 | for (i = delta; i < console->history_index; i++) |
| 770 | { |
| 771 | mem[i - delta] = console->history[i]; |
| 772 | console->history[i] = NULL; |
| 773 | } |
| 774 | console->history_index -= delta; |
| 775 | |
| 776 | for (i = 0; i < console->history_size; i++) |
Lionel Debroux | 2f89fe7 | 2007-10-20 09:35:13 +0200 | [diff] [blame] | 777 | free( console->history[i] ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 778 | free( console->history ); |
| 779 | console->history = mem; |
| 780 | console->history_size = req->history_size; |
| 781 | } |
Eric Pouech | fa8b85a | 2003-01-09 06:01:32 +0000 | [diff] [blame] | 782 | if (req->mask & SET_CONSOLE_INPUT_INFO_EDITION_MODE) |
| 783 | { |
| 784 | console->edition_mode = req->edition_mode; |
| 785 | } |
Kirill K. Smirnov | 9d74661 | 2007-05-10 21:19:47 +0400 | [diff] [blame] | 786 | if (req->mask & SET_CONSOLE_INPUT_INFO_INPUT_CODEPAGE) |
| 787 | { |
| 788 | console->input_cp = req->input_cp; |
| 789 | } |
| 790 | if (req->mask & SET_CONSOLE_INPUT_INFO_OUTPUT_CODEPAGE) |
| 791 | { |
| 792 | console->output_cp = req->output_cp; |
| 793 | } |
Kirill K. Smirnov | f3e1317 | 2007-08-23 19:17:17 +0400 | [diff] [blame] | 794 | if (req->mask & SET_CONSOLE_INPUT_INFO_WIN) |
| 795 | { |
| 796 | console->win = req->win; |
| 797 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 798 | release_object( console ); |
| 799 | return 1; |
| 800 | error: |
| 801 | if (console) release_object( console ); |
| 802 | return 0; |
| 803 | } |
| 804 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 805 | /* resize a screen buffer */ |
| 806 | static int change_screen_buffer_size( struct screen_buffer *screen_buffer, |
| 807 | int new_width, int new_height ) |
| 808 | { |
| 809 | int i, old_width, old_height, copy_width, copy_height; |
| 810 | char_info_t *new_data; |
| 811 | |
| 812 | if (!(new_data = malloc( new_width * new_height * sizeof(*new_data) ))) |
| 813 | { |
| 814 | set_error( STATUS_NO_MEMORY ); |
| 815 | return 0; |
| 816 | } |
| 817 | old_width = screen_buffer->width; |
| 818 | old_height = screen_buffer->height; |
| 819 | copy_width = min( old_width, new_width ); |
| 820 | copy_height = min( old_height, new_height ); |
| 821 | |
| 822 | /* copy all the rows */ |
| 823 | for (i = 0; i < copy_height; i++) |
| 824 | { |
| 825 | memcpy( &new_data[i * new_width], &screen_buffer->data[i * old_width], |
| 826 | copy_width * sizeof(char_info_t) ); |
| 827 | } |
| 828 | |
| 829 | /* clear the end of each row */ |
| 830 | if (new_width > old_width) |
| 831 | { |
| 832 | /* fill first row */ |
| 833 | for (i = old_width; i < new_width; i++) new_data[i] = empty_char_info; |
| 834 | /* and blast it to the other rows */ |
| 835 | for (i = 1; i < copy_height; i++) |
| 836 | memcpy( &new_data[i * new_width + old_width], &new_data[old_width], |
| 837 | (new_width - old_width) * sizeof(char_info_t) ); |
| 838 | } |
| 839 | |
| 840 | /* clear remaining rows */ |
| 841 | if (new_height > old_height) |
| 842 | { |
| 843 | /* fill first row */ |
| 844 | for (i = 0; i < new_width; i++) new_data[old_height * new_width + i] = empty_char_info; |
| 845 | /* and blast it to the other rows */ |
| 846 | for (i = old_height+1; i < new_height; i++) |
| 847 | memcpy( &new_data[i * new_width], &new_data[old_height * new_width], |
| 848 | new_width * sizeof(char_info_t) ); |
| 849 | } |
| 850 | free( screen_buffer->data ); |
| 851 | screen_buffer->data = new_data; |
| 852 | screen_buffer->width = new_width; |
| 853 | screen_buffer->height = new_height; |
| 854 | return 1; |
| 855 | } |
| 856 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 857 | /* set misc screen buffer information */ |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 858 | static int set_console_output_info( struct screen_buffer *screen_buffer, |
| 859 | const struct set_console_output_info_request *req ) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 860 | { |
| 861 | struct console_renderer_event evt; |
| 862 | |
Eric Pouech | 2e0b533 | 2006-01-27 16:17:51 +0100 | [diff] [blame] | 863 | memset(&evt.u, 0, sizeof(evt.u)); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 864 | if (req->mask & SET_CONSOLE_OUTPUT_INFO_CURSOR_GEOM) |
| 865 | { |
| 866 | if (req->cursor_size < 1 || req->cursor_size > 100) |
| 867 | { |
| 868 | set_error( STATUS_INVALID_PARAMETER ); |
| 869 | return 0; |
| 870 | } |
Vincent BĂ©ron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 871 | if (screen_buffer->cursor_size != req->cursor_size || |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 872 | screen_buffer->cursor_visible != req->cursor_visible) |
| 873 | { |
| 874 | screen_buffer->cursor_size = req->cursor_size; |
| 875 | screen_buffer->cursor_visible = req->cursor_visible; |
| 876 | evt.event = CONSOLE_RENDERER_CURSOR_GEOM_EVENT; |
| 877 | evt.u.cursor_geom.size = req->cursor_size; |
| 878 | evt.u.cursor_geom.visible = req->cursor_visible; |
Eric Pouech | 2f7af56 | 2010-08-30 22:19:06 +0200 | [diff] [blame] | 879 | console_input_events_append( screen_buffer->input, &evt ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 880 | } |
| 881 | } |
| 882 | if (req->mask & SET_CONSOLE_OUTPUT_INFO_CURSOR_POS) |
| 883 | { |
Vincent BĂ©ron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 884 | if (req->cursor_x < 0 || req->cursor_x >= screen_buffer->width || |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 885 | req->cursor_y < 0 || req->cursor_y >= screen_buffer->height) |
| 886 | { |
| 887 | set_error( STATUS_INVALID_PARAMETER ); |
| 888 | return 0; |
| 889 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 890 | if (screen_buffer->cursor_x != req->cursor_x || screen_buffer->cursor_y != req->cursor_y) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 891 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 892 | screen_buffer->cursor_x = req->cursor_x; |
| 893 | screen_buffer->cursor_y = req->cursor_y; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 894 | evt.event = CONSOLE_RENDERER_CURSOR_POS_EVENT; |
| 895 | evt.u.cursor_pos.x = req->cursor_x; |
| 896 | evt.u.cursor_pos.y = req->cursor_y; |
Eric Pouech | 2f7af56 | 2010-08-30 22:19:06 +0200 | [diff] [blame] | 897 | console_input_events_append( screen_buffer->input, &evt ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 898 | } |
| 899 | } |
| 900 | if (req->mask & SET_CONSOLE_OUTPUT_INFO_SIZE) |
| 901 | { |
Eric Pouech | f4b298b | 2003-01-05 01:07:34 +0000 | [diff] [blame] | 902 | unsigned cc; |
| 903 | |
| 904 | /* new screen-buffer cannot be smaller than actual window */ |
| 905 | if (req->width < screen_buffer->win.right - screen_buffer->win.left + 1 || |
| 906 | req->height < screen_buffer->win.bottom - screen_buffer->win.top + 1) |
| 907 | { |
| 908 | set_error( STATUS_INVALID_PARAMETER ); |
| 909 | return 0; |
| 910 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 911 | /* FIXME: there are also some basic minimum and max size to deal with */ |
| 912 | if (!change_screen_buffer_size( screen_buffer, req->width, req->height )) return 0; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 913 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 914 | evt.event = CONSOLE_RENDERER_SB_RESIZE_EVENT; |
| 915 | evt.u.resize.width = req->width; |
| 916 | evt.u.resize.height = req->height; |
Eric Pouech | 2f7af56 | 2010-08-30 22:19:06 +0200 | [diff] [blame] | 917 | console_input_events_append( screen_buffer->input, &evt ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 918 | |
Eric Pouech | f4b298b | 2003-01-05 01:07:34 +0000 | [diff] [blame] | 919 | evt.event = CONSOLE_RENDERER_UPDATE_EVENT; |
| 920 | evt.u.update.top = 0; |
| 921 | evt.u.update.bottom = screen_buffer->height - 1; |
Eric Pouech | 2f7af56 | 2010-08-30 22:19:06 +0200 | [diff] [blame] | 922 | console_input_events_append( screen_buffer->input, &evt ); |
Eric Pouech | f4b298b | 2003-01-05 01:07:34 +0000 | [diff] [blame] | 923 | |
| 924 | /* scroll window to display sb */ |
| 925 | if (screen_buffer->win.right >= req->width) |
| 926 | { |
| 927 | screen_buffer->win.right -= screen_buffer->win.left; |
| 928 | screen_buffer->win.left = 0; |
| 929 | } |
| 930 | if (screen_buffer->win.bottom >= req->height) |
| 931 | { |
| 932 | screen_buffer->win.bottom -= screen_buffer->win.top; |
| 933 | screen_buffer->win.top = 0; |
| 934 | } |
| 935 | /* reset cursor if needed (normally, if cursor was outside of new sb, the |
| 936 | * window has been shifted so that the new position of the cursor will be |
| 937 | * visible */ |
| 938 | cc = 0; |
| 939 | if (screen_buffer->cursor_x >= req->width) |
| 940 | { |
| 941 | screen_buffer->cursor_x = req->width - 1; |
| 942 | cc++; |
| 943 | } |
| 944 | if (screen_buffer->cursor_y >= req->height) |
| 945 | { |
| 946 | screen_buffer->cursor_y = req->height - 1; |
| 947 | cc++; |
| 948 | } |
| 949 | if (cc) |
| 950 | { |
| 951 | evt.event = CONSOLE_RENDERER_CURSOR_POS_EVENT; |
| 952 | evt.u.cursor_pos.x = req->cursor_x; |
| 953 | evt.u.cursor_pos.y = req->cursor_y; |
Eric Pouech | 2f7af56 | 2010-08-30 22:19:06 +0200 | [diff] [blame] | 954 | console_input_events_append( screen_buffer->input, &evt ); |
Eric Pouech | f4b298b | 2003-01-05 01:07:34 +0000 | [diff] [blame] | 955 | } |
| 956 | |
Vincent BĂ©ron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 957 | if (screen_buffer == screen_buffer->input->active && |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 958 | screen_buffer->input->mode & ENABLE_WINDOW_INPUT) |
| 959 | { |
| 960 | INPUT_RECORD ir; |
| 961 | ir.EventType = WINDOW_BUFFER_SIZE_EVENT; |
| 962 | ir.Event.WindowBufferSizeEvent.dwSize.X = req->width; |
| 963 | ir.Event.WindowBufferSizeEvent.dwSize.Y = req->height; |
| 964 | write_console_input( screen_buffer->input, 1, &ir ); |
| 965 | } |
| 966 | } |
| 967 | if (req->mask & SET_CONSOLE_OUTPUT_INFO_ATTR) |
| 968 | { |
| 969 | screen_buffer->attr = req->attr; |
| 970 | } |
| 971 | if (req->mask & SET_CONSOLE_OUTPUT_INFO_DISPLAY_WINDOW) |
| 972 | { |
Vincent BĂ©ron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 973 | if (req->win_left < 0 || req->win_left > req->win_right || |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 974 | req->win_right >= screen_buffer->width || |
Vincent BĂ©ron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 975 | req->win_top < 0 || req->win_top > req->win_bottom || |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 976 | req->win_bottom >= screen_buffer->height) |
| 977 | { |
| 978 | set_error( STATUS_INVALID_PARAMETER ); |
| 979 | return 0; |
| 980 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 981 | if (screen_buffer->win.left != req->win_left || screen_buffer->win.top != req->win_top || |
| 982 | screen_buffer->win.right != req->win_right || screen_buffer->win.bottom != req->win_bottom) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 983 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 984 | screen_buffer->win.left = req->win_left; |
| 985 | screen_buffer->win.top = req->win_top; |
| 986 | screen_buffer->win.right = req->win_right; |
| 987 | screen_buffer->win.bottom = req->win_bottom; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 988 | evt.event = CONSOLE_RENDERER_DISPLAY_EVENT; |
| 989 | evt.u.display.left = req->win_left; |
| 990 | evt.u.display.top = req->win_top; |
| 991 | evt.u.display.width = req->win_right - req->win_left + 1; |
| 992 | evt.u.display.height = req->win_bottom - req->win_top + 1; |
Eric Pouech | 2f7af56 | 2010-08-30 22:19:06 +0200 | [diff] [blame] | 993 | console_input_events_append( screen_buffer->input, &evt ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 994 | } |
| 995 | } |
| 996 | if (req->mask & SET_CONSOLE_OUTPUT_INFO_MAX_SIZE) |
| 997 | { |
| 998 | /* can only be done by renderer */ |
| 999 | if (current->process->console != screen_buffer->input) |
| 1000 | { |
| 1001 | set_error( STATUS_INVALID_PARAMETER ); |
| 1002 | return 0; |
| 1003 | } |
| 1004 | |
| 1005 | screen_buffer->max_width = req->max_width; |
| 1006 | screen_buffer->max_height = req->max_height; |
| 1007 | } |
| 1008 | |
| 1009 | return 1; |
| 1010 | } |
| 1011 | |
| 1012 | /* appends a new line to history (history is a fixed size array) */ |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 1013 | static void console_input_append_hist( struct console_input* console, const WCHAR* buf, data_size_t len ) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1014 | { |
| 1015 | WCHAR* ptr = mem_alloc( (len + 1) * sizeof(WCHAR) ); |
| 1016 | |
| 1017 | if (!ptr) |
Robert Shearman | 7a3df4d | 2006-04-07 11:17:12 +0100 | [diff] [blame] | 1018 | return; |
| 1019 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1020 | if (!console || !console->history_size) |
| 1021 | { |
| 1022 | set_error( STATUS_INVALID_PARAMETER ); /* FIXME */ |
Robert Shearman | 7a3df4d | 2006-04-07 11:17:12 +0100 | [diff] [blame] | 1023 | free( ptr ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1024 | return; |
| 1025 | } |
| 1026 | |
| 1027 | memcpy( ptr, buf, len * sizeof(WCHAR) ); |
| 1028 | ptr[len] = 0; |
| 1029 | |
| 1030 | if (console->history_mode && console->history_index && |
| 1031 | strncmpW( console->history[console->history_index - 1], ptr, len * sizeof(WCHAR) ) == 0) |
| 1032 | { |
| 1033 | /* ok, mode ask us to not use twice the same string... |
| 1034 | * so just free mem and returns |
| 1035 | */ |
| 1036 | set_error( STATUS_ALIAS_EXISTS ); |
| 1037 | free(ptr); |
| 1038 | return; |
| 1039 | } |
| 1040 | |
| 1041 | if (console->history_index < console->history_size) |
| 1042 | { |
| 1043 | console->history[console->history_index++] = ptr; |
| 1044 | } |
| 1045 | else |
| 1046 | { |
| 1047 | free( console->history[0]) ; |
Vincent BĂ©ron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1048 | memmove( &console->history[0], &console->history[1], |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1049 | (console->history_size - 1) * sizeof(WCHAR*) ); |
| 1050 | console->history[console->history_size - 1] = ptr; |
| 1051 | } |
| 1052 | } |
| 1053 | |
Eric Pouech | f4b298b | 2003-01-05 01:07:34 +0000 | [diff] [blame] | 1054 | /* returns a line from the cache */ |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 1055 | static data_size_t console_input_get_hist( struct console_input *console, int index ) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1056 | { |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 1057 | data_size_t ret = 0; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1058 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1059 | if (index >= console->history_index) set_error( STATUS_INVALID_PARAMETER ); |
| 1060 | else |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1061 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1062 | ret = strlenW( console->history[index] ) * sizeof(WCHAR); |
| 1063 | set_reply_data( console->history[index], min( ret, get_reply_max_size() )); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1064 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1065 | return ret; |
| 1066 | } |
| 1067 | |
| 1068 | /* dumb dump */ |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 1069 | static void console_input_dump( struct object *obj, int verbose ) |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 1070 | { |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 1071 | struct console_input *console = (struct console_input *)obj; |
| 1072 | assert( obj->ops == &console_input_ops ); |
Vincent BĂ©ron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1073 | fprintf( stderr, "Console input active=%p evt=%p\n", |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1074 | console->active, console->evt ); |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 1075 | } |
| 1076 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 1077 | static void console_input_destroy( struct object *obj ) |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 1078 | { |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1079 | struct console_input* console_in = (struct console_input *)obj; |
| 1080 | struct screen_buffer* curr; |
| 1081 | int i; |
| 1082 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 1083 | assert( obj->ops == &console_input_ops ); |
Michael Stefaniuc | 5ceccec | 2006-10-09 23:34:36 +0200 | [diff] [blame] | 1084 | free( console_in->title ); |
| 1085 | free( console_in->records ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1086 | |
Alexandre Julliard | b2eff1c | 2005-02-25 21:06:11 +0000 | [diff] [blame] | 1087 | if (console_in->active) release_object( console_in->active ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1088 | console_in->active = NULL; |
| 1089 | |
Alexandre Julliard | b2eff1c | 2005-02-25 21:06:11 +0000 | [diff] [blame] | 1090 | LIST_FOR_EACH_ENTRY( curr, &screen_buffer_list, struct screen_buffer, entry ) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1091 | { |
Alexandre Julliard | b2eff1c | 2005-02-25 21:06:11 +0000 | [diff] [blame] | 1092 | if (curr->input == console_in) curr->input = NULL; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1093 | } |
| 1094 | |
Eric Pouech | b39a8d9 | 2010-08-30 22:18:44 +0200 | [diff] [blame] | 1095 | if (console_in->evt) |
| 1096 | { |
| 1097 | release_object( console_in->evt ); |
| 1098 | console_in->evt = NULL; |
| 1099 | } |
Eric Pouech | a86a289 | 2003-06-23 03:37:14 +0000 | [diff] [blame] | 1100 | release_object( console_in->event ); |
Eric Pouech | b39a8d9 | 2010-08-30 22:18:44 +0200 | [diff] [blame] | 1101 | if (console_in->fd) |
Eric Pouech | b39a8d9 | 2010-08-30 22:18:44 +0200 | [diff] [blame] | 1102 | release_object( console_in->fd ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1103 | |
| 1104 | for (i = 0; i < console_in->history_size; i++) |
Lionel Debroux | 2f89fe7 | 2007-10-20 09:35:13 +0200 | [diff] [blame] | 1105 | free( console_in->history[i] ); |
Michael Stefaniuc | 5ceccec | 2006-10-09 23:34:36 +0200 | [diff] [blame] | 1106 | free( console_in->history ); |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | static void screen_buffer_dump( struct object *obj, int verbose ) |
| 1110 | { |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1111 | struct screen_buffer *screen_buffer = (struct screen_buffer *)obj; |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 1112 | assert( obj->ops == &screen_buffer_ops ); |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 1113 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1114 | fprintf(stderr, "Console screen buffer input=%p\n", screen_buffer->input ); |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 1115 | } |
| 1116 | |
| 1117 | static void screen_buffer_destroy( struct object *obj ) |
| 1118 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1119 | struct screen_buffer *screen_buffer = (struct screen_buffer *)obj; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1120 | |
Alexandre Julliard | 62a8b43 | 1999-01-19 17:48:23 +0000 | [diff] [blame] | 1121 | assert( obj->ops == &screen_buffer_ops ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1122 | |
Alexandre Julliard | b2eff1c | 2005-02-25 21:06:11 +0000 | [diff] [blame] | 1123 | list_remove( &screen_buffer->entry ); |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1124 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1125 | if (screen_buffer->input && screen_buffer->input->active == screen_buffer) |
| 1126 | { |
Alexandre Julliard | b2eff1c | 2005-02-25 21:06:11 +0000 | [diff] [blame] | 1127 | struct screen_buffer *sb; |
| 1128 | |
| 1129 | screen_buffer->input->active = NULL; |
| 1130 | LIST_FOR_EACH_ENTRY( sb, &screen_buffer_list, struct screen_buffer, entry ) |
| 1131 | { |
| 1132 | if (sb->input == screen_buffer->input) |
| 1133 | { |
| 1134 | sb->input->active = sb; |
| 1135 | break; |
| 1136 | } |
| 1137 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1138 | } |
Eric Pouech | 6f32644 | 2010-08-30 22:18:52 +0200 | [diff] [blame] | 1139 | if (screen_buffer->fd) release_object( screen_buffer->fd ); |
Michael Stefaniuc | 5ceccec | 2006-10-09 23:34:36 +0200 | [diff] [blame] | 1140 | free( screen_buffer->data ); |
Alexandre Julliard | aa0ebd0 | 1998-12-30 12:06:45 +0000 | [diff] [blame] | 1141 | } |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1142 | |
Eric Pouech | 6f32644 | 2010-08-30 22:18:52 +0200 | [diff] [blame] | 1143 | static struct fd *screen_buffer_get_fd( struct object *obj ) |
| 1144 | { |
| 1145 | struct screen_buffer *screen_buffer = (struct screen_buffer*)obj; |
| 1146 | assert( obj->ops == &screen_buffer_ops ); |
| 1147 | return screen_buffer->fd ? (struct fd*)grab_object( screen_buffer->fd ) : NULL; |
| 1148 | } |
| 1149 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1150 | /* write data into a screen buffer */ |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 1151 | static int write_console_output( struct screen_buffer *screen_buffer, data_size_t size, |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1152 | const void* data, enum char_info_mode mode, |
| 1153 | int x, int y, int wrap ) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1154 | { |
Michael Stefaniuc | a624977 | 2006-07-25 10:30:04 +0200 | [diff] [blame] | 1155 | unsigned int i; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1156 | char_info_t *end, *dest = screen_buffer->data + y * screen_buffer->width + x; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1157 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1158 | if (y >= screen_buffer->height) return 0; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1159 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1160 | if (wrap) |
| 1161 | end = screen_buffer->data + screen_buffer->height * screen_buffer->width; |
| 1162 | else |
| 1163 | end = screen_buffer->data + (y+1) * screen_buffer->width; |
| 1164 | |
| 1165 | switch(mode) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1166 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1167 | case CHAR_INFO_MODE_TEXT: |
| 1168 | { |
| 1169 | const WCHAR *ptr = data; |
| 1170 | for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++) dest->ch = ptr[i]; |
| 1171 | } |
| 1172 | break; |
| 1173 | case CHAR_INFO_MODE_ATTR: |
| 1174 | { |
| 1175 | const unsigned short *ptr = data; |
| 1176 | for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++) dest->attr = ptr[i]; |
| 1177 | } |
| 1178 | break; |
| 1179 | case CHAR_INFO_MODE_TEXTATTR: |
| 1180 | { |
| 1181 | const char_info_t *ptr = data; |
| 1182 | for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++) *dest = ptr[i]; |
| 1183 | } |
| 1184 | break; |
| 1185 | case CHAR_INFO_MODE_TEXTSTDATTR: |
| 1186 | { |
| 1187 | const WCHAR *ptr = data; |
| 1188 | for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++) |
| 1189 | { |
| 1190 | dest->ch = ptr[i]; |
| 1191 | dest->attr = screen_buffer->attr; |
| 1192 | } |
| 1193 | } |
| 1194 | break; |
| 1195 | default: |
| 1196 | set_error( STATUS_INVALID_PARAMETER ); |
| 1197 | return 0; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1198 | } |
| 1199 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1200 | if (i && screen_buffer == screen_buffer->input->active) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1201 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1202 | struct console_renderer_event evt; |
| 1203 | evt.event = CONSOLE_RENDERER_UPDATE_EVENT; |
Eric Pouech | 2e0b533 | 2006-01-27 16:17:51 +0100 | [diff] [blame] | 1204 | memset(&evt.u, 0, sizeof(evt.u)); |
Eric Pouech | f4b298b | 2003-01-05 01:07:34 +0000 | [diff] [blame] | 1205 | evt.u.update.top = y + x / screen_buffer->width; |
| 1206 | evt.u.update.bottom = y + (x + i - 1) / screen_buffer->width; |
Eric Pouech | 2f7af56 | 2010-08-30 22:19:06 +0200 | [diff] [blame] | 1207 | console_input_events_append( screen_buffer->input, &evt ); |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1208 | } |
| 1209 | return i; |
| 1210 | } |
| 1211 | |
| 1212 | /* fill a screen buffer with uniform data */ |
| 1213 | static int fill_console_output( struct screen_buffer *screen_buffer, char_info_t data, |
| 1214 | enum char_info_mode mode, int x, int y, int count, int wrap ) |
| 1215 | { |
| 1216 | int i; |
| 1217 | char_info_t *end, *dest = screen_buffer->data + y * screen_buffer->width + x; |
| 1218 | |
| 1219 | if (y >= screen_buffer->height) return 0; |
| 1220 | |
| 1221 | if (wrap) |
| 1222 | end = screen_buffer->data + screen_buffer->height * screen_buffer->width; |
| 1223 | else |
| 1224 | end = screen_buffer->data + (y+1) * screen_buffer->width; |
| 1225 | |
| 1226 | if (count > end - dest) count = end - dest; |
| 1227 | |
| 1228 | switch(mode) |
| 1229 | { |
| 1230 | case CHAR_INFO_MODE_TEXT: |
| 1231 | for (i = 0; i < count; i++) dest[i].ch = data.ch; |
| 1232 | break; |
| 1233 | case CHAR_INFO_MODE_ATTR: |
| 1234 | for (i = 0; i < count; i++) dest[i].attr = data.attr; |
| 1235 | break; |
| 1236 | case CHAR_INFO_MODE_TEXTATTR: |
| 1237 | for (i = 0; i < count; i++) dest[i] = data; |
| 1238 | break; |
| 1239 | case CHAR_INFO_MODE_TEXTSTDATTR: |
| 1240 | for (i = 0; i < count; i++) |
| 1241 | { |
| 1242 | dest[i].ch = data.ch; |
| 1243 | dest[i].attr = screen_buffer->attr; |
| 1244 | } |
| 1245 | break; |
| 1246 | default: |
| 1247 | set_error( STATUS_INVALID_PARAMETER ); |
| 1248 | return 0; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1249 | } |
| 1250 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1251 | if (count && screen_buffer == screen_buffer->input->active) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1252 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1253 | struct console_renderer_event evt; |
| 1254 | evt.event = CONSOLE_RENDERER_UPDATE_EVENT; |
Eric Pouech | 2e0b533 | 2006-01-27 16:17:51 +0100 | [diff] [blame] | 1255 | memset(&evt.u, 0, sizeof(evt.u)); |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1256 | evt.u.update.top = y; |
| 1257 | evt.u.update.bottom = (y * screen_buffer->width + x + count - 1) / screen_buffer->width; |
Eric Pouech | 2f7af56 | 2010-08-30 22:19:06 +0200 | [diff] [blame] | 1258 | console_input_events_append( screen_buffer->input, &evt ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1259 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1260 | return i; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | /* read data from a screen buffer */ |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1264 | static void read_console_output( struct screen_buffer *screen_buffer, int x, int y, |
| 1265 | enum char_info_mode mode, int wrap ) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1266 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1267 | int i; |
| 1268 | char_info_t *end, *src = screen_buffer->data + y * screen_buffer->width + x; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1269 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1270 | if (y >= screen_buffer->height) return; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1271 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1272 | if (wrap) |
| 1273 | end = screen_buffer->data + screen_buffer->height * screen_buffer->width; |
| 1274 | else |
| 1275 | end = screen_buffer->data + (y+1) * screen_buffer->width; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1276 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1277 | switch(mode) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1278 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1279 | case CHAR_INFO_MODE_TEXT: |
| 1280 | { |
| 1281 | WCHAR *data; |
| 1282 | int count = min( end - src, get_reply_max_size() / sizeof(*data) ); |
| 1283 | if ((data = set_reply_data_size( count * sizeof(*data) ))) |
| 1284 | { |
| 1285 | for (i = 0; i < count; i++) data[i] = src[i].ch; |
| 1286 | } |
| 1287 | } |
| 1288 | break; |
| 1289 | case CHAR_INFO_MODE_ATTR: |
| 1290 | { |
| 1291 | unsigned short *data; |
| 1292 | int count = min( end - src, get_reply_max_size() / sizeof(*data) ); |
| 1293 | if ((data = set_reply_data_size( count * sizeof(*data) ))) |
| 1294 | { |
| 1295 | for (i = 0; i < count; i++) data[i] = src[i].attr; |
| 1296 | } |
| 1297 | } |
| 1298 | break; |
| 1299 | case CHAR_INFO_MODE_TEXTATTR: |
| 1300 | { |
| 1301 | char_info_t *data; |
| 1302 | int count = min( end - src, get_reply_max_size() / sizeof(*data) ); |
| 1303 | if ((data = set_reply_data_size( count * sizeof(*data) ))) |
| 1304 | { |
| 1305 | for (i = 0; i < count; i++) data[i] = src[i]; |
| 1306 | } |
| 1307 | } |
| 1308 | break; |
| 1309 | default: |
| 1310 | set_error( STATUS_INVALID_PARAMETER ); |
| 1311 | break; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1312 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1313 | } |
| 1314 | |
| 1315 | /* scroll parts of a screen buffer */ |
Eric Pouech | daaee9e | 2010-08-30 22:19:12 +0200 | [diff] [blame] | 1316 | static void scroll_console_output( struct screen_buffer *screen_buffer, int xsrc, int ysrc, int xdst, int ydst, |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1317 | int w, int h ) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1318 | { |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1319 | int j; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1320 | char_info_t *psrc, *pdst; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1321 | struct console_renderer_event evt; |
| 1322 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1323 | if (xsrc < 0 || ysrc < 0 || xdst < 0 || ydst < 0 || |
| 1324 | xsrc + w > screen_buffer->width || |
| 1325 | xdst + w > screen_buffer->width || |
| 1326 | ysrc + h > screen_buffer->height || |
| 1327 | ydst + h > screen_buffer->height || |
| 1328 | w == 0 || h == 0) |
| 1329 | { |
| 1330 | set_error( STATUS_INVALID_PARAMETER ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1331 | return; |
| 1332 | } |
| 1333 | |
| 1334 | if (ysrc < ydst) |
| 1335 | { |
| 1336 | psrc = &screen_buffer->data[(ysrc + h - 1) * screen_buffer->width + xsrc]; |
| 1337 | pdst = &screen_buffer->data[(ydst + h - 1) * screen_buffer->width + xdst]; |
| 1338 | |
| 1339 | for (j = h; j > 0; j--) |
| 1340 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1341 | memcpy(pdst, psrc, w * sizeof(*pdst) ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1342 | pdst -= screen_buffer->width; |
| 1343 | psrc -= screen_buffer->width; |
| 1344 | } |
| 1345 | } |
| 1346 | else |
| 1347 | { |
| 1348 | psrc = &screen_buffer->data[ysrc * screen_buffer->width + xsrc]; |
| 1349 | pdst = &screen_buffer->data[ydst * screen_buffer->width + xdst]; |
| 1350 | |
| 1351 | for (j = 0; j < h; j++) |
| 1352 | { |
Vincent BĂ©ron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1353 | /* we use memmove here because when psrc and pdst are the same, |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1354 | * copies are done on the same row, so the dst and src blocks |
| 1355 | * can overlap */ |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1356 | memmove( pdst, psrc, w * sizeof(*pdst) ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1357 | pdst += screen_buffer->width; |
| 1358 | psrc += screen_buffer->width; |
| 1359 | } |
| 1360 | } |
| 1361 | |
| 1362 | /* FIXME: this could be enhanced, by signalling scroll */ |
| 1363 | evt.event = CONSOLE_RENDERER_UPDATE_EVENT; |
Eric Pouech | 2e0b533 | 2006-01-27 16:17:51 +0100 | [diff] [blame] | 1364 | memset(&evt.u, 0, sizeof(evt.u)); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1365 | evt.u.update.top = min(ysrc, ydst); |
| 1366 | evt.u.update.bottom = max(ysrc, ydst) + h - 1; |
Eric Pouech | 2f7af56 | 2010-08-30 22:19:06 +0200 | [diff] [blame] | 1367 | console_input_events_append( screen_buffer->input, &evt ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1368 | } |
| 1369 | |
| 1370 | /* allocate a console for the renderer */ |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1371 | DECL_HANDLER(alloc_console) |
| 1372 | { |
Alexandre Julliard | 5188574 | 2002-05-30 20:12:58 +0000 | [diff] [blame] | 1373 | obj_handle_t in = 0; |
| 1374 | obj_handle_t evt = 0; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1375 | struct process *process; |
Eric Pouech | b39a8d9 | 2010-08-30 22:18:44 +0200 | [diff] [blame] | 1376 | struct thread *renderer; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1377 | struct console_input *console; |
Eric Pouech | b39a8d9 | 2010-08-30 22:18:44 +0200 | [diff] [blame] | 1378 | int fd; |
Alexandre Julliard | 039aa42 | 1999-06-11 18:31:22 +0000 | [diff] [blame] | 1379 | |
Eric Pouech | b39a8d9 | 2010-08-30 22:18:44 +0200 | [diff] [blame] | 1380 | switch (req->pid) |
Alexandre Julliard | 31b02bb | 2007-01-04 09:41:14 +0100 | [diff] [blame] | 1381 | { |
Eric Pouech | b39a8d9 | 2010-08-30 22:18:44 +0200 | [diff] [blame] | 1382 | case 0: |
| 1383 | /* renderer is current, console to be attached to parent process */ |
| 1384 | renderer = current; |
Eric Pouech | 1f25534 | 2010-08-28 13:14:55 +0200 | [diff] [blame] | 1385 | if (!(process = current->process->parent)) |
Alexandre Julliard | 31b02bb | 2007-01-04 09:41:14 +0100 | [diff] [blame] | 1386 | { |
| 1387 | set_error( STATUS_ACCESS_DENIED ); |
| 1388 | return; |
| 1389 | } |
| 1390 | grab_object( process ); |
Eric Pouech | b39a8d9 | 2010-08-30 22:18:44 +0200 | [diff] [blame] | 1391 | break; |
| 1392 | case 0xffffffff: |
| 1393 | /* no renderer, console to be attached to current process */ |
| 1394 | renderer = NULL; |
| 1395 | process = current->process; |
| 1396 | grab_object( process ); |
| 1397 | break; |
| 1398 | default: |
| 1399 | /* renderer is current, console to be attached to req->pid */ |
| 1400 | renderer = current; |
| 1401 | if (!(process = get_process_from_id( req->pid ))) return; |
Alexandre Julliard | 31b02bb | 2007-01-04 09:41:14 +0100 | [diff] [blame] | 1402 | } |
Alexandre Julliard | 039aa42 | 1999-06-11 18:31:22 +0000 | [diff] [blame] | 1403 | |
Eric Pouech | 1f25534 | 2010-08-28 13:14:55 +0200 | [diff] [blame] | 1404 | if (process != current->process && process->console) |
Eric Pouech | b39a8d9 | 2010-08-30 22:18:44 +0200 | [diff] [blame] | 1405 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1406 | set_error( STATUS_ACCESS_DENIED ); |
Eric Pouech | b39a8d9 | 2010-08-30 22:18:44 +0200 | [diff] [blame] | 1407 | goto the_end; |
| 1408 | } |
| 1409 | if (req->input_fd != -1) |
| 1410 | { |
| 1411 | if ((fd = thread_get_inflight_fd( current, req->input_fd )) == -1) |
| 1412 | { |
| 1413 | set_error( STATUS_INVALID_PARAMETER ); |
| 1414 | goto the_end; |
| 1415 | } |
| 1416 | } |
| 1417 | else fd = -1; |
| 1418 | |
| 1419 | if ((console = (struct console_input*)create_console_input( renderer, fd ))) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1420 | { |
Eric Pouech | 1f25534 | 2010-08-28 13:14:55 +0200 | [diff] [blame] | 1421 | if ((in = alloc_handle( current->process, console, req->access, req->attributes ))) |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1422 | { |
Eric Pouech | b39a8d9 | 2010-08-30 22:18:44 +0200 | [diff] [blame] | 1423 | if (!console->evt || |
| 1424 | (evt = alloc_handle( current->process, console->evt, SYNCHRONIZE|GENERIC_READ|GENERIC_WRITE, 0 ))) |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1425 | { |
Eric Pouech | b39a8d9 | 2010-08-30 22:18:44 +0200 | [diff] [blame] | 1426 | process->console = (struct console_input*)grab_object( console ); |
| 1427 | console->num_proc++; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1428 | reply->handle_in = in; |
| 1429 | reply->event = evt; |
| 1430 | release_object( console ); |
| 1431 | goto the_end; |
| 1432 | } |
Eric Pouech | 1f25534 | 2010-08-28 13:14:55 +0200 | [diff] [blame] | 1433 | close_handle( current->process, in ); |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1434 | } |
| 1435 | free_console( process ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1436 | } |
| 1437 | the_end: |
| 1438 | release_object( process ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1439 | } |
| 1440 | |
| 1441 | /* free the console of the current process */ |
| 1442 | DECL_HANDLER(free_console) |
| 1443 | { |
| 1444 | free_console( current->process ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1445 | } |
| 1446 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1447 | /* let the renderer peek the events it's waiting on */ |
| 1448 | DECL_HANDLER(get_console_renderer_events) |
| 1449 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1450 | struct console_input_events *evt; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1451 | |
| 1452 | evt = (struct console_input_events *)get_handle_obj( current->process, req->handle, |
Eric Pouech | 465f3d1 | 2010-08-28 13:14:43 +0200 | [diff] [blame] | 1453 | FILE_READ_PROPERTIES, &console_input_events_ops ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1454 | if (!evt) return; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1455 | console_input_events_get( evt ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1456 | release_object( evt ); |
| 1457 | } |
| 1458 | |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1459 | /* open a handle to the process console */ |
| 1460 | DECL_HANDLER(open_console) |
| 1461 | { |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1462 | struct object *obj = NULL; |
Alexandre Julliard | 039aa42 | 1999-06-11 18:31:22 +0000 | [diff] [blame] | 1463 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1464 | reply->handle = 0; |
Francois Gouget | d6abd38 | 2008-12-01 11:10:06 +0100 | [diff] [blame] | 1465 | if (!req->from) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1466 | { |
Eric Pouech | b39a8d9 | 2010-08-30 22:18:44 +0200 | [diff] [blame] | 1467 | if (current->process->console) |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1468 | obj = grab_object( (struct object*)current->process->console ); |
Mike McCormack | fac494c | 2006-06-07 18:33:46 +0900 | [diff] [blame] | 1469 | } |
| 1470 | else if (req->from == (obj_handle_t)1) |
| 1471 | { |
Eric Pouech | 6f32644 | 2010-08-30 22:18:52 +0200 | [diff] [blame] | 1472 | if (current->process->console && current->process->console->active) |
| 1473 | obj = grab_object( (struct object*)current->process->console->active ); |
Mike McCormack | fac494c | 2006-06-07 18:33:46 +0900 | [diff] [blame] | 1474 | } |
| 1475 | else if ((obj = get_handle_obj( current->process, req->from, |
Eric Pouech | 465f3d1 | 2010-08-28 13:14:43 +0200 | [diff] [blame] | 1476 | FILE_READ_PROPERTIES|FILE_WRITE_PROPERTIES, &console_input_ops ))) |
Mike McCormack | fac494c | 2006-06-07 18:33:46 +0900 | [diff] [blame] | 1477 | { |
| 1478 | struct console_input *console = (struct console_input *)obj; |
| 1479 | obj = (console->active) ? grab_object( console->active ) : NULL; |
| 1480 | release_object( console ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1481 | } |
| 1482 | |
| 1483 | /* FIXME: req->share is not used (as in screen buffer creation) */ |
| 1484 | if (obj) |
| 1485 | { |
Alexandre Julliard | 24560e7 | 2005-12-09 13:58:25 +0100 | [diff] [blame] | 1486 | reply->handle = alloc_handle( current->process, obj, req->access, req->attributes ); |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1487 | release_object( obj ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1488 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1489 | else if (!get_error()) set_error( STATUS_ACCESS_DENIED ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1490 | } |
| 1491 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1492 | /* set info about a console input */ |
| 1493 | DECL_HANDLER(set_console_input_info) |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1494 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1495 | set_console_input_info( req, get_req_data(), get_req_data_size() ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1496 | } |
| 1497 | |
| 1498 | /* get info about a console (output only) */ |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1499 | DECL_HANDLER(get_console_input_info) |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1500 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1501 | struct console_input *console; |
Alexandre Julliard | 9264300 | 2000-08-31 01:59:51 +0000 | [diff] [blame] | 1502 | |
Eric Pouech | 465f3d1 | 2010-08-28 13:14:43 +0200 | [diff] [blame] | 1503 | if (!(console = console_input_get( req->handle, FILE_READ_PROPERTIES ))) return; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1504 | if (console->title) |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 1505 | { |
Alexandre Julliard | 0f273c1 | 2006-07-26 10:43:25 +0200 | [diff] [blame] | 1506 | data_size_t len = strlenW( console->title ) * sizeof(WCHAR); |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1507 | if (len > get_reply_max_size()) len = get_reply_max_size(); |
| 1508 | set_reply_data( console->title, len ); |
Alexandre Julliard | ebe29ef | 1999-06-26 08:43:26 +0000 | [diff] [blame] | 1509 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1510 | reply->history_mode = console->history_mode; |
| 1511 | reply->history_size = console->history_size; |
| 1512 | reply->history_index = console->history_index; |
Eric Pouech | fa8b85a | 2003-01-09 06:01:32 +0000 | [diff] [blame] | 1513 | reply->edition_mode = console->edition_mode; |
Kirill K. Smirnov | 9d74661 | 2007-05-10 21:19:47 +0400 | [diff] [blame] | 1514 | reply->input_cp = console->input_cp; |
| 1515 | reply->output_cp = console->output_cp; |
Kirill K. Smirnov | f3e1317 | 2007-08-23 19:17:17 +0400 | [diff] [blame] | 1516 | reply->win = console->win; |
Eric Pouech | fa8b85a | 2003-01-09 06:01:32 +0000 | [diff] [blame] | 1517 | |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1518 | release_object( console ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1519 | } |
| 1520 | |
| 1521 | /* get a console mode (input or output) */ |
| 1522 | DECL_HANDLER(get_console_mode) |
| 1523 | { |
Eric Pouech | 4fdcdef | 2010-08-30 22:19:00 +0200 | [diff] [blame] | 1524 | reply->mode = get_console_mode( req->handle, &reply->is_bare ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1525 | } |
| 1526 | |
| 1527 | /* set a console mode (input or output) */ |
| 1528 | DECL_HANDLER(set_console_mode) |
| 1529 | { |
| 1530 | set_console_mode( req->handle, req->mode ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1531 | } |
| 1532 | |
| 1533 | /* add input records to a console input queue */ |
| 1534 | DECL_HANDLER(write_console_input) |
| 1535 | { |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1536 | struct console_input *console; |
| 1537 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1538 | reply->written = 0; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1539 | if (!(console = (struct console_input *)get_handle_obj( current->process, req->handle, |
Eric Pouech | 465f3d1 | 2010-08-28 13:14:43 +0200 | [diff] [blame] | 1540 | FILE_WRITE_PROPERTIES, &console_input_ops ))) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1541 | return; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1542 | reply->written = write_console_input( console, get_req_data_size() / sizeof(INPUT_RECORD), |
| 1543 | get_req_data() ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1544 | release_object( console ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1545 | } |
| 1546 | |
| 1547 | /* fetch input records from a console input queue */ |
| 1548 | DECL_HANDLER(read_console_input) |
| 1549 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1550 | int count = get_reply_max_size() / sizeof(INPUT_RECORD); |
| 1551 | reply->read = read_console_input( req->handle, count, req->flush ); |
Alexandre Julliard | 43c190e | 1999-05-15 10:48:19 +0000 | [diff] [blame] | 1552 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1553 | |
| 1554 | /* appends a string to console's history */ |
| 1555 | DECL_HANDLER(append_console_input_history) |
| 1556 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1557 | struct console_input *console; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1558 | |
Eric Pouech | 465f3d1 | 2010-08-28 13:14:43 +0200 | [diff] [blame] | 1559 | if (!(console = console_input_get( req->handle, FILE_WRITE_PROPERTIES ))) return; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1560 | console_input_append_hist( console, get_req_data(), get_req_data_size() / sizeof(WCHAR) ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1561 | release_object( console ); |
| 1562 | } |
| 1563 | |
| 1564 | /* appends a string to console's history */ |
| 1565 | DECL_HANDLER(get_console_input_history) |
| 1566 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1567 | struct console_input *console; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1568 | |
Eric Pouech | 465f3d1 | 2010-08-28 13:14:43 +0200 | [diff] [blame] | 1569 | if (!(console = console_input_get( req->handle, FILE_READ_PROPERTIES ))) return; |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1570 | reply->total = console_input_get_hist( console, req->index ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1571 | release_object( console ); |
| 1572 | } |
| 1573 | |
| 1574 | /* creates a screen buffer */ |
| 1575 | DECL_HANDLER(create_console_output) |
| 1576 | { |
| 1577 | struct console_input* console; |
| 1578 | struct screen_buffer* screen_buffer; |
Eric Pouech | 6f32644 | 2010-08-30 22:18:52 +0200 | [diff] [blame] | 1579 | int fd; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1580 | |
Eric Pouech | 6f32644 | 2010-08-30 22:18:52 +0200 | [diff] [blame] | 1581 | if (req->fd != -1) |
| 1582 | { |
| 1583 | if ((fd = thread_get_inflight_fd( current, req->fd )) == -1) |
| 1584 | { |
Eric Pouech | daaee9e | 2010-08-30 22:19:12 +0200 | [diff] [blame] | 1585 | set_error( STATUS_INVALID_HANDLE ); |
Eric Pouech | 6f32644 | 2010-08-30 22:18:52 +0200 | [diff] [blame] | 1586 | return; |
| 1587 | } |
| 1588 | } |
| 1589 | else fd = -1; |
| 1590 | if (!(console = console_input_get( req->handle_in, FILE_WRITE_PROPERTIES ))) |
| 1591 | { |
| 1592 | close(fd); |
| 1593 | return; |
| 1594 | } |
Eric Pouech | daaee9e | 2010-08-30 22:19:12 +0200 | [diff] [blame] | 1595 | if (console_input_is_bare( console ) ^ (fd != -1)) |
| 1596 | { |
| 1597 | close( fd ); |
| 1598 | set_error( STATUS_INVALID_HANDLE ); |
| 1599 | return; |
| 1600 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1601 | |
Eric Pouech | 6f32644 | 2010-08-30 22:18:52 +0200 | [diff] [blame] | 1602 | screen_buffer = create_console_output( console, fd ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1603 | if (screen_buffer) |
| 1604 | { |
Vincent BĂ©ron | 9a62491 | 2002-05-31 23:06:46 +0000 | [diff] [blame] | 1605 | /* FIXME: should store sharing and test it when opening the CONOUT$ device |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1606 | * see file.c on how this could be done */ |
Alexandre Julliard | 24560e7 | 2005-12-09 13:58:25 +0100 | [diff] [blame] | 1607 | reply->handle_out = alloc_handle( current->process, screen_buffer, req->access, req->attributes ); |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1608 | release_object( screen_buffer ); |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1609 | } |
| 1610 | release_object( console ); |
| 1611 | } |
| 1612 | |
| 1613 | /* set info about a console screen buffer */ |
| 1614 | DECL_HANDLER(set_console_output_info) |
| 1615 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1616 | struct screen_buffer *screen_buffer; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1617 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1618 | if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle, |
Eric Pouech | 465f3d1 | 2010-08-28 13:14:43 +0200 | [diff] [blame] | 1619 | FILE_WRITE_PROPERTIES, &screen_buffer_ops))) |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1620 | { |
| 1621 | set_console_output_info( screen_buffer, req ); |
| 1622 | release_object( screen_buffer ); |
| 1623 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1624 | } |
| 1625 | |
| 1626 | /* get info about a console screen buffer */ |
| 1627 | DECL_HANDLER(get_console_output_info) |
| 1628 | { |
| 1629 | struct screen_buffer *screen_buffer; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1630 | |
| 1631 | if ((screen_buffer = (struct screen_buffer *)get_handle_obj( current->process, req->handle, |
Eric Pouech | 465f3d1 | 2010-08-28 13:14:43 +0200 | [diff] [blame] | 1632 | FILE_READ_PROPERTIES, &screen_buffer_ops))) |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1633 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1634 | reply->cursor_size = screen_buffer->cursor_size; |
| 1635 | reply->cursor_visible = screen_buffer->cursor_visible; |
| 1636 | reply->cursor_x = screen_buffer->cursor_x; |
| 1637 | reply->cursor_y = screen_buffer->cursor_y; |
| 1638 | reply->width = screen_buffer->width; |
| 1639 | reply->height = screen_buffer->height; |
| 1640 | reply->attr = screen_buffer->attr; |
| 1641 | reply->win_left = screen_buffer->win.left; |
| 1642 | reply->win_top = screen_buffer->win.top; |
| 1643 | reply->win_right = screen_buffer->win.right; |
| 1644 | reply->win_bottom = screen_buffer->win.bottom; |
| 1645 | reply->max_width = screen_buffer->max_width; |
| 1646 | reply->max_height = screen_buffer->max_height; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1647 | release_object( screen_buffer ); |
| 1648 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1649 | } |
| 1650 | |
| 1651 | /* read data (chars & attrs) from a screen buffer */ |
| 1652 | DECL_HANDLER(read_console_output) |
| 1653 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1654 | struct screen_buffer *screen_buffer; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1655 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1656 | if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle, |
Eric Pouech | 465f3d1 | 2010-08-28 13:14:43 +0200 | [diff] [blame] | 1657 | FILE_READ_DATA, &screen_buffer_ops ))) |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1658 | { |
Eric Pouech | daaee9e | 2010-08-30 22:19:12 +0200 | [diff] [blame] | 1659 | if (console_input_is_bare( screen_buffer->input )) |
| 1660 | { |
| 1661 | set_error( STATUS_OBJECT_TYPE_MISMATCH ); |
| 1662 | release_object( screen_buffer ); |
| 1663 | return; |
| 1664 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1665 | read_console_output( screen_buffer, req->x, req->y, req->mode, req->wrap ); |
| 1666 | reply->width = screen_buffer->width; |
| 1667 | reply->height = screen_buffer->height; |
| 1668 | release_object( screen_buffer ); |
| 1669 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1670 | } |
| 1671 | |
| 1672 | /* write data (char and/or attrs) to a screen buffer */ |
| 1673 | DECL_HANDLER(write_console_output) |
| 1674 | { |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1675 | struct screen_buffer *screen_buffer; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1676 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1677 | if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle, |
Eric Pouech | 465f3d1 | 2010-08-28 13:14:43 +0200 | [diff] [blame] | 1678 | FILE_WRITE_DATA, &screen_buffer_ops))) |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1679 | { |
Eric Pouech | daaee9e | 2010-08-30 22:19:12 +0200 | [diff] [blame] | 1680 | if (console_input_is_bare( screen_buffer->input )) |
| 1681 | { |
| 1682 | set_error( STATUS_OBJECT_TYPE_MISMATCH ); |
| 1683 | release_object( screen_buffer ); |
| 1684 | return; |
| 1685 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1686 | reply->written = write_console_output( screen_buffer, get_req_data_size(), get_req_data(), |
| 1687 | req->mode, req->x, req->y, req->wrap ); |
| 1688 | reply->width = screen_buffer->width; |
| 1689 | reply->height = screen_buffer->height; |
| 1690 | release_object( screen_buffer ); |
| 1691 | } |
| 1692 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1693 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1694 | /* fill a screen buffer with constant data (chars and/or attributes) */ |
| 1695 | DECL_HANDLER(fill_console_output) |
| 1696 | { |
| 1697 | struct screen_buffer *screen_buffer; |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1698 | |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1699 | if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle, |
Eric Pouech | 465f3d1 | 2010-08-28 13:14:43 +0200 | [diff] [blame] | 1700 | FILE_WRITE_DATA, &screen_buffer_ops))) |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1701 | { |
Eric Pouech | daaee9e | 2010-08-30 22:19:12 +0200 | [diff] [blame] | 1702 | if (console_input_is_bare( screen_buffer->input )) |
| 1703 | { |
| 1704 | set_error( STATUS_OBJECT_TYPE_MISMATCH ); |
| 1705 | release_object( screen_buffer ); |
| 1706 | return; |
| 1707 | } |
Alexandre Julliard | 9caa71e | 2001-11-30 18:46:42 +0000 | [diff] [blame] | 1708 | reply->written = fill_console_output( screen_buffer, req->data, req->mode, |
| 1709 | req->x, req->y, req->count, req->wrap ); |
| 1710 | release_object( screen_buffer ); |
| 1711 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1712 | } |
| 1713 | |
| 1714 | /* move a rect of data in a screen buffer */ |
| 1715 | DECL_HANDLER(move_console_output) |
| 1716 | { |
Eric Pouech | daaee9e | 2010-08-30 22:19:12 +0200 | [diff] [blame] | 1717 | struct screen_buffer *screen_buffer; |
| 1718 | |
| 1719 | if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle, |
| 1720 | FILE_WRITE_DATA, &screen_buffer_ops))) |
| 1721 | { |
| 1722 | if (console_input_is_bare( screen_buffer->input )) |
| 1723 | { |
| 1724 | set_error( STATUS_OBJECT_TYPE_MISMATCH ); |
| 1725 | release_object( screen_buffer ); |
| 1726 | return; |
| 1727 | } |
| 1728 | scroll_console_output( screen_buffer, req->x_src, req->y_src, req->x_dst, req->y_dst, |
| 1729 | req->w, req->h ); |
| 1730 | release_object( screen_buffer ); |
| 1731 | } |
Eric Pouech | 0b83d4c | 2001-11-23 23:04:58 +0000 | [diff] [blame] | 1732 | } |
Eric Pouech | 93bfa0d | 2002-06-02 21:22:22 +0000 | [diff] [blame] | 1733 | |
| 1734 | /* sends a signal to a console (process, group...) */ |
| 1735 | DECL_HANDLER(send_console_signal) |
| 1736 | { |
Alexandre Julliard | 54f2287 | 2002-10-03 19:54:57 +0000 | [diff] [blame] | 1737 | process_id_t group; |
Eric Pouech | 93bfa0d | 2002-06-02 21:22:22 +0000 | [diff] [blame] | 1738 | |
| 1739 | group = req->group_id ? req->group_id : current->process->group_id; |
| 1740 | |
| 1741 | if (!group) |
Eric Pouech | 412d37f | 2003-06-21 02:07:10 +0000 | [diff] [blame] | 1742 | set_error( STATUS_INVALID_PARAMETER ); |
Eric Pouech | 93bfa0d | 2002-06-02 21:22:22 +0000 | [diff] [blame] | 1743 | else |
| 1744 | propagate_console_signal( current->process->console, req->signal, group ); |
| 1745 | } |
Eric Pouech | 412d37f | 2003-06-21 02:07:10 +0000 | [diff] [blame] | 1746 | |
| 1747 | /* get console which renderer is 'current' */ |
| 1748 | static int cgwe_enum( struct process* process, void* user) |
| 1749 | { |
| 1750 | if (process->console && process->console->renderer == current) |
| 1751 | { |
| 1752 | *(struct console_input**)user = process->console; |
| 1753 | return 1; |
| 1754 | } |
| 1755 | return 0; |
| 1756 | } |
| 1757 | |
| 1758 | DECL_HANDLER(get_console_wait_event) |
| 1759 | { |
| 1760 | struct console_input* console = NULL; |
| 1761 | |
Eric Pouech | b39a8d9 | 2010-08-30 22:18:44 +0200 | [diff] [blame] | 1762 | if (current->process->console) |
Eric Pouech | 412d37f | 2003-06-21 02:07:10 +0000 | [diff] [blame] | 1763 | console = (struct console_input*)grab_object( (struct object*)current->process->console ); |
| 1764 | else enum_processes(cgwe_enum, &console); |
| 1765 | |
| 1766 | if (console) |
| 1767 | { |
Alexandre Julliard | 24560e7 | 2005-12-09 13:58:25 +0100 | [diff] [blame] | 1768 | reply->handle = alloc_handle( current->process, console->event, EVENT_ALL_ACCESS, 0 ); |
Eric Pouech | 412d37f | 2003-06-21 02:07:10 +0000 | [diff] [blame] | 1769 | release_object( console ); |
| 1770 | } |
| 1771 | else set_error( STATUS_INVALID_PARAMETER ); |
| 1772 | } |