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 char * title = malloc(strlen(line));
38 memcpy(title, line, strlen(line) - 1);
39 exit_err(NULL == fgets(line, linemax, file), world, err);
40 int16_t height = atoi(line);
41 exit_err(NULL == fgets(line, linemax, file), world, err);
42 int16_t width = atoi(line);
44 err = "Trouble in init_win_from_file() with fclose().";
45 exit_err(fclose(file), world, err);
47 struct WinMeta * wmeta = world->wins.meta;
49 init_win(wmeta, &w, title, height, width, world, f);
56 extern void sorted_wintoggle(struct World * world)
58 char * err = "Trouble in sorted_wintoggle() with fopen() on file "
59 "'config/toggle_win_order'.";
60 FILE * file = fopen("config/windows/toggle_order", "r");
61 exit_err(NULL == file, world, err);
63 textfile_sizes(file, &linemax, NULL);
64 char win_order[linemax];
65 err = "Trouble in sorted_wintoggle() with fgets() on file "
66 "'config/toggle_win_order'.";
67 exit_err(NULL == fgets(win_order, linemax, file), world, err);
68 err = "Trouble in sorted_wintoggle() with fclose() on file "
69 "'toggle_win_order'.";
70 exit_err(fclose(file), world, err);
74 for (; i < linemax; i++)
79 toggle_window(world->wins.meta, world->wins.keys);
83 toggle_window(world->wins.meta, world->wins.map);
87 toggle_window(world->wins.meta, world->wins.info);
91 toggle_window(world->wins.meta, world->wins.log);
99 extern uint8_t toggle_window(struct WinMeta * win_meta, struct Win * win)
101 if (0 != win->frame.curses_win)
103 return suspend_win(win_meta, win);
107 return append_win(win_meta, win);
113 extern void scroll_pad(struct WinMeta * win_meta, char dir)
117 reset_pad_offset(win_meta, win_meta->pad_offset + 1);
121 reset_pad_offset(win_meta, win_meta->pad_offset - 1);
127 extern uint8_t growshrink_active_window(struct WinMeta * win_meta, char change)
129 if (0 != win_meta->active)
131 struct yx_uint16 size = win_meta->active->frame.size;
136 else if (change == '+')
140 else if (change == '_')
144 else if (change == '*')
148 return resize_active_win (win_meta, size);