|
33 | 33 |
|
34 | 34 | /* Arbitrary sizes */ |
35 | 35 | #define DRAW_BUF_SIZ 20 * 1024 |
36 | | - |
37 | | -#define REDRAW_TIMEOUT (80 * 1000) /* 80 ms */ |
| 36 | +// #define REDRAW_TIMEOUT (80 * 1000) /* 80 ms */ |
38 | 37 |
|
39 | 38 | /* macros */ |
40 | 39 | #define TIMEDIFF(t1, t2) ((t1.tv_sec - t2.tv_sec) * 1000 + (t1.tv_usec - t2.tv_usec) / 1000) |
@@ -227,19 +226,27 @@ void sdl_shutdown(void) { |
227 | 226 |
|
228 | 227 | void window_event_handler(SDL_Event *event) { |
229 | 228 | #ifdef BR2 |
230 | | - return; // no resize for BR2 handheld devices builds because of kms video driver |
| 229 | + return; // no window events for BR2 handheld devices builds because of kms video driver |
231 | 230 | #endif |
232 | 231 | switch (event->window.event) { |
233 | 232 | case SDL_WINDOWEVENT_RESIZED: |
234 | | - scale_to_size(event->window.data1, event->window.data2); |
| 233 | + scale_to_size((int)(event->window.data1 / opt_scale), (int)(event->window.data2 / opt_scale)); |
| 234 | + break; |
| 235 | + case SDL_WINDOWEVENT_FOCUS_GAINED: |
| 236 | + main_window.state |= WIN_FOCUSED; |
| 237 | + // redraw(); // redraw to update cursor color |
| 238 | + break; |
| 239 | + case SDL_WINDOWEVENT_FOCUS_LOST: |
| 240 | + main_window.state &= ~WIN_FOCUSED; |
| 241 | + //redraw(); // redraw to update cursor color |
235 | 242 | break; |
236 | 243 | default: |
237 | 244 | break; |
238 | 245 | } |
239 | 246 | } |
240 | 247 |
|
241 | 248 | void scale_to_size(int width, int height) { |
242 | | - if (width <= 0 || height <= 0 || width > 8192 || height > 8192) return; |
| 249 | + if (width <= 100 || height <= 80 || width > 8192 || height > 8192) return; |
243 | 250 | main_window.width = width; |
244 | 251 | main_window.height = height; |
245 | 252 | printf("Set scale to size: %dx%d (x%.1f)\n", main_window.width, main_window.height, opt_scale); |
@@ -277,6 +284,7 @@ void scale_to_size(int width, int height) { |
277 | 284 | t_resize(col, row); |
278 | 285 | x_resize(col, row); |
279 | 286 | tty_resize(); |
| 287 | + redraw(); |
280 | 288 | } |
281 | 289 |
|
282 | 290 | void sdl_init(void) { |
@@ -315,7 +323,7 @@ void sdl_init(void) { |
315 | 323 | printf("Setting resolution to: %dx%d\n", main_window.width, main_window.height); |
316 | 324 | } |
317 | 325 |
|
318 | | - main_window.window = SDL_CreateWindow("Simple Terminal", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, main_window.width, main_window.height, SDL_WINDOW_SHOWN); |
| 326 | + main_window.window = SDL_CreateWindow("Simple Terminal", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, main_window.width, main_window.height, SDL_WINDOW_RESIZABLE | SDL_WINDOW_SHOWN); |
319 | 327 | if (!main_window.window) { |
320 | 328 | fprintf(stderr, "Unable to create window: %s\n", SDL_GetError()); |
321 | 329 | exit(EXIT_FAILURE); |
@@ -686,11 +694,10 @@ void x_draw_cursor(void) { |
686 | 694 | } |
687 | 695 |
|
688 | 696 | void redraw(void) { |
689 | | - struct timespec tv = {0, REDRAW_TIMEOUT * 1000}; |
690 | | - |
| 697 | + //struct timespec tv = {0, REDRAW_TIMEOUT * 1000}; |
691 | 698 | t_full_dirt(); |
692 | 699 | draw(); |
693 | | - nanosleep(&tv, NULL); |
| 700 | + //nanosleep(&tv, NULL); |
694 | 701 | } |
695 | 702 |
|
696 | 703 | void draw(void) { |
@@ -1066,14 +1073,8 @@ void main_loop(void) { |
1066 | 1073 | continue; // skip mouse events |
1067 | 1074 | } |
1068 | 1075 | if (ev.type == SDL_WINDOWEVENT) { |
1069 | | - // if (ev.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) { |
1070 | | - // main_window.state |= WIN_FOCUSED; |
1071 | | - // draw(); // redraw to update cursor color |
1072 | | - // } else if (ev.window.event == SDL_WINDOWEVENT_FOCUS_LOST) { |
1073 | | - // main_window.state &= ~WIN_FOCUSED; |
1074 | | - // draw(); // redraw to update cursor color |
1075 | | - // } |
1076 | | - continue; // skip other window events for now |
| 1076 | + window_event_handler(&ev); |
| 1077 | + continue; |
1077 | 1078 | } |
1078 | 1079 |
|
1079 | 1080 | if (ev.type == SDL_KEYDOWN || ev.type == SDL_KEYUP) { |
|
0 commit comments