root/src/androidterm.h

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

INCLUDED FROM


     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 #ifndef _ANDROID_TERM_H_
    21 #define _ANDROID_TERM_H_
    22 
    23 #include "androidgui.h"
    24 #include "frame.h"
    25 #include "character.h"
    26 #include "dispextern.h"
    27 #include "font.h"
    28 
    29 struct android_bitmap_record
    30 {
    31   /* The image backing the bitmap and its mask.  */
    32   android_pixmap pixmap, mask;
    33 
    34   /* The file from which it comes.  */
    35   char *file;
    36 
    37   /* The number of references to it.  */
    38   int refcount;
    39 
    40   /* The height and width and the depth.  */
    41   int height, width, depth;
    42 
    43   /* Whether or not there is a mask.  */
    44   bool have_mask;
    45 };
    46 
    47 struct android_display_info
    48 {
    49   /* Chain of all struct android_display_info structures.  */
    50   struct android_display_info *next;
    51 
    52   /* The terminal.  */
    53   struct terminal *terminal;
    54 
    55   /* The root window.  This field is unused.  */
    56   Emacs_Window root_window;
    57 
    58   /* List possibly used only for the font cache but probably used for
    59      something else too.  */
    60   Lisp_Object name_list_element;
    61 
    62   /* List of predefined X colors.  */
    63   Lisp_Object color_map;
    64 
    65   /* DPI of the display.  */
    66   double resx, resy;
    67 
    68   /* DPI used to convert font point sizes into pixel dimensions.
    69      This is resy adjusted by a fixed scaling factor specified by
    70      the user.  */
    71   double font_resolution;
    72 
    73   /* Scratch GC for drawing a cursor in a non-default face. */
    74   struct android_gc *scratch_cursor_gc;
    75 
    76   /* Mouse highlight information.  */
    77   Mouse_HLInfo mouse_highlight;
    78 
    79   /* Number of planes on this screen.  Always 24.  */
    80   int n_planes;
    81 
    82   /* Mask of things causing the mouse to be grabbed.  */
    83   int grabbed;
    84 
    85   /* Minimum width over all characters in all fonts in font_table.  */
    86   int smallest_char_width;
    87 
    88   /* Minimum font height over all fonts in font_table.  */
    89   int smallest_font_height;
    90 
    91   /* The number of fonts opened for this display.  */
    92   int n_fonts;
    93 
    94   /* Pointer to bitmap records.  */
    95   struct android_bitmap_record *bitmaps;
    96 
    97   /* Allocated size of bitmaps field.  */
    98   ptrdiff_t bitmaps_size;
    99 
   100   /* Last used bitmap index.  */
   101   ptrdiff_t bitmaps_last;
   102 
   103   /* The frame currently with the input focus.  */
   104   struct frame *focus_frame;
   105 
   106   /* The last frame mentioned in a focus event.  */
   107   struct frame *x_focus_event_frame;
   108 
   109   /* The frame which currently has the visual highlight, and should
   110      get keyboard input.  It points to the focus frame's selected
   111      window's frame, but can differ.  */
   112   struct frame *highlight_frame;
   113 
   114   /* The frame waiting to be auto-raised in android_read_socket.  */
   115   struct frame *pending_autoraise_frame;
   116 
   117   /* The frame where the mouse was the last time a button event
   118      happened.  */
   119   struct frame *last_mouse_frame;
   120 
   121   /* The frame where the mouse was the last time the mouse glyph
   122      changed.  */
   123   struct frame *last_mouse_glyph_frame;
   124 
   125   /* The frame where the mouse was the last time mouse motion
   126      happened.  */
   127   struct frame *last_mouse_motion_frame;
   128 
   129   /* Position where the mouse was last time we reported a motion.
   130      This is a position on last_mouse_motion_frame.  It is used in to
   131      report the mouse position as well: see
   132      android_mouse_position.  */
   133   int last_mouse_motion_x, last_mouse_motion_y;
   134 
   135   /* Where the mouse was the last time the mouse moved.  */
   136   Emacs_Rectangle last_mouse_glyph;
   137 
   138   /* The time of the last mouse movement.  */
   139   Time last_mouse_movement_time;
   140 
   141   /* ID of the last menu event received.  -1 means Emacs is waiting
   142      for a context menu event.  */
   143   int menu_event_id;
   144 
   145   /* The invisible cursor used for pointer blanking.  */
   146   android_cursor invisible_cursor;
   147 };
   148 
   149 /* Structure representing a single tool (finger or stylus) pressed
   150    onto a frame.  */
   151 
   152 struct android_touch_point
   153 {
   154   /* The next tool on this list.  */
   155   struct android_touch_point *next;
   156 
   157   /* The tool ID and the last known X and Y positions.  */
   158   int tool_id, x, y;
   159 
   160   /* Whether or not the tool is pressed on the tool bar.  */
   161   bool tool_bar_p;
   162 };
   163 
   164 struct android_output
   165 {
   166   /* Graphics contexts for the default font.  */
   167   struct android_gc *normal_gc, *reverse_gc, *cursor_gc;
   168 
   169   /* The window used for this frame.  */
   170   Emacs_Window window;
   171 
   172   /* Unused field.  */
   173   Emacs_Window parent_desc;
   174 
   175   /* Default ASCII font of this frame.  */
   176   struct font *font;
   177 
   178   /* The baseline offset of the default ASCII font.  */
   179   int baseline_offset;
   180 
   181   /* If a fontset is specified for this frame instead of font, this
   182      value contains an ID of the fontset, else -1.  */
   183   int fontset;
   184 
   185   /* Various colors.  */
   186   unsigned long cursor_pixel;
   187   unsigned long mouse_pixel;
   188   unsigned long cursor_foreground_pixel;
   189 
   190   /* Foreground color for scroll bars.  A value of -1 means use the
   191      default (black for non-toolkit scroll bars).  */
   192   unsigned long scroll_bar_foreground_pixel;
   193 
   194   /* Background color for scroll bars.  A value of -1 means use the
   195      default (background color of the frame for non-toolkit scroll
   196      bars).  */
   197   unsigned long scroll_bar_background_pixel;
   198 
   199   /* Cursors associated with this frame.  */
   200   Emacs_Cursor text_cursor;
   201   Emacs_Cursor nontext_cursor;
   202   Emacs_Cursor modeline_cursor;
   203   Emacs_Cursor hand_cursor;
   204   Emacs_Cursor hourglass_cursor;
   205   Emacs_Cursor horizontal_drag_cursor;
   206   Emacs_Cursor vertical_drag_cursor;
   207   Emacs_Cursor current_cursor;
   208   Emacs_Cursor left_edge_cursor;
   209   Emacs_Cursor top_left_corner_cursor;
   210   Emacs_Cursor top_edge_cursor;
   211   Emacs_Cursor top_right_corner_cursor;
   212   Emacs_Cursor right_edge_cursor;
   213   Emacs_Cursor bottom_right_corner_cursor;
   214   Emacs_Cursor bottom_edge_cursor;
   215   Emacs_Cursor bottom_left_corner_cursor;
   216 
   217   /* Whether or not the hourglass cursor is being displayed.  */
   218   bool hourglass;
   219 
   220   /* This is the Emacs structure for the display this frame is on.  */
   221   struct android_display_info *display_info;
   222 
   223   /* True if this frame was ever previously visible.  */
   224   bool_bf has_been_visible : 1;
   225 
   226   /* True if this frame's alpha value is the same for both the active
   227      and inactive states.  */
   228   bool_bf alpha_identical_p : 1;
   229 
   230   /* Flag that indicates whether or not the frame contents are
   231      complete and can be safely flushed while handling async
   232      input.  */
   233   bool_bf complete : 1;
   234 
   235   /* True that indicates whether or not a buffer flip is required
   236      because the frame contents have been dirtied.  */
   237   bool_bf need_buffer_flip : 1;
   238 
   239   /* Whether or not the input method should be notified every time the
   240      position of this frame's selected window changes.  */
   241   bool_bf need_cursor_updates : 1;
   242 
   243   /* Relief GCs, colors etc.  */
   244   struct relief {
   245     struct android_gc *gc;
   246     unsigned long pixel;
   247   } black_relief, white_relief;
   248 
   249   /* The background for which the above relief GCs were set up.
   250      They are changed only when a different background is involved.  */
   251   unsigned long relief_background;
   252 
   253   /* Focus state.  Only present for consistency with X; it is actually
   254      a boolean.  */
   255   int focus_state;
   256 
   257   /* List of all tools (either styluses or fingers) pressed onto the
   258      frame.  */
   259   struct android_touch_point *touch_points;
   260 
   261   /* Flags associated with the last request to obtain ``extracted
   262      text''.  */
   263   int extracted_text_flags;
   264 
   265   /* Token asssociated with that request.  */
   266   int extracted_text_token;
   267 
   268   /* The number of characters of extracted text wanted by the IM.  */
   269   int extracted_text_hint;
   270 };
   271 
   272 enum
   273   {
   274     /* Values for focus_state, used as bit mask.  EXPLICIT means we
   275        received a FocusIn for the frame and know it has the focus.
   276        IMPLICIT means we received an EnterNotify and the frame may
   277        have the focus if no window manager is running.  FocusOut and
   278        LeaveNotify clears EXPLICIT/IMPLICIT. */
   279     FOCUS_NONE     = 0,
   280     FOCUS_IMPLICIT = 1,
   281     FOCUS_EXPLICIT = 2
   282   };
   283 
   284 /* Return the Android output data for frame F.  */
   285 #define FRAME_ANDROID_OUTPUT(f) ((f)->output_data.android)
   286 #define FRAME_OUTPUT_DATA(f)    ((f)->output_data.android)
   287 
   288 /* Return the Android window used for displaying data in frame F.  */
   289 #define FRAME_ANDROID_WINDOW(f) ((f)->output_data.android->window)
   290 #define FRAME_NATIVE_WINDOW(f)  ((f)->output_data.android->window)
   291 
   292 /* Return the need-buffer-flip flag for frame F.  */
   293 #define FRAME_ANDROID_NEED_BUFFER_FLIP(f)       \
   294   ((f)->output_data.android->need_buffer_flip)
   295 
   296 /* Return the drawable used for rendering to frame F and mark the
   297    frame as needing a buffer flip later.  There's no easy way to run
   298    code after any drawing command, but code can be run whenever
   299    someone asks for the handle necessary to draw.  */
   300 #define FRAME_ANDROID_DRAWABLE(f)                       \
   301   (((f))->output_data.android->need_buffer_flip = true, \
   302    FRAME_ANDROID_WINDOW ((f)))
   303 
   304 /* Return whether or not the frame F has been completely drawn.  Used
   305    while handling async input.  */
   306 #define FRAME_ANDROID_COMPLETE_P(f)             \
   307   ((f)->output_data.android->complete)
   308 
   309 #define FRAME_FONT(f)           ((f)->output_data.android->font)
   310 #define FRAME_FONTSET(f)        ((f)->output_data.android->fontset)
   311 
   312 #define FRAME_BASELINE_OFFSET(f)                \
   313   ((f)->output_data.android->baseline_offset)
   314 
   315 /* This gives the android_display_info structure for the display F is
   316    on.  */
   317 #define FRAME_DISPLAY_INFO(f) ((f)->output_data.android->display_info)
   318 
   319 /* Some things for X compatibility.  */
   320 #define BLACK_PIX_DEFAULT(f) 0
   321 #define WHITE_PIX_DEFAULT(f) 0xffffffff
   322 
   323 /* Android-specific scroll bar stuff.  */
   324 
   325 /* We represent scroll bars as lisp vectors.  This allows us to place
   326    references to them in windows without worrying about whether we'll
   327    end up with windows referring to dead scroll bars; the garbage
   328    collector will free it when its time comes.
   329 
   330    We use struct scroll_bar as a template for accessing fields of the
   331    vector.  */
   332 
   333 struct scroll_bar
   334 {
   335   /* These fields are shared by all vectors.  */
   336   union vectorlike_header header;
   337 
   338   /* The window we're a scroll bar for.  */
   339   Lisp_Object window;
   340 
   341   /* The next and previous in the chain of scroll bars in this frame.  */
   342   Lisp_Object next, prev;
   343 
   344   /* Fields after 'prev' are not traced by the GC.  */
   345 
   346   /* The X window representing this scroll bar.  */
   347   Emacs_Window x_window;
   348 
   349   /* The position and size of the scroll bar in pixels, relative to the
   350      frame.  */
   351   int top, left, width, height;
   352 
   353   /* The starting and ending positions of the handle, relative to the
   354      handle area (i.e. zero is the top position, not
   355      SCROLL_BAR_TOP_BORDER).  If they're equal, that means the handle
   356      hasn't been drawn yet.
   357 
   358      These are not actually the locations where the beginning and end
   359      are drawn; in order to keep handles from becoming invisible when
   360      editing large files, we establish a minimum height by always
   361      drawing handle bottoms VERTICAL_SCROLL_BAR_MIN_HANDLE pixels below
   362      where they would be normally; the bottom and top are in a
   363      different coordinate system.  */
   364   int start, end;
   365 
   366   /* If the scroll bar handle is currently being dragged by the user,
   367      this is the number of pixels from the top of the handle to the
   368      place where the user grabbed it.  If the handle isn't currently
   369      being dragged, this is -1.  */
   370   int dragging;
   371 
   372   /* True if the scroll bar is horizontal.  */
   373   bool horizontal;
   374 };
   375 
   376 /* Turning a lisp vector value into a pointer to a struct scroll_bar.  */
   377 #define XSCROLL_BAR(vec) ((struct scroll_bar *) XVECTOR (vec))
   378 
   379 
   380 
   381 /* This is a chain of structures for all the Android displays
   382    currently in use.  There is only ever one, but the rest of Emacs is
   383    written with systems on which there can be many in mind.  */
   384 extern struct android_display_info *x_display_list;
   385 
   386 
   387 
   388 /* Start of function definitions.  These should be a neat subset of
   389    the same ones in xterm.h, and come in the same order.  */
   390 
   391 /* From androidfns.c.  */
   392 
   393 extern void android_free_gcs (struct frame *);
   394 extern void android_default_font_parameter (struct frame *, Lisp_Object);
   395 extern void android_set_preeditarea (struct window *, int, int);
   396 
   397 /* Defined in androidterm.c.  */
   398 
   399 extern void android_term_init (void);
   400 extern void android_set_window_size (struct frame *, bool, int, int);
   401 extern void android_iconify_frame (struct frame *);
   402 extern void android_make_frame_visible (struct frame *);
   403 extern void android_make_frame_invisible (struct frame *);
   404 extern void android_free_frame_resources (struct frame *);
   405 
   406 extern int android_parse_color (struct frame *, const char *,
   407                                 Emacs_Color *);
   408 extern bool android_alloc_nearest_color (struct frame *, Emacs_Color *);
   409 extern void android_query_colors (struct frame *, Emacs_Color *, int);
   410 extern void android_clear_under_internal_border (struct frame *);
   411 
   412 extern void syms_of_androidterm (void);
   413 extern void mark_androidterm (void);
   414 
   415 /* Defined in androidfns.c.  */
   416 
   417 extern void android_change_tab_bar_height (struct frame *, int);
   418 extern void android_change_tool_bar_height (struct frame *, int);
   419 extern void android_set_scroll_bar_default_width (struct frame *);
   420 extern void android_set_scroll_bar_default_height (struct frame *);
   421 extern bool android_defined_color (struct frame *, const char *,
   422                                    Emacs_Color *, bool, bool);
   423 extern void android_implicitly_set_name (struct frame *, Lisp_Object,
   424                                          Lisp_Object);
   425 extern void android_explicitly_set_name (struct frame *, Lisp_Object,
   426                                          Lisp_Object);
   427 
   428 extern void syms_of_androidfns (void);
   429 
   430 /* Defined in androidfont.c.  */
   431 
   432 extern struct font_driver androidfont_driver;
   433 
   434 extern void init_androidfont (void);
   435 extern void syms_of_androidfont (void);
   436 
   437 extern void android_finalize_font_entity (struct font_entity *);
   438 
   439 /* Defined in androidmenu.c.  */
   440 
   441 #ifndef ANDROID_STUBIFY
   442 
   443 extern unsigned int current_menu_serial;
   444 
   445 #endif
   446 
   447 extern Lisp_Object android_menu_show (struct frame *, int, int, int,
   448                                       Lisp_Object, const char **);
   449 extern Lisp_Object android_popup_dialog (struct frame *, Lisp_Object,
   450                                          Lisp_Object);
   451 
   452 extern void init_androidmenu (void);
   453 extern void syms_of_androidmenu (void);
   454 
   455 /* Defined in sfntfont-android.c.  */
   456 
   457 extern const struct font_driver android_sfntfont_driver;
   458 
   459 extern void sfntfont_android_shrink_scanline_buffer (void);
   460 extern void init_sfntfont_android (void);
   461 extern void syms_of_sfntfont_android (void);
   462 
   463 /* Defined in androidselect.c  */
   464 
   465 #ifndef ANDROID_STUBIFY
   466 
   467 extern void init_androidselect (void);
   468 extern void syms_of_androidselect (void);
   469 
   470 #endif
   471 
   472 
   473 
   474 #define RGB_TO_ULONG(r, g, b)   (((r) << 16) | ((g) << 8) | (b))
   475 #define RED_FROM_ULONG(color)   (((color) >> 16) & 0xff)
   476 #define GREEN_FROM_ULONG(color) (((color) >> 8) & 0xff)
   477 #define BLUE_FROM_ULONG(color)  ((color) & 0xff)
   478 
   479 
   480 
   481 #endif /* _ANDROID_TERM_H_ */

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