unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Renaming non-X x_* procedures in xdisp.c (and elsewhere)
@ 2019-03-23 15:07 Alex
  2019-03-23 15:38 ` Stefan Monnier
  2019-03-23 16:10 ` Eli Zaretskii
  0 siblings, 2 replies; 68+ messages in thread
From: Alex @ 2019-03-23 15:07 UTC (permalink / raw)
  To: emacs-devel

It would be helpful to determine at a glance whether or not a procedure
is generic or depends on X support. I'm guessing that this naming scheme
is a historical artifact from when graphical support meant X support,
but I believe that it is more confusing than it is worth at this point.

For example, x_write_glyphs could become disp_write_glyphs.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Renaming non-X x_* procedures in xdisp.c (and elsewhere)
  2019-03-23 15:07 Renaming non-X x_* procedures in xdisp.c (and elsewhere) Alex
@ 2019-03-23 15:38 ` Stefan Monnier
  2019-03-23 16:10 ` Eli Zaretskii
  1 sibling, 0 replies; 68+ messages in thread
From: Stefan Monnier @ 2019-03-23 15:38 UTC (permalink / raw)
  To: emacs-devel

> It would be helpful to determine at a glance whether or not a procedure
> is generic or depends on X support. I'm guessing that this naming scheme
> is a historical artifact from when graphical support meant X support,
> but I believe that it is more confusing than it is worth at this point.

That's right.

> For example, x_write_glyphs could become disp_write_glyphs.

Along similar lines, it would be nice to make sure that the "x_" prefix
is only used for X11 support, so that there's no name clashes between
the W32, X11, and NS backends, opening up the possibility to add the
ability to support several of those backends at the same time (e.g. so
the W32 and macOS builds could also use a remote X11 display).


        Stefan




^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Renaming non-X x_* procedures in xdisp.c (and elsewhere)
  2019-03-23 15:07 Renaming non-X x_* procedures in xdisp.c (and elsewhere) Alex
  2019-03-23 15:38 ` Stefan Monnier
@ 2019-03-23 16:10 ` Eli Zaretskii
  2019-03-23 16:41   ` Paul Eggert
  1 sibling, 1 reply; 68+ messages in thread
From: Eli Zaretskii @ 2019-03-23 16:10 UTC (permalink / raw)
  To: Alex; +Cc: emacs-devel

> From: Alex <agrambot@gmail.com>
> Date: Sat, 23 Mar 2019 09:07:04 -0600
> 
> It would be helpful to determine at a glance whether or not a procedure
> is generic or depends on X support.

As a rule of thumb that is 99% true, everything in xdisp.c is generic,
i.e. independent of the terminal-specific implementation.  The
terminal-dependent stuff is in xterm.c/xfns.c (for X),
w32term.c/w32fns.c (for w32), nsterm.m/nsfns.m (for NS), and term.c
(for TTY).

> I'm guessing that this naming scheme is a historical artifact from
> when graphical support meant X support, but I believe that it is
> more confusing than it is worth at this point.
> 
> For example, x_write_glyphs could become disp_write_glyphs.

The correct name would be something like gui_write_glyphs, since
there's tty_write_glyphs in term.c.  Although I personally fail to see
how such renaming will help anyone or anything.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Renaming non-X x_* procedures in xdisp.c (and elsewhere)
  2019-03-23 16:10 ` Eli Zaretskii
@ 2019-03-23 16:41   ` Paul Eggert
  2019-03-23 16:59     ` Eli Zaretskii
  0 siblings, 1 reply; 68+ messages in thread
From: Paul Eggert @ 2019-03-23 16:41 UTC (permalink / raw)
  To: Eli Zaretskii, Alex; +Cc: emacs-devel

Eli Zaretskii wrote:
> The correct name would be something like gui_write_glyphs, since
> there's tty_write_glyphs in term.c.  Although I personally fail to see
> how such renaming will help anyone or anything.

Renaming would make the code clearer now, and would benefit those unfamiliar 
with the code (or at least to this part of the code -- and I put myself in this 
category as I'm often confused by the non-X x_* names). However, renaming would 
also make software archaeology more difficult.  When weighing benefit vs cost, 
it partly depends on how forward-looking we want to be.

I would favor renaming, though I also see the benefits of leaving things alone.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Renaming non-X x_* procedures in xdisp.c (and elsewhere)
  2019-03-23 16:41   ` Paul Eggert
@ 2019-03-23 16:59     ` Eli Zaretskii
  2019-03-23 17:39       ` Alex
  2019-03-24  4:50       ` Alex
  0 siblings, 2 replies; 68+ messages in thread
From: Eli Zaretskii @ 2019-03-23 16:59 UTC (permalink / raw)
  To: Paul Eggert; +Cc: agrambot, emacs-devel

> Cc: emacs-devel@gnu.org
> From: Paul Eggert <eggert@cs.ucla.edu>
> Date: Sat, 23 Mar 2019 09:41:42 -0700
> 
> Renaming would make the code clearer now, and would benefit those unfamiliar 
> with the code (or at least to this part of the code -- and I put myself in this 
> category as I'm often confused by the non-X x_* names). However, renaming would 
> also make software archaeology more difficult.  When weighing benefit vs cost, 
> it partly depends on how forward-looking we want to be.
> 
> I would favor renaming, though I also see the benefits of leaving things alone.

I don't have strong opinions about this.  Aside of making the
archeology and forensics harder, renaming will get in the way of my
personal acquaintance with the code in xdisp.c and dispnew.c, but that
alone doesn't sound like a reason to object to the change.  It will
probably also require a lot more ugly #ifdef's in the mainline code
(or calling through function pointers, not sure which is worse), and
quite a few changes in the headers to go with that.

The original long-term plan, to remind us, was not just to rename the
functions, but also to extract the common code from them so that we
have only one copy of that.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Renaming non-X x_* procedures in xdisp.c (and elsewhere)
  2019-03-23 16:59     ` Eli Zaretskii
@ 2019-03-23 17:39       ` Alex
  2019-03-23 17:54         ` Alex
  2019-03-23 18:16         ` Eli Zaretskii
  2019-03-24  4:50       ` Alex
  1 sibling, 2 replies; 68+ messages in thread
From: Alex @ 2019-03-23 17:39 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Paul Eggert, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 1325 bytes --]

Eli Zaretskii <eliz@gnu.org> writes:

> As a rule of thumb that is 99% true, everything in xdisp.c is generic,
> i.e. independent of the terminal-specific implementation.  The
> terminal-dependent stuff is in xterm.c/xfns.c (for X),
> w32term.c/w32fns.c (for w32), nsterm.m/nsfns.m (for NS), and term.c
> (for TTY).

Which the naming scheme should reflect, IMO. This includes the presence
of x_* procedures in the NS/W32 code that Stefan mentioned.

> Although I personally fail to see how such renaming will help anyone
> or anything.

For example, the comment in ns_redisplay_interface that feels the
need to mention that the procedures aren't tied to X.

The part that made me make this thread was that there is no visual
distinction between the generic and X-dependent procedures in the
definition of x_redisplay_interface. It's not a huge deal, but it's not
ideal.

> The original long-term plan, to remind us, was not just to rename the
> functions, but also to extract the common code from them so that we
> have only one copy of that.

Right, but that work can be separate from the renaming of the generic
RIF procedures in xdisp.c. If it's going to happen, then IMO it should
happen sooner rather than later.

How about the attached patch? I can mention each rename individually in
the commit message if you agree.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Rename --]
[-- Type: text/x-patch, Size: 27898 bytes --]

From 7bb19b2cee31b19c359778877c024690a97d587c Mon Sep 17 00:00:00 2001
From: Alexander Gramiak <agrambot@gmail.com>
Date: Sat, 23 Mar 2019 11:19:40 -0600
Subject: [PATCH] Rename non-X x_* procedures in xdisp.c

---
 src/composite.c  |  2 +-
 src/dispextern.h | 36 ++++++++++-----------
 src/nsfns.m      |  4 +--
 src/nsterm.m     | 30 +++++++++---------
 src/w32fns.c     |  4 +--
 src/w32term.c    | 26 ++++++++--------
 src/xdisp.c      | 81 ++++++++++++++++++++++++------------------------
 src/xfns.c       | 10 +++---
 src/xterm.c      | 30 +++++++++---------
 9 files changed, 111 insertions(+), 112 deletions(-)

diff --git a/src/composite.c b/src/composite.c
index c426cbb124..839dc3dc71 100644
--- a/src/composite.c
+++ b/src/composite.c
@@ -176,7 +176,7 @@ get_composition_id (ptrdiff_t charpos, ptrdiff_t bytepos, ptrdiff_t nchars,
 
   /* Maximum length of a string of glyphs.  XftGlyphExtents limits
      this to INT_MAX, and Emacs limits it further.  Divide INT_MAX - 1
-     by 2 because x_produce_glyphs computes glyph_len * 2 + 1.  Divide
+     by 2 because gui_produce_glyphs computes glyph_len * 2 + 1.  Divide
      the size by MAX_MULTIBYTE_LENGTH because encode_terminal_code
      multiplies glyph_len by MAX_MULTIBYTE_LENGTH.  */
   enum {
diff --git a/src/dispextern.h b/src/dispextern.h
index 7947dc2dba..32049114c9 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -3275,19 +3275,19 @@ extern void get_font_ascent_descent (struct font *, int *, int *);
 extern void dump_glyph_string (struct glyph_string *) EXTERNALLY_VISIBLE;
 #endif
 
-extern void x_get_glyph_overhangs (struct glyph *, struct frame *,
-                                   int *, int *);
+extern void gui_get_glyph_overhangs (struct glyph *, struct frame *,
+                                     int *, int *);
 extern struct font *font_for_underline_metrics (struct glyph_string *);
-extern void x_produce_glyphs (struct it *);
-
-extern void x_write_glyphs (struct window *, struct glyph_row *,
-			    struct glyph *, enum glyph_row_area, int);
-extern void x_insert_glyphs (struct window *, struct glyph_row *,
-			     struct glyph *, enum glyph_row_area, int);
-extern void x_clear_end_of_line (struct window *, struct glyph_row *,
-				 enum glyph_row_area, int);
-extern void x_fix_overlapping_area (struct window *, struct glyph_row *,
-                                    enum glyph_row_area, int);
+extern void gui_produce_glyphs (struct it *);
+
+extern void gui_write_glyphs (struct window *, struct glyph_row *,
+                              struct glyph *, enum glyph_row_area, int);
+extern void gui_insert_glyphs (struct window *, struct glyph_row *,
+                               struct glyph *, enum glyph_row_area, int);
+extern void gui_clear_end_of_line (struct window *, struct glyph_row *,
+                                   enum glyph_row_area, int);
+extern void gui_fix_overlapping_area (struct window *, struct glyph_row *,
+                                      enum glyph_row_area, int);
 extern void draw_phys_cursor_glyph (struct window *,
                                     struct glyph_row *,
                                     enum draw_glyphs_face);
@@ -3295,10 +3295,10 @@ extern void get_phys_cursor_geometry (struct window *, struct glyph_row *,
                                       struct glyph *, int *, int *, int *);
 extern void erase_phys_cursor (struct window *);
 extern void display_and_set_cursor (struct window *, bool, int, int, int, int);
-extern void x_update_cursor (struct frame *, bool);
-extern void x_clear_cursor (struct window *);
-extern void x_draw_vertical_border (struct window *w);
-extern void x_draw_right_divider (struct window *w);
+extern void gui_update_cursor (struct frame *, bool);
+extern void gui_clear_cursor (struct window *);
+extern void gui_draw_vertical_border (struct window *w);
+extern void gui_draw_right_divider (struct window *w);
 
 extern int get_glyph_string_clip_rects (struct glyph_string *,
                                         NativeRectangle *, int);
@@ -3310,11 +3310,11 @@ extern void handle_tool_bar_click (struct frame *,
                                    int, int, bool, int);
 
 extern void expose_frame (struct frame *, int, int, int, int);
-extern bool x_intersect_rectangles (XRectangle *, XRectangle *, XRectangle *);
+extern bool gui_intersect_rectangles (XRectangle *, XRectangle *, XRectangle *);
 #endif	/* HAVE_WINDOW_SYSTEM */
 
 extern void note_mouse_highlight (struct frame *, int, int);
-extern void x_clear_window_mouse_face (struct window *);
+extern void gui_clear_window_mouse_face (struct window *);
 extern void cancel_mouse_face (struct frame *);
 extern bool clear_mouse_face (Mouse_HLInfo *);
 extern bool cursor_in_mouse_face_p (struct window *w);
diff --git a/src/nsfns.m b/src/nsfns.m
index f8a316a437..0b8316c5a5 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -342,8 +342,8 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
 
   if (FRAME_VISIBLE_P (f))
     {
-      x_update_cursor (f, 0);
-      x_update_cursor (f, 1);
+      gui_update_cursor (f, 0);
+      gui_update_cursor (f, 1);
     }
   update_face_from_frame_parameter (f, Qcursor_color, arg);
   unblock_input ();
diff --git a/src/nsterm.m b/src/nsterm.m
index 81d36be6cc..15316e23ed 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -1183,9 +1183,9 @@ static NSRect constrain_frame_rect(NSRect frameRect, bool isFullscreen)
       if (draw_window_fringes (w, 1))
 	{
 	  if (WINDOW_RIGHT_DIVIDER_WIDTH (w))
-	    x_draw_right_divider (w);
+	    gui_draw_right_divider (w);
 	  else
-	    x_draw_vertical_border (w);
+	    gui_draw_vertical_border (w);
 	}
 
       unblock_input ();
@@ -1528,12 +1528,12 @@ -(void)remove
     {
       if (old_highlight)
 	{
-          x_update_cursor (old_highlight, 1);
+          gui_update_cursor (old_highlight, 1);
 	  x_set_frame_alpha (old_highlight);
 	}
       if (dpyinfo->x_highlight_frame)
 	{
-          x_update_cursor (dpyinfo->x_highlight_frame, 1);
+          gui_update_cursor (dpyinfo->x_highlight_frame, 1);
           x_set_frame_alpha (dpyinfo->x_highlight_frame);
 	}
     }
@@ -2607,7 +2607,7 @@ so some key presses (TAB) are swallowed by the system.  */
       [[view window] invalidateCursorRectsForView: view];
       /* Redisplay assumes this function also draws the changed frame
          cursor, but this function doesn't, so do it explicitly.  */
-      x_update_cursor (f, 1);
+      gui_update_cursor (f, 1);
     }
 }
 
@@ -2885,7 +2885,7 @@ so some key presses (TAB) are swallowed by the system.  */
 
   block_input ();
 
-  x_clear_cursor (w);
+  gui_clear_cursor (w);
 
   {
     NSRect srcRect = NSMakeRect (x, from_y, width, height);
@@ -5099,7 +5099,7 @@ static Lisp_Object ns_string_to_lispmod (const char *s)
 
 
 /* This and next define (many of the) public functions in this file.  */
-/* x_... are generic versions in xdisp.c that we, and other terms, get away
+/* gui_* are generic versions in xdisp.c that we, and other terms, get away
          with using despite presence in the "system dependent" redisplay
          interface.  In addition, many of the ns_ methods have code that is
          shared with all terms, indicating need for further refactoring.  */
@@ -5107,18 +5107,18 @@ static Lisp_Object ns_string_to_lispmod (const char *s)
 static struct redisplay_interface ns_redisplay_interface =
 {
   ns_frame_parm_handlers,
-  x_produce_glyphs,
-  x_write_glyphs,
-  x_insert_glyphs,
-  x_clear_end_of_line,
+  gui_produce_glyphs,
+  gui_write_glyphs,
+  gui_insert_glyphs,
+  gui_clear_end_of_line,
   ns_scroll_run,
   ns_after_update_window_line,
   ns_update_window_begin,
   ns_update_window_end,
   0, /* flush_display */
-  x_clear_window_mouse_face,
-  x_get_glyph_overhangs,
-  x_fix_overlapping_area,
+  gui_clear_window_mouse_face,
+  gui_get_glyph_overhangs,
+  gui_fix_overlapping_area,
   ns_draw_fringe_bitmap,
   0, /* define_fringe_bitmap */ /* FIXME: simplify ns_draw_fringe_bitmap */
   0, /* destroy_fringe_bitmap */
@@ -7249,7 +7249,7 @@ - (void)windowDidResignKey: (NSNotification *)notification
             from sole-frame Emacs to get hollow box to show.  */
   if (!windowClosing && [[self window] isVisible] == YES)
     {
-      x_update_cursor (emacsframe, 1);
+      gui_update_cursor (emacsframe, 1);
       x_set_frame_alpha (emacsframe);
     }
 
diff --git a/src/w32fns.c b/src/w32fns.c
index e4794308ef..873fbaa6e0 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -1515,8 +1515,8 @@ x_set_cursor_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 
       if (FRAME_VISIBLE_P (f))
 	{
-	  x_update_cursor (f, 0);
-	  x_update_cursor (f, 1);
+	  gui_update_cursor (f, 0);
+	  gui_update_cursor (f, 1);
 	}
     }
 
diff --git a/src/w32term.c b/src/w32term.c
index 0f0d6482fc..4f34a1b274 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -363,7 +363,7 @@ w32_draw_underwave (struct glyph_string *s, COLORREF color)
   get_glyph_string_clip_rect (s, &w32_string_clip);
   CONVERT_TO_XRECT (string_clip, w32_string_clip);
 
-  if (!x_intersect_rectangles (&wave_clip, &string_clip, &final_clip))
+  if (!gui_intersect_rectangles (&wave_clip, &string_clip, &final_clip))
     return;
 
   hp = CreatePen (PS_SOLID, thickness, color);
@@ -713,9 +713,9 @@ x_update_window_end (struct window *w, bool cursor_on_p,
       if (draw_window_fringes (w, true))
 	{
 	  if (WINDOW_RIGHT_DIVIDER_WIDTH (w))
-	    x_draw_right_divider (w);
+	    gui_draw_right_divider (w);
 	  else
-	    x_draw_vertical_border (w);
+	    gui_draw_vertical_border (w);
 	}
 
       unblock_input ();
@@ -2845,7 +2845,7 @@ x_scroll_run (struct window *w, struct run *run)
   block_input ();
 
   /* Cursor off.  Will be switched on again in x_update_window_end.  */
-  x_clear_cursor (w);
+  gui_clear_cursor (w);
 
   {
     RECT from;
@@ -2888,14 +2888,14 @@ x_scroll_run (struct window *w, struct run *run)
 static void
 frame_highlight (struct frame *f)
 {
-  x_update_cursor (f, 1);
+  gui_update_cursor (f, 1);
   x_set_frame_alpha (f);
 }
 
 static void
 frame_unhighlight (struct frame *f)
 {
-  x_update_cursor (f, 1);
+  gui_update_cursor (f, 1);
   x_set_frame_alpha (f);
 }
 
@@ -7074,18 +7074,18 @@ extern frame_parm_handler w32_frame_parm_handlers[];
 static struct redisplay_interface w32_redisplay_interface =
 {
   w32_frame_parm_handlers,
-  x_produce_glyphs,
-  x_write_glyphs,
-  x_insert_glyphs,
-  x_clear_end_of_line,
+  gui_produce_glyphs,
+  gui_write_glyphs,
+  gui_insert_glyphs,
+  gui_clear_end_of_line,
   x_scroll_run,
   x_after_update_window_line,
   x_update_window_begin,
   x_update_window_end,
   0, /* flush_display */
-  x_clear_window_mouse_face,
-  x_get_glyph_overhangs,
-  x_fix_overlapping_area,
+  gui_clear_window_mouse_face,
+  gui_get_glyph_overhangs,
+  gui_fix_overlapping_area,
   w32_draw_fringe_bitmap,
   w32_define_fringe_bitmap,
   w32_destroy_fringe_bitmap,
diff --git a/src/xdisp.c b/src/xdisp.c
index a88fc698b8..285d9e91f2 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -900,7 +900,7 @@ static int underlying_face_id (struct it *);
 #ifdef HAVE_WINDOW_SYSTEM
 
 static void update_tool_bar (struct frame *, bool);
-static void x_draw_bottom_divider (struct window *w);
+static void gui_draw_bottom_divider (struct window *w);
 static void notice_overwritten_cursor (struct window *,
                                        enum glyph_row_area,
                                        int, int, int, int);
@@ -2133,7 +2133,7 @@ get_glyph_string_clip_rects (struct glyph_string *s, NativeRectangle *rects, int
 	  rc.width = s->w->phys_cursor_width;
 	  rc.height = s->w->phys_cursor_height;
 
-	  x_intersect_rectangles (&r_save, &rc, &r);
+	  gui_intersect_rectangles (&r_save, &rc, &r);
 	}
     }
   else
@@ -2194,7 +2194,7 @@ get_glyph_string_clip_rects (struct glyph_string *s, NativeRectangle *rects, int
     {
       XRectangle r_save = r;
 
-      if (! x_intersect_rectangles (&r_save, s->row->clip, &r))
+      if (! gui_intersect_rectangles (&r_save, s->row->clip, &r))
 	r.width = 0;
     }
 
@@ -6926,7 +6926,7 @@ static next_element_function const get_next_element[NUM_IT_METHODS] =
    method symbol.  By side-effect, update it->what and
    it->glyphless_method.  This function is called from
    get_next_display_element for each character element, and from
-   x_produce_glyphs when no suitable font was found.  */
+   gui_produce_glyphs when no suitable font was found.  */
 
 Lisp_Object
 lookup_glyphless_char_display (int c, struct it *it)
@@ -9624,7 +9624,7 @@ move_it_to (struct it *it, ptrdiff_t to_charpos, int to_x, int to_y, int to_vpos
 		      /* When display_line produces a continued line
 			 that ends in a TAB, it skips a tab stop that
 			 is closer than the font's space character
-			 width (see x_produce_glyphs where it produces
+			 width (see gui_produce_glyphs where it produces
 			 the stretch glyph which represents a TAB).
 			 We need to reproduce the same logic here.  */
 		      eassert (face_font);
@@ -11999,7 +11999,7 @@ store_mode_line_noprop (const char *string, int field_width, int precision)
    frame_title_format.  */
 
 static void
-x_consider_frame_title (Lisp_Object frame)
+gui_consider_frame_title (Lisp_Object frame)
 {
   struct frame *f = XFRAME (frame);
 
@@ -17697,16 +17697,16 @@ redisplay_window (Lisp_Object window, bool just_this_one_p)
       if (draw_window_fringes (w, true))
 	{
 	  if (WINDOW_RIGHT_DIVIDER_WIDTH (w))
-	    x_draw_right_divider (w);
+	    gui_draw_right_divider (w);
 	  else
-	    x_draw_vertical_border (w);
+	    gui_draw_vertical_border (w);
 	}
       unblock_input ();
       update_end (f);
     }
 
   if (WINDOW_BOTTOM_DIVIDER_WIDTH (w))
-    x_draw_bottom_divider (w);
+    gui_draw_bottom_divider (w);
 #endif /* HAVE_WINDOW_SYSTEM */
 
   /* We go to this label, with fonts_changed set, if it is
@@ -20174,7 +20174,7 @@ append_space_for_newline (struct it *it, bool default_face_p)
 	      it->object = saved_object; /* get_it_property needs this */
 	      normal_char_ascent_descent (font, -1, &it->ascent, &it->descent);
 	      /* Must do a subset of line height processing from
-		 x_produce_glyph for newline characters.  */
+		 gui_produce_glyph for newline characters.  */
 	      height = get_it_property (it, Qline_height);
 	      if (CONSP (height)
 		  && CONSP (XCDR (height))
@@ -26260,7 +26260,7 @@ normal_char_height (struct font *font, int c)
    assumed to be zero.  */
 
 void
-x_get_glyph_overhangs (struct glyph *glyph, struct frame *f, int *left, int *right)
+gui_get_glyph_overhangs (struct glyph *glyph, struct frame *f, int *left, int *right)
 {
   *left = *right = 0;
 
@@ -26350,7 +26350,7 @@ left_overwriting (struct glyph_string *s)
   for (i = first - 1; i >= 0; --i)
     {
       int left, right;
-      x_get_glyph_overhangs (glyphs + i, s->f, &left, &right);
+      gui_get_glyph_overhangs (glyphs + i, s->f, &left, &right);
       if (x + right > 0)
 	k = i;
       x -= glyphs[i].pixel_width;
@@ -26405,7 +26405,7 @@ right_overwriting (struct glyph_string *s)
   for (i = first; i < end; ++i)
     {
       int left, right;
-      x_get_glyph_overhangs (glyphs + i, s->f, &left, &right);
+      gui_get_glyph_overhangs (glyphs + i, s->f, &left, &right);
       if (x - left < 0)
 	k = i;
       x += glyphs[i].pixel_width;
@@ -27067,7 +27067,7 @@ font_for_underline_metrics (struct glyph_string *s)
   }
 
 /* Store one glyph for IT->char_to_display in IT->glyph_row.
-   Called from x_produce_glyphs when IT->glyph_row is non-null.  */
+   Called from gui_produce_glyphs when IT->glyph_row is non-null.  */
 
 static void
 append_glyph (struct it *it)
@@ -27149,9 +27149,8 @@ append_glyph (struct it *it)
     IT_EXPAND_MATRIX_WIDTH (it, area);
 }
 
-/* Store one glyph for the composition IT->cmp_it.id in
-   IT->glyph_row.  Called from x_produce_glyphs when IT->glyph_row is
-   non-null.  */
+/* Store one glyph for the composition IT->cmp_it.id in IT->glyph_row.
+   Called from gui_produce_glyphs when IT->glyph_row is non-null.  */
 
 static void
 append_composite_glyph (struct it *it)
@@ -28227,7 +28226,7 @@ produce_glyphless_glyph (struct it *it, bool for_no_font, Lisp_Object acronym)
    for an overview of struct it.  */
 
 void
-x_produce_glyphs (struct it *it)
+gui_produce_glyphs (struct it *it)
 {
   int extra_line_spacing = it->extra_line_spacing;
 
@@ -28995,7 +28994,7 @@ x_produce_glyphs (struct it *it)
    being updated, and UPDATED_AREA is the area of that row being updated.  */
 
 void
-x_write_glyphs (struct window *w, struct glyph_row *updated_row,
+gui_write_glyphs (struct window *w, struct glyph_row *updated_row,
 		struct glyph *start, enum glyph_row_area updated_area, int len)
 {
   int x, hpos, chpos = w->phys_cursor.hpos;
@@ -29039,7 +29038,7 @@ x_write_glyphs (struct window *w, struct glyph_row *updated_row,
    Insert LEN glyphs from START at the nominal cursor position.  */
 
 void
-x_insert_glyphs (struct window *w, struct glyph_row *updated_row,
+gui_insert_glyphs (struct window *w, struct glyph_row *updated_row,
 		 struct glyph *start, enum glyph_row_area updated_area, int len)
 {
   struct frame *f;
@@ -29096,7 +29095,7 @@ x_insert_glyphs (struct window *w, struct glyph_row *updated_row,
    updated window W.  TO_X == -1 means clear to the end of this area.  */
 
 void
-x_clear_end_of_line (struct window *w, struct glyph_row *updated_row,
+gui_clear_end_of_line (struct window *w, struct glyph_row *updated_row,
 		     enum glyph_row_area updated_area, int to_x)
 {
   struct frame *f;
@@ -29483,7 +29482,7 @@ notice_overwritten_cursor (struct window *w, enum glyph_row_area area,
    with respect to the overlapping part OVERLAPS.  */
 
 void
-x_fix_overlapping_area (struct window *w, struct glyph_row *row,
+gui_fix_overlapping_area (struct window *w, struct glyph_row *row,
 			enum glyph_row_area area, int overlaps)
 {
   int i, x;
@@ -29562,12 +29561,12 @@ draw_phys_cursor_glyph (struct window *w, struct glyph_row *row,
 
 	  if (row > w->current_matrix->rows
 	      && MATRIX_ROW_OVERLAPS_SUCC_P (row - 1))
-	    x_fix_overlapping_area (w, row - 1, TEXT_AREA,
+	    gui_fix_overlapping_area (w, row - 1, TEXT_AREA,
 				    OVERLAPS_ERASED_CURSOR);
 
 	  if (MATRIX_ROW_BOTTOM_Y (row) < window_text_bottom_y (w)
 	      && MATRIX_ROW_OVERLAPS_PRED_P (row + 1))
-	    x_fix_overlapping_area (w, row + 1, TEXT_AREA,
+	    gui_fix_overlapping_area (w, row + 1, TEXT_AREA,
 				    OVERLAPS_ERASED_CURSOR);
 	}
     }
@@ -29857,7 +29856,7 @@ update_cursor_in_window_tree (struct window *w, bool on_p)
    Don't change the cursor's position.  */
 
 void
-x_update_cursor (struct frame *f, bool on_p)
+gui_update_cursor (struct frame *f, bool on_p)
 {
   update_cursor_in_window_tree (XWINDOW (f->root_window), on_p);
 }
@@ -29869,7 +29868,7 @@ x_update_cursor (struct frame *f, bool on_p)
    is about to be rewritten.  */
 
 void
-x_clear_cursor (struct window *w)
+gui_clear_cursor (struct window *w)
 {
   if (FRAME_VISIBLE_P (XFRAME (w->frame)) && w->phys_cursor_on_p)
     update_window_cursor (w, false);
@@ -31897,7 +31896,7 @@ note_mouse_highlight (struct frame *f, int x, int y)
    functions to ensure the mouse-highlight is off.  */
 
 void
-x_clear_window_mouse_face (struct window *w)
+gui_clear_window_mouse_face (struct window *w)
 {
   Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (XFRAME (w->frame));
   Lisp_Object window;
@@ -32041,13 +32040,13 @@ expose_overlaps (struct window *w,
 
 	row->clip = r;
 	if (row->used[LEFT_MARGIN_AREA])
-	  x_fix_overlapping_area (w, row, LEFT_MARGIN_AREA, OVERLAPS_BOTH);
+	  gui_fix_overlapping_area (w, row, LEFT_MARGIN_AREA, OVERLAPS_BOTH);
 
 	if (row->used[TEXT_AREA])
-	  x_fix_overlapping_area (w, row, TEXT_AREA, OVERLAPS_BOTH);
+	  gui_fix_overlapping_area (w, row, TEXT_AREA, OVERLAPS_BOTH);
 
 	if (row->used[RIGHT_MARGIN_AREA])
-	  x_fix_overlapping_area (w, row, RIGHT_MARGIN_AREA, OVERLAPS_BOTH);
+	  gui_fix_overlapping_area (w, row, RIGHT_MARGIN_AREA, OVERLAPS_BOTH);
 	row->clip = NULL;
       }
 }
@@ -32076,7 +32075,7 @@ phys_cursor_in_rect_p (struct window *w, XRectangle *r)
       cr.y = row->y;
       cr.width = WINDOW_RIGHT_FRINGE_WIDTH (w);
       cr.height = row->height;
-      return x_intersect_rectangles (&cr, r, &result);
+      return gui_intersect_rectangles (&cr, r, &result);
     }
 
   cursor_glyph = get_phys_cursor_glyph (w);
@@ -32090,7 +32089,7 @@ phys_cursor_in_rect_p (struct window *w, XRectangle *r)
       cr.height = w->phys_cursor_height;
       /* ++KFS: W32 version used W32-specific IntersectRect here, but
 	 I assume the effect is the same -- and this is portable.  */
-      return x_intersect_rectangles (&cr, r, &result);
+      return gui_intersect_rectangles (&cr, r, &result);
     }
   /* If we don't understand the format, pretend we're not in the hot-spot.  */
   return false;
@@ -32102,7 +32101,7 @@ phys_cursor_in_rect_p (struct window *w, XRectangle *r)
    have vertical scroll bars.  */
 
 void
-x_draw_vertical_border (struct window *w)
+gui_draw_vertical_border (struct window *w)
 {
   struct frame *f = XFRAME (WINDOW_FRAME (w));
 
@@ -32153,7 +32152,7 @@ x_draw_vertical_border (struct window *w)
 /* Draw window dividers for window W.  */
 
 void
-x_draw_right_divider (struct window *w)
+gui_draw_right_divider (struct window *w)
 {
   struct frame *f = WINDOW_XFRAME (w);
 
@@ -32179,7 +32178,7 @@ x_draw_right_divider (struct window *w)
 }
 
 static void
-x_draw_bottom_divider (struct window *w)
+gui_draw_bottom_divider (struct window *w)
 {
   struct frame *f = XFRAME (WINDOW_FRAME (w));
 
@@ -32244,7 +32243,7 @@ expose_window (struct window *w, XRectangle *fr)
   wr.width = WINDOW_PIXEL_WIDTH (w);
   wr.height = WINDOW_PIXEL_HEIGHT (w);
 
-  if (x_intersect_rectangles (fr, &wr, &r))
+  if (gui_intersect_rectangles (fr, &wr, &r))
     {
       int yb = window_text_bottom_y (w);
       struct glyph_row *row;
@@ -32261,7 +32260,7 @@ expose_window (struct window *w, XRectangle *fr)
       bool cursor_cleared_p = (!w->pseudo_window_p
 			       && phys_cursor_in_rect_p (w, &r));
       if (cursor_cleared_p)
-	x_clear_cursor (w);
+	gui_clear_cursor (w);
 
       /* If the row containing the cursor extends face to end of line,
 	 then expose_area might overwrite the cursor outside the
@@ -32354,12 +32353,12 @@ expose_window (struct window *w, XRectangle *fr)
 
 	  /* Draw border between windows.  */
 	  if (WINDOW_RIGHT_DIVIDER_WIDTH (w))
-	    x_draw_right_divider (w);
+	    gui_draw_right_divider (w);
 	  else
-	    x_draw_vertical_border (w);
+	    gui_draw_vertical_border (w);
 
 	  if (WINDOW_BOTTOM_DIVIDER_WIDTH (w))
-	    x_draw_bottom_divider (w);
+	    gui_draw_bottom_divider (w);
 
 	  /* Turn the cursor on again.  */
 	  if (cursor_cleared_p
@@ -32493,7 +32492,7 @@ expose_frame (struct frame *f, int x, int y, int w, int h)
    empty.  */
 
 bool
-x_intersect_rectangles (XRectangle *r1, XRectangle *r2, XRectangle *result)
+gui_intersect_rectangles (XRectangle *r1, XRectangle *r2, XRectangle *result)
 {
   XRectangle *left, *right;
   XRectangle *upper, *lower;
diff --git a/src/xfns.c b/src/xfns.c
index 7234d02f4e..cca15b0467 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -1389,8 +1389,8 @@ x_set_cursor_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 
       if (FRAME_VISIBLE_P (f))
 	{
-	  x_update_cursor (f, false);
-	  x_update_cursor (f, true);
+	  gui_update_cursor (f, false);
+	  gui_update_cursor (f, true);
 	}
     }
 
@@ -4584,7 +4584,7 @@ x_get_monitor_for_frame (struct frame *f,
 
       if (mi->geom.width == 0) continue;
 
-      if (x_intersect_rectangles (&mi->geom, &frect, &res))
+      if (gui_intersect_rectangles (&mi->geom, &frect, &res))
         {
           a = res.width * res.height;
           if (a > area)
@@ -4713,7 +4713,7 @@ x_get_monitor_attributes_xinerama (struct x_display_info *dpyinfo)
       if (i == 0 && x_get_net_workarea (dpyinfo, &workarea_r))
 	{
 	  mi->work = workarea_r;
-	  if (! x_intersect_rectangles (&mi->geom, &mi->work, &mi->work))
+	  if (! gui_intersect_rectangles (&mi->geom, &mi->work, &mi->work))
 	    mi->work = mi->geom;
 	}
       else
@@ -4817,7 +4817,7 @@ x_get_monitor_attributes_xrandr (struct x_display_info *dpyinfo)
           if (i == primary && x_get_net_workarea (dpyinfo, &workarea_r))
             {
               mi->work= workarea_r;
-              if (! x_intersect_rectangles (&mi->geom, &mi->work, &mi->work))
+              if (! gui_intersect_rectangles (&mi->geom, &mi->work, &mi->work))
                 mi->work = mi->geom;
             }
           else
diff --git a/src/xterm.c b/src/xterm.c
index 1b0c2f5ec5..968ff165c5 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -1161,9 +1161,9 @@ x_update_window_end (struct window *w, bool cursor_on_p,
       if (draw_window_fringes (w, true))
 	{
 	  if (WINDOW_RIGHT_DIVIDER_WIDTH (w))
-	    x_draw_right_divider (w);
+	    gui_draw_right_divider (w);
 	  else
-	    x_draw_vertical_border (w);
+	    gui_draw_vertical_border (w);
 	}
 
       unblock_input ();
@@ -3069,7 +3069,7 @@ x_draw_image_foreground (struct glyph_string *s)
 	  image_rect.y = y;
 	  image_rect.width = s->slice.width;
 	  image_rect.height = s->slice.height;
-	  if (x_intersect_rectangles (&clip_rect, &image_rect, &r))
+	  if (gui_intersect_rectangles (&clip_rect, &image_rect, &r))
             x_composite_image (s, FRAME_X_DRAWABLE (s->f),
 			       s->slice.x + r.x - x, s->slice.y + r.y - y,
                                r.x, r.y, r.width, r.height);
@@ -3083,7 +3083,7 @@ x_draw_image_foreground (struct glyph_string *s)
 	  image_rect.y = y;
 	  image_rect.width = s->slice.width;
 	  image_rect.height = s->slice.height;
-	  if (x_intersect_rectangles (&clip_rect, &image_rect, &r))
+	  if (gui_intersect_rectangles (&clip_rect, &image_rect, &r))
             x_composite_image (s, FRAME_X_DRAWABLE (s->f), s->slice.x + r.x - x, s->slice.y + r.y - y,
                                r.x, r.y, r.width, r.height);
 
@@ -3579,7 +3579,7 @@ x_draw_underwave (struct glyph_string *s)
   wave_clip.height = wave_height;
   get_glyph_string_clip_rect (s, &string_clip);
 
-  if (!x_intersect_rectangles (&wave_clip, &string_clip, &final_clip))
+  if (!gui_intersect_rectangles (&wave_clip, &string_clip, &final_clip))
     return;
 
   XSetClipRectangles (s->display, s->gc, 0, 0, &final_clip, 1, Unsorted);
@@ -4310,7 +4310,7 @@ x_scroll_run (struct window *w, struct run *run)
   block_input ();
 
   /* Cursor off.  Will be switched on again in x_update_window_end.  */
-  x_clear_cursor (w);
+  gui_clear_cursor (w);
 
 #ifdef USE_CAIRO
   if (FRAME_CR_CONTEXT (f))
@@ -4372,7 +4372,7 @@ frame_highlight (struct frame *f)
 		    f->output_data.x->border_pixel);
   x_uncatch_errors ();
   unblock_input ();
-  x_update_cursor (f, true);
+  gui_update_cursor (f, true);
   x_set_frame_alpha (f);
 }
 
@@ -4390,7 +4390,7 @@ frame_unhighlight (struct frame *f)
 			  f->output_data.x->border_tile);
   x_uncatch_errors ();
   unblock_input ();
-  x_update_cursor (f, true);
+  gui_update_cursor (f, true);
   x_set_frame_alpha (f);
 }
 
@@ -13079,18 +13079,18 @@ x_activate_timeout_atimer (void)
 static struct redisplay_interface x_redisplay_interface =
   {
     x_frame_parm_handlers,
-    x_produce_glyphs,
-    x_write_glyphs,
-    x_insert_glyphs,
-    x_clear_end_of_line,
+    gui_produce_glyphs,
+    gui_write_glyphs,
+    gui_insert_glyphs,
+    gui_clear_end_of_line,
     x_scroll_run,
     x_after_update_window_line,
     x_update_window_begin,
     x_update_window_end,
     x_flip_and_flush,
-    x_clear_window_mouse_face,
-    x_get_glyph_overhangs,
-    x_fix_overlapping_area,
+    gui_clear_window_mouse_face,
+    gui_get_glyph_overhangs,
+    gui_fix_overlapping_area,
     x_draw_fringe_bitmap,
 #ifdef USE_CAIRO
     x_cr_define_fringe_bitmap,
-- 
2.21.0


[-- Attachment #3: Type: text/plain, Size: 151 bytes --]


P.S. Should x_clear_window_mouse_face instead be renamed to
clear_window_mouse_face since it doesn't depend on HAVE_WINDOW_SYSTEM
like the others do?

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* Re: Renaming non-X x_* procedures in xdisp.c (and elsewhere)
  2019-03-23 17:39       ` Alex
@ 2019-03-23 17:54         ` Alex
  2019-03-23 18:16         ` Eli Zaretskii
  1 sibling, 0 replies; 68+ messages in thread
From: Alex @ 2019-03-23 17:54 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Paul Eggert, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 209 bytes --]

Alex <agrambot@gmail.com> writes:

> How about the attached patch? I can mention each rename individually in
> the commit message if you agree.

Sorry, I sent out an unfinished patch; here's the correct one:


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Rename --]
[-- Type: text/x-patch, Size: 30267 bytes --]

From c6dbf1e863666b8ffcb25ac6e5f807238f8f8873 Mon Sep 17 00:00:00 2001
From: Alexander Gramiak <agrambot@gmail.com>
Date: Sat, 23 Mar 2019 11:19:40 -0600
Subject: [PATCH] Rename non-X x_* procedures in xdisp.c

---
 src/composite.c  |  2 +-
 src/dispextern.h | 36 +++++++++----------
 src/nsfns.m      |  4 +--
 src/nsterm.m     | 30 ++++++++--------
 src/w32fns.c     |  4 +--
 src/w32term.c    | 26 +++++++-------
 src/window.c     |  2 +-
 src/xdisp.c      | 91 ++++++++++++++++++++++++------------------------
 src/xfns.c       | 10 +++---
 src/xterm.c      | 30 ++++++++--------
 10 files changed, 117 insertions(+), 118 deletions(-)

diff --git a/src/composite.c b/src/composite.c
index c426cbb124..839dc3dc71 100644
--- a/src/composite.c
+++ b/src/composite.c
@@ -176,7 +176,7 @@ get_composition_id (ptrdiff_t charpos, ptrdiff_t bytepos, ptrdiff_t nchars,
 
   /* Maximum length of a string of glyphs.  XftGlyphExtents limits
      this to INT_MAX, and Emacs limits it further.  Divide INT_MAX - 1
-     by 2 because x_produce_glyphs computes glyph_len * 2 + 1.  Divide
+     by 2 because gui_produce_glyphs computes glyph_len * 2 + 1.  Divide
      the size by MAX_MULTIBYTE_LENGTH because encode_terminal_code
      multiplies glyph_len by MAX_MULTIBYTE_LENGTH.  */
   enum {
diff --git a/src/dispextern.h b/src/dispextern.h
index 7947dc2dba..32049114c9 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -3275,19 +3275,19 @@ extern void get_font_ascent_descent (struct font *, int *, int *);
 extern void dump_glyph_string (struct glyph_string *) EXTERNALLY_VISIBLE;
 #endif
 
-extern void x_get_glyph_overhangs (struct glyph *, struct frame *,
-                                   int *, int *);
+extern void gui_get_glyph_overhangs (struct glyph *, struct frame *,
+                                     int *, int *);
 extern struct font *font_for_underline_metrics (struct glyph_string *);
-extern void x_produce_glyphs (struct it *);
-
-extern void x_write_glyphs (struct window *, struct glyph_row *,
-			    struct glyph *, enum glyph_row_area, int);
-extern void x_insert_glyphs (struct window *, struct glyph_row *,
-			     struct glyph *, enum glyph_row_area, int);
-extern void x_clear_end_of_line (struct window *, struct glyph_row *,
-				 enum glyph_row_area, int);
-extern void x_fix_overlapping_area (struct window *, struct glyph_row *,
-                                    enum glyph_row_area, int);
+extern void gui_produce_glyphs (struct it *);
+
+extern void gui_write_glyphs (struct window *, struct glyph_row *,
+                              struct glyph *, enum glyph_row_area, int);
+extern void gui_insert_glyphs (struct window *, struct glyph_row *,
+                               struct glyph *, enum glyph_row_area, int);
+extern void gui_clear_end_of_line (struct window *, struct glyph_row *,
+                                   enum glyph_row_area, int);
+extern void gui_fix_overlapping_area (struct window *, struct glyph_row *,
+                                      enum glyph_row_area, int);
 extern void draw_phys_cursor_glyph (struct window *,
                                     struct glyph_row *,
                                     enum draw_glyphs_face);
@@ -3295,10 +3295,10 @@ extern void get_phys_cursor_geometry (struct window *, struct glyph_row *,
                                       struct glyph *, int *, int *, int *);
 extern void erase_phys_cursor (struct window *);
 extern void display_and_set_cursor (struct window *, bool, int, int, int, int);
-extern void x_update_cursor (struct frame *, bool);
-extern void x_clear_cursor (struct window *);
-extern void x_draw_vertical_border (struct window *w);
-extern void x_draw_right_divider (struct window *w);
+extern void gui_update_cursor (struct frame *, bool);
+extern void gui_clear_cursor (struct window *);
+extern void gui_draw_vertical_border (struct window *w);
+extern void gui_draw_right_divider (struct window *w);
 
 extern int get_glyph_string_clip_rects (struct glyph_string *,
                                         NativeRectangle *, int);
@@ -3310,11 +3310,11 @@ extern void handle_tool_bar_click (struct frame *,
                                    int, int, bool, int);
 
 extern void expose_frame (struct frame *, int, int, int, int);
-extern bool x_intersect_rectangles (XRectangle *, XRectangle *, XRectangle *);
+extern bool gui_intersect_rectangles (XRectangle *, XRectangle *, XRectangle *);
 #endif	/* HAVE_WINDOW_SYSTEM */
 
 extern void note_mouse_highlight (struct frame *, int, int);
-extern void x_clear_window_mouse_face (struct window *);
+extern void gui_clear_window_mouse_face (struct window *);
 extern void cancel_mouse_face (struct frame *);
 extern bool clear_mouse_face (Mouse_HLInfo *);
 extern bool cursor_in_mouse_face_p (struct window *w);
diff --git a/src/nsfns.m b/src/nsfns.m
index ee7598a1c7..009e9d55e2 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -342,8 +342,8 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
 
   if (FRAME_VISIBLE_P (f))
     {
-      x_update_cursor (f, 0);
-      x_update_cursor (f, 1);
+      gui_update_cursor (f, 0);
+      gui_update_cursor (f, 1);
     }
   update_face_from_frame_parameter (f, Qcursor_color, arg);
   unblock_input ();
diff --git a/src/nsterm.m b/src/nsterm.m
index 81d36be6cc..15316e23ed 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -1183,9 +1183,9 @@ static NSRect constrain_frame_rect(NSRect frameRect, bool isFullscreen)
       if (draw_window_fringes (w, 1))
 	{
 	  if (WINDOW_RIGHT_DIVIDER_WIDTH (w))
-	    x_draw_right_divider (w);
+	    gui_draw_right_divider (w);
 	  else
-	    x_draw_vertical_border (w);
+	    gui_draw_vertical_border (w);
 	}
 
       unblock_input ();
@@ -1528,12 +1528,12 @@ -(void)remove
     {
       if (old_highlight)
 	{
-          x_update_cursor (old_highlight, 1);
+          gui_update_cursor (old_highlight, 1);
 	  x_set_frame_alpha (old_highlight);
 	}
       if (dpyinfo->x_highlight_frame)
 	{
-          x_update_cursor (dpyinfo->x_highlight_frame, 1);
+          gui_update_cursor (dpyinfo->x_highlight_frame, 1);
           x_set_frame_alpha (dpyinfo->x_highlight_frame);
 	}
     }
@@ -2607,7 +2607,7 @@ so some key presses (TAB) are swallowed by the system.  */
       [[view window] invalidateCursorRectsForView: view];
       /* Redisplay assumes this function also draws the changed frame
          cursor, but this function doesn't, so do it explicitly.  */
-      x_update_cursor (f, 1);
+      gui_update_cursor (f, 1);
     }
 }
 
@@ -2885,7 +2885,7 @@ so some key presses (TAB) are swallowed by the system.  */
 
   block_input ();
 
-  x_clear_cursor (w);
+  gui_clear_cursor (w);
 
   {
     NSRect srcRect = NSMakeRect (x, from_y, width, height);
@@ -5099,7 +5099,7 @@ static Lisp_Object ns_string_to_lispmod (const char *s)
 
 
 /* This and next define (many of the) public functions in this file.  */
-/* x_... are generic versions in xdisp.c that we, and other terms, get away
+/* gui_* are generic versions in xdisp.c that we, and other terms, get away
          with using despite presence in the "system dependent" redisplay
          interface.  In addition, many of the ns_ methods have code that is
          shared with all terms, indicating need for further refactoring.  */
@@ -5107,18 +5107,18 @@ static Lisp_Object ns_string_to_lispmod (const char *s)
 static struct redisplay_interface ns_redisplay_interface =
 {
   ns_frame_parm_handlers,
-  x_produce_glyphs,
-  x_write_glyphs,
-  x_insert_glyphs,
-  x_clear_end_of_line,
+  gui_produce_glyphs,
+  gui_write_glyphs,
+  gui_insert_glyphs,
+  gui_clear_end_of_line,
   ns_scroll_run,
   ns_after_update_window_line,
   ns_update_window_begin,
   ns_update_window_end,
   0, /* flush_display */
-  x_clear_window_mouse_face,
-  x_get_glyph_overhangs,
-  x_fix_overlapping_area,
+  gui_clear_window_mouse_face,
+  gui_get_glyph_overhangs,
+  gui_fix_overlapping_area,
   ns_draw_fringe_bitmap,
   0, /* define_fringe_bitmap */ /* FIXME: simplify ns_draw_fringe_bitmap */
   0, /* destroy_fringe_bitmap */
@@ -7249,7 +7249,7 @@ - (void)windowDidResignKey: (NSNotification *)notification
             from sole-frame Emacs to get hollow box to show.  */
   if (!windowClosing && [[self window] isVisible] == YES)
     {
-      x_update_cursor (emacsframe, 1);
+      gui_update_cursor (emacsframe, 1);
       x_set_frame_alpha (emacsframe);
     }
 
diff --git a/src/w32fns.c b/src/w32fns.c
index 25900c54c8..4c0753c939 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -1514,8 +1514,8 @@ x_set_cursor_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 
       if (FRAME_VISIBLE_P (f))
 	{
-	  x_update_cursor (f, 0);
-	  x_update_cursor (f, 1);
+	  gui_update_cursor (f, 0);
+	  gui_update_cursor (f, 1);
 	}
     }
 
diff --git a/src/w32term.c b/src/w32term.c
index 0f0d6482fc..4f34a1b274 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -363,7 +363,7 @@ w32_draw_underwave (struct glyph_string *s, COLORREF color)
   get_glyph_string_clip_rect (s, &w32_string_clip);
   CONVERT_TO_XRECT (string_clip, w32_string_clip);
 
-  if (!x_intersect_rectangles (&wave_clip, &string_clip, &final_clip))
+  if (!gui_intersect_rectangles (&wave_clip, &string_clip, &final_clip))
     return;
 
   hp = CreatePen (PS_SOLID, thickness, color);
@@ -713,9 +713,9 @@ x_update_window_end (struct window *w, bool cursor_on_p,
       if (draw_window_fringes (w, true))
 	{
 	  if (WINDOW_RIGHT_DIVIDER_WIDTH (w))
-	    x_draw_right_divider (w);
+	    gui_draw_right_divider (w);
 	  else
-	    x_draw_vertical_border (w);
+	    gui_draw_vertical_border (w);
 	}
 
       unblock_input ();
@@ -2845,7 +2845,7 @@ x_scroll_run (struct window *w, struct run *run)
   block_input ();
 
   /* Cursor off.  Will be switched on again in x_update_window_end.  */
-  x_clear_cursor (w);
+  gui_clear_cursor (w);
 
   {
     RECT from;
@@ -2888,14 +2888,14 @@ x_scroll_run (struct window *w, struct run *run)
 static void
 frame_highlight (struct frame *f)
 {
-  x_update_cursor (f, 1);
+  gui_update_cursor (f, 1);
   x_set_frame_alpha (f);
 }
 
 static void
 frame_unhighlight (struct frame *f)
 {
-  x_update_cursor (f, 1);
+  gui_update_cursor (f, 1);
   x_set_frame_alpha (f);
 }
 
@@ -7074,18 +7074,18 @@ extern frame_parm_handler w32_frame_parm_handlers[];
 static struct redisplay_interface w32_redisplay_interface =
 {
   w32_frame_parm_handlers,
-  x_produce_glyphs,
-  x_write_glyphs,
-  x_insert_glyphs,
-  x_clear_end_of_line,
+  gui_produce_glyphs,
+  gui_write_glyphs,
+  gui_insert_glyphs,
+  gui_clear_end_of_line,
   x_scroll_run,
   x_after_update_window_line,
   x_update_window_begin,
   x_update_window_end,
   0, /* flush_display */
-  x_clear_window_mouse_face,
-  x_get_glyph_overhangs,
-  x_fix_overlapping_area,
+  gui_clear_window_mouse_face,
+  gui_get_glyph_overhangs,
+  gui_fix_overlapping_area,
   w32_draw_fringe_bitmap,
   w32_define_fringe_bitmap,
   w32_destroy_fringe_bitmap,
diff --git a/src/window.c b/src/window.c
index be338c2af6..7b11560263 100644
--- a/src/window.c
+++ b/src/window.c
@@ -220,7 +220,7 @@ static void
 wset_update_mode_line (struct window *w)
 {
   /* If this window is the selected window on its frame, set the
-     global variable update_mode_lines, so that x_consider_frame_title
+     global variable update_mode_lines, so that gui_consider_frame_title
      will consider this frame's title for redisplay.  */
   Lisp_Object fselected_window = XFRAME (WINDOW_FRAME (w))->selected_window;
 
diff --git a/src/xdisp.c b/src/xdisp.c
index a88fc698b8..ae4c405b8d 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -491,7 +491,7 @@ int windows_or_buffers_changed;
 
    Since the frame title uses the same %-constructs as the mode line
    (except %c, %C, and %l), if this variable is non-zero, we also consider
-   redisplaying the title of each frame, see x_consider_frame_title.
+   redisplaying the title of each frame, see gui_consider_frame_title.
 
    The `redisplay' bits are the same as those used for
    windows_or_buffers_changed, and setting windows_or_buffers_changed also
@@ -900,7 +900,7 @@ static int underlying_face_id (struct it *);
 #ifdef HAVE_WINDOW_SYSTEM
 
 static void update_tool_bar (struct frame *, bool);
-static void x_draw_bottom_divider (struct window *w);
+static void gui_draw_bottom_divider (struct window *w);
 static void notice_overwritten_cursor (struct window *,
                                        enum glyph_row_area,
                                        int, int, int, int);
@@ -2133,7 +2133,7 @@ get_glyph_string_clip_rects (struct glyph_string *s, NativeRectangle *rects, int
 	  rc.width = s->w->phys_cursor_width;
 	  rc.height = s->w->phys_cursor_height;
 
-	  x_intersect_rectangles (&r_save, &rc, &r);
+	  gui_intersect_rectangles (&r_save, &rc, &r);
 	}
     }
   else
@@ -2194,7 +2194,7 @@ get_glyph_string_clip_rects (struct glyph_string *s, NativeRectangle *rects, int
     {
       XRectangle r_save = r;
 
-      if (! x_intersect_rectangles (&r_save, s->row->clip, &r))
+      if (! gui_intersect_rectangles (&r_save, s->row->clip, &r))
 	r.width = 0;
     }
 
@@ -6926,7 +6926,7 @@ static next_element_function const get_next_element[NUM_IT_METHODS] =
    method symbol.  By side-effect, update it->what and
    it->glyphless_method.  This function is called from
    get_next_display_element for each character element, and from
-   x_produce_glyphs when no suitable font was found.  */
+   gui_produce_glyphs when no suitable font was found.  */
 
 Lisp_Object
 lookup_glyphless_char_display (int c, struct it *it)
@@ -9624,7 +9624,7 @@ move_it_to (struct it *it, ptrdiff_t to_charpos, int to_x, int to_y, int to_vpos
 		      /* When display_line produces a continued line
 			 that ends in a TAB, it skips a tab stop that
 			 is closer than the font's space character
-			 width (see x_produce_glyphs where it produces
+			 width (see gui_produce_glyphs where it produces
 			 the stretch glyph which represents a TAB).
 			 We need to reproduce the same logic here.  */
 		      eassert (face_font);
@@ -11999,7 +11999,7 @@ store_mode_line_noprop (const char *string, int field_width, int precision)
    frame_title_format.  */
 
 static void
-x_consider_frame_title (Lisp_Object frame)
+gui_consider_frame_title (Lisp_Object frame)
 {
   struct frame *f = XFRAME (frame);
 
@@ -12146,7 +12146,7 @@ prepare_menu_bars (void)
 		  || FRAME_VISIBLE_P (f) == 1
 		  /* Exclude TTY frames that are obscured because they
 		     are not the top frame on their console.  This is
-		     because x_consider_frame_title actually switches
+		     because gui_consider_frame_title actually switches
 		     to the frame, which for TTY frames means it is
 		     marked as garbaged, and will be completely
 		     redrawn on the next redisplay cycle.  This causes
@@ -12154,7 +12154,7 @@ prepare_menu_bars (void)
 		     are more than one of them, even though nothing
 		     should be changed on display.  */
 		  || (FRAME_VISIBLE_P (f) == 2 && FRAME_WINDOW_P (f))))
-	    x_consider_frame_title (frame);
+	    gui_consider_frame_title (frame);
 	}
     }
 #endif /* HAVE_WINDOW_SYSTEM */
@@ -17682,7 +17682,7 @@ redisplay_window (Lisp_Object window, bool just_this_one_p)
 	    ignore_mouse_drag_p = true;
 #endif
         }
-      x_consider_frame_title (w->frame);
+      gui_consider_frame_title (w->frame);
 #endif
     }
 
@@ -17697,16 +17697,16 @@ redisplay_window (Lisp_Object window, bool just_this_one_p)
       if (draw_window_fringes (w, true))
 	{
 	  if (WINDOW_RIGHT_DIVIDER_WIDTH (w))
-	    x_draw_right_divider (w);
+	    gui_draw_right_divider (w);
 	  else
-	    x_draw_vertical_border (w);
+	    gui_draw_vertical_border (w);
 	}
       unblock_input ();
       update_end (f);
     }
 
   if (WINDOW_BOTTOM_DIVIDER_WIDTH (w))
-    x_draw_bottom_divider (w);
+    gui_draw_bottom_divider (w);
 #endif /* HAVE_WINDOW_SYSTEM */
 
   /* We go to this label, with fonts_changed set, if it is
@@ -19150,7 +19150,7 @@ try_window_id (struct window *w)
 		     + window_internal_height (w));
 
 #if defined (HAVE_GPM) || defined (MSDOS)
-	  x_clear_window_mouse_face (w);
+	  gui_clear_window_mouse_face (w);
 #endif
 	  /* Perform the operation on the screen.  */
 	  if (dvpos > 0)
@@ -20174,7 +20174,7 @@ append_space_for_newline (struct it *it, bool default_face_p)
 	      it->object = saved_object; /* get_it_property needs this */
 	      normal_char_ascent_descent (font, -1, &it->ascent, &it->descent);
 	      /* Must do a subset of line height processing from
-		 x_produce_glyph for newline characters.  */
+		 gui_produce_glyph for newline characters.  */
 	      height = get_it_property (it, Qline_height);
 	      if (CONSP (height)
 		  && CONSP (XCDR (height))
@@ -26260,7 +26260,7 @@ normal_char_height (struct font *font, int c)
    assumed to be zero.  */
 
 void
-x_get_glyph_overhangs (struct glyph *glyph, struct frame *f, int *left, int *right)
+gui_get_glyph_overhangs (struct glyph *glyph, struct frame *f, int *left, int *right)
 {
   *left = *right = 0;
 
@@ -26350,7 +26350,7 @@ left_overwriting (struct glyph_string *s)
   for (i = first - 1; i >= 0; --i)
     {
       int left, right;
-      x_get_glyph_overhangs (glyphs + i, s->f, &left, &right);
+      gui_get_glyph_overhangs (glyphs + i, s->f, &left, &right);
       if (x + right > 0)
 	k = i;
       x -= glyphs[i].pixel_width;
@@ -26405,7 +26405,7 @@ right_overwriting (struct glyph_string *s)
   for (i = first; i < end; ++i)
     {
       int left, right;
-      x_get_glyph_overhangs (glyphs + i, s->f, &left, &right);
+      gui_get_glyph_overhangs (glyphs + i, s->f, &left, &right);
       if (x - left < 0)
 	k = i;
       x += glyphs[i].pixel_width;
@@ -27067,7 +27067,7 @@ font_for_underline_metrics (struct glyph_string *s)
   }
 
 /* Store one glyph for IT->char_to_display in IT->glyph_row.
-   Called from x_produce_glyphs when IT->glyph_row is non-null.  */
+   Called from gui_produce_glyphs when IT->glyph_row is non-null.  */
 
 static void
 append_glyph (struct it *it)
@@ -27149,9 +27149,8 @@ append_glyph (struct it *it)
     IT_EXPAND_MATRIX_WIDTH (it, area);
 }
 
-/* Store one glyph for the composition IT->cmp_it.id in
-   IT->glyph_row.  Called from x_produce_glyphs when IT->glyph_row is
-   non-null.  */
+/* Store one glyph for the composition IT->cmp_it.id in IT->glyph_row.
+   Called from gui_produce_glyphs when IT->glyph_row is non-null.  */
 
 static void
 append_composite_glyph (struct it *it)
@@ -28227,7 +28226,7 @@ produce_glyphless_glyph (struct it *it, bool for_no_font, Lisp_Object acronym)
    for an overview of struct it.  */
 
 void
-x_produce_glyphs (struct it *it)
+gui_produce_glyphs (struct it *it)
 {
   int extra_line_spacing = it->extra_line_spacing;
 
@@ -28995,7 +28994,7 @@ x_produce_glyphs (struct it *it)
    being updated, and UPDATED_AREA is the area of that row being updated.  */
 
 void
-x_write_glyphs (struct window *w, struct glyph_row *updated_row,
+gui_write_glyphs (struct window *w, struct glyph_row *updated_row,
 		struct glyph *start, enum glyph_row_area updated_area, int len)
 {
   int x, hpos, chpos = w->phys_cursor.hpos;
@@ -29039,7 +29038,7 @@ x_write_glyphs (struct window *w, struct glyph_row *updated_row,
    Insert LEN glyphs from START at the nominal cursor position.  */
 
 void
-x_insert_glyphs (struct window *w, struct glyph_row *updated_row,
+gui_insert_glyphs (struct window *w, struct glyph_row *updated_row,
 		 struct glyph *start, enum glyph_row_area updated_area, int len)
 {
   struct frame *f;
@@ -29096,7 +29095,7 @@ x_insert_glyphs (struct window *w, struct glyph_row *updated_row,
    updated window W.  TO_X == -1 means clear to the end of this area.  */
 
 void
-x_clear_end_of_line (struct window *w, struct glyph_row *updated_row,
+gui_clear_end_of_line (struct window *w, struct glyph_row *updated_row,
 		     enum glyph_row_area updated_area, int to_x)
 {
   struct frame *f;
@@ -29483,7 +29482,7 @@ notice_overwritten_cursor (struct window *w, enum glyph_row_area area,
    with respect to the overlapping part OVERLAPS.  */
 
 void
-x_fix_overlapping_area (struct window *w, struct glyph_row *row,
+gui_fix_overlapping_area (struct window *w, struct glyph_row *row,
 			enum glyph_row_area area, int overlaps)
 {
   int i, x;
@@ -29562,12 +29561,12 @@ draw_phys_cursor_glyph (struct window *w, struct glyph_row *row,
 
 	  if (row > w->current_matrix->rows
 	      && MATRIX_ROW_OVERLAPS_SUCC_P (row - 1))
-	    x_fix_overlapping_area (w, row - 1, TEXT_AREA,
+	    gui_fix_overlapping_area (w, row - 1, TEXT_AREA,
 				    OVERLAPS_ERASED_CURSOR);
 
 	  if (MATRIX_ROW_BOTTOM_Y (row) < window_text_bottom_y (w)
 	      && MATRIX_ROW_OVERLAPS_PRED_P (row + 1))
-	    x_fix_overlapping_area (w, row + 1, TEXT_AREA,
+	    gui_fix_overlapping_area (w, row + 1, TEXT_AREA,
 				    OVERLAPS_ERASED_CURSOR);
 	}
     }
@@ -29857,7 +29856,7 @@ update_cursor_in_window_tree (struct window *w, bool on_p)
    Don't change the cursor's position.  */
 
 void
-x_update_cursor (struct frame *f, bool on_p)
+gui_update_cursor (struct frame *f, bool on_p)
 {
   update_cursor_in_window_tree (XWINDOW (f->root_window), on_p);
 }
@@ -29869,7 +29868,7 @@ x_update_cursor (struct frame *f, bool on_p)
    is about to be rewritten.  */
 
 void
-x_clear_cursor (struct window *w)
+gui_clear_cursor (struct window *w)
 {
   if (FRAME_VISIBLE_P (XFRAME (w->frame)) && w->phys_cursor_on_p)
     update_window_cursor (w, false);
@@ -31897,7 +31896,7 @@ note_mouse_highlight (struct frame *f, int x, int y)
    functions to ensure the mouse-highlight is off.  */
 
 void
-x_clear_window_mouse_face (struct window *w)
+gui_clear_window_mouse_face (struct window *w)
 {
   Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (XFRAME (w->frame));
   Lisp_Object window;
@@ -32041,13 +32040,13 @@ expose_overlaps (struct window *w,
 
 	row->clip = r;
 	if (row->used[LEFT_MARGIN_AREA])
-	  x_fix_overlapping_area (w, row, LEFT_MARGIN_AREA, OVERLAPS_BOTH);
+	  gui_fix_overlapping_area (w, row, LEFT_MARGIN_AREA, OVERLAPS_BOTH);
 
 	if (row->used[TEXT_AREA])
-	  x_fix_overlapping_area (w, row, TEXT_AREA, OVERLAPS_BOTH);
+	  gui_fix_overlapping_area (w, row, TEXT_AREA, OVERLAPS_BOTH);
 
 	if (row->used[RIGHT_MARGIN_AREA])
-	  x_fix_overlapping_area (w, row, RIGHT_MARGIN_AREA, OVERLAPS_BOTH);
+	  gui_fix_overlapping_area (w, row, RIGHT_MARGIN_AREA, OVERLAPS_BOTH);
 	row->clip = NULL;
       }
 }
@@ -32076,7 +32075,7 @@ phys_cursor_in_rect_p (struct window *w, XRectangle *r)
       cr.y = row->y;
       cr.width = WINDOW_RIGHT_FRINGE_WIDTH (w);
       cr.height = row->height;
-      return x_intersect_rectangles (&cr, r, &result);
+      return gui_intersect_rectangles (&cr, r, &result);
     }
 
   cursor_glyph = get_phys_cursor_glyph (w);
@@ -32090,7 +32089,7 @@ phys_cursor_in_rect_p (struct window *w, XRectangle *r)
       cr.height = w->phys_cursor_height;
       /* ++KFS: W32 version used W32-specific IntersectRect here, but
 	 I assume the effect is the same -- and this is portable.  */
-      return x_intersect_rectangles (&cr, r, &result);
+      return gui_intersect_rectangles (&cr, r, &result);
     }
   /* If we don't understand the format, pretend we're not in the hot-spot.  */
   return false;
@@ -32102,7 +32101,7 @@ phys_cursor_in_rect_p (struct window *w, XRectangle *r)
    have vertical scroll bars.  */
 
 void
-x_draw_vertical_border (struct window *w)
+gui_draw_vertical_border (struct window *w)
 {
   struct frame *f = XFRAME (WINDOW_FRAME (w));
 
@@ -32153,7 +32152,7 @@ x_draw_vertical_border (struct window *w)
 /* Draw window dividers for window W.  */
 
 void
-x_draw_right_divider (struct window *w)
+gui_draw_right_divider (struct window *w)
 {
   struct frame *f = WINDOW_XFRAME (w);
 
@@ -32179,7 +32178,7 @@ x_draw_right_divider (struct window *w)
 }
 
 static void
-x_draw_bottom_divider (struct window *w)
+gui_draw_bottom_divider (struct window *w)
 {
   struct frame *f = XFRAME (WINDOW_FRAME (w));
 
@@ -32244,7 +32243,7 @@ expose_window (struct window *w, XRectangle *fr)
   wr.width = WINDOW_PIXEL_WIDTH (w);
   wr.height = WINDOW_PIXEL_HEIGHT (w);
 
-  if (x_intersect_rectangles (fr, &wr, &r))
+  if (gui_intersect_rectangles (fr, &wr, &r))
     {
       int yb = window_text_bottom_y (w);
       struct glyph_row *row;
@@ -32261,7 +32260,7 @@ expose_window (struct window *w, XRectangle *fr)
       bool cursor_cleared_p = (!w->pseudo_window_p
 			       && phys_cursor_in_rect_p (w, &r));
       if (cursor_cleared_p)
-	x_clear_cursor (w);
+	gui_clear_cursor (w);
 
       /* If the row containing the cursor extends face to end of line,
 	 then expose_area might overwrite the cursor outside the
@@ -32354,12 +32353,12 @@ expose_window (struct window *w, XRectangle *fr)
 
 	  /* Draw border between windows.  */
 	  if (WINDOW_RIGHT_DIVIDER_WIDTH (w))
-	    x_draw_right_divider (w);
+	    gui_draw_right_divider (w);
 	  else
-	    x_draw_vertical_border (w);
+	    gui_draw_vertical_border (w);
 
 	  if (WINDOW_BOTTOM_DIVIDER_WIDTH (w))
-	    x_draw_bottom_divider (w);
+	    gui_draw_bottom_divider (w);
 
 	  /* Turn the cursor on again.  */
 	  if (cursor_cleared_p
@@ -32493,7 +32492,7 @@ expose_frame (struct frame *f, int x, int y, int w, int h)
    empty.  */
 
 bool
-x_intersect_rectangles (XRectangle *r1, XRectangle *r2, XRectangle *result)
+gui_intersect_rectangles (XRectangle *r1, XRectangle *r2, XRectangle *result)
 {
   XRectangle *left, *right;
   XRectangle *upper, *lower;
diff --git a/src/xfns.c b/src/xfns.c
index f238a3daa1..2d703fb2db 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -1388,8 +1388,8 @@ x_set_cursor_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 
       if (FRAME_VISIBLE_P (f))
 	{
-	  x_update_cursor (f, false);
-	  x_update_cursor (f, true);
+	  gui_update_cursor (f, false);
+	  gui_update_cursor (f, true);
 	}
     }
 
@@ -4583,7 +4583,7 @@ x_get_monitor_for_frame (struct frame *f,
 
       if (mi->geom.width == 0) continue;
 
-      if (x_intersect_rectangles (&mi->geom, &frect, &res))
+      if (gui_intersect_rectangles (&mi->geom, &frect, &res))
         {
           a = res.width * res.height;
           if (a > area)
@@ -4712,7 +4712,7 @@ x_get_monitor_attributes_xinerama (struct x_display_info *dpyinfo)
       if (i == 0 && x_get_net_workarea (dpyinfo, &workarea_r))
 	{
 	  mi->work = workarea_r;
-	  if (! x_intersect_rectangles (&mi->geom, &mi->work, &mi->work))
+	  if (! gui_intersect_rectangles (&mi->geom, &mi->work, &mi->work))
 	    mi->work = mi->geom;
 	}
       else
@@ -4816,7 +4816,7 @@ x_get_monitor_attributes_xrandr (struct x_display_info *dpyinfo)
           if (i == primary && x_get_net_workarea (dpyinfo, &workarea_r))
             {
               mi->work= workarea_r;
-              if (! x_intersect_rectangles (&mi->geom, &mi->work, &mi->work))
+              if (! gui_intersect_rectangles (&mi->geom, &mi->work, &mi->work))
                 mi->work = mi->geom;
             }
           else
diff --git a/src/xterm.c b/src/xterm.c
index 1b0c2f5ec5..968ff165c5 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -1161,9 +1161,9 @@ x_update_window_end (struct window *w, bool cursor_on_p,
       if (draw_window_fringes (w, true))
 	{
 	  if (WINDOW_RIGHT_DIVIDER_WIDTH (w))
-	    x_draw_right_divider (w);
+	    gui_draw_right_divider (w);
 	  else
-	    x_draw_vertical_border (w);
+	    gui_draw_vertical_border (w);
 	}
 
       unblock_input ();
@@ -3069,7 +3069,7 @@ x_draw_image_foreground (struct glyph_string *s)
 	  image_rect.y = y;
 	  image_rect.width = s->slice.width;
 	  image_rect.height = s->slice.height;
-	  if (x_intersect_rectangles (&clip_rect, &image_rect, &r))
+	  if (gui_intersect_rectangles (&clip_rect, &image_rect, &r))
             x_composite_image (s, FRAME_X_DRAWABLE (s->f),
 			       s->slice.x + r.x - x, s->slice.y + r.y - y,
                                r.x, r.y, r.width, r.height);
@@ -3083,7 +3083,7 @@ x_draw_image_foreground (struct glyph_string *s)
 	  image_rect.y = y;
 	  image_rect.width = s->slice.width;
 	  image_rect.height = s->slice.height;
-	  if (x_intersect_rectangles (&clip_rect, &image_rect, &r))
+	  if (gui_intersect_rectangles (&clip_rect, &image_rect, &r))
             x_composite_image (s, FRAME_X_DRAWABLE (s->f), s->slice.x + r.x - x, s->slice.y + r.y - y,
                                r.x, r.y, r.width, r.height);
 
@@ -3579,7 +3579,7 @@ x_draw_underwave (struct glyph_string *s)
   wave_clip.height = wave_height;
   get_glyph_string_clip_rect (s, &string_clip);
 
-  if (!x_intersect_rectangles (&wave_clip, &string_clip, &final_clip))
+  if (!gui_intersect_rectangles (&wave_clip, &string_clip, &final_clip))
     return;
 
   XSetClipRectangles (s->display, s->gc, 0, 0, &final_clip, 1, Unsorted);
@@ -4310,7 +4310,7 @@ x_scroll_run (struct window *w, struct run *run)
   block_input ();
 
   /* Cursor off.  Will be switched on again in x_update_window_end.  */
-  x_clear_cursor (w);
+  gui_clear_cursor (w);
 
 #ifdef USE_CAIRO
   if (FRAME_CR_CONTEXT (f))
@@ -4372,7 +4372,7 @@ frame_highlight (struct frame *f)
 		    f->output_data.x->border_pixel);
   x_uncatch_errors ();
   unblock_input ();
-  x_update_cursor (f, true);
+  gui_update_cursor (f, true);
   x_set_frame_alpha (f);
 }
 
@@ -4390,7 +4390,7 @@ frame_unhighlight (struct frame *f)
 			  f->output_data.x->border_tile);
   x_uncatch_errors ();
   unblock_input ();
-  x_update_cursor (f, true);
+  gui_update_cursor (f, true);
   x_set_frame_alpha (f);
 }
 
@@ -13079,18 +13079,18 @@ x_activate_timeout_atimer (void)
 static struct redisplay_interface x_redisplay_interface =
   {
     x_frame_parm_handlers,
-    x_produce_glyphs,
-    x_write_glyphs,
-    x_insert_glyphs,
-    x_clear_end_of_line,
+    gui_produce_glyphs,
+    gui_write_glyphs,
+    gui_insert_glyphs,
+    gui_clear_end_of_line,
     x_scroll_run,
     x_after_update_window_line,
     x_update_window_begin,
     x_update_window_end,
     x_flip_and_flush,
-    x_clear_window_mouse_face,
-    x_get_glyph_overhangs,
-    x_fix_overlapping_area,
+    gui_clear_window_mouse_face,
+    gui_get_glyph_overhangs,
+    gui_fix_overlapping_area,
     x_draw_fringe_bitmap,
 #ifdef USE_CAIRO
     x_cr_define_fringe_bitmap,
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 68+ messages in thread

* Re: Renaming non-X x_* procedures in xdisp.c (and elsewhere)
  2019-03-23 17:39       ` Alex
  2019-03-23 17:54         ` Alex
@ 2019-03-23 18:16         ` Eli Zaretskii
  2019-03-23 18:55           ` Alex
  1 sibling, 1 reply; 68+ messages in thread
From: Eli Zaretskii @ 2019-03-23 18:16 UTC (permalink / raw)
  To: Alex; +Cc: eggert, emacs-devel

> From: Alex <agrambot@gmail.com>
> Cc: Paul Eggert <eggert@cs.ucla.edu>,  emacs-devel@gnu.org
> Date: Sat, 23 Mar 2019 11:39:49 -0600
> 
> > As a rule of thumb that is 99% true, everything in xdisp.c is generic,
> > i.e. independent of the terminal-specific implementation.  The
> > terminal-dependent stuff is in xterm.c/xfns.c (for X),
> > w32term.c/w32fns.c (for w32), nsterm.m/nsfns.m (for NS), and term.c
> > (for TTY).
> 
> Which the naming scheme should reflect, IMO. This includes the presence
> of x_* procedures in the NS/W32 code that Stefan mentioned.

But what you propose in the patch stops short of that goal, it just
renames the functions that are explicitly called from xdisp.c.  It
doesn't rename x_* functions in files unrelated to X.  I'm not sure
this partial renaming is worth the trouble.

> P.S. Should x_clear_window_mouse_face instead be renamed to
> clear_window_mouse_face since it doesn't depend on HAVE_WINDOW_SYSTEM
> like the others do?

It does depend on the window-system, albeit somewhat subtly: it is
only invoked for some terminal types.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Renaming non-X x_* procedures in xdisp.c (and elsewhere)
  2019-03-23 18:16         ` Eli Zaretskii
@ 2019-03-23 18:55           ` Alex
  2019-03-23 19:32             ` Eli Zaretskii
  0 siblings, 1 reply; 68+ messages in thread
From: Alex @ 2019-03-23 18:55 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: eggert, emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Alex <agrambot@gmail.com>
>> Cc: Paul Eggert <eggert@cs.ucla.edu>,  emacs-devel@gnu.org
>> Date: Sat, 23 Mar 2019 11:39:49 -0600
>> 
>> > As a rule of thumb that is 99% true, everything in xdisp.c is generic,
>> > i.e. independent of the terminal-specific implementation.  The
>> > terminal-dependent stuff is in xterm.c/xfns.c (for X),
>> > w32term.c/w32fns.c (for w32), nsterm.m/nsfns.m (for NS), and term.c
>> > (for TTY).
>> 
>> Which the naming scheme should reflect, IMO. This includes the presence
>> of x_* procedures in the NS/W32 code that Stefan mentioned.
>
> But what you propose in the patch stops short of that goal, it just
> renames the functions that are explicitly called from xdisp.c.  It
> doesn't rename x_* functions in files unrelated to X.  I'm not sure
> this partial renaming is worth the trouble.

It can be considered as just a step towards that goal. As I mentioned, I
don't see why all the work has to happen at the same time. IMO the RIF
x_* and the multiply-defined x_* are separate, even if related, issues;
the RIF x_* being much easier to solve (as demonstrated).

If you're referring to another class of x_* procedures to be renamed,
then those can be done in a later commit.

>> P.S. Should x_clear_window_mouse_face instead be renamed to
>> clear_window_mouse_face since it doesn't depend on HAVE_WINDOW_SYSTEM
>> like the others do?
>
> It does depend on the window-system, albeit somewhat subtly: it is
> only invoked for some terminal types.

If it's not invoked for non-GUI Emacs, then the gui_* prefix would
indeed be appropriate.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Renaming non-X x_* procedures in xdisp.c (and elsewhere)
  2019-03-23 18:55           ` Alex
@ 2019-03-23 19:32             ` Eli Zaretskii
  2019-03-24  4:14               ` Alex
  0 siblings, 1 reply; 68+ messages in thread
From: Eli Zaretskii @ 2019-03-23 19:32 UTC (permalink / raw)
  To: Alex; +Cc: eggert, emacs-devel

> From: Alex <agrambot@gmail.com>
> Cc: eggert@cs.ucla.edu,  emacs-devel@gnu.org
> Date: Sat, 23 Mar 2019 12:55:26 -0600
> 
> > But what you propose in the patch stops short of that goal, it just
> > renames the functions that are explicitly called from xdisp.c.  It
> > doesn't rename x_* functions in files unrelated to X.  I'm not sure
> > this partial renaming is worth the trouble.
> 
> It can be considered as just a step towards that goal.  As I mentioned, I
> don't see why all the work has to happen at the same time. IMO the RIF
> x_* and the multiply-defined x_* are separate, even if related, issues;
> the RIF x_* being much easier to solve (as demonstrated).

I tend to prefer to do it in one go.  The reason is that in the past
we've seen once or twice someone who made such initial steps towards a
goal that we considered important, but then didn't follow up with the
rest, and we were left with a slightly less readable and/or slightly
less familiar code, and no real gains.  So now I'm less inclined to
support such partial steps which in themselves have little gains to
offer.

Of course, it's possible to accumulate the changes piecemeal on a
separate branch, if you want to work on this in several increments,
I'm only talking about landing them on master.

> If you're referring to another class of x_* procedures to be renamed,
> then those can be done in a later commit.

I think I see them all as a single class.  That some of them are used
through redisplay_interface is not an important distinction, IMO.

> >> P.S. Should x_clear_window_mouse_face instead be renamed to
> >> clear_window_mouse_face since it doesn't depend on HAVE_WINDOW_SYSTEM
> >> like the others do?
> >
> > It does depend on the window-system, albeit somewhat subtly: it is
> > only invoked for some terminal types.
> 
> If it's not invoked for non-GUI Emacs, then the gui_* prefix would
> indeed be appropriate.

When the mouse is involved, the separation between GUI and non-GUI
tends to be blurry.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Renaming non-X x_* procedures in xdisp.c (and elsewhere)
  2019-03-23 19:32             ` Eli Zaretskii
@ 2019-03-24  4:14               ` Alex
  0 siblings, 0 replies; 68+ messages in thread
From: Alex @ 2019-03-24  4:14 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:


> I tend to prefer to do it in one go.  The reason is that in the past
> we've seen once or twice someone who made such initial steps towards a
> goal that we considered important, but then didn't follow up with the
> rest, and we were left with a slightly less readable and/or slightly
> less familiar code, and no real gains.  So now I'm less inclined to
> support such partial steps which in themselves have little gains to
> offer.

I see the tendency to prefer so, but I disagree that this would make the
code less readable or meaningfully less familiar.

>> If you're referring to another class of x_* procedures to be renamed,
>> then those can be done in a later commit.
>
> I think I see them all as a single class.  That some of them are used
> through redisplay_interface is not an important distinction, IMO.

I agree that it's not the RIF aspect that's the distinguishing factor; I
should have said "x_* procedures in the same class of x_* procedures as
those in my patch".

IMO renaming involving trivial changes (ones covered by my patch), and
renaming involving branching functionality to different windowing
systems are two distinct classes.

I'll see about making a scratch branch for the other x_* procedures.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Renaming non-X x_* procedures in xdisp.c (and elsewhere)
  2019-03-23 16:59     ` Eli Zaretskii
  2019-03-23 17:39       ` Alex
@ 2019-03-24  4:50       ` Alex
  2019-03-24  5:39         ` Eli Zaretskii
  1 sibling, 1 reply; 68+ messages in thread
From: Alex @ 2019-03-24  4:50 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Paul Eggert, emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

> I don't have strong opinions about this.  Aside of making the
> archeology and forensics harder, renaming will get in the way of my
> personal acquaintance with the code in xdisp.c and dispnew.c, but that
> alone doesn't sound like a reason to object to the change.  It will
> probably also require a lot more ugly #ifdef's in the mainline code
> (or calling through function pointers, not sure which is worse), and
> quite a few changes in the headers to go with that.

How about using something like the following? It's ugly, but at least
it doesn't ruin the rest of the code.

#ifdef HAVE_X_WINDOWS
#define CASE_X(proc, ...)                       \
  case output_x_window:                         \
  x_ ## proc (__VAR_ARGS__)
#define CASE_X_VAR(var, proc, ...)              \
  case output_x_window:                         \
  var = x_ ## proc (__VA_ARGS__)
#else
#define CASE_X(...)
#define CASE_X_VAR(...)
#endif

#ifdef HAVE_NTGUI
#define CASE_W32(proc, ...)                     \
  case output_w32:                              \
  w32_ ## proc (__VA_ARGS__)
#define CASE_W32_VAR(var, proc, ...)            \
  case output_w32:                              \
  var = w32_ ## proc (__VA_ARGS__)
#else
#define CASE_W32(...)
#define CASE_W32_VAR(...)
#endif

#ifdef HAVE_NS
#define CASE_NS(proc, ...)                      \
  case output_ns:                               \
  ns_ ## proc (__VA_ARGS__)
#define CASE_NS_VAR(var, proc, ...)             \
  case output_ns:                               \
  var = ns_ ## proc (__VA_ARGS__)
#else
#define CASE_NS(...)
#define CASE_NS_VAR(...)
#endif

#define CALL_FOR_WS(f, proc, ...)               \
  switch ((f)->output_method)                   \
    {                                           \
      CASE_X (proc, __VA_ARGS__);               \
      CASE_W32 (proc, __VA_ARGS__);             \
      CASE_NS (proc, __VA_ARGS__);              \
    }

#define ASSIGN_FOR_WS(f, var, proc, ...)        \
  switch ((f)->output_method)                   \
    {                                           \
      CASE_X_VAR (var, proc, __VA_ARGS__);      \
      CASE_W32_VAR (var, proc, __VA_ARGS__);    \
      CASE_NS_VAR (var, proc, __VA_ARGS__);     \
    }



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Renaming non-X x_* procedures in xdisp.c (and elsewhere)
  2019-03-24  4:50       ` Alex
@ 2019-03-24  5:39         ` Eli Zaretskii
  2019-03-24 15:05           ` Alex
  0 siblings, 1 reply; 68+ messages in thread
From: Eli Zaretskii @ 2019-03-24  5:39 UTC (permalink / raw)
  To: Alex; +Cc: Paul Eggert, emacs-devel

On March 24, 2019 6:50:45 AM GMT+02:00, Alex <agrambot@gmail.com> wrote:
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> > I don't have strong opinions about this.  Aside of making the
> > archeology and forensics harder, renaming will get in the way of my
> > personal acquaintance with the code in xdisp.c and dispnew.c, but
> that
> > alone doesn't sound like a reason to object to the change.  It will
> > probably also require a lot more ugly #ifdef's in the mainline code
> > (or calling through function pointers, not sure which is worse), and
> > quite a few changes in the headers to go with that.
> 
> How about using something like the following? It's ugly, but at least
> it doesn't ruin the rest of the code.
> 
> #ifdef HAVE_X_WINDOWS
> #define CASE_X(proc, ...)                       \
>   case output_x_window:                         \
>   x_ ## proc (__VAR_ARGS__)
> #define CASE_X_VAR(var, proc, ...)              \
>   case output_x_window:                         \
>   var = x_ ## proc (__VA_ARGS__)
> #else
> #define CASE_X(...)
> #define CASE_X_VAR(...)
> #endif
> 
> #ifdef HAVE_NTGUI
> #define CASE_W32(proc, ...)                     \
>   case output_w32:                              \
>   w32_ ## proc (__VA_ARGS__)
> #define CASE_W32_VAR(var, proc, ...)            \
>   case output_w32:                              \
>   var = w32_ ## proc (__VA_ARGS__)
> #else
> #define CASE_W32(...)
> #define CASE_W32_VAR(...)
> #endif
> 
> #ifdef HAVE_NS
> #define CASE_NS(proc, ...)                      \
>   case output_ns:                               \
>   ns_ ## proc (__VA_ARGS__)
> #define CASE_NS_VAR(var, proc, ...)             \
>   case output_ns:                               \
>   var = ns_ ## proc (__VA_ARGS__)
> #else
> #define CASE_NS(...)
> #define CASE_NS_VAR(...)
> #endif
> 
> #define CALL_FOR_WS(f, proc, ...)               \
>   switch ((f)->output_method)                   \
>     {                                           \
>       CASE_X (proc, __VA_ARGS__);               \
>       CASE_W32 (proc, __VA_ARGS__);             \
>       CASE_NS (proc, __VA_ARGS__);              \
>     }
> 
> #define ASSIGN_FOR_WS(f, var, proc, ...)        \
>   switch ((f)->output_method)                   \
>     {                                           \
>       CASE_X_VAR (var, proc, __VA_ARGS__);      \
>       CASE_W32_VAR (var, proc, __VA_ARGS__);    \
>       CASE_NS_VAR (var, proc, __VA_ARGS__);     \
>     }

Where would something like that be needed?  Can you point out a couple of places in the code where we should use this?



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Renaming non-X x_* procedures in xdisp.c (and elsewhere)
  2019-03-24  5:39         ` Eli Zaretskii
@ 2019-03-24 15:05           ` Alex
  2019-03-24 16:01             ` Yuri Khan
  2019-03-24 16:27             ` Eli Zaretskii
  0 siblings, 2 replies; 68+ messages in thread
From: Alex @ 2019-03-24 15:05 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Paul Eggert, emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

> Where would something like that be needed? Can you point out a couple
> of places in the code where we should use this?

This would be used wherever some generic procedure needed to call a
windowing system-specific procedure. Currently this is done by all
backends defining the same x_* procedure that the generic procedure
uses. This is a method to avoid this name clash (and also getting a step
closer to the goal of using multiple backends simultaneously).

For example, in frame.c (keep_ratio), replace the x_set_offset call
with:

CALL_FOR_WS (f, set_offset, f, pos_x, pos_y, -1)

In frame.c (adjust_frame_size), replace x_set_window_size with:

CALL_FOR_WS (f, set_window_size, f, 0, new_text_width, new_text_height, 1)

In frame.c (do_switch_frame), replace x_get_focus_frame with:

ASSIGN_FOR_WS (f, xfocus, get_focus_frame, f)

I believe these two macros should cover at least most cases, but any
remaining ones should be able to be covered with a similar macro or by
manually retrieving the current frame and then using one of these
macros.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Renaming non-X x_* procedures in xdisp.c (and elsewhere)
  2019-03-24 15:05           ` Alex
@ 2019-03-24 16:01             ` Yuri Khan
  2019-03-24 16:13               ` Eli Zaretskii
  2019-03-24 16:27             ` Eli Zaretskii
  1 sibling, 1 reply; 68+ messages in thread
From: Yuri Khan @ 2019-03-24 16:01 UTC (permalink / raw)
  To: Alex; +Cc: Eli Zaretskii, Paul Eggert, Emacs developers

On Sun, Mar 24, 2019 at 10:07 PM Alex <agrambot@gmail.com> wrote:

> This would be used wherever some generic procedure needed to call a
> windowing system-specific procedure.

Come on, this is a typical and solved design problem. The usual
solution is called polymorphism or virtual methods, does not require a
(macro-masked) switch statement at each call site, is quite possible
in C and not only OOP languages, and is used in Emacs in at least a
few places (terminals come to mind).

1: The generic part defines function pointer types for each
WS-specific function.
2: The generic part also defines a structure type whose members are of
function pointer types defined in step 1.
3: Each WS-specific part defines implementations for each WS-specific
function, with its own name prefix, following signatures defined in
step 1.
4: Each WS-specific part defines a global structure of type defined in
step 2 and fills it out with pointers to implementations defined in
step 3.
5: The structure defined in step 4 is either global (for a
single-windowing-system build) or gets passed around (for a
multiple-window-system build).



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Renaming non-X x_* procedures in xdisp.c (and elsewhere)
  2019-03-24 16:01             ` Yuri Khan
@ 2019-03-24 16:13               ` Eli Zaretskii
  2019-03-24 17:03                 ` Eli Zaretskii
  0 siblings, 1 reply; 68+ messages in thread
From: Eli Zaretskii @ 2019-03-24 16:13 UTC (permalink / raw)
  To: Yuri Khan; +Cc: eggert, agrambot, emacs-devel

> From: Yuri Khan <yurivkhan@gmail.com>
> Date: Sun, 24 Mar 2019 23:01:09 +0700
> Cc: Eli Zaretskii <eliz@gnu.org>, Paul Eggert <eggert@cs.ucla.edu>, 
> 	Emacs developers <emacs-devel@gnu.org>
> 
> 1: The generic part defines function pointer types for each
> WS-specific function.
> 2: The generic part also defines a structure type whose members are of
> function pointer types defined in step 1.
> 3: Each WS-specific part defines implementations for each WS-specific
> function, with its own name prefix, following signatures defined in
> step 1.
> 4: Each WS-specific part defines a global structure of type defined in
> step 2 and fills it out with pointers to implementations defined in
> step 3.
> 5: The structure defined in step 4 is either global (for a
> single-windowing-system build) or gets passed around (for a
> multiple-window-system build).

I think you have described redisplay_interface.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Renaming non-X x_* procedures in xdisp.c (and elsewhere)
  2019-03-24 15:05           ` Alex
  2019-03-24 16:01             ` Yuri Khan
@ 2019-03-24 16:27             ` Eli Zaretskii
  2019-03-24 18:30               ` Alex
  1 sibling, 1 reply; 68+ messages in thread
From: Eli Zaretskii @ 2019-03-24 16:27 UTC (permalink / raw)
  To: Alex; +Cc: eggert, emacs-devel

> From: Alex <agrambot@gmail.com>
> Cc: Paul Eggert <eggert@cs.ucla.edu>, emacs-devel@gnu.org
> Date: Sun, 24 Mar 2019 09:05:00 -0600
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> > Where would something like that be needed? Can you point out a couple
> > of places in the code where we should use this?
> 
> This would be used wherever some generic procedure needed to call a
> windowing system-specific procedure. Currently this is done by all
> backends defining the same x_* procedure that the generic procedure
> uses. This is a method to avoid this name clash (and also getting a step
> closer to the goal of using multiple backends simultaneously).
> 
> For example, in frame.c (keep_ratio), replace the x_set_offset call
> with:
> 
> CALL_FOR_WS (f, set_offset, f, pos_x, pos_y, -1)
> 
> In frame.c (adjust_frame_size), replace x_set_window_size with:
> 
> CALL_FOR_WS (f, set_window_size, f, 0, new_text_width, new_text_height, 1)

OK, thanks.

AFAICS, the vast majority of x_* functions defined in w32*.c and ns*.m
are either static or used from other w32*.c/ns*.m files, i.e. by the
same window-system back-end.  Those can be simply renamed into w32_*
and ns_*, and that's it.

The remaining small minority should probably simply be added to
redisplay_interface, and used as we do with the other functions
there.  Some of those are not literally "for redisplay", but I don't
think it matters too much.

In order for a function to be able to call through FRAME_RIF, it must
have access to the appropriate 'struct frame' pointer.  So my
suggestion is to audit all the 'extern' x_* functions which have such
multiple implementations, and see which ones have callers that don't
have access to the corresponding frame.  We then need to see how to
solve that (hopefully, in each such case we will find a way to get at
the frame somehow).

The only remaining problem that I could spot is that there's a small
number of Lisp primitives named x-SOMETHING, which are implemented by
each GUI backend.  Example: x-display-pixel-width.  I think for now we
should leave those primitives alone without renaming, and only change
their implementation to call the x_*, w32_*, or ns_* functions for
each back-end.  Renaming of these primitives can be done as a separate
step, and we will have to decide on the name pattern (something like
"xw-SOMETHING, perhaps?), and add obsolete aliases for backward
compatibility.

Are there any other issues related to this that I missed?

Thanks for working on this.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Renaming non-X x_* procedures in xdisp.c (and elsewhere)
  2019-03-24 16:13               ` Eli Zaretskii
@ 2019-03-24 17:03                 ` Eli Zaretskii
  0 siblings, 0 replies; 68+ messages in thread
From: Eli Zaretskii @ 2019-03-24 17:03 UTC (permalink / raw)
  To: yurivkhan; +Cc: emacs-devel

> Date: Sun, 24 Mar 2019 18:13:12 +0200
> From: Eli Zaretskii <eliz@gnu.org>
> Cc: eggert@cs.ucla.edu, agrambot@gmail.com, emacs-devel@gnu.org
> 
> I think you have described redisplay_interface.

And beyond that, we shouldn't assume that everyone here who tries
their hand in working on the C sources is an experienced C
programmer.  It should be possible to describe programming techniques
without making it sound as if everyone and their grandma should be
familiar with those techniques.

Thanks.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Renaming non-X x_* procedures in xdisp.c (and elsewhere)
  2019-03-24 16:27             ` Eli Zaretskii
@ 2019-03-24 18:30               ` Alex
  2019-03-24 18:48                 ` Eli Zaretskii
  0 siblings, 1 reply; 68+ messages in thread
From: Alex @ 2019-03-24 18:30 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

> AFAICS, the vast majority of x_* functions defined in w32*.c and ns*.m
> are either static or used from other w32*.c/ns*.m files, i.e. by the
> same window-system back-end.  Those can be simply renamed into w32_*
> and ns_*, and that's it.

Sorry, I thought that most/all of the x_* were named that way due to
being used in generic places like image.c and frame.c since I
encountered a good few of them in those two files, but I guess it's good
that I was wrong here. I'll handle those first.

> The remaining small minority should probably simply be added to
> redisplay_interface, and used as we do with the other functions
> there.  Some of those are not literally "for redisplay", but I don't
> think it matters too much.

I would find it confusing for procedures not used for redisplay to be
used in the RIF. If there turns out to be a sizeable group of related
x_* procedures, what about adding a separate set of function pointers
for them?

> The only remaining problem that I could spot is that there's a small
> number of Lisp primitives named x-SOMETHING, which are implemented by
> each GUI backend.  Example: x-display-pixel-width.  I think for now we
> should leave those primitives alone without renaming, and only change
> their implementation to call the x_*, w32_*, or ns_* functions for
> each back-end.  Renaming of these primitives can be done as a separate
> step, and we will have to decide on the name pattern (something like
> "xw-SOMETHING, perhaps?), and add obsolete aliases for backward
> compatibility.

IMO it would be nicer to get rid of the `x' entirely, and go for `gui'
as the generic prefix, and just `ns' and `w32' as the backend prefixes.

Where would be the best place to add the obsolete aliases? For example,
I'm not sure the best place to put the obsolete call for
x-stretch-cursor (now gui-stretch-cursor).

> Are there any other issues related to this that I missed?

I noticed that several procedures in frame.c contained this comment:

/* I think this should be done with a hook.  */

Which seems to be from 1993. Do you agree with this? Several of the x_*
could be turned into these hooks.

P.S. I happen to have some code that refactors the tooltip code in
xfns.c and w32fns.c (nsfns.c's is a bit too different, unfortunately)
into generic procedures that call out to backend procedures. I figured
that it would be nicer to create a new generic file guifns.c to host
these generalizations rather than put them in a file like frame.c; would
you rather not have such a new file?



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Renaming non-X x_* procedures in xdisp.c (and elsewhere)
  2019-03-24 18:30               ` Alex
@ 2019-03-24 18:48                 ` Eli Zaretskii
  2019-03-25 19:21                   ` Alex
  0 siblings, 1 reply; 68+ messages in thread
From: Eli Zaretskii @ 2019-03-24 18:48 UTC (permalink / raw)
  To: Alex; +Cc: emacs-devel

> From: Alex <agrambot@gmail.com>
> Cc: emacs-devel@gnu.org
> Date: Sun, 24 Mar 2019 12:30:16 -0600
> 
> > The remaining small minority should probably simply be added to
> > redisplay_interface, and used as we do with the other functions
> > there.  Some of those are not literally "for redisplay", but I don't
> > think it matters too much.
> 
> I would find it confusing for procedures not used for redisplay to be
> used in the RIF. If there turns out to be a sizeable group of related
> x_* procedures, what about adding a separate set of function pointers
> for them?

Maybe you are right.  How about making a list of those functions
first?  When I looked at them, my impression was that most of them
_are_ related to display, but maybe I was wrong.  We can decide once
we see the list.

> > The only remaining problem that I could spot is that there's a small
> > number of Lisp primitives named x-SOMETHING, which are implemented by
> > each GUI backend.  Example: x-display-pixel-width.  I think for now we
> > should leave those primitives alone without renaming, and only change
> > their implementation to call the x_*, w32_*, or ns_* functions for
> > each back-end.  Renaming of these primitives can be done as a separate
> > step, and we will have to decide on the name pattern (something like
> > "xw-SOMETHING, perhaps?), and add obsolete aliases for backward
> > compatibility.
> 
> IMO it would be nicer to get rid of the `x' entirely, and go for `gui'
> as the generic prefix, and just `ns' and `w32' as the backend prefixes.

The xw-* thing has a precedent, though.  We use gui- for selections
and such likes, but xw- for the other kind.

> Where would be the best place to add the obsolete aliases?

lisp/term/common-win.el, perhaps?

> I noticed that several procedures in frame.c contained this comment:
> 
> /* I think this should be done with a hook.  */
> 
> Which seems to be from 1993. Do you agree with this? Several of the x_*
> could be turned into these hooks.

Almost all of them are x_* functions which are being taken care here
anyway.  The 2 remaining ones are related to moving the mouse pointer,
and should probably be handled in the same manner.

> P.S. I happen to have some code that refactors the tooltip code in
> xfns.c and w32fns.c (nsfns.c's is a bit too different, unfortunately)
> into generic procedures that call out to backend procedures. I figured
> that it would be nicer to create a new generic file guifns.c to host
> these generalizations rather than put them in a file like frame.c; would
> you rather not have such a new file?

I think frame.c is a better place.  That file is not too large, so
adding a couple of functions to its would be okay.  Tooltips are
frames, after all.

Thanks.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Renaming non-X x_* procedures in xdisp.c (and elsewhere)
  2019-03-24 18:48                 ` Eli Zaretskii
@ 2019-03-25 19:21                   ` Alex
  2019-03-30 10:07                     ` Eli Zaretskii
  0 siblings, 1 reply; 68+ messages in thread
From: Alex @ 2019-03-25 19:21 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

> Maybe you are right.  How about making a list of those functions
> first?  When I looked at them, my impression was that most of them
> _are_ related to display, but maybe I was wrong.  We can decide once
> we see the list.

Alright, I got most of the grunt work done. There are three left in
xdisp.c:

** x_clear_under_internal_border
** x_change_tool_bar_height
** x_implicitly_set_name

Here are those called in frame.{c, h}

** x_set_scroll_bar_default_{width, height}
** x_set_frame_alpha
** x_bitmap_icon
** x_new_font
** x_set_offset
** x_set_window_size
** x_focus_frame
** x_make_frame_(in)visible
** x_iconify_frame

This one is called in image.c:
** x_query_color(s)

This one is called in keyboard.c:
** x_get_keysym_name

I'm not sure what purpose x_get_keysym_name serves (see the comment in
nsterm.m's implementation).

>> IMO it would be nicer to get rid of the `x' entirely, and go for `gui'
>> as the generic prefix, and just `ns' and `w32' as the backend prefixes.
>
> The xw-* thing has a precedent, though.  We use gui- for selections
> and such likes, but xw- for the other kind.

It doesn't look as if there's much of a precedent though, since there
are only 4 xw- procedures, all related to colors.

Plus, it looks like most of the gui- prefixed procedures were (recently
-- 25.1) renamed from x- procedures, so using gui- for current x-
procedures would be consistent.

In any case, IMO xw- wouldn't be much better than the current situation;
I would assume it to stand for X Windows (does it not?).

>> Where would be the best place to add the obsolete aliases?
>
> lisp/term/common-win.el, perhaps?

Oh, I figured I couldn't use that because of the `pc' window system, but
it looks like that one doesn't set HAVE_WINDOW_SYSTEM, confusingly
enough.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Renaming non-X x_* procedures in xdisp.c (and elsewhere)
  2019-03-25 19:21                   ` Alex
@ 2019-03-30 10:07                     ` Eli Zaretskii
  2019-03-30 17:26                       ` Alex
  0 siblings, 1 reply; 68+ messages in thread
From: Eli Zaretskii @ 2019-03-30 10:07 UTC (permalink / raw)
  To: Alex; +Cc: emacs-devel

> From: Alex <agrambot@gmail.com>
> Cc: emacs-devel@gnu.org
> Date: Mon, 25 Mar 2019 13:21:22 -0600
> 
> Eli Zaretskii <eliz@gnu.org> writes:
> 
> > Maybe you are right.  How about making a list of those functions
> > first?  When I looked at them, my impression was that most of them
> > _are_ related to display, but maybe I was wrong.  We can decide once
> > we see the list.
> 
> Alright, I got most of the grunt work done.

Thanks (and apologies for not getting to respond earlier).

> There are three left in xdisp.c:
> 
> ** x_clear_under_internal_border
> ** x_change_tool_bar_height
> ** x_implicitly_set_name
> 
> Here are those called in frame.{c, h}
> 
> ** x_set_scroll_bar_default_{width, height}
> ** x_set_frame_alpha
> ** x_bitmap_icon
> ** x_new_font
> ** x_set_offset
> ** x_set_window_size
> ** x_focus_frame
> ** x_make_frame_(in)visible
> ** x_iconify_frame
> 
> This one is called in image.c:
> ** x_query_color(s)

So why do you prefer not to add this to redisplay_interface?

We could, of course, invent a new struct and a new macro, but we'd be
reinventing the FRAME_RIF stuff anyway: the result will most probably
look identical to FRAME_RIF, except for names.  Is that worth our
while?

> This one is called in keyboard.c:
> ** x_get_keysym_name

This one should simply be renamed without the x_ prefix, I think.

> I'm not sure what purpose x_get_keysym_name serves (see the comment in
> nsterm.m's implementation).

Let's leave that specific issue for another time for now.

> >> Where would be the best place to add the obsolete aliases?
> >
> > lisp/term/common-win.el, perhaps?
> 
> Oh, I figured I couldn't use that because of the `pc' window system, but
> it looks like that one doesn't set HAVE_WINDOW_SYSTEM, confusingly
> enough.

It's due to some ancient history: once upon a time, text terminals
couldn't use colors, menus, and the mouse, whereas the MSDOS port did
that from day one.

Thanks.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Renaming non-X x_* procedures in xdisp.c (and elsewhere)
  2019-03-30 10:07                     ` Eli Zaretskii
@ 2019-03-30 17:26                       ` Alex
  2019-03-30 17:40                         ` Eli Zaretskii
  0 siblings, 1 reply; 68+ messages in thread
From: Alex @ 2019-03-30 17:26 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Alex <agrambot@gmail.com>
>> Cc: emacs-devel@gnu.org
>> Date: Mon, 25 Mar 2019 13:21:22 -0600
>> 
>> There are three left in xdisp.c:
>> 
>> ** x_clear_under_internal_border
>> ** x_change_tool_bar_height
>> ** x_implicitly_set_name
>> 
>> Here are those called in frame.{c, h}
>> 
>> ** x_set_scroll_bar_default_{width, height}
>> ** x_set_frame_alpha
>> ** x_bitmap_icon
>> ** x_new_font
>> ** x_set_offset
>> ** x_set_window_size
>> ** x_focus_frame
>> ** x_make_frame_(in)visible
>> ** x_iconify_frame
>> 
>> This one is called in image.c:
>> ** x_query_color(s)
>
> So why do you prefer not to add this to redisplay_interface?

I just would be a bit confused by the association of some of those
procedures with redisplay. I would expect the procedures there to be
"closer" to the redisplay code, but I suppose I was imagining that there
was more of a difference here. There's also a (perhaps outdated) comment
in termhooks.h that says that redisplay_interface is window-based while
terminal hooks are frame-based.

I think that x_clear_under_internal_border is a good fit for the RIF in
any case.

> We could, of course, invent a new struct and a new macro, but we'd be
> reinventing the FRAME_RIF stuff anyway: the result will most probably
> look identical to FRAME_RIF, except for names.  Is that worth our
> while?

Probably not. I was thinking about the rest being terminal hooks,
though. WDYT?

>> This one is called in keyboard.c:
>> ** x_get_keysym_name
>
> This one should simply be renamed without the x_ prefix, I think.

That would still leave the issue of it making the code
single-backend-only. Though, I guess it's not going anywhere.


Should I take it that you are in agreement with the gui- prefix for the
Lisp side?



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Renaming non-X x_* procedures in xdisp.c (and elsewhere)
  2019-03-30 17:26                       ` Alex
@ 2019-03-30 17:40                         ` Eli Zaretskii
  2019-03-30 17:59                           ` Alex
  0 siblings, 1 reply; 68+ messages in thread
From: Eli Zaretskii @ 2019-03-30 17:40 UTC (permalink / raw)
  To: Alex; +Cc: emacs-devel

> From: Alex <agrambot@gmail.com>
> Cc: emacs-devel@gnu.org
> Date: Sat, 30 Mar 2019 11:26:43 -0600
> 
> > We could, of course, invent a new struct and a new macro, but we'd be
> > reinventing the FRAME_RIF stuff anyway: the result will most probably
> > look identical to FRAME_RIF, except for names.  Is that worth our
> > while?
> 
> Probably not. I was thinking about the rest being terminal hooks,
> though. WDYT?

Not sure what you mean by "terminal hooks".  They all accept a pointer
to a frame, no?

> >> This one is called in keyboard.c:
> >> ** x_get_keysym_name
> >
> > This one should simply be renamed without the x_ prefix, I think.
> 
> That would still leave the issue of it making the code
> single-backend-only. Though, I guess it's not going anywhere.

What do you mean by single-backend-only?  There will be several
implementations, one each for every backend.  It's not a catastrophe,
and I don't see how to solve it without ugly ifdef's or even more
complications.  Doesn't sound justified, as long as no one is working
on allowing the same session create frames on different
window-systems.

> Should I take it that you are in agreement with the gui- prefix for the
> Lisp side?

I guess it's as good as any other.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Renaming non-X x_* procedures in xdisp.c (and elsewhere)
  2019-03-30 17:40                         ` Eli Zaretskii
@ 2019-03-30 17:59                           ` Alex
  2019-03-30 18:55                             ` Eli Zaretskii
  0 siblings, 1 reply; 68+ messages in thread
From: Alex @ 2019-03-30 17:59 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Alex <agrambot@gmail.com>
>> Cc: emacs-devel@gnu.org
>> Date: Sat, 30 Mar 2019 11:26:43 -0600
>> 
>> > We could, of course, invent a new struct and a new macro, but we'd be
>> > reinventing the FRAME_RIF stuff anyway: the result will most probably
>> > look identical to FRAME_RIF, except for names.  Is that worth our
>> > while?
>> 
>> Probably not. I was thinking about the rest being terminal hooks,
>> though. WDYT?
>
> Not sure what you mean by "terminal hooks".  They all accept a pointer
> to a frame, no?

I meant being used through a function pointer in the terminal struct
rather than in the redisplay_interface struct.

>> That would still leave the issue of it making the code
>> single-backend-only. Though, I guess it's not going anywhere.
>
> What do you mean by single-backend-only?  There will be several
> implementations, one each for every backend.  It's not a catastrophe,
> and I don't see how to solve it without ugly ifdef's or even more
> complications.  Doesn't sound justified, as long as no one is working
> on allowing the same session create frames on different
> window-systems.

The same session and different window-system case was what I was
thinking about, but I agree that it can be put off until someone takes
up that issue.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Renaming non-X x_* procedures in xdisp.c (and elsewhere)
  2019-03-30 17:59                           ` Alex
@ 2019-03-30 18:55                             ` Eli Zaretskii
  2019-03-30 23:27                               ` Alex
  0 siblings, 1 reply; 68+ messages in thread
From: Eli Zaretskii @ 2019-03-30 18:55 UTC (permalink / raw)
  To: Alex; +Cc: emacs-devel

> From: Alex <agrambot@gmail.com>
> Cc: emacs-devel@gnu.org
> Date: Sat, 30 Mar 2019 11:59:08 -0600
> 
> >> Probably not. I was thinking about the rest being terminal hooks,
> >> though. WDYT?
> >
> > Not sure what you mean by "terminal hooks".  They all accept a pointer
> > to a frame, no?
> 
> I meant being used through a function pointer in the terminal struct
> rather than in the redisplay_interface struct.

Are you talking about the arguments these functions receive now?  If
so, which ones specifically get terminal struct pointers?

> >> That would still leave the issue of it making the code
> >> single-backend-only. Though, I guess it's not going anywhere.
> >
> > What do you mean by single-backend-only?  There will be several
> > implementations, one each for every backend.  It's not a catastrophe,
> > and I don't see how to solve it without ugly ifdef's or even more
> > complications.  Doesn't sound justified, as long as no one is working
> > on allowing the same session create frames on different
> > window-systems.
> 
> The same session and different window-system case was what I was
> thinking about, but I agree that it can be put off until someone takes
> up that issue.

OK, so we agree on that.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Renaming non-X x_* procedures in xdisp.c (and elsewhere)
  2019-03-30 18:55                             ` Eli Zaretskii
@ 2019-03-30 23:27                               ` Alex
  2019-03-31 14:52                                 ` Eli Zaretskii
  0 siblings, 1 reply; 68+ messages in thread
From: Alex @ 2019-03-30 23:27 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Alex <agrambot@gmail.com>
>> Cc: emacs-devel@gnu.org
>> Date: Sat, 30 Mar 2019 11:59:08 -0600
>> 
>> >> Probably not. I was thinking about the rest being terminal hooks,
>> >> though. WDYT?
>> >
>> > Not sure what you mean by "terminal hooks".  They all accept a pointer
>> > to a frame, no?
>> 
>> I meant being used through a function pointer in the terminal struct
>> rather than in the redisplay_interface struct.
>
> Are you talking about the arguments these functions receive now?  If
> so, which ones specifically get terminal struct pointers?

Sorry for not being clear -- by "being terminal hooks" I meant being put
in the definition of the terminal struct (in termhooks.h), rather than
the redisplay_interface struct in dispextern.h. That is, being used like
FRAME_TERMINAL (f)->some_hook rather than FRAME_RIF (f)->procedure.

It's not a practical difference -- I'd rather not put the procedures in
a counterintuitive place if there's an alternative.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Renaming non-X x_* procedures in xdisp.c (and elsewhere)
  2019-03-30 23:27                               ` Alex
@ 2019-03-31 14:52                                 ` Eli Zaretskii
  2019-04-11 19:07                                   ` Alex
  2019-04-13 16:13                                   ` [PATCH] Renaming non-X x_* identifiers (was: Renaming non-X x_* procedures in xdisp.c (and elsewhere)) Alex Gramiak
  0 siblings, 2 replies; 68+ messages in thread
From: Eli Zaretskii @ 2019-03-31 14:52 UTC (permalink / raw)
  To: Alex; +Cc: emacs-devel

> From: Alex <agrambot@gmail.com>
> Cc: emacs-devel@gnu.org
> Date: Sat, 30 Mar 2019 17:27:11 -0600
> 
> >> > Not sure what you mean by "terminal hooks".  They all accept a pointer
> >> > to a frame, no?
> >> 
> >> I meant being used through a function pointer in the terminal struct
> >> rather than in the redisplay_interface struct.
> >
> > Are you talking about the arguments these functions receive now?  If
> > so, which ones specifically get terminal struct pointers?
> 
> Sorry for not being clear -- by "being terminal hooks" I meant being put
> in the definition of the terminal struct (in termhooks.h), rather than
> the redisplay_interface struct in dispextern.h. That is, being used like
> FRAME_TERMINAL (f)->some_hook rather than FRAME_RIF (f)->procedure.

I don't really mind, if using FRAME_TERMINAL doesn't mean more
complications on the source level.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Renaming non-X x_* procedures in xdisp.c (and elsewhere)
  2019-03-31 14:52                                 ` Eli Zaretskii
@ 2019-04-11 19:07                                   ` Alex
  2019-04-12 19:03                                     ` Eli Zaretskii
  2019-04-13 16:13                                   ` [PATCH] Renaming non-X x_* identifiers (was: Renaming non-X x_* procedures in xdisp.c (and elsewhere)) Alex Gramiak
  1 sibling, 1 reply; 68+ messages in thread
From: Alex @ 2019-04-11 19:07 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

I'm back to working on this now. I have a few disjointed questions, but
for now I'd like to ask:

* What's your opinion on changing FRAME_WINDOW_P to basically a C
  version of display-graphics-p? This would move toward using multiple
  windowing systems simultaneously, and helps clear the intent of the
  predicate. I searched and only found uses of it being used as a
  boolean.

* To get rid of a few FRAME_X_WINDOW calls in frame.c and all of the
  FRAME_X_OUTPUT (f)->* calls in xdisp.c I'm considering adding a new
  function pointer interface frame_output_interface, which would allow
  for a generic interface to common output_data elements. Would you be
  open to this? For example, the following:

    FRAME_X_OUTPUT (f)->nontext_cursor

  would be changed to something like:

    FRAME_OI (f)->get_nontext_cursor (f);

  And the FRAME_X_WINDOW calls in frame.c to:

    FRAME_OI (f)->have_native_window (f);

* Why is the font structure within a frame's output_data instead of in
  the frame itself? I was considering adding it to the above interface,
  but I see no immediate reason why it's considered device-dependent.




^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Renaming non-X x_* procedures in xdisp.c (and elsewhere)
  2019-04-11 19:07                                   ` Alex
@ 2019-04-12 19:03                                     ` Eli Zaretskii
  2019-04-12 19:50                                       ` Alex Gramiak
  0 siblings, 1 reply; 68+ messages in thread
From: Eli Zaretskii @ 2019-04-12 19:03 UTC (permalink / raw)
  To: Alex; +Cc: emacs-devel

> From: Alex <agrambot@gmail.com>
> Cc: emacs-devel@gnu.org
> Date: Thu, 11 Apr 2019 13:07:44 -0600
> 
> I'm back to working on this now. I have a few disjointed questions, but
> for now I'd like to ask:
> 
> * What's your opinion on changing FRAME_WINDOW_P to basically a C
>   version of display-graphics-p? This would move toward using multiple
>   windowing systems simultaneously, and helps clear the intent of the
>   predicate. I searched and only found uses of it being used as a
>   boolean.

You submitted a separate patch for this, so let's discuss this issue
there.

> * To get rid of a few FRAME_X_WINDOW calls in frame.c and all of the
>   FRAME_X_OUTPUT (f)->* calls in xdisp.c I'm considering adding a new
>   function pointer interface frame_output_interface, which would allow
>   for a generic interface to common output_data elements. Would you be
>   open to this?  For example, the following:
> 
>     FRAME_X_OUTPUT (f)->nontext_cursor
> 
>   would be changed to something like:
> 
>     FRAME_OI (f)->get_nontext_cursor (f);
> 
>   And the FRAME_X_WINDOW calls in frame.c to:
> 
>     FRAME_OI (f)->have_native_window (f);

Why is this an improvement?  It will certainly make the code a tiny
bit slower, due to a function call overhead.  There's nothing wrong
with the above macros, except their names, which come from X.  If you
want to change the name to something window-system agnostic, that
might be OK (although again, not a significant improvement IMO), but
other than that, I see no reason, as having a function pointer doesn't
get us any closer to supporting several frame types than the current
code.

> * Why is the font structure within a frame's output_data instead of in
>   the frame itself?

Because TTY frames don't need it, I guess.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Renaming non-X x_* procedures in xdisp.c (and elsewhere)
  2019-04-12 19:03                                     ` Eli Zaretskii
@ 2019-04-12 19:50                                       ` Alex Gramiak
  2019-04-12 20:10                                         ` Eli Zaretskii
  0 siblings, 1 reply; 68+ messages in thread
From: Alex Gramiak @ 2019-04-12 19:50 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Alex <agrambot@gmail.com>
>> Cc: emacs-devel@gnu.org
>> Date: Thu, 11 Apr 2019 13:07:44 -0600
>> 
>> I'm back to working on this now. I have a few disjointed questions, but
>> for now I'd like to ask:
>> 
>> * What's your opinion on changing FRAME_WINDOW_P to basically a C
>>   version of display-graphics-p? This would move toward using multiple
>>   windowing systems simultaneously, and helps clear the intent of the
>>   predicate. I searched and only found uses of it being used as a
>>   boolean.
>
> You submitted a separate patch for this, so let's discuss this issue
> there.

While the other patch is more related to this question than the topic of
this thread, that patch doesn't involve FRAME_WINDOW_P and is thus
separate from that patch as well.

The change I'd like to do to FRAME_WINDOW_P doesn't introduce
significant constructs like my other patch does.

It would introduce a tiny slowdown though. Here is the new version:

  #define FRAME_WINDOW_P(f) (!(FRAME_TERMINAL_P (f)
                              || FRAME_INITIAL_P (f)
                              || FRAME_MSDOS_P (f)))

Equivalently it would check for FRAME_{X,NS,W32}_P.

Or do you mean that you wouldn't accept such a patch without making the
entirety of Emacs multi-window-system capable? At the very least, I
believe there should be a comment by the definition of FRAME_WINDOW_P
that states not to use the return value as a non-boolean.

> Why is this an improvement?  It will certainly make the code a tiny
> bit slower, due to a function call overhead.  There's nothing wrong
> with the above macros, except their names, which come from X.  If you
> want to change the name to something window-system agnostic, that
> might be OK (although again, not a significant improvement IMO), but
> other than that, I see no reason, as having a function pointer doesn't
> get us any closer to supporting several frame types than the current
> code.

Would it not get us closer due to not depending on the specific
output_data type and thus the positioning of the cursor elements in the
output_data struct? Of course it would only be a tiny step closer.

I suppose I'll replace the FRAME_X_WINDOW calls with FRAME_NATIVE_WINDOW
and FRAME_X_OUTPUT (in non-X contexts) with FRAME_OUTPUT_DATA for now.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Renaming non-X x_* procedures in xdisp.c (and elsewhere)
  2019-04-12 19:50                                       ` Alex Gramiak
@ 2019-04-12 20:10                                         ` Eli Zaretskii
  2019-04-13 16:26                                           ` Alex Gramiak
  0 siblings, 1 reply; 68+ messages in thread
From: Eli Zaretskii @ 2019-04-12 20:10 UTC (permalink / raw)
  To: Alex Gramiak; +Cc: emacs-devel

> From: Alex Gramiak <agrambot@gmail.com>
> Cc: emacs-devel@gnu.org
> Date: Fri, 12 Apr 2019 13:50:01 -0600
> 
> The change I'd like to do to FRAME_WINDOW_P doesn't introduce
> significant constructs like my other patch does.
> 
> It would introduce a tiny slowdown though. Here is the new version:
> 
>   #define FRAME_WINDOW_P(f) (!(FRAME_TERMINAL_P (f)
>                               || FRAME_INITIAL_P (f)
>                               || FRAME_MSDOS_P (f)))

That could be OK, except that FRAME_MSDOS_P has the same problem as
FRAME_W32_P etc.: it is only defined for a single backend.

But if we want a single definition of FRAME_WINDOW_P, why not just
look at the output_method member and test that instead?  Maybe even
make it a bit mask, so a test is faster?

> Equivalently it would check for FRAME_{X,NS,W32}_P.

Not sure what that means, please elaborate.

> I believe there should be a comment by the definition of FRAME_WINDOW_P
> that states not to use the return value as a non-boolean.

It's okay to add such a comment, although the _P part of the name,
which stands for "Predicate", is supposed to say that already.

> Would it not get us closer due to not depending on the specific
> output_data type and thus the positioning of the cursor elements in the
> output_data struct? Of course it would only be a tiny step closer.

IMO, it's less than tiny.  Moving towards that goal one struct member
at a time makes no sense to me, because we are likely to discover that
other steps will need different changes that are incompatible with
this one.

Making Emacs able to use several window-systems in the same session is
a very worthy goal, but it must be a coherent set of changes made
according to some plan, and we should make those changes more or less
together, because otherwise there's a good chance we will be left with
only part of the changes and no real gain.  It happened before.

Thanks.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* [PATCH] Renaming non-X x_* identifiers (was: Renaming non-X x_* procedures in xdisp.c (and elsewhere))
  2019-03-31 14:52                                 ` Eli Zaretskii
  2019-04-11 19:07                                   ` Alex
@ 2019-04-13 16:13                                   ` Alex Gramiak
  2019-04-13 17:17                                     ` Eli Zaretskii
  2019-04-27  1:53                                     ` Basil L. Contovounesios
  1 sibling, 2 replies; 68+ messages in thread
From: Alex Gramiak @ 2019-04-13 16:13 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Alan Third, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 823 bytes --]

Okay, I believe I'm essentially done now, at least with the C-side. I
can't test with either w32 and NS, so I hope you and Alan can test the
attached patches with those backends.

There still exists a few remaining instances of non-X procedures that
use x in the name, but those mostly either need functionality changes or
are tied to some Lisp-side identifier.

I can clean up the commit messages and combine/split the 2 main commits
as seen fit if accepted.

A brief overview of this patch series is that w32 x_* procedures are
renamed w32_*, ns x_* procedures are renamed ns_*, and the procedures
that depended on being named x_* (called from window system-generic
code) were transformed into terminal hooks.

Many non-backend-specific x_* procedures were renamed to gui_* or
image_* in frame.c , xdisp.c, and image.c.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Rename-non-X-x_-procedures-in-xdisp.c.patch --]
[-- Type: text/x-patch, Size: 30271 bytes --]

From 7d9edeebf5be15eabb206273c02e37cef59f5be6 Mon Sep 17 00:00:00 2001
From: Alexander Gramiak <agrambot@gmail.com>
Date: Sat, 23 Mar 2019 11:19:40 -0600
Subject: [PATCH 1/5] Rename non-X x_* procedures in xdisp.c

---
 src/composite.c  |  2 +-
 src/dispextern.h | 36 +++++++++----------
 src/nsfns.m      |  4 +--
 src/nsterm.m     | 30 ++++++++--------
 src/w32fns.c     |  4 +--
 src/w32term.c    | 26 +++++++-------
 src/window.c     |  2 +-
 src/xdisp.c      | 91 ++++++++++++++++++++++++------------------------
 src/xfns.c       | 10 +++---
 src/xterm.c      | 30 ++++++++--------
 10 files changed, 117 insertions(+), 118 deletions(-)

diff --git a/src/composite.c b/src/composite.c
index 88f1235f11..7d7ed3f4a6 100644
--- a/src/composite.c
+++ b/src/composite.c
@@ -176,7 +176,7 @@ get_composition_id (ptrdiff_t charpos, ptrdiff_t bytepos, ptrdiff_t nchars,
 
   /* Maximum length of a string of glyphs.  XftGlyphExtents limits
      this to INT_MAX, and Emacs limits it further.  Divide INT_MAX - 1
-     by 2 because x_produce_glyphs computes glyph_len * 2 + 1.  Divide
+     by 2 because gui_produce_glyphs computes glyph_len * 2 + 1.  Divide
      the size by MAX_MULTIBYTE_LENGTH because encode_terminal_code
      multiplies glyph_len by MAX_MULTIBYTE_LENGTH.  */
   enum {
diff --git a/src/dispextern.h b/src/dispextern.h
index 1a53656353..79ec4ce52e 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -3274,19 +3274,19 @@ extern void get_font_ascent_descent (struct font *, int *, int *);
 extern void dump_glyph_string (struct glyph_string *) EXTERNALLY_VISIBLE;
 #endif
 
-extern void x_get_glyph_overhangs (struct glyph *, struct frame *,
-                                   int *, int *);
+extern void gui_get_glyph_overhangs (struct glyph *, struct frame *,
+                                     int *, int *);
 extern struct font *font_for_underline_metrics (struct glyph_string *);
-extern void x_produce_glyphs (struct it *);
-
-extern void x_write_glyphs (struct window *, struct glyph_row *,
-			    struct glyph *, enum glyph_row_area, int);
-extern void x_insert_glyphs (struct window *, struct glyph_row *,
-			     struct glyph *, enum glyph_row_area, int);
-extern void x_clear_end_of_line (struct window *, struct glyph_row *,
-				 enum glyph_row_area, int);
-extern void x_fix_overlapping_area (struct window *, struct glyph_row *,
-                                    enum glyph_row_area, int);
+extern void gui_produce_glyphs (struct it *);
+
+extern void gui_write_glyphs (struct window *, struct glyph_row *,
+                              struct glyph *, enum glyph_row_area, int);
+extern void gui_insert_glyphs (struct window *, struct glyph_row *,
+                               struct glyph *, enum glyph_row_area, int);
+extern void gui_clear_end_of_line (struct window *, struct glyph_row *,
+                                   enum glyph_row_area, int);
+extern void gui_fix_overlapping_area (struct window *, struct glyph_row *,
+                                      enum glyph_row_area, int);
 extern void draw_phys_cursor_glyph (struct window *,
                                     struct glyph_row *,
                                     enum draw_glyphs_face);
@@ -3294,10 +3294,10 @@ extern void get_phys_cursor_geometry (struct window *, struct glyph_row *,
                                       struct glyph *, int *, int *, int *);
 extern void erase_phys_cursor (struct window *);
 extern void display_and_set_cursor (struct window *, bool, int, int, int, int);
-extern void x_update_cursor (struct frame *, bool);
-extern void x_clear_cursor (struct window *);
-extern void x_draw_vertical_border (struct window *w);
-extern void x_draw_right_divider (struct window *w);
+extern void gui_update_cursor (struct frame *, bool);
+extern void gui_clear_cursor (struct window *);
+extern void gui_draw_vertical_border (struct window *w);
+extern void gui_draw_right_divider (struct window *w);
 
 extern int get_glyph_string_clip_rects (struct glyph_string *,
                                         NativeRectangle *, int);
@@ -3309,11 +3309,11 @@ extern void handle_tool_bar_click (struct frame *,
                                    int, int, bool, int);
 
 extern void expose_frame (struct frame *, int, int, int, int);
-extern bool x_intersect_rectangles (XRectangle *, XRectangle *, XRectangle *);
+extern bool gui_intersect_rectangles (XRectangle *, XRectangle *, XRectangle *);
 #endif	/* HAVE_WINDOW_SYSTEM */
 
 extern void note_mouse_highlight (struct frame *, int, int);
-extern void x_clear_window_mouse_face (struct window *);
+extern void gui_clear_window_mouse_face (struct window *);
 extern void cancel_mouse_face (struct frame *);
 extern bool clear_mouse_face (Mouse_HLInfo *);
 extern bool cursor_in_mouse_face_p (struct window *w);
diff --git a/src/nsfns.m b/src/nsfns.m
index ee7598a1c7..009e9d55e2 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -342,8 +342,8 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
 
   if (FRAME_VISIBLE_P (f))
     {
-      x_update_cursor (f, 0);
-      x_update_cursor (f, 1);
+      gui_update_cursor (f, 0);
+      gui_update_cursor (f, 1);
     }
   update_face_from_frame_parameter (f, Qcursor_color, arg);
   unblock_input ();
diff --git a/src/nsterm.m b/src/nsterm.m
index 81d36be6cc..15316e23ed 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -1183,9 +1183,9 @@ static NSRect constrain_frame_rect(NSRect frameRect, bool isFullscreen)
       if (draw_window_fringes (w, 1))
 	{
 	  if (WINDOW_RIGHT_DIVIDER_WIDTH (w))
-	    x_draw_right_divider (w);
+	    gui_draw_right_divider (w);
 	  else
-	    x_draw_vertical_border (w);
+	    gui_draw_vertical_border (w);
 	}
 
       unblock_input ();
@@ -1528,12 +1528,12 @@ -(void)remove
     {
       if (old_highlight)
 	{
-          x_update_cursor (old_highlight, 1);
+          gui_update_cursor (old_highlight, 1);
 	  x_set_frame_alpha (old_highlight);
 	}
       if (dpyinfo->x_highlight_frame)
 	{
-          x_update_cursor (dpyinfo->x_highlight_frame, 1);
+          gui_update_cursor (dpyinfo->x_highlight_frame, 1);
           x_set_frame_alpha (dpyinfo->x_highlight_frame);
 	}
     }
@@ -2607,7 +2607,7 @@ so some key presses (TAB) are swallowed by the system.  */
       [[view window] invalidateCursorRectsForView: view];
       /* Redisplay assumes this function also draws the changed frame
          cursor, but this function doesn't, so do it explicitly.  */
-      x_update_cursor (f, 1);
+      gui_update_cursor (f, 1);
     }
 }
 
@@ -2885,7 +2885,7 @@ so some key presses (TAB) are swallowed by the system.  */
 
   block_input ();
 
-  x_clear_cursor (w);
+  gui_clear_cursor (w);
 
   {
     NSRect srcRect = NSMakeRect (x, from_y, width, height);
@@ -5099,7 +5099,7 @@ static Lisp_Object ns_string_to_lispmod (const char *s)
 
 
 /* This and next define (many of the) public functions in this file.  */
-/* x_... are generic versions in xdisp.c that we, and other terms, get away
+/* gui_* are generic versions in xdisp.c that we, and other terms, get away
          with using despite presence in the "system dependent" redisplay
          interface.  In addition, many of the ns_ methods have code that is
          shared with all terms, indicating need for further refactoring.  */
@@ -5107,18 +5107,18 @@ static Lisp_Object ns_string_to_lispmod (const char *s)
 static struct redisplay_interface ns_redisplay_interface =
 {
   ns_frame_parm_handlers,
-  x_produce_glyphs,
-  x_write_glyphs,
-  x_insert_glyphs,
-  x_clear_end_of_line,
+  gui_produce_glyphs,
+  gui_write_glyphs,
+  gui_insert_glyphs,
+  gui_clear_end_of_line,
   ns_scroll_run,
   ns_after_update_window_line,
   ns_update_window_begin,
   ns_update_window_end,
   0, /* flush_display */
-  x_clear_window_mouse_face,
-  x_get_glyph_overhangs,
-  x_fix_overlapping_area,
+  gui_clear_window_mouse_face,
+  gui_get_glyph_overhangs,
+  gui_fix_overlapping_area,
   ns_draw_fringe_bitmap,
   0, /* define_fringe_bitmap */ /* FIXME: simplify ns_draw_fringe_bitmap */
   0, /* destroy_fringe_bitmap */
@@ -7249,7 +7249,7 @@ - (void)windowDidResignKey: (NSNotification *)notification
             from sole-frame Emacs to get hollow box to show.  */
   if (!windowClosing && [[self window] isVisible] == YES)
     {
-      x_update_cursor (emacsframe, 1);
+      gui_update_cursor (emacsframe, 1);
       x_set_frame_alpha (emacsframe);
     }
 
diff --git a/src/w32fns.c b/src/w32fns.c
index af82b46305..814998f5f2 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -1514,8 +1514,8 @@ x_set_cursor_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 
       if (FRAME_VISIBLE_P (f))
 	{
-	  x_update_cursor (f, 0);
-	  x_update_cursor (f, 1);
+	  gui_update_cursor (f, 0);
+	  gui_update_cursor (f, 1);
 	}
     }
 
diff --git a/src/w32term.c b/src/w32term.c
index bb1f0bad01..a43d43c558 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -363,7 +363,7 @@ w32_draw_underwave (struct glyph_string *s, COLORREF color)
   get_glyph_string_clip_rect (s, &w32_string_clip);
   CONVERT_TO_XRECT (string_clip, w32_string_clip);
 
-  if (!x_intersect_rectangles (&wave_clip, &string_clip, &final_clip))
+  if (!gui_intersect_rectangles (&wave_clip, &string_clip, &final_clip))
     return;
 
   hp = CreatePen (PS_SOLID, thickness, color);
@@ -713,9 +713,9 @@ x_update_window_end (struct window *w, bool cursor_on_p,
       if (draw_window_fringes (w, true))
 	{
 	  if (WINDOW_RIGHT_DIVIDER_WIDTH (w))
-	    x_draw_right_divider (w);
+	    gui_draw_right_divider (w);
 	  else
-	    x_draw_vertical_border (w);
+	    gui_draw_vertical_border (w);
 	}
 
       unblock_input ();
@@ -2863,7 +2863,7 @@ x_scroll_run (struct window *w, struct run *run)
   block_input ();
 
   /* Cursor off.  Will be switched on again in x_update_window_end.  */
-  x_clear_cursor (w);
+  gui_clear_cursor (w);
 
   {
     RECT from;
@@ -2906,14 +2906,14 @@ x_scroll_run (struct window *w, struct run *run)
 static void
 frame_highlight (struct frame *f)
 {
-  x_update_cursor (f, 1);
+  gui_update_cursor (f, 1);
   x_set_frame_alpha (f);
 }
 
 static void
 frame_unhighlight (struct frame *f)
 {
-  x_update_cursor (f, 1);
+  gui_update_cursor (f, 1);
   x_set_frame_alpha (f);
 }
 
@@ -7092,18 +7092,18 @@ extern frame_parm_handler w32_frame_parm_handlers[];
 static struct redisplay_interface w32_redisplay_interface =
 {
   w32_frame_parm_handlers,
-  x_produce_glyphs,
-  x_write_glyphs,
-  x_insert_glyphs,
-  x_clear_end_of_line,
+  gui_produce_glyphs,
+  gui_write_glyphs,
+  gui_insert_glyphs,
+  gui_clear_end_of_line,
   x_scroll_run,
   x_after_update_window_line,
   x_update_window_begin,
   x_update_window_end,
   0, /* flush_display */
-  x_clear_window_mouse_face,
-  x_get_glyph_overhangs,
-  x_fix_overlapping_area,
+  gui_clear_window_mouse_face,
+  gui_get_glyph_overhangs,
+  gui_fix_overlapping_area,
   w32_draw_fringe_bitmap,
   w32_define_fringe_bitmap,
   w32_destroy_fringe_bitmap,
diff --git a/src/window.c b/src/window.c
index ef2ed63850..05340ea439 100644
--- a/src/window.c
+++ b/src/window.c
@@ -220,7 +220,7 @@ static void
 wset_update_mode_line (struct window *w)
 {
   /* If this window is the selected window on its frame, set the
-     global variable update_mode_lines, so that x_consider_frame_title
+     global variable update_mode_lines, so that gui_consider_frame_title
      will consider this frame's title for redisplay.  */
   Lisp_Object fselected_window = XFRAME (WINDOW_FRAME (w))->selected_window;
 
diff --git a/src/xdisp.c b/src/xdisp.c
index a88fc698b8..ae4c405b8d 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -491,7 +491,7 @@ int windows_or_buffers_changed;
 
    Since the frame title uses the same %-constructs as the mode line
    (except %c, %C, and %l), if this variable is non-zero, we also consider
-   redisplaying the title of each frame, see x_consider_frame_title.
+   redisplaying the title of each frame, see gui_consider_frame_title.
 
    The `redisplay' bits are the same as those used for
    windows_or_buffers_changed, and setting windows_or_buffers_changed also
@@ -900,7 +900,7 @@ static int underlying_face_id (struct it *);
 #ifdef HAVE_WINDOW_SYSTEM
 
 static void update_tool_bar (struct frame *, bool);
-static void x_draw_bottom_divider (struct window *w);
+static void gui_draw_bottom_divider (struct window *w);
 static void notice_overwritten_cursor (struct window *,
                                        enum glyph_row_area,
                                        int, int, int, int);
@@ -2133,7 +2133,7 @@ get_glyph_string_clip_rects (struct glyph_string *s, NativeRectangle *rects, int
 	  rc.width = s->w->phys_cursor_width;
 	  rc.height = s->w->phys_cursor_height;
 
-	  x_intersect_rectangles (&r_save, &rc, &r);
+	  gui_intersect_rectangles (&r_save, &rc, &r);
 	}
     }
   else
@@ -2194,7 +2194,7 @@ get_glyph_string_clip_rects (struct glyph_string *s, NativeRectangle *rects, int
     {
       XRectangle r_save = r;
 
-      if (! x_intersect_rectangles (&r_save, s->row->clip, &r))
+      if (! gui_intersect_rectangles (&r_save, s->row->clip, &r))
 	r.width = 0;
     }
 
@@ -6926,7 +6926,7 @@ static next_element_function const get_next_element[NUM_IT_METHODS] =
    method symbol.  By side-effect, update it->what and
    it->glyphless_method.  This function is called from
    get_next_display_element for each character element, and from
-   x_produce_glyphs when no suitable font was found.  */
+   gui_produce_glyphs when no suitable font was found.  */
 
 Lisp_Object
 lookup_glyphless_char_display (int c, struct it *it)
@@ -9624,7 +9624,7 @@ move_it_to (struct it *it, ptrdiff_t to_charpos, int to_x, int to_y, int to_vpos
 		      /* When display_line produces a continued line
 			 that ends in a TAB, it skips a tab stop that
 			 is closer than the font's space character
-			 width (see x_produce_glyphs where it produces
+			 width (see gui_produce_glyphs where it produces
 			 the stretch glyph which represents a TAB).
 			 We need to reproduce the same logic here.  */
 		      eassert (face_font);
@@ -11999,7 +11999,7 @@ store_mode_line_noprop (const char *string, int field_width, int precision)
    frame_title_format.  */
 
 static void
-x_consider_frame_title (Lisp_Object frame)
+gui_consider_frame_title (Lisp_Object frame)
 {
   struct frame *f = XFRAME (frame);
 
@@ -12146,7 +12146,7 @@ prepare_menu_bars (void)
 		  || FRAME_VISIBLE_P (f) == 1
 		  /* Exclude TTY frames that are obscured because they
 		     are not the top frame on their console.  This is
-		     because x_consider_frame_title actually switches
+		     because gui_consider_frame_title actually switches
 		     to the frame, which for TTY frames means it is
 		     marked as garbaged, and will be completely
 		     redrawn on the next redisplay cycle.  This causes
@@ -12154,7 +12154,7 @@ prepare_menu_bars (void)
 		     are more than one of them, even though nothing
 		     should be changed on display.  */
 		  || (FRAME_VISIBLE_P (f) == 2 && FRAME_WINDOW_P (f))))
-	    x_consider_frame_title (frame);
+	    gui_consider_frame_title (frame);
 	}
     }
 #endif /* HAVE_WINDOW_SYSTEM */
@@ -17682,7 +17682,7 @@ redisplay_window (Lisp_Object window, bool just_this_one_p)
 	    ignore_mouse_drag_p = true;
 #endif
         }
-      x_consider_frame_title (w->frame);
+      gui_consider_frame_title (w->frame);
 #endif
     }
 
@@ -17697,16 +17697,16 @@ redisplay_window (Lisp_Object window, bool just_this_one_p)
       if (draw_window_fringes (w, true))
 	{
 	  if (WINDOW_RIGHT_DIVIDER_WIDTH (w))
-	    x_draw_right_divider (w);
+	    gui_draw_right_divider (w);
 	  else
-	    x_draw_vertical_border (w);
+	    gui_draw_vertical_border (w);
 	}
       unblock_input ();
       update_end (f);
     }
 
   if (WINDOW_BOTTOM_DIVIDER_WIDTH (w))
-    x_draw_bottom_divider (w);
+    gui_draw_bottom_divider (w);
 #endif /* HAVE_WINDOW_SYSTEM */
 
   /* We go to this label, with fonts_changed set, if it is
@@ -19150,7 +19150,7 @@ try_window_id (struct window *w)
 		     + window_internal_height (w));
 
 #if defined (HAVE_GPM) || defined (MSDOS)
-	  x_clear_window_mouse_face (w);
+	  gui_clear_window_mouse_face (w);
 #endif
 	  /* Perform the operation on the screen.  */
 	  if (dvpos > 0)
@@ -20174,7 +20174,7 @@ append_space_for_newline (struct it *it, bool default_face_p)
 	      it->object = saved_object; /* get_it_property needs this */
 	      normal_char_ascent_descent (font, -1, &it->ascent, &it->descent);
 	      /* Must do a subset of line height processing from
-		 x_produce_glyph for newline characters.  */
+		 gui_produce_glyph for newline characters.  */
 	      height = get_it_property (it, Qline_height);
 	      if (CONSP (height)
 		  && CONSP (XCDR (height))
@@ -26260,7 +26260,7 @@ normal_char_height (struct font *font, int c)
    assumed to be zero.  */
 
 void
-x_get_glyph_overhangs (struct glyph *glyph, struct frame *f, int *left, int *right)
+gui_get_glyph_overhangs (struct glyph *glyph, struct frame *f, int *left, int *right)
 {
   *left = *right = 0;
 
@@ -26350,7 +26350,7 @@ left_overwriting (struct glyph_string *s)
   for (i = first - 1; i >= 0; --i)
     {
       int left, right;
-      x_get_glyph_overhangs (glyphs + i, s->f, &left, &right);
+      gui_get_glyph_overhangs (glyphs + i, s->f, &left, &right);
       if (x + right > 0)
 	k = i;
       x -= glyphs[i].pixel_width;
@@ -26405,7 +26405,7 @@ right_overwriting (struct glyph_string *s)
   for (i = first; i < end; ++i)
     {
       int left, right;
-      x_get_glyph_overhangs (glyphs + i, s->f, &left, &right);
+      gui_get_glyph_overhangs (glyphs + i, s->f, &left, &right);
       if (x - left < 0)
 	k = i;
       x += glyphs[i].pixel_width;
@@ -27067,7 +27067,7 @@ font_for_underline_metrics (struct glyph_string *s)
   }
 
 /* Store one glyph for IT->char_to_display in IT->glyph_row.
-   Called from x_produce_glyphs when IT->glyph_row is non-null.  */
+   Called from gui_produce_glyphs when IT->glyph_row is non-null.  */
 
 static void
 append_glyph (struct it *it)
@@ -27149,9 +27149,8 @@ append_glyph (struct it *it)
     IT_EXPAND_MATRIX_WIDTH (it, area);
 }
 
-/* Store one glyph for the composition IT->cmp_it.id in
-   IT->glyph_row.  Called from x_produce_glyphs when IT->glyph_row is
-   non-null.  */
+/* Store one glyph for the composition IT->cmp_it.id in IT->glyph_row.
+   Called from gui_produce_glyphs when IT->glyph_row is non-null.  */
 
 static void
 append_composite_glyph (struct it *it)
@@ -28227,7 +28226,7 @@ produce_glyphless_glyph (struct it *it, bool for_no_font, Lisp_Object acronym)
    for an overview of struct it.  */
 
 void
-x_produce_glyphs (struct it *it)
+gui_produce_glyphs (struct it *it)
 {
   int extra_line_spacing = it->extra_line_spacing;
 
@@ -28995,7 +28994,7 @@ x_produce_glyphs (struct it *it)
    being updated, and UPDATED_AREA is the area of that row being updated.  */
 
 void
-x_write_glyphs (struct window *w, struct glyph_row *updated_row,
+gui_write_glyphs (struct window *w, struct glyph_row *updated_row,
 		struct glyph *start, enum glyph_row_area updated_area, int len)
 {
   int x, hpos, chpos = w->phys_cursor.hpos;
@@ -29039,7 +29038,7 @@ x_write_glyphs (struct window *w, struct glyph_row *updated_row,
    Insert LEN glyphs from START at the nominal cursor position.  */
 
 void
-x_insert_glyphs (struct window *w, struct glyph_row *updated_row,
+gui_insert_glyphs (struct window *w, struct glyph_row *updated_row,
 		 struct glyph *start, enum glyph_row_area updated_area, int len)
 {
   struct frame *f;
@@ -29096,7 +29095,7 @@ x_insert_glyphs (struct window *w, struct glyph_row *updated_row,
    updated window W.  TO_X == -1 means clear to the end of this area.  */
 
 void
-x_clear_end_of_line (struct window *w, struct glyph_row *updated_row,
+gui_clear_end_of_line (struct window *w, struct glyph_row *updated_row,
 		     enum glyph_row_area updated_area, int to_x)
 {
   struct frame *f;
@@ -29483,7 +29482,7 @@ notice_overwritten_cursor (struct window *w, enum glyph_row_area area,
    with respect to the overlapping part OVERLAPS.  */
 
 void
-x_fix_overlapping_area (struct window *w, struct glyph_row *row,
+gui_fix_overlapping_area (struct window *w, struct glyph_row *row,
 			enum glyph_row_area area, int overlaps)
 {
   int i, x;
@@ -29562,12 +29561,12 @@ draw_phys_cursor_glyph (struct window *w, struct glyph_row *row,
 
 	  if (row > w->current_matrix->rows
 	      && MATRIX_ROW_OVERLAPS_SUCC_P (row - 1))
-	    x_fix_overlapping_area (w, row - 1, TEXT_AREA,
+	    gui_fix_overlapping_area (w, row - 1, TEXT_AREA,
 				    OVERLAPS_ERASED_CURSOR);
 
 	  if (MATRIX_ROW_BOTTOM_Y (row) < window_text_bottom_y (w)
 	      && MATRIX_ROW_OVERLAPS_PRED_P (row + 1))
-	    x_fix_overlapping_area (w, row + 1, TEXT_AREA,
+	    gui_fix_overlapping_area (w, row + 1, TEXT_AREA,
 				    OVERLAPS_ERASED_CURSOR);
 	}
     }
@@ -29857,7 +29856,7 @@ update_cursor_in_window_tree (struct window *w, bool on_p)
    Don't change the cursor's position.  */
 
 void
-x_update_cursor (struct frame *f, bool on_p)
+gui_update_cursor (struct frame *f, bool on_p)
 {
   update_cursor_in_window_tree (XWINDOW (f->root_window), on_p);
 }
@@ -29869,7 +29868,7 @@ x_update_cursor (struct frame *f, bool on_p)
    is about to be rewritten.  */
 
 void
-x_clear_cursor (struct window *w)
+gui_clear_cursor (struct window *w)
 {
   if (FRAME_VISIBLE_P (XFRAME (w->frame)) && w->phys_cursor_on_p)
     update_window_cursor (w, false);
@@ -31897,7 +31896,7 @@ note_mouse_highlight (struct frame *f, int x, int y)
    functions to ensure the mouse-highlight is off.  */
 
 void
-x_clear_window_mouse_face (struct window *w)
+gui_clear_window_mouse_face (struct window *w)
 {
   Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (XFRAME (w->frame));
   Lisp_Object window;
@@ -32041,13 +32040,13 @@ expose_overlaps (struct window *w,
 
 	row->clip = r;
 	if (row->used[LEFT_MARGIN_AREA])
-	  x_fix_overlapping_area (w, row, LEFT_MARGIN_AREA, OVERLAPS_BOTH);
+	  gui_fix_overlapping_area (w, row, LEFT_MARGIN_AREA, OVERLAPS_BOTH);
 
 	if (row->used[TEXT_AREA])
-	  x_fix_overlapping_area (w, row, TEXT_AREA, OVERLAPS_BOTH);
+	  gui_fix_overlapping_area (w, row, TEXT_AREA, OVERLAPS_BOTH);
 
 	if (row->used[RIGHT_MARGIN_AREA])
-	  x_fix_overlapping_area (w, row, RIGHT_MARGIN_AREA, OVERLAPS_BOTH);
+	  gui_fix_overlapping_area (w, row, RIGHT_MARGIN_AREA, OVERLAPS_BOTH);
 	row->clip = NULL;
       }
 }
@@ -32076,7 +32075,7 @@ phys_cursor_in_rect_p (struct window *w, XRectangle *r)
       cr.y = row->y;
       cr.width = WINDOW_RIGHT_FRINGE_WIDTH (w);
       cr.height = row->height;
-      return x_intersect_rectangles (&cr, r, &result);
+      return gui_intersect_rectangles (&cr, r, &result);
     }
 
   cursor_glyph = get_phys_cursor_glyph (w);
@@ -32090,7 +32089,7 @@ phys_cursor_in_rect_p (struct window *w, XRectangle *r)
       cr.height = w->phys_cursor_height;
       /* ++KFS: W32 version used W32-specific IntersectRect here, but
 	 I assume the effect is the same -- and this is portable.  */
-      return x_intersect_rectangles (&cr, r, &result);
+      return gui_intersect_rectangles (&cr, r, &result);
     }
   /* If we don't understand the format, pretend we're not in the hot-spot.  */
   return false;
@@ -32102,7 +32101,7 @@ phys_cursor_in_rect_p (struct window *w, XRectangle *r)
    have vertical scroll bars.  */
 
 void
-x_draw_vertical_border (struct window *w)
+gui_draw_vertical_border (struct window *w)
 {
   struct frame *f = XFRAME (WINDOW_FRAME (w));
 
@@ -32153,7 +32152,7 @@ x_draw_vertical_border (struct window *w)
 /* Draw window dividers for window W.  */
 
 void
-x_draw_right_divider (struct window *w)
+gui_draw_right_divider (struct window *w)
 {
   struct frame *f = WINDOW_XFRAME (w);
 
@@ -32179,7 +32178,7 @@ x_draw_right_divider (struct window *w)
 }
 
 static void
-x_draw_bottom_divider (struct window *w)
+gui_draw_bottom_divider (struct window *w)
 {
   struct frame *f = XFRAME (WINDOW_FRAME (w));
 
@@ -32244,7 +32243,7 @@ expose_window (struct window *w, XRectangle *fr)
   wr.width = WINDOW_PIXEL_WIDTH (w);
   wr.height = WINDOW_PIXEL_HEIGHT (w);
 
-  if (x_intersect_rectangles (fr, &wr, &r))
+  if (gui_intersect_rectangles (fr, &wr, &r))
     {
       int yb = window_text_bottom_y (w);
       struct glyph_row *row;
@@ -32261,7 +32260,7 @@ expose_window (struct window *w, XRectangle *fr)
       bool cursor_cleared_p = (!w->pseudo_window_p
 			       && phys_cursor_in_rect_p (w, &r));
       if (cursor_cleared_p)
-	x_clear_cursor (w);
+	gui_clear_cursor (w);
 
       /* If the row containing the cursor extends face to end of line,
 	 then expose_area might overwrite the cursor outside the
@@ -32354,12 +32353,12 @@ expose_window (struct window *w, XRectangle *fr)
 
 	  /* Draw border between windows.  */
 	  if (WINDOW_RIGHT_DIVIDER_WIDTH (w))
-	    x_draw_right_divider (w);
+	    gui_draw_right_divider (w);
 	  else
-	    x_draw_vertical_border (w);
+	    gui_draw_vertical_border (w);
 
 	  if (WINDOW_BOTTOM_DIVIDER_WIDTH (w))
-	    x_draw_bottom_divider (w);
+	    gui_draw_bottom_divider (w);
 
 	  /* Turn the cursor on again.  */
 	  if (cursor_cleared_p
@@ -32493,7 +32492,7 @@ expose_frame (struct frame *f, int x, int y, int w, int h)
    empty.  */
 
 bool
-x_intersect_rectangles (XRectangle *r1, XRectangle *r2, XRectangle *result)
+gui_intersect_rectangles (XRectangle *r1, XRectangle *r2, XRectangle *result)
 {
   XRectangle *left, *right;
   XRectangle *upper, *lower;
diff --git a/src/xfns.c b/src/xfns.c
index 13f66f0718..da11e74345 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -1388,8 +1388,8 @@ x_set_cursor_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 
       if (FRAME_VISIBLE_P (f))
 	{
-	  x_update_cursor (f, false);
-	  x_update_cursor (f, true);
+	  gui_update_cursor (f, false);
+	  gui_update_cursor (f, true);
 	}
     }
 
@@ -4583,7 +4583,7 @@ x_get_monitor_for_frame (struct frame *f,
 
       if (mi->geom.width == 0) continue;
 
-      if (x_intersect_rectangles (&mi->geom, &frect, &res))
+      if (gui_intersect_rectangles (&mi->geom, &frect, &res))
         {
           a = res.width * res.height;
           if (a > area)
@@ -4712,7 +4712,7 @@ x_get_monitor_attributes_xinerama (struct x_display_info *dpyinfo)
       if (i == 0 && x_get_net_workarea (dpyinfo, &workarea_r))
 	{
 	  mi->work = workarea_r;
-	  if (! x_intersect_rectangles (&mi->geom, &mi->work, &mi->work))
+	  if (! gui_intersect_rectangles (&mi->geom, &mi->work, &mi->work))
 	    mi->work = mi->geom;
 	}
       else
@@ -4816,7 +4816,7 @@ x_get_monitor_attributes_xrandr (struct x_display_info *dpyinfo)
           if (i == primary && x_get_net_workarea (dpyinfo, &workarea_r))
             {
               mi->work= workarea_r;
-              if (! x_intersect_rectangles (&mi->geom, &mi->work, &mi->work))
+              if (! gui_intersect_rectangles (&mi->geom, &mi->work, &mi->work))
                 mi->work = mi->geom;
             }
           else
diff --git a/src/xterm.c b/src/xterm.c
index def6915d62..4145542dfa 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -1168,9 +1168,9 @@ x_update_window_end (struct window *w, bool cursor_on_p,
       if (draw_window_fringes (w, true))
 	{
 	  if (WINDOW_RIGHT_DIVIDER_WIDTH (w))
-	    x_draw_right_divider (w);
+	    gui_draw_right_divider (w);
 	  else
-	    x_draw_vertical_border (w);
+	    gui_draw_vertical_border (w);
 	}
 
       unblock_input ();
@@ -3104,7 +3104,7 @@ x_draw_image_foreground (struct glyph_string *s)
 	  image_rect.y = y;
 	  image_rect.width = s->slice.width;
 	  image_rect.height = s->slice.height;
-	  if (x_intersect_rectangles (&clip_rect, &image_rect, &r))
+	  if (gui_intersect_rectangles (&clip_rect, &image_rect, &r))
             x_composite_image (s, FRAME_X_DRAWABLE (s->f),
 			       s->slice.x + r.x - x, s->slice.y + r.y - y,
                                r.x, r.y, r.width, r.height);
@@ -3118,7 +3118,7 @@ x_draw_image_foreground (struct glyph_string *s)
 	  image_rect.y = y;
 	  image_rect.width = s->slice.width;
 	  image_rect.height = s->slice.height;
-	  if (x_intersect_rectangles (&clip_rect, &image_rect, &r))
+	  if (gui_intersect_rectangles (&clip_rect, &image_rect, &r))
             x_composite_image (s, FRAME_X_DRAWABLE (s->f), s->slice.x + r.x - x, s->slice.y + r.y - y,
                                r.x, r.y, r.width, r.height);
 
@@ -3603,7 +3603,7 @@ x_draw_underwave (struct glyph_string *s)
   wave_clip.height = wave_height;
   get_glyph_string_clip_rect (s, &string_clip);
 
-  if (!x_intersect_rectangles (&wave_clip, &string_clip, &final_clip))
+  if (!gui_intersect_rectangles (&wave_clip, &string_clip, &final_clip))
     return;
 
   XSetClipRectangles (s->display, s->gc, 0, 0, &final_clip, 1, Unsorted);
@@ -4334,7 +4334,7 @@ x_scroll_run (struct window *w, struct run *run)
   block_input ();
 
   /* Cursor off.  Will be switched on again in x_update_window_end.  */
-  x_clear_cursor (w);
+  gui_clear_cursor (w);
 
 #ifdef USE_CAIRO
   if (FRAME_CR_CONTEXT (f))
@@ -4395,7 +4395,7 @@ frame_highlight (struct frame *f)
 		    f->output_data.x->border_pixel);
   x_uncatch_errors ();
   unblock_input ();
-  x_update_cursor (f, true);
+  gui_update_cursor (f, true);
   x_set_frame_alpha (f);
 }
 
@@ -4413,7 +4413,7 @@ frame_unhighlight (struct frame *f)
 			  f->output_data.x->border_tile);
   x_uncatch_errors ();
   unblock_input ();
-  x_update_cursor (f, true);
+  gui_update_cursor (f, true);
   x_set_frame_alpha (f);
 }
 
@@ -13102,18 +13102,18 @@ x_activate_timeout_atimer (void)
 static struct redisplay_interface x_redisplay_interface =
   {
     x_frame_parm_handlers,
-    x_produce_glyphs,
-    x_write_glyphs,
-    x_insert_glyphs,
-    x_clear_end_of_line,
+    gui_produce_glyphs,
+    gui_write_glyphs,
+    gui_insert_glyphs,
+    gui_clear_end_of_line,
     x_scroll_run,
     x_after_update_window_line,
     x_update_window_begin,
     x_update_window_end,
     x_flip_and_flush,
-    x_clear_window_mouse_face,
-    x_get_glyph_overhangs,
-    x_fix_overlapping_area,
+    gui_clear_window_mouse_face,
+    gui_get_glyph_overhangs,
+    gui_fix_overlapping_area,
     x_draw_fringe_bitmap,
 #ifdef USE_CAIRO
     x_cr_define_fringe_bitmap,
-- 
2.21.0


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-Add-prefixes-to-some-window-system-dependent-procedu.patch --]
[-- Type: text/x-patch, Size: 16152 bytes --]

From 2ca8409b032298ac16fd2fe02e7ebaca97d0f0fc Mon Sep 17 00:00:00 2001
From: Alexander Gramiak <agrambot@gmail.com>
Date: Thu, 11 Apr 2019 09:00:58 -0600
Subject: [PATCH 2/5] Add prefixes to some window system-dependent procedures

* src/nsterm.m:
* src/w32fns.c:
* src/w32inevt.c:
* src/w32term.c:
* src/w32term.h:
* src/xterm.c: Add prefixes.
---
 src/nsterm.m   |  6 +++---
 src/w32fns.c   |  8 ++++----
 src/w32inevt.c |  2 +-
 src/w32term.c  | 43 +++++++++++++++++++++++--------------------
 src/w32term.h  |  2 +-
 src/xterm.c    | 42 +++++++++++++++++++++---------------------
 6 files changed, 53 insertions(+), 50 deletions(-)

diff --git a/src/nsterm.m b/src/nsterm.m
index 15316e23ed..62fb4b2e21 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -2467,7 +2467,7 @@ so some key presses (TAB) are swallowed by the system.  */
 }
 
 static int
-note_mouse_movement (struct frame *frame, CGFloat x, CGFloat y)
+ns_note_mouse_movement (struct frame *frame, CGFloat x, CGFloat y)
 /*   ------------------------------------------------------------------------
      Called by EmacsView on mouseMovement events.  Passes on
      to emacs mainstream code if we moved off of a rect of interest
@@ -6890,7 +6890,7 @@ - (void)mouseMoved: (NSEvent *)e
       last_mouse_window = window;
     }
 
-  if (!note_mouse_movement (emacsframe, pt.x, pt.y))
+  if (!ns_note_mouse_movement (emacsframe, pt.x, pt.y))
     help_echo_string = previous_help_echo_string;
 
   XSETFRAME (frame, emacsframe);
@@ -6898,7 +6898,7 @@ - (void)mouseMoved: (NSEvent *)e
     {
       /* NOTE: help_echo_{window,pos,object} are set in xdisp.c
          (note_mouse_highlight), which is called through the
-         note_mouse_movement () call above.  */
+         ns_note_mouse_movement () call above.  */
       any_help_event_p = YES;
       gen_help_event (help_echo_string, frame, help_echo_window,
                       help_echo_object, help_echo_pos);
diff --git a/src/w32fns.c b/src/w32fns.c
index 814998f5f2..e6cb1ee311 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -3061,7 +3061,7 @@ w32_get_modifiers (void)
    and window input.  */
 
 static int
-construct_console_modifiers (void)
+w32_construct_console_modifiers (void)
 {
   int mods;
 
@@ -3087,7 +3087,7 @@ w32_get_key_modifiers (unsigned int wparam, unsigned int lparam)
   int mods;
 
   /* Convert to emacs modifiers.  */
-  mods = w32_kbd_mods_to_emacs (construct_console_modifiers (), wparam);
+  mods = w32_kbd_mods_to_emacs (w32_construct_console_modifiers (), wparam);
 
   return mods;
 }
@@ -3719,7 +3719,7 @@ deliver_wm_chars (int do_translate, HWND hwnd, UINT msg, UINT wParam,
   if (count)
     {
       W32Msg wmsg;
-      DWORD console_modifiers = construct_console_modifiers ();
+      DWORD console_modifiers = w32_construct_console_modifiers ();
       int *b = buf, strip_ExtraMods = 1, hairy = 0;
       const char *type_CtrlAlt = NULL;
 
@@ -4351,7 +4351,7 @@ w32_wnd_proc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 	  /* If not defined as a function key, change it to a WM_CHAR message.  */
 	  if (wParam > 255 || !lispy_function_keys[wParam])
 	    {
-	      DWORD modifiers = construct_console_modifiers ();
+	      DWORD modifiers = w32_construct_console_modifiers ();
 
 	      if (!NILP (Vw32_recognize_altgr)
 		  && modifier_set (VK_LCONTROL) && modifier_set (VK_RMENU))
diff --git a/src/w32inevt.c b/src/w32inevt.c
index ab71c560d6..fc1f90cd02 100644
--- a/src/w32inevt.c
+++ b/src/w32inevt.c
@@ -680,7 +680,7 @@ handle_file_notifications (struct input_event *hold_quit)
 		     already be defined at this point.  */
 		  Lisp_Object fname
 		    = code_convert_string_norecord (utf_16_fn, cs, 0);
-		  Lisp_Object action = lispy_file_action (fni->Action);
+		  Lisp_Object action = w32_lispy_file_action (fni->Action);
 
 		  inev.kind = FILE_NOTIFY_EVENT;
 		  inev.timestamp = GetTickCount ();
diff --git a/src/w32term.c b/src/w32term.c
index a43d43c558..edcdc56a9e 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -180,8 +180,8 @@ static void w32_initialize (void);
 static void x_update_end (struct frame *);
 static void w32_frame_up_to_date (struct frame *);
 static void x_clear_frame (struct frame *);
-static void frame_highlight (struct frame *);
-static void frame_unhighlight (struct frame *);
+static void w32_frame_highlight (struct frame *);
+static void w32_frame_unhighlight (struct frame *);
 static void x_new_focus_frame (struct w32_display_info *,
                                struct frame *);
 static void x_focus_changed (int, int, struct w32_display_info *,
@@ -2904,14 +2904,14 @@ x_scroll_run (struct window *w, struct run *run)
  ***********************************************************************/
 
 static void
-frame_highlight (struct frame *f)
+w32_frame_highlight (struct frame *f)
 {
   gui_update_cursor (f, 1);
   x_set_frame_alpha (f);
 }
 
 static void
-frame_unhighlight (struct frame *f)
+w32_frame_unhighlight (struct frame *f)
 {
   gui_update_cursor (f, 1);
   x_set_frame_alpha (f);
@@ -3059,9 +3059,9 @@ x_frame_rehighlight (struct w32_display_info *dpyinfo)
   if (dpyinfo->x_highlight_frame != old_highlight)
     {
       if (old_highlight)
-	frame_unhighlight (old_highlight);
+	w32_frame_unhighlight (old_highlight);
       if (dpyinfo->x_highlight_frame)
-	frame_highlight (dpyinfo->x_highlight_frame);
+	w32_frame_highlight (dpyinfo->x_highlight_frame);
     }
 }
 \f
@@ -3168,7 +3168,8 @@ parse_button (int message, int xbutton, int * pbutton, int * pup)
    the mouse.  */
 
 static Lisp_Object
-construct_mouse_click (struct input_event *result, W32Msg *msg, struct frame *f)
+w32_construct_mouse_click (struct input_event *result, W32Msg *msg,
+                           struct frame *f)
 {
   int button = 0;
   int up = 0;
@@ -3194,7 +3195,8 @@ construct_mouse_click (struct input_event *result, W32Msg *msg, struct frame *f)
 }
 
 static Lisp_Object
-construct_mouse_wheel (struct input_event *result, W32Msg *msg, struct frame *f)
+w32_construct_mouse_wheel (struct input_event *result, W32Msg *msg,
+                           struct frame *f)
 {
   POINT p;
   int delta;
@@ -3228,7 +3230,8 @@ construct_mouse_wheel (struct input_event *result, W32Msg *msg, struct frame *f)
 }
 
 static Lisp_Object
-construct_drag_n_drop (struct input_event *result, W32Msg *msg, struct frame *f)
+w32_construct_drag_n_drop (struct input_event *result, W32Msg *msg,
+                           struct frame *f)
 {
   Lisp_Object files;
   Lisp_Object frame;
@@ -3307,7 +3310,7 @@ construct_drag_n_drop (struct input_event *result, W32Msg *msg, struct frame *f)
 /* File event notifications (see w32notify.c).  */
 
 Lisp_Object
-lispy_file_action (DWORD action)
+w32_lispy_file_action (DWORD action)
 {
   static char unknown_fmt[] = "unknown-action(%d)";
   Lisp_Object retval;
@@ -3347,8 +3350,8 @@ lispy_file_action (DWORD action)
    function runs when the WM_EMACS_FILENOTIFY message arrives from a
    watcher thread.  */
 static void
-queue_notifications (struct input_event *event, W32Msg *msg, struct frame *f,
-		     int *evcount)
+w32_queue_notifications (struct input_event *event, W32Msg *msg,
+                         struct frame *f, int *evcount)
 {
   struct notifications_set *ns = NULL;
   Lisp_Object frame;
@@ -3407,7 +3410,7 @@ queue_notifications (struct input_event *event, W32Msg *msg, struct frame *f,
 		     already be defined at this point.  */
 		  Lisp_Object fname
 		    = code_convert_string_norecord (utf_16_fn, cs, 0);
-		  Lisp_Object action = lispy_file_action (fni->Action);
+		  Lisp_Object action = w32_lispy_file_action (fni->Action);
 
 		  event->kind = FILE_NOTIFY_EVENT;
 		  event->timestamp = msg->msg.time;
@@ -3445,7 +3448,7 @@ queue_notifications (struct input_event *event, W32Msg *msg, struct frame *f,
    another motion event, so we can check again the next time it moves.  */
 
 static int
-note_mouse_movement (struct frame *frame, MSG *msg)
+w32_note_mouse_movement (struct frame *frame, MSG *msg)
 {
   struct w32_display_info *dpyinfo;
   int mouse_x = LOWORD (msg->lParam);
@@ -5020,7 +5023,7 @@ w32_read_socket (struct terminal *terminal,
 		  last_mouse_window = window;
 		}
 
-	      if (!note_mouse_movement (f, &msg.msg))
+	      if (!w32_note_mouse_movement (f, &msg.msg))
 		help_echo_string = previous_help_echo_string;
 	    }
 	  else
@@ -5064,7 +5067,7 @@ w32_read_socket (struct terminal *terminal,
 
 	    if (f)
 	      {
-                construct_mouse_click (&inev, &msg, f);
+                w32_construct_mouse_click (&inev, &msg, f);
 
                 /* Is this in the tool-bar?  */
                 if (WINDOWP (f->tool_bar_window)
@@ -5129,7 +5132,7 @@ w32_read_socket (struct terminal *terminal,
 		    || f == dpyinfo->w32_focus_frame)
 		  /* Emit an Emacs wheel-up/down event.  */
 		  {
-		    construct_mouse_wheel (&inev, &msg, f);
+		    w32_construct_mouse_wheel (&inev, &msg, f);
 
 		    /* Ignore any mouse motion that happened before this
 		       event; any subsequent mouse-movement Emacs events
@@ -5146,7 +5149,7 @@ w32_read_socket (struct terminal *terminal,
 
 		    if (f1 && FRAME_LIVE_P (f1) && FRAME_W32_P (f1))
 		      {
-			construct_mouse_wheel (&inev, &msg, f1);
+			w32_construct_mouse_wheel (&inev, &msg, f1);
 			f1->mouse_moved = false;
 			f1->last_tool_bar_item = -1;
 			dpyinfo->last_mouse_frame = f1;
@@ -5166,7 +5169,7 @@ w32_read_socket (struct terminal *terminal,
 	  f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
 
 	  if (f)
-	    construct_drag_n_drop (&inev, &msg, f);
+	    w32_construct_drag_n_drop (&inev, &msg, f);
 	  break;
 
 	case WM_HSCROLL:
@@ -5577,7 +5580,7 @@ w32_read_socket (struct terminal *terminal,
 	case WM_EMACS_FILENOTIFY:
 	  f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
 	  if (f)
-	    queue_notifications (&inev, &msg, f, &count);
+	    w32_queue_notifications (&inev, &msg, f, &count);
 	  break;
 #endif
 
diff --git a/src/w32term.h b/src/w32term.h
index 4c496e97e4..a0942d630a 100644
--- a/src/w32term.h
+++ b/src/w32term.h
@@ -732,7 +732,7 @@ struct notifications_set {
 };
 extern struct notifications_set *notifications_set_head;
 extern Lisp_Object w32_get_watch_object (void *);
-extern Lisp_Object lispy_file_action (DWORD);
+extern Lisp_Object w32_lispy_file_action (DWORD);
 extern int handle_file_notifications (struct input_event *);
 
 extern void w32_initialize_display_info (Lisp_Object);
diff --git a/src/xterm.c b/src/xterm.c
index 4145542dfa..bf6e3837a8 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -234,7 +234,7 @@ static void x_wm_set_window_state (struct frame *, int);
 static void x_wm_set_icon_pixmap (struct frame *, ptrdiff_t);
 static void x_initialize (void);
 
-static bool get_current_wm_state (struct frame *, Window, int *, bool *);
+static bool x_get_current_wm_state (struct frame *, Window, int *, bool *);
 
 /* Flush display of frame F.  */
 
@@ -4379,7 +4379,7 @@ x_scroll_run (struct window *w, struct run *run)
 
 \f
 static void
-frame_highlight (struct frame *f)
+x_frame_highlight (struct frame *f)
 {
   /* We used to only do this if Vx_no_window_manager was non-nil, but
      the ICCCM (section 4.1.6) says that the window's border pixmap
@@ -4400,7 +4400,7 @@ frame_highlight (struct frame *f)
 }
 
 static void
-frame_unhighlight (struct frame *f)
+x_frame_unhighlight (struct frame *f)
 {
   /* We used to only do this if Vx_no_window_manager was non-nil, but
      the ICCCM (section 4.1.6) says that the window's border pixmap
@@ -4765,9 +4765,9 @@ x_frame_rehighlight (struct x_display_info *dpyinfo)
   if (dpyinfo->x_highlight_frame != old_highlight)
     {
       if (old_highlight)
-	frame_unhighlight (old_highlight);
+	x_frame_unhighlight (old_highlight);
       if (dpyinfo->x_highlight_frame)
-	frame_highlight (dpyinfo->x_highlight_frame);
+	x_frame_highlight (dpyinfo->x_highlight_frame);
     }
 }
 
@@ -4987,9 +4987,9 @@ x_get_keysym_name (int keysym)
    the mouse.  */
 
 static Lisp_Object
-construct_mouse_click (struct input_event *result,
-		       const XButtonEvent *event,
-		       struct frame *f)
+x_construct_mouse_click (struct input_event *result,
+                         const XButtonEvent *event,
+                         struct frame *f)
 {
   /* Make the event type NO_EVENT; we'll change that when we decide
      otherwise.  */
@@ -5018,7 +5018,7 @@ construct_mouse_click (struct input_event *result,
    another motion event, so we can check again the next time it moves.  */
 
 static bool
-note_mouse_movement (struct frame *frame, const XMotionEvent *event)
+x_note_mouse_movement (struct frame *frame, const XMotionEvent *event)
 {
   XRectangle *r;
   struct x_display_info *dpyinfo;
@@ -7695,7 +7695,7 @@ x_net_wm_state (struct frame *f, Window window)
   Lisp_Object lval = Qnil;
   bool sticky = false;
 
-  get_current_wm_state (f, window, &value, &sticky);
+  x_get_current_wm_state (f, window, &value, &sticky);
 
   switch (value)
     {
@@ -8619,12 +8619,12 @@ handle_one_xevent (struct x_display_info *dpyinfo,
       /* EnterNotify counts as mouse movement,
 	 so update things that depend on mouse position.  */
       if (f && !f->output_data.x->hourglass_p)
-	note_mouse_movement (f, &event->xmotion);
+	x_note_mouse_movement (f, &event->xmotion);
 #ifdef USE_GTK
       /* We may get an EnterNotify on the buttons in the toolbar.  In that
          case we moved out of any highlighted area and need to note this.  */
       if (!f && dpyinfo->last_mouse_glyph_frame)
-        note_mouse_movement (dpyinfo->last_mouse_glyph_frame, &event->xmotion);
+        x_note_mouse_movement (dpyinfo->last_mouse_glyph_frame, &event->xmotion);
 #endif
       goto OTHER;
 
@@ -8657,7 +8657,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
 #ifdef USE_GTK
       /* See comment in EnterNotify above */
       else if (dpyinfo->last_mouse_glyph_frame)
-        note_mouse_movement (dpyinfo->last_mouse_glyph_frame, &event->xmotion);
+        x_note_mouse_movement (dpyinfo->last_mouse_glyph_frame, &event->xmotion);
 #endif
       goto OTHER;
 
@@ -8726,7 +8726,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
 		last_mouse_window = window;
 	      }
 
-            if (!note_mouse_movement (f, &event->xmotion))
+            if (!x_note_mouse_movement (f, &event->xmotion))
 	      help_echo_string = previous_help_echo_string;
           }
         else
@@ -8984,13 +8984,13 @@ handle_one_xevent (struct x_display_info *dpyinfo,
                           && event->xbutton.time > ignore_next_mouse_click_timeout)
                         {
                           ignore_next_mouse_click_timeout = 0;
-                          construct_mouse_click (&inev.ie, &event->xbutton, f);
+                          x_construct_mouse_click (&inev.ie, &event->xbutton, f);
                         }
                       if (event->type == ButtonRelease)
                         ignore_next_mouse_click_timeout = 0;
                     }
                   else
-                    construct_mouse_click (&inev.ie, &event->xbutton, f);
+                    x_construct_mouse_click (&inev.ie, &event->xbutton, f);
                 }
             if (FRAME_X_EMBEDDED_P (f))
               xembed_send_message (f, event->xbutton.time,
@@ -10696,10 +10696,10 @@ x_set_z_group (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
    Return true iff we are not hidden.  */
 
 static bool
-get_current_wm_state (struct frame *f,
-                      Window window,
-                      int *size_state,
-                      bool *sticky)
+x_get_current_wm_state (struct frame *f,
+                        Window window,
+                        int *size_state,
+                        bool *sticky)
 {
   unsigned long actual_size;
   int i;
@@ -10947,7 +10947,7 @@ x_handle_net_wm_state (struct frame *f, const XPropertyEvent *event)
   int value = FULLSCREEN_NONE;
   Lisp_Object lval;
   bool sticky = false;
-  bool not_hidden = get_current_wm_state (f, event->window, &value, &sticky);
+  bool not_hidden = x_get_current_wm_state (f, event->window, &value, &sticky);
 
   lval = Qnil;
   switch (value)
-- 
2.21.0


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0003-Rename-non-X-x_-identifiers.patch --]
[-- Type: text/x-patch, Size: 289044 bytes --]

From 55a39c6cb4eb9a1442dd3388766f0219bf8cd825 Mon Sep 17 00:00:00 2001
From: Alexander Gramiak <agrambot@gmail.com>
Date: Sat, 13 Apr 2019 09:40:03 -0600
Subject: [PATCH 3/5] Rename non-X x_* identifiers

* src/image.c: Rename x_* procedures to image_* and gui_*.

* src/frame.c: Rename x_* procedures to gui_*.
* src/nsfns.c:
* src/nsterm.m: Rename x_* procedures to ns_*.

* src/w32fns.c:
* src/w32term.c: Rename x_* procedures to w32_*.

* src/termhooks.h (focus_frame_hook)
(iconify_frame_hook, set_frame_alpha_hook)
(set_new_font_hook, implicit_set_name_hook)
(change_tool_bar_height_hook, set_scroll_bar_default_width_hook)
(set_scroll_bar_default_height_hook): New terminal hooks.

* src/dispextern.h (clear_under_internal_border): New RIF function
pointer.
---
 src/dispextern.h |  32 +--
 src/fontset.c    |  15 +-
 src/frame.c      | 194 ++++++++--------
 src/frame.h      |  70 +++---
 src/gtkutil.c    |  14 +-
 src/image.c      | 306 +++++++++++++------------
 src/keyboard.c   |   2 +-
 src/lisp.h       |   2 +-
 src/nsfns.m      | 310 ++++++++++++-------------
 src/nsterm.h     |  40 ++--
 src/nsterm.m     | 162 ++++++++-----
 src/termhooks.h  |  26 +++
 src/w32fns.c     | 578 +++++++++++++++++++++++------------------------
 src/w32font.c    |   2 +-
 src/w32menu.c    |   2 +-
 src/w32term.c    | 555 +++++++++++++++++++++++----------------------
 src/w32term.h    |  31 +--
 src/window.c     |   2 +-
 src/xdisp.c      |  23 +-
 src/xfaces.c     |   8 +-
 src/xfns.c       | 361 +++++++++++++----------------
 src/xterm.c      | 122 +++++++---
 src/xterm.h      |  17 +-
 23 files changed, 1470 insertions(+), 1404 deletions(-)

diff --git a/src/dispextern.h b/src/dispextern.h
index 79ec4ce52e..d42b0359ed 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -2897,6 +2897,11 @@ struct redisplay_interface
   void (*clear_frame_area) (struct frame *f, int x, int y,
                             int width, int height);
 
+ /* Clear area of frame F's internal border.  If the internal border
+    face of F has been specified (is not null), fill the area with
+    that face.  */
+  void (*clear_under_internal_border) (struct frame *f);
+
   /* Draw specified cursor CURSOR_TYPE of width CURSOR_WIDTH
      at row GLYPH_ROW on window W if ON_P is true.  If ON_P is
      false, don't draw cursor.  If ACTIVE_P is true, system caret
@@ -3348,19 +3353,19 @@ extern bool buffer_flipping_blocked_p (void);
 #ifdef HAVE_WINDOW_SYSTEM
 
 extern ptrdiff_t x_bitmap_pixmap (struct frame *, ptrdiff_t);
-extern void x_reference_bitmap (struct frame *, ptrdiff_t);
-extern ptrdiff_t x_create_bitmap_from_data (struct frame *, char *,
+extern void gui_reference_bitmap (struct frame *, ptrdiff_t);
+extern ptrdiff_t gui_create_bitmap_from_data (struct frame *, char *,
 					    unsigned int, unsigned int);
-extern ptrdiff_t x_create_bitmap_from_file (struct frame *, Lisp_Object);
+extern ptrdiff_t gui_create_bitmap_from_file (struct frame *, Lisp_Object);
 #if defined HAVE_XPM && defined HAVE_X_WINDOWS && !defined USE_GTK
 extern ptrdiff_t x_create_bitmap_from_xpm_data (struct frame *, const char **);
 #endif
 #ifndef x_destroy_bitmap
 extern void x_destroy_bitmap (struct frame *, ptrdiff_t);
 #endif
-extern void x_destroy_all_bitmaps (Display_Info *);
+extern void gui_destroy_all_bitmaps (Display_Info *);
 extern void x_create_bitmap_mask (struct frame *, ptrdiff_t);
-extern Lisp_Object x_find_image_file (Lisp_Object);
+extern Lisp_Object gui_find_image_file (Lisp_Object);
 
 void x_kill_gs_process (Pixmap, struct frame *);
 struct image_cache *make_image_cache (void);
@@ -3446,11 +3451,6 @@ void gamma_correct (struct frame *, COLORREF *);
 
 #ifdef HAVE_WINDOW_SYSTEM
 
-void x_implicitly_set_name (struct frame *, Lisp_Object, Lisp_Object);
-void x_change_tool_bar_height (struct frame *f, int);
-
-extern frame_parm_handler x_frame_parm_handlers[];
-
 extern void start_hourglass (void);
 extern void cancel_hourglass (void);
 
@@ -3593,16 +3593,16 @@ extern Lisp_Object x_frame_get_and_record_arg (struct frame *, Lisp_Object,
                                                Lisp_Object,
 					       const char *, const char *,
                                                enum resource_types);
-extern Lisp_Object x_default_parameter (struct frame *, Lisp_Object,
-                                        Lisp_Object, Lisp_Object,
-                                        const char *, const char *,
-                                        enum resource_types);
+extern Lisp_Object gui_default_parameter (struct frame *, Lisp_Object,
+                                          Lisp_Object, Lisp_Object,
+                                          const char *, const char *,
+                                          enum resource_types);
 extern char *x_get_string_resource (XrmDatabase, const char *,
 				    const char *);
 
 #ifndef HAVE_NS /* These both used on W32 and X only.  */
-extern bool x_mouse_grabbed (Display_Info *);
-extern void x_redo_mouse_highlight (Display_Info *);
+extern bool gui_mouse_grabbed (Display_Info *);
+extern void gui_redo_mouse_highlight (Display_Info *);
 #endif /* HAVE_NS */
 
 #endif /* HAVE_WINDOW_SYSTEM */
diff --git a/src/fontset.c b/src/fontset.c
index eec1e0da4c..0a6edc7eb1 100644
--- a/src/fontset.c
+++ b/src/fontset.c
@@ -1743,13 +1743,14 @@ static Lisp_Object auto_fontset_alist;
 static ptrdiff_t num_auto_fontsets;
 
 /* Return a fontset synthesized from FONT-OBJECT.  This is called from
-   x_new_font when FONT-OBJECT is used for the default ASCII font of a
-   frame, and the returned fontset is used for the default fontset of
-   that frame.  The fontset specifies a font of the same registry as
-   FONT-OBJECT for all characters in the repertory of the registry
-   (see Vfont_encoding_alist).  If the repertory is not known, the
-   fontset specifies the font for all Latin characters assuming that a
-   user intends to use FONT-OBJECT for Latin characters.  */
+   the terminal hook set_new_font_hook when FONT-OBJECT is used for
+   the default ASCII font of a frame, and the returned fontset is used
+   for the default fontset of that frame.  The fontset specifies a
+   font of the same registry as FONT-OBJECT for all characters in the
+   repertory of the registry (see Vfont_encoding_alist).  If the
+   repertory is not known, the fontset specifies the font for all
+   Latin characters assuming that a user intends to use FONT-OBJECT
+   for Latin characters.  */
 
 int
 fontset_from_font (Lisp_Object font_object)
diff --git a/src/frame.c b/src/frame.c
index 192ef4244f..48a6aa7668 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -77,7 +77,7 @@ int frame_default_tool_bar_height;
 #endif
 
 #ifdef HAVE_WINDOW_SYSTEM
-static void x_report_frame_params (struct frame *, Lisp_Object *);
+static void gui_report_frame_params (struct frame *, Lisp_Object *);
 #endif
 
 /* These setters are used only in this file, so they can be private.  */
@@ -537,8 +537,8 @@ keep_ratio (struct frame *f, struct frame *p, int old_width, int old_height,
  *   the frame's text height).
  *
  * 3 means call x_set_window_size if window minimum sizes must be
- *   preserved or frame_inhibit_resize allows it.  x_set_left_fringe,
- *   x_set_scroll_bar_width, x_new_font ... use (or should use) this.
+ *   preserved or frame_inhibit_resize allows it.  gui_set_left_fringe,
+ *   gui_set_scroll_bar_width, gui_new_font ... use (or should use) this.
  *
  * 4 means call x_set_window_size only if window minimum sizes must be
  *   preserved.  x_set_right_divider_width, x_set_border_width and the
@@ -1296,6 +1296,32 @@ affects all frames on the same terminal device.  */)
   return frame;
 }
 
+#ifdef HAVE_WINDOW_SYSTEM
+Lisp_Object
+gui_get_focus_frame (struct frame *frame)
+{
+  Lisp_Object gfocus;
+  struct frame *gui_focus_frame;
+
+#ifdef HAVE_X_WINDOWS
+  struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (frame);
+  gui_focus_frame = dpyinfo->x_focus_frame;
+#elif defined (HAVE_NTGUI)
+  struct w32_display_info *dpyinfo = FRAME_DISPLAY_INFO (frame);
+  gui_focus_frame = dpyinfo->w32_focus_frame;
+#elif defined (HAVE_NS)
+  struct ns_display_info *dpyinfo = FRAME_DISPLAY_INFO (frame);
+  gui_focus_frame = dpyinfo->ns_focus_frame;
+#endif
+
+  if (!gui_focus_frame)
+    return Qnil;
+
+  XSETFRAME (gfocus, gui_focus_frame);
+  return gfocus;
+}
+#endif
+
 \f
 /* Perform the switch to frame FRAME.
 
@@ -1366,18 +1392,18 @@ do_switch_frame (Lisp_Object frame, int track, int for_deletion, Lisp_Object nor
 #ifdef HAVE_WINDOW_SYSTEM
   if (track && FRAME_WINDOW_P (f))
     {
-      Lisp_Object focus, xfocus;
+      Lisp_Object focus, gfocus;
 
-      xfocus = x_get_focus_frame (f);
-      if (FRAMEP (xfocus))
+      gfocus = gui_get_focus_frame (f);
+      if (FRAMEP (gfocus))
 	{
-	  focus = FRAME_FOCUS_FRAME (XFRAME (xfocus));
+	  focus = FRAME_FOCUS_FRAME (XFRAME (gfocus));
 	  if ((FRAMEP (focus) && XFRAME (focus) == SELECTED_FRAME ())
 	      /* Redirect frame focus also when FRAME has its minibuffer
 		 window on the selected frame (see Bug#24500).  */
 	      || (NILP (focus)
 		  && EQ (FRAME_MINIBUF_WINDOW (f), sf->selected_window)))
-	    Fredirect_frame_focus (xfocus, frame);
+	    Fredirect_frame_focus (gfocus, frame);
 	}
     }
 #endif /* HAVE_X_WINDOWS */
@@ -2583,11 +2609,8 @@ If omitted, FRAME defaults to the currently selected frame.  */)
 {
   struct frame *f = decode_live_frame (frame);
 
-  /* I think this should be done with a hook.  */
-#ifdef HAVE_WINDOW_SYSTEM
-  if (FRAME_WINDOW_P (f))
-    x_make_frame_visible (f);
-#endif
+  if (FRAME_WINDOW_P (f) && FRAME_TERMINAL (f)->frame_visible_invisible_hook)
+    FRAME_TERMINAL (f)->frame_visible_invisible_hook (f, true);
 
   make_frame_visible_1 (f->root_window);
 
@@ -2639,11 +2662,8 @@ displayed in the terminal.  */)
   /* Don't allow minibuf_window to remain on an invisible frame.  */
   check_minibuf_window (frame, EQ (minibuf_window, selected_window));
 
-  /* I think this should be done with a hook.  */
-#ifdef HAVE_WINDOW_SYSTEM
-  if (FRAME_WINDOW_P (f))
-    x_make_frame_invisible (f);
-#endif
+  if (FRAME_WINDOW_P (f) && FRAME_TERMINAL (f)->frame_visible_invisible_hook)
+    FRAME_TERMINAL (f)->frame_visible_invisible_hook (f, false);
 
   /* Make menu bar update for the Buffers and Frames menus.  */
   windows_or_buffers_changed = 16;
@@ -2687,13 +2707,8 @@ for how to proceed.  */)
   /* Don't allow minibuf_window to remain on an iconified frame.  */
   check_minibuf_window (frame, EQ (minibuf_window, selected_window));
 
-  /* I think this should be done with a hook.  */
-  if (FRAME_WINDOW_P (f))
-    {
-#ifdef HAVE_WINDOW_SYSTEM
-      x_iconify_frame (f);
-#endif
-    }
+  if (FRAME_WINDOW_P (f) && FRAME_TERMINAL (f)->iconify_frame_hook)
+    FRAME_TERMINAL (f)->iconify_frame_hook (f);
 
   return Qnil;
 }
@@ -2755,7 +2770,7 @@ doesn't support multiple overlapping frames, this function selects FRAME.  */)
     Fmake_frame_visible (frame);
 
   if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
-    (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 1);
+    (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, true);
 
   return Qnil;
 }
@@ -2771,7 +2786,7 @@ doesn't support multiple overlapping frames, this function does nothing.  */)
   struct frame *f = decode_live_frame (frame);
 
   if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
-    (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
+    (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, false);
 
   return Qnil;
 }
@@ -2840,7 +2855,9 @@ If there is no window system support, this function does nothing.  */)
      (Lisp_Object frame, Lisp_Object noactivate)
 {
 #ifdef HAVE_WINDOW_SYSTEM
-  x_focus_frame (decode_window_system_frame (frame), !NILP (noactivate));
+  struct frame *f = decode_window_system_frame (frame);
+  if (f)
+    FRAME_TERMINAL (f)->focus_frame_hook (f, !NILP (noactivate));
 #endif
   return Qnil;
 }
@@ -2911,7 +2928,7 @@ frame_name_fnn_p (char *str, ptrdiff_t len)
 }
 
 /* Set the name of the terminal frame.  Also used by MSDOS frames.
-   Modeled after x_set_name which is used for WINDOW frames.  */
+   Modeled after *_set_name which is used for WINDOW frames.  */
 
 static void
 set_term_frame_name (struct frame *f, Lisp_Object name)
@@ -3163,7 +3180,7 @@ If FRAME is omitted or nil, return information on the currently selected frame.
   /* I think this should be done with a hook.  */
 #ifdef HAVE_WINDOW_SYSTEM
   if (FRAME_WINDOW_P (f))
-    x_report_frame_params (f, &alist);
+    gui_report_frame_params (f, &alist);
   else
 #endif
     {
@@ -3269,7 +3286,7 @@ list, but are otherwise ignored.  */)
   /* I think this should be done with a hook.  */
 #ifdef HAVE_WINDOW_SYSTEM
   if (FRAME_WINDOW_P (f))
-    x_set_frame_parameters (f, alist);
+    gui_set_frame_parameters (f, alist);
   else
 #endif
 #ifdef MSDOS
@@ -3651,12 +3668,12 @@ window state change flag is reset.  */)
 				Frame Parameters
  ***********************************************************************/
 
-/* Connect the frame-parameter names for X frames
-   to the ways of passing the parameter values to the window system.
+/* Connect the frame-parameter names for frames to the ways of passing
+   the parameter values to the window system.
 
-   The name of a parameter, as a Lisp symbol,
-   has an `x-frame-parameter' property which is an integer in Lisp
-   that is an index in this table.  */
+   The name of a parameter, as a Lisp symbol, has a
+   `frame-parameter-pos' property which is an integer in Lisp that is
+   an index in this table.  */
 
 struct frame_parm_table {
   const char *name;
@@ -3903,12 +3920,12 @@ frame_float (struct frame *f, Lisp_Object val, enum frame_float_type what,
 
 /* Change the parameters of frame F as specified by ALIST.
    If a parameter is not specially recognized, do nothing special;
-   otherwise call the `x_set_...' function for that parameter.
+   otherwise call the `gui_set_...' function for that parameter.
    Except for certain geometry properties, always call store_frame_param
    to store the new value in the parameter alist.  */
 
 void
-x_set_frame_parameters (struct frame *f, Lisp_Object alist)
+gui_set_frame_parameters (struct frame *f, Lisp_Object alist)
 {
   Lisp_Object tail, frame;
 
@@ -4035,7 +4052,7 @@ x_set_frame_parameters (struct frame *f, Lisp_Object alist)
 
 	  store_frame_param (f, prop, val);
 
-	  param_index = Fget (prop, Qx_frame_parameter);
+	  param_index = Fget (prop, Qframe_parameter_pos);
 	  if (FIXNATP (param_index)
 	      && XFIXNAT (param_index) < ARRAYELTS (frame_parms)
 	      && FRAME_RIF (f)->frame_parm_handlers[XFIXNUM (param_index)])
@@ -4097,7 +4114,7 @@ x_set_frame_parameters (struct frame *f, Lisp_Object alist)
        EmacsFrameResize intermittently provokes a delayed
        change_frame_size in the middle of adjust_frame_size.  */
     /** 	|| (f->can_x_set_window_size && (f->new_height || f->new_width))) **/
-    adjust_frame_size (f, width, height, 1, 0, Qx_set_frame_parameters);
+    adjust_frame_size (f, width, height, 1, 0, Qgui_set_frame_parameters);
 
   if ((!NILP (left) || !NILP (top))
       && ! (left_no_change && top_no_change)
@@ -4174,7 +4191,7 @@ x_set_frame_parameters (struct frame *f, Lisp_Object alist)
 
       store_frame_param (f, Qfullscreen, fullscreen);
       if (!EQ (fullscreen, old_value))
-	x_set_fullscreen (f, fullscreen, old_value);
+	gui_set_fullscreen (f, fullscreen, old_value);
     }
 
 
@@ -4188,14 +4205,14 @@ x_set_frame_parameters (struct frame *f, Lisp_Object alist)
 }
 
 
-/* Insert a description of internally-recorded parameters of frame X
+/* Insert a description of internally-recorded parameters of frame F
    into the parameter alist *ALISTPTR that is to be given to the user.
    Only parameters that are specific to the X window system
    and whose values are not correctly recorded in the frame's
    param_alist need to be considered here.  */
 
 void
-x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
+gui_report_frame_params (struct frame *f, Lisp_Object *alistptr)
 {
   Lisp_Object tem;
   uprintmax_t w;
@@ -4277,7 +4294,7 @@ x_report_frame_params (struct frame *f, Lisp_Object *alistptr)
    the previous value of that parameter, NEW_VALUE is the new value. */
 
 void
-x_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
+gui_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
 {
   if (NILP (new_value))
     f->want_fullscreen = FULLSCREEN_NONE;
@@ -4299,7 +4316,7 @@ x_set_fullscreen (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
    the previous value of that parameter, NEW_VALUE is the new value.  */
 
 void
-x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
+gui_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
 {
   if (NILP (new_value))
     f->extra_line_spacing = 0;
@@ -4325,7 +4342,7 @@ x_set_line_spacing (struct frame *f, Lisp_Object new_value, Lisp_Object old_valu
    the previous value of that parameter, NEW_VALUE is the new value.  */
 
 void
-x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
+gui_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
 {
   Lisp_Object bgcolor;
 
@@ -4341,7 +4358,7 @@ x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_valu
   bgcolor = Fassq (Qbackground_color, f->param_alist);
   if (CONSP (bgcolor) && (bgcolor = XCDR (bgcolor), STRINGP (bgcolor)))
     {
-      Lisp_Object parm_index = Fget (Qbackground_color, Qx_frame_parameter);
+      Lisp_Object parm_index = Fget (Qbackground_color, Qframe_parameter_pos);
       if (FIXNATP (parm_index)
 	  && XFIXNAT (parm_index) < ARRAYELTS (frame_parms)
 	  && FRAME_RIF (f)->frame_parm_handlers[XFIXNAT (parm_index)])
@@ -4355,7 +4372,7 @@ x_set_screen_gamma (struct frame *f, Lisp_Object new_value, Lisp_Object old_valu
 
 
 void
-x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
+gui_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
   Lisp_Object font_object;
   int fontset = -1;
@@ -4425,8 +4442,8 @@ x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 	  /* SPEC might be nil because ASCII_FONT's name doesn't parse
 	     according to stupid XLFD rules, which, for example,
 	     disallow font names that include a dash followed by a
-	     number.  So in those cases we simply request x_new_font
-	     below to generate a new fontset.  */
+	     number.  So in those cases we simply call
+	     set_new_font_hook below to generate a new fontset.  */
 	  if (NILP (spec) || ! font_match_p (spec, font_object))
 	    fontset = -1;
 	}
@@ -4437,7 +4454,7 @@ x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
   if (! NILP (Fequal (font_object, oldval)))
     return;
 
-  x_new_font (f, font_object, fontset);
+  FRAME_TERMINAL (f)->set_new_font_hook (f, font_object, fontset);
   store_frame_param (f, Qfont, arg);
 #ifdef HAVE_X_WINDOWS
   store_frame_param (f, Qfont_parameter, font_param);
@@ -4469,7 +4486,7 @@ x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 
 
 void
-x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
+gui_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
 {
   if (! NILP (new_value)
       && !CONSP (new_value))
@@ -4517,14 +4534,14 @@ x_set_font_backend (struct frame *f, Lisp_Object new_value, Lisp_Object old_valu
       Lisp_Object frame;
 
       XSETFRAME (frame, f);
-      x_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
+      gui_set_font (f, Fframe_parameter (frame, Qfont), Qnil);
       face_change = true;
       windows_or_buffers_changed = 18;
     }
 }
 
 void
-x_set_left_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
+gui_set_left_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
 {
   int unit = FRAME_COLUMN_WIDTH (f);
   int old_width = FRAME_LEFT_FRINGE_WIDTH (f);
@@ -4548,7 +4565,7 @@ x_set_left_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value
 
 
 void
-x_set_right_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
+gui_set_right_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
 {
   int unit = FRAME_COLUMN_WIDTH (f);
   int old_width = FRAME_RIGHT_FRINGE_WIDTH (f);
@@ -4572,7 +4589,7 @@ x_set_right_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_valu
 
 
 void
-x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
+gui_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
   CHECK_TYPE_RANGED_INTEGER (int, arg);
 
@@ -4586,7 +4603,7 @@ x_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 }
 
 void
-x_set_right_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
+gui_set_right_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
   int old = FRAME_RIGHT_DIVIDER_WIDTH (f);
   CHECK_TYPE_RANGED_INTEGER (int, arg);
@@ -4601,7 +4618,7 @@ x_set_right_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 }
 
 void
-x_set_bottom_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
+gui_set_bottom_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
   int old = FRAME_BOTTOM_DIVIDER_WIDTH (f);
   CHECK_TYPE_RANGED_INTEGER (int, arg);
@@ -4616,7 +4633,7 @@ x_set_bottom_divider_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval
 }
 
 void
-x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval)
+gui_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval)
 {
   Lisp_Object frame;
   XSETFRAME (frame, f);
@@ -4630,25 +4647,25 @@ x_set_visibility (struct frame *f, Lisp_Object value, Lisp_Object oldval)
 }
 
 void
-x_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
+gui_set_autoraise (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
   f->auto_raise = !NILP (arg);
 }
 
 void
-x_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
+gui_set_autolower (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
   f->auto_lower = !NILP (arg);
 }
 
 void
-x_set_unsplittable (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
+gui_set_unsplittable (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
   f->no_split = !NILP (arg);
 }
 
 void
-x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
+gui_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
   if ((EQ (arg, Qleft) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_RIGHT (f))
       || (EQ (arg, Qright) && FRAME_HAS_VERTICAL_SCROLL_BARS_ON_LEFT (f))
@@ -4680,7 +4697,7 @@ x_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval
 }
 
 void
-x_set_horizontal_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
+gui_set_horizontal_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
 #if USE_HORIZONTAL_SCROLL_BARS
   if ((NILP (arg) && FRAME_HAS_HORIZONTAL_SCROLL_BARS (f))
@@ -4701,7 +4718,7 @@ x_set_horizontal_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldv
 }
 
 void
-x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
+gui_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
   int unit = FRAME_COLUMN_WIDTH (f);
 
@@ -4717,7 +4734,7 @@ x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
     }
   else
     {
-      x_set_scroll_bar_default_width (f);
+      FRAME_TERMINAL (f)->set_scroll_bar_default_width_hook (f);
 
       if (FRAME_X_WINDOW (f))
 	adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_width);
@@ -4730,7 +4747,7 @@ x_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 }
 
 void
-x_set_scroll_bar_height (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
+gui_set_scroll_bar_height (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
 #if USE_HORIZONTAL_SCROLL_BARS
   int unit = FRAME_LINE_HEIGHT (f);
@@ -4747,7 +4764,7 @@ x_set_scroll_bar_height (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
     }
   else
     {
-      x_set_scroll_bar_default_height (f);
+      FRAME_TERMINAL (f)->set_scroll_bar_default_height_hook (f);
 
       if (FRAME_X_WINDOW (f))
 	adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_height);
@@ -4761,7 +4778,7 @@ x_set_scroll_bar_height (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 }
 
 void
-x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
+gui_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
   double alpha = 1.0;
   double newval[2];
@@ -4802,25 +4819,24 @@ x_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
   for (i = 0; i < 2; i++)
     f->alpha[i] = newval[i];
 
-#if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI) || defined (NS_IMPL_COCOA)
-  block_input ();
-  x_set_frame_alpha (f);
-  unblock_input ();
-#endif
-
-  return;
+  if (FRAME_TERMINAL (f)->set_frame_alpha_hook)
+    {
+      block_input ();
+      FRAME_TERMINAL (f)->set_frame_alpha_hook (f);
+      unblock_input ();
+    }
 }
 
 
 /**
- * x_set_no_special_glyphs:
+ * gui_set_no_special_glyphs:
  *
  * Set frame F's `no-special-glyphs' parameter which, if non-nil,
  * suppresses the display of truncation and continuation glyphs
  * outside fringes.
  */
 void
-x_set_no_special_glyphs (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
+gui_set_no_special_glyphs (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
 {
   if (!EQ (new_value, old_value))
     FRAME_NO_SPECIAL_GLYPHS (f) = !NILP (new_value);
@@ -4832,7 +4848,8 @@ x_set_no_special_glyphs (struct frame *f, Lisp_Object new_value, Lisp_Object old
 /* Non-zero if mouse is grabbed on DPYINFO
    and we know the frame where it is.  */
 
-bool x_mouse_grabbed (Display_Info *dpyinfo)
+bool
+gui_mouse_grabbed (Display_Info *dpyinfo)
 {
   return (dpyinfo->grabbed
 	  && dpyinfo->last_mouse_frame
@@ -4843,7 +4860,7 @@ bool x_mouse_grabbed (Display_Info *dpyinfo)
    on DPYINFO using saved frame and mouse position.  */
 
 void
-x_redo_mouse_highlight (Display_Info *dpyinfo)
+gui_redo_mouse_highlight (Display_Info *dpyinfo)
 {
   if (dpyinfo->last_mouse_motion_frame
       && FRAME_LIVE_P (dpyinfo->last_mouse_motion_frame))
@@ -5196,9 +5213,9 @@ x_frame_get_and_record_arg (struct frame *f, Lisp_Object alist,
    If that is not found either, use the value DEFLT.  */
 
 Lisp_Object
-x_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop,
-		     Lisp_Object deflt, const char *xprop, const char *xclass,
-		     enum resource_types type)
+gui_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop,
+                       Lisp_Object deflt, const char *xprop, const char *xclass,
+                       enum resource_types type)
 {
   Lisp_Object tem;
 
@@ -5206,7 +5223,7 @@ x_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop,
   if (EQ (tem, Qunbound))
     tem = deflt;
   AUTO_FRAME_ARG (arg, prop, tem);
-  x_set_frame_parameters (f, arg);
+  gui_set_frame_parameters (f, arg);
   return tem;
 }
 
@@ -5381,7 +5398,8 @@ On Nextstep, this just calls `ns-parse-geometry'.  */)
 #define DEFAULT_COLS 80
 
 long
-x_figure_window_size (struct frame *f, Lisp_Object parms, bool toolbar_p, int *x_width, int *x_height)
+gui_figure_window_size (struct frame *f, Lisp_Object parms, bool toolbar_p,
+                        int *x_width, int *x_height)
 {
   Lisp_Object height, width, user_size, top, left, user_position;
   long window_prompting = 0;
@@ -5808,7 +5826,7 @@ syms_of_frame (void)
   DEFSYM (Qfullboth, "fullboth");
   DEFSYM (Qmaximized, "maximized");
   DEFSYM (Qx_resource_name, "x-resource-name");
-  DEFSYM (Qx_frame_parameter, "x-frame-parameter");
+  DEFSYM (Qframe_parameter_pos, "frame-parameter-pos");
 
   DEFSYM (Qworkarea, "workarea");
   DEFSYM (Qmm_size, "mm-size");
@@ -5831,7 +5849,7 @@ syms_of_frame (void)
   DEFSYM (Qadjust_frame_size_1, "adjust-frame-size-1");
   DEFSYM (Qadjust_frame_size_2, "adjust-frame-size-2");
   DEFSYM (Qadjust_frame_size_3, "adjust-frame-size-3");
-  DEFSYM (Qx_set_frame_parameters, "x-set-frame-parameters");
+  DEFSYM (Qgui_set_frame_parameters, "gui-set-frame-parameters");
   DEFSYM (QEmacsFrameResize, "EmacsFrameResize");
   DEFSYM (Qset_frame_size, "set-frame-size");
   DEFSYM (Qframe_inhibit_resize, "frame-inhibit-resize");
@@ -5927,7 +5945,7 @@ syms_of_frame (void)
 	Lisp_Object v = (frame_parms[i].sym < 0
 			 ? intern_c_string (frame_parms[i].name)
 			 : builtin_lisp_symbol (frame_parms[i].sym));
-	Fput (v, Qx_frame_parameter, make_fixnum (i));
+	Fput (v, Qframe_parameter_pos, make_fixnum (i));
       }
   }
 
diff --git a/src/frame.h b/src/frame.h
index ec8f61465f..7b5aeaa136 100644
--- a/src/frame.h
+++ b/src/frame.h
@@ -1544,37 +1544,32 @@ FRAME_BOTTOM_DIVIDER_WIDTH (struct frame *f)
 /* The class of this X application.  */
 #define EMACS_CLASS "Emacs"
 
-extern void x_set_scroll_bar_default_width (struct frame *);
-extern void x_set_scroll_bar_default_height (struct frame *);
-extern void x_set_offset (struct frame *, int, int, int);
-extern void x_wm_set_size_hint (struct frame *f, long flags, bool user_position);
-extern Lisp_Object x_new_font (struct frame *, Lisp_Object, int);
-extern void x_set_frame_parameters (struct frame *, Lisp_Object);
-extern void x_set_fullscreen (struct frame *, Lisp_Object, Lisp_Object);
-extern void x_set_line_spacing (struct frame *, Lisp_Object, Lisp_Object);
-extern void x_set_screen_gamma (struct frame *, Lisp_Object, Lisp_Object);
-extern void x_set_font (struct frame *, Lisp_Object, Lisp_Object);
-extern void x_set_font_backend (struct frame *, Lisp_Object, Lisp_Object);
-extern void x_set_left_fringe (struct frame *, Lisp_Object, Lisp_Object);
-extern void x_set_right_fringe (struct frame *, Lisp_Object, Lisp_Object);
-extern void x_set_border_width (struct frame *, Lisp_Object, Lisp_Object);
-extern void x_set_right_divider_width (struct frame *, Lisp_Object,
-				       Lisp_Object);
-extern void x_set_bottom_divider_width (struct frame *, Lisp_Object,
-					Lisp_Object);
-extern void x_set_visibility (struct frame *, Lisp_Object, Lisp_Object);
-extern void x_set_autoraise (struct frame *, Lisp_Object, Lisp_Object);
-extern void x_set_autolower (struct frame *, Lisp_Object, Lisp_Object);
-extern void x_set_unsplittable (struct frame *, Lisp_Object, Lisp_Object);
-extern void x_set_vertical_scroll_bars (struct frame *, Lisp_Object, Lisp_Object);
-extern void x_set_horizontal_scroll_bars (struct frame *, Lisp_Object, Lisp_Object);
-extern void x_set_scroll_bar_width (struct frame *, Lisp_Object, Lisp_Object);
-extern void x_set_scroll_bar_height (struct frame *, Lisp_Object, Lisp_Object);
-
-extern long x_figure_window_size (struct frame *, Lisp_Object, bool, int *, int *);
-
-extern void x_set_alpha (struct frame *, Lisp_Object, Lisp_Object);
-extern void x_set_no_special_glyphs (struct frame *, Lisp_Object, Lisp_Object);
+extern void gui_set_frame_parameters (struct frame *, Lisp_Object);
+extern void gui_set_fullscreen (struct frame *, Lisp_Object, Lisp_Object);
+extern void gui_set_line_spacing (struct frame *, Lisp_Object, Lisp_Object);
+extern void gui_set_screen_gamma (struct frame *, Lisp_Object, Lisp_Object);
+extern void gui_set_font (struct frame *, Lisp_Object, Lisp_Object);
+extern void gui_set_font_backend (struct frame *, Lisp_Object, Lisp_Object);
+extern void gui_set_left_fringe (struct frame *, Lisp_Object, Lisp_Object);
+extern void gui_set_right_fringe (struct frame *, Lisp_Object, Lisp_Object);
+extern void gui_set_border_width (struct frame *, Lisp_Object, Lisp_Object);
+extern void gui_set_right_divider_width (struct frame *, Lisp_Object,
+                                         Lisp_Object);
+extern void gui_set_bottom_divider_width (struct frame *, Lisp_Object,
+                                          Lisp_Object);
+extern void gui_set_visibility (struct frame *, Lisp_Object, Lisp_Object);
+extern void gui_set_autoraise (struct frame *, Lisp_Object, Lisp_Object);
+extern void gui_set_autolower (struct frame *, Lisp_Object, Lisp_Object);
+extern void gui_set_unsplittable (struct frame *, Lisp_Object, Lisp_Object);
+extern void gui_set_vertical_scroll_bars (struct frame *, Lisp_Object, Lisp_Object);
+extern void gui_set_horizontal_scroll_bars (struct frame *, Lisp_Object, Lisp_Object);
+extern void gui_set_scroll_bar_width (struct frame *, Lisp_Object, Lisp_Object);
+extern void gui_set_scroll_bar_height (struct frame *, Lisp_Object, Lisp_Object);
+
+extern long gui_figure_window_size (struct frame *, Lisp_Object, bool, int *, int *);
+
+extern void gui_set_alpha (struct frame *, Lisp_Object, Lisp_Object);
+extern void gui_set_no_special_glyphs (struct frame *, Lisp_Object, Lisp_Object);
 
 extern void validate_x_resource_name (void);
 
@@ -1587,16 +1582,10 @@ extern Lisp_Object display_x_get_resource (Display_Info *,
 extern void set_frame_menubar (struct frame *f, bool first_time, bool deep_p);
 extern void x_set_window_size (struct frame *f, bool change_gravity,
 			       int width, int height, bool pixelwise);
-extern Lisp_Object x_get_focus_frame (struct frame *);
+extern Lisp_Object gui_get_focus_frame (struct frame *);
 extern void frame_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y);
-extern void x_make_frame_visible (struct frame *f);
-extern void x_make_frame_invisible (struct frame *f);
-extern void x_iconify_frame (struct frame *f);
-extern void x_set_frame_alpha (struct frame *f);
 extern void x_activate_menubar (struct frame *);
-extern void x_real_positions (struct frame *, int *, int *);
 extern void free_frame_menubar (struct frame *);
-extern void x_free_frame_resources (struct frame *);
 extern bool frame_ancestor_p (struct frame *af, struct frame *df);
 extern enum internal_border_part frame_internal_border_part (struct frame *f, int x, int y);
 
@@ -1608,9 +1597,6 @@ extern char *x_get_resource_string (const char *, const char *);
 extern void x_sync (struct frame *);
 #endif /* HAVE_X_WINDOWS */
 
-extern void x_query_colors (struct frame *f, XColor *, int);
-extern void x_focus_frame (struct frame *, bool);
-
 #ifndef HAVE_NS
 
 extern bool x_bitmap_icon (struct frame *, Lisp_Object);
@@ -1618,7 +1604,7 @@ extern bool x_bitmap_icon (struct frame *, Lisp_Object);
 /* Set F's bitmap icon, if specified among F's parameters.  */
 
 INLINE void
-x_set_bitmap_icon (struct frame *f)
+gui_set_bitmap_icon (struct frame *f)
 {
   Lisp_Object obj = assq_no_quit (Qicon_type, f->param_alist);
 
diff --git a/src/gtkutil.c b/src/gtkutil.c
index b130692c87..0ddf1886d8 100644
--- a/src/gtkutil.c
+++ b/src/gtkutil.c
@@ -385,7 +385,7 @@ xg_get_image_for_pixmap (struct frame *f,
      In that case, use the pixmap already loaded.  */
 
   if (STRINGP (specified_file)
-      && STRINGP (file = x_find_image_file (specified_file)))
+      && STRINGP (file = gui_find_image_file (specified_file)))
     {
       char *encoded_file = SSDATA (ENCODE_FILE (file));
       if (! old_widget)
@@ -935,7 +935,7 @@ xg_frame_resized (struct frame *f, int pixelwidth, int pixelheight)
       || pixelwidth != FRAME_PIXEL_WIDTH (f)
       || pixelheight != FRAME_PIXEL_HEIGHT (f))
     {
-      x_clear_under_internal_border (f);
+      FRAME_RIF (f)->clear_under_internal_border (f);
       change_frame_size (f, width, height, 0, 1, 0, 1);
       SET_FRAME_GARBAGED (f);
       cancel_mouse_face (f);
@@ -963,7 +963,7 @@ xg_frame_set_char_size (struct frame *f, int width, int height)
 		       &gwidth, &gheight);
 
   /* Do this before resize, as we don't know yet if we will be resized.  */
-  x_clear_under_internal_border (f);
+  FRAME_RIF (f)->clear_under_internal_border (f);
 
   totalheight /= xg_get_scale (f);
   totalwidth /= xg_get_scale (f);
@@ -1029,7 +1029,7 @@ xg_frame_set_char_size (struct frame *f, int width, int height)
 	/* Try to restore fullscreen state.  */
 	{
 	  store_frame_param (f, Qfullscreen, fullscreen);
-	  x_set_fullscreen (f, fullscreen, fullscreen);
+	  gui_set_fullscreen (f, fullscreen, fullscreen);
 	}
     }
   else
@@ -1147,8 +1147,8 @@ style_changed_cb (GObject *go,
               && FRAME_X_P (f)
               && FRAME_X_DISPLAY (f) == dpy)
             {
-              x_set_scroll_bar_default_width (f);
-              x_set_scroll_bar_default_height (f);
+              FRAME_TERMINAL (f)->set_scroll_bar_default_width_hook (f);
+              FRAME_TERMINAL (f)->set_scroll_bar_default_height_hook (f);
               xg_frame_set_char_size (f, FRAME_TEXT_WIDTH (f), FRAME_TEXT_HEIGHT (f));
             }
         }
@@ -4405,7 +4405,7 @@ xg_tool_bar_callback (GtkWidget *w, gpointer client_data)
 
   /* Return focus to the frame after we have clicked on a detached
      tool bar button. */
-  x_focus_frame (f, false);
+  FRAME_TERMINAL (f)->focus_frame_hook (f, false);
 }
 
 static GtkWidget *
diff --git a/src/image.c b/src/image.c
index 6e415ef1f7..2b47aebe99 100644
--- a/src/image.c
+++ b/src/image.c
@@ -111,9 +111,9 @@ typedef struct ns_bitmap_record Bitmap_Record;
 # define COLOR_TABLE_SUPPORT 1
 #endif
 
-static void x_disable_image (struct frame *, struct image *);
-static void x_edge_detection (struct frame *, struct image *, Lisp_Object,
-                              Lisp_Object);
+static void image_disable_image (struct frame *, struct image *);
+static void image_edge_detection (struct frame *, struct image *, Lisp_Object,
+                                  Lisp_Object);
 
 static void init_color_table (void);
 static unsigned long lookup_rgb_color (struct frame *f, int r, int g, int b);
@@ -129,7 +129,7 @@ static unsigned long *colors_in_color_table (int *n);
    Bitmap indices are guaranteed to be > 0, so a negative number can
    be used to indicate no bitmap.
 
-   If you use x_create_bitmap_from_data, then you must keep track of
+   If you use gui_create_bitmap_from_data, then you must keep track of
    the bitmaps yourself.  That is, creating a bitmap from the same
    data more than once will not be caught.  */
 
@@ -187,7 +187,7 @@ x_bitmap_mask (struct frame *f, ptrdiff_t id)
 /* Allocate a new bitmap record.  Returns index of new record.  */
 
 static ptrdiff_t
-x_allocate_bitmap_record (struct frame *f)
+gui_allocate_bitmap_record (struct frame *f)
 {
   Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f);
   ptrdiff_t i;
@@ -208,7 +208,7 @@ x_allocate_bitmap_record (struct frame *f)
 /* Add one reference to the reference count of the bitmap with id ID.  */
 
 void
-x_reference_bitmap (struct frame *f, ptrdiff_t id)
+gui_reference_bitmap (struct frame *f, ptrdiff_t id)
 {
   ++FRAME_DISPLAY_INFO (f)->bitmaps[id - 1].refcount;
 }
@@ -216,7 +216,8 @@ x_reference_bitmap (struct frame *f, ptrdiff_t id)
 /* Create a bitmap for frame F from a HEIGHT x WIDTH array of bits at BITS.  */
 
 ptrdiff_t
-x_create_bitmap_from_data (struct frame *f, char *bits, unsigned int width, unsigned int height)
+gui_create_bitmap_from_data (struct frame *f, char *bits,
+                             unsigned int width, unsigned int height)
 {
   Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f);
   ptrdiff_t id;
@@ -246,7 +247,7 @@ x_create_bitmap_from_data (struct frame *f, char *bits, unsigned int width, unsi
       return -1;
 #endif
 
-  id = x_allocate_bitmap_record (f);
+  id = gui_allocate_bitmap_record (f);
 
 #ifdef HAVE_NS
   dpyinfo->bitmaps[id - 1].img = bitmap;
@@ -276,7 +277,7 @@ x_create_bitmap_from_data (struct frame *f, char *bits, unsigned int width, unsi
 /* Create bitmap from file FILE for frame F.  */
 
 ptrdiff_t
-x_create_bitmap_from_file (struct frame *f, Lisp_Object file)
+gui_create_bitmap_from_file (struct frame *f, Lisp_Object file)
 {
 #ifdef HAVE_NTGUI
   return -1;  /* W32_TODO : bitmap support */
@@ -292,7 +293,7 @@ x_create_bitmap_from_file (struct frame *f, Lisp_Object file)
       return -1;
 
 
-  id = x_allocate_bitmap_record (f);
+  id = gui_allocate_bitmap_record (f);
   dpyinfo->bitmaps[id - 1].img = bitmap;
   dpyinfo->bitmaps[id - 1].refcount = 1;
   dpyinfo->bitmaps[id - 1].file = xlispstrdup (file);
@@ -335,7 +336,7 @@ x_create_bitmap_from_file (struct frame *f, Lisp_Object file)
   if (result != BitmapSuccess)
     return -1;
 
-  id = x_allocate_bitmap_record (f);
+  id = gui_allocate_bitmap_record (f);
   dpyinfo->bitmaps[id - 1].pixmap = bitmap;
   dpyinfo->bitmaps[id - 1].have_mask = false;
   dpyinfo->bitmaps[id - 1].refcount = 1;
@@ -397,7 +398,7 @@ x_destroy_bitmap (struct frame *f, ptrdiff_t id)
 /* Free all the bitmaps for the display specified by DPYINFO.  */
 
 void
-x_destroy_all_bitmaps (Display_Info *dpyinfo)
+gui_destroy_all_bitmaps (Display_Info *dpyinfo)
 {
   ptrdiff_t i;
   Bitmap_Record *bm = dpyinfo->bitmaps;
@@ -414,9 +415,9 @@ x_destroy_all_bitmaps (Display_Info *dpyinfo)
 typedef void Picture;
 #endif
 
-static bool x_create_x_image_and_pixmap (struct frame *, int, int, int,
-					 XImagePtr *, Pixmap *, Picture *);
-static void x_destroy_x_image (XImagePtr ximg);
+static bool gui_create_x_image_and_pixmap (struct frame *, int, int, int,
+                                           XImagePtr *, Pixmap *, Picture *);
+static void gui_destroy_x_image (XImagePtr ximg);
 
 #ifdef HAVE_NTGUI
 static XImagePtr_or_DC image_get_x_image_or_dc (struct frame *, struct image *,
@@ -478,8 +479,8 @@ x_create_bitmap_mask (struct frame *f, ptrdiff_t id)
       return;
     }
 
-  result = x_create_x_image_and_pixmap (f, width, height, 1,
-                                        &mask_img, &mask, NULL);
+  result = gui_create_x_image_and_pixmap (f, width, height, 1,
+                                          &mask_img, &mask, NULL);
 
   unblock_input ();
   if (!result)
@@ -523,7 +524,7 @@ x_create_bitmap_mask (struct frame *f, ptrdiff_t id)
   dpyinfo->bitmaps[id - 1].mask = mask;
 
   XDestroyImage (ximg);
-  x_destroy_x_image (mask_img);
+  gui_destroy_x_image (mask_img);
 }
 
 #endif /* HAVE_X_WINDOWS */
@@ -567,9 +568,9 @@ static struct image_type *image_types;
 /* Forward function prototypes.  */
 
 static struct image_type *lookup_image_type (Lisp_Object);
-static void x_laplace (struct frame *, struct image *);
-static void x_emboss (struct frame *, struct image *);
-static void x_build_heuristic_mask (struct frame *, struct image *,
+static void image_laplace (struct frame *, struct image *);
+static void image_emboss (struct frame *, struct image *);
+static void image_build_heuristic_mask (struct frame *, struct image *,
                                     Lisp_Object);
 #ifdef WINDOWSNT
 #define CACHE_IMAGE_TYPE(type, status) \
@@ -1313,13 +1314,17 @@ image_background_transparent (struct image *img, struct frame *f, XImagePtr_or_D
 
 /* Store F's background color into *BGCOLOR.  */
 static void
-x_query_frame_background_color (struct frame *f, XColor *bgcolor)
+gui_query_frame_background_color (struct frame *f, XColor *bgcolor)
 {
-#ifndef HAVE_NS
-  bgcolor->pixel = FRAME_BACKGROUND_PIXEL (f);
-  x_query_color (f, bgcolor);
+#ifdef HAVE_NS
+  ns_query_color (FRAME_BACKGROUND_COLOR (f), bgcolor, true);
 #else
-  ns_query_color (FRAME_BACKGROUND_COLOR (f), bgcolor, 1);
+  bgcolor->pixel = FRAME_BACKGROUND_PIXEL (f);
+# ifdef HAVE_NTGUI
+  w32_query_colors (f, bgcolor, 1);
+# else
+  x_query_colors (f, bgcolor, 1);
+# endif /* HAVE_NTGUI */
 #endif
 }
 
@@ -1341,7 +1346,7 @@ x_query_frame_background_color (struct frame *f, XColor *bgcolor)
 #define CLEAR_IMAGE_COLORS	(1 << 2)
 
 static void
-x_clear_image_1 (struct frame *f, struct image *img, int flags)
+gui_clear_image_1 (struct frame *f, struct image *img, int flags)
 {
   if (flags & CLEAR_IMAGE_PIXMAP)
     {
@@ -1355,7 +1360,7 @@ x_clear_image_1 (struct frame *f, struct image *img, int flags)
 #ifdef HAVE_X_WINDOWS
       if (img->ximg)
 	{
-	  x_destroy_x_image (img->ximg);
+	  gui_destroy_x_image (img->ximg);
 	  img->ximg = NULL;
 	  img->background_valid = 0;
 	}
@@ -1373,7 +1378,7 @@ x_clear_image_1 (struct frame *f, struct image *img, int flags)
 #ifdef HAVE_X_WINDOWS
       if (img->mask_img)
 	{
-	  x_destroy_x_image (img->mask_img);
+	  gui_destroy_x_image (img->mask_img);
 	  img->mask_img = NULL;
 	  img->background_transparent_valid = 0;
 	}
@@ -1396,14 +1401,14 @@ x_clear_image_1 (struct frame *f, struct image *img, int flags)
 /* Free X resources of image IMG which is used on frame F.  */
 
 static void
-x_clear_image (struct frame *f, struct image *img)
+gui_clear_image (struct frame *f, struct image *img)
 {
   block_input ();
 #ifdef USE_CAIRO
   if (img->cr_data)
     cairo_surface_destroy ((cairo_surface_t *)img->cr_data);
 #endif
-  x_clear_image_1 (f, img,
+  gui_clear_image_1 (f, img,
 		   CLEAR_IMAGE_PIXMAP | CLEAR_IMAGE_MASK | CLEAR_IMAGE_COLORS);
   unblock_input ();
 }
@@ -1415,7 +1420,7 @@ x_clear_image (struct frame *f, struct image *img)
    color.  */
 
 static unsigned long
-x_alloc_image_color (struct frame *f, struct image *img, Lisp_Object color_name,
+gui_alloc_image_color (struct frame *f, struct image *img, Lisp_Object color_name,
 		     unsigned long dflt)
 {
   XColor color;
@@ -1715,7 +1720,7 @@ postprocess_image (struct frame *f, struct image *img)
 
       mask = image_spec_value (spec, QCheuristic_mask, NULL);
       if (!NILP (mask))
-	x_build_heuristic_mask (f, img, mask);
+	image_build_heuristic_mask (f, img, mask);
       else
 	{
 	  bool found_p;
@@ -1723,37 +1728,37 @@ postprocess_image (struct frame *f, struct image *img)
 	  mask = image_spec_value (spec, QCmask, &found_p);
 
 	  if (EQ (mask, Qheuristic))
-	    x_build_heuristic_mask (f, img, Qt);
+	    image_build_heuristic_mask (f, img, Qt);
 	  else if (CONSP (mask)
 		   && EQ (XCAR (mask), Qheuristic))
 	    {
 	      if (CONSP (XCDR (mask)))
-		x_build_heuristic_mask (f, img, XCAR (XCDR (mask)));
+		image_build_heuristic_mask (f, img, XCAR (XCDR (mask)));
 	      else
-		x_build_heuristic_mask (f, img, XCDR (mask));
+		image_build_heuristic_mask (f, img, XCDR (mask));
 	    }
 	  else if (NILP (mask) && found_p && img->mask)
-	    x_clear_image_1 (f, img, CLEAR_IMAGE_MASK);
+	    gui_clear_image_1 (f, img, CLEAR_IMAGE_MASK);
 	}
 
 
       /* Should we apply an image transformation algorithm?  */
       conversion = image_spec_value (spec, QCconversion, NULL);
       if (EQ (conversion, Qdisabled))
-	x_disable_image (f, img);
+	image_disable_image (f, img);
       else if (EQ (conversion, Qlaplace))
-	x_laplace (f, img);
+	image_laplace (f, img);
       else if (EQ (conversion, Qemboss))
-	x_emboss (f, img);
+	image_emboss (f, img);
       else if (CONSP (conversion)
 	       && EQ (XCAR (conversion), Qedge_detection))
 	{
 	  Lisp_Object tem;
 	  tem = XCDR (conversion);
 	  if (CONSP (tem))
-	    x_edge_detection (f, img,
-			      Fplist_get (tem, QCmatrix),
-			      Fplist_get (tem, QCcolor_adjustment));
+	    image_edge_detection (f, img,
+                                  Fplist_get (tem, QCmatrix),
+                                  Fplist_get (tem, QCcolor_adjustment));
 	}
     }
 }
@@ -1860,7 +1865,7 @@ compute_image_size (size_t width, size_t height,
 #endif /* HAVE_IMAGEMAGICK || HAVE_NATIVE_SCALING */
 
 static void
-x_set_image_size (struct frame *f, struct image *img)
+gui_set_image_size (struct frame *f, struct image *img)
 {
 #ifdef HAVE_NATIVE_SCALING
 # ifdef HAVE_IMAGEMAGICK
@@ -1964,7 +1969,7 @@ lookup_image (struct frame *f, Lisp_Object spec)
 	     `:background COLOR'.  */
 	  Lisp_Object ascent, margin, relief, bg;
 	  int relief_bound;
-          x_set_image_size (f, img);
+          gui_set_image_size (f, img);
 
 	  ascent = image_spec_value (spec, QCascent, NULL);
 	  if (FIXNUMP (ascent))
@@ -1996,8 +2001,8 @@ lookup_image (struct frame *f, Lisp_Object spec)
 	      if (!NILP (bg))
 		{
 		  img->background
-		    = x_alloc_image_color (f, img, bg,
-					   FRAME_BACKGROUND_PIXEL (f));
+		    = gui_alloc_image_color (f, img, bg,
+                                             FRAME_BACKGROUND_PIXEL (f));
 		  img->background_valid = 1;
 		}
 	    }
@@ -2094,7 +2099,7 @@ mark_image_cache (struct image_cache *c)
    WIDTH and HEIGHT must both be positive.
    If XIMG is null, assume it is a bitmap.  */
 static bool
-x_check_image_size (XImagePtr ximg, int width, int height)
+gui_check_image_size (XImagePtr ximg, int width, int height)
 {
 #ifdef HAVE_X_WINDOWS
   /* Respect Xlib's limits: it cannot deal with images that have more
@@ -2138,8 +2143,8 @@ x_check_image_size (XImagePtr ximg, int width, int height)
    should indicate the bit depth of the image.  */
 
 static bool
-x_create_x_image_and_pixmap (struct frame *f, int width, int height, int depth,
-			     XImagePtr *ximg, Pixmap *pixmap, Picture *picture)
+gui_create_x_image_and_pixmap (struct frame *f, int width, int height, int depth,
+                               XImagePtr *ximg, Pixmap *pixmap, Picture *picture)
 {
 #ifdef HAVE_X_WINDOWS
   Display *display = FRAME_X_DISPLAY (f);
@@ -2159,9 +2164,9 @@ x_create_x_image_and_pixmap (struct frame *f, int width, int height, int depth,
       return 0;
     }
 
-  if (! x_check_image_size (*ximg, width, height))
+  if (! gui_check_image_size (*ximg, width, height))
     {
-      x_destroy_x_image (*ximg);
+      gui_destroy_x_image (*ximg);
       *ximg = NULL;
       image_error ("Image too large (%dx%d)",
 		   make_fixnum (width), make_fixnum (height));
@@ -2175,7 +2180,7 @@ x_create_x_image_and_pixmap (struct frame *f, int width, int height, int depth,
   *pixmap = XCreatePixmap (display, drawable, width, height, depth);
   if (*pixmap == NO_PIXMAP)
     {
-      x_destroy_x_image (*ximg);
+      gui_destroy_x_image (*ximg);
       *ximg = NULL;
       image_error ("Unable to create X pixmap");
       return 0;
@@ -2297,7 +2302,7 @@ x_create_x_image_and_pixmap (struct frame *f, int width, int height, int depth,
       /* All system errors are < 10000, so the following is safe.  */
       XSETINT (errcode, err);
       image_error ("Unable to create bitmap, error code %d", errcode);
-      x_destroy_x_image (*ximg);
+      gui_destroy_x_image (*ximg);
       *ximg = NULL;
       return 0;
     }
@@ -2323,7 +2328,7 @@ x_create_x_image_and_pixmap (struct frame *f, int width, int height, int depth,
 /* Destroy XImage XIMG.  Free XIMG->data.  */
 
 static void
-x_destroy_x_image (XImagePtr ximg)
+gui_destroy_x_image (XImagePtr ximg)
 {
   eassert (input_blocked_p ());
   if (ximg)
@@ -2349,7 +2354,7 @@ x_destroy_x_image (XImagePtr ximg)
    are width and height of both the image and pixmap.  */
 
 static void
-x_put_x_image (struct frame *f, XImagePtr ximg, Pixmap pixmap, int width, int height)
+gui_put_x_image (struct frame *f, XImagePtr ximg, Pixmap pixmap, int width, int height)
 {
 #ifdef HAVE_X_WINDOWS
   GC gc;
@@ -2375,7 +2380,7 @@ x_put_x_image (struct frame *f, XImagePtr ximg, Pixmap pixmap, int width, int he
 #endif
 }
 
-/* Thin wrapper for x_create_x_image_and_pixmap, so that it matches
+/* Thin wrapper for gui_create_x_image_and_pixmap, so that it matches
    with image_put_x_image.  */
 
 static bool
@@ -2389,9 +2394,9 @@ image_create_x_image_and_pixmap (struct frame *f, struct image *img,
 #ifdef HAVE_XRENDER
   picture = !mask_p ? &img->picture : &img->mask_picture;
 #endif
-  return x_create_x_image_and_pixmap (f, width, height, depth, ximg,
-				      !mask_p ? &img->pixmap : &img->mask,
-				      picture);
+  return gui_create_x_image_and_pixmap (f, width, height, depth, ximg,
+                                        !mask_p ? &img->pixmap : &img->mask,
+                                        picture);
 }
 
 /* Put X image XIMG into image IMG on frame F, as a mask if and only
@@ -2416,9 +2421,9 @@ image_put_x_image (struct frame *f, struct image *img, XImagePtr ximg,
       img->mask_img = ximg;
     }
 #else
-  x_put_x_image (f, ximg, !mask_p ? img->pixmap : img->mask,
+  gui_put_x_image (f, ximg, !mask_p ? img->pixmap : img->mask,
 		 img->width, img->height);
-  x_destroy_x_image (ximg);
+  gui_destroy_x_image (ximg);
 #endif
 }
 
@@ -2431,14 +2436,14 @@ image_sync_to_pixmaps (struct frame *f, struct image *img)
 {
   if (img->ximg)
     {
-      x_put_x_image (f, img->ximg, img->pixmap, img->width, img->height);
-      x_destroy_x_image (img->ximg);
+      gui_put_x_image (f, img->ximg, img->pixmap, img->width, img->height);
+      gui_destroy_x_image (img->ximg);
       img->ximg = NULL;
     }
   if (img->mask_img)
     {
-      x_put_x_image (f, img->mask_img, img->mask, img->width, img->height);
-      x_destroy_x_image (img->mask_img);
+      gui_put_x_image (f, img->mask_img, img->mask, img->width, img->height);
+      gui_destroy_x_image (img->mask_img);
       img->mask_img = NULL;
     }
 }
@@ -2520,7 +2525,7 @@ image_unget_x_image (struct image *img, bool mask_p, XImagePtr ximg)
    PFD is null, do not open the file.  */
 
 static Lisp_Object
-x_find_image_fd (Lisp_Object file, int *pfd)
+gui_find_image_fd (Lisp_Object file, int *pfd)
 {
   Lisp_Object file_found, search_path;
   int fd;
@@ -2558,9 +2563,9 @@ x_find_image_fd (Lisp_Object file, int *pfd)
    found, or nil if not found.  */
 
 Lisp_Object
-x_find_image_file (Lisp_Object file)
+gui_find_image_file (Lisp_Object file)
 {
-  return x_find_image_fd (file, 0);
+  return gui_find_image_fd (file, 0);
 }
 
 /* Read FILE into memory.  Value is a pointer to a buffer allocated
@@ -2661,7 +2666,7 @@ static struct image_type xbm_type =
   SYMBOL_INDEX (Qxbm),
   xbm_image_p,
   xbm_load,
-  x_clear_image,
+  gui_clear_image,
   NULL,
   NULL
 };
@@ -2981,7 +2986,7 @@ Create_Pixmap_From_Bitmap_Data (struct frame *f, struct image *img, char *data,
 
 #else
   img->pixmap =
-   (x_check_image_size (0, img->width, img->height)
+   (gui_check_image_size (0, img->width, img->height)
     ? XCreatePixmapFromBitmapData (FRAME_X_DISPLAY (f),
                                    FRAME_X_DRAWABLE (f),
 				   data,
@@ -3098,7 +3103,7 @@ xbm_read_bitmap_data (struct frame *f, char *contents, char *end,
   expect ('=');
   expect ('{');
 
-  if (! x_check_image_size (0, *width, *height))
+  if (! gui_check_image_size (0, *width, *height))
     {
       if (!inhibit_image_error)
 	image_error ("Image too large (%dx%d)",
@@ -3186,13 +3191,13 @@ xbm_load_image (struct frame *f, struct image *img, char *contents, char *end)
       value = image_spec_value (img->spec, QCforeground, NULL);
       if (!NILP (value))
 	{
-	  foreground = x_alloc_image_color (f, img, value, foreground);
+	  foreground = gui_alloc_image_color (f, img, value, foreground);
 	  non_default_colors = 1;
 	}
       value = image_spec_value (img->spec, QCbackground, NULL);
       if (!NILP (value))
 	{
-	  background = x_alloc_image_color (f, img, value, background);
+	  background = gui_alloc_image_color (f, img, value, background);
 	  img->background = background;
 	  img->background_valid = 1;
 	  non_default_colors = 1;
@@ -3205,7 +3210,7 @@ xbm_load_image (struct frame *f, struct image *img, char *contents, char *end)
 
       if (img->pixmap == NO_PIXMAP)
 	{
-	  x_clear_image (f, img);
+	  gui_clear_image (f, img);
 	  image_error ("Unable to create X pixmap for `%s'", img->spec);
 	}
       else
@@ -3247,7 +3252,7 @@ xbm_load (struct frame *f, struct image *img)
   if (STRINGP (file_name))
     {
       int fd;
-      Lisp_Object file = x_find_image_fd (file_name, &fd);
+      Lisp_Object file = gui_find_image_fd (file_name, &fd);
       if (!STRINGP (file))
 	{
 	  image_error ("Cannot find image file `%s'", file_name);
@@ -3302,16 +3307,16 @@ xbm_load (struct frame *f, struct image *img)
       if (fmt[XBM_FOREGROUND].count
 	  && STRINGP (fmt[XBM_FOREGROUND].value))
 	{
-	  foreground = x_alloc_image_color (f, img, fmt[XBM_FOREGROUND].value,
-					    foreground);
+	  foreground = gui_alloc_image_color (f, img, fmt[XBM_FOREGROUND].value,
+                                              foreground);
 	  non_default_colors = 1;
 	}
 
       if (fmt[XBM_BACKGROUND].count
 	  && STRINGP (fmt[XBM_BACKGROUND].value))
 	{
-	  background = x_alloc_image_color (f, img, fmt[XBM_BACKGROUND].value,
-					    background);
+	  background = gui_alloc_image_color (f, img, fmt[XBM_BACKGROUND].value,
+                                              background);
 	  non_default_colors = 1;
 	}
 
@@ -3358,7 +3363,7 @@ xbm_load (struct frame *f, struct image *img)
 #endif
 	  /* Create the pixmap.  */
 
-	  if (x_check_image_size (0, img->width, img->height))
+	  if (gui_check_image_size (0, img->width, img->height))
 	    Create_Pixmap_From_Bitmap_Data (f, img, bits,
 					    foreground, background,
 					    non_default_colors);
@@ -3371,7 +3376,7 @@ xbm_load (struct frame *f, struct image *img)
 	    {
 	      image_error ("Unable to create pixmap for XBM image `%s'",
 			   img->spec);
-	      x_clear_image (f, img);
+	      gui_clear_image (f, img);
 	    }
 
 	  SAFE_FREE ();
@@ -3468,7 +3473,7 @@ static struct image_type xpm_type =
   SYMBOL_INDEX (Qxpm),
   xpm_image_p,
   xpm_load,
-  x_clear_image,
+  gui_clear_image,
   init_xpm_functions,
   NULL
 };
@@ -3769,7 +3774,7 @@ x_create_bitmap_from_xpm_data (struct frame *f, const char **bits)
       return -1;
     }
 
-  id = x_allocate_bitmap_record (f);
+  id = gui_allocate_bitmap_record (f);
   dpyinfo->bitmaps[id - 1].pixmap = bitmap;
   dpyinfo->bitmaps[id - 1].have_mask = true;
   dpyinfo->bitmaps[id - 1].mask = mask;
@@ -3903,7 +3908,7 @@ xpm_load (struct frame *f, struct image *img)
 
   if (STRINGP (specified_file))
     {
-      Lisp_Object file = x_find_image_file (specified_file);
+      Lisp_Object file = gui_find_image_file (specified_file);
       if (!STRINGP (file))
 	{
 	  image_error ("Cannot find image file `%s'", specified_file);
@@ -3993,7 +3998,7 @@ xpm_load (struct frame *f, struct image *img)
   else
     {
       rc = XpmFileInvalid;
-      x_clear_image (f, img);
+      gui_clear_image (f, img);
     }
 #else
 #ifdef HAVE_X_WINDOWS
@@ -4004,7 +4009,7 @@ xpm_load (struct frame *f, struct image *img)
 				   img->ximg->depth);
       if (img->pixmap == NO_PIXMAP)
 	{
-	  x_clear_image (f, img);
+	  gui_clear_image (f, img);
 	  rc = XpmNoMemory;
 	}
       else if (img->mask_img)
@@ -4015,7 +4020,7 @@ xpm_load (struct frame *f, struct image *img)
 				     img->mask_img->depth);
 	  if (img->mask == NO_PIXMAP)
 	    {
-	      x_clear_image (f, img);
+	      gui_clear_image (f, img);
 	      rc = XpmNoMemory;
 	    }
 	}
@@ -4528,17 +4533,17 @@ xpm_load_image (struct frame *f,
     }
   else
     {
-      x_destroy_x_image (mask_img);
-      x_clear_image_1 (f, img, CLEAR_IMAGE_MASK);
+      gui_destroy_x_image (mask_img);
+      gui_clear_image_1 (f, img, CLEAR_IMAGE_MASK);
     }
 #endif
   return 1;
 
  failure:
   image_error ("Invalid XPM3 file (%s)", img->spec);
-  x_destroy_x_image (ximg);
-  x_destroy_x_image (mask_img);
-  x_clear_image (f, img);
+  gui_destroy_x_image (ximg);
+  gui_destroy_x_image (mask_img);
+  gui_clear_image (f, img);
   return 0;
 
 #undef match
@@ -4558,7 +4563,7 @@ xpm_load (struct frame *f,
   if (STRINGP (file_name))
     {
       int fd;
-      Lisp_Object file = x_find_image_fd (file_name, &fd);
+      Lisp_Object file = gui_find_image_fd (file_name, &fd);
       if (!STRINGP (file))
 	{
 	  image_error ("Cannot find image file `%s'", file_name);
@@ -4789,7 +4794,7 @@ lookup_pixel_color (struct frame *f, unsigned long pixel)
 #ifdef HAVE_X_WINDOWS
       cmap = FRAME_X_COLORMAP (f);
       color.pixel = pixel;
-      x_query_color (f, &color);
+      x_query_colors (f, &color, 1);
       rc = x_alloc_nearest_color (f, cmap, &color);
 #else
       block_input ();
@@ -4934,8 +4939,13 @@ x_to_xcolors (struct frame *f, struct image *img, bool rgb_p)
       for (x = 0; x < img->width; ++x, ++p)
 	p->pixel = GET_PIXEL (ximg, x, y);
       if (rgb_p)
-	x_query_colors (f, row, img->width);
-
+        {
+# ifdef HAVE_NTGUI
+          w32_query_colors (f, row, img->width);
+# else
+          x_query_colors (f, row, img->width);
+# endif
+        }
 #else
 
       for (x = 0; x < img->width; ++x, ++p)
@@ -5016,7 +5026,7 @@ x_from_xcolors (struct frame *f, struct image *img, XColor *colors)
 
   init_color_table ();
 
-  x_clear_image_1 (f, img, CLEAR_IMAGE_PIXMAP | CLEAR_IMAGE_COLORS);
+  gui_clear_image_1 (f, img, CLEAR_IMAGE_PIXMAP | CLEAR_IMAGE_COLORS);
   image_create_x_image_and_pixmap (f, img, img->width, img->height, 0,
 				   &oimg, 0);
   p = colors;
@@ -5047,7 +5057,8 @@ x_from_xcolors (struct frame *f, struct image *img, XColor *colors)
    outgoing image.  */
 
 static void
-x_detect_edges (struct frame *f, struct image *img, int *matrix, int color_adjust)
+image_detect_edges (struct frame *f, struct image *img,
+                    int *matrix, int color_adjust)
 {
   XColor *colors = x_to_xcolors (f, img, 1);
   XColor *new, *p;
@@ -5117,9 +5128,9 @@ x_detect_edges (struct frame *f, struct image *img, int *matrix, int color_adjus
    on frame F.  */
 
 static void
-x_emboss (struct frame *f, struct image *img)
+image_emboss (struct frame *f, struct image *img)
 {
-  x_detect_edges (f, img, emboss_matrix, 0xffff / 2);
+  image_detect_edges (f, img, emboss_matrix, 0xffff / 2);
 }
 
 
@@ -5128,9 +5139,9 @@ x_emboss (struct frame *f, struct image *img)
    to draw disabled buttons, for example.  */
 
 static void
-x_laplace (struct frame *f, struct image *img)
+image_laplace (struct frame *f, struct image *img)
 {
-  x_detect_edges (f, img, laplace_matrix, 45000);
+  image_detect_edges (f, img, laplace_matrix, 45000);
 }
 
 
@@ -5146,8 +5157,8 @@ x_laplace (struct frame *f, struct image *img)
    number.  */
 
 static void
-x_edge_detection (struct frame *f, struct image *img, Lisp_Object matrix,
-		  Lisp_Object color_adjust)
+image_edge_detection (struct frame *f, struct image *img,
+                      Lisp_Object matrix, Lisp_Object color_adjust)
 {
   int i = 0;
   int trans[9];
@@ -5169,14 +5180,14 @@ x_edge_detection (struct frame *f, struct image *img, Lisp_Object matrix,
     color_adjust = make_fixnum (0xffff / 2);
 
   if (i == 9 && NUMBERP (color_adjust))
-    x_detect_edges (f, img, trans, XFLOATINT (color_adjust));
+    image_detect_edges (f, img, trans, XFLOATINT (color_adjust));
 }
 
 
 /* Transform image IMG on frame F so that it looks disabled.  */
 
 static void
-x_disable_image (struct frame *f, struct image *img)
+image_disable_image (struct frame *f, struct image *img)
 {
   Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f);
 #ifdef HAVE_NTGUI
@@ -5279,7 +5290,8 @@ x_disable_image (struct frame *f, struct image *img)
    heuristically.  */
 
 static void
-x_build_heuristic_mask (struct frame *f, struct image *img, Lisp_Object how)
+image_build_heuristic_mask (struct frame *f, struct image *img,
+                            Lisp_Object how)
 {
   XImagePtr_or_DC ximg;
 #ifdef HAVE_NTGUI
@@ -5294,7 +5306,7 @@ x_build_heuristic_mask (struct frame *f, struct image *img, Lisp_Object how)
   unsigned long bg = 0;
 
   if (img->mask)
-    x_clear_image_1 (f, img, CLEAR_IMAGE_MASK);
+    gui_clear_image_1 (f, img, CLEAR_IMAGE_MASK);
 
 #ifndef HAVE_NTGUI
 #ifndef HAVE_NS
@@ -5335,7 +5347,7 @@ x_build_heuristic_mask (struct frame *f, struct image *img, Lisp_Object how)
 #ifdef HAVE_NTGUI
 		0x00ffffff & /* Filter out palette info.  */
 #endif /* HAVE_NTGUI */
-		x_alloc_image_color (f, img, build_string (color_name), 0));
+		gui_alloc_image_color (f, img, build_string (color_name), 0));
 	  use_img_background = 0;
 	}
     }
@@ -5378,7 +5390,7 @@ x_build_heuristic_mask (struct frame *f, struct image *img, Lisp_Object how)
   SelectObject (ximg, img->mask);
   image_background_transparent (img, f, ximg);
 
-  /* Was: x_destroy_x_image ((XImagePtr )mask_img); which seems bogus ++kfs */
+  /* Was: gui_destroy_x_image ((XImagePtr )mask_img); which seems bogus ++kfs */
   xfree (mask_img);
 #endif /* HAVE_NTGUI */
 
@@ -5436,7 +5448,7 @@ static struct image_type pbm_type =
   SYMBOL_INDEX (Qpbm),
   pbm_image_p,
   pbm_load,
-  x_clear_image,
+  gui_clear_image,
   NULL,
   NULL
 };
@@ -5547,7 +5559,7 @@ pbm_load (struct frame *f, struct image *img)
   if (STRINGP (specified_file))
     {
       int fd;
-      Lisp_Object file = x_find_image_fd (specified_file, &fd);
+      Lisp_Object file = gui_find_image_fd (specified_file, &fd);
       if (!STRINGP (file))
 	{
 	  image_error ("Cannot find image file `%s'", specified_file);
@@ -5675,7 +5687,7 @@ pbm_load (struct frame *f, struct image *img)
           || ! x_defined_color (f, SSDATA (fmt[PBM_FOREGROUND].value), &xfg, 0))
         {
           xfg.pixel = fg;
-          x_query_color (f, &xfg);
+          x_query_colors (f, &xfg, 1);
         }
       fga32 = xcolor_to_argb32 (xfg);
 
@@ -5684,17 +5696,17 @@ pbm_load (struct frame *f, struct image *img)
           || ! x_defined_color (f, SSDATA (fmt[PBM_BACKGROUND].value), &xbg, 0))
 	{
           xbg.pixel = bg;
-          x_query_color (f, &xbg);
+          x_query_colors (f, &xbg, 1);
 	}
       bga32 = xcolor_to_argb32 (xbg);
 #else
       if (fmt[PBM_FOREGROUND].count
 	  && STRINGP (fmt[PBM_FOREGROUND].value))
-	fg = x_alloc_image_color (f, img, fmt[PBM_FOREGROUND].value, fg);
+	fg = gui_alloc_image_color (f, img, fmt[PBM_FOREGROUND].value, fg);
       if (fmt[PBM_BACKGROUND].count
 	  && STRINGP (fmt[PBM_BACKGROUND].value))
 	{
-	  bg = x_alloc_image_color (f, img, fmt[PBM_BACKGROUND].value, bg);
+	  bg = gui_alloc_image_color (f, img, fmt[PBM_BACKGROUND].value, bg);
 	  img->background = bg;
 	  img->background_valid = 1;
 	}
@@ -5712,9 +5724,9 @@ pbm_load (struct frame *f, struct image *img)
 #ifdef USE_CAIRO
                         cairo_surface_destroy (surface);
 #else
-			x_destroy_x_image (ximg);
+			gui_destroy_x_image (ximg);
 #endif
-			x_clear_image (f, img);
+			gui_clear_image (f, img);
 			image_error ("Invalid image size in image `%s'",
 				     img->spec);
 			goto error;
@@ -5758,9 +5770,9 @@ pbm_load (struct frame *f, struct image *img)
 #ifdef USE_CAIRO
           cairo_surface_destroy (surface);
 #else
-	  x_destroy_x_image (ximg);
+	  gui_destroy_x_image (ximg);
 #endif
-	  x_clear_image (f, img);
+	  gui_clear_image (f, img);
 	  image_error ("Invalid image size in image `%s'", img->spec);
 	  goto error;
 	}
@@ -5792,7 +5804,7 @@ pbm_load (struct frame *f, struct image *img)
 #ifdef USE_CAIRO
                 cairo_surface_destroy (surface);
 #else
-		x_destroy_x_image (ximg);
+		gui_destroy_x_image (ximg);
 #endif
 		image_error ("Invalid pixel value in image `%s'", img->spec);
 		goto error;
@@ -5904,7 +5916,7 @@ static struct image_type png_type =
   SYMBOL_INDEX (Qpng),
   png_image_p,
   png_load,
-  x_clear_image,
+  gui_clear_image,
   init_png_functions,
   NULL
 };
@@ -6186,7 +6198,7 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
   if (NILP (specified_data))
     {
       int fd;
-      Lisp_Object file = x_find_image_fd (specified_file, &fd);
+      Lisp_Object file = gui_find_image_fd (specified_file, &fd);
       if (!STRINGP (file))
 	{
 	  image_error ("Cannot find image file `%s'", specified_file);
@@ -6341,7 +6353,7 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
 	 color set by the image.  */
       if (STRINGP (specified_bg)
 	  ? x_defined_color (f, SSDATA (specified_bg), &color, false)
-	  : (x_query_frame_background_color (f, &color), true))
+	  : (gui_query_frame_background_color (f, &color), true))
 	/* The user specified `:background', use that.  */
 	{
 	  int shift = bit_depth == 16 ? 0 : 8;
@@ -6398,8 +6410,8 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
       && !image_create_x_image_and_pixmap (f, img, width, height, 1,
 					   &mask_img, 1))
     {
-      x_destroy_x_image (ximg);
-      x_clear_image_1 (f, img, CLEAR_IMAGE_PIXMAP);
+      gui_destroy_x_image (ximg);
+      gui_clear_image_1 (f, img, CLEAR_IMAGE_PIXMAP);
       goto error;
     }
 #endif
@@ -6581,7 +6593,7 @@ static struct image_type jpeg_type =
   SYMBOL_INDEX (Qjpeg),
   jpeg_image_p,
   jpeg_load,
-  x_clear_image,
+  gui_clear_image,
   init_jpeg_functions,
   NULL
 };
@@ -6945,7 +6957,7 @@ jpeg_load_body (struct frame *f, struct image *img,
   if (NILP (specified_data))
     {
       int fd;
-      Lisp_Object file = x_find_image_fd (specified_file, &fd);
+      Lisp_Object file = gui_find_image_fd (specified_file, &fd);
       if (!STRINGP (file))
 	{
 	  image_error ("Cannot find image file `%s'", specified_file);
@@ -6997,10 +7009,10 @@ jpeg_load_body (struct frame *f, struct image *img,
 
       /* If we already have an XImage, free that.  */
 #ifndef USE_CAIRO
-      x_destroy_x_image (ximg);
+      gui_destroy_x_image (ximg);
 #endif
       /* Free pixmap and colors.  */
-      x_clear_image (f, img);
+      gui_clear_image (f, img);
       return 0;
     }
 
@@ -7213,7 +7225,7 @@ static struct image_type tiff_type =
   SYMBOL_INDEX (Qtiff),
   tiff_image_p,
   tiff_load,
-  x_clear_image,
+  gui_clear_image,
   init_tiff_functions,
   NULL
 };
@@ -7457,7 +7469,7 @@ tiff_load (struct frame *f, struct image *img)
   if (NILP (specified_data))
     {
       /* Read from a file */
-      Lisp_Object file = x_find_image_file (specified_file);
+      Lisp_Object file = gui_find_image_file (specified_file);
       if (!STRINGP (file))
 	{
 	  image_error ("Cannot find image file `%s'", specified_file);
@@ -7709,7 +7721,7 @@ static void
 gif_clear_image (struct frame *f, struct image *img)
 {
   img->lisp_data = Qnil;
-  x_clear_image (f, img);
+  gui_clear_image (f, img);
 }
 
 /* Return true if OBJECT is a valid GIF image specification.  */
@@ -7893,7 +7905,7 @@ gif_load (struct frame *f, struct image *img)
 
   if (NILP (specified_data))
     {
-      Lisp_Object file = x_find_image_file (specified_file);
+      Lisp_Object file = gui_find_image_file (specified_file);
       if (!STRINGP (file))
 	{
 	  image_error ("Cannot find image file `%s'", specified_file);
@@ -8079,8 +8091,8 @@ gif_load (struct frame *f, struct image *img)
 #ifndef USE_CAIRO
   unsigned long bgcolor UNINIT;
   if (STRINGP (specified_bg))
-    bgcolor = x_alloc_image_color (f, img, specified_bg,
-				   FRAME_BACKGROUND_PIXEL (f));
+    bgcolor = gui_alloc_image_color (f, img, specified_bg,
+                                     FRAME_BACKGROUND_PIXEL (f));
 #endif
 
   for (j = 0; j <= idx; ++j)
@@ -8376,7 +8388,7 @@ static void
 imagemagick_clear_image (struct frame *f,
                          struct image *img)
 {
-  x_clear_image (f, img);
+  gui_clear_image (f, img);
 }
 
 /* Return true if OBJECT is a valid IMAGEMAGICK image specification.  Do
@@ -8787,7 +8799,7 @@ imagemagick_load_image (struct frame *f, struct image *img,
     specified_bg = image_spec_value (img->spec, QCbackground, NULL);
     if (!STRINGP (specified_bg)
 	|| !x_defined_color (f, SSDATA (specified_bg), &bgcolor, 0))
-      x_query_frame_background_color (f, &bgcolor);
+      gui_query_frame_background_color (f, &bgcolor);
 
     bg_wand = NewPixelWand ();
     PixelSetRed   (bg_wand, (double) bgcolor.red   / 65535);
@@ -8981,7 +8993,7 @@ imagemagick_load_image (struct frame *f, struct image *img,
 	  free_color_table ();
 #endif
 #ifndef USE_CAIRO
-	  x_destroy_x_image (ximg);
+	  gui_destroy_x_image (ximg);
 #endif
           image_error ("Imagemagick pixel iterator creation failed");
           goto imagemagick_error;
@@ -9067,7 +9079,7 @@ imagemagick_load (struct frame *f, struct image *img)
   file_name = image_spec_value (img->spec, QCfile, NULL);
   if (STRINGP (file_name))
     {
-      Lisp_Object file = x_find_image_file (file_name);
+      Lisp_Object file = gui_find_image_file (file_name);
       if (!STRINGP (file))
 	{
 	  image_error ("Cannot find image file `%s'", file_name);
@@ -9198,7 +9210,7 @@ static struct image_type svg_type =
   SYMBOL_INDEX (Qsvg),
   svg_image_p,
   svg_load,
-  x_clear_image,
+  gui_clear_image,
   init_svg_functions,
   NULL
 };
@@ -9368,7 +9380,7 @@ svg_load (struct frame *f, struct image *img)
   if (STRINGP (file_name))
     {
       int fd;
-      Lisp_Object file = x_find_image_fd (file_name, &fd);
+      Lisp_Object file = gui_find_image_fd (file_name, &fd);
       if (!STRINGP (file))
 	{
 	  image_error ("Cannot find image file `%s'", file_name);
@@ -9522,7 +9534,7 @@ svg_load_image (struct frame *f, struct image *img, char *contents,
     Lisp_Object specified_bg = image_spec_value (img->spec, QCbackground, NULL);
     if (!STRINGP (specified_bg)
 	|| !x_defined_color (f, SSDATA (specified_bg), &background, 0))
-      x_query_frame_background_color (f, &background);
+      gui_query_frame_background_color (f, &background);
 
     /* SVG pixmaps specify transparency in the last byte, so right
        shift 8 bits to get rid of it, since emacs doesn't support
@@ -9665,7 +9677,7 @@ static struct image_type gs_type =
 static void
 gs_clear_image (struct frame *f, struct image *img)
 {
-  x_clear_image (f, img);
+  gui_clear_image (f, img);
 }
 
 
@@ -9745,7 +9757,7 @@ gs_load (struct frame *f, struct image *img)
   /* Create the pixmap.  */
   eassert (img->pixmap == NO_PIXMAP);
 
-  if (x_check_image_size (0, img->width, img->height))
+  if (gui_check_image_size (0, img->width, img->height))
     {
       /* Only W32 version did BLOCK_INPUT here.  ++kfs */
       block_input ();
@@ -9855,7 +9867,7 @@ x_kill_gs_process (Pixmap pixmap, struct frame *f)
 	  XDestroyImage (ximg);
 
 #if 0 /* This doesn't seem to be the case.  If we free the colors
-	 here, we get a BadAccess later in x_clear_image when
+	 here, we get a BadAccess later in gui_clear_image when
 	 freeing the colors.  */
 	  /* We have allocated colors once, but Ghostscript has also
 	     allocated colors on behalf of us.  So, to get the
diff --git a/src/keyboard.c b/src/keyboard.c
index 8fb6db987b..b6521e53bd 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -6510,7 +6510,7 @@ modify_event_symbol (ptrdiff_t symbol_num, int modifiers, Lisp_Object symbol_kin
 #ifdef HAVE_WINDOW_SYSTEM
       if (NILP (value))
 	{
-	  char *name = x_get_keysym_name (symbol_num);
+	  char *name = get_keysym_name (symbol_num);
 	  if (name)
 	    value = intern (name);
 	}
diff --git a/src/lisp.h b/src/lisp.h
index 681efc3b52..addac3b6db 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -4679,7 +4679,7 @@ extern void syms_of_xterm (void);
 
 #ifdef HAVE_WINDOW_SYSTEM
 /* Defined in xterm.c, nsterm.m, w32term.c.  */
-extern char *x_get_keysym_name (int);
+extern char *get_keysym_name (int);
 #endif /* HAVE_WINDOW_SYSTEM */
 
 /* Defined in xml.c.  */
diff --git a/src/nsfns.m b/src/nsfns.m
index 009e9d55e2..bc47c40ced 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -233,7 +233,7 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
 
 
 static void
-x_set_foreground_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
+ns_set_foreground_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
   NSColor *col;
   EmacsCGFloat r, g, b, alpha;
@@ -269,7 +269,7 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
 
 
 static void
-x_set_background_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
+ns_set_background_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
   struct face *face;
   NSColor *col;
@@ -325,7 +325,7 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
 
 
 static void
-x_set_cursor_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
+ns_set_cursor_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
   NSColor *col;
 
@@ -351,10 +351,10 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
 
 
 static void
-x_set_icon_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
+ns_set_icon_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
   NSView *view = FRAME_NS_VIEW (f);
-  NSTRACE ("x_set_icon_name");
+  NSTRACE ("ns_set_icon_name");
 
   /* See if it's changed.  */
   if (STRINGP (arg))
@@ -508,9 +508,9 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
    specified a name for the frame; the name will override any set by the
    redisplay code.  */
 static void
-x_explicitly_set_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
+ns_explicitly_set_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
-  NSTRACE ("x_explicitly_set_name");
+  NSTRACE ("ns_explicitly_set_name");
   ns_set_name (f, arg, 1);
 }
 
@@ -519,9 +519,9 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
    name; names set this way will never override names set by the user's
    lisp code.  */
 void
-x_implicitly_set_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
+ns_implicitly_set_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
-  NSTRACE ("x_implicitly_set_name");
+  NSTRACE ("ns_implicitly_set_name");
 
   if (ns_use_proxy_icon)
     ns_set_represented_filename (f);
@@ -534,9 +534,9 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
    If NAME is nil, use the frame name as the title.  */
 
 static void
-x_set_title (struct frame *f, Lisp_Object name, Lisp_Object old_name)
+ns_set_title (struct frame *f, Lisp_Object name, Lisp_Object old_name)
 {
-  NSTRACE ("x_set_title");
+  NSTRACE ("ns_set_title");
   /* Don't change the title if it's already NAME.  */
   if (EQ (name, f->title))
     return;
@@ -582,7 +582,7 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
 
 
 static void
-x_set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
+ns_set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
 {
   int nlines;
   if (FRAME_MINIBUF_ONLY_P (f))
@@ -612,7 +612,7 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
 
 /* toolbar support */
 static void
-x_set_tool_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
+ns_set_tool_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
 {
   /* Currently, when the tool bar changes state, the frame is resized.
 
@@ -621,7 +621,7 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
      `frame-inhibit-implied-resize'.  */
   int nlines;
 
-  NSTRACE ("x_set_tool_bar_lines");
+  NSTRACE ("ns_set_tool_bar_lines");
 
   if (FRAME_MINIBUF_ONLY_P (f))
     return;
@@ -680,7 +680,7 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
 
 
 static void
-x_set_internal_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
+ns_set_internal_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
   int old_width = FRAME_INTERNAL_BORDER_WIDTH (f);
 
@@ -771,13 +771,13 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
 
 
 static void
-x_set_icon_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
+ns_set_icon_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
   EmacsView *view = FRAME_NS_VIEW (f);
   id image = nil;
   BOOL setMini = YES;
 
-  NSTRACE ("x_set_icon_type");
+  NSTRACE ("ns_set_icon_type");
 
   if (!NILP (arg) && SYMBOLP (arg))
     {
@@ -811,7 +811,7 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
 
 /* This is the same as the xfns.c definition.  */
 static void
-x_set_cursor_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
+ns_set_cursor_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
   set_frame_cursor_types (f, arg);
 }
@@ -819,7 +819,7 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
 /* called to set mouse pointer color, but all other terms use it to
    initialize pointer types (and don't set the color ;) */
 static void
-x_set_mouse_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
+ns_set_mouse_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
   /* Don't think we can do this on Nextstep.  */
 }
@@ -864,7 +864,7 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
 
 
 static void
-x_icon (struct frame *f, Lisp_Object parms)
+ns_icon (struct frame *f, Lisp_Object parms)
 /* --------------------------------------------------------------------------
    Strangely-named function to set icon position parameters in frame.
    This is irrelevant under macOS, but might be needed under GNUstep,
@@ -897,56 +897,56 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
    implemented.  */
 frame_parm_handler ns_frame_parm_handlers[] =
 {
-  x_set_autoraise, /* generic OK */
-  x_set_autolower, /* generic OK */
-  x_set_background_color,
+  gui_set_autoraise, /* generic OK */
+  gui_set_autolower, /* generic OK */
+  ns_set_background_color,
   0, /* x_set_border_color,  may be impossible under Nextstep */
   0, /* x_set_border_width,  may be impossible under Nextstep */
-  x_set_cursor_color,
-  x_set_cursor_type,
-  x_set_font, /* generic OK */
-  x_set_foreground_color,
-  x_set_icon_name,
-  x_set_icon_type,
-  x_set_internal_border_width, /* generic OK */
-  x_set_right_divider_width,
-  x_set_bottom_divider_width,
-  x_set_menu_bar_lines,
-  x_set_mouse_color,
-  x_explicitly_set_name,
-  x_set_scroll_bar_width, /* generic OK */
-  x_set_scroll_bar_height, /* generic OK */
-  x_set_title,
-  x_set_unsplittable, /* generic OK */
-  x_set_vertical_scroll_bars, /* generic OK */
-  x_set_horizontal_scroll_bars, /* generic OK */
-  x_set_visibility, /* generic OK */
-  x_set_tool_bar_lines,
+  ns_set_cursor_color,
+  ns_set_cursor_type,
+  gui_set_font, /* generic OK */
+  ns_set_foreground_color,
+  ns_set_icon_name,
+  ns_set_icon_type,
+  ns_set_internal_border_width,
+  gui_set_right_divider_width, /* generic OK */
+  gui_set_bottom_divider_width, /* generic OK */
+  ns_set_menu_bar_lines,
+  ns_set_mouse_color,
+  ns_explicitly_set_name,
+  gui_set_scroll_bar_width, /* generic OK */
+  gui_set_scroll_bar_height, /* generic OK */
+  ns_set_title,
+  gui_set_unsplittable, /* generic OK */
+  gui_set_vertical_scroll_bars, /* generic OK */
+  gui_set_horizontal_scroll_bars, /* generic OK */
+  gui_set_visibility, /* generic OK */
+  ns_set_tool_bar_lines,
   0, /* x_set_scroll_bar_foreground, will ignore (not possible on NS) */
   0, /* x_set_scroll_bar_background,  will ignore (not possible on NS) */
-  x_set_screen_gamma, /* generic OK */
-  x_set_line_spacing, /* generic OK, sets f->extra_line_spacing to int */
-  x_set_left_fringe, /* generic OK */
-  x_set_right_fringe, /* generic OK */
+  gui_set_screen_gamma, /* generic OK */
+  gui_set_line_spacing, /* generic OK, sets f->extra_line_spacing to int */
+  gui_set_left_fringe, /* generic OK */
+  gui_set_right_fringe, /* generic OK */
   0, /* x_set_wait_for_wm, will ignore */
-  x_set_fullscreen, /* generic OK */
-  x_set_font_backend, /* generic OK */
-  x_set_alpha,
+  gui_set_fullscreen, /* generic OK */
+  gui_set_font_backend, /* generic OK */
+  gui_set_alpha,
   0, /* x_set_sticky */
   0, /* x_set_tool_bar_position */
   0, /* x_set_inhibit_double_buffering */
 #ifdef NS_IMPL_COCOA
-  x_set_undecorated,
+  ns_set_undecorated,
 #else
-  0, /* x_set_undecorated */
+  0, /* ns_set_undecorated */
 #endif
-  x_set_parent_frame,
+  ns_set_parent_frame,
   0, /* x_set_skip_taskbar */
-  x_set_no_focus_on_map,
-  x_set_no_accept_focus,
-  x_set_z_group, /* x_set_z_group */
+  ns_set_no_focus_on_map,
+  ns_set_no_accept_focus,
+  ns_set_z_group,
   0, /* x_set_override_redirect */
-  x_set_no_special_glyphs,
+  gui_set_no_special_glyphs,
 #ifdef NS_IMPL_COCOA
   ns_set_appearance,
   ns_set_transparent_titlebar,
@@ -979,14 +979,14 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
 	 private shadow variable, it means we are unwinding a frame
 	 for which we didn't yet call init_frame_faces, where the
 	 refcount is incremented.  Therefore, we increment it here, so
-	 that free_frame_faces, called in x_free_frame_resources
+	 that free_frame_faces, called in ns_free_frame_resources
 	 below, will not mistakenly decrement the counter that was not
 	 incremented yet to account for this new frame.  */
       if (FRAME_IMAGE_CACHE (f) != NULL
 	  && FRAME_IMAGE_CACHE (f)->refcount == image_cache_refcount)
 	FRAME_IMAGE_CACHE (f)->refcount++;
 
-      x_free_frame_resources (f);
+      ns_free_frame_resources (f);
       free_glyphs (f);
 
 #if defined GLYPH_DEBUG && defined ENABLE_CHECKING
@@ -1162,35 +1162,35 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
   image_cache_refcount =
     FRAME_IMAGE_CACHE (f) ? FRAME_IMAGE_CACHE (f)->refcount : 0;
 
-  x_default_parameter (f, parms, Qfont_backend, Qnil,
-			"fontBackend", "FontBackend", RES_TYPE_STRING);
+  gui_default_parameter (f, parms, Qfont_backend, Qnil,
+                         "fontBackend", "FontBackend", RES_TYPE_STRING);
 
   {
     /* use for default font name */
     id font = [NSFont userFixedPitchFontOfSize: -1.0]; /* default */
-    x_default_parameter (f, parms, Qfontsize,
-                                    make_fixnum (0 /* (int)[font pointSize] */),
-                                    "fontSize", "FontSize", RES_TYPE_NUMBER);
+    gui_default_parameter (f, parms, Qfontsize,
+                           make_fixnum (0 /* (int)[font pointSize] */),
+                           "fontSize", "FontSize", RES_TYPE_NUMBER);
     // Remove ' Regular', not handled by backends.
     char *fontname = xstrdup ([[font displayName] UTF8String]);
     int len = strlen (fontname);
     if (len > 8 && strcmp (fontname + len - 8, " Regular") == 0)
       fontname[len-8] = '\0';
-    x_default_parameter (f, parms, Qfont,
-                                 build_string (fontname),
-                                 "font", "Font", RES_TYPE_STRING);
+    gui_default_parameter (f, parms, Qfont,
+                           build_string (fontname),
+                           "font", "Font", RES_TYPE_STRING);
     xfree (fontname);
   }
   unblock_input ();
 
-  x_default_parameter (f, parms, Qborder_width, make_fixnum (0),
-		       "borderwidth", "BorderWidth", RES_TYPE_NUMBER);
-  x_default_parameter (f, parms, Qinternal_border_width, make_fixnum (2),
-                      "internalBorderWidth", "InternalBorderWidth",
-                      RES_TYPE_NUMBER);
-  x_default_parameter (f, parms, Qright_divider_width, make_fixnum (0),
+  gui_default_parameter (f, parms, Qborder_width, make_fixnum (0),
+                         "borderwidth", "BorderWidth", RES_TYPE_NUMBER);
+  gui_default_parameter (f, parms, Qinternal_border_width, make_fixnum (2),
+                         "internalBorderWidth", "InternalBorderWidth",
+                         RES_TYPE_NUMBER);
+  gui_default_parameter (f, parms, Qright_divider_width, make_fixnum (0),
 		       NULL, NULL, RES_TYPE_NUMBER);
-  x_default_parameter (f, parms, Qbottom_divider_width, make_fixnum (0),
+  gui_default_parameter (f, parms, Qbottom_divider_width, make_fixnum (0),
 		       NULL, NULL, RES_TYPE_NUMBER);
 
   /* default vertical scrollbars on right on Mac */
@@ -1201,25 +1201,25 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
 #else
           = Qright;
 #endif
-      x_default_parameter (f, parms, Qvertical_scroll_bars, spos,
-			   "verticalScrollBars", "VerticalScrollBars",
-			   RES_TYPE_SYMBOL);
+      gui_default_parameter (f, parms, Qvertical_scroll_bars, spos,
+                             "verticalScrollBars", "VerticalScrollBars",
+                             RES_TYPE_SYMBOL);
   }
-  x_default_parameter (f, parms, Qhorizontal_scroll_bars, Qnil,
-		       "horizontalScrollBars", "HorizontalScrollBars",
-		       RES_TYPE_SYMBOL);
-  x_default_parameter (f, parms, Qforeground_color, build_string ("Black"),
-                      "foreground", "Foreground", RES_TYPE_STRING);
-  x_default_parameter (f, parms, Qbackground_color, build_string ("White"),
-                      "background", "Background", RES_TYPE_STRING);
-  x_default_parameter (f, parms, Qline_spacing, Qnil,
-		       "lineSpacing", "LineSpacing", RES_TYPE_NUMBER);
-  x_default_parameter (f, parms, Qleft_fringe, Qnil,
-		       "leftFringe", "LeftFringe", RES_TYPE_NUMBER);
-  x_default_parameter (f, parms, Qright_fringe, Qnil,
-		       "rightFringe", "RightFringe", RES_TYPE_NUMBER);
-  x_default_parameter (f, parms, Qno_special_glyphs, Qnil,
-		       NULL, NULL, RES_TYPE_BOOLEAN);
+  gui_default_parameter (f, parms, Qhorizontal_scroll_bars, Qnil,
+                         "horizontalScrollBars", "HorizontalScrollBars",
+                         RES_TYPE_SYMBOL);
+  gui_default_parameter (f, parms, Qforeground_color, build_string ("Black"),
+                         "foreground", "Foreground", RES_TYPE_STRING);
+  gui_default_parameter (f, parms, Qbackground_color, build_string ("White"),
+                         "background", "Background", RES_TYPE_STRING);
+  gui_default_parameter (f, parms, Qline_spacing, Qnil,
+                         "lineSpacing", "LineSpacing", RES_TYPE_NUMBER);
+  gui_default_parameter (f, parms, Qleft_fringe, Qnil,
+                         "leftFringe", "LeftFringe", RES_TYPE_NUMBER);
+  gui_default_parameter (f, parms, Qright_fringe, Qnil,
+                         "rightFringe", "RightFringe", RES_TYPE_NUMBER);
+  gui_default_parameter (f, parms, Qno_special_glyphs, Qnil,
+                         NULL, NULL, RES_TYPE_BOOLEAN);
 
   init_frame_faces (f);
 
@@ -1263,31 +1263,32 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
   fset_parent_frame (f, parent_frame);
   store_frame_param (f, Qparent_frame, parent_frame);
 
-  x_default_parameter (f, parms, Qz_group, Qnil, NULL, NULL, RES_TYPE_SYMBOL);
-  x_default_parameter (f, parms, Qno_focus_on_map, Qnil,
-		       NULL, NULL, RES_TYPE_BOOLEAN);
-  x_default_parameter (f, parms, Qno_accept_focus, Qnil,
-                       NULL, NULL, RES_TYPE_BOOLEAN);
+  gui_default_parameter (f, parms, Qz_group, Qnil, NULL, NULL, RES_TYPE_SYMBOL);
+  gui_default_parameter (f, parms, Qno_focus_on_map, Qnil,
+                         NULL, NULL, RES_TYPE_BOOLEAN);
+  gui_default_parameter (f, parms, Qno_accept_focus, Qnil,
+                         NULL, NULL, RES_TYPE_BOOLEAN);
 
   /* The resources controlling the menu-bar and tool-bar are
      processed specially at startup, and reflected in the mode
      variables; ignore them here.  */
-  x_default_parameter (f, parms, Qmenu_bar_lines,
-		       NILP (Vmenu_bar_mode)
-		       ? make_fixnum (0) : make_fixnum (1),
-		       NULL, NULL, RES_TYPE_NUMBER);
-  x_default_parameter (f, parms, Qtool_bar_lines,
-		       NILP (Vtool_bar_mode)
-		       ? make_fixnum (0) : make_fixnum (1),
-		       NULL, NULL, RES_TYPE_NUMBER);
-
-  x_default_parameter (f, parms, Qbuffer_predicate, Qnil, "bufferPredicate",
-                       "BufferPredicate", RES_TYPE_SYMBOL);
-  x_default_parameter (f, parms, Qtitle, Qnil, "title", "Title",
-                       RES_TYPE_STRING);
+  gui_default_parameter (f, parms, Qmenu_bar_lines,
+                         NILP (Vmenu_bar_mode)
+                         ? make_fixnum (0) : make_fixnum (1),
+                         NULL, NULL, RES_TYPE_NUMBER);
+  gui_default_parameter (f, parms, Qtool_bar_lines,
+                         NILP (Vtool_bar_mode)
+                         ? make_fixnum (0) : make_fixnum (1),
+                         NULL, NULL, RES_TYPE_NUMBER);
+
+  gui_default_parameter (f, parms, Qbuffer_predicate, Qnil, "bufferPredicate",
+                         "BufferPredicate", RES_TYPE_SYMBOL);
+  gui_default_parameter (f, parms, Qtitle, Qnil, "title", "Title",
+                         RES_TYPE_STRING);
 
   parms = get_geometry_from_preferences (dpyinfo, parms);
-  window_prompting = x_figure_window_size (f, parms, true, &x_width, &x_height);
+  window_prompting = gui_figure_window_size (f, parms, true,
+                                             &x_width, &x_height);
 
   tem = x_get_arg (dpyinfo, parms, Qunsplittable, 0, 0, RES_TYPE_BOOLEAN);
   f->no_split = minibuffer_only || (!EQ (tem, Qunbound) && !NILP (tem));
@@ -1320,7 +1321,7 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
 
   [[EmacsView alloc] initFrameFromEmacs: f];
 
-  x_icon (f, parms);
+  ns_icon (f, parms);
 
   /* ns_display_info does not have a reference_count.  */
   f->terminal->reference_count++;
@@ -1330,25 +1331,25 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
      won't work.  */
   Vframe_list = Fcons (frame, Vframe_list);
 
-  x_default_parameter (f, parms, Qicon_type, Qnil,
-                       "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL);
-
-  x_default_parameter (f, parms, Qauto_raise, Qnil,
-                       "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN);
-  x_default_parameter (f, parms, Qauto_lower, Qnil,
-                       "autoLower", "AutoLower", RES_TYPE_BOOLEAN);
-  x_default_parameter (f, parms, Qcursor_type, Qbox,
-                       "cursorType", "CursorType", RES_TYPE_SYMBOL);
-  x_default_parameter (f, parms, Qscroll_bar_width, Qnil,
-                       "scrollBarWidth", "ScrollBarWidth",
-                       RES_TYPE_NUMBER);
-  x_default_parameter (f, parms, Qscroll_bar_height, Qnil,
-                       "scrollBarHeight", "ScrollBarHeight",
-                       RES_TYPE_NUMBER);
-  x_default_parameter (f, parms, Qalpha, Qnil,
-                       "alpha", "Alpha", RES_TYPE_NUMBER);
-  x_default_parameter (f, parms, Qfullscreen, Qnil,
-                       "fullscreen", "Fullscreen", RES_TYPE_SYMBOL);
+  gui_default_parameter (f, parms, Qicon_type, Qnil,
+                         "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL);
+
+  gui_default_parameter (f, parms, Qauto_raise, Qnil,
+                         "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN);
+  gui_default_parameter (f, parms, Qauto_lower, Qnil,
+                         "autoLower", "AutoLower", RES_TYPE_BOOLEAN);
+  gui_default_parameter (f, parms, Qcursor_type, Qbox,
+                         "cursorType", "CursorType", RES_TYPE_SYMBOL);
+  gui_default_parameter (f, parms, Qscroll_bar_width, Qnil,
+                         "scrollBarWidth", "ScrollBarWidth",
+                         RES_TYPE_NUMBER);
+  gui_default_parameter (f, parms, Qscroll_bar_height, Qnil,
+                         "scrollBarHeight", "ScrollBarHeight",
+                         RES_TYPE_NUMBER);
+  gui_default_parameter (f, parms, Qalpha, Qnil,
+                         "alpha", "Alpha", RES_TYPE_NUMBER);
+  gui_default_parameter (f, parms, Qfullscreen, Qnil,
+                         "fullscreen", "Fullscreen", RES_TYPE_SYMBOL);
 
   /* Allow x_set_window_size, now.  */
   f->can_x_set_window_size = true;
@@ -1371,7 +1372,7 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
 	visibility = Qt;
 
       if (EQ (visibility, Qicon))
-	x_iconify_frame (f);
+	ns_iconify_frame (f);
       else if (! NILP (visibility))
 	{
 	  x_make_frame_visible (f);
@@ -1395,7 +1396,7 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
       fset_param_alist (f, Fcons (XCAR (tem), f->param_alist));
 
   if (window_prompting & USPosition)
-    x_set_offset (f, f->left_pos, f->top_pos, 1);
+    ns_set_offset (f, f->left_pos, f->top_pos, 1);
 
   /* Make sure windows on this frame appear in calls to next-window
      and similar functions.  */
@@ -1404,21 +1405,6 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
   return unbind_to (count, frame);
 }
 
-void
-x_focus_frame (struct frame *f, bool noactivate)
-{
-  struct ns_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
-
-  if (dpyinfo->x_focus_frame != f)
-    {
-      EmacsView *view = FRAME_NS_VIEW (f);
-      block_input ();
-      [NSApp activateIgnoringOtherApps: YES];
-      [[view window] makeKeyAndOrderFront: view];
-      unblock_input ();
-    }
-}
-
 static BOOL
 ns_window_is_ancestor (NSWindow *win, NSWindow *candidate)
 /* Test whether CANDIDATE is an ancestor window of WIN.  */
@@ -1790,7 +1776,7 @@ Frames are listed from topmost (first) to bottommost (last).  */)
 {
   struct ns_display_info *dpyinfo = check_ns_display_info (terminal);
 
-  return make_fixnum (x_display_pixel_height (dpyinfo) / (92.0/25.4));
+  return make_fixnum (ns_display_pixel_height (dpyinfo) / (92.0/25.4));
 }
 
 
@@ -1800,7 +1786,7 @@ Frames are listed from topmost (first) to bottommost (last).  */)
 {
   struct ns_display_info *dpyinfo = check_ns_display_info (terminal);
 
-  return make_fixnum (x_display_pixel_width (dpyinfo) / (92.0/25.4));
+  return make_fixnum (ns_display_pixel_width (dpyinfo) / (92.0/25.4));
 }
 
 
@@ -2230,7 +2216,7 @@ Frames are listed from topmost (first) to bottommost (last).  */)
 
 
 void
-x_set_scroll_bar_default_width (struct frame *f)
+ns_set_scroll_bar_default_width (struct frame *f)
 {
   int wid = FRAME_COLUMN_WIDTH (f);
   FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = NS_SCROLL_BAR_WIDTH_DEFAULT;
@@ -2239,7 +2225,7 @@ Frames are listed from topmost (first) to bottommost (last).  */)
 }
 
 void
-x_set_scroll_bar_default_height (struct frame *f)
+ns_set_scroll_bar_default_height (struct frame *f)
 {
   int height = FRAME_LINE_HEIGHT (f);
   FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) = NS_SCROLL_BAR_WIDTH_DEFAULT;
@@ -2267,20 +2253,6 @@ Frames are listed from topmost (first) to bottommost (last).  */)
 		   : res);
 }
 
-
-Lisp_Object
-x_get_focus_frame (struct frame *frame)
-{
-  struct ns_display_info *dpyinfo = FRAME_DISPLAY_INFO (frame);
-  Lisp_Object nsfocus;
-
-  if (!dpyinfo->x_focus_frame)
-    return Qnil;
-
-  XSETFRAME (nsfocus, dpyinfo->x_focus_frame);
-  return nsfocus;
-}
-
 /* ==========================================================================
 
     Lisp definitions that, for whatever reason, we can't alias as 'ns-XXX'.
@@ -2361,7 +2333,7 @@ Frames are listed from topmost (first) to bottommost (last).  */)
 {
   struct ns_display_info *dpyinfo = check_ns_display_info (terminal);
 
-  return make_fixnum (x_display_pixel_width (dpyinfo));
+  return make_fixnum (ns_display_pixel_width (dpyinfo));
 }
 
 
@@ -2372,7 +2344,7 @@ Frames are listed from topmost (first) to bottommost (last).  */)
 {
   struct ns_display_info *dpyinfo = check_ns_display_info (terminal);
 
-  return make_fixnum (x_display_pixel_height (dpyinfo));
+  return make_fixnum (ns_display_pixel_height (dpyinfo));
 }
 
 #ifdef NS_IMPL_COCOA
@@ -2659,7 +2631,7 @@ Frames are listed from topmost (first) to bottommost (last).  */)
     {
       /* Absolute coordinates.  */
       pt.x = FIXNUMP (left) ? XFIXNUM (left) : XFIXNUM (right);
-      pt.y = (x_display_pixel_height (FRAME_DISPLAY_INFO (f))
+      pt.y = (ns_display_pixel_height (FRAME_DISPLAY_INFO (f))
 	      - (FIXNUMP (top) ? XFIXNUM (top) : XFIXNUM (bottom))
 	      - height);
     }
diff --git a/src/nsterm.h b/src/nsterm.h
index 78ce608554..4d72ae2402 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -881,8 +881,8 @@ struct ns_display_info
      mouse-face.  */
   Mouse_HLInfo mouse_highlight;
 
-  struct frame *x_highlight_frame;
-  struct frame *x_focus_frame;
+  struct frame *ns_highlight_frame;
+  struct frame *ns_focus_frame;
 
   /* The frame where the mouse was last time we reported a mouse event.  */
   struct frame *last_mouse_frame;
@@ -1122,6 +1122,9 @@ extern Lisp_Object ns_list_fonts (struct frame *f, Lisp_Object pattern,
                                   int size, int maxnames);
 extern void ns_clear_frame (struct frame *f);
 
+extern void ns_set_offset (struct frame *f, int xoff, int yoff,
+                           int change_grav);
+
 extern const char *ns_xlfd_to_fontname (const char *xlfd);
 
 extern Lisp_Object ns_map_event_to_object (void);
@@ -1151,6 +1154,12 @@ extern void ns_check_menu_open (NSMenu *menu);
 extern void ns_check_pending_open_menu (void);
 #endif
 
+/* Implemented in nsfns, published in nsterm.  */
+extern void ns_implicitly_set_name (struct frame *f, Lisp_Object arg,
+                                    Lisp_Object oldval);
+extern void ns_set_scroll_bar_default_width (struct frame *f);
+extern void ns_set_scroll_bar_default_height (struct frame *f);
+
 /* C access to ObjC functionality */
 extern void  ns_release_object (void *obj);
 extern void  ns_retain_object (void *obj);
@@ -1172,6 +1181,8 @@ extern Lisp_Object find_and_return_menu_selection (struct frame *f,
 extern Lisp_Object ns_popup_dialog (struct frame *, Lisp_Object header,
                                     Lisp_Object contents);
 
+extern void ns_free_frame_resources (struct frame *);
+
 #define NSAPP_DATA2_RUNASSCRIPT 10
 extern void ns_run_ascript (void);
 
@@ -1201,22 +1212,23 @@ extern unsigned long ns_get_pixel (void *img, int x, int y);
 extern void ns_put_pixel (void *img, int x, int y, unsigned long argb);
 extern void ns_set_alpha (void *img, int x, int y, unsigned char a);
 
-extern int x_display_pixel_height (struct ns_display_info *);
-extern int x_display_pixel_width (struct ns_display_info *);
+extern int ns_display_pixel_height (struct ns_display_info *);
+extern int ns_display_pixel_width (struct ns_display_info *);
 
 /* This in nsterm.m */
 extern float ns_antialias_threshold;
-extern void x_destroy_window (struct frame *f);
-extern void x_set_undecorated (struct frame *f, Lisp_Object new_value,
-                               Lisp_Object old_value);
-extern void x_set_parent_frame (struct frame *f, Lisp_Object new_value,
+extern void ns_make_frame_visible (struct frame *f)
+extern void ns_iconify_frame (struct frame *f);
+extern void ns_set_undecorated (struct frame *f, Lisp_Object new_value,
                                 Lisp_Object old_value);
-extern void x_set_no_focus_on_map (struct frame *f, Lisp_Object new_value,
-                                   Lisp_Object old_value);
-extern void x_set_no_accept_focus (struct frame *f, Lisp_Object new_value,
-                                   Lisp_Object old_value);
-extern void x_set_z_group (struct frame *f, Lisp_Object new_value,
-                           Lisp_Object old_value);
+extern void ns_set_parent_frame (struct frame *f, Lisp_Object new_value,
+                                 Lisp_Object old_value);
+extern void ns_set_no_focus_on_map (struct frame *f, Lisp_Object new_value,
+                                    Lisp_Object old_value);
+extern void ns_set_no_accept_focus (struct frame *f, Lisp_Object new_value,
+                                    Lisp_Object old_value);
+extern void ns_set_z_group (struct frame *f, Lisp_Object new_value,
+                            Lisp_Object old_value);
 #ifdef NS_IMPL_COCOA
 extern void ns_set_appearance (struct frame *f, Lisp_Object new_value,
                                Lisp_Object old_value);
diff --git a/src/nsterm.m b/src/nsterm.m
index 62fb4b2e21..8d0b14b38f 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -1444,6 +1444,23 @@ -(void)remove
 
    ========================================================================== */
 
+static void
+ns_focus_frame (struct frame *f, bool noactivate)
+/* --------------------------------------------------------------------------
+     External (hook)
+   -------------------------------------------------------------------------- */
+{
+  struct ns_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
+
+  if (dpyinfo->ns_focus_frame != f)
+    {
+      EmacsView *view = FRAME_NS_VIEW (f);
+      block_input ();
+      [NSApp activateIgnoringOtherApps: YES];
+      [[view window] makeKeyAndOrderFront: view];
+      unblock_input ();
+    }
+}
 
 static void
 ns_raise_frame (struct frame *f, BOOL make_key)
@@ -1497,6 +1514,7 @@ -(void)remove
     ns_lower_frame (f);
 }
 
+static void ns_set_frame_alpha (struct frame *f);
 
 static void
 ns_frame_rehighlight (struct frame *frame)
@@ -1508,16 +1526,16 @@ -(void)remove
   struct frame *old_highlight = dpyinfo->x_highlight_frame;
 
   NSTRACE ("ns_frame_rehighlight");
-  if (dpyinfo->x_focus_frame)
+  if (dpyinfo->ns_focus_frame)
     {
       dpyinfo->x_highlight_frame
-	= (FRAMEP (FRAME_FOCUS_FRAME (dpyinfo->x_focus_frame))
-           ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo->x_focus_frame))
-           : dpyinfo->x_focus_frame);
+	= (FRAMEP (FRAME_FOCUS_FRAME (dpyinfo->ns_focus_frame))
+           ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo->ns_focus_frame))
+           : dpyinfo->ns_focus_frame);
       if (!FRAME_LIVE_P (dpyinfo->x_highlight_frame))
         {
-          fset_focus_frame (dpyinfo->x_focus_frame, Qnil);
-          dpyinfo->x_highlight_frame = dpyinfo->x_focus_frame;
+          fset_focus_frame (dpyinfo->ns_focus_frame, Qnil);
+          dpyinfo->x_highlight_frame = dpyinfo->ns_focus_frame;
         }
     }
   else
@@ -1529,24 +1547,24 @@ -(void)remove
       if (old_highlight)
 	{
           gui_update_cursor (old_highlight, 1);
-	  x_set_frame_alpha (old_highlight);
+	  ns_set_frame_alpha (old_highlight);
 	}
       if (dpyinfo->x_highlight_frame)
 	{
           gui_update_cursor (dpyinfo->x_highlight_frame, 1);
-          x_set_frame_alpha (dpyinfo->x_highlight_frame);
+          ns_set_frame_alpha (dpyinfo->x_highlight_frame);
 	}
     }
 }
 
 
 void
-x_make_frame_visible (struct frame *f)
+ns_make_frame_visible (struct frame *f)
 /* --------------------------------------------------------------------------
      External: Show the window (X11 semantics)
    -------------------------------------------------------------------------- */
 {
-  NSTRACE ("x_make_frame_visible");
+  NSTRACE ("ns_make_frame_visible");
   /* XXX: at some points in past this was not needed, as the only place that
      called this (frame.c:Fraise_frame ()) also called raise_lower;
      if this ends up the case again, comment this out again.  */
@@ -1585,20 +1603,20 @@ -(void)remove
           /* If the parent frame moved while the child frame was
              invisible, the child frame's position won't have been
              updated.  Make sure it's in the right place now.  */
-          x_set_offset(f, f->left_pos, f->top_pos, 0);
+          ns_set_offset(f, f->left_pos, f->top_pos, 0);
         }
     }
 }
 
 
-void
-x_make_frame_invisible (struct frame *f)
+static void
+ns_make_frame_invisible (struct frame *f)
 /* --------------------------------------------------------------------------
-     External: Hide the window (X11 semantics)
+     Hide the window (X11 semantics)
    -------------------------------------------------------------------------- */
 {
   NSView *view;
-  NSTRACE ("x_make_frame_invisible");
+  NSTRACE ("ns_make_frame_invisible");
   check_window_system (f);
   view = FRAME_NS_VIEW (f);
   [[view window] orderOut: NSApp];
@@ -1606,17 +1624,28 @@ -(void)remove
   SET_FRAME_ICONIFIED (f, 0);
 }
 
+static void
+ns_make_frame_visible_invisible (struct frame *f, bool visible)
+/* --------------------------------------------------------------------------
+     External (hook)
+   -------------------------------------------------------------------------- */
+{
+  if (visible)
+    ns_make_frame_visible (f);
+  else
+    ns_make_frame_invisible (f);
+}
 
 void
-x_iconify_frame (struct frame *f)
+ns_iconify_frame (struct frame *f)
 /* --------------------------------------------------------------------------
-     External: Iconify window
+     External (hook): Iconify window
    -------------------------------------------------------------------------- */
 {
   NSView *view;
   struct ns_display_info *dpyinfo;
 
-  NSTRACE ("x_iconify_frame");
+  NSTRACE ("ns_iconify_frame");
   check_window_system (f);
   view = FRAME_NS_VIEW (f);
   dpyinfo = FRAME_DISPLAY_INFO (f);
@@ -1644,16 +1673,16 @@ -(void)remove
   unblock_input();
 }
 
-/* Free X resources of frame F.  */
+/* Free resources of frame F.  */
 
 void
-x_free_frame_resources (struct frame *f)
+ns_free_frame_resources (struct frame *f)
 {
   NSView *view;
   struct ns_display_info *dpyinfo;
   Mouse_HLInfo *hlinfo;
 
-  NSTRACE ("x_free_frame_resources");
+  NSTRACE ("ns_free_frame_resources");
   check_window_system (f);
   view = FRAME_NS_VIEW (f);
   dpyinfo = FRAME_DISPLAY_INFO (f);
@@ -1666,8 +1695,8 @@ -(void)remove
   free_frame_menubar (f);
   free_frame_faces (f);
 
-  if (f == dpyinfo->x_focus_frame)
-    dpyinfo->x_focus_frame = 0;
+  if (f == dpyinfo->ns_focus_frame)
+    dpyinfo->ns_focus_frame = 0;
   if (f == dpyinfo->x_highlight_frame)
     dpyinfo->x_highlight_frame = 0;
   if (f == hlinfo->mouse_face_mouse_frame)
@@ -1684,13 +1713,13 @@ -(void)remove
   unblock_input ();
 }
 
-void
-x_destroy_window (struct frame *f)
+static void
+ns_destroy_window (struct frame *f)
 /* --------------------------------------------------------------------------
      External: Delete the window
    -------------------------------------------------------------------------- */
 {
-  NSTRACE ("x_destroy_window");
+  NSTRACE ("ns_destroy_window");
 
   /* If this frame has a parent window, detach it as not doing so can
      cause a crash in GNUStep.  */
@@ -1703,13 +1732,13 @@ -(void)remove
     }
 
   check_window_system (f);
-  x_free_frame_resources (f);
+  ns_free_frame_resources (f);
   ns_window_num--;
 }
 
 
 void
-x_set_offset (struct frame *f, int xoff, int yoff, int change_grav)
+ns_set_offset (struct frame *f, int xoff, int yoff, int change_grav)
 /* --------------------------------------------------------------------------
      External: Position the window
    -------------------------------------------------------------------------- */
@@ -1717,7 +1746,7 @@ -(void)remove
   NSView *view = FRAME_NS_VIEW (f);
   NSScreen *screen = [[view window] screen];
 
-  NSTRACE ("x_set_offset");
+  NSTRACE ("ns_set_offset");
 
   block_input ();
 
@@ -1853,7 +1882,7 @@ breaks live resize (resizing with a mouse), so don't do it if
 
 #ifdef NS_IMPL_COCOA
 void
-x_set_undecorated (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
+ns_set_undecorated (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
 /* --------------------------------------------------------------------------
      Set frame F's `undecorated' parameter.  If non-nil, F's window-system
      window is drawn without decorations, title, minimize/maximize boxes
@@ -1868,7 +1897,7 @@ breaks live resize (resizing with a mouse), so don't do it if
   EmacsView *view = (EmacsView *)FRAME_NS_VIEW (f);
   NSWindow *window = [view window];
 
-  NSTRACE ("x_set_undecorated");
+  NSTRACE ("ns_set_undecorated");
 
   if (!EQ (new_value, old_value))
     {
@@ -1903,7 +1932,7 @@ so some key presses (TAB) are swallowed by the system.  */
 #endif /* NS_IMPL_COCOA */
 
 void
-x_set_parent_frame (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
+ns_set_parent_frame (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
 /* --------------------------------------------------------------------------
      Set frame F's `parent-frame' parameter.  If non-nil, make F a child
      frame of the frame specified by that parameter.  Technically, this
@@ -1929,7 +1958,7 @@ so some key presses (TAB) are swallowed by the system.  */
   struct frame *p = NULL;
   NSWindow *parent, *child;
 
-  NSTRACE ("x_set_parent_frame");
+  NSTRACE ("ns_set_parent_frame");
 
   if (!NILP (new_value)
       && (!FRAMEP (new_value)
@@ -1977,7 +2006,7 @@ so some key presses (TAB) are swallowed by the system.  */
 }
 
 void
-x_set_no_focus_on_map (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
+ns_set_no_focus_on_map (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
 /* Set frame F's `no-focus-on-map' parameter which, if non-nil, means
  * that F's window-system window does not want to receive input focus
  * when it is mapped.  (A frame's window is mapped when the frame is
@@ -1986,7 +2015,7 @@ so some key presses (TAB) are swallowed by the system.  */
  *
  * Some window managers may not honor this parameter.  */
 {
-  NSTRACE ("x_set_no_focus_on_map");
+  NSTRACE ("ns_set_no_focus_on_map");
 
   if (!EQ (new_value, old_value))
     {
@@ -1995,7 +2024,7 @@ so some key presses (TAB) are swallowed by the system.  */
 }
 
 void
-x_set_no_accept_focus (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
+ns_set_no_accept_focus (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
 /*  Set frame F's `no-accept-focus' parameter which, if non-nil, hints
  * that F's window-system window does not want to receive input focus
  * via mouse clicks or by moving the mouse into it.
@@ -2005,14 +2034,14 @@ so some key presses (TAB) are swallowed by the system.  */
  *
  * Some window managers may not honor this parameter.  */
 {
-  NSTRACE ("x_set_no_accept_focus");
+  NSTRACE ("ns_set_no_accept_focus");
 
   if (!EQ (new_value, old_value))
     FRAME_NO_ACCEPT_FOCUS (f) = !NILP (new_value);
 }
 
 void
-x_set_z_group (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
+ns_set_z_group (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
 /* Set frame F's `z-group' parameter.  If `above', F's window-system
    window is displayed above all windows that do not have the `above'
    property set.  If nil, F's window is shown below all windows that
@@ -2025,7 +2054,7 @@ so some key presses (TAB) are swallowed by the system.  */
   EmacsView *view = (EmacsView *)FRAME_NS_VIEW (f);
   NSWindow *window = [view window];
 
-  NSTRACE ("x_set_z_group");
+  NSTRACE ("ns_set_z_group");
 
   if (NILP (new_value))
     {
@@ -2351,7 +2380,7 @@ so some key presses (TAB) are swallowed by the system.  */
 }
 
 void
-ns_query_color(void *col, XColor *color_def, int setPixel)
+ns_query_color(void *col, XColor *color_def, bool setPixel)
 /* --------------------------------------------------------------------------
          Get ARGB values out of NSColor col and put them into color_def.
          If setPixel, set the pixel to a concatenated version.
@@ -2371,7 +2400,6 @@ so some key presses (TAB) are swallowed by the system.  */
 		      (int)(r*255), (int)(g*255), (int)(b*255));
 }
 
-
 bool
 ns_defined_color (struct frame *f,
                   const char *name,
@@ -2403,8 +2431,8 @@ so some key presses (TAB) are swallowed by the system.  */
 }
 
 
-void
-x_set_frame_alpha (struct frame *f)
+static void
+ns_set_frame_alpha (struct frame *f)
 /* --------------------------------------------------------------------------
      change the entire-frame transparency
    -------------------------------------------------------------------------- */
@@ -2413,7 +2441,7 @@ so some key presses (TAB) are swallowed by the system.  */
   double alpha = 1.0;
   double alpha_min = 1.0;
 
-  NSTRACE ("x_set_frame_alpha");
+  NSTRACE ("ns_set_frame_alpha");
 
   if (dpyinfo->x_highlight_frame == f)
     alpha = f->alpha[0];
@@ -2541,7 +2569,7 @@ so some key presses (TAB) are swallowed by the system.  */
       && FRAME_LIVE_P (dpyinfo->last_mouse_frame))
     f = dpyinfo->last_mouse_frame;
   else
-    f = dpyinfo->x_focus_frame ? dpyinfo->x_focus_frame : SELECTED_FRAME ();
+    f = dpyinfo->ns_focus_frame ? dpyinfo->ns_focus_frame : SELECTED_FRAME ();
 
   if (f && FRAME_NS_P (f))
     {
@@ -2639,14 +2667,14 @@ so some key presses (TAB) are swallowed by the system.  */
 
 
 char *
-x_get_keysym_name (int keysym)
+get_keysym_name (int keysym)
 /* --------------------------------------------------------------------------
     Called by keyboard.c.  Not sure if the return val is important, except
     that it be unique.
    -------------------------------------------------------------------------- */
 {
   static char value[16];
-  NSTRACE ("x_get_keysym_name");
+  NSTRACE ("get_keysym_name");
   sprintf (value, "%d", keysym);
   return value;
 }
@@ -4990,7 +5018,7 @@ in certain situations (rapid incoming events).
    ========================================================================== */
 
 int
-x_display_pixel_height (struct ns_display_info *dpyinfo)
+ns_display_pixel_height (struct ns_display_info *dpyinfo)
 {
   NSArray *screens = [NSScreen screens];
   NSEnumerator *enumerator = [screens objectEnumerator];
@@ -5005,7 +5033,7 @@ in certain situations (rapid incoming events).
 }
 
 int
-x_display_pixel_width (struct ns_display_info *dpyinfo)
+ns_display_pixel_width (struct ns_display_info *dpyinfo)
 {
   NSArray *screens = [NSScreen screens];
   NSEnumerator *enumerator = [screens objectEnumerator];
@@ -5089,7 +5117,7 @@ static Lisp_Object ns_string_to_lispmod (const char *s)
     dpyinfo->color_table = xmalloc (sizeof *dpyinfo->color_table);
     dpyinfo->color_table->colors = NULL;
     dpyinfo->root_window = 42; /* A placeholder.  */
-    dpyinfo->x_highlight_frame = dpyinfo->x_focus_frame = NULL;
+    dpyinfo->x_highlight_frame = dpyinfo->ns_focus_frame = NULL;
     dpyinfo->n_fonts = 0;
     dpyinfo->smallest_font_height = 1;
     dpyinfo->smallest_char_width = 1;
@@ -5126,6 +5154,7 @@ static Lisp_Object ns_string_to_lispmod (const char *s)
   ns_draw_glyph_string,
   ns_define_frame_cursor,
   ns_clear_frame_area,
+  0, /* clear_under_internal_border */
   ns_draw_window_cursor,
   ns_draw_vertical_window_border,
   ns_draw_window_divider,
@@ -5157,11 +5186,13 @@ static Lisp_Object ns_string_to_lispmod (const char *s)
 
   block_input ();
 
-  x_destroy_all_bitmaps (dpyinfo);
+  gui_destroy_all_bitmaps (dpyinfo);
   ns_delete_display (dpyinfo);
   unblock_input ();
 }
 
+static Lisp_Object ns_new_font (struct frame *f, Lisp_Object font_object,
+                                int fontset);
 
 static struct terminal *
 ns_create_terminal (struct ns_display_info *dpyinfo)
@@ -5185,17 +5216,25 @@ static Lisp_Object ns_string_to_lispmod (const char *s)
   terminal->read_socket_hook = ns_read_socket;
   terminal->frame_up_to_date_hook = ns_frame_up_to_date;
   terminal->mouse_position_hook = ns_mouse_position;
+  terminal->focus_frame_hook = ns_focus_frame;
   terminal->frame_rehighlight_hook = ns_frame_rehighlight;
   terminal->frame_raise_lower_hook = ns_frame_raise_lower;
+  terminal->frame_visible_invisible_hook = ns_make_frame_visible_invisible;
   terminal->fullscreen_hook = ns_fullscreen_hook;
+  terminal->iconify_frame_hook = ns_iconify_frame;
+  terminal->set_frame_alpha_hook = ns_set_frame_alpha;
+  terminal->set_new_font_hook = ns_new_font;
+  terminal->implicit_set_name_hook = ns_implicitly_set_name;
   terminal->menu_show_hook = ns_menu_show;
   terminal->popup_dialog_hook = ns_popup_dialog;
   terminal->set_vertical_scroll_bar_hook = ns_set_vertical_scroll_bar;
   terminal->set_horizontal_scroll_bar_hook = ns_set_horizontal_scroll_bar;
+  terminal->set_scroll_bar_default_width_hook = ns_set_scroll_bar_default_width;
+  terminal->set_scroll_bar_default_height_hook = ns_set_scroll_bar_default_height;
   terminal->condemn_scroll_bars_hook = ns_condemn_scroll_bars;
   terminal->redeem_scroll_bar_hook = ns_redeem_scroll_bar;
   terminal->judge_scroll_bars_hook = ns_judge_scroll_bars;
-  terminal->delete_frame_hook = x_destroy_window;
+  terminal->delete_frame_hook = ns_destroy_window;
   terminal->delete_terminal_hook = ns_delete_terminal;
   /* Other hooks are NULL by default.  */
 
@@ -5658,7 +5697,7 @@ - (void)sendEvent: (NSEvent *)theEvent
       struct ns_display_info *di;
       BOOL has_focus = NO;
       for (di = x_display_list; ! has_focus && di; di = di->next)
-        has_focus = di->x_focus_frame != 0;
+        has_focus = di->ns_focus_frame != 0;
       if (! has_focus)
         return;
     }
@@ -7215,12 +7254,12 @@ - (void)windowDidBecomeKey: (NSNotification *)notification
 - (void)windowDidBecomeKey      /* for direct calls */
 {
   struct ns_display_info *dpyinfo = FRAME_DISPLAY_INFO (emacsframe);
-  struct frame *old_focus = dpyinfo->x_focus_frame;
+  struct frame *old_focus = dpyinfo->ns_focus_frame;
 
   NSTRACE ("[EmacsView windowDidBecomeKey]");
 
   if (emacsframe != old_focus)
-    dpyinfo->x_focus_frame = emacsframe;
+    dpyinfo->ns_focus_frame = emacsframe;
 
   ns_frame_rehighlight (emacsframe);
 
@@ -7236,11 +7275,11 @@ - (void)windowDidResignKey: (NSNotification *)notification
 /* cf. x_detect_focus_change(), x_focus_changed(), x_new_focus_frame() */
 {
   struct ns_display_info *dpyinfo = FRAME_DISPLAY_INFO (emacsframe);
-  BOOL is_focus_frame = dpyinfo->x_focus_frame == emacsframe;
+  BOOL is_focus_frame = dpyinfo->ns_focus_frame == emacsframe;
   NSTRACE ("[EmacsView windowDidResignKey:]");
 
   if (is_focus_frame)
-    dpyinfo->x_focus_frame = 0;
+    dpyinfo->ns_focus_frame = 0;
 
   emacsframe->mouse_moved = 0;
   ns_frame_rehighlight (emacsframe);
@@ -7250,7 +7289,7 @@ - (void)windowDidResignKey: (NSNotification *)notification
   if (!windowClosing && [[self window] isVisible] == YES)
     {
       gui_update_cursor (emacsframe, 1);
-      x_set_frame_alpha (emacsframe);
+      ns_set_frame_alpha (emacsframe);
     }
 
   if (any_help_event_p)
@@ -9222,9 +9261,12 @@ @implementation EmacsDocument
    ========================================================================== */
 
 
-Lisp_Object
-x_new_font (struct frame *f, Lisp_Object font_object, int fontset)
+static Lisp_Object
+ns_new_font (struct frame *f, Lisp_Object font_object, int fontset)
 {
+  /* --------------------------------------------------------------------------
+     External (hook)
+     -------------------------------------------------------------------------- */
   struct font *font = XFONT_OBJECT (font_object);
   EmacsView *view = FRAME_NS_VIEW (f);
   int font_ascent, font_descent;
diff --git a/src/termhooks.h b/src/termhooks.h
index a92b981110..40749dda37 100644
--- a/src/termhooks.h
+++ b/src/termhooks.h
@@ -512,6 +512,9 @@ struct terminal
                                Lisp_Object *y,
                                Time *);
 
+  /* This hook is called to shift frame focus.  */
+  void (*focus_frame_hook) (struct frame *f, bool noactivate);
+
   /* When a frame's focus redirection is changed, this hook tells the
      window system code to re-decide where to put the highlight.  Under
      X, this means that Emacs lies about where the focus is.  */
@@ -534,6 +537,19 @@ struct terminal
      may do something OS dependent, like extended window manager hints on X11.  */
   void (*fullscreen_hook) (struct frame *f);
 
+  /* This hook is called to iconify the frame.  */
+  void (*iconify_frame_hook) (struct frame *f);
+
+  /* This hook is called to set the frame's transparency.  */
+  void (*set_frame_alpha_hook) (struct frame *f);
+
+  /* This hook is called to set a new font for the frame.  */
+  Lisp_Object (*set_new_font_hook) (struct frame *f, Lisp_Object font_object,
+                                    int fontset);
+
+  void (*implicit_set_name_hook) (struct frame *f, Lisp_Object arg,
+                                  Lisp_Object oldval);
+
   /* This hook is called to display menus.  */
   Lisp_Object (*menu_show_hook) (struct frame *f, int x, int y, int menuflags,
 				 Lisp_Object title, const char **error_name);
@@ -542,6 +558,11 @@ struct terminal
   Lisp_Object (*popup_dialog_hook) (struct frame *f, Lisp_Object header,
 				    Lisp_Object contents);
 
+#ifndef HAVE_EXT_TOOL_BAR
+  /* This hook is called to change the frame's (internal) tool-bar.  */
+  void (*change_tool_bar_height_hook) (struct frame *f, int height);
+#endif
+
   /* Scroll bar hooks.  */
 
   /* The representation of scroll bars is determined by the code which
@@ -583,6 +604,11 @@ struct terminal
 					  int portion, int whole,
 					  int position);
 
+  /* Set the default scroll bar width on FRAME.  */
+  void (*x_set_scroll_bar_default_width) (struct frame *frame);
+
+  /* Set the default scroll bar height on FRAME.  */
+  void (*x_set_scroll_bar_default_height) (struct frame *frame);
 
   /* The following three hooks are used when we're doing a thorough
      redisplay of the frame.  We don't explicitly know which scroll bars
diff --git a/src/w32fns.c b/src/w32fns.c
index e6cb1ee311..f01ced604b 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -314,7 +314,7 @@ check_x_display_info (Lisp_Object object)
       return t->display_info.w32;
     }
   else if (STRINGP (object))
-    return x_display_info_for_name (object);
+    return w32_display_info_for_name (object);
   else
     {
       struct frame *f;
@@ -331,7 +331,7 @@ check_x_display_info (Lisp_Object object)
    It could be the frame's main window or an icon window.  */
 
 struct frame *
-x_window_to_frame (struct w32_display_info *dpyinfo, HWND wdesc)
+w32_window_to_frame (struct w32_display_info *dpyinfo, HWND wdesc)
 {
   Lisp_Object tail, frame;
   struct frame *f;
@@ -355,16 +355,16 @@ static void my_create_window (struct frame *);
 static void my_create_tip_window (struct frame *);
 
 /* TODO: Native Input Method support; see x_create_im.  */
-void x_set_foreground_color (struct frame *, Lisp_Object, Lisp_Object);
-void x_set_background_color (struct frame *, Lisp_Object, Lisp_Object);
-void x_set_mouse_color (struct frame *, Lisp_Object, Lisp_Object);
-void x_set_cursor_color (struct frame *, Lisp_Object, Lisp_Object);
-void x_set_border_color (struct frame *, Lisp_Object, Lisp_Object);
-void x_set_cursor_type (struct frame *, Lisp_Object, Lisp_Object);
-void x_set_icon_type (struct frame *, Lisp_Object, Lisp_Object);
-void x_set_icon_name (struct frame *, Lisp_Object, Lisp_Object);
-void x_explicitly_set_name (struct frame *, Lisp_Object, Lisp_Object);
-void x_set_title (struct frame *, Lisp_Object, Lisp_Object);
+static void w32_set_foreground_color (struct frame *, Lisp_Object, Lisp_Object);
+static void w32_set_background_color (struct frame *, Lisp_Object, Lisp_Object);
+static void w32_set_mouse_color (struct frame *, Lisp_Object, Lisp_Object);
+static void w32_set_border_color (struct frame *, Lisp_Object, Lisp_Object);
+static void w32_set_cursor_color (struct frame *, Lisp_Object, Lisp_Object);
+static void w32_set_cursor_type (struct frame *, Lisp_Object, Lisp_Object);
+static void w32_set_icon_type (struct frame *, Lisp_Object, Lisp_Object);
+static void w32_set_icon_name (struct frame *, Lisp_Object, Lisp_Object);
+static void w32_explicitly_set_name (struct frame *, Lisp_Object, Lisp_Object);
+static void w32_set_title (struct frame *, Lisp_Object, Lisp_Object);
 \f
 
 /* Store the screen positions of frame F into XPTR and YPTR.
@@ -372,7 +372,7 @@ void x_set_title (struct frame *, Lisp_Object, Lisp_Object);
    not Emacs's own window.  */
 
 void
-x_real_positions (struct frame *f, int *xptr, int *yptr)
+w32_real_positions (struct frame *f, int *xptr, int *yptr)
 {
   RECT rect;
 
@@ -1244,7 +1244,7 @@ w32_defined_color (struct frame *f, const char *color, XColor *color_def,
    ARG says.  */
 
 static int
-x_decode_color (struct frame *f, Lisp_Object arg, int def)
+w32_decode_color (struct frame *f, Lisp_Object arg, int def)
 {
   XColor cdef;
 
@@ -1269,7 +1269,7 @@ x_decode_color (struct frame *f, Lisp_Object arg, int def)
 \f
 
 
-/* Functions called only from `x_set_frame_param'
+/* Functions called only from `gui_set_frame_parameters'
    to set individual parameters.
 
    If FRAME_W32_WINDOW (f) is 0,
@@ -1277,13 +1277,13 @@ x_decode_color (struct frame *f, Lisp_Object arg, int def)
    In that case, just record the parameter's new value
    in the standard place; do not attempt to change the window.  */
 
-void
-x_set_foreground_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
+static void
+w32_set_foreground_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
   struct w32_output *x = f->output_data.w32;
   PIX_TYPE fg, old_fg;
 
-  fg = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
+  fg = w32_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
   old_fg = FRAME_FOREGROUND_PIXEL (f);
   FRAME_FOREGROUND_PIXEL (f) = fg;
 
@@ -1301,11 +1301,11 @@ x_set_foreground_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
     }
 }
 
-void
-x_set_background_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
+static void
+w32_set_background_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
   FRAME_BACKGROUND_PIXEL (f)
-    = x_decode_color (f, arg, WHITE_PIX_DEFAULT (f));
+    = w32_decode_color (f, arg, WHITE_PIX_DEFAULT (f));
 
   if (FRAME_W32_WINDOW (f) != 0)
     {
@@ -1319,8 +1319,8 @@ x_set_background_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
     }
 }
 
-void
-x_set_mouse_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
+static void
+w32_set_mouse_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
 #if 0
   Cursor cursor, nontext_cursor, mode_cursor, hand_cursor;
@@ -1330,7 +1330,7 @@ x_set_mouse_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 
   if (!EQ (Qnil, arg))
     f->output_data.w32->mouse_pixel
-      = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
+      = w32_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
   mask_color = FRAME_BACKGROUND_PIXEL (f);
 
   /* Don't let pointers be invisible.  */
@@ -1479,18 +1479,18 @@ x_set_mouse_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 #endif /* TODO */
 }
 
-void
-x_set_cursor_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
+static void
+w32_set_cursor_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
   unsigned long fore_pixel, pixel;
 
   if (!NILP (Vx_cursor_fore_pixel))
-    fore_pixel = x_decode_color (f, Vx_cursor_fore_pixel,
+    fore_pixel = w32_decode_color (f, Vx_cursor_fore_pixel,
 				 WHITE_PIX_DEFAULT (f));
   else
     fore_pixel = FRAME_BACKGROUND_PIXEL (f);
 
-  pixel = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
+  pixel = w32_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
 
   /* Make sure that the cursor color differs from the background color.  */
   if (pixel == FRAME_BACKGROUND_PIXEL (f))
@@ -1527,7 +1527,7 @@ x_set_cursor_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
    F has a window.  */
 
 static void
-x_set_border_pixel (struct frame *f, int pix)
+w32_set_border_pixel (struct frame *f, int pix)
 {
 
   f->output_data.w32->border_pixel = pix;
@@ -1545,26 +1545,26 @@ x_set_border_pixel (struct frame *f, int pix)
    Note that this does not fully take effect if done before
    F has a window; it must be redone when the window is created.  */
 
-void
-x_set_border_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
+static void
+w32_set_border_color (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
   int pix;
 
   CHECK_STRING (arg);
-  pix = x_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
-  x_set_border_pixel (f, pix);
+  pix = w32_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
+  w32_set_border_pixel (f, pix);
   update_face_from_frame_parameter (f, Qborder_color, arg);
 }
 
 
-void
-x_set_cursor_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
+static void
+w32_set_cursor_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
   set_frame_cursor_types (f, arg);
 }
 
-void
-x_set_icon_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
+static void
+w32_set_icon_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
   bool result;
 
@@ -1590,8 +1590,8 @@ x_set_icon_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
   unblock_input ();
 }
 
-void
-x_set_icon_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
+static void
+w32_set_icon_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
   if (STRINGP (arg))
     {
@@ -1638,13 +1638,13 @@ x_set_icon_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 }
 \f
 /**
- * x_clear_under_internal_border:
+ * w32_clear_under_internal_border:
  *
  * Clear area of frame F's internal border.  If the internal border face
  * of F has been specified (is not null), fill the area with that face.
  */
 void
-x_clear_under_internal_border (struct frame *f)
+w32_clear_under_internal_border (struct frame *f)
 {
   int border = FRAME_INTERNAL_BORDER_WIDTH (f);
 
@@ -1685,13 +1685,13 @@ x_clear_under_internal_border (struct frame *f)
 
 
 /**
- * x_set_internal_border_width:
+ * w32_set_internal_border_width:
  *
  * Set width of frame F's internal border to ARG pixels.  ARG < 0 is
  * treated like ARG = 0.
  */
-void
-x_set_internal_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
+static void
+w32_set_internal_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
   int border;
 
@@ -1707,22 +1707,22 @@ x_set_internal_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldva
 	  adjust_frame_size (f, -1, -1, 3, false, Qinternal_border_width);
 
 	  if (FRAME_VISIBLE_P (f))
-	    x_clear_under_internal_border (f);
+	    w32_clear_under_internal_border (f);
 	}
     }
 }
 
 
 /**
- * x_set_menu_bar_lines:
+ * w32_set_menu_bar_lines:
  *
  * Set number of lines of frame F's menu bar to VALUE.  An integer
  * greater zero specifies 1 line and turns the menu bar on if it was off
  * before.  Any other value specifies 0 lines and turns the menu bar off
  * if it was on before.
  */
-void
-x_set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
+static void
+w32_set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
 {
   /* Right now, menu bars don't work properly in minibuf-only frames;
      most of the commands try to apply themselves to the minibuffer
@@ -1761,7 +1761,7 @@ x_set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
 	    }
 
 	  if (FRAME_W32_WINDOW (f))
-	    x_clear_under_internal_border (f);
+	    w32_clear_under_internal_border (f);
 
 	  /* Don't store anything but 1 or 0 in the parameter.  */
 	  store_frame_param (f, Qmenu_bar_lines, make_fixnum (new ? 1 : 0));
@@ -1777,8 +1777,8 @@ x_set_menu_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
    height.  By design, the frame's height doesn't change (but maybe it
    should if we don't get enough space otherwise).  */
 
-void
-x_set_tool_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
+static void
+w32_set_tool_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
 {
   int nlines;
 
@@ -1792,13 +1792,13 @@ x_set_tool_bar_lines (struct frame *f, Lisp_Object value, Lisp_Object oldval)
   else
     nlines = 0;
 
-  x_change_tool_bar_height (f, nlines * FRAME_LINE_HEIGHT (f));
+  w32_change_tool_bar_height (f, nlines * FRAME_LINE_HEIGHT (f));
 }
 
 
 /* Set the pixel height of the tool bar of frame F to HEIGHT.  */
 void
-x_change_tool_bar_height (struct frame *f, int height)
+w32_change_tool_bar_height (struct frame *f, int height)
 {
   int unit = FRAME_LINE_HEIGHT (f);
   int old_height = FRAME_TOOL_BAR_HEIGHT (f);
@@ -1849,7 +1849,7 @@ x_change_tool_bar_height (struct frame *f, int height)
   adjust_frame_glyphs (f);
   SET_FRAME_GARBAGED (f);
   if (FRAME_W32_WINDOW (f))
-    x_clear_under_internal_border (f);
+    w32_clear_under_internal_border (f);
 }
 
 static void
@@ -1909,7 +1909,7 @@ w32_set_title_bar_text (struct frame *f, Lisp_Object name)
        F->explicit_name is set, ignore the new name; otherwise, set it.  */
 
 static void
-x_set_name (struct frame *f, Lisp_Object name, bool explicit)
+w32_set_name (struct frame *f, Lisp_Object name, bool explicit)
 {
   /* Make sure that requests from lisp code override requests from
      Emacs redisplay code.  */
@@ -1955,26 +1955,26 @@ x_set_name (struct frame *f, Lisp_Object name, bool explicit)
 /* This function should be called when the user's lisp code has
    specified a name for the frame; the name will override any set by the
    redisplay code.  */
-void
-x_explicitly_set_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
+static void
+w32_explicitly_set_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
-  x_set_name (f, arg, true);
+  w32_set_name (f, arg, true);
 }
 
 /* This function should be called by Emacs redisplay code to set the
    name; names set this way will never override names set by the user's
    lisp code.  */
 void
-x_implicitly_set_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
+w32_implicitly_set_name (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 {
-  x_set_name (f, arg, false);
+  w32_set_name (f, arg, false);
 }
 \f
 /* Change the title of frame F to NAME.
    If NAME is nil, use the frame name as the title.  */
 
-void
-x_set_title (struct frame *f, Lisp_Object name, Lisp_Object old_name)
+static void
+w32_set_title (struct frame *f, Lisp_Object name, Lisp_Object old_name)
 {
   /* Don't change the title if it's already NAME.  */
   if (EQ (name, f->title))
@@ -1991,7 +1991,7 @@ x_set_title (struct frame *f, Lisp_Object name, Lisp_Object old_name)
 }
 
 void
-x_set_scroll_bar_default_width (struct frame *f)
+w32_set_scroll_bar_default_width (struct frame *f)
 {
   int unit = FRAME_COLUMN_WIDTH (f);
 
@@ -2002,7 +2002,7 @@ x_set_scroll_bar_default_width (struct frame *f)
 
 
 void
-x_set_scroll_bar_default_height (struct frame *f)
+w32_set_scroll_bar_default_height (struct frame *f)
 {
   int unit = FRAME_LINE_HEIGHT (f);
 
@@ -2012,7 +2012,7 @@ x_set_scroll_bar_default_height (struct frame *f)
 }
 
 /**
- * x_set_undecorated:
+ * w32_set_undecorated:
  *
  * Set frame F's `undecorated' parameter.  If non-nil, F's window-system
  * window is drawn without decorations, title, minimize/maximize boxes
@@ -2024,7 +2024,7 @@ x_set_scroll_bar_default_height (struct frame *f)
  * Some window managers may not honor this parameter.
  */
 static void
-x_set_undecorated (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
+w32_set_undecorated (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
 {
   HWND hwnd = FRAME_W32_WINDOW (f);
   DWORD dwStyle = GetWindowLong (hwnd, GWL_STYLE);
@@ -2055,7 +2055,7 @@ x_set_undecorated (struct frame *f, Lisp_Object new_value, Lisp_Object old_value
 }
 
 /**
- * x_set_parent_frame:
+ * w32_set_parent_frame:
  *
  * Set frame F's `parent-frame' parameter.  If non-nil, make F a child
  * frame of the frame specified by that parameter.  Technically, this
@@ -2083,7 +2083,7 @@ x_set_undecorated (struct frame *f, Lisp_Object new_value, Lisp_Object old_value
  * Some window managers may not honor this parameter.
  */
 static void
-x_set_parent_frame (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
+w32_set_parent_frame (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
 {
   struct frame *p = NULL;
 
@@ -2117,7 +2117,7 @@ x_set_parent_frame (struct frame *f, Lisp_Object new_value, Lisp_Object old_valu
 }
 
 /**
- * x_set_skip_taskbar:
+ * w32_set_skip_taskbar:
  *
  * Set frame F's `skip-taskbar' parameter.  If non-nil, this should
  * remove F's icon from the taskbar associated with the display of F's
@@ -2128,7 +2128,7 @@ x_set_parent_frame (struct frame *f, Lisp_Object new_value, Lisp_Object old_valu
  * Some window managers may not honor this parameter.
  */
 static void
-x_set_skip_taskbar (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
+w32_set_skip_taskbar (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
 {
   if (!EQ (new_value, old_value))
     {
@@ -2151,7 +2151,7 @@ x_set_skip_taskbar (struct frame *f, Lisp_Object new_value, Lisp_Object old_valu
 }
 
 /**
- * x_set_no_focus_on_map:
+ * w32_set_no_focus_on_map:
  *
  * Set frame F's `no-focus-on-map' parameter which, if non-nil, means
  * that F's window-system window does not want to receive input focus
@@ -2162,14 +2162,14 @@ x_set_skip_taskbar (struct frame *f, Lisp_Object new_value, Lisp_Object old_valu
  * Some window managers may not honor this parameter.
  */
 static void
-x_set_no_focus_on_map (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
+w32_set_no_focus_on_map (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
 {
   if (!EQ (new_value, old_value))
     FRAME_NO_FOCUS_ON_MAP (f) = !NILP (new_value);
 }
 
 /**
- * x_set_no_accept_focus:
+ * w32_set_no_accept_focus:
  *
  * Set frame F's `no-accept-focus' parameter which, if non-nil, hints
  * that F's window-system window does not want to receive input focus
@@ -2181,14 +2181,14 @@ x_set_no_focus_on_map (struct frame *f, Lisp_Object new_value, Lisp_Object old_v
  * Some window managers may not honor this parameter.
  */
 static void
-x_set_no_accept_focus (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
+w32_set_no_accept_focus (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
 {
   if (!EQ (new_value, old_value))
     FRAME_NO_ACCEPT_FOCUS (f) = !NILP (new_value);
 }
 
 /**
- * x_set_z_group:
+ * w32_set_z_group:
  *
  * Set frame F's `z-group' parameter.  If `above', F's window-system
  * window is displayed above all windows that do not have the `above'
@@ -2206,7 +2206,7 @@ x_set_no_accept_focus (struct frame *f, Lisp_Object new_value, Lisp_Object old_v
  * progress.
  */
 static void
-x_set_z_group (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
+w32_set_z_group (struct frame *f, Lisp_Object new_value, Lisp_Object old_value)
 {
   HWND hwnd = FRAME_W32_WINDOW (f);
 
@@ -4018,7 +4018,7 @@ w32_wnd_proc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
   int windows_translate;
   int key;
 
-  /* Note that it is okay to call x_window_to_frame, even though we are
+  /* Note that it is okay to call w32_window_to_frame, even though we are
      not running in the main lisp thread, because frame deletion
      requires the lisp thread to synchronize with this thread.  Thus, if
      a frame struct is returned, it can be used without concern that the
@@ -4037,7 +4037,7 @@ w32_wnd_proc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
   switch (msg)
     {
     case WM_ERASEBKGND:
-      f = x_window_to_frame (dpyinfo, hwnd);
+      f = w32_window_to_frame (dpyinfo, hwnd);
       if (f)
 	{
 	  HDC hdc = get_frame_dc (f);
@@ -4057,7 +4057,7 @@ w32_wnd_proc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
       /* ignore our own changes */
       if ((HWND)wParam != hwnd)
 	{
-	  f = x_window_to_frame (dpyinfo, hwnd);
+	  f = w32_window_to_frame (dpyinfo, hwnd);
 	  if (f)
 	    /* get_frame_dc will realize our palette and force all
 	       frames to be redrawn if needed. */
@@ -4070,7 +4070,7 @@ w32_wnd_proc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 	RECT update_rect;
 	memset (&update_rect, 0, sizeof (update_rect));
 
-	f = x_window_to_frame (dpyinfo, hwnd);
+	f = w32_window_to_frame (dpyinfo, hwnd);
 	if (f == 0)
 	  {
 	    DebPrint (("WM_PAINT received for unknown window %p\n", hwnd));
@@ -4522,7 +4522,7 @@ w32_wnd_proc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 	     careful not to move the IME window if the window
 	     described by W was deleted, as indicated by its buffer
 	     field being reset to nil.  */
-	  f = x_window_to_frame (dpyinfo, hwnd);
+	  f = w32_window_to_frame (dpyinfo, hwnd);
 	  if (!(f && FRAME_LIVE_P (f)))
 	    goto dflt;
 	  w = XWINDOW (FRAME_SELECTED_WINDOW (f));
@@ -4698,7 +4698,7 @@ w32_wnd_proc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 	int button;
 
 	/* Ignore middle and extra buttons as long as the menu is active.  */
-	f = x_window_to_frame (dpyinfo, hwnd);
+	f = w32_window_to_frame (dpyinfo, hwnd);
 	if (f && f->output_data.w32->menubar_active)
 	  return 0;
 
@@ -4740,7 +4740,7 @@ w32_wnd_proc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
       return (msg == WM_XBUTTONDOWN || msg == WM_XBUTTONUP);
 
     case WM_MOUSEMOVE:
-      f = x_window_to_frame (dpyinfo, hwnd);
+      f = w32_window_to_frame (dpyinfo, hwnd);
       if (f)
 	{
 	  /* Ignore mouse movements as long as the menu is active.
@@ -4878,7 +4878,7 @@ w32_wnd_proc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 	{
 	  KillTimer (hwnd, menu_free_timer);
 	  menu_free_timer = 0;
-	  f = x_window_to_frame (dpyinfo, hwnd);
+	  f = w32_window_to_frame (dpyinfo, hwnd);
 	  /* If a popup menu is active, don't wipe its strings.  */
 	  if (menubar_in_use
 	      && current_popup_menu == NULL)
@@ -4920,7 +4920,7 @@ w32_wnd_proc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 	 this (there is no possibility of confusion with real menubar
 	 being active).  */
 
-      f = x_window_to_frame (dpyinfo, hwnd);
+      f = w32_window_to_frame (dpyinfo, hwnd);
       if (f
 	  && (f->output_data.w32->menubar_active
 	      /* We can receive this message even in the absence of a
@@ -4945,7 +4945,7 @@ w32_wnd_proc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
       }
 
     case WM_EXITMENULOOP:
-      f = x_window_to_frame (dpyinfo, hwnd);
+      f = w32_window_to_frame (dpyinfo, hwnd);
 
       /* If a menu is still active, check again after a short delay,
 	 since Windows often (always?) sends the WM_EXITMENULOOP
@@ -4976,7 +4976,7 @@ w32_wnd_proc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
       return 0;
 
     case WM_MEASUREITEM:
-      f = x_window_to_frame (dpyinfo, hwnd);
+      f = w32_window_to_frame (dpyinfo, hwnd);
       if (f)
 	{
 	  MEASUREITEMSTRUCT * pMis = (MEASUREITEMSTRUCT *) lParam;
@@ -5022,7 +5022,7 @@ w32_wnd_proc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
       return 0;
 
     case WM_DRAWITEM:
-      f = x_window_to_frame (dpyinfo, hwnd);
+      f = w32_window_to_frame (dpyinfo, hwnd);
       if (f)
 	{
 	  DRAWITEMSTRUCT * pDis = (DRAWITEMSTRUCT *) lParam;
@@ -5083,7 +5083,7 @@ w32_wnd_proc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 	 user to click anywhere without changing point (or worse!).
 	 Don't eat mouse clicks on scrollbars though!!  */
 
-      if ((f = x_window_to_frame (dpyinfo, hwnd))
+      if ((f = w32_window_to_frame (dpyinfo, hwnd))
 	  && FRAME_NO_ACCEPT_FOCUS (f)
 	  /* Ignore child frames, they don't accept focus anyway.  */
 	  && !FRAME_PARENT_FRAME (f))
@@ -5132,7 +5132,7 @@ w32_wnd_proc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
       goto command;
     case WM_COMMAND:
       menubar_in_use = 0;
-      f = x_window_to_frame (dpyinfo, hwnd);
+      f = w32_window_to_frame (dpyinfo, hwnd);
       if (f && HIWORD (wParam) == 0)
 	{
 	  if (menu_free_timer)
@@ -5197,7 +5197,7 @@ w32_wnd_proc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
     case WM_SETCURSOR:
       if (LOWORD (lParam) == HTCLIENT)
 	{
-	  f = x_window_to_frame (dpyinfo, hwnd);
+	  f = w32_window_to_frame (dpyinfo, hwnd);
 	  if (f)
 	    {
 	      if (f->output_data.w32->hourglass_p
@@ -5216,7 +5216,7 @@ w32_wnd_proc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
     case WM_EMACS_SETCURSOR:
       {
 	Cursor cursor = (Cursor) wParam;
-	f = x_window_to_frame (dpyinfo, hwnd);
+	f = w32_window_to_frame (dpyinfo, hwnd);
 	if (f && cursor)
 	  {
 	    f->output_data.w32->current_cursor = cursor;
@@ -5355,7 +5355,7 @@ w32_wnd_proc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
 
 	/* Use menubar_active to indicate that WM_INITMENU is from
 	   TrackPopupMenu below, and should be ignored.  */
-	f = x_window_to_frame (dpyinfo, hwnd);
+	f = w32_window_to_frame (dpyinfo, hwnd);
 	if (f)
 	  f->output_data.w32->menubar_active = 1;
 
@@ -5496,7 +5496,7 @@ w32_window (struct frame *f, long window_prompting, bool minibuffer_only)
 
   validate_x_resource_name ();
 
-  /* x_set_name normally ignores requests to set the name if the
+  /* w32_set_name normally ignores requests to set the name if the
      requested name is the same as the current name.  This is the one
      place where that assumption isn't correct; f->name is set, but
      the server hasn't been told.  */
@@ -5507,7 +5507,7 @@ w32_window (struct frame *f, long window_prompting, bool minibuffer_only)
     f->explicit_name = 0;
     name = f->name;
     fset_name (f, Qnil);
-    x_set_name (f, name, explicit);
+    w32_set_name (f, name, explicit);
   }
 
   unblock_input ();
@@ -5525,7 +5525,7 @@ w32_window (struct frame *f, long window_prompting, bool minibuffer_only)
    well.  */
 
 static void
-x_icon (struct frame *f, Lisp_Object parms)
+w32_icon (struct frame *f, Lisp_Object parms)
 {
   Lisp_Object icon_x, icon_y;
   struct w32_display_info *dpyinfo = &one_w32_display_info;
@@ -5544,24 +5544,14 @@ x_icon (struct frame *f, Lisp_Object parms)
 
   block_input ();
 
-#if 0 /* TODO */
-  /* Start up iconic or window? */
-  x_wm_set_window_state
-    (f, (EQ (x_get_arg (dpyinfo, parms, Qvisibility, 0, 0, RES_TYPE_SYMBOL), Qicon)
-	 ? IconicState
-	 : NormalState));
-
-  x_text_icon (f, SSDATA ((!NILP (f->icon_name)
-			   ? f->icon_name
-			   : f->name)));
-#endif
+  /* TODO: Start up iconic or window? */
 
   unblock_input ();
 }
 
 
 static void
-x_make_gc (struct frame *f)
+w32_make_gc (struct frame *f)
 {
   XGCValues gc_values;
 
@@ -5589,8 +5579,8 @@ x_make_gc (struct frame *f)
 }
 
 
-/* Handler for signals raised during x_create_frame and
-   x_create_tip_frame.  FRAME is the frame which is partially
+/* Handler for signals raised during Fx_create_frame and
+   w32_create_tip_frame.  FRAME is the frame which is partially
    constructed.  */
 
 static Lisp_Object
@@ -5608,7 +5598,7 @@ unwind_create_frame (Lisp_Object frame)
 	 private shadow variable, it means we are unwinding a frame
 	 for which we didn't yet call init_frame_faces, where the
 	 refcount is incremented.  Therefore, we increment it here, so
-	 that free_frame_faces, called in x_free_frame_resources
+	 that free_frame_faces, called in w32_free_frame_resources
 	 below, will not mistakenly decrement the counter that was not
 	 incremented yet to account for this new frame.  */
       if (FRAME_IMAGE_CACHE (f) != NULL
@@ -5616,7 +5606,7 @@ unwind_create_frame (Lisp_Object frame)
 	FRAME_IMAGE_CACHE (f)->refcount++;
 #endif
 
-      x_free_frame_resources (f);
+      w32_free_frame_resources (f);
       free_glyphs (f);
 
 #ifdef GLYPH_DEBUG
@@ -5640,11 +5630,11 @@ do_unwind_create_frame (Lisp_Object frame)
 }
 
 static void
-x_default_font_parameter (struct frame *f, Lisp_Object parms)
+w32_default_font_parameter (struct frame *f, Lisp_Object parms)
 {
   struct w32_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
   Lisp_Object font_param = x_get_arg (dpyinfo, parms, Qfont, NULL, NULL,
-				RES_TYPE_STRING);
+                                      RES_TYPE_STRING);
   Lisp_Object font;
   if (EQ (font_param, Qunbound))
     font_param = Qnil;
@@ -5674,10 +5664,10 @@ x_default_font_parameter (struct frame *f, Lisp_Object parms)
     {
       /* Remember the explicit font parameter, so we can re-apply it after
 	 we've applied the `default' face settings.  */
-      x_set_frame_parameters (f, Fcons (Fcons (Qfont_parameter, font_param),
-					Qnil));
+      gui_set_frame_parameters (f, Fcons (Fcons (Qfont_parameter, font_param),
+                                          Qnil));
     }
-  x_default_parameter (f, parms, Qfont, font, "font", "Font", RES_TYPE_STRING);
+  gui_default_parameter (f, parms, Qfont, font, "font", "Font", RES_TYPE_STRING);
 }
 
 DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
@@ -5844,16 +5834,16 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
     register_font_driver (&uniscribe_font_driver, f);
   register_font_driver (&w32font_driver, f);
 
-  x_default_parameter (f, parameters, Qfont_backend, Qnil,
-		       "fontBackend", "FontBackend", RES_TYPE_STRING);
+  gui_default_parameter (f, parameters, Qfont_backend, Qnil,
+                         "fontBackend", "FontBackend", RES_TYPE_STRING);
 
   /* Extract the window parameters from the supplied values
      that are needed to determine window geometry.  */
-  x_default_font_parameter (f, parameters);
+  w32_default_font_parameter (f, parameters);
 
   /* Default BorderWidth to 0 to match other platforms.  */
-  x_default_parameter (f, parameters, Qborder_width, make_fixnum (0),
-		       "borderWidth", "BorderWidth", RES_TYPE_NUMBER);
+  gui_default_parameter (f, parameters, Qborder_width, make_fixnum (0),
+                         "borderWidth", "BorderWidth", RES_TYPE_NUMBER);
 
   /* We recognize either internalBorderWidth or internalBorder
      (which is what xterm calls it).  */
@@ -5868,46 +5858,46 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
 			    parameters);
     }
 
-  x_default_parameter (f, parameters, Qinternal_border_width, make_fixnum (0),
-		       "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER);
-  x_default_parameter (f, parameters, Qright_divider_width, make_fixnum (0),
-		       NULL, NULL, RES_TYPE_NUMBER);
-  x_default_parameter (f, parameters, Qbottom_divider_width, make_fixnum (0),
-		       NULL, NULL, RES_TYPE_NUMBER);
-  x_default_parameter (f, parameters, Qvertical_scroll_bars, Qright,
-		       "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL);
-  x_default_parameter (f, parameters, Qhorizontal_scroll_bars, Qnil,
-		       "horizontalScrollBars", "ScrollBars", RES_TYPE_SYMBOL);
+  gui_default_parameter (f, parameters, Qinternal_border_width, make_fixnum (0),
+                         "internalBorderWidth", "InternalBorder", RES_TYPE_NUMBER);
+  gui_default_parameter (f, parameters, Qright_divider_width, make_fixnum (0),
+                         NULL, NULL, RES_TYPE_NUMBER);
+  gui_default_parameter (f, parameters, Qbottom_divider_width, make_fixnum (0),
+                         NULL, NULL, RES_TYPE_NUMBER);
+  gui_default_parameter (f, parameters, Qvertical_scroll_bars, Qright,
+                         "verticalScrollBars", "ScrollBars", RES_TYPE_SYMBOL);
+  gui_default_parameter (f, parameters, Qhorizontal_scroll_bars, Qnil,
+                         "horizontalScrollBars", "ScrollBars", RES_TYPE_SYMBOL);
 
   /* Also do the stuff which must be set before the window exists.  */
-  x_default_parameter (f, parameters, Qforeground_color, build_string ("black"),
-		       "foreground", "Foreground", RES_TYPE_STRING);
-  x_default_parameter (f, parameters, Qbackground_color, build_string ("white"),
-		       "background", "Background", RES_TYPE_STRING);
-  x_default_parameter (f, parameters, Qmouse_color, build_string ("black"),
-		       "pointerColor", "Foreground", RES_TYPE_STRING);
-  x_default_parameter (f, parameters, Qborder_color, build_string ("black"),
-		       "borderColor", "BorderColor", RES_TYPE_STRING);
-  x_default_parameter (f, parameters, Qscreen_gamma, Qnil,
-		       "screenGamma", "ScreenGamma", RES_TYPE_FLOAT);
-  x_default_parameter (f, parameters, Qline_spacing, Qnil,
-		       "lineSpacing", "LineSpacing", RES_TYPE_NUMBER);
-  x_default_parameter (f, parameters, Qleft_fringe, Qnil,
-		       "leftFringe", "LeftFringe", RES_TYPE_NUMBER);
-  x_default_parameter (f, parameters, Qright_fringe, Qnil,
-		       "rightFringe", "RightFringe", RES_TYPE_NUMBER);
-  x_default_parameter (f, parameters, Qno_focus_on_map, Qnil,
-		       NULL, NULL, RES_TYPE_BOOLEAN);
-  x_default_parameter (f, parameters, Qno_accept_focus, Qnil,
-		       NULL, NULL, RES_TYPE_BOOLEAN);
-  x_default_parameter (f, parameters, Qno_special_glyphs, Qnil,
-		       NULL, NULL, RES_TYPE_BOOLEAN);
+  gui_default_parameter (f, parameters, Qforeground_color, build_string ("black"),
+                         "foreground", "Foreground", RES_TYPE_STRING);
+  gui_default_parameter (f, parameters, Qbackground_color, build_string ("white"),
+                         "background", "Background", RES_TYPE_STRING);
+  gui_default_parameter (f, parameters, Qmouse_color, build_string ("black"),
+                         "pointerColor", "Foreground", RES_TYPE_STRING);
+  gui_default_parameter (f, parameters, Qborder_color, build_string ("black"),
+                         "borderColor", "BorderColor", RES_TYPE_STRING);
+  gui_default_parameter (f, parameters, Qscreen_gamma, Qnil,
+                         "screenGamma", "ScreenGamma", RES_TYPE_FLOAT);
+  gui_default_parameter (f, parameters, Qline_spacing, Qnil,
+                         "lineSpacing", "LineSpacing", RES_TYPE_NUMBER);
+  gui_default_parameter (f, parameters, Qleft_fringe, Qnil,
+                         "leftFringe", "LeftFringe", RES_TYPE_NUMBER);
+  gui_default_parameter (f, parameters, Qright_fringe, Qnil,
+                         "rightFringe", "RightFringe", RES_TYPE_NUMBER);
+  gui_default_parameter (f, parameters, Qno_focus_on_map, Qnil,
+                         NULL, NULL, RES_TYPE_BOOLEAN);
+  gui_default_parameter (f, parameters, Qno_accept_focus, Qnil,
+                         NULL, NULL, RES_TYPE_BOOLEAN);
+  gui_default_parameter (f, parameters, Qno_special_glyphs, Qnil,
+                         NULL, NULL, RES_TYPE_BOOLEAN);
 
   /* Process alpha here (Bug#16619).  On XP this fails with child
      frames.  For `no-focus-on-map' frames delay processing of alpha
      until the frame becomes visible.  */
   if (!FRAME_NO_FOCUS_ON_MAP (f))
-    x_default_parameter (f, parameters, Qalpha, Qnil,
+    gui_default_parameter (f, parameters, Qalpha, Qnil,
 			 "alpha", "Alpha", RES_TYPE_NUMBER);
 
   /* Init faces first since we need the frame's column width/line
@@ -5915,7 +5905,7 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
   init_frame_faces (f);
 
   /* We have to call adjust_frame_size here since otherwise
-     x_set_tool_bar_lines will already work with the character sizes
+     w32_set_tool_bar_lines will already work with the character sizes
      installed by init_frame_faces while the frame's pixel size is still
      calculated from a character size of 1 and we subsequently hit the
      (height >= 0) assertion in window_box_height.
@@ -5943,24 +5933,24 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
      variables; ignore them here.  */
   if (NILP (parent_frame))
     {
-      x_default_parameter (f, parameters, Qmenu_bar_lines,
-			   NILP (Vmenu_bar_mode)
-			   ? make_fixnum (0) : make_fixnum (1),
-			   NULL, NULL, RES_TYPE_NUMBER);
+      gui_default_parameter (f, parameters, Qmenu_bar_lines,
+                             NILP (Vmenu_bar_mode)
+                             ? make_fixnum (0) : make_fixnum (1),
+                             NULL, NULL, RES_TYPE_NUMBER);
     }
   else
     /* No menu bar for child frames.  */
     store_frame_param (f, Qmenu_bar_lines, make_fixnum (0));
 
-  x_default_parameter (f, parameters, Qtool_bar_lines,
-		       NILP (Vtool_bar_mode)
-		       ? make_fixnum (0) : make_fixnum (1),
-		       NULL, NULL, RES_TYPE_NUMBER);
+  gui_default_parameter (f, parameters, Qtool_bar_lines,
+                         NILP (Vtool_bar_mode)
+                         ? make_fixnum (0) : make_fixnum (1),
+                         NULL, NULL, RES_TYPE_NUMBER);
 
-  x_default_parameter (f, parameters, Qbuffer_predicate, Qnil,
-		       "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL);
-  x_default_parameter (f, parameters, Qtitle, Qnil,
-		       "title", "Title", RES_TYPE_STRING);
+  gui_default_parameter (f, parameters, Qbuffer_predicate, Qnil,
+                         "bufferPredicate", "BufferPredicate", RES_TYPE_SYMBOL);
+  gui_default_parameter (f, parameters, Qtitle, Qnil,
+                         "title", "Title", RES_TYPE_STRING);
 
   f->output_data.w32->parent_desc = FRAME_DISPLAY_INFO (f)->root_window;
   f->output_data.w32->text_cursor = w32_load_cursor (IDC_IBEAM);
@@ -5981,15 +5971,16 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
 
   f->output_data.w32->current_cursor = f->output_data.w32->nontext_cursor;
 
-  window_prompting = x_figure_window_size (f, parameters, true, &x_width, &x_height);
+  window_prompting = gui_figure_window_size (f, parameters, true,
+                                             &x_width, &x_height);
 
   tem = x_get_arg (dpyinfo, parameters, Qunsplittable, 0, 0, RES_TYPE_BOOLEAN);
   f->no_split = minibuffer_only || EQ (tem, Qt);
 
   w32_window (f, window_prompting, minibuffer_only);
-  x_icon (f, parameters);
+  w32_icon (f, parameters);
 
-  x_make_gc (f);
+  w32_make_gc (f);
 
   /* Now consider the frame official.  */
   f->terminal->reference_count++;
@@ -5998,19 +5989,19 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
 
   /* We need to do this after creating the window, so that the
      icon-creation functions can say whose icon they're describing.  */
-  x_default_parameter (f, parameters, Qicon_type, Qnil,
-		       "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL);
-
-  x_default_parameter (f, parameters, Qauto_raise, Qnil,
-		       "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN);
-  x_default_parameter (f, parameters, Qauto_lower, Qnil,
-		       "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN);
-  x_default_parameter (f, parameters, Qcursor_type, Qbox,
-		       "cursorType", "CursorType", RES_TYPE_SYMBOL);
-  x_default_parameter (f, parameters, Qscroll_bar_width, Qnil,
-		       "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER);
-  x_default_parameter (f, parameters, Qscroll_bar_height, Qnil,
-		       "scrollBarHeight", "ScrollBarHeight", RES_TYPE_NUMBER);
+  gui_default_parameter (f, parameters, Qicon_type, Qnil,
+                         "bitmapIcon", "BitmapIcon", RES_TYPE_SYMBOL);
+
+  gui_default_parameter (f, parameters, Qauto_raise, Qnil,
+                         "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN);
+  gui_default_parameter (f, parameters, Qauto_lower, Qnil,
+                         "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN);
+  gui_default_parameter (f, parameters, Qcursor_type, Qbox,
+                         "cursorType", "CursorType", RES_TYPE_SYMBOL);
+  gui_default_parameter (f, parameters, Qscroll_bar_width, Qnil,
+                         "scrollBarWidth", "ScrollBarWidth", RES_TYPE_NUMBER);
+  gui_default_parameter (f, parameters, Qscroll_bar_height, Qnil,
+                         "scrollBarHeight", "ScrollBarHeight", RES_TYPE_NUMBER);
 
   /* Allow x_set_window_size, now.  */
   f->can_x_set_window_size = true;
@@ -6024,7 +6015,7 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
      badly we want them.  This should be done after we have the menu
      bar so that its size can be taken into account.  */
   block_input ();
-  x_wm_set_size_hint (f, window_prompting, false);
+  w32_wm_set_size_hint (f, window_prompting, false);
   unblock_input ();
 
   adjust_frame_size (f, FRAME_TEXT_WIDTH (f), FRAME_TEXT_HEIGHT (f), 0, true,
@@ -6033,10 +6024,10 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
   /* Process fullscreen parameter here in the hope that normalizing a
      fullheight/fullwidth frame will produce the size set by the last
      adjust_frame_size call.  */
-  x_default_parameter (f, parameters, Qfullscreen, Qnil,
-		       "fullscreen", "Fullscreen", RES_TYPE_SYMBOL);
-  x_default_parameter (f, parameters, Qz_group, Qnil,
-		       NULL, NULL, RES_TYPE_SYMBOL);
+  gui_default_parameter (f, parameters, Qfullscreen, Qnil,
+                         "fullscreen", "Fullscreen", RES_TYPE_SYMBOL);
+  gui_default_parameter (f, parameters, Qz_group, Qnil,
+                         NULL, NULL, RES_TYPE_SYMBOL);
 
   /* Make the window appear on the frame and enable display, unless
      the caller says not to.  However, with explicit parent, Emacs
@@ -6047,7 +6038,7 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
 	= x_get_arg (dpyinfo, parameters, Qvisibility, 0, 0, RES_TYPE_SYMBOL);
 
       if (EQ (visibility, Qicon))
-	x_iconify_frame (f);
+	w32_iconify_frame (f);
       else
 	{
 	  if (EQ (visibility, Qunbound))
@@ -6062,8 +6053,8 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
 
   /* For `no-focus-on-map' frames set alpha here.  */
   if (FRAME_NO_FOCUS_ON_MAP (f))
-    x_default_parameter (f, parameters, Qalpha, Qnil,
-			 "alpha", "Alpha", RES_TYPE_NUMBER);
+    gui_default_parameter (f, parameters, Qalpha, Qnil,
+                           "alpha", "Alpha", RES_TYPE_NUMBER);
 
   /* Initialize `default-minibuffer-frame' in case this is the first
      frame on this terminal.  */
@@ -6085,21 +6076,6 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
   return unbind_to (count, frame);
 }
 
-/* FRAME is used only to get a handle on the X display.  We don't pass the
-   display info directly because we're called from frame.c, which doesn't
-   know about that structure.  */
-Lisp_Object
-x_get_focus_frame (struct frame *frame)
-{
-  struct w32_display_info *dpyinfo = FRAME_DISPLAY_INFO (frame);
-  Lisp_Object xfocus;
-  if (! dpyinfo->w32_focus_frame)
-    return Qnil;
-
-  XSETFRAME (xfocus, dpyinfo->w32_focus_frame);
-  return xfocus;
-}
-
 DEFUN ("xw-color-defined-p", Fxw_color_defined_p, Sxw_color_defined_p, 1, 2, 0,
        doc: /* SKIP: real doc in xfns.c.  */)
   (Lisp_Object color, Lisp_Object frame)
@@ -6164,7 +6140,7 @@ DEFUN ("x-display-pixel-width", Fx_display_pixel_width,
 {
   struct w32_display_info *dpyinfo = check_x_display_info (display);
 
-  return make_fixnum (x_display_pixel_width (dpyinfo));
+  return make_fixnum (w32_display_pixel_width (dpyinfo));
 }
 
 DEFUN ("x-display-pixel-height", Fx_display_pixel_height,
@@ -6174,7 +6150,7 @@ DEFUN ("x-display-pixel-height", Fx_display_pixel_height,
 {
   struct w32_display_info *dpyinfo = check_x_display_info (display);
 
-  return make_fixnum (x_display_pixel_height (dpyinfo));
+  return make_fixnum (w32_display_pixel_height (dpyinfo));
 }
 
 DEFUN ("x-display-planes", Fx_display_planes, Sx_display_planes,
@@ -6248,7 +6224,7 @@ DEFUN ("x-display-mm-height", Fx_display_mm_height,
 		  / GetDeviceCaps (hdc, VERTRES));
   ReleaseDC (NULL, hdc);
 
-  return make_fixnum (x_display_pixel_height (dpyinfo) * mm_per_pixel + 0.5);
+  return make_fixnum (w32_display_pixel_height (dpyinfo) * mm_per_pixel + 0.5);
 }
 
 DEFUN ("x-display-mm-width", Fx_display_mm_width, Sx_display_mm_width, 0, 1, 0,
@@ -6264,7 +6240,7 @@ DEFUN ("x-display-mm-width", Fx_display_mm_width, Sx_display_mm_width, 0, 1, 0,
 		  / GetDeviceCaps (hdc, HORZRES));
   ReleaseDC (NULL, hdc);
 
-  return make_fixnum (x_display_pixel_width (dpyinfo) * mm_per_pixel + 0.5);
+  return make_fixnum (w32_display_pixel_width (dpyinfo) * mm_per_pixel + 0.5);
 }
 
 DEFUN ("x-display-backing-store", Fx_display_backing_store,
@@ -6438,8 +6414,8 @@ w32_display_monitor_attributes_list_fallback (struct w32_display_info *dpyinfo)
     }
   attributes = Fcons (Fcons (Qframes, frames), attributes);
 
-  pixel_width = x_display_pixel_width (dpyinfo);
-  pixel_height = x_display_pixel_height (dpyinfo);
+  pixel_width = w32_display_pixel_width (dpyinfo);
+  pixel_height = w32_display_pixel_height (dpyinfo);
 
   hdc = GetDC (NULL);
   mm_per_pixel = ((double) GetDeviceCaps (hdc, HORZSIZE)
@@ -6536,7 +6512,7 @@ x_screen_planes (register struct frame *f)
    Open a new connection if necessary.  */
 
 struct w32_display_info *
-x_display_info_for_name (Lisp_Object name)
+w32_display_info_for_name (Lisp_Object name)
 {
   struct w32_display_info *dpyinfo;
 
@@ -6655,7 +6631,7 @@ DEFUN ("x-close-connection", Fx_close_connection,
   block_input ();
   x_destroy_all_bitmaps (dpyinfo);
 
-  x_delete_display (dpyinfo);
+  w32_delete_display (dpyinfo);
   unblock_input ();
 
   return Qnil;
@@ -6831,13 +6807,13 @@ unwind_create_tip_frame (Lisp_Object frame)
 /* Create a frame for a tooltip on the display described by DPYINFO.
    PARMS is a list of frame parameters.  Value is the frame.
 
-   Note that functions called here, esp. x_default_parameter can
+   Note that functions called here, esp. gui_default_parameter can
    signal errors, for instance when a specified color name is
    undefined.  We have to make sure that we're in a consistent state
    when this happens.  */
 
 static Lisp_Object
-x_create_tip_frame (struct w32_display_info *dpyinfo, Lisp_Object parms)
+w32_create_tip_frame (struct w32_display_info *dpyinfo, Lisp_Object parms)
 {
   struct frame *f;
   Lisp_Object frame;
@@ -6876,7 +6852,7 @@ x_create_tip_frame (struct w32_display_info *dpyinfo, Lisp_Object parms)
 
   /* By setting the output method, we're essentially saying that
      the frame is live, as per FRAME_LIVE_P.  If we get a signal
-     from this point on, x_destroy_window might screw up reference
+     from this point on, w32_destroy_window might screw up reference
      counts etc.  */
   f->terminal = dpyinfo->terminal;
   f->output_method = output_w32;
@@ -6912,15 +6888,15 @@ x_create_tip_frame (struct w32_display_info *dpyinfo, Lisp_Object parms)
     register_font_driver (&uniscribe_font_driver, f);
   register_font_driver (&w32font_driver, f);
 
-  x_default_parameter (f, parms, Qfont_backend, Qnil,
-		       "fontBackend", "FontBackend", RES_TYPE_STRING);
+  gui_default_parameter (f, parms, Qfont_backend, Qnil,
+                         "fontBackend", "FontBackend", RES_TYPE_STRING);
 
   /* Extract the window parameters from the supplied values
      that are needed to determine window geometry.  */
-  x_default_font_parameter (f, parms);
+  w32_default_font_parameter (f, parms);
 
-  x_default_parameter (f, parms, Qborder_width, make_fixnum (2),
-		       "borderWidth", "BorderWidth", RES_TYPE_NUMBER);
+  gui_default_parameter (f, parms, Qborder_width, make_fixnum (2),
+                         "borderWidth", "BorderWidth", RES_TYPE_NUMBER);
   /* This defaults to 2 in order to match xterm.  We recognize either
      internalBorderWidth or internalBorder (which is what xterm calls
      it).  */
@@ -6935,24 +6911,24 @@ x_create_tip_frame (struct w32_display_info *dpyinfo, Lisp_Object parms)
 		       parms);
     }
 
-  x_default_parameter (f, parms, Qinternal_border_width, make_fixnum (1),
-		       "internalBorderWidth", "internalBorderWidth",
-		       RES_TYPE_NUMBER);
+  gui_default_parameter (f, parms, Qinternal_border_width, make_fixnum (1),
+                         "internalBorderWidth", "internalBorderWidth",
+                         RES_TYPE_NUMBER);
   /* Also do the stuff which must be set before the window exists.  */
-  x_default_parameter (f, parms, Qforeground_color, build_string ("black"),
-		       "foreground", "Foreground", RES_TYPE_STRING);
-  x_default_parameter (f, parms, Qbackground_color, build_string ("white"),
-		       "background", "Background", RES_TYPE_STRING);
-  x_default_parameter (f, parms, Qmouse_color, build_string ("black"),
-		       "pointerColor", "Foreground", RES_TYPE_STRING);
-  x_default_parameter (f, parms, Qcursor_color, build_string ("black"),
-		       "cursorColor", "Foreground", RES_TYPE_STRING);
-  x_default_parameter (f, parms, Qborder_color, build_string ("black"),
-		       "borderColor", "BorderColor", RES_TYPE_STRING);
-  x_default_parameter (f, parms, Qno_special_glyphs, Qt,
-		       NULL, NULL, RES_TYPE_BOOLEAN);
-
-  /* Init faces before x_default_parameter is called for the
+  gui_default_parameter (f, parms, Qforeground_color, build_string ("black"),
+                         "foreground", "Foreground", RES_TYPE_STRING);
+  gui_default_parameter (f, parms, Qbackground_color, build_string ("white"),
+                         "background", "Background", RES_TYPE_STRING);
+  gui_default_parameter (f, parms, Qmouse_color, build_string ("black"),
+                         "pointerColor", "Foreground", RES_TYPE_STRING);
+  gui_default_parameter (f, parms, Qcursor_color, build_string ("black"),
+                         "cursorColor", "Foreground", RES_TYPE_STRING);
+  gui_default_parameter (f, parms, Qborder_color, build_string ("black"),
+                         "borderColor", "BorderColor", RES_TYPE_STRING);
+  gui_default_parameter (f, parms, Qno_special_glyphs, Qt,
+                         NULL, NULL, RES_TYPE_BOOLEAN);
+
+  /* Init faces before gui_default_parameter is called for the
      scroll-bar-width parameter because otherwise we end up in
      init_iterator with a null face cache, which should not happen.  */
   init_frame_faces (f);
@@ -6961,7 +6937,7 @@ x_create_tip_frame (struct w32_display_info *dpyinfo, Lisp_Object parms)
   f->output_data.w32->parent_desc = FRAME_DISPLAY_INFO (f)->root_window;
   f->output_data.w32->explicit_parent = false;
 
-  x_figure_window_size (f, parms, true, &x_width, &x_height);
+  gui_figure_window_size (f, parms, true, &x_width, &x_height);
 
   /* No fringes on tip frame.  */
   f->fringe_cols = 0;
@@ -6975,17 +6951,17 @@ x_create_tip_frame (struct w32_display_info *dpyinfo, Lisp_Object parms)
   my_create_tip_window (f);
   unblock_input ();
 
-  x_make_gc (f);
+  w32_make_gc (f);
 
-  x_default_parameter (f, parms, Qauto_raise, Qnil,
-		       "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN);
-  x_default_parameter (f, parms, Qauto_lower, Qnil,
-		       "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN);
-  x_default_parameter (f, parms, Qcursor_type, Qbox,
-		       "cursorType", "CursorType", RES_TYPE_SYMBOL);
+  gui_default_parameter (f, parms, Qauto_raise, Qnil,
+                         "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN);
+  gui_default_parameter (f, parms, Qauto_lower, Qnil,
+                         "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN);
+  gui_default_parameter (f, parms, Qcursor_type, Qbox,
+                         "cursorType", "CursorType", RES_TYPE_SYMBOL);
   /* Process alpha here (Bug#17344).  */
-  x_default_parameter (f, parms, Qalpha, Qnil,
-		       "alpha", "Alpha", RES_TYPE_NUMBER);
+  gui_default_parameter (f, parms, Qalpha, Qnil,
+                         "alpha", "Alpha", RES_TYPE_NUMBER);
 
   /* Dimensions, especially FRAME_LINES (f), must be done via
      change_frame_size.  Change will not be effected unless different
@@ -7079,8 +7055,8 @@ compute_tip_xy (struct frame *f,
       /* Default min and max values.  */
       min_x = 0;
       min_y = 0;
-      max_x = x_display_pixel_width (FRAME_DISPLAY_INFO (f));
-      max_y = x_display_pixel_height (FRAME_DISPLAY_INFO (f));
+      max_x = w32_display_pixel_width (FRAME_DISPLAY_INFO (f));
+      max_y = w32_display_pixel_height (FRAME_DISPLAY_INFO (f));
 
       block_input ();
       GetCursorPos (&pt);
@@ -7145,7 +7121,7 @@ compute_tip_xy (struct frame *f,
 }
 
 /**
- * x_hide_tip:
+ * w32_hide_tip:
  *
  * Hide currently visible tooltip and cancel its timer.
  *
@@ -7156,7 +7132,7 @@ compute_tip_xy (struct frame *f,
  * otherwise.
  */
 static Lisp_Object
-x_hide_tip (bool delete)
+w32_hide_tip (bool delete)
 {
   if (!NILP (tip_timer))
     {
@@ -7329,13 +7305,13 @@ DEFUN ("x-show-tip", Fx_show_tip, Sx_show_tip, 1, 6, 0,
 		}
 	    }
 
-	  x_hide_tip (delete);
+	  w32_hide_tip (delete);
 	}
       else
-	x_hide_tip (true);
+	w32_hide_tip (true);
     }
   else
-    x_hide_tip (true);
+    w32_hide_tip (true);
 
   tip_last_frame = frame;
   tip_last_string = string;
@@ -7364,7 +7340,7 @@ DEFUN ("x-show-tip", Fx_show_tip, Sx_show_tip, 1, 6, 0,
       /* Create a frame for the tooltip and record it in the global
 	 variable tip_frame.  */
       struct frame *f;		/* The value is unused.  */
-      if (NILP (tip_frame = x_create_tip_frame (FRAME_DISPLAY_INFO (f), parms)))
+      if (NILP (tip_frame = w32_create_tip_frame (FRAME_DISPLAY_INFO (f), parms)))
 	{
 	  /* Creating the tip frame failed.  */
 	  unblock_input ();
@@ -7485,7 +7461,7 @@ DEFUN ("x-hide-tip", Fx_hide_tip, Sx_hide_tip, 0, 0, 0,
        doc: /* SKIP: real doc in xfns.c.  */)
   (void)
 {
-  return x_hide_tip (!tooltip_reuse_hidden_frame);
+  return w32_hide_tip (!tooltip_reuse_hidden_frame);
 }
 \f
 /***********************************************************************
@@ -7621,9 +7597,9 @@ w32_dialog_in_progress (Lisp_Object in_progress)
       struct frame *f = XFRAME (frame);
 
       if (!NILP (in_progress) && FRAME_Z_GROUP_ABOVE (f))
-	x_set_z_group (f, Qabove_suspended, Qabove);
+	w32_set_z_group (f, Qabove_suspended, Qabove);
       else if (NILP (in_progress) && FRAME_Z_GROUP_ABOVE_SUSPENDED (f))
-	x_set_z_group (f, Qabove, Qabove_suspended);
+	w32_set_z_group (f, Qabove, Qabove_suspended);
     }
 }
 
@@ -8924,7 +8900,7 @@ w32_frame_list_z_order (struct w32_display_info *dpyinfo, HWND window)
 
   while (window)
     {
-      struct frame *f = x_window_to_frame (dpyinfo, window);
+      struct frame *f = w32_window_to_frame (dpyinfo, window);
 
       if (f)
 	{
@@ -10162,52 +10138,52 @@ to be converted to forward slashes by the caller.  */)
 
 frame_parm_handler w32_frame_parm_handlers[] =
 {
-  x_set_autoraise,
-  x_set_autolower,
-  x_set_background_color,
-  x_set_border_color,
-  x_set_border_width,
-  x_set_cursor_color,
-  x_set_cursor_type,
-  x_set_font,
-  x_set_foreground_color,
-  x_set_icon_name,
-  x_set_icon_type,
-  x_set_internal_border_width,
-  x_set_right_divider_width,
-  x_set_bottom_divider_width,
-  x_set_menu_bar_lines,
-  x_set_mouse_color,
-  x_explicitly_set_name,
-  x_set_scroll_bar_width,
-  x_set_scroll_bar_height,
-  x_set_title,
-  x_set_unsplittable,
-  x_set_vertical_scroll_bars,
-  x_set_horizontal_scroll_bars,
-  x_set_visibility,
-  x_set_tool_bar_lines,
+  gui_set_autoraise,
+  gui_set_autolower,
+  w32_set_background_color,
+  w32_set_border_color,
+  gui_set_border_width,
+  w32_set_cursor_color,
+  w32_set_cursor_type,
+  gui_set_font,
+  w32_set_foreground_color,
+  w32_set_icon_name,
+  w32_set_icon_type,
+  w32_set_internal_border_width,
+  gui_set_right_divider_width,
+  gui_set_bottom_divider_width,
+  w32_set_menu_bar_lines,
+  w32_set_mouse_color,
+  w32_explicitly_set_name,
+  gui_set_scroll_bar_width,
+  gui_set_scroll_bar_height,
+  w32_set_title,
+  gui_set_unsplittable,
+  gui_set_vertical_scroll_bars,
+  gui_set_horizontal_scroll_bars,
+  gui_set_visibility,
+  w32_set_tool_bar_lines,
   0, /* x_set_scroll_bar_foreground, */
   0, /* x_set_scroll_bar_background, */
-  x_set_screen_gamma,
-  x_set_line_spacing,
-  x_set_left_fringe,
-  x_set_right_fringe,
+  gui_set_screen_gamma,
+  gui_set_line_spacing,
+  gui_set_left_fringe,
+  gui_set_right_fringe,
   0, /* x_set_wait_for_wm, */
-  x_set_fullscreen,
-  x_set_font_backend,
-  x_set_alpha,
+  gui_set_fullscreen,
+  gui_set_font_backend,
+  gui_set_alpha,
   0, /* x_set_sticky */
   0, /* x_set_tool_bar_position */
   0, /* x_set_inhibit_double_buffering */
-  x_set_undecorated,
-  x_set_parent_frame,
-  x_set_skip_taskbar,
-  x_set_no_focus_on_map,
-  x_set_no_accept_focus,
-  x_set_z_group,
+  w32_set_undecorated,
+  w32_set_parent_frame,
+  w32_set_skip_taskbar,
+  w32_set_no_focus_on_map,
+  w32_set_no_accept_focus,
+  w32_set_z_group,
   0, /* x_set_override_redirect */
-  x_set_no_special_glyphs,
+  gui_set_no_special_glyphs,
 };
 
 void
diff --git a/src/w32font.c b/src/w32font.c
index 33c89825e9..848016da1c 100644
--- a/src/w32font.c
+++ b/src/w32font.c
@@ -678,7 +678,7 @@ w32font_draw (struct glyph_string *s, int from, int to,
 	 characters, because drawing background with font dimensions
 	 in those cases makes the display illegible.  There's only one
 	 more call to the draw method with with_background set to
-	 true, and that's in x_draw_glyph_string_foreground, when
+	 true, and that's in w32_draw_glyph_string_foreground, when
 	 drawing the cursor, where we have no such heuristics
 	 available.  FIXME.  */
       if (s->first_glyph->type == GLYPHLESS_GLYPH
diff --git a/src/w32menu.c b/src/w32menu.c
index 38e1b506e0..42912db443 100644
--- a/src/w32menu.c
+++ b/src/w32menu.c
@@ -1469,7 +1469,7 @@ w32_menu_display_help (HWND owner, HMENU menu, UINT item, UINT flags)
 {
   if (get_menu_item_info)
     {
-      struct frame *f = x_window_to_frame (&one_w32_display_info, owner);
+      struct frame *f = w32_window_to_frame (&one_w32_display_info, owner);
       Lisp_Object frame, help;
 
       /* No help echo on owner-draw menu items, or when the keyboard
diff --git a/src/w32term.c b/src/w32term.c
index edcdc56a9e..a3589c06c9 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -87,9 +87,6 @@ extern unsigned int msh_mousewheel;
 extern int w32_codepage_for_font (char *fontname);
 extern Cursor w32_load_cursor (LPCTSTR name);
 
-#define x_any_window_to_frame x_window_to_frame
-#define x_top_window_to_frame x_window_to_frame
-
 \f
 /* This is display since w32 does not support multiple ones.  */
 struct w32_display_info one_w32_display_info;
@@ -171,27 +168,25 @@ static void w32_handle_tool_bar_click (struct frame *,
                                        struct input_event *);
 static void w32_define_cursor (Window, Cursor);
 
-void x_lower_frame (struct frame *);
-void x_scroll_bar_clear (struct frame *);
-void x_raise_frame (struct frame *);
-void x_wm_set_window_state (struct frame *, int);
-void x_wm_set_icon_pixmap (struct frame *, int);
+void w32_scroll_bar_clear (struct frame *);
+static void w32_raise_frame (struct frame *);
+static void w32_lower_frame (struct frame *);
 static void w32_initialize (void);
-static void x_update_end (struct frame *);
+static void w32_update_end (struct frame *);
 static void w32_frame_up_to_date (struct frame *);
-static void x_clear_frame (struct frame *);
+static void w32_clear_frame (struct frame *);
 static void w32_frame_highlight (struct frame *);
 static void w32_frame_unhighlight (struct frame *);
-static void x_new_focus_frame (struct w32_display_info *,
-                               struct frame *);
-static void x_focus_changed (int, int, struct w32_display_info *,
+static void w32_new_focus_frame (struct w32_display_info *,
+                                 struct frame *);
+static void w32_focus_changed (int, int, struct w32_display_info *,
                              struct frame *, struct input_event *);
 static void w32_detect_focus_change (struct w32_display_info *,
                                      W32Msg *, struct input_event *);
 static void w32_frame_rehighlight (struct frame *);
-static void x_frame_rehighlight (struct w32_display_info *);
-static void x_draw_hollow_cursor (struct window *, struct glyph_row *);
-static void x_draw_bar_cursor (struct window *, struct glyph_row *, int,
+static void w32_frame_rehighlight (struct w32_display_info *);
+static void w32_draw_hollow_cursor (struct window *, struct glyph_row *);
+static void w32_draw_bar_cursor (struct window *, struct glyph_row *, int,
                                enum text_cursor_kinds);
 static void w32_clip_to_row (struct window *, struct glyph_row *,
 			     enum glyph_row_area, HDC);
@@ -205,7 +200,7 @@ static void my_destroy_window (struct frame *, HWND);
 static void w32fullscreen_hook (struct frame *);
 
 #ifdef GLYPH_DEBUG
-static void x_check_font (struct frame *, struct font *);
+static void w32_check_font (struct frame *, struct font *);
 #endif
 
 \f
@@ -263,7 +258,7 @@ XCreateGC (void *ignore, HWND wignore, unsigned long mask, XGCValues *xgcv)
   return gc;
 }
 
-#if 0	/* unused for now, see x_draw_image_glyph_string below */
+#if 0	/* unused for now, see w32_draw_image_glyph_string below */
 static void
 XGetGCValues (void *ignore, XGCValues *gc,
 	      unsigned long mask, XGCValues *xgcv)
@@ -306,7 +301,7 @@ w32_restore_glyph_string_clip (struct glyph_string *s)
 }
 
 static void
-x_get_scale_factor(struct w32_display_info *dpyinfo, int *scale_x, int *scale_y)
+w32_get_scale_factor(struct w32_display_info *dpyinfo, int *scale_x, int *scale_y)
 {
   const int base_res = 96;
 
@@ -338,7 +333,7 @@ w32_draw_underwave (struct glyph_string *s, COLORREF color)
   struct w32_display_info *dpyinfo = FRAME_DISPLAY_INFO (s->f);
 
   int scale_x, scale_y;
-  x_get_scale_factor (dpyinfo, &scale_x, &scale_y);
+  w32_get_scale_factor (dpyinfo, &scale_x, &scale_y);
 
   int wave_height = 3 * scale_y, wave_length = 2 * scale_x, thickness = scale_y;
   int dx, dy, x0, y0, width, x1, y1, x2, y2, odd, xmax;
@@ -457,8 +452,8 @@ w32_clear_window (struct frame *f)
 
 #define OPAQUE_FRAME 255
 
-void
-x_set_frame_alpha (struct frame *f)
+static void
+w32_set_frame_alpha (struct frame *f)
 {
   struct w32_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
   double alpha = 1.0;
@@ -504,7 +499,7 @@ x_set_frame_alpha (struct frame *f)
 }
 
 int
-x_display_pixel_height (struct w32_display_info *dpyinfo)
+w32_display_pixel_height (struct w32_display_info *dpyinfo)
 {
   int pixels = GetSystemMetrics (SM_CYVIRTUALSCREEN);
 
@@ -516,7 +511,7 @@ x_display_pixel_height (struct w32_display_info *dpyinfo)
 }
 
 int
-x_display_pixel_width (struct w32_display_info *dpyinfo)
+w32_display_pixel_width (struct w32_display_info *dpyinfo)
 {
   int pixels = GetSystemMetrics (SM_CXVIRTUALSCREEN);
 
@@ -534,11 +529,11 @@ x_display_pixel_width (struct w32_display_info *dpyinfo)
 
 /* Start an update of frame F.  This function is installed as a hook
    for update_begin, i.e. it is called when update_begin is called.
-   This function is called prior to calls to x_update_window_begin for
-   each window being updated.  */
+   This function is called prior to calls to w32_update_window_begin
+   for each window being updated.  */
 
 static void
-x_update_begin (struct frame *f)
+w32_update_begin (struct frame *f)
 {
   struct w32_display_info *display_info = FRAME_DISPLAY_INFO (f);
 
@@ -558,7 +553,7 @@ x_update_begin (struct frame *f)
 /* Start update of window W.  */
 
 static void
-x_update_window_begin (struct window *w)
+w32_update_window_begin (struct window *w)
 {
   struct frame *f = XFRAME (WINDOW_FRAME (w));
   Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f);
@@ -698,7 +693,7 @@ w32_draw_window_divider (struct window *w, int x0, int x1, int y0, int y1)
    here. */
 
 static void
-x_update_window_end (struct window *w, bool cursor_on_p,
+w32_update_window_end (struct window *w, bool cursor_on_p,
 		     bool mouse_face_overwritten_p)
 {
   if (!w->pseudo_window_p)
@@ -734,7 +729,7 @@ x_update_window_end (struct window *w, bool cursor_on_p,
 
   /* Unhide the caret.  This won't actually show the cursor, unless it
      was visible before the corresponding call to HideCaret in
-     x_update_window_begin.  */
+     w32_update_window_begin.  */
   if (w32_use_visible_system_caret && w32_system_caret_hwnd)
     {
       SendMessageTimeout (w32_system_caret_hwnd, WM_EMACS_SHOW_CARET, 0, 0,
@@ -747,7 +742,7 @@ x_update_window_end (struct window *w, bool cursor_on_p,
    update_end.  */
 
 static void
-x_update_end (struct frame *f)
+w32_update_end (struct frame *f)
 {
   if (! FRAME_W32_P (f))
     return;
@@ -775,7 +770,7 @@ w32_frame_up_to_date (struct frame *f)
    between bitmaps to be drawn between current row and DESIRED_ROW.  */
 
 static void
-x_after_update_window_line (struct window *w, struct glyph_row *desired_row)
+w32_after_update_window_line (struct window *w, struct glyph_row *desired_row)
 {
   struct frame *f;
   int width, height;
@@ -942,27 +937,27 @@ w32_destroy_fringe_bitmap (int which)
 
 /* Function prototypes of this page.  */
 
-static void x_set_glyph_string_clipping (struct glyph_string *);
-static void x_set_glyph_string_gc (struct glyph_string *);
-static void x_draw_glyph_string_background (struct glyph_string *,
-                                            bool);
-static void x_draw_glyph_string_foreground (struct glyph_string *);
-static void x_draw_composite_glyph_string_foreground (struct glyph_string *);
-static void x_draw_glyph_string_box (struct glyph_string *);
-static void x_draw_glyph_string  (struct glyph_string *);
-static void x_set_cursor_gc (struct glyph_string *);
-static void x_set_mode_line_face_gc (struct glyph_string *);
-static void x_set_mouse_face_gc (struct glyph_string *);
+static void w32_set_glyph_string_clipping (struct glyph_string *);
+static void w32_set_glyph_string_gc (struct glyph_string *);
+static void w32_draw_glyph_string_background (struct glyph_string *,
+                                              bool);
+static void w32_draw_glyph_string_foreground (struct glyph_string *);
+static void w32_draw_composite_glyph_string_foreground (struct glyph_string *);
+static void w32_draw_glyph_string_box (struct glyph_string *);
+static void w32_draw_glyph_string  (struct glyph_string *);
+static void w32_set_cursor_gc (struct glyph_string *);
+static void w32_set_mode_line_face_gc (struct glyph_string *);
+static void w32_set_mouse_face_gc (struct glyph_string *);
 static int w32_alloc_lighter_color (struct frame *, COLORREF *, double, int);
 static void w32_setup_relief_color (struct frame *, struct relief *,
                                     double, int, COLORREF);
-static void x_setup_relief_colors (struct glyph_string *);
-static void x_draw_image_glyph_string (struct glyph_string *);
-static void x_draw_image_relief (struct glyph_string *);
-static void x_draw_image_foreground (struct glyph_string *);
+static void w32_setup_relief_colors (struct glyph_string *);
+static void w32_draw_image_glyph_string (struct glyph_string *);
+static void w32_draw_image_relief (struct glyph_string *);
+static void w32_draw_image_foreground (struct glyph_string *);
 static void w32_draw_image_foreground_1 (struct glyph_string *, HBITMAP);
-static void x_clear_glyph_string_rect (struct glyph_string *, int,
-                                       int, int, int);
+static void w32_clear_glyph_string_rect (struct glyph_string *, int,
+                                         int, int, int);
 static void w32_draw_relief_rect (struct frame *, int, int, int, int,
                                   int, int, int, int, int, int,
                                   RECT *);
@@ -974,7 +969,7 @@ static void w32_draw_box_rect (struct glyph_string *, int, int, int, int,
    face.  */
 
 static void
-x_set_cursor_gc (struct glyph_string *s)
+w32_set_cursor_gc (struct glyph_string *s)
 {
   if (s->font == FRAME_FONT (s->f)
       && s->face->background == FRAME_BACKGROUND_PIXEL (s->f)
@@ -1010,7 +1005,7 @@ x_set_cursor_gc (struct glyph_string *s)
 	  xgcv.foreground = s->face->background;
 	}
 
-      IF_DEBUG (x_check_font (s->f, s->font));
+      IF_DEBUG (w32_check_font (s->f, s->font));
       xgcv.font = s->font;
       mask = GCForeground | GCBackground | GCFont;
 
@@ -1029,7 +1024,7 @@ x_set_cursor_gc (struct glyph_string *s)
 /* Set up S->gc of glyph string S for drawing text in mouse face.  */
 
 static void
-x_set_mouse_face_gc (struct glyph_string *s)
+w32_set_mouse_face_gc (struct glyph_string *s)
 {
   int face_id;
   struct face *face;
@@ -1059,7 +1054,7 @@ x_set_mouse_face_gc (struct glyph_string *s)
 
       xgcv.background = s->face->background;
       xgcv.foreground = s->face->foreground;
-      IF_DEBUG (x_check_font (s->f, s->font));
+      IF_DEBUG (w32_check_font (s->f, s->font));
       xgcv.font = s->font;
       mask = GCForeground | GCBackground | GCFont;
 
@@ -1082,7 +1077,7 @@ x_set_mouse_face_gc (struct glyph_string *s)
    matrix was built, so there isn't much to do, here.  */
 
 static inline void
-x_set_mode_line_face_gc (struct glyph_string *s)
+w32_set_mode_line_face_gc (struct glyph_string *s)
 {
   s->gc = s->face->gc;
 }
@@ -1093,7 +1088,7 @@ x_set_mode_line_face_gc (struct glyph_string *s)
    pattern.  */
 
 static inline void
-x_set_glyph_string_gc (struct glyph_string *s)
+w32_set_glyph_string_gc (struct glyph_string *s)
 {
   prepare_face_for_display (s->f, s->face);
 
@@ -1104,17 +1099,17 @@ x_set_glyph_string_gc (struct glyph_string *s)
     }
   else if (s->hl == DRAW_INVERSE_VIDEO)
     {
-      x_set_mode_line_face_gc (s);
+      w32_set_mode_line_face_gc (s);
       s->stippled_p = s->face->stipple != 0;
     }
   else if (s->hl == DRAW_CURSOR)
     {
-      x_set_cursor_gc (s);
+      w32_set_cursor_gc (s);
       s->stippled_p = false;
     }
   else if (s->hl == DRAW_MOUSE_FACE)
     {
-      x_set_mouse_face_gc (s);
+      w32_set_mouse_face_gc (s);
       s->stippled_p = s->face->stipple != 0;
     }
   else if (s->hl == DRAW_IMAGE_RAISED
@@ -1135,7 +1130,7 @@ x_set_glyph_string_gc (struct glyph_string *s)
    line or menu if we don't have X toolkit support.  */
 
 static inline void
-x_set_glyph_string_clipping (struct glyph_string *s)
+w32_set_glyph_string_clipping (struct glyph_string *s)
 {
   RECT *r = s->clip;
   int n = get_glyph_string_clip_rects (s, r, 2);
@@ -1159,8 +1154,8 @@ x_set_glyph_string_clipping (struct glyph_string *s)
    the area of SRC.  */
 
 static void
-x_set_glyph_string_clipping_exactly (struct glyph_string *src,
-				     struct glyph_string *dst)
+w32_set_glyph_string_clipping_exactly (struct glyph_string *src,
+                                       struct glyph_string *dst)
 {
   RECT r;
 
@@ -1205,7 +1200,7 @@ w32_compute_glyph_string_overhangs (struct glyph_string *s)
 /* Fill rectangle X, Y, W, H with background color of glyph string S.  */
 
 static inline void
-x_clear_glyph_string_rect (struct glyph_string *s,
+w32_clear_glyph_string_rect (struct glyph_string *s,
 			   int x, int y, int w, int h)
 {
   int real_x = x;
@@ -1236,7 +1231,7 @@ x_clear_glyph_string_rect (struct glyph_string *s,
    contains the first component of a composition.  */
 
 static void
-x_draw_glyph_string_background (struct glyph_string *s, bool force_p)
+w32_draw_glyph_string_background (struct glyph_string *s, bool force_p)
 {
   /* Nothing to do if background has already been drawn or if it
      shouldn't be drawn in the first place.  */
@@ -1268,7 +1263,7 @@ x_draw_glyph_string_background (struct glyph_string *s, bool force_p)
 	       || s->extends_to_end_of_line_p
 	       || force_p)
 	{
-	  x_clear_glyph_string_rect (s, s->x, s->y + box_line_width,
+	  w32_clear_glyph_string_rect (s, s->x, s->y + box_line_width,
 				     s->background_width,
 				     s->height - 2 * box_line_width);
 	  s->background_filled_p = true;
@@ -1280,7 +1275,7 @@ x_draw_glyph_string_background (struct glyph_string *s, bool force_p)
 /* Draw the foreground of glyph string S.  */
 
 static void
-x_draw_glyph_string_foreground (struct glyph_string *s)
+w32_draw_glyph_string_foreground (struct glyph_string *s)
 {
   int i, x;
 
@@ -1337,7 +1332,7 @@ x_draw_glyph_string_foreground (struct glyph_string *s)
 /* Draw the foreground of composite glyph string S.  */
 
 static void
-x_draw_composite_glyph_string_foreground (struct glyph_string *s)
+w32_draw_composite_glyph_string_foreground (struct glyph_string *s)
 {
   int i, j, x;
   struct font *font = s->font;
@@ -1432,7 +1427,7 @@ x_draw_composite_glyph_string_foreground (struct glyph_string *s)
 /* Draw the foreground of glyph string S for glyphless characters.  */
 
 static void
-x_draw_glyphless_glyph_string_foreground (struct glyph_string *s)
+w32_draw_glyphless_glyph_string_foreground (struct glyph_string *s)
 {
   struct glyph *glyph = s->first_glyph;
   XChar2b char2b[8];
@@ -1599,7 +1594,7 @@ w32_alloc_lighter_color (struct frame *f, COLORREF *color,
    colors in COLORS.  On W32, we no longer try to map colors to
    a palette.  */
 void
-x_query_colors (struct frame *f, XColor *colors, int ncolors)
+w32_query_colors (struct frame *f, XColor *colors, int ncolors)
 {
   int i;
 
@@ -1613,12 +1608,6 @@ x_query_colors (struct frame *f, XColor *colors, int ncolors)
     }
 }
 
-void
-x_query_color (struct frame *f, XColor *color)
-{
-  x_query_colors (f, color, 1);
-}
-
 
 /* Set up the foreground color for drawing relief lines of glyph
    string S.  RELIEF is a pointer to a struct relief containing the GC
@@ -1665,7 +1654,7 @@ w32_setup_relief_color (struct frame *f, struct relief *relief, double factor,
 /* Set up colors for the relief lines around glyph string S.  */
 
 static void
-x_setup_relief_colors (struct glyph_string *s)
+w32_setup_relief_colors (struct glyph_string *s)
 {
   struct w32_output *di = s->f->output_data.w32;
   COLORREF color;
@@ -1799,7 +1788,7 @@ w32_draw_box_rect (struct glyph_string *s,
 /* Draw a box around glyph string S.  */
 
 static void
-x_draw_glyph_string_box (struct glyph_string *s)
+w32_draw_glyph_string_box (struct glyph_string *s)
 {
   int width, left_x, right_x, top_y, bottom_y, last_x;
   bool left_p, right_p, raised_p;
@@ -1840,7 +1829,7 @@ x_draw_glyph_string_box (struct glyph_string *s)
                        left_p, right_p, &clip_rect);
   else
     {
-      x_setup_relief_colors (s);
+      w32_setup_relief_colors (s);
       w32_draw_relief_rect (s->f, left_x, top_y, right_x, bottom_y,
                             width, raised_p, 1, 1, left_p, right_p, &clip_rect);
     }
@@ -1850,7 +1839,7 @@ x_draw_glyph_string_box (struct glyph_string *s)
 /* Draw foreground of image glyph string S.  */
 
 static void
-x_draw_image_foreground (struct glyph_string *s)
+w32_draw_image_foreground (struct glyph_string *s)
 {
   int x = s->x;
   int y = s->ybase - image_ascent (s->img, s->face, &s->slice);
@@ -1881,7 +1870,7 @@ x_draw_image_foreground (struct glyph_string *s)
       DIBSECTION dib;
       SetBkColor (compat_hdc, RGB (255, 255, 255));
       SetTextColor (s->hdc, RGB (0, 0, 0));
-      x_set_glyph_string_clipping (s);
+      w32_set_glyph_string_clipping (s);
       /* Extract the original dimensions of the bitmap.  */
       if (GetObject (s->img->pixmap, sizeof (dib), &dib) > 0)
 	{
@@ -1891,7 +1880,7 @@ x_draw_image_foreground (struct glyph_string *s)
 	}
       else
 	{
-	  DebPrint (("x_draw_image_foreground: GetObject failed!\n"));
+	  DebPrint (("w32_draw_image_foreground: GetObject failed!\n"));
 	  orig_width = s->slice.width;
 	  orig_height = s->slice.height;
 	}
@@ -2008,7 +1997,7 @@ x_draw_image_foreground (struct glyph_string *s)
 /* Draw a relief around the image glyph string S.  */
 
 static void
-x_draw_image_relief (struct glyph_string *s)
+w32_draw_image_relief (struct glyph_string *s)
 {
   int x1, y1, thick, raised_p, top_p, bot_p, left_p, right_p;
   int extra_x, extra_y;
@@ -2071,7 +2060,7 @@ x_draw_image_relief (struct glyph_string *s)
   if (s->slice.y + s->slice.height == s->img->height)
     y1 += thick + extra_y, bot_p = 1;
 
-  x_setup_relief_colors (s);
+  w32_setup_relief_colors (s);
   get_glyph_string_clip_rect (s, &r);
   w32_draw_relief_rect (s->f, x, y, x1, y1, thick, raised_p,
 			top_p, bot_p, left_p, right_p, &r);
@@ -2104,7 +2093,7 @@ w32_draw_image_foreground_1 (struct glyph_string *s, HBITMAP pixmap)
 
   /* FIXME (maybe): The below doesn't support image scaling.  But it
      seems to never be called, because the conditions for its call in
-     x_draw_image_glyph_string are never fulfilled (they will be if
+     w32_draw_image_glyph_string are never fulfilled (they will be if
      the #ifdef'ed away part of that function is ever activated).  */
   if (s->img->pixmap)
     {
@@ -2172,7 +2161,7 @@ w32_draw_image_foreground_1 (struct glyph_string *s, HBITMAP pixmap)
    give the rectangle to draw.  */
 
 static void
-x_draw_glyph_string_bg_rect (struct glyph_string *s, int x, int y, int w, int h)
+w32_draw_glyph_string_bg_rect (struct glyph_string *s, int x, int y, int w, int h)
 {
 #if 0 /* TODO: stipple */
   if (s->stippled_p)
@@ -2184,7 +2173,7 @@ x_draw_glyph_string_bg_rect (struct glyph_string *s, int x, int y, int w, int h)
     }
   else
 #endif
-    x_clear_glyph_string_rect (s, x, y, w, h);
+    w32_clear_glyph_string_rect (s, x, y, w, h);
 }
 
 
@@ -2203,7 +2192,7 @@ x_draw_glyph_string_bg_rect (struct glyph_string *s, int x, int y, int w, int h)
  */
 
 static void
-x_draw_image_glyph_string (struct glyph_string *s)
+w32_draw_image_glyph_string (struct glyph_string *s)
 {
   int x, y;
   int box_line_hwidth = eabs (s->face->box_line_width);
@@ -2281,7 +2270,7 @@ x_draw_image_glyph_string (struct glyph_string *s)
 	}
       else
 #endif
-	x_draw_glyph_string_bg_rect (s, x, y, width, height);
+	w32_draw_glyph_string_bg_rect (s, x, y, width, height);
 
       s->background_filled_p = true;
     }
@@ -2290,7 +2279,7 @@ x_draw_image_glyph_string (struct glyph_string *s)
   if (pixmap != 0)
     {
       w32_draw_image_foreground_1 (s, pixmap);
-      x_set_glyph_string_clipping (s);
+      w32_set_glyph_string_clipping (s);
       {
         HDC compat_hdc = CreateCompatibleDC (s->hdc);
         HBRUSH fg_brush = CreateSolidBrush (s->gc->foreground);
@@ -2311,20 +2300,20 @@ x_draw_image_glyph_string (struct glyph_string *s)
       pixmap = 0;
     }
   else
-    x_draw_image_foreground (s);
+    w32_draw_image_foreground (s);
 
   /* If we must draw a relief around the image, do it.  */
   if (s->img->relief
       || s->hl == DRAW_IMAGE_RAISED
       || s->hl == DRAW_IMAGE_SUNKEN)
-    x_draw_image_relief (s);
+    w32_draw_image_relief (s);
 }
 
 
 /* Draw stretch glyph string S.  */
 
 static void
-x_draw_stretch_glyph_string (struct glyph_string *s)
+w32_draw_stretch_glyph_string (struct glyph_string *s)
 {
   eassert (s->first_glyph->type == STRETCH_GLYPH);
 
@@ -2361,7 +2350,7 @@ x_draw_stretch_glyph_string (struct glyph_string *s)
 	x -= width;
 
       /* Draw cursor.  */
-      x_draw_glyph_string_bg_rect (s, x, s->y, width, s->height);
+      w32_draw_glyph_string_bg_rect (s, x, s->y, width, s->height);
 
       /* Clear rest using the GC of the original non-cursor face.  */
       if (width < background_width)
@@ -2379,7 +2368,7 @@ x_draw_stretch_glyph_string (struct glyph_string *s)
 	  if (s->row->mouse_face_p
 	      && cursor_in_mouse_face_p (s->w))
 	    {
-	      x_set_mouse_face_gc (s);
+	      w32_set_mouse_face_gc (s);
 	      gc = s->gc;
 	    }
 	  else
@@ -2416,7 +2405,7 @@ x_draw_stretch_glyph_string (struct glyph_string *s)
 	  x = left_x;
 	}
       if (background_width > 0)
-	x_draw_glyph_string_bg_rect (s, x, s->y, background_width, s->height);
+	w32_draw_glyph_string_bg_rect (s, x, s->y, background_width, s->height);
     }
 
   s->background_filled_p = true;
@@ -2426,7 +2415,7 @@ x_draw_stretch_glyph_string (struct glyph_string *s)
 /* Draw glyph string S.  */
 
 static void
-x_draw_glyph_string (struct glyph_string *s)
+w32_draw_glyph_string (struct glyph_string *s)
 {
   bool relief_drawn_p = 0;
 
@@ -2442,18 +2431,18 @@ x_draw_glyph_string (struct glyph_string *s)
            width += next->width, next = next->next)
         if (next->first_glyph->type != IMAGE_GLYPH)
           {
-            x_set_glyph_string_gc (next);
-            x_set_glyph_string_clipping (next);
+            w32_set_glyph_string_gc (next);
+            w32_set_glyph_string_clipping (next);
 	    if (next->first_glyph->type == STRETCH_GLYPH)
-	      x_draw_stretch_glyph_string (next);
+	      w32_draw_stretch_glyph_string (next);
 	    else
-	      x_draw_glyph_string_background (next, true);
+	      w32_draw_glyph_string_background (next, true);
             next->num_clips = 0;
           }
     }
 
   /* Set up S->gc, set clipping and draw S.  */
-  x_set_glyph_string_gc (s);
+  w32_set_glyph_string_gc (s);
 
   /* Draw relief (if any) in advance for char/composition so that the
      glyph string can be drawn over it.  */
@@ -2463,10 +2452,10 @@ x_draw_glyph_string (struct glyph_string *s)
 	  || s->first_glyph->type == COMPOSITE_GLYPH))
 
     {
-      x_set_glyph_string_clipping (s);
-      x_draw_glyph_string_background (s, true);
-      x_draw_glyph_string_box (s);
-      x_set_glyph_string_clipping (s);
+      w32_set_glyph_string_clipping (s);
+      w32_draw_glyph_string_background (s, true);
+      w32_draw_glyph_string_box (s);
+      w32_set_glyph_string_clipping (s);
       relief_drawn_p = 1;
     }
   else if (!s->clip_head /* draw_glyphs didn't specify a clip mask.  */
@@ -2476,26 +2465,26 @@ x_draw_glyph_string (struct glyph_string *s)
     /* We must clip just this glyph.  left_overhang part has already
        drawn when s->prev was drawn, and right_overhang part will be
        drawn later when s->next is drawn. */
-    x_set_glyph_string_clipping_exactly (s, s);
+    w32_set_glyph_string_clipping_exactly (s, s);
   else
-    x_set_glyph_string_clipping (s);
+    w32_set_glyph_string_clipping (s);
 
   switch (s->first_glyph->type)
     {
     case IMAGE_GLYPH:
-      x_draw_image_glyph_string (s);
+      w32_draw_image_glyph_string (s);
       break;
 
     case STRETCH_GLYPH:
-      x_draw_stretch_glyph_string (s);
+      w32_draw_stretch_glyph_string (s);
       break;
 
     case CHAR_GLYPH:
       if (s->for_overlaps)
 	s->background_filled_p = true;
       else
-        x_draw_glyph_string_background (s, false);
-      x_draw_glyph_string_foreground (s);
+        w32_draw_glyph_string_background (s, false);
+      w32_draw_glyph_string_foreground (s);
       break;
 
     case COMPOSITE_GLYPH:
@@ -2503,16 +2492,16 @@ x_draw_glyph_string (struct glyph_string *s)
 			      && ! s->first_glyph->u.cmp.automatic))
 	s->background_filled_p = true;
       else
-	x_draw_glyph_string_background (s, true);
-      x_draw_composite_glyph_string_foreground (s);
+	w32_draw_glyph_string_background (s, true);
+      w32_draw_composite_glyph_string_foreground (s);
       break;
 
     case GLYPHLESS_GLYPH:
       if (s->for_overlaps)
 	s->background_filled_p = true;
       else
-	x_draw_glyph_string_background (s, false);
-      x_draw_glyphless_glyph_string_foreground (s);
+	w32_draw_glyph_string_background (s, false);
+      w32_draw_glyphless_glyph_string_foreground (s);
       break;
 
     default:
@@ -2665,7 +2654,7 @@ x_draw_glyph_string (struct glyph_string *s)
 
       /* Draw relief if not yet drawn.  */
       if (!relief_drawn_p && s->face->box != FACE_NO_BOX)
-        x_draw_glyph_string_box (s);
+        w32_draw_glyph_string_box (s);
 
       if (s->prev)
         {
@@ -2680,12 +2669,12 @@ x_draw_glyph_string (struct glyph_string *s)
 		enum draw_glyphs_face save = prev->hl;
 
 		prev->hl = s->hl;
-		x_set_glyph_string_gc (prev);
-		x_set_glyph_string_clipping_exactly (s, prev);
+		w32_set_glyph_string_gc (prev);
+		w32_set_glyph_string_clipping_exactly (s, prev);
 		if (prev->first_glyph->type == CHAR_GLYPH)
-		  x_draw_glyph_string_foreground (prev);
+		  w32_draw_glyph_string_foreground (prev);
 		else
-		  x_draw_composite_glyph_string_foreground (prev);
+		  w32_draw_composite_glyph_string_foreground (prev);
                 w32_set_clip_rectangle (prev->hdc, NULL);
 		prev->hl = save;
 		prev->num_clips = 0;
@@ -2705,12 +2694,12 @@ x_draw_glyph_string (struct glyph_string *s)
 		enum draw_glyphs_face save = next->hl;
 
 		next->hl = s->hl;
-		x_set_glyph_string_gc (next);
-		x_set_glyph_string_clipping_exactly (s, next);
+		w32_set_glyph_string_gc (next);
+		w32_set_glyph_string_clipping_exactly (s, next);
 		if (next->first_glyph->type == CHAR_GLYPH)
-		  x_draw_glyph_string_foreground (next);
+		  w32_draw_glyph_string_foreground (next);
 		else
-		  x_draw_composite_glyph_string_foreground (next);
+		  w32_draw_composite_glyph_string_foreground (next);
                 w32_set_clip_rectangle (next->hdc, NULL);
 		next->hl = save;
 		next->num_clips = 0;
@@ -2745,7 +2734,7 @@ w32_shift_glyphs_for_insert (struct frame *f, int x, int y,
    for X frames.  */
 
 static void
-x_delete_glyphs (struct frame *f, register int n)
+w32_delete_glyphs (struct frame *f, register int n)
 {
   if (! FRAME_W32_P (f))
     return;
@@ -2757,7 +2746,7 @@ x_delete_glyphs (struct frame *f, register int n)
 /* Clear entire frame.  */
 
 static void
-x_clear_frame (struct frame *f)
+w32_clear_frame (struct frame *f)
 {
   if (! FRAME_W32_P (f))
     return;
@@ -2772,7 +2761,7 @@ x_clear_frame (struct frame *f)
 
   /* We have to clear the scroll bars, too.  If we have changed
      colors or something like that, then they should be notified.  */
-  x_scroll_bar_clear (f);
+  w32_scroll_bar_clear (f);
 
   unblock_input ();
 }
@@ -2811,7 +2800,7 @@ w32_ring_bell (struct frame *f)
    lines or deleting -N lines at vertical position VPOS.  */
 
 static void
-x_ins_del_lines (struct frame *f, int vpos, int n)
+w32_ins_del_lines (struct frame *f, int vpos, int n)
 {
   if (! FRAME_W32_P (f))
     return;
@@ -2823,7 +2812,7 @@ x_ins_del_lines (struct frame *f, int vpos, int n)
 /* Scroll part of the display as described by RUN.  */
 
 static void
-x_scroll_run (struct window *w, struct run *run)
+w32_scroll_run (struct window *w, struct run *run)
 {
   struct frame *f = XFRAME (w->frame);
   int x, y, width, height, from_y, to_y, bottom_y;
@@ -2862,7 +2851,7 @@ x_scroll_run (struct window *w, struct run *run)
 
   block_input ();
 
-  /* Cursor off.  Will be switched on again in x_update_window_end.  */
+  /* Cursor off.  Will be switched on again in w32_update_window_end.  */
   gui_clear_cursor (w);
 
   {
@@ -2907,14 +2896,14 @@ static void
 w32_frame_highlight (struct frame *f)
 {
   gui_update_cursor (f, 1);
-  x_set_frame_alpha (f);
+  w32_set_frame_alpha (f);
 }
 
 static void
 w32_frame_unhighlight (struct frame *f)
 {
   gui_update_cursor (f, 1);
-  x_set_frame_alpha (f);
+  w32_set_frame_alpha (f);
 }
 
 /* The focus has changed.  Update the frames as necessary to reflect
@@ -2924,7 +2913,7 @@ w32_frame_unhighlight (struct frame *f)
    Lisp code can tell when the switch took place by examining the events.  */
 
 static void
-x_new_focus_frame (struct w32_display_info *dpyinfo, struct frame *frame)
+w32_new_focus_frame (struct w32_display_info *dpyinfo, struct frame *frame)
 {
   struct frame *old_focus = dpyinfo->w32_focus_frame;
 
@@ -2935,7 +2924,7 @@ x_new_focus_frame (struct w32_display_info *dpyinfo, struct frame *frame)
       dpyinfo->w32_focus_frame = frame;
 
       if (old_focus && old_focus->auto_lower)
-	x_lower_frame (old_focus);
+	w32_lower_frame (old_focus);
 
       if (dpyinfo->w32_focus_frame && dpyinfo->w32_focus_frame->auto_raise)
 	dpyinfo->w32_pending_autoraise_frame = dpyinfo->w32_focus_frame;
@@ -2943,7 +2932,7 @@ x_new_focus_frame (struct w32_display_info *dpyinfo, struct frame *frame)
 	dpyinfo->w32_pending_autoraise_frame = NULL;
     }
 
-  x_frame_rehighlight (dpyinfo);
+  w32_reframe_highlight_1 (dpyinfo);
 }
 
 
@@ -2952,14 +2941,14 @@ x_new_focus_frame (struct w32_display_info *dpyinfo, struct frame *frame)
    a FOCUS_IN_EVENT into *BUFP.  */
 
 static void
-x_focus_changed (int type, int state, struct w32_display_info *dpyinfo,
+w32_focus_changed (int type, int state, struct w32_display_info *dpyinfo,
 		 struct frame *frame, struct input_event *bufp)
 {
   if (type == WM_SETFOCUS)
     {
       if (dpyinfo->w32_focus_event_frame != frame)
         {
-          x_new_focus_frame (dpyinfo, frame);
+          w32_new_focus_frame (dpyinfo, frame);
           dpyinfo->w32_focus_event_frame = frame;
           bufp->kind = FOCUS_IN_EVENT;
           XSETFRAME (bufp->frame_or_window, frame);
@@ -2976,7 +2965,7 @@ x_focus_changed (int type, int state, struct w32_display_info *dpyinfo,
       if (dpyinfo->w32_focus_event_frame == frame)
         {
           dpyinfo->w32_focus_event_frame = 0;
-          x_new_focus_frame (dpyinfo, 0);
+          w32_new_focus_frame (dpyinfo, 0);
 
           bufp->kind = FOCUS_OUT_EVENT;
           XSETFRAME (bufp->frame_or_window, frame);
@@ -2998,15 +2987,15 @@ w32_detect_focus_change (struct w32_display_info *dpyinfo, W32Msg *event,
 {
   struct frame *frame;
 
-  frame = x_any_window_to_frame (dpyinfo, event->msg.hwnd);
+  frame = w32_window_to_frame (dpyinfo, event->msg.hwnd);
   if (! frame)
     return;
 
   /* On w32, this is only called from focus events, so no switch needed.  */
-  x_focus_changed (event->msg.message,
-		   (event->msg.message == WM_KILLFOCUS ?
-		    FOCUS_IMPLICIT : FOCUS_EXPLICIT),
-		   dpyinfo, frame, bufp);
+  w32_focus_changed (event->msg.message,
+                     (event->msg.message == WM_KILLFOCUS ?
+                      FOCUS_IMPLICIT : FOCUS_EXPLICIT),
+                     dpyinfo, frame, bufp);
 }
 
 
@@ -3014,9 +3003,9 @@ w32_detect_focus_change (struct w32_display_info *dpyinfo, W32Msg *event,
 /* Handle an event saying the mouse has moved out of an Emacs frame.  */
 
 static void
-x_mouse_leave (struct w32_display_info *dpyinfo)
+w32_mouse_leave (struct w32_display_info *dpyinfo)
 {
-  x_new_focus_frame (dpyinfo, dpyinfo->w32_focus_event_frame);
+  w32_new_focus_frame (dpyinfo, dpyinfo->w32_focus_event_frame);
 }
 #endif
 
@@ -3033,11 +3022,11 @@ w32_frame_rehighlight (struct frame *frame)
 {
   if (! FRAME_W32_P (frame))
     return;
-  x_frame_rehighlight (FRAME_DISPLAY_INFO (frame));
+  w32_reframe_highlight_1 (FRAME_DISPLAY_INFO (frame));
 }
 
 static void
-x_frame_rehighlight (struct w32_display_info *dpyinfo)
+w32_reframe_highlight_1 (struct w32_display_info *dpyinfo)
 {
   struct frame *old_highlight = dpyinfo->x_highlight_frame;
 
@@ -3070,7 +3059,7 @@ x_frame_rehighlight (struct w32_display_info *dpyinfo)
 /* Convert a keysym to its name.  */
 
 char *
-x_get_keysym_name (int keysym)
+get_keysym_name (int keysym)
 {
   /* Make static so we can always return it */
   static char value[100];
@@ -3499,15 +3488,15 @@ w32_note_mouse_movement (struct frame *frame, MSG *msg)
 			      Mouse Face
  ************************************************************************/
 
-static struct scroll_bar *x_window_to_scroll_bar (Window, int);
-static void x_scroll_bar_report_motion (struct frame **, Lisp_Object *,
-					enum scroll_bar_part *,
-					Lisp_Object *, Lisp_Object *,
-					Time *);
-static void x_horizontal_scroll_bar_report_motion (struct frame **, Lisp_Object *,
-						   enum scroll_bar_part *,
-						   Lisp_Object *, Lisp_Object *,
-						   Time *);
+static struct scroll_bar *w32_window_to_scroll_bar (Window, int);
+static void w32_scroll_bar_report_motion (struct frame **, Lisp_Object *,
+                                          enum scroll_bar_part *,
+                                          Lisp_Object *, Lisp_Object *,
+                                          Time *);
+static void w32_horizontal_scroll_bar_report_motion (struct frame **, Lisp_Object *,
+                                                     enum scroll_bar_part *,
+                                                     Lisp_Object *, Lisp_Object *,
+                                                     Time *);
 static void
 w32_define_cursor (Window window, Cursor cursor)
 {
@@ -3548,9 +3537,9 @@ w32_mouse_position (struct frame **fp, int insist, Lisp_Object *bar_window,
       struct scroll_bar *bar = dpyinfo->last_mouse_scroll_bar;
 
       if (bar->horizontal)
-	x_horizontal_scroll_bar_report_motion (fp, bar_window, part, x, y, time);
+	w32_horizontal_scroll_bar_report_motion (fp, bar_window, part, x, y, time);
       else
-	x_scroll_bar_report_motion (fp, bar_window, part, x, y, time);
+	w32_scroll_bar_report_motion (fp, bar_window, part, x, y, time);
     }
   else
     {
@@ -3572,7 +3561,7 @@ w32_mouse_position (struct frame **fp, int insist, Lisp_Object *bar_window,
 	/* If mouse was grabbed on a frame, give coords for that
 	   frame even if the mouse is now outside it.  Otherwise
 	   check for window under mouse on one of our frames.  */
-	if (x_mouse_grabbed (dpyinfo))
+	if (gui_mouse_grabbed (dpyinfo))
 	  f1 = dpyinfo->last_mouse_frame;
 	else
 	  {
@@ -3580,14 +3569,14 @@ w32_mouse_position (struct frame **fp, int insist, Lisp_Object *bar_window,
 
 	    if (wfp)
 	      {
-		f1 = x_any_window_to_frame (dpyinfo, wfp);
+		f1 = w32_window_to_frame (dpyinfo, wfp);
 		if (f1)
 		  {
 		    HWND cwfp = ChildWindowFromPoint (wfp, pt);
 
 		    if (cwfp)
 		      {
-			struct frame *f2 = x_any_window_to_frame (dpyinfo, cwfp);
+			struct frame *f2 = w32_window_to_frame (dpyinfo, cwfp);
 
 			/* If a child window was found, make sure that its
 			   frame is a child frame (Bug#26615, maybe).  */
@@ -3602,7 +3591,7 @@ w32_mouse_position (struct frame **fp, int insist, Lisp_Object *bar_window,
 	if (! f1)
 	  {
 	    struct scroll_bar *bar
-              = x_window_to_scroll_bar (WindowFromPoint (pt), 2);
+              = w32_window_to_scroll_bar (WindowFromPoint (pt), 2);
 
 	    if (bar)
 	      f1 = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
@@ -3674,7 +3663,7 @@ w32_handle_tool_bar_click (struct frame *f, struct input_event *button_event)
    strip off mark bits.  */
 
 static struct scroll_bar *
-x_window_to_scroll_bar (Window window_id, int type)
+w32_window_to_scroll_bar (Window window_id, int type)
 {
   Lisp_Object tail, frame;
 
@@ -3893,7 +3882,8 @@ my_bring_window_to_top (HWND hwnd)
    scroll bar. */
 
 static struct scroll_bar *
-x_scroll_bar_create (struct window *w, int left, int top, int width, int height, bool horizontal)
+w32_scroll_bar_create (struct window *w, int left, int top,
+                       int width, int height, bool horizontal)
 {
   struct frame *f = XFRAME (WINDOW_FRAME (w));
   HWND hwnd;
@@ -3955,7 +3945,7 @@ x_scroll_bar_create (struct window *w, int left, int top, int width, int height,
    nil. */
 
 static void
-x_scroll_bar_remove (struct scroll_bar *bar)
+w32_scroll_bar_remove (struct scroll_bar *bar)
 {
   struct frame *f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
 
@@ -4009,7 +3999,7 @@ w32_set_vertical_scroll_bar (struct window *w,
 	}
       unblock_input ();
 
-      bar = x_scroll_bar_create (w, left, top, width, height, false);
+      bar = w32_scroll_bar_create (w, left, top, width, height, false);
     }
   else
     {
@@ -4042,7 +4032,7 @@ w32_set_vertical_scroll_bar (struct window *w,
 		 for them on the frame, we have to clear "under" them.  */
 	      w32_clear_area (f, hdc, left, top, width, height);
 	      release_frame_dc (f, hdc);
-	      x_clear_under_internal_border (f);
+	      w32_clear_under_internal_border (f);
 	    }
           /* Make sure scroll bar is "visible" before moving, to ensure the
              area of the parent window now exposed will be refreshed.  */
@@ -4113,7 +4103,7 @@ w32_set_horizontal_scroll_bar (struct window *w,
 	}
       unblock_input ();
 
-      bar = x_scroll_bar_create (w, left, top, width, height, true);
+      bar = w32_scroll_bar_create (w, left, top, width, height, true);
     }
   else
     {
@@ -4144,7 +4134,7 @@ w32_set_horizontal_scroll_bar (struct window *w,
 		 for them on the frame, we have to clear "under" them.  */
 	      w32_clear_area (f, hdc, clear_left, top, clear_width, height);
 	      release_frame_dc (f, hdc);
-	      x_clear_under_internal_border (f);
+	      w32_clear_under_internal_border (f);
 	    }
           /* Make sure scroll bar is "visible" before moving, to ensure the
              area of the parent window now exposed will be refreshed.  */
@@ -4319,7 +4309,7 @@ w32_judge_scroll_bars (struct frame *f)
     {
       struct scroll_bar *b = XSCROLL_BAR (bar);
 
-      x_scroll_bar_remove (b);
+      w32_scroll_bar_remove (b);
 
       next = b->next;
       b->next = b->prev = Qnil;
@@ -4563,7 +4553,7 @@ w32_horizontal_scroll_bar_handle_click (struct scroll_bar *bar, W32Msg *msg,
 /* Return information to the user about the current position of the mouse
    on the vertical scroll bar.  */
 static void
-x_scroll_bar_report_motion (struct frame **fp, Lisp_Object *bar_window,
+w32_scroll_bar_report_motion (struct frame **fp, Lisp_Object *bar_window,
 			    enum scroll_bar_part *part,
 			    Lisp_Object *x, Lisp_Object *y,
 			    Time *time)
@@ -4613,10 +4603,10 @@ x_scroll_bar_report_motion (struct frame **fp, Lisp_Object *bar_window,
 /* Return information to the user about the current position of the mouse
    on the horizontal scroll bar.  */
 static void
-x_horizontal_scroll_bar_report_motion (struct frame **fp, Lisp_Object *bar_window,
-				       enum scroll_bar_part *part,
-				       Lisp_Object *x, Lisp_Object *y,
-				       Time *time)
+w32_horizontal_scroll_bar_report_motion (struct frame **fp, Lisp_Object *bar_window,
+                                         enum scroll_bar_part *part,
+                                         Lisp_Object *x, Lisp_Object *y,
+                                         Time *time)
 {
   struct w32_display_info *dpyinfo = FRAME_DISPLAY_INFO (*fp);
   struct scroll_bar *bar = dpyinfo->last_mouse_scroll_bar;
@@ -4667,8 +4657,8 @@ x_horizontal_scroll_bar_report_motion (struct frame **fp, Lisp_Object *bar_windo
    Clear out the scroll bars, and ask for expose events, so we can
    redraw them.  */
 
-void
-x_scroll_bar_clear (struct frame *f)
+static void
+w32_scroll_bar_clear (struct frame *f)
 {
   Lisp_Object bar;
 
@@ -4691,7 +4681,7 @@ x_scroll_bar_clear (struct frame *f)
         GetClientRect (window, &rect);
         select_palette (f, hdc);
         w32_clear_rect (f, hdc, &rect);
-	x_clear_under_internal_border (f);
+	w32_clear_under_internal_border (f);
         deselect_palette (f, hdc);
 
         ReleaseDC (window, hdc);
@@ -4763,7 +4753,7 @@ w32_read_socket (struct terminal *terminal,
       switch (msg.msg.message)
 	{
 	case WM_EMACS_PAINT:
-	  f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
+	  f = w32_window_to_frame (dpyinfo, msg.msg.hwnd);
 
 	  if (f)
 	    {
@@ -4818,14 +4808,14 @@ w32_read_socket (struct terminal *terminal,
 				msg.rect.top,
 				msg.rect.right - msg.rect.left,
 				msg.rect.bottom - msg.rect.top);
-		  x_clear_under_internal_border (f);
+		  w32_clear_under_internal_border (f);
 		}
 	    }
 	  break;
 
 	case WM_INPUTLANGCHANGE:
 	  /* Generate a language change event.  */
-	  f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
+	  f = w32_window_to_frame (dpyinfo, msg.msg.hwnd);
 
 	  /* lParam contains the input language ID in its low 16 bits.
 	     Use it to update our record of the keyboard codepage.  */
@@ -4843,7 +4833,7 @@ w32_read_socket (struct terminal *terminal,
 
 	case WM_KEYDOWN:
 	case WM_SYSKEYDOWN:
-	  f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
+	  f = w32_window_to_frame (dpyinfo, msg.msg.hwnd);
 
 	  if (f && !FRAME_ICONIFIED_P (f))
 	    {
@@ -4868,7 +4858,7 @@ w32_read_socket (struct terminal *terminal,
         case WM_UNICHAR:
 	case WM_SYSCHAR:
 	case WM_CHAR:
-	  f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
+	  f = w32_window_to_frame (dpyinfo, msg.msg.hwnd);
 
 	  if (f && !FRAME_ICONIFIED_P (f))
 	    {
@@ -4946,7 +4936,7 @@ w32_read_socket (struct terminal *terminal,
 	  break;
 
         case WM_APPCOMMAND:
-	  f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
+	  f = w32_window_to_frame (dpyinfo, msg.msg.hwnd);
 
 	  if (f && !FRAME_ICONIFIED_P (f))
 	    {
@@ -4982,8 +4972,8 @@ w32_read_socket (struct terminal *terminal,
           previous_help_echo_string = help_echo_string;
 	  help_echo_string = Qnil;
 
-	  f = (x_mouse_grabbed (dpyinfo) ? dpyinfo->last_mouse_frame
-	       : x_window_to_frame (dpyinfo, msg.msg.hwnd));
+	  f = (gui_mouse_grabbed (dpyinfo) ? dpyinfo->last_mouse_frame
+	       : w32_window_to_frame (dpyinfo, msg.msg.hwnd));
 
 	  if (hlinfo->mouse_face_hidden)
 	    {
@@ -5062,8 +5052,8 @@ w32_read_socket (struct terminal *terminal,
 	    int button = 0;
 	    int up = 0;
 
-	    f = (x_mouse_grabbed (dpyinfo) ? dpyinfo->last_mouse_frame
-		 : x_window_to_frame (dpyinfo, msg.msg.hwnd));
+	    f = (gui_mouse_grabbed (dpyinfo) ? dpyinfo->last_mouse_frame
+		 : w32_window_to_frame (dpyinfo, msg.msg.hwnd));
 
 	    if (f)
 	      {
@@ -5123,8 +5113,8 @@ w32_read_socket (struct terminal *terminal,
 	case WM_MOUSEWHEEL:
         case WM_MOUSEHWHEEL:
 	  {
-	    f = (x_mouse_grabbed (dpyinfo) ? dpyinfo->last_mouse_frame
-		 : x_window_to_frame (dpyinfo, msg.msg.hwnd));
+	    f = (gui_mouse_grabbed (dpyinfo) ? dpyinfo->last_mouse_frame
+		 : w32_window_to_frame (dpyinfo, msg.msg.hwnd));
 
 	    if (f)
 	      {
@@ -5142,7 +5132,7 @@ w32_read_socket (struct terminal *terminal,
 		    dpyinfo->last_mouse_frame = f;
 		  }
 		else if (FRAME_NO_ACCEPT_FOCUS (f)
-			 && !x_mouse_grabbed (dpyinfo))
+			 && !gui_mouse_grabbed (dpyinfo))
 		  {
 		    Lisp_Object frame1 = get_frame_param (f, Qmouse_wheel_frame);
 		    struct frame *f1 = FRAMEP (frame1) ? XFRAME (frame1) : NULL;
@@ -5166,7 +5156,7 @@ w32_read_socket (struct terminal *terminal,
 	  break;
 
 	case WM_DROPFILES:
-	  f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
+	  f = w32_window_to_frame (dpyinfo, msg.msg.hwnd);
 
 	  if (f)
 	    w32_construct_drag_n_drop (&inev, &msg, f);
@@ -5175,7 +5165,7 @@ w32_read_socket (struct terminal *terminal,
 	case WM_HSCROLL:
 	  {
 	    struct scroll_bar *bar =
-	      x_window_to_scroll_bar ((HWND)msg.msg.lParam, 1);
+	      w32_window_to_scroll_bar ((HWND)msg.msg.lParam, 1);
 
 	    if (bar)
 	      w32_horizontal_scroll_bar_handle_click (bar, &msg, &inev);
@@ -5185,7 +5175,7 @@ w32_read_socket (struct terminal *terminal,
 	case WM_VSCROLL:
 	  {
 	    struct scroll_bar *bar =
-	      x_window_to_scroll_bar ((HWND)msg.msg.lParam, 0);
+	      w32_window_to_scroll_bar ((HWND)msg.msg.lParam, 0);
 
 	    if (bar)
 	      w32_scroll_bar_handle_click (bar, &msg, &inev);
@@ -5193,7 +5183,7 @@ w32_read_socket (struct terminal *terminal,
 	  }
 
 	case WM_WINDOWPOSCHANGED:
-	  f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
+	  f = w32_window_to_frame (dpyinfo, msg.msg.hwnd);
 
 	  if (f)
 	    {
@@ -5240,13 +5230,13 @@ w32_read_socket (struct terminal *terminal,
 
 	case WM_ACTIVATE:
 	case WM_ACTIVATEAPP:
-	  f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
+	  f = w32_window_to_frame (dpyinfo, msg.msg.hwnd);
 	  if (f)
 	    {
 	      /* Run the full-screen hook function also when we are
 		 being activated, to actually install the required
 		 size in effect, if the WAIT flag is set.  This is
-		 because when the hook is run from x_set_fullscreen,
+		 because when the hook is run from gui_set_fullscreen,
 		 the frame might not yet be visible, if that call is a
 		 result of make-frame, and in that case the hook just
 		 sets the WAIT flag.  */
@@ -5264,11 +5254,11 @@ w32_read_socket (struct terminal *terminal,
 	  break;
 
 	case WM_MOVE:
-	  f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
+	  f = w32_window_to_frame (dpyinfo, msg.msg.hwnd);
 
 	  if (f && FRAME_VISIBLE_P (f) && !FRAME_ICONIFIED_P(f))
 	    {
-	      x_real_positions (f, &f->left_pos, &f->top_pos);
+	      w32_real_positions (f, &f->left_pos, &f->top_pos);
 	      inev.kind = MOVE_FRAME_EVENT;
 	      XSETFRAME (inev.frame_or_window, f);
 	    }
@@ -5283,7 +5273,7 @@ w32_read_socket (struct terminal *terminal,
 	  if (!msg.msg.wParam && msg.msg.hwnd == tip_window)
 	    {
 	      tip_window = NULL;
-	      x_redo_mouse_highlight (dpyinfo);
+	      gui_redo_mouse_highlight (dpyinfo);
 	    }
 
 	  /* If window has been obscured or exposed by another window
@@ -5295,20 +5285,20 @@ w32_read_socket (struct terminal *terminal,
 	    check_visibility = 1;
 	  else
 	    {
-	      f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
+	      f = w32_window_to_frame (dpyinfo, msg.msg.hwnd);
 	      f->async_visible = msg.msg.wParam;
 	    }
 #endif
 
-	  f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
+	  f = w32_window_to_frame (dpyinfo, msg.msg.hwnd);
 	  if (f)
-	    x_clear_under_internal_border (f);
+	    w32_clear_under_internal_border (f);
 
 	  check_visibility = 1;
 	  break;
 
 	case WM_SIZE:
-	  f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
+	  f = w32_window_to_frame (dpyinfo, msg.msg.hwnd);
 
 	  /* Inform lisp of whether frame has been iconified etc. */
 	  if (f)
@@ -5344,7 +5334,7 @@ w32_read_socket (struct terminal *terminal,
 			   BEFORE telling us the Window is minimized
 			   when the Window is iconified, with 3000,3000
 			   as the co-ords. */
-			x_real_positions (f, &x, &y);
+			w32_real_positions (f, &x, &y);
 			f->left_pos = x;
 			f->top_pos = y;
 
@@ -5368,7 +5358,7 @@ w32_read_socket (struct terminal *terminal,
 		      {
 			int x, y;
 
-			x_real_positions (f, &x, &y);
+			w32_real_positions (f, &x, &y);
 			if (x < 0 && y < 0)
 			  store_frame_param (f, Qfullscreen, Qmaximized);
 		      }
@@ -5399,7 +5389,7 @@ w32_read_socket (struct terminal *terminal,
 			   BEFORE telling us the Window is minimized
 			   when the Window is iconified, with 3000,3000
 			   as the co-ords.  */
-			x_real_positions (f, &f->left_pos, &f->top_pos);
+			w32_real_positions (f, &f->left_pos, &f->top_pos);
 
 			inev.kind = DEICONIFY_EVENT;
 			XSETFRAME (inev.frame_or_window, f);
@@ -5463,7 +5453,7 @@ w32_read_socket (struct terminal *terminal,
 	  break;
 
 	case WM_MOUSELEAVE:
-	  f = x_any_window_to_frame (dpyinfo, msg.msg.hwnd);
+	  f = w32_window_to_frame (dpyinfo, msg.msg.hwnd);
 	  if (f)
 	    {
 	      if (f == hlinfo->mouse_face_mouse_frame)
@@ -5492,7 +5482,7 @@ w32_read_socket (struct terminal *terminal,
 
 	case WM_KILLFOCUS:
 	  w32_detect_focus_change (dpyinfo, &msg, &inev);
-	  f = x_top_window_to_frame (dpyinfo, msg.msg.hwnd);
+	  f = w32_window_to_frame (dpyinfo, msg.msg.hwnd);
 
           if (f)
             {
@@ -5517,7 +5507,7 @@ w32_read_socket (struct terminal *terminal,
 	  break;
 
 	case WM_CLOSE:
-	  f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
+	  f = w32_window_to_frame (dpyinfo, msg.msg.hwnd);
 
 	  if (f)
 	    {
@@ -5531,7 +5521,7 @@ w32_read_socket (struct terminal *terminal,
 	  break;
 
 	case WM_INITMENU:
-	  f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
+	  f = w32_window_to_frame (dpyinfo, msg.msg.hwnd);
 
 	  if (f)
 	    {
@@ -5541,7 +5531,7 @@ w32_read_socket (struct terminal *terminal,
 	  break;
 
 	case WM_COMMAND:
-	  f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
+	  f = w32_window_to_frame (dpyinfo, msg.msg.hwnd);
 
 	  if (f)
 	    {
@@ -5552,7 +5542,7 @@ w32_read_socket (struct terminal *terminal,
 	  break;
 
 	case WM_DISPLAYCHANGE:
-	  f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
+	  f = w32_window_to_frame (dpyinfo, msg.msg.hwnd);
 
 	  if (f)
 	    {
@@ -5564,7 +5554,7 @@ w32_read_socket (struct terminal *terminal,
 		 The following code is untested yet.  */
 	      if (!NILP (fullscreen))
 		{
-		  x_set_fullscreen (f, fullscreen, fullscreen);
+		  gui_set_fullscreen (f, fullscreen, fullscreen);
 		  w32fullscreen_hook (f);
 		}
 
@@ -5578,7 +5568,7 @@ w32_read_socket (struct terminal *terminal,
 
 #if HAVE_W32NOTIFY
 	case WM_EMACS_FILENOTIFY:
-	  f = x_window_to_frame (dpyinfo, msg.msg.hwnd);
+	  f = w32_window_to_frame (dpyinfo, msg.msg.hwnd);
 	  if (f)
 	    w32_queue_notifications (&inev, &msg, f, &count);
 	  break;
@@ -5636,7 +5626,7 @@ w32_read_socket (struct terminal *terminal,
      raise it now.  FIXME: handle more than one such frame.  */
   if (dpyinfo->w32_pending_autoraise_frame)
     {
-      x_raise_frame (dpyinfo->w32_pending_autoraise_frame);
+      w32_raise_frame (dpyinfo->w32_pending_autoraise_frame);
       dpyinfo->w32_pending_autoraise_frame = NULL;
     }
 
@@ -5748,7 +5738,7 @@ w32_clip_to_row (struct window *w, struct glyph_row *row,
 /* Draw a hollow box cursor on window W in glyph row ROW.  */
 
 static void
-x_draw_hollow_cursor (struct window *w, struct glyph_row *row)
+w32_draw_hollow_cursor (struct window *w, struct glyph_row *row)
 {
   struct frame *f = XFRAME (WINDOW_FRAME (w));
   HDC hdc;
@@ -5797,7 +5787,7 @@ x_draw_hollow_cursor (struct window *w, struct glyph_row *row)
    --gerd.  */
 
 static void
-x_draw_bar_cursor (struct window *w, struct glyph_row *row,
+w32_draw_bar_cursor (struct window *w, struct glyph_row *row,
 		   int width, enum text_cursor_kinds kind)
 {
   struct frame *f = XFRAME (w->frame);
@@ -5976,7 +5966,7 @@ w32_draw_window_cursor (struct window *w, struct glyph_row *glyph_row,
       switch (cursor_type)
 	{
 	case HOLLOW_BOX_CURSOR:
-	  x_draw_hollow_cursor (w, glyph_row);
+	  w32_draw_hollow_cursor (w, glyph_row);
 	  break;
 
 	case FILLED_BOX_CURSOR:
@@ -5984,11 +5974,11 @@ w32_draw_window_cursor (struct window *w, struct glyph_row *glyph_row,
 	  break;
 
 	case BAR_CURSOR:
-	  x_draw_bar_cursor (w, glyph_row, cursor_width, BAR_CURSOR);
+	  w32_draw_bar_cursor (w, glyph_row, cursor_width, BAR_CURSOR);
 	  break;
 
 	case HBAR_CURSOR:
-	  x_draw_bar_cursor (w, glyph_row, cursor_width, HBAR_CURSOR);
+	  w32_draw_bar_cursor (w, glyph_row, cursor_width, HBAR_CURSOR);
 	  break;
 
 	case NO_CURSOR:
@@ -6093,8 +6083,8 @@ x_io_error_quitter (display)
 \f
 /* Changing the font of the frame.  */
 
-Lisp_Object
-x_new_font (struct frame *f, Lisp_Object font_object, int fontset)
+static Lisp_Object
+w32_new_font (struct frame *f, Lisp_Object font_object, int fontset)
 {
   struct font *font = XFONT_OBJECT (font_object);
   int unit, font_ascent, font_descent;
@@ -6162,7 +6152,7 @@ xim_close_dpy (dpyinfo)
    from its current recorded position values and gravity.  */
 
 static void
-x_calc_absolute_position (struct frame *f)
+w32_calc_absolute_position (struct frame *f)
 {
   int flags = f->size_hint_flags;
 
@@ -6245,7 +6235,7 @@ x_calc_absolute_position (struct frame *f)
 		       + f->left_pos
 		       - left_right_borders_width);
       else
-	f->left_pos = (x_display_pixel_width (FRAME_DISPLAY_INFO (f))
+	f->left_pos = (w32_display_pixel_width (FRAME_DISPLAY_INFO (f))
 		       + display_left
 		       - FRAME_PIXEL_WIDTH (f)
 		       + f->left_pos
@@ -6260,7 +6250,7 @@ x_calc_absolute_position (struct frame *f)
 		      + f->top_pos
 		      - top_bottom_borders_height);
       else
-	f->top_pos = (x_display_pixel_height (FRAME_DISPLAY_INFO (f))
+	f->top_pos = (w32_display_pixel_height (FRAME_DISPLAY_INFO (f))
 		      + display_top
 		      - FRAME_PIXEL_HEIGHT (f)
 		      + f->top_pos
@@ -6274,13 +6264,13 @@ x_calc_absolute_position (struct frame *f)
 
 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
    to really change the position, and 0 when calling from
-   x_make_frame_visible (in that case, XOFF and YOFF are the current
-   position values).  It is -1 when calling from x_set_frame_parameters,
+   w32_make_frame_visible (in that case, XOFF and YOFF are the current
+   position values).  It is -1 when calling from gui_set_frame_parameters,
    which means, do adjust for borders but don't change the gravity.  */
 
-void
-x_set_offset (struct frame *f, register int xoff, register int yoff,
-	      int change_gravity)
+static void
+w32_set_offset (struct frame *f, register int xoff, register int yoff,
+                int change_gravity)
 {
   int modified_top, modified_left;
 
@@ -6295,10 +6285,10 @@ x_set_offset (struct frame *f, register int xoff, register int yoff,
 	f->size_hint_flags |= YNegative;
       f->win_gravity = NorthWestGravity;
     }
-  x_calc_absolute_position (f);
+  w32_calc_absolute_position (f);
 
   block_input ();
-  x_wm_set_size_hint (f, (long) 0, false);
+  w32_wm_set_size_hint (f, (long) 0, false);
 
   modified_left = f->left_pos;
   modified_top = f->top_pos;
@@ -6472,7 +6462,7 @@ x_set_window_size (struct frame *f, bool change_gravity,
     }
 
   f->win_gravity = NorthWestGravity;
-  x_wm_set_size_hint (f, (long) 0, false);
+  w32_wm_set_size_hint (f, (long) 0, false);
 
   rect.left = rect.top = 0;
   rect.right = pixelwidth;
@@ -6589,8 +6579,8 @@ frame_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y)
    Windows API: An application cannot activate an inactive window
    without also bringing it to the top of the Z order.  */
 
-void
-x_focus_frame (struct frame *f, bool noactivate)
+static void
+w32_focus_frame (struct frame *f, bool noactivate)
 {
 #if 0
   struct w32_display_info *dpyinfo = &one_w32_display_info;
@@ -6600,7 +6590,7 @@ x_focus_frame (struct frame *f, bool noactivate)
   block_input ();
 #if 0
   /* Try not to change its Z-order if possible.  */
-  if (x_window_to_frame (dpyinfo, GetForegroundWindow ()))
+  if (w32_window_to_frame (dpyinfo, GetForegroundWindow ()))
     my_set_focus (f, FRAME_W32_WINDOW (f));
   else
 #endif
@@ -6609,8 +6599,8 @@ x_focus_frame (struct frame *f, bool noactivate)
 }
 
 /* Raise frame F.  */
-void
-x_raise_frame (struct frame *f)
+static void
+w32_raise_frame (struct frame *f)
 {
   block_input ();
 
@@ -6671,8 +6661,8 @@ x_raise_frame (struct frame *f)
 }
 
 /* Lower frame F.  */
-void
-x_lower_frame (struct frame *f)
+static void
+w32_lower_frame (struct frame *f)
 {
   block_input ();
   my_set_window_pos (FRAME_W32_WINDOW (f),
@@ -6689,9 +6679,9 @@ w32_frame_raise_lower (struct frame *f, bool raise_flag)
     return;
 
   if (raise_flag)
-    x_raise_frame (f);
+    w32_raise_frame (f);
   else
-    x_lower_frame (f);
+    w32_lower_frame (f);
 }
 \f
 /* Change of visibility.  */
@@ -6705,17 +6695,17 @@ w32_frame_raise_lower (struct frame *f, bool raise_flag)
    finishes with it.  */
 
 void
-x_make_frame_visible (struct frame *f)
+w32_make_frame_visible (struct frame *f)
 {
   block_input ();
 
-  x_set_bitmap_icon (f);
+  gui_set_bitmap_icon (f);
 
   if (! FRAME_VISIBLE_P (f))
     {
       /* We test FRAME_GARBAGED_P here to make sure we don't
-	 call x_set_offset a second time
-	 if we get to x_make_frame_visible a second time
+	 call w32_set_offset a second time
+	 if we get to w32_make_frame_visible a second time
 	 before the window gets really visible.  */
       if (! FRAME_ICONIFIED_P (f)
 	  && ! f->output_data.w32->asked_for_visible)
@@ -6736,7 +6726,7 @@ x_make_frame_visible (struct frame *f)
 				  workarea_rect.top);
 	    }
 
-	  x_set_offset (f, f->left_pos, f->top_pos, 0);
+	  w32_set_offset (f, f->left_pos, f->top_pos, 0);
 	}
 
       f->output_data.w32->asked_for_visible = 1;
@@ -6807,7 +6797,7 @@ x_make_frame_visible (struct frame *f)
 /* Make the frame visible (mapped and not iconified).  */
 
 void
-x_make_frame_invisible (struct frame *f)
+w32_make_frame_invisible (struct frame *f)
 {
   /* Don't keep the highlight on an invisible frame.  */
   if (FRAME_DISPLAY_INFO (f)->x_highlight_frame == f)
@@ -6828,10 +6818,19 @@ x_make_frame_invisible (struct frame *f)
   unblock_input ();
 }
 
+static void
+w32_make_frame_visible_invisible (struct frame *f, bool visible)
+{
+  if (visible)
+    w32_make_frame_visible (f);
+  else
+    w32_make_frame_invisible (f);
+}
+
 /* Change window state from mapped to iconified. */
 
 void
-x_iconify_frame (struct frame *f)
+w32_iconify_frame (struct frame *f)
 {
   /* Don't keep the highlight on an invisible frame.  */
   if (FRAME_DISPLAY_INFO (f)->x_highlight_frame == f)
@@ -6842,7 +6841,7 @@ x_iconify_frame (struct frame *f)
 
   block_input ();
 
-  x_set_bitmap_icon (f);
+  gui_set_bitmap_icon (f);
 
   /* Simulate the user minimizing the frame.  */
   SendMessageTimeout (FRAME_W32_WINDOW (f), WM_SYSCOMMAND, SC_MINIMIZE, 0,
@@ -6855,10 +6854,10 @@ x_iconify_frame (struct frame *f)
 }
 
 \f
-/* Free X resources of frame F.  */
+/* Free resources of frame F.  */
 
 void
-x_free_frame_resources (struct frame *f)
+w32_free_frame_resources (struct frame *f)
 {
   struct w32_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
   Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f);
@@ -6893,11 +6892,11 @@ x_free_frame_resources (struct frame *f)
 
 /* Destroy the window of frame F.  */
 static void
-x_destroy_window (struct frame *f)
+w32_destroy_window (struct frame *f)
 {
   struct w32_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
 
-  x_free_frame_resources (f);
+  w32_free_frame_resources (f);
   dpyinfo->reference_count--;
 }
 
@@ -6910,7 +6909,7 @@ x_destroy_window (struct frame *f)
    If USER_POSITION, set the USPosition
    flag (this is useful when FLAGS is 0).  */
 void
-x_wm_set_size_hint (struct frame *f, long flags, bool user_position)
+w32_wm_set_size_hint (struct frame *f, long flags, bool user_position)
 {
   Window window = FRAME_W32_WINDOW (f);
 
@@ -6935,7 +6934,7 @@ x_wm_set_size_hint (struct frame *f, long flags, bool user_position)
    font table.  */
 
 static void
-x_check_font (struct frame *f, struct font *font)
+w32_check_font (struct frame *f, struct font *font)
 {
   eassert (font != NULL && ! NILP (font->props[FONT_TYPE_INDEX]));
   if (font->driver->check)
@@ -7099,10 +7098,10 @@ static struct redisplay_interface w32_redisplay_interface =
   gui_write_glyphs,
   gui_insert_glyphs,
   gui_clear_end_of_line,
-  x_scroll_run,
-  x_after_update_window_line,
-  x_update_window_begin,
-  x_update_window_end,
+  w32_scroll_run,
+  w32_after_update_window_line,
+  w32_update_window_begin,
+  w32_update_window_end,
   0, /* flush_display */
   gui_clear_window_mouse_face,
   gui_get_glyph_overhangs,
@@ -7111,9 +7110,10 @@ static struct redisplay_interface w32_redisplay_interface =
   w32_define_fringe_bitmap,
   w32_destroy_fringe_bitmap,
   w32_compute_glyph_string_overhangs,
-  x_draw_glyph_string,
+  w32_draw_glyph_string,
   w32_define_frame_cursor,
   w32_clear_frame_area,
+  w32_clear_under_internal_border,
   w32_draw_window_cursor,
   w32_draw_vertical_window_border,
   w32_draw_window_divider,
@@ -7122,7 +7122,7 @@ static struct redisplay_interface w32_redisplay_interface =
   w32_hide_hourglass
 };
 
-static void x_delete_terminal (struct terminal *term);
+static void w32_delete_terminal (struct terminal *term);
 
 static struct terminal *
 w32_create_terminal (struct w32_display_info *dpyinfo)
@@ -7136,28 +7136,37 @@ w32_create_terminal (struct w32_display_info *dpyinfo)
 
   /* MSVC does not type K&R functions with no arguments correctly, and
      so we must explicitly cast them.  */
-  terminal->clear_frame_hook = x_clear_frame;
-  terminal->ins_del_lines_hook = x_ins_del_lines;
-  terminal->delete_glyphs_hook = x_delete_glyphs;
+  terminal->clear_frame_hook = w32_clear_frame;
+  terminal->ins_del_lines_hook = w32_ins_del_lines;
+  terminal->delete_glyphs_hook = w32_delete_glyphs;
   terminal->ring_bell_hook = w32_ring_bell;
   terminal->toggle_invisible_pointer_hook = w32_toggle_invisible_pointer;
-  terminal->update_begin_hook = x_update_begin;
-  terminal->update_end_hook = x_update_end;
+  terminal->update_begin_hook = w32_update_begin;
+  terminal->update_end_hook = w32_update_end;
   terminal->read_socket_hook = w32_read_socket;
   terminal->frame_up_to_date_hook = w32_frame_up_to_date;
   terminal->mouse_position_hook = w32_mouse_position;
+  terminal->focus_frame_hook = w32_focus_frame;
   terminal->frame_rehighlight_hook = w32_frame_rehighlight;
   terminal->frame_raise_lower_hook = w32_frame_raise_lower;
+  terminal->frame_visible_invisible_hook = w32_make_frame_visible_invisible;
   terminal->fullscreen_hook = w32fullscreen_hook;
+  terminal->iconify_frame_hook = w32_iconify_frame;
+  terminal->set_frame_alpha_hook = w32_set_frame_alpha;
+  terminal->set_new_font_hook = w32_new_font;
+  terminal->implicit_set_name_hook = w32_implicitly_set_name;
   terminal->menu_show_hook = w32_menu_show;
   terminal->popup_dialog_hook = w32_popup_dialog;
+  terminal->change_tool_bar_height_hook = w32_change_tool_bar_height;
   terminal->set_vertical_scroll_bar_hook = w32_set_vertical_scroll_bar;
   terminal->set_horizontal_scroll_bar_hook = w32_set_horizontal_scroll_bar;
+  terminal->set_scroll_bar_default_width_hook = w32_set_scroll_bar_default_width;
+  terminal->set_scroll_bar_default_height_hook = w32_set_scroll_bar_default_height;
   terminal->condemn_scroll_bars_hook = w32_condemn_scroll_bars;
   terminal->redeem_scroll_bar_hook = w32_redeem_scroll_bar;
   terminal->judge_scroll_bars_hook = w32_judge_scroll_bars;
-  terminal->delete_frame_hook = x_destroy_window;
-  terminal->delete_terminal_hook = x_delete_terminal;
+  terminal->delete_frame_hook = w32_destroy_window;
+  terminal->delete_terminal_hook = w32_delete_terminal;
   /* Other hooks are NULL by default.  */
 
   /* We don't yet support separate terminals on W32, so don't try to share
@@ -7175,7 +7184,7 @@ w32_create_terminal (struct w32_display_info *dpyinfo)
 }
 
 static void
-x_delete_terminal (struct terminal *terminal)
+w32_delete_terminal (struct terminal *terminal)
 {
   struct w32_display_info *dpyinfo = terminal->display_info.w32;
 
@@ -7186,7 +7195,7 @@ x_delete_terminal (struct terminal *terminal)
 
   block_input ();
 
-  x_delete_display (dpyinfo);
+  w32_delete_display (dpyinfo);
   unblock_input ();
 }
 
@@ -7262,7 +7271,7 @@ w32_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
 \f
 /* Get rid of display DPYINFO, assuming all frames are already gone.  */
 void
-x_delete_display (struct w32_display_info *dpyinfo)
+w32_delete_display (struct w32_display_info *dpyinfo)
 {
   /* FIXME: the only display info apparently can't be deleted.  */
   /* free palette table */
diff --git a/src/w32term.h b/src/w32term.h
index a0942d630a..6374704b54 100644
--- a/src/w32term.h
+++ b/src/w32term.h
@@ -227,7 +227,14 @@ extern struct w32_display_info one_w32_display_info;
 extern HMENU current_popup_menu;
 extern int menubar_in_use;
 
-extern struct frame *x_window_to_frame (struct w32_display_info *, HWND);
+extern struct frame *w32_window_to_frame (struct w32_display_info *, HWND);
+
+extern void w32_real_positions (struct frame *f, int *xptr, int *yptr);
+
+extern void w32_change_tool_bar_height (struct frame *, int)
+extern void w32_implicitly_set_name (struct frame *, Lisp_Object, Lisp_Object);
+extern void w32_set_scroll_bar_default_width (struct frame *);
+extern void w32_set_scroll_bar_default_height (struct frame *);
 
 struct w32_display_info *x_display_info_for_name (Lisp_Object);
 
@@ -237,18 +244,17 @@ extern struct w32_display_info *w32_term_init (Lisp_Object,
 					       char *, char *);
 extern int w32_defined_color (struct frame *f, const char *color,
                               XColor *color_def, bool alloc_p);
-extern int x_display_pixel_height (struct w32_display_info *);
-extern int x_display_pixel_width (struct w32_display_info *);
-extern void x_set_menu_bar_lines (struct frame *, Lisp_Object, Lisp_Object);
-extern void x_set_tool_bar_lines (struct frame *f,
-                                  Lisp_Object value,
-                                  Lisp_Object oldval);
-extern void x_set_internal_border_width (struct frame *f,
-					 Lisp_Object value,
-					 Lisp_Object oldval);
+extern int w32_display_pixel_height (struct w32_display_info *);
+extern int w32_display_pixel_width (struct w32_display_info *);
 extern void initialize_frame_menubar (struct frame *);
 extern void w32_dialog_in_progress (Lisp_Object in_progress);
 
+extern void w32_make_frame_visible (struct frame *f)
+extern void w32_make_frame_invisible (struct frame *f)
+extern void w32_iconify_frame (struct frame *f);
+extern void w32_free_frame_resources (struct frame *);
+extern void w32_wm_set_size_hint (struct frame *, long, bool);
+
 /* w32inevt.c */
 extern int w32_kbd_patch_key (KEY_EVENT_RECORD *event, int cpId);
 extern int w32_kbd_mods_to_emacs (DWORD mods, WORD key);
@@ -715,9 +721,8 @@ extern void complete_deferred_msg (HWND hwnd, UINT msg, LRESULT result);
 extern BOOL parse_button (int, int, int *, int *);
 
 extern void w32_sys_ring_bell (struct frame *f);
-extern void x_delete_display (struct w32_display_info *dpyinfo);
-extern void x_clear_under_internal_border (struct frame *f);
-extern void x_query_color (struct frame *, XColor *);
+extern void w32_query_color (struct frame *, XColor *);
+extern void w32_delete_display (struct w32_display_info *dpyinfo);
 
 #define FILE_NOTIFICATIONS_SIZE 16384
 /* Notifications come in sets.  We use a doubly linked list with a
diff --git a/src/window.c b/src/window.c
index 05340ea439..d805d2f8b9 100644
--- a/src/window.c
+++ b/src/window.c
@@ -4683,7 +4683,7 @@ resize_frame_windows (struct frame *f, int size, bool horflag, bool pixelwise)
   int unit = horflag ? FRAME_COLUMN_WIDTH (f) : FRAME_LINE_HEIGHT (f);
 
   /* Don't let the size drop below one unit.  This is more comforting
-     when we are called from x_set_tool_bar_lines since the latter may
+     when we are called from *_set_tool_bar_lines since the latter may
      have implicitly given us a zero or negative height.  */
   if (pixelwise)
     {
diff --git a/src/xdisp.c b/src/xdisp.c
index ae4c405b8d..11667d2735 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -11592,9 +11592,8 @@ clear_garbaged_frames (void)
 	      else
 		clear_current_matrices (f);
 
-#if defined (HAVE_WINDOW_SYSTEM) && !defined (HAVE_NS)
-	      x_clear_under_internal_border (f);
-#endif /* HAVE_WINDOW_SYSTEM && !HAVE_NS */
+              if (FRAME_RIF (f)->clear_under_internal_border)
+                FRAME_RIF (f)->clear_under_internal_border (f);
 
 	      fset_redisplay (f);
 	      f->garbaged = false;
@@ -11664,9 +11663,8 @@ echo_area_display (bool update_frame_p)
 	    {
 	      n = redisplay_mode_lines (FRAME_ROOT_WINDOW (f), false);
 
-#if defined (HAVE_WINDOW_SYSTEM) && !defined (HAVE_NS)
-	      x_clear_under_internal_border (f);
-#endif /* HAVE_WINDOW_SYSTEM && !HAVE_NS */
+              if (FRAME_RIF (f)->clear_under_internal_border)
+                FRAME_RIF (f)->clear_under_internal_border (f);
 
 	    }
 
@@ -12074,7 +12072,9 @@ gui_consider_frame_title (Lisp_Object frame)
       if (! STRINGP (f->name)
 	  || SBYTES (f->name) != len
 	  || memcmp (title, SDATA (f->name), len) != 0)
-	x_implicitly_set_name (f, make_string (title, len), Qnil);
+	FRAME_TERMINAL (f)->implicit_set_name_hook (f,
+                                                    make_string (title, len),
+                                                    Qnil);
     }
 }
 
@@ -12848,7 +12848,7 @@ redisplay_tool_bar (struct frame *f)
 
       if (new_height != WINDOW_PIXEL_HEIGHT (w))
 	{
-	  x_change_tool_bar_height (f, new_height);
+	  FRAME_TERMINAL (f)->change_tool_bar_height_hook (f, new_height);
 	  frame_default_tool_bar_height = new_height;
 	  /* Always do that now.  */
 	  clear_glyph_matrix (w->desired_matrix);
@@ -12943,7 +12943,7 @@ redisplay_tool_bar (struct frame *f)
 
 	  if (change_height_p)
 	    {
-	      x_change_tool_bar_height (f, new_height);
+	      FRAME_TERMINAL (f)->change_tool_bar_height_hook (f, new_height);
 	      frame_default_tool_bar_height = new_height;
 	      clear_glyph_matrix (w->desired_matrix);
 	      f->n_tool_bar_rows = nrows;
@@ -14485,9 +14485,8 @@ redisplay_internal (void)
 		      && garbaged_frame_retries++ < MAX_GARBAGED_FRAME_RETRIES)
                     goto retry;
 
-#if defined (HAVE_WINDOW_SYSTEM) && !defined (HAVE_NS)
-		  x_clear_under_internal_border (f);
-#endif /* HAVE_WINDOW_SYSTEM && !HAVE_NS */
+                  if (FRAME_RIF (f)->clear_under_internal_border)
+                    FRAME_RIF (f)->clear_under_internal_border (f);
 
 		  /* Prevent various kinds of signals during display
 		     update.  stdio is not robust about handling
diff --git a/src/xfaces.c b/src/xfaces.c
index c6723ebe2c..24574ae141 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -777,13 +777,13 @@ load_pixmap (struct frame *f, Lisp_Object name)
       h = XFIXNUM (Fcar (Fcdr (name)));
       bits = Fcar (Fcdr (Fcdr (name)));
 
-      bitmap_id = x_create_bitmap_from_data (f, SSDATA (bits),
-					     w, h);
+      bitmap_id = gui_create_bitmap_from_data (f, SSDATA (bits),
+                                               w, h);
     }
   else
     {
       /* It must be a string -- a file name.  */
-      bitmap_id = x_create_bitmap_from_file (f, name);
+      bitmap_id = gui_create_bitmap_from_file (f, name);
     }
   unblock_input ();
 
@@ -5458,7 +5458,7 @@ realize_default_face (struct frame *f)
 	 acceptable as a font for the default face (perhaps because
 	 auto-scaled fonts are rejected), so we must adjust the frame
 	 font.  */
-      x_set_font (f, LFACE_FONT (lface), Qnil);
+      gui_set_font (f, LFACE_FONT (lface), Qnil);
     }
 #endif
   return true;
diff --git a/src/xfns.c b/src/xfns.c
index da11e74345..392185157a 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -978,7 +978,7 @@ xg_set_icon (struct frame *f, Lisp_Object file)
   bool result = false;
   Lisp_Object found;
 
-  found = x_find_image_file (file);
+  found = gui_find_image_file (file);
 
   if (! NILP (found))
     {
@@ -1021,7 +1021,7 @@ xg_set_icon_from_xpm_data (struct frame *f, const char **data)
 #endif /* USE_GTK */
 
 
-/* Functions called only from `x_set_frame_param'
+/* Functions called only from `gui_set_frame_parameters'
    to set individual parameters.
 
    If FRAME_X_WINDOW (f) is 0,
@@ -2056,7 +2056,7 @@ x_set_title (struct frame *f, Lisp_Object name, Lisp_Object old_name)
   x_set_name_internal (f, name);
 }
 
-void
+static void
 x_set_scroll_bar_default_width (struct frame *f)
 {
   int unit = FRAME_COLUMN_WIDTH (f);
@@ -2077,7 +2077,7 @@ x_set_scroll_bar_default_width (struct frame *f)
 #endif
 }
 
-void
+static void
 x_set_scroll_bar_default_height (struct frame *f)
 {
   int height = FRAME_LINE_HEIGHT (f);
@@ -2148,7 +2148,7 @@ x_default_scroll_bar_color_parameter (struct frame *f,
     }
 
   AUTO_FRAME_ARG (arg, prop, tem);
-  x_set_frame_parameters (f, arg);
+  gui_set_frame_parameters (f, arg);
   return tem;
 }
 
@@ -3407,7 +3407,7 @@ x_free_gcs (struct frame *f)
 
 
 /* Handler for signals raised during x_create_frame and
-   x_create_tip_frame.  FRAME is the frame which is partially
+   Fx_create_tip_frame.  FRAME is the frame which is partially
    constructed.  */
 
 static Lisp_Object
@@ -3417,7 +3417,7 @@ unwind_create_frame (Lisp_Object frame)
 
   /* If frame is already dead, nothing to do.  This can happen if the
      display is disconnected after the frame has become official, but
-     before x_create_frame removes the unwind protect.  */
+     before Fx_create_frame removes the unwind protect.  */
   if (!FRAME_LIVE_P (f))
     return Qnil;
 
@@ -3518,11 +3518,11 @@ x_default_font_parameter (struct frame *f, Lisp_Object parms)
       /* Remember the explicit font parameter, so we can re-apply it after
 	 we've applied the `default' face settings.  */
       AUTO_FRAME_ARG (arg, Qfont_parameter, font_param);
-      x_set_frame_parameters (f, arg);
+      gui_set_frame_parameters (f, arg);
     }
 
   /* This call will make X resources override any system font setting.  */
-  x_default_parameter (f, parms, Qfont, font, "font", "Font", RES_TYPE_STRING);
+  gui_default_parameter (f, parms, Qfont, font, "font", "Font", RES_TYPE_STRING);
 }
 
 
@@ -3768,8 +3768,8 @@ This function is an internal primitive--use `make-frame' instead.  */)
   dpyinfo_refcount = dpyinfo->reference_count;
 #endif /* GLYPH_DEBUG */
 
-  x_default_parameter (f, parms, Qfont_backend, Qnil,
-		       "fontBackend", "FontBackend", RES_TYPE_STRING);
+  gui_default_parameter (f, parms, Qfont_backend, Qnil,
+                         "fontBackend", "FontBackend", RES_TYPE_STRING);
 
   /* Extract the window parameters from the supplied values
      that are needed to determine window geometry.  */
@@ -3782,8 +3782,8 @@ This function is an internal primitive--use `make-frame' instead.  */)
 
   /* Frame contents get displaced if an embedded X window has a border.  */
   if (! FRAME_X_EMBEDDED_P (f))
-    x_default_parameter (f, parms, Qborder_width, make_fixnum (0),
-			 "borderWidth", "BorderWidth", RES_TYPE_NUMBER);
+    gui_default_parameter (f, parms, Qborder_width, make_fixnum (0),
+                           "borderWidth", "BorderWidth", RES_TYPE_NUMBER);
 
   /* This defaults to 1 in order to match xterm.  We recognize either
      internalBorderWidth or internalBorder (which is what xterm calls
@@ -3798,48 +3798,48 @@ This function is an internal primitive--use `make-frame' instead.  */)
 	parms = Fcons (Fcons (Qinternal_border_width, value),
 		       parms);
     }
-  x_default_parameter (f, parms, Qinternal_border_width,
+  gui_default_parameter (f, parms, Qinternal_border_width,
 #ifdef USE_GTK /* We used to impose 0 in xg_create_frame_widgets.  */
-		       make_fixnum (0),
+                         make_fixnum (0),
 #else
-		       make_fixnum (1),
+                         make_fixnum (1),
 #endif
-		       "internalBorderWidth", "internalBorderWidth",
-		       RES_TYPE_NUMBER);
-  x_default_parameter (f, parms, Qright_divider_width, make_fixnum (0),
-		       NULL, NULL, RES_TYPE_NUMBER);
-  x_default_parameter (f, parms, Qbottom_divider_width, make_fixnum (0),
-		       NULL, NULL, RES_TYPE_NUMBER);
-  x_default_parameter (f, parms, Qvertical_scroll_bars,
+                         "internalBorderWidth", "internalBorderWidth",
+                         RES_TYPE_NUMBER);
+  gui_default_parameter (f, parms, Qright_divider_width, make_fixnum (0),
+                         NULL, NULL, RES_TYPE_NUMBER);
+  gui_default_parameter (f, parms, Qbottom_divider_width, make_fixnum (0),
+                         NULL, NULL, RES_TYPE_NUMBER);
+  gui_default_parameter (f, parms, Qvertical_scroll_bars,
 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
-		       Qright,
+                         Qright,
 #else
-		       Qleft,
+                         Qleft,
 #endif
-		       "verticalScrollBars", "ScrollBars",
-		       RES_TYPE_SYMBOL);
-  x_default_parameter (f, parms, Qhorizontal_scroll_bars, Qnil,
-		       "horizontalScrollBars", "ScrollBars",
-		       RES_TYPE_SYMBOL);
+                         "verticalScrollBars", "ScrollBars",
+                         RES_TYPE_SYMBOL);
+  gui_default_parameter (f, parms, Qhorizontal_scroll_bars, Qnil,
+                         "horizontalScrollBars", "ScrollBars",
+                         RES_TYPE_SYMBOL);
   /* Also do the stuff which must be set before the window exists.  */
-  x_default_parameter (f, parms, Qforeground_color, build_string ("black"),
-		       "foreground", "Foreground", RES_TYPE_STRING);
-  x_default_parameter (f, parms, Qbackground_color, build_string ("white"),
-		       "background", "Background", RES_TYPE_STRING);
-  x_default_parameter (f, parms, Qmouse_color, build_string ("black"),
-		       "pointerColor", "Foreground", RES_TYPE_STRING);
-  x_default_parameter (f, parms, Qborder_color, build_string ("black"),
-		       "borderColor", "BorderColor", RES_TYPE_STRING);
-  x_default_parameter (f, parms, Qscreen_gamma, Qnil,
-		       "screenGamma", "ScreenGamma", RES_TYPE_FLOAT);
-  x_default_parameter (f, parms, Qline_spacing, Qnil,
-		       "lineSpacing", "LineSpacing", RES_TYPE_NUMBER);
-  x_default_parameter (f, parms, Qleft_fringe, Qnil,
-		       "leftFringe", "LeftFringe", RES_TYPE_NUMBER);
-  x_default_parameter (f, parms, Qright_fringe, Qnil,
-		       "rightFringe", "RightFringe", RES_TYPE_NUMBER);
-  x_default_parameter (f, parms, Qno_special_glyphs, Qnil,
-		       NULL, NULL, RES_TYPE_BOOLEAN);
+  gui_default_parameter (f, parms, Qforeground_color, build_string ("black"),
+                         "foreground", "Foreground", RES_TYPE_STRING);
+  gui_default_parameter (f, parms, Qbackground_color, build_string ("white"),
+                         "background", "Background", RES_TYPE_STRING);
+  gui_default_parameter (f, parms, Qmouse_color, build_string ("black"),
+                         "pointerColor", "Foreground", RES_TYPE_STRING);
+  gui_default_parameter (f, parms, Qborder_color, build_string ("black"),
+                         "borderColor", "BorderColor", RES_TYPE_STRING);
+  gui_default_parameter (f, parms, Qscreen_gamma, Qnil,
+                         "screenGamma", "ScreenGamma", RES_TYPE_FLOAT);
+  gui_default_parameter (f, parms, Qline_spacing, Qnil,
+                         "lineSpacing", "LineSpacing", RES_TYPE_NUMBER);
+  gui_default_parameter (f, parms, Qleft_fringe, Qnil,
+                         "leftFringe", "LeftFringe", RES_TYPE_NUMBER);
+  gui_default_parameter (f, parms, Qright_fringe, Qnil,
+                         "rightFringe", "RightFringe", RES_TYPE_NUMBER);
+  gui_default_parameter (f, parms, Qno_special_glyphs, Qnil,
+                         NULL, NULL, RES_TYPE_BOOLEAN);
 
   x_default_scroll_bar_color_parameter (f, parms, Qscroll_bar_foreground,
 					"scrollBarForeground",
@@ -3848,7 +3848,7 @@ This function is an internal primitive--use `make-frame' instead.  */)
 					"scrollBarBackground",
 					"ScrollBarBackground", false);
 
-  /* Init faces before x_default_parameter is called for the
+  /* Init faces before gui_default_parameter is called for the
      scroll-bar-width parameter because otherwise we end up in
      init_iterator with a null face cache, which should not happen.  */
   init_frame_faces (f);
@@ -3880,30 +3880,31 @@ This function is an internal primitive--use `make-frame' instead.  */)
      here; they are processed specially at startup, and reflected in
      the values of the mode variables.  */
 
-  x_default_parameter (f, parms, Qmenu_bar_lines,
-		       NILP (Vmenu_bar_mode)
-		       ? make_fixnum (0) : make_fixnum (1),
-		       NULL, NULL, RES_TYPE_NUMBER);
-  x_default_parameter (f, parms, Qtool_bar_lines,
-		       NILP (Vtool_bar_mode)
-		       ? make_fixnum (0) : make_fixnum (1),
-		       NULL, NULL, RES_TYPE_NUMBER);
-
-  x_default_parameter (f, parms, Qbuffer_predicate, Qnil,
-		       "bufferPredicate", "BufferPredicate",
-		       RES_TYPE_SYMBOL);
-  x_default_parameter (f, parms, Qtitle, Qnil,
-		       "title", "Title", RES_TYPE_STRING);
-  x_default_parameter (f, parms, Qwait_for_wm, Qt,
-		       "waitForWM", "WaitForWM", RES_TYPE_BOOLEAN);
-  x_default_parameter (f, parms, Qtool_bar_position,
-                       FRAME_TOOL_BAR_POSITION (f), 0, 0, RES_TYPE_SYMBOL);
-  x_default_parameter (f, parms, Qinhibit_double_buffering, Qnil,
-                       "inhibitDoubleBuffering", "InhibitDoubleBuffering",
-                       RES_TYPE_BOOLEAN);
+  gui_default_parameter (f, parms, Qmenu_bar_lines,
+                         NILP (Vmenu_bar_mode)
+                         ? make_fixnum (0) : make_fixnum (1),
+                         NULL, NULL, RES_TYPE_NUMBER);
+  gui_default_parameter (f, parms, Qtool_bar_lines,
+                         NILP (Vtool_bar_mode)
+                         ? make_fixnum (0) : make_fixnum (1),
+                         NULL, NULL, RES_TYPE_NUMBER);
+
+  gui_default_parameter (f, parms, Qbuffer_predicate, Qnil,
+                         "bufferPredicate", "BufferPredicate",
+                         RES_TYPE_SYMBOL);
+  gui_default_parameter (f, parms, Qtitle, Qnil,
+                         "title", "Title", RES_TYPE_STRING);
+  gui_default_parameter (f, parms, Qwait_for_wm, Qt,
+                         "waitForWM", "WaitForWM", RES_TYPE_BOOLEAN);
+  gui_default_parameter (f, parms, Qtool_bar_position,
+                         FRAME_TOOL_BAR_POSITION (f), 0, 0, RES_TYPE_SYMBOL);
+  gui_default_parameter (f, parms, Qinhibit_double_buffering, Qnil,
+                         "inhibitDoubleBuffering", "InhibitDoubleBuffering",
+                         RES_TYPE_BOOLEAN);
 
   /* Compute the size of the X window.  */
-  window_prompting = x_figure_window_size (f, parms, true, &x_width, &x_height);
+  window_prompting = gui_figure_window_size (f, parms, true,
+                                             &x_width, &x_height);
 
   tem = x_get_arg (dpyinfo, parms, Qunsplittable, 0, 0, RES_TYPE_BOOLEAN);
   f->no_split = minibuffer_only || EQ (tem, Qt);
@@ -3927,23 +3928,23 @@ This function is an internal primitive--use `make-frame' instead.  */)
 
   /* We need to do this after creating the X window, so that the
      icon-creation functions can say whose icon they're describing.  */
-  x_default_parameter (f, parms, Qicon_type, Qt,
-		       "bitmapIcon", "BitmapIcon", RES_TYPE_BOOLEAN);
-
-  x_default_parameter (f, parms, Qauto_raise, Qnil,
-		       "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN);
-  x_default_parameter (f, parms, Qauto_lower, Qnil,
-		       "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN);
-  x_default_parameter (f, parms, Qcursor_type, Qbox,
-		       "cursorType", "CursorType", RES_TYPE_SYMBOL);
-  x_default_parameter (f, parms, Qscroll_bar_width, Qnil,
-		       "scrollBarWidth", "ScrollBarWidth",
-		       RES_TYPE_NUMBER);
-  x_default_parameter (f, parms, Qscroll_bar_height, Qnil,
-		       "scrollBarHeight", "ScrollBarHeight",
-		       RES_TYPE_NUMBER);
-  x_default_parameter (f, parms, Qalpha, Qnil,
-		       "alpha", "Alpha", RES_TYPE_NUMBER);
+  gui_default_parameter (f, parms, Qicon_type, Qt,
+                         "bitmapIcon", "BitmapIcon", RES_TYPE_BOOLEAN);
+
+  gui_default_parameter (f, parms, Qauto_raise, Qnil,
+                         "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN);
+  gui_default_parameter (f, parms, Qauto_lower, Qnil,
+                         "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN);
+  gui_default_parameter (f, parms, Qcursor_type, Qbox,
+                         "cursorType", "CursorType", RES_TYPE_SYMBOL);
+  gui_default_parameter (f, parms, Qscroll_bar_width, Qnil,
+                         "scrollBarWidth", "ScrollBarWidth",
+                         RES_TYPE_NUMBER);
+  gui_default_parameter (f, parms, Qscroll_bar_height, Qnil,
+                         "scrollBarHeight", "ScrollBarHeight",
+                         RES_TYPE_NUMBER);
+  gui_default_parameter (f, parms, Qalpha, Qnil,
+                         "alpha", "Alpha", RES_TYPE_NUMBER);
 
   if (!NILP (parent_frame))
     {
@@ -3955,10 +3956,10 @@ This function is an internal primitive--use `make-frame' instead.  */)
       unblock_input ();
     }
 
-  x_default_parameter (f, parms, Qno_focus_on_map, Qnil,
-		       NULL, NULL, RES_TYPE_BOOLEAN);
-  x_default_parameter (f, parms, Qno_accept_focus, Qnil,
-		       NULL, NULL, RES_TYPE_BOOLEAN);
+  gui_default_parameter (f, parms, Qno_focus_on_map, Qnil,
+                         NULL, NULL, RES_TYPE_BOOLEAN);
+  gui_default_parameter (f, parms, Qno_accept_focus, Qnil,
+                         NULL, NULL, RES_TYPE_BOOLEAN);
 
 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
   /* Create the menu bar.  */
@@ -3999,8 +4000,8 @@ This function is an internal primitive--use `make-frame' instead.  */)
   /* Process fullscreen parameter here in the hope that normalizing a
      fullheight/fullwidth frame will produce the size set by the last
      adjust_frame_size call.  */
-  x_default_parameter (f, parms, Qfullscreen, Qnil,
-		       "fullscreen", "Fullscreen", RES_TYPE_SYMBOL);
+  gui_default_parameter (f, parms, Qfullscreen, Qnil,
+                         "fullscreen", "Fullscreen", RES_TYPE_SYMBOL);
 
   /* Make the window appear on the frame and enable display, unless
      the caller says not to.  However, with explicit parent, Emacs
@@ -4043,11 +4044,11 @@ This function is an internal primitive--use `make-frame' instead.  */)
   unblock_input ();
 
   /* Works iff frame has been already mapped.  */
-  x_default_parameter (f, parms, Qskip_taskbar, Qnil,
-		       NULL, NULL, RES_TYPE_BOOLEAN);
+  gui_default_parameter (f, parms, Qskip_taskbar, Qnil,
+                         NULL, NULL, RES_TYPE_BOOLEAN);
   /* The `z-group' parameter works only for visible frames.  */
-  x_default_parameter (f, parms, Qz_group, Qnil,
-		       NULL, NULL, RES_TYPE_SYMBOL);
+  gui_default_parameter (f, parms, Qz_group, Qnil,
+                         NULL, NULL, RES_TYPE_SYMBOL);
 
   /* Initialize `default-minibuffer-frame' in case this is the first
      frame on this terminal.  */
@@ -4069,60 +4070,6 @@ This function is an internal primitive--use `make-frame' instead.  */)
  return unbind_to (count, frame);
 }
 
-
-/* FRAME is used only to get a handle on the X display.  We don't pass the
-   display info directly because we're called from frame.c, which doesn't
-   know about that structure.  */
-
-Lisp_Object
-x_get_focus_frame (struct frame *frame)
-{
-  struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (frame);
-  Lisp_Object xfocus;
-  if (! dpyinfo->x_focus_frame)
-    return Qnil;
-
-  XSETFRAME (xfocus, dpyinfo->x_focus_frame);
-  return xfocus;
-}
-
-
-/* In certain situations, when the window manager follows a
-   click-to-focus policy, there seems to be no way around calling
-   XSetInputFocus to give another frame the input focus .
-
-   In an ideal world, XSetInputFocus should generally be avoided so
-   that applications don't interfere with the window manager's focus
-   policy.  But I think it's okay to use when it's clearly done
-   following a user-command.  */
-
-void
-x_focus_frame (struct frame *f, bool noactivate)
-{
-  Display *dpy = FRAME_X_DISPLAY (f);
-
-  block_input ();
-  x_catch_errors (dpy);
-
-  if (FRAME_X_EMBEDDED_P (f))
-    {
-      /* For Xembedded frames, normally the embedder forwards key
-	 events.  See XEmbed Protocol Specification at
-	 http://freedesktop.org/wiki/Specifications/xembed-spec  */
-      xembed_request_focus (f);
-    }
-  else
-    {
-      XSetInputFocus (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
-		      RevertToParent, CurrentTime);
-      if (!noactivate)
-	x_ewmh_activate_frame (f);
-    }
-
-  x_uncatch_errors ();
-  unblock_input ();
-}
-
 \f
 DEFUN ("xw-color-defined-p", Fxw_color_defined_p, Sxw_color_defined_p, 1, 2, 0,
        doc: /* Internal function called by `color-defined-p'.
@@ -6122,7 +6069,7 @@ unwind_create_tip_frame (Lisp_Object frame)
    PARMS is a list of frame parameters.  TEXT is the string to
    display in the tip frame.  Value is the frame.
 
-   Note that functions called here, esp. x_default_parameter can
+   Note that functions called here, esp. gui_default_parameter can
    signal errors, for instance when a specified color name is
    undefined.  We have to make sure that we're in a consistent state
    when this happens.  */
@@ -6245,15 +6192,15 @@ x_create_tip_frame (struct x_display_info *dpyinfo, Lisp_Object parms)
   dpyinfo_refcount = dpyinfo->reference_count;
 #endif /* GLYPH_DEBUG */
 
-  x_default_parameter (f, parms, Qfont_backend, Qnil,
-		       "fontBackend", "FontBackend", RES_TYPE_STRING);
+  gui_default_parameter (f, parms, Qfont_backend, Qnil,
+                         "fontBackend", "FontBackend", RES_TYPE_STRING);
 
   /* Extract the window parameters from the supplied values that are
      needed to determine window geometry.  */
   x_default_font_parameter (f, parms);
 
-  x_default_parameter (f, parms, Qborder_width, make_fixnum (0),
-		       "borderWidth", "BorderWidth", RES_TYPE_NUMBER);
+  gui_default_parameter (f, parms, Qborder_width, make_fixnum (0),
+                         "borderWidth", "BorderWidth", RES_TYPE_NUMBER);
 
   /* This defaults to 2 in order to match xterm.  We recognize either
      internalBorderWidth or internalBorder (which is what xterm calls
@@ -6269,36 +6216,36 @@ x_create_tip_frame (struct x_display_info *dpyinfo, Lisp_Object parms)
 		       parms);
     }
 
-  x_default_parameter (f, parms, Qinternal_border_width, make_fixnum (1),
-		       "internalBorderWidth", "internalBorderWidth",
-		       RES_TYPE_NUMBER);
-  x_default_parameter (f, parms, Qright_divider_width, make_fixnum (0),
-		       NULL, NULL, RES_TYPE_NUMBER);
-  x_default_parameter (f, parms, Qbottom_divider_width, make_fixnum (0),
-		       NULL, NULL, RES_TYPE_NUMBER);
+  gui_default_parameter (f, parms, Qinternal_border_width, make_fixnum (1),
+                         "internalBorderWidth", "internalBorderWidth",
+                         RES_TYPE_NUMBER);
+  gui_default_parameter (f, parms, Qright_divider_width, make_fixnum (0),
+                         NULL, NULL, RES_TYPE_NUMBER);
+  gui_default_parameter (f, parms, Qbottom_divider_width, make_fixnum (0),
+                         NULL, NULL, RES_TYPE_NUMBER);
 
   /* Also do the stuff which must be set before the window exists.  */
-  x_default_parameter (f, parms, Qforeground_color, build_string ("black"),
-		       "foreground", "Foreground", RES_TYPE_STRING);
-  x_default_parameter (f, parms, Qbackground_color, build_string ("white"),
-		       "background", "Background", RES_TYPE_STRING);
-  x_default_parameter (f, parms, Qmouse_color, build_string ("black"),
-		       "pointerColor", "Foreground", RES_TYPE_STRING);
-  x_default_parameter (f, parms, Qcursor_color, build_string ("black"),
-		       "cursorColor", "Foreground", RES_TYPE_STRING);
-  x_default_parameter (f, parms, Qborder_color, build_string ("black"),
-		       "borderColor", "BorderColor", RES_TYPE_STRING);
-  x_default_parameter (f, parms, Qno_special_glyphs, Qnil,
-		       NULL, NULL, RES_TYPE_BOOLEAN);
-
-  /* Init faces before x_default_parameter is called for the
+  gui_default_parameter (f, parms, Qforeground_color, build_string ("black"),
+                         "foreground", "Foreground", RES_TYPE_STRING);
+  gui_default_parameter (f, parms, Qbackground_color, build_string ("white"),
+                         "background", "Background", RES_TYPE_STRING);
+  gui_default_parameter (f, parms, Qmouse_color, build_string ("black"),
+                         "pointerColor", "Foreground", RES_TYPE_STRING);
+  gui_default_parameter (f, parms, Qcursor_color, build_string ("black"),
+                         "cursorColor", "Foreground", RES_TYPE_STRING);
+  gui_default_parameter (f, parms, Qborder_color, build_string ("black"),
+                         "borderColor", "BorderColor", RES_TYPE_STRING);
+  gui_default_parameter (f, parms, Qno_special_glyphs, Qnil,
+                         NULL, NULL, RES_TYPE_BOOLEAN);
+
+  /* Init faces before gui_default_parameter is called for the
      scroll-bar-width parameter because otherwise we end up in
      init_iterator with a null face cache, which should not happen.  */
   init_frame_faces (f);
 
   f->output_data.x->parent_desc = FRAME_DISPLAY_INFO (f)->root_window;
 
-  x_figure_window_size (f, parms, false, &x_width, &x_height);
+  gui_figure_window_size (f, parms, false, &x_width, &x_height);
 
   {
     XSetWindowAttributes attrs;
@@ -6341,14 +6288,14 @@ x_create_tip_frame (struct x_display_info *dpyinfo, Lisp_Object parms)
 
   x_make_gc (f);
 
-  x_default_parameter (f, parms, Qauto_raise, Qnil,
-		       "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN);
-  x_default_parameter (f, parms, Qauto_lower, Qnil,
-		       "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN);
-  x_default_parameter (f, parms, Qcursor_type, Qbox,
-		       "cursorType", "CursorType", RES_TYPE_SYMBOL);
-  x_default_parameter (f, parms, Qalpha, Qnil,
-		       "alpha", "Alpha", RES_TYPE_NUMBER);
+  gui_default_parameter (f, parms, Qauto_raise, Qnil,
+                         "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN);
+  gui_default_parameter (f, parms, Qauto_lower, Qnil,
+                         "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN);
+  gui_default_parameter (f, parms, Qcursor_type, Qbox,
+                         "cursorType", "CursorType", RES_TYPE_SYMBOL);
+  gui_default_parameter (f, parms, Qalpha, Qnil,
+                         "alpha", "Alpha", RES_TYPE_NUMBER);
 
   /* Dimensions, especially FRAME_LINES (f), must be done via change_frame_size.
      Change will not be effected unless different from the current
@@ -7605,41 +7552,41 @@ visible.  */)
 
 frame_parm_handler x_frame_parm_handlers[] =
 {
-  x_set_autoraise,
-  x_set_autolower,
+  gui_set_autoraise,
+  gui_set_autolower,
   x_set_background_color,
   x_set_border_color,
-  x_set_border_width,
+  gui_set_border_width,
   x_set_cursor_color,
   x_set_cursor_type,
-  x_set_font,
+  gui_set_font,
   x_set_foreground_color,
   x_set_icon_name,
   x_set_icon_type,
   x_set_internal_border_width,
-  x_set_right_divider_width,
-  x_set_bottom_divider_width,
+  gui_set_right_divider_width,
+  gui_set_bottom_divider_width,
   x_set_menu_bar_lines,
   x_set_mouse_color,
   x_explicitly_set_name,
-  x_set_scroll_bar_width,
-  x_set_scroll_bar_height,
+  gui_set_scroll_bar_width,
+  gui_set_scroll_bar_height,
   x_set_title,
-  x_set_unsplittable,
-  x_set_vertical_scroll_bars,
-  x_set_horizontal_scroll_bars,
-  x_set_visibility,
+  gui_set_unsplittable,
+  gui_set_vertical_scroll_bars,
+  gui_set_horizontal_scroll_bars,
+  gui_set_visibility,
   x_set_tool_bar_lines,
   x_set_scroll_bar_foreground,
   x_set_scroll_bar_background,
-  x_set_screen_gamma,
-  x_set_line_spacing,
-  x_set_left_fringe,
-  x_set_right_fringe,
+  gui_set_screen_gamma,
+  gui_set_line_spacing,
+  gui_set_left_fringe,
+  gui_set_right_fringe,
   x_set_wait_for_wm,
-  x_set_fullscreen,
-  x_set_font_backend,
-  x_set_alpha,
+  gui_set_fullscreen,
+  gui_set_font_backend,
+  gui_set_alpha,
   x_set_sticky,
   x_set_tool_bar_position,
   x_set_inhibit_double_buffering,
@@ -7650,7 +7597,7 @@ frame_parm_handler x_frame_parm_handlers[] =
   x_set_no_accept_focus,
   x_set_z_group,
   x_set_override_redirect,
-  x_set_no_special_glyphs,
+  gui_set_no_special_glyphs,
 };
 
 void
diff --git a/src/xterm.c b/src/xterm.c
index bf6e3837a8..785a50bd3a 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -405,7 +405,7 @@ x_set_cr_source_with_gc_foreground (struct frame *f, GC gc)
 
   XGetGCValues (FRAME_X_DISPLAY (f), gc, GCForeground, &xgcv);
   color.pixel = xgcv.foreground;
-  x_query_color (f, &color);
+  x_query_colors (f, &color, 1);
   cairo_set_source_rgb (FRAME_CR_CONTEXT (f), color.red / 65535.0,
 			color.green / 65535.0, color.blue / 65535.0);
 }
@@ -418,7 +418,7 @@ x_set_cr_source_with_gc_background (struct frame *f, GC gc)
 
   XGetGCValues (FRAME_X_DISPLAY (f), gc, GCBackground, &xgcv);
   color.pixel = xgcv.background;
-  x_query_color (f, &color);
+  x_query_colors (f, &color, 1);
   cairo_set_source_rgb (FRAME_CR_CONTEXT (f), color.red / 65535.0,
 			color.green / 65535.0, color.blue / 65535.0);
 }
@@ -906,7 +906,7 @@ x_find_topmost_parent (struct frame *f)
 
 #define OPAQUE  0xffffffff
 
-void
+static void
 x_set_frame_alpha (struct frame *f)
 {
   struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
@@ -2355,16 +2355,6 @@ x_query_colors (struct frame *f, XColor *colors, int ncolors)
 }
 
 
-/* On frame F, translate pixel color to RGB values for the color in
-   COLOR.  Use cached information, if available.  */
-
-void
-x_query_color (struct frame *f, XColor *color)
-{
-  x_query_colors (f, color, 1);
-}
-
-
 /* On frame F, translate the color name to RGB values.  Use cached
    information, if possible.
 
@@ -2528,7 +2518,7 @@ x_copy_color (struct frame *f, unsigned long pixel)
   color.pixel = pixel;
   block_input ();
   /* The color could still be found in the color_cells array.  */
-  x_query_color (f, &color);
+  x_query_colors (f, &color, 1);
   XAllocColor (FRAME_X_DISPLAY (f), FRAME_X_COLORMAP (f), &color);
   unblock_input ();
 #ifdef DEBUG_X_COLORS
@@ -2569,7 +2559,7 @@ x_alloc_lighter_color (struct frame *f, Display *display, Colormap cmap,
 
   /* Get RGB color values.  */
   color.pixel = *pixel;
-  x_query_color (f, &color);
+  x_query_colors (f, &color, 1);
 
   /* Change RGB values by specified FACTOR.  Avoid overflow!  */
   eassert (factor >= 0);
@@ -4950,7 +4940,7 @@ x_emacs_to_x_modifiers (struct x_display_info *dpyinfo, intmax_t state)
 /* Convert a keysym to its name.  */
 
 char *
-x_get_keysym_name (int keysym)
+get_keysym_name (int keysym)
 {
   char *value;
 
@@ -5156,7 +5146,7 @@ XTmouse_position (struct frame **fp, int insist, Lisp_Object *bar_window,
 
 	x_catch_errors (FRAME_X_DISPLAY (*fp));
 
-	if (x_mouse_grabbed (dpyinfo))
+	if (gui_mouse_grabbed (dpyinfo))
 	  {
 	    /* If mouse was grabbed on a frame, give coords for that frame
 	       even if the mouse is now outside it.  */
@@ -8184,7 +8174,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
       if (event->xunmap.window == tip_window)
         {
           tip_window = None;
-          x_redo_mouse_highlight (dpyinfo);
+          gui_redo_mouse_highlight (dpyinfo);
         }
 
       f = x_top_window_to_frame (dpyinfo, event->xunmap.window);
@@ -8671,7 +8661,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
         previous_help_echo_string = help_echo_string;
         help_echo_string = Qnil;
 
-	f = (x_mouse_grabbed (dpyinfo) ? dpyinfo->last_mouse_frame
+	f = (gui_mouse_grabbed (dpyinfo) ? dpyinfo->last_mouse_frame
 	     : x_window_to_frame (dpyinfo, event->xmotion.window));
 
         if (hlinfo->mouse_face_hidden)
@@ -8918,7 +8908,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
 	dpyinfo->last_mouse_glyph_frame = NULL;
 	x_display_set_last_user_time (dpyinfo, event->xbutton.time);
 
-	if (x_mouse_grabbed (dpyinfo))
+	if (gui_mouse_grabbed (dpyinfo))
 	  f = dpyinfo->last_mouse_frame;
 	else
 	  {
@@ -9572,7 +9562,7 @@ x_bitmap_icon (struct frame *f, Lisp_Object file)
       if (xg_set_icon (f, file))
 	return false;
 #endif /* USE_GTK */
-      bitmap_id = x_create_bitmap_from_file (f, file);
+      bitmap_id = gui_create_bitmap_from_file (f, file);
       x_create_bitmap_mask (f, bitmap_id);
     }
   else
@@ -9602,8 +9592,8 @@ x_bitmap_icon (struct frame *f, Lisp_Object file)
 	  /* If all else fails, use the (black and white) xbm image. */
 	  if (rc == -1)
 	    {
-	      rc = x_create_bitmap_from_data (f, (char *) gnu_xbm_bits,
-					      gnu_xbm_width, gnu_xbm_height);
+              rc = gui_create_bitmap_from_data (f, (char *) gnu_xbm_bits,
+                                                gnu_xbm_width, gnu_xbm_height);
 	      if (rc == -1)
 		return true;
 
@@ -9616,7 +9606,7 @@ x_bitmap_icon (struct frame *f, Lisp_Object file)
 	 this increments the ref-count one extra time.
 	 As a result, the GNU bitmap and mask are never freed.
 	 That way, we don't have to worry about allocating it again.  */
-      x_reference_bitmap (f, FRAME_DISPLAY_INFO (f)->icon_bitmap_id);
+      gui_reference_bitmap (f, FRAME_DISPLAY_INFO (f)->icon_bitmap_id);
 
       bitmap_id = FRAME_DISPLAY_INFO (f)->icon_bitmap_id;
     }
@@ -10018,7 +10008,7 @@ x_io_error_quitter (Display *display)
    frame.  If it is negative, generate a new fontset from
    FONT-OBJECT.  */
 
-Lisp_Object
+static Lisp_Object
 x_new_font (struct frame *f, Lisp_Object font_object, int fontset)
 {
   struct font *font = XFONT_OBJECT (font_object);
@@ -10390,7 +10380,7 @@ x_calc_absolute_position (struct frame *f)
 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
    to really change the position, and 0 when calling from
    x_make_frame_visible (in that case, XOFF and YOFF are the current
-   position values).  It is -1 when calling from x_set_frame_parameters,
+   position values).  It is -1 when calling from gui_set_frame_parameters,
    which means, do adjust for borders but don't change the gravity.  */
 
 void
@@ -11274,7 +11264,7 @@ x_set_window_size_1 (struct frame *f, bool change_gravity,
 	/* Try to restore fullscreen state.  */
 	{
 	  store_frame_param (f, Qfullscreen, fullscreen);
-	  x_set_fullscreen (f, fullscreen, fullscreen);
+	  gui_set_fullscreen (f, fullscreen, fullscreen);
 	}
     }
   else
@@ -11392,9 +11382,18 @@ x_lower_frame (struct frame *f)
     }
 }
 
+static void
+XTframe_raise_lower (struct frame *f, bool raise_flag)
+{
+  if (raise_flag)
+    x_raise_frame (f);
+  else
+    x_lower_frame (f);
+}
+
 /* Request focus with XEmbed */
 
-void
+static void
 xembed_request_focus (struct frame *f)
 {
   /* See XEmbed Protocol Specification at
@@ -11406,7 +11405,7 @@ xembed_request_focus (struct frame *f)
 
 /* Activate frame with Extended Window Manager Hints */
 
-void
+static void
 x_ewmh_activate_frame (struct frame *f)
 {
   /* See Window Manager Specification/Extended Window Manager Hints at
@@ -11425,14 +11424,42 @@ x_ewmh_activate_frame (struct frame *f)
     }
 }
 
+/* In certain situations, when the window manager follows a
+   click-to-focus policy, there seems to be no way around calling
+   XSetInputFocus to give another frame the input focus .
+
+   In an ideal world, XSetInputFocus should generally be avoided so
+   that applications don't interfere with the window manager's focus
+   policy.  But I think it's okay to use when it's clearly done
+   following a user-command.  */
+
 static void
-XTframe_raise_lower (struct frame *f, bool raise_flag)
+x_focus_frame (struct frame *f, bool noactivate)
 {
-  if (raise_flag)
-    x_raise_frame (f);
+  Display *dpy = FRAME_X_DISPLAY (f);
+
+  block_input ();
+  x_catch_errors (dpy);
+
+  if (FRAME_X_EMBEDDED_P (f))
+    {
+      /* For Xembedded frames, normally the embedder forwards key
+	 events.  See XEmbed Protocol Specification at
+	 http://freedesktop.org/wiki/Specifications/xembed-spec  */
+      xembed_request_focus (f);
+    }
   else
-    x_lower_frame (f);
+    {
+      XSetInputFocus (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
+		      RevertToParent, CurrentTime);
+      if (!noactivate)
+	x_ewmh_activate_frame (f);
+    }
+
+  x_uncatch_errors ();
+  unblock_input ();
 }
+
 \f
 /* XEmbed implementation.  */
 
@@ -11513,7 +11540,7 @@ x_make_frame_visible (struct frame *f)
 
   block_input ();
 
-  x_set_bitmap_icon (f);
+  gui_set_bitmap_icon (f);
 
   if (! FRAME_VISIBLE_P (f))
     {
@@ -11690,6 +11717,15 @@ x_make_frame_invisible (struct frame *f)
   unblock_input ();
 }
 
+static void
+x_make_frame_visible_invisible (struct frame *f, bool visible)
+{
+  if (visible)
+    x_make_frame_visible (f);
+  else
+    x_make_frame_invisible (f);
+}
+
 /* Change window state from mapped to iconified.  */
 
 void
@@ -11708,7 +11744,7 @@ x_iconify_frame (struct frame *f)
 
   block_input ();
 
-  x_set_bitmap_icon (f);
+  gui_set_bitmap_icon (f);
 
 #if defined (USE_GTK)
   if (FRAME_GTK_OUTER_WIDGET (f))
@@ -13099,6 +13135,8 @@ x_activate_timeout_atimer (void)
 \f
 /* Set up use of X before we make the first connection.  */
 
+extern frame_parm_handler x_frame_parm_handlers[];
+
 static struct redisplay_interface x_redisplay_interface =
   {
     x_frame_parm_handlers,
@@ -13126,6 +13164,7 @@ static struct redisplay_interface x_redisplay_interface =
     x_draw_glyph_string,
     x_define_frame_cursor,
     x_clear_frame_area,
+    x_clear_under_internal_border,
     x_draw_window_cursor,
     x_draw_vertical_window_border,
     x_draw_window_divider,
@@ -13157,7 +13196,7 @@ x_delete_terminal (struct terminal *terminal)
   /* Normally, the display is available...  */
   if (dpyinfo->display)
     {
-      x_destroy_all_bitmaps (dpyinfo);
+      gui_destroy_all_bitmaps (dpyinfo);
       XSetCloseDownMode (dpyinfo->display, DestroyAll);
 
       /* Whether or not XCloseDisplay destroys the associated resource
@@ -13242,15 +13281,26 @@ x_create_terminal (struct x_display_info *dpyinfo)
   terminal->frame_up_to_date_hook = XTframe_up_to_date;
   terminal->buffer_flipping_unblocked_hook = XTbuffer_flipping_unblocked_hook;
   terminal->mouse_position_hook = XTmouse_position;
+  terminal->focus_frame_hook = x_focus_frame;
   terminal->frame_rehighlight_hook = XTframe_rehighlight;
   terminal->frame_raise_lower_hook = XTframe_raise_lower;
+  terminal->frame_visible_invisible_hook = x_make_frame_visible_invisible;
   terminal->fullscreen_hook = XTfullscreen_hook;
+  terminal->iconify_frame_hook = x_iconify_frame;
+  terminal->set_frame_alpha_hook = x_set_frame_alpha;
+  terminal->set_new_font_hook = x_new_font;
+  terminal->implicit_set_name_hook = x_implicitly_set_name;
   terminal->menu_show_hook = x_menu_show;
 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
   terminal->popup_dialog_hook = xw_popup_dialog;
+#endif
+#ifndef HAVE_EXT_TOOL_BAR
+  terminal->change_tool_bar_height_hook = x_change_tool_bar_height;
 #endif
   terminal->set_vertical_scroll_bar_hook = XTset_vertical_scroll_bar;
   terminal->set_horizontal_scroll_bar_hook = XTset_horizontal_scroll_bar;
+  terminal->set_scroll_bar_default_width_hook = x_set_scroll_bar_default_width;
+  terminal->set_scroll_bar_default_height_hook = x_set_scroll_bar_default_height;
   terminal->condemn_scroll_bars_hook = XTcondemn_scroll_bars;
   terminal->redeem_scroll_bar_hook = XTredeem_scroll_bar;
   terminal->judge_scroll_bars_hook = XTjudge_scroll_bars;
diff --git a/src/xterm.h b/src/xterm.h
index c5ad38650c..a5313cf8f9 100644
--- a/src/xterm.h
+++ b/src/xterm.h
@@ -1103,8 +1103,12 @@ extern bool x_had_errors_p (Display *);
 extern void x_uncatch_errors (void);
 extern void x_uncatch_errors_after_check (void);
 extern void x_clear_errors (Display *);
-extern void xembed_request_focus (struct frame *);
-extern void x_ewmh_activate_frame (struct frame *);
+extern void x_make_frame_visible (struct frame *f)
+extern void x_make_frame_invisible (struct frame *f)
+extern void x_iconify_frame (struct frame *f);
+extern void x_free_frame_resources (struct frame *);
+extern void x_wm_set_size_hint (struct frame *, long, bool);
+
 extern void x_delete_terminal (struct terminal *terminal);
 extern unsigned long x_copy_color (struct frame *, unsigned long);
 #ifdef USE_X_TOOLKIT
@@ -1117,7 +1121,7 @@ extern bool x_alloc_lighter_color_for_widget (Widget, Display *, Colormap,
 					      double, int);
 #endif
 extern bool x_alloc_nearest_color (struct frame *, Colormap, XColor *);
-extern void x_query_color (struct frame *f, XColor *);
+extern void x_query_colors (struct frame *f, XColor *, int);
 extern void x_clear_area (struct frame *f, int, int, int, int);
 #if !defined USE_X_TOOLKIT && !defined USE_GTK
 extern void x_mouse_leave (struct x_display_info *);
@@ -1194,6 +1198,13 @@ extern void x_clear_under_internal_border (struct frame *f);
 extern void tear_down_x_back_buffer (struct frame *f);
 extern void initial_set_up_x_back_buffer (struct frame *f);
 
+/* Defined in xfns.c.  */
+extern void x_real_positions (struct frame *, int *, int *);
+extern void x_change_tool_bar_height (struct frame *, int)
+extern void x_implicitly_set_name (struct frame *, Lisp_Object, Lisp_Object);
+extern void x_set_scroll_bar_default_width (struct frame *);
+extern void x_set_scroll_bar_default_height (struct frame *);
+
 /* Defined in xselect.c.  */
 
 extern void x_handle_property_notify (const XPropertyEvent *);
-- 
2.21.0


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #5: 0004-Rename-non-X-x_-identifiers-2.patch --]
[-- Type: text/x-patch, Size: 128424 bytes --]

From f17f408a5832627be89e627931bdda04f0ccccac Mon Sep 17 00:00:00 2001
From: Alexander Gramiak <agrambot@gmail.com>
Date: Sat, 13 Apr 2019 09:12:30 -0600
Subject: [PATCH 4/5] Rename non-X x_* identifiers 2

* src/alloc.c:
* src/frame.c:
* src/xdisp.c: Use FRAME_OUTPUT_DATA instead of FRAME_X_OUTPUT.

* src/termhooks.c (frame_visible_invisible_hook, set_window_size_hook)
(set_frame_offset_hook, set_bitmap_icon_hook, activate_menubar_hook)
(get_string_resource_hook): New terminal hooks.
---
 src/alloc.c      |   2 +-
 src/dispextern.h |  36 ++++-----
 src/dispnew.c    |   2 +-
 src/fontset.c    |   2 +-
 src/frame.c      | 202 ++++++++++++++++++++++++-----------------------
 src/frame.h      |  31 ++++----
 src/image.c      |  44 +++++------
 src/keyboard.c   |   6 +-
 src/menu.h       |   3 +
 src/nsfns.m      |  92 ++++++++++++---------
 src/nsgui.h      |   3 -
 src/nsmenu.m     |   2 +-
 src/nsterm.h     |  11 ++-
 src/nsterm.m     |  24 +++---
 src/termhooks.h  |  38 ++++++++-
 src/w32fns.c     | 122 +++++++++++++++-------------
 src/w32gui.h     |   2 -
 src/w32menu.c    |   2 +-
 src/w32reg.c     |  15 ++--
 src/w32term.c    |  27 ++++---
 src/w32term.h    |  18 +++--
 src/window.c     |  14 ++--
 src/xdisp.c      |  78 +++++++++---------
 src/xfaces.c     |  40 +++++-----
 src/xfns.c       | 125 ++++++++++++++++++-----------
 src/xrdb.c       |  17 ++--
 src/xterm.c      |  63 ++++++++-------
 src/xterm.h      |  12 ++-
 28 files changed, 581 insertions(+), 452 deletions(-)

diff --git a/src/alloc.c b/src/alloc.c
index dd783863be..008c8fde9a 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -6517,7 +6517,7 @@ mark_frame (struct Lisp_Vector *ptr)
   mark_vectorlike (&ptr->header);
   mark_face_cache (f->face_cache);
 #ifdef HAVE_WINDOW_SYSTEM
-  if (FRAME_WINDOW_P (f) && FRAME_X_OUTPUT (f))
+  if (FRAME_WINDOW_P (f) && FRAME_OUTPUT_DATA (f))
     {
       struct font *font = FRAME_FONT (f);
 
diff --git a/src/dispextern.h b/src/dispextern.h
index d42b0359ed..4851fc6ba0 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -1680,7 +1680,7 @@ struct face
 
   /* True means that colors of this face may not be freed because they
      have been copied bitwise from a base face (see
-     realize_x_face).  */
+     realize_gui_face).  */
   bool_bf colors_copied_bitwise_p : 1;
 
   /* If non-zero, use overstrike (to simulate bold-face).  */
@@ -3352,19 +3352,21 @@ extern bool buffer_flipping_blocked_p (void);
 
 #ifdef HAVE_WINDOW_SYSTEM
 
-extern ptrdiff_t x_bitmap_pixmap (struct frame *, ptrdiff_t);
-extern void gui_reference_bitmap (struct frame *, ptrdiff_t);
-extern ptrdiff_t gui_create_bitmap_from_data (struct frame *, char *,
-					    unsigned int, unsigned int);
-extern ptrdiff_t gui_create_bitmap_from_file (struct frame *, Lisp_Object);
+extern ptrdiff_t image_bitmap_pixmap (struct frame *, ptrdiff_t);
+extern void image_reference_bitmap (struct frame *, ptrdiff_t);
+extern ptrdiff_t image_create_bitmap_from_data (struct frame *, char *,
+                                                unsigned int, unsigned int);
+extern ptrdiff_t image_create_bitmap_from_file (struct frame *, Lisp_Object);
 #if defined HAVE_XPM && defined HAVE_X_WINDOWS && !defined USE_GTK
 extern ptrdiff_t x_create_bitmap_from_xpm_data (struct frame *, const char **);
 #endif
-#ifndef x_destroy_bitmap
-extern void x_destroy_bitmap (struct frame *, ptrdiff_t);
+#ifndef image_destroy_bitmap
+extern void image_destroy_bitmap (struct frame *, ptrdiff_t);
 #endif
-extern void gui_destroy_all_bitmaps (Display_Info *);
+extern void image_destroy_all_bitmaps (Display_Info *);
+#ifdef HAVE_X_WINDOWS
 extern void x_create_bitmap_mask (struct frame *, ptrdiff_t);
+#endif
 extern Lisp_Object gui_find_image_file (Lisp_Object);
 
 void x_kill_gs_process (Pixmap, struct frame *);
@@ -3586,19 +3588,17 @@ enum resource_types
 };
 
 extern Display_Info *check_x_display_info (Lisp_Object);
-extern Lisp_Object x_get_arg (Display_Info *, Lisp_Object,
-                              Lisp_Object, const char *, const char *class,
-                              enum resource_types);
-extern Lisp_Object x_frame_get_and_record_arg (struct frame *, Lisp_Object,
-                                               Lisp_Object,
-					       const char *, const char *,
-                                               enum resource_types);
+extern Lisp_Object gui_display_get_arg (Display_Info *, Lisp_Object,
+                                        Lisp_Object, const char *, const char *,
+                                        enum resource_types);
+extern Lisp_Object gui_frame_get_and_record_arg (struct frame *, Lisp_Object,
+                                                 Lisp_Object,
+                                                 const char *, const char *,
+                                                 enum resource_types);
 extern Lisp_Object gui_default_parameter (struct frame *, Lisp_Object,
                                           Lisp_Object, Lisp_Object,
                                           const char *, const char *,
                                           enum resource_types);
-extern char *x_get_string_resource (XrmDatabase, const char *,
-				    const char *);
 
 #ifndef HAVE_NS /* These both used on W32 and X only.  */
 extern bool gui_mouse_grabbed (Display_Info *);
diff --git a/src/dispnew.c b/src/dispnew.c
index ccb08ec1b9..802209315f 100644
--- a/src/dispnew.c
+++ b/src/dispnew.c
@@ -5551,7 +5551,7 @@ change_frame_size_1 (struct frame *f, int new_width, int new_height,
 			* FRAME_LINE_HEIGHT (f));
 	}
 
-      /* Adjust frame size but make sure x_set_window_size does not
+      /* Adjust frame size but make sure set_window_size_hook does not
 	 get called.  */
       adjust_frame_size (f, new_width, new_height, 5, pretend,
 			 Qchange_frame_size);
diff --git a/src/fontset.c b/src/fontset.c
index 0a6edc7eb1..2c45c95c3a 100644
--- a/src/fontset.c
+++ b/src/fontset.c
@@ -1061,7 +1061,7 @@ font_for_char (struct face *face, int c, ptrdiff_t pos, Lisp_Object object)
 /* Make a realized fontset for ASCII face FACE on frame F from the
    base fontset BASE_FONTSET_ID.  If BASE_FONTSET_ID is -1, use the
    default fontset as the base.  Value is the id of the new fontset.
-   Called from realize_x_face.  */
+   Called from realize_gui_face.  */
 
 int
 make_fontset_for_ascii_face (struct frame *f, int base_fontset_id, struct face *face)
diff --git a/src/frame.c b/src/frame.c
index 48a6aa7668..b2efdb7b57 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -482,7 +482,7 @@ keep_ratio (struct frame *f, struct frame *p, int old_width, int old_height,
 	      f->top_pos = pos_y;
 	    }
 
-	  x_set_offset (f, pos_x, pos_y, -1);
+	  FRAME_TERMINAL (f)->set_frame_offset_hook (f, pos_x, pos_y, -1);
 	}
 
       if (!CONSP (keep_ratio) || !NILP (Fcar (keep_ratio)))
@@ -518,36 +518,37 @@ keep_ratio (struct frame *f, struct frame *p, int old_width, int old_height,
  * text size of F in pixels.  A value of -1 means no change is requested
  * for that direction (but the frame may still have to be resized to
  * accommodate windows with their minimum sizes).  This can either issue
- * a request to resize the frame externally (via x_set_window_size), to
+ * a request to resize the frame externally (via set_window_size_hook), to
  * resize the frame internally (via resize_frame_windows) or do nothing
  * at all.
  *
  * The argument INHIBIT can assume the following values:
  *
- * 0 means to unconditionally call x_set_window_size even if sizes
+ * 0 means to unconditionally call set_window_size_hook even if sizes
  *   apparently do not change.  Fx_create_frame uses this to pass the
  *   initial size to the window manager.
  *
- * 1 means to call x_set_window_size if the native frame size really
+ * 1 means to call set_window_size_hook if the native frame size really
  *   changes.  Fset_frame_size, Fset_frame_height, ... use this.
  *
- * 2 means to call x_set_window_size provided frame_inhibit_resize
+ * 2 means to call set_window_size_hook provided frame_inhibit_resize
  *   allows it.  The menu and tool bar code use this ("3" won't work
  *   here in general because menu and tool bar are often not counted in
  *   the frame's text height).
  *
- * 3 means call x_set_window_size if window minimum sizes must be
- *   preserved or frame_inhibit_resize allows it.  gui_set_left_fringe,
- *   gui_set_scroll_bar_width, gui_new_font ... use (or should use) this.
+ * 3 means call set_window_size_hook if window minimum sizes must be
+ *   preserved or frame_inhibit_resize allows it.
+ *   gui_set_left_fringe, gui_set_scroll_bar_width, gui_new_font
+ *   ... use (or should use) this.
  *
- * 4 means call x_set_window_size only if window minimum sizes must be
- *   preserved.  x_set_right_divider_width, x_set_border_width and the
- *   code responsible for wrapping the tool bar use this.
+ * 4 means call set_window_size_hook only if window minimum sizes must
+ *   be preserved.  x_set_right_divider_width, x_set_border_width and
+ *   the code responsible for wrapping the tool bar use this.
  *
- * 5 means to never call x_set_window_size.  change_frame_size uses
+ * 5 means to never call set_window_size_hook.  change_frame_size uses
  *   this.
  *
- * Note that even when x_set_window_size is not called, individual
+ * Note that even when set_window_size_hook is not called, individual
  * windows may have to be resized (via `window--sanitize-window-sizes')
  * in order to support minimum size constraints.
  *
@@ -570,7 +571,7 @@ adjust_frame_size (struct frame *f, int new_width, int new_height, int inhibit,
   /* The following two values are calculated from the old frame pixel
      sizes and any "new" settings for tool bar, menu bar and internal
      borders.  We do it this way to detect whether we have to call
-     x_set_window_size as consequence of the new settings.  */
+     set_window_size_hook as consequence of the new settings.  */
   int windows_width = FRAME_WINDOWS_WIDTH (f);
   int windows_height = FRAME_WINDOWS_HEIGHT (f);
   int min_windows_width, min_windows_height;
@@ -645,7 +646,7 @@ adjust_frame_size (struct frame *f, int new_width, int new_height, int inhibit,
 
 #ifdef HAVE_WINDOW_SYSTEM
   if (FRAME_WINDOW_P (f)
-      && f->can_x_set_window_size
+      && f->can_set_window_size
       && ((!inhibit_horizontal
 	   && (new_pixel_width != old_pixel_width
 	       || inhibit == 0 || inhibit == 2))
@@ -668,7 +669,11 @@ adjust_frame_size (struct frame *f, int new_width, int new_height, int inhibit,
 	 list2 (inhibit_horizontal ? Qt : Qnil,
 		inhibit_vertical ? Qt : Qnil));
 
-      x_set_window_size (f, 0, new_text_width, new_text_height, 1);
+      FRAME_TERMINAL (f)->set_window_size_hook (f,
+                                                0,
+                                                new_text_width,
+                                                new_text_height,
+                                                1);
       f->resized_p = true;
 
       return;
@@ -827,7 +832,7 @@ make_frame (bool mini_p)
   f->wants_modeline = true;
   f->redisplay = true;
   f->garbaged = true;
-  f->can_x_set_window_size = false;
+  f->can_set_window_size = false;
   f->after_make_frame = false;
   f->inhibit_horizontal_resize = false;
   f->inhibit_vertical_resize = false;
@@ -1089,7 +1094,7 @@ make_initial_frame (void)
 
   last_nonminibuf_frame = f;
 
-  f->can_x_set_window_size = true;
+  f->can_set_window_size = true;
   f->after_make_frame = true;
 
   return f;
@@ -1290,7 +1295,7 @@ affects all frames on the same terminal device.  */)
   for (tem = f->face_alist; CONSP (tem); tem = XCDR (tem))
     XSETCDR (XCAR (tem), Fcopy_sequence (XCDR (XCAR (tem))));
 
-  f->can_x_set_window_size = true;
+  f->can_set_window_size = true;
   f->after_make_frame = true;
 
   return frame;
@@ -3619,11 +3624,13 @@ bottom edge of FRAME's display.  */)
   CHECK_TYPE_RANGED_INTEGER (int, x);
   CHECK_TYPE_RANGED_INTEGER (int, y);
 
-  /* I think this should be done with a hook.  */
   if (FRAME_WINDOW_P (f))
     {
 #ifdef HAVE_WINDOW_SYSTEM
-      x_set_offset (f, XFIXNUM (x), XFIXNUM (y), 1);
+      FRAME_TERMINAL (f)->set_frame_offset_hook (f,
+                                                 XFIXNUM (x),
+                                                 XFIXNUM (y),
+                                                 1);
 #endif
     }
 
@@ -4113,7 +4120,7 @@ gui_set_frame_parameters (struct frame *f, Lisp_Object alist)
        all.  With the old setting it can get a Heisenbug when
        EmacsFrameResize intermittently provokes a delayed
        change_frame_size in the middle of adjust_frame_size.  */
-    /** 	|| (f->can_x_set_window_size && (f->new_height || f->new_width))) **/
+    /** 	|| (f->can_set_window_size && (f->new_height || f->new_width))) **/
     adjust_frame_size (f, width, height, 1, 0, Qgui_set_frame_parameters);
 
   if ((!NILP (left) || !NILP (top))
@@ -4179,7 +4186,7 @@ gui_set_frame_parameters (struct frame *f, Lisp_Object alist)
       f->win_gravity = NorthWestGravity;
 
       /* Actually set that position, and convert to absolute.  */
-      x_set_offset (f, leftpos, toppos, -1);
+      FRAME_TERMINAL (f)->set_frame_offset_hook (f, leftpos, toppos, -1);
     }
 
   if (fullscreen_change)
@@ -4187,7 +4194,7 @@ gui_set_frame_parameters (struct frame *f, Lisp_Object alist)
       Lisp_Object old_value = get_frame_param (f, Qfullscreen);
 
       frame_size_history_add
-	(f, Qx_set_fullscreen, 0, 0, list2 (old_value, fullscreen));
+	(f, Qgui_set_fullscreen, 0, 0, list2 (old_value, fullscreen));
 
       store_frame_param (f, Qfullscreen, fullscreen);
       if (!EQ (fullscreen, old_value))
@@ -4257,11 +4264,11 @@ gui_report_frame_params (struct frame *f, Lisp_Object *alistptr)
 		   /* nil means "use default height"
 		      for non-toolkit scroll bar.  */
 		   : Qnil));
-  /* FRAME_X_WINDOW is not guaranteed to return an integer.  E.g., on
-     MS-Windows it returns a value whose type is HANDLE, which is
-     actually a pointer.  Explicit casting avoids compiler
+  /* FRAME_NATIVE_WINDOW is not guaranteed to return an integer.
+     E.g., on MS-Windows it returns a value whose type is HANDLE,
+     which is actually a pointer.  Explicit casting avoids compiler
      warnings.  */
-  w = (uintptr_t) FRAME_X_WINDOW (f);
+  w = (uintptr_t) FRAME_NATIVE_WINDOW (f);
   store_in_alist (alistptr, Qwindow_id,
 		  make_formatted_string (buf, "%"pMu, w));
 #ifdef HAVE_X_WINDOWS
@@ -4280,10 +4287,10 @@ gui_report_frame_params (struct frame *f, Lisp_Object *alistptr)
   store_in_alist (alistptr, Qdisplay,
 		  XCAR (FRAME_DISPLAY_INFO (f)->name_list_element));
 
-  if (FRAME_X_OUTPUT (f)->parent_desc == FRAME_DISPLAY_INFO (f)->root_window)
+  if (FRAME_OUTPUT_DATA (f)->parent_desc == FRAME_DISPLAY_INFO (f)->root_window)
     tem = Qnil;
   else
-    tem = make_fixed_natnum ((uintptr_t) FRAME_X_OUTPUT (f)->parent_desc);
+    tem = make_fixed_natnum ((uintptr_t) FRAME_OUTPUT_DATA (f)->parent_desc);
   store_in_alist (alistptr, Qexplicit_name, (f->explicit_name ? Qt : Qnil));
   store_in_alist (alistptr, Qparent_id, tem);
   store_in_alist (alistptr, Qtool_bar_position, FRAME_TOOL_BAR_POSITION (f));
@@ -4556,7 +4563,7 @@ gui_set_left_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_val
       f->fringe_cols /* Round up.  */
 	= (new_width + FRAME_RIGHT_FRINGE_WIDTH (f) + unit - 1) / unit;
 
-      if (FRAME_X_WINDOW (f) != 0)
+      if (FRAME_NATIVE_WINDOW (f) != 0)
 	adjust_frame_size (f, -1, -1, 3, 0, Qleft_fringe);
 
       SET_FRAME_GARBAGED (f);
@@ -4580,7 +4587,7 @@ gui_set_right_fringe (struct frame *f, Lisp_Object new_value, Lisp_Object old_va
       f->fringe_cols /* Round up.  */
 	= (new_width + FRAME_LEFT_FRINGE_WIDTH (f) + unit - 1) / unit;
 
-      if (FRAME_X_WINDOW (f) != 0)
+      if (FRAME_NATIVE_WINDOW (f) != 0)
 	adjust_frame_size (f, -1, -1, 3, 0, Qright_fringe);
 
       SET_FRAME_GARBAGED (f);
@@ -4596,7 +4603,7 @@ gui_set_border_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
   if (XFIXNUM (arg) == f->border_width)
     return;
 
-  if (FRAME_X_WINDOW (f) != 0)
+  if (FRAME_NATIVE_WINDOW (f) != 0)
     error ("Cannot change the border width of a frame");
 
   f->border_width = XFIXNUM (arg);
@@ -4685,11 +4692,11 @@ gui_set_vertical_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object oldv
 	   ? vertical_scroll_bar_right
 	   : vertical_scroll_bar_none);
 
-      /* We set this parameter before creating the X window for the
-	 frame, so we can get the geometry right from the start.
+      /* We set this parameter before creating the native window for
+	 the frame, so we can get the geometry right from the start.
 	 However, if the window hasn't been created yet, we shouldn't
-	 call x_set_window_size.  */
-      if (FRAME_X_WINDOW (f))
+	 call set_window_size_hook.  */
+      if (FRAME_NATIVE_WINDOW (f))
 	adjust_frame_size (f, -1, -1, 3, 0, Qvertical_scroll_bars);
 
       SET_FRAME_GARBAGED (f);
@@ -4705,11 +4712,11 @@ gui_set_horizontal_scroll_bars (struct frame *f, Lisp_Object arg, Lisp_Object ol
     {
       f->horizontal_scroll_bars = NILP (arg) ? false : true;
 
-      /* We set this parameter before creating the X window for the
-	 frame, so we can get the geometry right from the start.
+      /* We set this parameter before creating the native window for
+	 the frame, so we can get the geometry right from the start.
 	 However, if the window hasn't been created yet, we shouldn't
-	 call x_set_window_size.  */
-      if (FRAME_X_WINDOW (f))
+	 call set_window_size_hook.  */
+      if (FRAME_NATIVE_WINDOW (f))
 	adjust_frame_size (f, -1, -1, 3, 0, Qhorizontal_scroll_bars);
 
       SET_FRAME_GARBAGED (f);
@@ -4727,7 +4734,7 @@ gui_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
     {
       FRAME_CONFIG_SCROLL_BAR_WIDTH (f) = XFIXNAT (arg);
       FRAME_CONFIG_SCROLL_BAR_COLS (f) = (XFIXNAT (arg) + unit - 1) / unit;
-      if (FRAME_X_WINDOW (f))
+      if (FRAME_NATIVE_WINDOW (f))
 	adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_width);
 
       SET_FRAME_GARBAGED (f);
@@ -4736,7 +4743,7 @@ gui_set_scroll_bar_width (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
     {
       FRAME_TERMINAL (f)->set_scroll_bar_default_width_hook (f);
 
-      if (FRAME_X_WINDOW (f))
+      if (FRAME_NATIVE_WINDOW (f))
 	adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_width);
 
       SET_FRAME_GARBAGED (f);
@@ -4757,7 +4764,7 @@ gui_set_scroll_bar_height (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
     {
       FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) = XFIXNAT (arg);
       FRAME_CONFIG_SCROLL_BAR_LINES (f) = (XFIXNAT (arg) + unit - 1) / unit;
-      if (FRAME_X_WINDOW (f))
+      if (FRAME_NATIVE_WINDOW (f))
 	adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_height);
 
       SET_FRAME_GARBAGED (f);
@@ -4766,7 +4773,7 @@ gui_set_scroll_bar_height (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
     {
       FRAME_TERMINAL (f)->set_scroll_bar_default_height_hook (f);
 
-      if (FRAME_X_WINDOW (f))
+      if (FRAME_NATIVE_WINDOW (f))
 	adjust_frame_size (f, -1, -1, 3, 0, Qscroll_bar_height);
 
       SET_FRAME_GARBAGED (f);
@@ -4942,11 +4949,13 @@ validate_x_resource_name (void)
     }
 }
 
-/* Get specified attribute from resource database RDB.
+/* Get a GUI resource, like Fx_get_resource, but for display DPYINFO.
    See Fx_get_resource below for other parameters.  */
 
-static Lisp_Object
-xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Lisp_Object component, Lisp_Object subclass)
+Lisp_Object
+gui_display_get_resource (Display_Info *dpyinfo, Lisp_Object attribute,
+                          Lisp_Object class, Lisp_Object component,
+                          Lisp_Object subclass)
 {
   CHECK_STRING (attribute);
   CHECK_STRING (class);
@@ -4999,7 +5008,10 @@ xrdb_get_resource (XrmDatabase rdb, Lisp_Object attribute, Lisp_Object class, Li
   *nz++ = '.';
   lispstpcpy (nz, attribute);
 
-  char *value = x_get_string_resource (rdb, name_key, class_key);
+  const char *value =
+    dpyinfo->terminal->get_string_resource_hook (&dpyinfo->rdb,
+                                                 name_key,
+                                                 class_key);
   SAFE_FREE();
 
   if (value && *value)
@@ -5024,28 +5036,17 @@ and the class is `Emacs.CLASS.SUBCLASS'.  */)
 {
   check_window_system (NULL);
 
-  return xrdb_get_resource (check_x_display_info (Qnil)->xrdb,
-			    attribute, class, component, subclass);
-}
-
-/* Get an X resource, like Fx_get_resource, but for display DPYINFO.  */
-
-Lisp_Object
-display_x_get_resource (Display_Info *dpyinfo, Lisp_Object attribute,
-			Lisp_Object class, Lisp_Object component,
-			Lisp_Object subclass)
-{
-  return xrdb_get_resource (dpyinfo->xrdb,
-			    attribute, class, component, subclass);
+  return gui_display_get_resource (check_x_display_info (Qnil),
+                                   attribute, class, component, subclass);
 }
 
 #if defined HAVE_X_WINDOWS && !defined USE_X_TOOLKIT && !defined USE_GTK
 /* Used when C code wants a resource value.  */
 /* Called from oldXMenu/Create.c.  */
-char *
+const char *
 x_get_resource_string (const char *attribute, const char *class)
 {
-  char *result;
+  const char *result;
   struct frame *sf = SELECTED_FRAME ();
   ptrdiff_t invocation_namelen = SBYTES (Vinvocation_name);
   USE_SAFE_ALLOCA;
@@ -5062,8 +5063,8 @@ x_get_resource_string (const char *attribute, const char *class)
   esprintf (name_key, "%s.%s", SSDATA (Vinvocation_name), attribute);
   sprintf (class_key, "%s.%s", EMACS_CLASS, class);
 
-  result = x_get_string_resource (FRAME_DISPLAY_INFO (sf)->xrdb,
-				  name_key, class_key);
+  result = gui_display_get_resource (&FRAME_DISPLAY_INFO (sf)->rdb,
+                                     name_key, class_key);
   SAFE_FREE ();
   return result;
 }
@@ -5071,18 +5072,21 @@ x_get_resource_string (const char *attribute, const char *class)
 
 /* Return the value of parameter PARAM.
 
-   First search ALIST, then Vdefault_frame_alist, then the X defaults
-   database, using ATTRIBUTE as the attribute name and CLASS as its class.
+   First search ALIST, then Vdefault_frame_alist, then the GUI
+   resource database, using ATTRIBUTE as the attribute name and CLASS
+   as its class.
 
    Convert the resource to the type specified by desired_type.
 
    If no default is specified, return Qunbound.  If you call
-   x_get_arg, make sure you deal with Qunbound in a reasonable way,
-   and don't let it get stored in any Lisp-visible variables!  */
+   gui_display_get_arg, make sure you deal with Qunbound in a
+   reasonable way, and don't let it get stored in any Lisp-visible
+   variables!  */
 
 Lisp_Object
-x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param,
-	   const char *attribute, const char *class, enum resource_types type)
+gui_display_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param,
+                     const char *attribute, const char *class,
+                     enum resource_types type)
 {
   Lisp_Object tem;
 
@@ -5112,7 +5116,7 @@ x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param,
 	{
 	  AUTO_STRING (at, attribute);
 	  AUTO_STRING (cl, class);
-	  tem = display_x_get_resource (dpyinfo, at, cl, Qnil, Qnil);
+	  tem = gui_display_get_resource (dpyinfo, at, cl, Qnil, Qnil);
 
 	  if (NILP (tem))
 	    return Qunbound;
@@ -5179,26 +5183,26 @@ x_get_arg (Display_Info *dpyinfo, Lisp_Object alist, Lisp_Object param,
 }
 
 static Lisp_Object
-x_frame_get_arg (struct frame *f, Lisp_Object alist, Lisp_Object param,
-		 const char *attribute, const char *class,
-		 enum resource_types type)
+gui_frame_get_arg (struct frame *f, Lisp_Object alist, Lisp_Object param,
+                   const char *attribute, const char *class,
+                   enum resource_types type)
 {
-  return x_get_arg (FRAME_DISPLAY_INFO (f),
-		    alist, param, attribute, class, type);
+  return gui_display_get_arg (FRAME_DISPLAY_INFO (f),
+                              alist, param, attribute, class, type);
 }
 
-/* Like x_frame_get_arg, but also record the value in f->param_alist.  */
+/* Like gui_frame_get_arg, but also record the value in f->param_alist.  */
 
 Lisp_Object
-x_frame_get_and_record_arg (struct frame *f, Lisp_Object alist,
-			    Lisp_Object param,
-			    const char *attribute, const char *class,
-			    enum resource_types type)
+gui_frame_get_and_record_arg (struct frame *f, Lisp_Object alist,
+                              Lisp_Object param,
+                              const char *attribute, const char *class,
+                              enum resource_types type)
 {
   Lisp_Object value;
 
-  value = x_get_arg (FRAME_DISPLAY_INFO (f), alist, param,
-		     attribute, class, type);
+  value = gui_display_get_arg (FRAME_DISPLAY_INFO (f), alist, param,
+                               attribute, class, type);
   if (! NILP (value) && ! EQ (value, Qunbound))
     store_frame_param (f, param, value);
 
@@ -5219,7 +5223,7 @@ gui_default_parameter (struct frame *f, Lisp_Object alist, Lisp_Object prop,
 {
   Lisp_Object tem;
 
-  tem = x_frame_get_arg (f, alist, prop, xprop, xclass, type);
+  tem = gui_frame_get_arg (f, alist, prop, xprop, xclass, type);
   if (EQ (tem, Qunbound))
     tem = deflt;
   AUTO_FRAME_ARG (arg, prop, tem);
@@ -5453,8 +5457,8 @@ gui_figure_window_size (struct frame *f, Lisp_Object parms, bool toolbar_p,
      override what we specify below.  */
   f->new_width = f->new_height = 0;
 
-  height = x_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
-  width = x_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
+  height = gui_display_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
+  width = gui_display_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
   if (!EQ (width, Qunbound) || !EQ (height, Qunbound))
     {
       if (!EQ (width, Qunbound))
@@ -5531,16 +5535,18 @@ gui_figure_window_size (struct frame *f, Lisp_Object parms, bool toolbar_p,
 	    }
 	}
 
-      user_size = x_get_arg (dpyinfo, parms, Quser_size, 0, 0, RES_TYPE_NUMBER);
+      user_size = gui_display_get_arg (dpyinfo, parms, Quser_size, 0, 0,
+                                       RES_TYPE_NUMBER);
       if (!NILP (user_size) && !EQ (user_size, Qunbound))
 	window_prompting |= USSize;
       else
 	window_prompting |= PSize;
     }
 
-  top = x_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
-  left = x_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
-  user_position = x_get_arg (dpyinfo, parms, Quser_position, 0, 0, RES_TYPE_NUMBER);
+  top = gui_display_get_arg (dpyinfo, parms, Qtop, 0, 0, RES_TYPE_NUMBER);
+  left = gui_display_get_arg (dpyinfo, parms, Qleft, 0, 0, RES_TYPE_NUMBER);
+  user_position = gui_display_get_arg (dpyinfo, parms, Quser_position, 0, 0,
+                                       RES_TYPE_NUMBER);
   if (! EQ (top, Qunbound) || ! EQ (left, Qunbound))
     {
       if (EQ (top, Qminus))
@@ -5853,15 +5859,15 @@ syms_of_frame (void)
   DEFSYM (QEmacsFrameResize, "EmacsFrameResize");
   DEFSYM (Qset_frame_size, "set-frame-size");
   DEFSYM (Qframe_inhibit_resize, "frame-inhibit-resize");
-  DEFSYM (Qx_set_fullscreen, "x-set-fullscreen");
+  DEFSYM (Qgui_set_fullscreen, "gui-set-fullscreen");
   DEFSYM (Qx_check_fullscreen, "x-check-fullscreen");
   DEFSYM (Qxg_frame_resized, "xg-frame-resized");
   DEFSYM (Qxg_frame_set_char_size_1, "xg-frame-set-char-size-1");
   DEFSYM (Qxg_frame_set_char_size_2, "xg-frame-set-char-size-2");
   DEFSYM (Qxg_frame_set_char_size_3, "xg-frame-set-char-size-3");
-  DEFSYM (Qx_set_window_size_1, "x-set-window-size-1");
-  DEFSYM (Qx_set_window_size_2, "x-set-window-size-2");
-  DEFSYM (Qx_set_window_size_3, "x-set-window-size-3");
+  DEFSYM (Qgui_set_window_size_1, "gui-set-window-size-1");
+  DEFSYM (Qgui_set_window_size_2, "gui-set-window-size-2");
+  DEFSYM (Qgui_set_window_size_3, "gui-set-window-size-3");
   DEFSYM (Qxg_change_toolbar_position, "xg-change-toolbar-position");
   DEFSYM (Qx_net_wm_state, "x-net-wm-state");
   DEFSYM (Qx_handle_net_wm_state, "x-handle-net-wm-state");
@@ -5872,8 +5878,8 @@ syms_of_frame (void)
   DEFSYM (Qchange_frame_size, "change-frame-size");
   DEFSYM (Qxg_frame_set_char_size, "xg-frame-set-char-size");
   DEFSYM (Qset_window_configuration, "set-window-configuration");
-  DEFSYM (Qx_create_frame_1, "x-create-frame-1");
-  DEFSYM (Qx_create_frame_2, "x-create-frame-2");
+  DEFSYM (Qgui_create_frame_1, "gui-create-frame-1");
+  DEFSYM (Qgui_create_frame_2, "gui-create-frame-2");
   DEFSYM (Qterminal_frame, "terminal-frame");
 
 #ifdef HAVE_NS
diff --git a/src/frame.h b/src/frame.h
index 7b5aeaa136..eca4eb45a1 100644
--- a/src/frame.h
+++ b/src/frame.h
@@ -397,9 +397,9 @@ struct frame
      in pixels.  */
   bool_bf new_pixelwise : 1;
 
-  /* True means x_set_window_size requests can be processed for this
-     frame.  */
-  bool_bf can_x_set_window_size : 1;
+  /* True means set_window_size_hook requests can be processed for
+     this frame.  */
+  bool_bf can_set_window_size : 1;
 
   /* Set to true after this frame was made by `make-frame'.  */
   bool_bf after_make_frame : 1;
@@ -543,6 +543,10 @@ struct frame
   }
   output_data;
 
+  /* Interface for accessing frame data generic constructs that are
+     device-dependent.  */
+  struct frame_output_interface *foif;
+
   /* List of font-drivers available on the frame.  */
   struct font_driver_list *font_driver_list;
 
@@ -786,8 +790,8 @@ default_pixels_per_inch_y (void)
 #define FRAME_NS_P(f) ((f)->output_method == output_ns)
 #endif
 
-/* FRAME_WINDOW_P tests whether the frame is a window, and is
-   defined to be the predicate for the window system being used.  */
+/* FRAME_WINDOW_P tests whether the frame is a graphical window system
+   frame.  */
 
 #ifdef HAVE_X_WINDOWS
 #define FRAME_WINDOW_P(f) FRAME_X_P (f)
@@ -1573,18 +1577,15 @@ extern void gui_set_no_special_glyphs (struct frame *, Lisp_Object, Lisp_Object)
 
 extern void validate_x_resource_name (void);
 
-extern Lisp_Object display_x_get_resource (Display_Info *,
-					   Lisp_Object attribute,
-					   Lisp_Object class,
-					   Lisp_Object component,
-					   Lisp_Object subclass);
+extern Lisp_Object gui_display_get_resource (Display_Info *,
+                                             Lisp_Object attribute,
+                                             Lisp_Object class,
+                                             Lisp_Object component,
+                                             Lisp_Object subclass);
 
 extern void set_frame_menubar (struct frame *f, bool first_time, bool deep_p);
-extern void x_set_window_size (struct frame *f, bool change_gravity,
-			       int width, int height, bool pixelwise);
 extern Lisp_Object gui_get_focus_frame (struct frame *);
 extern void frame_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y);
-extern void x_activate_menubar (struct frame *);
 extern void free_frame_menubar (struct frame *);
 extern bool frame_ancestor_p (struct frame *af, struct frame *df);
 extern enum internal_border_part frame_internal_border_part (struct frame *f, int x, int y);
@@ -1599,8 +1600,6 @@ extern void x_sync (struct frame *);
 
 #ifndef HAVE_NS
 
-extern bool x_bitmap_icon (struct frame *, Lisp_Object);
-
 /* Set F's bitmap icon, if specified among F's parameters.  */
 
 INLINE void
@@ -1609,7 +1608,7 @@ gui_set_bitmap_icon (struct frame *f)
   Lisp_Object obj = assq_no_quit (Qicon_type, f->param_alist);
 
   if (CONSP (obj) && !NILP (XCDR (obj)))
-    x_bitmap_icon (f, XCDR (obj));
+    FRAME_TERMINAL (f)->set_bitmap_icon_hook (f, XCDR (obj));
 }
 
 #endif /* !HAVE_NS */
diff --git a/src/image.c b/src/image.c
index 2b47aebe99..1885f751f5 100644
--- a/src/image.c
+++ b/src/image.c
@@ -129,8 +129,8 @@ static unsigned long *colors_in_color_table (int *n);
    Bitmap indices are guaranteed to be > 0, so a negative number can
    be used to indicate no bitmap.
 
-   If you use gui_create_bitmap_from_data, then you must keep track of
-   the bitmaps yourself.  That is, creating a bitmap from the same
+   If you use image_create_bitmap_from_data, then you must keep track
+   of the bitmaps yourself.  That is, creating a bitmap from the same
    data more than once will not be caught.  */
 
 #ifdef HAVE_NS
@@ -169,7 +169,7 @@ x_bitmap_width (struct frame *f, ptrdiff_t id)
 
 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI)
 ptrdiff_t
-x_bitmap_pixmap (struct frame *f, ptrdiff_t id)
+image_bitmap_pixmap (struct frame *f, ptrdiff_t id)
 {
   /* HAVE_NTGUI needs the explicit cast here.  */
   return (ptrdiff_t) FRAME_DISPLAY_INFO (f)->bitmaps[id - 1].pixmap;
@@ -187,7 +187,7 @@ x_bitmap_mask (struct frame *f, ptrdiff_t id)
 /* Allocate a new bitmap record.  Returns index of new record.  */
 
 static ptrdiff_t
-gui_allocate_bitmap_record (struct frame *f)
+image_allocate_bitmap_record (struct frame *f)
 {
   Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f);
   ptrdiff_t i;
@@ -208,7 +208,7 @@ gui_allocate_bitmap_record (struct frame *f)
 /* Add one reference to the reference count of the bitmap with id ID.  */
 
 void
-gui_reference_bitmap (struct frame *f, ptrdiff_t id)
+image_reference_bitmap (struct frame *f, ptrdiff_t id)
 {
   ++FRAME_DISPLAY_INFO (f)->bitmaps[id - 1].refcount;
 }
@@ -216,8 +216,8 @@ gui_reference_bitmap (struct frame *f, ptrdiff_t id)
 /* Create a bitmap for frame F from a HEIGHT x WIDTH array of bits at BITS.  */
 
 ptrdiff_t
-gui_create_bitmap_from_data (struct frame *f, char *bits,
-                             unsigned int width, unsigned int height)
+image_create_bitmap_from_data (struct frame *f, char *bits,
+                               unsigned int width, unsigned int height)
 {
   Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f);
   ptrdiff_t id;
@@ -247,7 +247,7 @@ gui_create_bitmap_from_data (struct frame *f, char *bits,
       return -1;
 #endif
 
-  id = gui_allocate_bitmap_record (f);
+  id = image_allocate_bitmap_record (f);
 
 #ifdef HAVE_NS
   dpyinfo->bitmaps[id - 1].img = bitmap;
@@ -277,7 +277,7 @@ gui_create_bitmap_from_data (struct frame *f, char *bits,
 /* Create bitmap from file FILE for frame F.  */
 
 ptrdiff_t
-gui_create_bitmap_from_file (struct frame *f, Lisp_Object file)
+image_create_bitmap_from_file (struct frame *f, Lisp_Object file)
 {
 #ifdef HAVE_NTGUI
   return -1;  /* W32_TODO : bitmap support */
@@ -293,7 +293,7 @@ gui_create_bitmap_from_file (struct frame *f, Lisp_Object file)
       return -1;
 
 
-  id = gui_allocate_bitmap_record (f);
+  id = image_allocate_bitmap_record (f);
   dpyinfo->bitmaps[id - 1].img = bitmap;
   dpyinfo->bitmaps[id - 1].refcount = 1;
   dpyinfo->bitmaps[id - 1].file = xlispstrdup (file);
@@ -336,7 +336,7 @@ gui_create_bitmap_from_file (struct frame *f, Lisp_Object file)
   if (result != BitmapSuccess)
     return -1;
 
-  id = gui_allocate_bitmap_record (f);
+  id = image_allocate_bitmap_record (f);
   dpyinfo->bitmaps[id - 1].pixmap = bitmap;
   dpyinfo->bitmaps[id - 1].have_mask = false;
   dpyinfo->bitmaps[id - 1].refcount = 1;
@@ -378,7 +378,7 @@ free_bitmap_record (Display_Info *dpyinfo, Bitmap_Record *bm)
 /* Remove reference to bitmap with id number ID.  */
 
 void
-x_destroy_bitmap (struct frame *f, ptrdiff_t id)
+image_destroy_bitmap (struct frame *f, ptrdiff_t id)
 {
   Display_Info *dpyinfo = FRAME_DISPLAY_INFO (f);
 
@@ -398,7 +398,7 @@ x_destroy_bitmap (struct frame *f, ptrdiff_t id)
 /* Free all the bitmaps for the display specified by DPYINFO.  */
 
 void
-gui_destroy_all_bitmaps (Display_Info *dpyinfo)
+image_destroy_all_bitmaps (Display_Info *dpyinfo)
 {
   ptrdiff_t i;
   Bitmap_Record *bm = dpyinfo->bitmaps;
@@ -411,7 +411,7 @@ gui_destroy_all_bitmaps (Display_Info *dpyinfo)
 }
 
 #ifndef HAVE_XRENDER
-/* Required for the definition of x_create_x_image_and_pixmap below.  */
+/* Required for the definition of gui_create_x_image_and_pixmap below.  */
 typedef void Picture;
 #endif
 
@@ -465,7 +465,7 @@ x_create_bitmap_mask (struct frame *f, ptrdiff_t id)
   if (!(id > 0))
     return;
 
-  pixmap = x_bitmap_pixmap (f, id);
+  pixmap = image_bitmap_pixmap (f, id);
   width = x_bitmap_width (f, id);
   height = x_bitmap_height (f, id);
 
@@ -3774,7 +3774,7 @@ x_create_bitmap_from_xpm_data (struct frame *f, const char **bits)
       return -1;
     }
 
-  id = gui_allocate_bitmap_record (f);
+  id = image_allocate_bitmap_record (f);
   dpyinfo->bitmaps[id - 1].pixmap = bitmap;
   dpyinfo->bitmaps[id - 1].have_mask = true;
   dpyinfo->bitmaps[id - 1].mask = mask;
@@ -4910,7 +4910,7 @@ static int laplace_matrix[9] = {
    allocated with xmalloc; it must be freed by the caller.  */
 
 static XColor *
-x_to_xcolors (struct frame *f, struct image *img, bool rgb_p)
+image_to_xcolors (struct frame *f, struct image *img, bool rgb_p)
 {
   int x, y;
   XColor *colors, *p;
@@ -5018,7 +5018,7 @@ XPutPixel (XImagePtr ximg, int x, int y, COLORREF color)
    COLORS will be freed; an existing IMG->pixmap will be freed, too.  */
 
 static void
-x_from_xcolors (struct frame *f, struct image *img, XColor *colors)
+image_from_xcolors (struct frame *f, struct image *img, XColor *colors)
 {
   int x, y;
   XImagePtr oimg = NULL;
@@ -5060,7 +5060,7 @@ static void
 image_detect_edges (struct frame *f, struct image *img,
                     int *matrix, int color_adjust)
 {
-  XColor *colors = x_to_xcolors (f, img, 1);
+  XColor *colors = image_to_xcolors (f, img, 1);
   XColor *new, *p;
   int x, y, i, sum;
   ptrdiff_t nbytes;
@@ -5118,7 +5118,7 @@ image_detect_edges (struct frame *f, struct image *img,
     }
 
   xfree (colors);
-  x_from_xcolors (f, img, new);
+  image_from_xcolors (f, img, new);
 
 #undef COLOR
 }
@@ -5201,7 +5201,7 @@ image_disable_image (struct frame *f, struct image *img)
       /* Color (or grayscale).  Convert to gray, and equalize.  Just
 	 drawing such images with a stipple can look very odd, so
 	 we're using this method instead.  */
-      XColor *colors = x_to_xcolors (f, img, 1);
+      XColor *colors = image_to_xcolors (f, img, 1);
       XColor *p, *end;
       const int h = 15000;
       const int l = 30000;
@@ -5215,7 +5215,7 @@ image_disable_image (struct frame *f, struct image *img)
 	  p->red = p->green = p->blue = i2;
 	}
 
-      x_from_xcolors (f, img, colors);
+      image_from_xcolors (f, img, colors);
     }
 
   /* Draw a cross over the disabled image, if we must or if we
diff --git a/src/keyboard.c b/src/keyboard.c
index b6521e53bd..17148603e8 100644
--- a/src/keyboard.c
+++ b/src/keyboard.c
@@ -3892,10 +3892,12 @@ kbd_buffer_get_event (KBOARD **kbp,
 #ifdef HAVE_EXT_MENU_BAR
       case MENU_BAR_ACTIVATE_EVENT:
 	{
+          struct frame *f;
 	  kbd_fetch_ptr = next_kbd_event (event);
 	  input_pending = readable_events (0);
-	  if (FRAME_LIVE_P (XFRAME (event->ie.frame_or_window)))
-	    x_activate_menubar (XFRAME (event->ie.frame_or_window));
+          f = (XFRAME (event->ie.frame_or_window));
+	  if (FRAME_LIVE_P (f) && FRAME_TERMINAL (f)->activate_menubar_hook)
+	    FRAME_TERMINAL (f)->activate_menubar_hook (f);
 	}
         break;
 #endif
diff --git a/src/menu.h b/src/menu.h
index 0321c27454..4412948224 100644
--- a/src/menu.h
+++ b/src/menu.h
@@ -47,14 +47,17 @@ extern widget_value *digest_single_submenu (int, int, bool);
 #if defined (HAVE_X_WINDOWS) || defined (MSDOS)
 extern Lisp_Object x_menu_show (struct frame *, int, int, int,
 				Lisp_Object, const char **);
+extern void x_activate_menubar (struct frame *);
 #endif
 #ifdef HAVE_NTGUI
 extern Lisp_Object w32_menu_show (struct frame *, int, int, int,
 				  Lisp_Object, const char **);
+extern void w32_activate_menubar (struct frame *);
 #endif
 #ifdef HAVE_NS
 extern Lisp_Object ns_menu_show (struct frame *, int, int, int,
 				 Lisp_Object, const char **);
+extern void ns_activate_menubar (struct frame *);
 #endif
 extern Lisp_Object tty_menu_show (struct frame *, int, int, int,
 				  Lisp_Object, const char **);
diff --git a/src/nsfns.m b/src/nsfns.m
index bc47c40ced..09dcd86f1c 100644
--- a/src/nsfns.m
+++ b/src/nsfns.m
@@ -692,7 +692,7 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
   if (FRAME_INTERNAL_BORDER_WIDTH (f) == old_width)
     return;
 
-  if (FRAME_X_WINDOW (f) != 0)
+  if (FRAME_NATIVE_WINDOW (f) != 0)
     adjust_frame_size (f, -1, -1, 3, 0, Qinternal_border_width);
 
   SET_FRAME_GARBAGED (f);
@@ -879,8 +879,10 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
   f->output_data.ns->icon_left = -1;
 
   /* Set the position of the icon.  */
-  icon_x = x_get_arg (dpyinfo, parms, Qicon_left, 0, 0, RES_TYPE_NUMBER);
-  icon_y = x_get_arg (dpyinfo, parms, Qicon_top, 0, 0,  RES_TYPE_NUMBER);
+  icon_x = gui_display_get_arg (dpyinfo, parms, Qicon_left, 0, 0,
+                                RES_TYPE_NUMBER);
+  icon_y = gui_display_get_arg (dpyinfo, parms, Qicon_top, 0, 0,
+                                RES_TYPE_NUMBER);
   if (!EQ (icon_x, Qunbound) && !EQ (icon_y, Qunbound))
     {
       CHECK_FIXNUM (icon_x);
@@ -1022,8 +1024,8 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
       if (NILP (Fassq (r[i].tem, parms)))
         {
           Lisp_Object value
-            = x_get_arg (dpyinfo, parms, r[i].tem, r[i].val, r[i].cls,
-                         RES_TYPE_NUMBER);
+            = gui_display_get_arg (dpyinfo, parms, r[i].tem, r[i].val, r[i].cls,
+                                   RES_TYPE_NUMBER);
           if (! EQ (value, Qunbound))
             parms = Fcons (Fcons (r[i].tem, value), parms);
         }
@@ -1056,14 +1058,15 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
   static int desc_ctr = 1;
   int x_width = 0, x_height = 0;
 
-  /* x_get_arg modifies parms.  */
+  /* gui_display_get_arg modifies parms.  */
   parms = Fcopy_alist (parms);
 
   /* Use this general default value to start with
      until we know if this frame has a specified name.  */
   Vx_resource_name = Vinvocation_name;
 
-  display = x_get_arg (dpyinfo, parms, Qterminal, 0, 0, RES_TYPE_STRING);
+  display = gui_display_get_arg (dpyinfo, parms, Qterminal, 0, 0,
+                                 RES_TYPE_STRING);
   if (EQ (display, Qunbound))
     display = Qnil;
   dpyinfo = check_ns_display_info (display);
@@ -1072,7 +1075,8 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
   if (!dpyinfo->terminal->name)
     error ("Terminal is not live, can't create new frames on it");
 
-  name = x_get_arg (dpyinfo, parms, Qname, 0, 0, RES_TYPE_STRING);
+  name = gui_display_get_arg (dpyinfo, parms, Qname, 0, 0,
+                              RES_TYPE_STRING);
   if (!STRINGP (name)
       && ! EQ (name, Qunbound)
       && ! NILP (name))
@@ -1081,7 +1085,8 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
   if (STRINGP (name))
     Vx_resource_name = name;
 
-  parent = x_get_arg (dpyinfo, parms, Qparent_id, 0, 0, RES_TYPE_NUMBER);
+  parent = gui_display_get_arg (dpyinfo, parms, Qparent_id, 0, 0,
+                                RES_TYPE_NUMBER);
   if (EQ (parent, Qunbound))
     parent = Qnil;
   if (! NILP (parent))
@@ -1091,8 +1096,9 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
   /* No need to protect DISPLAY because that's not used after passing
      it to make_frame_without_minibuffer.  */
   frame = Qnil;
-  tem = x_get_arg (dpyinfo, parms, Qminibuffer, "minibuffer", "Minibuffer",
-                  RES_TYPE_SYMBOL);
+  tem = gui_display_get_arg (dpyinfo, parms, Qminibuffer,
+                             "minibuffer", "Minibuffer",
+                             RES_TYPE_SYMBOL);
   if (EQ (tem, Qnone) || NILP (tem))
       f = make_frame_without_minibuffer (Qnil, kb, display);
   else if (EQ (tem, Qonly))
@@ -1114,9 +1120,9 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
 
   FRAME_FONTSET (f) = -1;
 
-  fset_icon_name (f, x_get_arg (dpyinfo, parms, Qicon_name,
-				"iconName", "Title",
-				RES_TYPE_STRING));
+  fset_icon_name (f, gui_display_get_arg (dpyinfo, parms, Qicon_name,
+                                          "iconName", "Title",
+                                          RES_TYPE_STRING));
   if (! STRINGP (f->icon_name))
     fset_icon_name (f, Qnil);
 
@@ -1224,34 +1230,38 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
   init_frame_faces (f);
 
   /* Read comment about this code in corresponding place in xfns.c.  */
-  tem = x_get_arg (dpyinfo, parms, Qmin_width, NULL, NULL, RES_TYPE_NUMBER);
+  tem = gui_display_get_arg (dpyinfo, parms, Qmin_width, NULL, NULL,
+                             RES_TYPE_NUMBER);
   if (FIXNUMP (tem))
     store_frame_param (f, Qmin_width, tem);
-  tem = x_get_arg (dpyinfo, parms, Qmin_height, NULL, NULL, RES_TYPE_NUMBER);
+  tem = gui_display_get_arg (dpyinfo, parms, Qmin_height, NULL, NULL,
+                             RES_TYPE_NUMBER);
   if (FIXNUMP (tem))
     store_frame_param (f, Qmin_height, tem);
   adjust_frame_size (f, FRAME_COLS (f) * FRAME_COLUMN_WIDTH (f),
 		     FRAME_LINES (f) * FRAME_LINE_HEIGHT (f), 5, 1,
-		     Qx_create_frame_1);
+		     Qgui_create_frame_1);
 
-  tem = x_get_arg (dpyinfo, parms, Qundecorated, NULL, NULL, RES_TYPE_BOOLEAN);
+  tem = gui_display_get_arg (dpyinfo, parms, Qundecorated, NULL, NULL,
+                             RES_TYPE_BOOLEAN);
   FRAME_UNDECORATED (f) = !NILP (tem) && !EQ (tem, Qunbound);
   store_frame_param (f, Qundecorated, FRAME_UNDECORATED (f) ? Qt : Qnil);
 
 #ifdef NS_IMPL_COCOA
-  tem = x_get_arg (dpyinfo, parms, Qns_appearance, NULL, NULL, RES_TYPE_SYMBOL);
+  tem = gui_display_get_arg (dpyinfo, parms, Qns_appearance, NULL, NULL,
+                             RES_TYPE_SYMBOL);
   FRAME_NS_APPEARANCE (f) = EQ (tem, Qdark)
     ? ns_appearance_vibrant_dark : ns_appearance_aqua;
   store_frame_param (f, Qns_appearance, tem);
 
-  tem = x_get_arg (dpyinfo, parms, Qns_transparent_titlebar,
-                   NULL, NULL, RES_TYPE_BOOLEAN);
+  tem = gui_display_get_arg (dpyinfo, parms, Qns_transparent_titlebar,
+                             NULL, NULL, RES_TYPE_BOOLEAN);
   FRAME_NS_TRANSPARENT_TITLEBAR (f) = !NILP (tem) && !EQ (tem, Qunbound);
   store_frame_param (f, Qns_transparent_titlebar, tem);
 #endif
 
-  parent_frame = x_get_arg (dpyinfo, parms, Qparent_frame, NULL, NULL,
-			    RES_TYPE_SYMBOL);
+  parent_frame = gui_display_get_arg (dpyinfo, parms, Qparent_frame, NULL, NULL,
+                                      RES_TYPE_SYMBOL);
   /* Accept parent-frame iff parent-id was not specified.  */
   if (!NILP (parent)
       || EQ (parent_frame, Qunbound)
@@ -1290,7 +1300,8 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
   window_prompting = gui_figure_window_size (f, parms, true,
                                              &x_width, &x_height);
 
-  tem = x_get_arg (dpyinfo, parms, Qunsplittable, 0, 0, RES_TYPE_BOOLEAN);
+  tem = gui_display_get_arg (dpyinfo, parms, Qunsplittable, 0, 0,
+                             RES_TYPE_BOOLEAN);
   f->no_split = minibuffer_only || (!EQ (tem, Qunbound) && !NILP (tem));
 
   /* NOTE: on other terms, this is done in set_mouse_color, however this
@@ -1351,8 +1362,8 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
   gui_default_parameter (f, parms, Qfullscreen, Qnil,
                          "fullscreen", "Fullscreen", RES_TYPE_SYMBOL);
 
-  /* Allow x_set_window_size, now.  */
-  f->can_x_set_window_size = true;
+  /* Allow set_window_size_hook, now.  */
+  f->can_set_window_size = true;
 
   if (x_width > 0)
     SET_FRAME_WIDTH (f, x_width);
@@ -1360,14 +1371,14 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
     SET_FRAME_HEIGHT (f, x_height);
 
   adjust_frame_size (f, FRAME_TEXT_WIDTH (f), FRAME_TEXT_HEIGHT (f), 0, 1,
-		     Qx_create_frame_2);
+		     Qgui_create_frame_2);
 
   if (! f->output_data.ns->explicit_parent)
     {
       Lisp_Object visibility;
 
-      visibility = x_get_arg (dpyinfo, parms, Qvisibility, 0, 0,
-                              RES_TYPE_SYMBOL);
+      visibility = gui_display_get_arg (dpyinfo, parms, Qvisibility, 0, 0,
+                                        RES_TYPE_SYMBOL);
       if (EQ (visibility, Qunbound))
 	visibility = Qt;
 
@@ -1389,8 +1400,9 @@ Turn the input menu (an NSMenu) into a lisp list for tracking on lisp side.
           || !FRAME_LIVE_P (XFRAME (KVAR (kb, Vdefault_minibuffer_frame)))))
     kset_default_minibuffer_frame (kb, frame);
 
-  /* All remaining specified parameters, which have not been "used"
-     by x_get_arg and friends, now go in the misc. alist of the frame.  */
+  /* All remaining specified parameters, which have not been "used" by
+     gui_display_get_arg and friends, now go in the misc. alist of the
+     frame.  */
   for (tem = parms; CONSP (tem); tem = XCDR (tem))
     if (CONSP (XCAR (tem)) && !NILP (XCAR (XCAR (tem))))
       fset_param_alist (f, Fcons (XCAR (tem), f->param_alist));
@@ -2234,8 +2246,8 @@ Frames are listed from topmost (first) to bottommost (last).  */)
 }
 
 /* Terms implement this instead of x-get-resource directly.  */
-char *
-x_get_string_resource (XrmDatabase rdb, const char *name, const char *class)
+const char *
+ns_get_string_resource (void *_rdb, const char *name, const char *class)
 {
   /* remove appname prefix; TODO: allow for !="Emacs" */
   const char *res, *toCheck = class + (!strncmp (class, "Emacs.", 6) ? 6 : 0);
@@ -2247,10 +2259,10 @@ Frames are listed from topmost (first) to bottommost (last).  */)
     return NULL;
 
   res = ns_get_defaults_value (toCheck);
-  return (char *) (!res ? NULL
-		   : !c_strncasecmp (res, "YES", 3) ? "true"
-		   : !c_strncasecmp (res, "NO", 2) ? "false"
-		   : res);
+  return (const char *) (!res ? NULL
+                         : !c_strncasecmp (res, "YES", 3) ? "true"
+                         : !c_strncasecmp (res, "NO", 2) ? "false"
+                         : res);
 }
 
 /* ==========================================================================
@@ -2720,11 +2732,13 @@ Frames are listed from topmost (first) to bottommost (last).  */)
   else
     Fx_hide_tip ();
 
-  t = x_get_arg (NULL, parms, Qbackground_color, NULL, NULL, RES_TYPE_STRING);
+  t = gui_display_get_arg (NULL, parms, Qbackground_color, NULL, NULL,
+                           RES_TYPE_STRING);
   if (ns_lisp_to_color (t, &color) == 0)
     [ns_tooltip setBackgroundColor: color];
 
-  t = x_get_arg (NULL, parms, Qforeground_color, NULL, NULL, RES_TYPE_STRING);
+  t = gui_display_get_arg (NULL, parms, Qforeground_color, NULL, NULL,
+                           RES_TYPE_STRING);
   if (ns_lisp_to_color (t, &color) == 0)
     [ns_tooltip setForegroundColor: color];
 
diff --git a/src/nsgui.h b/src/nsgui.h
index c857d77d9c..c147f4dec4 100644
--- a/src/nsgui.h
+++ b/src/nsgui.h
@@ -117,9 +117,6 @@ typedef void * Color;
 typedef int Window;
 typedef int Display;
 
-/* Xism */
-typedef Lisp_Object XrmDatabase;
-
 
 /* Some sort of attempt to normalize rectangle handling.  Seems a bit
    much for what is accomplished.  */
diff --git a/src/nsmenu.m b/src/nsmenu.m
index 34ec980856..fd1323344b 100644
--- a/src/nsmenu.m
+++ b/src/nsmenu.m
@@ -470,7 +470,7 @@
 }
 
 void
-x_activate_menubar (struct frame *f)
+ns_activate_menubar (struct frame *f)
 {
 #ifdef NS_IMPL_COCOA
   ns_update_menubar (f, true, nil);
diff --git a/src/nsterm.h b/src/nsterm.h
index 4d72ae2402..55b06ddb29 100644
--- a/src/nsterm.h
+++ b/src/nsterm.h
@@ -869,7 +869,7 @@ struct ns_display_info
   Window root_window;
 
   /* Xism */
-  XrmDatabase xrdb;
+  Lisp_Object rdb;
 
   /* The cursor to use for vertical scroll bars.  */
   Cursor vertical_scroll_bar_cursor;
@@ -993,9 +993,9 @@ struct x_output
 
 /* This gives the ns_display_info structure for the display F is on.  */
 #define FRAME_DISPLAY_INFO(f) ((f)->output_data.ns->display_info)
-#define FRAME_X_OUTPUT(f) ((f)->output_data.ns)
+#define FRAME_OUTPUT_DATA(f) ((f)->output_data.ns)
 #define FRAME_NS_WINDOW(f) ((f)->output_data.ns->window_desc)
-#define FRAME_X_WINDOW(f) ((f)->output_data.ns->window_desc)
+#define FRAME_NATIVE_WINDOW(f) FRAME_NS_WINDOW (f)
 
 /* This is the `Display *' which frame F is on.  */
 #define FRAME_NS_DISPLAY(f) (0)
@@ -1159,6 +1159,9 @@ extern void ns_implicitly_set_name (struct frame *f, Lisp_Object arg,
                                     Lisp_Object oldval);
 extern void ns_set_scroll_bar_default_width (struct frame *f);
 extern void ns_set_scroll_bar_default_height (struct frame *f);
+extern const char *ns_get_string_resource (void *_rdb,
+                                           const char *name,
+                                           const char *class);
 
 /* C access to ObjC functionality */
 extern void  ns_release_object (void *obj);
@@ -1217,7 +1220,7 @@ extern int ns_display_pixel_width (struct ns_display_info *);
 
 /* This in nsterm.m */
 extern float ns_antialias_threshold;
-extern void ns_make_frame_visible (struct frame *f)
+extern void ns_make_frame_visible (struct frame *f);
 extern void ns_iconify_frame (struct frame *f);
 extern void ns_set_undecorated (struct frame *f, Lisp_Object new_value,
                                 Lisp_Object old_value);
diff --git a/src/nsterm.m b/src/nsterm.m
index 8d0b14b38f..d72e679e4d 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -698,7 +698,7 @@ Free a pool and temporary objects it refers to (callable from C)
    NSDisableScreenUpdates.
 
    We use these functions to prevent the user seeing a blank frame
-   after it has been resized.  x_set_window_size disables updates and
+   after it has been resized.  ns_set_window_size disables updates and
    when redisplay completes unwind_redisplay enables them again
    (bug#30699).  */
 
@@ -1803,12 +1803,12 @@ Hide the window (X11 semantics)
 }
 
 
-void
-x_set_window_size (struct frame *f,
-                   bool change_gravity,
-                   int width,
-                   int height,
-                   bool pixelwise)
+static void
+ns_set_window_size (struct frame *f,
+                    bool change_gravity,
+                    int width,
+                    int height,
+                    bool pixelwise)
 /* --------------------------------------------------------------------------
      Adjust window pixel size based on given character grid size
      Impl is a bit more complex than other terms, need to do some
@@ -1821,7 +1821,7 @@ Hide the window (X11 semantics)
   int pixelwidth, pixelheight;
   int orig_height = wr.size.height;
 
-  NSTRACE ("x_set_window_size");
+  NSTRACE ("ns_set_window_size");
 
   if (view == nil)
     return;
@@ -1867,7 +1867,7 @@ breaks live resize (resizing with a mouse), so don't do it if
    wr.origin.y += orig_height - wr.size.height;
 
  frame_size_history_add
-   (f, Qx_set_window_size_1, width, height,
+   (f, Qgui_set_window_size_1, width, height,
     list5 (Fcons (make_fixnum (pixelwidth), make_fixnum (pixelheight)),
 	   Fcons (make_fixnum (wr.size.width), make_fixnum (wr.size.height)),
 	   make_fixnum (f->border_width),
@@ -5222,10 +5222,13 @@ static Lisp_Object ns_new_font (struct frame *f, Lisp_Object font_object,
   terminal->frame_visible_invisible_hook = ns_make_frame_visible_invisible;
   terminal->fullscreen_hook = ns_fullscreen_hook;
   terminal->iconify_frame_hook = ns_iconify_frame;
+  terminal->set_window_size_hook = ns_set_window_size;
+  terminal->set_frame_offset_hook = ns_set_offset;
   terminal->set_frame_alpha_hook = ns_set_frame_alpha;
   terminal->set_new_font_hook = ns_new_font;
   terminal->implicit_set_name_hook = ns_implicitly_set_name;
   terminal->menu_show_hook = ns_menu_show;
+  terminal->activate_menubar_hook = ns_activate_menubar;
   terminal->popup_dialog_hook = ns_popup_dialog;
   terminal->set_vertical_scroll_bar_hook = ns_set_vertical_scroll_bar;
   terminal->set_horizontal_scroll_bar_hook = ns_set_horizontal_scroll_bar;
@@ -5234,6 +5237,7 @@ static Lisp_Object ns_new_font (struct frame *f, Lisp_Object font_object,
   terminal->condemn_scroll_bars_hook = ns_condemn_scroll_bars;
   terminal->redeem_scroll_bar_hook = ns_redeem_scroll_bar;
   terminal->judge_scroll_bars_hook = ns_judge_scroll_bars;
+  terminal->get_string_resource_hook = ns_get_string_resource;
   terminal->delete_frame_hook = ns_destroy_window;
   terminal->delete_terminal_hook = ns_delete_terminal;
   /* Other hooks are NULL by default.  */
@@ -7558,7 +7562,7 @@ - (void)windowDidMove: sender
 
 
 /* Called AFTER method below, but before our windowWillResize call there leads
-   to windowDidResize -> x_set_window_size.  Update emacs' notion of frame
+   to windowDidResize -> ns_set_window_size.  Update emacs' notion of frame
    location so set_window_size moves the frame.  */
 - (BOOL)windowShouldZoom: (NSWindow *)sender toFrame: (NSRect)newFrame
 {
diff --git a/src/termhooks.h b/src/termhooks.h
index 40749dda37..97994f856d 100644
--- a/src/termhooks.h
+++ b/src/termhooks.h
@@ -532,6 +532,10 @@ struct terminal
      windows.  */
   void (*frame_raise_lower_hook) (struct frame *f, bool raise_flag);
 
+  /* This hook is called to make the frame F visible if VISIBLE is
+     true, or invisible otherwise. */
+  void (*frame_visible_invisible_hook) (struct frame *f, bool visible);
+
   /* If the value of the frame parameter changed, this hook is called.
      For example, if going from fullscreen to not fullscreen this hook
      may do something OS dependent, like extended window manager hints on X11.  */
@@ -540,6 +544,22 @@ struct terminal
   /* This hook is called to iconify the frame.  */
   void (*iconify_frame_hook) (struct frame *f);
 
+  /* This hook is called to change the size of frame F's native
+   (underlying) window.  If CHANGE_GRAVITY, change to top-left-corner
+   window gravity for this size change and subsequent size changes.
+   Otherwise we leave the window gravity unchanged.  */
+  void (*set_window_size_hook) (struct frame *f, bool change_gravity,
+                                int width, int height, bool pixelwise);
+
+  /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
+   to really change the position, and 0 when calling from
+   *_make_frame_visible (in that case, XOFF and YOFF are the current
+   position values).  It is -1 when calling from gui_set_frame_parameters,
+   which means, do adjust for borders but don't change the gravity.  */
+
+  void (*set_frame_offset_hook) (struct frame *f, register int xoff,
+                                 register int yoff, int change_gravity);
+
   /* This hook is called to set the frame's transparency.  */
   void (*set_frame_alpha_hook) (struct frame *f);
 
@@ -547,6 +567,10 @@ struct terminal
   Lisp_Object (*set_new_font_hook) (struct frame *f, Lisp_Object font_object,
                                     int fontset);
 
+  /* This hook is called to set the GUI window icon of F using FILE.  */
+  bool (*set_bitmap_icon_hook) (struct frame *f, Lisp_Object file);
+
+
   void (*implicit_set_name_hook) (struct frame *f, Lisp_Object arg,
                                   Lisp_Object oldval);
 
@@ -554,6 +578,11 @@ struct terminal
   Lisp_Object (*menu_show_hook) (struct frame *f, int x, int y, int menuflags,
 				 Lisp_Object title, const char **error_name);
 
+#ifdef HAVE_EXT_MENU_BAR
+  /* This hook is called to activate the menu bar.  */
+  void (*activate_menubar_hook) (struct frame *f);
+#endif
+
   /* This hook is called to display popup dialog.  */
   Lisp_Object (*popup_dialog_hook) (struct frame *f, Lisp_Object header,
 				    Lisp_Object contents);
@@ -605,10 +634,10 @@ struct terminal
 					  int position);
 
   /* Set the default scroll bar width on FRAME.  */
-  void (*x_set_scroll_bar_default_width) (struct frame *frame);
+  void (*set_scroll_bar_default_width_hook) (struct frame *frame);
 
   /* Set the default scroll bar height on FRAME.  */
-  void (*x_set_scroll_bar_default_height) (struct frame *frame);
+  void (*set_scroll_bar_default_height_hook) (struct frame *frame);
 
   /* The following three hooks are used when we're doing a thorough
      redisplay of the frame.  We don't explicitly know which scroll bars
@@ -671,6 +700,11 @@ struct terminal
      while it runs.  */
   void (*buffer_flipping_unblocked_hook) (struct frame *);
 
+  /* Retrieve the string resource specified by NAME with CLASS from
+     database RDB. */
+  const char * (*get_string_resource_hook) (void *rdb,
+                                            const char *name,
+                                            const char *class);
 \f
   /* Called to delete the device-specific portions of a frame that is
      on this terminal device. */
diff --git a/src/w32fns.c b/src/w32fns.c
index f01ced604b..350f8d3f97 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -1580,7 +1580,7 @@ w32_set_icon_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 
   block_input ();
 
-  result = x_bitmap_icon (f, arg);
+  result = FRAME_TERMINAL (f)->set_bitmap_icon_hook (f, arg);
   if (result)
     {
       unblock_input ();
@@ -1702,7 +1702,7 @@ w32_set_internal_border_width (struct frame *f, Lisp_Object arg, Lisp_Object old
     {
       f->internal_border_width = border;
 
-      if (FRAME_X_WINDOW (f) != 0)
+      if (FRAME_NATIVE_WINDOW (f) != 0)
 	{
 	  adjust_frame_size (f, -1, -1, 3, false, Qinternal_border_width);
 
@@ -5413,10 +5413,12 @@ my_create_window (struct frame * f)
   Lisp_Object left, top;
   struct w32_display_info *dpyinfo = &one_w32_display_info;
 
-  /* When called with RES_TYPE_NUMBER, x_get_arg will return zero for
-     anything that is not a number and is not Qunbound.  */
-  left = x_get_arg (dpyinfo, Qnil, Qleft, "left", "Left", RES_TYPE_NUMBER);
-  top = x_get_arg (dpyinfo, Qnil, Qtop, "top", "Top", RES_TYPE_NUMBER);
+  /* When called with RES_TYPE_NUMBER, gui_display_get_arg will return
+     zero for anything that is not a number and is not Qunbound.  */
+  left = gui_display_get_arg (dpyinfo, Qnil, Qleft, "left", "Left",
+                              RES_TYPE_NUMBER);
+  top = gui_display_get_arg (dpyinfo, Qnil, Qtop, "top", "Top",
+                             RES_TYPE_NUMBER);
   if (EQ (left, Qunbound))
     coords[0] = CW_USEDEFAULT;
   else
@@ -5532,8 +5534,10 @@ w32_icon (struct frame *f, Lisp_Object parms)
 
   /* Set the position of the icon.  Note that Windows 95 groups all
      icons in the tray.  */
-  icon_x = x_get_arg (dpyinfo, parms, Qicon_left, 0, 0, RES_TYPE_NUMBER);
-  icon_y = x_get_arg (dpyinfo, parms, Qicon_top, 0, 0, RES_TYPE_NUMBER);
+  icon_x = gui_display_get_arg (dpyinfo, parms, Qicon_left, 0, 0,
+                                RES_TYPE_NUMBER);
+  icon_y = gui_display_get_arg (dpyinfo, parms, Qicon_top, 0, 0,
+                                RES_TYPE_NUMBER);
   if (!EQ (icon_x, Qunbound) && !EQ (icon_y, Qunbound))
     {
       CHECK_FIXNUM (icon_x);
@@ -5633,13 +5637,15 @@ static void
 w32_default_font_parameter (struct frame *f, Lisp_Object parms)
 {
   struct w32_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
-  Lisp_Object font_param = x_get_arg (dpyinfo, parms, Qfont, NULL, NULL,
-                                      RES_TYPE_STRING);
+  Lisp_Object font_param = gui_display_get_arg (dpyinfo,
+                                                parms, Qfont, NULL, NULL,
+                                                RES_TYPE_STRING);
   Lisp_Object font;
   if (EQ (font_param, Qunbound))
     font_param = Qnil;
   font = !NILP (font_param) ? font_param
-    : x_get_arg (dpyinfo, parms, Qfont, "font", "Font", RES_TYPE_STRING);
+    : gui_display_get_arg (dpyinfo, parms, Qfont, "font", "Font",
+                           RES_TYPE_STRING);
 
   if (!STRINGP (font))
     {
@@ -5699,9 +5705,11 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
      until we know if this frame has a specified name.  */
   Vx_resource_name = Vinvocation_name;
 
-  display = x_get_arg (dpyinfo, parameters, Qterminal, 0, 0, RES_TYPE_NUMBER);
+  display = gui_display_get_arg (dpyinfo, parameters, Qterminal, 0, 0,
+                                 RES_TYPE_NUMBER);
   if (EQ (display, Qunbound))
-    display = x_get_arg (dpyinfo, parameters, Qdisplay, 0, 0, RES_TYPE_STRING);
+    display = gui_display_get_arg (dpyinfo, parameters, Qdisplay, 0, 0,
+                                   RES_TYPE_STRING);
   if (EQ (display, Qunbound))
     display = Qnil;
   dpyinfo = check_x_display_info (display);
@@ -5710,7 +5718,8 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
   if (!dpyinfo->terminal->name)
     error ("Terminal is not live, can't create new frames on it");
 
-  name = x_get_arg (dpyinfo, parameters, Qname, "name", "Name", RES_TYPE_STRING);
+  name = gui_display_get_arg (dpyinfo, parameters, Qname, "name", "Name",
+                              RES_TYPE_STRING);
   if (!STRINGP (name)
       && ! EQ (name, Qunbound)
       && ! NILP (name))
@@ -5720,8 +5729,8 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
     Vx_resource_name = name;
 
   /* See if parent window is specified.  */
-  parent = x_get_arg (dpyinfo, parameters, Qparent_id, NULL, NULL,
-		      RES_TYPE_NUMBER);
+  parent = gui_display_get_arg (dpyinfo, parameters, Qparent_id, NULL, NULL,
+                                RES_TYPE_NUMBER);
   if (EQ (parent, Qunbound))
     parent = Qnil;
   else if (!NILP (parent))
@@ -5731,8 +5740,9 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
   /* No need to protect DISPLAY because that's not used after passing
      it to make_frame_without_minibuffer.  */
   frame = Qnil;
-  tem = x_get_arg (dpyinfo, parameters, Qminibuffer, "minibuffer", "Minibuffer",
-		   RES_TYPE_SYMBOL);
+  tem = gui_display_get_arg (dpyinfo, parameters, Qminibuffer,
+                             "minibuffer", "Minibuffer",
+                             RES_TYPE_SYMBOL);
   if (EQ (tem, Qnone) || NILP (tem))
     f = make_frame_without_minibuffer (Qnil, kb, display);
   else if (EQ (tem, Qonly))
@@ -5747,8 +5757,9 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
 
   XSETFRAME (frame, f);
 
-  parent_frame = x_get_arg (dpyinfo, parameters, Qparent_frame, NULL, NULL,
-			    RES_TYPE_SYMBOL);
+  parent_frame = gui_display_get_arg (dpyinfo, parameters, Qparent_frame,
+                                      NULL, NULL,
+                                      RES_TYPE_SYMBOL);
   /* Apply `parent-frame' parameter only when no `parent-id' was
      specified.  */
   if (!NILP (parent_frame)
@@ -5761,13 +5772,13 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
   fset_parent_frame (f, parent_frame);
   store_frame_param (f, Qparent_frame, parent_frame);
 
-  tem = x_get_arg (dpyinfo, parameters, Qundecorated, NULL, NULL,
-		   RES_TYPE_BOOLEAN);
+  tem = gui_display_get_arg (dpyinfo, parameters, Qundecorated, NULL, NULL,
+                             RES_TYPE_BOOLEAN);
   FRAME_UNDECORATED (f) = !NILP (tem) && !EQ (tem, Qunbound);
   store_frame_param (f, Qundecorated, FRAME_UNDECORATED (f) ? Qt : Qnil);
 
-  tem = x_get_arg (dpyinfo, parameters, Qskip_taskbar, NULL, NULL,
-		   RES_TYPE_BOOLEAN);
+  tem = gui_display_get_arg (dpyinfo, parameters, Qskip_taskbar, NULL, NULL,
+                             RES_TYPE_BOOLEAN);
   FRAME_SKIP_TASKBAR (f) = !NILP (tem) && !EQ (tem, Qunbound);
   store_frame_param (f, Qskip_taskbar,
 		     (NILP (tem) || EQ (tem, Qunbound)) ? Qnil : Qt);
@@ -5782,9 +5793,12 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
   f->output_data.w32 = xzalloc (sizeof (struct w32_output));
   FRAME_FONTSET (f) = -1;
 
-  fset_icon_name
-    (f, x_get_arg (dpyinfo, parameters, Qicon_name, "iconName", "Title",
-		   RES_TYPE_STRING));
+  fset_icon_name (f, gui_display_get_arg (dpyinfo,
+                                          parameters,
+                                          Qicon_name,
+                                          "iconName",
+                                          "Title",
+                                          RES_TYPE_STRING));
   if (! STRINGP (f->icon_name))
     fset_icon_name (f, Qnil);
 
@@ -5851,8 +5865,9 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
     {
       Lisp_Object value;
 
-      value = x_get_arg (dpyinfo, parameters, Qinternal_border_width,
-			 "internalBorder", "InternalBorder", RES_TYPE_NUMBER);
+      value = gui_display_get_arg (dpyinfo, parameters, Qinternal_border_width,
+                                   "internalBorder", "InternalBorder",
+                                   RES_TYPE_NUMBER);
       if (! EQ (value, Qunbound))
 	parameters = Fcons (Fcons (Qinternal_border_width, value),
 			    parameters);
@@ -5916,17 +5931,17 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
 
      Also process `min-width' and `min-height' parameters right here
      because `frame-windows-min-size' needs them.  */
-  tem = x_get_arg (dpyinfo, parameters, Qmin_width, NULL, NULL,
-		   RES_TYPE_NUMBER);
+  tem = gui_display_get_arg (dpyinfo, parameters, Qmin_width, NULL, NULL,
+                             RES_TYPE_NUMBER);
   if (FIXNUMP (tem))
     store_frame_param (f, Qmin_width, tem);
-  tem = x_get_arg (dpyinfo, parameters, Qmin_height, NULL, NULL,
-		   RES_TYPE_NUMBER);
+  tem = gui_display_get_arg (dpyinfo, parameters, Qmin_height, NULL, NULL,
+                             RES_TYPE_NUMBER);
   if (FIXNUMP (tem))
     store_frame_param (f, Qmin_height, tem);
   adjust_frame_size (f, FRAME_COLS (f) * FRAME_COLUMN_WIDTH (f),
 		     FRAME_LINES (f) * FRAME_LINE_HEIGHT (f), 5, true,
-		     Qx_create_frame_1);
+		     Qgui_create_frame_1);
 
   /* The X resources controlling the menu-bar and tool-bar are
      processed specially at startup, and reflected in the mode
@@ -5974,7 +5989,8 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
   window_prompting = gui_figure_window_size (f, parameters, true,
                                              &x_width, &x_height);
 
-  tem = x_get_arg (dpyinfo, parameters, Qunsplittable, 0, 0, RES_TYPE_BOOLEAN);
+  tem = gui_display_get_arg (dpyinfo, parameters, Qunsplittable, 0, 0,
+                             RES_TYPE_BOOLEAN);
   f->no_split = minibuffer_only || EQ (tem, Qt);
 
   w32_window (f, window_prompting, minibuffer_only);
@@ -6003,8 +6019,8 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
   gui_default_parameter (f, parameters, Qscroll_bar_height, Qnil,
                          "scrollBarHeight", "ScrollBarHeight", RES_TYPE_NUMBER);
 
-  /* Allow x_set_window_size, now.  */
-  f->can_x_set_window_size = true;
+  /* Allow set_window_size_hook, now.  */
+  f->can_set_window_size = true;
 
   if (x_width > 0)
     SET_FRAME_WIDTH (f, x_width);
@@ -6019,7 +6035,7 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
   unblock_input ();
 
   adjust_frame_size (f, FRAME_TEXT_WIDTH (f), FRAME_TEXT_HEIGHT (f), 0, true,
-		     Qx_create_frame_2);
+		     Qgui_create_frame_2);
 
   /* Process fullscreen parameter here in the hope that normalizing a
      fullheight/fullwidth frame will produce the size set by the last
@@ -6035,7 +6051,8 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
   if (!f->output_data.w32->explicit_parent)
     {
       Lisp_Object visibility
-	= x_get_arg (dpyinfo, parameters, Qvisibility, 0, 0, RES_TYPE_SYMBOL);
+	= gui_display_get_arg (dpyinfo, parameters, Qvisibility, 0, 0,
+                               RES_TYPE_SYMBOL);
 
       if (EQ (visibility, Qicon))
 	w32_iconify_frame (f);
@@ -6063,8 +6080,9 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
 	  || !FRAME_LIVE_P (XFRAME (KVAR (kb, Vdefault_minibuffer_frame)))))
     kset_default_minibuffer_frame (kb, frame);
 
-  /* All remaining specified parameters, which have not been "used"
-     by x_get_arg and friends, now go in the misc. alist of the frame.  */
+  /* All remaining specified parameters, which have not been "used" by
+     gui_display_get_arg and friends, now go in the misc. alist of the
+     frame.  */
   for (tem = parameters; CONSP (tem); tem = XCDR (tem))
     if (CONSP (XCAR (tem)) && !NILP (XCAR (XCAR (tem))))
       fset_param_alist (f, Fcons (XCAR (tem), f->param_alist));
@@ -6500,13 +6518,6 @@ SOUND is nil to use the normal beep.  */)
   return sound;
 }
 
-#if 0	/* unused */
-int
-x_screen_planes (register struct frame *f)
-{
-  return FRAME_DISPLAY_INFO (f)->n_planes;
-}
-#endif
 \f
 /* Return the display structure for the display named NAME.
    Open a new connection if necessary.  */
@@ -6830,12 +6841,14 @@ w32_create_tip_frame (struct w32_display_info *dpyinfo, Lisp_Object parms)
 
   kb = dpyinfo->terminal->kboard;
 
-  /* The calls to x_get_arg remove elements from PARMS, so copy it to
-     avoid destructive changes behind our caller's back.  */
+  /* The calls to gui_display_get_arg remove elements from PARMS, so
+     copy it to avoid destructive changes behind our caller's
+     back.  */
   parms = Fcopy_alist (parms);
 
   /* Get the name of the frame to use for resource lookup.  */
-  name = x_get_arg (dpyinfo, parms, Qname, "name", "Name", RES_TYPE_STRING);
+  name = gui_display_get_arg (dpyinfo, parms, Qname, "name", "Name",
+                              RES_TYPE_STRING);
   if (!STRINGP (name)
       && !EQ (name, Qunbound)
       && !NILP (name))
@@ -6904,8 +6917,9 @@ w32_create_tip_frame (struct w32_display_info *dpyinfo, Lisp_Object parms)
     {
       Lisp_Object value;
 
-      value = x_get_arg (dpyinfo, parms, Qinternal_border_width,
-			 "internalBorder", "internalBorder", RES_TYPE_NUMBER);
+      value = gui_display_get_arg (dpyinfo, parms, Qinternal_border_width,
+                                   "internalBorder", "internalBorder",
+                                   RES_TYPE_NUMBER);
       if (! EQ (value, Qunbound))
 	parms = Fcons (Fcons (Qinternal_border_width, value),
 		       parms);
@@ -7011,7 +7025,7 @@ w32_create_tip_frame (struct w32_display_info *dpyinfo, Lisp_Object parms)
      below.  And the frame needs to be on Vframe_list or making it
      visible won't work.  */
   Vframe_list = Fcons (frame, Vframe_list);
-  f->can_x_set_window_size = true;
+  f->can_set_window_size = true;
 
   /* Setting attributes of faces of the tooltip frame from resources
      and similar will set face_change, which leads to the
diff --git a/src/w32gui.h b/src/w32gui.h
index dbc67993ce..5dcbbd9516 100644
--- a/src/w32gui.h
+++ b/src/w32gui.h
@@ -42,8 +42,6 @@ typedef struct _XGCValues
 typedef HBITMAP Pixmap;
 typedef HBITMAP Bitmap;
 
-typedef char * XrmDatabase;
-
 typedef XGCValues * GC;
 typedef COLORREF Color;
 typedef HWND Window;
diff --git a/src/w32menu.c b/src/w32menu.c
index 42912db443..669161c408 100644
--- a/src/w32menu.c
+++ b/src/w32menu.c
@@ -153,7 +153,7 @@ w32_popup_dialog (struct frame *f, Lisp_Object header, Lisp_Object contents)
    This way we can safely execute Lisp code.  */
 
 void
-x_activate_menubar (struct frame *f)
+w32_activate_menubar (struct frame *f)
 {
   set_frame_menubar (f, false, true);
 
diff --git a/src/w32reg.c b/src/w32reg.c
index aff131dd37..e8201d3c4f 100644
--- a/src/w32reg.c
+++ b/src/w32reg.c
@@ -21,7 +21,6 @@ along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
 
 #include <config.h>
 #include "lisp.h"
-#include "w32term.h"	/* for XrmDatabase, xrdb */
 #include "blockinput.h"
 
 #include <stdio.h>
@@ -73,8 +72,8 @@ w32_get_rdb_resource (const char *rdb, const char *resource)
   return NULL;
 }
 
-static char *
-w32_get_string_resource (const char *name, const char *class, DWORD dwexptype)
+static const char *
+w32_get_string_resource_1 (const char *name, const char *class, DWORD dwexptype)
 {
   LPBYTE lpvalue = NULL;
   HKEY hrootkey = NULL;
@@ -134,15 +133,17 @@ w32_get_string_resource (const char *name, const char *class, DWORD dwexptype)
       /* Check if there are Windows specific defaults defined.  */
       return w32_get_rdb_resource (SYSTEM_DEFAULT_RESOURCES, name);
     }
-  return (char *)lpvalue;
+  return (const char *)lpvalue;
 }
 
 /* Retrieve the string resource specified by NAME with CLASS from
    database RDB. */
 
-char *
-x_get_string_resource (XrmDatabase rdb, const char *name, const char *class)
+const char *
+w32_get_string_resource (void *v_rdb, const char *name, const char *class)
 {
+  const char *rdb = *((const char *)v_rdb);
+
   if (rdb)
     {
       char *resource;
@@ -157,5 +158,5 @@ x_get_string_resource (XrmDatabase rdb, const char *name, const char *class)
     /* --quick was passed, so this is a no-op.  */
     return NULL;
 
-  return w32_get_string_resource (name, class, REG_SZ);
+  return w32_get_string_resource_1 (name, class, REG_SZ);
 }
diff --git a/src/w32term.c b/src/w32term.c
index a3589c06c9..64357df139 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -3444,7 +3444,7 @@ w32_note_mouse_movement (struct frame *frame, MSG *msg)
   int mouse_y = HIWORD (msg->lParam);
   RECT *r;
 
-  if (!FRAME_X_OUTPUT (frame))
+  if (!FRAME_OUTPUT_DATA (frame))
     return 0;
 
   dpyinfo = FRAME_DISPLAY_INFO (frame);
@@ -5995,8 +5995,8 @@ w32_draw_window_cursor (struct window *w, struct glyph_row *glyph_row,
 \f
 /* Icons.  */
 
-bool
-x_bitmap_icon (struct frame *f, Lisp_Object icon)
+static bool
+w32_bitmap_icon (struct frame *f, Lisp_Object icon)
 {
   HANDLE main_icon;
   HANDLE small_icon = NULL;
@@ -6116,7 +6116,7 @@ w32_new_font (struct frame *f, Lisp_Object font_object, int fontset)
     }
 
   /* Now make the frame display the given font.  */
-  if (FRAME_X_WINDOW (f) != 0)
+  if (FRAME_NATIVE_WINDOW (f) != 0)
     {
       /* Don't change the size of a tip frame; there's no point in
 	 doing it because it's done in Fx_show_tip, and it leads to
@@ -6407,13 +6407,13 @@ w32fullscreen_hook (struct frame *f)
     f->want_fullscreen |= FULLSCREEN_WAIT;
 }
 
-/* Call this to change the size of frame F's x-window.
+/* Call this to change the size of frame F's native window.
    If CHANGE_GRAVITY, change to top-left-corner window gravity
    for this size change and subsequent size changes.
    Otherwise we leave the window gravity unchanged.  */
 
-void
-x_set_window_size (struct frame *f, bool change_gravity,
+static void
+w32_set_window_size (struct frame *f, bool change_gravity,
 		   int width, int height, bool pixelwise)
 {
   int pixelwidth, pixelheight;
@@ -6499,7 +6499,7 @@ x_set_window_size (struct frame *f, bool change_gravity,
   if (pixelwidth > 0 || pixelheight > 0)
     {
       frame_size_history_add
-	(f, Qx_set_window_size_1, width, height,
+	(f, Qgui_set_window_size_1, width, height,
 	 list2 (Fcons (make_fixnum (pixelwidth),
 		       make_fixnum (pixelheight)),
 		Fcons (make_fixnum (rect.right - rect.left),
@@ -6950,7 +6950,7 @@ w32_show_hourglass (struct frame *f)
 {
   if (!menubar_in_use && !current_popup_menu)
     {
-      struct w32_output *w32 = FRAME_X_OUTPUT (f);
+      struct w32_output *w32 = FRAME_OUTPUT_DATA (f);
 
       w32->hourglass_p = 1;
       SetCursor (w32->hourglass_cursor);
@@ -6962,7 +6962,7 @@ w32_show_hourglass (struct frame *f)
 static void
 w32_hide_hourglass (struct frame *f)
 {
-  struct w32_output *w32 = FRAME_X_OUTPUT (f);
+  struct w32_output *w32 = FRAME_OUTPUT_DATA (f);
 
   w32->hourglass_p = 0;
   if (f->pointer_invisible)
@@ -7152,10 +7152,14 @@ w32_create_terminal (struct w32_display_info *dpyinfo)
   terminal->frame_visible_invisible_hook = w32_make_frame_visible_invisible;
   terminal->fullscreen_hook = w32fullscreen_hook;
   terminal->iconify_frame_hook = w32_iconify_frame;
+  terminal->set_window_size_hook = w32_set_window_size;
+  terminal->set_frame_offset_hook = w32_set_offset;
   terminal->set_frame_alpha_hook = w32_set_frame_alpha;
   terminal->set_new_font_hook = w32_new_font;
+  terminal->set_bitmap_icon_hook = w32_bitmap_icon;
   terminal->implicit_set_name_hook = w32_implicitly_set_name;
   terminal->menu_show_hook = w32_menu_show;
+  terminal->activate_menubar_hook = w32_activate_menubar;
   terminal->popup_dialog_hook = w32_popup_dialog;
   terminal->change_tool_bar_height_hook = w32_change_tool_bar_height;
   terminal->set_vertical_scroll_bar_hook = w32_set_vertical_scroll_bar;
@@ -7165,6 +7169,7 @@ w32_create_terminal (struct w32_display_info *dpyinfo)
   terminal->condemn_scroll_bars_hook = w32_condemn_scroll_bars;
   terminal->redeem_scroll_bar_hook = w32_redeem_scroll_bar;
   terminal->judge_scroll_bars_hook = w32_judge_scroll_bars;
+  terminal->get_string_resource_hook = w32_get_string_resource;
   terminal->delete_frame_hook = w32_destroy_window;
   terminal->delete_terminal_hook = w32_delete_terminal;
   /* Other hooks are NULL by default.  */
@@ -7222,7 +7227,7 @@ w32_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
   /* Set the name of the terminal. */
   terminal->name = xlispstrdup (display_name);
 
-  dpyinfo->xrdb = xrm_option ? w32_make_rdb (xrm_option) : NULL;
+  dpyinfo->rdb = xrm_option ? w32_make_rdb (xrm_option) : NULL;
 
   /* Put this display on the chain.  */
   dpyinfo->next = x_display_list;
diff --git a/src/w32term.h b/src/w32term.h
index 6374704b54..d742aea5c2 100644
--- a/src/w32term.h
+++ b/src/w32term.h
@@ -120,7 +120,7 @@ struct w32_display_info
   Cursor horizontal_scroll_bar_cursor;
 
   /* Resource data base */
-  XrmDatabase xrdb;
+  const char *rdb;
 
   /* color palette information.  */
   int has_palette;
@@ -231,7 +231,7 @@ extern struct frame *w32_window_to_frame (struct w32_display_info *, HWND);
 
 extern void w32_real_positions (struct frame *f, int *xptr, int *yptr);
 
-extern void w32_change_tool_bar_height (struct frame *, int)
+extern void w32_change_tool_bar_height (struct frame *, int);
 extern void w32_implicitly_set_name (struct frame *, Lisp_Object, Lisp_Object);
 extern void w32_set_scroll_bar_default_width (struct frame *);
 extern void w32_set_scroll_bar_default_height (struct frame *);
@@ -249,8 +249,8 @@ extern int w32_display_pixel_width (struct w32_display_info *);
 extern void initialize_frame_menubar (struct frame *);
 extern void w32_dialog_in_progress (Lisp_Object in_progress);
 
-extern void w32_make_frame_visible (struct frame *f)
-extern void w32_make_frame_invisible (struct frame *f)
+extern void w32_make_frame_visible (struct frame *f);
+extern void w32_make_frame_invisible (struct frame *f);
 extern void w32_iconify_frame (struct frame *f);
 extern void w32_free_frame_resources (struct frame *);
 extern void w32_wm_set_size_hint (struct frame *, long, bool);
@@ -263,6 +263,10 @@ extern int w32_kbd_mods_to_emacs (DWORD mods, WORD key);
 extern void w32con_hide_cursor (void);
 extern void w32con_show_cursor (void);
 
+/* w32reg.c */
+extern const char *w32_get_string_resource (void *v_rdb,
+                                            const char *name,
+                                            const char *class);
 \f
 #define PIX_TYPE COLORREF
 
@@ -403,12 +407,12 @@ struct w32_output
 
 extern struct w32_output w32term_display;
 
-/* Return the X output data for frame F.  */
-#define FRAME_X_OUTPUT(f) ((f)->output_data.w32)
+/* Return the output data for frame F.  */
+#define FRAME_OUTPUT_DATA(f) ((f)->output_data.w32)
 
 /* Return the window associated with the frame F.  */
 #define FRAME_W32_WINDOW(f) ((f)->output_data.w32->window_desc)
-#define FRAME_X_WINDOW(f) FRAME_W32_WINDOW (f)
+#define FRAME_NATIVE_WINDOW(f) FRAME_W32_WINDOW (f)
 
 #define FRAME_FONT(f) ((f)->output_data.w32->font)
 #define FRAME_FONTSET(f) ((f)->output_data.w32->fontset)
diff --git a/src/window.c b/src/window.c
index d805d2f8b9..30ffad0e51 100644
--- a/src/window.c
+++ b/src/window.c
@@ -3434,7 +3434,7 @@ run_window_configuration_change_hook (struct frame *f)
   XSETFRAME (frame, f);
 
   if (NILP (Vrun_hooks)
-      || !f->can_x_set_window_size
+      || !f->can_set_window_size
       || !f->after_make_frame)
     return;
 
@@ -3763,7 +3763,7 @@ run_window_change_functions (void)
       ptrdiff_t number_of_windows;
 
       if (!FRAME_LIVE_P (f)
-	  || !f->can_x_set_window_size
+	  || !f->can_set_window_size
 	  || !f->after_make_frame
 	  || FRAME_TOOLTIP_P (f)
 	  || !(frame_window_change
@@ -6867,8 +6867,8 @@ the return value is nil.  Otherwise the value is t.  */)
 	    call1 (Qrecord_window_buffer, window);
 	}
 
-      /* Disallow x_set_window_size, temporarily.  */
-      f->can_x_set_window_size = false;
+      /* Disallow set_window_size_hook, temporarily.  */
+      f->can_set_window_size = false;
       /* The mouse highlighting code could get screwed up
 	 if it runs during this.  */
       block_input ();
@@ -7072,9 +7072,9 @@ the return value is nil.  Otherwise the value is t.  */)
 	if (NILP (leaf_windows[i]->contents))
 	  free_window_matrices (leaf_windows[i]);
 
-      /* Allow x_set_window_size again and apply frame size changes if
-	 needed.  */
-      f->can_x_set_window_size = true;
+      /* Allow set_window_size_hook again and apply frame size changes
+	 if needed.  */
+      f->can_set_window_size = true;
       adjust_frame_size (f, -1, -1, 1, false, Qset_window_configuration);
 
       adjust_frame_glyphs (f);
diff --git a/src/xdisp.c b/src/xdisp.c
index 11667d2735..371fdf462a 100644
--- a/src/xdisp.c
+++ b/src/xdisp.c
@@ -336,8 +336,8 @@ along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
 #include TERM_HEADER
 #endif /* HAVE_WINDOW_SYSTEM */
 
-#ifndef FRAME_X_OUTPUT
-#define FRAME_X_OUTPUT(f) ((f)->output_data.x)
+#ifndef FRAME_OUTPUT_DATA
+#define FRAME_OUTPUT_DATA(f) (NULL)
 #endif
 
 #define DISP_INFINITY 10000000
@@ -11275,7 +11275,7 @@ resize_mini_window (struct window *w, bool exact_p)
   /* Nil means don't try to resize.  */
   if ((NILP (Vresize_mini_windows)
        && (NILP (resize_mini_frames) || !FRAME_MINIBUF_ONLY_P (f)))
-      || (FRAME_X_P (f) && FRAME_X_OUTPUT (f) == NULL))
+      || (FRAME_X_P (f) && FRAME_OUTPUT_DATA (f) == NULL))
     return false;
 
   /* By default, start display at the beginning.  */
@@ -30018,13 +30018,13 @@ show_mouse_face (Mouse_HLInfo *hlinfo, enum draw_glyphs_face draw)
 #ifndef HAVE_EXT_TOOL_BAR
       if (draw == DRAW_NORMAL_TEXT
 	  && !EQ (hlinfo->mouse_face_window, f->tool_bar_window))
-	FRAME_RIF (f)->define_frame_cursor (f, FRAME_X_OUTPUT (f)->text_cursor);
+	FRAME_RIF (f)->define_frame_cursor (f, FRAME_OUTPUT_DATA (f)->text_cursor);
       else
 #endif
       if (draw == DRAW_MOUSE_FACE)
-	FRAME_RIF (f)->define_frame_cursor (f, FRAME_X_OUTPUT (f)->hand_cursor);
+	FRAME_RIF (f)->define_frame_cursor (f, FRAME_OUTPUT_DATA (f)->hand_cursor);
       else
-	FRAME_RIF (f)->define_frame_cursor (f, FRAME_X_OUTPUT (f)->nontext_cursor);
+	FRAME_RIF (f)->define_frame_cursor (f, FRAME_OUTPUT_DATA (f)->nontext_cursor);
     }
 #endif	/* HAVE_WINDOW_SYSTEM */
 }
@@ -30966,25 +30966,25 @@ define_frame_cursor1 (struct frame *f, Cursor cursor, Lisp_Object pointer)
   if (!NILP (pointer))
     {
       if (EQ (pointer, Qarrow))
-	cursor = FRAME_X_OUTPUT (f)->nontext_cursor;
+	cursor = FRAME_OUTPUT_DATA (f)->nontext_cursor;
       else if (EQ (pointer, Qhand))
-	cursor = FRAME_X_OUTPUT (f)->hand_cursor;
+	cursor = FRAME_OUTPUT_DATA (f)->hand_cursor;
       else if (EQ (pointer, Qtext))
-	cursor = FRAME_X_OUTPUT (f)->text_cursor;
+	cursor = FRAME_OUTPUT_DATA (f)->text_cursor;
       else if (EQ (pointer, intern ("hdrag")))
-	cursor = FRAME_X_OUTPUT (f)->horizontal_drag_cursor;
+	cursor = FRAME_OUTPUT_DATA (f)->horizontal_drag_cursor;
       else if (EQ (pointer, intern ("nhdrag")))
-	cursor = FRAME_X_OUTPUT (f)->vertical_drag_cursor;
+	cursor = FRAME_OUTPUT_DATA (f)->vertical_drag_cursor;
 # ifdef HAVE_X_WINDOWS
       else if (EQ (pointer, intern ("vdrag")))
 	cursor = FRAME_DISPLAY_INFO (f)->vertical_scroll_bar_cursor;
 # endif
       else if (EQ (pointer, intern ("hourglass")))
-	cursor = FRAME_X_OUTPUT (f)->hourglass_cursor;
+	cursor = FRAME_OUTPUT_DATA (f)->hourglass_cursor;
       else if (EQ (pointer, Qmodeline))
-	cursor = FRAME_X_OUTPUT (f)->modeline_cursor;
+	cursor = FRAME_OUTPUT_DATA (f)->modeline_cursor;
       else
-	cursor = FRAME_X_OUTPUT (f)->nontext_cursor;
+	cursor = FRAME_OUTPUT_DATA (f)->nontext_cursor;
     }
 
   if (cursor != No_Cursor)
@@ -31136,7 +31136,7 @@ note_mode_line_or_margin_highlight (Lisp_Object window, int x, int y,
 
 	  if (STRINGP (string))
 	    {
-	      cursor = FRAME_X_OUTPUT (f)->nontext_cursor;
+	      cursor = FRAME_OUTPUT_DATA (f)->nontext_cursor;
 
 	      if (NILP (pointer))
 		pointer = Fget_text_property (pos, Qpointer, string);
@@ -31151,13 +31151,13 @@ note_mode_line_or_margin_highlight (Lisp_Object window, int x, int y,
 		  if (!KEYMAPP (map))
 		    map = Fget_text_property (pos, Qkeymap, string);
 		  if (!KEYMAPP (map) && draggable && area == ON_MODE_LINE)
-		    cursor = FRAME_X_OUTPUT (f)->vertical_drag_cursor;
+		    cursor = FRAME_OUTPUT_DATA (f)->vertical_drag_cursor;
 		}
 	    }
 	  else if (draggable && area == ON_MODE_LINE)
-	    cursor = FRAME_X_OUTPUT (f)->vertical_drag_cursor;
+	    cursor = FRAME_OUTPUT_DATA (f)->vertical_drag_cursor;
 	  else
-	    cursor = FRAME_X_OUTPUT (f)->nontext_cursor;
+	    cursor = FRAME_OUTPUT_DATA (f)->nontext_cursor;
 	}
 #endif
     }
@@ -31366,41 +31366,41 @@ note_mouse_highlight (struct frame *f, int x, int y)
       switch (part)
 	{
 	case INTERNAL_BORDER_NONE:
-	  if (cursor != FRAME_X_OUTPUT (f)->nontext_cursor)
+	  if (cursor != FRAME_OUTPUT_DATA (f)->nontext_cursor)
 	    /* Reset cursor.  */
-	    cursor = FRAME_X_OUTPUT (f)->nontext_cursor;
+	    cursor = FRAME_OUTPUT_DATA (f)->nontext_cursor;
 	  break;
 	case INTERNAL_BORDER_LEFT_EDGE:
-	  cursor = FRAME_X_OUTPUT (f)->left_edge_cursor;
+	  cursor = FRAME_OUTPUT_DATA (f)->left_edge_cursor;
 	  break;
 	case INTERNAL_BORDER_TOP_LEFT_CORNER:
-	  cursor = FRAME_X_OUTPUT (f)->top_left_corner_cursor;
+	  cursor = FRAME_OUTPUT_DATA (f)->top_left_corner_cursor;
 	  break;
 	case INTERNAL_BORDER_TOP_EDGE:
-	  cursor = FRAME_X_OUTPUT (f)->top_edge_cursor;
+	  cursor = FRAME_OUTPUT_DATA (f)->top_edge_cursor;
 	  break;
 	case INTERNAL_BORDER_TOP_RIGHT_CORNER:
-	  cursor = FRAME_X_OUTPUT (f)->top_right_corner_cursor;
+	  cursor = FRAME_OUTPUT_DATA (f)->top_right_corner_cursor;
 	  break;
 	case INTERNAL_BORDER_RIGHT_EDGE:
-	  cursor = FRAME_X_OUTPUT (f)->right_edge_cursor;
+	  cursor = FRAME_OUTPUT_DATA (f)->right_edge_cursor;
 	  break;
 	case INTERNAL_BORDER_BOTTOM_RIGHT_CORNER:
-	  cursor = FRAME_X_OUTPUT (f)->bottom_right_corner_cursor;
+	  cursor = FRAME_OUTPUT_DATA (f)->bottom_right_corner_cursor;
 	  break;
 	case INTERNAL_BORDER_BOTTOM_EDGE:
-	  cursor = FRAME_X_OUTPUT (f)->bottom_edge_cursor;
+	  cursor = FRAME_OUTPUT_DATA (f)->bottom_edge_cursor;
 	  break;
 	case INTERNAL_BORDER_BOTTOM_LEFT_CORNER:
-	  cursor = FRAME_X_OUTPUT (f)->bottom_left_corner_cursor;
+	  cursor = FRAME_OUTPUT_DATA (f)->bottom_left_corner_cursor;
 	  break;
 	default:
 	  /* This should not happen.  */
-	  if (cursor != FRAME_X_OUTPUT (f)->nontext_cursor)
-	    cursor = FRAME_X_OUTPUT (f)->nontext_cursor;
+	  if (cursor != FRAME_OUTPUT_DATA (f)->nontext_cursor)
+	    cursor = FRAME_OUTPUT_DATA (f)->nontext_cursor;
 	}
 
-      if (cursor != FRAME_X_OUTPUT (f)->nontext_cursor)
+      if (cursor != FRAME_OUTPUT_DATA (f)->nontext_cursor)
 	{
 	  /* Do we really want a help echo here?  */
 	  help_echo_string = build_string ("drag-mouse-1: resize frame");
@@ -31436,7 +31436,7 @@ note_mouse_highlight (struct frame *f, int x, int y)
 #ifdef HAVE_WINDOW_SYSTEM
       if (part == ON_LEFT_MARGIN || part == ON_RIGHT_MARGIN)
 	{
-	  cursor = FRAME_X_OUTPUT (f)->nontext_cursor;
+	  cursor = FRAME_OUTPUT_DATA (f)->nontext_cursor;
 	  /* Show non-text cursor (Bug#16647).  */
 	  goto set_cursor;
 	}
@@ -31448,13 +31448,13 @@ note_mouse_highlight (struct frame *f, int x, int y)
 #ifdef HAVE_WINDOW_SYSTEM
   if (part == ON_VERTICAL_BORDER)
     {
-      cursor = FRAME_X_OUTPUT (f)->horizontal_drag_cursor;
+      cursor = FRAME_OUTPUT_DATA (f)->horizontal_drag_cursor;
       help_echo_string = build_string ("drag-mouse-1: resize");
       goto set_cursor;
     }
   else if (part == ON_RIGHT_DIVIDER)
     {
-      cursor = FRAME_X_OUTPUT (f)->horizontal_drag_cursor;
+      cursor = FRAME_OUTPUT_DATA (f)->horizontal_drag_cursor;
       help_echo_string = build_string ("drag-mouse-1: resize");
       goto set_cursor;
     }
@@ -31463,18 +31463,18 @@ note_mouse_highlight (struct frame *f, int x, int y)
 	|| minibuf_level
 	|| NILP (Vresize_mini_windows))
       {
-	cursor = FRAME_X_OUTPUT (f)->vertical_drag_cursor;
+	cursor = FRAME_OUTPUT_DATA (f)->vertical_drag_cursor;
 	help_echo_string = build_string ("drag-mouse-1: resize");
 	goto set_cursor;
       }
     else
-      cursor = FRAME_X_OUTPUT (f)->nontext_cursor;
+      cursor = FRAME_OUTPUT_DATA (f)->nontext_cursor;
   else if (part == ON_LEFT_FRINGE || part == ON_RIGHT_FRINGE
 	   || part == ON_VERTICAL_SCROLL_BAR
 	   || part == ON_HORIZONTAL_SCROLL_BAR)
-    cursor = FRAME_X_OUTPUT (f)->nontext_cursor;
+    cursor = FRAME_OUTPUT_DATA (f)->nontext_cursor;
   else
-    cursor = FRAME_X_OUTPUT (f)->text_cursor;
+    cursor = FRAME_OUTPUT_DATA (f)->text_cursor;
 #endif
 
   /* Are we in a window whose display is up to date?
@@ -31565,7 +31565,7 @@ note_mouse_highlight (struct frame *f, int x, int y)
 	    {
 #ifdef HAVE_WINDOW_SYSTEM
 	      if (area != TEXT_AREA)
-		cursor = FRAME_X_OUTPUT (f)->nontext_cursor;
+		cursor = FRAME_OUTPUT_DATA (f)->nontext_cursor;
 	      else
 		pointer = Vvoid_text_area_pointer;
 #endif
diff --git a/src/xfaces.c b/src/xfaces.c
index 24574ae141..3f627d3843 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -343,7 +343,7 @@ struct named_merge_point;
 
 static struct face *realize_face (struct face_cache *, Lisp_Object *,
 				  int);
-static struct face *realize_x_face (struct face_cache *, Lisp_Object *);
+static struct face *realize_gui_face (struct face_cache *, Lisp_Object *);
 static struct face *realize_tty_face (struct face_cache *, Lisp_Object *);
 static bool realize_basic_faces (struct frame *);
 static bool realize_default_face (struct frame *);
@@ -777,13 +777,13 @@ load_pixmap (struct frame *f, Lisp_Object name)
       h = XFIXNUM (Fcar (Fcdr (name)));
       bits = Fcar (Fcdr (Fcdr (name)));
 
-      bitmap_id = gui_create_bitmap_from_data (f, SSDATA (bits),
-                                               w, h);
+      bitmap_id = image_create_bitmap_from_data (f, SSDATA (bits),
+                                                 w, h);
     }
   else
     {
       /* It must be a string -- a file name.  */
-      bitmap_id = gui_create_bitmap_from_file (f, name);
+      bitmap_id = image_create_bitmap_from_file (f, name);
     }
   unblock_input ();
 
@@ -1188,7 +1188,7 @@ load_face_colors (struct frame *f, struct face *face,
   if (!face_color_supported_p (f, SSDATA (bg), false)
       && !NILP (Fbitmap_spec_p (Vface_default_stipple)))
     {
-      x_destroy_bitmap (f, face->stipple);
+      image_destroy_bitmap (f, face->stipple);
       face->stipple = load_pixmap (f, Vface_default_stipple);
     }
 
@@ -3484,8 +3484,8 @@ ordinary `x-get-resource' doesn't take a frame argument.  */)
   CHECK_STRING (class);
   f = decode_live_frame (frame);
   block_input ();
-  value = display_x_get_resource (FRAME_DISPLAY_INFO (f),
-				  resource, class, Qnil, Qnil);
+  value = gui_display_get_resource (FRAME_DISPLAY_INFO (f),
+                                    resource, class, Qnil, Qnil);
   unblock_input ();
   return value;
 }
@@ -4153,7 +4153,7 @@ free_realized_face (struct frame *f, struct face *face)
 #ifdef HAVE_X_WINDOWS
 	  free_face_colors (f, face);
 #endif /* HAVE_X_WINDOWS */
-	  x_destroy_bitmap (f, face->stipple);
+	  image_destroy_bitmap (f, face->stipple);
 	}
 #endif /* HAVE_WINDOW_SYSTEM */
 
@@ -4188,7 +4188,7 @@ prepare_face_for_display (struct frame *f, struct face *face)
       if (face->stipple)
 	{
 	  xgcv.fill_style = FillOpaqueStippled;
-	  xgcv.stipple = x_bitmap_pixmap (f, face->stipple);
+	  xgcv.stipple = image_bitmap_pixmap (f, face->stipple);
 	  mask |= GCFillStyle | GCStipple;
 	}
 #endif
@@ -4799,9 +4799,9 @@ DEFUN ("face-attributes-as-vector", Fface_attributes_as_vector,
     (2) `close in spirit' to what the attributes specify, if not exact.  */
 
 static bool
-x_supports_face_attributes_p (struct frame *f,
-			      Lisp_Object attrs[LFACE_VECTOR_SIZE],
-			      struct face *def_face)
+gui_supports_face_attributes_p (struct frame *f,
+                                Lisp_Object attrs[LFACE_VECTOR_SIZE],
+                                struct face *def_face)
 {
   Lisp_Object *def_attrs = def_face->lface;
 
@@ -5138,7 +5138,7 @@ face for italic.  */)
     supports = tty_supports_face_attributes_p (f, attrs, def_face);
 #ifdef HAVE_WINDOW_SYSTEM
   else
-    supports = x_supports_face_attributes_p (f, attrs, def_face);
+    supports = gui_supports_face_attributes_p (f, attrs, def_face);
 #endif
 
   return supports ? Qt : Qnil;
@@ -5524,7 +5524,7 @@ realize_face (struct face_cache *cache, Lisp_Object attrs[LFACE_VECTOR_SIZE],
     }
 
   if (FRAME_WINDOW_P (cache->f))
-    face = realize_x_face (cache, attrs);
+    face = realize_gui_face (cache, attrs);
   else if (FRAME_TERMCAP_P (cache->f) || FRAME_MSDOS_P (cache->f))
     face = realize_tty_face (cache, attrs);
   else if (FRAME_INITIAL_P (cache->f))
@@ -5575,14 +5575,14 @@ realize_non_ascii_face (struct frame *f, Lisp_Object font_object,
 
 
 /* Realize the fully-specified face with attributes ATTRS in face
-   cache CACHE for ASCII characters.  Do it for X frame CACHE->f.  If
-   the new face doesn't share font with the default face, a fontname
-   is allocated from the heap and set in `font_name' of the new face,
-   but it is not yet loaded here.  Value is a pointer to the newly
-   created realized face.  */
+   cache CACHE for ASCII characters.  Do it for GUI frame CACHE->f.
+   If the new face doesn't share font with the default face, a
+   fontname is allocated from the heap and set in `font_name' of the
+   new face, but it is not yet loaded here.  Value is a pointer to the
+   newly created realized face.  */
 
 static struct face *
-realize_x_face (struct face_cache *cache, Lisp_Object attrs[LFACE_VECTOR_SIZE])
+realize_gui_face (struct face_cache *cache, Lisp_Object attrs[LFACE_VECTOR_SIZE])
 {
   struct face *face = NULL;
 #ifdef HAVE_WINDOW_SYSTEM
diff --git a/src/xfns.c b/src/xfns.c
index 392185157a..11e2315194 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -1466,7 +1466,7 @@ x_set_icon_type (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
 				   ? f->icon_name
 				   : f->name)));
   else
-    result = x_bitmap_icon (f, arg);
+    result = FRAME_TERMINAL (f)->set_bitmap_icon_hook (f, arg);
 
   if (result)
     {
@@ -2056,7 +2056,7 @@ x_set_title (struct frame *f, Lisp_Object name, Lisp_Object old_name)
   x_set_name_internal (f, name);
 }
 
-static void
+void
 x_set_scroll_bar_default_width (struct frame *f)
 {
   int unit = FRAME_COLUMN_WIDTH (f);
@@ -2077,7 +2077,7 @@ x_set_scroll_bar_default_width (struct frame *f)
 #endif
 }
 
-static void
+void
 x_set_scroll_bar_default_height (struct frame *f)
 {
   int height = FRAME_LINE_HEIGHT (f);
@@ -2115,7 +2115,8 @@ x_default_scroll_bar_color_parameter (struct frame *f,
   struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
   Lisp_Object tem;
 
-  tem = x_get_arg (dpyinfo, alist, prop, xprop, xclass, RES_TYPE_STRING);
+  tem = gui_display_get_arg (dpyinfo, alist, prop, xprop, xclass,
+                             RES_TYPE_STRING);
   if (EQ (tem, Qunbound))
     {
 #ifdef USE_TOOLKIT_SCROLL_BARS
@@ -2125,7 +2126,7 @@ x_default_scroll_bar_color_parameter (struct frame *f,
       AUTO_STRING (foreground, "foreground");
       AUTO_STRING (background, "foreground");
       AUTO_STRING (verticalScrollBar, "verticalScrollBar");
-      tem = (display_x_get_resource
+      tem = (gui_display_get_resource
 	     (dpyinfo, foreground_p ? foreground : background,
 	      empty_unibyte_string,
 	      verticalScrollBar,
@@ -3257,8 +3258,8 @@ x_icon_verify (struct frame *f, Lisp_Object parms)
 
   /* Set the position of the icon.  Note that twm groups all
      icons in an icon window.  */
-  icon_x = x_frame_get_and_record_arg (f, parms, Qicon_left, 0, 0, RES_TYPE_NUMBER);
-  icon_y = x_frame_get_and_record_arg (f, parms, Qicon_top, 0, 0, RES_TYPE_NUMBER);
+  icon_x = gui_frame_get_and_record_arg (f, parms, Qicon_left, 0, 0, RES_TYPE_NUMBER);
+  icon_y = gui_frame_get_and_record_arg (f, parms, Qicon_top, 0, 0, RES_TYPE_NUMBER);
   if (!EQ (icon_x, Qunbound) && !EQ (icon_y, Qunbound))
     {
       CHECK_FIXNUM (icon_x);
@@ -3278,9 +3279,9 @@ x_icon (struct frame *f, Lisp_Object parms)
   /* Set the position of the icon.  Note that twm groups all
      icons in an icon window.  */
   Lisp_Object icon_x
-    = x_frame_get_and_record_arg (f, parms, Qicon_left, 0, 0, RES_TYPE_NUMBER);
+    = gui_frame_get_and_record_arg (f, parms, Qicon_left, 0, 0, RES_TYPE_NUMBER);
   Lisp_Object icon_y
-    = x_frame_get_and_record_arg (f, parms, Qicon_top, 0, 0, RES_TYPE_NUMBER);
+    = gui_frame_get_and_record_arg (f, parms, Qicon_top, 0, 0, RES_TYPE_NUMBER);
   if (!EQ (icon_x, Qunbound) && !EQ (icon_y, Qunbound))
     {
       CHECK_TYPE_RANGED_INTEGER (int, icon_x);
@@ -3294,12 +3295,13 @@ x_icon (struct frame *f, Lisp_Object parms)
   if (! EQ (icon_x, Qunbound))
     x_wm_set_icon_position (f, XFIXNUM (icon_x), XFIXNUM (icon_y));
 
-#if false /* x_get_arg removes the visibility parameter as a side effect,
-	     but x_create_frame still needs it.  */
+#if false /* gui_display_get_arg removes the visibility parameter as a
+	     side effect, but x_create_frame still needs it.  */
   /* Start up iconic or window? */
   struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
   x_wm_set_window_state
-    (f, (EQ (x_get_arg (dpyinfo, parms, Qvisibility, 0, 0, RES_TYPE_SYMBOL),
+    (f, (EQ (gui_display_get_arg (dpyinfo, parms, Qvisibility, 0, 0,
+                                  RES_TYPE_SYMBOL),
 	     Qicon)
 	 ? IconicState
 	 : NormalState));
@@ -3463,8 +3465,8 @@ static void
 x_default_font_parameter (struct frame *f, Lisp_Object parms)
 {
   struct x_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
-  Lisp_Object font_param = x_get_arg (dpyinfo, parms, Qfont, NULL, NULL,
-                                      RES_TYPE_STRING);
+  Lisp_Object font_param = gui_display_get_arg (dpyinfo, parms, Qfont, NULL, NULL,
+                                                RES_TYPE_STRING);
   Lisp_Object font = Qnil;
   if (EQ (font_param, Qunbound))
     font_param = Qnil;
@@ -3481,7 +3483,8 @@ x_default_font_parameter (struct frame *f, Lisp_Object parms)
 
   if (NILP (font))
       font = !NILP (font_param) ? font_param
-      : x_get_arg (dpyinfo, parms, Qfont, "font", "Font", RES_TYPE_STRING);
+      : gui_display_get_arg (dpyinfo, parms, Qfont, "font", "Font",
+                             RES_TYPE_STRING);
 
   if (! FONTP (font) && ! STRINGP (font))
     {
@@ -3592,9 +3595,11 @@ This function is an internal primitive--use `make-frame' instead.  */)
      until we know if this frame has a specified name.  */
   Vx_resource_name = Vinvocation_name;
 
-  display = x_get_arg (dpyinfo, parms, Qterminal, 0, 0, RES_TYPE_NUMBER);
+  display = gui_display_get_arg (dpyinfo, parms, Qterminal, 0, 0,
+                                 RES_TYPE_NUMBER);
   if (EQ (display, Qunbound))
-    display = x_get_arg (dpyinfo, parms, Qdisplay, 0, 0, RES_TYPE_STRING);
+    display = gui_display_get_arg (dpyinfo, parms, Qdisplay, 0, 0,
+                                   RES_TYPE_STRING);
   if (EQ (display, Qunbound))
     display = Qnil;
   dpyinfo = check_x_display_info (display);
@@ -3603,7 +3608,8 @@ This function is an internal primitive--use `make-frame' instead.  */)
   if (!dpyinfo->terminal->name)
     error ("Terminal is not live, can't create new frames on it");
 
-  name = x_get_arg (dpyinfo, parms, Qname, "name", "Name", RES_TYPE_STRING);
+  name = gui_display_get_arg (dpyinfo, parms, Qname, "name", "Name",
+                              RES_TYPE_STRING);
   if (!STRINGP (name)
       && ! EQ (name, Qunbound)
       && ! NILP (name))
@@ -3613,15 +3619,17 @@ This function is an internal primitive--use `make-frame' instead.  */)
     Vx_resource_name = name;
 
   /* See if parent window is specified.  */
-  parent = x_get_arg (dpyinfo, parms, Qparent_id, NULL, NULL, RES_TYPE_NUMBER);
+  parent = gui_display_get_arg (dpyinfo, parms, Qparent_id, NULL, NULL,
+                                RES_TYPE_NUMBER);
   if (EQ (parent, Qunbound))
     parent = Qnil;
   if (! NILP (parent))
     CHECK_FIXNUM (parent);
 
   frame = Qnil;
-  tem = x_get_arg (dpyinfo, parms, Qminibuffer, "minibuffer", "Minibuffer",
-		   RES_TYPE_SYMBOL);
+  tem = gui_display_get_arg (dpyinfo,
+                             parms, Qminibuffer, "minibuffer", "Minibuffer",
+                             RES_TYPE_SYMBOL);
   if (EQ (tem, Qnone) || NILP (tem))
     f = make_frame_without_minibuffer (Qnil, kb, display);
   else if (EQ (tem, Qonly))
@@ -3634,8 +3642,12 @@ This function is an internal primitive--use `make-frame' instead.  */)
   else
     f = make_frame (true);
 
-  parent_frame = x_get_arg (dpyinfo, parms, Qparent_frame, NULL, NULL,
-			    RES_TYPE_SYMBOL);
+  parent_frame = gui_display_get_arg (dpyinfo,
+                                      parms,
+                                      Qparent_frame,
+                                      NULL,
+                                      NULL,
+                                      RES_TYPE_SYMBOL);
   /* Accept parent-frame iff parent-id was not specified.  */
   if (!NILP (parent)
       || EQ (parent_frame, Qunbound)
@@ -3648,16 +3660,24 @@ This function is an internal primitive--use `make-frame' instead.  */)
   fset_parent_frame (f, parent_frame);
   store_frame_param (f, Qparent_frame, parent_frame);
 
-  if (!NILP (tem = (x_get_arg (dpyinfo, parms, Qundecorated, NULL, NULL,
-			       RES_TYPE_BOOLEAN)))
+  if (!NILP (tem = (gui_display_get_arg (dpyinfo,
+                                         parms,
+                                         Qundecorated,
+                                         NULL,
+                                         NULL,
+                                         RES_TYPE_BOOLEAN)))
       && !(EQ (tem, Qunbound)))
     undecorated = true;
 
   FRAME_UNDECORATED (f) = undecorated;
   store_frame_param (f, Qundecorated, undecorated ? Qt : Qnil);
 
-  if (!NILP (tem = (x_get_arg (dpyinfo, parms, Qoverride_redirect, NULL, NULL,
-			       RES_TYPE_BOOLEAN)))
+  if (!NILP (tem = (gui_display_get_arg (dpyinfo,
+                                         parms,
+                                         Qoverride_redirect,
+                                         NULL,
+                                         NULL,
+                                         RES_TYPE_BOOLEAN)))
       && !(EQ (tem, Qunbound)))
     override_redirect = true;
 
@@ -3681,9 +3701,12 @@ This function is an internal primitive--use `make-frame' instead.  */)
   f->output_data.x->white_relief.pixel = -1;
   f->output_data.x->black_relief.pixel = -1;
 
-  fset_icon_name (f,
-		  x_get_arg (dpyinfo, parms, Qicon_name, "iconName", "Title",
-			     RES_TYPE_STRING));
+  fset_icon_name (f, gui_display_get_arg (dpyinfo,
+                                          parms,
+                                          Qicon_name,
+                                          "iconName",
+                                          "Title",
+                                          RES_TYPE_STRING));
   if (! STRINGP (f->icon_name))
     fset_icon_name (f, Qnil);
 
@@ -3792,8 +3815,9 @@ This function is an internal primitive--use `make-frame' instead.  */)
     {
       Lisp_Object value;
 
-      value = x_get_arg (dpyinfo, parms, Qinternal_border_width,
-			 "internalBorder", "internalBorder", RES_TYPE_NUMBER);
+      value = gui_display_get_arg (dpyinfo, parms, Qinternal_border_width,
+                                   "internalBorder", "internalBorder",
+                                   RES_TYPE_NUMBER);
       if (! EQ (value, Qunbound))
 	parms = Fcons (Fcons (Qinternal_border_width, value),
 		       parms);
@@ -3865,15 +3889,17 @@ This function is an internal primitive--use `make-frame' instead.  */)
 
      Also process `min-width' and `min-height' parameters right here
      because `frame-windows-min-size' needs them.  */
-  tem = x_get_arg (dpyinfo, parms, Qmin_width, NULL, NULL, RES_TYPE_NUMBER);
+  tem = gui_display_get_arg (dpyinfo, parms, Qmin_width, NULL, NULL,
+                             RES_TYPE_NUMBER);
   if (FIXNUMP (tem))
     store_frame_param (f, Qmin_width, tem);
-  tem = x_get_arg (dpyinfo, parms, Qmin_height, NULL, NULL, RES_TYPE_NUMBER);
+  tem = gui_display_get_arg (dpyinfo, parms, Qmin_height, NULL, NULL,
+                             RES_TYPE_NUMBER);
   if (FIXNUMP (tem))
     store_frame_param (f, Qmin_height, tem);
   adjust_frame_size (f, FRAME_COLS (f) * FRAME_COLUMN_WIDTH (f),
 		     FRAME_LINES (f) * FRAME_LINE_HEIGHT (f), 5, true,
-		     Qx_create_frame_1);
+		     Qgui_create_frame_1);
 
   /* Set the menu-bar-lines and tool-bar-lines parameters.  We don't
      look up the X resources controlling the menu-bar and tool-bar
@@ -3906,7 +3932,8 @@ This function is an internal primitive--use `make-frame' instead.  */)
   window_prompting = gui_figure_window_size (f, parms, true,
                                              &x_width, &x_height);
 
-  tem = x_get_arg (dpyinfo, parms, Qunsplittable, 0, 0, RES_TYPE_BOOLEAN);
+  tem = gui_display_get_arg (dpyinfo, parms, Qunsplittable, 0, 0,
+                             RES_TYPE_BOOLEAN);
   f->no_split = minibuffer_only || EQ (tem, Qt);
 
   x_icon_verify (f, parms);
@@ -3980,7 +4007,7 @@ This function is an internal primitive--use `make-frame' instead.  */)
 #endif /* USE_X_TOOLKIT || USE_GTK */
 
   /* Consider frame official, now.  */
-  f->can_x_set_window_size = true;
+  f->can_set_window_size = true;
 
   if (x_width > 0)
     SET_FRAME_WIDTH (f, x_width);
@@ -3995,7 +4022,7 @@ This function is an internal primitive--use `make-frame' instead.  */)
   unblock_input ();
 
   adjust_frame_size (f, FRAME_TEXT_WIDTH (f), FRAME_TEXT_HEIGHT (f),
-		     0, true, Qx_create_frame_2);
+		     0, true, Qgui_create_frame_2);
 
   /* Process fullscreen parameter here in the hope that normalizing a
      fullheight/fullwidth frame will produce the size set by the last
@@ -4009,7 +4036,8 @@ This function is an internal primitive--use `make-frame' instead.  */)
   if (!f->output_data.x->explicit_parent)
     {
       Lisp_Object visibility
-	= x_get_arg (dpyinfo, parms, Qvisibility, 0, 0, RES_TYPE_SYMBOL);
+	= gui_display_get_arg (dpyinfo, parms, Qvisibility, 0, 0,
+                               RES_TYPE_SYMBOL);
 
       if (EQ (visibility, Qicon))
 	x_iconify_frame (f);
@@ -4057,8 +4085,9 @@ This function is an internal primitive--use `make-frame' instead.  */)
           || !FRAME_LIVE_P (XFRAME (KVAR (kb, Vdefault_minibuffer_frame)))))
     kset_default_minibuffer_frame (kb, frame);
 
-  /* All remaining specified parameters, which have not been "used"
-     by x_get_arg and friends, now go in the misc. alist of the frame.  */
+  /* All remaining specified parameters, which have not been "used" by
+     gui_display_get_arg and friends, now go in the misc. alist of the
+     frame.  */
   for (tem = parms; CONSP (tem); tem = XCDR (tem))
     if (CONSP (XCAR (tem)) && !NILP (XCAR (XCAR (tem))))
       fset_param_alist (f, Fcons (XCAR (tem), f->param_alist));
@@ -5482,8 +5511,8 @@ select_visual (struct x_display_info *dpyinfo)
   /* See if a visual is specified.  */
   AUTO_STRING (visualClass, "visualClass");
   AUTO_STRING (VisualClass, "VisualClass");
-  Lisp_Object value = display_x_get_resource (dpyinfo, visualClass,
-					      VisualClass, Qnil, Qnil);
+  Lisp_Object value = gui_display_get_resource (dpyinfo, visualClass,
+                                                VisualClass, Qnil, Qnil);
 
   if (STRINGP (value))
     {
@@ -6091,7 +6120,8 @@ x_create_tip_frame (struct x_display_info *dpyinfo, Lisp_Object parms)
   parms = Fcopy_alist (parms);
 
   /* Get the name of the frame to use for resource lookup.  */
-  name = x_get_arg (dpyinfo, parms, Qname, "name", "Name", RES_TYPE_STRING);
+  name = gui_display_get_arg (dpyinfo, parms, Qname, "name", "Name",
+                              RES_TYPE_STRING);
   if (!STRINGP (name)
       && !EQ (name, Qunbound)
       && !NILP (name))
@@ -6209,8 +6239,9 @@ x_create_tip_frame (struct x_display_info *dpyinfo, Lisp_Object parms)
     {
       Lisp_Object value;
 
-      value = x_get_arg (dpyinfo, parms, Qinternal_border_width,
-			 "internalBorder", "internalBorder", RES_TYPE_NUMBER);
+      value = gui_display_get_arg (dpyinfo, parms, Qinternal_border_width,
+                                   "internalBorder", "internalBorder",
+                                   RES_TYPE_NUMBER);
       if (! EQ (value, Qunbound))
 	parms = Fcons (Fcons (Qinternal_border_width, value),
 		       parms);
@@ -6366,7 +6397,7 @@ x_create_tip_frame (struct x_display_info *dpyinfo, Lisp_Object parms)
      below.  And the frame needs to be on Vframe_list or making it
      visible won't work.  */
   Vframe_list = Fcons (frame, Vframe_list);
-  f->can_x_set_window_size = true;
+  f->can_set_window_size = true;
 
   /* Setting attributes of faces of the tooltip frame from resources
      and similar will set face_change, which leads to the clearing of
diff --git a/src/xrdb.c b/src/xrdb.c
index 35de446cb7..06db98c498 100644
--- a/src/xrdb.c
+++ b/src/xrdb.c
@@ -60,12 +60,12 @@ x_get_customization_string (XrmDatabase db, const char *name,
 {
   char *full_name = alloca (strlen (name) + sizeof "customization" + 3);
   char *full_class = alloca (strlen (class) + sizeof "Customization" + 3);
-  char *result;
+  const char *result;
 
   sprintf (full_name,  "%s.%s", name,  "customization");
   sprintf (full_class, "%s.%s", class, "Customization");
 
-  result = x_get_string_resource (db, full_name, full_class);
+  result = x_get_string_resource (&db, full_name, full_class);
   return result ? xstrdup (result) : NULL;
 }
 
@@ -547,19 +547,20 @@ x_get_resource (XrmDatabase rdb, const char *name, const char *class,
 /* Retrieve the string resource specified by NAME with CLASS from
    database RDB. */
 
-char *
-x_get_string_resource (XrmDatabase rdb, const char *name, const char *class)
+const char *
+x_get_string_resource (void *v_rdb, const char *name, const char *class)
 {
+  XrmDatabase *rdb = v_rdb;
   XrmValue value;
 
   if (inhibit_x_resources)
     /* --quick was passed, so this is a no-op.  */
     return NULL;
 
-  if (x_get_resource (rdb, name, class, x_rm_string, &value))
-    return (char *) value.addr;
+  if (x_get_resource (*rdb, name, class, x_rm_string, &value))
+    return (const char *) value.addr;
 
-  return 0;
+  return NULL;
 }
 \f
 /* Stand-alone test facilities.  */
@@ -648,7 +649,7 @@ main (int argc, char **argv)
 	  printf ("Class: ");
 	  gets (query_class);
 
-	  value = x_get_string_resource (xdb, query_name, query_class);
+	  value = x_get_string_resource (&xdb, query_name, query_class);
 
 	  if (value != NULL)
 	    printf ("\t%s(%s):  %s\n\n", query_name, query_class, value);
diff --git a/src/xterm.c b/src/xterm.c
index 785a50bd3a..15ff326ec1 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -9541,7 +9541,7 @@ x_draw_window_cursor (struct window *w, struct glyph_row *glyph_row, int x,
 
 /* Make the x-window of frame F use the gnu icon bitmap.  */
 
-bool
+static bool
 x_bitmap_icon (struct frame *f, Lisp_Object file)
 {
   ptrdiff_t bitmap_id;
@@ -9551,7 +9551,7 @@ x_bitmap_icon (struct frame *f, Lisp_Object file)
 
   /* Free up our existing icon bitmap and mask if any.  */
   if (f->output_data.x->icon_bitmap > 0)
-    x_destroy_bitmap (f, f->output_data.x->icon_bitmap);
+    image_destroy_bitmap (f, f->output_data.x->icon_bitmap);
   f->output_data.x->icon_bitmap = 0;
 
   if (STRINGP (file))
@@ -9562,7 +9562,7 @@ x_bitmap_icon (struct frame *f, Lisp_Object file)
       if (xg_set_icon (f, file))
 	return false;
 #endif /* USE_GTK */
-      bitmap_id = gui_create_bitmap_from_file (f, file);
+      bitmap_id = image_create_bitmap_from_file (f, file);
       x_create_bitmap_mask (f, bitmap_id);
     }
   else
@@ -9592,8 +9592,10 @@ x_bitmap_icon (struct frame *f, Lisp_Object file)
 	  /* If all else fails, use the (black and white) xbm image. */
 	  if (rc == -1)
 	    {
-              rc = gui_create_bitmap_from_data (f, (char *) gnu_xbm_bits,
-                                                gnu_xbm_width, gnu_xbm_height);
+              rc = image_create_bitmap_from_data (f,
+                                                  (char *) gnu_xbm_bits,
+                                                  gnu_xbm_width,
+                                                  gnu_xbm_height);
 	      if (rc == -1)
 		return true;
 
@@ -9606,7 +9608,7 @@ x_bitmap_icon (struct frame *f, Lisp_Object file)
 	 this increments the ref-count one extra time.
 	 As a result, the GNU bitmap and mask are never freed.
 	 That way, we don't have to worry about allocating it again.  */
-      gui_reference_bitmap (f, FRAME_DISPLAY_INFO (f)->icon_bitmap_id);
+      image_reference_bitmap (f, FRAME_DISPLAY_INFO (f)->icon_bitmap_id);
 
       bitmap_id = FRAME_DISPLAY_INFO (f)->icon_bitmap_id;
     }
@@ -9637,7 +9639,7 @@ x_text_icon (struct frame *f, const char *icon_name)
   }
 
   if (f->output_data.x->icon_bitmap > 0)
-    x_destroy_bitmap (f, f->output_data.x->icon_bitmap);
+    image_destroy_bitmap (f, f->output_data.x->icon_bitmap);
   f->output_data.x->icon_bitmap = 0;
   x_wm_set_icon_pixmap (f, 0);
 
@@ -10140,7 +10142,7 @@ xim_open_dpy (struct x_display_info *dpyinfo, char *resource_name)
     {
       if (dpyinfo->xim)
 	XCloseIM (dpyinfo->xim);
-      xim = XOpenIM (dpyinfo->display, dpyinfo->xrdb, resource_name,
+      xim = XOpenIM (dpyinfo->display, dpyinfo->rdb, resource_name,
 		     emacs_class);
       dpyinfo->xim = xim;
 
@@ -10239,7 +10241,7 @@ xim_initialize (struct x_display_info *dpyinfo, char *resource_name)
       xim_inst->dpyinfo = dpyinfo;
       xim_inst->resource_name = xstrdup (resource_name);
       ret = XRegisterIMInstantiateCallback
-	(dpyinfo->display, dpyinfo->xrdb, xim_inst->resource_name,
+	(dpyinfo->display, dpyinfo->rdb, xim_inst->resource_name,
 	 emacs_class, xim_instantiate_callback,
 	 /* This is XPointer in XFree86 but (XPointer *)
 	    on Tru64, at least, hence the configure test.  */
@@ -10267,7 +10269,7 @@ xim_close_dpy (struct x_display_info *dpyinfo)
       if (dpyinfo->display)
 	{
 	  Bool ret = XUnregisterIMInstantiateCallback
-	    (dpyinfo->display, dpyinfo->xrdb, xim_inst->resource_name,
+	    (dpyinfo->display, dpyinfo->rdb, xim_inst->resource_name,
 	     emacs_class, xim_instantiate_callback,
 	     (XRegisterIMInstantiateCallback_arg6) xim_inst);
 	  eassert (ret == True);
@@ -10383,7 +10385,7 @@ x_calc_absolute_position (struct frame *f)
    position values).  It is -1 when calling from gui_set_frame_parameters,
    which means, do adjust for borders but don't change the gravity.  */
 
-void
+static void
 x_set_offset (struct frame *f, register int xoff, register int yoff, int change_gravity)
 {
   int modified_top, modified_left;
@@ -10796,7 +10798,7 @@ do_ewmh_fullscreen (struct frame *f)
   int cur;
   bool dummy;
 
-  get_current_wm_state (f, FRAME_OUTER_WINDOW (f), &cur, &dummy);
+  x_get_current_wm_state (f, FRAME_OUTER_WINDOW (f), &cur, &dummy);
 
   /* Some window managers don't say they support _NET_WM_STATE, but they do say
      they support _NET_WM_STATE_FULLSCREEN.  Try that also.  */
@@ -11201,7 +11203,7 @@ x_set_window_size_1 (struct frame *f, bool change_gravity,
   if (EQ (fullscreen, Qfullwidth) && width == FRAME_TEXT_WIDTH (f))
     {
       frame_size_history_add
-	(f, Qx_set_window_size_1, width, height,
+	(f, Qgui_set_window_size_1, width, height,
 	 list2i (old_height, pixelheight + FRAME_MENUBAR_HEIGHT (f)));
 
       XResizeWindow (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f),
@@ -11210,7 +11212,7 @@ x_set_window_size_1 (struct frame *f, bool change_gravity,
   else if (EQ (fullscreen, Qfullheight) && height == FRAME_TEXT_HEIGHT (f))
     {
       frame_size_history_add
-	(f, Qx_set_window_size_2, width, height,
+	(f, Qgui_set_window_size_2, width, height,
 	 list2i (old_width, pixelwidth));
 
       XResizeWindow (FRAME_X_DISPLAY (f), FRAME_OUTER_WINDOW (f),
@@ -11220,7 +11222,7 @@ x_set_window_size_1 (struct frame *f, bool change_gravity,
   else
     {
       frame_size_history_add
-	(f, Qx_set_window_size_3, width, height,
+	(f, Qgui_set_window_size_3, width, height,
 	 list3i (pixelwidth + FRAME_TOOLBAR_WIDTH (f),
 		 (pixelheight + FRAME_TOOLBAR_HEIGHT (f)
 		  + FRAME_MENUBAR_HEIGHT (f)),
@@ -11358,7 +11360,7 @@ frame_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y)
 \f
 /* Raise frame F.  */
 
-void
+static void
 x_raise_frame (struct frame *f)
 {
   block_input ();
@@ -12169,7 +12171,7 @@ x_wm_set_icon_pixmap (struct frame *f, ptrdiff_t pixmap_id)
 
   if (pixmap_id > 0)
     {
-      icon_pixmap = x_bitmap_pixmap (f, pixmap_id);
+      icon_pixmap = image_bitmap_pixmap (f, pixmap_id);
       f->output_data.x->wm_hints.icon_pixmap = icon_pixmap;
       icon_mask = x_bitmap_mask (f, pixmap_id);
       f->output_data.x->wm_hints.icon_mask = icon_mask;
@@ -12743,7 +12745,7 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
 #endif
   /* Put the rdb where we can find it in a way that works on
      all versions.  */
-  dpyinfo->xrdb = xrdb;
+  dpyinfo->rdb = xrdb;
 
   dpyinfo->screen = ScreenOfDisplay (dpyinfo->display,
 				     DefaultScreen (dpyinfo->display));
@@ -12774,8 +12776,8 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
 	  AUTO_STRING (privateColormap, "privateColormap");
 	  AUTO_STRING (PrivateColormap, "PrivateColormap");
 	  Lisp_Object value
-	    = display_x_get_resource (dpyinfo, privateColormap,
-				      PrivateColormap, Qnil, Qnil);
+	    = gui_display_get_resource (dpyinfo, privateColormap,
+                                        PrivateColormap, Qnil, Qnil);
 	  if (STRINGP (value)
 	      && (!strcmp (SSDATA (value), "true")
 		  || !strcmp (SSDATA (value), "on")))
@@ -12992,8 +12994,8 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
   {
     AUTO_STRING (synchronous, "synchronous");
     AUTO_STRING (Synchronous, "Synchronous");
-    Lisp_Object value = display_x_get_resource (dpyinfo, synchronous,
-						Synchronous, Qnil, Qnil);
+    Lisp_Object value = gui_display_get_resource (dpyinfo, synchronous,
+                                                  Synchronous, Qnil, Qnil);
     if (STRINGP (value)
 	&& (!strcmp (SSDATA (value), "true")
 	    || !strcmp (SSDATA (value), "on")))
@@ -13003,8 +13005,8 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
   {
     AUTO_STRING (useXIM, "useXIM");
     AUTO_STRING (UseXIM, "UseXIM");
-    Lisp_Object value = display_x_get_resource (dpyinfo, useXIM, UseXIM,
-						Qnil, Qnil);
+    Lisp_Object value = gui_display_get_resource (dpyinfo, useXIM, UseXIM,
+                                                  Qnil, Qnil);
 #ifdef USE_XIM
     if (STRINGP (value)
 	&& (!strcmp (SSDATA (value), "false")
@@ -13196,13 +13198,13 @@ x_delete_terminal (struct terminal *terminal)
   /* Normally, the display is available...  */
   if (dpyinfo->display)
     {
-      gui_destroy_all_bitmaps (dpyinfo);
+      image_destroy_all_bitmaps (dpyinfo);
       XSetCloseDownMode (dpyinfo->display, DestroyAll);
 
       /* Whether or not XCloseDisplay destroys the associated resource
 	 database depends on the version of libX11.  To avoid both
 	 crash and memory leak, we dissociate the database from the
-	 display and then destroy dpyinfo->xrdb ourselves.
+	 display and then destroy dpyinfo->rdb ourselves.
 
 	 Unfortunately, the above strategy does not work in some
 	 situations due to a bug in newer versions of libX11: because
@@ -13222,7 +13224,7 @@ x_delete_terminal (struct terminal *terminal)
       /* We used to call XrmDestroyDatabase from x_delete_display, but
 	 some older versions of libX11 crash if we call it after
 	 closing all the displays.  */
-      XrmDestroyDatabase (dpyinfo->xrdb);
+      XrmDestroyDatabase (dpyinfo->rdb);
 #endif
 
 #ifdef USE_GTK
@@ -13287,10 +13289,16 @@ x_create_terminal (struct x_display_info *dpyinfo)
   terminal->frame_visible_invisible_hook = x_make_frame_visible_invisible;
   terminal->fullscreen_hook = XTfullscreen_hook;
   terminal->iconify_frame_hook = x_iconify_frame;
+  terminal->set_window_size_hook = x_set_window_size;
+  terminal->set_frame_offset_hook = x_set_offset;
   terminal->set_frame_alpha_hook = x_set_frame_alpha;
   terminal->set_new_font_hook = x_new_font;
+  terminal->set_bitmap_icon_hook = x_bitmap_icon;
   terminal->implicit_set_name_hook = x_implicitly_set_name;
   terminal->menu_show_hook = x_menu_show;
+#ifdef HAVE_EXT_MENU_BAR
+  terminal->activate_menubar_hook = x_activate_menubar;
+#endif
 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
   terminal->popup_dialog_hook = xw_popup_dialog;
 #endif
@@ -13304,6 +13312,7 @@ x_create_terminal (struct x_display_info *dpyinfo)
   terminal->condemn_scroll_bars_hook = XTcondemn_scroll_bars;
   terminal->redeem_scroll_bar_hook = XTredeem_scroll_bar;
   terminal->judge_scroll_bars_hook = XTjudge_scroll_bars;
+  terminal->get_string_resource_hook = x_get_string_resource;
   terminal->delete_frame_hook = x_destroy_window;
   terminal->delete_terminal_hook = x_delete_terminal;
   /* Other hooks are NULL by default.  */
diff --git a/src/xterm.h b/src/xterm.h
index a5313cf8f9..637ff2fd50 100644
--- a/src/xterm.h
+++ b/src/xterm.h
@@ -249,7 +249,7 @@ struct x_display_info
 #endif
 
   /* X Resource data base */
-  XrmDatabase xrdb;
+  XrmDatabase rdb;
 
   /* Minimum width over all characters in all fonts in font_table.  */
   int smallest_char_width;
@@ -764,9 +764,11 @@ enum
 
 /* Return the X output data for frame F.  */
 #define FRAME_X_OUTPUT(f) ((f)->output_data.x)
+#define FRAME_OUTPUT_DATA(f) FRAME_X_OUTPUT (f)
 
 /* Return the X window used for displaying data in frame F.  */
 #define FRAME_X_WINDOW(f) ((f)->output_data.x->window_desc)
+#define FRAME_NATIVE_WINDOW(f) FRAME_X_WINDOW (f)
 
 /* Return the drawable used for rendering to frame F.  */
 #define FRAME_X_RAW_DRAWABLE(f) ((f)->output_data.x->draw_desc)
@@ -1087,6 +1089,7 @@ extern void x_real_pos_and_offsets (struct frame *f,
 
 XrmDatabase x_load_resources (Display *, const char *, const char *,
 			      const char *);
+extern const char *x_get_string_resource (void *, const char *, const char *);
 
 /* Defined in xterm.c */
 
@@ -1103,8 +1106,9 @@ extern bool x_had_errors_p (Display *);
 extern void x_uncatch_errors (void);
 extern void x_uncatch_errors_after_check (void);
 extern void x_clear_errors (Display *);
-extern void x_make_frame_visible (struct frame *f)
-extern void x_make_frame_invisible (struct frame *f)
+extern void x_set_window_size (struct frame *f, bool, int, int, bool);
+extern void x_make_frame_visible (struct frame *f);
+extern void x_make_frame_invisible (struct frame *f);
 extern void x_iconify_frame (struct frame *f);
 extern void x_free_frame_resources (struct frame *);
 extern void x_wm_set_size_hint (struct frame *, long, bool);
@@ -1200,7 +1204,7 @@ extern void initial_set_up_x_back_buffer (struct frame *f);
 
 /* Defined in xfns.c.  */
 extern void x_real_positions (struct frame *, int *, int *);
-extern void x_change_tool_bar_height (struct frame *, int)
+extern void x_change_tool_bar_height (struct frame *, int);
 extern void x_implicitly_set_name (struct frame *, Lisp_Object, Lisp_Object);
 extern void x_set_scroll_bar_default_width (struct frame *);
 extern void x_set_scroll_bar_default_height (struct frame *);
-- 
2.21.0


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #6: 0005-Add-terminal-hook-defined_color_hook.patch --]
[-- Type: text/x-patch, Size: 14455 bytes --]

From ea8a533962187100cade0b719538a34f057791c7 Mon Sep 17 00:00:00 2001
From: Alexander Gramiak <agrambot@gmail.com>
Date: Sat, 13 Apr 2019 08:59:07 -0600
Subject: [PATCH 5/5] Add terminal hook defined_color_hook

* src/termhooks.h (defined_color_hook): New terminal hook.

* src/xterm.c:
* src/nsterm.m:
* src/term.c:
* src/w32term.c: Set defined_color_hook.

* src/nsterm.m (ns_defined_color_hook): New hook wrapper procedure.

* src/xfaces.c: Use defined_color_hook.
(defined_color): Remove.

* src/image.c (image_defined_color): New wrapper procedure for NS.
Remove redefinitions of x_defined_color, and rename x_defined_color to
image_defined_color.
---
 src/dispextern.h |  2 ++
 src/image.c      | 45 +++++++++++++++++++++++++++++--------------
 src/nsterm.m     | 12 ++++++++++++
 src/term.c       |  2 ++
 src/termhooks.h  |  8 ++++++++
 src/w32term.c    |  1 +
 src/xfaces.c     | 50 +++++++++++++-----------------------------------
 src/xterm.c      |  1 +
 8 files changed, 70 insertions(+), 51 deletions(-)

diff --git a/src/dispextern.h b/src/dispextern.h
index 4851fc6ba0..899a1f1136 100644
--- a/src/dispextern.h
+++ b/src/dispextern.h
@@ -3413,6 +3413,8 @@ void x_free_colors (struct frame *, unsigned long *, int);
 
 void update_face_from_frame_parameter (struct frame *, Lisp_Object,
                                        Lisp_Object);
+extern bool tty_defined_color (struct frame *f, const char *, XColor *, bool);
+
 Lisp_Object tty_color_name (struct frame *, int);
 void clear_face_cache (bool);
 unsigned long load_color (struct frame *, struct face *, Lisp_Object,
diff --git a/src/image.c b/src/image.c
index 1885f751f5..b554d5c20e 100644
--- a/src/image.c
+++ b/src/image.c
@@ -89,8 +89,6 @@ typedef struct w32_bitmap_record Bitmap_Record;
 #define PIX_MASK_RETAIN	0
 #define PIX_MASK_DRAW	1
 
-#define x_defined_color w32_defined_color
-
 #endif /* HAVE_NTGUI */
 
 #ifdef HAVE_NS
@@ -101,8 +99,6 @@ typedef struct ns_bitmap_record Bitmap_Record;
 
 #define PIX_MASK_RETAIN	0
 
-#define x_defined_color(f, name, color_def, alloc) \
-  ns_defined_color (f, name, color_def, alloc, 0)
 #endif /* HAVE_NS */
 
 #if (defined HAVE_X_WINDOWS \
@@ -1413,6 +1409,21 @@ gui_clear_image (struct frame *f, struct image *img)
   unblock_input ();
 }
 
+/* Wrapper for defined_color_hook to support the extra argument in
+   ns_defined_color. */
+
+static bool
+image_defined_color (struct frame *f, const char *color_name, XColor *color_def,
+                     bool alloc)
+{
+#ifdef HAVE_NS
+  if (FRAME_NS_P (f))
+    return ns_defined_color (f, color_name, color_def, alloc, false);
+  else
+#endif
+    return FRAME_TERMINAL (f)->defined_color_hook
+      (f, color_name, color_def, alloc);
+}
 
 /* Allocate color COLOR_NAME for image IMG on frame F.  If color
    cannot be allocated, use DFLT.  Add a newly allocated color to
@@ -1428,7 +1439,7 @@ gui_alloc_image_color (struct frame *f, struct image *img, Lisp_Object color_nam
 
   eassert (STRINGP (color_name));
 
-  if (x_defined_color (f, SSDATA (color_name), &color, 1)
+  if (image_defined_color (f, SSDATA (color_name), &color, true)
       && img->ncolors < min (min (PTRDIFF_MAX, SIZE_MAX) / sizeof *img->colors,
 			     INT_MAX))
     {
@@ -4469,8 +4480,8 @@ xpm_load_image (struct frame *f,
 	    {
 	      if (xstrcasecmp (SSDATA (XCDR (specified_color)), "None") == 0)
 		color_val = Qt;
-	      else if (x_defined_color (f, SSDATA (XCDR (specified_color)),
-					&cdef, 0))
+	      else if (image_defined_color (f, SSDATA (XCDR (specified_color)),
+                                            &cdef, false))
 		color_val = make_fixnum (cdef.pixel);
 	    }
 	}
@@ -4478,7 +4489,7 @@ xpm_load_image (struct frame *f,
 	{
 	  if (xstrcasecmp (max_color, "None") == 0)
 	    color_val = Qt;
-	  else if (x_defined_color (f, max_color, &cdef, 0))
+	  else if (image_defined_color (f, max_color, &cdef, false))
 	    color_val = make_fixnum (cdef.pixel);
 	}
       if (!NILP (color_val))
@@ -5684,7 +5695,10 @@ pbm_load (struct frame *f, struct image *img)
 #ifdef USE_CAIRO
       if (! fmt[PBM_FOREGROUND].count
           || ! STRINGP (fmt[PBM_FOREGROUND].value)
-          || ! x_defined_color (f, SSDATA (fmt[PBM_FOREGROUND].value), &xfg, 0))
+          || ! image_defined_color (f,
+                                    SSDATA (fmt[PBM_FOREGROUND].value),
+                                    &xfg,
+                                    false))
         {
           xfg.pixel = fg;
           x_query_colors (f, &xfg, 1);
@@ -5693,7 +5707,10 @@ pbm_load (struct frame *f, struct image *img)
 
       if (! fmt[PBM_BACKGROUND].count
           || ! STRINGP (fmt[PBM_BACKGROUND].value)
-          || ! x_defined_color (f, SSDATA (fmt[PBM_BACKGROUND].value), &xbg, 0))
+          || ! image_defined_color (f,
+                                    SSDATA (fmt[PBM_BACKGROUND].value),
+                                    &xbg,
+                                    false))
 	{
           xbg.pixel = bg;
           x_query_colors (f, &xbg, 1);
@@ -6352,7 +6369,7 @@ png_load_body (struct frame *f, struct image *img, struct png_load_context *c)
 	 current frame background, ignoring any default background
 	 color set by the image.  */
       if (STRINGP (specified_bg)
-	  ? x_defined_color (f, SSDATA (specified_bg), &color, false)
+	  ? image_defined_color (f, SSDATA (specified_bg), &color, false)
 	  : (gui_query_frame_background_color (f, &color), true))
 	/* The user specified `:background', use that.  */
 	{
@@ -8037,7 +8054,7 @@ gif_load (struct frame *f, struct image *img)
   if (STRINGP (specified_bg))
     {
       XColor color;
-      if (x_defined_color (f, SSDATA (specified_bg), &color, 0))
+      if (image_defined_color (f, SSDATA (specified_bg), &color, false))
         {
           uint32_t *dataptr = data32;
           int r = color.red/256;
@@ -8798,7 +8815,7 @@ imagemagick_load_image (struct frame *f, struct image *img,
 
     specified_bg = image_spec_value (img->spec, QCbackground, NULL);
     if (!STRINGP (specified_bg)
-	|| !x_defined_color (f, SSDATA (specified_bg), &bgcolor, 0))
+	|| !image_defined_color (f, SSDATA (specified_bg), &bgcolor, false))
       gui_query_frame_background_color (f, &bgcolor);
 
     bg_wand = NewPixelWand ();
@@ -9533,7 +9550,7 @@ svg_load_image (struct frame *f, struct image *img, char *contents,
     XColor background;
     Lisp_Object specified_bg = image_spec_value (img->spec, QCbackground, NULL);
     if (!STRINGP (specified_bg)
-	|| !x_defined_color (f, SSDATA (specified_bg), &background, 0))
+	|| !image_defined_color (f, SSDATA (specified_bg), &background, false))
       gui_query_frame_background_color (f, &background);
 
     /* SVG pixmaps specify transparency in the last byte, so right
diff --git a/src/nsterm.m b/src/nsterm.m
index d72e679e4d..317124d66d 100644
--- a/src/nsterm.m
+++ b/src/nsterm.m
@@ -2430,6 +2430,17 @@ so some key presses (TAB) are swallowed by the system.  */
   return 1;
 }
 
+static bool
+ns_defined_color_hook (struct frame *f,
+                       const char *name,
+                       XColor *color_def,
+                       bool alloc)
+/* --------------------------------------------------------------------------
+   External (hook): Used as the terminal hook interface for ns_defined_color
+   -------------------------------------------------------------------------- */
+{
+  return ns_defined_color (f, name, color_def, alloc, true);
+}
 
 static void
 ns_set_frame_alpha (struct frame *f)
@@ -5215,6 +5226,7 @@ static Lisp_Object ns_new_font (struct frame *f, Lisp_Object font_object,
   terminal->update_end_hook = ns_update_end;
   terminal->read_socket_hook = ns_read_socket;
   terminal->frame_up_to_date_hook = ns_frame_up_to_date;
+  terminal->defined_color_hook = ns_defined_color_hook;
   terminal->mouse_position_hook = ns_mouse_position;
   terminal->focus_frame_hook = ns_focus_frame;
   terminal->frame_rehighlight_hook = ns_frame_rehighlight;
diff --git a/src/term.c b/src/term.c
index a492276c88..a150da7084 100644
--- a/src/term.c
+++ b/src/term.c
@@ -3839,6 +3839,7 @@ clear_tty_hooks (struct terminal *terminal)
   terminal->update_begin_hook = 0;
   terminal->update_end_hook = 0;
   terminal->set_terminal_window_hook = 0;
+  terminal->defined_color_hook = 0;
   terminal->mouse_position_hook = 0;
   terminal->frame_rehighlight_hook = 0;
   terminal->frame_raise_lower_hook = 0;
@@ -3882,6 +3883,7 @@ set_tty_hooks (struct terminal *terminal)
   terminal->menu_show_hook = &tty_menu_show;
 #endif
   terminal->set_terminal_window_hook = &tty_set_terminal_window;
+  terminal->defined_color_hook = &tty_defined_color; /* xfaces.c */
   terminal->read_socket_hook = &tty_read_avail_input; /* keyboard.c */
   terminal->delete_frame_hook = &tty_free_frame_resources;
   terminal->delete_terminal_hook = &delete_tty;
diff --git a/src/termhooks.h b/src/termhooks.h
index 97994f856d..3c2de4287e 100644
--- a/src/termhooks.h
+++ b/src/termhooks.h
@@ -24,6 +24,7 @@ along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
 /* Miscellanea.   */
 
 #include "lisp.h"
+#include "dispextern.h"
 #include "systime.h" /* for Time */
 
 struct glyph;
@@ -488,6 +489,13 @@ struct terminal
   void (*update_end_hook) (struct frame *);
   void (*set_terminal_window_hook) (struct frame *, int);
 
+  /* Decide if color named COLOR_NAME is valid for the display
+   associated with the frame F; if so, return the rgb values in
+   COLOR_DEF.  If ALLOC, allocate a new colormap cell. */
+  bool (*defined_color_hook) (struct frame *f, const char *color_name,
+                              XColor *color_def,
+                              bool alloc);
+
   /* Multi-frame and mouse support hooks.  */
 
   /* Return the current position of the mouse.
diff --git a/src/w32term.c b/src/w32term.c
index 64357df139..33f4caa257 100644
--- a/src/w32term.c
+++ b/src/w32term.c
@@ -7145,6 +7145,7 @@ w32_create_terminal (struct w32_display_info *dpyinfo)
   terminal->update_end_hook = w32_update_end;
   terminal->read_socket_hook = w32_read_socket;
   terminal->frame_up_to_date_hook = w32_frame_up_to_date;
+  terminal->defined_color_hook = w32_defined_color;
   terminal->mouse_position_hook = w32_mouse_position;
   terminal->focus_frame_hook = w32_focus_frame;
   terminal->frame_rehighlight_hook = w32_frame_rehighlight;
diff --git a/src/xfaces.c b/src/xfaces.c
index 3f627d3843..c723ca40a2 100644
--- a/src/xfaces.c
+++ b/src/xfaces.c
@@ -898,9 +898,9 @@ tty_lookup_color (struct frame *f, Lisp_Object color, XColor *tty_color,
     return false;
 }
 
-/* A version of defined_color for non-X frames.  */
+/* An implementation of defined_color_hook for tty frames.  */
 
-static bool
+bool
 tty_defined_color (struct frame *f, const char *color_name,
 		   XColor *color_def, bool alloc)
 {
@@ -929,36 +929,6 @@ tty_defined_color (struct frame *f, const char *color_name,
   return status;
 }
 
-
-/* Decide if color named COLOR_NAME is valid for the display
-   associated with the frame F; if so, return the rgb values in
-   COLOR_DEF.  If ALLOC, allocate a new colormap cell.
-
-   This does the right thing for any type of frame.  */
-
-static bool
-defined_color (struct frame *f, const char *color_name, XColor *color_def,
-	       bool alloc)
-{
-  if (!FRAME_WINDOW_P (f))
-    return tty_defined_color (f, color_name, color_def, alloc);
-#ifdef HAVE_X_WINDOWS
-  else if (FRAME_X_P (f))
-    return x_defined_color (f, color_name, color_def, alloc);
-#endif
-#ifdef HAVE_NTGUI
-  else if (FRAME_W32_P (f))
-    return w32_defined_color (f, color_name, color_def, alloc);
-#endif
-#ifdef HAVE_NS
-  else if (FRAME_NS_P (f))
-    return ns_defined_color (f, color_name, color_def, alloc, true);
-#endif
-  else
-    emacs_abort ();
-}
-
-
 /* Given the index IDX of a tty color on frame F, return its name, a
    Lisp string.  */
 
@@ -1003,7 +973,7 @@ face_color_gray_p (struct frame *f, const char *color_name)
   XColor color;
   bool gray_p;
 
-  if (defined_color (f, color_name, &color, false))
+  if (FRAME_TERMINAL (f)->defined_color_hook (f, color_name, &color, false))
     gray_p = (/* Any color sufficiently close to black counts as gray.  */
 	      (color.red < 5000 && color.green < 5000 && color.blue < 5000)
 	      ||
@@ -1087,9 +1057,9 @@ load_color2 (struct frame *f, struct face *face, Lisp_Object name,
 	   || target_index == LFACE_STRIKE_THROUGH_INDEX
 	   || target_index == LFACE_BOX_INDEX);
 
-  /* if the color map is full, defined_color will return a best match
+  /* if the color map is full, defined_color_hook will return a best match
      to the values in an existing cell. */
-  if (!defined_color (f, SSDATA (name), color, true))
+  if (!FRAME_TERMINAL (f)->defined_color_hook (f, SSDATA (name), color, true))
     {
       add_to_log ("Unable to load color \"%s\"", name);
 
@@ -4243,11 +4213,17 @@ two lists of the form (RED GREEN BLUE) aforementioned. */)
 
   if (!(CONSP (color1) && parse_rgb_list (color1, &cdef1))
       && !(STRINGP (color1)
-	   && defined_color (f, SSDATA (color1), &cdef1, false)))
+	   && FRAME_TERMINAL (f)->defined_color_hook (f,
+                                                      SSDATA (color1),
+                                                      &cdef1,
+                                                      false)))
     signal_error ("Invalid color", color1);
   if (!(CONSP (color2) && parse_rgb_list (color2, &cdef2))
       && !(STRINGP (color2)
-	   && defined_color (f, SSDATA (color2), &cdef2, false)))
+	   && FRAME_TERMINAL (f)->defined_color_hook (f,
+                                                      SSDATA (color2),
+                                                      &cdef2,
+                                                      false)))
     signal_error ("Invalid color", color2);
 
   if (NILP (metric))
diff --git a/src/xterm.c b/src/xterm.c
index 15ff326ec1..e790e276d9 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -13282,6 +13282,7 @@ x_create_terminal (struct x_display_info *dpyinfo)
   terminal->read_socket_hook = XTread_socket;
   terminal->frame_up_to_date_hook = XTframe_up_to_date;
   terminal->buffer_flipping_unblocked_hook = XTbuffer_flipping_unblocked_hook;
+  terminal->defined_color_hook = x_defined_color;
   terminal->mouse_position_hook = XTmouse_position;
   terminal->focus_frame_hook = x_focus_frame;
   terminal->frame_rehighlight_hook = XTframe_rehighlight;
-- 
2.21.0


^ permalink raw reply related	[flat|nested] 68+ messages in thread

* Re: Renaming non-X x_* procedures in xdisp.c (and elsewhere)
  2019-04-12 20:10                                         ` Eli Zaretskii
@ 2019-04-13 16:26                                           ` Alex Gramiak
  2019-04-13 17:20                                             ` Eli Zaretskii
  0 siblings, 1 reply; 68+ messages in thread
From: Alex Gramiak @ 2019-04-13 16:26 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel


>> Equivalently it would check for FRAME_{X,NS,W32}_P.
>
> Not sure what that means, please elaborate.

I just meant implementing FRAME_WINDOW_P using the graphical window
system predicates instead of the terminal predicates; the same principle
you mentioned in the display-graphic-p thread.

>> I believe there should be a comment by the definition of FRAME_WINDOW_P
>> that states not to use the return value as a non-boolean.
>
> It's okay to add such a comment, although the _P part of the name,
> which stands for "Predicate", is supposed to say that already.

Right, I was just mildly concerned since the comment by it mentions that
"it's defined to be the predicate for the window system being used",
which might not be good for code to rely on in the very long-term.

I removed that part of the comment in the patch series I just posted, is
that an acceptable change?



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH] Renaming non-X x_* identifiers (was: Renaming non-X x_* procedures in xdisp.c (and elsewhere))
  2019-04-13 16:13                                   ` [PATCH] Renaming non-X x_* identifiers (was: Renaming non-X x_* procedures in xdisp.c (and elsewhere)) Alex Gramiak
@ 2019-04-13 17:17                                     ` Eli Zaretskii
  2019-04-13 18:43                                       ` [PATCH] Renaming non-X x_* identifiers Alex Gramiak
  2019-04-27  1:53                                     ` Basil L. Contovounesios
  1 sibling, 1 reply; 68+ messages in thread
From: Eli Zaretskii @ 2019-04-13 17:17 UTC (permalink / raw)
  To: Alex Gramiak; +Cc: alan, emacs-devel

> From: Alex Gramiak <agrambot@gmail.com>
> Cc: emacs-devel@gnu.org, Alan Third <alan@idiocy.org>
> Date: Sat, 13 Apr 2019 10:13:36 -0600
> 
> Okay, I believe I'm essentially done now, at least with the C-side. I
> can't test with either w32 and NS, so I hope you and Alan can test the
> attached patches with those backends.

I think we should soon push these to a scratch branch, so that people
could try that and provide feedback.  It's hard to work with such
large changes otherwise.

I have a few comments/questions:

> +#ifdef HAVE_WINDOW_SYSTEM
> +Lisp_Object
> +gui_get_focus_frame (struct frame *frame)

I don't think I understand why this function is implemented
differently from others, i.e. why it isn't a frame hook.  Doing so
would remove system-dependent #ifdef's from frame.c, at the very
least.  Can you explain why you did it this way?

> @@ -2771,7 +2786,7 @@ doesn't support multiple overlapping frames, this function does nothing.  */)
>    struct frame *f = decode_live_frame (frame);
>  
>    if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
> -    (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
> +    (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, false);
>  
>    return Qnil;
>  }
> @@ -2840,7 +2855,9 @@ If there is no window system support, this function does nothing.  */)
>       (Lisp_Object frame, Lisp_Object noactivate)
>  {
>  #ifdef HAVE_WINDOW_SYSTEM
> -  x_focus_frame (decode_window_system_frame (frame), !NILP (noactivate));
> +  struct frame *f = decode_window_system_frame (frame);
> +  if (f)
> +    FRAME_TERMINAL (f)->focus_frame_hook (f, !NILP (noactivate));
>  #endif

Some frame hooks are called after first making sure they are non-NULL,
others skip the test.  Is there a reason for this inconsistency?

> @@ -4035,7 +4052,7 @@ x_set_frame_parameters (struct frame *f, Lisp_Object alist)
>  
>  	  store_frame_param (f, prop, val);
>  
> -	  param_index = Fget (prop, Qx_frame_parameter);
> +	  param_index = Fget (prop, Qframe_parameter_pos);

The x-frame-parameter property is visible from Lisp, no?  You are here
replacing it with a different symbol, which is a backward-incompatible
change.

> -    adjust_frame_size (f, width, height, 1, 0, Qx_set_frame_parameters);
> +    adjust_frame_size (f, width, height, 1, 0, Qgui_set_frame_parameters);

Likewise here.

>  /* Store F's background color into *BGCOLOR.  */
>  static void
> -x_query_frame_background_color (struct frame *f, XColor *bgcolor)
> +gui_query_frame_background_color (struct frame *f, XColor *bgcolor)
>  {
> -#ifndef HAVE_NS
> -  bgcolor->pixel = FRAME_BACKGROUND_PIXEL (f);
> -  x_query_color (f, bgcolor);
> +#ifdef HAVE_NS
> +  ns_query_color (FRAME_BACKGROUND_COLOR (f), bgcolor, true);
>  #else
> -  ns_query_color (FRAME_BACKGROUND_COLOR (f), bgcolor, 1);
> +  bgcolor->pixel = FRAME_BACKGROUND_PIXEL (f);
> +# ifdef HAVE_NTGUI
> +  w32_query_colors (f, bgcolor, 1);
> +# else
> +  x_query_colors (f, bgcolor, 1);
> +# endif /* HAVE_NTGUI */
>  #endif

Why didn't you convert this to a terminal hook?

>  static void
> -x_set_image_size (struct frame *f, struct image *img)
> +gui_set_image_size (struct frame *f, struct image *img)

Any reason why some x_* functions in image.c were renamed image_*,
while others gui_* ?

> -	x_query_colors (f, row, img->width);
> -
> +        {
> +# ifdef HAVE_NTGUI
> +          w32_query_colors (f, row, img->width);
> +# else
> +          x_query_colors (f, row, img->width);
> +# endif
> +        }

Can this be a terminal hook?

> @@ -4187,7 +4194,7 @@ gui_set_frame_parameters (struct frame *f, Lisp_Object alist)
>        Lisp_Object old_value = get_frame_param (f, Qfullscreen);
>  
>        frame_size_history_add
> -	(f, Qx_set_fullscreen, 0, 0, list2 (old_value, fullscreen));
> +	(f, Qgui_set_fullscreen, 0, 0, list2 (old_value, fullscreen));

This is also visible from Lisp, right?  So renaming the symbol would
be an incompatible change.

> -  DEFSYM (Qx_set_window_size_1, "x-set-window-size-1");
> -  DEFSYM (Qx_set_window_size_2, "x-set-window-size-2");
> -  DEFSYM (Qx_set_window_size_3, "x-set-window-size-3");
> +  DEFSYM (Qgui_set_window_size_1, "gui-set-window-size-1");
> +  DEFSYM (Qgui_set_window_size_2, "gui-set-window-size-2");
> +  DEFSYM (Qgui_set_window_size_3, "gui-set-window-size-3");
>    DEFSYM (Qxg_change_toolbar_position, "xg-change-toolbar-position");
>    DEFSYM (Qx_net_wm_state, "x-net-wm-state");
>    DEFSYM (Qx_handle_net_wm_state, "x-handle-net-wm-state");
> @@ -5872,8 +5878,8 @@ syms_of_frame (void)
>    DEFSYM (Qchange_frame_size, "change-frame-size");
>    DEFSYM (Qxg_frame_set_char_size, "xg-frame-set-char-size");
>    DEFSYM (Qset_window_configuration, "set-window-configuration");
> -  DEFSYM (Qx_create_frame_1, "x-create-frame-1");
> -  DEFSYM (Qx_create_frame_2, "x-create-frame-2");
> +  DEFSYM (Qgui_create_frame_1, "gui-create-frame-1");
> +  DEFSYM (Qgui_create_frame_2, "gui-create-frame-2");
>    DEFSYM (Qterminal_frame, "terminal-frame");

Likewise with these symbols.

> diff --git a/src/menu.h b/src/menu.h
> index 0321c27454..4412948224 100644
> --- a/src/menu.h
> +++ b/src/menu.h
> @@ -47,14 +47,17 @@ extern widget_value *digest_single_submenu (int, int, bool);
>  #if defined (HAVE_X_WINDOWS) || defined (MSDOS)
>  extern Lisp_Object x_menu_show (struct frame *, int, int, int,
>  				Lisp_Object, const char **);
> +extern void x_activate_menubar (struct frame *);
>  #endif
>  #ifdef HAVE_NTGUI
>  extern Lisp_Object w32_menu_show (struct frame *, int, int, int,
>  				  Lisp_Object, const char **);
> +extern void w32_activate_menubar (struct frame *);
>  #endif
>  #ifdef HAVE_NS
>  extern Lisp_Object ns_menu_show (struct frame *, int, int, int,
>  				 Lisp_Object, const char **);
> +extern void ns_activate_menubar (struct frame *);

Since you introduced activate_menubar_hook, why do we need to declare
prototypes for its implementation on menu.h, which is a
system-independent header?

> +/* Wrapper for defined_color_hook to support the extra argument in
> +   ns_defined_color. */

If the extra parameter is the only problem, we could add it to all the
terminal types, and just ignore it where it is not needed.  Then we
won't need a wrapper.

Thanks again for working on this.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: Renaming non-X x_* procedures in xdisp.c (and elsewhere)
  2019-04-13 16:26                                           ` Alex Gramiak
@ 2019-04-13 17:20                                             ` Eli Zaretskii
  0 siblings, 0 replies; 68+ messages in thread
From: Eli Zaretskii @ 2019-04-13 17:20 UTC (permalink / raw)
  To: Alex Gramiak; +Cc: emacs-devel

> From: Alex Gramiak <agrambot@gmail.com>
> Cc: emacs-devel@gnu.org
> Date: Sat, 13 Apr 2019 10:26:16 -0600
> 
> > It's okay to add such a comment, although the _P part of the name,
> > which stands for "Predicate", is supposed to say that already.
> 
> Right, I was just mildly concerned since the comment by it mentions that
> "it's defined to be the predicate for the window system being used",
> which might not be good for code to rely on in the very long-term.
> 
> I removed that part of the comment in the patch series I just posted, is
> that an acceptable change?

If the comment no longer fits the code, then the comment should be
updated, sure.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH] Renaming non-X x_* identifiers
  2019-04-13 17:17                                     ` Eli Zaretskii
@ 2019-04-13 18:43                                       ` Alex Gramiak
  2019-04-13 19:00                                         ` Eli Zaretskii
  2019-04-14  3:47                                         ` Stefan Monnier
  0 siblings, 2 replies; 68+ messages in thread
From: Alex Gramiak @ 2019-04-13 18:43 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: alan, emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Alex Gramiak <agrambot@gmail.com>
>> Cc: emacs-devel@gnu.org, Alan Third <alan@idiocy.org>
>> Date: Sat, 13 Apr 2019 10:13:36 -0600
>> 
>> Okay, I believe I'm essentially done now, at least with the C-side. I
>> can't test with either w32 and NS, so I hope you and Alan can test the
>> attached patches with those backends.
>
> I think we should soon push these to a scratch branch, so that people
> could try that and provide feedback.  It's hard to work with such
> large changes otherwise.

Sure. What's the policy is for rebasing on scratch branches? I pushed
the branch as scratch/x_emacs.

> I have a few comments/questions:
>
>> +#ifdef HAVE_WINDOW_SYSTEM
>> +Lisp_Object
>> +gui_get_focus_frame (struct frame *frame)
>
> I don't think I understand why this function is implemented
> differently from others, i.e. why it isn't a frame hook.  Doing so
> would remove system-dependent #ifdef's from frame.c, at the very
> least.  Can you explain why you did it this way?

Honestly, I can't. I think it was one of the ones I did in the
beginning, so I forgot to make it a terminal hook. I changed it to a
hook.

>> @@ -2771,7 +2786,7 @@ doesn't support multiple overlapping frames, this function does nothing.  */)
>>    struct frame *f = decode_live_frame (frame);
>>  
>>    if (FRAME_TERMINAL (f)->frame_raise_lower_hook)
>> -    (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, 0);
>> +    (*FRAME_TERMINAL (f)->frame_raise_lower_hook) (f, false);
>>  
>>    return Qnil;
>>  }
>> @@ -2840,7 +2855,9 @@ If there is no window system support, this function does nothing.  */)
>>       (Lisp_Object frame, Lisp_Object noactivate)
>>  {
>>  #ifdef HAVE_WINDOW_SYSTEM
>> -  x_focus_frame (decode_window_system_frame (frame), !NILP (noactivate));
>> +  struct frame *f = decode_window_system_frame (frame);
>> +  if (f)
>> +    FRAME_TERMINAL (f)->focus_frame_hook (f, !NILP (noactivate));
>>  #endif
>
> Some frame hooks are called after first making sure they are non-NULL,
> others skip the test.  Is there a reason for this inconsistency?

The ones with no checks are in HAVE_WINDOW_SYSTEM and are assumed to
exist, while the ones with checks are outside of HAVE_WINDOW_SYSTEM.
Though it appears that I also checked a few that are in
HAVE_WINDOW_SYSTEM. Would you prefer all of them to be checked, or just
the ones outside of HAVE_WINDOW_SYSTEM?

>> @@ -4035,7 +4052,7 @@ x_set_frame_parameters (struct frame *f, Lisp_Object alist)
>>  
>>  	  store_frame_param (f, prop, val);
>>  
>> -	  param_index = Fget (prop, Qx_frame_parameter);
>> +	  param_index = Fget (prop, Qframe_parameter_pos);
>
> The x-frame-parameter property is visible from Lisp, no?  You are here
> replacing it with a different symbol, which is a backward-incompatible
> change.

While it is visible from Lisp, I don't see why anyone would change it
considering that AFAIU it's used as an internal value in frame.c.
frame.c sets it and uses the value of the property to call the
appropriate element in frame_parm_table, which Lisp-code should not rely
on.

Then again, apparently cedet/semantic/util-modes.el accesses this
property, but that could be changed.

>> -    adjust_frame_size (f, width, height, 1, 0, Qx_set_frame_parameters);
>> +    adjust_frame_size (f, width, height, 1, 0, Qgui_set_frame_parameters);
>
> Likewise here.

Hmm, frame-inhibit-implied-resize checks the presence of the symbol in
frame-inhibit-implied-resize, so I suppose it probably can't be changed.
Then again, x-set-frame-parameters isn't documented as a valid type in
the docstring of frame-inhibit-implied-resize, so I'm not sure this is a
problem.

>>  /* Store F's background color into *BGCOLOR.  */
>>  static void
>> -x_query_frame_background_color (struct frame *f, XColor *bgcolor)
>> +gui_query_frame_background_color (struct frame *f, XColor *bgcolor)
>>  {
>> -#ifndef HAVE_NS
>> -  bgcolor->pixel = FRAME_BACKGROUND_PIXEL (f);
>> -  x_query_color (f, bgcolor);
>> +#ifdef HAVE_NS
>> +  ns_query_color (FRAME_BACKGROUND_COLOR (f), bgcolor, true);
>>  #else
>> -  ns_query_color (FRAME_BACKGROUND_COLOR (f), bgcolor, 1);
>> +  bgcolor->pixel = FRAME_BACKGROUND_PIXEL (f);
>> +# ifdef HAVE_NTGUI
>> +  w32_query_colors (f, bgcolor, 1);
>> +# else
>> +  x_query_colors (f, bgcolor, 1);
>> +# endif /* HAVE_NTGUI */
>>  #endif
>
> Why didn't you convert this to a terminal hook?

In some cases I decided to leave some terminal hooks for a later patch
to implement, just to make it easier to get this one accepted. I can add
a hook for this if you'd like.

>>  static void
>> -x_set_image_size (struct frame *f, struct image *img)
>> +gui_set_image_size (struct frame *f, struct image *img)
>
> Any reason why some x_* functions in image.c were renamed image_*,
> while others gui_* ?

My intention is for the HAVE_WINDOW_SYSTEM-only procedures to be gui_*
and the others to be image_*. I decided on this later on, so I may have
a few gui_* procedures that should be image_*.

>> -	x_query_colors (f, row, img->width);
>> -
>> +        {
>> +# ifdef HAVE_NTGUI
>> +          w32_query_colors (f, row, img->width);
>> +# else
>> +          x_query_colors (f, row, img->width);
>> +# endif
>> +        }
>
> Can this be a terminal hook?

This one could as well.

>> @@ -4187,7 +4194,7 @@ gui_set_frame_parameters (struct frame *f, Lisp_Object alist)
>>        Lisp_Object old_value = get_frame_param (f, Qfullscreen);
>>  
>>        frame_size_history_add
>> -	(f, Qx_set_fullscreen, 0, 0, list2 (old_value, fullscreen));
>> +	(f, Qgui_set_fullscreen, 0, 0, list2 (old_value, fullscreen));
>
> This is also visible from Lisp, right?  So renaming the symbol would
> be an incompatible change.

I believe frame_size_history_add only uses the symbols as a
visual/debugging aid, so I don't believe this is, meaningfully, an
incompatible change.

>> -  DEFSYM (Qx_set_window_size_1, "x-set-window-size-1");
>> -  DEFSYM (Qx_set_window_size_2, "x-set-window-size-2");
>> -  DEFSYM (Qx_set_window_size_3, "x-set-window-size-3");
>> +  DEFSYM (Qgui_set_window_size_1, "gui-set-window-size-1");
>> +  DEFSYM (Qgui_set_window_size_2, "gui-set-window-size-2");
>> +  DEFSYM (Qgui_set_window_size_3, "gui-set-window-size-3");
>>    DEFSYM (Qxg_change_toolbar_position, "xg-change-toolbar-position");
>>    DEFSYM (Qx_net_wm_state, "x-net-wm-state");
>>    DEFSYM (Qx_handle_net_wm_state, "x-handle-net-wm-state");
>> @@ -5872,8 +5878,8 @@ syms_of_frame (void)
>>    DEFSYM (Qchange_frame_size, "change-frame-size");
>>    DEFSYM (Qxg_frame_set_char_size, "xg-frame-set-char-size");
>>    DEFSYM (Qset_window_configuration, "set-window-configuration");
>> -  DEFSYM (Qx_create_frame_1, "x-create-frame-1");
>> -  DEFSYM (Qx_create_frame_2, "x-create-frame-2");
>> +  DEFSYM (Qgui_create_frame_1, "gui-create-frame-1");
>> +  DEFSYM (Qgui_create_frame_2, "gui-create-frame-2");
>>    DEFSYM (Qterminal_frame, "terminal-frame");
>
> Likewise with these symbols.

These are likewise just used by frame_size_history_add.

>> diff --git a/src/menu.h b/src/menu.h
>> index 0321c27454..4412948224 100644
>> --- a/src/menu.h
>> +++ b/src/menu.h
>> @@ -47,14 +47,17 @@ extern widget_value *digest_single_submenu (int, int, bool);
>>  #if defined (HAVE_X_WINDOWS) || defined (MSDOS)
>>  extern Lisp_Object x_menu_show (struct frame *, int, int, int,
>>  				Lisp_Object, const char **);
>> +extern void x_activate_menubar (struct frame *);
>>  #endif
>>  #ifdef HAVE_NTGUI
>>  extern Lisp_Object w32_menu_show (struct frame *, int, int, int,
>>  				  Lisp_Object, const char **);
>> +extern void w32_activate_menubar (struct frame *);
>>  #endif
>>  #ifdef HAVE_NS
>>  extern Lisp_Object ns_menu_show (struct frame *, int, int, int,
>>  				 Lisp_Object, const char **);
>> +extern void ns_activate_menubar (struct frame *);
>
> Since you introduced activate_menubar_hook, why do we need to declare
> prototypes for its implementation on menu.h, which is a
> system-independent header?

The implementations are defined in the *menu.c files, but are added as
terminal hooks in the *term.c files.

>> +/* Wrapper for defined_color_hook to support the extra argument in
>> +   ns_defined_color. */
>
> If the extra parameter is the only problem, we could add it to all the
> terminal types, and just ignore it where it is not needed.  Then we
> won't need a wrapper.

I wanted to avoid that (see my earlier thread about ns_defined_color),
but if you prefer it I'll change it.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH] Renaming non-X x_* identifiers
  2019-04-13 18:43                                       ` [PATCH] Renaming non-X x_* identifiers Alex Gramiak
@ 2019-04-13 19:00                                         ` Eli Zaretskii
  2019-04-14  3:35                                           ` Alex Gramiak
  2019-04-14  3:47                                         ` Stefan Monnier
  1 sibling, 1 reply; 68+ messages in thread
From: Eli Zaretskii @ 2019-04-13 19:00 UTC (permalink / raw)
  To: Alex Gramiak; +Cc: alan, emacs-devel

> From: Alex Gramiak <agrambot@gmail.com>
> Cc: emacs-devel@gnu.org,  alan@idiocy.org
> Date: Sat, 13 Apr 2019 12:43:10 -0600
> 
> > I think we should soon push these to a scratch branch, so that people
> > could try that and provide feedback.  It's hard to work with such
> > large changes otherwise.
> 
> Sure. What's the policy is for rebasing on scratch branches?

Not sure I understand what you mean by "policy".  Rebasing or not in
general is up to you, but maybe you are asking about something more
specific.

> I pushed the branch as scratch/x_emacs.

That's okay, thanks.

> > Some frame hooks are called after first making sure they are non-NULL,
> > others skip the test.  Is there a reason for this inconsistency?
> 
> The ones with no checks are in HAVE_WINDOW_SYSTEM and are assumed to
> exist, while the ones with checks are outside of HAVE_WINDOW_SYSTEM.
> Though it appears that I also checked a few that are in
> HAVE_WINDOW_SYSTEM. Would you prefer all of them to be checked, or just
> the ones outside of HAVE_WINDOW_SYSTEM?

If every window-system is required to provide these hooks, then I
think it will be enough to test only those which also have
implementations on TTY frames.

> >>  	  store_frame_param (f, prop, val);
> >>  
> >> -	  param_index = Fget (prop, Qx_frame_parameter);
> >> +	  param_index = Fget (prop, Qframe_parameter_pos);
> >
> > The x-frame-parameter property is visible from Lisp, no?  You are here
> > replacing it with a different symbol, which is a backward-incompatible
> > change.
> 
> While it is visible from Lisp, I don't see why anyone would change it
> considering that AFAIU it's used as an internal value in frame.c.
> frame.c sets it and uses the value of the property to call the
> appropriate element in frame_parm_table, which Lisp-code should not rely
> on.
> 
> Then again, apparently cedet/semantic/util-modes.el accesses this
> property, but that could be changed.

Anything that gets put into frame-parameters can have some Lisp out
there using it.  So I think we have 2 alternatives:

  1) leave those symbols alone
  2) declare them obsolete, but meanwhile put both the new and the old
     symbols into frame-parameters

The above assumes that if a Lisp program does something with one of
these parameters, that will have no effect, i.e. that these parameters
are one-way communications from the Emacs internals to Lisp, as far as
Lisp programs are concerned.  If the communications are two-way, then
I don't see how we can change these names; do you have any ideas?

> >>  /* Store F's background color into *BGCOLOR.  */
> >>  static void
> >> -x_query_frame_background_color (struct frame *f, XColor *bgcolor)
> >> +gui_query_frame_background_color (struct frame *f, XColor *bgcolor)
> >>  {
> >> -#ifndef HAVE_NS
> >> -  bgcolor->pixel = FRAME_BACKGROUND_PIXEL (f);
> >> -  x_query_color (f, bgcolor);
> >> +#ifdef HAVE_NS
> >> +  ns_query_color (FRAME_BACKGROUND_COLOR (f), bgcolor, true);
> >>  #else
> >> -  ns_query_color (FRAME_BACKGROUND_COLOR (f), bgcolor, 1);
> >> +  bgcolor->pixel = FRAME_BACKGROUND_PIXEL (f);
> >> +# ifdef HAVE_NTGUI
> >> +  w32_query_colors (f, bgcolor, 1);
> >> +# else
> >> +  x_query_colors (f, bgcolor, 1);
> >> +# endif /* HAVE_NTGUI */
> >>  #endif
> >
> > Why didn't you convert this to a terminal hook?
> 
> In some cases I decided to leave some terminal hooks for a later patch
> to implement, just to make it easier to get this one accepted. I can add
> a hook for this if you'd like.

It's okay to do that in a followup, but please do that soon.  I don't
want to risk leaving an unfinished job in the sources.

> > Any reason why some x_* functions in image.c were renamed image_*,
> > while others gui_* ?
> 
> My intention is for the HAVE_WINDOW_SYSTEM-only procedures to be gui_*
> and the others to be image_*. I decided on this later on, so I may have
> a few gui_* procedures that should be image_*.

I think using image_* for all the functions in image.c would be
better.

> >> -	(f, Qx_set_fullscreen, 0, 0, list2 (old_value, fullscreen));
> >> +	(f, Qgui_set_fullscreen, 0, 0, list2 (old_value, fullscreen));
> >
> > This is also visible from Lisp, right?  So renaming the symbol would
> > be an incompatible change.
> 
> I believe frame_size_history_add only uses the symbols as a
> visual/debugging aid, so I don't believe this is, meaningfully, an
> incompatible change.

Are they in frame-parameters?  If so, they are visible.

> >> diff --git a/src/menu.h b/src/menu.h
> >> index 0321c27454..4412948224 100644
> >> --- a/src/menu.h
> >> +++ b/src/menu.h
> >> @@ -47,14 +47,17 @@ extern widget_value *digest_single_submenu (int, int, bool);
> >>  #if defined (HAVE_X_WINDOWS) || defined (MSDOS)
> >>  extern Lisp_Object x_menu_show (struct frame *, int, int, int,
> >>  				Lisp_Object, const char **);
> >> +extern void x_activate_menubar (struct frame *);
> >>  #endif
> >>  #ifdef HAVE_NTGUI
> >>  extern Lisp_Object w32_menu_show (struct frame *, int, int, int,
> >>  				  Lisp_Object, const char **);
> >> +extern void w32_activate_menubar (struct frame *);
> >>  #endif
> >>  #ifdef HAVE_NS
> >>  extern Lisp_Object ns_menu_show (struct frame *, int, int, int,
> >>  				 Lisp_Object, const char **);
> >> +extern void ns_activate_menubar (struct frame *);
> >
> > Since you introduced activate_menubar_hook, why do we need to declare
> > prototypes for its implementation on menu.h, which is a
> > system-independent header?
> 
> The implementations are defined in the *menu.c files, but are added as
> terminal hooks in the *term.c files.

I'm not sure I understand the answer.  I didn't ask about the
implementations, I asked about the prototypes.  Since these are hooks,
their names are not visible outside the corresponding *term.c file,
right?  Then why do we need the prototypes of w32_activate_menubar,
ns_activate_menubar, etc. in menu.h?

> >> +/* Wrapper for defined_color_hook to support the extra argument in
> >> +   ns_defined_color. */
> >
> > If the extra parameter is the only problem, we could add it to all the
> > terminal types, and just ignore it where it is not needed.  Then we
> > won't need a wrapper.
> 
> I wanted to avoid that (see my earlier thread about ns_defined_color),
> but if you prefer it I'll change it.

Yes, I think avoiding it makes the code less clean than having an
unused argument.

Thanks.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH] Renaming non-X x_* identifiers
  2019-04-13 19:00                                         ` Eli Zaretskii
@ 2019-04-14  3:35                                           ` Alex Gramiak
  2019-04-14 14:02                                             ` Eli Zaretskii
  0 siblings, 1 reply; 68+ messages in thread
From: Alex Gramiak @ 2019-04-14  3:35 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: alan, emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

> Not sure I understand what you mean by "policy".  Rebasing or not in
> general is up to you, but maybe you are asking about something more
> specific.

I mean specifically about rebasing during the review process. Though it
turns out that the Savannah git server doesn't allow this, so I just
deleted and repushed the entire branch instead.

> If every window-system is required to provide these hooks, then I
> think it will be enough to test only those which also have
> implementations on TTY frames.

Okay. How about wrapping the required hooks in termhooks.h in #ifdef
HAVE_WINDOW_SYSTEM so that terminal-only builds that erroneously have
these hooks in their scope issue a compiler error?

>> >>  	  store_frame_param (f, prop, val);
>> >>  
>> >> -	  param_index = Fget (prop, Qx_frame_parameter);
>> >> +	  param_index = Fget (prop, Qframe_parameter_pos);
>> >
>> > The x-frame-parameter property is visible from Lisp, no?  You are here
>> > replacing it with a different symbol, which is a backward-incompatible
>> > change.
>> 
>> While it is visible from Lisp, I don't see why anyone would change it
>> considering that AFAIU it's used as an internal value in frame.c.
>> frame.c sets it and uses the value of the property to call the
>> appropriate element in frame_parm_table, which Lisp-code should not rely
>> on.
>> 
>> Then again, apparently cedet/semantic/util-modes.el accesses this
>> property, but that could be changed.
>
> Anything that gets put into frame-parameters can have some Lisp out
> there using it.  So I think we have 2 alternatives:
>
>   1) leave those symbols alone
>   2) declare them obsolete, but meanwhile put both the new and the old
>      symbols into frame-parameters
>
> The above assumes that if a Lisp program does something with one of
> these parameters, that will have no effect, i.e. that these parameters
> are one-way communications from the Emacs internals to Lisp, as far as
> Lisp programs are concerned.  If the communications are two-way, then
> I don't see how we can change these names; do you have any ideas?

AFAIU it's technically possible that someone could use `put' to set a
new value, but that's tantamount to changing the internal definition of
the frame parameter setter to another frame parameter setter, so I don't
think such a use case should really be considered.

I don't have any other ideas, but 2) doesn't sound terrible as long as
it would be removed some day. Though I don't feel strongly about the
symbols here.

> It's okay to do that in a followup, but please do that soon.  I don't
> want to risk leaving an unfinished job in the sources.

I just pushed commits implementing this hook and the other one
discussed.

> I think using image_* for all the functions in image.c would be
> better.

Okay, done.

>> >> -	(f, Qx_set_fullscreen, 0, 0, list2 (old_value, fullscreen));
>> >> +	(f, Qgui_set_fullscreen, 0, 0, list2 (old_value, fullscreen));
>> >
>> > This is also visible from Lisp, right?  So renaming the symbol would
>> > be an incompatible change.
>> 
>> I believe frame_size_history_add only uses the symbols as a
>> visual/debugging aid, so I don't believe this is, meaningfully, an
>> incompatible change.
>
> Are they in frame-parameters?  If so, they are visible.

No, but they are used in the variable frame-size-history which is used
by frame--size-history. I'm not sure if this is significant enough to
warrant leaving it alone.

>> >> diff --git a/src/menu.h b/src/menu.h
>> >> index 0321c27454..4412948224 100644
>> >> --- a/src/menu.h
>> >> +++ b/src/menu.h
>> >> @@ -47,14 +47,17 @@ extern widget_value *digest_single_submenu (int, int, bool);
>> >>  #if defined (HAVE_X_WINDOWS) || defined (MSDOS)
>> >>  extern Lisp_Object x_menu_show (struct frame *, int, int, int,
>> >>  				Lisp_Object, const char **);
>> >> +extern void x_activate_menubar (struct frame *);
>> >>  #endif
>> >>  #ifdef HAVE_NTGUI
>> >>  extern Lisp_Object w32_menu_show (struct frame *, int, int, int,
>> >>  				  Lisp_Object, const char **);
>> >> +extern void w32_activate_menubar (struct frame *);
>> >>  #endif
>> >>  #ifdef HAVE_NS
>> >>  extern Lisp_Object ns_menu_show (struct frame *, int, int, int,
>> >>  				 Lisp_Object, const char **);
>> >> +extern void ns_activate_menubar (struct frame *);
>> >
>> > Since you introduced activate_menubar_hook, why do we need to declare
>> > prototypes for its implementation on menu.h, which is a
>> > system-independent header?
>> 
>> The implementations are defined in the *menu.c files, but are added as
>> terminal hooks in the *term.c files.
>
> I'm not sure I understand the answer.  I didn't ask about the
> implementations, I asked about the prototypes.  Since these are hooks,
> their names are not visible outside the corresponding *term.c file,
> right?  Then why do we need the prototypes of w32_activate_menubar,
> ns_activate_menubar, etc. in menu.h?

The declarations are to make the names visible to *term.c. *menu.c
contains the actual definitions, so *term.c needs declarations to set
the hook. It's why *_menu_show are there as well, even though they are
terminal hooks.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH] Renaming non-X x_* identifiers
  2019-04-13 18:43                                       ` [PATCH] Renaming non-X x_* identifiers Alex Gramiak
  2019-04-13 19:00                                         ` Eli Zaretskii
@ 2019-04-14  3:47                                         ` Stefan Monnier
  1 sibling, 0 replies; 68+ messages in thread
From: Stefan Monnier @ 2019-04-14  3:47 UTC (permalink / raw)
  To: emacs-devel

> Sure. What's the policy is for rebasing on scratch branches? I pushed
> the branch as scratch/x_emacs.

Branches in `scratch/*` can be removed/rebased/changed to your heart's
content.  But be aware that the emacs.git repository does not accept
"forced pushes", so when you rebase you need to delete the branch and
then push it.


        Stefan




^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH] Renaming non-X x_* identifiers
  2019-04-14  3:35                                           ` Alex Gramiak
@ 2019-04-14 14:02                                             ` Eli Zaretskii
  2019-04-14 15:57                                               ` Alex Gramiak
  0 siblings, 1 reply; 68+ messages in thread
From: Eli Zaretskii @ 2019-04-14 14:02 UTC (permalink / raw)
  To: Alex Gramiak; +Cc: alan, emacs-devel

> From: Alex Gramiak <agrambot@gmail.com>
> Cc: emacs-devel@gnu.org,  alan@idiocy.org
> Date: Sat, 13 Apr 2019 21:35:01 -0600
> 
> > If every window-system is required to provide these hooks, then I
> > think it will be enough to test only those which also have
> > implementations on TTY frames.
> 
> Okay. How about wrapping the required hooks in termhooks.h in #ifdef
> HAVE_WINDOW_SYSTEM so that terminal-only builds that erroneously have
> these hooks in their scope issue a compiler error?

I generally dislike system-dependent definitions and declarations.  I
prefer them to be available on all systems, with some default values
instead.  And terminal-only builds are extremely rare (I think only
Hydra does them regularly, because all the bugs in that area are
flagged by Hydra), so this defense is quite weak, IME.

So I think a test for the relevant hooks to be non-NULL would be a
better alternative.  We can document in the struct definition which
members can be NULL and in what situations.

> >   1) leave those symbols alone
> >   2) declare them obsolete, but meanwhile put both the new and the old
> >      symbols into frame-parameters
> >
> > The above assumes that if a Lisp program does something with one of
> > these parameters, that will have no effect, i.e. that these parameters
> > are one-way communications from the Emacs internals to Lisp, as far as
> > Lisp programs are concerned.  If the communications are two-way, then
> > I don't see how we can change these names; do you have any ideas?
> 
> AFAIU it's technically possible that someone could use `put' to set a
> new value, but that's tantamount to changing the internal definition of
> the frame parameter setter to another frame parameter setter, so I don't
> think such a use case should really be considered.
> 
> I don't have any other ideas, but 2) doesn't sound terrible as long as
> it would be removed some day. Though I don't feel strongly about the
> symbols here.

On second thought, I think we should simply leave these alone.  They
are just symbol names, and mostly used internally, so the problem is
purely aesthetic and usually hidden from the view.  Doing something
like 2) above would be an overkill for such minor issue.

> The declarations are to make the names visible to *term.c. *menu.c
> contains the actual definitions, so *term.c needs declarations to set
> the hook. It's why *_menu_show are there as well, even though they are
> terminal hooks.

Got it, thanks.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH] Renaming non-X x_* identifiers
  2019-04-14 14:02                                             ` Eli Zaretskii
@ 2019-04-14 15:57                                               ` Alex Gramiak
  2019-04-14 16:10                                                 ` Eli Zaretskii
  0 siblings, 1 reply; 68+ messages in thread
From: Alex Gramiak @ 2019-04-14 15:57 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: alan, emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Alex Gramiak <agrambot@gmail.com>
>> Cc: emacs-devel@gnu.org,  alan@idiocy.org
>> Date: Sat, 13 Apr 2019 21:35:01 -0600
>> 
>> > If every window-system is required to provide these hooks, then I
>> > think it will be enough to test only those which also have
>> > implementations on TTY frames.
>> 
>> Okay. How about wrapping the required hooks in termhooks.h in #ifdef
>> HAVE_WINDOW_SYSTEM so that terminal-only builds that erroneously have
>> these hooks in their scope issue a compiler error?
>
> I generally dislike system-dependent definitions and declarations.  I
> prefer them to be available on all systems, with some default values
> instead.  And terminal-only builds are extremely rare (I think only
> Hydra does them regularly, because all the bugs in that area are
> flagged by Hydra), so this defense is quite weak, IME.

The hooks I'm referring to are ones that AFAIU don't make any sense on
non-HAVE_WINDOW_SYSTEM, and their calls are (should be) already #ifdef'd
out (with non-window-system frames never reaching the call). Including
the #ifdefs in the declaration side would allow for Hydra to detect
cases where an undefined hook is called, which would mean adding the
appropriate #ifdef or an appropriate check around that call.

> So I think a test for the relevant hooks to be non-NULL would be a
> better alternative.  We can document in the struct definition which
> members can be NULL and in what situations.

I agree about the documentation, though I was thinking about documenting
which hooks _must_ be defined for certain types of platforms. I suppose
we could do both.

I'm a bit confused by your comment on testing. Didn't you say that it
was okay that the code that was under HAVE_WINDOW_SYSTEM didn't test for
existence of required HAVE_WINDOW_SYSTEM hooks? Those hooks are the ones
I was thinking about wrapping into #ifdefs.

>> >   1) leave those symbols alone
>> >   2) declare them obsolete, but meanwhile put both the new and the old
>> >      symbols into frame-parameters
>> >
>> > The above assumes that if a Lisp program does something with one of
>> > these parameters, that will have no effect, i.e. that these parameters
>> > are one-way communications from the Emacs internals to Lisp, as far as
>> > Lisp programs are concerned.  If the communications are two-way, then
>> > I don't see how we can change these names; do you have any ideas?
>> 
>> AFAIU it's technically possible that someone could use `put' to set a
>> new value, but that's tantamount to changing the internal definition of
>> the frame parameter setter to another frame parameter setter, so I don't
>> think such a use case should really be considered.
>> 
>> I don't have any other ideas, but 2) doesn't sound terrible as long as
>> it would be removed some day. Though I don't feel strongly about the
>> symbols here.
>
> On second thought, I think we should simply leave these alone.  They
> are just symbol names, and mostly used internally, so the problem is
> purely aesthetic and usually hidden from the view.  Doing something
> like 2) above would be an overkill for such minor issue.

Okay, I pushed a couple commits to revert these changes.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH] Renaming non-X x_* identifiers
  2019-04-14 15:57                                               ` Alex Gramiak
@ 2019-04-14 16:10                                                 ` Eli Zaretskii
  2019-04-14 17:34                                                   ` Alex Gramiak
  0 siblings, 1 reply; 68+ messages in thread
From: Eli Zaretskii @ 2019-04-14 16:10 UTC (permalink / raw)
  To: Alex Gramiak; +Cc: alan, emacs-devel

> From: Alex Gramiak <agrambot@gmail.com>
> Cc: emacs-devel@gnu.org,  alan@idiocy.org
> Date: Sun, 14 Apr 2019 09:57:47 -0600
> 
> > I generally dislike system-dependent definitions and declarations.  I
> > prefer them to be available on all systems, with some default values
> > instead.  And terminal-only builds are extremely rare (I think only
> > Hydra does them regularly, because all the bugs in that area are
> > flagged by Hydra), so this defense is quite weak, IME.
> 
> The hooks I'm referring to are ones that AFAIU don't make any sense on
> non-HAVE_WINDOW_SYSTEM, and their calls are (should be) already #ifdef'd
> out (with non-window-system frames never reaching the call). Including
> the #ifdefs in the declaration side would allow for Hydra to detect
> cases where an undefined hook is called, which would mean adding the
> appropriate #ifdef or an appropriate check around that call.

Can you show the list of those hooks you want to #ifdef?  Maybe I'm
misinterpreting your suggestion.

> I'm a bit confused by your comment on testing. Didn't you say that it
> was okay that the code that was under HAVE_WINDOW_SYSTEM didn't test for
> existence of required HAVE_WINDOW_SYSTEM hooks? Those hooks are the ones
> I was thinking about wrapping into #ifdefs.

Ah, I see the misunderstanding.  Yes, it would be okay to #ifdef the
calls to those which are only available on window-systems, but then
why would we test the other kind of hooks for being non-NULL?

I thought those which don't need to be tested are available on both
GUI and TTY frames.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH] Renaming non-X x_* identifiers
  2019-04-14 16:10                                                 ` Eli Zaretskii
@ 2019-04-14 17:34                                                   ` Alex Gramiak
  2019-04-15 14:51                                                     ` Eli Zaretskii
  0 siblings, 1 reply; 68+ messages in thread
From: Alex Gramiak @ 2019-04-14 17:34 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: alan, emacs-devel

[-- Attachment #1: Type: text/plain, Size: 2369 bytes --]

Eli Zaretskii <eliz@gnu.org> writes:

>> The hooks I'm referring to are ones that AFAIU don't make any sense on
>> non-HAVE_WINDOW_SYSTEM, and their calls are (should be) already #ifdef'd
>> out (with non-window-system frames never reaching the call). Including
>> the #ifdefs in the declaration side would allow for Hydra to detect
>> cases where an undefined hook is called, which would mean adding the
>> appropriate #ifdef or an appropriate check around that call.
>
> Can you show the list of those hooks you want to #ifdef?  Maybe I'm
> misinterpreting your suggestion.

I've included a diff at the end of my email.

>> I'm a bit confused by your comment on testing. Didn't you say that it
>> was okay that the code that was under HAVE_WINDOW_SYSTEM didn't test for
>> existence of required HAVE_WINDOW_SYSTEM hooks? Those hooks are the ones
>> I was thinking about wrapping into #ifdefs.
>
> Ah, I see the misunderstanding.  Yes, it would be okay to #ifdef the
> calls to those which are only available on window-systems, but then
> why would we test the other kind of hooks for being non-NULL?

The calls should already be #ifdef'd; it's the declarations that would
be #ifdef'd.

> I thought those which don't need to be tested are available on both
> GUI and TTY frames.

I believe there are (currently) three categories:

(a) Hooks implemented by all backends, which don't need to be tested.

(b) Hooks implemented by only GUI frames, but occurring in branches that
non-GUI frames are used. These have to be tested.

(c) Hooks implemented by only GUI frames, and occurring in branches that
only GUI frames are used, and are in a preprocessor conditional. These
don't have to be (and some currently aren't) tested.

The #ifdefs I'm proposing (around declarations of (c) hooks) would
allow Hydra and terminal-only users to catch code that assumes (c) when
it should be (b). The alternatives would be to test all code in (c)
anyway, or just hope that no one made an error by omitting any checks.

P.S. I noticed that the only caller of buffer_flipping_unblocked_hook is
unblock_buffer_flips in xdisp.c. Should this code be #ifdef'd out to
only platforms that do this buffer flipping (HAVE_X_WINDOWS, I believe)?
I'm not sure how much of a performance impact this code has on
redisplay, but it introduces a record_unwind_protect in
redisplay_preserve_echo_area.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: ifdiff --]
[-- Type: text/x-patch, Size: 4156 bytes --]

diff --git a/src/frame.h b/src/frame.h
index a780ea6085..479d72f20a 100644
--- a/src/frame.h
+++ b/src/frame.h
@@ -1597,7 +1597,7 @@ extern char *x_get_resource_string (const char *, const char *);
 extern void x_sync (struct frame *);
 #endif /* HAVE_X_WINDOWS */
 
-#ifndef HAVE_NS
+#if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI)
 
 /* Set F's bitmap icon, if specified among F's parameters.  */
 
@@ -1610,7 +1610,7 @@ gui_set_bitmap_icon (struct frame *f)
     FRAME_TERMINAL (f)->set_bitmap_icon_hook (f, XCDR (obj));
 }
 
-#endif /* !HAVE_NS */
+#endif /* HAVE_X_WINDOWS || HAVE_NTGUI */
 #endif /* HAVE_WINDOW_SYSTEM */
 
 INLINE void
diff --git a/src/termhooks.h b/src/termhooks.h
index ab1a701bef..a8a2a453e2 100644
--- a/src/termhooks.h
+++ b/src/termhooks.h
@@ -501,9 +501,10 @@ struct terminal
                               bool makeIndex);
 
   /* Multi-frame and mouse support hooks.  */
-
+#ifdef HAVE_WINDOW_SYSTEM
   void (*query_frame_background_color) (struct frame *f, XColor *bgcolor);
 
+#endif
 #if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI)
   /* On frame F, translate pixel colors to RGB values for the NCOLORS
      colors in COLORS.  Use cached information, if available.  */
@@ -532,12 +533,13 @@ struct terminal
                                Lisp_Object *y,
                                Time *);
 
+#ifdef HAVE_WINDOW_SYSTEM
   /* This hook is called to get the focus frame.  */
   Lisp_Object (*get_focus_frame) (struct frame *f);
 
   /* This hook is called to shift frame focus.  */
   void (*focus_frame_hook) (struct frame *f, bool noactivate);
-
+#endif
   /* When a frame's focus redirection is changed, this hook tells the
      window system code to re-decide where to put the highlight.  Under
      X, this means that Emacs lies about where the focus is.  */
@@ -555,15 +557,17 @@ struct terminal
      windows.  */
   void (*frame_raise_lower_hook) (struct frame *f, bool raise_flag);
 
+#ifdef HAVE_WINDOW_SYSTEM
   /* This hook is called to make the frame F visible if VISIBLE is
      true, or invisible otherwise. */
   void (*frame_visible_invisible_hook) (struct frame *f, bool visible);
-
+#endif
   /* If the value of the frame parameter changed, this hook is called.
      For example, if going from fullscreen to not fullscreen this hook
      may do something OS dependent, like extended window manager hints on X11.  */
   void (*fullscreen_hook) (struct frame *f);
 
+#ifdef HAVE_WINDOW_SYSTEM
   /* This hook is called to iconify the frame.  */
   void (*iconify_frame_hook) (struct frame *f);
 
@@ -589,14 +593,14 @@ struct terminal
   /* This hook is called to set a new font for the frame.  */
   Lisp_Object (*set_new_font_hook) (struct frame *f, Lisp_Object font_object,
                                     int fontset);
-
+#if defined (HAVE_X_WINDOWS) || defined (HAVE_NTGUI)
   /* This hook is called to set the GUI window icon of F using FILE.  */
   bool (*set_bitmap_icon_hook) (struct frame *f, Lisp_Object file);
 
-
+#endif
   void (*implicit_set_name_hook) (struct frame *f, Lisp_Object arg,
                                   Lisp_Object oldval);
-
+#endif
   /* This hook is called to display menus.  */
   Lisp_Object (*menu_show_hook) (struct frame *f, int x, int y, int menuflags,
 				 Lisp_Object title, const char **error_name);
@@ -718,16 +722,19 @@ struct terminal
   /* Called when a frame's display becomes entirely up to date.  */
   void (*frame_up_to_date_hook) (struct frame *);
 
+#ifdef HAVE_X_WINDOWS
   /* Called when buffer flipping becomes unblocked after having
      previously been blocked.  Redisplay always blocks buffer flips
      while it runs.  */
   void (*buffer_flipping_unblocked_hook) (struct frame *);
-
+#endif
+#ifdef HAVE_WINDOW_SYSTEM
   /* Retrieve the string resource specified by NAME with CLASS from
      database RDB. */
   const char * (*get_string_resource_hook) (void *rdb,
                                             const char *name,
                                             const char *class);
+#endif
 \f
   /* Called to delete the device-specific portions of a frame that is
      on this terminal device. */

^ permalink raw reply related	[flat|nested] 68+ messages in thread

* Re: [PATCH] Renaming non-X x_* identifiers
  2019-04-14 17:34                                                   ` Alex Gramiak
@ 2019-04-15 14:51                                                     ` Eli Zaretskii
  2019-04-15 17:46                                                       ` Alex Gramiak
  2019-04-15 22:01                                                       ` Stefan Monnier
  0 siblings, 2 replies; 68+ messages in thread
From: Eli Zaretskii @ 2019-04-15 14:51 UTC (permalink / raw)
  To: Alex Gramiak; +Cc: alan, emacs-devel

> From: Alex Gramiak <agrambot@gmail.com>
> Cc: emacs-devel@gnu.org,  alan@idiocy.org
> Date: Sun, 14 Apr 2019 11:34:22 -0600
> 
> The calls should already be #ifdef'd; it's the declarations that would
> be #ifdef'd.
> 
> > I thought those which don't need to be tested are available on both
> > GUI and TTY frames.
> 
> I believe there are (currently) three categories:
> 
> (a) Hooks implemented by all backends, which don't need to be tested.
> 
> (b) Hooks implemented by only GUI frames, but occurring in branches that
> non-GUI frames are used. These have to be tested.
> 
> (c) Hooks implemented by only GUI frames, and occurring in branches that
> only GUI frames are used, and are in a preprocessor conditional. These
> don't have to be (and some currently aren't) tested.

Thanks, now the issue is clear.

I think I'd prefer to treat (c) the same as (b), though, i.e. add the
tests where we don't have them, and leave the declarations visible in
all builds.  My reasoning is that the current situation is more or
less ad-hoc, and therefore some of the (c) could at some point become
(b).  If and when that happens, treating them the same will allow
easier rearrangement of the code.  By contrast, having such a modified
code fail to compile would require the person making the change to
perform some non-trivial analysis of why that hook was not declared,
then move its declaration out of the #ifdef.  It would also increase
the number of #ifdef's, which I think is both uglier and farther from
the goal of supporting several window-systems in the same session.

> P.S. I noticed that the only caller of buffer_flipping_unblocked_hook is
> unblock_buffer_flips in xdisp.c. Should this code be #ifdef'd out to
> only platforms that do this buffer flipping (HAVE_X_WINDOWS, I believe)?
> I'm not sure how much of a performance impact this code has on
> redisplay, but it introduces a record_unwind_protect in
> redisplay_preserve_echo_area.

Again, I wouldn't like to increase the number of #ifdef's if that can
be avoided.  In this case, I don't think it's justified by performance
issues.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH] Renaming non-X x_* identifiers
  2019-04-15 14:51                                                     ` Eli Zaretskii
@ 2019-04-15 17:46                                                       ` Alex Gramiak
  2019-04-15 18:43                                                         ` Eli Zaretskii
  2019-04-15 22:01                                                       ` Stefan Monnier
  1 sibling, 1 reply; 68+ messages in thread
From: Alex Gramiak @ 2019-04-15 17:46 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: alan, emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Alex Gramiak <agrambot@gmail.com>
>> Cc: emacs-devel@gnu.org,  alan@idiocy.org
>> Date: Sun, 14 Apr 2019 11:34:22 -0600
>> 
>> The calls should already be #ifdef'd; it's the declarations that would
>> be #ifdef'd.
>> 
>> > I thought those which don't need to be tested are available on both
>> > GUI and TTY frames.
>> 
>> I believe there are (currently) three categories:
>> 
>> (a) Hooks implemented by all backends, which don't need to be tested.
>> 
>> (b) Hooks implemented by only GUI frames, but occurring in branches that
>> non-GUI frames are used. These have to be tested.
>> 
>> (c) Hooks implemented by only GUI frames, and occurring in branches that
>> only GUI frames are used, and are in a preprocessor conditional. These
>> don't have to be (and some currently aren't) tested.
>
> Thanks, now the issue is clear.
>
> I think I'd prefer to treat (c) the same as (b), though, i.e. add the
> tests where we don't have them, and leave the declarations visible in
> all builds.  My reasoning is that the current situation is more or
> less ad-hoc, and therefore some of the (c) could at some point become
> (b).  If and when that happens, treating them the same will allow
> easier rearrangement of the code.  By contrast, having such a modified
> code fail to compile would require the person making the change to
> perform some non-trivial analysis of why that hook was not declared,
> then move its declaration out of the #ifdef.

That makes sense. I pushed the relevant changes. Is it okay that I left
the get_focus_frame hook in do_switch_frame (frame.c) unchecked? It's
enclosed by a FRAME_WINDOW_P, so a comment in termhooks.c mandating that
window systems implement that hook should be sufficient, no? On the
other hand, it's the only one remaining in the generic code that's left
unchecked.

> It would also increase the number of #ifdef's, which I think is both
> uglier

Indeed.

> and farther from the goal of supporting several window-systems in the
> same session.

Not sure about this, as long the hooks' calling sites and declarations
are compiled in for each supported window-system. I think it would be
different if using #ifndefs, though.


Are there any other issues to discuss, besides the comments in
termhooks.h (which I'll work on soon)? Have you tested this branch on
w32 to check if I missed anything there?



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH] Renaming non-X x_* identifiers
  2019-04-15 17:46                                                       ` Alex Gramiak
@ 2019-04-15 18:43                                                         ` Eli Zaretskii
  2019-04-16 16:24                                                           ` Alex Gramiak
  0 siblings, 1 reply; 68+ messages in thread
From: Eli Zaretskii @ 2019-04-15 18:43 UTC (permalink / raw)
  To: Alex Gramiak; +Cc: alan, emacs-devel

> From: Alex Gramiak <agrambot@gmail.com>
> Cc: emacs-devel@gnu.org,  alan@idiocy.org
> Date: Mon, 15 Apr 2019 11:46:18 -0600
> 
> Is it okay that I left the get_focus_frame hook in do_switch_frame
> (frame.c) unchecked? It's enclosed by a FRAME_WINDOW_P, so a comment
> in termhooks.c mandating that window systems implement that hook
> should be sufficient, no? On the other hand, it's the only one
> remaining in the generic code that's left unchecked.

Yes, and we have others in the same situations which _are_ tested, for
example:

  if (FRAME_WINDOW_P (f) && FRAME_TERMINAL (f)->frame_visible_invisible_hook)
    FRAME_TERMINAL (f)->frame_visible_invisible_hook (f, true);

So I think we should do the same with get_focus_frame hook as well.

> Are there any other issues to discuss, besides the comments in
> termhooks.h (which I'll work on soon)? Have you tested this branch on
> w32 to check if I missed anything there?

I didn't yet try the to build the branch, no.  I will try soon if no
one beats me to it.  After you finish the comments, let's wait for a
few days so people could try the branch.

Thanks.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH] Renaming non-X x_* identifiers
  2019-04-15 14:51                                                     ` Eli Zaretskii
  2019-04-15 17:46                                                       ` Alex Gramiak
@ 2019-04-15 22:01                                                       ` Stefan Monnier
  2019-04-16  2:29                                                         ` Eli Zaretskii
  1 sibling, 1 reply; 68+ messages in thread
From: Stefan Monnier @ 2019-04-15 22:01 UTC (permalink / raw)
  To: emacs-devel

BTW, instead of setting those hook function slots to NULL in
text-terminals and then test for non-NULL-ness before calling them,
can't we set them to `the_ignore_function`, which we could implement as
a vararg function which does nothing?


        Stefan




^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH] Renaming non-X x_* identifiers
  2019-04-15 22:01                                                       ` Stefan Monnier
@ 2019-04-16  2:29                                                         ` Eli Zaretskii
  2019-04-16 12:55                                                           ` Stefan Monnier
  0 siblings, 1 reply; 68+ messages in thread
From: Eli Zaretskii @ 2019-04-16  2:29 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

> From: Stefan Monnier <monnier@iro.umontreal.ca>
> Date: Mon, 15 Apr 2019 18:01:52 -0400
> 
> BTW, instead of setting those hook function slots to NULL in
> text-terminals and then test for non-NULL-ness before calling them,
> can't we set them to `the_ignore_function`, which we could implement as
> a vararg function which does nothing?

I thought about that, but calling an empty function would add a small
inefficiency, significantly larger than just a test against NULL.
Besides, the non-NULL tests were already all over the place anyway.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH] Renaming non-X x_* identifiers
  2019-04-16  2:29                                                         ` Eli Zaretskii
@ 2019-04-16 12:55                                                           ` Stefan Monnier
  2019-04-16 14:58                                                             ` Eli Zaretskii
  0 siblings, 1 reply; 68+ messages in thread
From: Stefan Monnier @ 2019-04-16 12:55 UTC (permalink / raw)
  To: emacs-devel

>> BTW, instead of setting those hook function slots to NULL in
>> text-terminals and then test for non-NULL-ness before calling them,
>> can't we set them to `the_ignore_function`, which we could implement as
>> a vararg function which does nothing?
>
> I thought about that, but calling an empty function would add a small
> inefficiency, significantly larger than just a test against NULL.

I doubt efficiency at those places in the code would ever be
noticeable ;-)

I was thinking about it from the point of the view of maintenance rather
than efficiency: it removes the need to know which slots might be NULL
(and hence require a test) and which not, so it should simplify
the code.

Anyway, either way is fine, of course,


        Stefan




^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH] Renaming non-X x_* identifiers
  2019-04-16 12:55                                                           ` Stefan Monnier
@ 2019-04-16 14:58                                                             ` Eli Zaretskii
  0 siblings, 0 replies; 68+ messages in thread
From: Eli Zaretskii @ 2019-04-16 14:58 UTC (permalink / raw)
  To: Stefan Monnier; +Cc: emacs-devel

> From: Stefan Monnier <monnier@iro.umontreal.ca>
> Date: Tue, 16 Apr 2019 08:55:38 -0400
> 
> I was thinking about it from the point of the view of maintenance rather
> than efficiency: it removes the need to know which slots might be NULL
> (and hence require a test) and which not, so it should simplify
> the code.

I'm not sure this simplification is for the better.  It makes
_writing_ the code easier, but it gets in the way of _reading_ it,
because one must go and see what the hook does, especially when
investigating some issue for a configuration where the hook makes no
sense.  This is C, not Lisp, so it's usually impossible to eval
something on the spot and see that the hook points to some function
whose name talks for itself.  You must fire up a debugger, stop it at
the right place, and only then you know.  I find this less convenient
than just reading the source, it feels like a C++ program, not a C
program.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH] Renaming non-X x_* identifiers
  2019-04-15 18:43                                                         ` Eli Zaretskii
@ 2019-04-16 16:24                                                           ` Alex Gramiak
  2019-04-16 16:45                                                             ` Eli Zaretskii
  0 siblings, 1 reply; 68+ messages in thread
From: Alex Gramiak @ 2019-04-16 16:24 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: alan, emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

> So I think we should do the same with get_focus_frame hook as well.

Right, done.

As for the comments, since we now check all of them in the generic code,
I don't think there's a whole lot to do. I have the following comment;
do you think it's sufficient?

  /* Multi-frame and mouse support hooks.  */

  /* Graphical window systems are expected to define all of the
     following hooks with the possible exception of:

   * query_colors
   * activate_menubar_hook
   * change_tool_bar_height_hook
   * set_bitmap_icon_hook
   * buffer_flipping_unblocked_hook

   */

I also added a couple missing comments to query_frame_background_color
and implicit_set_name_hook:

  /* This hook is called to store the frame's background color into
     BGCOLOR.  */

  /* This hook is called to set the name of the GUI window by redisplay
     unless another name was explicitly requested.  */



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH] Renaming non-X x_* identifiers
  2019-04-16 16:24                                                           ` Alex Gramiak
@ 2019-04-16 16:45                                                             ` Eli Zaretskii
  2019-04-16 16:59                                                               ` Alex Gramiak
  0 siblings, 1 reply; 68+ messages in thread
From: Eli Zaretskii @ 2019-04-16 16:45 UTC (permalink / raw)
  To: Alex Gramiak; +Cc: alan, emacs-devel

> From: Alex Gramiak <agrambot@gmail.com>
> Cc: emacs-devel@gnu.org,  alan@idiocy.org
> Date: Tue, 16 Apr 2019 10:24:13 -0600
> 
>   /* Multi-frame and mouse support hooks.  */
> 
>   /* Graphical window systems are expected to define all of the
>      following hooks with the possible exception of:
> 
>    * query_colors
>    * activate_menubar_hook
>    * change_tool_bar_height_hook
>    * set_bitmap_icon_hook
>    * buffer_flipping_unblocked_hook
> 
>    */
> 
> I also added a couple missing comments to query_frame_background_color
> and implicit_set_name_hook:
> 
>   /* This hook is called to store the frame's background color into
>      BGCOLOR.  */
> 
>   /* This hook is called to set the name of the GUI window by redisplay
>      unless another name was explicitly requested.  */

Sounds good enough, thanks.  We can always add more later if needed.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH] Renaming non-X x_* identifiers
  2019-04-16 16:45                                                             ` Eli Zaretskii
@ 2019-04-16 16:59                                                               ` Alex Gramiak
  2019-04-16 17:04                                                                 ` Eli Zaretskii
  0 siblings, 1 reply; 68+ messages in thread
From: Alex Gramiak @ 2019-04-16 16:59 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: alan, emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

> Sounds good enough, thanks.  We can always add more later if needed.

Okay, I pushed those changes. Hopefully you and Alan can find some time
in the next week or so to check out the w32/ns side of things.

Finally, what would you like me to do with the "Rename non-X x_*
identifiers" and "Rename non-X x_* identifiers 2" patches? Should I
split them up further, or is it okay to squash them into a single patch?



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH] Renaming non-X x_* identifiers
  2019-04-16 16:59                                                               ` Alex Gramiak
@ 2019-04-16 17:04                                                                 ` Eli Zaretskii
  2019-04-16 17:07                                                                   ` Alex Gramiak
  0 siblings, 1 reply; 68+ messages in thread
From: Eli Zaretskii @ 2019-04-16 17:04 UTC (permalink / raw)
  To: Alex Gramiak; +Cc: alan, emacs-devel

> From: Alex Gramiak <agrambot@gmail.com>
> Cc: emacs-devel@gnu.org,  alan@idiocy.org
> Date: Tue, 16 Apr 2019 10:59:15 -0600
> 
> Finally, what would you like me to do with the "Rename non-X x_*
> identifiers" and "Rename non-X x_* identifiers 2" patches? Should I
> split them up further, or is it okay to squash them into a single patch?

Hmm... I don't think I understand which patches are you talking
about.  Can you point me to the respective messages in the list
archives?



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH] Renaming non-X x_* identifiers
  2019-04-16 17:04                                                                 ` Eli Zaretskii
@ 2019-04-16 17:07                                                                   ` Alex Gramiak
  2019-04-16 18:09                                                                     ` Eli Zaretskii
  0 siblings, 1 reply; 68+ messages in thread
From: Alex Gramiak @ 2019-04-16 17:07 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: alan, emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Alex Gramiak <agrambot@gmail.com>
>> Cc: emacs-devel@gnu.org,  alan@idiocy.org
>> Date: Tue, 16 Apr 2019 10:59:15 -0600
>> 
>> Finally, what would you like me to do with the "Rename non-X x_*
>> identifiers" and "Rename non-X x_* identifiers 2" patches? Should I
>> split them up further, or is it okay to squash them into a single patch?
>
> Hmm... I don't think I understand which patches are you talking
> about.  Can you point me to the respective messages in the list
> archives?

I'm referring to the commits named "Rename non-X x_* identifiers"* in
scratch/x_emacs. Specifically commits 09fd8e70a0 and e7c3d39925. I left
the two commits separated until now since I wasn't sure whether a single
larger patch would be preferred/accepted.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH] Renaming non-X x_* identifiers
  2019-04-16 17:07                                                                   ` Alex Gramiak
@ 2019-04-16 18:09                                                                     ` Eli Zaretskii
  2019-04-24 19:40                                                                       ` Alex Gramiak
  0 siblings, 1 reply; 68+ messages in thread
From: Eli Zaretskii @ 2019-04-16 18:09 UTC (permalink / raw)
  To: Alex Gramiak; +Cc: alan, emacs-devel

> From: Alex Gramiak <agrambot@gmail.com>
> Cc: emacs-devel@gnu.org,  alan@idiocy.org
> Date: Tue, 16 Apr 2019 11:07:53 -0600
> 
> I'm referring to the commits named "Rename non-X x_* identifiers"* in
> scratch/x_emacs. Specifically commits 09fd8e70a0 and e7c3d39925. I left
> the two commits separated until now since I wasn't sure whether a single
> larger patch would be preferred/accepted.

It's entirely up to you how you merge the branch onto master, as long
as you make sure to accompany that with a suitable log message which
mentions the changes.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH] Renaming non-X x_* identifiers
  2019-04-16 18:09                                                                     ` Eli Zaretskii
@ 2019-04-24 19:40                                                                       ` Alex Gramiak
  2019-04-25  5:25                                                                         ` Eli Zaretskii
  0 siblings, 1 reply; 68+ messages in thread
From: Alex Gramiak @ 2019-04-24 19:40 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: alan, emacs-devel

Have you had a chance to build scratch/x_emacs on w32? I was hoping that
it would be okay to land this in master later this week, but no one has
tested the w32 side yet.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH] Renaming non-X x_* identifiers
  2019-04-24 19:40                                                                       ` Alex Gramiak
@ 2019-04-25  5:25                                                                         ` Eli Zaretskii
  2019-04-25  9:56                                                                           ` Eli Zaretskii
  0 siblings, 1 reply; 68+ messages in thread
From: Eli Zaretskii @ 2019-04-25  5:25 UTC (permalink / raw)
  To: Alex Gramiak; +Cc: alan, emacs-devel

> From: Alex Gramiak <agrambot@gmail.com>
> Cc: emacs-devel@gnu.org,  alan@idiocy.org
> Date: Wed, 24 Apr 2019 13:40:51 -0600
> 
> Have you had a chance to build scratch/x_emacs on w32?

Not yet, soon.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH] Renaming non-X x_* identifiers
  2019-04-25  5:25                                                                         ` Eli Zaretskii
@ 2019-04-25  9:56                                                                           ` Eli Zaretskii
  2019-04-25 14:50                                                                             ` Alex Gramiak
  0 siblings, 1 reply; 68+ messages in thread
From: Eli Zaretskii @ 2019-04-25  9:56 UTC (permalink / raw)
  To: agrambot; +Cc: alan, emacs-devel

> Date: Thu, 25 Apr 2019 08:25:17 +0300
> From: Eli Zaretskii <eliz@gnu.org>
> Cc: alan@idiocy.org, emacs-devel@gnu.org
> 
> > From: Alex Gramiak <agrambot@gmail.com>
> > Cc: emacs-devel@gnu.org,  alan@idiocy.org
> > Date: Wed, 24 Apr 2019 13:40:51 -0600
> > 
> > Have you had a chance to build scratch/x_emacs on w32?
> 
> Not yet, soon.

Done now.  The original didn't compile; error messages below for your
reference.  The patch to fix those is near the end; after applying it,
Emacs builds and seems to work.

Thanks!

    CC       xdisp.o
  xdisp.c: In function 'note_tool_bar_highlight':
  xdisp.c:13167:19: warning: implicit declaration of function 'x_mouse_grabbed'; did you mean 'gui_mouse_grabbed'? [-Wimplicit-function-declaration]
     mouse_down_p = (x_mouse_grabbed (dpyinfo)
		     ^~~~~~~~~~~~~~~
		     gui_mouse_grabbed
  xdisp.c:13167:19: warning: nested extern declaration of 'x_mouse_grabbed' [-Wnested-externs]
    [...]
    CC       w32fns.o
  w32fns.c:1649:1: warning: no previous prototype for 'w32_clear_under_internal_border' [-Wmissing-prototypes]
   w32_clear_under_internal_border (struct frame *f)
   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    CC       w32menu.o
    CC       w32reg.o
  w32reg.c:143:1: warning: no previous prototype for 'w32_get_string_resource' [-Wmissing-prototypes]
   w32_get_string_resource (void *v_rdb, const char *name, const char *class)
   ^~~~~~~~~~~~~~~~~~~~~~~
  w32reg.c: In function 'w32_get_string_resource':
  w32reg.c:145:21: warning: initialization makes pointer from integer without a cast [-Wint-conversion]
     const char *rdb = *((const char *)v_rdb);
		       ^
    CC       w32font.o
    CC       w32term.o
  w32term.c:187:13: error: conflicting types for 'w32_frame_rehighlight'
   static void w32_frame_rehighlight (struct w32_display_info *);
	       ^~~~~~~~~~~~~~~~~~~~~
  w32term.c:186:13: note: previous declaration of 'w32_frame_rehighlight' was here

   static void w32_frame_rehighlight (struct frame *);
	       ^~~~~~~~~~~~~~~~~~~~~
  w32term.c: In function 'w32_new_focus_frame':
  w32term.c:2943:3: warning: implicit declaration of function 'w32_reframe_highlight_1'; did you mean 'w32_frame_highlight'? [-Wimplicit-function-declaration]
     w32_reframe_highlight_1 (dpyinfo);
     ^~~~~~~~~~~~~~~~~~~~~~~
     w32_frame_highlight
  w32term.c:2943:3: warning: nested extern declaration of 'w32_reframe_highlight_1' [-Wnested-externs]
  w32term.c: At top level:
  w32term.c:3029:1: error: conflicting types for 'w32_frame_rehighlight'
   w32_frame_rehighlight (struct frame *frame)
   ^~~~~~~~~~~~~~~~~~~~~
  w32term.c:187:13: note: previous declaration of 'w32_frame_rehighlight' was here

   static void w32_frame_rehighlight (struct w32_display_info *);
	       ^~~~~~~~~~~~~~~~~~~~~
  w32term.c:3037:1: warning: conflicting types for 'w32_reframe_highlight_1'
   w32_reframe_highlight_1 (struct w32_display_info *dpyinfo)
   ^~~~~~~~~~~~~~~~~~~~~~~
  w32term.c:3037:1: error: static declaration of 'w32_reframe_highlight_1' follows non-static declaration
  w32term.c:2943:3: note: previous implicit declaration of 'w32_reframe_highlight_1' was here
     w32_reframe_highlight_1 (dpyinfo);
     ^~~~~~~~~~~~~~~~~~~~~~~
  w32term.c: In function 'w32_set_vertical_scroll_bar':
  w32term.c:4043:8: warning: implicit declaration of function 'w32_clear_under_internal_border'; did you mean 'iQdrag_internal_border'? [-Wimplicit-function-decla
  ration]
	  w32_clear_under_internal_border (f);
	  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	  iQdrag_internal_border
  w32term.c:4043:8: warning: nested extern declaration of 'w32_clear_under_internal_border' [-Wnested-externs]
  w32term.c: At top level:
  w32term.c:4669:1: error: static declaration of 'w32_scroll_bar_clear' follows non-static declaration
   w32_scroll_bar_clear (struct frame *f)
   ^~~~~~~~~~~~~~~~~~~~
  w32term.c:171:6: note: previous declaration of 'w32_scroll_bar_clear' was here
   void w32_scroll_bar_clear (struct frame *);
	^~~~~~~~~~~~~~~~~~~~
  w32term.c:7138:3: error: 'w32_clear_under_internal_border' undeclared here (not in a function); did you mean 'Qdrag_internal_border'?
     w32_clear_under_internal_border,
     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     Qdrag_internal_border
  w32term.c: In function 'w32_create_terminal':
  w32term.c:7170:32: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
     terminal->defined_color_hook = w32_defined_color;
				  ^
  At top level:
  w32term.c:4669:1: warning: 'w32_scroll_bar_clear' defined but not used [-Wunused-function]
   w32_scroll_bar_clear (struct frame *f)
   ^~~~~~~~~~~~~~~~~~~~
  w32term.c:3037:1: warning: 'w32_reframe_highlight_1' defined but not used [-Wunused-function]
   w32_reframe_highlight_1 (struct w32_display_info *dpyinfo)
   ^~~~~~~~~~~~~~~~~~~~~~~
  Makefile:394: recipe for target `w32term.o' failed
  make[1]: *** [w32term.o] Error 1
  make[1]: Leaving directory `/d/gnu/git/emacs/trunk/src'
  Makefile:423: recipe for target `src' failed
  make: *** [src] Error 2

--- ./src/w32fns.c~0	2019-04-25 12:25:08.979250000 +0300
+++ ./src/w32fns.c	2019-04-25 12:45:07.229250000 +0300
@@ -1173,7 +1173,7 @@ gamma_correct (struct frame *f, COLORREF
    the selected frame; if so, return the rgb values in COLOR_DEF.
    If ALLOC is nonzero, allocate a new colormap cell.  */
 
-int
+bool
 w32_defined_color (struct frame *f, const char *color, XColor *color_def,
 		   bool alloc_p, bool _makeIndex)
 {
--- ./src/w32reg.c~0	2019-04-25 12:25:08.994875000 +0300
+++ ./src/w32reg.c	2019-04-25 12:36:20.713625000 +0300
@@ -22,6 +22,7 @@ along with GNU Emacs.  If not, see <http
 #include <config.h>
 #include "lisp.h"
 #include "blockinput.h"
+#include "w32term.h"
 
 #include <stdio.h>
 
@@ -142,7 +143,7 @@ w32_get_string_resource_1 (const char *n
 const char *
 w32_get_string_resource (void *v_rdb, const char *name, const char *class)
 {
-  const char *rdb = *((const char *)v_rdb);
+  const char *rdb = v_rdb;
 
   if (rdb)
     {
--- ./src/w32term.c~0	2019-04-25 12:25:09.010500000 +0300
+++ ./src/w32term.c	2019-04-25 12:42:41.010500000 +0300
@@ -168,7 +168,7 @@ static void w32_handle_tool_bar_click (s
                                        struct input_event *);
 static void w32_define_cursor (Window, Cursor);
 
-void w32_scroll_bar_clear (struct frame *);
+static void w32_scroll_bar_clear (struct frame *);
 static void w32_raise_frame (struct frame *);
 static void w32_lower_frame (struct frame *);
 static void w32_initialize (void);
@@ -184,7 +184,7 @@ static void w32_focus_changed (int, int,
 static void w32_detect_focus_change (struct w32_display_info *,
                                      W32Msg *, struct input_event *);
 static void w32_frame_rehighlight (struct frame *);
-static void w32_frame_rehighlight (struct w32_display_info *);
+static void w32_reframe_highlight_1 (struct w32_display_info *);
 static void w32_draw_hollow_cursor (struct window *, struct glyph_row *);
 static void w32_draw_bar_cursor (struct window *, struct glyph_row *, int,
                                enum text_cursor_kinds);
--- ./src/w32term.h~0	2019-04-25 12:25:09.010500000 +0300
+++ ./src/w32term.h	2019-04-25 12:45:52.057375000 +0300
@@ -239,8 +239,8 @@ extern void w32_set_scroll_bar_default_h
 
 extern struct w32_display_info *w32_term_init (Lisp_Object,
 					       char *, char *);
-extern int w32_defined_color (struct frame *f, const char *color,
-                              XColor *color_def, bool alloc_p, bool _makeIndex);
+extern bool w32_defined_color (struct frame *, const char *, XColor *,
+			       bool, bool);
 extern int w32_display_pixel_height (struct w32_display_info *);
 extern int w32_display_pixel_width (struct w32_display_info *);
 extern void initialize_frame_menubar (struct frame *);
@@ -865,6 +865,7 @@ typedef char guichar_t;
 extern Lisp_Object w32_popup_dialog (struct frame *, Lisp_Object, Lisp_Object);
 extern void w32_arrow_cursor (void);
 
+extern void w32_clear_under_internal_border (struct frame *);
 extern void syms_of_w32term (void);
 extern void syms_of_w32menu (void);
 extern void syms_of_w32fns (void);
--- ./src/xdisp.c~0	2019-04-25 12:25:09.026125000 +0300
+++ ./src/xdisp.c	2019-04-25 12:29:48.573000000 +0300
@@ -13164,7 +13164,7 @@ note_tool_bar_highlight (struct frame *f
   clear_mouse_face (hlinfo);
 
   /* Mouse is down, but on different tool-bar item?  */
-  mouse_down_p = (x_mouse_grabbed (dpyinfo)
+  mouse_down_p = (gui_mouse_grabbed (dpyinfo)
 		  && f == dpyinfo->last_mouse_frame);
 
   if (mouse_down_p && f->last_tool_bar_item != prop_idx)



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH] Renaming non-X x_* identifiers
  2019-04-25  9:56                                                                           ` Eli Zaretskii
@ 2019-04-25 14:50                                                                             ` Alex Gramiak
  2019-04-25 15:04                                                                               ` Eli Zaretskii
  0 siblings, 1 reply; 68+ messages in thread
From: Alex Gramiak @ 2019-04-25 14:50 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: alan, emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

>> Date: Thu, 25 Apr 2019 08:25:17 +0300
>> From: Eli Zaretskii <eliz@gnu.org>
>> Cc: alan@idiocy.org, emacs-devel@gnu.org
>> 
>> > From: Alex Gramiak <agrambot@gmail.com>
>> > Cc: emacs-devel@gnu.org,  alan@idiocy.org
>> > Date: Wed, 24 Apr 2019 13:40:51 -0600
>> > 
>> > Have you had a chance to build scratch/x_emacs on w32?
>> 
>> Not yet, soon.
>
> Done now.  The original didn't compile; error messages below for your
> reference.  The patch to fix those is near the end; after applying it,
> Emacs builds and seems to work.

Thanks, I applied a few fixups around your patch that should cover
everything.

If everything is fine on your end, may I land this in the next few days
or so?



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH] Renaming non-X x_* identifiers
  2019-04-25 14:50                                                                             ` Alex Gramiak
@ 2019-04-25 15:04                                                                               ` Eli Zaretskii
  2019-04-26  6:52                                                                                 ` Robert Pluim
  0 siblings, 1 reply; 68+ messages in thread
From: Eli Zaretskii @ 2019-04-25 15:04 UTC (permalink / raw)
  To: Alex Gramiak; +Cc: alan, emacs-devel

> From: Alex Gramiak <agrambot@gmail.com>
> Cc: alan@idiocy.org,  emacs-devel@gnu.org
> Date: Thu, 25 Apr 2019 08:50:40 -0600
> 
> If everything is fine on your end, may I land this in the next few days
> or so?

If the NS port is verified as well, then yes.

Thanks.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH] Renaming non-X x_* identifiers
  2019-04-25 15:04                                                                               ` Eli Zaretskii
@ 2019-04-26  6:52                                                                                 ` Robert Pluim
  2019-04-26  8:07                                                                                   ` Eli Zaretskii
  0 siblings, 1 reply; 68+ messages in thread
From: Robert Pluim @ 2019-04-26  6:52 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: alan, Alex Gramiak, emacs-devel

>>>>> On Thu, 25 Apr 2019 18:04:25 +0300, Eli Zaretskii <eliz@gnu.org> said:

    >> From: Alex Gramiak <agrambot@gmail.com> Cc: alan@idiocy.org,
    >> emacs-devel@gnu.org Date: Thu, 25 Apr 2019 08:50:40 -0600
    >> 
    >> If everything is fine on your end, may I land this in the next
    >> few days or so?

    Eli> If the NS port is verified as well, then yes.

It builds and runs on NS and Ubuntu for me.

Robert




^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH] Renaming non-X x_* identifiers
  2019-04-26  6:52                                                                                 ` Robert Pluim
@ 2019-04-26  8:07                                                                                   ` Eli Zaretskii
  2019-04-26 23:12                                                                                     ` Alex Gramiak
  0 siblings, 1 reply; 68+ messages in thread
From: Eli Zaretskii @ 2019-04-26  8:07 UTC (permalink / raw)
  To: Robert Pluim; +Cc: emacs-devel

> From: Robert Pluim <rpluim@gmail.com>
> Cc: Alex Gramiak <agrambot@gmail.com>,  alan@idiocy.org,  emacs-devel@gnu.org
> Gmane-Reply-To-List: yes
> Date: Fri, 26 Apr 2019 08:52:56 +0200
> 
>     >> If everything is fine on your end, may I land this in the next
>     >> few days or so?
> 
>     Eli> If the NS port is verified as well, then yes.
> 
> It builds and runs on NS and Ubuntu for me.

Thanks, then I guess we are good to go with that changeset.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH] Renaming non-X x_* identifiers
  2019-04-26  8:07                                                                                   ` Eli Zaretskii
@ 2019-04-26 23:12                                                                                     ` Alex Gramiak
  0 siblings, 0 replies; 68+ messages in thread
From: Alex Gramiak @ 2019-04-26 23:12 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: Robert Pluim, emacs-devel

Eli Zaretskii <eliz@gnu.org> writes:

>> From: Robert Pluim <rpluim@gmail.com>
>> Cc: Alex Gramiak <agrambot@gmail.com>,  alan@idiocy.org,  emacs-devel@gnu.org
>> Gmane-Reply-To-List: yes
>> Date: Fri, 26 Apr 2019 08:52:56 +0200
>> 
>> It builds and runs on NS and Ubuntu for me.
>
> Thanks, then I guess we are good to go with that changeset.

OK, I rebased the changes onto master as ff4e31fa32..02397678b1.



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH] Renaming non-X x_* identifiers
  2019-04-13 16:13                                   ` [PATCH] Renaming non-X x_* identifiers (was: Renaming non-X x_* procedures in xdisp.c (and elsewhere)) Alex Gramiak
  2019-04-13 17:17                                     ` Eli Zaretskii
@ 2019-04-27  1:53                                     ` Basil L. Contovounesios
  2019-04-27  3:46                                       ` Alex Gramiak
  1 sibling, 1 reply; 68+ messages in thread
From: Basil L. Contovounesios @ 2019-04-27  1:53 UTC (permalink / raw)
  To: Alex Gramiak; +Cc: Eli Zaretskii, Alan Third, emacs-devel

> From 55a39c6cb4eb9a1442dd3388766f0219bf8cd825 Mon Sep 17 00:00:00 2001
> From: Alexander Gramiak <agrambot@gmail.com>
> Date: Sat, 13 Apr 2019 09:40:03 -0600
> Subject: [PATCH 3/5] Rename non-X x_* identifiers

[...]

> * src/dispextern.h (clear_under_internal_border): New RIF function
> pointer.

[...]

> diff --git a/src/xdisp.c b/src/xdisp.c
> index ae4c405b8d..11667d2735 100644
> --- a/src/xdisp.c
> +++ b/src/xdisp.c
> @@ -11592,9 +11592,8 @@ clear_garbaged_frames (void)
>  	      else
>  		clear_current_matrices (f);
>  
> -#if defined (HAVE_WINDOW_SYSTEM) && !defined (HAVE_NS)
> -	      x_clear_under_internal_border (f);
> -#endif /* HAVE_WINDOW_SYSTEM && !HAVE_NS */
> +              if (FRAME_RIF (f)->clear_under_internal_border)
> +                FRAME_RIF (f)->clear_under_internal_border (f);
>  
>  	      fset_redisplay (f);
>  	      f->garbaged = false;

This causes a segfault in 'emacs -nw' and emacsclient because
FRAME_RIF (f) is NULL in tty frames such as the initial daemon frame.
Is x_clear_under_internal_border not supposed to be run in tty frames?

Thanks,

-- 
Basil



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH] Renaming non-X x_* identifiers
  2019-04-27  1:53                                     ` Basil L. Contovounesios
@ 2019-04-27  3:46                                       ` Alex Gramiak
  2019-04-27 11:37                                         ` Basil L. Contovounesios
  0 siblings, 1 reply; 68+ messages in thread
From: Alex Gramiak @ 2019-04-27  3:46 UTC (permalink / raw)
  To: Basil L. Contovounesios; +Cc: Eli Zaretskii, emacs-devel

"Basil L. Contovounesios" <contovob@tcd.ie> writes:

>> diff --git a/src/xdisp.c b/src/xdisp.c
>> index ae4c405b8d..11667d2735 100644
>> --- a/src/xdisp.c
>> +++ b/src/xdisp.c
>> @@ -11592,9 +11592,8 @@ clear_garbaged_frames (void)
>>  	      else
>>  		clear_current_matrices (f);
>>  
>> -#if defined (HAVE_WINDOW_SYSTEM) && !defined (HAVE_NS)
>> -	      x_clear_under_internal_border (f);
>> -#endif /* HAVE_WINDOW_SYSTEM && !HAVE_NS */
>> +              if (FRAME_RIF (f)->clear_under_internal_border)
>> +                FRAME_RIF (f)->clear_under_internal_border (f);
>>  
>>  	      fset_redisplay (f);
>>  	      f->garbaged = false;
>
> This causes a segfault in 'emacs -nw' and emacsclient because
> FRAME_RIF (f) is NULL in tty frames such as the initial daemon frame.

Sorry about the trouble. Somehow I didn't test using -nw with a
HAVE_WINDOW_SYSTEM build. It should be fixed now.

> Is x_clear_under_internal_border not supposed to be run in tty frames?

Previously it did, but each implementation of that procedure was a no-op
for tty frames. The issue is that FRAME_RIF procedures shouldn't be
called for tty frames; I didn't realize that FRAME_RIF was NULL for tty
frames instead of a blank struct. I wonder if that should be changed to
avoid this in the future?



^ permalink raw reply	[flat|nested] 68+ messages in thread

* Re: [PATCH] Renaming non-X x_* identifiers
  2019-04-27  3:46                                       ` Alex Gramiak
@ 2019-04-27 11:37                                         ` Basil L. Contovounesios
  0 siblings, 0 replies; 68+ messages in thread
From: Basil L. Contovounesios @ 2019-04-27 11:37 UTC (permalink / raw)
  To: Alex Gramiak; +Cc: Eli Zaretskii, emacs-devel

Alex Gramiak <agrambot@gmail.com> writes:

> "Basil L. Contovounesios" <contovob@tcd.ie> writes:
>
>>> diff --git a/src/xdisp.c b/src/xdisp.c
>>> index ae4c405b8d..11667d2735 100644
>>> --- a/src/xdisp.c
>>> +++ b/src/xdisp.c
>>> @@ -11592,9 +11592,8 @@ clear_garbaged_frames (void)
>>>  	      else
>>>  		clear_current_matrices (f);
>>>  
>>> -#if defined (HAVE_WINDOW_SYSTEM) && !defined (HAVE_NS)
>>> -	      x_clear_under_internal_border (f);
>>> -#endif /* HAVE_WINDOW_SYSTEM && !HAVE_NS */
>>> +              if (FRAME_RIF (f)->clear_under_internal_border)
>>> +                FRAME_RIF (f)->clear_under_internal_border (f);
>>>  
>>>  	      fset_redisplay (f);
>>>  	      f->garbaged = false;
>>
>> This causes a segfault in 'emacs -nw' and emacsclient because
>> FRAME_RIF (f) is NULL in tty frames such as the initial daemon frame.
>
> Sorry about the trouble. Somehow I didn't test using -nw with a
> HAVE_WINDOW_SYSTEM build. It should be fixed now.

Thanks for the quick fix!

>> Is x_clear_under_internal_border not supposed to be run in tty frames?
>
> Previously it did, but each implementation of that procedure was a no-op
> for tty frames. The issue is that FRAME_RIF procedures shouldn't be
> called for tty frames; I didn't realize that FRAME_RIF was NULL for tty
> frames instead of a blank struct. I wonder if that should be changed to
> avoid this in the future?

I'm always for consistency, but I'm not familiar enough with this area
to know what drawbacks such a change may entail, or how much of the code
relies on current behaviour.  FWIW, here's the relevant commentary in
termhooks.h:

  /* Window-based redisplay interface for this device (0 for tty
     devices). */
  struct redisplay_interface *rif;

I'm guessing setting it to NULL as opposed to initialising the struct is
an optimisation for tty frames.  As a side note, I chuckled at this
commentary in an old version of dispnew.c:

  /* Current interface for window-based redisplay.  Set from
     update_begin.  A null value means we are not using window-based
     redisplay.  */
  /* XXX this variable causes frequent coredumps */

  struct redisplay_interface *rif;

-- 
Basil



^ permalink raw reply	[flat|nested] 68+ messages in thread

end of thread, other threads:[~2019-04-27 11:37 UTC | newest]

Thread overview: 68+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-23 15:07 Renaming non-X x_* procedures in xdisp.c (and elsewhere) Alex
2019-03-23 15:38 ` Stefan Monnier
2019-03-23 16:10 ` Eli Zaretskii
2019-03-23 16:41   ` Paul Eggert
2019-03-23 16:59     ` Eli Zaretskii
2019-03-23 17:39       ` Alex
2019-03-23 17:54         ` Alex
2019-03-23 18:16         ` Eli Zaretskii
2019-03-23 18:55           ` Alex
2019-03-23 19:32             ` Eli Zaretskii
2019-03-24  4:14               ` Alex
2019-03-24  4:50       ` Alex
2019-03-24  5:39         ` Eli Zaretskii
2019-03-24 15:05           ` Alex
2019-03-24 16:01             ` Yuri Khan
2019-03-24 16:13               ` Eli Zaretskii
2019-03-24 17:03                 ` Eli Zaretskii
2019-03-24 16:27             ` Eli Zaretskii
2019-03-24 18:30               ` Alex
2019-03-24 18:48                 ` Eli Zaretskii
2019-03-25 19:21                   ` Alex
2019-03-30 10:07                     ` Eli Zaretskii
2019-03-30 17:26                       ` Alex
2019-03-30 17:40                         ` Eli Zaretskii
2019-03-30 17:59                           ` Alex
2019-03-30 18:55                             ` Eli Zaretskii
2019-03-30 23:27                               ` Alex
2019-03-31 14:52                                 ` Eli Zaretskii
2019-04-11 19:07                                   ` Alex
2019-04-12 19:03                                     ` Eli Zaretskii
2019-04-12 19:50                                       ` Alex Gramiak
2019-04-12 20:10                                         ` Eli Zaretskii
2019-04-13 16:26                                           ` Alex Gramiak
2019-04-13 17:20                                             ` Eli Zaretskii
2019-04-13 16:13                                   ` [PATCH] Renaming non-X x_* identifiers (was: Renaming non-X x_* procedures in xdisp.c (and elsewhere)) Alex Gramiak
2019-04-13 17:17                                     ` Eli Zaretskii
2019-04-13 18:43                                       ` [PATCH] Renaming non-X x_* identifiers Alex Gramiak
2019-04-13 19:00                                         ` Eli Zaretskii
2019-04-14  3:35                                           ` Alex Gramiak
2019-04-14 14:02                                             ` Eli Zaretskii
2019-04-14 15:57                                               ` Alex Gramiak
2019-04-14 16:10                                                 ` Eli Zaretskii
2019-04-14 17:34                                                   ` Alex Gramiak
2019-04-15 14:51                                                     ` Eli Zaretskii
2019-04-15 17:46                                                       ` Alex Gramiak
2019-04-15 18:43                                                         ` Eli Zaretskii
2019-04-16 16:24                                                           ` Alex Gramiak
2019-04-16 16:45                                                             ` Eli Zaretskii
2019-04-16 16:59                                                               ` Alex Gramiak
2019-04-16 17:04                                                                 ` Eli Zaretskii
2019-04-16 17:07                                                                   ` Alex Gramiak
2019-04-16 18:09                                                                     ` Eli Zaretskii
2019-04-24 19:40                                                                       ` Alex Gramiak
2019-04-25  5:25                                                                         ` Eli Zaretskii
2019-04-25  9:56                                                                           ` Eli Zaretskii
2019-04-25 14:50                                                                             ` Alex Gramiak
2019-04-25 15:04                                                                               ` Eli Zaretskii
2019-04-26  6:52                                                                                 ` Robert Pluim
2019-04-26  8:07                                                                                   ` Eli Zaretskii
2019-04-26 23:12                                                                                     ` Alex Gramiak
2019-04-15 22:01                                                       ` Stefan Monnier
2019-04-16  2:29                                                         ` Eli Zaretskii
2019-04-16 12:55                                                           ` Stefan Monnier
2019-04-16 14:58                                                             ` Eli Zaretskii
2019-04-14  3:47                                         ` Stefan Monnier
2019-04-27  1:53                                     ` Basil L. Contovounesios
2019-04-27  3:46                                       ` Alex Gramiak
2019-04-27 11:37                                         ` Basil L. Contovounesios

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).