crypt32: Implement CRLDistPoints encoding/decoding.
[wine/wine-gecko.git] / server / console.c
blob9cf606c3b6bcf4aaee972e70ef651ded728159fc
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 "ntstatus.h"
33 #define WIN32_NO_STATUS
34 #include "handle.h"
35 #include "process.h"
36 #include "request.h"
37 #include "unicode.h"
38 #include "console.h"
39 #include "winternl.h"
41 static void console_input_dump( struct object *obj, int verbose );
42 static void console_input_destroy( struct object *obj );
44 static const struct object_ops console_input_ops =
46 sizeof(struct console_input), /* size */
47 console_input_dump, /* dump */
48 no_add_queue, /* add_queue */
49 NULL, /* remove_queue */
50 NULL, /* signaled */
51 no_satisfied, /* satisfied */
52 no_signal, /* signal */
53 no_get_fd, /* get_fd */
54 no_map_access, /* map_access */
55 no_lookup_name, /* lookup_name */
56 no_close_handle, /* close_handle */
57 console_input_destroy /* destroy */
60 static void console_input_events_dump( struct object *obj, int verbose );
61 static void console_input_events_destroy( struct object *obj );
62 static int console_input_events_signaled( struct object *obj, struct thread *thread );
64 struct console_input_events
66 struct object obj; /* object header */
67 int num_alloc; /* number of allocated events */
68 int num_used; /* number of actually used events */
69 struct console_renderer_event* events;
72 static const struct object_ops console_input_events_ops =
74 sizeof(struct console_input_events), /* size */
75 console_input_events_dump, /* dump */
76 add_queue, /* add_queue */
77 remove_queue, /* remove_queue */
78 console_input_events_signaled, /* signaled */
79 no_satisfied, /* satisfied */
80 no_signal, /* signal */
81 no_get_fd, /* get_fd */
82 no_map_access, /* map_access */
83 no_lookup_name, /* lookup_name */
84 no_close_handle, /* close_handle */
85 console_input_events_destroy /* destroy */
88 struct screen_buffer
90 struct object obj; /* object header */
91 struct list entry; /* entry in list of all screen buffers */
92 struct console_input *input; /* associated console input */
93 int mode; /* output mode */
94 int cursor_size; /* size of cursor (percentage filled) */
95 int cursor_visible;/* cursor visibility flag */
96 int cursor_x; /* position of cursor */
97 int cursor_y; /* position of cursor */
98 int width; /* size (w-h) of the screen buffer */
99 int height;
100 int max_width; /* size (w-h) of the window given font size */
101 int max_height;
102 char_info_t *data; /* the data for each cell - a width x height matrix */
103 unsigned short attr; /* default attribute for screen buffer */
104 rectangle_t win; /* current visible window on the screen buffer *
105 * as seen in wineconsole */
108 static void screen_buffer_dump( struct object *obj, int verbose );
109 static void screen_buffer_destroy( struct object *obj );
111 static const struct object_ops screen_buffer_ops =
113 sizeof(struct screen_buffer), /* size */
114 screen_buffer_dump, /* dump */
115 no_add_queue, /* add_queue */
116 NULL, /* remove_queue */
117 NULL, /* signaled */
118 NULL, /* satisfied */
119 no_signal, /* signal */
120 no_get_fd, /* get_fd */
121 no_map_access, /* map_access */
122 no_lookup_name, /* lookup_name */
123 no_close_handle, /* close_handle */
124 screen_buffer_destroy /* destroy */
127 static struct list screen_buffer_list = LIST_INIT(screen_buffer_list);
129 static const char_info_t empty_char_info = { ' ', 0x000f }; /* white on black space */
131 /* dumps the renderer events of a console */
132 static void console_input_events_dump( struct object *obj, int verbose )
134 struct console_input_events *evts = (struct console_input_events *)obj;
135 assert( obj->ops == &console_input_events_ops );
136 fprintf( stderr, "Console input events: %d/%d events\n",
137 evts->num_used, evts->num_alloc );
140 /* destroys the renderer events of a console */
141 static void console_input_events_destroy( struct object *obj )
143 struct console_input_events *evts = (struct console_input_events *)obj;
144 assert( obj->ops == &console_input_events_ops );
145 free( evts->events );
148 /* the renderer events list is signaled when it's not empty */
149 static int console_input_events_signaled( struct object *obj, struct thread *thread )
151 struct console_input_events *evts = (struct console_input_events *)obj;
152 assert( obj->ops == &console_input_events_ops );
153 return (evts->num_used != 0);
156 /* add an event to the console's renderer events list */
157 static void console_input_events_append( struct console_input_events* evts,
158 struct console_renderer_event* evt)
160 int collapsed = FALSE;
162 /* to be done even when evt has been generated by the rendere ? */
164 /* try to collapse evt into current queue's events */
165 if (evts->num_used)
167 struct console_renderer_event* last = &evts->events[evts->num_used - 1];
169 if (last->event == CONSOLE_RENDERER_UPDATE_EVENT &&
170 evt->event == CONSOLE_RENDERER_UPDATE_EVENT)
172 /* if two update events overlap, collapse them into a single one */
173 if (last->u.update.bottom + 1 >= evt->u.update.top &&
174 evt->u.update.bottom + 1 >= last->u.update.top)
176 last->u.update.top = min(last->u.update.top, evt->u.update.top);
177 last->u.update.bottom = max(last->u.update.bottom, evt->u.update.bottom);
178 collapsed = TRUE;
182 if (!collapsed)
184 if (evts->num_used == evts->num_alloc)
186 evts->num_alloc += 16;
187 evts->events = realloc( evts->events, evts->num_alloc * sizeof(*evt) );
188 assert(evts->events);
190 evts->events[evts->num_used++] = *evt;
192 wake_up( &evts->obj, 0 );
195 /* retrieves events from the console's renderer events list */
196 static void console_input_events_get( struct console_input_events* evts )
198 size_t num = get_reply_max_size() / sizeof(evts->events[0]);
200 if (num > evts->num_used) num = evts->num_used;
201 set_reply_data( evts->events, num * sizeof(evts->events[0]) );
202 if (num < evts->num_used)
204 memmove( &evts->events[0], &evts->events[num],
205 (evts->num_used - num) * sizeof(evts->events[0]) );
207 evts->num_used -= num;
210 static struct console_input_events *create_console_input_events(void)
212 struct console_input_events* evt;
214 if (!(evt = alloc_object( &console_input_events_ops ))) return NULL;
215 evt->num_alloc = evt->num_used = 0;
216 evt->events = NULL;
217 return evt;
220 static struct object *create_console_input( struct thread* renderer )
222 struct console_input *console_input;
224 if (!(console_input = alloc_object( &console_input_ops ))) return NULL;
225 console_input->renderer = renderer;
226 console_input->mode = ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT |
227 ENABLE_ECHO_INPUT | ENABLE_MOUSE_INPUT;
228 console_input->num_proc = 0;
229 console_input->active = NULL;
230 console_input->recnum = 0;
231 console_input->records = NULL;
232 console_input->evt = create_console_input_events();
233 console_input->title = NULL;
234 console_input->history_size = 50;
235 console_input->history = calloc( console_input->history_size, sizeof(WCHAR*) );
236 console_input->history_index = 0;
237 console_input->history_mode = 0;
238 console_input->edition_mode = 0;
239 console_input->event = create_event( NULL, NULL, 0, 1, 0 );
241 if (!console_input->history || !console_input->evt)
243 release_object( console_input );
244 return NULL;
246 return &console_input->obj;
249 static struct screen_buffer *create_console_output( struct console_input *console_input )
251 struct screen_buffer *screen_buffer;
252 struct console_renderer_event evt;
253 int i;
255 if (!(screen_buffer = alloc_object( &screen_buffer_ops ))) return NULL;
256 screen_buffer->mode = ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT;
257 screen_buffer->input = console_input;
258 screen_buffer->cursor_size = 100;
259 screen_buffer->cursor_visible = 1;
260 screen_buffer->width = 80;
261 screen_buffer->height = 150;
262 screen_buffer->max_width = 80;
263 screen_buffer->max_height = 25;
264 screen_buffer->cursor_x = 0;
265 screen_buffer->cursor_y = 0;
266 screen_buffer->attr = 0x0F;
267 screen_buffer->win.left = 0;
268 screen_buffer->win.right = screen_buffer->max_width - 1;
269 screen_buffer->win.top = 0;
270 screen_buffer->win.bottom = screen_buffer->max_height - 1;
272 list_add_head( &screen_buffer_list, &screen_buffer->entry );
274 if (!(screen_buffer->data = malloc( screen_buffer->width * screen_buffer->height *
275 sizeof(*screen_buffer->data) )))
277 release_object( screen_buffer );
278 return NULL;
280 /* clear the first row */
281 for (i = 0; i < screen_buffer->width; i++) screen_buffer->data[i] = empty_char_info;
282 /* and copy it to all other rows */
283 for (i = 1; i < screen_buffer->height; i++)
284 memcpy( &screen_buffer->data[i * screen_buffer->width], screen_buffer->data,
285 screen_buffer->width * sizeof(char_info_t) );
287 if (!console_input->active)
289 console_input->active = (struct screen_buffer*)grab_object( screen_buffer );
291 /* generate the initial events */
292 evt.event = CONSOLE_RENDERER_ACTIVE_SB_EVENT;
293 console_input_events_append( console_input->evt, &evt );
295 evt.event = CONSOLE_RENDERER_SB_RESIZE_EVENT;
296 evt.u.resize.width = screen_buffer->width;
297 evt.u.resize.height = screen_buffer->height;
298 console_input_events_append( console_input->evt, &evt );
300 evt.event = CONSOLE_RENDERER_DISPLAY_EVENT;
301 evt.u.display.left = screen_buffer->win.left;
302 evt.u.display.top = screen_buffer->win.top;
303 evt.u.display.width = screen_buffer->win.right - screen_buffer->win.left + 1;
304 evt.u.display.height = screen_buffer->win.bottom - screen_buffer->win.top + 1;
305 console_input_events_append( console_input->evt, &evt );
307 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
308 evt.u.update.top = 0;
309 evt.u.update.bottom = screen_buffer->height - 1;
310 console_input_events_append( console_input->evt, &evt );
312 evt.event = CONSOLE_RENDERER_CURSOR_GEOM_EVENT;
313 evt.u.cursor_geom.size = screen_buffer->cursor_size;
314 evt.u.cursor_geom.visible = screen_buffer->cursor_visible;
315 console_input_events_append( console_input->evt, &evt );
317 evt.event = CONSOLE_RENDERER_CURSOR_POS_EVENT;
318 evt.u.cursor_pos.x = screen_buffer->cursor_x;
319 evt.u.cursor_pos.y = screen_buffer->cursor_y;
320 console_input_events_append( console_input->evt, &evt );
322 return screen_buffer;
325 /* free the console for this process */
326 int free_console( struct process *process )
328 struct console_input* console = process->console;
330 if (!console || !console->renderer) return 0;
332 process->console = NULL;
333 if (--console->num_proc == 0)
335 /* all processes have terminated... tell the renderer to terminate too */
336 struct console_renderer_event evt;
337 evt.event = CONSOLE_RENDERER_EXIT_EVENT;
338 console_input_events_append( console->evt, &evt );
340 release_object( console );
342 return 1;
345 /* let process inherit the console from parent... this handle two cases :
346 * 1/ generic console inheritance
347 * 2/ parent is a renderer which launches process, and process should attach to the console
348 * renderered by parent
350 void inherit_console(struct thread *parent_thread, struct process *process, obj_handle_t hconin)
352 int done = 0;
353 struct process* parent = parent_thread->process;
355 /* if parent is a renderer, then attach current process to its console
356 * a bit hacky....
358 if (hconin)
360 struct console_input* console;
362 /* FIXME: should we check some access rights ? */
363 if ((console = (struct console_input*)get_handle_obj( parent, hconin,
364 0, &console_input_ops )))
366 if (console->renderer == parent_thread)
368 process->console = (struct console_input*)grab_object( console );
369 process->console->num_proc++;
370 done = 1;
372 release_object( console );
374 else clear_error(); /* ignore error */
376 /* otherwise, if parent has a console, attach child to this console */
377 if (!done && parent->console)
379 assert(parent->console->renderer);
380 process->console = (struct console_input*)grab_object( parent->console );
381 process->console->num_proc++;
385 static struct console_input* console_input_get( obj_handle_t handle, unsigned access )
387 struct console_input* console = NULL;
389 if (handle)
390 console = (struct console_input *)get_handle_obj( current->process, handle,
391 access, &console_input_ops );
392 else if (current->process->console)
394 assert( current->process->console->renderer );
395 console = (struct console_input *)grab_object( current->process->console );
398 if (!console && !get_error()) set_error(STATUS_INVALID_PARAMETER);
399 return console;
402 struct console_signal_info
404 struct console_input *console;
405 process_id_t group;
406 int signal;
409 static int propagate_console_signal_cb(struct process *process, void *user)
411 struct console_signal_info* csi = (struct console_signal_info*)user;
413 if (process->console == csi->console && process->running_threads &&
414 (!csi->group || process->group_id == csi->group))
416 /* find a suitable thread to signal */
417 struct thread *thread;
418 LIST_FOR_EACH_ENTRY( thread, &process->thread_list, struct thread, proc_entry )
420 if (send_thread_signal( thread, csi->signal )) break;
423 return FALSE;
426 static void propagate_console_signal( struct console_input *console,
427 int sig, process_id_t group_id )
429 struct console_signal_info csi;
431 if (!console)
433 set_error( STATUS_INVALID_PARAMETER );
434 return;
436 /* FIXME: should support the other events (like CTRL_BREAK) */
437 if (sig != CTRL_C_EVENT)
439 set_error( STATUS_NOT_IMPLEMENTED );
440 return;
442 csi.console = console;
443 csi.signal = SIGINT;
444 csi.group = group_id;
446 enum_processes(propagate_console_signal_cb, &csi);
449 static int get_console_mode( obj_handle_t handle )
451 struct object *obj;
452 int ret = 0;
454 if ((obj = get_handle_obj( current->process, handle, GENERIC_READ, NULL )))
456 if (obj->ops == &console_input_ops)
457 ret = ((struct console_input *)obj)->mode;
458 else if (obj->ops == &screen_buffer_ops)
459 ret = ((struct screen_buffer *)obj)->mode;
460 else
461 set_error( STATUS_OBJECT_TYPE_MISMATCH );
462 release_object( obj );
464 return ret;
467 /* changes the mode of either a console input or a screen buffer */
468 static int set_console_mode( obj_handle_t handle, int mode )
470 struct object *obj;
471 int ret = 0;
473 if (!(obj = get_handle_obj( current->process, handle, GENERIC_WRITE, NULL )))
474 return 0;
475 if (obj->ops == &console_input_ops)
477 /* FIXME: if we remove the edit mode bits, we need (???) to clean up the history */
478 ((struct console_input *)obj)->mode = mode;
479 ret = 1;
481 else if (obj->ops == &screen_buffer_ops)
483 ((struct screen_buffer *)obj)->mode = mode;
484 ret = 1;
486 else set_error( STATUS_OBJECT_TYPE_MISMATCH );
487 release_object( obj );
488 return ret;
491 /* add input events to a console input queue */
492 static int write_console_input( struct console_input* console, int count,
493 const INPUT_RECORD *records )
495 INPUT_RECORD *new_rec;
497 if (!count) return 0;
498 if (!(new_rec = realloc( console->records,
499 (console->recnum + count) * sizeof(INPUT_RECORD) )))
501 set_error( STATUS_NO_MEMORY );
502 release_object( console );
503 return -1;
505 console->records = new_rec;
506 memcpy( new_rec + console->recnum, records, count * sizeof(INPUT_RECORD) );
508 if (console->mode & ENABLE_PROCESSED_INPUT)
510 int i = 0;
511 while (i < count)
513 if (records[i].EventType == KEY_EVENT &&
514 records[i].Event.KeyEvent.uChar.UnicodeChar == 'C' - 64 &&
515 !(records[i].Event.KeyEvent.dwControlKeyState & ENHANCED_KEY))
517 if (i != count - 1)
518 memcpy( &console->records[console->recnum + i],
519 &console->records[console->recnum + i + 1],
520 (count - i - 1) * sizeof(INPUT_RECORD) );
521 count--;
522 if (records[i].Event.KeyEvent.bKeyDown)
524 /* send SIGINT to all processes attached to this console */
525 propagate_console_signal( console, CTRL_C_EVENT, 0 );
528 else i++;
531 if (!console->recnum && count) set_event( console->event );
532 console->recnum += count;
533 return count;
536 /* retrieve a pointer to the console input records */
537 static int read_console_input( obj_handle_t handle, int count, int flush )
539 struct console_input *console;
541 if (!(console = (struct console_input *)get_handle_obj( current->process, handle,
542 GENERIC_READ, &console_input_ops )))
543 return -1;
545 if (!count)
547 /* special case: do not retrieve anything, but return
548 * the total number of records available */
549 count = console->recnum;
551 else
553 if (count > console->recnum) count = console->recnum;
554 set_reply_data( console->records, count * sizeof(INPUT_RECORD) );
556 if (flush)
558 int i;
559 for (i = count; i < console->recnum; i++)
560 console->records[i-count] = console->records[i];
561 if ((console->recnum -= count) > 0)
563 INPUT_RECORD *new_rec = realloc( console->records,
564 console->recnum * sizeof(INPUT_RECORD) );
565 if (new_rec) console->records = new_rec;
567 else
569 free( console->records );
570 console->records = NULL;
571 reset_event( console->event );
574 release_object( console );
575 return count;
578 /* set misc console input information */
579 static int set_console_input_info( const struct set_console_input_info_request *req,
580 const WCHAR *title, size_t len )
582 struct console_input *console;
583 struct console_renderer_event evt;
585 if (!(console = console_input_get( req->handle, GENERIC_WRITE ))) goto error;
587 if (req->mask & SET_CONSOLE_INPUT_INFO_ACTIVE_SB)
589 struct screen_buffer *screen_buffer;
591 screen_buffer = (struct screen_buffer *)get_handle_obj( current->process, req->active_sb,
592 GENERIC_READ, &screen_buffer_ops );
593 if (!screen_buffer || screen_buffer->input != console)
595 set_error( STATUS_INVALID_PARAMETER );
596 if (screen_buffer) release_object( screen_buffer );
597 goto error;
600 if (screen_buffer != console->active)
602 if (console->active) release_object( console->active );
603 console->active = screen_buffer;
604 evt.event = CONSOLE_RENDERER_ACTIVE_SB_EVENT;
605 console_input_events_append( console->evt, &evt );
607 else
608 release_object( screen_buffer );
610 if (req->mask & SET_CONSOLE_INPUT_INFO_TITLE)
612 WCHAR *new_title = mem_alloc( len + sizeof(WCHAR) );
613 if (new_title)
615 memcpy( new_title, title, len );
616 new_title[len / sizeof(WCHAR)] = 0;
617 if (console->title) free( console->title );
618 console->title = new_title;
619 evt.event = CONSOLE_RENDERER_TITLE_EVENT;
620 console_input_events_append( console->evt, &evt );
623 if (req->mask & SET_CONSOLE_INPUT_INFO_HISTORY_MODE)
625 console->history_mode = req->history_mode;
627 if ((req->mask & SET_CONSOLE_INPUT_INFO_HISTORY_SIZE) &&
628 console->history_size != req->history_size)
630 WCHAR** mem = NULL;
631 int i;
632 int delta;
634 if (req->history_size)
636 mem = mem_alloc( req->history_size * sizeof(WCHAR*) );
637 if (!mem) goto error;
638 memset( mem, 0, req->history_size * sizeof(WCHAR*) );
641 delta = (console->history_index > req->history_size) ?
642 (console->history_index - req->history_size) : 0;
644 for (i = delta; i < console->history_index; i++)
646 mem[i - delta] = console->history[i];
647 console->history[i] = NULL;
649 console->history_index -= delta;
651 for (i = 0; i < console->history_size; i++)
652 if (console->history[i]) free( console->history[i] );
653 free( console->history );
654 console->history = mem;
655 console->history_size = req->history_size;
657 if (req->mask & SET_CONSOLE_INPUT_INFO_EDITION_MODE)
659 console->edition_mode = req->edition_mode;
661 release_object( console );
662 return 1;
663 error:
664 if (console) release_object( console );
665 return 0;
668 /* resize a screen buffer */
669 static int change_screen_buffer_size( struct screen_buffer *screen_buffer,
670 int new_width, int new_height )
672 int i, old_width, old_height, copy_width, copy_height;
673 char_info_t *new_data;
675 if (!(new_data = malloc( new_width * new_height * sizeof(*new_data) )))
677 set_error( STATUS_NO_MEMORY );
678 return 0;
680 old_width = screen_buffer->width;
681 old_height = screen_buffer->height;
682 copy_width = min( old_width, new_width );
683 copy_height = min( old_height, new_height );
685 /* copy all the rows */
686 for (i = 0; i < copy_height; i++)
688 memcpy( &new_data[i * new_width], &screen_buffer->data[i * old_width],
689 copy_width * sizeof(char_info_t) );
692 /* clear the end of each row */
693 if (new_width > old_width)
695 /* fill first row */
696 for (i = old_width; i < new_width; i++) new_data[i] = empty_char_info;
697 /* and blast it to the other rows */
698 for (i = 1; i < copy_height; i++)
699 memcpy( &new_data[i * new_width + old_width], &new_data[old_width],
700 (new_width - old_width) * sizeof(char_info_t) );
703 /* clear remaining rows */
704 if (new_height > old_height)
706 /* fill first row */
707 for (i = 0; i < new_width; i++) new_data[old_height * new_width + i] = empty_char_info;
708 /* and blast it to the other rows */
709 for (i = old_height+1; i < new_height; i++)
710 memcpy( &new_data[i * new_width], &new_data[old_height * new_width],
711 new_width * sizeof(char_info_t) );
713 free( screen_buffer->data );
714 screen_buffer->data = new_data;
715 screen_buffer->width = new_width;
716 screen_buffer->height = new_height;
717 return 1;
720 /* set misc screen buffer information */
721 static int set_console_output_info( struct screen_buffer *screen_buffer,
722 const struct set_console_output_info_request *req )
724 struct console_renderer_event evt;
726 if (req->mask & SET_CONSOLE_OUTPUT_INFO_CURSOR_GEOM)
728 if (req->cursor_size < 1 || req->cursor_size > 100)
730 set_error( STATUS_INVALID_PARAMETER );
731 return 0;
733 if (screen_buffer->cursor_size != req->cursor_size ||
734 screen_buffer->cursor_visible != req->cursor_visible)
736 screen_buffer->cursor_size = req->cursor_size;
737 screen_buffer->cursor_visible = req->cursor_visible;
738 evt.event = CONSOLE_RENDERER_CURSOR_GEOM_EVENT;
739 evt.u.cursor_geom.size = req->cursor_size;
740 evt.u.cursor_geom.visible = req->cursor_visible;
741 console_input_events_append( screen_buffer->input->evt, &evt );
744 if (req->mask & SET_CONSOLE_OUTPUT_INFO_CURSOR_POS)
746 if (req->cursor_x < 0 || req->cursor_x >= screen_buffer->width ||
747 req->cursor_y < 0 || req->cursor_y >= screen_buffer->height)
749 set_error( STATUS_INVALID_PARAMETER );
750 return 0;
752 if (screen_buffer->cursor_x != req->cursor_x || screen_buffer->cursor_y != req->cursor_y)
754 screen_buffer->cursor_x = req->cursor_x;
755 screen_buffer->cursor_y = req->cursor_y;
756 evt.event = CONSOLE_RENDERER_CURSOR_POS_EVENT;
757 evt.u.cursor_pos.x = req->cursor_x;
758 evt.u.cursor_pos.y = req->cursor_y;
759 console_input_events_append( screen_buffer->input->evt, &evt );
762 if (req->mask & SET_CONSOLE_OUTPUT_INFO_SIZE)
764 unsigned cc;
766 /* new screen-buffer cannot be smaller than actual window */
767 if (req->width < screen_buffer->win.right - screen_buffer->win.left + 1 ||
768 req->height < screen_buffer->win.bottom - screen_buffer->win.top + 1)
770 set_error( STATUS_INVALID_PARAMETER );
771 return 0;
773 /* FIXME: there are also some basic minimum and max size to deal with */
774 if (!change_screen_buffer_size( screen_buffer, req->width, req->height )) return 0;
776 evt.event = CONSOLE_RENDERER_SB_RESIZE_EVENT;
777 evt.u.resize.width = req->width;
778 evt.u.resize.height = req->height;
779 console_input_events_append( screen_buffer->input->evt, &evt );
781 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
782 evt.u.update.top = 0;
783 evt.u.update.bottom = screen_buffer->height - 1;
784 console_input_events_append( screen_buffer->input->evt, &evt );
786 /* scroll window to display sb */
787 if (screen_buffer->win.right >= req->width)
789 screen_buffer->win.right -= screen_buffer->win.left;
790 screen_buffer->win.left = 0;
792 if (screen_buffer->win.bottom >= req->height)
794 screen_buffer->win.bottom -= screen_buffer->win.top;
795 screen_buffer->win.top = 0;
797 /* reset cursor if needed (normally, if cursor was outside of new sb, the
798 * window has been shifted so that the new position of the cursor will be
799 * visible */
800 cc = 0;
801 if (screen_buffer->cursor_x >= req->width)
803 screen_buffer->cursor_x = req->width - 1;
804 cc++;
806 if (screen_buffer->cursor_y >= req->height)
808 screen_buffer->cursor_y = req->height - 1;
809 cc++;
811 if (cc)
813 evt.event = CONSOLE_RENDERER_CURSOR_POS_EVENT;
814 evt.u.cursor_pos.x = req->cursor_x;
815 evt.u.cursor_pos.y = req->cursor_y;
816 console_input_events_append( screen_buffer->input->evt, &evt );
819 if (screen_buffer == screen_buffer->input->active &&
820 screen_buffer->input->mode & ENABLE_WINDOW_INPUT)
822 INPUT_RECORD ir;
823 ir.EventType = WINDOW_BUFFER_SIZE_EVENT;
824 ir.Event.WindowBufferSizeEvent.dwSize.X = req->width;
825 ir.Event.WindowBufferSizeEvent.dwSize.Y = req->height;
826 write_console_input( screen_buffer->input, 1, &ir );
829 if (req->mask & SET_CONSOLE_OUTPUT_INFO_ATTR)
831 screen_buffer->attr = req->attr;
833 if (req->mask & SET_CONSOLE_OUTPUT_INFO_DISPLAY_WINDOW)
835 if (req->win_left < 0 || req->win_left > req->win_right ||
836 req->win_right >= screen_buffer->width ||
837 req->win_top < 0 || req->win_top > req->win_bottom ||
838 req->win_bottom >= screen_buffer->height)
840 set_error( STATUS_INVALID_PARAMETER );
841 return 0;
843 if (screen_buffer->win.left != req->win_left || screen_buffer->win.top != req->win_top ||
844 screen_buffer->win.right != req->win_right || screen_buffer->win.bottom != req->win_bottom)
846 screen_buffer->win.left = req->win_left;
847 screen_buffer->win.top = req->win_top;
848 screen_buffer->win.right = req->win_right;
849 screen_buffer->win.bottom = req->win_bottom;
850 evt.event = CONSOLE_RENDERER_DISPLAY_EVENT;
851 evt.u.display.left = req->win_left;
852 evt.u.display.top = req->win_top;
853 evt.u.display.width = req->win_right - req->win_left + 1;
854 evt.u.display.height = req->win_bottom - req->win_top + 1;
855 console_input_events_append( screen_buffer->input->evt, &evt );
858 if (req->mask & SET_CONSOLE_OUTPUT_INFO_MAX_SIZE)
860 /* can only be done by renderer */
861 if (current->process->console != screen_buffer->input)
863 set_error( STATUS_INVALID_PARAMETER );
864 return 0;
867 screen_buffer->max_width = req->max_width;
868 screen_buffer->max_height = req->max_height;
871 return 1;
874 /* appends a new line to history (history is a fixed size array) */
875 static void console_input_append_hist( struct console_input* console, const WCHAR* buf, size_t len )
877 WCHAR* ptr = mem_alloc( (len + 1) * sizeof(WCHAR) );
879 if (!ptr)
881 set_error( STATUS_NO_MEMORY );
882 return;
884 if (!console || !console->history_size)
886 set_error( STATUS_INVALID_PARAMETER ); /* FIXME */
887 return;
890 memcpy( ptr, buf, len * sizeof(WCHAR) );
891 ptr[len] = 0;
893 if (console->history_mode && console->history_index &&
894 strncmpW( console->history[console->history_index - 1], ptr, len * sizeof(WCHAR) ) == 0)
896 /* ok, mode ask us to not use twice the same string...
897 * so just free mem and returns
899 set_error( STATUS_ALIAS_EXISTS );
900 free(ptr);
901 return;
904 if (console->history_index < console->history_size)
906 console->history[console->history_index++] = ptr;
908 else
910 free( console->history[0]) ;
911 memmove( &console->history[0], &console->history[1],
912 (console->history_size - 1) * sizeof(WCHAR*) );
913 console->history[console->history_size - 1] = ptr;
917 /* returns a line from the cache */
918 static size_t console_input_get_hist( struct console_input *console, int index )
920 size_t ret = 0;
922 if (index >= console->history_index) set_error( STATUS_INVALID_PARAMETER );
923 else
925 ret = strlenW( console->history[index] ) * sizeof(WCHAR);
926 set_reply_data( console->history[index], min( ret, get_reply_max_size() ));
928 return ret;
931 /* dumb dump */
932 static void console_input_dump( struct object *obj, int verbose )
934 struct console_input *console = (struct console_input *)obj;
935 assert( obj->ops == &console_input_ops );
936 fprintf( stderr, "Console input active=%p evt=%p\n",
937 console->active, console->evt );
940 static void console_input_destroy( struct object *obj )
942 struct console_input* console_in = (struct console_input *)obj;
943 struct screen_buffer* curr;
944 int i;
946 assert( obj->ops == &console_input_ops );
947 if (console_in->title) free( console_in->title );
948 if (console_in->records) free( console_in->records );
950 if (console_in->active) release_object( console_in->active );
951 console_in->active = NULL;
953 LIST_FOR_EACH_ENTRY( curr, &screen_buffer_list, struct screen_buffer, entry )
955 if (curr->input == console_in) curr->input = NULL;
958 release_object( console_in->evt );
959 console_in->evt = NULL;
960 release_object( console_in->event );
962 for (i = 0; i < console_in->history_size; i++)
963 if (console_in->history[i]) free( console_in->history[i] );
964 if (console_in->history) free( console_in->history );
967 static void screen_buffer_dump( struct object *obj, int verbose )
969 struct screen_buffer *screen_buffer = (struct screen_buffer *)obj;
970 assert( obj->ops == &screen_buffer_ops );
972 fprintf(stderr, "Console screen buffer input=%p\n", screen_buffer->input );
975 static void screen_buffer_destroy( struct object *obj )
977 struct screen_buffer *screen_buffer = (struct screen_buffer *)obj;
979 assert( obj->ops == &screen_buffer_ops );
981 list_remove( &screen_buffer->entry );
983 if (screen_buffer->input && screen_buffer->input->active == screen_buffer)
985 struct screen_buffer *sb;
987 screen_buffer->input->active = NULL;
988 LIST_FOR_EACH_ENTRY( sb, &screen_buffer_list, struct screen_buffer, entry )
990 if (sb->input == screen_buffer->input)
992 sb->input->active = sb;
993 break;
997 if (screen_buffer->data) free( screen_buffer->data );
1000 /* write data into a screen buffer */
1001 static int write_console_output( struct screen_buffer *screen_buffer, size_t size,
1002 const void* data, enum char_info_mode mode,
1003 int x, int y, int wrap )
1005 int i;
1006 char_info_t *end, *dest = screen_buffer->data + y * screen_buffer->width + x;
1008 if (y >= screen_buffer->height) return 0;
1010 if (wrap)
1011 end = screen_buffer->data + screen_buffer->height * screen_buffer->width;
1012 else
1013 end = screen_buffer->data + (y+1) * screen_buffer->width;
1015 switch(mode)
1017 case CHAR_INFO_MODE_TEXT:
1019 const WCHAR *ptr = data;
1020 for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++) dest->ch = ptr[i];
1022 break;
1023 case CHAR_INFO_MODE_ATTR:
1025 const unsigned short *ptr = data;
1026 for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++) dest->attr = ptr[i];
1028 break;
1029 case CHAR_INFO_MODE_TEXTATTR:
1031 const char_info_t *ptr = data;
1032 for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++) *dest = ptr[i];
1034 break;
1035 case CHAR_INFO_MODE_TEXTSTDATTR:
1037 const WCHAR *ptr = data;
1038 for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++)
1040 dest->ch = ptr[i];
1041 dest->attr = screen_buffer->attr;
1044 break;
1045 default:
1046 set_error( STATUS_INVALID_PARAMETER );
1047 return 0;
1050 if (i && screen_buffer == screen_buffer->input->active)
1052 struct console_renderer_event evt;
1053 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
1054 evt.u.update.top = y + x / screen_buffer->width;
1055 evt.u.update.bottom = y + (x + i - 1) / screen_buffer->width;
1056 console_input_events_append( screen_buffer->input->evt, &evt );
1058 return i;
1061 /* fill a screen buffer with uniform data */
1062 static int fill_console_output( struct screen_buffer *screen_buffer, char_info_t data,
1063 enum char_info_mode mode, int x, int y, int count, int wrap )
1065 int i;
1066 char_info_t *end, *dest = screen_buffer->data + y * screen_buffer->width + x;
1068 if (y >= screen_buffer->height) return 0;
1070 if (wrap)
1071 end = screen_buffer->data + screen_buffer->height * screen_buffer->width;
1072 else
1073 end = screen_buffer->data + (y+1) * screen_buffer->width;
1075 if (count > end - dest) count = end - dest;
1077 switch(mode)
1079 case CHAR_INFO_MODE_TEXT:
1080 for (i = 0; i < count; i++) dest[i].ch = data.ch;
1081 break;
1082 case CHAR_INFO_MODE_ATTR:
1083 for (i = 0; i < count; i++) dest[i].attr = data.attr;
1084 break;
1085 case CHAR_INFO_MODE_TEXTATTR:
1086 for (i = 0; i < count; i++) dest[i] = data;
1087 break;
1088 case CHAR_INFO_MODE_TEXTSTDATTR:
1089 for (i = 0; i < count; i++)
1091 dest[i].ch = data.ch;
1092 dest[i].attr = screen_buffer->attr;
1094 break;
1095 default:
1096 set_error( STATUS_INVALID_PARAMETER );
1097 return 0;
1100 if (count && screen_buffer == screen_buffer->input->active)
1102 struct console_renderer_event evt;
1103 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
1104 evt.u.update.top = y;
1105 evt.u.update.bottom = (y * screen_buffer->width + x + count - 1) / screen_buffer->width;
1106 console_input_events_append( screen_buffer->input->evt, &evt );
1108 return i;
1111 /* read data from a screen buffer */
1112 static void read_console_output( struct screen_buffer *screen_buffer, int x, int y,
1113 enum char_info_mode mode, int wrap )
1115 int i;
1116 char_info_t *end, *src = screen_buffer->data + y * screen_buffer->width + x;
1118 if (y >= screen_buffer->height) return;
1120 if (wrap)
1121 end = screen_buffer->data + screen_buffer->height * screen_buffer->width;
1122 else
1123 end = screen_buffer->data + (y+1) * screen_buffer->width;
1125 switch(mode)
1127 case CHAR_INFO_MODE_TEXT:
1129 WCHAR *data;
1130 int count = min( end - src, get_reply_max_size() / sizeof(*data) );
1131 if ((data = set_reply_data_size( count * sizeof(*data) )))
1133 for (i = 0; i < count; i++) data[i] = src[i].ch;
1136 break;
1137 case CHAR_INFO_MODE_ATTR:
1139 unsigned short *data;
1140 int count = min( end - src, get_reply_max_size() / sizeof(*data) );
1141 if ((data = set_reply_data_size( count * sizeof(*data) )))
1143 for (i = 0; i < count; i++) data[i] = src[i].attr;
1146 break;
1147 case CHAR_INFO_MODE_TEXTATTR:
1149 char_info_t *data;
1150 int count = min( end - src, get_reply_max_size() / sizeof(*data) );
1151 if ((data = set_reply_data_size( count * sizeof(*data) )))
1153 for (i = 0; i < count; i++) data[i] = src[i];
1156 break;
1157 default:
1158 set_error( STATUS_INVALID_PARAMETER );
1159 break;
1163 /* scroll parts of a screen buffer */
1164 static void scroll_console_output( obj_handle_t handle, int xsrc, int ysrc, int xdst, int ydst,
1165 int w, int h )
1167 struct screen_buffer *screen_buffer;
1168 int j;
1169 char_info_t *psrc, *pdst;
1170 struct console_renderer_event evt;
1172 if (!(screen_buffer = (struct screen_buffer *)get_handle_obj( current->process, handle,
1173 GENERIC_READ, &screen_buffer_ops )))
1174 return;
1175 if (xsrc < 0 || ysrc < 0 || xdst < 0 || ydst < 0 ||
1176 xsrc + w > screen_buffer->width ||
1177 xdst + w > screen_buffer->width ||
1178 ysrc + h > screen_buffer->height ||
1179 ydst + h > screen_buffer->height ||
1180 w == 0 || h == 0)
1182 set_error( STATUS_INVALID_PARAMETER );
1183 release_object( screen_buffer );
1184 return;
1187 if (ysrc < ydst)
1189 psrc = &screen_buffer->data[(ysrc + h - 1) * screen_buffer->width + xsrc];
1190 pdst = &screen_buffer->data[(ydst + h - 1) * screen_buffer->width + xdst];
1192 for (j = h; j > 0; j--)
1194 memcpy(pdst, psrc, w * sizeof(*pdst) );
1195 pdst -= screen_buffer->width;
1196 psrc -= screen_buffer->width;
1199 else
1201 psrc = &screen_buffer->data[ysrc * screen_buffer->width + xsrc];
1202 pdst = &screen_buffer->data[ydst * screen_buffer->width + xdst];
1204 for (j = 0; j < h; j++)
1206 /* we use memmove here because when psrc and pdst are the same,
1207 * copies are done on the same row, so the dst and src blocks
1208 * can overlap */
1209 memmove( pdst, psrc, w * sizeof(*pdst) );
1210 pdst += screen_buffer->width;
1211 psrc += screen_buffer->width;
1215 /* FIXME: this could be enhanced, by signalling scroll */
1216 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
1217 evt.u.update.top = min(ysrc, ydst);
1218 evt.u.update.bottom = max(ysrc, ydst) + h - 1;
1219 console_input_events_append( screen_buffer->input->evt, &evt );
1221 release_object( screen_buffer );
1224 /* allocate a console for the renderer */
1225 DECL_HANDLER(alloc_console)
1227 obj_handle_t in = 0;
1228 obj_handle_t evt = 0;
1229 struct process *process;
1230 struct process *renderer = current->process;
1231 struct console_input *console;
1233 process = (req->pid) ? get_process_from_id( req->pid ) :
1234 (struct process *)grab_object( renderer->parent );
1236 reply->handle_in = 0;
1237 reply->event = 0;
1238 if (!process) return;
1239 if (process != renderer && process->console)
1241 set_error( STATUS_ACCESS_DENIED );
1242 goto the_end;
1244 if ((console = (struct console_input*)create_console_input( current )))
1246 if ((in = alloc_handle( renderer, console, req->access, req->attributes )))
1248 if ((evt = alloc_handle( renderer, console->evt, SYNCHRONIZE|GENERIC_READ|GENERIC_WRITE, 0 )))
1250 if (process != renderer)
1252 process->console = (struct console_input*)grab_object( console );
1253 console->num_proc++;
1255 reply->handle_in = in;
1256 reply->event = evt;
1257 release_object( console );
1258 goto the_end;
1260 close_handle( renderer, in, NULL );
1262 free_console( process );
1264 the_end:
1265 release_object( process );
1268 /* free the console of the current process */
1269 DECL_HANDLER(free_console)
1271 free_console( current->process );
1274 /* let the renderer peek the events it's waiting on */
1275 DECL_HANDLER(get_console_renderer_events)
1277 struct console_input_events *evt;
1279 evt = (struct console_input_events *)get_handle_obj( current->process, req->handle,
1280 GENERIC_WRITE, &console_input_events_ops );
1281 if (!evt) return;
1282 console_input_events_get( evt );
1283 release_object( evt );
1286 /* open a handle to the process console */
1287 DECL_HANDLER(open_console)
1289 struct object *obj = NULL;
1291 reply->handle = 0;
1292 switch (req->from)
1294 case 0:
1295 if (current->process->console && current->process->console->renderer)
1296 obj = grab_object( (struct object*)current->process->console );
1297 break;
1298 case 1:
1299 if (current->process->console && current->process->console->renderer &&
1300 current->process->console->active)
1301 obj = grab_object( (struct object*)current->process->console->active );
1302 break;
1303 default:
1304 if ((obj = get_handle_obj( current->process, (obj_handle_t)req->from,
1305 GENERIC_READ|GENERIC_WRITE, &console_input_ops )))
1307 struct console_input* console = (struct console_input*)obj;
1308 obj = (console->active) ? grab_object( console->active ) : NULL;
1309 release_object( console );
1311 break;
1314 /* FIXME: req->share is not used (as in screen buffer creation) */
1315 if (obj)
1317 reply->handle = alloc_handle( current->process, obj, req->access, req->attributes );
1318 release_object( obj );
1320 else if (!get_error()) set_error( STATUS_ACCESS_DENIED );
1323 /* set info about a console input */
1324 DECL_HANDLER(set_console_input_info)
1326 set_console_input_info( req, get_req_data(), get_req_data_size() );
1329 /* get info about a console (output only) */
1330 DECL_HANDLER(get_console_input_info)
1332 struct console_input *console;
1334 if (!(console = console_input_get( req->handle, GENERIC_READ ))) return;
1335 if (console->title)
1337 size_t len = strlenW( console->title ) * sizeof(WCHAR);
1338 if (len > get_reply_max_size()) len = get_reply_max_size();
1339 set_reply_data( console->title, len );
1341 reply->history_mode = console->history_mode;
1342 reply->history_size = console->history_size;
1343 reply->history_index = console->history_index;
1344 reply->edition_mode = console->edition_mode;
1346 release_object( console );
1349 /* get a console mode (input or output) */
1350 DECL_HANDLER(get_console_mode)
1352 reply->mode = get_console_mode( req->handle );
1355 /* set a console mode (input or output) */
1356 DECL_HANDLER(set_console_mode)
1358 set_console_mode( req->handle, req->mode );
1361 /* add input records to a console input queue */
1362 DECL_HANDLER(write_console_input)
1364 struct console_input *console;
1366 reply->written = 0;
1367 if (!(console = (struct console_input *)get_handle_obj( current->process, req->handle,
1368 GENERIC_WRITE, &console_input_ops )))
1369 return;
1370 reply->written = write_console_input( console, get_req_data_size() / sizeof(INPUT_RECORD),
1371 get_req_data() );
1372 release_object( console );
1375 /* fetch input records from a console input queue */
1376 DECL_HANDLER(read_console_input)
1378 int count = get_reply_max_size() / sizeof(INPUT_RECORD);
1379 reply->read = read_console_input( req->handle, count, req->flush );
1382 /* appends a string to console's history */
1383 DECL_HANDLER(append_console_input_history)
1385 struct console_input *console;
1387 if (!(console = console_input_get( req->handle, GENERIC_WRITE ))) return;
1388 console_input_append_hist( console, get_req_data(), get_req_data_size() / sizeof(WCHAR) );
1389 release_object( console );
1392 /* appends a string to console's history */
1393 DECL_HANDLER(get_console_input_history)
1395 struct console_input *console;
1397 if (!(console = console_input_get( req->handle, GENERIC_WRITE ))) return;
1398 reply->total = console_input_get_hist( console, req->index );
1399 release_object( console );
1402 /* creates a screen buffer */
1403 DECL_HANDLER(create_console_output)
1405 struct console_input* console;
1406 struct screen_buffer* screen_buffer;
1408 if (!(console = console_input_get( req->handle_in, GENERIC_WRITE))) return;
1410 screen_buffer = create_console_output( console );
1411 if (screen_buffer)
1413 /* FIXME: should store sharing and test it when opening the CONOUT$ device
1414 * see file.c on how this could be done */
1415 reply->handle_out = alloc_handle( current->process, screen_buffer, req->access, req->attributes );
1416 release_object( screen_buffer );
1418 release_object( console );
1421 /* set info about a console screen buffer */
1422 DECL_HANDLER(set_console_output_info)
1424 struct screen_buffer *screen_buffer;
1426 if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle,
1427 GENERIC_WRITE, &screen_buffer_ops)))
1429 set_console_output_info( screen_buffer, req );
1430 release_object( screen_buffer );
1434 /* get info about a console screen buffer */
1435 DECL_HANDLER(get_console_output_info)
1437 struct screen_buffer *screen_buffer;
1439 if ((screen_buffer = (struct screen_buffer *)get_handle_obj( current->process, req->handle,
1440 GENERIC_READ, &screen_buffer_ops)))
1442 reply->cursor_size = screen_buffer->cursor_size;
1443 reply->cursor_visible = screen_buffer->cursor_visible;
1444 reply->cursor_x = screen_buffer->cursor_x;
1445 reply->cursor_y = screen_buffer->cursor_y;
1446 reply->width = screen_buffer->width;
1447 reply->height = screen_buffer->height;
1448 reply->attr = screen_buffer->attr;
1449 reply->win_left = screen_buffer->win.left;
1450 reply->win_top = screen_buffer->win.top;
1451 reply->win_right = screen_buffer->win.right;
1452 reply->win_bottom = screen_buffer->win.bottom;
1453 reply->max_width = screen_buffer->max_width;
1454 reply->max_height = screen_buffer->max_height;
1455 release_object( screen_buffer );
1459 /* read data (chars & attrs) from a screen buffer */
1460 DECL_HANDLER(read_console_output)
1462 struct screen_buffer *screen_buffer;
1464 if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle,
1465 GENERIC_READ, &screen_buffer_ops )))
1467 read_console_output( screen_buffer, req->x, req->y, req->mode, req->wrap );
1468 reply->width = screen_buffer->width;
1469 reply->height = screen_buffer->height;
1470 release_object( screen_buffer );
1474 /* write data (char and/or attrs) to a screen buffer */
1475 DECL_HANDLER(write_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 = write_console_output( screen_buffer, get_req_data_size(), get_req_data(),
1483 req->mode, req->x, req->y, req->wrap );
1484 reply->width = screen_buffer->width;
1485 reply->height = screen_buffer->height;
1486 release_object( screen_buffer );
1490 /* fill a screen buffer with constant data (chars and/or attributes) */
1491 DECL_HANDLER(fill_console_output)
1493 struct screen_buffer *screen_buffer;
1495 if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle,
1496 GENERIC_WRITE, &screen_buffer_ops)))
1498 reply->written = fill_console_output( screen_buffer, req->data, req->mode,
1499 req->x, req->y, req->count, req->wrap );
1500 release_object( screen_buffer );
1504 /* move a rect of data in a screen buffer */
1505 DECL_HANDLER(move_console_output)
1507 scroll_console_output( req->handle, req->x_src, req->y_src, req->x_dst, req->y_dst,
1508 req->w, req->h );
1511 /* sends a signal to a console (process, group...) */
1512 DECL_HANDLER(send_console_signal)
1514 process_id_t group;
1516 group = req->group_id ? req->group_id : current->process->group_id;
1518 if (!group)
1519 set_error( STATUS_INVALID_PARAMETER );
1520 else
1521 propagate_console_signal( current->process->console, req->signal, group );
1524 /* get console which renderer is 'current' */
1525 static int cgwe_enum( struct process* process, void* user)
1527 if (process->console && process->console->renderer == current)
1529 *(struct console_input**)user = process->console;
1530 return 1;
1532 return 0;
1535 DECL_HANDLER(get_console_wait_event)
1537 struct console_input* console = NULL;
1539 if (current->process->console && current->process->console->renderer)
1540 console = (struct console_input*)grab_object( (struct object*)current->process->console );
1541 else enum_processes(cgwe_enum, &console);
1543 if (console)
1545 reply->handle = alloc_handle( current->process, console->event, EVENT_ALL_ACCESS, 0 );
1546 release_object( console );
1548 else set_error( STATUS_INVALID_PARAMETER );