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"
33 #define WIN32_NO_STATUS
43 struct console_input_events;
47 struct object obj; /* object header */
48 int num_proc; /* number of processes attached to this console */
49 struct thread *renderer; /* console renderer thread */
50 int mode; /* input mode */
51 struct screen_buffer *active; /* active screen buffer */
52 int recnum; /* number of input records */
53 INPUT_RECORD *records; /* input records */
54 struct console_input_events *evt; /* synchronization event with renderer */
55 WCHAR *title; /* console title */
56 WCHAR **history; /* lines history */
57 int history_size; /* number of entries in history array */
58 int history_index; /* number of used entries in history array */
59 int history_mode; /* mode of history (non zero means remove doubled strings */
60 int edition_mode; /* index to edition mode flavors */
61 int input_cp; /* console input codepage */
62 int output_cp; /* console output codepage */
63 user_handle_t win; /* window handle if backend supports it */
64 struct event *event; /* event to wait on for input queue */
65 struct fd *fd; /* for bare console, attached input fd */
68 static void console_input_dump( struct object *obj, int verbose );
69 static void console_input_destroy( struct object *obj );
70 static struct fd *console_input_get_fd( struct object *obj );
72 static const struct object_ops console_input_ops =
74 sizeof(struct console_input), /* size */
75 console_input_dump, /* dump */
76 no_get_type, /* get_type */
77 no_add_queue, /* add_queue */
78 NULL, /* remove_queue */
80 no_satisfied, /* satisfied */
81 no_signal, /* signal */
82 console_input_get_fd, /* get_fd */
83 default_fd_map_access, /* map_access */
84 default_get_sd, /* get_sd */
85 default_set_sd, /* set_sd */
86 no_lookup_name, /* lookup_name */
87 no_open_file, /* open_file */
88 no_close_handle, /* close_handle */
89 console_input_destroy /* destroy */
92 static void console_input_events_dump( struct object *obj, int verbose );
93 static void console_input_events_destroy( struct object *obj );
94 static int console_input_events_signaled( struct object *obj, struct thread *thread );
96 struct console_input_events
98 struct object obj; /* object header */
99 int num_alloc; /* number of allocated events */
100 int num_used; /* number of actually used events */
101 struct console_renderer_event* events;
104 static const struct object_ops console_input_events_ops =
106 sizeof(struct console_input_events), /* size */
107 console_input_events_dump, /* dump */
108 no_get_type, /* get_type */
109 add_queue, /* add_queue */
110 remove_queue, /* remove_queue */
111 console_input_events_signaled, /* signaled */
112 no_satisfied, /* satisfied */
113 no_signal, /* signal */
114 no_get_fd, /* get_fd */
115 default_fd_map_access, /* map_access */
116 default_get_sd, /* get_sd */
117 default_set_sd, /* set_sd */
118 no_lookup_name, /* lookup_name */
119 no_open_file, /* open_file */
120 no_close_handle, /* close_handle */
121 console_input_events_destroy /* destroy */
126 struct object obj; /* object header */
127 struct list entry; /* entry in list of all screen buffers */
128 struct console_input *input; /* associated console input */
129 int mode; /* output mode */
130 int cursor_size; /* size of cursor (percentage filled) */
131 int cursor_visible;/* cursor visibility flag */
132 int cursor_x; /* position of cursor */
133 int cursor_y; /* position of cursor */
134 int width; /* size (w-h) of the screen buffer */
136 int max_width; /* size (w-h) of the window given font size */
138 char_info_t *data; /* the data for each cell - a width x height matrix */
139 unsigned short attr; /* default attribute for screen buffer */
140 rectangle_t win; /* current visible window on the screen buffer *
141 * as seen in wineconsole */
142 struct fd *fd; /* for bare console, attached output fd */
145 static void screen_buffer_dump( struct object *obj, int verbose );
146 static void screen_buffer_destroy( struct object *obj );
147 static struct fd *screen_buffer_get_fd( struct object *obj );
149 static const struct object_ops screen_buffer_ops =
151 sizeof(struct screen_buffer), /* size */
152 screen_buffer_dump, /* dump */
153 no_get_type, /* get_type */
154 no_add_queue, /* add_queue */
155 NULL, /* remove_queue */
157 NULL, /* satisfied */
158 no_signal, /* signal */
159 screen_buffer_get_fd, /* get_fd */
160 default_fd_map_access, /* map_access */
161 default_get_sd, /* get_sd */
162 default_set_sd, /* set_sd */
163 no_lookup_name, /* lookup_name */
164 no_open_file, /* open_file */
165 no_close_handle, /* close_handle */
166 screen_buffer_destroy /* destroy */
169 static enum server_fd_type console_get_fd_type( struct fd *fd );
171 static const struct fd_ops console_fd_ops =
173 default_fd_get_poll_events, /* get_poll_events */
174 default_poll_event, /* poll_event */
175 no_flush, /* flush */
176 console_get_fd_type, /* get_fd_type */
177 default_fd_ioctl, /* ioctl */
178 default_fd_queue_async, /* queue_async */
179 default_fd_reselect_async, /* reselect_async */
180 default_fd_cancel_async /* cancel_async */
183 static struct list screen_buffer_list = LIST_INIT(screen_buffer_list);
185 static const char_info_t empty_char_info = { ' ', 0x000f }; /* white on black space */
187 static int console_input_is_bare( struct console_input* cin )
189 return cin->evt == NULL;
192 static struct fd *console_input_get_fd( struct object* obj )
194 struct console_input *console_input = (struct console_input*)obj;
195 assert( obj->ops == &console_input_ops );
196 return console_input->fd ? (struct fd*)grab_object( console_input->fd ) : NULL;
199 static enum server_fd_type console_get_fd_type( struct fd *fd )
204 /* dumps the renderer events of a console */
205 static void console_input_events_dump( struct object *obj, int verbose )
207 struct console_input_events *evts = (struct console_input_events *)obj;
208 assert( obj->ops == &console_input_events_ops );
209 fprintf( stderr, "Console input events: %d/%d events\n",
210 evts->num_used, evts->num_alloc );
213 /* destroys the renderer events of a console */
214 static void console_input_events_destroy( struct object *obj )
216 struct console_input_events *evts = (struct console_input_events *)obj;
217 assert( obj->ops == &console_input_events_ops );
218 free( evts->events );
221 /* the renderer events list is signaled when it's not empty */
222 static int console_input_events_signaled( struct object *obj, struct thread *thread )
224 struct console_input_events *evts = (struct console_input_events *)obj;
225 assert( obj->ops == &console_input_events_ops );
226 return (evts->num_used != 0);
229 /* add an event to the console's renderer events list */
230 static void console_input_events_append( struct console_input* console,
231 struct console_renderer_event* evt)
233 struct console_input_events* evts;
234 int collapsed = FALSE;
236 if (!(evts = console->evt)) return;
237 /* to be done even when evt has been generated by the renderer ? */
239 /* try to collapse evt into current queue's events */
242 struct console_renderer_event* last = &evts->events[evts->num_used - 1];
244 if (last->event == CONSOLE_RENDERER_UPDATE_EVENT &&
245 evt->event == CONSOLE_RENDERER_UPDATE_EVENT)
247 /* if two update events overlap, collapse them into a single one */
248 if (last->u.update.bottom + 1 >= evt->u.update.top &&
249 evt->u.update.bottom + 1 >= last->u.update.top)
251 last->u.update.top = min(last->u.update.top, evt->u.update.top);
252 last->u.update.bottom = max(last->u.update.bottom, evt->u.update.bottom);
259 if (evts->num_used == evts->num_alloc)
261 evts->num_alloc += 16;
262 evts->events = realloc( evts->events, evts->num_alloc * sizeof(*evt) );
263 assert(evts->events);
265 evts->events[evts->num_used++] = *evt;
267 wake_up( &evts->obj, 0 );
270 /* retrieves events from the console's renderer events list */
271 static void console_input_events_get( struct console_input_events* evts )
273 data_size_t num = get_reply_max_size() / sizeof(evts->events[0]);
275 if (num > evts->num_used) num = evts->num_used;
276 set_reply_data( evts->events, num * sizeof(evts->events[0]) );
277 if (num < evts->num_used)
279 memmove( &evts->events[0], &evts->events[num],
280 (evts->num_used - num) * sizeof(evts->events[0]) );
282 evts->num_used -= num;
285 static struct console_input_events *create_console_input_events(void)
287 struct console_input_events* evt;
289 if (!(evt = alloc_object( &console_input_events_ops ))) return NULL;
290 evt->num_alloc = evt->num_used = 0;
295 static struct object *create_console_input( struct thread* renderer, int fd )
297 struct console_input *console_input;
299 if (!(console_input = alloc_object( &console_input_ops ))) return NULL;
300 console_input->renderer = renderer;
301 console_input->mode = ENABLE_PROCESSED_INPUT | ENABLE_LINE_INPUT |
302 ENABLE_ECHO_INPUT | ENABLE_MOUSE_INPUT;
303 console_input->num_proc = 0;
304 console_input->active = NULL;
305 console_input->recnum = 0;
306 console_input->records = NULL;
307 console_input->evt = renderer ? create_console_input_events() : NULL;
308 console_input->title = NULL;
309 console_input->history_size = 50;
310 console_input->history = calloc( console_input->history_size, sizeof(WCHAR*) );
311 console_input->history_index = 0;
312 console_input->history_mode = 0;
313 console_input->edition_mode = 0;
314 console_input->input_cp = 0;
315 console_input->output_cp = 0;
316 console_input->win = 0;
317 console_input->event = create_event( NULL, NULL, 0, 1, 0, NULL );
318 console_input->fd = NULL;
320 if (!console_input->history || (renderer && !console_input->evt) || !console_input->event)
322 release_object( console_input );
325 if (fd != -1) /* bare console */
327 if (!(console_input->fd = create_anonymous_fd( &console_fd_ops, fd, &console_input->obj,
328 FILE_SYNCHRONOUS_IO_NONALERT )))
330 release_object( console_input );
333 allow_fd_caching( console_input->fd );
336 return &console_input->obj;
339 static void generate_sb_initial_events( struct console_input *console_input )
341 struct screen_buffer *screen_buffer = console_input->active;
342 struct console_renderer_event evt;
344 evt.event = CONSOLE_RENDERER_ACTIVE_SB_EVENT;
345 memset(&evt.u, 0, sizeof(evt.u));
346 console_input_events_append( console_input, &evt );
348 evt.event = CONSOLE_RENDERER_SB_RESIZE_EVENT;
349 evt.u.resize.width = screen_buffer->width;
350 evt.u.resize.height = screen_buffer->height;
351 console_input_events_append( console_input, &evt );
353 evt.event = CONSOLE_RENDERER_DISPLAY_EVENT;
354 evt.u.display.left = screen_buffer->win.left;
355 evt.u.display.top = screen_buffer->win.top;
356 evt.u.display.width = screen_buffer->win.right - screen_buffer->win.left + 1;
357 evt.u.display.height = screen_buffer->win.bottom - screen_buffer->win.top + 1;
358 console_input_events_append( console_input, &evt );
360 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
361 evt.u.update.top = 0;
362 evt.u.update.bottom = screen_buffer->height - 1;
363 console_input_events_append( console_input, &evt );
365 evt.event = CONSOLE_RENDERER_CURSOR_GEOM_EVENT;
366 evt.u.cursor_geom.size = screen_buffer->cursor_size;
367 evt.u.cursor_geom.visible = screen_buffer->cursor_visible;
368 console_input_events_append( console_input, &evt );
370 evt.event = CONSOLE_RENDERER_CURSOR_POS_EVENT;
371 evt.u.cursor_pos.x = screen_buffer->cursor_x;
372 evt.u.cursor_pos.y = screen_buffer->cursor_y;
373 console_input_events_append( console_input, &evt );
376 static struct screen_buffer *create_console_output( struct console_input *console_input, int fd )
378 struct screen_buffer *screen_buffer;
381 if (!(screen_buffer = alloc_object( &screen_buffer_ops ))) return NULL;
382 screen_buffer->mode = ENABLE_PROCESSED_OUTPUT | ENABLE_WRAP_AT_EOL_OUTPUT;
383 screen_buffer->input = console_input;
384 screen_buffer->cursor_size = 100;
385 screen_buffer->cursor_visible = 1;
386 screen_buffer->width = 80;
387 screen_buffer->height = 150;
388 screen_buffer->max_width = 80;
389 screen_buffer->max_height = 25;
390 screen_buffer->cursor_x = 0;
391 screen_buffer->cursor_y = 0;
392 screen_buffer->attr = 0x0F;
393 screen_buffer->win.left = 0;
394 screen_buffer->win.right = screen_buffer->max_width - 1;
395 screen_buffer->win.top = 0;
396 screen_buffer->win.bottom = screen_buffer->max_height - 1;
398 screen_buffer->fd = NULL;
401 if (!(screen_buffer->fd = create_anonymous_fd( &console_fd_ops, fd, &screen_buffer->obj,
402 FILE_SYNCHRONOUS_IO_NONALERT )))
404 release_object( screen_buffer );
407 allow_fd_caching(screen_buffer->fd);
410 list_add_head( &screen_buffer_list, &screen_buffer->entry );
412 if (!(screen_buffer->data = malloc( screen_buffer->width * screen_buffer->height *
413 sizeof(*screen_buffer->data) )))
415 release_object( screen_buffer );
418 /* clear the first row */
419 for (i = 0; i < screen_buffer->width; i++) screen_buffer->data[i] = empty_char_info;
420 /* and copy it to all other rows */
421 for (i = 1; i < screen_buffer->height; i++)
422 memcpy( &screen_buffer->data[i * screen_buffer->width], screen_buffer->data,
423 screen_buffer->width * sizeof(char_info_t) );
425 if (!console_input->active)
427 console_input->active = (struct screen_buffer*)grab_object( screen_buffer );
428 generate_sb_initial_events( console_input );
430 return screen_buffer;
433 /* free the console for this process */
434 int free_console( struct process *process )
436 struct console_input* console = process->console;
438 if (!console) return 0;
440 process->console = NULL;
441 if (--console->num_proc == 0 && console->renderer)
443 /* all processes have terminated... tell the renderer to terminate too */
444 struct console_renderer_event evt;
445 evt.event = CONSOLE_RENDERER_EXIT_EVENT;
446 memset(&evt.u, 0, sizeof(evt.u));
447 console_input_events_append( console, &evt );
449 release_object( console );
454 /* let process inherit the console from parent... this handle two cases :
455 * 1/ generic console inheritance
456 * 2/ parent is a renderer which launches process, and process should attach to the console
457 * renderered by parent
459 void inherit_console(struct thread *parent_thread, struct process *process, obj_handle_t hconin)
462 struct process* parent = parent_thread->process;
464 /* if parent is a renderer, then attach current process to its console
469 struct console_input* console;
471 /* FIXME: should we check some access rights ? */
472 if ((console = (struct console_input*)get_handle_obj( parent, hconin,
473 0, &console_input_ops )))
475 if (console->renderer == parent_thread)
477 process->console = (struct console_input*)grab_object( console );
478 process->console->num_proc++;
481 release_object( console );
483 else clear_error(); /* ignore error */
485 /* otherwise, if parent has a console, attach child to this console */
486 if (!done && parent->console)
488 process->console = (struct console_input*)grab_object( parent->console );
489 process->console->num_proc++;
493 struct thread *console_get_renderer( struct console_input *console )
495 return console->renderer;
498 static struct console_input* console_input_get( obj_handle_t handle, unsigned access )
500 struct console_input* console = NULL;
503 console = (struct console_input *)get_handle_obj( current->process, handle,
504 access, &console_input_ops );
505 else if (current->process->console)
507 console = (struct console_input *)grab_object( current->process->console );
510 if (!console && !get_error()) set_error(STATUS_INVALID_PARAMETER);
514 struct console_signal_info
516 struct console_input *console;
521 static int propagate_console_signal_cb(struct process *process, void *user)
523 struct console_signal_info* csi = (struct console_signal_info*)user;
525 if (process->console == csi->console && process->running_threads &&
526 (!csi->group || process->group_id == csi->group))
528 /* find a suitable thread to signal */
529 struct thread *thread;
530 LIST_FOR_EACH_ENTRY( thread, &process->thread_list, struct thread, proc_entry )
532 if (send_thread_signal( thread, csi->signal )) break;
538 static void propagate_console_signal( struct console_input *console,
539 int sig, process_id_t group_id )
541 struct console_signal_info csi;
545 set_error( STATUS_INVALID_PARAMETER );
548 /* FIXME: should support the other events (like CTRL_BREAK) */
549 if (sig != CTRL_C_EVENT)
551 set_error( STATUS_NOT_IMPLEMENTED );
554 csi.console = console;
556 csi.group = group_id;
558 enum_processes(propagate_console_signal_cb, &csi);
561 static int get_console_mode( obj_handle_t handle, int *bare )
566 if ((obj = get_handle_obj( current->process, handle, FILE_READ_PROPERTIES, NULL )))
568 if (obj->ops == &console_input_ops)
570 ret = ((struct console_input *)obj)->mode;
571 *bare = console_input_is_bare((struct console_input *)obj);
573 else if (obj->ops == &screen_buffer_ops)
575 ret = ((struct screen_buffer *)obj)->mode;
576 *bare = console_input_is_bare(((struct screen_buffer *)obj)->input);
579 set_error( STATUS_OBJECT_TYPE_MISMATCH );
580 release_object( obj );
585 /* changes the mode of either a console input or a screen buffer */
586 static int set_console_mode( obj_handle_t handle, int mode )
591 if (!(obj = get_handle_obj( current->process, handle, FILE_WRITE_PROPERTIES, NULL )))
593 if (obj->ops == &console_input_ops)
595 /* FIXME: if we remove the edit mode bits, we need (???) to clean up the history */
596 ((struct console_input *)obj)->mode = mode;
599 else if (obj->ops == &screen_buffer_ops)
601 ((struct screen_buffer *)obj)->mode = mode;
604 else set_error( STATUS_OBJECT_TYPE_MISMATCH );
605 release_object( obj );
609 /* add input events to a console input queue */
610 static int write_console_input( struct console_input* console, int count,
611 const INPUT_RECORD *records )
613 INPUT_RECORD *new_rec;
615 if (!count) return 0;
616 if (!(new_rec = realloc( console->records,
617 (console->recnum + count) * sizeof(INPUT_RECORD) )))
619 set_error( STATUS_NO_MEMORY );
620 release_object( console );
623 console->records = new_rec;
624 memcpy( new_rec + console->recnum, records, count * sizeof(INPUT_RECORD) );
626 if (console->mode & ENABLE_PROCESSED_INPUT)
631 if (records[i].EventType == KEY_EVENT &&
632 records[i].Event.KeyEvent.uChar.UnicodeChar == 'C' - 64 &&
633 !(records[i].Event.KeyEvent.dwControlKeyState & ENHANCED_KEY))
636 memcpy( &console->records[console->recnum + i],
637 &console->records[console->recnum + i + 1],
638 (count - i - 1) * sizeof(INPUT_RECORD) );
640 if (records[i].Event.KeyEvent.bKeyDown)
642 /* send SIGINT to all processes attached to this console */
643 propagate_console_signal( console, CTRL_C_EVENT, 0 );
649 if (!console->recnum && count) set_event( console->event );
650 console->recnum += count;
654 /* retrieve a pointer to the console input records */
655 static int read_console_input( obj_handle_t handle, int count, int flush )
657 struct console_input *console;
659 if (!(console = (struct console_input *)get_handle_obj( current->process, handle,
660 FILE_READ_DATA, &console_input_ops )))
665 /* special case: do not retrieve anything, but return
666 * the total number of records available */
667 count = console->recnum;
671 if (count > console->recnum) count = console->recnum;
672 set_reply_data( console->records, count * sizeof(INPUT_RECORD) );
677 for (i = count; i < console->recnum; i++)
678 console->records[i-count] = console->records[i];
679 if ((console->recnum -= count) > 0)
681 INPUT_RECORD *new_rec = realloc( console->records,
682 console->recnum * sizeof(INPUT_RECORD) );
683 if (new_rec) console->records = new_rec;
687 free( console->records );
688 console->records = NULL;
689 reset_event( console->event );
692 release_object( console );
696 /* set misc console input information */
697 static int set_console_input_info( const struct set_console_input_info_request *req,
698 const WCHAR *title, data_size_t len )
700 struct console_input *console;
701 struct console_renderer_event evt;
703 if (!(console = console_input_get( req->handle, FILE_WRITE_PROPERTIES ))) goto error;
704 if (console_input_is_bare(console) &&
705 (req->mask & (SET_CONSOLE_INPUT_INFO_ACTIVE_SB|
706 SET_CONSOLE_INPUT_INFO_WIN)))
708 set_error( STATUS_UNSUCCESSFUL );
712 memset(&evt.u, 0, sizeof(evt.u));
713 if (req->mask & SET_CONSOLE_INPUT_INFO_ACTIVE_SB)
715 struct screen_buffer *screen_buffer;
717 screen_buffer = (struct screen_buffer *)get_handle_obj( current->process, req->active_sb,
718 FILE_WRITE_PROPERTIES, &screen_buffer_ops );
719 if (!screen_buffer || screen_buffer->input != console)
721 set_error( STATUS_INVALID_HANDLE );
722 if (screen_buffer) release_object( screen_buffer );
726 if (screen_buffer != console->active)
728 if (console->active) release_object( console->active );
729 console->active = screen_buffer;
730 generate_sb_initial_events( console );
733 release_object( screen_buffer );
735 if (req->mask & SET_CONSOLE_INPUT_INFO_TITLE)
737 WCHAR *new_title = mem_alloc( len + sizeof(WCHAR) );
740 memcpy( new_title, title, len );
741 new_title[len / sizeof(WCHAR)] = 0;
742 free( console->title );
743 console->title = new_title;
744 evt.event = CONSOLE_RENDERER_TITLE_EVENT;
745 console_input_events_append( console, &evt );
748 if (req->mask & SET_CONSOLE_INPUT_INFO_HISTORY_MODE)
750 console->history_mode = req->history_mode;
752 if ((req->mask & SET_CONSOLE_INPUT_INFO_HISTORY_SIZE) &&
753 console->history_size != req->history_size)
759 if (req->history_size)
761 mem = mem_alloc( req->history_size * sizeof(WCHAR*) );
762 if (!mem) goto error;
763 memset( mem, 0, req->history_size * sizeof(WCHAR*) );
766 delta = (console->history_index > req->history_size) ?
767 (console->history_index - req->history_size) : 0;
769 for (i = delta; i < console->history_index; i++)
771 mem[i - delta] = console->history[i];
772 console->history[i] = NULL;
774 console->history_index -= delta;
776 for (i = 0; i < console->history_size; i++)
777 free( console->history[i] );
778 free( console->history );
779 console->history = mem;
780 console->history_size = req->history_size;
782 if (req->mask & SET_CONSOLE_INPUT_INFO_EDITION_MODE)
784 console->edition_mode = req->edition_mode;
786 if (req->mask & SET_CONSOLE_INPUT_INFO_INPUT_CODEPAGE)
788 console->input_cp = req->input_cp;
790 if (req->mask & SET_CONSOLE_INPUT_INFO_OUTPUT_CODEPAGE)
792 console->output_cp = req->output_cp;
794 if (req->mask & SET_CONSOLE_INPUT_INFO_WIN)
796 console->win = req->win;
798 release_object( console );
801 if (console) release_object( console );
805 /* resize a screen buffer */
806 static int change_screen_buffer_size( struct screen_buffer *screen_buffer,
807 int new_width, int new_height )
809 int i, old_width, old_height, copy_width, copy_height;
810 char_info_t *new_data;
812 if (!(new_data = malloc( new_width * new_height * sizeof(*new_data) )))
814 set_error( STATUS_NO_MEMORY );
817 old_width = screen_buffer->width;
818 old_height = screen_buffer->height;
819 copy_width = min( old_width, new_width );
820 copy_height = min( old_height, new_height );
822 /* copy all the rows */
823 for (i = 0; i < copy_height; i++)
825 memcpy( &new_data[i * new_width], &screen_buffer->data[i * old_width],
826 copy_width * sizeof(char_info_t) );
829 /* clear the end of each row */
830 if (new_width > old_width)
833 for (i = old_width; i < new_width; i++) new_data[i] = empty_char_info;
834 /* and blast it to the other rows */
835 for (i = 1; i < copy_height; i++)
836 memcpy( &new_data[i * new_width + old_width], &new_data[old_width],
837 (new_width - old_width) * sizeof(char_info_t) );
840 /* clear remaining rows */
841 if (new_height > old_height)
844 for (i = 0; i < new_width; i++) new_data[old_height * new_width + i] = empty_char_info;
845 /* and blast it to the other rows */
846 for (i = old_height+1; i < new_height; i++)
847 memcpy( &new_data[i * new_width], &new_data[old_height * new_width],
848 new_width * sizeof(char_info_t) );
850 free( screen_buffer->data );
851 screen_buffer->data = new_data;
852 screen_buffer->width = new_width;
853 screen_buffer->height = new_height;
857 /* set misc screen buffer information */
858 static int set_console_output_info( struct screen_buffer *screen_buffer,
859 const struct set_console_output_info_request *req )
861 struct console_renderer_event evt;
863 memset(&evt.u, 0, sizeof(evt.u));
864 if (req->mask & SET_CONSOLE_OUTPUT_INFO_CURSOR_GEOM)
866 if (req->cursor_size < 1 || req->cursor_size > 100)
868 set_error( STATUS_INVALID_PARAMETER );
871 if (screen_buffer->cursor_size != req->cursor_size ||
872 screen_buffer->cursor_visible != req->cursor_visible)
874 screen_buffer->cursor_size = req->cursor_size;
875 screen_buffer->cursor_visible = req->cursor_visible;
876 evt.event = CONSOLE_RENDERER_CURSOR_GEOM_EVENT;
877 evt.u.cursor_geom.size = req->cursor_size;
878 evt.u.cursor_geom.visible = req->cursor_visible;
879 console_input_events_append( screen_buffer->input, &evt );
882 if (req->mask & SET_CONSOLE_OUTPUT_INFO_CURSOR_POS)
884 if (req->cursor_x < 0 || req->cursor_x >= screen_buffer->width ||
885 req->cursor_y < 0 || req->cursor_y >= screen_buffer->height)
887 set_error( STATUS_INVALID_PARAMETER );
890 if (screen_buffer->cursor_x != req->cursor_x || screen_buffer->cursor_y != req->cursor_y)
892 screen_buffer->cursor_x = req->cursor_x;
893 screen_buffer->cursor_y = req->cursor_y;
894 evt.event = CONSOLE_RENDERER_CURSOR_POS_EVENT;
895 evt.u.cursor_pos.x = req->cursor_x;
896 evt.u.cursor_pos.y = req->cursor_y;
897 console_input_events_append( screen_buffer->input, &evt );
900 if (req->mask & SET_CONSOLE_OUTPUT_INFO_SIZE)
904 /* new screen-buffer cannot be smaller than actual window */
905 if (req->width < screen_buffer->win.right - screen_buffer->win.left + 1 ||
906 req->height < screen_buffer->win.bottom - screen_buffer->win.top + 1)
908 set_error( STATUS_INVALID_PARAMETER );
911 /* FIXME: there are also some basic minimum and max size to deal with */
912 if (!change_screen_buffer_size( screen_buffer, req->width, req->height )) return 0;
914 evt.event = CONSOLE_RENDERER_SB_RESIZE_EVENT;
915 evt.u.resize.width = req->width;
916 evt.u.resize.height = req->height;
917 console_input_events_append( screen_buffer->input, &evt );
919 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
920 evt.u.update.top = 0;
921 evt.u.update.bottom = screen_buffer->height - 1;
922 console_input_events_append( screen_buffer->input, &evt );
924 /* scroll window to display sb */
925 if (screen_buffer->win.right >= req->width)
927 screen_buffer->win.right -= screen_buffer->win.left;
928 screen_buffer->win.left = 0;
930 if (screen_buffer->win.bottom >= req->height)
932 screen_buffer->win.bottom -= screen_buffer->win.top;
933 screen_buffer->win.top = 0;
935 /* reset cursor if needed (normally, if cursor was outside of new sb, the
936 * window has been shifted so that the new position of the cursor will be
939 if (screen_buffer->cursor_x >= req->width)
941 screen_buffer->cursor_x = req->width - 1;
944 if (screen_buffer->cursor_y >= req->height)
946 screen_buffer->cursor_y = req->height - 1;
951 evt.event = CONSOLE_RENDERER_CURSOR_POS_EVENT;
952 evt.u.cursor_pos.x = req->cursor_x;
953 evt.u.cursor_pos.y = req->cursor_y;
954 console_input_events_append( screen_buffer->input, &evt );
957 if (screen_buffer == screen_buffer->input->active &&
958 screen_buffer->input->mode & ENABLE_WINDOW_INPUT)
961 ir.EventType = WINDOW_BUFFER_SIZE_EVENT;
962 ir.Event.WindowBufferSizeEvent.dwSize.X = req->width;
963 ir.Event.WindowBufferSizeEvent.dwSize.Y = req->height;
964 write_console_input( screen_buffer->input, 1, &ir );
967 if (req->mask & SET_CONSOLE_OUTPUT_INFO_ATTR)
969 screen_buffer->attr = req->attr;
971 if (req->mask & SET_CONSOLE_OUTPUT_INFO_DISPLAY_WINDOW)
973 if (req->win_left < 0 || req->win_left > req->win_right ||
974 req->win_right >= screen_buffer->width ||
975 req->win_top < 0 || req->win_top > req->win_bottom ||
976 req->win_bottom >= screen_buffer->height)
978 set_error( STATUS_INVALID_PARAMETER );
981 if (screen_buffer->win.left != req->win_left || screen_buffer->win.top != req->win_top ||
982 screen_buffer->win.right != req->win_right || screen_buffer->win.bottom != req->win_bottom)
984 screen_buffer->win.left = req->win_left;
985 screen_buffer->win.top = req->win_top;
986 screen_buffer->win.right = req->win_right;
987 screen_buffer->win.bottom = req->win_bottom;
988 evt.event = CONSOLE_RENDERER_DISPLAY_EVENT;
989 evt.u.display.left = req->win_left;
990 evt.u.display.top = req->win_top;
991 evt.u.display.width = req->win_right - req->win_left + 1;
992 evt.u.display.height = req->win_bottom - req->win_top + 1;
993 console_input_events_append( screen_buffer->input, &evt );
996 if (req->mask & SET_CONSOLE_OUTPUT_INFO_MAX_SIZE)
998 /* can only be done by renderer */
999 if (current->process->console != screen_buffer->input)
1001 set_error( STATUS_INVALID_PARAMETER );
1005 screen_buffer->max_width = req->max_width;
1006 screen_buffer->max_height = req->max_height;
1012 /* appends a new line to history (history is a fixed size array) */
1013 static void console_input_append_hist( struct console_input* console, const WCHAR* buf, data_size_t len )
1015 WCHAR* ptr = mem_alloc( (len + 1) * sizeof(WCHAR) );
1020 if (!console || !console->history_size)
1022 set_error( STATUS_INVALID_PARAMETER ); /* FIXME */
1027 memcpy( ptr, buf, len * sizeof(WCHAR) );
1030 if (console->history_mode && console->history_index &&
1031 strncmpW( console->history[console->history_index - 1], ptr, len * sizeof(WCHAR) ) == 0)
1033 /* ok, mode ask us to not use twice the same string...
1034 * so just free mem and returns
1036 set_error( STATUS_ALIAS_EXISTS );
1041 if (console->history_index < console->history_size)
1043 console->history[console->history_index++] = ptr;
1047 free( console->history[0]) ;
1048 memmove( &console->history[0], &console->history[1],
1049 (console->history_size - 1) * sizeof(WCHAR*) );
1050 console->history[console->history_size - 1] = ptr;
1054 /* returns a line from the cache */
1055 static data_size_t console_input_get_hist( struct console_input *console, int index )
1057 data_size_t ret = 0;
1059 if (index >= console->history_index) set_error( STATUS_INVALID_PARAMETER );
1062 ret = strlenW( console->history[index] ) * sizeof(WCHAR);
1063 set_reply_data( console->history[index], min( ret, get_reply_max_size() ));
1069 static void console_input_dump( struct object *obj, int verbose )
1071 struct console_input *console = (struct console_input *)obj;
1072 assert( obj->ops == &console_input_ops );
1073 fprintf( stderr, "Console input active=%p evt=%p\n",
1074 console->active, console->evt );
1077 static void console_input_destroy( struct object *obj )
1079 struct console_input* console_in = (struct console_input *)obj;
1080 struct screen_buffer* curr;
1083 assert( obj->ops == &console_input_ops );
1084 free( console_in->title );
1085 free( console_in->records );
1087 if (console_in->active) release_object( console_in->active );
1088 console_in->active = NULL;
1090 LIST_FOR_EACH_ENTRY( curr, &screen_buffer_list, struct screen_buffer, entry )
1092 if (curr->input == console_in) curr->input = NULL;
1095 if (console_in->evt)
1097 release_object( console_in->evt );
1098 console_in->evt = NULL;
1100 release_object( console_in->event );
1102 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 if (screen_buffer->fd) release_object( screen_buffer->fd );
1140 free( screen_buffer->data );
1143 static struct fd *screen_buffer_get_fd( struct object *obj )
1145 struct screen_buffer *screen_buffer = (struct screen_buffer*)obj;
1146 assert( obj->ops == &screen_buffer_ops );
1147 return screen_buffer->fd ? (struct fd*)grab_object( screen_buffer->fd ) : NULL;
1150 /* write data into a screen buffer */
1151 static int write_console_output( struct screen_buffer *screen_buffer, data_size_t size,
1152 const void* data, enum char_info_mode mode,
1153 int x, int y, int wrap )
1156 char_info_t *end, *dest = screen_buffer->data + y * screen_buffer->width + x;
1158 if (y >= screen_buffer->height) return 0;
1161 end = screen_buffer->data + screen_buffer->height * screen_buffer->width;
1163 end = screen_buffer->data + (y+1) * screen_buffer->width;
1167 case CHAR_INFO_MODE_TEXT:
1169 const WCHAR *ptr = data;
1170 for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++) dest->ch = ptr[i];
1173 case CHAR_INFO_MODE_ATTR:
1175 const unsigned short *ptr = data;
1176 for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++) dest->attr = ptr[i];
1179 case CHAR_INFO_MODE_TEXTATTR:
1181 const char_info_t *ptr = data;
1182 for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++) *dest = ptr[i];
1185 case CHAR_INFO_MODE_TEXTSTDATTR:
1187 const WCHAR *ptr = data;
1188 for (i = 0; i < size/sizeof(*ptr) && dest < end; dest++, i++)
1191 dest->attr = screen_buffer->attr;
1196 set_error( STATUS_INVALID_PARAMETER );
1200 if (i && screen_buffer == screen_buffer->input->active)
1202 struct console_renderer_event evt;
1203 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
1204 memset(&evt.u, 0, sizeof(evt.u));
1205 evt.u.update.top = y + x / screen_buffer->width;
1206 evt.u.update.bottom = y + (x + i - 1) / screen_buffer->width;
1207 console_input_events_append( screen_buffer->input, &evt );
1212 /* fill a screen buffer with uniform data */
1213 static int fill_console_output( struct screen_buffer *screen_buffer, char_info_t data,
1214 enum char_info_mode mode, int x, int y, int count, int wrap )
1217 char_info_t *end, *dest = screen_buffer->data + y * screen_buffer->width + x;
1219 if (y >= screen_buffer->height) return 0;
1222 end = screen_buffer->data + screen_buffer->height * screen_buffer->width;
1224 end = screen_buffer->data + (y+1) * screen_buffer->width;
1226 if (count > end - dest) count = end - dest;
1230 case CHAR_INFO_MODE_TEXT:
1231 for (i = 0; i < count; i++) dest[i].ch = data.ch;
1233 case CHAR_INFO_MODE_ATTR:
1234 for (i = 0; i < count; i++) dest[i].attr = data.attr;
1236 case CHAR_INFO_MODE_TEXTATTR:
1237 for (i = 0; i < count; i++) dest[i] = data;
1239 case CHAR_INFO_MODE_TEXTSTDATTR:
1240 for (i = 0; i < count; i++)
1242 dest[i].ch = data.ch;
1243 dest[i].attr = screen_buffer->attr;
1247 set_error( STATUS_INVALID_PARAMETER );
1251 if (count && screen_buffer == screen_buffer->input->active)
1253 struct console_renderer_event evt;
1254 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
1255 memset(&evt.u, 0, sizeof(evt.u));
1256 evt.u.update.top = y;
1257 evt.u.update.bottom = (y * screen_buffer->width + x + count - 1) / screen_buffer->width;
1258 console_input_events_append( screen_buffer->input, &evt );
1263 /* read data from a screen buffer */
1264 static void read_console_output( struct screen_buffer *screen_buffer, int x, int y,
1265 enum char_info_mode mode, int wrap )
1268 char_info_t *end, *src = screen_buffer->data + y * screen_buffer->width + x;
1270 if (y >= screen_buffer->height) return;
1273 end = screen_buffer->data + screen_buffer->height * screen_buffer->width;
1275 end = screen_buffer->data + (y+1) * screen_buffer->width;
1279 case CHAR_INFO_MODE_TEXT:
1282 int count = min( end - src, get_reply_max_size() / sizeof(*data) );
1283 if ((data = set_reply_data_size( count * sizeof(*data) )))
1285 for (i = 0; i < count; i++) data[i] = src[i].ch;
1289 case CHAR_INFO_MODE_ATTR:
1291 unsigned short *data;
1292 int count = min( end - src, get_reply_max_size() / sizeof(*data) );
1293 if ((data = set_reply_data_size( count * sizeof(*data) )))
1295 for (i = 0; i < count; i++) data[i] = src[i].attr;
1299 case CHAR_INFO_MODE_TEXTATTR:
1302 int count = min( end - src, get_reply_max_size() / sizeof(*data) );
1303 if ((data = set_reply_data_size( count * sizeof(*data) )))
1305 for (i = 0; i < count; i++) data[i] = src[i];
1310 set_error( STATUS_INVALID_PARAMETER );
1315 /* scroll parts of a screen buffer */
1316 static void scroll_console_output( struct screen_buffer *screen_buffer, int xsrc, int ysrc, int xdst, int ydst,
1320 char_info_t *psrc, *pdst;
1321 struct console_renderer_event evt;
1323 if (xsrc < 0 || ysrc < 0 || xdst < 0 || ydst < 0 ||
1324 xsrc + w > screen_buffer->width ||
1325 xdst + w > screen_buffer->width ||
1326 ysrc + h > screen_buffer->height ||
1327 ydst + h > screen_buffer->height ||
1330 set_error( STATUS_INVALID_PARAMETER );
1336 psrc = &screen_buffer->data[(ysrc + h - 1) * screen_buffer->width + xsrc];
1337 pdst = &screen_buffer->data[(ydst + h - 1) * screen_buffer->width + xdst];
1339 for (j = h; j > 0; j--)
1341 memcpy(pdst, psrc, w * sizeof(*pdst) );
1342 pdst -= screen_buffer->width;
1343 psrc -= screen_buffer->width;
1348 psrc = &screen_buffer->data[ysrc * screen_buffer->width + xsrc];
1349 pdst = &screen_buffer->data[ydst * screen_buffer->width + xdst];
1351 for (j = 0; j < h; j++)
1353 /* we use memmove here because when psrc and pdst are the same,
1354 * copies are done on the same row, so the dst and src blocks
1356 memmove( pdst, psrc, w * sizeof(*pdst) );
1357 pdst += screen_buffer->width;
1358 psrc += screen_buffer->width;
1362 /* FIXME: this could be enhanced, by signalling scroll */
1363 evt.event = CONSOLE_RENDERER_UPDATE_EVENT;
1364 memset(&evt.u, 0, sizeof(evt.u));
1365 evt.u.update.top = min(ysrc, ydst);
1366 evt.u.update.bottom = max(ysrc, ydst) + h - 1;
1367 console_input_events_append( screen_buffer->input, &evt );
1370 /* allocate a console for the renderer */
1371 DECL_HANDLER(alloc_console)
1373 obj_handle_t in = 0;
1374 obj_handle_t evt = 0;
1375 struct process *process;
1376 struct thread *renderer;
1377 struct console_input *console;
1383 /* renderer is current, console to be attached to parent process */
1385 if (!(process = current->process->parent))
1387 set_error( STATUS_ACCESS_DENIED );
1390 grab_object( process );
1393 /* no renderer, console to be attached to current process */
1395 process = current->process;
1396 grab_object( process );
1399 /* renderer is current, console to be attached to req->pid */
1401 if (!(process = get_process_from_id( req->pid ))) return;
1404 if (process != current->process && process->console)
1406 set_error( STATUS_ACCESS_DENIED );
1409 if (req->input_fd != -1)
1411 if ((fd = thread_get_inflight_fd( current, req->input_fd )) == -1)
1413 set_error( STATUS_INVALID_PARAMETER );
1419 if ((console = (struct console_input*)create_console_input( renderer, fd )))
1421 if ((in = alloc_handle( current->process, console, req->access, req->attributes )))
1423 if (!console->evt ||
1424 (evt = alloc_handle( current->process, console->evt, SYNCHRONIZE|GENERIC_READ|GENERIC_WRITE, 0 )))
1426 process->console = (struct console_input*)grab_object( console );
1427 console->num_proc++;
1428 reply->handle_in = in;
1430 release_object( console );
1433 close_handle( current->process, in );
1435 free_console( process );
1438 release_object( process );
1441 /* free the console of the current process */
1442 DECL_HANDLER(free_console)
1444 free_console( current->process );
1447 /* let the renderer peek the events it's waiting on */
1448 DECL_HANDLER(get_console_renderer_events)
1450 struct console_input_events *evt;
1452 evt = (struct console_input_events *)get_handle_obj( current->process, req->handle,
1453 FILE_READ_PROPERTIES, &console_input_events_ops );
1455 console_input_events_get( evt );
1456 release_object( evt );
1459 /* open a handle to the process console */
1460 DECL_HANDLER(open_console)
1462 struct object *obj = NULL;
1467 if (current->process->console)
1468 obj = grab_object( (struct object*)current->process->console );
1470 else if (req->from == (obj_handle_t)1)
1472 if (current->process->console && current->process->console->active)
1473 obj = grab_object( (struct object*)current->process->console->active );
1475 else if ((obj = get_handle_obj( current->process, req->from,
1476 FILE_READ_PROPERTIES|FILE_WRITE_PROPERTIES, &console_input_ops )))
1478 struct console_input *console = (struct console_input *)obj;
1479 obj = (console->active) ? grab_object( console->active ) : NULL;
1480 release_object( console );
1483 /* FIXME: req->share is not used (as in screen buffer creation) */
1486 reply->handle = alloc_handle( current->process, obj, req->access, req->attributes );
1487 release_object( obj );
1489 else if (!get_error()) set_error( STATUS_ACCESS_DENIED );
1492 /* set info about a console input */
1493 DECL_HANDLER(set_console_input_info)
1495 set_console_input_info( req, get_req_data(), get_req_data_size() );
1498 /* get info about a console (output only) */
1499 DECL_HANDLER(get_console_input_info)
1501 struct console_input *console;
1503 if (!(console = console_input_get( req->handle, FILE_READ_PROPERTIES ))) return;
1506 data_size_t len = strlenW( console->title ) * sizeof(WCHAR);
1507 if (len > get_reply_max_size()) len = get_reply_max_size();
1508 set_reply_data( console->title, len );
1510 reply->history_mode = console->history_mode;
1511 reply->history_size = console->history_size;
1512 reply->history_index = console->history_index;
1513 reply->edition_mode = console->edition_mode;
1514 reply->input_cp = console->input_cp;
1515 reply->output_cp = console->output_cp;
1516 reply->win = console->win;
1518 release_object( console );
1521 /* get a console mode (input or output) */
1522 DECL_HANDLER(get_console_mode)
1524 reply->mode = get_console_mode( req->handle, &reply->is_bare );
1527 /* set a console mode (input or output) */
1528 DECL_HANDLER(set_console_mode)
1530 set_console_mode( req->handle, req->mode );
1533 /* add input records to a console input queue */
1534 DECL_HANDLER(write_console_input)
1536 struct console_input *console;
1539 if (!(console = (struct console_input *)get_handle_obj( current->process, req->handle,
1540 FILE_WRITE_PROPERTIES, &console_input_ops )))
1542 reply->written = write_console_input( console, get_req_data_size() / sizeof(INPUT_RECORD),
1544 release_object( console );
1547 /* fetch input records from a console input queue */
1548 DECL_HANDLER(read_console_input)
1550 int count = get_reply_max_size() / sizeof(INPUT_RECORD);
1551 reply->read = read_console_input( req->handle, count, req->flush );
1554 /* appends a string to console's history */
1555 DECL_HANDLER(append_console_input_history)
1557 struct console_input *console;
1559 if (!(console = console_input_get( req->handle, FILE_WRITE_PROPERTIES ))) return;
1560 console_input_append_hist( console, get_req_data(), get_req_data_size() / sizeof(WCHAR) );
1561 release_object( console );
1564 /* appends a string to console's history */
1565 DECL_HANDLER(get_console_input_history)
1567 struct console_input *console;
1569 if (!(console = console_input_get( req->handle, FILE_READ_PROPERTIES ))) return;
1570 reply->total = console_input_get_hist( console, req->index );
1571 release_object( console );
1574 /* creates a screen buffer */
1575 DECL_HANDLER(create_console_output)
1577 struct console_input* console;
1578 struct screen_buffer* screen_buffer;
1583 if ((fd = thread_get_inflight_fd( current, req->fd )) == -1)
1585 set_error( STATUS_INVALID_HANDLE );
1590 if (!(console = console_input_get( req->handle_in, FILE_WRITE_PROPERTIES )))
1595 if (console_input_is_bare( console ) ^ (fd != -1))
1598 set_error( STATUS_INVALID_HANDLE );
1602 screen_buffer = create_console_output( console, fd );
1605 /* FIXME: should store sharing and test it when opening the CONOUT$ device
1606 * see file.c on how this could be done */
1607 reply->handle_out = alloc_handle( current->process, screen_buffer, req->access, req->attributes );
1608 release_object( screen_buffer );
1610 release_object( console );
1613 /* set info about a console screen buffer */
1614 DECL_HANDLER(set_console_output_info)
1616 struct screen_buffer *screen_buffer;
1618 if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle,
1619 FILE_WRITE_PROPERTIES, &screen_buffer_ops)))
1621 set_console_output_info( screen_buffer, req );
1622 release_object( screen_buffer );
1626 /* get info about a console screen buffer */
1627 DECL_HANDLER(get_console_output_info)
1629 struct screen_buffer *screen_buffer;
1631 if ((screen_buffer = (struct screen_buffer *)get_handle_obj( current->process, req->handle,
1632 FILE_READ_PROPERTIES, &screen_buffer_ops)))
1634 reply->cursor_size = screen_buffer->cursor_size;
1635 reply->cursor_visible = screen_buffer->cursor_visible;
1636 reply->cursor_x = screen_buffer->cursor_x;
1637 reply->cursor_y = screen_buffer->cursor_y;
1638 reply->width = screen_buffer->width;
1639 reply->height = screen_buffer->height;
1640 reply->attr = screen_buffer->attr;
1641 reply->win_left = screen_buffer->win.left;
1642 reply->win_top = screen_buffer->win.top;
1643 reply->win_right = screen_buffer->win.right;
1644 reply->win_bottom = screen_buffer->win.bottom;
1645 reply->max_width = screen_buffer->max_width;
1646 reply->max_height = screen_buffer->max_height;
1647 release_object( screen_buffer );
1651 /* read data (chars & attrs) from a screen buffer */
1652 DECL_HANDLER(read_console_output)
1654 struct screen_buffer *screen_buffer;
1656 if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle,
1657 FILE_READ_DATA, &screen_buffer_ops )))
1659 if (console_input_is_bare( screen_buffer->input ))
1661 set_error( STATUS_OBJECT_TYPE_MISMATCH );
1662 release_object( screen_buffer );
1665 read_console_output( screen_buffer, req->x, req->y, req->mode, req->wrap );
1666 reply->width = screen_buffer->width;
1667 reply->height = screen_buffer->height;
1668 release_object( screen_buffer );
1672 /* write data (char and/or attrs) to a screen buffer */
1673 DECL_HANDLER(write_console_output)
1675 struct screen_buffer *screen_buffer;
1677 if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle,
1678 FILE_WRITE_DATA, &screen_buffer_ops)))
1680 if (console_input_is_bare( screen_buffer->input ))
1682 set_error( STATUS_OBJECT_TYPE_MISMATCH );
1683 release_object( screen_buffer );
1686 reply->written = write_console_output( screen_buffer, get_req_data_size(), get_req_data(),
1687 req->mode, req->x, req->y, req->wrap );
1688 reply->width = screen_buffer->width;
1689 reply->height = screen_buffer->height;
1690 release_object( screen_buffer );
1694 /* fill a screen buffer with constant data (chars and/or attributes) */
1695 DECL_HANDLER(fill_console_output)
1697 struct screen_buffer *screen_buffer;
1699 if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle,
1700 FILE_WRITE_DATA, &screen_buffer_ops)))
1702 if (console_input_is_bare( screen_buffer->input ))
1704 set_error( STATUS_OBJECT_TYPE_MISMATCH );
1705 release_object( screen_buffer );
1708 reply->written = fill_console_output( screen_buffer, req->data, req->mode,
1709 req->x, req->y, req->count, req->wrap );
1710 release_object( screen_buffer );
1714 /* move a rect of data in a screen buffer */
1715 DECL_HANDLER(move_console_output)
1717 struct screen_buffer *screen_buffer;
1719 if ((screen_buffer = (struct screen_buffer*)get_handle_obj( current->process, req->handle,
1720 FILE_WRITE_DATA, &screen_buffer_ops)))
1722 if (console_input_is_bare( screen_buffer->input ))
1724 set_error( STATUS_OBJECT_TYPE_MISMATCH );
1725 release_object( screen_buffer );
1728 scroll_console_output( screen_buffer, req->x_src, req->y_src, req->x_dst, req->y_dst,
1730 release_object( screen_buffer );
1734 /* sends a signal to a console (process, group...) */
1735 DECL_HANDLER(send_console_signal)
1739 group = req->group_id ? req->group_id : current->process->group_id;
1742 set_error( STATUS_INVALID_PARAMETER );
1744 propagate_console_signal( current->process->console, req->signal, group );
1747 /* get console which renderer is 'current' */
1748 static int cgwe_enum( struct process* process, void* user)
1750 if (process->console && process->console->renderer == current)
1752 *(struct console_input**)user = process->console;
1758 DECL_HANDLER(get_console_wait_event)
1760 struct console_input* console = NULL;
1762 if (current->process->console)
1763 console = (struct console_input*)grab_object( (struct object*)current->process->console );
1764 else enum_processes(cgwe_enum, &console);
1768 reply->handle = alloc_handle( current->process, console->event, EVENT_ALL_ACCESS, 0 );
1769 release_object( console );
1771 else set_error( STATUS_INVALID_PARAMETER );