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); /* Eliminate newline char at end */
39 title[strlen(line) - 1] = '\0'; /* of string. */
40 exit_err(NULL == fgets(line, linemax, file), world, err);
41 int16_t height = atoi(line);
42 exit_err(NULL == fgets(line, linemax, file), world, err);
43 int16_t width = atoi(line);
45 err = "Trouble in init_win_from_file() with fclose().";
46 exit_err(fclose(file), world, err);
48 struct WinMeta * wmeta = world->wins.meta;
49 struct Win * wp; // = malloc(sizeof(struct Win));
50 init_win(wmeta, &wp, title, height, width, world, f);
57 extern void sorted_wintoggle(struct World * world)
59 char * err = "Trouble in sorted_wintoggle() with fopen() on file "
60 "'config/toggle_win_order'.";
61 FILE * file = fopen("config/windows/toggle_order", "r");
62 exit_err(NULL == file, world, err);
64 textfile_sizes(file, &linemax, NULL);
65 char win_order[linemax];
66 err = "Trouble in sorted_wintoggle() with fgets() on file "
67 "'config/toggle_win_order'.";
68 exit_err(NULL == fgets(win_order, linemax, file), world, err);
69 err = "Trouble in sorted_wintoggle() with fclose() on file "
70 "'toggle_win_order'.";
71 exit_err(fclose(file), world, err);
75 for (; i < linemax; i++)
80 toggle_window(world->wins.meta, world->wins.keys);
84 toggle_window(world->wins.meta, world->wins.map);
88 toggle_window(world->wins.meta, world->wins.info);
92 toggle_window(world->wins.meta, world->wins.log);
100 extern uint8_t toggle_window(struct WinMeta * win_meta, struct Win * win)
102 if (0 != win->frame.curses_win)
104 return suspend_win(win_meta, win);
108 return append_win(win_meta, win);
114 extern void scroll_pad(struct WinMeta * win_meta, char dir)
118 reset_pad_offset(win_meta, win_meta->pad_offset + 1);
122 reset_pad_offset(win_meta, win_meta->pad_offset - 1);
128 extern uint8_t growshrink_active_window(struct WinMeta * win_meta, char change)
130 if (0 != win_meta->active)
132 struct yx_uint16 size = win_meta->active->frame.size;
137 else if (change == '+')
141 else if (change == '_')
145 else if (change == '*')
149 return resize_active_win (win_meta, size);