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;
235 back = backend_from_proto(cfg.protocol);
241 char *realhost = NULL;
242 error = back->init(self, &backhandle, &cfg, cfg.host, cfg.port,
243 &realhost, cfg.tcp_nodelay, cfg.tcp_keepalives);
245 fatalbox("%s\n", error); /* FIXME: connection_fatal at worst */
249 sfree(realhost); /* FIXME: do something with this */
251 back->provide_logctx(backhandle, logctx);
254 * Create a line discipline. (This must be done after creating
255 * the terminal _and_ the backend, since it needs to be passed
258 ldisc = ldisc_create(&cfg, term, back, backhandle, self);
261 * FIXME: Set up a scrollbar.
264 self = [super initWithContentRect:rect
265 styleMask:(NSTitledWindowMask | NSMiniaturizableWindowMask |
266 NSClosableWindowMask)
267 backing:NSBackingStoreBuffered
269 [self setTitle:@"PuTTY"];
271 [self setIgnoresMouseEvents:NO];
274 * Put the terminal view in the window.
276 rect = [termview frame];
277 rect.origin = NSMakePoint(cfg.window_border, cfg.window_border);
278 [termview setFrame:rect];
279 [[self contentView] addSubview:termview];
282 * Set up the colour palette.
287 * FIXME: Only the _first_ document window should be centred.
288 * The subsequent ones should appear down and to the right of
289 * it, probably using the cascade function provided by Cocoa.
290 * Also we're apparently required by the HIG to remember and
291 * reuse previous positions of windows, although I'm not sure
292 * how that works if the user opens more than one of the same
295 [self center]; /* :-) */
305 * FIXME: Here we must deallocate all sorts of stuff: the
306 * terminal, the backend, the ldisc, the logctx, you name it.
311 back->free(backhandle);
314 /* ldisc must be freed before term, since ldisc_free expects term
315 * still to be around. */
323 - (void)drawStartFinish:(BOOL)start
325 [termview drawStartFinish:start];
328 - (void)setColour:(int)n r:(float)r g:(float)g b:(float)b
330 [termview setColour:n r:r g:g b:b];
333 - (void)doText:(wchar_t *)text len:(int)len x:(int)x y:(int)y
334 attr:(unsigned long)attr lattr:(int)lattr
336 /* Pass this straight on to the TerminalView. */
337 [termview doText:text len:len x:x y:y attr:attr lattr:lattr];
345 - (void)keyDown:(NSEvent *)ev
347 NSString *s = [ev characters];
349 int n = [s length], c = [s characterAtIndex:0], m = [ev modifierFlags];
350 int cm = [[ev charactersIgnoringModifiers] characterAtIndex:0];
353 int use_coutput = FALSE, special = FALSE, start, end;
355 //printf("n=%d c=U+%04x cm=U+%04x m=%08x\n", n, c, cm, m);
358 * FIXME: Alt+numberpad codes.
362 * Shift and Ctrl with PageUp/PageDown for scrollback.
364 if (n == 1 && c == NSPageUpFunctionKey && (m & NSShiftKeyMask)) {
365 term_scroll(term, 0, -term->rows/2);
368 if (n == 1 && c == NSPageUpFunctionKey && (m & NSControlKeyMask)) {
369 term_scroll(term, 0, -1);
372 if (n == 1 && c == NSPageDownFunctionKey && (m & NSShiftKeyMask)) {
373 term_scroll(term, 0, +term->rows/2);
376 if (n == 1 && c == NSPageDownFunctionKey && (m & NSControlKeyMask)) {
377 term_scroll(term, 0, +1);
382 * FIXME: Shift-Ins for paste? Or is that not Maccy enough?
386 * FIXME: Alt (Option? Command?) prefix in general.
388 * (Note that Alt-Shift-thing will work just by looking at
389 * charactersIgnoringModifiers; but Alt-Ctrl-thing will need
390 * processing properly, and Alt-as-in-Option won't happen at
393 * (Note also that we need to be able to override menu key
394 * equivalents before this is particularly useful.)
400 * Ctrl-` is the same as Ctrl-\, unless we already have a
403 if ((m & NSControlKeyMask) && n == 1 && cm == '`' && c == '`') {
408 /* We handle Return ourselves, because it needs to be flagged as
409 * special to ldisc. */
410 if (n == 1 && c == '\015') {
417 /* Control-Shift-Space is 160 (ISO8859 nonbreaking space) */
418 if (n == 1 && (m & NSControlKeyMask) && (m & NSShiftKeyMask) &&
424 /* Control-2, Control-Space and Control-@ are all NUL. */
425 if ((m & NSControlKeyMask) && n == 1 &&
426 (cm == '2' || cm == '@' || cm == ' ') && c == cm) {
431 /* We don't let MacOS tell us what Backspace is! We know better. */
432 if (cm == 0x7F && !(m & NSShiftKeyMask)) {
433 coutput[1] = cfg.bksp_is_delete ? '\x7F' : '\x08';
435 use_coutput = special = TRUE;
437 /* For Shift Backspace, do opposite of what is configured. */
438 if (cm == 0x7F && (m & NSShiftKeyMask)) {
439 coutput[1] = cfg.bksp_is_delete ? '\x08' : '\x7F';
441 use_coutput = special = TRUE;
444 /* Shift-Tab is ESC [ Z. Oddly, this combination generates ^Y by
445 * default on MacOS! */
446 if (cm == 0x19 && (m & NSShiftKeyMask) && !(m & NSControlKeyMask)) {
448 output[end++] = '\033';
454 * NetHack keypad mode.
456 if (cfg.nethack_keypad && (m & NSNumericPadKeyMask)) {
457 wchar_t *keys = NULL;
459 case '1': keys = L"bB"; break;
460 case '2': keys = L"jJ"; break;
461 case '3': keys = L"nN"; break;
462 case '4': keys = L"hH"; break;
463 case '5': keys = L".."; break;
464 case '6': keys = L"lL"; break;
465 case '7': keys = L"yY"; break;
466 case '8': keys = L"kK"; break;
467 case '9': keys = L"uU"; break;
471 if (m & NSShiftKeyMask)
480 * Application keypad mode.
482 if (term->app_keypad_keys && !cfg.no_applic_k &&
483 (m & NSNumericPadKeyMask)) {
486 case NSClearLineFunctionKey: xkey = 'P'; break;
487 case '=': xkey = 'Q'; break;
488 case '/': xkey = 'R'; break;
489 case '*': xkey = 'S'; break;
491 * FIXME: keypad - and + need to be mapped to ESC O l
492 * and ESC O k, or ESC O l and ESC O m, depending on
493 * xterm function key mode, and I can't remember which
496 case '\003': xkey = 'M'; break;
497 case '0': xkey = 'p'; break;
498 case '1': xkey = 'q'; break;
499 case '2': xkey = 'r'; break;
500 case '3': xkey = 's'; break;
501 case '4': xkey = 't'; break;
502 case '5': xkey = 'u'; break;
503 case '6': xkey = 'v'; break;
504 case '7': xkey = 'w'; break;
505 case '8': xkey = 'x'; break;
506 case '9': xkey = 'y'; break;
507 case '.': xkey = 'n'; break;
510 if (term->vt52_mode) {
511 if (xkey >= 'P' && xkey <= 'S') {
512 output[end++] = '\033';
513 output[end++] = xkey;
515 output[end++] = '\033';
517 output[end++] = xkey;
520 output[end++] = '\033';
522 output[end++] = xkey;
529 * Next, all the keys that do tilde codes. (ESC '[' nn '~',
530 * for integer decimal nn.)
532 * We also deal with the weird ones here. Linux VCs replace F1
533 * to F5 by ESC [ [ A to ESC [ [ E. rxvt doesn't do _that_, but
534 * does replace Home and End (1~ and 4~) by ESC [ H and ESC O w
540 case NSF1FunctionKey:
541 code = (m & NSShiftKeyMask ? 23 : 11);
543 case NSF2FunctionKey:
544 code = (m & NSShiftKeyMask ? 24 : 12);
546 case NSF3FunctionKey:
547 code = (m & NSShiftKeyMask ? 25 : 13);
549 case NSF4FunctionKey:
550 code = (m & NSShiftKeyMask ? 26 : 14);
552 case NSF5FunctionKey:
553 code = (m & NSShiftKeyMask ? 28 : 15);
555 case NSF6FunctionKey:
556 code = (m & NSShiftKeyMask ? 29 : 17);
558 case NSF7FunctionKey:
559 code = (m & NSShiftKeyMask ? 31 : 18);
561 case NSF8FunctionKey:
562 code = (m & NSShiftKeyMask ? 32 : 19);
564 case NSF9FunctionKey:
565 code = (m & NSShiftKeyMask ? 33 : 20);
567 case NSF10FunctionKey:
568 code = (m & NSShiftKeyMask ? 34 : 21);
570 case NSF11FunctionKey:
573 case NSF12FunctionKey:
576 case NSF13FunctionKey:
579 case NSF14FunctionKey:
582 case NSF15FunctionKey:
585 case NSF16FunctionKey:
588 case NSF17FunctionKey:
591 case NSF18FunctionKey:
594 case NSF19FunctionKey:
597 case NSF20FunctionKey:
601 if (!(m & NSControlKeyMask)) switch (cm) {
602 case NSHomeFunctionKey:
606 case GDK_Insert: case GDK_KP_Insert:
610 case NSDeleteFunctionKey:
613 case NSEndFunctionKey:
616 case NSPageUpFunctionKey:
619 case NSPageDownFunctionKey:
623 /* Reorder edit keys to physical order */
624 if (cfg.funky_type == FUNKY_VT400 && code <= 6)
625 code = "\0\2\1\4\5\3\6"[code];
627 if (term->vt52_mode && code > 0 && code <= 6) {
628 output[end++] = '\033';
629 output[end++] = " HLMEIG"[code];
633 if (cfg.funky_type == FUNKY_SCO && /* SCO function keys */
634 code >= 11 && code <= 34) {
635 char codes[] = "MNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@[\\]^_`{";
638 case NSF1FunctionKey: index = 0; break;
639 case NSF2FunctionKey: index = 1; break;
640 case NSF3FunctionKey: index = 2; break;
641 case NSF4FunctionKey: index = 3; break;
642 case NSF5FunctionKey: index = 4; break;
643 case NSF6FunctionKey: index = 5; break;
644 case NSF7FunctionKey: index = 6; break;
645 case NSF8FunctionKey: index = 7; break;
646 case NSF9FunctionKey: index = 8; break;
647 case NSF10FunctionKey: index = 9; break;
648 case NSF11FunctionKey: index = 10; break;
649 case NSF12FunctionKey: index = 11; break;
651 if (m & NSShiftKeyMask) index += 12;
652 if (m & NSControlKeyMask) index += 24;
653 output[end++] = '\033';
655 output[end++] = codes[index];
658 if (cfg.funky_type == FUNKY_SCO && /* SCO small keypad */
659 code >= 1 && code <= 6) {
660 char codes[] = "HL.FIG";
665 output[end++] = '\033';
667 output[end++] = codes[code-1];
671 if ((term->vt52_mode || cfg.funky_type == FUNKY_VT100P) &&
672 code >= 11 && code <= 24) {
678 if (term->vt52_mode) {
679 output[end++] = '\033';
680 output[end++] = code + 'P' - 11 - offt;
682 output[end++] = '\033';
684 output[end++] = code + 'P' - 11 - offt;
688 if (cfg.funky_type == FUNKY_LINUX && code >= 11 && code <= 15) {
689 output[end++] = '\033';
692 output[end++] = code + 'A' - 11;
695 if (cfg.funky_type == FUNKY_XTERM && code >= 11 && code <= 14) {
696 if (term->vt52_mode) {
697 output[end++] = '\033';
698 output[end++] = code + 'P' - 11;
700 output[end++] = '\033';
702 output[end++] = code + 'P' - 11;
706 if (cfg.rxvt_homeend && (code == 1 || code == 4)) {
708 output[end++] = '\033';
712 output[end++] = '\033';
720 sprintf(buf, "\x1B[%d~", code);
721 for (i = 0; buf[i]; i++)
722 output[end++] = buf[i];
728 * Cursor keys. (This includes the numberpad cursor keys,
729 * if we haven't already done them due to app keypad mode.)
734 case NSUpArrowFunctionKey: xkey = 'A'; break;
735 case NSDownArrowFunctionKey: xkey = 'B'; break;
736 case NSRightArrowFunctionKey: xkey = 'C'; break;
737 case NSLeftArrowFunctionKey: xkey = 'D'; break;
740 end += format_arrow_key(output+end, term, xkey,
741 m & NSControlKeyMask);
749 * Failing everything else, send the exact Unicode we got from
753 if (n > lenof(output)-start)
754 n = lenof(output)-start; /* _shouldn't_ happen! */
755 for (i = 0; i < n; i++) {
756 output[i+start] = [s characterAtIndex:i];
763 assert(end < lenof(coutput));
765 ldisc_send(ldisc, coutput+start, -2, TRUE);
767 luni_send(ldisc, output+start, end-start, TRUE);
771 - (int)fromBackend:(const char *)data len:(int)len isStderr:(int)is_stderr
773 return term_data(term, is_stderr, data, len);
776 - (int)fromBackendUntrusted:(const char *)data len:(int)len
778 return term_data_untrusted(term, data, len);
781 - (void)startAlert:(NSAlert *)alert
782 withCallback:(void (*)(void *, int))callback andCtx:(void *)ctx
784 if (alert_ctx || alert_qhead) {
786 * Queue this alert to be shown later.
788 struct alert_queue *qitem = snew(struct alert_queue);
790 qitem->alert = alert;
791 qitem->callback = callback;
794 alert_qtail->next = qitem;
799 alert_callback = callback;
800 alert_ctx = ctx; /* NB this is assumed to need freeing! */
801 [alert beginSheetModalForWindow:self modalDelegate:self
802 didEndSelector:@selector(alertSheetDidEnd:returnCode:contextInfo:)
807 - (void)alertSheetDidEnd:(NSAlert *)alert returnCode:(int)returnCode
808 contextInfo:(void *)contextInfo
810 [self performSelectorOnMainThread:
811 @selector(alertSheetDidFinishEnding:)
812 withObject:[NSNumber numberWithInt:returnCode]
816 - (void)alertSheetDidFinishEnding:(id)object
818 int returnCode = [object intValue];
820 alert_callback(alert_ctx, returnCode); /* transfers ownership of ctx */
823 * If there's an alert in our queue (either already or because
824 * the callback just queued it), start it.
827 struct alert_queue *qnext;
829 alert_callback = alert_qhead->callback;
830 alert_ctx = alert_qhead->ctx;
831 [alert_qhead->alert beginSheetModalForWindow:self modalDelegate:self
832 didEndSelector:@selector(alertSheetDidEnd:returnCode:contextInfo:)
835 qnext = alert_qhead->next;
845 - (void)notifyRemoteExit
849 if (!exited && (exitcode = back->exitcode(backhandle)) >= 0)
850 [self endSession:(exitcode == 0)];
853 - (void)endSession:(int)clean
861 back->free(backhandle);
864 //FIXME: update specials menu;
866 if (cfg.close_on_exit == FORCE_ON ||
867 (cfg.close_on_exit == AUTO && clean))
869 // FIXME: else show restart menu item
879 int from_backend(void *frontend, int is_stderr, const char *data, int len)
881 SessionWindow *win = (SessionWindow *)frontend;
882 return [win fromBackend:data len:len isStderr:is_stderr];
885 int from_backend_untrusted(void *frontend, const char *data, int len)
887 SessionWindow *win = (SessionWindow *)frontend;
888 return [win fromBackendUntrusted:data len:len];
891 int get_userpass_input(prompts_t *p, unsigned char *in, int inlen)
893 SessionWindow *win = (SessionWindow *)p->frontend;
894 Terminal *term = [win term];
895 return term_get_userpass_input(term, p, in, inlen);
898 void frontend_keypress(void *handle)
903 void notify_remote_exit(void *frontend)
905 SessionWindow *win = (SessionWindow *)frontend;
907 [win notifyRemoteExit];
910 void ldisc_update(void *frontend, int echo, int edit)
912 //SessionWindow *win = (SessionWindow *)frontend;
914 * In a GUI front end, this need do nothing.
918 char *get_ttymode(void *frontend, const char *mode)
920 SessionWindow *win = (SessionWindow *)frontend;
921 Terminal *term = [win term];
922 return term_get_ttymode(term, mode);
925 void update_specials_menu(void *frontend)
927 //SessionWindow *win = (SessionWindow *)frontend;
932 * This is still called when mode==BELL_VISUAL, even though the
933 * visual bell is handled entirely within terminal.c, because we
934 * may want to perform additional actions on any kind of bell (for
935 * example, taskbar flashing in Windows).
937 void do_beep(void *frontend, int mode)
939 //SessionWindow *win = (SessionWindow *)frontend;
940 if (mode != BELL_VISUAL)
944 int char_width(Context ctx, int uc)
947 * Under X, any fixed-width font really _is_ fixed-width.
948 * Double-width characters will be dealt with using a separate
949 * font. For the moment we can simply return 1.
954 void palette_set(void *frontend, int n, int r, int g, int b)
956 SessionWindow *win = (SessionWindow *)frontend;
962 [win setColour:n r:r/255.0 g:g/255.0 b:b/255.0];
965 * FIXME: do we need an OS X equivalent of set_window_background?
969 void palette_reset(void *frontend)
971 SessionWindow *win = (SessionWindow *)frontend;
972 Config *cfg = [win cfg];
974 /* This maps colour indices in cfg to those used in colours[]. */
975 static const int ww[] = {
976 256, 257, 258, 259, 260, 261,
977 0, 8, 1, 9, 2, 10, 3, 11,
978 4, 12, 5, 13, 6, 14, 7, 15
983 for (i = 0; i < NCFGCOLOURS; i++) {
984 [win setColour:ww[i] r:cfg->colours[i][0]/255.0
985 g:cfg->colours[i][1]/255.0 b:cfg->colours[i][2]/255.0];
988 for (i = 0; i < NEXTCOLOURS; i++) {
990 int r = i / 36, g = (i / 6) % 6, b = i % 6;
991 r = r ? r*40+55 : 0; g = g ? b*40+55 : 0; b = b ? b*40+55 : 0;
992 [win setColour:i+16 r:r/255.0 g:g/255.0 b:b/255.0];
995 float fshade = (shade * 10 + 8) / 255.0;
996 [win setColour:i+16 r:fshade g:fshade b:fshade];
1001 * FIXME: do we need an OS X equivalent of set_window_background?
1005 Context get_ctx(void *frontend)
1007 SessionWindow *win = (SessionWindow *)frontend;
1010 * Lock the drawing focus on the image inside the TerminalView.
1012 [win drawStartFinish:YES];
1014 [[NSGraphicsContext currentContext] setShouldAntialias:YES];
1017 * Cocoa drawing functions don't take a graphics context: that
1018 * parameter is implicit. Therefore, we'll use the frontend
1019 * handle itself as the context, on the grounds that it's as
1020 * good a thing to use as any.
1025 void free_ctx(Context ctx)
1027 SessionWindow *win = (SessionWindow *)ctx;
1029 [win drawStartFinish:NO];
1032 void do_text(Context ctx, int x, int y, wchar_t *text, int len,
1033 unsigned long attr, int lattr)
1035 SessionWindow *win = (SessionWindow *)ctx;
1037 [win doText:text len:len x:x y:y attr:attr lattr:lattr];
1040 void do_cursor(Context ctx, int x, int y, wchar_t *text, int len,
1041 unsigned long attr, int lattr)
1043 SessionWindow *win = (SessionWindow *)ctx;
1044 Config *cfg = [win cfg];
1045 int active, passive;
1047 if (attr & TATTR_PASCURS) {
1048 attr &= ~TATTR_PASCURS;
1052 if ((attr & TATTR_ACTCURS) && cfg->cursor_type != 0) {
1053 attr &= ~TATTR_ACTCURS;
1058 [win doText:text len:len x:x y:y attr:attr lattr:lattr];
1061 * FIXME: now draw the various cursor types (both passive and
1062 * active underlines and vertical lines, plus passive blocks).
1067 * Minimise or restore the window in response to a server-side
1070 void set_iconic(void *frontend, int iconic)
1072 //SessionWindow *win = (SessionWindow *)frontend;
1077 * Move the window in response to a server-side request.
1079 void move_window(void *frontend, int x, int y)
1081 //SessionWindow *win = (SessionWindow *)frontend;
1086 * Move the window to the top or bottom of the z-order in response
1087 * to a server-side request.
1089 void set_zorder(void *frontend, int top)
1091 //SessionWindow *win = (SessionWindow *)frontend;
1096 * Refresh the window in response to a server-side request.
1098 void refresh_window(void *frontend)
1100 //SessionWindow *win = (SessionWindow *)frontend;
1105 * Maximise or restore the window in response to a server-side
1108 void set_zoomed(void *frontend, int zoomed)
1110 //SessionWindow *win = (SessionWindow *)frontend;
1115 * Report whether the window is iconic, for terminal reports.
1117 int is_iconic(void *frontend)
1119 //SessionWindow *win = (SessionWindow *)frontend;
1120 return NO; /* FIXME */
1124 * Report the window's position, for terminal reports.
1126 void get_window_pos(void *frontend, int *x, int *y)
1128 //SessionWindow *win = (SessionWindow *)frontend;
1133 * Report the window's pixel size, for terminal reports.
1135 void get_window_pixels(void *frontend, int *x, int *y)
1137 //SessionWindow *win = (SessionWindow *)frontend;
1142 * Return the window or icon title.
1144 char *get_window_title(void *frontend, int icon)
1146 //SessionWindow *win = (SessionWindow *)frontend;
1147 return NULL; /* FIXME */
1150 void set_title(void *frontend, char *title)
1152 //SessionWindow *win = (SessionWindow *)frontend;
1156 void set_icon(void *frontend, char *title)
1158 //SessionWindow *win = (SessionWindow *)frontend;
1162 void set_sbar(void *frontend, int total, int start, int page)
1164 //SessionWindow *win = (SessionWindow *)frontend;
1168 void get_clip(void *frontend, wchar_t ** p, int *len)
1170 //SessionWindow *win = (SessionWindow *)frontend;
1174 void write_clip(void *frontend, wchar_t *data, int *attr, int len, int must_deselect)
1176 //SessionWindow *win = (SessionWindow *)frontend;
1180 void request_paste(void *frontend)
1182 //SessionWindow *win = (SessionWindow *)frontend;
1186 void set_raw_mouse_mode(void *frontend, int activate)
1188 //SessionWindow *win = (SessionWindow *)frontend;
1192 void request_resize(void *frontend, int w, int h)
1194 //SessionWindow *win = (SessionWindow *)frontend;
1198 void sys_cursor(void *frontend, int x, int y)
1200 //SessionWindow *win = (SessionWindow *)frontend;
1202 * This is probably meaningless under OS X. FIXME: find out for
1207 void logevent(void *frontend, const char *string)
1209 //SessionWindow *win = (SessionWindow *)frontend;
1211 printf("logevent: %s\n", string);
1214 int font_dimension(void *frontend, int which)/* 0 for width, 1 for height */
1216 //SessionWindow *win = (SessionWindow *)frontend;
1217 return 1; /* FIXME */
1220 void set_busy_status(void *frontend, int status)
1223 * We need do nothing here: the OS X `application is busy'
1224 * beachball pointer appears _automatically_ when the
1225 * application isn't responding to GUI messages.