root/src/androidfns.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. android_display_info_for_name
  2. check_android_display_info
  3. check_x_display_info
  4. gamma_correct
  5. android_defined_color
  6. android_decode_color
  7. android_set_parent_frame
  8. android_implicitly_set_name
  9. android_explicitly_set_name
  10. android_set_tool_bar_lines
  11. android_set_tool_bar_position
  12. android_change_tool_bar_height
  13. android_set_tab_bar_lines
  14. android_change_tab_bar_height
  15. android_set_scroll_bar_default_height
  16. android_set_scroll_bar_default_width
  17. android_icon_verify
  18. android_icon
  19. android_make_gc
  20. android_free_gcs
  21. unwind_create_frame
  22. do_unwind_create_frame
  23. android_default_font_parameter
  24. android_create_frame_window
  25. DEFUN
  26. DEFUN
  27. DEFUN
  28. DEFUN
  29. DEFUN
  30. DEFUN
  31. DEFUN
  32. DEFUN
  33. DEFUN
  34. DEFUN
  35. DEFUN
  36. DEFUN
  37. DEFUN
  38. DEFUN
  39. android_make_monitor_attribute_list
  40. DEFUN
  41. frame_geometry
  42. DEFUN
  43. android_frame_list_z_order
  44. DEFUN
  45. DEFUN
  46. DEFUN
  47. DEFUN
  48. unwind_create_tip_frame
  49. android_create_tip_frame
  50. android_hide_tip
  51. compute_tip_xy
  52. DEFUN
  53. DEFUN
  54. android_set_background_color
  55. android_set_border_color
  56. android_set_cursor_color
  57. android_set_cursor_type
  58. android_set_foreground_color
  59. android_set_child_frame_border_width
  60. android_set_internal_border_width
  61. android_set_menu_bar_lines
  62. android_set_mouse_color
  63. android_set_title
  64. android_set_alpha
  65. android_set_no_focus_on_map
  66. android_set_no_accept_focus
  67. DEFUN
  68. DEFUN
  69. android_set_preeditarea
  70. syms_of_androidfns

     1 /* Communication module for Android terminals.
     2 
     3 Copyright (C) 2023 Free Software Foundation, Inc.
     4 
     5 This file is part of GNU Emacs.
     6 
     7 GNU Emacs is free software: you can redistribute it and/or modify
     8 it under the terms of the GNU General Public License as published by
     9 the Free Software Foundation, either version 3 of the License, or (at
    10 your option) any later version.
    11 
    12 GNU Emacs is distributed in the hope that it will be useful,
    13 but WITHOUT ANY WARRANTY; without even the implied warranty of
    14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    15 GNU General Public License for more details.
    16 
    17 You should have received a copy of the GNU General Public License
    18 along with GNU Emacs.  If not, see <https://www.gnu.org/licenses/>.  */
    19 
    20 #include <config.h>
    21 #include <math.h>
    22 
    23 #include "lisp.h"
    24 #include "android.h"
    25 #include "androidterm.h"
    26 #include "blockinput.h"
    27 #include "keyboard.h"
    28 #include "buffer.h"
    29 #include "androidgui.h"
    30 
    31 #ifndef ANDROID_STUBIFY
    32 
    33 /* Some kind of reference count for the image cache.  */
    34 static ptrdiff_t image_cache_refcount;
    35 
    36 /* The frame of the currently visible tooltip, or nil if none.  */
    37 static Lisp_Object tip_frame;
    38 
    39 /* The window-system window corresponding to the frame of the
    40    currently visible tooltip.  */
    41 static android_window tip_window;
    42 
    43 /* The X and Y deltas of the last call to `x-show-tip'.  */
    44 static Lisp_Object tip_dx, tip_dy;
    45 
    46 /* A timer that hides or deletes the currently visible tooltip when it
    47    fires.  */
    48 static Lisp_Object tip_timer;
    49 
    50 /* STRING argument of last `x-show-tip' call.  */
    51 static Lisp_Object tip_last_string;
    52 
    53 /* Normalized FRAME argument of last `x-show-tip' call.  */
    54 static Lisp_Object tip_last_frame;
    55 
    56 /* PARMS argument of last `x-show-tip' call.  */
    57 static Lisp_Object tip_last_parms;
    58 
    59 #endif
    60 
    61 static struct android_display_info *
    62 android_display_info_for_name (Lisp_Object name)
    63 {
    64   struct android_display_info *dpyinfo;
    65 
    66   CHECK_STRING (name);
    67 
    68   for (dpyinfo = x_display_list; dpyinfo; dpyinfo = dpyinfo->next)
    69     {
    70       if (!NILP (Fstring_equal (XCAR (dpyinfo->name_list_element),
    71                                 name)))
    72         return dpyinfo;
    73     }
    74 
    75   error ("Cannot connect to Android if it was not initialized"
    76          " at startup");
    77 }
    78 
    79 static struct android_display_info *
    80 check_android_display_info (Lisp_Object object)
    81 {
    82   struct android_display_info *dpyinfo;
    83   struct frame *sf, *f;
    84   struct terminal *t;
    85 
    86   if (NILP (object))
    87     {
    88       sf = XFRAME (selected_frame);
    89 
    90       if (FRAME_ANDROID_P (sf) && FRAME_LIVE_P (sf))
    91         dpyinfo = FRAME_DISPLAY_INFO (sf);
    92       else if (x_display_list)
    93         dpyinfo = x_display_list;
    94       else
    95         error ("Android windows are not in use or not initialized");
    96     }
    97   else if (TERMINALP (object))
    98     {
    99       t = decode_live_terminal (object);
   100 
   101       if (t->type != output_android)
   102         error ("Terminal %d is not an Android display", t->id);
   103 
   104       dpyinfo = t->display_info.android;
   105     }
   106   else if (STRINGP (object))
   107     dpyinfo = android_display_info_for_name (object);
   108   else
   109     {
   110       f = decode_window_system_frame (object);
   111       dpyinfo = FRAME_DISPLAY_INFO (f);
   112     }
   113 
   114   return dpyinfo;
   115 }
   116 
   117 Display_Info *
   118 check_x_display_info (Lisp_Object object)
   119 {
   120   return check_android_display_info (object);
   121 }
   122 
   123 
   124 
   125 #ifndef ANDROID_STUBIFY
   126 
   127 void
   128 gamma_correct (struct frame *f, Emacs_Color *color)
   129 {
   130   if (f->gamma)
   131     {
   132       color->red = pow (color->red / 65535.0, f->gamma) * 65535.0 + 0.5;
   133       color->green = pow (color->green / 65535.0, f->gamma) * 65535.0 + 0.5;
   134       color->blue = pow (color->blue / 65535.0, f->gamma) * 65535.0 + 0.5;
   135     }
   136 }
   137 
   138 /* Decide if color named COLOR_NAME is valid for use on frame F.  If
   139    so, return the RGB values in COLOR.  If ALLOC_P, allocate the
   140    color.  Value is false if COLOR_NAME is invalid, or no color could
   141    be allocated.  MAKE_INDEX is some mysterious argument used on
   142    NS. */
   143 
   144 bool
   145 android_defined_color (struct frame *f, const char *color_name,
   146                        Emacs_Color *color, bool alloc_p,
   147                        bool make_index)
   148 {
   149   bool success_p;
   150 
   151   success_p = false;
   152 
   153   block_input ();
   154   success_p = android_parse_color (f, color_name, color);
   155   if (success_p && alloc_p)
   156     success_p = android_alloc_nearest_color (f, color);
   157   unblock_input ();
   158 
   159   return success_p;
   160 }
   161 
   162 /* Return the pixel color value for color COLOR_NAME on frame F.  If F
   163    is a monochrome frame, return MONO_COLOR regardless of what ARG
   164    says.  Signal an error if color can't be allocated.  */
   165 
   166 static unsigned long
   167 android_decode_color (struct frame *f, Lisp_Object color_name, int mono_color)
   168 {
   169   Emacs_Color cdef;
   170 
   171   CHECK_STRING (color_name);
   172 
   173   if (android_defined_color (f, SSDATA (color_name), &cdef,
   174                              true, false))
   175     return cdef.pixel;
   176 
   177   signal_error ("Undefined color", color_name);
   178 }
   179 
   180 static void
   181 android_set_parent_frame (struct frame *f, Lisp_Object new_value,
   182                           Lisp_Object old_value)
   183 {
   184   struct frame *p;
   185 
   186   p = NULL;
   187 
   188   if (!NILP (new_value)
   189       && (!FRAMEP (new_value)
   190           || !FRAME_LIVE_P (p = XFRAME (new_value))
   191           || !FRAME_ANDROID_P (p)))
   192     {
   193       store_frame_param (f, Qparent_frame, old_value);
   194       error ("Invalid specification of `parent-frame'");
   195     }
   196 
   197   if (p != FRAME_PARENT_FRAME (f))
   198     {
   199       block_input ();
   200       android_reparent_window (FRAME_ANDROID_WINDOW (f),
   201                                (p ? FRAME_ANDROID_WINDOW (p)
   202                                 : FRAME_DISPLAY_INFO (f)->root_window),
   203                                f->left_pos, f->top_pos);
   204       unblock_input ();
   205 
   206       fset_parent_frame (f, new_value);
   207     }
   208 
   209   /* Update the fullscreen frame parameter as well.  */
   210   FRAME_TERMINAL (f)->fullscreen_hook (f);
   211 }
   212 
   213 void
   214 android_implicitly_set_name (struct frame *f, Lisp_Object arg,
   215                              Lisp_Object oldval)
   216 {
   217 
   218 }
   219 
   220 void
   221 android_explicitly_set_name (struct frame *f, Lisp_Object arg,
   222                              Lisp_Object oldval)
   223 {
   224 
   225 }
   226 
   227 /* Set the number of lines used for the tool bar of frame F to VALUE.
   228    VALUE not an integer, or < 0 means set the lines to zero.  OLDVAL
   229    is the old number of tool bar lines.  This function changes the
   230    height of all windows on frame F to match the new tool bar height.
   231    The frame's height doesn't change.  */
   232 
   233 static void
   234 android_set_tool_bar_lines (struct frame *f, Lisp_Object value,
   235                             Lisp_Object oldval)
   236 {
   237   int nlines;
   238 
   239   /* Treat tool bars like menu bars.  */
   240   if (FRAME_MINIBUF_ONLY_P (f))
   241     return;
   242 
   243   /* Use VALUE only if an int >= 0.  */
   244   if (RANGED_FIXNUMP (0, value, INT_MAX))
   245     nlines = XFIXNAT (value);
   246   else
   247     nlines = 0;
   248 
   249   android_change_tool_bar_height (f, nlines * FRAME_LINE_HEIGHT (f));
   250 }
   251 
   252 static void
   253 android_set_tool_bar_position (struct frame *f,
   254                                Lisp_Object new_value,
   255                                Lisp_Object old_value)
   256 {
   257   if (!EQ (new_value, Qtop) && !EQ (new_value, Qbottom))
   258     error ("Tool bar position must be either `top' or `bottom'");
   259 
   260   if (EQ (new_value, old_value))
   261     return;
   262 
   263   /* Set the tool bar position.  */
   264   fset_tool_bar_position (f, new_value);
   265 
   266   /* Now reconfigure frame glyphs to place the tool bar at the
   267      bottom.  While the inner height has not changed, call
   268      `resize_frame_windows' to place each of the windows at its
   269      new position.  */
   270 
   271   adjust_frame_size (f, -1, -1, 3, false, Qtool_bar_position);
   272   adjust_frame_glyphs (f);
   273   SET_FRAME_GARBAGED (f);
   274 
   275   if (FRAME_ANDROID_WINDOW (f))
   276     android_clear_under_internal_border (f);
   277 }
   278 
   279 void
   280 android_change_tool_bar_height (struct frame *f, int height)
   281 {
   282   int unit = FRAME_LINE_HEIGHT (f);
   283   int old_height = FRAME_TOOL_BAR_HEIGHT (f);
   284   int lines = (height + unit - 1) / unit;
   285   Lisp_Object fullscreen = get_frame_param (f, Qfullscreen);
   286 
   287   /* Make sure we redisplay all windows in this frame.  */
   288   fset_redisplay (f);
   289 
   290   FRAME_TOOL_BAR_HEIGHT (f) = height;
   291   FRAME_TOOL_BAR_LINES (f) = lines;
   292   store_frame_param (f, Qtool_bar_lines, make_fixnum (lines));
   293 
   294   if (FRAME_ANDROID_WINDOW (f) && FRAME_TOOL_BAR_HEIGHT (f) == 0)
   295     {
   296       clear_frame (f);
   297       clear_current_matrices (f);
   298     }
   299 
   300   if ((height < old_height) && WINDOWP (f->tool_bar_window))
   301     clear_glyph_matrix (XWINDOW (f->tool_bar_window)->current_matrix);
   302 
   303   if (!f->tool_bar_resized)
   304     {
   305       /* As long as tool_bar_resized is false, effectively try to change
   306          F's native height.  */
   307       if (NILP (fullscreen) || EQ (fullscreen, Qfullwidth))
   308         adjust_frame_size (f, FRAME_TEXT_WIDTH (f), FRAME_TEXT_HEIGHT (f),
   309                            1, false, Qtool_bar_lines);
   310       else
   311         adjust_frame_size (f, -1, -1, 4, false, Qtool_bar_lines);
   312 
   313       f->tool_bar_resized =  f->tool_bar_redisplayed;
   314     }
   315   else
   316     /* Any other change may leave the native size of F alone.  */
   317     adjust_frame_size (f, -1, -1, 3, false, Qtool_bar_lines);
   318 
   319   /* adjust_frame_size might not have done anything, garbage frame
   320      here.  */
   321   adjust_frame_glyphs (f);
   322   SET_FRAME_GARBAGED (f);
   323 }
   324 
   325 /* Set the number of lines used for the tab bar of frame F to VALUE.
   326    VALUE not an integer, or < 0 means set the lines to zero.  OLDVAL
   327    is the old number of tab bar lines.  This function may change the
   328    height of all windows on frame F to match the new tab bar height.
   329    The frame's height may change if frame_inhibit_implied_resize was
   330    set accordingly.  */
   331 
   332 static void
   333 android_set_tab_bar_lines (struct frame *f, Lisp_Object value,
   334                            Lisp_Object oldval)
   335 {
   336   int olines;
   337   int nlines;
   338 
   339   olines = FRAME_TAB_BAR_LINES (f);
   340 
   341   /* Treat tab bars like menu bars.  */
   342   if (FRAME_MINIBUF_ONLY_P (f))
   343     return;
   344 
   345   /* Use VALUE only if an int >= 0.  */
   346   if (RANGED_FIXNUMP (0, value, INT_MAX))
   347     nlines = XFIXNAT (value);
   348   else
   349     nlines = 0;
   350 
   351   if (nlines != olines && (olines == 0 || nlines == 0))
   352     android_change_tab_bar_height (f, nlines * FRAME_LINE_HEIGHT (f));
   353 }
   354 
   355 void
   356 android_change_tab_bar_height (struct frame *f, int height)
   357 {
   358   int unit, old_height, lines;
   359   Lisp_Object fullscreen;
   360 
   361   unit = FRAME_LINE_HEIGHT (f);
   362   old_height = FRAME_TAB_BAR_HEIGHT (f);
   363   fullscreen = get_frame_param (f, Qfullscreen);
   364 
   365   /* This differs from the tool bar code in that the tab bar height is
   366      not rounded up.  Otherwise, if redisplay_tab_bar decides to grow
   367      the tab bar by even 1 pixel, FRAME_TAB_BAR_LINES will be changed,
   368      leading to the tab bar height being incorrectly set upon the next
   369      call to android_set_font.  (bug#59285) */
   370   lines = height / unit;
   371 
   372   /* Make sure we redisplay all windows in this frame.  */
   373   fset_redisplay (f);
   374 
   375   /* Recalculate tab bar and frame text sizes.  */
   376   FRAME_TAB_BAR_HEIGHT (f) = height;
   377   FRAME_TAB_BAR_LINES (f) = lines;
   378   store_frame_param (f, Qtab_bar_lines, make_fixnum (lines));
   379 
   380   if (FRAME_ANDROID_WINDOW (f) && FRAME_TAB_BAR_HEIGHT (f) == 0)
   381     {
   382       clear_frame (f);
   383       clear_current_matrices (f);
   384     }
   385 
   386   if ((height < old_height) && WINDOWP (f->tab_bar_window))
   387     clear_glyph_matrix (XWINDOW (f->tab_bar_window)->current_matrix);
   388 
   389   if (!f->tab_bar_resized)
   390     {
   391       /* As long as tab_bar_resized is false, effectively try to change
   392          F's native height.  */
   393       if (NILP (fullscreen) || EQ (fullscreen, Qfullwidth))
   394         adjust_frame_size (f, FRAME_TEXT_WIDTH (f), FRAME_TEXT_HEIGHT (f),
   395                            1, false, Qtab_bar_lines);
   396       else
   397         adjust_frame_size (f, -1, -1, 4, false, Qtab_bar_lines);
   398 
   399       f->tab_bar_resized = f->tab_bar_redisplayed;
   400     }
   401   else
   402     /* Any other change may leave the native size of F alone.  */
   403     adjust_frame_size (f, -1, -1, 3, false, Qtab_bar_lines);
   404 
   405   /* adjust_frame_size might not have done anything, garbage frame
   406      here.  */
   407   adjust_frame_glyphs (f);
   408   SET_FRAME_GARBAGED (f);
   409 }
   410 
   411 void
   412 android_set_scroll_bar_default_height (struct frame *f)
   413 {
   414   int height;
   415 
   416   height = FRAME_LINE_HEIGHT (f);
   417 
   418   /* The height of a non-toolkit scrollbar is 14 pixels.  */
   419   FRAME_CONFIG_SCROLL_BAR_LINES (f) = (14 + height - 1) / height;
   420 
   421   /* Use all of that space (aside from required margins) for the
   422      scroll bar.  */
   423   FRAME_CONFIG_SCROLL_BAR_HEIGHT (f) = 14;
   424 }
   425 
   426 void
   427 android_set_scroll_bar_default_width (struct frame *f)
   428 {
   429   int unit;
   430 
   431   unit = FRAME_COLUMN_WIDTH (f);
   432 
   433   FRAME_CONFIG_SCROLL_BAR_COLS (f) = (14 + unit - 1) / unit;
   434   FRAME_CONFIG_SCROLL_BAR_WIDTH (f)
   435     = FRAME_CONFIG_SCROLL_BAR_COLS (f) * unit;
   436 }
   437 
   438 
   439 /* Verify that the icon position args for this window are valid.  */
   440 
   441 static void
   442 android_icon_verify (struct frame *f, Lisp_Object parms)
   443 {
   444   Lisp_Object icon_x, icon_y;
   445 
   446   /* Set the position of the icon.  Note that twm groups all
   447      icons in an icon window.  */
   448   icon_x = gui_frame_get_and_record_arg (f, parms, Qicon_left, 0, 0,
   449                                          RES_TYPE_NUMBER);
   450   icon_y = gui_frame_get_and_record_arg (f, parms, Qicon_top, 0, 0,
   451                                          RES_TYPE_NUMBER);
   452 
   453   if (!BASE_EQ (icon_x, Qunbound) && !BASE_EQ (icon_y, Qunbound))
   454     {
   455       CHECK_FIXNUM (icon_x);
   456       CHECK_FIXNUM (icon_y);
   457     }
   458   else if (!BASE_EQ (icon_x, Qunbound) || !BASE_EQ (icon_y, Qunbound))
   459     error ("Both left and top icon corners of icon must be specified");
   460 }
   461 
   462 /* Handle the icon stuff for this window.  Perhaps later we might
   463    want an x_set_icon_position which can be called interactively as
   464    well.  */
   465 
   466 static void
   467 android_icon (struct frame *f, Lisp_Object parms)
   468 {
   469   /* Set the position of the icon.  Note that twm groups all
   470      icons in an icon window.  */
   471   Lisp_Object icon_x
   472     = gui_frame_get_and_record_arg (f, parms, Qicon_left, 0, 0,
   473                                     RES_TYPE_NUMBER);
   474   Lisp_Object icon_y
   475     = gui_frame_get_and_record_arg (f, parms, Qicon_top, 0, 0,
   476                                     RES_TYPE_NUMBER);
   477 
   478   bool xgiven = !BASE_EQ (icon_x, Qunbound);
   479   bool ygiven = !BASE_EQ (icon_y, Qunbound);
   480 
   481   if (xgiven != ygiven)
   482     error ("Both left and top icon corners of icon must be specified");
   483 
   484   if (xgiven)
   485     {
   486       check_integer_range (icon_x, INT_MIN, INT_MAX);
   487       check_integer_range (icon_y, INT_MIN, INT_MAX);
   488     }
   489 
   490   /* Now return as this is not supported on Android.  */
   491 }
   492 
   493 /* Make the GCs needed for this window, setting the background
   494    color.  */
   495 
   496 static void
   497 android_make_gc (struct frame *f)
   498 {
   499   struct android_gc_values gc_values;
   500 
   501   block_input ();
   502 
   503   /* Create the GCs of this frame.
   504      Note that many default values are used.  */
   505 
   506   gc_values.foreground = FRAME_FOREGROUND_PIXEL (f);
   507   gc_values.background = FRAME_BACKGROUND_PIXEL (f);
   508   f->output_data.android->normal_gc
   509     = android_create_gc (ANDROID_GC_FOREGROUND | ANDROID_GC_BACKGROUND,
   510                          &gc_values);
   511 
   512   /* Reverse video style.  */
   513   gc_values.foreground = FRAME_BACKGROUND_PIXEL (f);
   514   gc_values.background = FRAME_FOREGROUND_PIXEL (f);
   515   f->output_data.android->reverse_gc
   516     = android_create_gc (ANDROID_GC_FOREGROUND | ANDROID_GC_BACKGROUND,
   517                          &gc_values);
   518 
   519   /* Cursor has cursor-color background, background-color foreground.  */
   520   gc_values.foreground = FRAME_BACKGROUND_PIXEL (f);
   521   gc_values.background = f->output_data.android->cursor_pixel;
   522   f->output_data.android->cursor_gc
   523     = android_create_gc (ANDROID_GC_FOREGROUND | ANDROID_GC_BACKGROUND,
   524                          &gc_values);
   525   unblock_input ();
   526 }
   527 
   528 
   529 /* Free what was allocated in android_make_gc.  */
   530 
   531 void
   532 android_free_gcs (struct frame *f)
   533 {
   534   block_input ();
   535 
   536   if (f->output_data.android->normal_gc)
   537     {
   538       android_free_gc (f->output_data.android->normal_gc);
   539       f->output_data.android->normal_gc = 0;
   540     }
   541 
   542   if (f->output_data.android->reverse_gc)
   543     {
   544       android_free_gc (f->output_data.android->reverse_gc);
   545       f->output_data.android->reverse_gc = 0;
   546     }
   547 
   548   if (f->output_data.android->cursor_gc)
   549     {
   550       android_free_gc (f->output_data.android->cursor_gc);
   551       f->output_data.android->cursor_gc = 0;
   552     }
   553 
   554   unblock_input ();
   555 }
   556 
   557 /* Handler for signals raised during x_create_frame and
   558    Fx_create_tip_frame.  FRAME is the frame which is partially
   559    constructed.  */
   560 
   561 static Lisp_Object
   562 unwind_create_frame (Lisp_Object frame)
   563 {
   564   struct frame *f = XFRAME (frame);
   565 
   566   /* If frame is already dead, nothing to do.  This can happen if the
   567      display is disconnected after the frame has become official, but
   568      before Fx_create_frame removes the unwind protect.  */
   569   if (!FRAME_LIVE_P (f))
   570     return Qnil;
   571 
   572   /* If frame is ``official'', nothing to do.  */
   573   if (NILP (Fmemq (frame, Vframe_list)))
   574     {
   575       /* If the frame's image cache refcount is still the same as our
   576          private shadow variable, it means we are unwinding a frame
   577          for which we didn't yet call init_frame_faces, where the
   578          refcount is incremented.  Therefore, we increment it here, so
   579          that free_frame_faces, called in x_free_frame_resources
   580          below, will not mistakenly decrement the counter that was not
   581          incremented yet to account for this new frame.  */
   582       if (FRAME_IMAGE_CACHE (f) != NULL
   583           && FRAME_IMAGE_CACHE (f)->refcount == image_cache_refcount)
   584         FRAME_IMAGE_CACHE (f)->refcount++;
   585 
   586       android_free_frame_resources (f);
   587       free_glyphs (f);
   588       return Qt;
   589     }
   590 
   591   return Qnil;
   592 }
   593 
   594 static void
   595 do_unwind_create_frame (Lisp_Object frame)
   596 {
   597   unwind_create_frame (frame);
   598 }
   599 
   600 void
   601 android_default_font_parameter (struct frame *f, Lisp_Object parms)
   602 {
   603   struct android_display_info *dpyinfo = FRAME_DISPLAY_INFO (f);
   604   Lisp_Object font_param = gui_display_get_arg (dpyinfo, parms, Qfont, NULL, NULL,
   605                                                 RES_TYPE_STRING);
   606   Lisp_Object font = Qnil;
   607   if (BASE_EQ (font_param, Qunbound))
   608     font_param = Qnil;
   609 
   610   if (NILP (font))
   611     font = (!NILP (font_param)
   612             ? font_param
   613             : gui_display_get_arg (dpyinfo, parms,
   614                                    Qfont, "font", "Font",
   615                                    RES_TYPE_STRING));
   616 
   617   if (! FONTP (font) && ! STRINGP (font))
   618     {
   619       const char *names[] = {
   620         "Droid Sans Mono-12",
   621         "Monospace-12",
   622         "DroidSansMono-12",
   623         NULL
   624       };
   625       int i;
   626 
   627       for (i = 0; names[i]; i++)
   628         {
   629           font = font_open_by_name (f, build_unibyte_string (names[i]));
   630           if (! NILP (font))
   631             break;
   632         }
   633 
   634       if (NILP (font))
   635         error ("No suitable font was found");
   636     }
   637 
   638   gui_default_parameter (f, parms, Qfont, font, "font", "Font", RES_TYPE_STRING);
   639 }
   640 
   641 static void
   642 android_create_frame_window (struct frame *f)
   643 {
   644   struct android_set_window_attributes attributes;
   645   enum android_window_value_mask attribute_mask;
   646 
   647   attributes.background_pixel = FRAME_BACKGROUND_PIXEL (f);
   648   attribute_mask = ANDROID_CW_BACK_PIXEL;
   649 
   650   block_input ();
   651   FRAME_ANDROID_WINDOW (f)
   652     = android_create_window (FRAME_DISPLAY_INFO (f)->root_window,
   653                              f->left_pos,
   654                              f->top_pos,
   655                              FRAME_PIXEL_WIDTH (f),
   656                              FRAME_PIXEL_HEIGHT (f),
   657                              attribute_mask, &attributes);
   658   unblock_input ();
   659 }
   660 
   661 #endif /* ANDROID_STUBIFY */
   662 
   663 
   664 
   665 DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame,
   666        1, 1, 0,
   667        doc: /* SKIP: real doc in xfns.c.  */)
   668   (Lisp_Object parms)
   669 {
   670 #ifdef ANDROID_STUBIFY
   671   error ("Android cross-compilation stub called!");
   672   return Qnil;
   673 #else
   674   struct frame *f;
   675   Lisp_Object frame, tem;
   676   Lisp_Object name;
   677   bool minibuffer_only;
   678   bool undecorated, override_redirect;
   679   long window_prompting;
   680   specpdl_ref count;
   681   Lisp_Object display;
   682   struct android_display_info *dpyinfo;
   683   Lisp_Object parent, parent_frame;
   684   struct kboard *kb;
   685 
   686   minibuffer_only = false;
   687   undecorated = false;
   688   override_redirect = false;
   689   window_prompting = 0;
   690   count = SPECPDL_INDEX ();
   691   dpyinfo = NULL;
   692 
   693   /* Not actually used, but be consistent with X.  */
   694   ((void) window_prompting);
   695 
   696   parms = Fcopy_alist (parms);
   697 
   698   /* Use this general default value to start with
   699      until we know if this frame has a specified name.  */
   700   Vx_resource_name = Vinvocation_name;
   701 
   702   display = gui_display_get_arg (dpyinfo, parms, Qterminal, 0, 0,
   703                                  RES_TYPE_NUMBER);
   704   if (BASE_EQ (display, Qunbound))
   705     display = gui_display_get_arg (dpyinfo, parms, Qdisplay, 0, 0,
   706                                    RES_TYPE_STRING);
   707   if (BASE_EQ (display, Qunbound))
   708     display = Qnil;
   709   dpyinfo = check_android_display_info (display);
   710   kb = dpyinfo->terminal->kboard;
   711 
   712   if (!dpyinfo->terminal->name)
   713     error ("Terminal is not live, can't create new frames on it");
   714 
   715   name = gui_display_get_arg (dpyinfo, parms, Qname, "name", "Name",
   716                               RES_TYPE_STRING);
   717   if (!STRINGP (name)
   718       && ! BASE_EQ (name, Qunbound)
   719       && ! NILP (name))
   720     error ("Invalid frame name--not a string or nil");
   721 
   722   if (STRINGP (name))
   723     Vx_resource_name = name;
   724 
   725   /* See if parent window is specified.  */
   726   parent = gui_display_get_arg (dpyinfo, parms, Qparent_id, NULL, NULL,
   727                                 RES_TYPE_NUMBER);
   728   if (BASE_EQ (parent, Qunbound))
   729     parent = Qnil;
   730   if (! NILP (parent))
   731     CHECK_FIXNUM (parent);
   732 
   733   frame = Qnil;
   734   tem = gui_display_get_arg (dpyinfo,
   735                              parms, Qminibuffer, "minibuffer", "Minibuffer",
   736                              RES_TYPE_SYMBOL);
   737   if (EQ (tem, Qnone) || NILP (tem))
   738     f = make_frame_without_minibuffer (Qnil, kb, display);
   739   else if (EQ (tem, Qonly))
   740     {
   741       f = make_minibuffer_frame ();
   742       minibuffer_only = true;
   743     }
   744   else if (WINDOWP (tem))
   745     f = make_frame_without_minibuffer (tem, kb, display);
   746   else
   747     f = make_frame (true);
   748 
   749   parent_frame = gui_display_get_arg (dpyinfo,
   750                                       parms,
   751                                       Qparent_frame,
   752                                       NULL,
   753                                       NULL,
   754                                       RES_TYPE_SYMBOL);
   755   /* Accept parent-frame iff parent-id was not specified.  */
   756   if (!NILP (parent)
   757       || BASE_EQ (parent_frame, Qunbound)
   758       || NILP (parent_frame)
   759       || !FRAMEP (parent_frame)
   760       || !FRAME_LIVE_P (XFRAME (parent_frame))
   761       || !FRAME_ANDROID_P (XFRAME (parent_frame)))
   762     parent_frame = Qnil;
   763 
   764   fset_parent_frame (f, parent_frame);
   765   store_frame_param (f, Qparent_frame, parent_frame);
   766 
   767   if (!NILP (tem = (gui_display_get_arg (dpyinfo,
   768                                          parms,
   769                                          Qundecorated,
   770                                          NULL,
   771                                          NULL,
   772                                          RES_TYPE_BOOLEAN)))
   773       && !(BASE_EQ (tem, Qunbound)))
   774     undecorated = true;
   775 
   776   FRAME_UNDECORATED (f) = undecorated;
   777   store_frame_param (f, Qundecorated, undecorated ? Qt : Qnil);
   778 
   779   if (!NILP (tem = (gui_display_get_arg (dpyinfo,
   780                                          parms,
   781                                          Qoverride_redirect,
   782                                          NULL,
   783                                          NULL,
   784                                          RES_TYPE_BOOLEAN)))
   785       && !(BASE_EQ (tem, Qunbound)))
   786     override_redirect = true;
   787 
   788   FRAME_OVERRIDE_REDIRECT (f) = override_redirect;
   789   store_frame_param (f, Qoverride_redirect, override_redirect ? Qt : Qnil);
   790 
   791   XSETFRAME (frame, f);
   792 
   793   f->terminal = dpyinfo->terminal;
   794 
   795   f->output_method = output_android;
   796   f->output_data.android = xzalloc (sizeof *f->output_data.android);
   797   FRAME_FONTSET (f) = -1;
   798   f->output_data.android->scroll_bar_foreground_pixel = -1;
   799   f->output_data.android->scroll_bar_background_pixel = -1;
   800   f->output_data.android->white_relief.pixel = -1;
   801   f->output_data.android->black_relief.pixel = -1;
   802 
   803   fset_icon_name (f, gui_display_get_arg (dpyinfo,
   804                                           parms,
   805                                           Qicon_name,
   806                                           "iconName",
   807                                           "Title",
   808                                           RES_TYPE_STRING));
   809   if (! STRINGP (f->icon_name))
   810     fset_icon_name (f, Qnil);
   811 
   812   FRAME_DISPLAY_INFO (f) = dpyinfo;
   813 
   814   /* With FRAME_DISPLAY_INFO set up, this unwind-protect is safe.  */
   815   record_unwind_protect (do_unwind_create_frame, frame);
   816 
   817   /* These colors will be set anyway later, but it's important
   818      to get the color reference counts right, so initialize them!
   819 
   820      (Not really on Android, but it's best to be consistent with
   821      X.) */
   822   {
   823     Lisp_Object black;
   824 
   825     /* Function x_decode_color can signal an error.  Make
   826        sure to initialize color slots so that we won't try
   827        to free colors we haven't allocated.  */
   828     FRAME_FOREGROUND_PIXEL (f) = -1;
   829     FRAME_BACKGROUND_PIXEL (f) = -1;
   830     f->output_data.android->cursor_pixel = -1;
   831     f->output_data.android->cursor_foreground_pixel = -1;
   832     f->output_data.android->mouse_pixel = -1;
   833 
   834     black = build_string ("black");
   835     FRAME_FOREGROUND_PIXEL (f)
   836       = android_decode_color (f, black, BLACK_PIX_DEFAULT (f));
   837     FRAME_BACKGROUND_PIXEL (f)
   838       = android_decode_color (f, black, BLACK_PIX_DEFAULT (f));
   839     f->output_data.android->cursor_pixel
   840       = android_decode_color (f, black, BLACK_PIX_DEFAULT (f));
   841     f->output_data.android->cursor_foreground_pixel
   842       = android_decode_color (f, black, BLACK_PIX_DEFAULT (f));
   843     f->output_data.android->mouse_pixel
   844       = android_decode_color (f, black, BLACK_PIX_DEFAULT (f));
   845   }
   846 
   847   /* Set the name; the functions to which we pass f expect the name to
   848      be set.  */
   849   if (BASE_EQ (name, Qunbound) || NILP (name))
   850     {
   851       fset_name (f, build_string ("GNU Emacs"));
   852       f->explicit_name = false;
   853     }
   854   else
   855     {
   856       fset_name (f, name);
   857       f->explicit_name = true;
   858       /* Use the frame's title when getting resources for this frame.  */
   859       specbind (Qx_resource_name, name);
   860     }
   861 
   862   register_font_driver (&androidfont_driver, f);
   863   register_font_driver (&android_sfntfont_driver, f);
   864 
   865   image_cache_refcount = (FRAME_IMAGE_CACHE (f)
   866                           ? FRAME_IMAGE_CACHE (f)->refcount
   867                           : 0);
   868 
   869   gui_default_parameter (f, parms, Qfont_backend, Qnil,
   870                          "fontBackend", "FontBackend", RES_TYPE_STRING);
   871 
   872   /* Extract the window parameters from the supplied values
   873      that are needed to determine window geometry.  */
   874   android_default_font_parameter (f, parms);
   875   if (!FRAME_FONT (f))
   876     {
   877       delete_frame (frame, Qnoelisp);
   878       error ("Invalid frame font");
   879     }
   880 
   881   if (NILP (Fassq (Qinternal_border_width, parms)))
   882     {
   883       Lisp_Object value;
   884 
   885       value = gui_display_get_arg (dpyinfo, parms, Qinternal_border_width,
   886                                    "internalBorder", "internalBorder",
   887                                    RES_TYPE_NUMBER);
   888       if (! BASE_EQ (value, Qunbound))
   889         parms = Fcons (Fcons (Qinternal_border_width, value),
   890                        parms);
   891     }
   892 
   893   gui_default_parameter (f, parms, Qinternal_border_width,
   894                          make_fixnum (0),
   895                          "internalBorderWidth", "internalBorderWidth",
   896                          RES_TYPE_NUMBER);
   897 
   898   /* Same for child frames.  */
   899   if (NILP (Fassq (Qchild_frame_border_width, parms)))
   900     {
   901       Lisp_Object value;
   902 
   903       value = gui_display_get_arg (dpyinfo, parms, Qchild_frame_border_width,
   904                                    "childFrameBorder", "childFrameBorder",
   905                                    RES_TYPE_NUMBER);
   906       if (! BASE_EQ (value, Qunbound))
   907         parms = Fcons (Fcons (Qchild_frame_border_width, value),
   908                        parms);
   909     }
   910 
   911   gui_default_parameter (f, parms, Qchild_frame_border_width, Qnil,
   912                          "childFrameBorderWidth", "childFrameBorderWidth",
   913                          RES_TYPE_NUMBER);
   914   gui_default_parameter (f, parms, Qright_divider_width, make_fixnum (0),
   915                          NULL, NULL, RES_TYPE_NUMBER);
   916   gui_default_parameter (f, parms, Qbottom_divider_width, make_fixnum (0),
   917                          NULL, NULL, RES_TYPE_NUMBER);
   918 
   919   /* `vertical-scroll-bars' defaults to nil on Android as a
   920      consequence of scroll bars not being supported at all.  */
   921 
   922   gui_default_parameter (f, parms, Qvertical_scroll_bars, Qnil,
   923                          "verticalScrollBars", "ScrollBars",
   924                          RES_TYPE_SYMBOL);
   925   gui_default_parameter (f, parms, Qhorizontal_scroll_bars, Qnil,
   926                          "horizontalScrollBars", "ScrollBars",
   927                          RES_TYPE_SYMBOL);
   928 
   929   /* Also do the stuff which must be set before the window exists.  */
   930   gui_default_parameter (f, parms, Qforeground_color, build_string ("black"),
   931                          "foreground", "Foreground", RES_TYPE_STRING);
   932   gui_default_parameter (f, parms, Qbackground_color, build_string ("white"),
   933                          "background", "Background", RES_TYPE_STRING);
   934   gui_default_parameter (f, parms, Qmouse_color, build_string ("black"),
   935                          "pointerColor", "Foreground", RES_TYPE_STRING);
   936   gui_default_parameter (f, parms, Qborder_color, build_string ("black"),
   937                          "borderColor", "BorderColor", RES_TYPE_STRING);
   938   gui_default_parameter (f, parms, Qscreen_gamma, Qnil,
   939                          "screenGamma", "ScreenGamma", RES_TYPE_FLOAT);
   940   gui_default_parameter (f, parms, Qline_spacing, Qnil,
   941                          "lineSpacing", "LineSpacing", RES_TYPE_NUMBER);
   942   gui_default_parameter (f, parms, Qleft_fringe, Qnil,
   943                          "leftFringe", "LeftFringe", RES_TYPE_NUMBER);
   944   gui_default_parameter (f, parms, Qright_fringe, Qnil,
   945                          "rightFringe", "RightFringe", RES_TYPE_NUMBER);
   946   gui_default_parameter (f, parms, Qno_special_glyphs, Qnil,
   947                          NULL, NULL, RES_TYPE_BOOLEAN);
   948 
   949 #if 0
   950   android_default_scroll_bar_color_parameter (f, parms, Qscroll_bar_foreground,
   951                                               "scrollBarForeground",
   952                                               "ScrollBarForeground", true);
   953   android_default_scroll_bar_color_parameter (f, parms, Qscroll_bar_background,
   954                                               "scrollBarBackground",
   955                                               "ScrollBarBackground", false);
   956 #endif
   957 
   958   /* Init faces before gui_default_parameter is called for the
   959      scroll-bar-width parameter because otherwise we end up in
   960      init_iterator with a null face cache, which should not
   961      happen.  */
   962 
   963   init_frame_faces (f);
   964 
   965   tem = gui_display_get_arg (dpyinfo, parms, Qmin_width, NULL, NULL,
   966                              RES_TYPE_NUMBER);
   967   if (FIXNUMP (tem))
   968     store_frame_param (f, Qmin_width, tem);
   969   tem = gui_display_get_arg (dpyinfo, parms, Qmin_height, NULL, NULL,
   970                              RES_TYPE_NUMBER);
   971   if (FIXNUMP (tem))
   972     store_frame_param (f, Qmin_height, tem);
   973 
   974   adjust_frame_size (f, FRAME_COLS (f) * FRAME_COLUMN_WIDTH (f),
   975                      FRAME_LINES (f) * FRAME_LINE_HEIGHT (f), 5, true,
   976                      Qx_create_frame_1);
   977 
   978   /* Set the menu-bar-lines and tool-bar-lines parameters.  We don't
   979      look up the X resources controlling the menu-bar and tool-bar
   980      here; they are processed specially at startup, and reflected in
   981      the values of the mode variables.  */
   982 
   983   gui_default_parameter (f, parms, Qmenu_bar_lines,
   984                          NILP (Vmenu_bar_mode)
   985                          ? make_fixnum (0) : make_fixnum (1),
   986                          NULL, NULL, RES_TYPE_NUMBER);
   987   gui_default_parameter (f, parms, Qtab_bar_lines,
   988                          NILP (Vtab_bar_mode)
   989                          ? make_fixnum (0) : make_fixnum (1),
   990                          NULL, NULL, RES_TYPE_NUMBER);
   991   gui_default_parameter (f, parms, Qtool_bar_lines,
   992                          NILP (Vtool_bar_mode)
   993                          ? make_fixnum (0) : make_fixnum (1),
   994                          NULL, NULL, RES_TYPE_NUMBER);
   995 
   996   gui_default_parameter (f, parms, Qbuffer_predicate, Qnil,
   997                          "bufferPredicate", "BufferPredicate",
   998                          RES_TYPE_SYMBOL);
   999   gui_default_parameter (f, parms, Qtitle, Qnil,
  1000                          "title", "Title", RES_TYPE_STRING);
  1001   gui_default_parameter (f, parms, Qwait_for_wm, Qt,
  1002                          "waitForWM", "WaitForWM", RES_TYPE_BOOLEAN);
  1003   gui_default_parameter (f, parms, Qtool_bar_position,
  1004                          FRAME_TOOL_BAR_POSITION (f), 0, 0, RES_TYPE_SYMBOL);
  1005   gui_default_parameter (f, parms, Qinhibit_double_buffering, Qnil,
  1006                          "inhibitDoubleBuffering", "InhibitDoubleBuffering",
  1007                          RES_TYPE_BOOLEAN);
  1008 
  1009   /* Compute the size of the X window.  */
  1010   window_prompting = gui_figure_window_size (f, parms, true, true);
  1011 
  1012   tem = gui_display_get_arg (dpyinfo, parms, Qunsplittable, 0, 0,
  1013                              RES_TYPE_BOOLEAN);
  1014   f->no_split = minibuffer_only || EQ (tem, Qt);
  1015 
  1016   android_icon_verify (f, parms);
  1017   android_create_frame_window (f);
  1018   android_icon (f, parms);
  1019   android_make_gc (f);
  1020 
  1021   /* Now consider the frame official.  */
  1022   f->terminal->reference_count++;
  1023   Vframe_list = Fcons (frame, Vframe_list);
  1024 
  1025   /* We need to do this after creating the window, so that the
  1026      icon-creation functions can say whose icon they're
  1027      describing.  */
  1028   gui_default_parameter (f, parms, Qicon_type, Qt,
  1029                          "bitmapIcon", "BitmapIcon", RES_TYPE_BOOLEAN);
  1030 
  1031   gui_default_parameter (f, parms, Qauto_raise, Qnil,
  1032                          "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN);
  1033   gui_default_parameter (f, parms, Qauto_lower, Qnil,
  1034                          "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN);
  1035   gui_default_parameter (f, parms, Qcursor_type, Qbox,
  1036                          "cursorType", "CursorType", RES_TYPE_SYMBOL);
  1037   /* Scroll bars are not supported on Android, as they are near
  1038      useless.  */
  1039   gui_default_parameter (f, parms, Qscroll_bar_width, Qnil,
  1040                          "scrollBarWidth", "ScrollBarWidth",
  1041                          RES_TYPE_NUMBER);
  1042   gui_default_parameter (f, parms, Qscroll_bar_height, Qnil,
  1043                          "scrollBarHeight", "ScrollBarHeight",
  1044                          RES_TYPE_NUMBER);
  1045   gui_default_parameter (f, parms, Qalpha, Qnil,
  1046                          "alpha", "Alpha", RES_TYPE_NUMBER);
  1047   gui_default_parameter (f, parms, Qalpha_background, Qnil,
  1048                          "alphaBackground", "AlphaBackground", RES_TYPE_NUMBER);
  1049 
  1050   if (!NILP (parent_frame))
  1051     {
  1052       struct frame *p = XFRAME (parent_frame);
  1053 
  1054       block_input ();
  1055       android_reparent_window (FRAME_ANDROID_WINDOW (f),
  1056                                FRAME_ANDROID_WINDOW (p),
  1057                                f->left_pos, f->top_pos);
  1058       unblock_input ();
  1059     }
  1060 
  1061   gui_default_parameter (f, parms, Qno_focus_on_map, Qnil,
  1062                          NULL, NULL, RES_TYPE_BOOLEAN);
  1063   gui_default_parameter (f, parms, Qno_accept_focus, Qnil,
  1064                          NULL, NULL, RES_TYPE_BOOLEAN);
  1065 
  1066   /* Consider frame official, now.  */
  1067   f->can_set_window_size = true;
  1068 
  1069   adjust_frame_size (f, FRAME_TEXT_WIDTH (f), FRAME_TEXT_HEIGHT (f),
  1070                      0, true, Qx_create_frame_2);
  1071 
  1072   /* Process fullscreen parameter here in the hope that normalizing a
  1073      fullheight/fullwidth frame will produce the size set by the last
  1074      adjust_frame_size call.  Note that Android only supports the
  1075      `maximized' state.  */
  1076   gui_default_parameter (f, parms, Qfullscreen, Qmaximized,
  1077                          "fullscreen", "Fullscreen", RES_TYPE_SYMBOL);
  1078 
  1079   /* When called from `x-create-frame-with-faces' visibility is
  1080      always explicitly nil.  */
  1081   Lisp_Object visibility
  1082     = gui_display_get_arg (dpyinfo, parms, Qvisibility, 0, 0,
  1083                            RES_TYPE_SYMBOL);
  1084   Lisp_Object height
  1085     = gui_display_get_arg (dpyinfo, parms, Qheight, 0, 0, RES_TYPE_NUMBER);
  1086   Lisp_Object width
  1087     = gui_display_get_arg (dpyinfo, parms, Qwidth, 0, 0, RES_TYPE_NUMBER);
  1088 
  1089   if (EQ (visibility, Qicon))
  1090     {
  1091       f->was_invisible = true;
  1092       android_iconify_frame (f);
  1093     }
  1094   else
  1095     {
  1096       if (BASE_EQ (visibility, Qunbound))
  1097         visibility = Qt;
  1098 
  1099       if (!NILP (visibility))
  1100         android_make_frame_visible (f);
  1101       else
  1102         f->was_invisible = true;
  1103     }
  1104 
  1105   /* Leave f->was_invisible true only if height or width were
  1106      specified too.  This takes effect only when we are not called
  1107      from `x-create-frame-with-faces' (see above comment).  */
  1108   f->was_invisible
  1109     = (f->was_invisible
  1110        && (!BASE_EQ (height, Qunbound) || !BASE_EQ (width, Qunbound)));
  1111 
  1112   store_frame_param (f, Qvisibility, visibility);
  1113 
  1114   /* Set whether or not frame synchronization is enabled.  */
  1115   gui_default_parameter (f, parms, Quse_frame_synchronization, Qt,
  1116                          NULL, NULL, RES_TYPE_BOOLEAN);
  1117 
  1118   /* Works iff frame has been already mapped.  */
  1119   gui_default_parameter (f, parms, Qskip_taskbar, Qnil,
  1120                          NULL, NULL, RES_TYPE_BOOLEAN);
  1121   /* The `z-group' parameter works only for visible frames.  */
  1122   gui_default_parameter (f, parms, Qz_group, Qnil,
  1123                          NULL, NULL, RES_TYPE_SYMBOL);
  1124 
  1125   /* Initialize `default-minibuffer-frame' in case this is the first
  1126      frame on this terminal.  */
  1127   if (FRAME_HAS_MINIBUF_P (f)
  1128       && (!FRAMEP (KVAR (kb, Vdefault_minibuffer_frame))
  1129           || !FRAME_LIVE_P (XFRAME (KVAR (kb, Vdefault_minibuffer_frame)))))
  1130     kset_default_minibuffer_frame (kb, frame);
  1131 
  1132   /* All remaining specified parameters, which have not been "used" by
  1133      gui_display_get_arg and friends, now go in the misc. alist of the
  1134      frame.  */
  1135   for (tem = parms; CONSP (tem); tem = XCDR (tem))
  1136     if (CONSP (XCAR (tem)) && !NILP (XCAR (XCAR (tem))))
  1137       fset_param_alist (f, Fcons (XCAR (tem), f->param_alist));
  1138 
  1139   /* Make sure windows on this frame appear in calls to next-window
  1140      and similar functions.  */
  1141   Vwindow_list = Qnil;
  1142 
  1143   return unbind_to (count, frame);
  1144 #endif
  1145 }
  1146 
  1147 DEFUN ("xw-color-defined-p", Fxw_color_defined_p, Sxw_color_defined_p,
  1148        1, 2, 0, doc: /* SKIP: real doc in xfns.c.  */)
  1149   (Lisp_Object color, Lisp_Object frame)
  1150 {
  1151 #ifdef ANDROID_STUBIFY
  1152   error ("Android cross-compilation stub called!");
  1153   return Qnil;
  1154 #else
  1155   Emacs_Color foo;
  1156   struct frame *f;
  1157 
  1158   f = decode_window_system_frame (frame);
  1159 
  1160   CHECK_STRING (color);
  1161 
  1162   if (android_defined_color (f, SSDATA (color), &foo, false, false))
  1163     return Qt;
  1164   else
  1165     return Qnil;
  1166 #endif
  1167 }
  1168 
  1169 DEFUN ("xw-color-values", Fxw_color_values, Sxw_color_values, 1, 2,
  1170        0, doc: /* SKIP: real doc in xfns.c.  */)
  1171   (Lisp_Object color, Lisp_Object frame)
  1172 {
  1173 #ifdef ANDROID_STUBIFY
  1174   error ("Android cross-compilation stub called!");
  1175   return Qnil;
  1176 #else
  1177   Emacs_Color foo;
  1178   struct frame *f;
  1179 
  1180   f = decode_window_system_frame (frame);
  1181 
  1182   CHECK_STRING (color);
  1183 
  1184   if (android_defined_color (f, SSDATA (color), &foo, false, false))
  1185     return list3i (foo.red, foo.green, foo.blue);
  1186   else
  1187     return Qnil;
  1188 #endif
  1189 }
  1190 
  1191 DEFUN ("xw-display-color-p", Fxw_display_color_p,
  1192        Sxw_display_color_p, 0, 1, 0,
  1193        doc: /* SKIP: real doc in xfns.c.  */)
  1194   (Lisp_Object terminal)
  1195 {
  1196   return Qt;
  1197 }
  1198 
  1199 DEFUN ("x-display-grayscale-p", Fx_display_grayscale_p,
  1200        Sx_display_grayscale_p, 0, 1, 0,
  1201        doc: /* SKIP: real doc in xfns.c.  */)
  1202   (Lisp_Object terminal)
  1203 {
  1204   return Qnil;
  1205 }
  1206 
  1207 DEFUN ("x-display-pixel-width", Fx_display_pixel_width,
  1208        Sx_display_pixel_width, 0, 1, 0,
  1209        doc: /* SKIP: real doc in xfns.c.  */)
  1210   (Lisp_Object terminal)
  1211 {
  1212 #ifdef ANDROID_STUBIFY
  1213   error ("Android cross-compilation stub called!");
  1214   return Qnil;
  1215 #else
  1216   return make_fixnum (android_get_screen_width ());
  1217 #endif
  1218 }
  1219 
  1220 DEFUN ("x-display-pixel-height", Fx_display_pixel_height,
  1221        Sx_display_pixel_height, 0, 1, 0,
  1222        doc: /* SKIP: real doc in xfns.c.  */)
  1223   (Lisp_Object terminal)
  1224 {
  1225 #ifdef ANDROID_STUBIFY
  1226   error ("Android cross-compilation stub called!");
  1227   return Qnil;
  1228 #else
  1229   return make_fixnum (android_get_screen_height ());
  1230 #endif
  1231 }
  1232 
  1233 DEFUN ("x-display-planes", Fx_display_planes, Sx_display_planes,
  1234        0, 1, 0,
  1235        doc: /* SKIP: real doc in xfns.c.  */)
  1236   (Lisp_Object terminal)
  1237 {
  1238   struct android_display_info *dpyinfo;
  1239 
  1240   dpyinfo = check_android_display_info (terminal);
  1241 
  1242   return make_fixnum (dpyinfo->n_planes);
  1243 }
  1244 
  1245 DEFUN ("x-display-color-cells", Fx_display_color_cells, Sx_display_color_cells,
  1246        0, 1, 0,
  1247        doc: /* SKIP: real doc in xfns.c.  */)
  1248   (Lisp_Object terminal)
  1249 {
  1250   struct android_display_info *dpyinfo;
  1251   int nr_planes;
  1252 
  1253   dpyinfo = check_android_display_info (terminal);
  1254   nr_planes = dpyinfo->n_planes;
  1255 
  1256   /* Truncate nr_planes to 24 to avoid integer overflow.  */
  1257 
  1258   if (nr_planes > 24)
  1259     nr_planes = 24;
  1260 
  1261   return make_fixnum (1 << nr_planes);
  1262 }
  1263 
  1264 DEFUN ("x-server-vendor", Fx_server_vendor, Sx_server_vendor, 0, 1, 0,
  1265        doc: /* SKIP: real doc in xfns.c.  */)
  1266   (Lisp_Object terminal)
  1267 {
  1268 #ifdef ANDROID_STUBIFY
  1269   error ("Android cross-compilation stub called!");
  1270   return Qnil;
  1271 #else
  1272   check_android_display_info (terminal);
  1273   return Vandroid_build_manufacturer;
  1274 #endif
  1275 }
  1276 
  1277 DEFUN ("x-server-version", Fx_server_version, Sx_server_version, 0, 1, 0,
  1278        doc: /* SKIP: real doc in xfns.c.  */)
  1279   (Lisp_Object terminal)
  1280 {
  1281 #ifdef ANDROID_STUBIFY
  1282   error ("Android cross-compilation stub called!");
  1283   return Qnil;
  1284 #else
  1285   check_android_display_info (terminal);
  1286   return list3i (android_get_current_api_level (), 0, 0);
  1287 #endif
  1288 }
  1289 
  1290 DEFUN ("x-display-screens", Fx_display_screens, Sx_display_screens,
  1291        0, 1, 0, doc: /* SKIP: real doc in xfns.c.  */)
  1292   (Lisp_Object terminal)
  1293 {
  1294   check_android_display_info (terminal);
  1295   return make_fixnum (1);
  1296 }
  1297 
  1298 DEFUN ("x-display-mm-width", Fx_display_mm_width, Sx_display_mm_width,
  1299        0, 1, 0, doc: /* SKIP: real doc in xfns.c.  */)
  1300   (Lisp_Object terminal)
  1301 {
  1302 #ifdef ANDROID_STUBIFY
  1303   error ("Android cross-compilation stub called!");
  1304   return Qnil;
  1305 #else
  1306   return make_fixnum (android_get_mm_width ());
  1307 #endif
  1308 }
  1309 
  1310 DEFUN ("x-display-mm-height", Fx_display_mm_height, Sx_display_mm_height,
  1311        0, 1, 0, doc: /* SKIP: real doc in xfns.c.  */)
  1312   (Lisp_Object terminal)
  1313 {
  1314 #ifdef ANDROID_STUBIFY
  1315   error ("Android cross-compilation stub called!");
  1316   return Qnil;
  1317 #else
  1318   return make_fixnum (android_get_mm_height ());
  1319 #endif
  1320 }
  1321 
  1322 DEFUN ("x-display-backing-store", Fx_display_backing_store,
  1323        Sx_display_backing_store, 0, 1, 0,
  1324        doc: /* SKIP: real doc in xfns.c.  */)
  1325   (Lisp_Object terminal)
  1326 {
  1327   check_android_display_info (terminal);
  1328 
  1329   /* The Java part is implemented in a way that it always does the
  1330      equivalent of backing store.  */
  1331   return Qalways;
  1332 }
  1333 
  1334 DEFUN ("x-display-visual-class", Fx_display_visual_class,
  1335        Sx_display_visual_class, 0, 1, 0,
  1336        doc: /* SKIP: real doc in xfns.c.  */)
  1337   (Lisp_Object terminal)
  1338 {
  1339   check_android_display_info (terminal);
  1340 
  1341   return Qtrue_color;
  1342 }
  1343 
  1344 #ifndef ANDROID_STUBIFY
  1345 
  1346 static Lisp_Object
  1347 android_make_monitor_attribute_list (struct MonitorInfo *monitors,
  1348                                      int n_monitors,
  1349                                      int primary_monitor)
  1350 {
  1351   Lisp_Object monitor_frames;
  1352   Lisp_Object frame, rest;
  1353   struct frame *f;
  1354 
  1355   monitor_frames = make_nil_vector (n_monitors);
  1356 
  1357   FOR_EACH_FRAME (rest, frame)
  1358     {
  1359       f = XFRAME (frame);
  1360 
  1361       /* Associate all frames with the primary monitor.  */
  1362 
  1363       if (FRAME_WINDOW_P (f)
  1364           && !FRAME_TOOLTIP_P (f))
  1365         ASET (monitor_frames, primary_monitor,
  1366               Fcons (frame, AREF (monitor_frames,
  1367                                   primary_monitor)));
  1368     }
  1369 
  1370   return make_monitor_attribute_list (monitors, n_monitors,
  1371                                       primary_monitor,
  1372                                       monitor_frames, NULL);
  1373 }
  1374 
  1375 #endif
  1376 
  1377 DEFUN ("android-display-monitor-attributes-list",
  1378        Fandroid_display_monitor_attributes_list,
  1379        Sandroid_display_monitor_attributes_list,
  1380        0, 1, 0,
  1381        doc: /* Return a list of physical monitor attributes on the X display TERMINAL.
  1382 
  1383 The optional argument TERMINAL specifies which display to ask about.
  1384 TERMINAL should be a terminal object, a frame or a display name (a string).
  1385 If omitted or nil, that stands for the selected frame's display.
  1386 
  1387 Internal use only, use `display-monitor-attributes-list' instead.  */)
  1388   (Lisp_Object terminal)
  1389 {
  1390 #ifdef ANDROID_STUBIFY
  1391   error ("Android cross-compilation stub called!");
  1392   return Qnil;
  1393 #else
  1394   struct MonitorInfo monitor;
  1395 
  1396   memset (&monitor, 0, sizeof monitor);
  1397   monitor.geom.width = android_get_screen_width ();
  1398   monitor.geom.height = android_get_screen_height ();
  1399   monitor.mm_width = android_get_mm_width ();
  1400   monitor.mm_height = android_get_mm_height ();
  1401   monitor.work = monitor.geom;
  1402   monitor.name = (char *) "Android device monitor";
  1403 
  1404   return android_make_monitor_attribute_list (&monitor, 1, 0);
  1405 #endif
  1406 }
  1407 
  1408 #ifndef ANDROID_STUBIFY
  1409 
  1410 static Lisp_Object
  1411 frame_geometry (Lisp_Object frame, Lisp_Object attribute)
  1412 {
  1413   struct frame *f = decode_live_frame (frame);
  1414   android_window rootw;
  1415   unsigned int native_width, native_height, x_border_width = 0;
  1416   int x_native = 0, y_native = 0, xptr = 0, yptr = 0;
  1417   int left_off = 0, right_off = 0, top_off = 0, bottom_off = 0;
  1418   int outer_left, outer_top, outer_right, outer_bottom;
  1419   int native_left, native_top, native_right, native_bottom;
  1420   int inner_left, inner_top, inner_right, inner_bottom;
  1421   int internal_border_width;
  1422   bool menu_bar_external = false, tool_bar_external = false;
  1423   int menu_bar_height = 0, menu_bar_width = 0;
  1424   int tab_bar_height = 0, tab_bar_width = 0;
  1425   int tool_bar_height = 0, tool_bar_width = 0;
  1426 
  1427   if (FRAME_INITIAL_P (f) || !FRAME_ANDROID_P (f)
  1428       || !FRAME_ANDROID_WINDOW (f))
  1429     return Qnil;
  1430 
  1431   block_input ();
  1432   android_get_geometry (FRAME_ANDROID_WINDOW (f),
  1433                         &rootw, &x_native, &y_native,
  1434                         &native_width, &native_height, &x_border_width);
  1435   unblock_input ();
  1436 
  1437   if (FRAME_PARENT_FRAME (f))
  1438     {
  1439       Lisp_Object parent, edges;
  1440 
  1441       XSETFRAME (parent, FRAME_PARENT_FRAME (f));
  1442       edges = Fandroid_frame_edges (parent, Qnative_edges);
  1443       if (!NILP (edges))
  1444         {
  1445           x_native += XFIXNUM (Fnth (make_fixnum (0), edges));
  1446           y_native += XFIXNUM (Fnth (make_fixnum (1), edges));
  1447         }
  1448 
  1449       outer_left = x_native;
  1450       outer_top = y_native;
  1451       outer_right = outer_left + native_width + 2 * x_border_width;
  1452       outer_bottom = outer_top + native_height + 2 * x_border_width;
  1453 
  1454       native_left = x_native + x_border_width;
  1455       native_top = y_native + x_border_width;
  1456       native_right = native_left + native_width;
  1457       native_bottom = native_top + native_height;
  1458     }
  1459   else
  1460     {
  1461       outer_left = xptr;
  1462       outer_top = yptr;
  1463       outer_right = outer_left + left_off + native_width + right_off;
  1464       outer_bottom = outer_top + top_off + native_height + bottom_off;
  1465 
  1466       native_left = outer_left + left_off;
  1467       native_top = outer_top + top_off;
  1468       native_right = native_left + native_width;
  1469       native_bottom = native_top + native_height;
  1470     }
  1471 
  1472   internal_border_width = FRAME_INTERNAL_BORDER_WIDTH (f);
  1473   inner_left = native_left + internal_border_width;
  1474   inner_top = native_top + internal_border_width;
  1475   inner_right = native_right - internal_border_width;
  1476   inner_bottom = native_bottom - internal_border_width;
  1477 
  1478   menu_bar_height = FRAME_MENU_BAR_HEIGHT (f);
  1479   inner_top += menu_bar_height;
  1480   menu_bar_width = menu_bar_height ? native_width : 0;
  1481 
  1482   tab_bar_height = FRAME_TAB_BAR_HEIGHT (f);
  1483   tab_bar_width = (tab_bar_height
  1484                    ? native_width - 2 * internal_border_width
  1485                     : 0);
  1486   inner_top += tab_bar_height;
  1487 
  1488   tool_bar_height = FRAME_TOOL_BAR_HEIGHT (f);
  1489   tool_bar_width = (tool_bar_height
  1490                     ? native_width - 2 * internal_border_width
  1491                     : 0);
  1492 
  1493   /* Subtract or add to the inner dimensions based on the tool bar
  1494      position.  */
  1495 
  1496   if (EQ (FRAME_TOOL_BAR_POSITION (f), Qtop))
  1497     inner_top += tool_bar_height;
  1498   else
  1499     inner_bottom -= tool_bar_height;
  1500 
  1501   /* Construct list.  */
  1502   if (EQ (attribute, Qouter_edges))
  1503     return list4i (outer_left, outer_top, outer_right, outer_bottom);
  1504   else if (EQ (attribute, Qnative_edges))
  1505     return list4i (native_left, native_top, native_right, native_bottom);
  1506   else if (EQ (attribute, Qinner_edges))
  1507     return list4i (inner_left, inner_top, inner_right, inner_bottom);
  1508   else
  1509     return
  1510        list (Fcons (Qouter_position,
  1511                     Fcons (make_fixnum (outer_left),
  1512                            make_fixnum (outer_top))),
  1513              Fcons (Qouter_size,
  1514                     Fcons (make_fixnum (outer_right - outer_left),
  1515                            make_fixnum (outer_bottom - outer_top))),
  1516              /* Approximate.  */
  1517              Fcons (Qexternal_border_size,
  1518                     Fcons (make_fixnum (right_off),
  1519                            make_fixnum (bottom_off))),
  1520              Fcons (Qouter_border_width, make_fixnum (x_border_width)),
  1521              /* Approximate.  */
  1522              Fcons (Qtitle_bar_size,
  1523                     Fcons (make_fixnum (0),
  1524                            make_fixnum (top_off - bottom_off))),
  1525              Fcons (Qmenu_bar_external, menu_bar_external ? Qt : Qnil),
  1526              Fcons (Qmenu_bar_size,
  1527                     Fcons (make_fixnum (menu_bar_width),
  1528                            make_fixnum (menu_bar_height))),
  1529              Fcons (Qtab_bar_size,
  1530                     Fcons (make_fixnum (tab_bar_width),
  1531                            make_fixnum (tab_bar_height))),
  1532              Fcons (Qtool_bar_external, tool_bar_external ? Qt : Qnil),
  1533              Fcons (Qtool_bar_position, FRAME_TOOL_BAR_POSITION (f)),
  1534              Fcons (Qtool_bar_size,
  1535                     Fcons (make_fixnum (tool_bar_width),
  1536                            make_fixnum (tool_bar_height))),
  1537              Fcons (Qinternal_border_width,
  1538                     make_fixnum (internal_border_width)));
  1539 }
  1540 
  1541 #endif
  1542 
  1543 DEFUN ("android-frame-geometry", Fandroid_frame_geometry,
  1544        Sandroid_frame_geometry,
  1545        0, 1, 0,
  1546        doc: /* Return geometric attributes of FRAME.
  1547 FRAME must be a live frame and defaults to the selected one.  The return
  1548 value is an association list of the attributes listed below.  All height
  1549 and width values are in pixels.
  1550 
  1551 `outer-position' is a cons of the outer left and top edges of FRAME
  1552   relative to the origin - the position (0, 0) - of FRAME's display.
  1553 
  1554 `outer-size' is a cons of the outer width and height of FRAME.  The
  1555   outer size includes the title bar and the external borders as well as
  1556   any menu and/or tool bar of frame.
  1557 
  1558 `external-border-size' is a cons of the horizontal and vertical width of
  1559   FRAME's external borders as supplied by the window manager.
  1560 
  1561 `title-bar-size' is a cons of the width and height of the title bar of
  1562   FRAME as supplied by the window manager.  If both of them are zero,
  1563   FRAME has no title bar.  If only the width is zero, Emacs was not
  1564   able to retrieve the width information.
  1565 
  1566 `menu-bar-external', if non-nil, means the menu bar is external (never
  1567   included in the inner edges of FRAME).
  1568 
  1569 `menu-bar-size' is a cons of the width and height of the menu bar of
  1570   FRAME.
  1571 
  1572 `tool-bar-external', if non-nil, means the tool bar is external (never
  1573   included in the inner edges of FRAME).
  1574 
  1575 `tool-bar-position' tells on which side the tool bar on FRAME is and can
  1576   be one of `left', `top', `right' or `bottom'.  If this is nil, FRAME
  1577   has no tool bar.
  1578 
  1579 `tool-bar-size' is a cons of the width and height of the tool bar of
  1580   FRAME.
  1581 
  1582 `internal-border-width' is the width of the internal border of
  1583   FRAME.  */)
  1584   (Lisp_Object frame)
  1585 {
  1586 #ifdef ANDROID_STUBIFY
  1587   error ("Android cross-compilation stub called!");
  1588   return Qnil;
  1589 #else
  1590   return frame_geometry (frame, Qnil);
  1591 #endif
  1592 }
  1593 
  1594 DEFUN ("android-frame-edges", Fandroid_frame_edges, Sandroid_frame_edges, 0, 2, 0,
  1595        doc: /* Return edge coordinates of FRAME.
  1596 FRAME must be a live frame and defaults to the selected one.  The return
  1597 value is a list of the form (LEFT, TOP, RIGHT, BOTTOM).  All values are
  1598 in pixels relative to the origin - the position (0, 0) - of FRAME's
  1599 display.
  1600 
  1601 If optional argument TYPE is the symbol `outer-edges', return the outer
  1602 edges of FRAME.  The outer edges comprise the decorations of the window
  1603 manager (like the title bar or external borders) as well as any external
  1604 menu or tool bar of FRAME.  If optional argument TYPE is the symbol
  1605 `native-edges' or nil, return the native edges of FRAME.  The native
  1606 edges exclude the decorations of the window manager and any external
  1607 menu or tool bar of FRAME.  If TYPE is the symbol `inner-edges', return
  1608 the inner edges of FRAME.  These edges exclude title bar, any borders,
  1609 menu bar or tool bar of FRAME.  */)
  1610   (Lisp_Object frame, Lisp_Object type)
  1611 {
  1612 #ifndef ANDROID_STUBIFY
  1613   return frame_geometry (frame, ((EQ (type, Qouter_edges)
  1614                                   || EQ (type, Qinner_edges))
  1615                                  ? type
  1616                                  : Qnative_edges));
  1617 #else
  1618   return Qnil;
  1619 #endif
  1620 }
  1621 
  1622 #ifndef ANDROID_STUBIFY
  1623 
  1624 static Lisp_Object
  1625 android_frame_list_z_order (struct android_display_info *dpyinfo,
  1626                             android_window window)
  1627 {
  1628   android_window root, parent, *children;
  1629   unsigned int nchildren;
  1630   unsigned long i;
  1631   Lisp_Object frames;
  1632 
  1633   frames = Qnil;
  1634 
  1635   if (android_query_tree (window, &root, &parent,
  1636                           &children, &nchildren))
  1637     {
  1638       for (i = 0; i < nchildren; i++)
  1639         {
  1640           Lisp_Object frame, tail;
  1641 
  1642           FOR_EACH_FRAME (tail, frame)
  1643             {
  1644               struct frame *cf = XFRAME (frame);
  1645 
  1646               if (FRAME_ANDROID_P (cf)
  1647                   && (FRAME_ANDROID_WINDOW (cf) == children[i]))
  1648                 frames = Fcons (frame, frames);
  1649             }
  1650         }
  1651 
  1652       if (children)
  1653         xfree (children);
  1654     }
  1655 
  1656   return frames;
  1657 }
  1658 
  1659 #endif
  1660 
  1661 DEFUN ("android-frame-list-z-order", Fandroid_frame_list_z_order,
  1662        Sandroid_frame_list_z_order, 0, 1, 0,
  1663        doc: /* Return list of Emacs' frames, in Z (stacking) order.
  1664 The optional argument TERMINAL specifies which display to ask about.
  1665 TERMINAL should be either a frame or a display name (a string).  If
  1666 omitted or nil, that stands for the selected frame's display.  Return
  1667 nil if TERMINAL contains no Emacs frame.
  1668 
  1669 As a special case, if TERMINAL is non-nil and specifies a live frame,
  1670 return the child frames of that frame in Z (stacking) order.
  1671 
  1672 Frames are listed from topmost (first) to bottommost (last).
  1673 
  1674 On Android, the order of the frames returned is undefined unless
  1675 TERMINAL is a frame.  */)
  1676   (Lisp_Object terminal)
  1677 {
  1678 #ifdef ANDROID_STUBIFY
  1679   error ("Android cross-compilation stub called!");
  1680   return Qnil;
  1681 #else
  1682   struct android_display_info *dpyinfo;
  1683   android_window window;
  1684 
  1685   dpyinfo = check_android_display_info (terminal);
  1686 
  1687   if (FRAMEP (terminal) && FRAME_LIVE_P (XFRAME (terminal)))
  1688     window = FRAME_ANDROID_WINDOW (XFRAME (terminal));
  1689   else
  1690     window = dpyinfo->root_window;
  1691 
  1692   return android_frame_list_z_order (dpyinfo, window);
  1693 #endif
  1694 }
  1695 
  1696 DEFUN ("android-frame-restack", Fandroid_frame_restack,
  1697        Sandroid_frame_restack, 2, 3, 0,
  1698        doc: /* Restack FRAME1 below FRAME2.
  1699 This means that if both frames are visible and the display areas of
  1700 these frames overlap, FRAME2 (partially) obscures FRAME1.  If optional
  1701 third argument ABOVE is non-nil, restack FRAME1 above FRAME2.  This
  1702 means that if both frames are visible and the display areas of these
  1703 frames overlap, FRAME1 (partially) obscures FRAME2.
  1704 
  1705 This may be thought of as an atomic action performed in two steps: The
  1706 first step removes FRAME1's window-step window from the display.  The
  1707 second step reinserts FRAME1's window below (above if ABOVE is true)
  1708 that of FRAME2.  Hence the position of FRAME2 in its display's Z
  1709 \(stacking) order relative to all other frames excluding FRAME1 remains
  1710 unaltered.
  1711 
  1712 The Android system refuses to restack windows, so this does not
  1713 work.  */)
  1714   (Lisp_Object frame1, Lisp_Object frame2, Lisp_Object frame3)
  1715 {
  1716 #ifdef ANDROID_STUBIFY
  1717   error ("Android cross-compilation stub called!");
  1718   return Qnil;
  1719 #else
  1720   /* This is not supported on Android because of limitations in the
  1721      platform that prevent ViewGroups from restacking
  1722      SurfaceViews.  */
  1723   return Qnil;
  1724 #endif
  1725 }
  1726 
  1727 DEFUN ("android-mouse-absolute-pixel-position",
  1728        Fandroid_mouse_absolute_pixel_position,
  1729        Sandroid_mouse_absolute_pixel_position, 0, 0, 0,
  1730        doc: /* Return absolute position of mouse cursor in pixels.
  1731 The position is returned as a cons cell (X . Y) of the coordinates of
  1732 the mouse cursor position in pixels relative to a position (0, 0) of the
  1733 selected frame's display.  This does not work on Android.  */)
  1734   (void)
  1735 {
  1736   /* This cannot be implemented on Android.  */
  1737   return Qnil;
  1738 }
  1739 
  1740 DEFUN ("android-set-mouse-absolute-pixel-position",
  1741        Fandroid_set_mouse_absolute_pixel_position,
  1742        Sandroid_set_mouse_absolute_pixel_position, 2, 2, 0,
  1743        doc: /* Move mouse pointer to a pixel position at (X, Y).  The
  1744 coordinates X and Y are interpreted to start from the top-left corner
  1745 of the screen.  This does not work on Android.  */)
  1746   (Lisp_Object x, Lisp_Object y)
  1747 {
  1748   /* This cannot be implemented on Android.  */
  1749   return Qnil;
  1750 }
  1751 
  1752 DEFUN ("android-get-connection", Fandroid_get_connection,
  1753        Sandroid_get_connection, 0, 0, 0,
  1754        doc: /* Get the connection to the display server.
  1755 Return the terminal if it exists, else nil.
  1756 
  1757 Emacs cannot open a connection to the display server itself under
  1758 Android, so there is no equivalent of `x-open-connection'.  */)
  1759   (void)
  1760 {
  1761 #ifdef ANDROID_STUBIFY
  1762   error ("Android cross-compilation stub called!");
  1763   return Qnil;
  1764 #else
  1765   Lisp_Object terminal;
  1766 
  1767   terminal = Qnil;
  1768 
  1769   if (x_display_list)
  1770     XSETTERMINAL (terminal, x_display_list->terminal);
  1771 
  1772   return terminal;
  1773 #endif
  1774 }
  1775 
  1776 DEFUN ("x-display-list", Fx_display_list, Sx_display_list, 0, 0, 0,
  1777        doc: /* SKIP: real doc in xfns.c.  */)
  1778   (void)
  1779 {
  1780   Lisp_Object result;
  1781 
  1782   result = Qnil;
  1783 
  1784   if (x_display_list)
  1785     result = Fcons (XCAR (x_display_list->name_list_element),
  1786                     result);
  1787 
  1788   return result;
  1789 }
  1790 
  1791 #ifndef ANDROID_STUBIFY
  1792 
  1793 static void
  1794 unwind_create_tip_frame (Lisp_Object frame)
  1795 {
  1796   Lisp_Object deleted;
  1797 
  1798   deleted = unwind_create_frame (frame);
  1799   if (EQ (deleted, Qt))
  1800     {
  1801       tip_window = ANDROID_NONE;
  1802       tip_frame = Qnil;
  1803     }
  1804 }
  1805 
  1806 static Lisp_Object
  1807 android_create_tip_frame (struct android_display_info *dpyinfo,
  1808                           Lisp_Object parms)
  1809 {
  1810   struct frame *f;
  1811   Lisp_Object frame;
  1812   Lisp_Object name;
  1813   specpdl_ref count = SPECPDL_INDEX ();
  1814   bool face_change_before = face_change;
  1815 
  1816   if (!dpyinfo->terminal->name)
  1817     error ("Terminal is not live, can't create new frames on it");
  1818 
  1819   parms = Fcopy_alist (parms);
  1820 
  1821   /* Get the name of the frame to use for resource lookup.  */
  1822   name = gui_display_get_arg (dpyinfo, parms, Qname, "name", "Name",
  1823                               RES_TYPE_STRING);
  1824   if (!STRINGP (name)
  1825       && !BASE_EQ (name, Qunbound)
  1826       && !NILP (name))
  1827     error ("Invalid frame name--not a string or nil");
  1828 
  1829   frame = Qnil;
  1830   f = make_frame (false);
  1831   f->wants_modeline = false;
  1832   XSETFRAME (frame, f);
  1833   record_unwind_protect (unwind_create_tip_frame, frame);
  1834 
  1835   f->terminal = dpyinfo->terminal;
  1836 
  1837   /* By setting the output method, we're essentially saying that
  1838      the frame is live, as per FRAME_LIVE_P.  If we get a signal
  1839      from this point on, x_destroy_window might screw up reference
  1840      counts etc.  */
  1841   f->output_method = output_android;
  1842   f->output_data.android = xzalloc (sizeof *f->output_data.android);
  1843   FRAME_FONTSET (f) = -1;
  1844   f->output_data.android->white_relief.pixel = -1;
  1845   f->output_data.android->black_relief.pixel = -1;
  1846 
  1847   f->tooltip = true;
  1848   fset_icon_name (f, Qnil);
  1849   FRAME_DISPLAY_INFO (f) = dpyinfo;
  1850   f->output_data.android->parent_desc = FRAME_DISPLAY_INFO (f)->root_window;
  1851 
  1852   /* These colors will be set anyway later, but it's important
  1853      to get the color reference counts right, so initialize them!  */
  1854   {
  1855     Lisp_Object black;
  1856 
  1857     /* Function android_decode_color can signal an error.  Make sure
  1858        to initialize color slots so that we won't try to free colors
  1859        we haven't allocated.  */
  1860     FRAME_FOREGROUND_PIXEL (f) = -1;
  1861     FRAME_BACKGROUND_PIXEL (f) = -1;
  1862     f->output_data.android->cursor_pixel = -1;
  1863     f->output_data.android->cursor_foreground_pixel = -1;
  1864     f->output_data.android->mouse_pixel = -1;
  1865 
  1866     black = build_string ("black");
  1867     FRAME_FOREGROUND_PIXEL (f)
  1868       = android_decode_color (f, black, BLACK_PIX_DEFAULT (f));
  1869     FRAME_BACKGROUND_PIXEL (f)
  1870       = android_decode_color (f, black, BLACK_PIX_DEFAULT (f));
  1871     f->output_data.android->cursor_pixel
  1872       = android_decode_color (f, black, BLACK_PIX_DEFAULT (f));
  1873     f->output_data.android->cursor_foreground_pixel
  1874       = android_decode_color (f, black, BLACK_PIX_DEFAULT (f));
  1875     f->output_data.android->mouse_pixel
  1876       = android_decode_color (f, black, BLACK_PIX_DEFAULT (f));
  1877   }
  1878 
  1879   /* Set the name; the functions to which we pass f expect the name to
  1880      be set.  */
  1881   if (BASE_EQ (name, Qunbound) || NILP (name))
  1882     f->explicit_name = false;
  1883   else
  1884     {
  1885       fset_name (f, name);
  1886       f->explicit_name = true;
  1887       /* use the frame's title when getting resources for this frame.  */
  1888       specbind (Qx_resource_name, name);
  1889     }
  1890 
  1891   register_font_driver (&androidfont_driver, f);
  1892   register_font_driver (&android_sfntfont_driver, f);
  1893 
  1894   image_cache_refcount
  1895     = FRAME_IMAGE_CACHE (f) ? FRAME_IMAGE_CACHE (f)->refcount : 0;
  1896 #ifdef GLYPH_DEBUG
  1897   dpyinfo_refcount = dpyinfo->reference_count;
  1898 #endif /* GLYPH_DEBUG */
  1899 
  1900   gui_default_parameter (f, parms, Qfont_backend, Qnil,
  1901                          "fontBackend", "FontBackend", RES_TYPE_STRING);
  1902 
  1903   /* Extract the window parameters from the supplied values that are
  1904      needed to determine window geometry.  */
  1905   android_default_font_parameter (f, parms);
  1906 
  1907   gui_default_parameter (f, parms, Qborder_width, make_fixnum (0),
  1908                          "borderWidth", "BorderWidth", RES_TYPE_NUMBER);
  1909 
  1910   /* This defaults to 1 in order to match xterm.  We recognize either
  1911      internalBorderWidth or internalBorder (which is what xterm calls
  1912      it).  */
  1913   if (NILP (Fassq (Qinternal_border_width, parms)))
  1914     {
  1915       Lisp_Object value;
  1916 
  1917       value = gui_display_get_arg (dpyinfo, parms, Qinternal_border_width,
  1918                                    "internalBorder", "internalBorder",
  1919                                    RES_TYPE_NUMBER);
  1920       if (! BASE_EQ (value, Qunbound))
  1921         parms = Fcons (Fcons (Qinternal_border_width, value),
  1922                        parms);
  1923     }
  1924 
  1925   gui_default_parameter (f, parms, Qinternal_border_width, make_fixnum (1),
  1926                          "internalBorderWidth", "internalBorderWidth",
  1927                          RES_TYPE_NUMBER);
  1928   gui_default_parameter (f, parms, Qright_divider_width, make_fixnum (0),
  1929                          NULL, NULL, RES_TYPE_NUMBER);
  1930   gui_default_parameter (f, parms, Qbottom_divider_width, make_fixnum (0),
  1931                          NULL, NULL, RES_TYPE_NUMBER);
  1932 
  1933   /* Also do the stuff which must be set before the window exists.  */
  1934   gui_default_parameter (f, parms, Qforeground_color, build_string ("black"),
  1935                          "foreground", "Foreground", RES_TYPE_STRING);
  1936   gui_default_parameter (f, parms, Qbackground_color, build_string ("white"),
  1937                          "background", "Background", RES_TYPE_STRING);
  1938   gui_default_parameter (f, parms, Qmouse_color, build_string ("black"),
  1939                          "pointerColor", "Foreground", RES_TYPE_STRING);
  1940   gui_default_parameter (f, parms, Qcursor_color, build_string ("black"),
  1941                          "cursorColor", "Foreground", RES_TYPE_STRING);
  1942   gui_default_parameter (f, parms, Qborder_color, build_string ("black"),
  1943                          "borderColor", "BorderColor", RES_TYPE_STRING);
  1944   gui_default_parameter (f, parms, Qno_special_glyphs, Qnil,
  1945                          NULL, NULL, RES_TYPE_BOOLEAN);
  1946 
  1947   {
  1948     struct android_set_window_attributes attrs;
  1949     unsigned long mask;
  1950 
  1951     block_input ();
  1952     mask = ANDROID_CW_OVERRIDE_REDIRECT | ANDROID_CW_BACK_PIXEL;
  1953 
  1954     attrs.override_redirect = true;
  1955     attrs.background_pixel = FRAME_BACKGROUND_PIXEL (f);
  1956     tip_window
  1957       = FRAME_ANDROID_WINDOW (f)
  1958       = android_create_window (FRAME_DISPLAY_INFO (f)->root_window,
  1959                                /* x, y, width, height, value-mask,
  1960                                   attrs.  */
  1961                                0, 0, 1, 1, mask, &attrs);
  1962     unblock_input ();
  1963   }
  1964 
  1965   /* Init faces before gui_default_parameter is called for the
  1966      scroll-bar-width parameter because otherwise we end up in
  1967      init_iterator with a null face cache, which should not happen.  */
  1968   init_frame_faces (f);
  1969 
  1970   gui_default_parameter (f, parms, Qinhibit_double_buffering, Qnil,
  1971                          "inhibitDoubleBuffering", "InhibitDoubleBuffering",
  1972                          RES_TYPE_BOOLEAN);
  1973 
  1974   gui_figure_window_size (f, parms, false, false);
  1975 
  1976   f->output_data.android->parent_desc = FRAME_DISPLAY_INFO (f)->root_window;
  1977 
  1978   android_make_gc (f);
  1979 
  1980   gui_default_parameter (f, parms, Qauto_raise, Qnil,
  1981                          "autoRaise", "AutoRaiseLower", RES_TYPE_BOOLEAN);
  1982   gui_default_parameter (f, parms, Qauto_lower, Qnil,
  1983                          "autoLower", "AutoRaiseLower", RES_TYPE_BOOLEAN);
  1984   gui_default_parameter (f, parms, Qcursor_type, Qbox,
  1985                          "cursorType", "CursorType", RES_TYPE_SYMBOL);
  1986   gui_default_parameter (f, parms, Qalpha, Qnil,
  1987                          "alpha", "Alpha", RES_TYPE_NUMBER);
  1988   gui_default_parameter (f, parms, Qalpha_background, Qnil,
  1989                          "alphaBackground", "AlphaBackground", RES_TYPE_NUMBER);
  1990 
  1991   /* Add `tooltip' frame parameter's default value. */
  1992   if (NILP (Fframe_parameter (frame, Qtooltip)))
  1993     {
  1994       AUTO_FRAME_ARG (arg, Qtooltip, Qt);
  1995       Fmodify_frame_parameters (frame, arg);
  1996     }
  1997 
  1998   /* FIXME - can this be done in a similar way to normal frames?
  1999      https://lists.gnu.org/r/emacs-devel/2007-10/msg00641.html */
  2000 
  2001   /* Set the `display-type' frame parameter before setting up faces. */
  2002   {
  2003     Lisp_Object disptype;
  2004 
  2005     disptype = Qcolor;
  2006 
  2007     if (NILP (Fframe_parameter (frame, Qdisplay_type)))
  2008       {
  2009         AUTO_FRAME_ARG (arg, Qdisplay_type, disptype);
  2010         Fmodify_frame_parameters (frame, arg);
  2011       }
  2012   }
  2013 
  2014   /* Set up faces after all frame parameters are known.  This call
  2015      also merges in face attributes specified for new frames.  */
  2016   {
  2017     Lisp_Object bg = Fframe_parameter (frame, Qbackground_color);
  2018 
  2019     call2 (Qface_set_after_frame_default, frame, Qnil);
  2020 
  2021     if (!EQ (bg, Fframe_parameter (frame, Qbackground_color)))
  2022       {
  2023         AUTO_FRAME_ARG (arg, Qbackground_color, bg);
  2024         Fmodify_frame_parameters (frame, arg);
  2025       }
  2026   }
  2027 
  2028   f->no_split = true;
  2029 
  2030   /* Now that the frame will be official, it counts as a reference to
  2031      its display and terminal.  */
  2032   f->terminal->reference_count++;
  2033 
  2034   /* It is now ok to make the frame official even if we get an error
  2035      below.  And the frame needs to be on Vframe_list or making it
  2036      visible won't work.  */
  2037   Vframe_list = Fcons (frame, Vframe_list);
  2038   f->can_set_window_size = true;
  2039   adjust_frame_size (f, FRAME_TEXT_WIDTH (f), FRAME_TEXT_HEIGHT (f),
  2040                      0, true, Qtip_frame);
  2041 
  2042   /* Setting attributes of faces of the tooltip frame from resources
  2043      and similar will set face_change, which leads to the clearing of
  2044      all current matrices.  Since this isn't necessary here, avoid it
  2045      by resetting face_change to the value it had before we created
  2046      the tip frame.  */
  2047   face_change = face_change_before;
  2048 
  2049   /* Discard the unwind_protect.  */
  2050   return unbind_to (count, frame);
  2051 }
  2052 
  2053 static Lisp_Object
  2054 android_hide_tip (bool delete)
  2055 {
  2056   if (!NILP (tip_timer))
  2057     {
  2058       call1 (Qcancel_timer, tip_timer);
  2059       tip_timer = Qnil;
  2060     }
  2061 
  2062   if (NILP (tip_frame)
  2063       || (!delete
  2064           && !NILP (tip_frame)
  2065           && FRAME_LIVE_P (XFRAME (tip_frame))
  2066           && !FRAME_VISIBLE_P (XFRAME (tip_frame))))
  2067     return Qnil;
  2068   else
  2069     {
  2070       Lisp_Object was_open = Qnil;
  2071 
  2072       specpdl_ref count = SPECPDL_INDEX ();
  2073       specbind (Qinhibit_redisplay, Qt);
  2074       specbind (Qinhibit_quit, Qt);
  2075 
  2076       if (!NILP (tip_frame))
  2077         {
  2078           struct frame *f = XFRAME (tip_frame);
  2079 
  2080           if (FRAME_LIVE_P (f))
  2081             {
  2082               if (delete)
  2083                 {
  2084                   delete_frame (tip_frame, Qnil);
  2085                   tip_frame = Qnil;
  2086                 }
  2087               else
  2088                 android_make_frame_invisible (XFRAME (tip_frame));
  2089 
  2090               was_open = Qt;
  2091             }
  2092           else
  2093             tip_frame = Qnil;
  2094         }
  2095       else
  2096         tip_frame = Qnil;
  2097 
  2098       return unbind_to (count, was_open);
  2099     }
  2100 }
  2101 
  2102 static void
  2103 compute_tip_xy (struct frame *f, Lisp_Object parms, Lisp_Object dx,
  2104                 Lisp_Object dy, int width, int height, int *root_x,
  2105                 int *root_y)
  2106 {
  2107   Lisp_Object left, top, right, bottom;
  2108   int min_x, min_y, max_x, max_y = -1;
  2109   android_window window;
  2110   struct frame *mouse_frame;
  2111 
  2112   /* Initialize these values in case there is no mouse frame.  */
  2113   *root_x = 0;
  2114   *root_y = 0;
  2115 
  2116   /* User-specified position?  */
  2117   left = CDR (Fassq (Qleft, parms));
  2118   top  = CDR (Fassq (Qtop, parms));
  2119   right = CDR (Fassq (Qright, parms));
  2120   bottom = CDR (Fassq (Qbottom, parms));
  2121 
  2122   /* Move the tooltip window where the mouse pointer was last seen.
  2123      Resize and show it.  */
  2124   if ((!FIXNUMP (left) && !FIXNUMP (right))
  2125       || (!FIXNUMP (top) && !FIXNUMP (bottom)))
  2126     {
  2127       if (x_display_list->last_mouse_motion_frame)
  2128         {
  2129           *root_x = x_display_list->last_mouse_motion_x;
  2130           *root_y = x_display_list->last_mouse_motion_y;
  2131           mouse_frame = x_display_list->last_mouse_motion_frame;
  2132           window = FRAME_ANDROID_WINDOW (mouse_frame);
  2133 
  2134           /* Translate the coordinates to the screen.  */
  2135           android_translate_coordinates (window, *root_x, *root_y,
  2136                                          root_x, root_y);
  2137         }
  2138     }
  2139 
  2140   min_x = 0;
  2141   min_y = 0;
  2142   max_x = android_get_screen_width ();
  2143   max_y = android_get_screen_height ();
  2144 
  2145   if (FIXNUMP (top))
  2146     *root_y = XFIXNUM (top);
  2147   else if (FIXNUMP (bottom))
  2148     *root_y = XFIXNUM (bottom) - height;
  2149   else if (*root_y + XFIXNUM (dy) <= min_y)
  2150     *root_y = min_y; /* Can happen for negative dy */
  2151   else if (*root_y + XFIXNUM (dy) + height <= max_y)
  2152     /* It fits below the pointer */
  2153     *root_y += XFIXNUM (dy);
  2154   else if (height + XFIXNUM (dy) + min_y <= *root_y)
  2155     /* It fits above the pointer.  */
  2156     *root_y -= height + XFIXNUM (dy);
  2157   else
  2158     /* Put it on the top.  */
  2159     *root_y = min_y;
  2160 
  2161   if (FIXNUMP (left))
  2162     *root_x = XFIXNUM (left);
  2163   else if (FIXNUMP (right))
  2164     *root_x = XFIXNUM (right) - width;
  2165   else if (*root_x + XFIXNUM (dx) <= min_x)
  2166     *root_x = 0; /* Can happen for negative dx */
  2167   else if (*root_x + XFIXNUM (dx) + width <= max_x)
  2168     /* It fits to the right of the pointer.  */
  2169     *root_x += XFIXNUM (dx);
  2170   else if (width + XFIXNUM (dx) + min_x <= *root_x)
  2171     /* It fits to the left of the pointer.  */
  2172     *root_x -= width + XFIXNUM (dx);
  2173   else
  2174     /* Put it left justified on the screen -- it ought to fit that way.  */
  2175     *root_x = min_x;
  2176 }
  2177 
  2178 #endif
  2179 
  2180 DEFUN ("x-show-tip", Fx_show_tip, Sx_show_tip, 1, 6, 0,
  2181        doc: /* SKIP: real doc in xfns.c.  */)
  2182   (Lisp_Object string, Lisp_Object frame, Lisp_Object parms,
  2183    Lisp_Object timeout, Lisp_Object dx, Lisp_Object dy)
  2184 {
  2185 #ifdef ANDROID_STUBIFY
  2186   error ("Android cross-compilation stub called!");
  2187   return Qnil;
  2188 #else
  2189   struct frame *f, *tip_f;
  2190   struct window *w;
  2191   int root_x, root_y;
  2192   struct buffer *old_buffer;
  2193   struct text_pos pos;
  2194   int width, height;
  2195   int old_windows_or_buffers_changed = windows_or_buffers_changed;
  2196   specpdl_ref count = SPECPDL_INDEX ();
  2197   Lisp_Object window, size, tip_buf;
  2198   bool displayed;
  2199 #ifdef ENABLE_CHECKING
  2200   struct glyph_row *row, *end;
  2201 #endif
  2202   AUTO_STRING (tip, " *tip*");
  2203 
  2204   specbind (Qinhibit_redisplay, Qt);
  2205 
  2206   CHECK_STRING (string);
  2207   if (SCHARS (string) == 0)
  2208     string = make_unibyte_string (" ", 1);
  2209 
  2210   if (NILP (frame))
  2211     frame = selected_frame;
  2212   f = decode_window_system_frame (frame);
  2213 
  2214   if (NILP (timeout))
  2215     timeout = Vx_show_tooltip_timeout;
  2216   CHECK_FIXNAT (timeout);
  2217 
  2218   if (NILP (dx))
  2219     dx = make_fixnum (5);
  2220   else
  2221     CHECK_FIXNUM (dx);
  2222 
  2223   if (NILP (dy))
  2224     dy = make_fixnum (-10);
  2225   else
  2226     CHECK_FIXNUM (dy);
  2227 
  2228   tip_dx = dx;
  2229   tip_dy = dy;
  2230 
  2231   if (!NILP (tip_frame) && FRAME_LIVE_P (XFRAME (tip_frame)))
  2232     {
  2233       if (FRAME_VISIBLE_P (XFRAME (tip_frame))
  2234           && !NILP (Fequal_including_properties (tip_last_string,
  2235                                                  string))
  2236           && !NILP (Fequal (tip_last_parms, parms)))
  2237         {
  2238           /* Only DX and DY have changed.  */
  2239           tip_f = XFRAME (tip_frame);
  2240           if (!NILP (tip_timer))
  2241             {
  2242               call1 (Qcancel_timer, tip_timer);
  2243               tip_timer = Qnil;
  2244             }
  2245 
  2246           block_input ();
  2247           compute_tip_xy (tip_f, parms, dx, dy, FRAME_PIXEL_WIDTH (tip_f),
  2248                           FRAME_PIXEL_HEIGHT (tip_f), &root_x, &root_y);
  2249           android_move_window (FRAME_ANDROID_WINDOW (tip_f),
  2250                                root_x, root_y);
  2251           unblock_input ();
  2252 
  2253           goto start_timer;
  2254         }
  2255       else
  2256         android_hide_tip (true);
  2257     }
  2258   else
  2259     android_hide_tip (true);
  2260 
  2261   tip_last_frame = frame;
  2262   tip_last_string = string;
  2263   tip_last_parms = parms;
  2264 
  2265   if (NILP (tip_frame) || !FRAME_LIVE_P (XFRAME (tip_frame)))
  2266     {
  2267       /* Add default values to frame parameters.  */
  2268       if (NILP (Fassq (Qname, parms)))
  2269         parms = Fcons (Fcons (Qname, build_string ("tooltip")), parms);
  2270       if (NILP (Fassq (Qinternal_border_width, parms)))
  2271         parms = Fcons (Fcons (Qinternal_border_width, make_fixnum (3)),
  2272                        parms);
  2273       if (NILP (Fassq (Qborder_width, parms)))
  2274         parms = Fcons (Fcons (Qborder_width, make_fixnum (1)), parms);
  2275       if (NILP (Fassq (Qborder_color, parms)))
  2276         parms = Fcons (Fcons (Qborder_color, build_string ("lightyellow")),
  2277                        parms);
  2278       if (NILP (Fassq (Qbackground_color, parms)))
  2279         parms = Fcons (Fcons (Qbackground_color,
  2280                               build_string ("lightyellow")),
  2281                        parms);
  2282 
  2283       /* Create a frame for the tooltip, and record it in the global
  2284          variable tip_frame.  */
  2285       if (NILP (tip_frame = android_create_tip_frame (FRAME_DISPLAY_INFO (f),
  2286                                                       parms)))
  2287         /* Creating the tip frame failed.  */
  2288         return unbind_to (count, Qnil);
  2289     }
  2290 
  2291   tip_f = XFRAME (tip_frame);
  2292   window = FRAME_ROOT_WINDOW (tip_f);
  2293   tip_buf = Fget_buffer_create (tip, Qnil);
  2294   /* We will mark the tip window a "pseudo-window" below, and such
  2295      windows cannot have display margins.  */
  2296   bset_left_margin_cols (XBUFFER (tip_buf), make_fixnum (0));
  2297   bset_right_margin_cols (XBUFFER (tip_buf), make_fixnum (0));
  2298   set_window_buffer (window, tip_buf, false, false);
  2299   w = XWINDOW (window);
  2300   w->pseudo_window_p = true;
  2301   /* Try to avoid that `other-window' select us (Bug#47207).  */
  2302   Fset_window_parameter (window, Qno_other_window, Qt);
  2303 
  2304   /* Set up the frame's root window.  Note: The following code does not
  2305      try to size the window or its frame correctly.  Its only purpose is
  2306      to make the subsequent text size calculations work.  The right
  2307      sizes should get installed when the toolkit gets back to us.  */
  2308   w->left_col = 0;
  2309   w->top_line = 0;
  2310   w->pixel_left = 0;
  2311   w->pixel_top = 0;
  2312 
  2313   if (CONSP (Vx_max_tooltip_size)
  2314       && RANGED_FIXNUMP (1, XCAR (Vx_max_tooltip_size), INT_MAX)
  2315       && RANGED_FIXNUMP (1, XCDR (Vx_max_tooltip_size), INT_MAX))
  2316     {
  2317       w->total_cols = XFIXNAT (XCAR (Vx_max_tooltip_size));
  2318       w->total_lines = XFIXNAT (XCDR (Vx_max_tooltip_size));
  2319     }
  2320   else
  2321     {
  2322       w->total_cols = 80;
  2323       w->total_lines = 40;
  2324     }
  2325 
  2326   w->pixel_width = w->total_cols * FRAME_COLUMN_WIDTH (tip_f);
  2327   w->pixel_height = w->total_lines * FRAME_LINE_HEIGHT (tip_f);
  2328   FRAME_TOTAL_COLS (tip_f) = w->total_cols;
  2329   adjust_frame_glyphs (tip_f);
  2330 
  2331   /* Insert STRING into root window's buffer and fit the frame to the
  2332      buffer.  */
  2333   specpdl_ref count_1 = SPECPDL_INDEX ();
  2334   old_buffer = current_buffer;
  2335   set_buffer_internal_1 (XBUFFER (w->contents));
  2336   bset_truncate_lines (current_buffer, Qnil);
  2337   specbind (Qinhibit_read_only, Qt);
  2338   specbind (Qinhibit_modification_hooks, Qt);
  2339   specbind (Qinhibit_point_motion_hooks, Qt);
  2340   Ferase_buffer ();
  2341   Finsert (1, &string);
  2342   clear_glyph_matrix (w->desired_matrix);
  2343   clear_glyph_matrix (w->current_matrix);
  2344   SET_TEXT_POS (pos, BEGV, BEGV_BYTE);
  2345   displayed = try_window (window, pos, TRY_WINDOW_IGNORE_FONTS_CHANGE);
  2346 
  2347   if (!displayed && NILP (Vx_max_tooltip_size))
  2348     {
  2349 #ifdef ENABLE_CHECKING
  2350       row = w->desired_matrix->rows;
  2351       end = w->desired_matrix->rows + w->desired_matrix->nrows;
  2352 
  2353       while (row < end)
  2354         {
  2355           if (!row->displays_text_p
  2356               || row->ends_at_zv_p)
  2357             break;
  2358           ++row;
  2359         }
  2360 
  2361       eassert (row < end && row->ends_at_zv_p);
  2362 #endif
  2363     }
  2364 
  2365   /* Calculate size of tooltip window.  */
  2366   size = Fwindow_text_pixel_size (window, Qnil, Qnil, Qnil,
  2367                                   make_fixnum (w->pixel_height), Qnil,
  2368                                   Qnil);
  2369   /* Add the frame's internal border to calculated size.  */
  2370   width = XFIXNUM (CAR (size)) + 2 * FRAME_INTERNAL_BORDER_WIDTH (tip_f);
  2371   height = XFIXNUM (CDR (size)) + 2 * FRAME_INTERNAL_BORDER_WIDTH (tip_f);
  2372 
  2373   /* Calculate position of tooltip frame.  */
  2374   compute_tip_xy (tip_f, parms, dx, dy, width, height, &root_x, &root_y);
  2375 
  2376   /* Show tooltip frame.  */
  2377   block_input ();
  2378   android_move_resize_window (FRAME_ANDROID_WINDOW (tip_f),
  2379                               root_x, root_y, width,
  2380                               height);
  2381   android_map_raised (FRAME_ANDROID_WINDOW (tip_f));
  2382   unblock_input ();
  2383 
  2384   /* Garbage the tip frame too.  */
  2385   SET_FRAME_GARBAGED (tip_f);
  2386 
  2387   w->must_be_updated_p = true;
  2388   update_single_window (w);
  2389   flush_frame (tip_f);
  2390   set_buffer_internal_1 (old_buffer);
  2391   unbind_to (count_1, Qnil);
  2392   windows_or_buffers_changed = old_windows_or_buffers_changed;
  2393 
  2394   /* MapNotify events are not sent on Android, so make the frame
  2395      visible.  */
  2396 
  2397   SET_FRAME_VISIBLE (tip_f, true);
  2398 
  2399  start_timer:
  2400   /* Let the tip disappear after timeout seconds.  */
  2401   tip_timer = call3 (Qrun_at_time, timeout, Qnil,
  2402                      Qx_hide_tip);
  2403 
  2404   return unbind_to (count, Qnil);
  2405 #endif
  2406 }
  2407 
  2408 DEFUN ("x-hide-tip", Fx_hide_tip, Sx_hide_tip, 0, 0, 0,
  2409        doc: /* SKIP: real doc in xfns.c.  */)
  2410   (void)
  2411 {
  2412 #ifdef ANDROID_STUBIFY
  2413   error ("Android cross-compilation stub called!");
  2414   return Qnil;
  2415 #else
  2416   return android_hide_tip (true);
  2417 #endif
  2418 }
  2419 
  2420 DEFUN ("android-detect-mouse", Fandroid_detect_mouse,
  2421        Sandroid_detect_mouse, 0, 0, 0,
  2422        doc: /* Figure out whether or not there is a mouse.
  2423 Return non-nil if a mouse is connected to this computer, and nil if
  2424 there is no mouse.  */)
  2425   (void)
  2426 {
  2427 #ifndef ANDROID_STUBIFY
  2428   /* If no display connection is present, just return nil.  */
  2429 
  2430   if (!android_init_gui)
  2431     return Qnil;
  2432 
  2433   return android_detect_mouse () ? Qt : Qnil;
  2434 #else
  2435   return Qnil;
  2436 #endif
  2437 }
  2438 
  2439 DEFUN ("android-toggle-on-screen-keyboard",
  2440        Fandroid_toggle_on_screen_keyboard,
  2441        Sandroid_toggle_on_screen_keyboard, 2, 2, 0,
  2442        doc: /* Display or hide the on-screen keyboard.
  2443 If HIDE is non-nil, hide the on screen keyboard if it is currently
  2444 being displayed.  Else, request that the system display it on behalf
  2445 of FRAME.  This request may be rejected if FRAME does not have the
  2446 input focus.  */)
  2447   (Lisp_Object frame, Lisp_Object hide)
  2448 {
  2449 #ifndef ANDROID_STUBIFY
  2450   struct frame *f;
  2451 
  2452   f = decode_window_system_frame (frame);
  2453 
  2454   block_input ();
  2455   android_toggle_on_screen_keyboard (FRAME_ANDROID_WINDOW (f),
  2456                                      NILP (hide));
  2457   unblock_input ();
  2458 #endif
  2459 
  2460   return Qnil;
  2461 }
  2462 
  2463 
  2464 
  2465 #ifndef ANDROID_STUBIFY
  2466 
  2467 static void
  2468 android_set_background_color (struct frame *f, Lisp_Object arg,
  2469                               Lisp_Object oldval)
  2470 {
  2471   struct android_output *x;
  2472   unsigned long bg;
  2473 
  2474   x = f->output_data.android;
  2475   bg = android_decode_color (f, arg, WHITE_PIX_DEFAULT (f));
  2476   FRAME_BACKGROUND_PIXEL (f) = bg;
  2477 
  2478   if (FRAME_ANDROID_WINDOW (f) != 0)
  2479     {
  2480       block_input ();
  2481       android_set_background (x->normal_gc, bg);
  2482       android_set_foreground (x->reverse_gc, bg);
  2483       android_set_window_background (FRAME_ANDROID_WINDOW (f), bg);
  2484       android_set_foreground (x->cursor_gc, bg);
  2485       unblock_input ();
  2486 
  2487       update_face_from_frame_parameter (f, Qbackground_color, arg);
  2488 
  2489       if (FRAME_VISIBLE_P (f))
  2490         redraw_frame (f);
  2491     }
  2492 }
  2493 
  2494 static void
  2495 android_set_border_color (struct frame *f, Lisp_Object arg,
  2496                           Lisp_Object oldval)
  2497 {
  2498   /* Left unimplemented because Android has no window borders.  */
  2499   CHECK_STRING (arg);
  2500   android_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
  2501   update_face_from_frame_parameter (f, Qborder_color, arg);
  2502 }
  2503 
  2504 static void
  2505 android_set_cursor_color (struct frame *f, Lisp_Object arg,
  2506                           Lisp_Object oldval)
  2507 {
  2508   unsigned long fore_pixel, pixel;
  2509   struct android_output *x;
  2510 
  2511   x = f->output_data.android;
  2512 
  2513   if (!NILP (Vx_cursor_fore_pixel))
  2514     fore_pixel = android_decode_color (f, Vx_cursor_fore_pixel,
  2515                                        WHITE_PIX_DEFAULT (f));
  2516   else
  2517     fore_pixel = FRAME_BACKGROUND_PIXEL (f);
  2518 
  2519   pixel = android_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
  2520 
  2521   /* Make sure that the cursor color differs from the background color.  */
  2522   if (pixel == FRAME_BACKGROUND_PIXEL (f))
  2523     {
  2524       pixel = FRAME_FOREGROUND_PIXEL (f);
  2525       if (pixel == fore_pixel)
  2526         fore_pixel = FRAME_BACKGROUND_PIXEL (f);
  2527     }
  2528 
  2529   x->cursor_foreground_pixel = fore_pixel;
  2530   x->cursor_pixel = pixel;
  2531 
  2532   if (FRAME_ANDROID_WINDOW (f) != 0)
  2533     {
  2534       block_input ();
  2535       android_set_background (x->cursor_gc, x->cursor_pixel);
  2536       android_set_foreground (x->cursor_gc, fore_pixel);
  2537       unblock_input ();
  2538 
  2539       if (FRAME_VISIBLE_P (f))
  2540         {
  2541           gui_update_cursor (f, false);
  2542           gui_update_cursor (f, true);
  2543         }
  2544     }
  2545 
  2546   update_face_from_frame_parameter (f, Qcursor_color, arg);
  2547 }
  2548 
  2549 static void
  2550 android_set_cursor_type (struct frame *f, Lisp_Object arg,
  2551                          Lisp_Object oldval)
  2552 {
  2553   set_frame_cursor_types (f, arg);
  2554 }
  2555 
  2556 static void
  2557 android_set_foreground_color (struct frame *f, Lisp_Object arg,
  2558                               Lisp_Object oldval)
  2559 {
  2560   struct android_output *x;
  2561   unsigned long fg, old_fg;
  2562 
  2563   x = f->output_data.android;
  2564 
  2565   fg = android_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
  2566   old_fg = FRAME_FOREGROUND_PIXEL (f);
  2567   FRAME_FOREGROUND_PIXEL (f) = fg;
  2568 
  2569   if (FRAME_ANDROID_WINDOW (f) != 0)
  2570     {
  2571       block_input ();
  2572       android_set_foreground (x->normal_gc, fg);
  2573       android_set_background (x->reverse_gc, fg);
  2574 
  2575       if (x->cursor_pixel == old_fg)
  2576         {
  2577           x->cursor_pixel = fg;
  2578           android_set_background (x->cursor_gc, x->cursor_pixel);
  2579         }
  2580 
  2581       unblock_input ();
  2582 
  2583       update_face_from_frame_parameter (f, Qforeground_color, arg);
  2584 
  2585       if (FRAME_VISIBLE_P (f))
  2586         redraw_frame (f);
  2587     }
  2588 }
  2589 
  2590 static void
  2591 android_set_child_frame_border_width (struct frame *f, Lisp_Object arg,
  2592                                       Lisp_Object oldval)
  2593 {
  2594   int border;
  2595 
  2596   if (NILP (arg))
  2597     border = -1;
  2598   else if (RANGED_FIXNUMP (0, arg, INT_MAX))
  2599     border = XFIXNAT (arg);
  2600   else
  2601     signal_error ("Invalid child frame border width", arg);
  2602 
  2603   if (border != FRAME_CHILD_FRAME_BORDER_WIDTH (f))
  2604     {
  2605       f->child_frame_border_width = border;
  2606 
  2607       if (FRAME_ANDROID_WINDOW (f))
  2608         {
  2609           adjust_frame_size (f, -1, -1, 3, false, Qchild_frame_border_width);
  2610           android_clear_under_internal_border (f);
  2611         }
  2612     }
  2613 }
  2614 
  2615 static void
  2616 android_set_internal_border_width (struct frame *f, Lisp_Object arg,
  2617                                    Lisp_Object oldval)
  2618 {
  2619   int border = check_int_nonnegative (arg);
  2620 
  2621   if (border != FRAME_INTERNAL_BORDER_WIDTH (f))
  2622     {
  2623       f->internal_border_width = border;
  2624 
  2625       if (FRAME_ANDROID_WINDOW (f))
  2626         {
  2627           adjust_frame_size (f, -1, -1, 3, false, Qinternal_border_width);
  2628           android_clear_under_internal_border (f);
  2629         }
  2630     }
  2631 }
  2632 
  2633 static void
  2634 android_set_menu_bar_lines (struct frame *f, Lisp_Object value,
  2635                             Lisp_Object oldval)
  2636 {
  2637   int nlines;
  2638   int olines = FRAME_MENU_BAR_LINES (f);
  2639 
  2640   /* Right now, menu bars don't work properly in minibuf-only frames;
  2641      most of the commands try to apply themselves to the minibuffer
  2642      frame itself, and get an error because you can't switch buffers
  2643      in or split the minibuffer window.  */
  2644   if (FRAME_MINIBUF_ONLY_P (f) || FRAME_PARENT_FRAME (f))
  2645     return;
  2646 
  2647   if (TYPE_RANGED_FIXNUMP (int, value))
  2648     nlines = XFIXNUM (value);
  2649   else
  2650     nlines = 0;
  2651 
  2652   /* Make sure we redisplay all windows in this frame.  */
  2653   fset_redisplay (f);
  2654 
  2655   FRAME_MENU_BAR_LINES (f) = nlines;
  2656   FRAME_MENU_BAR_HEIGHT (f) = nlines * FRAME_LINE_HEIGHT (f);
  2657   if (FRAME_ANDROID_WINDOW (f))
  2658     android_clear_under_internal_border (f);
  2659 
  2660   /* If the menu bar height gets changed, the internal border below
  2661      the top margin has to be cleared.  Also, if the menu bar gets
  2662      larger, the area for the added lines has to be cleared except for
  2663      the first menu bar line that is to be drawn later.  */
  2664   if (nlines != olines)
  2665     {
  2666       int height = FRAME_INTERNAL_BORDER_WIDTH (f);
  2667       int width = FRAME_PIXEL_WIDTH (f);
  2668       int y;
  2669 
  2670       adjust_frame_size (f, -1, -1, 3, true, Qmenu_bar_lines);
  2671 
  2672       /* height can be zero here. */
  2673       if (FRAME_ANDROID_WINDOW (f) && height > 0 && width > 0)
  2674         {
  2675           y = FRAME_TOP_MARGIN_HEIGHT (f);
  2676 
  2677           block_input ();
  2678           android_clear_area (FRAME_ANDROID_DRAWABLE (f),
  2679                               0, y, width, height);
  2680           unblock_input ();
  2681         }
  2682 
  2683       if (nlines > 1 && nlines > olines)
  2684         {
  2685           y = (olines == 0 ? 1 : olines) * FRAME_LINE_HEIGHT (f);
  2686           height = nlines * FRAME_LINE_HEIGHT (f) - y;
  2687 
  2688           block_input ();
  2689           android_clear_area (FRAME_ANDROID_DRAWABLE (f), 0, y,
  2690                               width, height);
  2691           unblock_input ();
  2692         }
  2693 
  2694       if (nlines == 0 && WINDOWP (f->menu_bar_window))
  2695         clear_glyph_matrix (XWINDOW (f->menu_bar_window)->current_matrix);
  2696     }
  2697 
  2698   adjust_frame_glyphs (f);
  2699 }
  2700 
  2701 
  2702 
  2703 /* These enums must stay in sync with the mouse_cursor_types array
  2704    below!  */
  2705 
  2706 enum mouse_cursor
  2707   {
  2708     mouse_cursor_text,
  2709     mouse_cursor_nontext,
  2710     mouse_cursor_hourglass,
  2711     mouse_cursor_mode,
  2712     mouse_cursor_hand,
  2713     mouse_cursor_horizontal_drag,
  2714     mouse_cursor_vertical_drag,
  2715     mouse_cursor_left_edge,
  2716     mouse_cursor_top_left_corner,
  2717     mouse_cursor_top_edge,
  2718     mouse_cursor_top_right_corner,
  2719     mouse_cursor_right_edge,
  2720     mouse_cursor_bottom_right_corner,
  2721     mouse_cursor_bottom_edge,
  2722     mouse_cursor_bottom_left_corner,
  2723     mouse_cursor_max
  2724   };
  2725 
  2726 struct mouse_cursor_types
  2727 {
  2728   /* Printable name for error messages (optional).  */
  2729   const char *name;
  2730 
  2731   /* Lisp variable controlling the cursor shape.  */
  2732   /* FIXME: A couple of these variables are defined in the C code but
  2733      are not actually accessible from Lisp.  They should probably be
  2734      made accessible or removed.  */
  2735   Lisp_Object *shape_var_ptr;
  2736 
  2737   /* The default shape.  */
  2738   int default_shape;
  2739 };
  2740 
  2741 /* This array must stay in sync with enum mouse_cursor above!  */
  2742 
  2743 static const struct mouse_cursor_types mouse_cursor_types[] =
  2744   {
  2745     {"text", &Vx_pointer_shape, ANDROID_XC_XTERM, },
  2746     {"nontext", &Vx_nontext_pointer_shape, ANDROID_XC_LEFT_PTR, },
  2747     {"hourglass", &Vx_hourglass_pointer_shape, ANDROID_XC_WATCH, },
  2748     {"modeline", &Vx_mode_pointer_shape, ANDROID_XC_XTERM, },
  2749     {NULL, &Vx_sensitive_text_pointer_shape, ANDROID_XC_HAND2, },
  2750     {NULL, &Vx_window_horizontal_drag_shape, ANDROID_XC_SB_H_DOUBLE_ARROW, },
  2751     {NULL, &Vx_window_vertical_drag_shape, ANDROID_XC_SB_V_DOUBLE_ARROW, },
  2752     {NULL, &Vx_window_left_edge_shape, ANDROID_XC_LEFT_SIDE, },
  2753     {NULL, &Vx_window_top_left_corner_shape, ANDROID_XC_TOP_LEFT_CORNER, },
  2754     {NULL, &Vx_window_top_edge_shape, ANDROID_XC_TOP_SIDE, },
  2755     {NULL, &Vx_window_top_right_corner_shape, ANDROID_XC_TOP_RIGHT_CORNER, },
  2756     {NULL, &Vx_window_right_edge_shape, ANDROID_XC_RIGHT_SIDE, },
  2757     {NULL, &Vx_window_bottom_right_corner_shape,
  2758      ANDROID_XC_BOTTOM_RIGHT_CORNER, },
  2759     {NULL, &Vx_window_bottom_edge_shape, ANDROID_XC_BOTTOM_SIDE, },
  2760     {NULL, &Vx_window_bottom_left_corner_shape,
  2761         ANDROID_XC_BOTTOM_LEFT_CORNER, },
  2762   };
  2763 
  2764 struct mouse_cursor_data
  2765 {
  2766   /* Cursor numbers chosen.  */
  2767   unsigned int cursor_num[mouse_cursor_max];
  2768 
  2769   /* Allocated Cursor values, or zero for failed attempts.  */
  2770   android_cursor cursor[mouse_cursor_max];
  2771 };
  2772 
  2773 
  2774 
  2775 static void
  2776 android_set_mouse_color (struct frame *f, Lisp_Object arg,
  2777                          Lisp_Object oldval)
  2778 {
  2779   struct android_output *x = f->output_data.android;
  2780   struct mouse_cursor_data cursor_data = { -1, -1 };
  2781   unsigned long pixel = android_decode_color (f, arg, BLACK_PIX_DEFAULT (f));
  2782   unsigned long mask_color = FRAME_BACKGROUND_PIXEL (f);
  2783   int i;
  2784 
  2785   /* Don't let pointers be invisible.  */
  2786   if (mask_color == pixel)
  2787     pixel = FRAME_FOREGROUND_PIXEL (f);
  2788 
  2789   x->mouse_pixel = pixel;
  2790 
  2791   for (i = 0; i < mouse_cursor_max; i++)
  2792     {
  2793       Lisp_Object shape_var = *mouse_cursor_types[i].shape_var_ptr;
  2794       cursor_data.cursor_num[i]
  2795         = (!NILP (shape_var)
  2796            ? check_uinteger_max (shape_var, UINT_MAX)
  2797            : mouse_cursor_types[i].default_shape);
  2798     }
  2799 
  2800   block_input ();
  2801 
  2802   for (i = 0; i < mouse_cursor_max; i++)
  2803     cursor_data.cursor[i]
  2804       = android_create_font_cursor (cursor_data.cursor_num[i]);
  2805 
  2806   if (FRAME_ANDROID_WINDOW (f))
  2807     {
  2808       f->output_data.android->current_cursor
  2809         = cursor_data.cursor[mouse_cursor_text];
  2810       android_define_cursor (FRAME_ANDROID_WINDOW (f),
  2811                              f->output_data.android->current_cursor);
  2812     }
  2813 
  2814 #define INSTALL_CURSOR(FIELD, SHORT_INDEX)                              \
  2815    eassert (x->FIELD                                                    \
  2816             != cursor_data.cursor[mouse_cursor_ ## SHORT_INDEX]);       \
  2817    if (x->FIELD != 0)                                                   \
  2818      android_free_cursor (x->FIELD);                                    \
  2819    x->FIELD = cursor_data.cursor[mouse_cursor_ ## SHORT_INDEX];
  2820 
  2821   INSTALL_CURSOR (text_cursor, text);
  2822   INSTALL_CURSOR (nontext_cursor, nontext);
  2823   INSTALL_CURSOR (hourglass_cursor, hourglass);
  2824   INSTALL_CURSOR (modeline_cursor, mode);
  2825   INSTALL_CURSOR (hand_cursor, hand);
  2826   INSTALL_CURSOR (horizontal_drag_cursor, horizontal_drag);
  2827   INSTALL_CURSOR (vertical_drag_cursor, vertical_drag);
  2828   INSTALL_CURSOR (left_edge_cursor, left_edge);
  2829   INSTALL_CURSOR (top_left_corner_cursor, top_left_corner);
  2830   INSTALL_CURSOR (top_edge_cursor, top_edge);
  2831   INSTALL_CURSOR (top_right_corner_cursor, top_right_corner);
  2832   INSTALL_CURSOR (right_edge_cursor, right_edge);
  2833   INSTALL_CURSOR (bottom_right_corner_cursor, bottom_right_corner);
  2834   INSTALL_CURSOR (bottom_edge_cursor, bottom_edge);
  2835   INSTALL_CURSOR (bottom_left_corner_cursor, bottom_left_corner);
  2836 
  2837 #undef INSTALL_CURSOR
  2838 
  2839   unblock_input ();
  2840 
  2841   update_face_from_frame_parameter (f, Qmouse_color, arg);
  2842 }
  2843 
  2844 static void
  2845 android_set_title (struct frame *f, Lisp_Object name,
  2846                    Lisp_Object old_name)
  2847 {
  2848   /* Don't change the title if it's already NAME.  */
  2849   if (EQ (name, f->title))
  2850     return;
  2851 
  2852   update_mode_lines = 38;
  2853 
  2854   fset_title (f, name);
  2855 
  2856   if (NILP (name))
  2857     name = f->name;
  2858   else
  2859     CHECK_STRING (name);
  2860 }
  2861 
  2862 static void
  2863 android_set_alpha (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
  2864 {
  2865   double alpha = 1.0;
  2866   double newval[2];
  2867   int i;
  2868   Lisp_Object item;
  2869 
  2870   /* N.B. that setting the window alpha is actually unsupported under
  2871      Android.  */
  2872 
  2873   for (i = 0; i < 2; i++)
  2874     {
  2875       newval[i] = 1.0;
  2876       if (CONSP (arg))
  2877         {
  2878           item = CAR (arg);
  2879           arg  = CDR (arg);
  2880         }
  2881       else
  2882         item = arg;
  2883 
  2884       if (NILP (item))
  2885         alpha = - 1.0;
  2886       else if (FLOATP (item))
  2887         {
  2888           alpha = XFLOAT_DATA (item);
  2889           if (! (0 <= alpha && alpha <= 1.0))
  2890             args_out_of_range (make_float (0.0), make_float (1.0));
  2891         }
  2892       else if (FIXNUMP (item))
  2893         {
  2894           EMACS_INT ialpha = XFIXNUM (item);
  2895           if (! (0 <= ialpha && ialpha <= 100))
  2896             args_out_of_range (make_fixnum (0), make_fixnum (100));
  2897           alpha = ialpha / 100.0;
  2898         }
  2899       else
  2900         wrong_type_argument (Qnumberp, item);
  2901       newval[i] = alpha;
  2902     }
  2903 
  2904   for (i = 0; i < 2; i++)
  2905     f->alpha[i] = newval[i];
  2906 
  2907   if (FRAME_TERMINAL (f)->set_frame_alpha_hook)
  2908     {
  2909       block_input ();
  2910       FRAME_TERMINAL (f)->set_frame_alpha_hook (f);
  2911       unblock_input ();
  2912     }
  2913 }
  2914 
  2915 static void
  2916 android_set_no_focus_on_map (struct frame *f, Lisp_Object new_value,
  2917                              Lisp_Object old_value)
  2918 {
  2919   if (!EQ (new_value, old_value))
  2920     {
  2921       android_set_dont_focus_on_map (FRAME_ANDROID_WINDOW (f),
  2922                                      !NILP (new_value));
  2923       FRAME_NO_FOCUS_ON_MAP (f) = !NILP (new_value);
  2924     }
  2925 }
  2926 
  2927 static void
  2928 android_set_no_accept_focus (struct frame *f, Lisp_Object new_value,
  2929                              Lisp_Object old_value)
  2930 {
  2931   if (!EQ (new_value, old_value))
  2932     {
  2933       android_set_dont_accept_focus (FRAME_ANDROID_WINDOW (f),
  2934                                      !NILP (new_value));
  2935       FRAME_NO_ACCEPT_FOCUS (f) = !NILP (new_value);
  2936     }
  2937 }
  2938 
  2939 frame_parm_handler android_frame_parm_handlers[] =
  2940 {
  2941   gui_set_autoraise,
  2942   gui_set_autolower,
  2943   android_set_background_color,
  2944   android_set_border_color,
  2945   gui_set_border_width,
  2946   android_set_cursor_color,
  2947   android_set_cursor_type,
  2948   gui_set_font,
  2949   android_set_foreground_color,
  2950   NULL,
  2951   NULL,
  2952   android_set_child_frame_border_width,
  2953   android_set_internal_border_width,
  2954   gui_set_right_divider_width,
  2955   gui_set_bottom_divider_width,
  2956   android_set_menu_bar_lines,
  2957   android_set_mouse_color,
  2958   android_explicitly_set_name,
  2959   gui_set_scroll_bar_width,
  2960   gui_set_scroll_bar_height,
  2961   android_set_title,
  2962   gui_set_unsplittable,
  2963   gui_set_vertical_scroll_bars,
  2964   gui_set_horizontal_scroll_bars,
  2965   gui_set_visibility,
  2966   android_set_tab_bar_lines,
  2967   android_set_tool_bar_lines,
  2968   NULL,
  2969   NULL,
  2970   gui_set_screen_gamma,
  2971   gui_set_line_spacing,
  2972   gui_set_left_fringe,
  2973   gui_set_right_fringe,
  2974   NULL,
  2975   gui_set_fullscreen,
  2976   gui_set_font_backend,
  2977   android_set_alpha,
  2978   NULL,
  2979   android_set_tool_bar_position,
  2980   NULL,
  2981   NULL,
  2982   android_set_parent_frame,
  2983   NULL,
  2984   android_set_no_focus_on_map,
  2985   android_set_no_accept_focus,
  2986   NULL,
  2987   NULL,
  2988   gui_set_no_special_glyphs,
  2989   NULL,
  2990   NULL,
  2991 };
  2992 
  2993 
  2994 
  2995 /* Battery information support.  */
  2996 
  2997 DEFUN ("android-query-battery", Fandroid_query_battery,
  2998        Sandroid_query_battery, 0, 0, 0,
  2999        doc: /* Perform a query for battery information.
  3000 Value is nil upon failure, or a list of the form:
  3001 
  3002   (CAPACITY CHARGE-COUNTER CURRENT-AVERAGE CURRENT-NOW STATUS
  3003    REMAINING PLUGGED TEMP)
  3004 
  3005 where REMAINING, CURRENT-AVERAGE, and CURRENT-NOW are undefined prior
  3006 to Android 5.0.
  3007 
  3008 See the documentation at
  3009 
  3010   https://developer.android.com/reference/android/os/BatteryManager
  3011 
  3012 for more details about these values.  */)
  3013   (void)
  3014 {
  3015   struct android_battery_state state;
  3016 
  3017   /* Make sure the Android libraries have been initialized.  */
  3018 
  3019   if (!android_init_gui)
  3020     return Qnil;
  3021 
  3022   /* Perform the query.  */
  3023 
  3024   if (android_query_battery (&state))
  3025     return Qnil;
  3026 
  3027   return listn (8, make_int (state.capacity),
  3028                 make_fixnum (state.charge_counter),
  3029                 make_int (state.current_average),
  3030                 make_int (state.current_now),
  3031                 make_fixnum (state.status),
  3032                 make_int (state.remaining),
  3033                 make_fixnum (state.plugged),
  3034                 make_fixnum (state.temperature));
  3035 }
  3036 
  3037 
  3038 
  3039 /* Directory access requests.  */
  3040 
  3041 DEFUN ("android-request-directory-access", Fandroid_request_directory_access,
  3042        Sandroid_request_directory_access, 0, 0, "",
  3043        doc: /* Request access to a directory within external storage.
  3044 On Android 5.0 and later, prompt for a directory within external or
  3045 application storage, and grant access to it; some of these directories
  3046 cannot be accessed through the regular `/sdcard' filesystem.
  3047 
  3048 If access to the directory is granted, it will eventually appear
  3049 within the directory `/content/storage'.  */)
  3050   (void)
  3051 {
  3052   if (android_get_current_api_level () < 21)
  3053     error ("Emacs can only access application storage on"
  3054            " Android 5.0 and later");
  3055 
  3056   if (!android_init_gui)
  3057     return Qnil;
  3058 
  3059   android_request_directory_access ();
  3060   return Qnil;
  3061 }
  3062 
  3063 
  3064 
  3065 /* Miscellaneous input method related stuff.  */
  3066 
  3067 /* Report X, Y, by the phys cursor width and height as the cursor
  3068    anchor rectangle for W's frame.  */
  3069 
  3070 void
  3071 android_set_preeditarea (struct window *w, int x, int y)
  3072 {
  3073   struct frame *f;
  3074 
  3075   f = WINDOW_XFRAME (w);
  3076 
  3077   /* Convert the window coordinates to the frame's coordinate
  3078      space.  */
  3079   x = (WINDOW_TO_FRAME_PIXEL_X (w, x)
  3080        + WINDOW_LEFT_FRINGE_WIDTH (w)
  3081        + WINDOW_LEFT_MARGIN_WIDTH (w));
  3082   y = WINDOW_TO_FRAME_PIXEL_Y (w, y);
  3083 
  3084   /* Note that calculating the baseline is too hard, so the bottom of
  3085      the cursor is used instead.  */
  3086   android_update_cursor_anchor_info (FRAME_ANDROID_WINDOW (f), x,
  3087                                      y, y + w->phys_cursor_height,
  3088                                      y + w->phys_cursor_height);
  3089 }
  3090 
  3091 #endif /* !ANDROID_STUBIFY */
  3092 
  3093 
  3094 
  3095 void
  3096 syms_of_androidfns (void)
  3097 {
  3098   /* Miscellaneous symbols used by some functions here.  */
  3099   DEFSYM (Qtrue_color, "true-color");
  3100   DEFSYM (Qalways, "always");
  3101 
  3102   DEFVAR_LISP ("x-pointer-shape", Vx_pointer_shape,
  3103     doc: /* SKIP: real text in xfns.c.  */);
  3104   Vx_pointer_shape = Qnil;
  3105 
  3106 #if false /* This doesn't really do anything.  */
  3107   DEFVAR_LISP ("x-nontext-pointer-shape", Vx_nontext_pointer_shape,
  3108     doc: /* SKIP: real doc in xfns.c.  */);
  3109 #endif
  3110   Vx_nontext_pointer_shape = Qnil;
  3111 
  3112   DEFVAR_LISP ("x-hourglass-pointer-shape", Vx_hourglass_pointer_shape,
  3113     doc: /* SKIP: real text in xfns.c.  */);
  3114   Vx_hourglass_pointer_shape = Qnil;
  3115 
  3116   DEFVAR_LISP ("x-sensitive-text-pointer-shape",
  3117               Vx_sensitive_text_pointer_shape,
  3118     doc: /* SKIP: real text in xfns.c.  */);
  3119   Vx_sensitive_text_pointer_shape = Qnil;
  3120 
  3121   DEFVAR_LISP ("x-window-horizontal-drag-cursor",
  3122               Vx_window_horizontal_drag_shape,
  3123     doc: /* SKIP: real text in xfns.c.  */);
  3124   Vx_window_horizontal_drag_shape = Qnil;
  3125 
  3126   DEFVAR_LISP ("x-window-vertical-drag-cursor",
  3127               Vx_window_vertical_drag_shape,
  3128     doc: /* SKIP: real text in xfns.c.  */);
  3129   Vx_window_vertical_drag_shape = Qnil;
  3130 
  3131   DEFVAR_LISP ("x-window-left-edge-cursor",
  3132                Vx_window_left_edge_shape,
  3133     doc: /* SKIP: real text in xfns.c.  */);
  3134   Vx_window_left_edge_shape = Qnil;
  3135 
  3136   DEFVAR_LISP ("x-window-top-left-corner-cursor",
  3137                Vx_window_top_left_corner_shape,
  3138     doc: /* SKIP: real text in xfns.c.  */);
  3139   Vx_window_top_left_corner_shape = Qnil;
  3140 
  3141   DEFVAR_LISP ("x-window-top-edge-cursor",
  3142                Vx_window_top_edge_shape,
  3143     doc: /* SKIP: real text in xfns.c.  */);
  3144   Vx_window_top_edge_shape = Qnil;
  3145 
  3146   DEFVAR_LISP ("x-window-top-right-corner-cursor",
  3147                Vx_window_top_right_corner_shape,
  3148     doc: /* SKIP: real text in xfns.c.  */);
  3149   Vx_window_top_right_corner_shape = Qnil;
  3150 
  3151   DEFVAR_LISP ("x-window-right-edge-cursor",
  3152                Vx_window_right_edge_shape,
  3153     doc: /* SKIP: real text in xfns.c.  */);
  3154   Vx_window_right_edge_shape = Qnil;
  3155 
  3156   DEFVAR_LISP ("x-window-bottom-right-corner-cursor",
  3157                Vx_window_bottom_right_corner_shape,
  3158     doc: /* SKIP: real text in xfns.c.  */);
  3159   Vx_window_bottom_right_corner_shape = Qnil;
  3160 
  3161   DEFVAR_LISP ("x-window-bottom-edge-cursor",
  3162                Vx_window_bottom_edge_shape,
  3163     doc: /* SKIP: real text in xfns.c.  */);
  3164   Vx_window_bottom_edge_shape = Qnil;
  3165 
  3166 #if false /* This doesn't really do anything.  */
  3167   DEFVAR_LISP ("x-mode-pointer-shape", Vx_mode_pointer_shape,
  3168     doc: /* SKIP: real doc in xfns.c.  */);
  3169 #endif
  3170   Vx_mode_pointer_shape = Qnil;
  3171 
  3172   DEFVAR_LISP ("x-window-bottom-left-corner-cursor",
  3173                Vx_window_bottom_left_corner_shape,
  3174     doc: /* SKIP: real text in xfns.c.  */);
  3175   Vx_window_bottom_left_corner_shape = Qnil;
  3176 
  3177   DEFVAR_LISP ("x-cursor-fore-pixel", Vx_cursor_fore_pixel,
  3178     doc: /* SKIP: real doc in xfns.c.  */);
  3179   Vx_cursor_fore_pixel = Qnil;
  3180 
  3181   /* Used by Fx_show_tip.  */
  3182   DEFSYM (Qrun_at_time, "run-at-time");
  3183   DEFSYM (Qx_hide_tip, "x-hide-tip");
  3184   DEFSYM (Qcancel_timer, "cancel-timer");
  3185   DEFSYM (Qassq_delete_all, "assq-delete-all");
  3186   DEFSYM (Qcolor, "color");
  3187 
  3188   DEFVAR_LISP ("x-max-tooltip-size", Vx_max_tooltip_size,
  3189     doc: /* SKIP: real doc in xfns.c.  */);
  3190   Vx_max_tooltip_size = Qnil;
  3191 
  3192   DEFVAR_BOOL ("android-pass-multimedia-buttons-to-system",
  3193                android_pass_multimedia_buttons_to_system,
  3194     doc: /* Whether or not to pass volume control buttons to the system.
  3195 Generally, the `volume-up', `volume-down' and `volume-mute' keys are
  3196 processed by Emacs, but setting this to non-nil they are passed to the
  3197 operating system instead of being intercepted by Emacs.
  3198 
  3199 Note that if you set this, you will no longer be able to quit Emacs
  3200 using the volume down button.  */);
  3201   android_pass_multimedia_buttons_to_system = false;
  3202 
  3203   DEFVAR_BOOL ("android-use-exec-loader", android_use_exec_loader,
  3204     doc: /* Whether or not to bypass system restrictions on program execution.
  3205 
  3206 Android 10 and later prevent programs from executing files installed
  3207 in writable directories, such as the application data directory.
  3208 
  3209 When non-nil, Emacs will bypass this restriction by running such
  3210 executables under system call tracing, and replacing the `execve'
  3211 system call with a version which ignores the system's security
  3212 restrictions.
  3213 
  3214 This option has no effect on Android 9 and earlier.  */);
  3215   android_use_exec_loader = true;
  3216 
  3217   /* Functions defined.  */
  3218   defsubr (&Sx_create_frame);
  3219   defsubr (&Sxw_color_defined_p);
  3220   defsubr (&Sxw_color_values);
  3221   defsubr (&Sxw_display_color_p);
  3222   defsubr (&Sx_display_grayscale_p);
  3223   defsubr (&Sx_display_pixel_width);
  3224   defsubr (&Sx_display_pixel_height);
  3225   defsubr (&Sx_display_planes);
  3226   defsubr (&Sx_display_color_cells);
  3227   defsubr (&Sx_display_screens);
  3228   defsubr (&Sx_display_mm_width);
  3229   defsubr (&Sx_display_mm_height);
  3230   defsubr (&Sx_display_backing_store);
  3231   defsubr (&Sx_display_visual_class);
  3232   defsubr (&Sandroid_display_monitor_attributes_list);
  3233   defsubr (&Sandroid_frame_geometry);
  3234   defsubr (&Sandroid_frame_edges);
  3235   defsubr (&Sandroid_frame_list_z_order);
  3236   defsubr (&Sandroid_frame_restack);
  3237   defsubr (&Sandroid_mouse_absolute_pixel_position);
  3238   defsubr (&Sandroid_set_mouse_absolute_pixel_position);
  3239   defsubr (&Sandroid_get_connection);
  3240   defsubr (&Sx_display_list);
  3241   defsubr (&Sx_show_tip);
  3242   defsubr (&Sx_hide_tip);
  3243   defsubr (&Sandroid_detect_mouse);
  3244   defsubr (&Sandroid_toggle_on_screen_keyboard);
  3245   defsubr (&Sx_server_vendor);
  3246   defsubr (&Sx_server_version);
  3247 #ifndef ANDROID_STUBIFY
  3248   defsubr (&Sandroid_query_battery);
  3249   defsubr (&Sandroid_request_directory_access);
  3250 
  3251   tip_timer = Qnil;
  3252   staticpro (&tip_timer);
  3253   tip_frame = Qnil;
  3254   staticpro (&tip_frame);
  3255   tip_last_frame = Qnil;
  3256   staticpro (&tip_last_frame);
  3257   tip_last_string = Qnil;
  3258   staticpro (&tip_last_string);
  3259   tip_last_parms = Qnil;
  3260   staticpro (&tip_last_parms);
  3261   tip_dx = Qnil;
  3262   staticpro (&tip_dx);
  3263   tip_dy = Qnil;
  3264   staticpro (&tip_dy);
  3265 #endif /* !ANDROID_STUBIFY */
  3266 }

/* [<][>][^][v][top][bottom][index][help] */