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(), free_win(),
11 #include "yx_uint16.h" /* for yx_uint16 struct */
12 #include "main.h" /* for Wins struct */
13 #include "misc.h" /* for textfile_sizes() */
14 #include "rexit.h" /* for exit_err() */
15 #include "main.h" /* for World, Wins structs */
16 #include "draw_wins.h" /* for draw_keys_win(), draw_info_win(), draw_log_win(),
22 extern void reload_win_config(struct World * world)
24 while (0 != world->wins.meta->active)
26 suspend_win(world->wins.meta, world->wins.meta->active);
28 free_win(world->wins.info);
29 free_win(world->wins.keys);
30 free_win(world->wins.map);
31 free_win(world->wins.log);
32 world->wins.keys = init_win_from_file(world, "Keys", draw_keys_win);
33 world->wins.info = init_win_from_file(world, "Info", draw_info_win);
34 world->wins.log = init_win_from_file(world, "Log", draw_log_win);
35 world->wins.map = init_win_from_file(world, "Map", draw_map_win);
36 sorted_wintoggle(world);
41 extern struct Win * init_win_from_file(struct World * world, char * w_name,
42 void (* f) (struct Win *))
44 char * err_m = "Trouble in init_win_from_file() with malloc().";
45 char * prefix = "config/windows/";
46 uint8_t size = strlen(prefix) + strlen(w_name) + 1;
47 char * path = malloc(size);
48 exit_err(NULL == path, world, err_m);
49 sprintf(path, "%s%s", prefix, w_name);
50 char * err = "Trouble in init_win_from_file() with fopen().";
51 FILE * file = fopen(path, "r");
53 exit_err(NULL == file, world, err);
55 err = "Trouble in init_win_from_file() with textfile_sizes().";
56 exit_err(textfile_sizes(file, &linemax, NULL), world, err);
57 char * line = malloc(linemax);
58 exit_err(NULL == line, world, err_m);
59 err = "Trouble in init_win_from_file() with fgets().";
60 exit_err(NULL == fgets(line, linemax, file), world, err);
61 char * title = malloc(strlen(line));
62 exit_err(NULL == title, world, err_m);
63 memcpy(title, line, strlen(line) - 1); /* Eliminate newline char at end */
64 title[strlen(line) - 1] = '\0'; /* of string. */
65 exit_err(NULL == fgets(line, linemax, file), world, err);
66 int16_t height = atoi(line);
67 exit_err(NULL == fgets(line, linemax, file), world, err);
68 int16_t width = atoi(line);
70 err = "Trouble in init_win_from_file() with fclose().";
71 exit_err(fclose(file), world, err);
72 struct WinMeta * wmeta = world->wins.meta;
74 err = "Trouble in init_win_from_file() with init_win().";
75 exit_err(init_win(wmeta, &wp, title, height, width, world, f), world, err);
82 extern void sorted_wintoggle(struct World * world)
84 char * err = "Trouble in sorted_wintoggle() with fopen().";
85 FILE * file = fopen("config/windows/toggle_order", "r");
86 exit_err(NULL == file, world, err);
88 err = "Trouble in sorted_wintoggle() with textfile_sizes().";
89 exit_err(textfile_sizes(file, &linemax, NULL), world, err);
90 char win_order[linemax];
91 err = "Trouble in sorted_wintoggle() with fgets().";
92 exit_err(NULL == fgets(win_order, linemax, file), world, err);
93 err = "Trouble in sorted_wintoggle() with fclose().";
94 exit_err(fclose(file), world, err);
98 for (; i < linemax; i++)
103 toggle_window(world->wins.meta, world->wins.keys);
107 toggle_window(world->wins.meta, world->wins.map);
111 toggle_window(world->wins.meta, world->wins.info);
115 toggle_window(world->wins.meta, world->wins.log);
123 extern uint8_t toggle_window(struct WinMeta * win_meta, struct Win * win)
125 if (0 != win->frame.curses_win)
127 return suspend_win(win_meta, win);
131 return append_win(win_meta, win);
137 extern void scroll_pad(struct WinMeta * win_meta, char dir)
141 reset_pad_offset(win_meta, win_meta->pad_offset + 1);
145 reset_pad_offset(win_meta, win_meta->pad_offset - 1);
151 extern uint8_t growshrink_active_window(struct WinMeta * win_meta, char change)
153 if (0 != win_meta->active)
155 struct yx_uint16 size = win_meta->active->frame.size;
160 else if (change == '+')
164 else if (change == '_')
168 else if (change == '*')
172 return resize_active_win (win_meta, size);