-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
147 lines (121 loc) · 4 KB
/
main.c
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#define GLAD_GL_IMPLEMENTATION
#include "gl.h"
#define GLFW_INCLUDE_NONE
#include <GLFW/glfw3.h>
#include <stdio.h>
//#include "render.h"
#define RFONT_IMPLEMENTATION
#include "RFont.h"
#include <vterm.h>
#include <stdbool.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <pty.h>
#include <unistd.h>
//custom
#include "term_parts/fps_counter.h"
#include "term_parts/application.h"
#include "term_parts/pty_manager.h"
#include "term_parts/terminal.h"
int damage(VTermRect rect, void *user) {
//printf("damage: [%d, %d, %d, %d]\n", rect.start_col,
// rect.start_row, rect.end_col, rect.end_row);
return 1;
}
int moverect(VTermRect dest, VTermRect src, void *user) {
return 1;
}
int movecursor(VTermPos pos, VTermPos oldpos, int visible, void *user) {
return 1;
}
int settermprop(VTermProp prop, VTermValue *val, void *user) {
return 1;
}
/*int bell(void *user) {
TERM_State *state = (TERM_State*)user;
state->bell.active = true;
state->bell.ticks = state->ticks;
return 1;
}*/
int sb_pushline(int cols, const VTermScreenCell *cells, void *user) {
printf("SB Pushline\n");
return 1;
}
int sb_popline(int cols, VTermScreenCell *cells, void *user) {
return 1;
}
VTermScreenCallbacks callbacks = {
.movecursor = movecursor,
.sb_pushline = sb_pushline,
.damage = damage
};
// Die Funktion, die aufgerufen wird, wenn ein Tastenereignis auftritt
void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods) {
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
glfwSetWindowShouldClose(window, GLFW_TRUE);
}
int main(void) {
GLFWwindow* window;
// Initialisiere die GLFW-Bibliothek
if (!glfwInit()) {
fprintf(stderr, "Fehler beim Initialisieren von GLFW\n");
return -1;
}
//glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
//glfwWindowHint(GLFW_TRANSPARENT_FRAMEBUFFER, GLFW_TRUE);
window = glfwCreateWindow(900, 600, "Mein erstes GLFW-Fenster", NULL, NULL);
if (!window) {
fprintf(stderr, "Fehler beim Erstellen des Fensters\n");
glfwTerminate();
return -1;
}
// Setze den Tastenrückruf
//glfwSetKeyCallback(window, key_callback);
// Mache das neu erstellte Fenster zum aktuellen Kontext
glfwMakeContextCurrent(window);
gladLoadGL(glfwGetProcAddress);
Application app;
glfwGetWindowSize(window, &app.width, &app.height);
//RFont init
RFont_init(app.width, app.height);
app.font = *RFont_font_init("NotoSansMono-Regular.ttf");
//app.font = *RFont_font_init("JetBrainsMono-Regular.ttf");
//RFont_font* japanese = RFont_font_init("DroidSansJapanese.ttf");
app.font_height = 24;
//draw text as test
app.font_width = (int) RFont_text_width_len(&app.font, "\\u00A0", 1, app.font_height, 0);
printf("%i\n", app.font_width);
app.cols = app.width / app.font_width;
app.rows = app.height / app.font_height;
printf( " Row spacing %i\n", app.height % app.font_height);
if(create_pty_fork(&app) < 0) {
printf("error\n");
exit(0);
}
app.vterm = create_vterm(app.rows, app.cols);
app.screen = vterm_obtain_screen(app.vterm);
vterm_screen_reset(app.screen, 1);
app.termstate = vterm_obtain_state(app.vterm);
vterm_screen_set_callbacks(app.screen, &callbacks, &app);
struct winsize ws = {0};
ws.ws_col = app.cols;
ws.ws_row = app.rows;
ioctl(app.childfd, TIOCSWINSZ, &ws);
// Schleife, um das Fenster offen zu halten, bis es geschlossen wird
glViewport(0, 0, app.width, app.height);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Hintergrundfarbe setzen (schwarz)
glOrtho(0, app.width, app.height, 0, 1,-1);
while (!glfwWindowShouldClose(window)) {
glClear(GL_COLOR_BUFFER_BIT);
TERM_HandleChildEvents(&app);
render_screen(&app);
fps_counter(window);
glfwSwapBuffers(window);
glfwPollEvents();
}
// Aufräumen
glfwDestroyWindow(window);
glfwTerminate();
return 0;
}