From cc4c8e6e9f41bc07cb3047e4ecc52ccfeaac0c75 Mon Sep 17 00:00:00 2001 From: "Basil L. Contovounesios" Date: Wed, 18 Mar 2026 12:16:37 +0100 Subject: [PATCH] Simplify some struct frame.output_method checks * src/lisp.h (inhibit_window_system): Fix typo in commentary. * src/dispnew.c (Fopen_termscript): (init_display_interactive) [!HAVE_ANDROID, !MSDOS]: * src/dosfns.c [MSDOS] (dos_cleanup): * src/frame.c (frame_inhibit_resize, frame_windows_min_size) (do_switch_frame, delete_frame): (make_terminal_frame) [MSDOS]: (Fmake_terminal_frame) [MSDOS, WINDOWSNT]: * src/keyboard.c (read_decoded_event_from_main_queue) [!WINDOWSNT]: (Fcurrent_input_mode): * src/menu.c (single_menu_item): * src/msdos.c [MSDOS] (internal_terminal_init): * src/sysdep.c (init_sys_modes): * src/term.c: [HAVE_GPM] (Fgpm_mouse_start, Fgpm_mouse_stop): [MSDOS] (tty_free_frame_resources): * src/w32xfns.c (get_frame_dc): * src/xdisp.c (clear_garbaged_frames, hscroll_window_tree) (redisplay_internal): * src/xfaces.c (Fdisplay_supports_face_attributes_p) (realize_default_face, realize_face, realize_tty_face): Use is_tty_frame, FRAME_INITIAL_P, FRAME_MSDOS_P, FRAME_TERMCAP_P, FRAME_W32_P, and FRAME_TTY as appropriate instead of open-coding them (bug#80629). --- src/dispnew.c | 7 +++---- src/dosfns.c | 3 +-- src/frame.c | 15 +++++++-------- src/keyboard.c | 4 ++-- src/lisp.h | 2 +- src/menu.c | 3 +-- src/msdos.c | 2 +- src/sysdep.c | 3 +-- src/term.c | 10 +++------- src/w32xfns.c | 2 +- src/xdisp.c | 14 +++++--------- src/xfaces.c | 10 +++++----- 12 files changed, 31 insertions(+), 44 deletions(-) diff --git a/src/dispnew.c b/src/dispnew.c index 908345645bc..736647408cb 100644 --- a/src/dispnew.c +++ b/src/dispnew.c @@ -6776,8 +6776,7 @@ FILE = nil means just close any termscript file currently open. */) { struct tty_display_info *tty; - if (! FRAME_TERMCAP_P (SELECTED_FRAME ()) - && ! FRAME_MSDOS_P (SELECTED_FRAME ())) + if (!is_tty_frame (SELECTED_FRAME ())) error ("Current frame is not on a tty device"); tty = CURTTY (); @@ -7344,7 +7343,7 @@ init_display_interactive (void) t = init_tty (0, terminal_type, 1); /* Errors are fatal. */ /* Convert the initial frame to use the new display. */ - if (f->output_method != output_initial) + if (!FRAME_INITIAL_P (f)) emacs_abort (); f->output_method = t->type; f->terminal = t; @@ -7354,7 +7353,7 @@ init_display_interactive (void) f->output_data.tty = &the_only_tty_output; f->output_data.tty->display_info = &the_only_display_info; #else - if (f->output_method == output_termcap) + if (FRAME_TERMCAP_P (f)) create_tty_output (f); #endif t->display_info.tty->top_frame = selected_frame; diff --git a/src/dosfns.c b/src/dosfns.c index 414cc550510..07d553b0d78 100644 --- a/src/dosfns.c +++ b/src/dosfns.c @@ -681,8 +681,7 @@ dos_cleanup (void) { struct frame *sf = XFRAME (selected_frame); - if (FRAME_LIVE_P (sf) - && (FRAME_MSDOS_P (sf) || FRAME_TERMCAP_P (sf))) + if (FRAME_LIVE_P (sf) && is_tty_frame (sf)) { tty = CURTTY (); if (tty->termscript) diff --git a/src/frame.c b/src/frame.c index 89ea58b3fe2..2e98937fab3 100644 --- a/src/frame.c +++ b/src/frame.c @@ -213,7 +213,7 @@ frame_inhibit_resize (struct frame *f, bool horizontal, Lisp_Object parameter) && !NILP (fullscreen) && !EQ (fullscreen, Qfullheight)) || (!horizontal && !NILP (fullscreen) && !EQ (fullscreen, Qfullwidth)) - || FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f)))); + || is_tty_frame (f)))); } @@ -561,7 +561,7 @@ frame_windows_min_size (Lisp_Object frame, Lisp_Object horizontal, /* Don't allow too small height of text-mode frames, or else cm.c might abort in cmcheckmagic. */ - if ((FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f)) && NILP (horizontal)) + if (is_tty_frame (f) && NILP (horizontal)) { int min_height = (FRAME_MENU_BAR_LINES (f) + FRAME_TAB_BAR_LINES (f) + FRAME_WANTS_MODELINE_P (f) @@ -1572,7 +1572,7 @@ make_terminal_frame (struct terminal *terminal, Lisp_Object parent, f->output_data.tty->display_info = &the_only_display_info; if (!inhibit_window_system && (!FRAMEP (selected_frame) || !FRAME_LIVE_P (XFRAME (selected_frame)) - || XFRAME (selected_frame)->output_method == output_msdos_raw)) + || FRAME_MSDOS_P (XFRAME (selected_frame)))) f->output_method = output_msdos_raw; else f->output_method = output_termcap; @@ -1762,13 +1762,12 @@ affects all frames on the same terminal device. */) struct frame *sf = SELECTED_FRAME (); #ifdef MSDOS - if (sf->output_method != output_msdos_raw - && sf->output_method != output_termcap) + if (!is_tty_frame (sf)) emacs_abort (); #else /* not MSDOS */ #ifdef WINDOWSNT /* This should work now! */ - if (sf->output_method != output_termcap) + if (!FRAME_TERMCAP_P (sf)) error ("Not using an ASCII terminal now; cannot make a new ASCII frame"); #endif #endif /* not MSDOS */ @@ -1985,7 +1984,7 @@ do_switch_frame (Lisp_Object frame, int track, int for_deletion, Lisp_Object nor if (!for_deletion && FRAME_HAS_MINIBUF_P (sf)) resize_mini_window (XWINDOW (FRAME_MINIBUF_WINDOW (sf)), 1); - if (FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f)) + if (is_tty_frame (f)) { struct tty_display_info *tty = FRAME_TTY (f); Lisp_Object top_frame = tty->top_frame; @@ -2799,7 +2798,7 @@ delete_frame (Lisp_Object frame, Lisp_Object force) && FRAME_LIVE_P (f1) && !FRAME_TOOLTIP_P (f1)) { - if (FRAME_TERMCAP_P (f1) || FRAME_MSDOS_P (f1)) + if (is_tty_frame (f1)) { Lisp_Object top_frame = FRAME_TTY (f1)->top_frame; diff --git a/src/keyboard.c b/src/keyboard.c index c16cc5277e9..c64b2a6dd57 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -2436,7 +2436,7 @@ read_decoded_event_from_main_queue (struct timespec *end_time, #else struct frame *frame = XFRAME (selected_frame); struct terminal *terminal = frame->terminal; - if (!((FRAME_TERMCAP_P (frame) || FRAME_MSDOS_P (frame)) + if (!(is_tty_frame (frame) /* Don't apply decoding if we're just reading a raw event (e.g. reading bytes sent by the xterm to specify the position of a mouse click). */ @@ -12982,7 +12982,7 @@ The elements of this list correspond to the arguments of Lisp_Object interrupt = interrupt_input ? Qt : Qnil; Lisp_Object flow, meta; - if (FRAME_TERMCAP_P (sf) || FRAME_MSDOS_P (sf)) + if (is_tty_frame (sf)) { flow = FRAME_TTY (sf)->flow_control ? Qt : Qnil; meta = (FRAME_TTY (sf)->meta_key == 2 diff --git a/src/lisp.h b/src/lisp.h index cbd61126a74..223eb4df564 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -5166,7 +5166,7 @@ extern void *w32_daemon_event; /* True if handling a fatal error already. */ extern bool fatal_error_in_progress; -/* True means don't do use window-system-specific display code. */ +/* True means don't use window-system-specific display code. */ extern bool inhibit_window_system; /* True means that a filter or a sentinel is running. */ extern bool running_asynch_code; diff --git a/src/menu.c b/src/menu.c index 69fd3867002..ff4721d35f7 100644 --- a/src/menu.c +++ b/src/menu.c @@ -404,8 +404,7 @@ single_menu_item (Lisp_Object key, Lisp_Object item, Lisp_Object dummy, void *sk } } - if ((FRAME_TERMCAP_P (XFRAME (Vmenu_updating_frame)) - || FRAME_MSDOS_P (XFRAME (Vmenu_updating_frame))) + if (is_tty_frame (XFRAME (Vmenu_updating_frame)) && !NILP (map)) /* Indicate visually that this is a submenu. */ { diff --git a/src/msdos.c b/src/msdos.c index 7e89d549706..4d111b30969 100644 --- a/src/msdos.c +++ b/src/msdos.c @@ -1787,7 +1787,7 @@ internal_terminal_init (void) #endif /* If this is the initial terminal, we are done here. */ - if (sf->output_method == output_initial) + if (FRAME_INITIAL_P (sf)) return; internal_terminal diff --git a/src/sysdep.c b/src/sysdep.c index 8895655566e..10269e4d0ce 100644 --- a/src/sysdep.c +++ b/src/sysdep.c @@ -1341,8 +1341,7 @@ init_sys_modes (struct tty_display_info *tty_out) frame_garbaged = 1; FOR_EACH_FRAME (tail, frame) { - if ((FRAME_TERMCAP_P (XFRAME (frame)) - || FRAME_MSDOS_P (XFRAME (frame))) + if (is_tty_frame (XFRAME (frame)) && FRAME_TTY (XFRAME (frame)) == tty_out) FRAME_GARBAGED_P (XFRAME (frame)) = 1; } diff --git a/src/term.c b/src/term.c index 1d1fc05ac41..b5cf418450f 100644 --- a/src/term.c +++ b/src/term.c @@ -2968,9 +2968,7 @@ Gpm-mouse can only be activated for one tty at a time. */) (void) { struct frame *f = SELECTED_FRAME (); - struct tty_display_info *tty - = ((f)->output_method == output_termcap - ? (f)->terminal->display_info.tty : NULL); + struct tty_display_info *tty = FRAME_TERMCAP_P (f) ? FRAME_TTY (f) : NULL; Gpm_Connect connection; if (!tty) @@ -3016,9 +3014,7 @@ DEFUN ("gpm-mouse-stop", Fgpm_mouse_stop, Sgpm_mouse_stop, (void) { struct frame *f = SELECTED_FRAME (); - struct tty_display_info *tty - = ((f)->output_method == output_termcap - ? (f)->terminal->display_info.tty : NULL); + struct tty_display_info *tty = FRAME_TERMCAP_P (f) ? FRAME_TTY (f) : NULL; if (!tty || gpm_tty != tty) return Qnil; /* Not activated on this terminal, nothing to do. */ @@ -4198,7 +4194,7 @@ tty_free_frame_resources (struct frame *f) static void tty_free_frame_resources (struct frame *f) { - eassert (FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f)); + eassert (is_tty_frame (f)); free_frame_faces (f); /* Deleting a child frame means we have to thoroughly redisplay its root frame to make sure the child disappears from the display. */ diff --git a/src/w32xfns.c b/src/w32xfns.c index f920e407343..df3d42c9d28 100644 --- a/src/w32xfns.c +++ b/src/w32xfns.c @@ -177,7 +177,7 @@ get_frame_dc (struct frame *f) HGDIOBJ obj; struct w32_output *output; - if (f->output_method != output_w32) + if (!FRAME_W32_P (f)) emacs_abort (); enter_crit (); diff --git a/src/xdisp.c b/src/xdisp.c index 8af54ad49f1..179c1bae72b 100644 --- a/src/xdisp.c +++ b/src/xdisp.c @@ -13651,7 +13651,7 @@ clear_garbaged_frames (void) selected frame, and might leave the selected frame with corrupted display, if it happens not to be marked garbaged. */ - && !(f != sf && (FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f)))) + && !(f != sf && is_tty_frame (f))) redraw_frame (f); else clear_current_matrices (f); @@ -16639,11 +16639,8 @@ hscroll_window_tree (Lisp_Object window) } } if (cursor_row->truncated_on_left_p) - { - /* On TTY frames, don't count the left truncation glyph. */ - struct frame *f = XFRAME (WINDOW_FRAME (w)); - x_offset -= (FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f)); - } + /* On TTY frames, don't count the left truncation glyph. */ + x_offset -= is_tty_frame (XFRAME (WINDOW_FRAME (w))); text_area_width = window_box_width (w, TEXT_AREA); @@ -17377,7 +17374,7 @@ redisplay_internal (void) windows_or_buffers_changed = 47; struct frame *previous_frame; - if ((FRAME_TERMCAP_P (sf) || FRAME_MSDOS_P (sf)) + if (is_tty_frame (sf) && (previous_frame = FRAME_TTY (sf)->previous_frame, previous_frame != sf)) { @@ -17822,8 +17819,7 @@ redisplay_internal (void) } retry_frame: - if (FRAME_WINDOW_P (f) - || FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f) || f == sf) + if (FRAME_WINDOW_P (f) || is_tty_frame (f) || f == sf) { /* Only GC scrollbars when we redisplay the whole frame. */ bool gcscrollbars = f->redisplay || !REDISPLAY_SOME_P (); diff --git a/src/xfaces.c b/src/xfaces.c index a27e1c6b480..ab0934abde2 100644 --- a/src/xfaces.c +++ b/src/xfaces.c @@ -5776,7 +5776,7 @@ face for italic. */) } /* Dispatch to the appropriate handler. */ - if (FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f)) + if (is_tty_frame (f)) supports = tty_supports_face_attributes_p (f, attrs, def_face); #ifdef HAVE_WINDOW_SYSTEM else @@ -6070,7 +6070,7 @@ realize_default_face (struct frame *f) ASET (lface, LFACE_FOREGROUND_INDEX, XCDR (color)); else if (FRAME_WINDOW_P (f)) return false; - else if (FRAME_INITIAL_P (f) || FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f)) + else if (FRAME_INITIAL_P (f) || is_tty_frame (f)) ASET (lface, LFACE_FOREGROUND_INDEX, build_string (unspecified_fg)); else emacs_abort (); @@ -6085,7 +6085,7 @@ realize_default_face (struct frame *f) ASET (lface, LFACE_BACKGROUND_INDEX, XCDR (color)); else if (FRAME_WINDOW_P (f)) return false; - else if (FRAME_INITIAL_P (f) || FRAME_TERMCAP_P (f) || FRAME_MSDOS_P (f)) + else if (FRAME_INITIAL_P (f) || is_tty_frame (f)) ASET (lface, LFACE_BACKGROUND_INDEX, build_string (unspecified_bg)); else emacs_abort (); @@ -6196,7 +6196,7 @@ realize_face (struct face_cache *cache, Lisp_Object attrs[LFACE_VECTOR_SIZE], if (FRAME_WINDOW_P (cache->f)) face = realize_gui_face (cache, attrs); - else if (FRAME_TERMCAP_P (cache->f) || FRAME_MSDOS_P (cache->f)) + else if (is_tty_frame (cache->f)) face = realize_tty_face (cache, attrs); else if (FRAME_INITIAL_P (cache->f)) { @@ -6705,7 +6705,7 @@ realize_tty_face (struct face_cache *cache, struct frame *f = cache->f; /* Frame must be a termcap frame. */ - eassert (FRAME_TERMCAP_P (cache->f) || FRAME_MSDOS_P (cache->f)); + eassert (is_tty_frame (cache->f)); /* Allocate a new realized face. */ face = make_realized_face (attrs);