No need continuing tests if no NetUserGetInfo.
[wine/multimedia.git] / server / console.c
blobb51f56de2b8efe570ef508fe6a4a2e6378a99fe1
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_get_fd, /* get_fd */
50 console_input_destroy /* destroy */
53 static void console_input_events_dump( struct object *obj, int verbose );
54 static void console_input_events_destroy( struct object *obj );
55 static int console_input_events_signaled( struct object *obj, struct thread *thread );
57 struct console_input_events
59 struct object obj; /* object header */
60 int num_alloc; /* number of allocated events */
61 int num_used; /* number of actually used events */
62 struct console_renderer_event* events;
65 static const struct object_ops console_input_events_ops =
67 sizeof(struct console_input_events), /* size */
68 console_input_events_dump, /* dump */
69 add_queue, /* add_queue */
70 remove_queue, /* remove_queue */
71 console_input_events_signaled, /* signaled */
72 no_satisfied, /* satisfied */
73 no_get_fd, /* get_fd */
74 console_input_events_destroy /* destroy */
77 struct screen_buffer
79 struct object obj; /* object header */
80 struct list entry; /* entry in list of all screen buffers */
81 struct console_input *input; /* associated console input */
82 int mode; /* output mode */
83 int cursor_size; /* size of cursor (percentage filled) */
84 int cursor_visible;/* cursor visibility flag */
85 int cursor_x; /* position of cursor */
86 int cursor_y; /* position of cursor */
87 int width; /* size (w-h) of the screen buffer */
88 int height;
89 int max_width; /* size (w-h) of the window given font size */
90 int max_height;
91 char_info_t *data; /* the data for each cell - a width x height matrix */
92 unsigned short attr; /* default attribute for screen buffer */
93 rectangle_t win; /* current visible window on the screen buffer *
94 * as seen in wineconsole */
97 static void screen_buffer_dump( struct object *obj, int verbose );
98 static void screen_buffer_destroy( struct object *obj );
100 static const struct object_ops screen_buffer_ops =
102 sizeof(struct screen_buffer), /* size */
103 screen_buffer_dump, /* dump */
104 no_add_queue, /* add_queue */
105 NULL, /* remove_queue */
106 NULL, /* signaled */
107 NULL, /* satisfied */
108 no_get_fd, /* get_fd */
109 screen_buffer_destroy /* destroy */
112 static struct list screen_buffer_list = LIST_INIT(screen_buffer_list);
114 static const char_info_t empty_char_info = { ' ', 0x000f }; /* white on black space */
116 /* dumps the renderer events of a console */
117 static void console_input_events_dump( struct object *obj, int verbose )
119 struct console_input_events *evts = (struct console_input_events *)obj;
120 assert( obj->ops == &console_input_events_ops );
121 fprintf( stderr, "Console input events: %d/%d events\n",
122 evts->num_used, evts->num_alloc );
125 /* destroys the renderer events of a console */
126 static void console_input_events_destroy( struct object *obj )
128 struct console_input_events *evts = (struct console_input_events *)obj;
129 assert( obj->ops == &console_input_events_ops );
130 free( evts->events );
133 /* the renderer events list is signaled when it's not empty */
134 static int console_input_events_signaled( struct object *obj, struct thread *thread )
136 struct console_input_events *evts = (struct console_input_events *)obj;
137 assert( obj->ops == &console_input_events_ops );
138 return (evts->num_used != 0);
141 /* add an event to the console's renderer events list */
142 static void console_input_events_append( struct console_input_events* evts,
143 struct console_renderer_event* evt)
145 int collapsed = FALSE;
147 /* to be done even when evt has been generated by the rendere ? */
149 /* try to collapse evt into current queue's events */
150 if (evts->num_used)
152 struct console_renderer_event* last = &evts->events[evts->num_used - 1];
154 if (last->event == CONSOLE_RENDERER_UPDATE_EVENT &&
155 evt->event == CONSOLE_RENDERER_UPDATE_EVENT)
157 /* if two update events overlap, collapse them into a single one */
158 if (last->u.update.bottom + 1 >= evt->u.update.top &&
159 evt->u.update.bottom + 1 >= last->u.update.top)
161 last->u.update.top = min(last->u.update.top, evt->u.update.top);
162 last->u.update.bottom = max(last->u.update.bottom, evt->u.update.bottom);
163 collapsed = TRUE;
167 if (!collapsed)
169 if (evts->num_used == evts->num_alloc)
171 evts->num_alloc += 16;
172 evts->events = realloc( evts->events, evts->num_alloc * sizeof(*evt) );
173 assert(evts->events);
175 evts->events[evts->num_used++] = *evt;
177 wake_up( &evts->obj, 0 );
180 /* retrieves events from the console's renderer events list */
181 static void console_input_events_get( struct console_input_events* evts )
183 size_t num = get_reply_max_size() / sizeof(evts->events[0]);
185 if (num > evts->num_used) num = evts->num_used;
186 set_reply_data( evts->events, num * sizeof(evts->events[0]) );
187 if (num < evts->num_used)
189 memmove( &evts->events[0], &evts->events[num],
190 (evts->num_used - num) * sizeof(evts->events[0]) );
192 evts->num_used -= num;
195 static struct console_input_events *create_console_input_events(void)
197 struct console_input_events* evt;
199 if (!(evt = alloc_object( &console_input_events_ops ))) return NULL;
200 evt->num_alloc = evt->num_used = 0;
201 evt->events = NULL;
202 return evt;
205 static struct object *create_console_input( struct thread* renderer )
207 struct console_input *console_input;
209 if (!(console_input = alloc_object( &console_input_ops ))) return NULL;
210 console_input->renderer = renderer;
211 console_input->mode = ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT |
212 ENABLE_ECHO_INPUT | ENABLE_MOUSE_INPUT;
213 console_input->num_proc = 0;
214 console_input->active = NULL;
215 console_input->recnum = 0;
216 console_input->records = NULL;
217 console_input->evt = create_console_input_events();
218 console_input->title = NULL;
219 console_input->history_size = 50;
220 console_input->history = calloc( console_input->history_size, sizeof(WCHAR*) );
221 console_input->history_index = 0;
222 console_input->history_mode = 0;
223 console_input->edition_mode = 0;
224 console_input->event = create_event( NULL, 0, 1, 0 );
226 if (!console_input->history || !console_input->evt)
228 release_object( console_input );
229 return NULL;
231 return &console_input->obj;
234 static struct screen_buffer *create_console_output( struct console_input *console_input )
236 struct screen_buffer *screen_buffer;
237 struct console_renderer_event evt;
238 int i;
240 if (!(screen_buffer = alloc_object( &screen_buffer_ops ))) return NULL;
241 screen_buffer->mode = ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT;
242 screen_buffer->input = console_input;
243 screen_buffer->cursor_size = 100;
244 screen_buffer->cursor_visible = 1;
245 screen_buffer->width = 80;
246 screen_buffer->height = 150;
247 screen_buffer->max_width = 80;
248 screen_buffer->max_height = 25;
249 screen_buffer->cursor_x = 0;
250 screen_buffer->cursor_y = 0;
251 screen_buffer->attr = 0x0F;
252 screen_buffer->win.left = 0;
253 screen_buffer->win.right = screen_buffer->max_width - 1;
254 screen_buffer->win.top = 0;
255 screen_buffer->win.bottom = screen_buffer->max_height - 1;
257 list_add_head( &screen_buffer_list, &screen_buffer->entry );
259 if (!(screen_buffer->data = malloc( screen_buffer->width * screen_buffer->height *
260 sizeof(*screen_buffer->data) )))
262 release_object( screen_buffer );
263 return NULL;
265 /* clear the first row */
266 for (i = 0; i < screen_buffer->width; i++) screen_buffer->data[i] = empty_char_info;
267 /* and copy it to all other rows */
268 for (i = 1; i < screen_buffer->height; i++)
269 memcpy( &screen_buffer->data[i * screen_buffer->width], screen_buffer->data,
270 screen_buffer->width * sizeof(char_info_t) );
272 if (!console_input->active)
274 console_input->active = (struct screen_buffer*)grab_object( screen_buffer );
276 /* generate the initial events */
277 evt.event = CONSOLE_RENDERER_ACTIVE_SB_EVENT;
278 console_input_events_append( console_input->evt, &evt );
280 evt.event = CONSOLE_RENDERER_SB_RESIZE_EVENT;
281 evt.u.resize.width = screen_buffer->width;
282 evt.u.resize.height = screen_buffer->height;
283 console_input_events_append( console_input->evt, &evt );
285 evt.event = CONSOLE_RENDERER_DISPLAY_EVENT;
286 evt.u.display.left = screen_buffer->win.left;
287 evt.u.display.top = screen_buffer->win.top;
288 evt.u.display.width = screen_buffer->win.right - screen_buffer->win.left + 1;
289 evt.u.display.height = screen_buffer->win.bottom - screen_buffer->win.top + 1;
290 console_input_events_append( console_input->evt, &evt );
292 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
293 evt.u.update.top = 0;
294 evt.u.update.bottom = screen_buffer->height - 1;
295 console_input_events_append( console_input->evt, &evt );
297 evt.event = CONSOLE_RENDERER_CURSOR_GEOM_EVENT;
298 evt.u.cursor_geom.size = screen_buffer->cursor_size;
299 evt.u.cursor_geom.visible = screen_buffer->cursor_visible;
300 console_input_events_append( console_input->evt, &evt );
302 evt.event = CONSOLE_RENDERER_CURSOR_POS_EVENT;
303 evt.u.cursor_pos.x = screen_buffer->cursor_x;
304 evt.u.cursor_pos.y = screen_buffer->cursor_y;
305 console_input_events_append( console_input->evt, &evt );
307 return screen_buffer;
310 /* free the console for this process */
311 int free_console( struct process *process )
313 struct console_input* console = process->console;
315 if (!console || !console->renderer) return 0;
317 process->console = NULL;
318 if (--console->num_proc == 0)
320 /* all processes have terminated... tell the renderer to terminate too */
321 struct console_renderer_event evt;
322 evt.event = CONSOLE_RENDERER_EXIT_EVENT;
323 console_input_events_append( console->evt, &evt );
325 release_object( console );
327 return 1;
330 /* let process inherit the console from parent... this handle two cases :
331 * 1/ generic console inheritance
332 * 2/ parent is a renderer which launches process, and process should attach to the console
333 * renderered by parent
335 void inherit_console(struct thread *parent_thread, struct process *process, obj_handle_t hconin)
337 int done = 0;
338 struct process* parent = parent_thread->process;
340 /* if parent is a renderer, then attach current process to its console
341 * a bit hacky....
343 if (hconin)
345 struct console_input* console;
347 /* FIXME: should we check some access rights ? */
348 if ((console = (struct console_input*)get_handle_obj( parent, hconin,
349 0, &console_input_ops )))
351 if (console->renderer == parent_thread)
353 process->console = (struct console_input*)grab_object( console );
354 process->console->num_proc++;
355 done = 1;
357 release_object( console );
360 /* otherwise, if parent has a console, attach child to this console */
361 if (!done && parent->console)
363 assert(parent->console->renderer);
364 process->console = (struct console_input*)grab_object( parent->console );
365 process->console->num_proc++;
369 static struct console_input* console_input_get( obj_handle_t handle, unsigned access )
371 struct console_input* console = 0;
373 if (handle)
374 console = (struct console_input *)get_handle_obj( current->process, handle,
375 access, &console_input_ops );
376 else if (current->process->console)
378 assert( current->process->console->renderer );
379 console = (struct console_input *)grab_object( current->process->console );
382 if (!console && !get_error()) set_error(STATUS_INVALID_PARAMETER);
383 return console;
386 struct console_signal_info
388 struct console_input *console;
389 process_id_t group;
390 int signal;
393 static int propagate_console_signal_cb(struct process *process, void *user)
395 struct console_signal_info* csi = (struct console_signal_info*)user;
397 if (process->console == csi->console && process->running_threads &&
398 (!csi->group || process->group_id == csi->group))
400 /* find a suitable thread to signal */
401 struct thread *thread;
402 LIST_FOR_EACH_ENTRY( thread, &process->thread_list, struct thread, proc_entry )
404 if (send_thread_signal( thread, csi->signal )) break;
407 return FALSE;
410 static void propagate_console_signal( struct console_input *console,
411 int sig, process_id_t group_id )
413 struct console_signal_info csi;
415 if (!console)
417 set_error( STATUS_INVALID_PARAMETER );
418 return;
420 /* FIXME: should support the other events (like CTRL_BREAK) */
421 if (sig != CTRL_C_EVENT)
423 set_error( STATUS_NOT_IMPLEMENTED );
424 return;
426 csi.console = console;
427 csi.signal = SIGINT;
428 csi.group = group_id;
430 enum_processes(propagate_console_signal_cb, &csi);
433 static int get_console_mode( obj_handle_t handle )
435 struct object *obj;
436 int ret = 0;
438 if ((obj = get_handle_obj( current->process, handle, GENERIC_READ, NULL )))
440 if (obj->ops == &console_input_ops)
441 ret = ((struct console_input *)obj)->mode;
442 else if (obj->ops == &screen_buffer_ops)
443 ret = ((struct screen_buffer *)obj)->mode;
444 else
445 set_error( STATUS_OBJECT_TYPE_MISMATCH );
446 release_object( obj );
448 return ret;
451 /* changes the mode of either a console input or a screen buffer */
452 static int set_console_mode( obj_handle_t handle, int mode )
454 struct object *obj;
455 int ret = 0;
457 if (!(obj = get_handle_obj( current->process, handle, GENERIC_WRITE, NULL )))
458 return 0;
459 if (obj->ops == &console_input_ops)
461 /* FIXME: if we remove the edit mode bits, we need (???) to clean up the history */
462 ((struct console_input *)obj)->mode = mode;
463 ret = 1;
465 else if (obj->ops == &screen_buffer_ops)
467 ((struct screen_buffer *)obj)->mode = mode;
468 ret = 1;
470 else set_error( STATUS_OBJECT_TYPE_MISMATCH );
471 release_object( obj );
472 return ret;
475 /* add input events to a console input queue */
476 static int write_console_input( struct console_input* console, int count,
477 const INPUT_RECORD *records )
479 INPUT_RECORD *new_rec;
481 if (!count) return 0;
482 if (!(new_rec = realloc( console->records,
483 (console->recnum + count) * sizeof(INPUT_RECORD) )))
485 set_error( STATUS_NO_MEMORY );
486 release_object( console );
487 return -1;
489 console->records = new_rec;
490 memcpy( new_rec + console->recnum, records, count * sizeof(INPUT_RECORD) );
492 if (console->mode & ENABLE_PROCESSED_INPUT)
494 int i = 0;
495 while (i < count)
497 if (records[i].EventType == KEY_EVENT &&
498 records[i].Event.KeyEvent.uChar.UnicodeChar == 'C' - 64 &&
499 !(records[i].Event.KeyEvent.dwControlKeyState & ENHANCED_KEY))
501 if (i != count - 1)
502 memcpy( &console->records[console->recnum + i],
503 &console->records[console->recnum + i + 1],
504 (count - i - 1) * sizeof(INPUT_RECORD) );
505 count--;
506 if (records[i].Event.KeyEvent.bKeyDown)
508 /* send SIGINT to all processes attached to this console */
509 propagate_console_signal( console, CTRL_C_EVENT, 0 );
512 else i++;
515 if (!console->recnum && count) set_event( console->event );
516 console->recnum += count;
517 return count;
520 /* retrieve a pointer to the console input records */
521 static int read_console_input( obj_handle_t handle, int count, int flush )
523 struct console_input *console;
525 if (!(console = (struct console_input *)get_handle_obj( current->process, handle,
526 GENERIC_READ, &console_input_ops )))
527 return -1;
529 if (!count)
531 /* special case: do not retrieve anything, but return
532 * the total number of records available */
533 count = console->recnum;
535 else
537 if (count > console->recnum) count = console->recnum;
538 set_reply_data( console->records, count * sizeof(INPUT_RECORD) );
540 if (flush)
542 int i;
543 for (i = count; i < console->recnum; i++)
544 console->records[i-count] = console->records[i];
545 if ((console->recnum -= count) > 0)
547 INPUT_RECORD *new_rec = realloc( console->records,
548 console->recnum * sizeof(INPUT_RECORD) );
549 if (new_rec) console->records = new_rec;
551 else
553 free( console->records );
554 console->records = NULL;
555 reset_event( console->event );
558 release_object( console );
559 return count;
562 /* set misc console input information */
563 static int set_console_input_info( const struct set_console_input_info_request *req,
564 const WCHAR *title, size_t len )
566 struct console_input *console;
567 struct console_renderer_event evt;
569 if (!(console = console_input_get( req->handle, GENERIC_WRITE ))) goto error;
571 if (req->mask & SET_CONSOLE_INPUT_INFO_ACTIVE_SB)
573 struct screen_buffer *screen_buffer;
575 screen_buffer = (struct screen_buffer *)get_handle_obj( current->process, req->active_sb,
576 GENERIC_READ, &screen_buffer_ops );
577 if (!screen_buffer || screen_buffer->input != console)
579 set_error( STATUS_INVALID_PARAMETER );
580 if (screen_buffer) release_object( screen_buffer );
581 goto error;
584 if (screen_buffer != console->active)
586 if (console->active) release_object( console->active );
587 console->active = screen_buffer;
588 evt.event = CONSOLE_RENDERER_ACTIVE_SB_EVENT;
589 console_input_events_append( console->evt, &evt );
591 else
592 release_object( screen_buffer );
594 if (req->mask & SET_CONSOLE_INPUT_INFO_TITLE)
596 WCHAR *new_title = mem_alloc( len + sizeof(WCHAR) );
597 if (new_title)
599 memcpy( new_title, title, len );
600 new_title[len / sizeof(WCHAR)] = 0;
601 if (console->title) free( console->title );
602 console->title = new_title;
603 evt.event = CONSOLE_RENDERER_TITLE_EVENT;
604 console_input_events_append( console->evt, &evt );
607 if (req->mask & SET_CONSOLE_INPUT_INFO_HISTORY_MODE)
609 console->history_mode = req->history_mode;
611 if ((req->mask & SET_CONSOLE_INPUT_INFO_HISTORY_SIZE) &&
612 console->history_size != req->history_size)
614 WCHAR** mem = NULL;
615 int i;
616 int delta;
618 if (req->history_size)
620 mem = mem_alloc( req->history_size * sizeof(WCHAR*) );
621 if (!mem) goto error;
622 memset( mem, 0, req->history_size * sizeof(WCHAR*) );
625 delta = (console->history_index > req->history_size) ?
626 (console->history_index - req->history_size) : 0;
628 for (i = delta; i < console->history_index; i++)
630 mem[i - delta] = console->history[i];
631 console->history[i] = NULL;
633 console->history_index -= delta;
635 for (i = 0; i < console->history_size; i++)
636 if (console->history[i]) free( console->history[i] );
637 free( console->history );
638 console->history = mem;
639 console->history_size = req->history_size;
641 if (req->mask & SET_CONSOLE_INPUT_INFO_EDITION_MODE)
643 console->edition_mode = req->edition_mode;
645 release_object( console );
646 return 1;
647 error:
648 if (console) release_object( console );
649 return 0;
652 /* resize a screen buffer */
653 static int change_screen_buffer_size( struct screen_buffer *screen_buffer,
654 int new_width, int new_height )
656 int i, old_width, old_height, copy_width, copy_height;
657 char_info_t *new_data;
659 if (!(new_data = malloc( new_width * new_height * sizeof(*new_data) )))
661 set_error( STATUS_NO_MEMORY );
662 return 0;
664 old_width = screen_buffer->width;
665 old_height = screen_buffer->height;
666 copy_width = min( old_width, new_width );
667 copy_height = min( old_height, new_height );
669 /* copy all the rows */
670 for (i = 0; i < copy_height; i++)
672 memcpy( &new_data[i * new_width], &screen_buffer->data[i * old_width],
673 copy_width * sizeof(char_info_t) );
676 /* clear the end of each row */
677 if (new_width > old_width)
679 /* fill first row */
680 for (i = old_width; i < new_width; i++) new_data[i] = empty_char_info;
681 /* and blast it to the other rows */
682 for (i = 1; i < copy_height; i++)
683 memcpy( &new_data[i * new_width + old_width], &new_data[old_width],
684 (new_width - old_width) * sizeof(char_info_t) );
687 /* clear remaining rows */
688 if (new_height > old_height)
690 /* fill first row */
691 for (i = 0; i < new_width; i++) new_data[old_height * new_width + i] = empty_char_info;
692 /* and blast it to the other rows */
693 for (i = old_height+1; i < new_height; i++)
694 memcpy( &new_data[i * new_width], &new_data[old_height * new_width],
695 new_width * sizeof(char_info_t) );
697 free( screen_buffer->data );
698 screen_buffer->data = new_data;
699 screen_buffer->width = new_width;
700 screen_buffer->height = new_height;
701 return 1;
704 /* set misc screen buffer information */
705 static int set_console_output_info( struct screen_buffer *screen_buffer,
706 const struct set_console_output_info_request *req )
708 struct console_renderer_event evt;
710 if (req->mask & SET_CONSOLE_OUTPUT_INFO_CURSOR_GEOM)
712 if (req->cursor_size < 1 || req->cursor_size > 100)
714 set_error( STATUS_INVALID_PARAMETER );
715 return 0;
717 if (screen_buffer->cursor_size != req->cursor_size ||
718 screen_buffer->cursor_visible != req->cursor_visible)
720 screen_buffer->cursor_size = req->cursor_size;
721 screen_buffer->cursor_visible = req->cursor_visible;
722 evt.event = CONSOLE_RENDERER_CURSOR_GEOM_EVENT;
723 evt.u.cursor_geom.size = req->cursor_size;
724 evt.u.cursor_geom.visible = req->cursor_visible;
725 console_input_events_append( screen_buffer->input->evt, &evt );
728 if (req->mask & SET_CONSOLE_OUTPUT_INFO_CURSOR_POS)
730 if (req->cursor_x < 0 || req->cursor_x >= screen_buffer->width ||
731 req->cursor_y < 0 || req->cursor_y >= screen_buffer->height)
733 set_error( STATUS_INVALID_PARAMETER );
734 return 0;
736 if (screen_buffer->cursor_x != req->cursor_x || screen_buffer->cursor_y != req->cursor_y)
738 screen_buffer->cursor_x = req->cursor_x;
739 screen_buffer->cursor_y = req->cursor_y;
740 evt.event = CONSOLE_RENDERER_CURSOR_POS_EVENT;
741 evt.u.cursor_pos.x = req->cursor_x;
742 evt.u.cursor_pos.y = req->cursor_y;
743 console_input_events_append( screen_buffer->input->evt, &evt );
746 if (req->mask & SET_CONSOLE_OUTPUT_INFO_SIZE)
748 unsigned cc;
750 /* new screen-buffer cannot be smaller than actual window */
751 if (req->width < screen_buffer->win.right - screen_buffer->win.left + 1 ||
752 req->height < screen_buffer->win.bottom - screen_buffer->win.top + 1)
754 set_error( STATUS_INVALID_PARAMETER );
755 return 0;
757 /* FIXME: there are also some basic minimum and max size to deal with */
758 if (!change_screen_buffer_size( screen_buffer, req->width, req->height )) return 0;
760 evt.event = CONSOLE_RENDERER_SB_RESIZE_EVENT;
761 evt.u.resize.width = req->width;
762 evt.u.resize.height = req->height;
763 console_input_events_append( screen_buffer->input->evt, &evt );
765 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
766 evt.u.update.top = 0;
767 evt.u.update.bottom = screen_buffer->height - 1;
768 console_input_events_append( screen_buffer->input->evt, &evt );
770 /* scroll window to display sb */
771 if (screen_buffer->win.right >= req->width)
773 screen_buffer->win.right -= screen_buffer->win.left;
774 screen_buffer->win.left = 0;
776 if (screen_buffer->win.bottom >= req->height)
778 screen_buffer->win.bottom -= screen_buffer->win.top;
779 screen_buffer->win.top = 0;
781 /* reset cursor if needed (normally, if cursor was outside of new sb, the
782 * window has been shifted so that the new position of the cursor will be
783 * visible */
784 cc = 0;
785 if (screen_buffer->cursor_x >= req->width)
787 screen_buffer->cursor_x = req->width - 1;
788 cc++;
790 if (screen_buffer->cursor_y >= req->height)
792 screen_buffer->cursor_y = req->height - 1;
793 cc++;
795 if (cc)
797 evt.event = CONSOLE_RENDERER_CURSOR_POS_EVENT;
798 evt.u.cursor_pos.x = req->cursor_x;
799 evt.u.cursor_pos.y = req->cursor_y;
800 console_input_events_append( screen_buffer->input->evt, &evt );
803 if (screen_buffer == screen_buffer->input->active &&
804 screen_buffer->input->mode & ENABLE_WINDOW_INPUT)
806 INPUT_RECORD ir;
807 ir.EventType = WINDOW_BUFFER_SIZE_EVENT;
808 ir.Event.WindowBufferSizeEvent.dwSize.X = req->width;
809 ir.Event.WindowBufferSizeEvent.dwSize.Y = req->height;
810 write_console_input( screen_buffer->input, 1, &ir );
813 if (req->mask & SET_CONSOLE_OUTPUT_INFO_ATTR)
815 screen_buffer->attr = req->attr;
817 if (req->mask & SET_CONSOLE_OUTPUT_INFO_DISPLAY_WINDOW)
819 if (req->win_left < 0 || req->win_left > req->win_right ||
820 req->win_right >= screen_buffer->width ||
821 req->win_top < 0 || req->win_top > req->win_bottom ||
822 req->win_bottom >= screen_buffer->height)
824 set_error( STATUS_INVALID_PARAMETER );
825 return 0;
827 if (screen_buffer->win.left != req->win_left || screen_buffer->win.top != req->win_top ||
828 screen_buffer->win.right != req->win_right || screen_buffer->win.bottom != req->win_bottom)
830 screen_buffer->win.left = req->win_left;
831 screen_buffer->win.top = req->win_top;
832 screen_buffer->win.right = req->win_right;
833 screen_buffer->win.bottom = req->win_bottom;
834 evt.event = CONSOLE_RENDERER_DISPLAY_EVENT;
835 evt.u.display.left = req->win_left;
836 evt.u.display.top = req->win_top;
837 evt.u.display.width = req->win_right - req->win_left + 1;
838 evt.u.display.height = req->win_bottom - req->win_top + 1;
839 console_input_events_append( screen_buffer->input->evt, &evt );
842 if (req->mask & SET_CONSOLE_OUTPUT_INFO_MAX_SIZE)
844 /* can only be done by renderer */
845 if (current->process->console != screen_buffer->input)
847 set_error( STATUS_INVALID_PARAMETER );
848 return 0;
851 screen_buffer->max_width = req->max_width;
852 screen_buffer->max_height = req->max_height;
855 return 1;
858 /* appends a new line to history (history is a fixed size array) */
859 static void console_input_append_hist( struct console_input* console, const WCHAR* buf, size_t len )
861 WCHAR* ptr = mem_alloc( (len + 1) * sizeof(WCHAR) );
863 if (!ptr)
865 set_error( STATUS_NO_MEMORY );
866 return;
868 if (!console || !console->history_size)
870 set_error( STATUS_INVALID_PARAMETER ); /* FIXME */
871 return;
874 memcpy( ptr, buf, len * sizeof(WCHAR) );
875 ptr[len] = 0;
877 if (console->history_mode && console->history_index &&
878 strncmpW( console->history[console->history_index - 1], ptr, len * sizeof(WCHAR) ) == 0)
880 /* ok, mode ask us to not use twice the same string...
881 * so just free mem and returns
883 set_error( STATUS_ALIAS_EXISTS );
884 free(ptr);
885 return;
888 if (console->history_index < console->history_size)
890 console->history[console->history_index++] = ptr;
892 else
894 free( console->history[0]) ;
895 memmove( &console->history[0], &console->history[1],
896 (console->history_size - 1) * sizeof(WCHAR*) );
897 console->history[console->history_size - 1] = ptr;
901 /* returns a line from the cache */
902 static size_t console_input_get_hist( struct console_input *console, int index )
904 size_t ret = 0;
906 if (index >= console->history_index) set_error( STATUS_INVALID_PARAMETER );
907 else
909 ret = strlenW( console->history[index] ) * sizeof(WCHAR);
910 set_reply_data( console->history[index], min( ret, get_reply_max_size() ));
912 return ret;
915 /* dumb dump */
916 static void console_input_dump( struct object *obj, int verbose )
918 struct console_input *console = (struct console_input *)obj;
919 assert( obj->ops == &console_input_ops );
920 fprintf( stderr, "Console input active=%p evt=%p\n",
921 console->active, console->evt );
924 static void console_input_destroy( struct object *obj )
926 struct console_input* console_in = (struct console_input *)obj;
927 struct screen_buffer* curr;
928 int i;
930 assert( obj->ops == &console_input_ops );
931 if (console_in->title) free( console_in->title );
932 if (console_in->records) free( console_in->records );
934 if (console_in->active) release_object( console_in->active );
935 console_in->active = NULL;
937 LIST_FOR_EACH_ENTRY( curr, &screen_buffer_list, struct screen_buffer, entry )
939 if (curr->input == console_in) curr->input = NULL;
942 release_object( console_in->evt );
943 console_in->evt = NULL;
944 release_object( console_in->event );
946 for (i = 0; i < console_in->history_size; i++)
947 if (console_in->history[i]) free( console_in->history[i] );
948 if (console_in->history) free( console_in->history );
951 static void screen_buffer_dump( struct object *obj, int verbose )
953 struct screen_buffer *screen_buffer = (struct screen_buffer *)obj;
954 assert( obj->ops == &screen_buffer_ops );
956 fprintf(stderr, "Console screen buffer input=%p\n", screen_buffer->input );
959 static void screen_buffer_destroy( struct object *obj )
961 struct screen_buffer *screen_buffer = (struct screen_buffer *)obj;
963 assert( obj->ops == &screen_buffer_ops );
965 list_remove( &screen_buffer->entry );
967 if (screen_buffer->input && screen_buffer->input->active == screen_buffer)
969 struct screen_buffer *sb;
971 screen_buffer->input->active = NULL;
972 LIST_FOR_EACH_ENTRY( sb, &screen_buffer_list, struct screen_buffer, entry )
974 if (sb->input == screen_buffer->input)
976 sb->input->active = sb;
977 break;
981 if (screen_buffer->data) free( screen_buffer->data );
984 /* write data into a screen buffer */
985 static int write_console_output( struct screen_buffer *screen_buffer, size_t size,
986 const void* data, enum char_info_mode mode,
987 int x, int y, int wrap )
989 int i;
990 char_info_t *end, *dest = screen_buffer->data + y * screen_buffer->width + x;
992 if (y >= screen_buffer->height) return 0;
994 if (wrap)
995 end = screen_buffer->data + screen_buffer->height * screen_buffer->width;
996 else
997 end = screen_buffer->data + (y+1) * screen_buffer->width;
999 switch(mode)
1001 case CHAR_INFO_MODE_TEXT:
1003 const WCHAR *ptr = data;
1004 for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++) dest->ch = ptr[i];
1006 break;
1007 case CHAR_INFO_MODE_ATTR:
1009 const unsigned short *ptr = data;
1010 for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++) dest->attr = ptr[i];
1012 break;
1013 case CHAR_INFO_MODE_TEXTATTR:
1015 const char_info_t *ptr = data;
1016 for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++) *dest = ptr[i];
1018 break;
1019 case CHAR_INFO_MODE_TEXTSTDATTR:
1021 const WCHAR *ptr = data;
1022 for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++)
1024 dest->ch = ptr[i];
1025 dest->attr = screen_buffer->attr;
1028 break;
1029 default:
1030 set_error( STATUS_INVALID_PARAMETER );
1031 return 0;
1034 if (i && screen_buffer == screen_buffer->input->active)
1036 struct console_renderer_event evt;
1037 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
1038 evt.u.update.top = y + x / screen_buffer->width;
1039 evt.u.update.bottom = y + (x + i - 1) / screen_buffer->width;
1040 console_input_events_append( screen_buffer->input->evt, &evt );
1042 return i;
1045 /* fill a screen buffer with uniform data */
1046 static int fill_console_output( struct screen_buffer *screen_buffer, char_info_t data,
1047 enum char_info_mode mode, int x, int y, int count, int wrap )
1049 int i;
1050 char_info_t *end, *dest = screen_buffer->data + y * screen_buffer->width + x;
1052 if (y >= screen_buffer->height) return 0;
1054 if (wrap)
1055 end = screen_buffer->data + screen_buffer->height * screen_buffer->width;
1056 else
1057 end = screen_buffer->data + (y+1) * screen_buffer->width;
1059 if (count > end - dest) count = end - dest;
1061 switch(mode)
1063 case CHAR_INFO_MODE_TEXT:
1064 for (i = 0; i < count; i++) dest[i].ch = data.ch;
1065 break;
1066 case CHAR_INFO_MODE_ATTR:
1067 for (i = 0; i < count; i++) dest[i].attr = data.attr;
1068 break;
1069 case CHAR_INFO_MODE_TEXTATTR:
1070 for (i = 0; i < count; i++) dest[i] = data;
1071 break;
1072 case CHAR_INFO_MODE_TEXTSTDATTR:
1073 for (i = 0; i < count; i++)
1075 dest[i].ch = data.ch;
1076 dest[i].attr = screen_buffer->attr;
1078 break;
1079 default:
1080 set_error( STATUS_INVALID_PARAMETER );
1081 return 0;
1084 if (count && screen_buffer == screen_buffer->input->active)
1086 struct console_renderer_event evt;
1087 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
1088 evt.u.update.top = y;
1089 evt.u.update.bottom = (y * screen_buffer->width + x + count - 1) / screen_buffer->width;
1090 console_input_events_append( screen_buffer->input->evt, &evt );
1092 return i;
1095 /* read data from a screen buffer */
1096 static void read_console_output( struct screen_buffer *screen_buffer, int x, int y,
1097 enum char_info_mode mode, int wrap )
1099 int i;
1100 char_info_t *end, *src = screen_buffer->data + y * screen_buffer->width + x;
1102 if (y >= screen_buffer->height) return;
1104 if (wrap)
1105 end = screen_buffer->data + screen_buffer->height * screen_buffer->width;
1106 else
1107 end = screen_buffer->data + (y+1) * screen_buffer->width;
1109 switch(mode)
1111 case CHAR_INFO_MODE_TEXT:
1113 WCHAR *data;
1114 int count = min( end - src, get_reply_max_size() / sizeof(*data) );
1115 if ((data = set_reply_data_size( count * sizeof(*data) )))
1117 for (i = 0; i < count; i++) data[i] = src[i].ch;
1120 break;
1121 case CHAR_INFO_MODE_ATTR:
1123 unsigned short *data;
1124 int count = min( end - src, get_reply_max_size() / sizeof(*data) );
1125 if ((data = set_reply_data_size( count * sizeof(*data) )))
1127 for (i = 0; i < count; i++) data[i] = src[i].attr;
1130 break;
1131 case CHAR_INFO_MODE_TEXTATTR:
1133 char_info_t *data;
1134 int count = min( end - src, get_reply_max_size() / sizeof(*data) );
1135 if ((data = set_reply_data_size( count * sizeof(*data) )))
1137 for (i = 0; i < count; i++) data[i] = src[i];
1140 break;
1141 default:
1142 set_error( STATUS_INVALID_PARAMETER );
1143 break;
1147 /* scroll parts of a screen buffer */
1148 static void scroll_console_output( obj_handle_t handle, int xsrc, int ysrc, int xdst, int ydst,
1149 int w, int h )
1151 struct screen_buffer *screen_buffer;
1152 int j;
1153 char_info_t *psrc, *pdst;
1154 struct console_renderer_event evt;
1156 if (!(screen_buffer = (struct screen_buffer *)get_handle_obj( current->process, handle,
1157 GENERIC_READ, &screen_buffer_ops )))
1158 return;
1159 if (xsrc < 0 || ysrc < 0 || xdst < 0 || ydst < 0 ||
1160 xsrc + w > screen_buffer->width ||
1161 xdst + w > screen_buffer->width ||
1162 ysrc + h > screen_buffer->height ||
1163 ydst + h > screen_buffer->height ||
1164 w == 0 || h == 0)
1166 set_error( STATUS_INVALID_PARAMETER );
1167 release_object( screen_buffer );
1168 return;
1171 if (ysrc < ydst)
1173 psrc = &screen_buffer->data[(ysrc + h - 1) * screen_buffer->width + xsrc];
1174 pdst = &screen_buffer->data[(ydst + h - 1) * screen_buffer->width + xdst];
1176 for (j = h; j > 0; j--)
1178 memcpy(pdst, psrc, w * sizeof(*pdst) );
1179 pdst -= screen_buffer->width;
1180 psrc -= screen_buffer->width;
1183 else
1185 psrc = &screen_buffer->data[ysrc * screen_buffer->width + xsrc];
1186 pdst = &screen_buffer->data[ydst * screen_buffer->width + xdst];
1188 for (j = 0; j < h; j++)
1190 /* we use memmove here because when psrc and pdst are the same,
1191 * copies are done on the same row, so the dst and src blocks
1192 * can overlap */
1193 memmove( pdst, psrc, w * sizeof(*pdst) );
1194 pdst += screen_buffer->width;
1195 psrc += screen_buffer->width;
1199 /* FIXME: this could be enhanced, by signalling scroll */
1200 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
1201 evt.u.update.top = min(ysrc, ydst);
1202 evt.u.update.bottom = max(ysrc, ydst) + h - 1;
1203 console_input_events_append( screen_buffer->input->evt, &evt );
1205 release_object( screen_buffer );
1208 /* allocate a console for the renderer */
1209 DECL_HANDLER(alloc_console)
1211 obj_handle_t in = 0;
1212 obj_handle_t evt = 0;
1213 struct process *process;
1214 struct process *renderer = current->process;
1215 struct console_input *console;
1217 process = (req->pid) ? get_process_from_id( req->pid ) :
1218 (struct process *)grab_object( renderer->parent );
1220 reply->handle_in = 0;
1221 reply->event = 0;
1222 if (!process) return;
1223 if (process != renderer && process->console)
1225 set_error( STATUS_ACCESS_DENIED );
1226 goto the_end;
1228 if ((console = (struct console_input*)create_console_input( current )))
1230 if ((in = alloc_handle( renderer, console, req->access, req->inherit )))
1232 if ((evt = alloc_handle( renderer, console->evt,
1233 SYNCHRONIZE|GENERIC_READ|GENERIC_WRITE, FALSE )))
1235 if (process != renderer)
1237 process->console = (struct console_input*)grab_object( console );
1238 console->num_proc++;
1240 reply->handle_in = in;
1241 reply->event = evt;
1242 release_object( console );
1243 goto the_end;
1245 close_handle( renderer, in, NULL );
1247 free_console( process );
1249 the_end:
1250 release_object( process );
1253 /* free the console of the current process */
1254 DECL_HANDLER(free_console)
1256 free_console( current->process );
1259 /* let the renderer peek the events it's waiting on */
1260 DECL_HANDLER(get_console_renderer_events)
1262 struct console_input_events *evt;
1264 evt = (struct console_input_events *)get_handle_obj( current->process, req->handle,
1265 GENERIC_WRITE, &console_input_events_ops );
1266 if (!evt) return;
1267 console_input_events_get( evt );
1268 release_object( evt );
1271 /* open a handle to the process console */
1272 DECL_HANDLER(open_console)
1274 struct object *obj = NULL;
1276 reply->handle = 0;
1277 switch (req->from)
1279 case 0:
1280 if (current->process->console && current->process->console->renderer)
1281 obj = grab_object( (struct object*)current->process->console );
1282 break;
1283 case 1:
1284 if (current->process->console && current->process->console->renderer &&
1285 current->process->console->active)
1286 obj = grab_object( (struct object*)current->process->console->active );
1287 break;
1288 default:
1289 if ((obj = get_handle_obj( current->process, (obj_handle_t)req->from,
1290 GENERIC_READ|GENERIC_WRITE, &console_input_ops )))
1292 struct console_input* console = (struct console_input*)obj;
1293 obj = (console->active) ? grab_object( console->active ) : NULL;
1294 release_object( console );
1296 break;
1299 /* FIXME: req->share is not used (as in screen buffer creation) */
1300 if (obj)
1302 reply->handle = alloc_handle( current->process, obj, req->access, req->inherit );
1303 release_object( obj );
1305 else if (!get_error()) set_error( STATUS_ACCESS_DENIED );
1308 /* set info about a console input */
1309 DECL_HANDLER(set_console_input_info)
1311 set_console_input_info( req, get_req_data(), get_req_data_size() );
1314 /* get info about a console (output only) */
1315 DECL_HANDLER(get_console_input_info)
1317 struct console_input *console;
1319 if (!(console = console_input_get( req->handle, GENERIC_READ ))) return;
1320 if (console->title)
1322 size_t len = strlenW( console->title ) * sizeof(WCHAR);
1323 if (len > get_reply_max_size()) len = get_reply_max_size();
1324 set_reply_data( console->title, len );
1326 reply->history_mode = console->history_mode;
1327 reply->history_size = console->history_size;
1328 reply->history_index = console->history_index;
1329 reply->edition_mode = console->edition_mode;
1331 release_object( console );
1334 /* get a console mode (input or output) */
1335 DECL_HANDLER(get_console_mode)
1337 reply->mode = get_console_mode( req->handle );
1340 /* set a console mode (input or output) */
1341 DECL_HANDLER(set_console_mode)
1343 set_console_mode( req->handle, req->mode );
1346 /* add input records to a console input queue */
1347 DECL_HANDLER(write_console_input)
1349 struct console_input *console;
1351 reply->written = 0;
1352 if (!(console = (struct console_input *)get_handle_obj( current->process, req->handle,
1353 GENERIC_WRITE, &console_input_ops )))
1354 return;
1355 reply->written = write_console_input( console, get_req_data_size() / sizeof(INPUT_RECORD),
1356 get_req_data() );
1357 release_object( console );
1360 /* fetch input records from a console input queue */
1361 DECL_HANDLER(read_console_input)
1363 int count = get_reply_max_size() / sizeof(INPUT_RECORD);
1364 reply->read = read_console_input( req->handle, count, req->flush );
1367 /* appends a string to console's history */
1368 DECL_HANDLER(append_console_input_history)
1370 struct console_input *console;
1372 if (!(console = console_input_get( req->handle, GENERIC_WRITE ))) return;
1373 console_input_append_hist( console, get_req_data(), get_req_data_size() / sizeof(WCHAR) );
1374 release_object( console );
1377 /* appends a string to console's history */
1378 DECL_HANDLER(get_console_input_history)
1380 struct console_input *console;
1382 if (!(console = console_input_get( req->handle, GENERIC_WRITE ))) return;
1383 reply->total = console_input_get_hist( console, req->index );
1384 release_object( console );
1387 /* creates a screen buffer */
1388 DECL_HANDLER(create_console_output)
1390 struct console_input* console;
1391 struct screen_buffer* screen_buffer;
1393 if (!(console = console_input_get( req->handle_in, GENERIC_WRITE))) return;
1395 screen_buffer = create_console_output( console );
1396 if (screen_buffer)
1398 /* FIXME: should store sharing and test it when opening the CONOUT$ device
1399 * see file.c on how this could be done */
1400 reply->handle_out = alloc_handle( current->process, screen_buffer,
1401 req->access, req->inherit );
1402 release_object( screen_buffer );
1404 release_object( console );
1407 /* set info about a console screen buffer */
1408 DECL_HANDLER(set_console_output_info)
1410 struct screen_buffer *screen_buffer;
1412 if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle,
1413 GENERIC_WRITE, &screen_buffer_ops)))
1415 set_console_output_info( screen_buffer, req );
1416 release_object( screen_buffer );
1420 /* get info about a console screen buffer */
1421 DECL_HANDLER(get_console_output_info)
1423 struct screen_buffer *screen_buffer;
1425 if ((screen_buffer = (struct screen_buffer *)get_handle_obj( current->process, req->handle,
1426 GENERIC_READ, &screen_buffer_ops)))
1428 reply->cursor_size = screen_buffer->cursor_size;
1429 reply->cursor_visible = screen_buffer->cursor_visible;
1430 reply->cursor_x = screen_buffer->cursor_x;
1431 reply->cursor_y = screen_buffer->cursor_y;
1432 reply->width = screen_buffer->width;
1433 reply->height = screen_buffer->height;
1434 reply->attr = screen_buffer->attr;
1435 reply->win_left = screen_buffer->win.left;
1436 reply->win_top = screen_buffer->win.top;
1437 reply->win_right = screen_buffer->win.right;
1438 reply->win_bottom = screen_buffer->win.bottom;
1439 reply->max_width = screen_buffer->max_width;
1440 reply->max_height = screen_buffer->max_height;
1441 release_object( screen_buffer );
1445 /* read data (chars & attrs) from a screen buffer */
1446 DECL_HANDLER(read_console_output)
1448 struct screen_buffer *screen_buffer;
1450 if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle,
1451 GENERIC_READ, &screen_buffer_ops )))
1453 read_console_output( screen_buffer, req->x, req->y, req->mode, req->wrap );
1454 reply->width = screen_buffer->width;
1455 reply->height = screen_buffer->height;
1456 release_object( screen_buffer );
1460 /* write data (char and/or attrs) to a screen buffer */
1461 DECL_HANDLER(write_console_output)
1463 struct screen_buffer *screen_buffer;
1465 if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle,
1466 GENERIC_WRITE, &screen_buffer_ops)))
1468 reply->written = write_console_output( screen_buffer, get_req_data_size(), get_req_data(),
1469 req->mode, req->x, req->y, req->wrap );
1470 reply->width = screen_buffer->width;
1471 reply->height = screen_buffer->height;
1472 release_object( screen_buffer );
1476 /* fill a screen buffer with constant data (chars and/or attributes) */
1477 DECL_HANDLER(fill_console_output)
1479 struct screen_buffer *screen_buffer;
1481 if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle,
1482 GENERIC_WRITE, &screen_buffer_ops)))
1484 reply->written = fill_console_output( screen_buffer, req->data, req->mode,
1485 req->x, req->y, req->count, req->wrap );
1486 release_object( screen_buffer );
1490 /* move a rect of data in a screen buffer */
1491 DECL_HANDLER(move_console_output)
1493 scroll_console_output( req->handle, req->x_src, req->y_src, req->x_dst, req->y_dst,
1494 req->w, req->h );
1497 /* sends a signal to a console (process, group...) */
1498 DECL_HANDLER(send_console_signal)
1500 process_id_t group;
1502 group = req->group_id ? req->group_id : current->process->group_id;
1504 if (!group)
1505 set_error( STATUS_INVALID_PARAMETER );
1506 else
1507 propagate_console_signal( current->process->console, req->signal, group );
1510 /* get console which renderer is 'current' */
1511 static int cgwe_enum( struct process* process, void* user)
1513 if (process->console && process->console->renderer == current)
1515 *(struct console_input**)user = process->console;
1516 return 1;
1518 return 0;
1521 DECL_HANDLER(get_console_wait_event)
1523 struct console_input* console = NULL;
1525 if (current->process->console && current->process->console->renderer)
1526 console = (struct console_input*)grab_object( (struct object*)current->process->console );
1527 else enum_processes(cgwe_enum, &console);
1529 if (console)
1531 reply->handle = alloc_handle( current->process, console->event,
1532 EVENT_ALL_ACCESS, FALSE);
1533 release_object( console );
1535 else set_error( STATUS_INVALID_PARAMETER );