2 * osxwin.m: code to manage a session window in Mac OS X PuTTY.
5 #import <Cocoa/Cocoa.h>
10 /* Colours come in two flavours: configurable, and xterm-extended. */
11 #define NCFGCOLOURS (lenof(((Config *)0)->colours))
12 #define NEXTCOLOURS 240 /* 216 colour-cube plus 24 shades of grey */
13 #define NALLCOLOURS (NCFGCOLOURS + NEXTCOLOURS)
16 * The key component of the per-session data is the SessionWindow
17 * class. A pointer to this is used as the frontend handle, to be
18 * passed to all the platform-independent subsystems that require
22 @interface TerminalView : NSImageView
28 NSColor *colours[NALLCOLOURS];
29 float fw, fasc, fdesc, fh;
31 - (void)drawStartFinish:(BOOL)start;
32 - (void)setColour:(int)n r:(float)r g:(float)g b:(float)b;
33 - (void)doText:(wchar_t *)text len:(int)len x:(int)x y:(int)y
34 attr:(unsigned long)attr lattr:(int)lattr;
37 @implementation TerminalView
42 - (id)initWithTerminal:(Terminal *)aTerm config:(Config)aCfg
46 self = [self initWithFrame:NSMakeRect(0,0,100,100)];
52 * Initialise the fonts we're going to use.
54 * FIXME: for the moment I'm sticking with exactly one default font.
56 font = [NSFont userFixedPitchFontOfSize:0];
59 * Now determine the size of the primary font.
61 * FIXME: If we have multiple fonts, we may need to set fasc
62 * and fdesc to the _maximum_ asc and desc out of all the
63 * fonts, _before_ adding them together to get fh.
65 fw = [font widthOfString:@"A"];
66 fasc = [font ascender];
67 fdesc = -[font descender];
69 fh = (int)fh + (fh > (int)fh); /* round up, ickily */
72 * Use this to figure out the size of the terminal view.
78 * And set our size and subimage.
80 image = [[NSImage alloc] initWithSize:NSMakeSize(w,h)];
81 [image setFlipped:YES];
82 [self setImage:image];
83 [self setFrame:NSMakeRect(0,0,w,h)];
85 term_invalidate(term);
89 - (void)drawStartFinish:(BOOL)start
96 - (void)doText:(wchar_t *)text len:(int)len x:(int)x y:(int)y
97 attr:(unsigned long)attr lattr:(int)lattr
99 int nfg, nbg, rlen, widefactor;
100 float ox, oy, tw, th;
101 NSDictionary *attrdict;
103 /* FIXME: TATTR_COMBINING */
105 nfg = ((attr & ATTR_FGMASK) >> ATTR_FGSHIFT);
106 nbg = ((attr & ATTR_BGMASK) >> ATTR_BGSHIFT);
107 if (attr & ATTR_REVERSE) {
112 if (cfg.bold_colour && (attr & ATTR_BOLD)) {
113 if (nfg < 16) nfg |= 8;
114 else if (nfg >= 256) nfg |= 1;
116 if (cfg.bold_colour && (attr & ATTR_BLINK)) {
117 if (nbg < 16) nbg |= 8;
118 else if (nbg >= 256) nbg |= 1;
120 if (attr & TATTR_ACTCURS) {
125 if (attr & ATTR_WIDE) {
127 /* FIXME: what do we actually have to do about wide characters? */
132 /* FIXME: ATTR_BOLD without cfg.bold_colour */
134 if ((lattr & LATTR_MODE) != LATTR_NORM) {
138 if (x + len*2*widefactor > term->cols)
139 len = (term->cols-x)/2/widefactor;/* trim to LH half */
144 /* FIXME: how do we actually implement double-{width,height} lattrs? */
148 tw = rlen * widefactor * fw;
152 * Set the clipping rectangle.
154 [[NSGraphicsContext currentContext] saveGraphicsState];
155 [NSBezierPath clipRect:NSMakeRect(ox, oy, tw, th)];
157 attrdict = [NSDictionary dictionaryWithObjectsAndKeys:
158 colours[nfg], NSForegroundColorAttributeName,
159 colours[nbg], NSBackgroundColorAttributeName,
160 font, NSFontAttributeName, nil];
163 * Create an NSString and draw it.
165 * Annoyingly, although our input is wchar_t which is four
166 * bytes wide on OS X and terminal.c supports 32-bit Unicode,
167 * we must convert into the two-byte type `unichar' to store in
168 * NSString, so we lose display capability for extra-BMP stuff
176 utext = snewn(len, unichar);
177 for (i = 0; i < len; i++)
178 utext[i] = (text[i] >= 0x10000 ? 0xFFFD : text[i]);
180 string = [NSString stringWithCharacters:utext length:len];
181 [string drawAtPoint:NSMakePoint(ox, oy) withAttributes:attrdict];
187 * Restore the graphics state from before the clipRect: call.
189 [[NSGraphicsContext currentContext] restoreGraphicsState];
192 * And flag this area as needing display.
194 [self setNeedsDisplayInRect:NSMakeRect(ox, oy, tw, th)];
197 - (void)setColour:(int)n r:(float)r g:(float)g b:(float)b
199 assert(n >= 0 && n < lenof(colours));
200 colours[n] = [[NSColor colorWithDeviceRed:r green:g blue:b alpha:1.0]
205 @implementation SessionWindow
206 - (id)initWithConfig:(Config)aCfg
208 NSRect rect = { {0,0}, {0,0} };
212 cfg = aCfg; /* structure copy */
214 init_ucs(&ucsdata, cfg.line_codepage, cfg.utf8_override,
215 CS_UTF8, cfg.vtmode);
216 term = term_init(&cfg, &ucsdata, self);
217 logctx = log_init(self, &cfg);
218 term_provide_logctx(term, logctx);
219 term_size(term, cfg.height, cfg.width, cfg.savelines);
221 termview = [[[TerminalView alloc] initWithTerminal:term config:cfg]
225 * Now work out the size of the window.
227 rect = [termview frame];
228 rect.origin = NSMakePoint(0,0);
229 rect.size.width += 2 * cfg.window_border;
230 rect.size.height += 2 * cfg.window_border;
238 for (i = 0; backends[i].backend != NULL; i++)
239 if (backends[i].protocol == cfg.protocol) {
240 back = backends[i].backend;
247 char *realhost = NULL;
248 error = back->init(self, &backhandle, &cfg, cfg.host, cfg.port,
249 &realhost, cfg.tcp_nodelay, cfg.tcp_keepalives);
251 fatalbox("%s\n", error); /* FIXME: connection_fatal at worst */
255 sfree(realhost); /* FIXME: do something with this */
257 back->provide_logctx(backhandle, logctx);
260 * Create a line discipline. (This must be done after creating
261 * the terminal _and_ the backend, since it needs to be passed
264 ldisc = ldisc_create(&cfg, term, back, backhandle, self);
267 * FIXME: Set up a scrollbar.
270 self = [super initWithContentRect:rect
271 styleMask:(NSTitledWindowMask | NSMiniaturizableWindowMask |
272 NSClosableWindowMask)
273 backing:NSBackingStoreBuffered
275 [self setTitle:@"PuTTY"];
277 [self setIgnoresMouseEvents:NO];
280 * Put the terminal view in the window.
282 rect = [termview frame];
283 rect.origin = NSMakePoint(cfg.window_border, cfg.window_border);
284 [termview setFrame:rect];
285 [[self contentView] addSubview:termview];
288 * Set up the colour palette.
293 * FIXME: Only the _first_ document window should be centred.
294 * The subsequent ones should appear down and to the right of
295 * it, probably using the cascade function provided by Cocoa.
296 * Also we're apparently required by the HIG to remember and
297 * reuse previous positions of windows, although I'm not sure
298 * how that works if the user opens more than one of the same
301 [self center]; /* :-) */
311 * FIXME: Here we must deallocate all sorts of stuff: the
312 * terminal, the backend, the ldisc, the logctx, you name it.
317 back->free(backhandle);
320 /* ldisc must be freed before term, since ldisc_free expects term
321 * still to be around. */
329 - (void)drawStartFinish:(BOOL)start
331 [termview drawStartFinish:start];
334 - (void)setColour:(int)n r:(float)r g:(float)g b:(float)b
336 [termview setColour:n r:r g:g b:b];
339 - (void)doText:(wchar_t *)text len:(int)len x:(int)x y:(int)y
340 attr:(unsigned long)attr lattr:(int)lattr
342 /* Pass this straight on to the TerminalView. */
343 [termview doText:text len:len x:x y:y attr:attr lattr:lattr];
351 - (void)keyDown:(NSEvent *)ev
353 NSString *s = [ev characters];
355 int n = [s length], c = [s characterAtIndex:0], m = [ev modifierFlags];
356 int cm = [[ev charactersIgnoringModifiers] characterAtIndex:0];
359 int use_coutput = FALSE, special = FALSE, start, end;
361 //printf("n=%d c=U+%04x cm=U+%04x m=%08x\n", n, c, cm, m);
364 * FIXME: Alt+numberpad codes.
368 * Shift and Ctrl with PageUp/PageDown for scrollback.
370 if (n == 1 && c == NSPageUpFunctionKey && (m & NSShiftKeyMask)) {
371 term_scroll(term, 0, -term->rows/2);
374 if (n == 1 && c == NSPageUpFunctionKey && (m & NSControlKeyMask)) {
375 term_scroll(term, 0, -1);
378 if (n == 1 && c == NSPageDownFunctionKey && (m & NSShiftKeyMask)) {
379 term_scroll(term, 0, +term->rows/2);
382 if (n == 1 && c == NSPageDownFunctionKey && (m & NSControlKeyMask)) {
383 term_scroll(term, 0, +1);
388 * FIXME: Shift-Ins for paste? Or is that not Maccy enough?
392 * FIXME: Alt (Option? Command?) prefix in general.
394 * (Note that Alt-Shift-thing will work just by looking at
395 * charactersIgnoringModifiers; but Alt-Ctrl-thing will need
396 * processing properly, and Alt-as-in-Option won't happen at
399 * (Note also that we need to be able to override menu key
400 * equivalents before this is particularly useful.)
406 * Ctrl-` is the same as Ctrl-\, unless we already have a
409 if ((m & NSControlKeyMask) && n == 1 && cm == '`' && c == '`') {
414 /* We handle Return ourselves, because it needs to be flagged as
415 * special to ldisc. */
416 if (n == 1 && c == '\015') {
423 /* Control-Shift-Space is 160 (ISO8859 nonbreaking space) */
424 if (n == 1 && (m & NSControlKeyMask) && (m & NSShiftKeyMask) &&
430 /* Control-2, Control-Space and Control-@ are all NUL. */
431 if ((m & NSControlKeyMask) && n == 1 &&
432 (cm == '2' || cm == '@' || cm == ' ') && c == cm) {
437 /* We don't let MacOS tell us what Backspace is! We know better. */
438 if (cm == 0x7F && !(m & NSShiftKeyMask)) {
439 coutput[1] = cfg.bksp_is_delete ? '\x7F' : '\x08';
441 use_coutput = special = TRUE;
443 /* For Shift Backspace, do opposite of what is configured. */
444 if (cm == 0x7F && (m & NSShiftKeyMask)) {
445 coutput[1] = cfg.bksp_is_delete ? '\x08' : '\x7F';
447 use_coutput = special = TRUE;
450 /* Shift-Tab is ESC [ Z. Oddly, this combination generates ^Y by
451 * default on MacOS! */
452 if (cm == 0x19 && (m & NSShiftKeyMask) && !(m & NSControlKeyMask)) {
454 output[end++] = '\033';
460 * NetHack keypad mode.
462 if (cfg.nethack_keypad && (m & NSNumericPadKeyMask)) {
463 wchar_t *keys = NULL;
465 case '1': keys = L"bB"; break;
466 case '2': keys = L"jJ"; break;
467 case '3': keys = L"nN"; break;
468 case '4': keys = L"hH"; break;
469 case '5': keys = L".."; break;
470 case '6': keys = L"lL"; break;
471 case '7': keys = L"yY"; break;
472 case '8': keys = L"kK"; break;
473 case '9': keys = L"uU"; break;
477 if (m & NSShiftKeyMask)
486 * Application keypad mode.
488 if (term->app_keypad_keys && !cfg.no_applic_k &&
489 (m & NSNumericPadKeyMask)) {
492 case NSClearLineFunctionKey: xkey = 'P'; break;
493 case '=': xkey = 'Q'; break;
494 case '/': xkey = 'R'; break;
495 case '*': xkey = 'S'; break;
497 * FIXME: keypad - and + need to be mapped to ESC O l
498 * and ESC O k, or ESC O l and ESC O m, depending on
499 * xterm function key mode, and I can't remember which
502 case '\003': xkey = 'M'; break;
503 case '0': xkey = 'p'; break;
504 case '1': xkey = 'q'; break;
505 case '2': xkey = 'r'; break;
506 case '3': xkey = 's'; break;
507 case '4': xkey = 't'; break;
508 case '5': xkey = 'u'; break;
509 case '6': xkey = 'v'; break;
510 case '7': xkey = 'w'; break;
511 case '8': xkey = 'x'; break;
512 case '9': xkey = 'y'; break;
513 case '.': xkey = 'n'; break;
516 if (term->vt52_mode) {
517 if (xkey >= 'P' && xkey <= 'S') {
518 output[end++] = '\033';
519 output[end++] = xkey;
521 output[end++] = '\033';
523 output[end++] = xkey;
526 output[end++] = '\033';
528 output[end++] = xkey;
535 * Next, all the keys that do tilde codes. (ESC '[' nn '~',
536 * for integer decimal nn.)
538 * We also deal with the weird ones here. Linux VCs replace F1
539 * to F5 by ESC [ [ A to ESC [ [ E. rxvt doesn't do _that_, but
540 * does replace Home and End (1~ and 4~) by ESC [ H and ESC O w
546 case NSF1FunctionKey:
547 code = (m & NSShiftKeyMask ? 23 : 11);
549 case NSF2FunctionKey:
550 code = (m & NSShiftKeyMask ? 24 : 12);
552 case NSF3FunctionKey:
553 code = (m & NSShiftKeyMask ? 25 : 13);
555 case NSF4FunctionKey:
556 code = (m & NSShiftKeyMask ? 26 : 14);
558 case NSF5FunctionKey:
559 code = (m & NSShiftKeyMask ? 28 : 15);
561 case NSF6FunctionKey:
562 code = (m & NSShiftKeyMask ? 29 : 17);
564 case NSF7FunctionKey:
565 code = (m & NSShiftKeyMask ? 31 : 18);
567 case NSF8FunctionKey:
568 code = (m & NSShiftKeyMask ? 32 : 19);
570 case NSF9FunctionKey:
571 code = (m & NSShiftKeyMask ? 33 : 20);
573 case NSF10FunctionKey:
574 code = (m & NSShiftKeyMask ? 34 : 21);
576 case NSF11FunctionKey:
579 case NSF12FunctionKey:
582 case NSF13FunctionKey:
585 case NSF14FunctionKey:
588 case NSF15FunctionKey:
591 case NSF16FunctionKey:
594 case NSF17FunctionKey:
597 case NSF18FunctionKey:
600 case NSF19FunctionKey:
603 case NSF20FunctionKey:
607 if (!(m & NSControlKeyMask)) switch (cm) {
608 case NSHomeFunctionKey:
612 case GDK_Insert: case GDK_KP_Insert:
616 case NSDeleteFunctionKey:
619 case NSEndFunctionKey:
622 case NSPageUpFunctionKey:
625 case NSPageDownFunctionKey:
629 /* Reorder edit keys to physical order */
630 if (cfg.funky_type == FUNKY_VT400 && code <= 6)
631 code = "\0\2\1\4\5\3\6"[code];
633 if (term->vt52_mode && code > 0 && code <= 6) {
634 output[end++] = '\033';
635 output[end++] = " HLMEIG"[code];
639 if (cfg.funky_type == FUNKY_SCO && /* SCO function keys */
640 code >= 11 && code <= 34) {
641 char codes[] = "MNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@[\\]^_`{";
644 case NSF1FunctionKey: index = 0; break;
645 case NSF2FunctionKey: index = 1; break;
646 case NSF3FunctionKey: index = 2; break;
647 case NSF4FunctionKey: index = 3; break;
648 case NSF5FunctionKey: index = 4; break;
649 case NSF6FunctionKey: index = 5; break;
650 case NSF7FunctionKey: index = 6; break;
651 case NSF8FunctionKey: index = 7; break;
652 case NSF9FunctionKey: index = 8; break;
653 case NSF10FunctionKey: index = 9; break;
654 case NSF11FunctionKey: index = 10; break;
655 case NSF12FunctionKey: index = 11; break;
657 if (m & NSShiftKeyMask) index += 12;
658 if (m & NSControlKeyMask) index += 24;
659 output[end++] = '\033';
661 output[end++] = codes[index];
664 if (cfg.funky_type == FUNKY_SCO && /* SCO small keypad */
665 code >= 1 && code <= 6) {
666 char codes[] = "HL.FIG";
671 output[end++] = '\033';
673 output[end++] = codes[code-1];
677 if ((term->vt52_mode || cfg.funky_type == FUNKY_VT100P) &&
678 code >= 11 && code <= 24) {
684 if (term->vt52_mode) {
685 output[end++] = '\033';
686 output[end++] = code + 'P' - 11 - offt;
688 output[end++] = '\033';
690 output[end++] = code + 'P' - 11 - offt;
694 if (cfg.funky_type == FUNKY_LINUX && code >= 11 && code <= 15) {
695 output[end++] = '\033';
698 output[end++] = code + 'A' - 11;
701 if (cfg.funky_type == FUNKY_XTERM && code >= 11 && code <= 14) {
702 if (term->vt52_mode) {
703 output[end++] = '\033';
704 output[end++] = code + 'P' - 11;
706 output[end++] = '\033';
708 output[end++] = code + 'P' - 11;
712 if (cfg.rxvt_homeend && (code == 1 || code == 4)) {
714 output[end++] = '\033';
718 output[end++] = '\033';
726 sprintf(buf, "\x1B[%d~", code);
727 for (i = 0; buf[i]; i++)
728 output[end++] = buf[i];
734 * Cursor keys. (This includes the numberpad cursor keys,
735 * if we haven't already done them due to app keypad mode.)
740 case NSUpArrowFunctionKey: xkey = 'A'; break;
741 case NSDownArrowFunctionKey: xkey = 'B'; break;
742 case NSRightArrowFunctionKey: xkey = 'C'; break;
743 case NSLeftArrowFunctionKey: xkey = 'D'; break;
747 * The arrow keys normally do ESC [ A and so on. In
748 * app cursor keys mode they do ESC O A instead.
749 * Ctrl toggles the two modes.
751 if (term->vt52_mode) {
752 output[end++] = '\033';
753 output[end++] = xkey;
754 } else if (!term->app_cursor_keys ^ !(m & NSControlKeyMask)) {
755 output[end++] = '\033';
757 output[end++] = xkey;
759 output[end++] = '\033';
761 output[end++] = xkey;
770 * Failing everything else, send the exact Unicode we got from
774 if (n > lenof(output)-start)
775 n = lenof(output)-start; /* _shouldn't_ happen! */
776 for (i = 0; i < n; i++) {
777 output[i+start] = [s characterAtIndex:i];
784 assert(end < lenof(coutput));
786 ldisc_send(ldisc, coutput+start, -2, TRUE);
788 luni_send(ldisc, output+start, end-start, TRUE);
792 - (int)fromBackend:(const char *)data len:(int)len isStderr:(int)is_stderr
794 return term_data(term, is_stderr, data, len);
797 - (void)startAlert:(NSAlert *)alert
798 withCallback:(void (*)(void *, int))callback andCtx:(void *)ctx
800 if (alert_ctx || alert_qhead) {
802 * Queue this alert to be shown later.
804 struct alert_queue *qitem = snew(struct alert_queue);
806 qitem->alert = alert;
807 qitem->callback = callback;
810 alert_qtail->next = qitem;
815 alert_callback = callback;
816 alert_ctx = ctx; /* NB this is assumed to need freeing! */
817 [alert beginSheetModalForWindow:self modalDelegate:self
818 didEndSelector:@selector(alertSheetDidEnd:returnCode:contextInfo:)
823 - (void)alertSheetDidEnd:(NSAlert *)alert returnCode:(int)returnCode
824 contextInfo:(void *)contextInfo
826 [self performSelectorOnMainThread:
827 @selector(alertSheetDidFinishEnding:)
828 withObject:[NSNumber numberWithInt:returnCode]
832 - (void)alertSheetDidFinishEnding:(id)object
834 int returnCode = [object intValue];
836 alert_callback(alert_ctx, returnCode); /* transfers ownership of ctx */
839 * If there's an alert in our queue (either already or because
840 * the callback just queued it), start it.
843 struct alert_queue *qnext;
845 alert_callback = alert_qhead->callback;
846 alert_ctx = alert_qhead->ctx;
847 [alert_qhead->alert beginSheetModalForWindow:self modalDelegate:self
848 didEndSelector:@selector(alertSheetDidEnd:returnCode:contextInfo:)
851 qnext = alert_qhead->next;
861 - (void)notifyRemoteExit
865 if (!exited && (exitcode = back->exitcode(backhandle)) >= 0)
866 [self endSession:(exitcode == 0)];
869 - (void)endSession:(int)clean
877 back->free(backhandle);
880 //FIXME: update specials menu;
882 if (cfg.close_on_exit == FORCE_ON ||
883 (cfg.close_on_exit == AUTO && clean))
885 // FIXME: else show restart menu item
890 int from_backend(void *frontend, int is_stderr, const char *data, int len)
892 SessionWindow *win = (SessionWindow *)frontend;
893 return [win fromBackend:data len:len isStderr:is_stderr];
896 void frontend_keypress(void *handle)
901 void notify_remote_exit(void *frontend)
903 SessionWindow *win = (SessionWindow *)frontend;
905 [win notifyRemoteExit];
908 void ldisc_update(void *frontend, int echo, int edit)
910 //SessionWindow *win = (SessionWindow *)frontend;
912 * In a GUI front end, this need do nothing.
916 char *get_ttymode(void *frontend, const char *mode)
918 SessionWindow *win = (SessionWindow *)ctx;
919 Terminal *term = [win term];
920 return term_get_ttymode(term, mode);
923 void update_specials_menu(void *frontend)
925 //SessionWindow *win = (SessionWindow *)frontend;
930 * This is still called when mode==BELL_VISUAL, even though the
931 * visual bell is handled entirely within terminal.c, because we
932 * may want to perform additional actions on any kind of bell (for
933 * example, taskbar flashing in Windows).
935 void beep(void *frontend, int mode)
937 //SessionWindow *win = (SessionWindow *)frontend;
938 if (mode != BELL_VISUAL)
942 int char_width(Context ctx, int uc)
945 * Under X, any fixed-width font really _is_ fixed-width.
946 * Double-width characters will be dealt with using a separate
947 * font. For the moment we can simply return 1.
952 void palette_set(void *frontend, int n, int r, int g, int b)
954 SessionWindow *win = (SessionWindow *)frontend;
960 [win setColour:n r:r/255.0 g:g/255.0 b:b/255.0];
963 * FIXME: do we need an OS X equivalent of set_window_background?
967 void palette_reset(void *frontend)
969 SessionWindow *win = (SessionWindow *)frontend;
970 Config *cfg = [win cfg];
972 /* This maps colour indices in cfg to those used in colours[]. */
973 static const int ww[] = {
974 256, 257, 258, 259, 260, 261,
975 0, 8, 1, 9, 2, 10, 3, 11,
976 4, 12, 5, 13, 6, 14, 7, 15
981 for (i = 0; i < NCFGCOLOURS; i++) {
982 [win setColour:ww[i] r:cfg->colours[i][0]/255.0
983 g:cfg->colours[i][1]/255.0 b:cfg->colours[i][2]/255.0];
986 for (i = 0; i < NEXTCOLOURS; i++) {
988 int r = i / 36, g = (i / 6) % 6, b = i % 6;
989 r = r ? r*40+55 : 0; g = g ? b*40+55 : 0; b = b ? b*40+55 : 0;
990 [win setColour:i+16 r:r/255.0 g:g/255.0 b:b/255.0];
993 float fshade = (shade * 10 + 8) / 255.0;
994 [win setColour:i+16 r:fshade g:fshade b:fshade];
999 * FIXME: do we need an OS X equivalent of set_window_background?
1003 Context get_ctx(void *frontend)
1005 SessionWindow *win = (SessionWindow *)frontend;
1008 * Lock the drawing focus on the image inside the TerminalView.
1010 [win drawStartFinish:YES];
1012 [[NSGraphicsContext currentContext] setShouldAntialias:YES];
1015 * Cocoa drawing functions don't take a graphics context: that
1016 * parameter is implicit. Therefore, we'll use the frontend
1017 * handle itself as the context, on the grounds that it's as
1018 * good a thing to use as any.
1023 void free_ctx(Context ctx)
1025 SessionWindow *win = (SessionWindow *)ctx;
1027 [win drawStartFinish:NO];
1030 void do_text(Context ctx, int x, int y, wchar_t *text, int len,
1031 unsigned long attr, int lattr)
1033 SessionWindow *win = (SessionWindow *)ctx;
1035 [win doText:text len:len x:x y:y attr:attr lattr:lattr];
1038 void do_cursor(Context ctx, int x, int y, wchar_t *text, int len,
1039 unsigned long attr, int lattr)
1041 SessionWindow *win = (SessionWindow *)ctx;
1042 Config *cfg = [win cfg];
1043 int active, passive;
1045 if (attr & TATTR_PASCURS) {
1046 attr &= ~TATTR_PASCURS;
1050 if ((attr & TATTR_ACTCURS) && cfg->cursor_type != 0) {
1051 attr &= ~TATTR_ACTCURS;
1056 [win doText:text len:len x:x y:y attr:attr lattr:lattr];
1059 * FIXME: now draw the various cursor types (both passive and
1060 * active underlines and vertical lines, plus passive blocks).
1065 * Minimise or restore the window in response to a server-side
1068 void set_iconic(void *frontend, int iconic)
1070 //SessionWindow *win = (SessionWindow *)frontend;
1075 * Move the window in response to a server-side request.
1077 void move_window(void *frontend, int x, int y)
1079 //SessionWindow *win = (SessionWindow *)frontend;
1084 * Move the window to the top or bottom of the z-order in response
1085 * to a server-side request.
1087 void set_zorder(void *frontend, int top)
1089 //SessionWindow *win = (SessionWindow *)frontend;
1094 * Refresh the window in response to a server-side request.
1096 void refresh_window(void *frontend)
1098 //SessionWindow *win = (SessionWindow *)frontend;
1103 * Maximise or restore the window in response to a server-side
1106 void set_zoomed(void *frontend, int zoomed)
1108 //SessionWindow *win = (SessionWindow *)frontend;
1113 * Report whether the window is iconic, for terminal reports.
1115 int is_iconic(void *frontend)
1117 //SessionWindow *win = (SessionWindow *)frontend;
1118 return NO; /* FIXME */
1122 * Report the window's position, for terminal reports.
1124 void get_window_pos(void *frontend, int *x, int *y)
1126 //SessionWindow *win = (SessionWindow *)frontend;
1131 * Report the window's pixel size, for terminal reports.
1133 void get_window_pixels(void *frontend, int *x, int *y)
1135 //SessionWindow *win = (SessionWindow *)frontend;
1140 * Return the window or icon title.
1142 char *get_window_title(void *frontend, int icon)
1144 //SessionWindow *win = (SessionWindow *)frontend;
1145 return NULL; /* FIXME */
1148 void set_title(void *frontend, char *title)
1150 //SessionWindow *win = (SessionWindow *)frontend;
1154 void set_icon(void *frontend, char *title)
1156 //SessionWindow *win = (SessionWindow *)frontend;
1160 void set_sbar(void *frontend, int total, int start, int page)
1162 //SessionWindow *win = (SessionWindow *)frontend;
1166 void get_clip(void *frontend, wchar_t ** p, int *len)
1168 //SessionWindow *win = (SessionWindow *)frontend;
1172 void write_clip(void *frontend, wchar_t * data, int len, int must_deselect)
1174 //SessionWindow *win = (SessionWindow *)frontend;
1178 void request_paste(void *frontend)
1180 //SessionWindow *win = (SessionWindow *)frontend;
1184 void set_raw_mouse_mode(void *frontend, int activate)
1186 //SessionWindow *win = (SessionWindow *)frontend;
1190 void request_resize(void *frontend, int w, int h)
1192 //SessionWindow *win = (SessionWindow *)frontend;
1196 void sys_cursor(void *frontend, int x, int y)
1198 //SessionWindow *win = (SessionWindow *)frontend;
1200 * This is probably meaningless under OS X. FIXME: find out for
1205 void logevent(void *frontend, const char *string)
1207 //SessionWindow *win = (SessionWindow *)frontend;
1209 printf("logevent: %s\n", string);
1212 int font_dimension(void *frontend, int which)/* 0 for width, 1 for height */
1214 //SessionWindow *win = (SessionWindow *)frontend;
1215 return 1; /* FIXME */
1218 void set_busy_status(void *frontend, int status)
1221 * We need do nothing here: the OS X `application is busy'
1222 * beachball pointer appears _automatically_ when the
1223 * application isn't responding to GUI messages.