Use GUIDs from itss.idl.
[wine/wine64.git] / server / console.c
blob871a66ebb49cde6fa6b4e51c17dde07f00194535
1 /*
2 * Server-side console management
4 * Copyright (C) 1998 Alexandre Julliard
5 * 2001 Eric Pouech
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.
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.
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
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "config.h"
24 #include "wine/port.h"
26 #include <assert.h>
27 #include <string.h>
28 #include <stdio.h>
29 #include <unistd.h>
30 #include <signal.h>
32 #include "handle.h"
33 #include "process.h"
34 #include "request.h"
35 #include "unicode.h"
36 #include "console.h"
38 static void console_input_dump( struct object *obj, int verbose );
39 static void console_input_destroy( struct object *obj );
41 static const struct object_ops console_input_ops =
43 sizeof(struct console_input), /* size */
44 console_input_dump, /* dump */
45 no_add_queue, /* add_queue */
46 NULL, /* remove_queue */
47 NULL, /* signaled */
48 no_satisfied, /* satisfied */
49 no_signal, /* signal */
50 no_get_fd, /* get_fd */
51 no_close_handle, /* close_handle */
52 console_input_destroy /* destroy */
55 static void console_input_events_dump( struct object *obj, int verbose );
56 static void console_input_events_destroy( struct object *obj );
57 static int console_input_events_signaled( struct object *obj, struct thread *thread );
59 struct console_input_events
61 struct object obj; /* object header */
62 int num_alloc; /* number of allocated events */
63 int num_used; /* number of actually used events */
64 struct console_renderer_event* events;
67 static const struct object_ops console_input_events_ops =
69 sizeof(struct console_input_events), /* size */
70 console_input_events_dump, /* dump */
71 add_queue, /* add_queue */
72 remove_queue, /* remove_queue */
73 console_input_events_signaled, /* signaled */
74 no_satisfied, /* satisfied */
75 no_signal, /* signal */
76 no_get_fd, /* get_fd */
77 no_close_handle, /* close_handle */
78 console_input_events_destroy /* destroy */
81 struct screen_buffer
83 struct object obj; /* object header */
84 struct list entry; /* entry in list of all screen buffers */
85 struct console_input *input; /* associated console input */
86 int mode; /* output mode */
87 int cursor_size; /* size of cursor (percentage filled) */
88 int cursor_visible;/* cursor visibility flag */
89 int cursor_x; /* position of cursor */
90 int cursor_y; /* position of cursor */
91 int width; /* size (w-h) of the screen buffer */
92 int height;
93 int max_width; /* size (w-h) of the window given font size */
94 int max_height;
95 char_info_t *data; /* the data for each cell - a width x height matrix */
96 unsigned short attr; /* default attribute for screen buffer */
97 rectangle_t win; /* current visible window on the screen buffer *
98 * as seen in wineconsole */
101 static void screen_buffer_dump( struct object *obj, int verbose );
102 static void screen_buffer_destroy( struct object *obj );
104 static const struct object_ops screen_buffer_ops =
106 sizeof(struct screen_buffer), /* size */
107 screen_buffer_dump, /* dump */
108 no_add_queue, /* add_queue */
109 NULL, /* remove_queue */
110 NULL, /* signaled */
111 NULL, /* satisfied */
112 no_signal, /* signal */
113 no_get_fd, /* get_fd */
114 no_close_handle, /* close_handle */
115 screen_buffer_destroy /* destroy */
118 static struct list screen_buffer_list = LIST_INIT(screen_buffer_list);
120 static const char_info_t empty_char_info = { ' ', 0x000f }; /* white on black space */
122 /* dumps the renderer events of a console */
123 static void console_input_events_dump( struct object *obj, int verbose )
125 struct console_input_events *evts = (struct console_input_events *)obj;
126 assert( obj->ops == &console_input_events_ops );
127 fprintf( stderr, "Console input events: %d/%d events\n",
128 evts->num_used, evts->num_alloc );
131 /* destroys the renderer events of a console */
132 static void console_input_events_destroy( struct object *obj )
134 struct console_input_events *evts = (struct console_input_events *)obj;
135 assert( obj->ops == &console_input_events_ops );
136 free( evts->events );
139 /* the renderer events list is signaled when it's not empty */
140 static int console_input_events_signaled( struct object *obj, struct thread *thread )
142 struct console_input_events *evts = (struct console_input_events *)obj;
143 assert( obj->ops == &console_input_events_ops );
144 return (evts->num_used != 0);
147 /* add an event to the console's renderer events list */
148 static void console_input_events_append( struct console_input_events* evts,
149 struct console_renderer_event* evt)
151 int collapsed = FALSE;
153 /* to be done even when evt has been generated by the rendere ? */
155 /* try to collapse evt into current queue's events */
156 if (evts->num_used)
158 struct console_renderer_event* last = &evts->events[evts->num_used - 1];
160 if (last->event == CONSOLE_RENDERER_UPDATE_EVENT &&
161 evt->event == CONSOLE_RENDERER_UPDATE_EVENT)
163 /* if two update events overlap, collapse them into a single one */
164 if (last->u.update.bottom + 1 >= evt->u.update.top &&
165 evt->u.update.bottom + 1 >= last->u.update.top)
167 last->u.update.top = min(last->u.update.top, evt->u.update.top);
168 last->u.update.bottom = max(last->u.update.bottom, evt->u.update.bottom);
169 collapsed = TRUE;
173 if (!collapsed)
175 if (evts->num_used == evts->num_alloc)
177 evts->num_alloc += 16;
178 evts->events = realloc( evts->events, evts->num_alloc * sizeof(*evt) );
179 assert(evts->events);
181 evts->events[evts->num_used++] = *evt;
183 wake_up( &evts->obj, 0 );
186 /* retrieves events from the console's renderer events list */
187 static void console_input_events_get( struct console_input_events* evts )
189 size_t num = get_reply_max_size() / sizeof(evts->events[0]);
191 if (num > evts->num_used) num = evts->num_used;
192 set_reply_data( evts->events, num * sizeof(evts->events[0]) );
193 if (num < evts->num_used)
195 memmove( &evts->events[0], &evts->events[num],
196 (evts->num_used - num) * sizeof(evts->events[0]) );
198 evts->num_used -= num;
201 static struct console_input_events *create_console_input_events(void)
203 struct console_input_events* evt;
205 if (!(evt = alloc_object( &console_input_events_ops ))) return NULL;
206 evt->num_alloc = evt->num_used = 0;
207 evt->events = NULL;
208 return evt;
211 static struct object *create_console_input( struct thread* renderer )
213 struct console_input *console_input;
215 if (!(console_input = alloc_object( &console_input_ops ))) return NULL;
216 console_input->renderer = renderer;
217 console_input->mode = ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT |
218 ENABLE_ECHO_INPUT | ENABLE_MOUSE_INPUT;
219 console_input->num_proc = 0;
220 console_input->active = NULL;
221 console_input->recnum = 0;
222 console_input->records = NULL;
223 console_input->evt = create_console_input_events();
224 console_input->title = NULL;
225 console_input->history_size = 50;
226 console_input->history = calloc( console_input->history_size, sizeof(WCHAR*) );
227 console_input->history_index = 0;
228 console_input->history_mode = 0;
229 console_input->edition_mode = 0;
230 console_input->event = create_event( NULL, 0, 1, 0 );
232 if (!console_input->history || !console_input->evt)
234 release_object( console_input );
235 return NULL;
237 return &console_input->obj;
240 static struct screen_buffer *create_console_output( struct console_input *console_input )
242 struct screen_buffer *screen_buffer;
243 struct console_renderer_event evt;
244 int i;
246 if (!(screen_buffer = alloc_object( &screen_buffer_ops ))) return NULL;
247 screen_buffer->mode = ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT;
248 screen_buffer->input = console_input;
249 screen_buffer->cursor_size = 100;
250 screen_buffer->cursor_visible = 1;
251 screen_buffer->width = 80;
252 screen_buffer->height = 150;
253 screen_buffer->max_width = 80;
254 screen_buffer->max_height = 25;
255 screen_buffer->cursor_x = 0;
256 screen_buffer->cursor_y = 0;
257 screen_buffer->attr = 0x0F;
258 screen_buffer->win.left = 0;
259 screen_buffer->win.right = screen_buffer->max_width - 1;
260 screen_buffer->win.top = 0;
261 screen_buffer->win.bottom = screen_buffer->max_height - 1;
263 list_add_head( &screen_buffer_list, &screen_buffer->entry );
265 if (!(screen_buffer->data = malloc( screen_buffer->width * screen_buffer->height *
266 sizeof(*screen_buffer->data) )))
268 release_object( screen_buffer );
269 return NULL;
271 /* clear the first row */
272 for (i = 0; i < screen_buffer->width; i++) screen_buffer->data[i] = empty_char_info;
273 /* and copy it to all other rows */
274 for (i = 1; i < screen_buffer->height; i++)
275 memcpy( &screen_buffer->data[i * screen_buffer->width], screen_buffer->data,
276 screen_buffer->width * sizeof(char_info_t) );
278 if (!console_input->active)
280 console_input->active = (struct screen_buffer*)grab_object( screen_buffer );
282 /* generate the initial events */
283 evt.event = CONSOLE_RENDERER_ACTIVE_SB_EVENT;
284 console_input_events_append( console_input->evt, &evt );
286 evt.event = CONSOLE_RENDERER_SB_RESIZE_EVENT;
287 evt.u.resize.width = screen_buffer->width;
288 evt.u.resize.height = screen_buffer->height;
289 console_input_events_append( console_input->evt, &evt );
291 evt.event = CONSOLE_RENDERER_DISPLAY_EVENT;
292 evt.u.display.left = screen_buffer->win.left;
293 evt.u.display.top = screen_buffer->win.top;
294 evt.u.display.width = screen_buffer->win.right - screen_buffer->win.left + 1;
295 evt.u.display.height = screen_buffer->win.bottom - screen_buffer->win.top + 1;
296 console_input_events_append( console_input->evt, &evt );
298 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
299 evt.u.update.top = 0;
300 evt.u.update.bottom = screen_buffer->height - 1;
301 console_input_events_append( console_input->evt, &evt );
303 evt.event = CONSOLE_RENDERER_CURSOR_GEOM_EVENT;
304 evt.u.cursor_geom.size = screen_buffer->cursor_size;
305 evt.u.cursor_geom.visible = screen_buffer->cursor_visible;
306 console_input_events_append( console_input->evt, &evt );
308 evt.event = CONSOLE_RENDERER_CURSOR_POS_EVENT;
309 evt.u.cursor_pos.x = screen_buffer->cursor_x;
310 evt.u.cursor_pos.y = screen_buffer->cursor_y;
311 console_input_events_append( console_input->evt, &evt );
313 return screen_buffer;
316 /* free the console for this process */
317 int free_console( struct process *process )
319 struct console_input* console = process->console;
321 if (!console || !console->renderer) return 0;
323 process->console = NULL;
324 if (--console->num_proc == 0)
326 /* all processes have terminated... tell the renderer to terminate too */
327 struct console_renderer_event evt;
328 evt.event = CONSOLE_RENDERER_EXIT_EVENT;
329 console_input_events_append( console->evt, &evt );
331 release_object( console );
333 return 1;
336 /* let process inherit the console from parent... this handle two cases :
337 * 1/ generic console inheritance
338 * 2/ parent is a renderer which launches process, and process should attach to the console
339 * renderered by parent
341 void inherit_console(struct thread *parent_thread, struct process *process, obj_handle_t hconin)
343 int done = 0;
344 struct process* parent = parent_thread->process;
346 /* if parent is a renderer, then attach current process to its console
347 * a bit hacky....
349 if (hconin)
351 struct console_input* console;
353 /* FIXME: should we check some access rights ? */
354 if ((console = (struct console_input*)get_handle_obj( parent, hconin,
355 0, &console_input_ops )))
357 if (console->renderer == parent_thread)
359 process->console = (struct console_input*)grab_object( console );
360 process->console->num_proc++;
361 done = 1;
363 release_object( console );
366 /* otherwise, if parent has a console, attach child to this console */
367 if (!done && parent->console)
369 assert(parent->console->renderer);
370 process->console = (struct console_input*)grab_object( parent->console );
371 process->console->num_proc++;
375 static struct console_input* console_input_get( obj_handle_t handle, unsigned access )
377 struct console_input* console = NULL;
379 if (handle)
380 console = (struct console_input *)get_handle_obj( current->process, handle,
381 access, &console_input_ops );
382 else if (current->process->console)
384 assert( current->process->console->renderer );
385 console = (struct console_input *)grab_object( current->process->console );
388 if (!console && !get_error()) set_error(STATUS_INVALID_PARAMETER);
389 return console;
392 struct console_signal_info
394 struct console_input *console;
395 process_id_t group;
396 int signal;
399 static int propagate_console_signal_cb(struct process *process, void *user)
401 struct console_signal_info* csi = (struct console_signal_info*)user;
403 if (process->console == csi->console && process->running_threads &&
404 (!csi->group || process->group_id == csi->group))
406 /* find a suitable thread to signal */
407 struct thread *thread;
408 LIST_FOR_EACH_ENTRY( thread, &process->thread_list, struct thread, proc_entry )
410 if (send_thread_signal( thread, csi->signal )) break;
413 return FALSE;
416 static void propagate_console_signal( struct console_input *console,
417 int sig, process_id_t group_id )
419 struct console_signal_info csi;
421 if (!console)
423 set_error( STATUS_INVALID_PARAMETER );
424 return;
426 /* FIXME: should support the other events (like CTRL_BREAK) */
427 if (sig != CTRL_C_EVENT)
429 set_error( STATUS_NOT_IMPLEMENTED );
430 return;
432 csi.console = console;
433 csi.signal = SIGINT;
434 csi.group = group_id;
436 enum_processes(propagate_console_signal_cb, &csi);
439 static int get_console_mode( obj_handle_t handle )
441 struct object *obj;
442 int ret = 0;
444 if ((obj = get_handle_obj( current->process, handle, GENERIC_READ, NULL )))
446 if (obj->ops == &console_input_ops)
447 ret = ((struct console_input *)obj)->mode;
448 else if (obj->ops == &screen_buffer_ops)
449 ret = ((struct screen_buffer *)obj)->mode;
450 else
451 set_error( STATUS_OBJECT_TYPE_MISMATCH );
452 release_object( obj );
454 return ret;
457 /* changes the mode of either a console input or a screen buffer */
458 static int set_console_mode( obj_handle_t handle, int mode )
460 struct object *obj;
461 int ret = 0;
463 if (!(obj = get_handle_obj( current->process, handle, GENERIC_WRITE, NULL )))
464 return 0;
465 if (obj->ops == &console_input_ops)
467 /* FIXME: if we remove the edit mode bits, we need (???) to clean up the history */
468 ((struct console_input *)obj)->mode = mode;
469 ret = 1;
471 else if (obj->ops == &screen_buffer_ops)
473 ((struct screen_buffer *)obj)->mode = mode;
474 ret = 1;
476 else set_error( STATUS_OBJECT_TYPE_MISMATCH );
477 release_object( obj );
478 return ret;
481 /* add input events to a console input queue */
482 static int write_console_input( struct console_input* console, int count,
483 const INPUT_RECORD *records )
485 INPUT_RECORD *new_rec;
487 if (!count) return 0;
488 if (!(new_rec = realloc( console->records,
489 (console->recnum + count) * sizeof(INPUT_RECORD) )))
491 set_error( STATUS_NO_MEMORY );
492 release_object( console );
493 return -1;
495 console->records = new_rec;
496 memcpy( new_rec + console->recnum, records, count * sizeof(INPUT_RECORD) );
498 if (console->mode & ENABLE_PROCESSED_INPUT)
500 int i = 0;
501 while (i < count)
503 if (records[i].EventType == KEY_EVENT &&
504 records[i].Event.KeyEvent.uChar.UnicodeChar == 'C' - 64 &&
505 !(records[i].Event.KeyEvent.dwControlKeyState & ENHANCED_KEY))
507 if (i != count - 1)
508 memcpy( &console->records[console->recnum + i],
509 &console->records[console->recnum + i + 1],
510 (count - i - 1) * sizeof(INPUT_RECORD) );
511 count--;
512 if (records[i].Event.KeyEvent.bKeyDown)
514 /* send SIGINT to all processes attached to this console */
515 propagate_console_signal( console, CTRL_C_EVENT, 0 );
518 else i++;
521 if (!console->recnum && count) set_event( console->event );
522 console->recnum += count;
523 return count;
526 /* retrieve a pointer to the console input records */
527 static int read_console_input( obj_handle_t handle, int count, int flush )
529 struct console_input *console;
531 if (!(console = (struct console_input *)get_handle_obj( current->process, handle,
532 GENERIC_READ, &console_input_ops )))
533 return -1;
535 if (!count)
537 /* special case: do not retrieve anything, but return
538 * the total number of records available */
539 count = console->recnum;
541 else
543 if (count > console->recnum) count = console->recnum;
544 set_reply_data( console->records, count * sizeof(INPUT_RECORD) );
546 if (flush)
548 int i;
549 for (i = count; i < console->recnum; i++)
550 console->records[i-count] = console->records[i];
551 if ((console->recnum -= count) > 0)
553 INPUT_RECORD *new_rec = realloc( console->records,
554 console->recnum * sizeof(INPUT_RECORD) );
555 if (new_rec) console->records = new_rec;
557 else
559 free( console->records );
560 console->records = NULL;
561 reset_event( console->event );
564 release_object( console );
565 return count;
568 /* set misc console input information */
569 static int set_console_input_info( const struct set_console_input_info_request *req,
570 const WCHAR *title, size_t len )
572 struct console_input *console;
573 struct console_renderer_event evt;
575 if (!(console = console_input_get( req->handle, GENERIC_WRITE ))) goto error;
577 if (req->mask & SET_CONSOLE_INPUT_INFO_ACTIVE_SB)
579 struct screen_buffer *screen_buffer;
581 screen_buffer = (struct screen_buffer *)get_handle_obj( current->process, req->active_sb,
582 GENERIC_READ, &screen_buffer_ops );
583 if (!screen_buffer || screen_buffer->input != console)
585 set_error( STATUS_INVALID_PARAMETER );
586 if (screen_buffer) release_object( screen_buffer );
587 goto error;
590 if (screen_buffer != console->active)
592 if (console->active) release_object( console->active );
593 console->active = screen_buffer;
594 evt.event = CONSOLE_RENDERER_ACTIVE_SB_EVENT;
595 console_input_events_append( console->evt, &evt );
597 else
598 release_object( screen_buffer );
600 if (req->mask & SET_CONSOLE_INPUT_INFO_TITLE)
602 WCHAR *new_title = mem_alloc( len + sizeof(WCHAR) );
603 if (new_title)
605 memcpy( new_title, title, len );
606 new_title[len / sizeof(WCHAR)] = 0;
607 if (console->title) free( console->title );
608 console->title = new_title;
609 evt.event = CONSOLE_RENDERER_TITLE_EVENT;
610 console_input_events_append( console->evt, &evt );
613 if (req->mask & SET_CONSOLE_INPUT_INFO_HISTORY_MODE)
615 console->history_mode = req->history_mode;
617 if ((req->mask & SET_CONSOLE_INPUT_INFO_HISTORY_SIZE) &&
618 console->history_size != req->history_size)
620 WCHAR** mem = NULL;
621 int i;
622 int delta;
624 if (req->history_size)
626 mem = mem_alloc( req->history_size * sizeof(WCHAR*) );
627 if (!mem) goto error;
628 memset( mem, 0, req->history_size * sizeof(WCHAR*) );
631 delta = (console->history_index > req->history_size) ?
632 (console->history_index - req->history_size) : 0;
634 for (i = delta; i < console->history_index; i++)
636 mem[i - delta] = console->history[i];
637 console->history[i] = NULL;
639 console->history_index -= delta;
641 for (i = 0; i < console->history_size; i++)
642 if (console->history[i]) free( console->history[i] );
643 free( console->history );
644 console->history = mem;
645 console->history_size = req->history_size;
647 if (req->mask & SET_CONSOLE_INPUT_INFO_EDITION_MODE)
649 console->edition_mode = req->edition_mode;
651 release_object( console );
652 return 1;
653 error:
654 if (console) release_object( console );
655 return 0;
658 /* resize a screen buffer */
659 static int change_screen_buffer_size( struct screen_buffer *screen_buffer,
660 int new_width, int new_height )
662 int i, old_width, old_height, copy_width, copy_height;
663 char_info_t *new_data;
665 if (!(new_data = malloc( new_width * new_height * sizeof(*new_data) )))
667 set_error( STATUS_NO_MEMORY );
668 return 0;
670 old_width = screen_buffer->width;
671 old_height = screen_buffer->height;
672 copy_width = min( old_width, new_width );
673 copy_height = min( old_height, new_height );
675 /* copy all the rows */
676 for (i = 0; i < copy_height; i++)
678 memcpy( &new_data[i * new_width], &screen_buffer->data[i * old_width],
679 copy_width * sizeof(char_info_t) );
682 /* clear the end of each row */
683 if (new_width > old_width)
685 /* fill first row */
686 for (i = old_width; i < new_width; i++) new_data[i] = empty_char_info;
687 /* and blast it to the other rows */
688 for (i = 1; i < copy_height; i++)
689 memcpy( &new_data[i * new_width + old_width], &new_data[old_width],
690 (new_width - old_width) * sizeof(char_info_t) );
693 /* clear remaining rows */
694 if (new_height > old_height)
696 /* fill first row */
697 for (i = 0; i < new_width; i++) new_data[old_height * new_width + i] = empty_char_info;
698 /* and blast it to the other rows */
699 for (i = old_height+1; i < new_height; i++)
700 memcpy( &new_data[i * new_width], &new_data[old_height * new_width],
701 new_width * sizeof(char_info_t) );
703 free( screen_buffer->data );
704 screen_buffer->data = new_data;
705 screen_buffer->width = new_width;
706 screen_buffer->height = new_height;
707 return 1;
710 /* set misc screen buffer information */
711 static int set_console_output_info( struct screen_buffer *screen_buffer,
712 const struct set_console_output_info_request *req )
714 struct console_renderer_event evt;
716 if (req->mask & SET_CONSOLE_OUTPUT_INFO_CURSOR_GEOM)
718 if (req->cursor_size < 1 || req->cursor_size > 100)
720 set_error( STATUS_INVALID_PARAMETER );
721 return 0;
723 if (screen_buffer->cursor_size != req->cursor_size ||
724 screen_buffer->cursor_visible != req->cursor_visible)
726 screen_buffer->cursor_size = req->cursor_size;
727 screen_buffer->cursor_visible = req->cursor_visible;
728 evt.event = CONSOLE_RENDERER_CURSOR_GEOM_EVENT;
729 evt.u.cursor_geom.size = req->cursor_size;
730 evt.u.cursor_geom.visible = req->cursor_visible;
731 console_input_events_append( screen_buffer->input->evt, &evt );
734 if (req->mask & SET_CONSOLE_OUTPUT_INFO_CURSOR_POS)
736 if (req->cursor_x < 0 || req->cursor_x >= screen_buffer->width ||
737 req->cursor_y < 0 || req->cursor_y >= screen_buffer->height)
739 set_error( STATUS_INVALID_PARAMETER );
740 return 0;
742 if (screen_buffer->cursor_x != req->cursor_x || screen_buffer->cursor_y != req->cursor_y)
744 screen_buffer->cursor_x = req->cursor_x;
745 screen_buffer->cursor_y = req->cursor_y;
746 evt.event = CONSOLE_RENDERER_CURSOR_POS_EVENT;
747 evt.u.cursor_pos.x = req->cursor_x;
748 evt.u.cursor_pos.y = req->cursor_y;
749 console_input_events_append( screen_buffer->input->evt, &evt );
752 if (req->mask & SET_CONSOLE_OUTPUT_INFO_SIZE)
754 unsigned cc;
756 /* new screen-buffer cannot be smaller than actual window */
757 if (req->width < screen_buffer->win.right - screen_buffer->win.left + 1 ||
758 req->height < screen_buffer->win.bottom - screen_buffer->win.top + 1)
760 set_error( STATUS_INVALID_PARAMETER );
761 return 0;
763 /* FIXME: there are also some basic minimum and max size to deal with */
764 if (!change_screen_buffer_size( screen_buffer, req->width, req->height )) return 0;
766 evt.event = CONSOLE_RENDERER_SB_RESIZE_EVENT;
767 evt.u.resize.width = req->width;
768 evt.u.resize.height = req->height;
769 console_input_events_append( screen_buffer->input->evt, &evt );
771 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
772 evt.u.update.top = 0;
773 evt.u.update.bottom = screen_buffer->height - 1;
774 console_input_events_append( screen_buffer->input->evt, &evt );
776 /* scroll window to display sb */
777 if (screen_buffer->win.right >= req->width)
779 screen_buffer->win.right -= screen_buffer->win.left;
780 screen_buffer->win.left = 0;
782 if (screen_buffer->win.bottom >= req->height)
784 screen_buffer->win.bottom -= screen_buffer->win.top;
785 screen_buffer->win.top = 0;
787 /* reset cursor if needed (normally, if cursor was outside of new sb, the
788 * window has been shifted so that the new position of the cursor will be
789 * visible */
790 cc = 0;
791 if (screen_buffer->cursor_x >= req->width)
793 screen_buffer->cursor_x = req->width - 1;
794 cc++;
796 if (screen_buffer->cursor_y >= req->height)
798 screen_buffer->cursor_y = req->height - 1;
799 cc++;
801 if (cc)
803 evt.event = CONSOLE_RENDERER_CURSOR_POS_EVENT;
804 evt.u.cursor_pos.x = req->cursor_x;
805 evt.u.cursor_pos.y = req->cursor_y;
806 console_input_events_append( screen_buffer->input->evt, &evt );
809 if (screen_buffer == screen_buffer->input->active &&
810 screen_buffer->input->mode & ENABLE_WINDOW_INPUT)
812 INPUT_RECORD ir;
813 ir.EventType = WINDOW_BUFFER_SIZE_EVENT;
814 ir.Event.WindowBufferSizeEvent.dwSize.X = req->width;
815 ir.Event.WindowBufferSizeEvent.dwSize.Y = req->height;
816 write_console_input( screen_buffer->input, 1, &ir );
819 if (req->mask & SET_CONSOLE_OUTPUT_INFO_ATTR)
821 screen_buffer->attr = req->attr;
823 if (req->mask & SET_CONSOLE_OUTPUT_INFO_DISPLAY_WINDOW)
825 if (req->win_left < 0 || req->win_left > req->win_right ||
826 req->win_right >= screen_buffer->width ||
827 req->win_top < 0 || req->win_top > req->win_bottom ||
828 req->win_bottom >= screen_buffer->height)
830 set_error( STATUS_INVALID_PARAMETER );
831 return 0;
833 if (screen_buffer->win.left != req->win_left || screen_buffer->win.top != req->win_top ||
834 screen_buffer->win.right != req->win_right || screen_buffer->win.bottom != req->win_bottom)
836 screen_buffer->win.left = req->win_left;
837 screen_buffer->win.top = req->win_top;
838 screen_buffer->win.right = req->win_right;
839 screen_buffer->win.bottom = req->win_bottom;
840 evt.event = CONSOLE_RENDERER_DISPLAY_EVENT;
841 evt.u.display.left = req->win_left;
842 evt.u.display.top = req->win_top;
843 evt.u.display.width = req->win_right - req->win_left + 1;
844 evt.u.display.height = req->win_bottom - req->win_top + 1;
845 console_input_events_append( screen_buffer->input->evt, &evt );
848 if (req->mask & SET_CONSOLE_OUTPUT_INFO_MAX_SIZE)
850 /* can only be done by renderer */
851 if (current->process->console != screen_buffer->input)
853 set_error( STATUS_INVALID_PARAMETER );
854 return 0;
857 screen_buffer->max_width = req->max_width;
858 screen_buffer->max_height = req->max_height;
861 return 1;
864 /* appends a new line to history (history is a fixed size array) */
865 static void console_input_append_hist( struct console_input* console, const WCHAR* buf, size_t len )
867 WCHAR* ptr = mem_alloc( (len + 1) * sizeof(WCHAR) );
869 if (!ptr)
871 set_error( STATUS_NO_MEMORY );
872 return;
874 if (!console || !console->history_size)
876 set_error( STATUS_INVALID_PARAMETER ); /* FIXME */
877 return;
880 memcpy( ptr, buf, len * sizeof(WCHAR) );
881 ptr[len] = 0;
883 if (console->history_mode && console->history_index &&
884 strncmpW( console->history[console->history_index - 1], ptr, len * sizeof(WCHAR) ) == 0)
886 /* ok, mode ask us to not use twice the same string...
887 * so just free mem and returns
889 set_error( STATUS_ALIAS_EXISTS );
890 free(ptr);
891 return;
894 if (console->history_index < console->history_size)
896 console->history[console->history_index++] = ptr;
898 else
900 free( console->history[0]) ;
901 memmove( &console->history[0], &console->history[1],
902 (console->history_size - 1) * sizeof(WCHAR*) );
903 console->history[console->history_size - 1] = ptr;
907 /* returns a line from the cache */
908 static size_t console_input_get_hist( struct console_input *console, int index )
910 size_t ret = 0;
912 if (index >= console->history_index) set_error( STATUS_INVALID_PARAMETER );
913 else
915 ret = strlenW( console->history[index] ) * sizeof(WCHAR);
916 set_reply_data( console->history[index], min( ret, get_reply_max_size() ));
918 return ret;
921 /* dumb dump */
922 static void console_input_dump( struct object *obj, int verbose )
924 struct console_input *console = (struct console_input *)obj;
925 assert( obj->ops == &console_input_ops );
926 fprintf( stderr, "Console input active=%p evt=%p\n",
927 console->active, console->evt );
930 static void console_input_destroy( struct object *obj )
932 struct console_input* console_in = (struct console_input *)obj;
933 struct screen_buffer* curr;
934 int i;
936 assert( obj->ops == &console_input_ops );
937 if (console_in->title) free( console_in->title );
938 if (console_in->records) free( console_in->records );
940 if (console_in->active) release_object( console_in->active );
941 console_in->active = NULL;
943 LIST_FOR_EACH_ENTRY( curr, &screen_buffer_list, struct screen_buffer, entry )
945 if (curr->input == console_in) curr->input = NULL;
948 release_object( console_in->evt );
949 console_in->evt = NULL;
950 release_object( console_in->event );
952 for (i = 0; i < console_in->history_size; i++)
953 if (console_in->history[i]) free( console_in->history[i] );
954 if (console_in->history) free( console_in->history );
957 static void screen_buffer_dump( struct object *obj, int verbose )
959 struct screen_buffer *screen_buffer = (struct screen_buffer *)obj;
960 assert( obj->ops == &screen_buffer_ops );
962 fprintf(stderr, "Console screen buffer input=%p\n", screen_buffer->input );
965 static void screen_buffer_destroy( struct object *obj )
967 struct screen_buffer *screen_buffer = (struct screen_buffer *)obj;
969 assert( obj->ops == &screen_buffer_ops );
971 list_remove( &screen_buffer->entry );
973 if (screen_buffer->input && screen_buffer->input->active == screen_buffer)
975 struct screen_buffer *sb;
977 screen_buffer->input->active = NULL;
978 LIST_FOR_EACH_ENTRY( sb, &screen_buffer_list, struct screen_buffer, entry )
980 if (sb->input == screen_buffer->input)
982 sb->input->active = sb;
983 break;
987 if (screen_buffer->data) free( screen_buffer->data );
990 /* write data into a screen buffer */
991 static int write_console_output( struct screen_buffer *screen_buffer, size_t size,
992 const void* data, enum char_info_mode mode,
993 int x, int y, int wrap )
995 int i;
996 char_info_t *end, *dest = screen_buffer->data + y * screen_buffer->width + x;
998 if (y >= screen_buffer->height) return 0;
1000 if (wrap)
1001 end = screen_buffer->data + screen_buffer->height * screen_buffer->width;
1002 else
1003 end = screen_buffer->data + (y+1) * screen_buffer->width;
1005 switch(mode)
1007 case CHAR_INFO_MODE_TEXT:
1009 const WCHAR *ptr = data;
1010 for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++) dest->ch = ptr[i];
1012 break;
1013 case CHAR_INFO_MODE_ATTR:
1015 const unsigned short *ptr = data;
1016 for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++) dest->attr = ptr[i];
1018 break;
1019 case CHAR_INFO_MODE_TEXTATTR:
1021 const char_info_t *ptr = data;
1022 for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++) *dest = ptr[i];
1024 break;
1025 case CHAR_INFO_MODE_TEXTSTDATTR:
1027 const WCHAR *ptr = data;
1028 for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++)
1030 dest->ch = ptr[i];
1031 dest->attr = screen_buffer->attr;
1034 break;
1035 default:
1036 set_error( STATUS_INVALID_PARAMETER );
1037 return 0;
1040 if (i && screen_buffer == screen_buffer->input->active)
1042 struct console_renderer_event evt;
1043 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
1044 evt.u.update.top = y + x / screen_buffer->width;
1045 evt.u.update.bottom = y + (x + i - 1) / screen_buffer->width;
1046 console_input_events_append( screen_buffer->input->evt, &evt );
1048 return i;
1051 /* fill a screen buffer with uniform data */
1052 static int fill_console_output( struct screen_buffer *screen_buffer, char_info_t data,
1053 enum char_info_mode mode, int x, int y, int count, int wrap )
1055 int i;
1056 char_info_t *end, *dest = screen_buffer->data + y * screen_buffer->width + x;
1058 if (y >= screen_buffer->height) return 0;
1060 if (wrap)
1061 end = screen_buffer->data + screen_buffer->height * screen_buffer->width;
1062 else
1063 end = screen_buffer->data + (y+1) * screen_buffer->width;
1065 if (count > end - dest) count = end - dest;
1067 switch(mode)
1069 case CHAR_INFO_MODE_TEXT:
1070 for (i = 0; i < count; i++) dest[i].ch = data.ch;
1071 break;
1072 case CHAR_INFO_MODE_ATTR:
1073 for (i = 0; i < count; i++) dest[i].attr = data.attr;
1074 break;
1075 case CHAR_INFO_MODE_TEXTATTR:
1076 for (i = 0; i < count; i++) dest[i] = data;
1077 break;
1078 case CHAR_INFO_MODE_TEXTSTDATTR:
1079 for (i = 0; i < count; i++)
1081 dest[i].ch = data.ch;
1082 dest[i].attr = screen_buffer->attr;
1084 break;
1085 default:
1086 set_error( STATUS_INVALID_PARAMETER );
1087 return 0;
1090 if (count && screen_buffer == screen_buffer->input->active)
1092 struct console_renderer_event evt;
1093 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
1094 evt.u.update.top = y;
1095 evt.u.update.bottom = (y * screen_buffer->width + x + count - 1) / screen_buffer->width;
1096 console_input_events_append( screen_buffer->input->evt, &evt );
1098 return i;
1101 /* read data from a screen buffer */
1102 static void read_console_output( struct screen_buffer *screen_buffer, int x, int y,
1103 enum char_info_mode mode, int wrap )
1105 int i;
1106 char_info_t *end, *src = screen_buffer->data + y * screen_buffer->width + x;
1108 if (y >= screen_buffer->height) return;
1110 if (wrap)
1111 end = screen_buffer->data + screen_buffer->height * screen_buffer->width;
1112 else
1113 end = screen_buffer->data + (y+1) * screen_buffer->width;
1115 switch(mode)
1117 case CHAR_INFO_MODE_TEXT:
1119 WCHAR *data;
1120 int count = min( end - src, get_reply_max_size() / sizeof(*data) );
1121 if ((data = set_reply_data_size( count * sizeof(*data) )))
1123 for (i = 0; i < count; i++) data[i] = src[i].ch;
1126 break;
1127 case CHAR_INFO_MODE_ATTR:
1129 unsigned short *data;
1130 int count = min( end - src, get_reply_max_size() / sizeof(*data) );
1131 if ((data = set_reply_data_size( count * sizeof(*data) )))
1133 for (i = 0; i < count; i++) data[i] = src[i].attr;
1136 break;
1137 case CHAR_INFO_MODE_TEXTATTR:
1139 char_info_t *data;
1140 int count = min( end - src, get_reply_max_size() / sizeof(*data) );
1141 if ((data = set_reply_data_size( count * sizeof(*data) )))
1143 for (i = 0; i < count; i++) data[i] = src[i];
1146 break;
1147 default:
1148 set_error( STATUS_INVALID_PARAMETER );
1149 break;
1153 /* scroll parts of a screen buffer */
1154 static void scroll_console_output( obj_handle_t handle, int xsrc, int ysrc, int xdst, int ydst,
1155 int w, int h )
1157 struct screen_buffer *screen_buffer;
1158 int j;
1159 char_info_t *psrc, *pdst;
1160 struct console_renderer_event evt;
1162 if (!(screen_buffer = (struct screen_buffer *)get_handle_obj( current->process, handle,
1163 GENERIC_READ, &screen_buffer_ops )))
1164 return;
1165 if (xsrc < 0 || ysrc < 0 || xdst < 0 || ydst < 0 ||
1166 xsrc + w > screen_buffer->width ||
1167 xdst + w > screen_buffer->width ||
1168 ysrc + h > screen_buffer->height ||
1169 ydst + h > screen_buffer->height ||
1170 w == 0 || h == 0)
1172 set_error( STATUS_INVALID_PARAMETER );
1173 release_object( screen_buffer );
1174 return;
1177 if (ysrc < ydst)
1179 psrc = &screen_buffer->data[(ysrc + h - 1) * screen_buffer->width + xsrc];
1180 pdst = &screen_buffer->data[(ydst + h - 1) * screen_buffer->width + xdst];
1182 for (j = h; j > 0; j--)
1184 memcpy(pdst, psrc, w * sizeof(*pdst) );
1185 pdst -= screen_buffer->width;
1186 psrc -= screen_buffer->width;
1189 else
1191 psrc = &screen_buffer->data[ysrc * screen_buffer->width + xsrc];
1192 pdst = &screen_buffer->data[ydst * screen_buffer->width + xdst];
1194 for (j = 0; j < h; j++)
1196 /* we use memmove here because when psrc and pdst are the same,
1197 * copies are done on the same row, so the dst and src blocks
1198 * can overlap */
1199 memmove( pdst, psrc, w * sizeof(*pdst) );
1200 pdst += screen_buffer->width;
1201 psrc += screen_buffer->width;
1205 /* FIXME: this could be enhanced, by signalling scroll */
1206 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
1207 evt.u.update.top = min(ysrc, ydst);
1208 evt.u.update.bottom = max(ysrc, ydst) + h - 1;
1209 console_input_events_append( screen_buffer->input->evt, &evt );
1211 release_object( screen_buffer );
1214 /* allocate a console for the renderer */
1215 DECL_HANDLER(alloc_console)
1217 obj_handle_t in = 0;
1218 obj_handle_t evt = 0;
1219 struct process *process;
1220 struct process *renderer = current->process;
1221 struct console_input *console;
1223 process = (req->pid) ? get_process_from_id( req->pid ) :
1224 (struct process *)grab_object( renderer->parent );
1226 reply->handle_in = 0;
1227 reply->event = 0;
1228 if (!process) return;
1229 if (process != renderer && process->console)
1231 set_error( STATUS_ACCESS_DENIED );
1232 goto the_end;
1234 if ((console = (struct console_input*)create_console_input( current )))
1236 if ((in = alloc_handle( renderer, console, req->access, req->inherit )))
1238 if ((evt = alloc_handle( renderer, console->evt,
1239 SYNCHRONIZE|GENERIC_READ|GENERIC_WRITE, FALSE )))
1241 if (process != renderer)
1243 process->console = (struct console_input*)grab_object( console );
1244 console->num_proc++;
1246 reply->handle_in = in;
1247 reply->event = evt;
1248 release_object( console );
1249 goto the_end;
1251 close_handle( renderer, in, NULL );
1253 free_console( process );
1255 the_end:
1256 release_object( process );
1259 /* free the console of the current process */
1260 DECL_HANDLER(free_console)
1262 free_console( current->process );
1265 /* let the renderer peek the events it's waiting on */
1266 DECL_HANDLER(get_console_renderer_events)
1268 struct console_input_events *evt;
1270 evt = (struct console_input_events *)get_handle_obj( current->process, req->handle,
1271 GENERIC_WRITE, &console_input_events_ops );
1272 if (!evt) return;
1273 console_input_events_get( evt );
1274 release_object( evt );
1277 /* open a handle to the process console */
1278 DECL_HANDLER(open_console)
1280 struct object *obj = NULL;
1282 reply->handle = 0;
1283 switch (req->from)
1285 case 0:
1286 if (current->process->console && current->process->console->renderer)
1287 obj = grab_object( (struct object*)current->process->console );
1288 break;
1289 case 1:
1290 if (current->process->console && current->process->console->renderer &&
1291 current->process->console->active)
1292 obj = grab_object( (struct object*)current->process->console->active );
1293 break;
1294 default:
1295 if ((obj = get_handle_obj( current->process, (obj_handle_t)req->from,
1296 GENERIC_READ|GENERIC_WRITE, &console_input_ops )))
1298 struct console_input* console = (struct console_input*)obj;
1299 obj = (console->active) ? grab_object( console->active ) : NULL;
1300 release_object( console );
1302 break;
1305 /* FIXME: req->share is not used (as in screen buffer creation) */
1306 if (obj)
1308 reply->handle = alloc_handle( current->process, obj, req->access, req->inherit );
1309 release_object( obj );
1311 else if (!get_error()) set_error( STATUS_ACCESS_DENIED );
1314 /* set info about a console input */
1315 DECL_HANDLER(set_console_input_info)
1317 set_console_input_info( req, get_req_data(), get_req_data_size() );
1320 /* get info about a console (output only) */
1321 DECL_HANDLER(get_console_input_info)
1323 struct console_input *console;
1325 if (!(console = console_input_get( req->handle, GENERIC_READ ))) return;
1326 if (console->title)
1328 size_t len = strlenW( console->title ) * sizeof(WCHAR);
1329 if (len > get_reply_max_size()) len = get_reply_max_size();
1330 set_reply_data( console->title, len );
1332 reply->history_mode = console->history_mode;
1333 reply->history_size = console->history_size;
1334 reply->history_index = console->history_index;
1335 reply->edition_mode = console->edition_mode;
1337 release_object( console );
1340 /* get a console mode (input or output) */
1341 DECL_HANDLER(get_console_mode)
1343 reply->mode = get_console_mode( req->handle );
1346 /* set a console mode (input or output) */
1347 DECL_HANDLER(set_console_mode)
1349 set_console_mode( req->handle, req->mode );
1352 /* add input records to a console input queue */
1353 DECL_HANDLER(write_console_input)
1355 struct console_input *console;
1357 reply->written = 0;
1358 if (!(console = (struct console_input *)get_handle_obj( current->process, req->handle,
1359 GENERIC_WRITE, &console_input_ops )))
1360 return;
1361 reply->written = write_console_input( console, get_req_data_size() / sizeof(INPUT_RECORD),
1362 get_req_data() );
1363 release_object( console );
1366 /* fetch input records from a console input queue */
1367 DECL_HANDLER(read_console_input)
1369 int count = get_reply_max_size() / sizeof(INPUT_RECORD);
1370 reply->read = read_console_input( req->handle, count, req->flush );
1373 /* appends a string to console's history */
1374 DECL_HANDLER(append_console_input_history)
1376 struct console_input *console;
1378 if (!(console = console_input_get( req->handle, GENERIC_WRITE ))) return;
1379 console_input_append_hist( console, get_req_data(), get_req_data_size() / sizeof(WCHAR) );
1380 release_object( console );
1383 /* appends a string to console's history */
1384 DECL_HANDLER(get_console_input_history)
1386 struct console_input *console;
1388 if (!(console = console_input_get( req->handle, GENERIC_WRITE ))) return;
1389 reply->total = console_input_get_hist( console, req->index );
1390 release_object( console );
1393 /* creates a screen buffer */
1394 DECL_HANDLER(create_console_output)
1396 struct console_input* console;
1397 struct screen_buffer* screen_buffer;
1399 if (!(console = console_input_get( req->handle_in, GENERIC_WRITE))) return;
1401 screen_buffer = create_console_output( console );
1402 if (screen_buffer)
1404 /* FIXME: should store sharing and test it when opening the CONOUT$ device
1405 * see file.c on how this could be done */
1406 reply->handle_out = alloc_handle( current->process, screen_buffer,
1407 req->access, req->inherit );
1408 release_object( screen_buffer );
1410 release_object( console );
1413 /* set info about a console screen buffer */
1414 DECL_HANDLER(set_console_output_info)
1416 struct screen_buffer *screen_buffer;
1418 if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle,
1419 GENERIC_WRITE, &screen_buffer_ops)))
1421 set_console_output_info( screen_buffer, req );
1422 release_object( screen_buffer );
1426 /* get info about a console screen buffer */
1427 DECL_HANDLER(get_console_output_info)
1429 struct screen_buffer *screen_buffer;
1431 if ((screen_buffer = (struct screen_buffer *)get_handle_obj( current->process, req->handle,
1432 GENERIC_READ, &screen_buffer_ops)))
1434 reply->cursor_size = screen_buffer->cursor_size;
1435 reply->cursor_visible = screen_buffer->cursor_visible;
1436 reply->cursor_x = screen_buffer->cursor_x;
1437 reply->cursor_y = screen_buffer->cursor_y;
1438 reply->width = screen_buffer->width;
1439 reply->height = screen_buffer->height;
1440 reply->attr = screen_buffer->attr;
1441 reply->win_left = screen_buffer->win.left;
1442 reply->win_top = screen_buffer->win.top;
1443 reply->win_right = screen_buffer->win.right;
1444 reply->win_bottom = screen_buffer->win.bottom;
1445 reply->max_width = screen_buffer->max_width;
1446 reply->max_height = screen_buffer->max_height;
1447 release_object( screen_buffer );
1451 /* read data (chars & attrs) from a screen buffer */
1452 DECL_HANDLER(read_console_output)
1454 struct screen_buffer *screen_buffer;
1456 if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle,
1457 GENERIC_READ, &screen_buffer_ops )))
1459 read_console_output( screen_buffer, req->x, req->y, req->mode, req->wrap );
1460 reply->width = screen_buffer->width;
1461 reply->height = screen_buffer->height;
1462 release_object( screen_buffer );
1466 /* write data (char and/or attrs) to a screen buffer */
1467 DECL_HANDLER(write_console_output)
1469 struct screen_buffer *screen_buffer;
1471 if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle,
1472 GENERIC_WRITE, &screen_buffer_ops)))
1474 reply->written = write_console_output( screen_buffer, get_req_data_size(), get_req_data(),
1475 req->mode, req->x, req->y, req->wrap );
1476 reply->width = screen_buffer->width;
1477 reply->height = screen_buffer->height;
1478 release_object( screen_buffer );
1482 /* fill a screen buffer with constant data (chars and/or attributes) */
1483 DECL_HANDLER(fill_console_output)
1485 struct screen_buffer *screen_buffer;
1487 if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle,
1488 GENERIC_WRITE, &screen_buffer_ops)))
1490 reply->written = fill_console_output( screen_buffer, req->data, req->mode,
1491 req->x, req->y, req->count, req->wrap );
1492 release_object( screen_buffer );
1496 /* move a rect of data in a screen buffer */
1497 DECL_HANDLER(move_console_output)
1499 scroll_console_output( req->handle, req->x_src, req->y_src, req->x_dst, req->y_dst,
1500 req->w, req->h );
1503 /* sends a signal to a console (process, group...) */
1504 DECL_HANDLER(send_console_signal)
1506 process_id_t group;
1508 group = req->group_id ? req->group_id : current->process->group_id;
1510 if (!group)
1511 set_error( STATUS_INVALID_PARAMETER );
1512 else
1513 propagate_console_signal( current->process->console, req->signal, group );
1516 /* get console which renderer is 'current' */
1517 static int cgwe_enum( struct process* process, void* user)
1519 if (process->console && process->console->renderer == current)
1521 *(struct console_input**)user = process->console;
1522 return 1;
1524 return 0;
1527 DECL_HANDLER(get_console_wait_event)
1529 struct console_input* console = NULL;
1531 if (current->process->console && current->process->console->renderer)
1532 console = (struct console_input*)grab_object( (struct object*)current->process->console );
1533 else enum_processes(cgwe_enum, &console);
1535 if (console)
1537 reply->handle = alloc_handle( current->process, console->event,
1538 EVENT_ALL_ACCESS, FALSE);
1539 release_object( console );
1541 else set_error( STATUS_INVALID_PARAMETER );