Record whether the width or height were set manually, and refrain from changing a manually set value when the terminal size changes.
This commit is contained in:
@@ -53,6 +53,8 @@ struct opts_s { /* structure describing run-time options */
|
||||
unsigned int average_rate_window; /* time window in seconds for average rate calculations */
|
||||
unsigned int width; /* screen width */
|
||||
unsigned int height; /* screen height */
|
||||
bool width_set_manually; /* width was set manually, not detected */
|
||||
bool height_set_manually; /* height was set manually, not detected */
|
||||
/*@keep@*/ /*@null@*/ char *name; /* display name, if any */
|
||||
/*@keep@*/ /*@null@*/ char *format; /* output format, if any */
|
||||
/*@keep@*/ /*@null@*/ char *pidfile; /* PID file, if any */
|
||||
|
||||
@@ -107,6 +107,8 @@ struct pvstate_s {
|
||||
int watch_fd; /* fd to watch */
|
||||
unsigned int width; /* screen width */
|
||||
unsigned int height; /* screen height */
|
||||
bool width_set_manually; /* width was set manually, not detected */
|
||||
bool height_set_manually; /* height was set manually, not detected */
|
||||
/*@null@*/ char *name; /* display name */
|
||||
char default_format[PV_SIZEOF_DEFAULT_FORMAT]; /* default format string */
|
||||
char *format_string; /* output format string */
|
||||
|
||||
+2
-2
@@ -119,8 +119,8 @@ extern void pv_state_no_splice_set(pvstate_t, bool);
|
||||
extern void pv_state_discard_input_set(pvstate_t, bool);
|
||||
extern void pv_state_size_set(pvstate_t, unsigned long long);
|
||||
extern void pv_state_interval_set(pvstate_t, double);
|
||||
extern void pv_state_width_set(pvstate_t, unsigned int);
|
||||
extern void pv_state_height_set(pvstate_t, unsigned int);
|
||||
extern void pv_state_width_set(pvstate_t, unsigned int, bool);
|
||||
extern void pv_state_height_set(pvstate_t, unsigned int, bool);
|
||||
extern void pv_state_name_set(pvstate_t, /*@null@*/ const char *);
|
||||
extern void pv_state_format_string_set(pvstate_t, /*@null@*/ const char *);
|
||||
extern void pv_state_watch_pid_set(pvstate_t, unsigned int);
|
||||
|
||||
+2
-2
@@ -258,8 +258,8 @@ int main(int argc, char **argv)
|
||||
* Copy parameters from options into main state.
|
||||
*/
|
||||
pv_state_interval_set(state, opts->interval);
|
||||
pv_state_width_set(state, opts->width);
|
||||
pv_state_height_set(state, opts->height);
|
||||
pv_state_width_set(state, opts->width, opts->width_set_manually);
|
||||
pv_state_height_set(state, opts->height, opts->height_set_manually);
|
||||
pv_state_no_display_set(state, opts->no_display);
|
||||
pv_state_force_set(state, opts->force);
|
||||
pv_state_cursor_set(state, opts->cursor);
|
||||
|
||||
@@ -238,6 +238,9 @@ opts_t opts_parse(unsigned int argc, char **argv)
|
||||
opts->watch_fd = -1;
|
||||
opts->average_rate_window = 30;
|
||||
|
||||
opts->width_set_manually = false;
|
||||
opts->height_set_manually = false;
|
||||
|
||||
do {
|
||||
#ifdef HAVE_GETOPT_LONG
|
||||
c = getopt_long((int) argc, argv, short_options, long_options, &option_index); /* flawfinder: ignore */
|
||||
@@ -431,9 +434,11 @@ opts_t opts_parse(unsigned int argc, char **argv)
|
||||
break;
|
||||
case 'w':
|
||||
opts->width = pv_getnum_ui(optarg);
|
||||
opts->width_set_manually = opts->width == 0 ? false : true;
|
||||
break;
|
||||
case 'H':
|
||||
opts->height = pv_getnum_ui(optarg);
|
||||
opts->height_set_manually = opts->height == 0 ? false : true;
|
||||
break;
|
||||
case 'N':
|
||||
opts->name = xstrdup(optarg);
|
||||
|
||||
+8
-4
@@ -42,6 +42,8 @@ struct remote_msg {
|
||||
double interval; /* interval between updates */
|
||||
unsigned int width; /* screen width */
|
||||
unsigned int height; /* screen height */
|
||||
bool width_set_manually; /* width was set manually, not detected */
|
||||
bool height_set_manually; /* height was set manually, not detected */
|
||||
char name[256]; /* flawfinder: ignore */
|
||||
char format[256]; /* flawfinder: ignore */
|
||||
};
|
||||
@@ -151,6 +153,8 @@ int pv_remote_set(opts_t opts)
|
||||
msgbuf.interval = opts->interval;
|
||||
msgbuf.width = opts->width;
|
||||
msgbuf.height = opts->height;
|
||||
msgbuf.width_set_manually = opts->width_set_manually;
|
||||
msgbuf.height_set_manually = opts->height_set_manually;
|
||||
|
||||
if (opts->name != NULL) {
|
||||
strncpy(msgbuf.name, opts->name, sizeof(msgbuf.name) - 1); /* flawfinder: ignore */
|
||||
@@ -295,10 +299,10 @@ void pv_remote_check(pvstate_t state)
|
||||
pv_state_size_set(state, msgbuf.size);
|
||||
if (msgbuf.interval > 0)
|
||||
pv_state_interval_set(state, msgbuf.interval);
|
||||
if (msgbuf.width > 0)
|
||||
pv_state_width_set(state, msgbuf.width);
|
||||
if (msgbuf.height > 0)
|
||||
pv_state_height_set(state, msgbuf.height);
|
||||
if (msgbuf.width > 0 && msgbuf.width_set_manually)
|
||||
pv_state_width_set(state, msgbuf.width, msgbuf.width_set_manually);
|
||||
if (msgbuf.height > 0 && msgbuf.height_set_manually)
|
||||
pv_state_height_set(state, msgbuf.height, msgbuf.height_set_manually);
|
||||
if (msgbuf.format[0] != '\0')
|
||||
pv_state_format_string_set(state, msgbuf.format);
|
||||
}
|
||||
|
||||
+22
-2
@@ -321,8 +321,18 @@ int pv_main_loop(pvstate_t state)
|
||||
since_last = -1;
|
||||
|
||||
if (state->pv_sig_newsize) {
|
||||
unsigned int new_width, new_height;
|
||||
|
||||
state->pv_sig_newsize = 0;
|
||||
pv_screensize(&(state->width), &(state->height));
|
||||
|
||||
new_width = state->width;
|
||||
new_height = state->height;
|
||||
pv_screensize(&new_width, &new_height);
|
||||
|
||||
if (!state->width_set_manually)
|
||||
state->width = new_width;
|
||||
if (!state->height_set_manually)
|
||||
state->height = new_height;
|
||||
}
|
||||
|
||||
pv_display(state, elapsed, since_last, total_written);
|
||||
@@ -475,8 +485,18 @@ int pv_watchfd_loop(pvstate_t state)
|
||||
since_last = -1;
|
||||
|
||||
if (state->pv_sig_newsize) {
|
||||
unsigned int new_width, new_height;
|
||||
|
||||
state->pv_sig_newsize = 0;
|
||||
pv_screensize(&(state->width), &(state->height));
|
||||
|
||||
new_width = state->width;
|
||||
new_height = state->height;
|
||||
pv_screensize(&new_width, &new_height);
|
||||
|
||||
if (!state->width_set_manually)
|
||||
state->width = new_width;
|
||||
if (!state->height_set_manually)
|
||||
state->height = new_height;
|
||||
}
|
||||
|
||||
pv_display(state, elapsed, since_last, total_written);
|
||||
|
||||
+4
-2
@@ -253,14 +253,16 @@ void pv_state_interval_set(pvstate_t state, double val)
|
||||
state->interval = val;
|
||||
};
|
||||
|
||||
void pv_state_width_set(pvstate_t state, unsigned int val)
|
||||
void pv_state_width_set(pvstate_t state, unsigned int val, bool was_set_manually)
|
||||
{
|
||||
state->width = val;
|
||||
state->width_set_manually = was_set_manually;
|
||||
};
|
||||
|
||||
void pv_state_height_set(pvstate_t state, unsigned int val)
|
||||
void pv_state_height_set(pvstate_t state, unsigned int val, bool was_set_manually)
|
||||
{
|
||||
state->height = val;
|
||||
state->height_set_manually = was_set_manually;
|
||||
};
|
||||
|
||||
void pv_state_name_set(pvstate_t state, /*@null@ */ const char *val)
|
||||
|
||||
Reference in New Issue
Block a user