2 * Server-side console management
4 * Copyright (C) 1998 Alexandre Julliard
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #include "wine/port.h"
36 #define WIN32_NO_STATUS
46 struct console_input_events;
50 struct object obj; /* object header */
51 int num_proc; /* number of processes attached to this console */
52 struct thread *renderer; /* console renderer thread */
53 int mode; /* input mode */
54 struct screen_buffer *active; /* active screen buffer */
55 int recnum; /* number of input records */
56 INPUT_RECORD *records; /* input records */
57 struct console_input_events *evt; /* synchronization event with renderer */
58 WCHAR *title; /* console title */
59 WCHAR **history; /* lines history */
60 int history_size; /* number of entries in history array */
61 int history_index; /* number of used entries in history array */
62 int history_mode; /* mode of history (non zero means remove doubled strings */
63 int edition_mode; /* index to edition mode flavors */
64 int input_cp; /* console input codepage */
65 int output_cp; /* console output codepage */
66 user_handle_t win; /* window handle if backend supports it */
67 struct event *event; /* event to wait on for input queue */
68 struct fd *fd; /* for bare console, attached input fd */
69 struct termios termios; /* for bare console, saved termio info */
72 static void console_input_dump( struct object *obj, int verbose );
73 static void console_input_destroy( struct object *obj );
74 static struct fd *console_input_get_fd( struct object *obj );
76 static const struct object_ops console_input_ops =
78 sizeof(struct console_input), /* size */
79 console_input_dump, /* dump */
80 no_get_type, /* get_type */
81 no_add_queue, /* add_queue */
82 NULL, /* remove_queue */
84 no_satisfied, /* satisfied */
85 no_signal, /* signal */
86 console_input_get_fd, /* get_fd */
87 default_fd_map_access, /* map_access */
88 default_get_sd, /* get_sd */
89 default_set_sd, /* set_sd */
90 no_lookup_name, /* lookup_name */
91 no_open_file, /* open_file */
92 no_close_handle, /* close_handle */
93 console_input_destroy /* destroy */
96 static void console_input_events_dump( struct object *obj, int verbose );
97 static void console_input_events_destroy( struct object *obj );
98 static int console_input_events_signaled( struct object *obj, struct thread *thread );
100 struct console_input_events
102 struct object obj; /* object header */
103 int num_alloc; /* number of allocated events */
104 int num_used; /* number of actually used events */
105 struct console_renderer_event* events;
108 static const struct object_ops console_input_events_ops =
110 sizeof(struct console_input_events), /* size */
111 console_input_events_dump, /* dump */
112 no_get_type, /* get_type */
113 add_queue, /* add_queue */
114 remove_queue, /* remove_queue */
115 console_input_events_signaled, /* signaled */
116 no_satisfied, /* satisfied */
117 no_signal, /* signal */
118 no_get_fd, /* get_fd */
119 default_fd_map_access, /* map_access */
120 default_get_sd, /* get_sd */
121 default_set_sd, /* set_sd */
122 no_lookup_name, /* lookup_name */
123 no_open_file, /* open_file */
124 no_close_handle, /* close_handle */
125 console_input_events_destroy /* destroy */
130 struct object obj; /* object header */
131 struct list entry; /* entry in list of all screen buffers */
132 struct console_input *input; /* associated console input */
133 int mode; /* output mode */
134 int cursor_size; /* size of cursor (percentage filled) */
135 int cursor_visible;/* cursor visibility flag */
136 int cursor_x; /* position of cursor */
137 int cursor_y; /* position of cursor */
138 int width; /* size (w-h) of the screen buffer */
140 int max_width; /* size (w-h) of the window given font size */
142 char_info_t *data; /* the data for each cell - a width x height matrix */
143 unsigned short attr; /* default attribute for screen buffer */
144 rectangle_t win; /* current visible window on the screen buffer *
145 * as seen in wineconsole */
148 static void screen_buffer_dump( struct object *obj, int verbose );
149 static void screen_buffer_destroy( struct object *obj );
151 static const struct object_ops screen_buffer_ops =
153 sizeof(struct screen_buffer), /* size */
154 screen_buffer_dump, /* dump */
155 no_get_type, /* get_type */
156 no_add_queue, /* add_queue */
157 NULL, /* remove_queue */
159 NULL, /* satisfied */
160 no_signal, /* signal */
161 no_get_fd, /* get_fd */
162 default_fd_map_access, /* map_access */
163 default_get_sd, /* get_sd */
164 default_set_sd, /* set_sd */
165 no_lookup_name, /* lookup_name */
166 no_open_file, /* open_file */
167 no_close_handle, /* close_handle */
168 screen_buffer_destroy /* destroy */
171 static enum server_fd_type console_get_fd_type( struct fd *fd );
173 static const struct fd_ops console_fd_ops =
175 default_fd_get_poll_events, /* get_poll_events */
176 default_poll_event, /* poll_event */
177 no_flush, /* flush */
178 console_get_fd_type, /* get_fd_type */
179 default_fd_ioctl, /* ioctl */
180 default_fd_queue_async, /* queue_async */
181 default_fd_reselect_async, /* reselect_async */
182 default_fd_cancel_async /* cancel_async */
185 static struct list screen_buffer_list = LIST_INIT(screen_buffer_list);
187 static const char_info_t empty_char_info = { ' ', 0x000f }; /* white on black space */
189 static struct fd *console_input_get_fd( struct object* obj )
191 struct console_input *console_input = (struct console_input*)obj;
192 assert( obj->ops == &console_input_ops );
193 return console_input->fd ? (struct fd*)grab_object( console_input->fd ) : NULL;
196 static enum server_fd_type console_get_fd_type( struct fd *fd )
201 /* dumps the renderer events of a console */
202 static void console_input_events_dump( struct object *obj, int verbose )
204 struct console_input_events *evts = (struct console_input_events *)obj;
205 assert( obj->ops == &console_input_events_ops );
206 fprintf( stderr, "Console input events: %d/%d events\n",
207 evts->num_used, evts->num_alloc );
210 /* destroys the renderer events of a console */
211 static void console_input_events_destroy( struct object *obj )
213 struct console_input_events *evts = (struct console_input_events *)obj;
214 assert( obj->ops == &console_input_events_ops );
215 free( evts->events );
218 /* the renderer events list is signaled when it's not empty */
219 static int console_input_events_signaled( struct object *obj, struct thread *thread )
221 struct console_input_events *evts = (struct console_input_events *)obj;
222 assert( obj->ops == &console_input_events_ops );
223 return (evts->num_used != 0);
226 /* add an event to the console's renderer events list */
227 static void console_input_events_append( struct console_input_events* evts,
228 struct console_renderer_event* evt)
230 int collapsed = FALSE;
233 /* to be done even when evt has been generated by the renderer ? */
235 /* try to collapse evt into current queue's events */
238 struct console_renderer_event* last = &evts->events[evts->num_used - 1];
240 if (last->event == CONSOLE_RENDERER_UPDATE_EVENT &&
241 evt->event == CONSOLE_RENDERER_UPDATE_EVENT)
243 /* if two update events overlap, collapse them into a single one */
244 if (last->u.update.bottom + 1 >= evt->u.update.top &&
245 evt->u.update.bottom + 1 >= last->u.update.top)
247 last->u.update.top = min(last->u.update.top, evt->u.update.top);
248 last->u.update.bottom = max(last->u.update.bottom, evt->u.update.bottom);
255 if (evts->num_used == evts->num_alloc)
257 evts->num_alloc += 16;
258 evts->events = realloc( evts->events, evts->num_alloc * sizeof(*evt) );
259 assert(evts->events);
261 evts->events[evts->num_used++] = *evt;
263 wake_up( &evts->obj, 0 );
266 /* retrieves events from the console's renderer events list */
267 static void console_input_events_get( struct console_input_events* evts )
269 data_size_t num = get_reply_max_size() / sizeof(evts->events[0]);
271 if (num > evts->num_used) num = evts->num_used;
272 set_reply_data( evts->events, num * sizeof(evts->events[0]) );
273 if (num < evts->num_used)
275 memmove( &evts->events[0], &evts->events[num],
276 (evts->num_used - num) * sizeof(evts->events[0]) );
278 evts->num_used -= num;
281 static struct console_input_events *create_console_input_events(void)
283 struct console_input_events* evt;
285 if (!(evt = alloc_object( &console_input_events_ops ))) return NULL;
286 evt->num_alloc = evt->num_used = 0;
291 static struct object *create_console_input( struct thread* renderer, int fd )
293 struct console_input *console_input;
295 if (!(console_input = alloc_object( &console_input_ops ))) return NULL;
296 console_input->renderer = renderer;
297 console_input->mode = ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT |
298 ENABLE_ECHO_INPUT | ENABLE_MOUSE_INPUT;
299 console_input->num_proc = 0;
300 console_input->active = NULL;
301 console_input->recnum = 0;
302 console_input->records = NULL;
303 console_input->evt = renderer ? create_console_input_events() : NULL;
304 console_input->title = NULL;
305 console_input->history_size = 50;
306 console_input->history = calloc( console_input->history_size, sizeof(WCHAR*) );
307 console_input->history_index = 0;
308 console_input->history_mode = 0;
309 console_input->edition_mode = 0;
310 console_input->input_cp = 0;
311 console_input->output_cp = 0;
312 console_input->win = 0;
313 console_input->event = create_event( NULL, NULL, 0, 1, 0, NULL );
314 console_input->fd = NULL;
316 if (!console_input->history || (renderer && !console_input->evt) || !console_input->event)
318 release_object( console_input );
321 if (fd != -1) /* bare console */
325 if (!(console_input->fd = create_anonymous_fd( &console_fd_ops, fd, &console_input->obj,
326 FILE_SYNCHRONOUS_IO_NONALERT )))
328 release_object( console_input );
331 if (tcgetattr(fd, &term) < 0)
333 release_object( console_input );
334 set_error( STATUS_INVALID_HANDLE );
337 console_input->termios = term;
338 term.c_lflag &= ~(ECHO | ECHONL | ICANON | IEXTEN);
339 term.c_iflag &= ~(BRKINT | ICRNL | INPCK | ISTRIP | IXON);
340 term.c_cflag &= ~(CSIZE | PARENB);
342 /* FIXME: we should actually disable output processing here
343 * and let kernel32/console.c do the job (with support of enable/disable of
346 /* term.c_oflag &= ~(OPOST); */
348 term.c_cc[VTIME] = 0;
349 if (tcsetattr(fd, TCSANOW, &term) < 0)
351 release_object( console_input );
352 set_error( STATUS_INVALID_HANDLE );
355 allow_fd_caching( console_input->fd );
358 return &console_input->obj;
361 static void generate_sb_initial_events( struct console_input *console_input )
363 struct screen_buffer *screen_buffer = console_input->active;
364 struct console_renderer_event evt;
366 evt.event = CONSOLE_RENDERER_ACTIVE_SB_EVENT;
367 memset(&evt.u, 0, sizeof(evt.u));
368 console_input_events_append( console_input->evt, &evt );
370 evt.event = CONSOLE_RENDERER_SB_RESIZE_EVENT;
371 evt.u.resize.width = screen_buffer->width;
372 evt.u.resize.height = screen_buffer->height;
373 console_input_events_append( console_input->evt, &evt );
375 evt.event = CONSOLE_RENDERER_DISPLAY_EVENT;
376 evt.u.display.left = screen_buffer->win.left;
377 evt.u.display.top = screen_buffer->win.top;
378 evt.u.display.width = screen_buffer->win.right - screen_buffer->win.left + 1;
379 evt.u.display.height = screen_buffer->win.bottom - screen_buffer->win.top + 1;
380 console_input_events_append( console_input->evt, &evt );
382 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
383 evt.u.update.top = 0;
384 evt.u.update.bottom = screen_buffer->height - 1;
385 console_input_events_append( console_input->evt, &evt );
387 evt.event = CONSOLE_RENDERER_CURSOR_GEOM_EVENT;
388 evt.u.cursor_geom.size = screen_buffer->cursor_size;
389 evt.u.cursor_geom.visible = screen_buffer->cursor_visible;
390 console_input_events_append( console_input->evt, &evt );
392 evt.event = CONSOLE_RENDERER_CURSOR_POS_EVENT;
393 evt.u.cursor_pos.x = screen_buffer->cursor_x;
394 evt.u.cursor_pos.y = screen_buffer->cursor_y;
395 console_input_events_append( console_input->evt, &evt );
398 static struct screen_buffer *create_console_output( struct console_input *console_input )
400 struct screen_buffer *screen_buffer;
403 if (!(screen_buffer = alloc_object( &screen_buffer_ops ))) return NULL;
404 screen_buffer->mode = ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT;
405 screen_buffer->input = console_input;
406 screen_buffer->cursor_size = 100;
407 screen_buffer->cursor_visible = 1;
408 screen_buffer->width = 80;
409 screen_buffer->height = 150;
410 screen_buffer->max_width = 80;
411 screen_buffer->max_height = 25;
412 screen_buffer->cursor_x = 0;
413 screen_buffer->cursor_y = 0;
414 screen_buffer->attr = 0x0F;
415 screen_buffer->win.left = 0;
416 screen_buffer->win.right = screen_buffer->max_width - 1;
417 screen_buffer->win.top = 0;
418 screen_buffer->win.bottom = screen_buffer->max_height - 1;
420 list_add_head( &screen_buffer_list, &screen_buffer->entry );
422 if (!(screen_buffer->data = malloc( screen_buffer->width * screen_buffer->height *
423 sizeof(*screen_buffer->data) )))
425 release_object( screen_buffer );
428 /* clear the first row */
429 for (i = 0; i < screen_buffer->width; i++) screen_buffer->data[i] = empty_char_info;
430 /* and copy it to all other rows */
431 for (i = 1; i < screen_buffer->height; i++)
432 memcpy( &screen_buffer->data[i * screen_buffer->width], screen_buffer->data,
433 screen_buffer->width * sizeof(char_info_t) );
435 if (!console_input->active)
437 console_input->active = (struct screen_buffer*)grab_object( screen_buffer );
438 generate_sb_initial_events( console_input );
440 return screen_buffer;
443 /* free the console for this process */
444 int free_console( struct process *process )
446 struct console_input* console = process->console;
448 if (!console) return 0;
450 process->console = NULL;
451 if (--console->num_proc == 0 && console->renderer)
453 /* all processes have terminated... tell the renderer to terminate too */
454 struct console_renderer_event evt;
455 evt.event = CONSOLE_RENDERER_EXIT_EVENT;
456 memset(&evt.u, 0, sizeof(evt.u));
457 console_input_events_append( console->evt, &evt );
459 release_object( console );
464 /* let process inherit the console from parent... this handle two cases :
465 * 1/ generic console inheritance
466 * 2/ parent is a renderer which launches process, and process should attach to the console
467 * renderered by parent
469 void inherit_console(struct thread *parent_thread, struct process *process, obj_handle_t hconin)
472 struct process* parent = parent_thread->process;
474 /* if parent is a renderer, then attach current process to its console
479 struct console_input* console;
481 /* FIXME: should we check some access rights ? */
482 if ((console = (struct console_input*)get_handle_obj( parent, hconin,
483 0, &console_input_ops )))
485 if (console->renderer == parent_thread)
487 process->console = (struct console_input*)grab_object( console );
488 process->console->num_proc++;
491 release_object( console );
493 else clear_error(); /* ignore error */
495 /* otherwise, if parent has a console, attach child to this console */
496 if (!done && parent->console)
498 process->console = (struct console_input*)grab_object( parent->console );
499 process->console->num_proc++;
503 struct thread *console_get_renderer( struct console_input *console )
505 return console->renderer;
508 static struct console_input* console_input_get( obj_handle_t handle, unsigned access )
510 struct console_input* console = NULL;
513 console = (struct console_input *)get_handle_obj( current->process, handle,
514 access, &console_input_ops );
515 else if (current->process->console)
517 console = (struct console_input *)grab_object( current->process->console );
520 if (!console && !get_error()) set_error(STATUS_INVALID_PARAMETER);
524 struct console_signal_info
526 struct console_input *console;
531 static int propagate_console_signal_cb(struct process *process, void *user)
533 struct console_signal_info* csi = (struct console_signal_info*)user;
535 if (process->console == csi->console && process->running_threads &&
536 (!csi->group || process->group_id == csi->group))
538 /* find a suitable thread to signal */
539 struct thread *thread;
540 LIST_FOR_EACH_ENTRY( thread, &process->thread_list, struct thread, proc_entry )
542 if (send_thread_signal( thread, csi->signal )) break;
548 static void propagate_console_signal( struct console_input *console,
549 int sig, process_id_t group_id )
551 struct console_signal_info csi;
555 set_error( STATUS_INVALID_PARAMETER );
558 /* FIXME: should support the other events (like CTRL_BREAK) */
559 if (sig != CTRL_C_EVENT)
561 set_error( STATUS_NOT_IMPLEMENTED );
564 csi.console = console;
566 csi.group = group_id;
568 enum_processes(propagate_console_signal_cb, &csi);
571 static int get_console_mode( obj_handle_t handle )
576 if ((obj = get_handle_obj( current->process, handle, FILE_READ_PROPERTIES, NULL )))
578 if (obj->ops == &console_input_ops)
579 ret = ((struct console_input *)obj)->mode;
580 else if (obj->ops == &screen_buffer_ops)
581 ret = ((struct screen_buffer *)obj)->mode;
583 set_error( STATUS_OBJECT_TYPE_MISMATCH );
584 release_object( obj );
589 /* changes the mode of either a console input or a screen buffer */
590 static int set_console_mode( obj_handle_t handle, int mode )
595 if (!(obj = get_handle_obj( current->process, handle, FILE_WRITE_PROPERTIES, NULL )))
597 if (obj->ops == &console_input_ops)
599 /* FIXME: if we remove the edit mode bits, we need (???) to clean up the history */
600 ((struct console_input *)obj)->mode = mode;
603 else if (obj->ops == &screen_buffer_ops)
605 ((struct screen_buffer *)obj)->mode = mode;
608 else set_error( STATUS_OBJECT_TYPE_MISMATCH );
609 release_object( obj );
613 /* add input events to a console input queue */
614 static int write_console_input( struct console_input* console, int count,
615 const INPUT_RECORD *records )
617 INPUT_RECORD *new_rec;
619 if (!count) return 0;
620 if (!(new_rec = realloc( console->records,
621 (console->recnum + count) * sizeof(INPUT_RECORD) )))
623 set_error( STATUS_NO_MEMORY );
624 release_object( console );
627 console->records = new_rec;
628 memcpy( new_rec + console->recnum, records, count * sizeof(INPUT_RECORD) );
630 if (console->mode & ENABLE_PROCESSED_INPUT)
635 if (records[i].EventType == KEY_EVENT &&
636 records[i].Event.KeyEvent.uChar.UnicodeChar == 'C' - 64 &&
637 !(records[i].Event.KeyEvent.dwControlKeyState & ENHANCED_KEY))
640 memcpy( &console->records[console->recnum + i],
641 &console->records[console->recnum + i + 1],
642 (count - i - 1) * sizeof(INPUT_RECORD) );
644 if (records[i].Event.KeyEvent.bKeyDown)
646 /* send SIGINT to all processes attached to this console */
647 propagate_console_signal( console, CTRL_C_EVENT, 0 );
653 if (!console->recnum && count) set_event( console->event );
654 console->recnum += count;
658 /* retrieve a pointer to the console input records */
659 static int read_console_input( obj_handle_t handle, int count, int flush )
661 struct console_input *console;
663 if (!(console = (struct console_input *)get_handle_obj( current->process, handle,
664 FILE_READ_DATA, &console_input_ops )))
669 /* special case: do not retrieve anything, but return
670 * the total number of records available */
671 count = console->recnum;
675 if (count > console->recnum) count = console->recnum;
676 set_reply_data( console->records, count * sizeof(INPUT_RECORD) );
681 for (i = count; i < console->recnum; i++)
682 console->records[i-count] = console->records[i];
683 if ((console->recnum -= count) > 0)
685 INPUT_RECORD *new_rec = realloc( console->records,
686 console->recnum * sizeof(INPUT_RECORD) );
687 if (new_rec) console->records = new_rec;
691 free( console->records );
692 console->records = NULL;
693 reset_event( console->event );
696 release_object( console );
700 /* set misc console input information */
701 static int set_console_input_info( const struct set_console_input_info_request *req,
702 const WCHAR *title, data_size_t len )
704 struct console_input *console;
705 struct console_renderer_event evt;
707 if (!(console = console_input_get( req->handle, FILE_WRITE_PROPERTIES ))) goto error;
709 memset(&evt.u, 0, sizeof(evt.u));
710 if (req->mask & SET_CONSOLE_INPUT_INFO_ACTIVE_SB)
712 struct screen_buffer *screen_buffer;
714 screen_buffer = (struct screen_buffer *)get_handle_obj( current->process, req->active_sb,
715 FILE_WRITE_PROPERTIES, &screen_buffer_ops );
716 if (!screen_buffer || screen_buffer->input != console)
718 set_error( STATUS_INVALID_HANDLE );
719 if (screen_buffer) release_object( screen_buffer );
723 if (screen_buffer != console->active)
725 if (console->active) release_object( console->active );
726 console->active = screen_buffer;
727 generate_sb_initial_events( console );
730 release_object( screen_buffer );
732 if (req->mask & SET_CONSOLE_INPUT_INFO_TITLE)
734 WCHAR *new_title = mem_alloc( len + sizeof(WCHAR) );
737 memcpy( new_title, title, len );
738 new_title[len / sizeof(WCHAR)] = 0;
739 free( console->title );
740 console->title = new_title;
741 evt.event = CONSOLE_RENDERER_TITLE_EVENT;
742 console_input_events_append( console->evt, &evt );
745 if (req->mask & SET_CONSOLE_INPUT_INFO_HISTORY_MODE)
747 console->history_mode = req->history_mode;
749 if ((req->mask & SET_CONSOLE_INPUT_INFO_HISTORY_SIZE) &&
750 console->history_size != req->history_size)
756 if (req->history_size)
758 mem = mem_alloc( req->history_size * sizeof(WCHAR*) );
759 if (!mem) goto error;
760 memset( mem, 0, req->history_size * sizeof(WCHAR*) );
763 delta = (console->history_index > req->history_size) ?
764 (console->history_index - req->history_size) : 0;
766 for (i = delta; i < console->history_index; i++)
768 mem[i - delta] = console->history[i];
769 console->history[i] = NULL;
771 console->history_index -= delta;
773 for (i = 0; i < console->history_size; i++)
774 free( console->history[i] );
775 free( console->history );
776 console->history = mem;
777 console->history_size = req->history_size;
779 if (req->mask & SET_CONSOLE_INPUT_INFO_EDITION_MODE)
781 console->edition_mode = req->edition_mode;
783 if (req->mask & SET_CONSOLE_INPUT_INFO_INPUT_CODEPAGE)
785 console->input_cp = req->input_cp;
787 if (req->mask & SET_CONSOLE_INPUT_INFO_OUTPUT_CODEPAGE)
789 console->output_cp = req->output_cp;
791 if (req->mask & SET_CONSOLE_INPUT_INFO_WIN)
793 console->win = req->win;
795 release_object( console );
798 if (console) release_object( console );
802 /* resize a screen buffer */
803 static int change_screen_buffer_size( struct screen_buffer *screen_buffer,
804 int new_width, int new_height )
806 int i, old_width, old_height, copy_width, copy_height;
807 char_info_t *new_data;
809 if (!(new_data = malloc( new_width * new_height * sizeof(*new_data) )))
811 set_error( STATUS_NO_MEMORY );
814 old_width = screen_buffer->width;
815 old_height = screen_buffer->height;
816 copy_width = min( old_width, new_width );
817 copy_height = min( old_height, new_height );
819 /* copy all the rows */
820 for (i = 0; i < copy_height; i++)
822 memcpy( &new_data[i * new_width], &screen_buffer->data[i * old_width],
823 copy_width * sizeof(char_info_t) );
826 /* clear the end of each row */
827 if (new_width > old_width)
830 for (i = old_width; i < new_width; i++) new_data[i] = empty_char_info;
831 /* and blast it to the other rows */
832 for (i = 1; i < copy_height; i++)
833 memcpy( &new_data[i * new_width + old_width], &new_data[old_width],
834 (new_width - old_width) * sizeof(char_info_t) );
837 /* clear remaining rows */
838 if (new_height > old_height)
841 for (i = 0; i < new_width; i++) new_data[old_height * new_width + i] = empty_char_info;
842 /* and blast it to the other rows */
843 for (i = old_height+1; i < new_height; i++)
844 memcpy( &new_data[i * new_width], &new_data[old_height * new_width],
845 new_width * sizeof(char_info_t) );
847 free( screen_buffer->data );
848 screen_buffer->data = new_data;
849 screen_buffer->width = new_width;
850 screen_buffer->height = new_height;
854 /* set misc screen buffer information */
855 static int set_console_output_info( struct screen_buffer *screen_buffer,
856 const struct set_console_output_info_request *req )
858 struct console_renderer_event evt;
860 memset(&evt.u, 0, sizeof(evt.u));
861 if (req->mask & SET_CONSOLE_OUTPUT_INFO_CURSOR_GEOM)
863 if (req->cursor_size < 1 || req->cursor_size > 100)
865 set_error( STATUS_INVALID_PARAMETER );
868 if (screen_buffer->cursor_size != req->cursor_size ||
869 screen_buffer->cursor_visible != req->cursor_visible)
871 screen_buffer->cursor_size = req->cursor_size;
872 screen_buffer->cursor_visible = req->cursor_visible;
873 evt.event = CONSOLE_RENDERER_CURSOR_GEOM_EVENT;
874 evt.u.cursor_geom.size = req->cursor_size;
875 evt.u.cursor_geom.visible = req->cursor_visible;
876 console_input_events_append( screen_buffer->input->evt, &evt );
879 if (req->mask & SET_CONSOLE_OUTPUT_INFO_CURSOR_POS)
881 if (req->cursor_x < 0 || req->cursor_x >= screen_buffer->width ||
882 req->cursor_y < 0 || req->cursor_y >= screen_buffer->height)
884 set_error( STATUS_INVALID_PARAMETER );
887 if (screen_buffer->cursor_x != req->cursor_x || screen_buffer->cursor_y != req->cursor_y)
889 screen_buffer->cursor_x = req->cursor_x;
890 screen_buffer->cursor_y = req->cursor_y;
891 evt.event = CONSOLE_RENDERER_CURSOR_POS_EVENT;
892 evt.u.cursor_pos.x = req->cursor_x;
893 evt.u.cursor_pos.y = req->cursor_y;
894 console_input_events_append( screen_buffer->input->evt, &evt );
897 if (req->mask & SET_CONSOLE_OUTPUT_INFO_SIZE)
901 /* new screen-buffer cannot be smaller than actual window */
902 if (req->width < screen_buffer->win.right - screen_buffer->win.left + 1 ||
903 req->height < screen_buffer->win.bottom - screen_buffer->win.top + 1)
905 set_error( STATUS_INVALID_PARAMETER );
908 /* FIXME: there are also some basic minimum and max size to deal with */
909 if (!change_screen_buffer_size( screen_buffer, req->width, req->height )) return 0;
911 evt.event = CONSOLE_RENDERER_SB_RESIZE_EVENT;
912 evt.u.resize.width = req->width;
913 evt.u.resize.height = req->height;
914 console_input_events_append( screen_buffer->input->evt, &evt );
916 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
917 evt.u.update.top = 0;
918 evt.u.update.bottom = screen_buffer->height - 1;
919 console_input_events_append( screen_buffer->input->evt, &evt );
921 /* scroll window to display sb */
922 if (screen_buffer->win.right >= req->width)
924 screen_buffer->win.right -= screen_buffer->win.left;
925 screen_buffer->win.left = 0;
927 if (screen_buffer->win.bottom >= req->height)
929 screen_buffer->win.bottom -= screen_buffer->win.top;
930 screen_buffer->win.top = 0;
932 /* reset cursor if needed (normally, if cursor was outside of new sb, the
933 * window has been shifted so that the new position of the cursor will be
936 if (screen_buffer->cursor_x >= req->width)
938 screen_buffer->cursor_x = req->width - 1;
941 if (screen_buffer->cursor_y >= req->height)
943 screen_buffer->cursor_y = req->height - 1;
948 evt.event = CONSOLE_RENDERER_CURSOR_POS_EVENT;
949 evt.u.cursor_pos.x = req->cursor_x;
950 evt.u.cursor_pos.y = req->cursor_y;
951 console_input_events_append( screen_buffer->input->evt, &evt );
954 if (screen_buffer == screen_buffer->input->active &&
955 screen_buffer->input->mode & ENABLE_WINDOW_INPUT)
958 ir.EventType = WINDOW_BUFFER_SIZE_EVENT;
959 ir.Event.WindowBufferSizeEvent.dwSize.X = req->width;
960 ir.Event.WindowBufferSizeEvent.dwSize.Y = req->height;
961 write_console_input( screen_buffer->input, 1, &ir );
964 if (req->mask & SET_CONSOLE_OUTPUT_INFO_ATTR)
966 screen_buffer->attr = req->attr;
968 if (req->mask & SET_CONSOLE_OUTPUT_INFO_DISPLAY_WINDOW)
970 if (req->win_left < 0 || req->win_left > req->win_right ||
971 req->win_right >= screen_buffer->width ||
972 req->win_top < 0 || req->win_top > req->win_bottom ||
973 req->win_bottom >= screen_buffer->height)
975 set_error( STATUS_INVALID_PARAMETER );
978 if (screen_buffer->win.left != req->win_left || screen_buffer->win.top != req->win_top ||
979 screen_buffer->win.right != req->win_right || screen_buffer->win.bottom != req->win_bottom)
981 screen_buffer->win.left = req->win_left;
982 screen_buffer->win.top = req->win_top;
983 screen_buffer->win.right = req->win_right;
984 screen_buffer->win.bottom = req->win_bottom;
985 evt.event = CONSOLE_RENDERER_DISPLAY_EVENT;
986 evt.u.display.left = req->win_left;
987 evt.u.display.top = req->win_top;
988 evt.u.display.width = req->win_right - req->win_left + 1;
989 evt.u.display.height = req->win_bottom - req->win_top + 1;
990 console_input_events_append( screen_buffer->input->evt, &evt );
993 if (req->mask & SET_CONSOLE_OUTPUT_INFO_MAX_SIZE)
995 /* can only be done by renderer */
996 if (current->process->console != screen_buffer->input)
998 set_error( STATUS_INVALID_PARAMETER );
1002 screen_buffer->max_width = req->max_width;
1003 screen_buffer->max_height = req->max_height;
1009 /* appends a new line to history (history is a fixed size array) */
1010 static void console_input_append_hist( struct console_input* console, const WCHAR* buf, data_size_t len )
1012 WCHAR* ptr = mem_alloc( (len + 1) * sizeof(WCHAR) );
1017 if (!console || !console->history_size)
1019 set_error( STATUS_INVALID_PARAMETER ); /* FIXME */
1024 memcpy( ptr, buf, len * sizeof(WCHAR) );
1027 if (console->history_mode && console->history_index &&
1028 strncmpW( console->history[console->history_index - 1], ptr, len * sizeof(WCHAR) ) == 0)
1030 /* ok, mode ask us to not use twice the same string...
1031 * so just free mem and returns
1033 set_error( STATUS_ALIAS_EXISTS );
1038 if (console->history_index < console->history_size)
1040 console->history[console->history_index++] = ptr;
1044 free( console->history[0]) ;
1045 memmove( &console->history[0], &console->history[1],
1046 (console->history_size - 1) * sizeof(WCHAR*) );
1047 console->history[console->history_size - 1] = ptr;
1051 /* returns a line from the cache */
1052 static data_size_t console_input_get_hist( struct console_input *console, int index )
1054 data_size_t ret = 0;
1056 if (index >= console->history_index) set_error( STATUS_INVALID_PARAMETER );
1059 ret = strlenW( console->history[index] ) * sizeof(WCHAR);
1060 set_reply_data( console->history[index], min( ret, get_reply_max_size() ));
1066 static void console_input_dump( struct object *obj, int verbose )
1068 struct console_input *console = (struct console_input *)obj;
1069 assert( obj->ops == &console_input_ops );
1070 fprintf( stderr, "Console input active=%p evt=%p\n",
1071 console->active, console->evt );
1074 static void console_input_destroy( struct object *obj )
1076 struct console_input* console_in = (struct console_input *)obj;
1077 struct screen_buffer* curr;
1080 assert( obj->ops == &console_input_ops );
1081 free( console_in->title );
1082 free( console_in->records );
1084 if (console_in->active) release_object( console_in->active );
1085 console_in->active = NULL;
1087 LIST_FOR_EACH_ENTRY( curr, &screen_buffer_list, struct screen_buffer, entry )
1089 if (curr->input == console_in) curr->input = NULL;
1092 if (console_in->evt)
1094 release_object( console_in->evt );
1095 console_in->evt = NULL;
1097 release_object( console_in->event );
1100 tcsetattr(get_unix_fd(console_in->fd), TCSANOW, &console_in->termios);
1101 release_object( console_in->fd );
1104 for (i = 0; i < console_in->history_size; i++)
1105 free( console_in->history[i] );
1106 free( console_in->history );
1109 static void screen_buffer_dump( struct object *obj, int verbose )
1111 struct screen_buffer *screen_buffer = (struct screen_buffer *)obj;
1112 assert( obj->ops == &screen_buffer_ops );
1114 fprintf(stderr, "Console screen buffer input=%p\n", screen_buffer->input );
1117 static void screen_buffer_destroy( struct object *obj )
1119 struct screen_buffer *screen_buffer = (struct screen_buffer *)obj;
1121 assert( obj->ops == &screen_buffer_ops );
1123 list_remove( &screen_buffer->entry );
1125 if (screen_buffer->input && screen_buffer->input->active == screen_buffer)
1127 struct screen_buffer *sb;
1129 screen_buffer->input->active = NULL;
1130 LIST_FOR_EACH_ENTRY( sb, &screen_buffer_list, struct screen_buffer, entry )
1132 if (sb->input == screen_buffer->input)
1134 sb->input->active = sb;
1139 free( screen_buffer->data );
1142 /* write data into a screen buffer */
1143 static int write_console_output( struct screen_buffer *screen_buffer, data_size_t size,
1144 const void* data, enum char_info_mode mode,
1145 int x, int y, int wrap )
1148 char_info_t *end, *dest = screen_buffer->data + y * screen_buffer->width + x;
1150 if (y >= screen_buffer->height) return 0;
1153 end = screen_buffer->data + screen_buffer->height * screen_buffer->width;
1155 end = screen_buffer->data + (y+1) * screen_buffer->width;
1159 case CHAR_INFO_MODE_TEXT:
1161 const WCHAR *ptr = data;
1162 for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++) dest->ch = ptr[i];
1165 case CHAR_INFO_MODE_ATTR:
1167 const unsigned short *ptr = data;
1168 for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++) dest->attr = ptr[i];
1171 case CHAR_INFO_MODE_TEXTATTR:
1173 const char_info_t *ptr = data;
1174 for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++) *dest = ptr[i];
1177 case CHAR_INFO_MODE_TEXTSTDATTR:
1179 const WCHAR *ptr = data;
1180 for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++)
1183 dest->attr = screen_buffer->attr;
1188 set_error( STATUS_INVALID_PARAMETER );
1192 if (i && screen_buffer == screen_buffer->input->active)
1194 struct console_renderer_event evt;
1195 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
1196 memset(&evt.u, 0, sizeof(evt.u));
1197 evt.u.update.top = y + x / screen_buffer->width;
1198 evt.u.update.bottom = y + (x + i - 1) / screen_buffer->width;
1199 console_input_events_append( screen_buffer->input->evt, &evt );
1204 /* fill a screen buffer with uniform data */
1205 static int fill_console_output( struct screen_buffer *screen_buffer, char_info_t data,
1206 enum char_info_mode mode, int x, int y, int count, int wrap )
1209 char_info_t *end, *dest = screen_buffer->data + y * screen_buffer->width + x;
1211 if (y >= screen_buffer->height) return 0;
1214 end = screen_buffer->data + screen_buffer->height * screen_buffer->width;
1216 end = screen_buffer->data + (y+1) * screen_buffer->width;
1218 if (count > end - dest) count = end - dest;
1222 case CHAR_INFO_MODE_TEXT:
1223 for (i = 0; i < count; i++) dest[i].ch = data.ch;
1225 case CHAR_INFO_MODE_ATTR:
1226 for (i = 0; i < count; i++) dest[i].attr = data.attr;
1228 case CHAR_INFO_MODE_TEXTATTR:
1229 for (i = 0; i < count; i++) dest[i] = data;
1231 case CHAR_INFO_MODE_TEXTSTDATTR:
1232 for (i = 0; i < count; i++)
1234 dest[i].ch = data.ch;
1235 dest[i].attr = screen_buffer->attr;
1239 set_error( STATUS_INVALID_PARAMETER );
1243 if (count && screen_buffer == screen_buffer->input->active)
1245 struct console_renderer_event evt;
1246 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
1247 memset(&evt.u, 0, sizeof(evt.u));
1248 evt.u.update.top = y;
1249 evt.u.update.bottom = (y * screen_buffer->width + x + count - 1) / screen_buffer->width;
1250 console_input_events_append( screen_buffer->input->evt, &evt );
1255 /* read data from a screen buffer */
1256 static void read_console_output( struct screen_buffer *screen_buffer, int x, int y,
1257 enum char_info_mode mode, int wrap )
1260 char_info_t *end, *src = screen_buffer->data + y * screen_buffer->width + x;
1262 if (y >= screen_buffer->height) return;
1265 end = screen_buffer->data + screen_buffer->height * screen_buffer->width;
1267 end = screen_buffer->data + (y+1) * screen_buffer->width;
1271 case CHAR_INFO_MODE_TEXT:
1274 int count = min( end - src, get_reply_max_size() / sizeof(*data) );
1275 if ((data = set_reply_data_size( count * sizeof(*data) )))
1277 for (i = 0; i < count; i++) data[i] = src[i].ch;
1281 case CHAR_INFO_MODE_ATTR:
1283 unsigned short *data;
1284 int count = min( end - src, get_reply_max_size() / sizeof(*data) );
1285 if ((data = set_reply_data_size( count * sizeof(*data) )))
1287 for (i = 0; i < count; i++) data[i] = src[i].attr;
1291 case CHAR_INFO_MODE_TEXTATTR:
1294 int count = min( end - src, get_reply_max_size() / sizeof(*data) );
1295 if ((data = set_reply_data_size( count * sizeof(*data) )))
1297 for (i = 0; i < count; i++) data[i] = src[i];
1302 set_error( STATUS_INVALID_PARAMETER );
1307 /* scroll parts of a screen buffer */
1308 static void scroll_console_output( obj_handle_t handle, int xsrc, int ysrc, int xdst, int ydst,
1311 struct screen_buffer *screen_buffer;
1313 char_info_t *psrc, *pdst;
1314 struct console_renderer_event evt;
1316 if (!(screen_buffer = (struct screen_buffer *)get_handle_obj( current->process, handle,
1317 FILE_WRITE_DATA, &screen_buffer_ops )))
1319 if (xsrc < 0 || ysrc < 0 || xdst < 0 || ydst < 0 ||
1320 xsrc + w > screen_buffer->width ||
1321 xdst + w > screen_buffer->width ||
1322 ysrc + h > screen_buffer->height ||
1323 ydst + h > screen_buffer->height ||
1326 set_error( STATUS_INVALID_PARAMETER );
1327 release_object( screen_buffer );
1333 psrc = &screen_buffer->data[(ysrc + h - 1) * screen_buffer->width + xsrc];
1334 pdst = &screen_buffer->data[(ydst + h - 1) * screen_buffer->width + xdst];
1336 for (j = h; j > 0; j--)
1338 memcpy(pdst, psrc, w * sizeof(*pdst) );
1339 pdst -= screen_buffer->width;
1340 psrc -= screen_buffer->width;
1345 psrc = &screen_buffer->data[ysrc * screen_buffer->width + xsrc];
1346 pdst = &screen_buffer->data[ydst * screen_buffer->width + xdst];
1348 for (j = 0; j < h; j++)
1350 /* we use memmove here because when psrc and pdst are the same,
1351 * copies are done on the same row, so the dst and src blocks
1353 memmove( pdst, psrc, w * sizeof(*pdst) );
1354 pdst += screen_buffer->width;
1355 psrc += screen_buffer->width;
1359 /* FIXME: this could be enhanced, by signalling scroll */
1360 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
1361 memset(&evt.u, 0, sizeof(evt.u));
1362 evt.u.update.top = min(ysrc, ydst);
1363 evt.u.update.bottom = max(ysrc, ydst) + h - 1;
1364 console_input_events_append( screen_buffer->input->evt, &evt );
1366 release_object( screen_buffer );
1369 /* allocate a console for the renderer */
1370 DECL_HANDLER(alloc_console)
1372 obj_handle_t in = 0;
1373 obj_handle_t evt = 0;
1374 struct process *process;
1375 struct thread *renderer;
1376 struct console_input *console;
1382 /* renderer is current, console to be attached to parent process */
1384 if (!(process = current->process->parent))
1386 set_error( STATUS_ACCESS_DENIED );
1389 grab_object( process );
1392 /* no renderer, console to be attached to current process */
1394 process = current->process;
1395 grab_object( process );
1398 /* renderer is current, console to be attached to req->pid */
1400 if (!(process = get_process_from_id( req->pid ))) return;
1403 if (process != current->process && process->console)
1405 set_error( STATUS_ACCESS_DENIED );
1408 if (req->input_fd != -1)
1410 if ((fd = thread_get_inflight_fd( current, req->input_fd )) == -1)
1412 set_error( STATUS_INVALID_PARAMETER );
1418 if ((console = (struct console_input*)create_console_input( renderer, fd )))
1420 if ((in = alloc_handle( current->process, console, req->access, req->attributes )))
1422 if (!console->evt ||
1423 (evt = alloc_handle( current->process, console->evt, SYNCHRONIZE|GENERIC_READ|GENERIC_WRITE, 0 )))
1425 process->console = (struct console_input*)grab_object( console );
1426 console->num_proc++;
1427 reply->handle_in = in;
1429 release_object( console );
1432 close_handle( current->process, in );
1434 free_console( process );
1437 release_object( process );
1440 /* free the console of the current process */
1441 DECL_HANDLER(free_console)
1443 free_console( current->process );
1446 /* let the renderer peek the events it's waiting on */
1447 DECL_HANDLER(get_console_renderer_events)
1449 struct console_input_events *evt;
1451 evt = (struct console_input_events *)get_handle_obj( current->process, req->handle,
1452 FILE_READ_PROPERTIES, &console_input_events_ops );
1454 console_input_events_get( evt );
1455 release_object( evt );
1458 /* open a handle to the process console */
1459 DECL_HANDLER(open_console)
1461 struct object *obj = NULL;
1466 if (current->process->console)
1467 obj = grab_object( (struct object*)current->process->console );
1469 else if (req->from == (obj_handle_t)1)
1471 if (current->process->console && current->process->console->active)
1472 obj = grab_object( (struct object*)current->process->console->active );
1474 else if ((obj = get_handle_obj( current->process, req->from,
1475 FILE_READ_PROPERTIES|FILE_WRITE_PROPERTIES, &console_input_ops )))
1477 struct console_input *console = (struct console_input *)obj;
1478 obj = (console->active) ? grab_object( console->active ) : NULL;
1479 release_object( console );
1482 /* FIXME: req->share is not used (as in screen buffer creation) */
1485 reply->handle = alloc_handle( current->process, obj, req->access, req->attributes );
1486 release_object( obj );
1488 else if (!get_error()) set_error( STATUS_ACCESS_DENIED );
1491 /* set info about a console input */
1492 DECL_HANDLER(set_console_input_info)
1494 set_console_input_info( req, get_req_data(), get_req_data_size() );
1497 /* get info about a console (output only) */
1498 DECL_HANDLER(get_console_input_info)
1500 struct console_input *console;
1502 if (!(console = console_input_get( req->handle, FILE_READ_PROPERTIES ))) return;
1505 data_size_t len = strlenW( console->title ) * sizeof(WCHAR);
1506 if (len > get_reply_max_size()) len = get_reply_max_size();
1507 set_reply_data( console->title, len );
1509 reply->history_mode = console->history_mode;
1510 reply->history_size = console->history_size;
1511 reply->history_index = console->history_index;
1512 reply->edition_mode = console->edition_mode;
1513 reply->input_cp = console->input_cp;
1514 reply->output_cp = console->output_cp;
1515 reply->win = console->win;
1517 release_object( console );
1520 /* get a console mode (input or output) */
1521 DECL_HANDLER(get_console_mode)
1523 reply->mode = get_console_mode( req->handle );
1526 /* set a console mode (input or output) */
1527 DECL_HANDLER(set_console_mode)
1529 set_console_mode( req->handle, req->mode );
1532 /* add input records to a console input queue */
1533 DECL_HANDLER(write_console_input)
1535 struct console_input *console;
1538 if (!(console = (struct console_input *)get_handle_obj( current->process, req->handle,
1539 FILE_WRITE_PROPERTIES, &console_input_ops )))
1541 reply->written = write_console_input( console, get_req_data_size() / sizeof(INPUT_RECORD),
1543 release_object( console );
1546 /* fetch input records from a console input queue */
1547 DECL_HANDLER(read_console_input)
1549 int count = get_reply_max_size() / sizeof(INPUT_RECORD);
1550 reply->read = read_console_input( req->handle, count, req->flush );
1553 /* appends a string to console's history */
1554 DECL_HANDLER(append_console_input_history)
1556 struct console_input *console;
1558 if (!(console = console_input_get( req->handle, FILE_WRITE_PROPERTIES ))) return;
1559 console_input_append_hist( console, get_req_data(), get_req_data_size() / sizeof(WCHAR) );
1560 release_object( console );
1563 /* appends a string to console's history */
1564 DECL_HANDLER(get_console_input_history)
1566 struct console_input *console;
1568 if (!(console = console_input_get( req->handle, FILE_READ_PROPERTIES ))) return;
1569 reply->total = console_input_get_hist( console, req->index );
1570 release_object( console );
1573 /* creates a screen buffer */
1574 DECL_HANDLER(create_console_output)
1576 struct console_input* console;
1577 struct screen_buffer* screen_buffer;
1579 if (!(console = console_input_get( req->handle_in, FILE_WRITE_PROPERTIES ))) return;
1581 screen_buffer = create_console_output( console );
1584 /* FIXME: should store sharing and test it when opening the CONOUT$ device
1585 * see file.c on how this could be done */
1586 reply->handle_out = alloc_handle( current->process, screen_buffer, req->access, req->attributes );
1587 release_object( screen_buffer );
1589 release_object( console );
1592 /* set info about a console screen buffer */
1593 DECL_HANDLER(set_console_output_info)
1595 struct screen_buffer *screen_buffer;
1597 if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle,
1598 FILE_WRITE_PROPERTIES, &screen_buffer_ops)))
1600 set_console_output_info( screen_buffer, req );
1601 release_object( screen_buffer );
1605 /* get info about a console screen buffer */
1606 DECL_HANDLER(get_console_output_info)
1608 struct screen_buffer *screen_buffer;
1610 if ((screen_buffer = (struct screen_buffer *)get_handle_obj( current->process, req->handle,
1611 FILE_READ_PROPERTIES, &screen_buffer_ops)))
1613 reply->cursor_size = screen_buffer->cursor_size;
1614 reply->cursor_visible = screen_buffer->cursor_visible;
1615 reply->cursor_x = screen_buffer->cursor_x;
1616 reply->cursor_y = screen_buffer->cursor_y;
1617 reply->width = screen_buffer->width;
1618 reply->height = screen_buffer->height;
1619 reply->attr = screen_buffer->attr;
1620 reply->win_left = screen_buffer->win.left;
1621 reply->win_top = screen_buffer->win.top;
1622 reply->win_right = screen_buffer->win.right;
1623 reply->win_bottom = screen_buffer->win.bottom;
1624 reply->max_width = screen_buffer->max_width;
1625 reply->max_height = screen_buffer->max_height;
1626 release_object( screen_buffer );
1630 /* read data (chars & attrs) from a screen buffer */
1631 DECL_HANDLER(read_console_output)
1633 struct screen_buffer *screen_buffer;
1635 if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle,
1636 FILE_READ_DATA, &screen_buffer_ops )))
1638 read_console_output( screen_buffer, req->x, req->y, req->mode, req->wrap );
1639 reply->width = screen_buffer->width;
1640 reply->height = screen_buffer->height;
1641 release_object( screen_buffer );
1645 /* write data (char and/or attrs) to a screen buffer */
1646 DECL_HANDLER(write_console_output)
1648 struct screen_buffer *screen_buffer;
1650 if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle,
1651 FILE_WRITE_DATA, &screen_buffer_ops)))
1653 reply->written = write_console_output( screen_buffer, get_req_data_size(), get_req_data(),
1654 req->mode, req->x, req->y, req->wrap );
1655 reply->width = screen_buffer->width;
1656 reply->height = screen_buffer->height;
1657 release_object( screen_buffer );
1661 /* fill a screen buffer with constant data (chars and/or attributes) */
1662 DECL_HANDLER(fill_console_output)
1664 struct screen_buffer *screen_buffer;
1666 if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle,
1667 FILE_WRITE_DATA, &screen_buffer_ops)))
1669 reply->written = fill_console_output( screen_buffer, req->data, req->mode,
1670 req->x, req->y, req->count, req->wrap );
1671 release_object( screen_buffer );
1675 /* move a rect of data in a screen buffer */
1676 DECL_HANDLER(move_console_output)
1678 scroll_console_output( req->handle, req->x_src, req->y_src, req->x_dst, req->y_dst,
1682 /* sends a signal to a console (process, group...) */
1683 DECL_HANDLER(send_console_signal)
1687 group = req->group_id ? req->group_id : current->process->group_id;
1690 set_error( STATUS_INVALID_PARAMETER );
1692 propagate_console_signal( current->process->console, req->signal, group );
1695 /* get console which renderer is 'current' */
1696 static int cgwe_enum( struct process* process, void* user)
1698 if (process->console && process->console->renderer == current)
1700 *(struct console_input**)user = process->console;
1706 DECL_HANDLER(get_console_wait_event)
1708 struct console_input* console = NULL;
1710 if (current->process->console)
1711 console = (struct console_input*)grab_object( (struct object*)current->process->console );
1712 else enum_processes(cgwe_enum, &console);
1716 reply->handle = alloc_handle( current->process, console->event, EVENT_ALL_ACCESS, 0 );
1717 release_object( console );
1719 else set_error( STATUS_INVALID_PARAMETER );