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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "wine/port.h"
39 static void console_input_dump( struct object
*obj
, int verbose
);
40 static void console_input_destroy( struct object
*obj
);
41 static int console_input_signaled( struct object
*obj
, struct thread
*thread
);
44 static int console_get_file_info( struct object
*obj
, struct get_file_info_reply
*reply
, int *flags
);
46 static const struct object_ops console_input_ops
=
48 sizeof(struct console_input
), /* size */
49 console_input_dump
, /* dump */
50 add_queue
, /* add_queue */
51 remove_queue
, /* remove_queue */
52 console_input_signaled
, /* signaled */
53 no_satisfied
, /* satisfied */
54 NULL
, /* get_poll_events */
55 NULL
, /* poll_event */
56 no_get_fd
, /* get_fd */
58 console_get_file_info
, /* get_file_info */
59 NULL
, /* queue_async */
60 console_input_destroy
/* destroy */
63 static void console_input_events_dump( struct object
*obj
, int verbose
);
64 static void console_input_events_destroy( struct object
*obj
);
65 static int console_input_events_signaled( struct object
*obj
, struct thread
*thread
);
67 struct console_input_events
69 struct object obj
; /* object header */
70 int num_alloc
; /* number of allocated events */
71 int num_used
; /* number of actually used events */
72 struct console_renderer_event
* events
;
75 static const struct object_ops console_input_events_ops
=
77 sizeof(struct console_input_events
), /* size */
78 console_input_events_dump
, /* dump */
79 add_queue
, /* add_queue */
80 remove_queue
, /* remove_queue */
81 console_input_events_signaled
, /* signaled */
82 no_satisfied
, /* satisfied */
83 NULL
, /* get_poll_events */
84 NULL
, /* poll_event */
85 no_get_fd
, /* get_fd */
87 no_get_file_info
, /* get_file_info */
88 NULL
, /* queue_async */
89 console_input_events_destroy
/* destroy */
94 struct object obj
; /* object header */
95 struct screen_buffer
*next
; /* linked list of all screen buffers */
96 struct screen_buffer
*prev
;
97 struct console_input
*input
; /* associated console input */
98 int mode
; /* output mode */
99 int cursor_size
; /* size of cursor (percentage filled) */
100 int cursor_visible
;/* cursor visibility flag */
101 int cursor_x
; /* position of cursor */
102 int cursor_y
; /* position of cursor */
103 int width
; /* size (w-h) of the screen buffer */
105 int max_width
; /* size (w-h) of the window given font size */
107 char_info_t
*data
; /* the data for each cell - a width x height matrix */
108 unsigned short attr
; /* default attribute for screen buffer */
109 rectangle_t win
; /* current visible window on the screen buffer *
110 * as seen in wineconsole */
113 static void screen_buffer_dump( struct object
*obj
, int verbose
);
114 static void screen_buffer_destroy( struct object
*obj
);
116 static const struct object_ops screen_buffer_ops
=
118 sizeof(struct screen_buffer
), /* size */
119 screen_buffer_dump
, /* dump */
120 no_add_queue
, /* add_queue */
121 NULL
, /* remove_queue */
123 NULL
, /* satisfied */
124 NULL
, /* get_poll_events */
125 NULL
, /* poll_event */
126 no_get_fd
, /* get_fd */
127 no_flush
, /* flush */
128 console_get_file_info
, /* get_file_info */
129 NULL
, /* queue_async */
130 screen_buffer_destroy
/* destroy */
133 static struct screen_buffer
*screen_buffer_list
;
135 static const char_info_t empty_char_info
= { ' ', 0x000f }; /* white on black space */
137 /* dumps the renderer events of a console */
138 static void console_input_events_dump( struct object
*obj
, int verbose
)
140 struct console_input_events
*evts
= (struct console_input_events
*)obj
;
141 assert( obj
->ops
== &console_input_events_ops
);
142 fprintf( stderr
, "Console input events: %d/%d events\n",
143 evts
->num_used
, evts
->num_alloc
);
146 /* destroys the renderer events of a console */
147 static void console_input_events_destroy( struct object
*obj
)
149 struct console_input_events
*evts
= (struct console_input_events
*)obj
;
150 assert( obj
->ops
== &console_input_events_ops
);
151 free( evts
->events
);
154 /* the renderer events list is signaled when it's not empty */
155 static int console_input_events_signaled( struct object
*obj
, struct thread
*thread
)
157 struct console_input_events
*evts
= (struct console_input_events
*)obj
;
158 assert( obj
->ops
== &console_input_events_ops
);
159 return (evts
->num_used
!= 0);
162 /* add an event to the console's renderer events list */
163 static void console_input_events_append( struct console_input_events
* evts
,
164 struct console_renderer_event
* evt
)
166 int collapsed
= FALSE
;
168 /* to be done even when evt has been generated by the rendere ? */
170 /* try to collapse evt into current queue's events */
173 struct console_renderer_event
* last
= &evts
->events
[evts
->num_used
- 1];
175 if (last
->event
== CONSOLE_RENDERER_UPDATE_EVENT
&&
176 evt
->event
== CONSOLE_RENDERER_UPDATE_EVENT
)
178 /* if two update events overlap, collapse them into a single one */
179 if (last
->u
.update
.bottom
+ 1 >= evt
->u
.update
.top
&&
180 evt
->u
.update
.bottom
+ 1 >= last
->u
.update
.top
)
182 last
->u
.update
.top
= min(last
->u
.update
.top
, evt
->u
.update
.top
);
183 last
->u
.update
.bottom
= max(last
->u
.update
.bottom
, evt
->u
.update
.bottom
);
190 if (evts
->num_used
== evts
->num_alloc
)
192 evts
->num_alloc
+= 16;
193 evts
->events
= realloc( evts
->events
, evts
->num_alloc
* sizeof(*evt
) );
194 assert(evts
->events
);
196 evts
->events
[evts
->num_used
++] = *evt
;
198 wake_up( &evts
->obj
, 0 );
201 /* retrieves events from the console's renderer events list */
202 static void console_input_events_get( struct console_input_events
* evts
)
204 size_t num
= get_reply_max_size() / sizeof(evts
->events
[0]);
206 if (num
> evts
->num_used
) num
= evts
->num_used
;
207 set_reply_data( evts
->events
, num
* sizeof(evts
->events
[0]) );
208 if (num
< evts
->num_used
)
210 memmove( &evts
->events
[0], &evts
->events
[num
],
211 (evts
->num_used
- num
) * sizeof(evts
->events
[0]) );
213 evts
->num_used
-= num
;
216 static struct console_input_events
*create_console_input_events(void)
218 struct console_input_events
* evt
;
220 if (!(evt
= alloc_object( &console_input_events_ops
, -1 ))) return NULL
;
221 evt
->num_alloc
= evt
->num_used
= 0;
226 static struct object
*create_console_input( struct thread
* renderer
)
228 struct console_input
*console_input
;
230 if (!(console_input
= alloc_object( &console_input_ops
, -1 ))) return NULL
;
231 console_input
->renderer
= renderer
;
232 console_input
->mode
= ENABLE_PROCESSED_INPUT
| ENABLE_LINE_INPUT
|
233 ENABLE_ECHO_INPUT
| ENABLE_MOUSE_INPUT
;
234 console_input
->num_proc
= 0;
235 console_input
->active
= NULL
;
236 console_input
->recnum
= 0;
237 console_input
->records
= NULL
;
238 console_input
->evt
= create_console_input_events();
239 console_input
->title
= NULL
;
240 console_input
->history_size
= 50;
241 console_input
->history
= calloc( console_input
->history_size
, sizeof(WCHAR
*) );
242 console_input
->history_index
= 0;
243 console_input
->history_mode
= 0;
245 if (!console_input
->history
|| !console_input
->evt
)
247 release_object( console_input
);
250 return &console_input
->obj
;
253 static struct screen_buffer
*create_console_output( struct console_input
*console_input
)
255 struct screen_buffer
*screen_buffer
;
256 struct console_renderer_event evt
;
259 if (!(screen_buffer
= alloc_object( &screen_buffer_ops
, -1 ))) return NULL
;
260 screen_buffer
->mode
= ENABLE_PROCESSED_OUTPUT
| ENABLE_WRAP_AT_EOL_OUTPUT
;
261 screen_buffer
->input
= console_input
;
262 screen_buffer
->cursor_size
= 100;
263 screen_buffer
->cursor_visible
= 1;
264 screen_buffer
->width
= 80;
265 screen_buffer
->height
= 150;
266 screen_buffer
->max_width
= 80;
267 screen_buffer
->max_height
= 25;
268 screen_buffer
->cursor_x
= 0;
269 screen_buffer
->cursor_y
= 0;
270 screen_buffer
->attr
= 0x0F;
271 screen_buffer
->win
.left
= 0;
272 screen_buffer
->win
.right
= screen_buffer
->max_width
- 1;
273 screen_buffer
->win
.top
= 0;
274 screen_buffer
->win
.bottom
= screen_buffer
->max_height
- 1;
276 if ((screen_buffer
->next
= screen_buffer_list
)) screen_buffer
->next
->prev
= screen_buffer
;
277 screen_buffer
->prev
= NULL
;
278 screen_buffer_list
= screen_buffer
;
280 if (!(screen_buffer
->data
= malloc( screen_buffer
->width
* screen_buffer
->height
*
281 sizeof(*screen_buffer
->data
) )))
283 release_object( screen_buffer
);
286 /* clear the first row */
287 for (i
= 0; i
< screen_buffer
->width
; i
++) screen_buffer
->data
[i
] = empty_char_info
;
288 /* and copy it to all other rows */
289 for (i
= 1; i
< screen_buffer
->height
; i
++)
290 memcpy( &screen_buffer
->data
[i
* screen_buffer
->width
], screen_buffer
->data
,
291 screen_buffer
->width
* sizeof(char_info_t
) );
293 if (!console_input
->active
)
295 console_input
->active
= (struct screen_buffer
*)grab_object( screen_buffer
);
297 /* generate the initial events */
298 evt
.event
= CONSOLE_RENDERER_ACTIVE_SB_EVENT
;
299 console_input_events_append( console_input
->evt
, &evt
);
301 evt
.event
= CONSOLE_RENDERER_SB_RESIZE_EVENT
;
302 evt
.u
.resize
.width
= screen_buffer
->width
;
303 evt
.u
.resize
.height
= screen_buffer
->height
;
304 console_input_events_append( console_input
->evt
, &evt
);
306 evt
.event
= CONSOLE_RENDERER_DISPLAY_EVENT
;
307 evt
.u
.display
.left
= screen_buffer
->win
.left
;
308 evt
.u
.display
.top
= screen_buffer
->win
.top
;
309 evt
.u
.display
.width
= screen_buffer
->win
.right
- screen_buffer
->win
.left
+ 1;
310 evt
.u
.display
.height
= screen_buffer
->win
.bottom
- screen_buffer
->win
.top
+ 1;
311 console_input_events_append( console_input
->evt
, &evt
);
313 evt
.event
= CONSOLE_RENDERER_UPDATE_EVENT
;
314 evt
.u
.update
.top
= 0;
315 evt
.u
.update
.bottom
= screen_buffer
->height
- 1;
316 console_input_events_append( console_input
->evt
, &evt
);
318 evt
.event
= CONSOLE_RENDERER_CURSOR_GEOM_EVENT
;
319 evt
.u
.cursor_geom
.size
= screen_buffer
->cursor_size
;
320 evt
.u
.cursor_geom
.visible
= screen_buffer
->cursor_visible
;
321 console_input_events_append( console_input
->evt
, &evt
);
323 evt
.event
= CONSOLE_RENDERER_CURSOR_POS_EVENT
;
324 evt
.u
.cursor_pos
.x
= screen_buffer
->cursor_x
;
325 evt
.u
.cursor_pos
.y
= screen_buffer
->cursor_y
;
326 console_input_events_append( console_input
->evt
, &evt
);
328 return screen_buffer
;
331 /* free the console for this process */
332 int free_console( struct process
*process
)
334 struct console_input
* console
= process
->console
;
336 if (!console
|| !console
->renderer
) return 0;
338 process
->console
= NULL
;
339 if (--console
->num_proc
== 0)
341 /* all processes have terminated... tell the renderer to terminate too */
342 struct console_renderer_event evt
;
343 evt
.event
= CONSOLE_RENDERER_EXIT_EVENT
;
344 console_input_events_append( console
->evt
, &evt
);
346 release_object( console
);
351 /* let process inherit the console from parent... this handle two cases :
352 * 1/ generic console inheritance
353 * 2/ parent is a renderer which launches process, and process should attach to the console
354 * renderered by parent
356 void inherit_console(struct thread
*parent_thread
, struct process
*process
, obj_handle_t hconin
)
359 struct process
* parent
= parent_thread
->process
;
361 /* if parent is a renderer, then attach current process to its console
366 struct console_input
* console
;
368 if ((console
= (struct console_input
*)get_handle_obj( parent
, hconin
, 0, NULL
)))
370 if (console
->renderer
== parent_thread
)
372 process
->console
= (struct console_input
*)grab_object( console
);
373 process
->console
->num_proc
++;
376 release_object( console
);
379 /* otherwise, if parent has a console, attach child to this console */
380 if (!done
&& parent
->console
)
382 assert(parent
->console
->renderer
);
383 process
->console
= (struct console_input
*)grab_object( parent
->console
);
384 process
->console
->num_proc
++;
388 static struct console_input
* console_input_get( obj_handle_t handle
, unsigned access
)
390 struct console_input
* console
= 0;
393 console
= (struct console_input
*)get_handle_obj( current
->process
, handle
,
394 access
, &console_input_ops
);
395 else if (current
->process
->console
)
397 assert( current
->process
->console
->renderer
);
398 console
= (struct console_input
*)grab_object( current
->process
->console
);
401 if (!console
&& !get_error()) set_error(STATUS_INVALID_PARAMETER
);
405 /* check if a console input is signaled: yes if non read input records */
406 static int console_input_signaled( struct object
*obj
, struct thread
*thread
)
408 struct console_input
*console
= (struct console_input
*)obj
;
409 assert( obj
->ops
== &console_input_ops
);
410 return console
->recnum
? 1 : 0;
413 struct console_signal_info
{
414 struct console_input
*console
;
419 static int propagate_console_signal_cb(struct process
*process
, void *user
)
421 struct console_signal_info
* csi
= (struct console_signal_info
*)user
;
423 if (process
->console
== csi
->console
&& process
->running_threads
&&
424 (!csi
->group
|| process
->group_id
== csi
->group
))
426 struct thread
*thread
= process
->thread_list
;
430 struct thread
*next
= thread
->proc_next
;
431 kill( thread
->unix_pid
, csi
->signal
);
438 static void propagate_console_signal( struct console_input
*console
,
439 int sig
, process_id_t group_id
)
441 struct console_signal_info csi
;
445 set_error( STATUS_INVALID_PARAMETER
);
448 /* FIXME: should support the other events (like CTRL_BREAK) */
449 if (sig
!= CTRL_C_EVENT
)
451 set_error( STATUS_NOT_IMPLEMENTED
);
454 csi
.console
= console
;
456 csi
.group
= group_id
;
458 enum_processes(propagate_console_signal_cb
, &csi
);
461 static int get_console_mode( obj_handle_t handle
)
466 if ((obj
= get_handle_obj( current
->process
, handle
, GENERIC_READ
, NULL
)))
468 if (obj
->ops
== &console_input_ops
)
469 ret
= ((struct console_input
*)obj
)->mode
;
470 else if (obj
->ops
== &screen_buffer_ops
)
471 ret
= ((struct screen_buffer
*)obj
)->mode
;
473 set_error( STATUS_OBJECT_TYPE_MISMATCH
);
474 release_object( obj
);
479 /* changes the mode of either a console input or a screen buffer */
480 static int set_console_mode( obj_handle_t handle
, int mode
)
485 if (!(obj
= get_handle_obj( current
->process
, handle
, GENERIC_WRITE
, NULL
)))
487 if (obj
->ops
== &console_input_ops
)
489 /* FIXME: if we remove the edit mode bits, we need (???) to clean up the history */
490 ((struct console_input
*)obj
)->mode
= mode
;
493 else if (obj
->ops
== &screen_buffer_ops
)
495 ((struct screen_buffer
*)obj
)->mode
= mode
;
498 else set_error( STATUS_OBJECT_TYPE_MISMATCH
);
499 release_object( obj
);
503 /* add input events to a console input queue */
504 static int write_console_input( struct console_input
* console
, int count
,
505 const INPUT_RECORD
*records
)
507 INPUT_RECORD
*new_rec
;
509 if (!count
) return 0;
510 if (!(new_rec
= realloc( console
->records
,
511 (console
->recnum
+ count
) * sizeof(INPUT_RECORD
) )))
513 set_error( STATUS_NO_MEMORY
);
514 release_object( console
);
517 console
->records
= new_rec
;
518 memcpy( new_rec
+ console
->recnum
, records
, count
* sizeof(INPUT_RECORD
) );
520 if (console
->mode
& ENABLE_PROCESSED_INPUT
)
525 if (records
[i
].EventType
== KEY_EVENT
&&
526 records
[i
].Event
.KeyEvent
.uChar
.UnicodeChar
== 'C' - 64 &&
527 !(records
[i
].Event
.KeyEvent
.dwControlKeyState
& ENHANCED_KEY
))
530 memcpy( &console
->records
[console
->recnum
+ i
],
531 &console
->records
[console
->recnum
+ i
+ 1],
532 (count
- i
- 1) * sizeof(INPUT_RECORD
) );
534 if (records
[i
].Event
.KeyEvent
.bKeyDown
)
536 /* send SIGINT to all processes attached to this console */
537 propagate_console_signal( console
, CTRL_C_EVENT
, 0 );
543 console
->recnum
+= count
;
544 /* wake up all waiters */
545 wake_up( &console
->obj
, 0 );
549 /* retrieve a pointer to the console input records */
550 static int read_console_input( obj_handle_t handle
, int count
, int flush
)
552 struct console_input
*console
;
554 if (!(console
= (struct console_input
*)get_handle_obj( current
->process
, handle
,
555 GENERIC_READ
, &console_input_ops
)))
560 /* special case: do not retrieve anything, but return
561 * the total number of records available */
562 count
= console
->recnum
;
566 if (count
> console
->recnum
) count
= console
->recnum
;
567 set_reply_data( console
->records
, count
* sizeof(INPUT_RECORD
) );
572 for (i
= count
; i
< console
->recnum
; i
++)
573 console
->records
[i
-count
] = console
->records
[i
];
574 if ((console
->recnum
-= count
) > 0)
576 INPUT_RECORD
*new_rec
= realloc( console
->records
,
577 console
->recnum
* sizeof(INPUT_RECORD
) );
578 if (new_rec
) console
->records
= new_rec
;
582 free( console
->records
);
583 console
->records
= NULL
;
586 release_object( console
);
590 /* set misc console input information */
591 static int set_console_input_info( const struct set_console_input_info_request
*req
,
592 const WCHAR
*title
, size_t len
)
594 struct console_input
*console
;
595 struct console_renderer_event evt
;
597 if (!(console
= console_input_get( req
->handle
, GENERIC_WRITE
))) goto error
;
599 if (req
->mask
& SET_CONSOLE_INPUT_INFO_ACTIVE_SB
)
601 struct screen_buffer
*screen_buffer
;
603 screen_buffer
= (struct screen_buffer
*)get_handle_obj( current
->process
, req
->active_sb
,
604 GENERIC_READ
, &screen_buffer_ops
);
605 if (!screen_buffer
|| screen_buffer
->input
!= console
)
607 set_error( STATUS_INVALID_PARAMETER
);
608 if (screen_buffer
) release_object( screen_buffer
);
612 if (screen_buffer
!= console
->active
)
614 if (console
->active
) release_object( console
->active
);
615 console
->active
= screen_buffer
;
616 evt
.event
= CONSOLE_RENDERER_ACTIVE_SB_EVENT
;
617 console_input_events_append( console
->evt
, &evt
);
620 release_object( screen_buffer
);
622 if (req
->mask
& SET_CONSOLE_INPUT_INFO_TITLE
)
624 WCHAR
*new_title
= mem_alloc( len
+ sizeof(WCHAR
) );
627 memcpy( new_title
, title
, len
+ sizeof(WCHAR
) );
628 new_title
[len
/ sizeof(WCHAR
)] = 0;
629 if (console
->title
) free( console
->title
);
630 console
->title
= new_title
;
631 evt
.event
= CONSOLE_RENDERER_TITLE_EVENT
;
632 console_input_events_append( console
->evt
, &evt
);
635 if (req
->mask
& SET_CONSOLE_INPUT_INFO_HISTORY_MODE
)
637 console
->history_mode
= req
->history_mode
;
639 if ((req
->mask
& SET_CONSOLE_INPUT_INFO_HISTORY_SIZE
) &&
640 console
->history_size
!= req
->history_size
)
646 if (req
->history_size
)
648 mem
= mem_alloc( req
->history_size
* sizeof(WCHAR
*) );
649 if (!mem
) goto error
;
650 memset( mem
, 0, req
->history_size
* sizeof(WCHAR
*) );
653 delta
= (console
->history_index
> req
->history_size
) ?
654 (console
->history_index
- req
->history_size
) : 0;
656 for (i
= delta
; i
< console
->history_index
; i
++)
658 mem
[i
- delta
] = console
->history
[i
];
659 console
->history
[i
] = NULL
;
661 console
->history_index
-= delta
;
663 for (i
= 0; i
< console
->history_size
; i
++)
664 if (console
->history
[i
]) free( console
->history
[i
] );
665 free( console
->history
);
666 console
->history
= mem
;
667 console
->history_size
= req
->history_size
;
669 release_object( console
);
672 if (console
) release_object( console
);
676 /* resize a screen buffer */
677 static int change_screen_buffer_size( struct screen_buffer
*screen_buffer
,
678 int new_width
, int new_height
)
680 int i
, old_width
, old_height
, copy_width
, copy_height
;
681 char_info_t
*new_data
;
683 if (!(new_data
= malloc( new_width
* new_height
* sizeof(*new_data
) )))
685 set_error( STATUS_NO_MEMORY
);
688 old_width
= screen_buffer
->width
;
689 old_height
= screen_buffer
->height
;
690 copy_width
= min( old_width
, new_width
);
691 copy_height
= min( old_height
, new_height
);
693 /* copy all the rows */
694 for (i
= 0; i
< copy_height
; i
++)
696 memcpy( &new_data
[i
* new_width
], &screen_buffer
->data
[i
* old_width
],
697 copy_width
* sizeof(char_info_t
) );
700 /* clear the end of each row */
701 if (new_width
> old_width
)
704 for (i
= old_width
; i
< new_width
; i
++) new_data
[i
] = empty_char_info
;
705 /* and blast it to the other rows */
706 for (i
= 1; i
< copy_height
; i
++)
707 memcpy( &new_data
[i
* new_width
+ old_width
], &new_data
[old_width
],
708 (new_width
- old_width
) * sizeof(char_info_t
) );
711 /* clear remaining rows */
712 if (new_height
> old_height
)
715 for (i
= 0; i
< new_width
; i
++) new_data
[old_height
* new_width
+ i
] = empty_char_info
;
716 /* and blast it to the other rows */
717 for (i
= old_height
+1; i
< new_height
; i
++)
718 memcpy( &new_data
[i
* new_width
], &new_data
[old_height
* new_width
],
719 new_width
* sizeof(char_info_t
) );
721 free( screen_buffer
->data
);
722 screen_buffer
->data
= new_data
;
723 screen_buffer
->width
= new_width
;
724 screen_buffer
->height
= new_height
;
728 /* set misc screen buffer information */
729 static int set_console_output_info( struct screen_buffer
*screen_buffer
,
730 const struct set_console_output_info_request
*req
)
732 struct console_renderer_event evt
;
734 if (req
->mask
& SET_CONSOLE_OUTPUT_INFO_CURSOR_GEOM
)
736 if (req
->cursor_size
< 1 || req
->cursor_size
> 100)
738 set_error( STATUS_INVALID_PARAMETER
);
741 if (screen_buffer
->cursor_size
!= req
->cursor_size
||
742 screen_buffer
->cursor_visible
!= req
->cursor_visible
)
744 screen_buffer
->cursor_size
= req
->cursor_size
;
745 screen_buffer
->cursor_visible
= req
->cursor_visible
;
746 evt
.event
= CONSOLE_RENDERER_CURSOR_GEOM_EVENT
;
747 evt
.u
.cursor_geom
.size
= req
->cursor_size
;
748 evt
.u
.cursor_geom
.visible
= req
->cursor_visible
;
749 console_input_events_append( screen_buffer
->input
->evt
, &evt
);
752 if (req
->mask
& SET_CONSOLE_OUTPUT_INFO_CURSOR_POS
)
754 if (req
->cursor_x
< 0 || req
->cursor_x
>= screen_buffer
->width
||
755 req
->cursor_y
< 0 || req
->cursor_y
>= screen_buffer
->height
)
757 set_error( STATUS_INVALID_PARAMETER
);
760 if (screen_buffer
->cursor_x
!= req
->cursor_x
|| screen_buffer
->cursor_y
!= req
->cursor_y
)
762 screen_buffer
->cursor_x
= req
->cursor_x
;
763 screen_buffer
->cursor_y
= req
->cursor_y
;
764 evt
.event
= CONSOLE_RENDERER_CURSOR_POS_EVENT
;
765 evt
.u
.cursor_pos
.x
= req
->cursor_x
;
766 evt
.u
.cursor_pos
.y
= req
->cursor_y
;
767 console_input_events_append( screen_buffer
->input
->evt
, &evt
);
770 if (req
->mask
& SET_CONSOLE_OUTPUT_INFO_SIZE
)
774 /* new screen-buffer cannot be smaller than actual window */
775 if (req
->width
< screen_buffer
->win
.right
- screen_buffer
->win
.left
+ 1 ||
776 req
->height
< screen_buffer
->win
.bottom
- screen_buffer
->win
.top
+ 1)
778 set_error( STATUS_INVALID_PARAMETER
);
781 /* FIXME: there are also some basic minimum and max size to deal with */
782 if (!change_screen_buffer_size( screen_buffer
, req
->width
, req
->height
)) return 0;
784 evt
.event
= CONSOLE_RENDERER_SB_RESIZE_EVENT
;
785 evt
.u
.resize
.width
= req
->width
;
786 evt
.u
.resize
.height
= req
->height
;
787 console_input_events_append( screen_buffer
->input
->evt
, &evt
);
789 evt
.event
= CONSOLE_RENDERER_UPDATE_EVENT
;
790 evt
.u
.update
.top
= 0;
791 evt
.u
.update
.bottom
= screen_buffer
->height
- 1;
792 console_input_events_append( screen_buffer
->input
->evt
, &evt
);
794 /* scroll window to display sb */
795 if (screen_buffer
->win
.right
>= req
->width
)
797 screen_buffer
->win
.right
-= screen_buffer
->win
.left
;
798 screen_buffer
->win
.left
= 0;
800 if (screen_buffer
->win
.bottom
>= req
->height
)
802 screen_buffer
->win
.bottom
-= screen_buffer
->win
.top
;
803 screen_buffer
->win
.top
= 0;
805 /* reset cursor if needed (normally, if cursor was outside of new sb, the
806 * window has been shifted so that the new position of the cursor will be
809 if (screen_buffer
->cursor_x
>= req
->width
)
811 screen_buffer
->cursor_x
= req
->width
- 1;
814 if (screen_buffer
->cursor_y
>= req
->height
)
816 screen_buffer
->cursor_y
= req
->height
- 1;
821 evt
.event
= CONSOLE_RENDERER_CURSOR_POS_EVENT
;
822 evt
.u
.cursor_pos
.x
= req
->cursor_x
;
823 evt
.u
.cursor_pos
.y
= req
->cursor_y
;
824 console_input_events_append( screen_buffer
->input
->evt
, &evt
);
827 if (screen_buffer
== screen_buffer
->input
->active
&&
828 screen_buffer
->input
->mode
& ENABLE_WINDOW_INPUT
)
831 ir
.EventType
= WINDOW_BUFFER_SIZE_EVENT
;
832 ir
.Event
.WindowBufferSizeEvent
.dwSize
.X
= req
->width
;
833 ir
.Event
.WindowBufferSizeEvent
.dwSize
.Y
= req
->height
;
834 write_console_input( screen_buffer
->input
, 1, &ir
);
837 if (req
->mask
& SET_CONSOLE_OUTPUT_INFO_ATTR
)
839 screen_buffer
->attr
= req
->attr
;
841 if (req
->mask
& SET_CONSOLE_OUTPUT_INFO_DISPLAY_WINDOW
)
843 if (req
->win_left
< 0 || req
->win_left
> req
->win_right
||
844 req
->win_right
>= screen_buffer
->width
||
845 req
->win_top
< 0 || req
->win_top
> req
->win_bottom
||
846 req
->win_bottom
>= screen_buffer
->height
)
848 set_error( STATUS_INVALID_PARAMETER
);
851 if (screen_buffer
->win
.left
!= req
->win_left
|| screen_buffer
->win
.top
!= req
->win_top
||
852 screen_buffer
->win
.right
!= req
->win_right
|| screen_buffer
->win
.bottom
!= req
->win_bottom
)
854 screen_buffer
->win
.left
= req
->win_left
;
855 screen_buffer
->win
.top
= req
->win_top
;
856 screen_buffer
->win
.right
= req
->win_right
;
857 screen_buffer
->win
.bottom
= req
->win_bottom
;
858 evt
.event
= CONSOLE_RENDERER_DISPLAY_EVENT
;
859 evt
.u
.display
.left
= req
->win_left
;
860 evt
.u
.display
.top
= req
->win_top
;
861 evt
.u
.display
.width
= req
->win_right
- req
->win_left
+ 1;
862 evt
.u
.display
.height
= req
->win_bottom
- req
->win_top
+ 1;
863 console_input_events_append( screen_buffer
->input
->evt
, &evt
);
866 if (req
->mask
& SET_CONSOLE_OUTPUT_INFO_MAX_SIZE
)
868 /* can only be done by renderer */
869 if (current
->process
->console
!= screen_buffer
->input
)
871 set_error( STATUS_INVALID_PARAMETER
);
875 screen_buffer
->max_width
= req
->max_width
;
876 screen_buffer
->max_height
= req
->max_height
;
882 /* appends a new line to history (history is a fixed size array) */
883 static void console_input_append_hist( struct console_input
* console
, const WCHAR
* buf
, size_t len
)
885 WCHAR
* ptr
= mem_alloc( (len
+ 1) * sizeof(WCHAR
) );
889 set_error( STATUS_NO_MEMORY
);
892 if (!console
|| !console
->history_size
)
894 set_error( STATUS_INVALID_PARAMETER
); /* FIXME */
898 memcpy( ptr
, buf
, len
* sizeof(WCHAR
) );
901 if (console
->history_mode
&& console
->history_index
&&
902 strncmpW( console
->history
[console
->history_index
- 1], ptr
, len
* sizeof(WCHAR
) ) == 0)
904 /* ok, mode ask us to not use twice the same string...
905 * so just free mem and returns
907 set_error( STATUS_ALIAS_EXISTS
);
912 if (console
->history_index
< console
->history_size
)
914 console
->history
[console
->history_index
++] = ptr
;
918 free( console
->history
[0]) ;
919 memmove( &console
->history
[0], &console
->history
[1],
920 (console
->history_size
- 1) * sizeof(WCHAR
*) );
921 console
->history
[console
->history_size
- 1] = ptr
;
925 /* returns a line from the cache */
926 static size_t console_input_get_hist( struct console_input
*console
, int index
)
930 if (index
>= console
->history_index
) set_error( STATUS_INVALID_PARAMETER
);
933 ret
= strlenW( console
->history
[index
] ) * sizeof(WCHAR
);
934 set_reply_data( console
->history
[index
], min( ret
, get_reply_max_size() ));
940 static void console_input_dump( struct object
*obj
, int verbose
)
942 struct console_input
*console
= (struct console_input
*)obj
;
943 assert( obj
->ops
== &console_input_ops
);
944 fprintf( stderr
, "Console input active=%p evt=%p\n",
945 console
->active
, console
->evt
);
948 static int console_get_file_info( struct object
*obj
, struct get_file_info_reply
*reply
, int *flags
)
952 reply
->type
= FILE_TYPE_CHAR
;
954 reply
->access_time
= 0;
955 reply
->write_time
= 0;
956 reply
->size_high
= 0;
959 reply
->index_high
= 0;
960 reply
->index_low
= 0;
964 return FD_TYPE_CONSOLE
;
967 static void console_input_destroy( struct object
*obj
)
969 struct console_input
* console_in
= (struct console_input
*)obj
;
970 struct screen_buffer
* curr
;
973 assert( obj
->ops
== &console_input_ops
);
974 if (console_in
->title
) free( console_in
->title
);
975 if (console_in
->records
) free( console_in
->records
);
977 if (console_in
->active
) release_object( console_in
->active
);
978 console_in
->active
= NULL
;
980 for (curr
= screen_buffer_list
; curr
; curr
= curr
->next
)
982 if (curr
->input
== console_in
) curr
->input
= NULL
;
985 release_object( console_in
->evt
);
986 console_in
->evt
= NULL
;
988 for (i
= 0; i
< console_in
->history_size
; i
++)
989 if (console_in
->history
[i
]) free( console_in
->history
[i
] );
990 if (console_in
->history
) free( console_in
->history
);
993 static void screen_buffer_dump( struct object
*obj
, int verbose
)
995 struct screen_buffer
*screen_buffer
= (struct screen_buffer
*)obj
;
996 assert( obj
->ops
== &screen_buffer_ops
);
998 fprintf(stderr
, "Console screen buffer input=%p\n", screen_buffer
->input
);
1001 static void screen_buffer_destroy( struct object
*obj
)
1003 struct screen_buffer
*screen_buffer
= (struct screen_buffer
*)obj
;
1005 assert( obj
->ops
== &screen_buffer_ops
);
1007 if (screen_buffer
->next
) screen_buffer
->next
->prev
= screen_buffer
->prev
;
1008 if (screen_buffer
->prev
) screen_buffer
->prev
->next
= screen_buffer
->next
;
1009 else screen_buffer_list
= screen_buffer
->next
;
1011 if (screen_buffer
->input
&& screen_buffer
->input
->active
== screen_buffer
)
1013 struct screen_buffer
* sb
;
1014 for (sb
= screen_buffer_list
; sb
&& sb
->input
!= screen_buffer
->input
; sb
= sb
->next
);
1015 screen_buffer
->input
->active
= sb
;
1017 if (screen_buffer
->data
) free( screen_buffer
->data
);
1020 /* write data into a screen buffer */
1021 static int write_console_output( struct screen_buffer
*screen_buffer
, size_t size
,
1022 const void* data
, enum char_info_mode mode
,
1023 int x
, int y
, int wrap
)
1026 char_info_t
*end
, *dest
= screen_buffer
->data
+ y
* screen_buffer
->width
+ x
;
1028 if (y
>= screen_buffer
->height
) return 0;
1031 end
= screen_buffer
->data
+ screen_buffer
->height
* screen_buffer
->width
;
1033 end
= screen_buffer
->data
+ (y
+1) * screen_buffer
->width
;
1037 case CHAR_INFO_MODE_TEXT
:
1039 const WCHAR
*ptr
= data
;
1040 for (i
= 0; i
< size
/sizeof(*ptr
) && dest
< end
; dest
++, i
++) dest
->ch
= ptr
[i
];
1043 case CHAR_INFO_MODE_ATTR
:
1045 const unsigned short *ptr
= data
;
1046 for (i
= 0; i
< size
/sizeof(*ptr
) && dest
< end
; dest
++, i
++) dest
->attr
= ptr
[i
];
1049 case CHAR_INFO_MODE_TEXTATTR
:
1051 const char_info_t
*ptr
= data
;
1052 for (i
= 0; i
< size
/sizeof(*ptr
) && dest
< end
; dest
++, i
++) *dest
= ptr
[i
];
1055 case CHAR_INFO_MODE_TEXTSTDATTR
:
1057 const WCHAR
*ptr
= data
;
1058 for (i
= 0; i
< size
/sizeof(*ptr
) && dest
< end
; dest
++, i
++)
1061 dest
->attr
= screen_buffer
->attr
;
1066 set_error( STATUS_INVALID_PARAMETER
);
1070 if (i
&& screen_buffer
== screen_buffer
->input
->active
)
1072 struct console_renderer_event evt
;
1073 evt
.event
= CONSOLE_RENDERER_UPDATE_EVENT
;
1074 evt
.u
.update
.top
= y
+ x
/ screen_buffer
->width
;
1075 evt
.u
.update
.bottom
= y
+ (x
+ i
- 1) / screen_buffer
->width
;
1076 console_input_events_append( screen_buffer
->input
->evt
, &evt
);
1081 /* fill a screen buffer with uniform data */
1082 static int fill_console_output( struct screen_buffer
*screen_buffer
, char_info_t data
,
1083 enum char_info_mode mode
, int x
, int y
, int count
, int wrap
)
1086 char_info_t
*end
, *dest
= screen_buffer
->data
+ y
* screen_buffer
->width
+ x
;
1088 if (y
>= screen_buffer
->height
) return 0;
1091 end
= screen_buffer
->data
+ screen_buffer
->height
* screen_buffer
->width
;
1093 end
= screen_buffer
->data
+ (y
+1) * screen_buffer
->width
;
1095 if (count
> end
- dest
) count
= end
- dest
;
1099 case CHAR_INFO_MODE_TEXT
:
1100 for (i
= 0; i
< count
; i
++) dest
[i
].ch
= data
.ch
;
1102 case CHAR_INFO_MODE_ATTR
:
1103 for (i
= 0; i
< count
; i
++) dest
[i
].attr
= data
.attr
;
1105 case CHAR_INFO_MODE_TEXTATTR
:
1106 for (i
= 0; i
< count
; i
++) dest
[i
] = data
;
1108 case CHAR_INFO_MODE_TEXTSTDATTR
:
1109 for (i
= 0; i
< count
; i
++)
1111 dest
[i
].ch
= data
.ch
;
1112 dest
[i
].attr
= screen_buffer
->attr
;
1116 set_error( STATUS_INVALID_PARAMETER
);
1120 if (count
&& screen_buffer
== screen_buffer
->input
->active
)
1122 struct console_renderer_event evt
;
1123 evt
.event
= CONSOLE_RENDERER_UPDATE_EVENT
;
1124 evt
.u
.update
.top
= y
;
1125 evt
.u
.update
.bottom
= (y
* screen_buffer
->width
+ x
+ count
- 1) / screen_buffer
->width
;
1126 console_input_events_append( screen_buffer
->input
->evt
, &evt
);
1131 /* read data from a screen buffer */
1132 static void read_console_output( struct screen_buffer
*screen_buffer
, int x
, int y
,
1133 enum char_info_mode mode
, int wrap
)
1136 char_info_t
*end
, *src
= screen_buffer
->data
+ y
* screen_buffer
->width
+ x
;
1138 if (y
>= screen_buffer
->height
) return;
1141 end
= screen_buffer
->data
+ screen_buffer
->height
* screen_buffer
->width
;
1143 end
= screen_buffer
->data
+ (y
+1) * screen_buffer
->width
;
1147 case CHAR_INFO_MODE_TEXT
:
1150 int count
= min( end
- src
, get_reply_max_size() / sizeof(*data
) );
1151 if ((data
= set_reply_data_size( count
* sizeof(*data
) )))
1153 for (i
= 0; i
< count
; i
++) data
[i
] = src
[i
].ch
;
1157 case CHAR_INFO_MODE_ATTR
:
1159 unsigned short *data
;
1160 int count
= min( end
- src
, get_reply_max_size() / sizeof(*data
) );
1161 if ((data
= set_reply_data_size( count
* sizeof(*data
) )))
1163 for (i
= 0; i
< count
; i
++) data
[i
] = src
[i
].attr
;
1167 case CHAR_INFO_MODE_TEXTATTR
:
1170 int count
= min( end
- src
, get_reply_max_size() / sizeof(*data
) );
1171 if ((data
= set_reply_data_size( count
* sizeof(*data
) )))
1173 for (i
= 0; i
< count
; i
++) data
[i
] = src
[i
];
1178 set_error( STATUS_INVALID_PARAMETER
);
1183 /* scroll parts of a screen buffer */
1184 static void scroll_console_output( obj_handle_t handle
, int xsrc
, int ysrc
, int xdst
, int ydst
,
1187 struct screen_buffer
*screen_buffer
;
1189 char_info_t
*psrc
, *pdst
;
1190 struct console_renderer_event evt
;
1192 if (!(screen_buffer
= (struct screen_buffer
*)get_handle_obj( current
->process
, handle
,
1193 GENERIC_READ
, &screen_buffer_ops
)))
1195 if (xsrc
< 0 || ysrc
< 0 || xdst
< 0 || ydst
< 0 ||
1196 xsrc
+ w
> screen_buffer
->width
||
1197 xdst
+ w
> screen_buffer
->width
||
1198 ysrc
+ h
> screen_buffer
->height
||
1199 ydst
+ h
> screen_buffer
->height
||
1202 set_error( STATUS_INVALID_PARAMETER
);
1203 release_object( screen_buffer
);
1209 psrc
= &screen_buffer
->data
[(ysrc
+ h
- 1) * screen_buffer
->width
+ xsrc
];
1210 pdst
= &screen_buffer
->data
[(ydst
+ h
- 1) * screen_buffer
->width
+ xdst
];
1212 for (j
= h
; j
> 0; j
--)
1214 memcpy(pdst
, psrc
, w
* sizeof(*pdst
) );
1215 pdst
-= screen_buffer
->width
;
1216 psrc
-= screen_buffer
->width
;
1221 psrc
= &screen_buffer
->data
[ysrc
* screen_buffer
->width
+ xsrc
];
1222 pdst
= &screen_buffer
->data
[ydst
* screen_buffer
->width
+ xdst
];
1224 for (j
= 0; j
< h
; j
++)
1226 /* we use memmove here because when psrc and pdst are the same,
1227 * copies are done on the same row, so the dst and src blocks
1229 memmove( pdst
, psrc
, w
* sizeof(*pdst
) );
1230 pdst
+= screen_buffer
->width
;
1231 psrc
+= screen_buffer
->width
;
1235 /* FIXME: this could be enhanced, by signalling scroll */
1236 evt
.event
= CONSOLE_RENDERER_UPDATE_EVENT
;
1237 evt
.u
.update
.top
= min(ysrc
, ydst
);
1238 evt
.u
.update
.bottom
= max(ysrc
, ydst
) + h
- 1;
1239 console_input_events_append( screen_buffer
->input
->evt
, &evt
);
1241 release_object( screen_buffer
);
1244 /* allocate a console for the renderer */
1245 DECL_HANDLER(alloc_console
)
1247 obj_handle_t in
= 0;
1248 obj_handle_t evt
= 0;
1249 struct process
*process
;
1250 struct process
*renderer
= current
->process
;
1251 struct console_input
*console
;
1253 process
= (req
->pid
) ? get_process_from_id( req
->pid
) :
1254 (struct process
*)grab_object( renderer
->parent
);
1256 reply
->handle_in
= 0;
1258 if (!process
) return;
1259 if (process
!= renderer
&& process
->console
)
1261 set_error( STATUS_ACCESS_DENIED
);
1265 if ((console
= (struct console_input
*)create_console_input( current
)))
1267 if ((in
= alloc_handle( renderer
, console
, req
->access
, req
->inherit
)))
1269 if ((evt
= alloc_handle( renderer
, console
->evt
,
1270 SYNCHRONIZE
|GENERIC_READ
|GENERIC_WRITE
, FALSE
)))
1272 if (process
!= renderer
)
1274 process
->console
= (struct console_input
*)grab_object( console
);
1275 console
->num_proc
++;
1277 reply
->handle_in
= in
;
1279 release_object( console
);
1282 close_handle( renderer
, in
, NULL
);
1284 free_console( process
);
1287 release_object( process
);
1290 /* free the console of the current process */
1291 DECL_HANDLER(free_console
)
1293 free_console( current
->process
);
1296 /* let the renderer peek the events it's waiting on */
1297 DECL_HANDLER(get_console_renderer_events
)
1299 struct console_input_events
*evt
;
1301 evt
= (struct console_input_events
*)get_handle_obj( current
->process
, req
->handle
,
1302 GENERIC_WRITE
, &console_input_events_ops
);
1304 console_input_events_get( evt
);
1305 release_object( evt
);
1308 /* open a handle to the process console */
1309 DECL_HANDLER(open_console
)
1311 struct object
*obj
= NULL
;
1317 if (current
->process
->console
&& current
->process
->console
->renderer
)
1318 obj
= grab_object( (struct object
*)current
->process
->console
);
1321 if (current
->process
->console
&& current
->process
->console
->renderer
&&
1322 current
->process
->console
->active
)
1323 obj
= grab_object( (struct object
*)current
->process
->console
->active
);
1326 if ((obj
= get_handle_obj( current
->process
, (obj_handle_t
)req
->from
,
1327 GENERIC_READ
|GENERIC_WRITE
, &console_input_ops
)))
1329 struct console_input
* console
= (struct console_input
*)obj
;
1330 obj
= (console
->active
) ? grab_object( console
->active
) : NULL
;
1331 release_object( console
);
1336 /* FIXME: req->share is not used (as in screen buffer creation) */
1339 reply
->handle
= alloc_handle( current
->process
, obj
, req
->access
, req
->inherit
);
1340 release_object( obj
);
1342 else if (!get_error()) set_error( STATUS_ACCESS_DENIED
);
1345 /* set info about a console input */
1346 DECL_HANDLER(set_console_input_info
)
1348 set_console_input_info( req
, get_req_data(), get_req_data_size() );
1351 /* get info about a console (output only) */
1352 DECL_HANDLER(get_console_input_info
)
1354 struct console_input
*console
;
1356 if (!(console
= console_input_get( req
->handle
, GENERIC_READ
))) return;
1359 size_t len
= strlenW( console
->title
) * sizeof(WCHAR
);
1360 if (len
> get_reply_max_size()) len
= get_reply_max_size();
1361 set_reply_data( console
->title
, len
);
1363 reply
->history_mode
= console
->history_mode
;
1364 reply
->history_size
= console
->history_size
;
1365 reply
->history_index
= console
->history_index
;
1366 release_object( console
);
1369 /* get a console mode (input or output) */
1370 DECL_HANDLER(get_console_mode
)
1372 reply
->mode
= get_console_mode( req
->handle
);
1375 /* set a console mode (input or output) */
1376 DECL_HANDLER(set_console_mode
)
1378 set_console_mode( req
->handle
, req
->mode
);
1381 /* add input records to a console input queue */
1382 DECL_HANDLER(write_console_input
)
1384 struct console_input
*console
;
1387 if (!(console
= (struct console_input
*)get_handle_obj( current
->process
, req
->handle
,
1388 GENERIC_WRITE
, &console_input_ops
)))
1390 reply
->written
= write_console_input( console
, get_req_data_size() / sizeof(INPUT_RECORD
),
1392 release_object( console
);
1395 /* fetch input records from a console input queue */
1396 DECL_HANDLER(read_console_input
)
1398 int count
= get_reply_max_size() / sizeof(INPUT_RECORD
);
1399 reply
->read
= read_console_input( req
->handle
, count
, req
->flush
);
1402 /* appends a string to console's history */
1403 DECL_HANDLER(append_console_input_history
)
1405 struct console_input
*console
;
1407 if (!(console
= console_input_get( req
->handle
, GENERIC_WRITE
))) return;
1408 console_input_append_hist( console
, get_req_data(), get_req_data_size() / sizeof(WCHAR
) );
1409 release_object( console
);
1412 /* appends a string to console's history */
1413 DECL_HANDLER(get_console_input_history
)
1415 struct console_input
*console
;
1417 if (!(console
= console_input_get( req
->handle
, GENERIC_WRITE
))) return;
1418 reply
->total
= console_input_get_hist( console
, req
->index
);
1419 release_object( console
);
1422 /* creates a screen buffer */
1423 DECL_HANDLER(create_console_output
)
1425 struct console_input
* console
;
1426 struct screen_buffer
* screen_buffer
;
1428 if (!(console
= console_input_get( req
->handle_in
, GENERIC_WRITE
))) return;
1430 screen_buffer
= create_console_output( console
);
1433 /* FIXME: should store sharing and test it when opening the CONOUT$ device
1434 * see file.c on how this could be done */
1435 reply
->handle_out
= alloc_handle( current
->process
, screen_buffer
,
1436 req
->access
, req
->inherit
);
1437 release_object( screen_buffer
);
1439 release_object( console
);
1442 /* set info about a console screen buffer */
1443 DECL_HANDLER(set_console_output_info
)
1445 struct screen_buffer
*screen_buffer
;
1447 if ((screen_buffer
= (struct screen_buffer
*)get_handle_obj( current
->process
, req
->handle
,
1448 GENERIC_WRITE
, &screen_buffer_ops
)))
1450 set_console_output_info( screen_buffer
, req
);
1451 release_object( screen_buffer
);
1455 /* get info about a console screen buffer */
1456 DECL_HANDLER(get_console_output_info
)
1458 struct screen_buffer
*screen_buffer
;
1460 if ((screen_buffer
= (struct screen_buffer
*)get_handle_obj( current
->process
, req
->handle
,
1461 GENERIC_READ
, &screen_buffer_ops
)))
1463 reply
->cursor_size
= screen_buffer
->cursor_size
;
1464 reply
->cursor_visible
= screen_buffer
->cursor_visible
;
1465 reply
->cursor_x
= screen_buffer
->cursor_x
;
1466 reply
->cursor_y
= screen_buffer
->cursor_y
;
1467 reply
->width
= screen_buffer
->width
;
1468 reply
->height
= screen_buffer
->height
;
1469 reply
->attr
= screen_buffer
->attr
;
1470 reply
->win_left
= screen_buffer
->win
.left
;
1471 reply
->win_top
= screen_buffer
->win
.top
;
1472 reply
->win_right
= screen_buffer
->win
.right
;
1473 reply
->win_bottom
= screen_buffer
->win
.bottom
;
1474 reply
->max_width
= screen_buffer
->max_width
;
1475 reply
->max_height
= screen_buffer
->max_height
;
1476 release_object( screen_buffer
);
1480 /* read data (chars & attrs) from a screen buffer */
1481 DECL_HANDLER(read_console_output
)
1483 struct screen_buffer
*screen_buffer
;
1485 if ((screen_buffer
= (struct screen_buffer
*)get_handle_obj( current
->process
, req
->handle
,
1486 GENERIC_READ
, &screen_buffer_ops
)))
1488 read_console_output( screen_buffer
, req
->x
, req
->y
, req
->mode
, req
->wrap
);
1489 reply
->width
= screen_buffer
->width
;
1490 reply
->height
= screen_buffer
->height
;
1491 release_object( screen_buffer
);
1495 /* write data (char and/or attrs) to a screen buffer */
1496 DECL_HANDLER(write_console_output
)
1498 struct screen_buffer
*screen_buffer
;
1500 if ((screen_buffer
= (struct screen_buffer
*)get_handle_obj( current
->process
, req
->handle
,
1501 GENERIC_WRITE
, &screen_buffer_ops
)))
1503 reply
->written
= write_console_output( screen_buffer
, get_req_data_size(), get_req_data(),
1504 req
->mode
, req
->x
, req
->y
, req
->wrap
);
1505 reply
->width
= screen_buffer
->width
;
1506 reply
->height
= screen_buffer
->height
;
1507 release_object( screen_buffer
);
1511 /* fill a screen buffer with constant data (chars and/or attributes) */
1512 DECL_HANDLER(fill_console_output
)
1514 struct screen_buffer
*screen_buffer
;
1516 if ((screen_buffer
= (struct screen_buffer
*)get_handle_obj( current
->process
, req
->handle
,
1517 GENERIC_WRITE
, &screen_buffer_ops
)))
1519 reply
->written
= fill_console_output( screen_buffer
, req
->data
, req
->mode
,
1520 req
->x
, req
->y
, req
->count
, req
->wrap
);
1521 release_object( screen_buffer
);
1525 /* move a rect of data in a screen buffer */
1526 DECL_HANDLER(move_console_output
)
1528 scroll_console_output( req
->handle
, req
->x_src
, req
->y_src
, req
->x_dst
, req
->y_dst
,
1532 /* sends a signal to a console (process, group...) */
1533 DECL_HANDLER(send_console_signal
)
1537 group
= req
->group_id
? req
->group_id
: current
->process
->group_id
;
1540 set_error( STATUS_INVALID_PARAMETER
);
1542 propagate_console_signal( current
->process
->console
, req
->signal
, group
);