Skip to content

Commit

Permalink
Reorganize screen handling
Browse files Browse the repository at this point in the history
This reorganizes the screen handling code into
* initialisation,
* screen update function (called in a loop, with menu bar),
* teardown,
which is (as before) arranged into a table indexed by function keys.
The code reorganization is necessary for supporting screen resizing.
  • Loading branch information
Gerrit Renker committed Jan 30, 2011
1 parent 3adc768 commit ba70714
Show file tree
Hide file tree
Showing 8 changed files with 234 additions and 195 deletions.
48 changes: 10 additions & 38 deletions about_scr.c
Expand Up @@ -20,6 +20,8 @@
#include "wavemon.h"

/* GLOBALS */
static WINDOW *w_about;

static char *about_lines[] = {
"wavemon - status monitor for wireless network devices",
"version " PACKAGE_VERSION " (built " BUILD_DATE ")",
Expand All @@ -36,11 +38,11 @@ static char *about_lines[] = {
PACKAGE_URL
};

static int *linecd[ARRAY_SIZE(about_lines)];
static int *linecd[ARRAY_SIZE(about_lines)], i, j;

static void init_scramble(void)
void scr_about_init(void)
{
int i, j;
w_about = newwin_title(0, WAV_HEIGHT, "About", false);

for (i = 0; i < ARRAY_SIZE(about_lines); i++) {
linecd[i] = malloc(strlen(about_lines[i]) * sizeof(int));
Expand All @@ -49,17 +51,8 @@ static void init_scramble(void)
}
}

static void free_scramble(void)
int scr_about_loop(WINDOW *w_menu)
{
int i;

for (i = 0; i < ARRAY_SIZE(about_lines); i++)
free(linecd[i]);
}

static void draw_lines(WINDOW *w_about)
{
int i, j;
char buf[0x100];

for (i = 0; i < ARRAY_SIZE(about_lines); i++) {
Expand All @@ -78,33 +71,12 @@ static void draw_lines(WINDOW *w_about)
waddstr_center(w_about, (WAV_HEIGHT - ARRAY_SIZE(about_lines))/2 + i, buf);
}
wrefresh(w_about);
return wgetch(w_menu);
}

enum wavemon_screen scr_about(WINDOW *w_menu)
void scr_about_fini(void)
{
WINDOW *w_about;
int key = 0;

w_about = newwin_title(0, WAV_HEIGHT, "About", false);

init_scramble();

while (key < KEY_F(1) || key > KEY_F(10)) {
do {
draw_lines(w_about);
key = wgetch(w_menu);
usleep(5000);
} while (key <= 0);

/* Keyboard shortcuts */
if (key == 'q')
key = KEY_F(10);
else if (key == 'i')
key = KEY_F(1);
}

free_scramble();
delwin(w_about);

return key - KEY_F(1);
for (i = 0; i < ARRAY_SIZE(about_lines); i++)
free(linecd[i]);
}
106 changes: 52 additions & 54 deletions conf_scr.c
Expand Up @@ -19,9 +19,6 @@
*/
#include "wavemon.h"

/* GLOBALS */
extern int conf_items; /* index into array storing menu items */

/* Make configuration screen fit into half of minimum screen width */
#define CONF_SCREEN_WIDTH (MIN_SCREEN_COLS / 2)
/*
Expand All @@ -30,6 +27,14 @@ extern int conf_items; /* index into array storing menu items */
*/
#define MAX_NUM_CONF_ROWS (MAXYLEN - 1)

/* GLOBALS */
extern int conf_items; /* index into array storing menu items */

static WINDOW *w_conf, *w_confpad;
static int first_item, active_item;
static int num_items, list_offset;
static struct conf_item *item;

static void waddstr_item(WINDOW *w, int y, struct conf_item *item, char hilight)
{
char s[0x40];
Expand Down Expand Up @@ -152,69 +157,62 @@ static int m_pref(WINDOW *w_conf, int list_offset, int active_item, int num_item
return list_offset;
}

enum wavemon_screen scr_conf(WINDOW *w_menu)
void scr_conf_init(void)
{
WINDOW *w_conf, *w_confpad;
int first_item, active_item = 0;
int num_items = ll_size(conf_items);
int list_offset = 0;
int key = 0;
struct conf_item *item;

iw_get_interface_list(); /* may have changed in the meantime */

num_items = ll_size(conf_items);
w_conf = newwin_title(0, WAV_HEIGHT, "Preferences", false);
w_confpad = newpad(num_items + 1, CONF_SCREEN_WIDTH);

while ((item = ll_get(conf_items, active_item)) && item->type == t_sep)
active_item++;
first_item = active_item;
}

while (key < KEY_F(1) || key > KEY_F(10)) {
list_offset = m_pref(w_confpad, list_offset, active_item, num_items);

prefresh(w_confpad, list_offset, 0,
1, (WAV_WIDTH - CONF_SCREEN_WIDTH)/2,
MAXYLEN, (WAV_WIDTH + CONF_SCREEN_WIDTH)/2);
wrefresh(w_conf);

key = wgetch(w_menu);
switch (key) {
case KEY_DOWN:
active_item = select_item(active_item, 1);
if (active_item >= num_items) {
active_item = first_item;
list_offset = 0;
}
break;
case KEY_UP:
active_item = select_item(active_item, -1);
if (active_item < first_item)
active_item = num_items - 1;
break;
case KEY_LEFT:
change_item(active_item, -1);
break;
case KEY_RIGHT:
change_item(active_item, 1);
break;
case '\r':
item = ll_get(conf_items, active_item);
if (item->type == t_func) {
flash();
(*item->v.fp)();
}
break;
/* Keyboard shortcuts */
case 'q':
key = KEY_F(10);
break;
case 'i':
key = KEY_F(1);
int scr_conf_loop(WINDOW *w_menu)
{
int key;

list_offset = m_pref(w_confpad, list_offset, active_item, num_items);

prefresh(w_confpad, list_offset, 0,
1, (WAV_WIDTH - CONF_SCREEN_WIDTH)/2,
MAXYLEN, (WAV_WIDTH + CONF_SCREEN_WIDTH)/2);
wrefresh(w_conf);

key = wgetch(w_menu);
switch (key) {
case KEY_DOWN:
active_item = select_item(active_item, 1);
if (active_item >= num_items) {
active_item = first_item;
list_offset = 0;
}
break;
case KEY_UP:
active_item = select_item(active_item, -1);
if (active_item < first_item)
active_item = num_items - 1;
break;
case KEY_LEFT:
change_item(active_item, -1);
break;
case KEY_RIGHT:
change_item(active_item, 1);
break;
case '\r':
item = ll_get(conf_items, active_item);
if (item->type == t_func) {
flash();
(*item->v.fp)();
}
}
return key;
}

void scr_conf_fini(void)
{
delwin(w_conf);
delwin(w_confpad);

return key - KEY_F(1);
}
29 changes: 11 additions & 18 deletions help_scr.c
Expand Up @@ -19,29 +19,22 @@
*/
#include "wavemon.h"

enum wavemon_screen scr_help(WINDOW *w_menu)
{
WINDOW *w_help;
int key = 0;
/* GLOBALS */
static WINDOW *w_help;

void scr_help_init(void)
{
w_help = newwin_title(0, WAV_HEIGHT, "Help", false);

waddstr_center(w_help, WAV_HEIGHT/2 - 1, "don't panic.");

wrefresh(w_help);
}

while (key < KEY_F(1) || key > KEY_F(10)) {
while ((key = wgetch(w_menu)) <= 0)
usleep(5000);

/* Keyboard shortcuts */
if (key == 'q')
key = KEY_F(10);
else if (key == 'i')
key = KEY_F(1);
}
int scr_help_loop(WINDOW *w_menu)
{
return wgetch(w_menu);
}

void scr_help_fini(void)
{
delwin(w_help);

return key - KEY_F(1);
}
42 changes: 19 additions & 23 deletions info_scr.c
Expand Up @@ -20,8 +20,8 @@
#include "iw_if.h"

/* GLOBALS */
static WINDOW *w_levels, *w_stats;

static WINDOW *w_levels, *w_stats, *w_if, *w_info, *w_net;
static struct timer dyn_updates;
static struct iw_stat cur;

void sampling_init(void (*sampling_handler)(int))
Expand Down Expand Up @@ -505,11 +505,9 @@ static void redraw_stat_levels(int signum)
display_stats();
}

enum wavemon_screen scr_info(WINDOW *w_menu)
void scr_info_init(void)
{
WINDOW *w_if, *w_info, *w_net;
struct timer t1;
int key = 0, line = 0;
int line = 0;

w_if = newwin_title(line, WH_IFACE, "Interface", true);
line += WH_IFACE;
Expand All @@ -526,29 +524,27 @@ enum wavemon_screen scr_info(WINDOW *w_menu)

display_info(w_if, w_info);
display_netinfo(w_net);
start_timer(&dyn_updates, conf.info_iv * 1000000);
sampling_init(redraw_stat_levels);
}

while (key < KEY_F(1) || key > KEY_F(10)) {
int scr_info_loop(WINDOW *w_menu)
{
if (end_timer(&dyn_updates)) {
display_info(w_if, w_info);
display_netinfo(w_net);

start_timer(&t1, conf.info_iv * 1000000);
while (!end_timer(&t1) && (key = wgetch(w_menu)) <= 0)
sleep(1);

/* Keyboard shortcuts */
if (key == 'q')
key = KEY_F(10);
else if (key == 'i')
key = KEY_F(1);
start_timer(&dyn_updates, conf.info_iv * 1000000);
}
return wgetch(w_menu);
}

void scr_info_fini(void)
{
sampling_stop();

delwin(w_if);
delwin(w_levels);
delwin(w_stats);
delwin(w_info);
delwin(w_net);

return key - KEY_F(1);
delwin(w_info);
delwin(w_stats);
delwin(w_levels);
delwin(w_if);
}
23 changes: 8 additions & 15 deletions lhist_scr.c
Expand Up @@ -316,10 +316,8 @@ static void redraw_lhist(int signum)
}
}

enum wavemon_screen scr_lhist(WINDOW *w_menu)
void scr_lhist_init(void)
{
int key = 0;

w_lhist = newwin_title(0, HIST_WIN_HEIGHT, "Level histogram", true);
w_key = newwin_title(HIST_MAXYLEN + 1, KEY_WIN_HEIGHT, "Key", false);

Expand All @@ -329,21 +327,16 @@ enum wavemon_screen scr_lhist(WINDOW *w_menu)
sampling_init(redraw_lhist);

display_key(w_key);
}

while (key < KEY_F(1) || key > KEY_F(10)) {
while ((key = wgetch(w_menu)) <= 0)
usleep(5000);
int scr_lhist_loop(WINDOW *w_menu)
{
return wgetch(w_menu);
}

/* Keyboard shortcuts */
if (key == 'q')
key = KEY_F(10);
else if (key == 'i')
key = KEY_F(1);
}
void scr_lhist_fini(void)
{
sampling_stop();

delwin(w_lhist);
delwin(w_key);

return key - KEY_F(1);
}

0 comments on commit ba70714

Please sign in to comment.