#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
+- 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
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;
cfg_inputsleep = INPUT_SLEEP;
cfg_inputsleepskip = INPUT_SLEEP_SKIP;
+ cfg_selecttimeout = SELECT_TIMEOUT;
+
cfg_uppercaseview = UPPERCASE_VIEW;
cfg_recordfifo = NULL;
/*
+ * 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.
*/
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
-#include <sys/time.h>
#include <unistd.h>
#include <state.h>
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);
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 */
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 */
/* 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
*/
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)
{
/* 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
#include <screen.h>
#include <state.h>
#include <font.h>
+#include <timer.h>
#include <draw.h>
#include <tty.h>
if ((state = state_init(ttys->ptyfd)) == NULL)
err(EXIT_FAILURE, "state_init()");
font_init(state, screen);
+ timer_init(state);
draw_init(state, screen);
/*
static Atom atom_primary, atom_targets, atom_utf8_string,
atom_string, atom_incr;
+int screen_select_ticks = 0;
+
screen_t *
screen_init(void)
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
void screen_select_notify(state_t *, XSelectionEvent *);
+extern int screen_select_ticks;
+
+
#endif
--- /dev/null
+/*
+ * 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 <err.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <sys/time.h>
+
+#include <config.h>
+#include <screen.h>
+#include <draw.h>
+
+
+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);
+ }
+}
--- /dev/null
+/*
+ * 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 <state.h>
+
+
+void timer_init(state_t *);
+
+
+#endif