commit a83272e0a27ba1e4e04725b0923dc802d892ed2c
parent 5b389661c37fd326c47b2a4e452dac3b861205ac
Author: hhvn <dev@hhvn.uk>
Date: Sun, 24 Apr 2022 14:16:33 +0100
Seperate hiding of windows from .location variables
Diffstat:
4 files changed, 83 insertions(+), 64 deletions(-)
diff --git a/src/config.c b/src/config.c
@@ -25,18 +25,16 @@
#include <limits.h>
#include "hirc.h"
-static int config_nicklist_location(long num);
-static int config_nicklist_width(long num);
-static int config_buflist_location(long num);
-static int config_buflist_width(long num);
-static int config_nickcolour_self(long num);
-static int config_nickcolour_range(long a, long b);
-static int config_redrawl(long num);
-static int config_redraws(char *str);
+static int config_window_hide(struct Config *conf, long num);
+static int config_window_location(struct Config *conf, long num);
+static int config_window_width(struct Config *conf, long num);
+static int config_nickcolour_self(struct Config *conf, long num);
+static int config_nickcolour_range(struct Config *conf, long a, long b);
+static int config_redrawl(struct Config *conf, long num);
+static int config_redraws(struct Config *conf, char *str);
static char *strbool[] = { "true", "false", NULL };
static char *strlocation[] = {
- [Location_hidden] = "hidden",
[Location_left] = "left",
[Location_right] = "right",
NULL
@@ -54,7 +52,7 @@ static struct {
[Val_nzunsigned] = {"greater than zero", 1, LONG_MAX},
[Val_pair] = {"a pair", LONG_MIN, LONG_MAX},
[Val_colourpair] = {"pair with numbers from 0 to 99", 0, 99},
- [Val_location] = {"a location (hidden/left/right)", Location_hidden, Location_right},
+ [Val_location] = {"a location (left/right)", Location_left, Location_right},
};
#include "data/config.h"
@@ -137,7 +135,7 @@ config_setl(struct Config *conf, long num) {
conf->valtype == Val_nzunsigned ||
conf->valtype == Val_location)) {
if (conf->numhandle)
- if (!conf->numhandle(num))
+ if (!conf->numhandle(conf, num))
return;
conf->isdef = 0;
conf->num = num;
@@ -155,7 +153,7 @@ config_sets(struct Config *conf, char *str) {
return;
}
if (conf->strhandle)
- if (!conf->strhandle(str))
+ if (!conf->strhandle(conf, str))
return;
if (!conf->isdef)
pfree(&conf->str);
@@ -171,7 +169,7 @@ config_setr(struct Config *conf, long a, long b) {
if (a >= vals[conf->valtype].min && b <= vals[conf->valtype].max &&
(conf->valtype == Val_pair || conf->valtype == Val_colourpair)) {
if (conf->pairhandle)
- if (!conf->pairhandle(a, b))
+ if (!conf->pairhandle(conf, a, b))
return;
conf->isdef = 0;
conf->pair[0] = a;
@@ -208,13 +206,15 @@ config_set(char *name, char *val) {
config_setl(conf, 1);
else if (strcmp(tok[0], "false") == 0)
config_setl(conf, 0);
+ else
+ goto inval;
} else if (tok[0] && !tok[1] && conf->valtype == Val_location) {
- if (strcmp(tok[0], "hidden") == 0)
- config_setl(conf, Location_hidden);
- else if (strcmp(tok[0], "left") == 0)
+ if (strcmp(tok[0], "left") == 0)
config_setl(conf, Location_left);
else if (strcmp(tok[0], "right") == 0)
config_setl(conf, Location_right);
+ else
+ goto inval;
} else if (tok[0]) {
config_sets(conf, str);
} else {
@@ -303,77 +303,86 @@ shrink:
}
static int
-config_nicklist_location(long num) {
- struct Config *nick = config_getp("nicklist.location");
- struct Config *buf = config_getp("buflist.location");
-
- if (num == buf->num != Location_hidden) {
- buf->num = (num == Location_left) ? Location_right : Location_left;
- if (windows[Win_buflist].location != Location_hidden)
- windows[Win_buflist].location = buf->num;
+config_window_hide(struct Config *conf, long num) {
+ enum Windows win;
+ enum WindowLocation loc = Location_hidden;
+ if (strcmp(conf->name, "buflist.hidden") == 0) {
+ win = Win_buflist;
+ if (!num)
+ loc = config_getl("buflist.location");
+ } else if (strcmp(conf->name, "nicklist.hidden") == 0) {
+ win = Win_nicklist;
+ if (!num)
+ loc = config_getl("nicklist.location");
}
- nick->num = windows[Win_nicklist].location = num;
+ windows[win].location = loc;
+ conf->isdef = 0;
ui_redraw();
- return 0;
+ return 1;
}
static int
-config_nicklist_width(long num) {
- if (num <= COLS - (windows[Win_buflist].location ? windows[Win_buflist].w : 0) - 2) {
- uineedredraw = 1;
- return 1;
- } else {
- ui_error("nicklist will be too big", NULL);
- return 0;
+config_window_location(struct Config *conf, long num) {
+ struct Config *otherloc, *otherhide;
+ enum WindowLocation win, otherwin;
+ if (strcmp(conf->name, "buflist.location") == 0) {
+ win = Win_buflist;
+ otherwin = Win_nicklist;
+ otherloc = config_getp("nicklist.location");
+ otherhide = config_getp("nicklist.hidden");
+ } else if (strcmp(conf->name, "nicklist.location") == 0) {
+ win = Win_nicklist;
+ otherwin = Win_buflist;
+ otherloc = config_getp("buflist.location");
+ otherhide = config_getp("buflist.hidden");
}
-}
-
-static int
-config_buflist_location(long num) {
- struct Config *buf = config_getp("buflist.location");
- struct Config *nick = config_getp("nicklist.location");
-
- if (num == nick->num != Location_hidden) {
- nick->num = (num == Location_left) ? Location_right : Location_left;
- if (windows[Win_nicklist].location != Location_hidden)
- windows[Win_nicklist].location = buf->num;
+ if (num == otherloc->num) {
+ otherloc->num = (num == Location_left) ? Location_right : Location_left;
+ otherloc->isdef = 0;
+ if (!otherhide->num)
+ windows[otherwin].location = otherloc->num;
}
- buf->num = windows[Win_buflist].location = num;
+ conf->num = windows[win].location = num;
+ conf->isdef = 0;
ui_redraw();
- return 0;
}
static int
-config_buflist_width(long num) {
- if (num <= COLS - (windows[Win_nicklist].location ? windows[Win_nicklist].w : 0) - 2) {
+config_window_width(struct Config *conf, long num) {
+ enum WindowLocation win;
+ if (strcmp(conf->name, "buflist.width") == 0)
+ win = Win_buflist;
+ else if (strcmp(conf->name, "nicklist.width") == 0)
+ win = Win_nicklist;
+ if (num <= COLS - (windows[win].location ? windows[win].w : 0) - 2) {
uineedredraw = 1;
return 1;
} else {
- ui_error("buflist will be too big", NULL);
+ ui_error("window will be too big", NULL);
return 0;
}
}
static int
-config_nickcolour_self(long num) {
+config_nickcolour_self(struct Config *conf, long num) {
windows[Win_nicklist].refresh = 1;
return 1;
}
static int
-config_nickcolour_range(long a, long b) {
+config_nickcolour_range(struct Config *conf, long a, long b) {
windows[Win_nicklist].refresh = 1;
return 1;
}
static int
-config_redraws(char *str) {
+config_redraws(struct Config *conf, char *str) {
ui_redraw();
return 1;
}
static int
-config_redrawl(long num) {
+config_redrawl(struct Config *conf, long num) {
ui_redraw();
return 1;
}
diff --git a/src/data/config.h b/src/data/config.h
@@ -120,26 +120,36 @@ struct Config config[] = {
"Must be 0, 99 or anywhere between. 99 is no colour",
"Giving a single value or two identical values will",
"use that colour only", NULL}},
+ {"nicklist.hidden", 1, Val_bool,
+ .num = 0,
+ .numhandle = config_window_hide,
+ .description = {
+ "Hide nicklist from view.", NULL}},
{"nicklist.location", 1, Val_location,
.num = Location_right,
- .numhandle = config_nicklist_location,
+ .numhandle = config_window_location,
.description = {
"Location of nicklist.",
- "Accepted values: hidden, left, right.", NULL}},
+ "Accepted values: left, right.", NULL}},
{"nicklist.width", 1, Val_nzunsigned,
.num = 15,
- .numhandle = config_nicklist_width,
+ .numhandle = config_window_width,
.description = {
"Number of columns nicklist will take up.", NULL}},
+ {"buflist.hidden", 1, Val_bool,
+ .num = 0,
+ .numhandle = config_window_hide,
+ .description = {
+ "Hide buflist from view.", NULL}},
{"buflist.location", 1, Val_location,
.num = Location_left,
- .numhandle = config_buflist_location,
+ .numhandle = config_window_location,
.description = {
"Location of buflist.",
- "Accepted values: hidden, left, right.", NULL}},
+ "Accepted values: left, right.", NULL}},
{"buflist.width", 1, Val_nzunsigned,
.num = 25,
- .numhandle = config_buflist_width,
+ .numhandle = config_window_width,
.description = {
"Number of columns buflist will take up.", NULL}},
{"misc.topiccolour", 1, Val_colourpair,
diff --git a/src/struct.h b/src/struct.h
@@ -240,9 +240,9 @@ struct Config {
char *str;
long num;
long pair[2];
- int (*strhandle)(char *string);
- int (*numhandle)(long num);
- int (*pairhandle)(long a, long b);
+ int (*strhandle)(struct Config *, char *);
+ int (*numhandle)(struct Config *, long);
+ int (*pairhandle)(struct Config *, long, long);
};
enum WindowLocation {
@@ -262,7 +262,7 @@ struct Window {
WINDOW *window;
};
-enum {
+enum Windows {
Win_dummy,
Win_main,
Win_nicklist,
diff --git a/src/ui.c b/src/ui.c
@@ -903,7 +903,7 @@ ui_select(struct Server *server, struct Channel *channel) {
selected.history->activity = Activity_none;
selected.history->unread = selected.history->ignored = 0;
- if (!selected.hasnicks)
+ if (!selected.hasnicks || config_getl("nicklist.hidden"))
windows[Win_nicklist].location = Location_hidden;
else
windows[Win_nicklist].location = config_getl("nicklist.location");