3 #include "wincontrol.h"
4 #include <stdlib.h> /* for malloc(), free() */
5 #include <string.h> /* for strlen() */
6 #include <stdint.h> /* for uint8_t, uint16_t */
7 #include "windows.h" /* for suspend_win(), append_win(), reset_pad_offset(),
8 * resize_active_win(), init_win(), structs Win, WinMeta
10 #include "yx_uint16.h" /* for yx_uint16 struct */
11 #include "main.h" /* for Wins struct */
12 #include "misc.h" /* for textfile_sizes() */
13 #include "rexit.h" /* for exit_err() */
14 #include "main.h" /* for World, Wins structs */
18 extern struct Win init_win_from_file(struct World * world, char * w_name,
19 void (* f) (struct Win *))
21 char * err = "Trouble in init_win_from_file() with malloc().";
22 char * prefix = "config/windows/";
23 uint8_t size = strlen(prefix) + strlen(w_name) + 1;
24 char * path = malloc(size);
25 exit_err(NULL == path, world, err);
26 sprintf(path, "%s%s", prefix, w_name);
28 err = "Trouble in init_win_from_file() with fopen().";
29 FILE * file = fopen(path, "r");
31 exit_err(NULL == file, world, err);
33 textfile_sizes(file, &linemax, NULL);
34 char * line = malloc(linemax);
35 err = "Trouble in init_win_from_file() with fgets().";
36 exit_err(NULL == fgets(line, linemax, file), world, err);
37 int16_t height = atoi(line);
38 exit_err(NULL == fgets(line, linemax, file), world, err);
39 int16_t width = atoi(line);
41 err = "Trouble in init_win_from_file() with fclose().";
42 exit_err(fclose(file), world, err);
44 struct WinMeta * wmeta = world->wins.meta;
45 return init_win(wmeta, w_name, height, width, world, f);
50 extern void sorted_wintoggle(struct World * world)
52 char * err = "Trouble in sorted_wintoggle() with fopen() on file "
53 "'config/toggle_win_order'.";
54 FILE * file = fopen("config/windows/toggle_order", "r");
55 exit_err(NULL == file, world, err);
57 textfile_sizes(file, &linemax, NULL);
58 char win_order[linemax];
59 err = "Trouble in sorted_wintoggle() with fgets() on file "
60 "'config/toggle_win_order'.";
61 exit_err(NULL == fgets(win_order, linemax, file), world, err);
62 err = "Trouble in sorted_wintoggle() with fclose() on file "
63 "'toggle_win_order'.";
64 exit_err(fclose(file), world, err);
68 for (; i < linemax; i++)
73 toggle_window(world->wins.meta, world->wins.keys);
77 toggle_window(world->wins.meta, world->wins.map);
81 toggle_window(world->wins.meta, world->wins.info);
85 toggle_window(world->wins.meta, world->wins.log);
93 extern uint8_t toggle_window(struct WinMeta * win_meta, struct Win * win)
95 if (0 != win->frame.curses_win)
97 return suspend_win(win_meta, win);
101 return append_win(win_meta, win);
107 extern void scroll_pad(struct WinMeta * win_meta, char dir)
111 reset_pad_offset(win_meta, win_meta->pad_offset + 1);
115 reset_pad_offset(win_meta, win_meta->pad_offset - 1);
121 extern uint8_t growshrink_active_window(struct WinMeta * win_meta, char change)
123 if (0 != win_meta->active)
125 struct yx_uint16 size = win_meta->active->frame.size;
130 else if (change == '+')
134 else if (change == '_')
138 else if (change == '*')
142 return resize_active_win (win_meta, size);