- add vertex Declaration support (using wined3d)
[wine.git] / server / console.c
blob9312f4242df485f19b641d96d6d179c8455824ea
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 screen_buffer *next; /* linked list of all screen buffers */
81 struct screen_buffer *prev;
82 struct console_input *input; /* associated console input */
83 int mode; /* output mode */
84 int cursor_size; /* size of cursor (percentage filled) */
85 int cursor_visible;/* cursor visibility flag */
86 int cursor_x; /* position of cursor */
87 int cursor_y; /* position of cursor */
88 int width; /* size (w-h) of the screen buffer */
89 int height;
90 int max_width; /* size (w-h) of the window given font size */
91 int max_height;
92 char_info_t *data; /* the data for each cell - a width x height matrix */
93 unsigned short attr; /* default attribute for screen buffer */
94 rectangle_t win; /* current visible window on the screen buffer *
95 * as seen in wineconsole */
98 static void screen_buffer_dump( struct object *obj, int verbose );
99 static void screen_buffer_destroy( struct object *obj );
101 static const struct object_ops screen_buffer_ops =
103 sizeof(struct screen_buffer), /* size */
104 screen_buffer_dump, /* dump */
105 no_add_queue, /* add_queue */
106 NULL, /* remove_queue */
107 NULL, /* signaled */
108 NULL, /* satisfied */
109 no_get_fd, /* get_fd */
110 screen_buffer_destroy /* destroy */
113 static struct screen_buffer *screen_buffer_list;
115 static const char_info_t empty_char_info = { ' ', 0x000f }; /* white on black space */
117 /* dumps the renderer events of a console */
118 static void console_input_events_dump( struct object *obj, int verbose )
120 struct console_input_events *evts = (struct console_input_events *)obj;
121 assert( obj->ops == &console_input_events_ops );
122 fprintf( stderr, "Console input events: %d/%d events\n",
123 evts->num_used, evts->num_alloc );
126 /* destroys the renderer events of a console */
127 static void console_input_events_destroy( struct object *obj )
129 struct console_input_events *evts = (struct console_input_events *)obj;
130 assert( obj->ops == &console_input_events_ops );
131 free( evts->events );
134 /* the renderer events list is signaled when it's not empty */
135 static int console_input_events_signaled( struct object *obj, struct thread *thread )
137 struct console_input_events *evts = (struct console_input_events *)obj;
138 assert( obj->ops == &console_input_events_ops );
139 return (evts->num_used != 0);
142 /* add an event to the console's renderer events list */
143 static void console_input_events_append( struct console_input_events* evts,
144 struct console_renderer_event* evt)
146 int collapsed = FALSE;
148 /* to be done even when evt has been generated by the rendere ? */
150 /* try to collapse evt into current queue's events */
151 if (evts->num_used)
153 struct console_renderer_event* last = &evts->events[evts->num_used - 1];
155 if (last->event == CONSOLE_RENDERER_UPDATE_EVENT &&
156 evt->event == CONSOLE_RENDERER_UPDATE_EVENT)
158 /* if two update events overlap, collapse them into a single one */
159 if (last->u.update.bottom + 1 >= evt->u.update.top &&
160 evt->u.update.bottom + 1 >= last->u.update.top)
162 last->u.update.top = min(last->u.update.top, evt->u.update.top);
163 last->u.update.bottom = max(last->u.update.bottom, evt->u.update.bottom);
164 collapsed = TRUE;
168 if (!collapsed)
170 if (evts->num_used == evts->num_alloc)
172 evts->num_alloc += 16;
173 evts->events = realloc( evts->events, evts->num_alloc * sizeof(*evt) );
174 assert(evts->events);
176 evts->events[evts->num_used++] = *evt;
178 wake_up( &evts->obj, 0 );
181 /* retrieves events from the console's renderer events list */
182 static void console_input_events_get( struct console_input_events* evts )
184 size_t num = get_reply_max_size() / sizeof(evts->events[0]);
186 if (num > evts->num_used) num = evts->num_used;
187 set_reply_data( evts->events, num * sizeof(evts->events[0]) );
188 if (num < evts->num_used)
190 memmove( &evts->events[0], &evts->events[num],
191 (evts->num_used - num) * sizeof(evts->events[0]) );
193 evts->num_used -= num;
196 static struct console_input_events *create_console_input_events(void)
198 struct console_input_events* evt;
200 if (!(evt = alloc_object( &console_input_events_ops ))) return NULL;
201 evt->num_alloc = evt->num_used = 0;
202 evt->events = NULL;
203 return evt;
206 static struct object *create_console_input( struct thread* renderer )
208 struct console_input *console_input;
210 if (!(console_input = alloc_object( &console_input_ops ))) return NULL;
211 console_input->renderer = renderer;
212 console_input->mode = ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT |
213 ENABLE_ECHO_INPUT | ENABLE_MOUSE_INPUT;
214 console_input->num_proc = 0;
215 console_input->active = NULL;
216 console_input->recnum = 0;
217 console_input->records = NULL;
218 console_input->evt = create_console_input_events();
219 console_input->title = NULL;
220 console_input->history_size = 50;
221 console_input->history = calloc( console_input->history_size, sizeof(WCHAR*) );
222 console_input->history_index = 0;
223 console_input->history_mode = 0;
224 console_input->edition_mode = 0;
225 console_input->event = create_event( NULL, 0, 1, 0 );
227 if (!console_input->history || !console_input->evt)
229 release_object( console_input );
230 return NULL;
232 return &console_input->obj;
235 static struct screen_buffer *create_console_output( struct console_input *console_input )
237 struct screen_buffer *screen_buffer;
238 struct console_renderer_event evt;
239 int i;
241 if (!(screen_buffer = alloc_object( &screen_buffer_ops ))) return NULL;
242 screen_buffer->mode = ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT;
243 screen_buffer->input = console_input;
244 screen_buffer->cursor_size = 100;
245 screen_buffer->cursor_visible = 1;
246 screen_buffer->width = 80;
247 screen_buffer->height = 150;
248 screen_buffer->max_width = 80;
249 screen_buffer->max_height = 25;
250 screen_buffer->cursor_x = 0;
251 screen_buffer->cursor_y = 0;
252 screen_buffer->attr = 0x0F;
253 screen_buffer->win.left = 0;
254 screen_buffer->win.right = screen_buffer->max_width - 1;
255 screen_buffer->win.top = 0;
256 screen_buffer->win.bottom = screen_buffer->max_height - 1;
258 if ((screen_buffer->next = screen_buffer_list)) screen_buffer->next->prev = screen_buffer;
259 screen_buffer->prev = NULL;
260 screen_buffer_list = screen_buffer;
262 if (!(screen_buffer->data = malloc( screen_buffer->width * screen_buffer->height *
263 sizeof(*screen_buffer->data) )))
265 release_object( screen_buffer );
266 return NULL;
268 /* clear the first row */
269 for (i = 0; i < screen_buffer->width; i++) screen_buffer->data[i] = empty_char_info;
270 /* and copy it to all other rows */
271 for (i = 1; i < screen_buffer->height; i++)
272 memcpy( &screen_buffer->data[i * screen_buffer->width], screen_buffer->data,
273 screen_buffer->width * sizeof(char_info_t) );
275 if (!console_input->active)
277 console_input->active = (struct screen_buffer*)grab_object( screen_buffer );
279 /* generate the initial events */
280 evt.event = CONSOLE_RENDERER_ACTIVE_SB_EVENT;
281 console_input_events_append( console_input->evt, &evt );
283 evt.event = CONSOLE_RENDERER_SB_RESIZE_EVENT;
284 evt.u.resize.width = screen_buffer->width;
285 evt.u.resize.height = screen_buffer->height;
286 console_input_events_append( console_input->evt, &evt );
288 evt.event = CONSOLE_RENDERER_DISPLAY_EVENT;
289 evt.u.display.left = screen_buffer->win.left;
290 evt.u.display.top = screen_buffer->win.top;
291 evt.u.display.width = screen_buffer->win.right - screen_buffer->win.left + 1;
292 evt.u.display.height = screen_buffer->win.bottom - screen_buffer->win.top + 1;
293 console_input_events_append( console_input->evt, &evt );
295 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
296 evt.u.update.top = 0;
297 evt.u.update.bottom = screen_buffer->height - 1;
298 console_input_events_append( console_input->evt, &evt );
300 evt.event = CONSOLE_RENDERER_CURSOR_GEOM_EVENT;
301 evt.u.cursor_geom.size = screen_buffer->cursor_size;
302 evt.u.cursor_geom.visible = screen_buffer->cursor_visible;
303 console_input_events_append( console_input->evt, &evt );
305 evt.event = CONSOLE_RENDERER_CURSOR_POS_EVENT;
306 evt.u.cursor_pos.x = screen_buffer->cursor_x;
307 evt.u.cursor_pos.y = screen_buffer->cursor_y;
308 console_input_events_append( console_input->evt, &evt );
310 return screen_buffer;
313 /* free the console for this process */
314 int free_console( struct process *process )
316 struct console_input* console = process->console;
318 if (!console || !console->renderer) return 0;
320 process->console = NULL;
321 if (--console->num_proc == 0)
323 /* all processes have terminated... tell the renderer to terminate too */
324 struct console_renderer_event evt;
325 evt.event = CONSOLE_RENDERER_EXIT_EVENT;
326 console_input_events_append( console->evt, &evt );
328 release_object( console );
330 return 1;
333 /* let process inherit the console from parent... this handle two cases :
334 * 1/ generic console inheritance
335 * 2/ parent is a renderer which launches process, and process should attach to the console
336 * renderered by parent
338 void inherit_console(struct thread *parent_thread, struct process *process, obj_handle_t hconin)
340 int done = 0;
341 struct process* parent = parent_thread->process;
343 /* if parent is a renderer, then attach current process to its console
344 * a bit hacky....
346 if (hconin)
348 struct console_input* console;
350 /* FIXME: should we check some access rights ? */
351 if ((console = (struct console_input*)get_handle_obj( parent, hconin,
352 0, &console_input_ops )))
354 if (console->renderer == parent_thread)
356 process->console = (struct console_input*)grab_object( console );
357 process->console->num_proc++;
358 done = 1;
360 release_object( console );
363 /* otherwise, if parent has a console, attach child to this console */
364 if (!done && parent->console)
366 assert(parent->console->renderer);
367 process->console = (struct console_input*)grab_object( parent->console );
368 process->console->num_proc++;
372 static struct console_input* console_input_get( obj_handle_t handle, unsigned access )
374 struct console_input* console = 0;
376 if (handle)
377 console = (struct console_input *)get_handle_obj( current->process, handle,
378 access, &console_input_ops );
379 else if (current->process->console)
381 assert( current->process->console->renderer );
382 console = (struct console_input *)grab_object( current->process->console );
385 if (!console && !get_error()) set_error(STATUS_INVALID_PARAMETER);
386 return console;
389 struct console_signal_info
391 struct console_input *console;
392 process_id_t group;
393 int signal;
396 static int propagate_console_signal_cb(struct process *process, void *user)
398 struct console_signal_info* csi = (struct console_signal_info*)user;
400 if (process->console == csi->console && process->running_threads &&
401 (!csi->group || process->group_id == csi->group))
403 /* find a suitable thread to signal */
404 struct thread *thread;
405 for (thread = process->thread_list; thread; thread = thread->proc_next)
407 if (send_thread_signal( thread, csi->signal )) break;
410 return FALSE;
413 static void propagate_console_signal( struct console_input *console,
414 int sig, process_id_t group_id )
416 struct console_signal_info csi;
418 if (!console)
420 set_error( STATUS_INVALID_PARAMETER );
421 return;
423 /* FIXME: should support the other events (like CTRL_BREAK) */
424 if (sig != CTRL_C_EVENT)
426 set_error( STATUS_NOT_IMPLEMENTED );
427 return;
429 csi.console = console;
430 csi.signal = SIGINT;
431 csi.group = group_id;
433 enum_processes(propagate_console_signal_cb, &csi);
436 static int get_console_mode( obj_handle_t handle )
438 struct object *obj;
439 int ret = 0;
441 if ((obj = get_handle_obj( current->process, handle, GENERIC_READ, NULL )))
443 if (obj->ops == &console_input_ops)
444 ret = ((struct console_input *)obj)->mode;
445 else if (obj->ops == &screen_buffer_ops)
446 ret = ((struct screen_buffer *)obj)->mode;
447 else
448 set_error( STATUS_OBJECT_TYPE_MISMATCH );
449 release_object( obj );
451 return ret;
454 /* changes the mode of either a console input or a screen buffer */
455 static int set_console_mode( obj_handle_t handle, int mode )
457 struct object *obj;
458 int ret = 0;
460 if (!(obj = get_handle_obj( current->process, handle, GENERIC_WRITE, NULL )))
461 return 0;
462 if (obj->ops == &console_input_ops)
464 /* FIXME: if we remove the edit mode bits, we need (???) to clean up the history */
465 ((struct console_input *)obj)->mode = mode;
466 ret = 1;
468 else if (obj->ops == &screen_buffer_ops)
470 ((struct screen_buffer *)obj)->mode = mode;
471 ret = 1;
473 else set_error( STATUS_OBJECT_TYPE_MISMATCH );
474 release_object( obj );
475 return ret;
478 /* add input events to a console input queue */
479 static int write_console_input( struct console_input* console, int count,
480 const INPUT_RECORD *records )
482 INPUT_RECORD *new_rec;
484 if (!count) return 0;
485 if (!(new_rec = realloc( console->records,
486 (console->recnum + count) * sizeof(INPUT_RECORD) )))
488 set_error( STATUS_NO_MEMORY );
489 release_object( console );
490 return -1;
492 console->records = new_rec;
493 memcpy( new_rec + console->recnum, records, count * sizeof(INPUT_RECORD) );
495 if (console->mode & ENABLE_PROCESSED_INPUT)
497 int i = 0;
498 while (i < count)
500 if (records[i].EventType == KEY_EVENT &&
501 records[i].Event.KeyEvent.uChar.UnicodeChar == 'C' - 64 &&
502 !(records[i].Event.KeyEvent.dwControlKeyState & ENHANCED_KEY))
504 if (i != count - 1)
505 memcpy( &console->records[console->recnum + i],
506 &console->records[console->recnum + i + 1],
507 (count - i - 1) * sizeof(INPUT_RECORD) );
508 count--;
509 if (records[i].Event.KeyEvent.bKeyDown)
511 /* send SIGINT to all processes attached to this console */
512 propagate_console_signal( console, CTRL_C_EVENT, 0 );
515 else i++;
518 if (!console->recnum && count) set_event( console->event );
519 console->recnum += count;
520 return count;
523 /* retrieve a pointer to the console input records */
524 static int read_console_input( obj_handle_t handle, int count, int flush )
526 struct console_input *console;
528 if (!(console = (struct console_input *)get_handle_obj( current->process, handle,
529 GENERIC_READ, &console_input_ops )))
530 return -1;
532 if (!count)
534 /* special case: do not retrieve anything, but return
535 * the total number of records available */
536 count = console->recnum;
538 else
540 if (count > console->recnum) count = console->recnum;
541 set_reply_data( console->records, count * sizeof(INPUT_RECORD) );
543 if (flush)
545 int i;
546 for (i = count; i < console->recnum; i++)
547 console->records[i-count] = console->records[i];
548 if ((console->recnum -= count) > 0)
550 INPUT_RECORD *new_rec = realloc( console->records,
551 console->recnum * sizeof(INPUT_RECORD) );
552 if (new_rec) console->records = new_rec;
554 else
556 free( console->records );
557 console->records = NULL;
558 reset_event( console->event );
561 release_object( console );
562 return count;
565 /* set misc console input information */
566 static int set_console_input_info( const struct set_console_input_info_request *req,
567 const WCHAR *title, size_t len )
569 struct console_input *console;
570 struct console_renderer_event evt;
572 if (!(console = console_input_get( req->handle, GENERIC_WRITE ))) goto error;
574 if (req->mask & SET_CONSOLE_INPUT_INFO_ACTIVE_SB)
576 struct screen_buffer *screen_buffer;
578 screen_buffer = (struct screen_buffer *)get_handle_obj( current->process, req->active_sb,
579 GENERIC_READ, &screen_buffer_ops );
580 if (!screen_buffer || screen_buffer->input != console)
582 set_error( STATUS_INVALID_PARAMETER );
583 if (screen_buffer) release_object( screen_buffer );
584 goto error;
587 if (screen_buffer != console->active)
589 if (console->active) release_object( console->active );
590 console->active = screen_buffer;
591 evt.event = CONSOLE_RENDERER_ACTIVE_SB_EVENT;
592 console_input_events_append( console->evt, &evt );
594 else
595 release_object( screen_buffer );
597 if (req->mask & SET_CONSOLE_INPUT_INFO_TITLE)
599 WCHAR *new_title = mem_alloc( len + sizeof(WCHAR) );
600 if (new_title)
602 memcpy( new_title, title, len );
603 new_title[len / sizeof(WCHAR)] = 0;
604 if (console->title) free( console->title );
605 console->title = new_title;
606 evt.event = CONSOLE_RENDERER_TITLE_EVENT;
607 console_input_events_append( console->evt, &evt );
610 if (req->mask & SET_CONSOLE_INPUT_INFO_HISTORY_MODE)
612 console->history_mode = req->history_mode;
614 if ((req->mask & SET_CONSOLE_INPUT_INFO_HISTORY_SIZE) &&
615 console->history_size != req->history_size)
617 WCHAR** mem = NULL;
618 int i;
619 int delta;
621 if (req->history_size)
623 mem = mem_alloc( req->history_size * sizeof(WCHAR*) );
624 if (!mem) goto error;
625 memset( mem, 0, req->history_size * sizeof(WCHAR*) );
628 delta = (console->history_index > req->history_size) ?
629 (console->history_index - req->history_size) : 0;
631 for (i = delta; i < console->history_index; i++)
633 mem[i - delta] = console->history[i];
634 console->history[i] = NULL;
636 console->history_index -= delta;
638 for (i = 0; i < console->history_size; i++)
639 if (console->history[i]) free( console->history[i] );
640 free( console->history );
641 console->history = mem;
642 console->history_size = req->history_size;
644 if (req->mask & SET_CONSOLE_INPUT_INFO_EDITION_MODE)
646 console->edition_mode = req->edition_mode;
648 release_object( console );
649 return 1;
650 error:
651 if (console) release_object( console );
652 return 0;
655 /* resize a screen buffer */
656 static int change_screen_buffer_size( struct screen_buffer *screen_buffer,
657 int new_width, int new_height )
659 int i, old_width, old_height, copy_width, copy_height;
660 char_info_t *new_data;
662 if (!(new_data = malloc( new_width * new_height * sizeof(*new_data) )))
664 set_error( STATUS_NO_MEMORY );
665 return 0;
667 old_width = screen_buffer->width;
668 old_height = screen_buffer->height;
669 copy_width = min( old_width, new_width );
670 copy_height = min( old_height, new_height );
672 /* copy all the rows */
673 for (i = 0; i < copy_height; i++)
675 memcpy( &new_data[i * new_width], &screen_buffer->data[i * old_width],
676 copy_width * sizeof(char_info_t) );
679 /* clear the end of each row */
680 if (new_width > old_width)
682 /* fill first row */
683 for (i = old_width; i < new_width; i++) new_data[i] = empty_char_info;
684 /* and blast it to the other rows */
685 for (i = 1; i < copy_height; i++)
686 memcpy( &new_data[i * new_width + old_width], &new_data[old_width],
687 (new_width - old_width) * sizeof(char_info_t) );
690 /* clear remaining rows */
691 if (new_height > old_height)
693 /* fill first row */
694 for (i = 0; i < new_width; i++) new_data[old_height * new_width + i] = empty_char_info;
695 /* and blast it to the other rows */
696 for (i = old_height+1; i < new_height; i++)
697 memcpy( &new_data[i * new_width], &new_data[old_height * new_width],
698 new_width * sizeof(char_info_t) );
700 free( screen_buffer->data );
701 screen_buffer->data = new_data;
702 screen_buffer->width = new_width;
703 screen_buffer->height = new_height;
704 return 1;
707 /* set misc screen buffer information */
708 static int set_console_output_info( struct screen_buffer *screen_buffer,
709 const struct set_console_output_info_request *req )
711 struct console_renderer_event evt;
713 if (req->mask & SET_CONSOLE_OUTPUT_INFO_CURSOR_GEOM)
715 if (req->cursor_size < 1 || req->cursor_size > 100)
717 set_error( STATUS_INVALID_PARAMETER );
718 return 0;
720 if (screen_buffer->cursor_size != req->cursor_size ||
721 screen_buffer->cursor_visible != req->cursor_visible)
723 screen_buffer->cursor_size = req->cursor_size;
724 screen_buffer->cursor_visible = req->cursor_visible;
725 evt.event = CONSOLE_RENDERER_CURSOR_GEOM_EVENT;
726 evt.u.cursor_geom.size = req->cursor_size;
727 evt.u.cursor_geom.visible = req->cursor_visible;
728 console_input_events_append( screen_buffer->input->evt, &evt );
731 if (req->mask & SET_CONSOLE_OUTPUT_INFO_CURSOR_POS)
733 if (req->cursor_x < 0 || req->cursor_x >= screen_buffer->width ||
734 req->cursor_y < 0 || req->cursor_y >= screen_buffer->height)
736 set_error( STATUS_INVALID_PARAMETER );
737 return 0;
739 if (screen_buffer->cursor_x != req->cursor_x || screen_buffer->cursor_y != req->cursor_y)
741 screen_buffer->cursor_x = req->cursor_x;
742 screen_buffer->cursor_y = req->cursor_y;
743 evt.event = CONSOLE_RENDERER_CURSOR_POS_EVENT;
744 evt.u.cursor_pos.x = req->cursor_x;
745 evt.u.cursor_pos.y = req->cursor_y;
746 console_input_events_append( screen_buffer->input->evt, &evt );
749 if (req->mask & SET_CONSOLE_OUTPUT_INFO_SIZE)
751 unsigned cc;
753 /* new screen-buffer cannot be smaller than actual window */
754 if (req->width < screen_buffer->win.right - screen_buffer->win.left + 1 ||
755 req->height < screen_buffer->win.bottom - screen_buffer->win.top + 1)
757 set_error( STATUS_INVALID_PARAMETER );
758 return 0;
760 /* FIXME: there are also some basic minimum and max size to deal with */
761 if (!change_screen_buffer_size( screen_buffer, req->width, req->height )) return 0;
763 evt.event = CONSOLE_RENDERER_SB_RESIZE_EVENT;
764 evt.u.resize.width = req->width;
765 evt.u.resize.height = req->height;
766 console_input_events_append( screen_buffer->input->evt, &evt );
768 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
769 evt.u.update.top = 0;
770 evt.u.update.bottom = screen_buffer->height - 1;
771 console_input_events_append( screen_buffer->input->evt, &evt );
773 /* scroll window to display sb */
774 if (screen_buffer->win.right >= req->width)
776 screen_buffer->win.right -= screen_buffer->win.left;
777 screen_buffer->win.left = 0;
779 if (screen_buffer->win.bottom >= req->height)
781 screen_buffer->win.bottom -= screen_buffer->win.top;
782 screen_buffer->win.top = 0;
784 /* reset cursor if needed (normally, if cursor was outside of new sb, the
785 * window has been shifted so that the new position of the cursor will be
786 * visible */
787 cc = 0;
788 if (screen_buffer->cursor_x >= req->width)
790 screen_buffer->cursor_x = req->width - 1;
791 cc++;
793 if (screen_buffer->cursor_y >= req->height)
795 screen_buffer->cursor_y = req->height - 1;
796 cc++;
798 if (cc)
800 evt.event = CONSOLE_RENDERER_CURSOR_POS_EVENT;
801 evt.u.cursor_pos.x = req->cursor_x;
802 evt.u.cursor_pos.y = req->cursor_y;
803 console_input_events_append( screen_buffer->input->evt, &evt );
806 if (screen_buffer == screen_buffer->input->active &&
807 screen_buffer->input->mode & ENABLE_WINDOW_INPUT)
809 INPUT_RECORD ir;
810 ir.EventType = WINDOW_BUFFER_SIZE_EVENT;
811 ir.Event.WindowBufferSizeEvent.dwSize.X = req->width;
812 ir.Event.WindowBufferSizeEvent.dwSize.Y = req->height;
813 write_console_input( screen_buffer->input, 1, &ir );
816 if (req->mask & SET_CONSOLE_OUTPUT_INFO_ATTR)
818 screen_buffer->attr = req->attr;
820 if (req->mask & SET_CONSOLE_OUTPUT_INFO_DISPLAY_WINDOW)
822 if (req->win_left < 0 || req->win_left > req->win_right ||
823 req->win_right >= screen_buffer->width ||
824 req->win_top < 0 || req->win_top > req->win_bottom ||
825 req->win_bottom >= screen_buffer->height)
827 set_error( STATUS_INVALID_PARAMETER );
828 return 0;
830 if (screen_buffer->win.left != req->win_left || screen_buffer->win.top != req->win_top ||
831 screen_buffer->win.right != req->win_right || screen_buffer->win.bottom != req->win_bottom)
833 screen_buffer->win.left = req->win_left;
834 screen_buffer->win.top = req->win_top;
835 screen_buffer->win.right = req->win_right;
836 screen_buffer->win.bottom = req->win_bottom;
837 evt.event = CONSOLE_RENDERER_DISPLAY_EVENT;
838 evt.u.display.left = req->win_left;
839 evt.u.display.top = req->win_top;
840 evt.u.display.width = req->win_right - req->win_left + 1;
841 evt.u.display.height = req->win_bottom - req->win_top + 1;
842 console_input_events_append( screen_buffer->input->evt, &evt );
845 if (req->mask & SET_CONSOLE_OUTPUT_INFO_MAX_SIZE)
847 /* can only be done by renderer */
848 if (current->process->console != screen_buffer->input)
850 set_error( STATUS_INVALID_PARAMETER );
851 return 0;
854 screen_buffer->max_width = req->max_width;
855 screen_buffer->max_height = req->max_height;
858 return 1;
861 /* appends a new line to history (history is a fixed size array) */
862 static void console_input_append_hist( struct console_input* console, const WCHAR* buf, size_t len )
864 WCHAR* ptr = mem_alloc( (len + 1) * sizeof(WCHAR) );
866 if (!ptr)
868 set_error( STATUS_NO_MEMORY );
869 return;
871 if (!console || !console->history_size)
873 set_error( STATUS_INVALID_PARAMETER ); /* FIXME */
874 return;
877 memcpy( ptr, buf, len * sizeof(WCHAR) );
878 ptr[len] = 0;
880 if (console->history_mode && console->history_index &&
881 strncmpW( console->history[console->history_index - 1], ptr, len * sizeof(WCHAR) ) == 0)
883 /* ok, mode ask us to not use twice the same string...
884 * so just free mem and returns
886 set_error( STATUS_ALIAS_EXISTS );
887 free(ptr);
888 return;
891 if (console->history_index < console->history_size)
893 console->history[console->history_index++] = ptr;
895 else
897 free( console->history[0]) ;
898 memmove( &console->history[0], &console->history[1],
899 (console->history_size - 1) * sizeof(WCHAR*) );
900 console->history[console->history_size - 1] = ptr;
904 /* returns a line from the cache */
905 static size_t console_input_get_hist( struct console_input *console, int index )
907 size_t ret = 0;
909 if (index >= console->history_index) set_error( STATUS_INVALID_PARAMETER );
910 else
912 ret = strlenW( console->history[index] ) * sizeof(WCHAR);
913 set_reply_data( console->history[index], min( ret, get_reply_max_size() ));
915 return ret;
918 /* dumb dump */
919 static void console_input_dump( struct object *obj, int verbose )
921 struct console_input *console = (struct console_input *)obj;
922 assert( obj->ops == &console_input_ops );
923 fprintf( stderr, "Console input active=%p evt=%p\n",
924 console->active, console->evt );
927 static void console_input_destroy( struct object *obj )
929 struct console_input* console_in = (struct console_input *)obj;
930 struct screen_buffer* curr;
931 int i;
933 assert( obj->ops == &console_input_ops );
934 if (console_in->title) free( console_in->title );
935 if (console_in->records) free( console_in->records );
937 if (console_in->active) release_object( console_in->active );
938 console_in->active = NULL;
940 for (curr = screen_buffer_list; curr; curr = curr->next)
942 if (curr->input == console_in) curr->input = NULL;
945 release_object( console_in->evt );
946 console_in->evt = NULL;
947 release_object( console_in->event );
949 for (i = 0; i < console_in->history_size; i++)
950 if (console_in->history[i]) free( console_in->history[i] );
951 if (console_in->history) free( console_in->history );
954 static void screen_buffer_dump( struct object *obj, int verbose )
956 struct screen_buffer *screen_buffer = (struct screen_buffer *)obj;
957 assert( obj->ops == &screen_buffer_ops );
959 fprintf(stderr, "Console screen buffer input=%p\n", screen_buffer->input );
962 static void screen_buffer_destroy( struct object *obj )
964 struct screen_buffer *screen_buffer = (struct screen_buffer *)obj;
966 assert( obj->ops == &screen_buffer_ops );
968 if (screen_buffer->next) screen_buffer->next->prev = screen_buffer->prev;
969 if (screen_buffer->prev) screen_buffer->prev->next = screen_buffer->next;
970 else screen_buffer_list = screen_buffer->next;
972 if (screen_buffer->input && screen_buffer->input->active == screen_buffer)
974 struct screen_buffer* sb;
975 for (sb = screen_buffer_list; sb && sb->input != screen_buffer->input; sb = sb->next);
976 screen_buffer->input->active = sb;
978 if (screen_buffer->data) free( screen_buffer->data );
981 /* write data into a screen buffer */
982 static int write_console_output( struct screen_buffer *screen_buffer, size_t size,
983 const void* data, enum char_info_mode mode,
984 int x, int y, int wrap )
986 int i;
987 char_info_t *end, *dest = screen_buffer->data + y * screen_buffer->width + x;
989 if (y >= screen_buffer->height) return 0;
991 if (wrap)
992 end = screen_buffer->data + screen_buffer->height * screen_buffer->width;
993 else
994 end = screen_buffer->data + (y+1) * screen_buffer->width;
996 switch(mode)
998 case CHAR_INFO_MODE_TEXT:
1000 const WCHAR *ptr = data;
1001 for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++) dest->ch = ptr[i];
1003 break;
1004 case CHAR_INFO_MODE_ATTR:
1006 const unsigned short *ptr = data;
1007 for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++) dest->attr = ptr[i];
1009 break;
1010 case CHAR_INFO_MODE_TEXTATTR:
1012 const char_info_t *ptr = data;
1013 for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++) *dest = ptr[i];
1015 break;
1016 case CHAR_INFO_MODE_TEXTSTDATTR:
1018 const WCHAR *ptr = data;
1019 for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++)
1021 dest->ch = ptr[i];
1022 dest->attr = screen_buffer->attr;
1025 break;
1026 default:
1027 set_error( STATUS_INVALID_PARAMETER );
1028 return 0;
1031 if (i && screen_buffer == screen_buffer->input->active)
1033 struct console_renderer_event evt;
1034 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
1035 evt.u.update.top = y + x / screen_buffer->width;
1036 evt.u.update.bottom = y + (x + i - 1) / screen_buffer->width;
1037 console_input_events_append( screen_buffer->input->evt, &evt );
1039 return i;
1042 /* fill a screen buffer with uniform data */
1043 static int fill_console_output( struct screen_buffer *screen_buffer, char_info_t data,
1044 enum char_info_mode mode, int x, int y, int count, int wrap )
1046 int i;
1047 char_info_t *end, *dest = screen_buffer->data + y * screen_buffer->width + x;
1049 if (y >= screen_buffer->height) return 0;
1051 if (wrap)
1052 end = screen_buffer->data + screen_buffer->height * screen_buffer->width;
1053 else
1054 end = screen_buffer->data + (y+1) * screen_buffer->width;
1056 if (count > end - dest) count = end - dest;
1058 switch(mode)
1060 case CHAR_INFO_MODE_TEXT:
1061 for (i = 0; i < count; i++) dest[i].ch = data.ch;
1062 break;
1063 case CHAR_INFO_MODE_ATTR:
1064 for (i = 0; i < count; i++) dest[i].attr = data.attr;
1065 break;
1066 case CHAR_INFO_MODE_TEXTATTR:
1067 for (i = 0; i < count; i++) dest[i] = data;
1068 break;
1069 case CHAR_INFO_MODE_TEXTSTDATTR:
1070 for (i = 0; i < count; i++)
1072 dest[i].ch = data.ch;
1073 dest[i].attr = screen_buffer->attr;
1075 break;
1076 default:
1077 set_error( STATUS_INVALID_PARAMETER );
1078 return 0;
1081 if (count && screen_buffer == screen_buffer->input->active)
1083 struct console_renderer_event evt;
1084 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
1085 evt.u.update.top = y;
1086 evt.u.update.bottom = (y * screen_buffer->width + x + count - 1) / screen_buffer->width;
1087 console_input_events_append( screen_buffer->input->evt, &evt );
1089 return i;
1092 /* read data from a screen buffer */
1093 static void read_console_output( struct screen_buffer *screen_buffer, int x, int y,
1094 enum char_info_mode mode, int wrap )
1096 int i;
1097 char_info_t *end, *src = screen_buffer->data + y * screen_buffer->width + x;
1099 if (y >= screen_buffer->height) return;
1101 if (wrap)
1102 end = screen_buffer->data + screen_buffer->height * screen_buffer->width;
1103 else
1104 end = screen_buffer->data + (y+1) * screen_buffer->width;
1106 switch(mode)
1108 case CHAR_INFO_MODE_TEXT:
1110 WCHAR *data;
1111 int count = min( end - src, get_reply_max_size() / sizeof(*data) );
1112 if ((data = set_reply_data_size( count * sizeof(*data) )))
1114 for (i = 0; i < count; i++) data[i] = src[i].ch;
1117 break;
1118 case CHAR_INFO_MODE_ATTR:
1120 unsigned short *data;
1121 int count = min( end - src, get_reply_max_size() / sizeof(*data) );
1122 if ((data = set_reply_data_size( count * sizeof(*data) )))
1124 for (i = 0; i < count; i++) data[i] = src[i].attr;
1127 break;
1128 case CHAR_INFO_MODE_TEXTATTR:
1130 char_info_t *data;
1131 int count = min( end - src, get_reply_max_size() / sizeof(*data) );
1132 if ((data = set_reply_data_size( count * sizeof(*data) )))
1134 for (i = 0; i < count; i++) data[i] = src[i];
1137 break;
1138 default:
1139 set_error( STATUS_INVALID_PARAMETER );
1140 break;
1144 /* scroll parts of a screen buffer */
1145 static void scroll_console_output( obj_handle_t handle, int xsrc, int ysrc, int xdst, int ydst,
1146 int w, int h )
1148 struct screen_buffer *screen_buffer;
1149 int j;
1150 char_info_t *psrc, *pdst;
1151 struct console_renderer_event evt;
1153 if (!(screen_buffer = (struct screen_buffer *)get_handle_obj( current->process, handle,
1154 GENERIC_READ, &screen_buffer_ops )))
1155 return;
1156 if (xsrc < 0 || ysrc < 0 || xdst < 0 || ydst < 0 ||
1157 xsrc + w > screen_buffer->width ||
1158 xdst + w > screen_buffer->width ||
1159 ysrc + h > screen_buffer->height ||
1160 ydst + h > screen_buffer->height ||
1161 w == 0 || h == 0)
1163 set_error( STATUS_INVALID_PARAMETER );
1164 release_object( screen_buffer );
1165 return;
1168 if (ysrc < ydst)
1170 psrc = &screen_buffer->data[(ysrc + h - 1) * screen_buffer->width + xsrc];
1171 pdst = &screen_buffer->data[(ydst + h - 1) * screen_buffer->width + xdst];
1173 for (j = h; j > 0; j--)
1175 memcpy(pdst, psrc, w * sizeof(*pdst) );
1176 pdst -= screen_buffer->width;
1177 psrc -= screen_buffer->width;
1180 else
1182 psrc = &screen_buffer->data[ysrc * screen_buffer->width + xsrc];
1183 pdst = &screen_buffer->data[ydst * screen_buffer->width + xdst];
1185 for (j = 0; j < h; j++)
1187 /* we use memmove here because when psrc and pdst are the same,
1188 * copies are done on the same row, so the dst and src blocks
1189 * can overlap */
1190 memmove( pdst, psrc, w * sizeof(*pdst) );
1191 pdst += screen_buffer->width;
1192 psrc += screen_buffer->width;
1196 /* FIXME: this could be enhanced, by signalling scroll */
1197 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
1198 evt.u.update.top = min(ysrc, ydst);
1199 evt.u.update.bottom = max(ysrc, ydst) + h - 1;
1200 console_input_events_append( screen_buffer->input->evt, &evt );
1202 release_object( screen_buffer );
1205 /* allocate a console for the renderer */
1206 DECL_HANDLER(alloc_console)
1208 obj_handle_t in = 0;
1209 obj_handle_t evt = 0;
1210 struct process *process;
1211 struct process *renderer = current->process;
1212 struct console_input *console;
1214 process = (req->pid) ? get_process_from_id( req->pid ) :
1215 (struct process *)grab_object( renderer->parent );
1217 reply->handle_in = 0;
1218 reply->event = 0;
1219 if (!process) return;
1220 if (process != renderer && process->console)
1222 set_error( STATUS_ACCESS_DENIED );
1223 goto the_end;
1225 if ((console = (struct console_input*)create_console_input( current )))
1227 if ((in = alloc_handle( renderer, console, req->access, req->inherit )))
1229 if ((evt = alloc_handle( renderer, console->evt,
1230 SYNCHRONIZE|GENERIC_READ|GENERIC_WRITE, FALSE )))
1232 if (process != renderer)
1234 process->console = (struct console_input*)grab_object( console );
1235 console->num_proc++;
1237 reply->handle_in = in;
1238 reply->event = evt;
1239 release_object( console );
1240 goto the_end;
1242 close_handle( renderer, in, NULL );
1244 free_console( process );
1246 the_end:
1247 release_object( process );
1250 /* free the console of the current process */
1251 DECL_HANDLER(free_console)
1253 free_console( current->process );
1256 /* let the renderer peek the events it's waiting on */
1257 DECL_HANDLER(get_console_renderer_events)
1259 struct console_input_events *evt;
1261 evt = (struct console_input_events *)get_handle_obj( current->process, req->handle,
1262 GENERIC_WRITE, &console_input_events_ops );
1263 if (!evt) return;
1264 console_input_events_get( evt );
1265 release_object( evt );
1268 /* open a handle to the process console */
1269 DECL_HANDLER(open_console)
1271 struct object *obj = NULL;
1273 reply->handle = 0;
1274 switch (req->from)
1276 case 0:
1277 if (current->process->console && current->process->console->renderer)
1278 obj = grab_object( (struct object*)current->process->console );
1279 break;
1280 case 1:
1281 if (current->process->console && current->process->console->renderer &&
1282 current->process->console->active)
1283 obj = grab_object( (struct object*)current->process->console->active );
1284 break;
1285 default:
1286 if ((obj = get_handle_obj( current->process, (obj_handle_t)req->from,
1287 GENERIC_READ|GENERIC_WRITE, &console_input_ops )))
1289 struct console_input* console = (struct console_input*)obj;
1290 obj = (console->active) ? grab_object( console->active ) : NULL;
1291 release_object( console );
1293 break;
1296 /* FIXME: req->share is not used (as in screen buffer creation) */
1297 if (obj)
1299 reply->handle = alloc_handle( current->process, obj, req->access, req->inherit );
1300 release_object( obj );
1302 else if (!get_error()) set_error( STATUS_ACCESS_DENIED );
1305 /* set info about a console input */
1306 DECL_HANDLER(set_console_input_info)
1308 set_console_input_info( req, get_req_data(), get_req_data_size() );
1311 /* get info about a console (output only) */
1312 DECL_HANDLER(get_console_input_info)
1314 struct console_input *console;
1316 if (!(console = console_input_get( req->handle, GENERIC_READ ))) return;
1317 if (console->title)
1319 size_t len = strlenW( console->title ) * sizeof(WCHAR);
1320 if (len > get_reply_max_size()) len = get_reply_max_size();
1321 set_reply_data( console->title, len );
1323 reply->history_mode = console->history_mode;
1324 reply->history_size = console->history_size;
1325 reply->history_index = console->history_index;
1326 reply->edition_mode = console->edition_mode;
1328 release_object( console );
1331 /* get a console mode (input or output) */
1332 DECL_HANDLER(get_console_mode)
1334 reply->mode = get_console_mode( req->handle );
1337 /* set a console mode (input or output) */
1338 DECL_HANDLER(set_console_mode)
1340 set_console_mode( req->handle, req->mode );
1343 /* add input records to a console input queue */
1344 DECL_HANDLER(write_console_input)
1346 struct console_input *console;
1348 reply->written = 0;
1349 if (!(console = (struct console_input *)get_handle_obj( current->process, req->handle,
1350 GENERIC_WRITE, &console_input_ops )))
1351 return;
1352 reply->written = write_console_input( console, get_req_data_size() / sizeof(INPUT_RECORD),
1353 get_req_data() );
1354 release_object( console );
1357 /* fetch input records from a console input queue */
1358 DECL_HANDLER(read_console_input)
1360 int count = get_reply_max_size() / sizeof(INPUT_RECORD);
1361 reply->read = read_console_input( req->handle, count, req->flush );
1364 /* appends a string to console's history */
1365 DECL_HANDLER(append_console_input_history)
1367 struct console_input *console;
1369 if (!(console = console_input_get( req->handle, GENERIC_WRITE ))) return;
1370 console_input_append_hist( console, get_req_data(), get_req_data_size() / sizeof(WCHAR) );
1371 release_object( console );
1374 /* appends a string to console's history */
1375 DECL_HANDLER(get_console_input_history)
1377 struct console_input *console;
1379 if (!(console = console_input_get( req->handle, GENERIC_WRITE ))) return;
1380 reply->total = console_input_get_hist( console, req->index );
1381 release_object( console );
1384 /* creates a screen buffer */
1385 DECL_HANDLER(create_console_output)
1387 struct console_input* console;
1388 struct screen_buffer* screen_buffer;
1390 if (!(console = console_input_get( req->handle_in, GENERIC_WRITE))) return;
1392 screen_buffer = create_console_output( console );
1393 if (screen_buffer)
1395 /* FIXME: should store sharing and test it when opening the CONOUT$ device
1396 * see file.c on how this could be done */
1397 reply->handle_out = alloc_handle( current->process, screen_buffer,
1398 req->access, req->inherit );
1399 release_object( screen_buffer );
1401 release_object( console );
1404 /* set info about a console screen buffer */
1405 DECL_HANDLER(set_console_output_info)
1407 struct screen_buffer *screen_buffer;
1409 if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle,
1410 GENERIC_WRITE, &screen_buffer_ops)))
1412 set_console_output_info( screen_buffer, req );
1413 release_object( screen_buffer );
1417 /* get info about a console screen buffer */
1418 DECL_HANDLER(get_console_output_info)
1420 struct screen_buffer *screen_buffer;
1422 if ((screen_buffer = (struct screen_buffer *)get_handle_obj( current->process, req->handle,
1423 GENERIC_READ, &screen_buffer_ops)))
1425 reply->cursor_size = screen_buffer->cursor_size;
1426 reply->cursor_visible = screen_buffer->cursor_visible;
1427 reply->cursor_x = screen_buffer->cursor_x;
1428 reply->cursor_y = screen_buffer->cursor_y;
1429 reply->width = screen_buffer->width;
1430 reply->height = screen_buffer->height;
1431 reply->attr = screen_buffer->attr;
1432 reply->win_left = screen_buffer->win.left;
1433 reply->win_top = screen_buffer->win.top;
1434 reply->win_right = screen_buffer->win.right;
1435 reply->win_bottom = screen_buffer->win.bottom;
1436 reply->max_width = screen_buffer->max_width;
1437 reply->max_height = screen_buffer->max_height;
1438 release_object( screen_buffer );
1442 /* read data (chars & attrs) from a screen buffer */
1443 DECL_HANDLER(read_console_output)
1445 struct screen_buffer *screen_buffer;
1447 if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle,
1448 GENERIC_READ, &screen_buffer_ops )))
1450 read_console_output( screen_buffer, req->x, req->y, req->mode, req->wrap );
1451 reply->width = screen_buffer->width;
1452 reply->height = screen_buffer->height;
1453 release_object( screen_buffer );
1457 /* write data (char and/or attrs) to a screen buffer */
1458 DECL_HANDLER(write_console_output)
1460 struct screen_buffer *screen_buffer;
1462 if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle,
1463 GENERIC_WRITE, &screen_buffer_ops)))
1465 reply->written = write_console_output( screen_buffer, get_req_data_size(), get_req_data(),
1466 req->mode, req->x, req->y, req->wrap );
1467 reply->width = screen_buffer->width;
1468 reply->height = screen_buffer->height;
1469 release_object( screen_buffer );
1473 /* fill a screen buffer with constant data (chars and/or attributes) */
1474 DECL_HANDLER(fill_console_output)
1476 struct screen_buffer *screen_buffer;
1478 if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle,
1479 GENERIC_WRITE, &screen_buffer_ops)))
1481 reply->written = fill_console_output( screen_buffer, req->data, req->mode,
1482 req->x, req->y, req->count, req->wrap );
1483 release_object( screen_buffer );
1487 /* move a rect of data in a screen buffer */
1488 DECL_HANDLER(move_console_output)
1490 scroll_console_output( req->handle, req->x_src, req->y_src, req->x_dst, req->y_dst,
1491 req->w, req->h );
1494 /* sends a signal to a console (process, group...) */
1495 DECL_HANDLER(send_console_signal)
1497 process_id_t group;
1499 group = req->group_id ? req->group_id : current->process->group_id;
1501 if (!group)
1502 set_error( STATUS_INVALID_PARAMETER );
1503 else
1504 propagate_console_signal( current->process->console, req->signal, group );
1507 /* get console which renderer is 'current' */
1508 static int cgwe_enum( struct process* process, void* user)
1510 if (process->console && process->console->renderer == current)
1512 *(struct console_input**)user = process->console;
1513 return 1;
1515 return 0;
1518 DECL_HANDLER(get_console_wait_event)
1520 struct console_input* console = NULL;
1522 if (current->process->console && current->process->console->renderer)
1523 console = (struct console_input*)grab_object( (struct object*)current->process->console );
1524 else enum_processes(cgwe_enum, &console);
1526 if (console)
1528 reply->handle = alloc_handle( current->process, console->event,
1529 EVENT_ALL_ACCESS, FALSE);
1530 release_object( console );
1532 else set_error( STATUS_INVALID_PARAMETER );