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 void free_win(struct Win * win)
26 extern struct Win * init_win_from_file(struct World * world, char * w_name,
27 void (* f) (struct Win *))
29 char * err = "Trouble in init_win_from_file() with malloc().";
30 char * prefix = "config/windows/";
31 uint8_t size = strlen(prefix) + strlen(w_name) + 1;
32 char * path = malloc(size);
33 exit_err(NULL == path, world, err);
34 sprintf(path, "%s%s", prefix, w_name);
36 err = "Trouble in init_win_from_file() with fopen().";
37 FILE * file = fopen(path, "r");
39 exit_err(NULL == file, world, err);
41 textfile_sizes(file, &linemax, NULL);
42 char * line = malloc(linemax);
43 err = "Trouble in init_win_from_file() with fgets().";
44 exit_err(NULL == fgets(line, linemax, file), world, err);
45 char * title = malloc(strlen(line));
46 memcpy(title, line, strlen(line) - 1); /* Eliminate newline char at end */
47 title[strlen(line) - 1] = '\0'; /* of string. */
48 exit_err(NULL == fgets(line, linemax, file), world, err);
49 int16_t height = atoi(line);
50 exit_err(NULL == fgets(line, linemax, file), world, err);
51 int16_t width = atoi(line);
53 err = "Trouble in init_win_from_file() with fclose().";
54 exit_err(fclose(file), world, err);
56 struct WinMeta * wmeta = world->wins.meta;
57 struct Win * w = malloc(sizeof(struct Win));
58 init_win(wmeta, w, title, height, width, world, f);
65 extern void sorted_wintoggle(struct World * world)
67 char * err = "Trouble in sorted_wintoggle() with fopen() on file "
68 "'config/toggle_win_order'.";
69 FILE * file = fopen("config/windows/toggle_order", "r");
70 exit_err(NULL == file, world, err);
72 textfile_sizes(file, &linemax, NULL);
73 char win_order[linemax];
74 err = "Trouble in sorted_wintoggle() with fgets() on file "
75 "'config/toggle_win_order'.";
76 exit_err(NULL == fgets(win_order, linemax, file), world, err);
77 err = "Trouble in sorted_wintoggle() with fclose() on file "
78 "'toggle_win_order'.";
79 exit_err(fclose(file), world, err);
83 for (; i < linemax; i++)
88 toggle_window(world->wins.meta, world->wins.keys);
92 toggle_window(world->wins.meta, world->wins.map);
96 toggle_window(world->wins.meta, world->wins.info);
100 toggle_window(world->wins.meta, world->wins.log);
108 extern uint8_t toggle_window(struct WinMeta * win_meta, struct Win * win)
110 if (0 != win->frame.curses_win)
112 return suspend_win(win_meta, win);
116 return append_win(win_meta, win);
122 extern void scroll_pad(struct WinMeta * win_meta, char dir)
126 reset_pad_offset(win_meta, win_meta->pad_offset + 1);
130 reset_pad_offset(win_meta, win_meta->pad_offset - 1);
136 extern uint8_t growshrink_active_window(struct WinMeta * win_meta, char change)
138 if (0 != win_meta->active)
140 struct yx_uint16 size = win_meta->active->frame.size;
145 else if (change == '+')
149 else if (change == '_')
153 else if (change == '*')
157 return resize_active_win (win_meta, size);