src/w32console.c, src/w32term.c: Remove unused variables.
[bpt/emacs.git] / src / w32console.c
1 /* Terminal hooks for GNU Emacs on the Microsoft Windows API.
2 Copyright (C) 1992, 1999, 2001-2013 Free Software Foundation, Inc.
3
4 This file is part of GNU Emacs.
5
6 GNU Emacs is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
18
19 /*
20 Tim Fleehart (apollo@online.com) 1-17-92
21 Geoff Voelker (voelker@cs.washington.edu) 9-12-93
22 */
23
24
25 #include <config.h>
26
27 #include <stdio.h>
28 #include <windows.h>
29
30 #include "lisp.h"
31 #include "character.h"
32 #include "coding.h"
33 #include "disptab.h"
34 #include "frame.h"
35 #include "window.h"
36 #include "termhooks.h"
37 #include "termchar.h"
38 #include "dispextern.h"
39 #include "w32term.h"
40 #include "w32common.h" /* for os_subtype */
41 #include "w32inevt.h"
42
43 /* from window.c */
44 extern Lisp_Object Frecenter (Lisp_Object);
45
46 static void w32con_move_cursor (struct frame *f, int row, int col);
47 static void w32con_clear_to_end (struct frame *f);
48 static void w32con_clear_frame (struct frame *f);
49 static void w32con_clear_end_of_line (struct frame *f, int);
50 static void w32con_ins_del_lines (struct frame *f, int vpos, int n);
51 static void w32con_insert_glyphs (struct frame *f, struct glyph *start, int len);
52 static void w32con_write_glyphs (struct frame *f, struct glyph *string, int len);
53 static void w32con_delete_glyphs (struct frame *f, int n);
54 static void w32con_reset_terminal_modes (struct terminal *t);
55 static void w32con_set_terminal_modes (struct terminal *t);
56 static void w32con_update_begin (struct frame * f);
57 static void w32con_update_end (struct frame * f);
58 static WORD w32_face_attributes (struct frame *f, int face_id);
59
60 static COORD cursor_coords;
61 static HANDLE prev_screen, cur_screen;
62 static WORD char_attr_normal;
63 static DWORD prev_console_mode;
64
65 #ifndef USE_SEPARATE_SCREEN
66 static CONSOLE_CURSOR_INFO prev_console_cursor;
67 #endif
68
69 HANDLE keyboard_handle;
70 int w32_console_unicode_input;
71
72
73 /* Setting this as the ctrl handler prevents emacs from being killed when
74 someone hits ^C in a 'suspended' session (child shell).
75 Also ignore Ctrl-Break signals. */
76
77 BOOL
78 ctrl_c_handler (unsigned long type)
79 {
80 /* Only ignore "interrupt" events when running interactively. */
81 return (!noninteractive
82 && (type == CTRL_C_EVENT || type == CTRL_BREAK_EVENT));
83 }
84
85
86 /* Move the cursor to (ROW, COL) on FRAME. */
87 static void
88 w32con_move_cursor (struct frame *f, int row, int col)
89 {
90 cursor_coords.X = col;
91 cursor_coords.Y = row;
92
93 /* TODO: for multi-tty support, cur_screen should be replaced with a
94 reference to the terminal for this frame. */
95 SetConsoleCursorPosition (cur_screen, cursor_coords);
96 }
97
98 /* Clear from cursor to end of screen. */
99 static void
100 w32con_clear_to_end (struct frame *f)
101 {
102 w32con_clear_end_of_line (f, FRAME_COLS (f) - 1);
103 w32con_ins_del_lines (f, cursor_coords.Y, FRAME_LINES (f) - cursor_coords.Y - 1);
104 }
105
106 /* Clear the frame. */
107 static void
108 w32con_clear_frame (struct frame *f)
109 {
110 COORD dest;
111 int n;
112 DWORD r;
113 CONSOLE_SCREEN_BUFFER_INFO info;
114
115 GetConsoleScreenBufferInfo (GetStdHandle (STD_OUTPUT_HANDLE), &info);
116
117 /* Remember that the screen buffer might be wider than the window. */
118 n = FRAME_LINES (f) * info.dwSize.X;
119 dest.X = dest.Y = 0;
120
121 FillConsoleOutputAttribute (cur_screen, char_attr_normal, n, dest, &r);
122 FillConsoleOutputCharacter (cur_screen, ' ', n, dest, &r);
123
124 w32con_move_cursor (f, 0, 0);
125 }
126
127
128 static struct glyph glyph_base[256];
129 static BOOL ceol_initialized = FALSE;
130
131 /* Clear from Cursor to end (what's "standout marker"?). */
132 static void
133 w32con_clear_end_of_line (struct frame *f, int end)
134 {
135 if (!ceol_initialized)
136 {
137 int i;
138 for (i = 0; i < 256; i++)
139 {
140 memcpy (&glyph_base[i], &space_glyph, sizeof (struct glyph));
141 }
142 ceol_initialized = TRUE;
143 }
144 w32con_write_glyphs (f, glyph_base, end - cursor_coords.X); /* fencepost ? */
145 }
146
147 /* Insert n lines at vpos. if n is negative delete -n lines. */
148 static void
149 w32con_ins_del_lines (struct frame *f, int vpos, int n)
150 {
151 int i, nb;
152 SMALL_RECT scroll;
153 SMALL_RECT clip;
154 COORD dest;
155 CHAR_INFO fill;
156
157 if (n < 0)
158 {
159 scroll.Top = vpos - n;
160 scroll.Bottom = FRAME_LINES (f);
161 dest.Y = vpos;
162 }
163 else
164 {
165 scroll.Top = vpos;
166 scroll.Bottom = FRAME_LINES (f) - n;
167 dest.Y = vpos + n;
168 }
169 clip.Top = clip.Left = scroll.Left = 0;
170 clip.Right = scroll.Right = FRAME_COLS (f);
171 clip.Bottom = FRAME_LINES (f);
172
173 dest.X = 0;
174
175 fill.Char.AsciiChar = 0x20;
176 fill.Attributes = char_attr_normal;
177
178 ScrollConsoleScreenBuffer (cur_screen, &scroll, &clip, dest, &fill);
179
180 /* Here we have to deal with a w32 console flake: If the scroll
181 region looks like abc and we scroll c to a and fill with d we get
182 cbd... if we scroll block c one line at a time to a, we get cdd...
183 Emacs expects cdd consistently... So we have to deal with that
184 here... (this also occurs scrolling the same way in the other
185 direction. */
186
187 if (n > 0)
188 {
189 if (scroll.Bottom < dest.Y)
190 {
191 for (i = scroll.Bottom; i < dest.Y; i++)
192 {
193 w32con_move_cursor (f, i, 0);
194 w32con_clear_end_of_line (f, FRAME_COLS (f));
195 }
196 }
197 }
198 else
199 {
200 nb = dest.Y + (scroll.Bottom - scroll.Top) + 1;
201
202 if (nb < scroll.Top)
203 {
204 for (i = nb; i < scroll.Top; i++)
205 {
206 w32con_move_cursor (f, i, 0);
207 w32con_clear_end_of_line (f, FRAME_COLS (f));
208 }
209 }
210 }
211
212 cursor_coords.X = 0;
213 cursor_coords.Y = vpos;
214 }
215
216 #undef LEFT
217 #undef RIGHT
218 #define LEFT 1
219 #define RIGHT 0
220
221 static void
222 scroll_line (struct frame *f, int dist, int direction)
223 {
224 /* The idea here is to implement a horizontal scroll in one line to
225 implement delete and half of insert. */
226 SMALL_RECT scroll, clip;
227 COORD dest;
228 CHAR_INFO fill;
229
230 clip.Top = scroll.Top = clip.Bottom = scroll.Bottom = cursor_coords.Y;
231 clip.Left = 0;
232 clip.Right = FRAME_COLS (f);
233
234 if (direction == LEFT)
235 {
236 scroll.Left = cursor_coords.X + dist;
237 scroll.Right = FRAME_COLS (f) - 1;
238 }
239 else
240 {
241 scroll.Left = cursor_coords.X;
242 scroll.Right = FRAME_COLS (f) - dist - 1;
243 }
244
245 dest.X = cursor_coords.X;
246 dest.Y = cursor_coords.Y;
247
248 fill.Char.AsciiChar = 0x20;
249 fill.Attributes = char_attr_normal;
250
251 ScrollConsoleScreenBuffer (cur_screen, &scroll, &clip, dest, &fill);
252 }
253
254
255 /* If start is zero insert blanks instead of a string at start ?. */
256 static void
257 w32con_insert_glyphs (struct frame *f, register struct glyph *start,
258 register int len)
259 {
260 scroll_line (f, len, RIGHT);
261
262 /* Move len chars to the right starting at cursor_coords, fill with blanks */
263 if (start)
264 {
265 /* Print the first len characters of start, cursor_coords.X adjusted
266 by write_glyphs. */
267
268 w32con_write_glyphs (f, start, len);
269 }
270 else
271 {
272 w32con_clear_end_of_line (f, cursor_coords.X + len);
273 }
274 }
275
276 static void
277 w32con_write_glyphs (struct frame *f, register struct glyph *string,
278 register int len)
279 {
280 DWORD r;
281 WORD char_attr;
282 unsigned char *conversion_buffer;
283 struct coding_system *coding;
284
285 if (len <= 0)
286 return;
287
288 /* If terminal_coding does any conversion, use it, otherwise use
289 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here
290 because it always return 1 if the member src_multibyte is 1. */
291 coding = (FRAME_TERMINAL_CODING (f)->common_flags & CODING_REQUIRE_ENCODING_MASK
292 ? FRAME_TERMINAL_CODING (f) : &safe_terminal_coding);
293 /* The mode bit CODING_MODE_LAST_BLOCK should be set to 1 only at
294 the tail. */
295 coding->mode &= ~CODING_MODE_LAST_BLOCK;
296
297 while (len > 0)
298 {
299 /* Identify a run of glyphs with the same face. */
300 int face_id = string->face_id;
301 int n;
302
303 for (n = 1; n < len; ++n)
304 if (string[n].face_id != face_id)
305 break;
306
307 /* Turn appearance modes of the face of the run on. */
308 char_attr = w32_face_attributes (f, face_id);
309
310 if (n == len)
311 /* This is the last run. */
312 coding->mode |= CODING_MODE_LAST_BLOCK;
313 conversion_buffer = encode_terminal_code (string, n, coding);
314 if (coding->produced > 0)
315 {
316 /* Set the attribute for these characters. */
317 if (!FillConsoleOutputAttribute (cur_screen, char_attr,
318 coding->produced, cursor_coords,
319 &r))
320 {
321 printf ("Failed writing console attributes: %d\n",
322 GetLastError ());
323 fflush (stdout);
324 }
325
326 /* Write the characters. */
327 if (!WriteConsoleOutputCharacter (cur_screen, conversion_buffer,
328 coding->produced, cursor_coords,
329 &r))
330 {
331 printf ("Failed writing console characters: %d\n",
332 GetLastError ());
333 fflush (stdout);
334 }
335
336 cursor_coords.X += coding->produced;
337 w32con_move_cursor (f, cursor_coords.Y, cursor_coords.X);
338 }
339 len -= n;
340 string += n;
341 }
342 }
343
344 /* Used for mouse highlight. */
345 static void
346 w32con_write_glyphs_with_face (struct frame *f, register int x, register int y,
347 register struct glyph *string, register int len,
348 register int face_id)
349 {
350 unsigned char *conversion_buffer;
351 struct coding_system *coding;
352
353 if (len <= 0)
354 return;
355
356 /* If terminal_coding does any conversion, use it, otherwise use
357 safe_terminal_coding. We can't use CODING_REQUIRE_ENCODING here
358 because it always return 1 if the member src_multibyte is 1. */
359 coding = (FRAME_TERMINAL_CODING (f)->common_flags & CODING_REQUIRE_ENCODING_MASK
360 ? FRAME_TERMINAL_CODING (f) : &safe_terminal_coding);
361 /* We are going to write the entire block of glyphs in one go, as
362 they all have the same face. So this _is_ the last block. */
363 coding->mode |= CODING_MODE_LAST_BLOCK;
364
365 conversion_buffer = encode_terminal_code (string, len, coding);
366 if (coding->produced > 0)
367 {
368 DWORD filled, written;
369 /* Compute the character attributes corresponding to the face. */
370 DWORD char_attr = w32_face_attributes (f, face_id);
371 COORD start_coords;
372
373 start_coords.X = x;
374 start_coords.Y = y;
375 /* Set the attribute for these characters. */
376 if (!FillConsoleOutputAttribute (cur_screen, char_attr,
377 coding->produced, start_coords,
378 &filled))
379 DebPrint (("Failed writing console attributes: %d\n", GetLastError ()));
380 else
381 {
382 /* Write the characters. */
383 if (!WriteConsoleOutputCharacter (cur_screen, conversion_buffer,
384 filled, start_coords, &written))
385 DebPrint (("Failed writing console characters: %d\n",
386 GetLastError ()));
387 }
388 }
389 }
390
391 /* Implementation of draw_row_with_mouse_face for W32 console. */
392 void
393 tty_draw_row_with_mouse_face (struct window *w, struct glyph_row *row,
394 int start_hpos, int end_hpos,
395 enum draw_glyphs_face draw)
396 {
397 int nglyphs = end_hpos - start_hpos;
398 struct frame *f = XFRAME (WINDOW_FRAME (w));
399 struct tty_display_info *tty = FRAME_TTY (f);
400 int face_id = tty->mouse_highlight.mouse_face_face_id;
401 int pos_x, pos_y;
402
403 if (end_hpos >= row->used[TEXT_AREA])
404 nglyphs = row->used[TEXT_AREA] - start_hpos;
405
406 pos_y = row->y + WINDOW_TOP_EDGE_Y (w);
407 pos_x = row->used[LEFT_MARGIN_AREA] + start_hpos + WINDOW_LEFT_EDGE_X (w);
408
409 if (draw == DRAW_MOUSE_FACE)
410 w32con_write_glyphs_with_face (f, pos_x, pos_y,
411 row->glyphs[TEXT_AREA] + start_hpos,
412 nglyphs, face_id);
413 else if (draw == DRAW_NORMAL_TEXT)
414 {
415 COORD save_coords = cursor_coords;
416
417 w32con_move_cursor (f, pos_y, pos_x);
418 write_glyphs (f, row->glyphs[TEXT_AREA] + start_hpos, nglyphs);
419 w32con_move_cursor (f, save_coords.Y, save_coords.X);
420 }
421 }
422
423 static void
424 w32con_delete_glyphs (struct frame *f, int n)
425 {
426 /* delete chars means scroll chars from cursor_coords.X + n to
427 cursor_coords.X, anything beyond the edge of the screen should
428 come out empty... */
429
430 scroll_line (f, n, LEFT);
431 }
432
433
434 static void
435 w32con_reset_terminal_modes (struct terminal *t)
436 {
437 COORD dest;
438 CONSOLE_SCREEN_BUFFER_INFO info;
439 int n;
440 DWORD r;
441
442 /* Clear the complete screen buffer. This is required because Emacs
443 sets the cursor position to the top of the buffer, but there might
444 be other output below the bottom of the Emacs frame if the screen buffer
445 is larger than the window size. */
446 GetConsoleScreenBufferInfo (cur_screen, &info);
447 dest.X = 0;
448 dest.Y = 0;
449 n = info.dwSize.X * info.dwSize.Y;
450
451 FillConsoleOutputAttribute (cur_screen, char_attr_normal, n, dest, &r);
452 FillConsoleOutputCharacter (cur_screen, ' ', n, dest, &r);
453 /* Now that the screen is clear, put the cursor at the top. */
454 SetConsoleCursorPosition (cur_screen, dest);
455
456 #ifdef USE_SEPARATE_SCREEN
457 SetConsoleActiveScreenBuffer (prev_screen);
458 #else
459 SetConsoleCursorInfo (prev_screen, &prev_console_cursor);
460 #endif
461
462 SetConsoleMode (keyboard_handle, prev_console_mode);
463 }
464
465 static void
466 w32con_set_terminal_modes (struct terminal *t)
467 {
468 CONSOLE_CURSOR_INFO cci;
469
470 /* make cursor big and visible (100 on Windows 95 makes it disappear) */
471 cci.dwSize = 99;
472 cci.bVisible = TRUE;
473 (void) SetConsoleCursorInfo (cur_screen, &cci);
474
475 SetConsoleActiveScreenBuffer (cur_screen);
476
477 SetConsoleMode (keyboard_handle, ENABLE_MOUSE_INPUT | ENABLE_WINDOW_INPUT);
478
479 /* Initialize input mode: interrupt_input off, no flow control, allow
480 8 bit character input, standard quit char. */
481 Fset_input_mode (Qnil, Qnil, make_number (2), Qnil);
482 }
483
484 /* hmmm... perhaps these let us bracket screen changes so that we can flush
485 clumps rather than one-character-at-a-time...
486
487 we'll start with not moving the cursor while an update is in progress. */
488 static void
489 w32con_update_begin (struct frame * f)
490 {
491 }
492
493 static void
494 w32con_update_end (struct frame * f)
495 {
496 SetConsoleCursorPosition (cur_screen, cursor_coords);
497 }
498
499 /***********************************************************************
500 stubs from termcap.c
501 ***********************************************************************/
502
503 void
504 sys_tputs (char *str, int nlines, int (*outfun) (int))
505 {
506 }
507
508 char *
509 sys_tgetstr (char *cap, char **area)
510 {
511 return NULL;
512 }
513
514
515 /***********************************************************************
516 stubs from cm.c
517 ***********************************************************************/
518
519 struct tty_display_info *current_tty = NULL;
520 int cost = 0;
521
522 int
523 evalcost (int c)
524 {
525 return c;
526 }
527
528 int
529 cmputc (int c)
530 {
531 return c;
532 }
533
534 void
535 cmcheckmagic (struct tty_display_info *tty)
536 {
537 }
538
539 void
540 cmcostinit (struct tty_display_info *tty)
541 {
542 }
543
544 void
545 cmgoto (struct tty_display_info *tty, int row, int col)
546 {
547 }
548
549 void
550 Wcm_clear (struct tty_display_info *tty)
551 {
552 }
553
554
555 /***********************************************************************
556 Faces
557 ***********************************************************************/
558
559
560 /* Turn appearances of face FACE_ID on tty frame F on. */
561
562 static WORD
563 w32_face_attributes (struct frame *f, int face_id)
564 {
565 WORD char_attr;
566 struct face *face = FACE_FROM_ID (f, face_id);
567
568 eassert (face != NULL);
569
570 char_attr = char_attr_normal;
571
572 /* Reverse the default color if requested. If background and
573 foreground are specified, then they have been reversed already. */
574 if (face->tty_reverse_p)
575 char_attr = (char_attr & 0xff00) + ((char_attr & 0x000f) << 4)
576 + ((char_attr & 0x00f0) >> 4);
577
578 /* Before the terminal is properly initialized, all colors map to 0.
579 Don't try to resolve them. */
580 if (NILP (Vtty_defined_color_alist))
581 return char_attr;
582
583 /* Colors should be in the range 0...15 unless they are one of
584 FACE_TTY_DEFAULT_COLOR, FACE_TTY_DEFAULT_FG_COLOR or
585 FACE_TTY_DEFAULT_BG_COLOR. Other out of range colors are
586 invalid, so it is better to use the default color if they ever
587 get through to here. */
588 if (face->foreground >= 0 && face->foreground < 16)
589 char_attr = (char_attr & 0xfff0) + face->foreground;
590
591 if (face->background >= 0 && face->background < 16)
592 char_attr = (char_attr & 0xff0f) + (face->background << 4);
593
594 return char_attr;
595 }
596
597 void
598 initialize_w32_display (struct terminal *term, int *width, int *height)
599 {
600 CONSOLE_SCREEN_BUFFER_INFO info;
601
602 term->rif = 0; /* No window based redisplay on the console. */
603 term->cursor_to_hook = w32con_move_cursor;
604 term->raw_cursor_to_hook = w32con_move_cursor;
605 term->clear_to_end_hook = w32con_clear_to_end;
606 term->clear_frame_hook = w32con_clear_frame;
607 term->clear_end_of_line_hook = w32con_clear_end_of_line;
608 term->ins_del_lines_hook = w32con_ins_del_lines;
609 term->insert_glyphs_hook = w32con_insert_glyphs;
610 term->write_glyphs_hook = w32con_write_glyphs;
611 term->delete_glyphs_hook = w32con_delete_glyphs;
612 term->ring_bell_hook = w32_sys_ring_bell;
613 term->reset_terminal_modes_hook = w32con_reset_terminal_modes;
614 term->set_terminal_modes_hook = w32con_set_terminal_modes;
615 term->set_terminal_window_hook = NULL;
616 term->update_begin_hook = w32con_update_begin;
617 term->update_end_hook = w32con_update_end;
618
619 term->read_socket_hook = w32_console_read_socket;
620 term->mouse_position_hook = w32_console_mouse_position;
621
622 /* The following are not used on the console. */
623 term->frame_rehighlight_hook = 0;
624 term->frame_raise_lower_hook = 0;
625 term->set_vertical_scroll_bar_hook = 0;
626 term->condemn_scroll_bars_hook = 0;
627 term->redeem_scroll_bar_hook = 0;
628 term->judge_scroll_bars_hook = 0;
629 term->frame_up_to_date_hook = 0;
630
631 /* Initialize the mouse-highlight data. */
632 reset_mouse_highlight (&term->display_info.tty->mouse_highlight);
633
634 /* Initialize interrupt_handle. */
635 init_crit ();
636
637 /* Remember original console settings. */
638 keyboard_handle = GetStdHandle (STD_INPUT_HANDLE);
639 GetConsoleMode (keyboard_handle, &prev_console_mode);
640
641 prev_screen = GetStdHandle (STD_OUTPUT_HANDLE);
642
643 #ifdef USE_SEPARATE_SCREEN
644 cur_screen = CreateConsoleScreenBuffer (GENERIC_READ | GENERIC_WRITE,
645 0, NULL,
646 CONSOLE_TEXTMODE_BUFFER,
647 NULL);
648
649 if (cur_screen == INVALID_HANDLE_VALUE)
650 {
651 printf ("CreateConsoleScreenBuffer failed in ResetTerm\n");
652 printf ("LastError = 0x%lx\n", GetLastError ());
653 fflush (stdout);
654 exit (0);
655 }
656 #else
657 cur_screen = prev_screen;
658 GetConsoleCursorInfo (prev_screen, &prev_console_cursor);
659 #endif
660
661 /* Respect setting of LINES and COLUMNS environment variables. */
662 {
663 char * lines = getenv ("LINES");
664 char * columns = getenv ("COLUMNS");
665
666 if (lines != NULL && columns != NULL)
667 {
668 SMALL_RECT new_win_dims;
669 COORD new_size;
670
671 new_size.X = atoi (columns);
672 new_size.Y = atoi (lines);
673
674 GetConsoleScreenBufferInfo (cur_screen, &info);
675
676 /* Shrink the window first, so the buffer dimensions can be
677 reduced if necessary. */
678 new_win_dims.Top = 0;
679 new_win_dims.Left = 0;
680 new_win_dims.Bottom = min (new_size.Y, info.dwSize.Y) - 1;
681 new_win_dims.Right = min (new_size.X, info.dwSize.X) - 1;
682 SetConsoleWindowInfo (cur_screen, TRUE, &new_win_dims);
683
684 SetConsoleScreenBufferSize (cur_screen, new_size);
685
686 /* Set the window size to match the buffer dimension. */
687 new_win_dims.Top = 0;
688 new_win_dims.Left = 0;
689 new_win_dims.Bottom = new_size.Y - 1;
690 new_win_dims.Right = new_size.X - 1;
691 SetConsoleWindowInfo (cur_screen, TRUE, &new_win_dims);
692 }
693 }
694
695 GetConsoleScreenBufferInfo (cur_screen, &info);
696
697 char_attr_normal = info.wAttributes;
698
699 /* Determine if the info returned by GetConsoleScreenBufferInfo
700 is realistic. Old MS Telnet servers used to only fill out
701 the dwSize portion, even modern one fill the whole struct with
702 garbage when using non-MS telnet clients. */
703 if ((w32_use_full_screen_buffer
704 && (info.dwSize.Y < 20 || info.dwSize.Y > 100
705 || info.dwSize.X < 40 || info.dwSize.X > 200))
706 || (!w32_use_full_screen_buffer
707 && (info.srWindow.Bottom - info.srWindow.Top < 20
708 || info.srWindow.Bottom - info.srWindow.Top > 100
709 || info.srWindow.Right - info.srWindow.Left < 40
710 || info.srWindow.Right - info.srWindow.Left > 100)))
711 {
712 *height = 25;
713 *width = 80;
714 }
715
716 else if (w32_use_full_screen_buffer)
717 {
718 *height = info.dwSize.Y; /* lines per page */
719 *width = info.dwSize.X; /* characters per line */
720 }
721 else
722 {
723 /* Lines per page. Use buffer coords instead of buffer size. */
724 *height = 1 + info.srWindow.Bottom - info.srWindow.Top;
725 /* Characters per line. Use buffer coords instead of buffer size. */
726 *width = 1 + info.srWindow.Right - info.srWindow.Left;
727 }
728
729 if (os_subtype == OS_NT)
730 w32_console_unicode_input = 1;
731 else
732 w32_console_unicode_input = 0;
733
734 /* This is needed by w32notify.c:send_notifications. */
735 dwMainThreadId = GetCurrentThreadId ();
736
737 /* Setup w32_display_info structure for this frame. */
738
739 w32_initialize_display_info (build_string ("Console"));
740
741 }
742
743
744 DEFUN ("set-screen-color", Fset_screen_color, Sset_screen_color, 2, 2, 0,
745 doc: /* Set screen foreground and background colors.
746
747 Arguments should be indices between 0 and 15, see w32console.el. */)
748 (Lisp_Object foreground, Lisp_Object background)
749 {
750 char_attr_normal = XFASTINT (foreground) + (XFASTINT (background) << 4);
751
752 Frecenter (Qnil);
753 return Qt;
754 }
755
756 DEFUN ("get-screen-color", Fget_screen_color, Sget_screen_color, 0, 0, 0,
757 doc: /* Get color indices of the current screen foreground and background.
758
759 The colors are returned as a list of 2 indices (FOREGROUND BACKGROUND).
760 See w32console.el and `tty-defined-color-alist' for mapping of indices
761 to colors. */)
762 (void)
763 {
764 return Fcons (make_number (char_attr_normal & 0x000f),
765 Fcons (make_number ((char_attr_normal >> 4) & 0x000f), Qnil));
766 }
767
768 DEFUN ("set-cursor-size", Fset_cursor_size, Sset_cursor_size, 1, 1, 0,
769 doc: /* Set cursor size. */)
770 (Lisp_Object size)
771 {
772 CONSOLE_CURSOR_INFO cci;
773 cci.dwSize = XFASTINT (size);
774 cci.bVisible = TRUE;
775 (void) SetConsoleCursorInfo (cur_screen, &cci);
776
777 return Qt;
778 }
779
780 void
781 syms_of_ntterm (void)
782 {
783 DEFVAR_BOOL ("w32-use-full-screen-buffer",
784 w32_use_full_screen_buffer,
785 doc: /* Non-nil means make terminal frames use the full screen buffer dimensions.
786 This is desirable when running Emacs over telnet.
787 A value of nil means use the current console window dimensions; this
788 may be preferable when working directly at the console with a large
789 scroll-back buffer. */);
790 w32_use_full_screen_buffer = 0;
791
792 defsubr (&Sset_screen_color);
793 defsubr (&Sget_screen_color);
794 defsubr (&Sset_cursor_size);
795 }