AnalogTerm2:
authorMatthew Mondor <mmondor@pulsar-zone.net>
Wed, 26 Apr 2023 04:34:48 +0000 (04:34 +0000)
committerMatthew Mondor <mmondor@pulsar-zone.net>
Wed, 26 Apr 2023 04:34:48 +0000 (04:34 +0000)
- No longer enforce bright cursor when switching to block mode
  and reflect user configuration choice instead.
- Automatically set a reasonable fullscreen window if the
  dimensions are unspecified (-1).

mmsoftware/analogterm2/src/config.h
mmsoftware/analogterm2/src/main.c
mmsoftware/analogterm2/src/screen.c
mmsoftware/analogterm2/src/state.c

index a59ee1b..886c1e2 100644 (file)
@@ -189,18 +189,20 @@ extern bool cfg_condensed;
  * application output, a smaller terminal should help.
  * The terminal window may eventually be dynamically resizable but it
  * currently is not, for simplicity and performance.
+ * -1 Means that unless specified by the user, the window should be made to
+ * fit the parent window's dimensions automatically.
  */
 
 #if (CONDENSE_X == true)
-#define TEXT_WIDTH             176
+#define TEXT_WIDTH             -1
 #else
-#define TEXT_WIDTH             137
+#define TEXT_WIDTH             -1
 #endif
 
 #if (EXPAND_Y == true)
-#define TEXT_HEIGHT            40
+#define TEXT_HEIGHT            -1
 #else
-#define TEXT_HEIGHT            57
+#define TEXT_HEIGHT            -1
 #endif
 
 /* Close to 1920x1080 with 2x2 zoom.
index bb8d930..db8eb02 100644 (file)
@@ -480,6 +480,9 @@ endopt:
        if (!color_set)
                cfg_color = (cfg_mono ? DEFAULT_MONOCOLOR : DEFAULT_COLOR);
 
+       if ((screen = screen_init()) == NULL)
+               err(EXIT_FAILURE, "screen_init()");
+
        winsize.ws_row = cfg_text_height;
        winsize.ws_col = cfg_text_width;
        /* XXX Should we set these? */
@@ -494,8 +497,6 @@ endopt:
 #endif
        ttys = tty_shell(envp, &winsize, command);
 
-       if ((screen = screen_init()) == NULL)
-               err(EXIT_FAILURE, "screen_init()");
        if ((state = state_init(ttys->ptyfd)) == NULL)
                err(EXIT_FAILURE, "state_init()");
        font_init(state, screen);
index 2231555..b95d16a 100644 (file)
@@ -146,6 +146,7 @@ screen_t *
 screen_init(void)
 {
        screen_t *s;
+       XWindowAttributes wattr;
        int depth, width, height;
 
        if ((s = malloc(sizeof(screen_t))) == NULL) {
@@ -170,6 +171,19 @@ screen_init(void)
        s->visual = s->vinfo.visual;
        depth = s->vinfo.depth;
 
+       /*
+        * If cfg_text_width or cfg_text_height are -1 set them to a large
+        * size but that likely fit in the visual port.
+        */
+       if (XGetWindowAttributes(s->dpy, s->parentwin, &wattr) == 0)
+               err(EXIT_FAILURE, "XGetWindowAttributes()");
+       if (cfg_text_width == -1)
+               cfg_text_width = ((wattr.width - wattr.border_width) /
+                   (FONT_WIDTH * (cfg_condensed ? 1.5 : 2)) - 6);
+       if (cfg_text_height == -1)
+               cfg_text_height = (wattr.height /
+                   ((FONT_HEIGHT + cfg_leading) * 2) - 3);
+
        /* Font rendered with 2x/1.5x software zoom */
        if (cfg_condensed)
                width = ((int)((cfg_text_width * FONT_WIDTH) * 1.5)) + 1;
index 8050cde..9b38a86 100644 (file)
@@ -1589,7 +1589,7 @@ endh:
                                        st->cursor_mode = CMODE_BLOCK;
                                        if (cfg_cursorblink)
                                                st->cursor_blink = true;
-                                       st->cursor_bright = true; /* XXX */
+                                       st->cursor_bright = cfg_cursorbright;
                                        break;
                                case 2:
                                        st->cursor_mode = CMODE_BLOCK;