From: Matthew Mondor Date: Sat, 12 Aug 2023 05:37:08 +0000 (+0000) Subject: AnalogTerm2: Add clipboard text selection timeout, add timer.c X-Git-Url: http://git.pulsar-zone.net/?a=commitdiff_plain;h=d437658eac054fb559e3a9aa9c2cbd7a00d1821e;p=mmondor.git AnalogTerm2: Add clipboard text selection timeout, add timer.c --- diff --git a/mmsoftware/analogterm2/GNUmakefile b/mmsoftware/analogterm2/GNUmakefile index cf718f2..4c15cfb 100644 --- a/mmsoftware/analogterm2/GNUmakefile +++ b/mmsoftware/analogterm2/GNUmakefile @@ -31,7 +31,7 @@ CFLAGS += -DNDEBUG #LDFLAGS += -pg CHARS := src/font/*9.xbm -OBJS := $(addprefix src/,config.o main.o font.o utf8.o state.o xshm.o screen.o draw.o tty.o) +OBJS := $(addprefix src/,config.o timer.o main.o font.o utf8.o state.o xshm.o screen.o draw.o tty.o) BIN := analogterm2 FONTDIRS := fonts/* FONTS := fonts/*/*-ansi.txt.gz fonts/ibm-vio/*-ansi.txt.gz diff --git a/mmsoftware/analogterm2/TODO.txt b/mmsoftware/analogterm2/TODO.txt index 158c83d..cad5637 100644 --- a/mmsoftware/analogterm2/TODO.txt +++ b/mmsoftware/analogterm2/TODO.txt @@ -1,3 +1,6 @@ +- Maybe add a custom 4x6 font (5x7 with borders) +- Maybe integrate my old custom small fonts designed for a general shapes + custom editor and its GUI toolkit for early VGA. - There appear to be no terminal sequence to specify that numbers should use text figures (lowercase digits) and unicode points were not reserved for these, for an apparently absurd rationale. There however are codes to diff --git a/mmsoftware/analogterm2/src/config.c b/mmsoftware/analogterm2/src/config.c index 58ff1bd..20bb64d 100644 --- a/mmsoftware/analogterm2/src/config.c +++ b/mmsoftware/analogterm2/src/config.c @@ -73,6 +73,7 @@ int cfg_jumpscrolllines, cfg_smoothscrollskip; int cfg_font_width, cfg_font_height; int cfg_leading; int cfg_inputsleep, cfg_inputsleepskip; +int cfg_selecttimeout; bool cfg_uppercaseview; const char *cfg_recordfifo; @@ -127,6 +128,8 @@ cfg_setdefaults(void) cfg_inputsleep = INPUT_SLEEP; cfg_inputsleepskip = INPUT_SLEEP_SKIP; + cfg_selecttimeout = SELECT_TIMEOUT; + cfg_uppercaseview = UPPERCASE_VIEW; cfg_recordfifo = NULL; diff --git a/mmsoftware/analogterm2/src/config.h b/mmsoftware/analogterm2/src/config.h index 9c7efb1..ef79213 100644 --- a/mmsoftware/analogterm2/src/config.h +++ b/mmsoftware/analogterm2/src/config.h @@ -359,6 +359,16 @@ extern bool cfg_uppercaseview; /* + * Time in seconds before forgetting a user-selected copy-paste clipboard + * selection. This may prevent inadvertently pasting sensitive information if + * the selection was forgotten after use. + */ +#define SELECT_TIMEOUT 180 /* 3 minutes */ + +extern int cfg_selecttimeout; + + +/* * The XShm extention allows to accelerate graphics when the client is running * on the same system as the X11 server. */ diff --git a/mmsoftware/analogterm2/src/draw.c b/mmsoftware/analogterm2/src/draw.c index ce0f676..e1ca7c0 100644 --- a/mmsoftware/analogterm2/src/draw.c +++ b/mmsoftware/analogterm2/src/draw.c @@ -57,7 +57,6 @@ #include #include #include -#include #include #include @@ -88,7 +87,6 @@ static double color_lum[COLOR_MAX]; static void draw_cleanup(void); -static void alarm_sighandler(int); static inline uint32_t rgb32(uint8_t, uint8_t, uint8_t); static inline uint32_t icolor(double); static inline uint32_t acolor(double); @@ -106,7 +104,6 @@ static glyph_t **row_glyphs = NULL; static uint32_t *row_modes = NULL; static bool *row_selected = NULL; static int scanjmp = 0; -static int cursor_blink_ticks = 0, text_blink_ticks = 0; static uint8_t *empty = NULL; /* Recording */ @@ -118,13 +115,13 @@ bool draw_cursor_blink_state = true, draw_text_blink_state = true; bool refresh_expired = false; int jump_scroll_lines = 0; +int cursor_blink_ticks = 0, text_blink_ticks = 0; void draw_init(state_t *st, screen_t *sc) { struct sigaction act; - struct itimerval itv; int i; /* Fill color luminance table for monochrome mode */ @@ -156,22 +153,6 @@ draw_init(state_t *st, screen_t *sc) /* Scanline length, scanjmp */ scanjmp = screen->pixels_width; - /* Setup signal handler */ - act.sa_handler = alarm_sighandler; - act.sa_flags = SA_RESTART; - (void)sigemptyset(&act.sa_mask); - (void)sigaction(SIGALRM, &act, NULL); - - /* Setup interval timer */ - timerclear(&itv.it_interval); - timerclear(&itv.it_value); - itv.it_interval.tv_sec = 0; - itv.it_interval.tv_usec = cfg_refreshspeed; - itv.it_value.tv_sec = itv.it_interval.tv_sec; - itv.it_value.tv_usec = itv.it_interval.tv_usec; - if (setitimer(ITIMER_REAL, &itv, NULL) == -1) - goto err; - /* * Ignore SIGPIPE to not be killed when trying to write for recording */ @@ -201,54 +182,6 @@ draw_cleanup(void) free(empty); } -/* - * General timer, used to refresh the display, toggle the exported - * draw_*_blink_state, decrease tick timers, etc. - */ -static void -alarm_sighandler(int sig) -{ - int blinkspeed; - - if (sig != SIGALRM) - return; - - /* Flag expiration condition to trigger a refresh */ - refresh_expired = true; - - /* Smooth scrolling temporarily disables the cursor with a timer */ - if (state->cursor_disabled_ticks > 0) { - if (--state->cursor_disabled_ticks == 0) - draw_blink_reset(); - } - - /* Modulate the cursor blinking state */ - blinkspeed = (draw_cursor_blink_state ? - state->cursor_speed[state->cursor_mode][1] : - state->cursor_speed[state->cursor_mode][0]); - if (++cursor_blink_ticks == blinkspeed) { - cursor_blink_ticks = 0; - draw_cursor_blink_state = !draw_cursor_blink_state; - state->blink_update = true; - } - /* And the text blinking state */ - blinkspeed = (draw_text_blink_state ? - state->text_blink_speed_off : state->text_blink_speed_on); - if (++text_blink_ticks == blinkspeed) { - text_blink_ticks = 0; - draw_text_blink_state = !draw_text_blink_state; - state->blink_update = true; - } - if (!state->text_blink) - draw_text_blink_state = false; - - /* Emulation control sequence input timeout */ - if (estate_ticks > 0) { - if (--estate_ticks == 0) - estate_reset(); - } -} - void draw_blink_reset(void) { diff --git a/mmsoftware/analogterm2/src/draw.h b/mmsoftware/analogterm2/src/draw.h index 5d29b0c..eff29bc 100644 --- a/mmsoftware/analogterm2/src/draw.h +++ b/mmsoftware/analogterm2/src/draw.h @@ -70,7 +70,7 @@ void record_stop(void); /* Regularly toggled by a timer */ extern bool draw_cursor_blink_state, draw_text_blink_state, refresh_expired; -extern int jump_scroll_lines; +extern int jump_scroll_lines, cursor_blink_ticks, text_blink_ticks; #endif diff --git a/mmsoftware/analogterm2/src/main.c b/mmsoftware/analogterm2/src/main.c index ce3c54b..f0e6601 100644 --- a/mmsoftware/analogterm2/src/main.c +++ b/mmsoftware/analogterm2/src/main.c @@ -46,6 +46,7 @@ #include #include #include +#include #include #include @@ -587,6 +588,7 @@ endopt: if ((state = state_init(ttys->ptyfd)) == NULL) err(EXIT_FAILURE, "state_init()"); font_init(state, screen); + timer_init(state); draw_init(state, screen); /* diff --git a/mmsoftware/analogterm2/src/screen.c b/mmsoftware/analogterm2/src/screen.c index fb16842..d52dd41 100644 --- a/mmsoftware/analogterm2/src/screen.c +++ b/mmsoftware/analogterm2/src/screen.c @@ -142,6 +142,8 @@ static Time lastmotion = -1; static Atom atom_primary, atom_targets, atom_utf8_string, atom_string, atom_incr; +int screen_select_ticks = 0; + screen_t * screen_init(void) @@ -814,6 +816,11 @@ done: if (st->selected) XSetSelectionOwner(screen->dpy, atom_primary, screen->win, CurrentTime); + + /* Set expiry */ + if (cfg_selecttimeout > 0) + screen_select_ticks = cfg_selecttimeout * + (1000000 / cfg_refreshspeed); } void diff --git a/mmsoftware/analogterm2/src/screen.h b/mmsoftware/analogterm2/src/screen.h index 0af4215..ae22027 100644 --- a/mmsoftware/analogterm2/src/screen.h +++ b/mmsoftware/analogterm2/src/screen.h @@ -81,4 +81,7 @@ void screen_select_request(state_t *, XSelectionRequestEvent *); void screen_select_notify(state_t *, XSelectionEvent *); +extern int screen_select_ticks; + + #endif diff --git a/mmsoftware/analogterm2/src/timer.c b/mmsoftware/analogterm2/src/timer.c new file mode 100644 index 0000000..047e1be --- /dev/null +++ b/mmsoftware/analogterm2/src/timer.c @@ -0,0 +1,121 @@ +/* + * Copyright (c) 2022, 2023, Matthew Mondor + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY MATTHEW MONDOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL MATTHEW MONDOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include +#include +#include +#include + +#include +#include +#include + + +static void alarm_sighandler(int); + + +static state_t *state = NULL; + + +void +timer_init(state_t *st) +{ + struct sigaction act; + struct itimerval itv; + + state = st; + + /* Setup signal handler */ + act.sa_handler = alarm_sighandler; + act.sa_flags = SA_RESTART; + (void)sigemptyset(&act.sa_mask); + (void)sigaction(SIGALRM, &act, NULL); + + /* Setup interval timer */ + timerclear(&itv.it_interval); + timerclear(&itv.it_value); + itv.it_interval.tv_sec = 0; + itv.it_interval.tv_usec = cfg_refreshspeed; + itv.it_value.tv_sec = itv.it_interval.tv_sec; + itv.it_value.tv_usec = itv.it_interval.tv_usec; + if (setitimer(ITIMER_REAL, &itv, NULL) == -1) + err(EXIT_FAILURE, "timer_init() - setitimer()"); +} + +/* + * General timer, used to refresh the display, toggle the exported + * draw_*_blink_state, decrease tick timers, etc. + * XXX Maybe move to timer.c or main.c + */ +static void +alarm_sighandler(int sig) +{ + int blinkspeed; + + if (sig != SIGALRM) + return; + + /* Flag expiration condition to trigger a refresh */ + refresh_expired = true; + + /* Smooth scrolling temporarily disables the cursor with a timer */ + if (state->cursor_disabled_ticks > 0) { + if (--state->cursor_disabled_ticks == 0) + draw_blink_reset(); + } + + /* Modulate the cursor blinking state */ + blinkspeed = (draw_cursor_blink_state ? + state->cursor_speed[state->cursor_mode][1] : + state->cursor_speed[state->cursor_mode][0]); + if (++cursor_blink_ticks == blinkspeed) { + cursor_blink_ticks = 0; + draw_cursor_blink_state = !draw_cursor_blink_state; + state->blink_update = true; + } + /* And the text blinking state */ + blinkspeed = (draw_text_blink_state ? + state->text_blink_speed_off : state->text_blink_speed_on); + if (++text_blink_ticks == blinkspeed) { + text_blink_ticks = 0; + draw_text_blink_state = !draw_text_blink_state; + state->blink_update = true; + } + if (!state->text_blink) + draw_text_blink_state = false; + + /* Emulation control sequence input timeout */ + if (estate_ticks > 0) { + if (--estate_ticks == 0) + estate_reset(); + } + + /* Clipboard selection timeout */ + if (screen_select_ticks > 0) { + if (--screen_select_ticks == 0) + screen_select_clear(state); + } +} diff --git a/mmsoftware/analogterm2/src/timer.h b/mmsoftware/analogterm2/src/timer.h new file mode 100644 index 0000000..8c136b9 --- /dev/null +++ b/mmsoftware/analogterm2/src/timer.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2022, 2023, Matthew Mondor + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY MATTHEW MONDOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL MATTHEW MONDOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __ANALOGTERM_TIMER_H__ +#define __ANALOGTERM_TIMER_H__ + + +#include + + +void timer_init(state_t *); + + +#endif