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"
38 static void console_input_dump( struct object
*obj
, int verbose
);
39 static void console_input_destroy( struct object
*obj
);
41 static const struct object_ops console_input_ops
=
43 sizeof(struct console_input
), /* size */
44 console_input_dump
, /* dump */
45 no_add_queue
, /* add_queue */
46 NULL
, /* remove_queue */
48 no_satisfied
, /* satisfied */
49 no_signal
, /* signal */
50 no_get_fd
, /* get_fd */
51 console_input_destroy
/* destroy */
54 static void console_input_events_dump( struct object
*obj
, int verbose
);
55 static void console_input_events_destroy( struct object
*obj
);
56 static int console_input_events_signaled( struct object
*obj
, struct thread
*thread
);
58 struct console_input_events
60 struct object obj
; /* object header */
61 int num_alloc
; /* number of allocated events */
62 int num_used
; /* number of actually used events */
63 struct console_renderer_event
* events
;
66 static const struct object_ops console_input_events_ops
=
68 sizeof(struct console_input_events
), /* size */
69 console_input_events_dump
, /* dump */
70 add_queue
, /* add_queue */
71 remove_queue
, /* remove_queue */
72 console_input_events_signaled
, /* signaled */
73 no_satisfied
, /* satisfied */
74 no_signal
, /* signal */
75 no_get_fd
, /* get_fd */
76 console_input_events_destroy
/* destroy */
81 struct object obj
; /* object header */
82 struct list entry
; /* entry in list of all screen buffers */
83 struct console_input
*input
; /* associated console input */
84 int mode
; /* output mode */
85 int cursor_size
; /* size of cursor (percentage filled) */
86 int cursor_visible
;/* cursor visibility flag */
87 int cursor_x
; /* position of cursor */
88 int cursor_y
; /* position of cursor */
89 int width
; /* size (w-h) of the screen buffer */
91 int max_width
; /* size (w-h) of the window given font size */
93 char_info_t
*data
; /* the data for each cell - a width x height matrix */
94 unsigned short attr
; /* default attribute for screen buffer */
95 rectangle_t win
; /* current visible window on the screen buffer *
96 * as seen in wineconsole */
99 static void screen_buffer_dump( struct object
*obj
, int verbose
);
100 static void screen_buffer_destroy( struct object
*obj
);
102 static const struct object_ops screen_buffer_ops
=
104 sizeof(struct screen_buffer
), /* size */
105 screen_buffer_dump
, /* dump */
106 no_add_queue
, /* add_queue */
107 NULL
, /* remove_queue */
109 NULL
, /* satisfied */
110 no_signal
, /* signal */
111 no_get_fd
, /* get_fd */
112 screen_buffer_destroy
/* destroy */
115 static struct list screen_buffer_list
= LIST_INIT(screen_buffer_list
);
117 static const char_info_t empty_char_info
= { ' ', 0x000f }; /* white on black space */
119 /* dumps the renderer events of a console */
120 static void console_input_events_dump( struct object
*obj
, int verbose
)
122 struct console_input_events
*evts
= (struct console_input_events
*)obj
;
123 assert( obj
->ops
== &console_input_events_ops
);
124 fprintf( stderr
, "Console input events: %d/%d events\n",
125 evts
->num_used
, evts
->num_alloc
);
128 /* destroys the renderer events of a console */
129 static void console_input_events_destroy( struct object
*obj
)
131 struct console_input_events
*evts
= (struct console_input_events
*)obj
;
132 assert( obj
->ops
== &console_input_events_ops
);
133 free( evts
->events
);
136 /* the renderer events list is signaled when it's not empty */
137 static int console_input_events_signaled( struct object
*obj
, struct thread
*thread
)
139 struct console_input_events
*evts
= (struct console_input_events
*)obj
;
140 assert( obj
->ops
== &console_input_events_ops
);
141 return (evts
->num_used
!= 0);
144 /* add an event to the console's renderer events list */
145 static void console_input_events_append( struct console_input_events
* evts
,
146 struct console_renderer_event
* evt
)
148 int collapsed
= FALSE
;
150 /* to be done even when evt has been generated by the rendere ? */
152 /* try to collapse evt into current queue's events */
155 struct console_renderer_event
* last
= &evts
->events
[evts
->num_used
- 1];
157 if (last
->event
== CONSOLE_RENDERER_UPDATE_EVENT
&&
158 evt
->event
== CONSOLE_RENDERER_UPDATE_EVENT
)
160 /* if two update events overlap, collapse them into a single one */
161 if (last
->u
.update
.bottom
+ 1 >= evt
->u
.update
.top
&&
162 evt
->u
.update
.bottom
+ 1 >= last
->u
.update
.top
)
164 last
->u
.update
.top
= min(last
->u
.update
.top
, evt
->u
.update
.top
);
165 last
->u
.update
.bottom
= max(last
->u
.update
.bottom
, evt
->u
.update
.bottom
);
172 if (evts
->num_used
== evts
->num_alloc
)
174 evts
->num_alloc
+= 16;
175 evts
->events
= realloc( evts
->events
, evts
->num_alloc
* sizeof(*evt
) );
176 assert(evts
->events
);
178 evts
->events
[evts
->num_used
++] = *evt
;
180 wake_up( &evts
->obj
, 0 );
183 /* retrieves events from the console's renderer events list */
184 static void console_input_events_get( struct console_input_events
* evts
)
186 size_t num
= get_reply_max_size() / sizeof(evts
->events
[0]);
188 if (num
> evts
->num_used
) num
= evts
->num_used
;
189 set_reply_data( evts
->events
, num
* sizeof(evts
->events
[0]) );
190 if (num
< evts
->num_used
)
192 memmove( &evts
->events
[0], &evts
->events
[num
],
193 (evts
->num_used
- num
) * sizeof(evts
->events
[0]) );
195 evts
->num_used
-= num
;
198 static struct console_input_events
*create_console_input_events(void)
200 struct console_input_events
* evt
;
202 if (!(evt
= alloc_object( &console_input_events_ops
))) return NULL
;
203 evt
->num_alloc
= evt
->num_used
= 0;
208 static struct object
*create_console_input( struct thread
* renderer
)
210 struct console_input
*console_input
;
212 if (!(console_input
= alloc_object( &console_input_ops
))) return NULL
;
213 console_input
->renderer
= renderer
;
214 console_input
->mode
= ENABLE_PROCESSED_INPUT
| ENABLE_LINE_INPUT
|
215 ENABLE_ECHO_INPUT
| ENABLE_MOUSE_INPUT
;
216 console_input
->num_proc
= 0;
217 console_input
->active
= NULL
;
218 console_input
->recnum
= 0;
219 console_input
->records
= NULL
;
220 console_input
->evt
= create_console_input_events();
221 console_input
->title
= NULL
;
222 console_input
->history_size
= 50;
223 console_input
->history
= calloc( console_input
->history_size
, sizeof(WCHAR
*) );
224 console_input
->history_index
= 0;
225 console_input
->history_mode
= 0;
226 console_input
->edition_mode
= 0;
227 console_input
->event
= create_event( NULL
, 0, 1, 0 );
229 if (!console_input
->history
|| !console_input
->evt
)
231 release_object( console_input
);
234 return &console_input
->obj
;
237 static struct screen_buffer
*create_console_output( struct console_input
*console_input
)
239 struct screen_buffer
*screen_buffer
;
240 struct console_renderer_event evt
;
243 if (!(screen_buffer
= alloc_object( &screen_buffer_ops
))) return NULL
;
244 screen_buffer
->mode
= ENABLE_PROCESSED_OUTPUT
| ENABLE_WRAP_AT_EOL_OUTPUT
;
245 screen_buffer
->input
= console_input
;
246 screen_buffer
->cursor_size
= 100;
247 screen_buffer
->cursor_visible
= 1;
248 screen_buffer
->width
= 80;
249 screen_buffer
->height
= 150;
250 screen_buffer
->max_width
= 80;
251 screen_buffer
->max_height
= 25;
252 screen_buffer
->cursor_x
= 0;
253 screen_buffer
->cursor_y
= 0;
254 screen_buffer
->attr
= 0x0F;
255 screen_buffer
->win
.left
= 0;
256 screen_buffer
->win
.right
= screen_buffer
->max_width
- 1;
257 screen_buffer
->win
.top
= 0;
258 screen_buffer
->win
.bottom
= screen_buffer
->max_height
- 1;
260 list_add_head( &screen_buffer_list
, &screen_buffer
->entry
);
262 if (!(screen_buffer
->data
= malloc( screen_buffer
->width
* screen_buffer
->height
*
263 sizeof(*screen_buffer
->data
) )))
265 release_object( screen_buffer
);
268 /* clear the first row */
269 for (i
= 0; i
< screen_buffer
->width
; i
++) screen_buffer
->data
[i
] = empty_char_info
;
270 /* and copy it to all other rows */
271 for (i
= 1; i
< screen_buffer
->height
; i
++)
272 memcpy( &screen_buffer
->data
[i
* screen_buffer
->width
], screen_buffer
->data
,
273 screen_buffer
->width
* sizeof(char_info_t
) );
275 if (!console_input
->active
)
277 console_input
->active
= (struct screen_buffer
*)grab_object( screen_buffer
);
279 /* generate the initial events */
280 evt
.event
= CONSOLE_RENDERER_ACTIVE_SB_EVENT
;
281 console_input_events_append( console_input
->evt
, &evt
);
283 evt
.event
= CONSOLE_RENDERER_SB_RESIZE_EVENT
;
284 evt
.u
.resize
.width
= screen_buffer
->width
;
285 evt
.u
.resize
.height
= screen_buffer
->height
;
286 console_input_events_append( console_input
->evt
, &evt
);
288 evt
.event
= CONSOLE_RENDERER_DISPLAY_EVENT
;
289 evt
.u
.display
.left
= screen_buffer
->win
.left
;
290 evt
.u
.display
.top
= screen_buffer
->win
.top
;
291 evt
.u
.display
.width
= screen_buffer
->win
.right
- screen_buffer
->win
.left
+ 1;
292 evt
.u
.display
.height
= screen_buffer
->win
.bottom
- screen_buffer
->win
.top
+ 1;
293 console_input_events_append( console_input
->evt
, &evt
);
295 evt
.event
= CONSOLE_RENDERER_UPDATE_EVENT
;
296 evt
.u
.update
.top
= 0;
297 evt
.u
.update
.bottom
= screen_buffer
->height
- 1;
298 console_input_events_append( console_input
->evt
, &evt
);
300 evt
.event
= CONSOLE_RENDERER_CURSOR_GEOM_EVENT
;
301 evt
.u
.cursor_geom
.size
= screen_buffer
->cursor_size
;
302 evt
.u
.cursor_geom
.visible
= screen_buffer
->cursor_visible
;
303 console_input_events_append( console_input
->evt
, &evt
);
305 evt
.event
= CONSOLE_RENDERER_CURSOR_POS_EVENT
;
306 evt
.u
.cursor_pos
.x
= screen_buffer
->cursor_x
;
307 evt
.u
.cursor_pos
.y
= screen_buffer
->cursor_y
;
308 console_input_events_append( console_input
->evt
, &evt
);
310 return screen_buffer
;
313 /* free the console for this process */
314 int free_console( struct process
*process
)
316 struct console_input
* console
= process
->console
;
318 if (!console
|| !console
->renderer
) return 0;
320 process
->console
= NULL
;
321 if (--console
->num_proc
== 0)
323 /* all processes have terminated... tell the renderer to terminate too */
324 struct console_renderer_event evt
;
325 evt
.event
= CONSOLE_RENDERER_EXIT_EVENT
;
326 console_input_events_append( console
->evt
, &evt
);
328 release_object( console
);
333 /* let process inherit the console from parent... this handle two cases :
334 * 1/ generic console inheritance
335 * 2/ parent is a renderer which launches process, and process should attach to the console
336 * renderered by parent
338 void inherit_console(struct thread
*parent_thread
, struct process
*process
, obj_handle_t hconin
)
341 struct process
* parent
= parent_thread
->process
;
343 /* if parent is a renderer, then attach current process to its console
348 struct console_input
* console
;
350 /* FIXME: should we check some access rights ? */
351 if ((console
= (struct console_input
*)get_handle_obj( parent
, hconin
,
352 0, &console_input_ops
)))
354 if (console
->renderer
== parent_thread
)
356 process
->console
= (struct console_input
*)grab_object( console
);
357 process
->console
->num_proc
++;
360 release_object( console
);
363 /* otherwise, if parent has a console, attach child to this console */
364 if (!done
&& parent
->console
)
366 assert(parent
->console
->renderer
);
367 process
->console
= (struct console_input
*)grab_object( parent
->console
);
368 process
->console
->num_proc
++;
372 static struct console_input
* console_input_get( obj_handle_t handle
, unsigned access
)
374 struct console_input
* console
= NULL
;
377 console
= (struct console_input
*)get_handle_obj( current
->process
, handle
,
378 access
, &console_input_ops
);
379 else if (current
->process
->console
)
381 assert( current
->process
->console
->renderer
);
382 console
= (struct console_input
*)grab_object( current
->process
->console
);
385 if (!console
&& !get_error()) set_error(STATUS_INVALID_PARAMETER
);
389 struct console_signal_info
391 struct console_input
*console
;
396 static int propagate_console_signal_cb(struct process
*process
, void *user
)
398 struct console_signal_info
* csi
= (struct console_signal_info
*)user
;
400 if (process
->console
== csi
->console
&& process
->running_threads
&&
401 (!csi
->group
|| process
->group_id
== csi
->group
))
403 /* find a suitable thread to signal */
404 struct thread
*thread
;
405 LIST_FOR_EACH_ENTRY( thread
, &process
->thread_list
, struct thread
, proc_entry
)
407 if (send_thread_signal( thread
, csi
->signal
)) break;
413 static void propagate_console_signal( struct console_input
*console
,
414 int sig
, process_id_t group_id
)
416 struct console_signal_info csi
;
420 set_error( STATUS_INVALID_PARAMETER
);
423 /* FIXME: should support the other events (like CTRL_BREAK) */
424 if (sig
!= CTRL_C_EVENT
)
426 set_error( STATUS_NOT_IMPLEMENTED
);
429 csi
.console
= console
;
431 csi
.group
= group_id
;
433 enum_processes(propagate_console_signal_cb
, &csi
);
436 static int get_console_mode( obj_handle_t handle
)
441 if ((obj
= get_handle_obj( current
->process
, handle
, GENERIC_READ
, NULL
)))
443 if (obj
->ops
== &console_input_ops
)
444 ret
= ((struct console_input
*)obj
)->mode
;
445 else if (obj
->ops
== &screen_buffer_ops
)
446 ret
= ((struct screen_buffer
*)obj
)->mode
;
448 set_error( STATUS_OBJECT_TYPE_MISMATCH
);
449 release_object( obj
);
454 /* changes the mode of either a console input or a screen buffer */
455 static int set_console_mode( obj_handle_t handle
, int mode
)
460 if (!(obj
= get_handle_obj( current
->process
, handle
, GENERIC_WRITE
, NULL
)))
462 if (obj
->ops
== &console_input_ops
)
464 /* FIXME: if we remove the edit mode bits, we need (???) to clean up the history */
465 ((struct console_input
*)obj
)->mode
= mode
;
468 else if (obj
->ops
== &screen_buffer_ops
)
470 ((struct screen_buffer
*)obj
)->mode
= mode
;
473 else set_error( STATUS_OBJECT_TYPE_MISMATCH
);
474 release_object( obj
);
478 /* add input events to a console input queue */
479 static int write_console_input( struct console_input
* console
, int count
,
480 const INPUT_RECORD
*records
)
482 INPUT_RECORD
*new_rec
;
484 if (!count
) return 0;
485 if (!(new_rec
= realloc( console
->records
,
486 (console
->recnum
+ count
) * sizeof(INPUT_RECORD
) )))
488 set_error( STATUS_NO_MEMORY
);
489 release_object( console
);
492 console
->records
= new_rec
;
493 memcpy( new_rec
+ console
->recnum
, records
, count
* sizeof(INPUT_RECORD
) );
495 if (console
->mode
& ENABLE_PROCESSED_INPUT
)
500 if (records
[i
].EventType
== KEY_EVENT
&&
501 records
[i
].Event
.KeyEvent
.uChar
.UnicodeChar
== 'C' - 64 &&
502 !(records
[i
].Event
.KeyEvent
.dwControlKeyState
& ENHANCED_KEY
))
505 memcpy( &console
->records
[console
->recnum
+ i
],
506 &console
->records
[console
->recnum
+ i
+ 1],
507 (count
- i
- 1) * sizeof(INPUT_RECORD
) );
509 if (records
[i
].Event
.KeyEvent
.bKeyDown
)
511 /* send SIGINT to all processes attached to this console */
512 propagate_console_signal( console
, CTRL_C_EVENT
, 0 );
518 if (!console
->recnum
&& count
) set_event( console
->event
);
519 console
->recnum
+= count
;
523 /* retrieve a pointer to the console input records */
524 static int read_console_input( obj_handle_t handle
, int count
, int flush
)
526 struct console_input
*console
;
528 if (!(console
= (struct console_input
*)get_handle_obj( current
->process
, handle
,
529 GENERIC_READ
, &console_input_ops
)))
534 /* special case: do not retrieve anything, but return
535 * the total number of records available */
536 count
= console
->recnum
;
540 if (count
> console
->recnum
) count
= console
->recnum
;
541 set_reply_data( console
->records
, count
* sizeof(INPUT_RECORD
) );
546 for (i
= count
; i
< console
->recnum
; i
++)
547 console
->records
[i
-count
] = console
->records
[i
];
548 if ((console
->recnum
-= count
) > 0)
550 INPUT_RECORD
*new_rec
= realloc( console
->records
,
551 console
->recnum
* sizeof(INPUT_RECORD
) );
552 if (new_rec
) console
->records
= new_rec
;
556 free( console
->records
);
557 console
->records
= NULL
;
558 reset_event( console
->event
);
561 release_object( console
);
565 /* set misc console input information */
566 static int set_console_input_info( const struct set_console_input_info_request
*req
,
567 const WCHAR
*title
, size_t len
)
569 struct console_input
*console
;
570 struct console_renderer_event evt
;
572 if (!(console
= console_input_get( req
->handle
, GENERIC_WRITE
))) goto error
;
574 if (req
->mask
& SET_CONSOLE_INPUT_INFO_ACTIVE_SB
)
576 struct screen_buffer
*screen_buffer
;
578 screen_buffer
= (struct screen_buffer
*)get_handle_obj( current
->process
, req
->active_sb
,
579 GENERIC_READ
, &screen_buffer_ops
);
580 if (!screen_buffer
|| screen_buffer
->input
!= console
)
582 set_error( STATUS_INVALID_PARAMETER
);
583 if (screen_buffer
) release_object( screen_buffer
);
587 if (screen_buffer
!= console
->active
)
589 if (console
->active
) release_object( console
->active
);
590 console
->active
= screen_buffer
;
591 evt
.event
= CONSOLE_RENDERER_ACTIVE_SB_EVENT
;
592 console_input_events_append( console
->evt
, &evt
);
595 release_object( screen_buffer
);
597 if (req
->mask
& SET_CONSOLE_INPUT_INFO_TITLE
)
599 WCHAR
*new_title
= mem_alloc( len
+ sizeof(WCHAR
) );
602 memcpy( new_title
, title
, len
);
603 new_title
[len
/ sizeof(WCHAR
)] = 0;
604 if (console
->title
) free( console
->title
);
605 console
->title
= new_title
;
606 evt
.event
= CONSOLE_RENDERER_TITLE_EVENT
;
607 console_input_events_append( console
->evt
, &evt
);
610 if (req
->mask
& SET_CONSOLE_INPUT_INFO_HISTORY_MODE
)
612 console
->history_mode
= req
->history_mode
;
614 if ((req
->mask
& SET_CONSOLE_INPUT_INFO_HISTORY_SIZE
) &&
615 console
->history_size
!= req
->history_size
)
621 if (req
->history_size
)
623 mem
= mem_alloc( req
->history_size
* sizeof(WCHAR
*) );
624 if (!mem
) goto error
;
625 memset( mem
, 0, req
->history_size
* sizeof(WCHAR
*) );
628 delta
= (console
->history_index
> req
->history_size
) ?
629 (console
->history_index
- req
->history_size
) : 0;
631 for (i
= delta
; i
< console
->history_index
; i
++)
633 mem
[i
- delta
] = console
->history
[i
];
634 console
->history
[i
] = NULL
;
636 console
->history_index
-= delta
;
638 for (i
= 0; i
< console
->history_size
; i
++)
639 if (console
->history
[i
]) free( console
->history
[i
] );
640 free( console
->history
);
641 console
->history
= mem
;
642 console
->history_size
= req
->history_size
;
644 if (req
->mask
& SET_CONSOLE_INPUT_INFO_EDITION_MODE
)
646 console
->edition_mode
= req
->edition_mode
;
648 release_object( console
);
651 if (console
) release_object( console
);
655 /* resize a screen buffer */
656 static int change_screen_buffer_size( struct screen_buffer
*screen_buffer
,
657 int new_width
, int new_height
)
659 int i
, old_width
, old_height
, copy_width
, copy_height
;
660 char_info_t
*new_data
;
662 if (!(new_data
= malloc( new_width
* new_height
* sizeof(*new_data
) )))
664 set_error( STATUS_NO_MEMORY
);
667 old_width
= screen_buffer
->width
;
668 old_height
= screen_buffer
->height
;
669 copy_width
= min( old_width
, new_width
);
670 copy_height
= min( old_height
, new_height
);
672 /* copy all the rows */
673 for (i
= 0; i
< copy_height
; i
++)
675 memcpy( &new_data
[i
* new_width
], &screen_buffer
->data
[i
* old_width
],
676 copy_width
* sizeof(char_info_t
) );
679 /* clear the end of each row */
680 if (new_width
> old_width
)
683 for (i
= old_width
; i
< new_width
; i
++) new_data
[i
] = empty_char_info
;
684 /* and blast it to the other rows */
685 for (i
= 1; i
< copy_height
; i
++)
686 memcpy( &new_data
[i
* new_width
+ old_width
], &new_data
[old_width
],
687 (new_width
- old_width
) * sizeof(char_info_t
) );
690 /* clear remaining rows */
691 if (new_height
> old_height
)
694 for (i
= 0; i
< new_width
; i
++) new_data
[old_height
* new_width
+ i
] = empty_char_info
;
695 /* and blast it to the other rows */
696 for (i
= old_height
+1; i
< new_height
; i
++)
697 memcpy( &new_data
[i
* new_width
], &new_data
[old_height
* new_width
],
698 new_width
* sizeof(char_info_t
) );
700 free( screen_buffer
->data
);
701 screen_buffer
->data
= new_data
;
702 screen_buffer
->width
= new_width
;
703 screen_buffer
->height
= new_height
;
707 /* set misc screen buffer information */
708 static int set_console_output_info( struct screen_buffer
*screen_buffer
,
709 const struct set_console_output_info_request
*req
)
711 struct console_renderer_event evt
;
713 if (req
->mask
& SET_CONSOLE_OUTPUT_INFO_CURSOR_GEOM
)
715 if (req
->cursor_size
< 1 || req
->cursor_size
> 100)
717 set_error( STATUS_INVALID_PARAMETER
);
720 if (screen_buffer
->cursor_size
!= req
->cursor_size
||
721 screen_buffer
->cursor_visible
!= req
->cursor_visible
)
723 screen_buffer
->cursor_size
= req
->cursor_size
;
724 screen_buffer
->cursor_visible
= req
->cursor_visible
;
725 evt
.event
= CONSOLE_RENDERER_CURSOR_GEOM_EVENT
;
726 evt
.u
.cursor_geom
.size
= req
->cursor_size
;
727 evt
.u
.cursor_geom
.visible
= req
->cursor_visible
;
728 console_input_events_append( screen_buffer
->input
->evt
, &evt
);
731 if (req
->mask
& SET_CONSOLE_OUTPUT_INFO_CURSOR_POS
)
733 if (req
->cursor_x
< 0 || req
->cursor_x
>= screen_buffer
->width
||
734 req
->cursor_y
< 0 || req
->cursor_y
>= screen_buffer
->height
)
736 set_error( STATUS_INVALID_PARAMETER
);
739 if (screen_buffer
->cursor_x
!= req
->cursor_x
|| screen_buffer
->cursor_y
!= req
->cursor_y
)
741 screen_buffer
->cursor_x
= req
->cursor_x
;
742 screen_buffer
->cursor_y
= req
->cursor_y
;
743 evt
.event
= CONSOLE_RENDERER_CURSOR_POS_EVENT
;
744 evt
.u
.cursor_pos
.x
= req
->cursor_x
;
745 evt
.u
.cursor_pos
.y
= req
->cursor_y
;
746 console_input_events_append( screen_buffer
->input
->evt
, &evt
);
749 if (req
->mask
& SET_CONSOLE_OUTPUT_INFO_SIZE
)
753 /* new screen-buffer cannot be smaller than actual window */
754 if (req
->width
< screen_buffer
->win
.right
- screen_buffer
->win
.left
+ 1 ||
755 req
->height
< screen_buffer
->win
.bottom
- screen_buffer
->win
.top
+ 1)
757 set_error( STATUS_INVALID_PARAMETER
);
760 /* FIXME: there are also some basic minimum and max size to deal with */
761 if (!change_screen_buffer_size( screen_buffer
, req
->width
, req
->height
)) return 0;
763 evt
.event
= CONSOLE_RENDERER_SB_RESIZE_EVENT
;
764 evt
.u
.resize
.width
= req
->width
;
765 evt
.u
.resize
.height
= req
->height
;
766 console_input_events_append( screen_buffer
->input
->evt
, &evt
);
768 evt
.event
= CONSOLE_RENDERER_UPDATE_EVENT
;
769 evt
.u
.update
.top
= 0;
770 evt
.u
.update
.bottom
= screen_buffer
->height
- 1;
771 console_input_events_append( screen_buffer
->input
->evt
, &evt
);
773 /* scroll window to display sb */
774 if (screen_buffer
->win
.right
>= req
->width
)
776 screen_buffer
->win
.right
-= screen_buffer
->win
.left
;
777 screen_buffer
->win
.left
= 0;
779 if (screen_buffer
->win
.bottom
>= req
->height
)
781 screen_buffer
->win
.bottom
-= screen_buffer
->win
.top
;
782 screen_buffer
->win
.top
= 0;
784 /* reset cursor if needed (normally, if cursor was outside of new sb, the
785 * window has been shifted so that the new position of the cursor will be
788 if (screen_buffer
->cursor_x
>= req
->width
)
790 screen_buffer
->cursor_x
= req
->width
- 1;
793 if (screen_buffer
->cursor_y
>= req
->height
)
795 screen_buffer
->cursor_y
= req
->height
- 1;
800 evt
.event
= CONSOLE_RENDERER_CURSOR_POS_EVENT
;
801 evt
.u
.cursor_pos
.x
= req
->cursor_x
;
802 evt
.u
.cursor_pos
.y
= req
->cursor_y
;
803 console_input_events_append( screen_buffer
->input
->evt
, &evt
);
806 if (screen_buffer
== screen_buffer
->input
->active
&&
807 screen_buffer
->input
->mode
& ENABLE_WINDOW_INPUT
)
810 ir
.EventType
= WINDOW_BUFFER_SIZE_EVENT
;
811 ir
.Event
.WindowBufferSizeEvent
.dwSize
.X
= req
->width
;
812 ir
.Event
.WindowBufferSizeEvent
.dwSize
.Y
= req
->height
;
813 write_console_input( screen_buffer
->input
, 1, &ir
);
816 if (req
->mask
& SET_CONSOLE_OUTPUT_INFO_ATTR
)
818 screen_buffer
->attr
= req
->attr
;
820 if (req
->mask
& SET_CONSOLE_OUTPUT_INFO_DISPLAY_WINDOW
)
822 if (req
->win_left
< 0 || req
->win_left
> req
->win_right
||
823 req
->win_right
>= screen_buffer
->width
||
824 req
->win_top
< 0 || req
->win_top
> req
->win_bottom
||
825 req
->win_bottom
>= screen_buffer
->height
)
827 set_error( STATUS_INVALID_PARAMETER
);
830 if (screen_buffer
->win
.left
!= req
->win_left
|| screen_buffer
->win
.top
!= req
->win_top
||
831 screen_buffer
->win
.right
!= req
->win_right
|| screen_buffer
->win
.bottom
!= req
->win_bottom
)
833 screen_buffer
->win
.left
= req
->win_left
;
834 screen_buffer
->win
.top
= req
->win_top
;
835 screen_buffer
->win
.right
= req
->win_right
;
836 screen_buffer
->win
.bottom
= req
->win_bottom
;
837 evt
.event
= CONSOLE_RENDERER_DISPLAY_EVENT
;
838 evt
.u
.display
.left
= req
->win_left
;
839 evt
.u
.display
.top
= req
->win_top
;
840 evt
.u
.display
.width
= req
->win_right
- req
->win_left
+ 1;
841 evt
.u
.display
.height
= req
->win_bottom
- req
->win_top
+ 1;
842 console_input_events_append( screen_buffer
->input
->evt
, &evt
);
845 if (req
->mask
& SET_CONSOLE_OUTPUT_INFO_MAX_SIZE
)
847 /* can only be done by renderer */
848 if (current
->process
->console
!= screen_buffer
->input
)
850 set_error( STATUS_INVALID_PARAMETER
);
854 screen_buffer
->max_width
= req
->max_width
;
855 screen_buffer
->max_height
= req
->max_height
;
861 /* appends a new line to history (history is a fixed size array) */
862 static void console_input_append_hist( struct console_input
* console
, const WCHAR
* buf
, size_t len
)
864 WCHAR
* ptr
= mem_alloc( (len
+ 1) * sizeof(WCHAR
) );
868 set_error( STATUS_NO_MEMORY
);
871 if (!console
|| !console
->history_size
)
873 set_error( STATUS_INVALID_PARAMETER
); /* FIXME */
877 memcpy( ptr
, buf
, len
* sizeof(WCHAR
) );
880 if (console
->history_mode
&& console
->history_index
&&
881 strncmpW( console
->history
[console
->history_index
- 1], ptr
, len
* sizeof(WCHAR
) ) == 0)
883 /* ok, mode ask us to not use twice the same string...
884 * so just free mem and returns
886 set_error( STATUS_ALIAS_EXISTS
);
891 if (console
->history_index
< console
->history_size
)
893 console
->history
[console
->history_index
++] = ptr
;
897 free( console
->history
[0]) ;
898 memmove( &console
->history
[0], &console
->history
[1],
899 (console
->history_size
- 1) * sizeof(WCHAR
*) );
900 console
->history
[console
->history_size
- 1] = ptr
;
904 /* returns a line from the cache */
905 static size_t console_input_get_hist( struct console_input
*console
, int index
)
909 if (index
>= console
->history_index
) set_error( STATUS_INVALID_PARAMETER
);
912 ret
= strlenW( console
->history
[index
] ) * sizeof(WCHAR
);
913 set_reply_data( console
->history
[index
], min( ret
, get_reply_max_size() ));
919 static void console_input_dump( struct object
*obj
, int verbose
)
921 struct console_input
*console
= (struct console_input
*)obj
;
922 assert( obj
->ops
== &console_input_ops
);
923 fprintf( stderr
, "Console input active=%p evt=%p\n",
924 console
->active
, console
->evt
);
927 static void console_input_destroy( struct object
*obj
)
929 struct console_input
* console_in
= (struct console_input
*)obj
;
930 struct screen_buffer
* curr
;
933 assert( obj
->ops
== &console_input_ops
);
934 if (console_in
->title
) free( console_in
->title
);
935 if (console_in
->records
) free( console_in
->records
);
937 if (console_in
->active
) release_object( console_in
->active
);
938 console_in
->active
= NULL
;
940 LIST_FOR_EACH_ENTRY( curr
, &screen_buffer_list
, struct screen_buffer
, entry
)
942 if (curr
->input
== console_in
) curr
->input
= NULL
;
945 release_object( console_in
->evt
);
946 console_in
->evt
= NULL
;
947 release_object( console_in
->event
);
949 for (i
= 0; i
< console_in
->history_size
; i
++)
950 if (console_in
->history
[i
]) free( console_in
->history
[i
] );
951 if (console_in
->history
) free( console_in
->history
);
954 static void screen_buffer_dump( struct object
*obj
, int verbose
)
956 struct screen_buffer
*screen_buffer
= (struct screen_buffer
*)obj
;
957 assert( obj
->ops
== &screen_buffer_ops
);
959 fprintf(stderr
, "Console screen buffer input=%p\n", screen_buffer
->input
);
962 static void screen_buffer_destroy( struct object
*obj
)
964 struct screen_buffer
*screen_buffer
= (struct screen_buffer
*)obj
;
966 assert( obj
->ops
== &screen_buffer_ops
);
968 list_remove( &screen_buffer
->entry
);
970 if (screen_buffer
->input
&& screen_buffer
->input
->active
== screen_buffer
)
972 struct screen_buffer
*sb
;
974 screen_buffer
->input
->active
= NULL
;
975 LIST_FOR_EACH_ENTRY( sb
, &screen_buffer_list
, struct screen_buffer
, entry
)
977 if (sb
->input
== screen_buffer
->input
)
979 sb
->input
->active
= sb
;
984 if (screen_buffer
->data
) free( screen_buffer
->data
);
987 /* write data into a screen buffer */
988 static int write_console_output( struct screen_buffer
*screen_buffer
, size_t size
,
989 const void* data
, enum char_info_mode mode
,
990 int x
, int y
, int wrap
)
993 char_info_t
*end
, *dest
= screen_buffer
->data
+ y
* screen_buffer
->width
+ x
;
995 if (y
>= screen_buffer
->height
) return 0;
998 end
= screen_buffer
->data
+ screen_buffer
->height
* screen_buffer
->width
;
1000 end
= screen_buffer
->data
+ (y
+1) * screen_buffer
->width
;
1004 case CHAR_INFO_MODE_TEXT
:
1006 const WCHAR
*ptr
= data
;
1007 for (i
= 0; i
< size
/sizeof(*ptr
) && dest
< end
; dest
++, i
++) dest
->ch
= ptr
[i
];
1010 case CHAR_INFO_MODE_ATTR
:
1012 const unsigned short *ptr
= data
;
1013 for (i
= 0; i
< size
/sizeof(*ptr
) && dest
< end
; dest
++, i
++) dest
->attr
= ptr
[i
];
1016 case CHAR_INFO_MODE_TEXTATTR
:
1018 const char_info_t
*ptr
= data
;
1019 for (i
= 0; i
< size
/sizeof(*ptr
) && dest
< end
; dest
++, i
++) *dest
= ptr
[i
];
1022 case CHAR_INFO_MODE_TEXTSTDATTR
:
1024 const WCHAR
*ptr
= data
;
1025 for (i
= 0; i
< size
/sizeof(*ptr
) && dest
< end
; dest
++, i
++)
1028 dest
->attr
= screen_buffer
->attr
;
1033 set_error( STATUS_INVALID_PARAMETER
);
1037 if (i
&& screen_buffer
== screen_buffer
->input
->active
)
1039 struct console_renderer_event evt
;
1040 evt
.event
= CONSOLE_RENDERER_UPDATE_EVENT
;
1041 evt
.u
.update
.top
= y
+ x
/ screen_buffer
->width
;
1042 evt
.u
.update
.bottom
= y
+ (x
+ i
- 1) / screen_buffer
->width
;
1043 console_input_events_append( screen_buffer
->input
->evt
, &evt
);
1048 /* fill a screen buffer with uniform data */
1049 static int fill_console_output( struct screen_buffer
*screen_buffer
, char_info_t data
,
1050 enum char_info_mode mode
, int x
, int y
, int count
, int wrap
)
1053 char_info_t
*end
, *dest
= screen_buffer
->data
+ y
* screen_buffer
->width
+ x
;
1055 if (y
>= screen_buffer
->height
) return 0;
1058 end
= screen_buffer
->data
+ screen_buffer
->height
* screen_buffer
->width
;
1060 end
= screen_buffer
->data
+ (y
+1) * screen_buffer
->width
;
1062 if (count
> end
- dest
) count
= end
- dest
;
1066 case CHAR_INFO_MODE_TEXT
:
1067 for (i
= 0; i
< count
; i
++) dest
[i
].ch
= data
.ch
;
1069 case CHAR_INFO_MODE_ATTR
:
1070 for (i
= 0; i
< count
; i
++) dest
[i
].attr
= data
.attr
;
1072 case CHAR_INFO_MODE_TEXTATTR
:
1073 for (i
= 0; i
< count
; i
++) dest
[i
] = data
;
1075 case CHAR_INFO_MODE_TEXTSTDATTR
:
1076 for (i
= 0; i
< count
; i
++)
1078 dest
[i
].ch
= data
.ch
;
1079 dest
[i
].attr
= screen_buffer
->attr
;
1083 set_error( STATUS_INVALID_PARAMETER
);
1087 if (count
&& screen_buffer
== screen_buffer
->input
->active
)
1089 struct console_renderer_event evt
;
1090 evt
.event
= CONSOLE_RENDERER_UPDATE_EVENT
;
1091 evt
.u
.update
.top
= y
;
1092 evt
.u
.update
.bottom
= (y
* screen_buffer
->width
+ x
+ count
- 1) / screen_buffer
->width
;
1093 console_input_events_append( screen_buffer
->input
->evt
, &evt
);
1098 /* read data from a screen buffer */
1099 static void read_console_output( struct screen_buffer
*screen_buffer
, int x
, int y
,
1100 enum char_info_mode mode
, int wrap
)
1103 char_info_t
*end
, *src
= screen_buffer
->data
+ y
* screen_buffer
->width
+ x
;
1105 if (y
>= screen_buffer
->height
) return;
1108 end
= screen_buffer
->data
+ screen_buffer
->height
* screen_buffer
->width
;
1110 end
= screen_buffer
->data
+ (y
+1) * screen_buffer
->width
;
1114 case CHAR_INFO_MODE_TEXT
:
1117 int count
= min( end
- src
, get_reply_max_size() / sizeof(*data
) );
1118 if ((data
= set_reply_data_size( count
* sizeof(*data
) )))
1120 for (i
= 0; i
< count
; i
++) data
[i
] = src
[i
].ch
;
1124 case CHAR_INFO_MODE_ATTR
:
1126 unsigned short *data
;
1127 int count
= min( end
- src
, get_reply_max_size() / sizeof(*data
) );
1128 if ((data
= set_reply_data_size( count
* sizeof(*data
) )))
1130 for (i
= 0; i
< count
; i
++) data
[i
] = src
[i
].attr
;
1134 case CHAR_INFO_MODE_TEXTATTR
:
1137 int count
= min( end
- src
, get_reply_max_size() / sizeof(*data
) );
1138 if ((data
= set_reply_data_size( count
* sizeof(*data
) )))
1140 for (i
= 0; i
< count
; i
++) data
[i
] = src
[i
];
1145 set_error( STATUS_INVALID_PARAMETER
);
1150 /* scroll parts of a screen buffer */
1151 static void scroll_console_output( obj_handle_t handle
, int xsrc
, int ysrc
, int xdst
, int ydst
,
1154 struct screen_buffer
*screen_buffer
;
1156 char_info_t
*psrc
, *pdst
;
1157 struct console_renderer_event evt
;
1159 if (!(screen_buffer
= (struct screen_buffer
*)get_handle_obj( current
->process
, handle
,
1160 GENERIC_READ
, &screen_buffer_ops
)))
1162 if (xsrc
< 0 || ysrc
< 0 || xdst
< 0 || ydst
< 0 ||
1163 xsrc
+ w
> screen_buffer
->width
||
1164 xdst
+ w
> screen_buffer
->width
||
1165 ysrc
+ h
> screen_buffer
->height
||
1166 ydst
+ h
> screen_buffer
->height
||
1169 set_error( STATUS_INVALID_PARAMETER
);
1170 release_object( screen_buffer
);
1176 psrc
= &screen_buffer
->data
[(ysrc
+ h
- 1) * screen_buffer
->width
+ xsrc
];
1177 pdst
= &screen_buffer
->data
[(ydst
+ h
- 1) * screen_buffer
->width
+ xdst
];
1179 for (j
= h
; j
> 0; j
--)
1181 memcpy(pdst
, psrc
, w
* sizeof(*pdst
) );
1182 pdst
-= screen_buffer
->width
;
1183 psrc
-= screen_buffer
->width
;
1188 psrc
= &screen_buffer
->data
[ysrc
* screen_buffer
->width
+ xsrc
];
1189 pdst
= &screen_buffer
->data
[ydst
* screen_buffer
->width
+ xdst
];
1191 for (j
= 0; j
< h
; j
++)
1193 /* we use memmove here because when psrc and pdst are the same,
1194 * copies are done on the same row, so the dst and src blocks
1196 memmove( pdst
, psrc
, w
* sizeof(*pdst
) );
1197 pdst
+= screen_buffer
->width
;
1198 psrc
+= screen_buffer
->width
;
1202 /* FIXME: this could be enhanced, by signalling scroll */
1203 evt
.event
= CONSOLE_RENDERER_UPDATE_EVENT
;
1204 evt
.u
.update
.top
= min(ysrc
, ydst
);
1205 evt
.u
.update
.bottom
= max(ysrc
, ydst
) + h
- 1;
1206 console_input_events_append( screen_buffer
->input
->evt
, &evt
);
1208 release_object( screen_buffer
);
1211 /* allocate a console for the renderer */
1212 DECL_HANDLER(alloc_console
)
1214 obj_handle_t in
= 0;
1215 obj_handle_t evt
= 0;
1216 struct process
*process
;
1217 struct process
*renderer
= current
->process
;
1218 struct console_input
*console
;
1220 process
= (req
->pid
) ? get_process_from_id( req
->pid
) :
1221 (struct process
*)grab_object( renderer
->parent
);
1223 reply
->handle_in
= 0;
1225 if (!process
) return;
1226 if (process
!= renderer
&& process
->console
)
1228 set_error( STATUS_ACCESS_DENIED
);
1231 if ((console
= (struct console_input
*)create_console_input( current
)))
1233 if ((in
= alloc_handle( renderer
, console
, req
->access
, req
->inherit
)))
1235 if ((evt
= alloc_handle( renderer
, console
->evt
,
1236 SYNCHRONIZE
|GENERIC_READ
|GENERIC_WRITE
, FALSE
)))
1238 if (process
!= renderer
)
1240 process
->console
= (struct console_input
*)grab_object( console
);
1241 console
->num_proc
++;
1243 reply
->handle_in
= in
;
1245 release_object( console
);
1248 close_handle( renderer
, in
, NULL
);
1250 free_console( process
);
1253 release_object( process
);
1256 /* free the console of the current process */
1257 DECL_HANDLER(free_console
)
1259 free_console( current
->process
);
1262 /* let the renderer peek the events it's waiting on */
1263 DECL_HANDLER(get_console_renderer_events
)
1265 struct console_input_events
*evt
;
1267 evt
= (struct console_input_events
*)get_handle_obj( current
->process
, req
->handle
,
1268 GENERIC_WRITE
, &console_input_events_ops
);
1270 console_input_events_get( evt
);
1271 release_object( evt
);
1274 /* open a handle to the process console */
1275 DECL_HANDLER(open_console
)
1277 struct object
*obj
= NULL
;
1283 if (current
->process
->console
&& current
->process
->console
->renderer
)
1284 obj
= grab_object( (struct object
*)current
->process
->console
);
1287 if (current
->process
->console
&& current
->process
->console
->renderer
&&
1288 current
->process
->console
->active
)
1289 obj
= grab_object( (struct object
*)current
->process
->console
->active
);
1292 if ((obj
= get_handle_obj( current
->process
, (obj_handle_t
)req
->from
,
1293 GENERIC_READ
|GENERIC_WRITE
, &console_input_ops
)))
1295 struct console_input
* console
= (struct console_input
*)obj
;
1296 obj
= (console
->active
) ? grab_object( console
->active
) : NULL
;
1297 release_object( console
);
1302 /* FIXME: req->share is not used (as in screen buffer creation) */
1305 reply
->handle
= alloc_handle( current
->process
, obj
, req
->access
, req
->inherit
);
1306 release_object( obj
);
1308 else if (!get_error()) set_error( STATUS_ACCESS_DENIED
);
1311 /* set info about a console input */
1312 DECL_HANDLER(set_console_input_info
)
1314 set_console_input_info( req
, get_req_data(), get_req_data_size() );
1317 /* get info about a console (output only) */
1318 DECL_HANDLER(get_console_input_info
)
1320 struct console_input
*console
;
1322 if (!(console
= console_input_get( req
->handle
, GENERIC_READ
))) return;
1325 size_t len
= strlenW( console
->title
) * sizeof(WCHAR
);
1326 if (len
> get_reply_max_size()) len
= get_reply_max_size();
1327 set_reply_data( console
->title
, len
);
1329 reply
->history_mode
= console
->history_mode
;
1330 reply
->history_size
= console
->history_size
;
1331 reply
->history_index
= console
->history_index
;
1332 reply
->edition_mode
= console
->edition_mode
;
1334 release_object( console
);
1337 /* get a console mode (input or output) */
1338 DECL_HANDLER(get_console_mode
)
1340 reply
->mode
= get_console_mode( req
->handle
);
1343 /* set a console mode (input or output) */
1344 DECL_HANDLER(set_console_mode
)
1346 set_console_mode( req
->handle
, req
->mode
);
1349 /* add input records to a console input queue */
1350 DECL_HANDLER(write_console_input
)
1352 struct console_input
*console
;
1355 if (!(console
= (struct console_input
*)get_handle_obj( current
->process
, req
->handle
,
1356 GENERIC_WRITE
, &console_input_ops
)))
1358 reply
->written
= write_console_input( console
, get_req_data_size() / sizeof(INPUT_RECORD
),
1360 release_object( console
);
1363 /* fetch input records from a console input queue */
1364 DECL_HANDLER(read_console_input
)
1366 int count
= get_reply_max_size() / sizeof(INPUT_RECORD
);
1367 reply
->read
= read_console_input( req
->handle
, count
, req
->flush
);
1370 /* appends a string to console's history */
1371 DECL_HANDLER(append_console_input_history
)
1373 struct console_input
*console
;
1375 if (!(console
= console_input_get( req
->handle
, GENERIC_WRITE
))) return;
1376 console_input_append_hist( console
, get_req_data(), get_req_data_size() / sizeof(WCHAR
) );
1377 release_object( console
);
1380 /* appends a string to console's history */
1381 DECL_HANDLER(get_console_input_history
)
1383 struct console_input
*console
;
1385 if (!(console
= console_input_get( req
->handle
, GENERIC_WRITE
))) return;
1386 reply
->total
= console_input_get_hist( console
, req
->index
);
1387 release_object( console
);
1390 /* creates a screen buffer */
1391 DECL_HANDLER(create_console_output
)
1393 struct console_input
* console
;
1394 struct screen_buffer
* screen_buffer
;
1396 if (!(console
= console_input_get( req
->handle_in
, GENERIC_WRITE
))) return;
1398 screen_buffer
= create_console_output( console
);
1401 /* FIXME: should store sharing and test it when opening the CONOUT$ device
1402 * see file.c on how this could be done */
1403 reply
->handle_out
= alloc_handle( current
->process
, screen_buffer
,
1404 req
->access
, req
->inherit
);
1405 release_object( screen_buffer
);
1407 release_object( console
);
1410 /* set info about a console screen buffer */
1411 DECL_HANDLER(set_console_output_info
)
1413 struct screen_buffer
*screen_buffer
;
1415 if ((screen_buffer
= (struct screen_buffer
*)get_handle_obj( current
->process
, req
->handle
,
1416 GENERIC_WRITE
, &screen_buffer_ops
)))
1418 set_console_output_info( screen_buffer
, req
);
1419 release_object( screen_buffer
);
1423 /* get info about a console screen buffer */
1424 DECL_HANDLER(get_console_output_info
)
1426 struct screen_buffer
*screen_buffer
;
1428 if ((screen_buffer
= (struct screen_buffer
*)get_handle_obj( current
->process
, req
->handle
,
1429 GENERIC_READ
, &screen_buffer_ops
)))
1431 reply
->cursor_size
= screen_buffer
->cursor_size
;
1432 reply
->cursor_visible
= screen_buffer
->cursor_visible
;
1433 reply
->cursor_x
= screen_buffer
->cursor_x
;
1434 reply
->cursor_y
= screen_buffer
->cursor_y
;
1435 reply
->width
= screen_buffer
->width
;
1436 reply
->height
= screen_buffer
->height
;
1437 reply
->attr
= screen_buffer
->attr
;
1438 reply
->win_left
= screen_buffer
->win
.left
;
1439 reply
->win_top
= screen_buffer
->win
.top
;
1440 reply
->win_right
= screen_buffer
->win
.right
;
1441 reply
->win_bottom
= screen_buffer
->win
.bottom
;
1442 reply
->max_width
= screen_buffer
->max_width
;
1443 reply
->max_height
= screen_buffer
->max_height
;
1444 release_object( screen_buffer
);
1448 /* read data (chars & attrs) from a screen buffer */
1449 DECL_HANDLER(read_console_output
)
1451 struct screen_buffer
*screen_buffer
;
1453 if ((screen_buffer
= (struct screen_buffer
*)get_handle_obj( current
->process
, req
->handle
,
1454 GENERIC_READ
, &screen_buffer_ops
)))
1456 read_console_output( screen_buffer
, req
->x
, req
->y
, req
->mode
, req
->wrap
);
1457 reply
->width
= screen_buffer
->width
;
1458 reply
->height
= screen_buffer
->height
;
1459 release_object( screen_buffer
);
1463 /* write data (char and/or attrs) to a screen buffer */
1464 DECL_HANDLER(write_console_output
)
1466 struct screen_buffer
*screen_buffer
;
1468 if ((screen_buffer
= (struct screen_buffer
*)get_handle_obj( current
->process
, req
->handle
,
1469 GENERIC_WRITE
, &screen_buffer_ops
)))
1471 reply
->written
= write_console_output( screen_buffer
, get_req_data_size(), get_req_data(),
1472 req
->mode
, req
->x
, req
->y
, req
->wrap
);
1473 reply
->width
= screen_buffer
->width
;
1474 reply
->height
= screen_buffer
->height
;
1475 release_object( screen_buffer
);
1479 /* fill a screen buffer with constant data (chars and/or attributes) */
1480 DECL_HANDLER(fill_console_output
)
1482 struct screen_buffer
*screen_buffer
;
1484 if ((screen_buffer
= (struct screen_buffer
*)get_handle_obj( current
->process
, req
->handle
,
1485 GENERIC_WRITE
, &screen_buffer_ops
)))
1487 reply
->written
= fill_console_output( screen_buffer
, req
->data
, req
->mode
,
1488 req
->x
, req
->y
, req
->count
, req
->wrap
);
1489 release_object( screen_buffer
);
1493 /* move a rect of data in a screen buffer */
1494 DECL_HANDLER(move_console_output
)
1496 scroll_console_output( req
->handle
, req
->x_src
, req
->y_src
, req
->x_dst
, req
->y_dst
,
1500 /* sends a signal to a console (process, group...) */
1501 DECL_HANDLER(send_console_signal
)
1505 group
= req
->group_id
? req
->group_id
: current
->process
->group_id
;
1508 set_error( STATUS_INVALID_PARAMETER
);
1510 propagate_console_signal( current
->process
->console
, req
->signal
, group
);
1513 /* get console which renderer is 'current' */
1514 static int cgwe_enum( struct process
* process
, void* user
)
1516 if (process
->console
&& process
->console
->renderer
== current
)
1518 *(struct console_input
**)user
= process
->console
;
1524 DECL_HANDLER(get_console_wait_event
)
1526 struct console_input
* console
= NULL
;
1528 if (current
->process
->console
&& current
->process
->console
->renderer
)
1529 console
= (struct console_input
*)grab_object( (struct object
*)current
->process
->console
);
1530 else enum_processes(cgwe_enum
, &console
);
1534 reply
->handle
= alloc_handle( current
->process
, console
->event
,
1535 EVENT_ALL_ACCESS
, FALSE
);
1536 release_object( console
);
1538 else set_error( STATUS_INVALID_PARAMETER
);