Update the dlls section.
[wine/multimedia.git] / server / console.c
blobb9da5a6dd6fda7d7b7ca57902261e9086a1edb1a
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 {
390 struct console_input *console;
391 process_id_t group;
392 int signal;
395 static int propagate_console_signal_cb(struct process *process, void *user)
397 struct console_signal_info* csi = (struct console_signal_info*)user;
399 if (process->console == csi->console && process->running_threads &&
400 (!csi->group || process->group_id == csi->group))
402 struct thread *thread = process->thread_list;
404 while (thread)
406 struct thread *next = thread->proc_next;
407 send_thread_signal( thread, csi->signal );
408 thread = next;
411 return FALSE;
414 static void propagate_console_signal( struct console_input *console,
415 int sig, process_id_t group_id )
417 struct console_signal_info csi;
419 if (!console)
421 set_error( STATUS_INVALID_PARAMETER );
422 return;
424 /* FIXME: should support the other events (like CTRL_BREAK) */
425 if (sig != CTRL_C_EVENT)
427 set_error( STATUS_NOT_IMPLEMENTED );
428 return;
430 csi.console = console;
431 csi.signal = SIGINT;
432 csi.group = group_id;
434 enum_processes(propagate_console_signal_cb, &csi);
437 static int get_console_mode( obj_handle_t handle )
439 struct object *obj;
440 int ret = 0;
442 if ((obj = get_handle_obj( current->process, handle, GENERIC_READ, NULL )))
444 if (obj->ops == &console_input_ops)
445 ret = ((struct console_input *)obj)->mode;
446 else if (obj->ops == &screen_buffer_ops)
447 ret = ((struct screen_buffer *)obj)->mode;
448 else
449 set_error( STATUS_OBJECT_TYPE_MISMATCH );
450 release_object( obj );
452 return ret;
455 /* changes the mode of either a console input or a screen buffer */
456 static int set_console_mode( obj_handle_t handle, int mode )
458 struct object *obj;
459 int ret = 0;
461 if (!(obj = get_handle_obj( current->process, handle, GENERIC_WRITE, NULL )))
462 return 0;
463 if (obj->ops == &console_input_ops)
465 /* FIXME: if we remove the edit mode bits, we need (???) to clean up the history */
466 ((struct console_input *)obj)->mode = mode;
467 ret = 1;
469 else if (obj->ops == &screen_buffer_ops)
471 ((struct screen_buffer *)obj)->mode = mode;
472 ret = 1;
474 else set_error( STATUS_OBJECT_TYPE_MISMATCH );
475 release_object( obj );
476 return ret;
479 /* add input events to a console input queue */
480 static int write_console_input( struct console_input* console, int count,
481 const INPUT_RECORD *records )
483 INPUT_RECORD *new_rec;
485 if (!count) return 0;
486 if (!(new_rec = realloc( console->records,
487 (console->recnum + count) * sizeof(INPUT_RECORD) )))
489 set_error( STATUS_NO_MEMORY );
490 release_object( console );
491 return -1;
493 console->records = new_rec;
494 memcpy( new_rec + console->recnum, records, count * sizeof(INPUT_RECORD) );
496 if (console->mode & ENABLE_PROCESSED_INPUT)
498 int i = 0;
499 while (i < count)
501 if (records[i].EventType == KEY_EVENT &&
502 records[i].Event.KeyEvent.uChar.UnicodeChar == 'C' - 64 &&
503 !(records[i].Event.KeyEvent.dwControlKeyState & ENHANCED_KEY))
505 if (i != count - 1)
506 memcpy( &console->records[console->recnum + i],
507 &console->records[console->recnum + i + 1],
508 (count - i - 1) * sizeof(INPUT_RECORD) );
509 count--;
510 if (records[i].Event.KeyEvent.bKeyDown)
512 /* send SIGINT to all processes attached to this console */
513 propagate_console_signal( console, CTRL_C_EVENT, 0 );
516 else i++;
519 if (!console->recnum && count) set_event( console->event );
520 console->recnum += count;
521 return count;
524 /* retrieve a pointer to the console input records */
525 static int read_console_input( obj_handle_t handle, int count, int flush )
527 struct console_input *console;
529 if (!(console = (struct console_input *)get_handle_obj( current->process, handle,
530 GENERIC_READ, &console_input_ops )))
531 return -1;
533 if (!count)
535 /* special case: do not retrieve anything, but return
536 * the total number of records available */
537 count = console->recnum;
539 else
541 if (count > console->recnum) count = console->recnum;
542 set_reply_data( console->records, count * sizeof(INPUT_RECORD) );
544 if (flush)
546 int i;
547 for (i = count; i < console->recnum; i++)
548 console->records[i-count] = console->records[i];
549 if ((console->recnum -= count) > 0)
551 INPUT_RECORD *new_rec = realloc( console->records,
552 console->recnum * sizeof(INPUT_RECORD) );
553 if (new_rec) console->records = new_rec;
555 else
557 free( console->records );
558 console->records = NULL;
559 reset_event( console->event );
562 release_object( console );
563 return count;
566 /* set misc console input information */
567 static int set_console_input_info( const struct set_console_input_info_request *req,
568 const WCHAR *title, size_t len )
570 struct console_input *console;
571 struct console_renderer_event evt;
573 if (!(console = console_input_get( req->handle, GENERIC_WRITE ))) goto error;
575 if (req->mask & SET_CONSOLE_INPUT_INFO_ACTIVE_SB)
577 struct screen_buffer *screen_buffer;
579 screen_buffer = (struct screen_buffer *)get_handle_obj( current->process, req->active_sb,
580 GENERIC_READ, &screen_buffer_ops );
581 if (!screen_buffer || screen_buffer->input != console)
583 set_error( STATUS_INVALID_PARAMETER );
584 if (screen_buffer) release_object( screen_buffer );
585 goto error;
588 if (screen_buffer != console->active)
590 if (console->active) release_object( console->active );
591 console->active = screen_buffer;
592 evt.event = CONSOLE_RENDERER_ACTIVE_SB_EVENT;
593 console_input_events_append( console->evt, &evt );
595 else
596 release_object( screen_buffer );
598 if (req->mask & SET_CONSOLE_INPUT_INFO_TITLE)
600 WCHAR *new_title = mem_alloc( len + sizeof(WCHAR) );
601 if (new_title)
603 memcpy( new_title, title, len );
604 new_title[len / sizeof(WCHAR)] = 0;
605 if (console->title) free( console->title );
606 console->title = new_title;
607 evt.event = CONSOLE_RENDERER_TITLE_EVENT;
608 console_input_events_append( console->evt, &evt );
611 if (req->mask & SET_CONSOLE_INPUT_INFO_HISTORY_MODE)
613 console->history_mode = req->history_mode;
615 if ((req->mask & SET_CONSOLE_INPUT_INFO_HISTORY_SIZE) &&
616 console->history_size != req->history_size)
618 WCHAR** mem = NULL;
619 int i;
620 int delta;
622 if (req->history_size)
624 mem = mem_alloc( req->history_size * sizeof(WCHAR*) );
625 if (!mem) goto error;
626 memset( mem, 0, req->history_size * sizeof(WCHAR*) );
629 delta = (console->history_index > req->history_size) ?
630 (console->history_index - req->history_size) : 0;
632 for (i = delta; i < console->history_index; i++)
634 mem[i - delta] = console->history[i];
635 console->history[i] = NULL;
637 console->history_index -= delta;
639 for (i = 0; i < console->history_size; i++)
640 if (console->history[i]) free( console->history[i] );
641 free( console->history );
642 console->history = mem;
643 console->history_size = req->history_size;
645 if (req->mask & SET_CONSOLE_INPUT_INFO_EDITION_MODE)
647 console->edition_mode = req->edition_mode;
649 release_object( console );
650 return 1;
651 error:
652 if (console) release_object( console );
653 return 0;
656 /* resize a screen buffer */
657 static int change_screen_buffer_size( struct screen_buffer *screen_buffer,
658 int new_width, int new_height )
660 int i, old_width, old_height, copy_width, copy_height;
661 char_info_t *new_data;
663 if (!(new_data = malloc( new_width * new_height * sizeof(*new_data) )))
665 set_error( STATUS_NO_MEMORY );
666 return 0;
668 old_width = screen_buffer->width;
669 old_height = screen_buffer->height;
670 copy_width = min( old_width, new_width );
671 copy_height = min( old_height, new_height );
673 /* copy all the rows */
674 for (i = 0; i < copy_height; i++)
676 memcpy( &new_data[i * new_width], &screen_buffer->data[i * old_width],
677 copy_width * sizeof(char_info_t) );
680 /* clear the end of each row */
681 if (new_width > old_width)
683 /* fill first row */
684 for (i = old_width; i < new_width; i++) new_data[i] = empty_char_info;
685 /* and blast it to the other rows */
686 for (i = 1; i < copy_height; i++)
687 memcpy( &new_data[i * new_width + old_width], &new_data[old_width],
688 (new_width - old_width) * sizeof(char_info_t) );
691 /* clear remaining rows */
692 if (new_height > old_height)
694 /* fill first row */
695 for (i = 0; i < new_width; i++) new_data[old_height * new_width + i] = empty_char_info;
696 /* and blast it to the other rows */
697 for (i = old_height+1; i < new_height; i++)
698 memcpy( &new_data[i * new_width], &new_data[old_height * new_width],
699 new_width * sizeof(char_info_t) );
701 free( screen_buffer->data );
702 screen_buffer->data = new_data;
703 screen_buffer->width = new_width;
704 screen_buffer->height = new_height;
705 return 1;
708 /* set misc screen buffer information */
709 static int set_console_output_info( struct screen_buffer *screen_buffer,
710 const struct set_console_output_info_request *req )
712 struct console_renderer_event evt;
714 if (req->mask & SET_CONSOLE_OUTPUT_INFO_CURSOR_GEOM)
716 if (req->cursor_size < 1 || req->cursor_size > 100)
718 set_error( STATUS_INVALID_PARAMETER );
719 return 0;
721 if (screen_buffer->cursor_size != req->cursor_size ||
722 screen_buffer->cursor_visible != req->cursor_visible)
724 screen_buffer->cursor_size = req->cursor_size;
725 screen_buffer->cursor_visible = req->cursor_visible;
726 evt.event = CONSOLE_RENDERER_CURSOR_GEOM_EVENT;
727 evt.u.cursor_geom.size = req->cursor_size;
728 evt.u.cursor_geom.visible = req->cursor_visible;
729 console_input_events_append( screen_buffer->input->evt, &evt );
732 if (req->mask & SET_CONSOLE_OUTPUT_INFO_CURSOR_POS)
734 if (req->cursor_x < 0 || req->cursor_x >= screen_buffer->width ||
735 req->cursor_y < 0 || req->cursor_y >= screen_buffer->height)
737 set_error( STATUS_INVALID_PARAMETER );
738 return 0;
740 if (screen_buffer->cursor_x != req->cursor_x || screen_buffer->cursor_y != req->cursor_y)
742 screen_buffer->cursor_x = req->cursor_x;
743 screen_buffer->cursor_y = req->cursor_y;
744 evt.event = CONSOLE_RENDERER_CURSOR_POS_EVENT;
745 evt.u.cursor_pos.x = req->cursor_x;
746 evt.u.cursor_pos.y = req->cursor_y;
747 console_input_events_append( screen_buffer->input->evt, &evt );
750 if (req->mask & SET_CONSOLE_OUTPUT_INFO_SIZE)
752 unsigned cc;
754 /* new screen-buffer cannot be smaller than actual window */
755 if (req->width < screen_buffer->win.right - screen_buffer->win.left + 1 ||
756 req->height < screen_buffer->win.bottom - screen_buffer->win.top + 1)
758 set_error( STATUS_INVALID_PARAMETER );
759 return 0;
761 /* FIXME: there are also some basic minimum and max size to deal with */
762 if (!change_screen_buffer_size( screen_buffer, req->width, req->height )) return 0;
764 evt.event = CONSOLE_RENDERER_SB_RESIZE_EVENT;
765 evt.u.resize.width = req->width;
766 evt.u.resize.height = req->height;
767 console_input_events_append( screen_buffer->input->evt, &evt );
769 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
770 evt.u.update.top = 0;
771 evt.u.update.bottom = screen_buffer->height - 1;
772 console_input_events_append( screen_buffer->input->evt, &evt );
774 /* scroll window to display sb */
775 if (screen_buffer->win.right >= req->width)
777 screen_buffer->win.right -= screen_buffer->win.left;
778 screen_buffer->win.left = 0;
780 if (screen_buffer->win.bottom >= req->height)
782 screen_buffer->win.bottom -= screen_buffer->win.top;
783 screen_buffer->win.top = 0;
785 /* reset cursor if needed (normally, if cursor was outside of new sb, the
786 * window has been shifted so that the new position of the cursor will be
787 * visible */
788 cc = 0;
789 if (screen_buffer->cursor_x >= req->width)
791 screen_buffer->cursor_x = req->width - 1;
792 cc++;
794 if (screen_buffer->cursor_y >= req->height)
796 screen_buffer->cursor_y = req->height - 1;
797 cc++;
799 if (cc)
801 evt.event = CONSOLE_RENDERER_CURSOR_POS_EVENT;
802 evt.u.cursor_pos.x = req->cursor_x;
803 evt.u.cursor_pos.y = req->cursor_y;
804 console_input_events_append( screen_buffer->input->evt, &evt );
807 if (screen_buffer == screen_buffer->input->active &&
808 screen_buffer->input->mode & ENABLE_WINDOW_INPUT)
810 INPUT_RECORD ir;
811 ir.EventType = WINDOW_BUFFER_SIZE_EVENT;
812 ir.Event.WindowBufferSizeEvent.dwSize.X = req->width;
813 ir.Event.WindowBufferSizeEvent.dwSize.Y = req->height;
814 write_console_input( screen_buffer->input, 1, &ir );
817 if (req->mask & SET_CONSOLE_OUTPUT_INFO_ATTR)
819 screen_buffer->attr = req->attr;
821 if (req->mask & SET_CONSOLE_OUTPUT_INFO_DISPLAY_WINDOW)
823 if (req->win_left < 0 || req->win_left > req->win_right ||
824 req->win_right >= screen_buffer->width ||
825 req->win_top < 0 || req->win_top > req->win_bottom ||
826 req->win_bottom >= screen_buffer->height)
828 set_error( STATUS_INVALID_PARAMETER );
829 return 0;
831 if (screen_buffer->win.left != req->win_left || screen_buffer->win.top != req->win_top ||
832 screen_buffer->win.right != req->win_right || screen_buffer->win.bottom != req->win_bottom)
834 screen_buffer->win.left = req->win_left;
835 screen_buffer->win.top = req->win_top;
836 screen_buffer->win.right = req->win_right;
837 screen_buffer->win.bottom = req->win_bottom;
838 evt.event = CONSOLE_RENDERER_DISPLAY_EVENT;
839 evt.u.display.left = req->win_left;
840 evt.u.display.top = req->win_top;
841 evt.u.display.width = req->win_right - req->win_left + 1;
842 evt.u.display.height = req->win_bottom - req->win_top + 1;
843 console_input_events_append( screen_buffer->input->evt, &evt );
846 if (req->mask & SET_CONSOLE_OUTPUT_INFO_MAX_SIZE)
848 /* can only be done by renderer */
849 if (current->process->console != screen_buffer->input)
851 set_error( STATUS_INVALID_PARAMETER );
852 return 0;
855 screen_buffer->max_width = req->max_width;
856 screen_buffer->max_height = req->max_height;
859 return 1;
862 /* appends a new line to history (history is a fixed size array) */
863 static void console_input_append_hist( struct console_input* console, const WCHAR* buf, size_t len )
865 WCHAR* ptr = mem_alloc( (len + 1) * sizeof(WCHAR) );
867 if (!ptr)
869 set_error( STATUS_NO_MEMORY );
870 return;
872 if (!console || !console->history_size)
874 set_error( STATUS_INVALID_PARAMETER ); /* FIXME */
875 return;
878 memcpy( ptr, buf, len * sizeof(WCHAR) );
879 ptr[len] = 0;
881 if (console->history_mode && console->history_index &&
882 strncmpW( console->history[console->history_index - 1], ptr, len * sizeof(WCHAR) ) == 0)
884 /* ok, mode ask us to not use twice the same string...
885 * so just free mem and returns
887 set_error( STATUS_ALIAS_EXISTS );
888 free(ptr);
889 return;
892 if (console->history_index < console->history_size)
894 console->history[console->history_index++] = ptr;
896 else
898 free( console->history[0]) ;
899 memmove( &console->history[0], &console->history[1],
900 (console->history_size - 1) * sizeof(WCHAR*) );
901 console->history[console->history_size - 1] = ptr;
905 /* returns a line from the cache */
906 static size_t console_input_get_hist( struct console_input *console, int index )
908 size_t ret = 0;
910 if (index >= console->history_index) set_error( STATUS_INVALID_PARAMETER );
911 else
913 ret = strlenW( console->history[index] ) * sizeof(WCHAR);
914 set_reply_data( console->history[index], min( ret, get_reply_max_size() ));
916 return ret;
919 /* dumb dump */
920 static void console_input_dump( struct object *obj, int verbose )
922 struct console_input *console = (struct console_input *)obj;
923 assert( obj->ops == &console_input_ops );
924 fprintf( stderr, "Console input active=%p evt=%p\n",
925 console->active, console->evt );
928 static void console_input_destroy( struct object *obj )
930 struct console_input* console_in = (struct console_input *)obj;
931 struct screen_buffer* curr;
932 int i;
934 assert( obj->ops == &console_input_ops );
935 if (console_in->title) free( console_in->title );
936 if (console_in->records) free( console_in->records );
938 if (console_in->active) release_object( console_in->active );
939 console_in->active = NULL;
941 for (curr = screen_buffer_list; curr; curr = curr->next)
943 if (curr->input == console_in) curr->input = NULL;
946 release_object( console_in->evt );
947 console_in->evt = NULL;
948 release_object( console_in->event );
950 for (i = 0; i < console_in->history_size; i++)
951 if (console_in->history[i]) free( console_in->history[i] );
952 if (console_in->history) free( console_in->history );
955 static void screen_buffer_dump( struct object *obj, int verbose )
957 struct screen_buffer *screen_buffer = (struct screen_buffer *)obj;
958 assert( obj->ops == &screen_buffer_ops );
960 fprintf(stderr, "Console screen buffer input=%p\n", screen_buffer->input );
963 static void screen_buffer_destroy( struct object *obj )
965 struct screen_buffer *screen_buffer = (struct screen_buffer *)obj;
967 assert( obj->ops == &screen_buffer_ops );
969 if (screen_buffer->next) screen_buffer->next->prev = screen_buffer->prev;
970 if (screen_buffer->prev) screen_buffer->prev->next = screen_buffer->next;
971 else screen_buffer_list = screen_buffer->next;
973 if (screen_buffer->input && screen_buffer->input->active == screen_buffer)
975 struct screen_buffer* sb;
976 for (sb = screen_buffer_list; sb && sb->input != screen_buffer->input; sb = sb->next);
977 screen_buffer->input->active = sb;
979 if (screen_buffer->data) free( screen_buffer->data );
982 /* write data into a screen buffer */
983 static int write_console_output( struct screen_buffer *screen_buffer, size_t size,
984 const void* data, enum char_info_mode mode,
985 int x, int y, int wrap )
987 int i;
988 char_info_t *end, *dest = screen_buffer->data + y * screen_buffer->width + x;
990 if (y >= screen_buffer->height) return 0;
992 if (wrap)
993 end = screen_buffer->data + screen_buffer->height * screen_buffer->width;
994 else
995 end = screen_buffer->data + (y+1) * screen_buffer->width;
997 switch(mode)
999 case CHAR_INFO_MODE_TEXT:
1001 const WCHAR *ptr = data;
1002 for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++) dest->ch = ptr[i];
1004 break;
1005 case CHAR_INFO_MODE_ATTR:
1007 const unsigned short *ptr = data;
1008 for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++) dest->attr = ptr[i];
1010 break;
1011 case CHAR_INFO_MODE_TEXTATTR:
1013 const char_info_t *ptr = data;
1014 for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++) *dest = ptr[i];
1016 break;
1017 case CHAR_INFO_MODE_TEXTSTDATTR:
1019 const WCHAR *ptr = data;
1020 for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++)
1022 dest->ch = ptr[i];
1023 dest->attr = screen_buffer->attr;
1026 break;
1027 default:
1028 set_error( STATUS_INVALID_PARAMETER );
1029 return 0;
1032 if (i && screen_buffer == screen_buffer->input->active)
1034 struct console_renderer_event evt;
1035 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
1036 evt.u.update.top = y + x / screen_buffer->width;
1037 evt.u.update.bottom = y + (x + i - 1) / screen_buffer->width;
1038 console_input_events_append( screen_buffer->input->evt, &evt );
1040 return i;
1043 /* fill a screen buffer with uniform data */
1044 static int fill_console_output( struct screen_buffer *screen_buffer, char_info_t data,
1045 enum char_info_mode mode, int x, int y, int count, int wrap )
1047 int i;
1048 char_info_t *end, *dest = screen_buffer->data + y * screen_buffer->width + x;
1050 if (y >= screen_buffer->height) return 0;
1052 if (wrap)
1053 end = screen_buffer->data + screen_buffer->height * screen_buffer->width;
1054 else
1055 end = screen_buffer->data + (y+1) * screen_buffer->width;
1057 if (count > end - dest) count = end - dest;
1059 switch(mode)
1061 case CHAR_INFO_MODE_TEXT:
1062 for (i = 0; i < count; i++) dest[i].ch = data.ch;
1063 break;
1064 case CHAR_INFO_MODE_ATTR:
1065 for (i = 0; i < count; i++) dest[i].attr = data.attr;
1066 break;
1067 case CHAR_INFO_MODE_TEXTATTR:
1068 for (i = 0; i < count; i++) dest[i] = data;
1069 break;
1070 case CHAR_INFO_MODE_TEXTSTDATTR:
1071 for (i = 0; i < count; i++)
1073 dest[i].ch = data.ch;
1074 dest[i].attr = screen_buffer->attr;
1076 break;
1077 default:
1078 set_error( STATUS_INVALID_PARAMETER );
1079 return 0;
1082 if (count && screen_buffer == screen_buffer->input->active)
1084 struct console_renderer_event evt;
1085 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
1086 evt.u.update.top = y;
1087 evt.u.update.bottom = (y * screen_buffer->width + x + count - 1) / screen_buffer->width;
1088 console_input_events_append( screen_buffer->input->evt, &evt );
1090 return i;
1093 /* read data from a screen buffer */
1094 static void read_console_output( struct screen_buffer *screen_buffer, int x, int y,
1095 enum char_info_mode mode, int wrap )
1097 int i;
1098 char_info_t *end, *src = screen_buffer->data + y * screen_buffer->width + x;
1100 if (y >= screen_buffer->height) return;
1102 if (wrap)
1103 end = screen_buffer->data + screen_buffer->height * screen_buffer->width;
1104 else
1105 end = screen_buffer->data + (y+1) * screen_buffer->width;
1107 switch(mode)
1109 case CHAR_INFO_MODE_TEXT:
1111 WCHAR *data;
1112 int count = min( end - src, get_reply_max_size() / sizeof(*data) );
1113 if ((data = set_reply_data_size( count * sizeof(*data) )))
1115 for (i = 0; i < count; i++) data[i] = src[i].ch;
1118 break;
1119 case CHAR_INFO_MODE_ATTR:
1121 unsigned short *data;
1122 int count = min( end - src, get_reply_max_size() / sizeof(*data) );
1123 if ((data = set_reply_data_size( count * sizeof(*data) )))
1125 for (i = 0; i < count; i++) data[i] = src[i].attr;
1128 break;
1129 case CHAR_INFO_MODE_TEXTATTR:
1131 char_info_t *data;
1132 int count = min( end - src, get_reply_max_size() / sizeof(*data) );
1133 if ((data = set_reply_data_size( count * sizeof(*data) )))
1135 for (i = 0; i < count; i++) data[i] = src[i];
1138 break;
1139 default:
1140 set_error( STATUS_INVALID_PARAMETER );
1141 break;
1145 /* scroll parts of a screen buffer */
1146 static void scroll_console_output( obj_handle_t handle, int xsrc, int ysrc, int xdst, int ydst,
1147 int w, int h )
1149 struct screen_buffer *screen_buffer;
1150 int j;
1151 char_info_t *psrc, *pdst;
1152 struct console_renderer_event evt;
1154 if (!(screen_buffer = (struct screen_buffer *)get_handle_obj( current->process, handle,
1155 GENERIC_READ, &screen_buffer_ops )))
1156 return;
1157 if (xsrc < 0 || ysrc < 0 || xdst < 0 || ydst < 0 ||
1158 xsrc + w > screen_buffer->width ||
1159 xdst + w > screen_buffer->width ||
1160 ysrc + h > screen_buffer->height ||
1161 ydst + h > screen_buffer->height ||
1162 w == 0 || h == 0)
1164 set_error( STATUS_INVALID_PARAMETER );
1165 release_object( screen_buffer );
1166 return;
1169 if (ysrc < ydst)
1171 psrc = &screen_buffer->data[(ysrc + h - 1) * screen_buffer->width + xsrc];
1172 pdst = &screen_buffer->data[(ydst + h - 1) * screen_buffer->width + xdst];
1174 for (j = h; j > 0; j--)
1176 memcpy(pdst, psrc, w * sizeof(*pdst) );
1177 pdst -= screen_buffer->width;
1178 psrc -= screen_buffer->width;
1181 else
1183 psrc = &screen_buffer->data[ysrc * screen_buffer->width + xsrc];
1184 pdst = &screen_buffer->data[ydst * screen_buffer->width + xdst];
1186 for (j = 0; j < h; j++)
1188 /* we use memmove here because when psrc and pdst are the same,
1189 * copies are done on the same row, so the dst and src blocks
1190 * can overlap */
1191 memmove( pdst, psrc, w * sizeof(*pdst) );
1192 pdst += screen_buffer->width;
1193 psrc += screen_buffer->width;
1197 /* FIXME: this could be enhanced, by signalling scroll */
1198 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
1199 evt.u.update.top = min(ysrc, ydst);
1200 evt.u.update.bottom = max(ysrc, ydst) + h - 1;
1201 console_input_events_append( screen_buffer->input->evt, &evt );
1203 release_object( screen_buffer );
1206 /* allocate a console for the renderer */
1207 DECL_HANDLER(alloc_console)
1209 obj_handle_t in = 0;
1210 obj_handle_t evt = 0;
1211 struct process *process;
1212 struct process *renderer = current->process;
1213 struct console_input *console;
1215 process = (req->pid) ? get_process_from_id( req->pid ) :
1216 (struct process *)grab_object( renderer->parent );
1218 reply->handle_in = 0;
1219 reply->event = 0;
1220 if (!process) return;
1221 if (process != renderer && process->console)
1223 set_error( STATUS_ACCESS_DENIED );
1224 goto the_end;
1226 if ((console = (struct console_input*)create_console_input( current )))
1228 if ((in = alloc_handle( renderer, console, req->access, req->inherit )))
1230 if ((evt = alloc_handle( renderer, console->evt,
1231 SYNCHRONIZE|GENERIC_READ|GENERIC_WRITE, FALSE )))
1233 if (process != renderer)
1235 process->console = (struct console_input*)grab_object( console );
1236 console->num_proc++;
1238 reply->handle_in = in;
1239 reply->event = evt;
1240 release_object( console );
1241 goto the_end;
1243 close_handle( renderer, in, NULL );
1245 free_console( process );
1247 the_end:
1248 release_object( process );
1251 /* free the console of the current process */
1252 DECL_HANDLER(free_console)
1254 free_console( current->process );
1257 /* let the renderer peek the events it's waiting on */
1258 DECL_HANDLER(get_console_renderer_events)
1260 struct console_input_events *evt;
1262 evt = (struct console_input_events *)get_handle_obj( current->process, req->handle,
1263 GENERIC_WRITE, &console_input_events_ops );
1264 if (!evt) return;
1265 console_input_events_get( evt );
1266 release_object( evt );
1269 /* open a handle to the process console */
1270 DECL_HANDLER(open_console)
1272 struct object *obj = NULL;
1274 reply->handle = 0;
1275 switch (req->from)
1277 case 0:
1278 if (current->process->console && current->process->console->renderer)
1279 obj = grab_object( (struct object*)current->process->console );
1280 break;
1281 case 1:
1282 if (current->process->console && current->process->console->renderer &&
1283 current->process->console->active)
1284 obj = grab_object( (struct object*)current->process->console->active );
1285 break;
1286 default:
1287 if ((obj = get_handle_obj( current->process, (obj_handle_t)req->from,
1288 GENERIC_READ|GENERIC_WRITE, &console_input_ops )))
1290 struct console_input* console = (struct console_input*)obj;
1291 obj = (console->active) ? grab_object( console->active ) : NULL;
1292 release_object( console );
1294 break;
1297 /* FIXME: req->share is not used (as in screen buffer creation) */
1298 if (obj)
1300 reply->handle = alloc_handle( current->process, obj, req->access, req->inherit );
1301 release_object( obj );
1303 else if (!get_error()) set_error( STATUS_ACCESS_DENIED );
1306 /* set info about a console input */
1307 DECL_HANDLER(set_console_input_info)
1309 set_console_input_info( req, get_req_data(), get_req_data_size() );
1312 /* get info about a console (output only) */
1313 DECL_HANDLER(get_console_input_info)
1315 struct console_input *console;
1317 if (!(console = console_input_get( req->handle, GENERIC_READ ))) return;
1318 if (console->title)
1320 size_t len = strlenW( console->title ) * sizeof(WCHAR);
1321 if (len > get_reply_max_size()) len = get_reply_max_size();
1322 set_reply_data( console->title, len );
1324 reply->history_mode = console->history_mode;
1325 reply->history_size = console->history_size;
1326 reply->history_index = console->history_index;
1327 reply->edition_mode = console->edition_mode;
1329 release_object( console );
1332 /* get a console mode (input or output) */
1333 DECL_HANDLER(get_console_mode)
1335 reply->mode = get_console_mode( req->handle );
1338 /* set a console mode (input or output) */
1339 DECL_HANDLER(set_console_mode)
1341 set_console_mode( req->handle, req->mode );
1344 /* add input records to a console input queue */
1345 DECL_HANDLER(write_console_input)
1347 struct console_input *console;
1349 reply->written = 0;
1350 if (!(console = (struct console_input *)get_handle_obj( current->process, req->handle,
1351 GENERIC_WRITE, &console_input_ops )))
1352 return;
1353 reply->written = write_console_input( console, get_req_data_size() / sizeof(INPUT_RECORD),
1354 get_req_data() );
1355 release_object( console );
1358 /* fetch input records from a console input queue */
1359 DECL_HANDLER(read_console_input)
1361 int count = get_reply_max_size() / sizeof(INPUT_RECORD);
1362 reply->read = read_console_input( req->handle, count, req->flush );
1365 /* appends a string to console's history */
1366 DECL_HANDLER(append_console_input_history)
1368 struct console_input *console;
1370 if (!(console = console_input_get( req->handle, GENERIC_WRITE ))) return;
1371 console_input_append_hist( console, get_req_data(), get_req_data_size() / sizeof(WCHAR) );
1372 release_object( console );
1375 /* appends a string to console's history */
1376 DECL_HANDLER(get_console_input_history)
1378 struct console_input *console;
1380 if (!(console = console_input_get( req->handle, GENERIC_WRITE ))) return;
1381 reply->total = console_input_get_hist( console, req->index );
1382 release_object( console );
1385 /* creates a screen buffer */
1386 DECL_HANDLER(create_console_output)
1388 struct console_input* console;
1389 struct screen_buffer* screen_buffer;
1391 if (!(console = console_input_get( req->handle_in, GENERIC_WRITE))) return;
1393 screen_buffer = create_console_output( console );
1394 if (screen_buffer)
1396 /* FIXME: should store sharing and test it when opening the CONOUT$ device
1397 * see file.c on how this could be done */
1398 reply->handle_out = alloc_handle( current->process, screen_buffer,
1399 req->access, req->inherit );
1400 release_object( screen_buffer );
1402 release_object( console );
1405 /* set info about a console screen buffer */
1406 DECL_HANDLER(set_console_output_info)
1408 struct screen_buffer *screen_buffer;
1410 if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle,
1411 GENERIC_WRITE, &screen_buffer_ops)))
1413 set_console_output_info( screen_buffer, req );
1414 release_object( screen_buffer );
1418 /* get info about a console screen buffer */
1419 DECL_HANDLER(get_console_output_info)
1421 struct screen_buffer *screen_buffer;
1423 if ((screen_buffer = (struct screen_buffer *)get_handle_obj( current->process, req->handle,
1424 GENERIC_READ, &screen_buffer_ops)))
1426 reply->cursor_size = screen_buffer->cursor_size;
1427 reply->cursor_visible = screen_buffer->cursor_visible;
1428 reply->cursor_x = screen_buffer->cursor_x;
1429 reply->cursor_y = screen_buffer->cursor_y;
1430 reply->width = screen_buffer->width;
1431 reply->height = screen_buffer->height;
1432 reply->attr = screen_buffer->attr;
1433 reply->win_left = screen_buffer->win.left;
1434 reply->win_top = screen_buffer->win.top;
1435 reply->win_right = screen_buffer->win.right;
1436 reply->win_bottom = screen_buffer->win.bottom;
1437 reply->max_width = screen_buffer->max_width;
1438 reply->max_height = screen_buffer->max_height;
1439 release_object( screen_buffer );
1443 /* read data (chars & attrs) from a screen buffer */
1444 DECL_HANDLER(read_console_output)
1446 struct screen_buffer *screen_buffer;
1448 if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle,
1449 GENERIC_READ, &screen_buffer_ops )))
1451 read_console_output( screen_buffer, req->x, req->y, req->mode, req->wrap );
1452 reply->width = screen_buffer->width;
1453 reply->height = screen_buffer->height;
1454 release_object( screen_buffer );
1458 /* write data (char and/or attrs) to a screen buffer */
1459 DECL_HANDLER(write_console_output)
1461 struct screen_buffer *screen_buffer;
1463 if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle,
1464 GENERIC_WRITE, &screen_buffer_ops)))
1466 reply->written = write_console_output( screen_buffer, get_req_data_size(), get_req_data(),
1467 req->mode, req->x, req->y, req->wrap );
1468 reply->width = screen_buffer->width;
1469 reply->height = screen_buffer->height;
1470 release_object( screen_buffer );
1474 /* fill a screen buffer with constant data (chars and/or attributes) */
1475 DECL_HANDLER(fill_console_output)
1477 struct screen_buffer *screen_buffer;
1479 if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle,
1480 GENERIC_WRITE, &screen_buffer_ops)))
1482 reply->written = fill_console_output( screen_buffer, req->data, req->mode,
1483 req->x, req->y, req->count, req->wrap );
1484 release_object( screen_buffer );
1488 /* move a rect of data in a screen buffer */
1489 DECL_HANDLER(move_console_output)
1491 scroll_console_output( req->handle, req->x_src, req->y_src, req->x_dst, req->y_dst,
1492 req->w, req->h );
1495 /* sends a signal to a console (process, group...) */
1496 DECL_HANDLER(send_console_signal)
1498 process_id_t group;
1500 group = req->group_id ? req->group_id : current->process->group_id;
1502 if (!group)
1503 set_error( STATUS_INVALID_PARAMETER );
1504 else
1505 propagate_console_signal( current->process->console, req->signal, group );
1508 /* get console which renderer is 'current' */
1509 static int cgwe_enum( struct process* process, void* user)
1511 if (process->console && process->console->renderer == current)
1513 *(struct console_input**)user = process->console;
1514 return 1;
1516 return 0;
1519 DECL_HANDLER(get_console_wait_event)
1521 struct console_input* console = NULL;
1523 if (current->process->console && current->process->console->renderer)
1524 console = (struct console_input*)grab_object( (struct object*)current->process->console );
1525 else enum_processes(cgwe_enum, &console);
1527 if (console)
1529 reply->handle = alloc_handle( current->process, console->event,
1530 EVENT_ALL_ACCESS, FALSE);
1531 release_object( console );
1533 else set_error( STATUS_INVALID_PARAMETER );