1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
#include <stdlib.h>
#include <string.h>
#include "runes.h"
#include "term.h"
#include "config.h"
#include "display.h"
#include "pty-unix.h"
#include "window-xlib.h"
RunesTerm *runes_term_new(
int argc, char *argv[], char *envp[], char *cwd, RunesWindowBackend *wb)
{
RunesTerm *t;
int width, height;
t = calloc(1, sizeof(RunesTerm));
t->config = runes_config_new(argc, argv);
t->display = runes_display_new(t->config->font_name);
t->w = runes_window_new(wb);
t->pty = runes_pty_new();
t->scr = vt100_screen_new(t->config->default_cols, t->config->default_rows);
vt100_screen_set_scrollback_length(t->scr, t->config->scrollback_length);
runes_window_create_window(t, argc, argv);
runes_pty_spawn_subprocess(t, envp, cwd);
runes_display_set_context(t, t->w->backend_cr);
runes_window_get_size(t, &width, &height);
runes_term_set_window_size(t, width, height);
return t;
}
void runes_term_register_with_loop(RunesTerm *t, RunesLoop *loop)
{
t->loop = loop;
runes_window_init_loop(t, loop);
runes_pty_init_loop(t, loop);
}
void runes_term_set_window_size(RunesTerm *t, int xpixel, int ypixel)
{
int row = ypixel / t->display->fonty, col = xpixel / t->display->fontx;
runes_pty_set_window_size(t, row, col, xpixel, ypixel);
vt100_screen_set_window_size(t->scr, row, col);
}
void runes_term_refcnt_inc(RunesTerm *t)
{
t->refcnt++;
}
void runes_term_refcnt_dec(RunesTerm *t)
{
t->refcnt--;
if (t->refcnt <= 0) {
runes_term_delete(t);
}
}
void runes_term_delete(RunesTerm *t)
{
vt100_screen_delete(t->scr);
runes_pty_delete(t->pty);
runes_window_delete(t->w);
runes_display_delete(t->display);
runes_config_delete(t->config);
free(t);
}
|