unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* Input for TTY menus
@ 2013-09-19 13:38 Eli Zaretskii
  2013-09-19 13:52 ` Masatake YAMATO
                   ` (2 more replies)
  0 siblings, 3 replies; 40+ messages in thread
From: Eli Zaretskii @ 2013-09-19 13:38 UTC (permalink / raw)
  To: emacs-devel

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

I need help from experts here on Emacs input in general and Emacs TTY
input in particular.

I'm working on adding support for menus on text-mode frames.  The code
which displays drop-down and pop-up menus, displays help-echo for the
menu items (in the echo area), and returns the user selection is
written, debugged, and works fairly well; as a teaser, I attach below
a few snapshots from my development machine.

The problem is how to drive the movement between, and selection of,
the menu items with keyboard input (or with mouse a on TTYs that
support mouse).  What is needed, as a minimum, is to be able to read
simple cursor motion commands (up/down/left/right) and RET, and
convert them into appropriate movements/selection in the menu.  We
should support not only the C-f/C-b/C-n/C-p keys, but also the arrow
keys which typically produce more-or-less arbitrary escape sequences.

Which of the Emacs input routines should I use to get this to work?
There's a gazillion of read_SOMETHING functions in keyboard.c.  After
some reading of the code and the commentary, I decided that read_char
is the one I need, as it seems to be capable of both reading
single-character keys and mouse events.  Is there a better function?

Anyway, an attempt to use read_char didn't succeed: when that function
is called after dropping down the first menu, Emacs gets stuck inside
'select', which never returns, no matter how many keys I press.
(Well, it will probably return after 100000 sec., but I didn't wait.)
IOW, when called in this manner, read_char somehow doesn't sense that
keyboard input arrived.

Is this supposed to work?  (I'm developing this on Windows, so what I
see might be some Windows-specific issue; I could continue development
on Unix, if read_char is supposed to work in this situation on Posix
platforms.)

Note that read_char is called recursively here, because x-popup-menu
is itself called from read_char.  Is it possible that read_char does
not tolerate recursive calls?

If using read_char for this is not a good idea, then what else should
I use?

Just in case it matters, here's the interesting part of the backtrace
recorded when read_char was called from the menu code (some functions
below Fx_popup_menu are new functions I wrote, so you will be unable
to find them in the current trunk sources, but their names will
hopefully tell what they do):

  #7  0x01227dc0 in sys_select (nfds=1, rfds=0x82f018, wfds=0x0, efds=0x0,
      timeout=0x82eff0, ignored=0x0) at w32proc.c:2096
  #8  0x011c47cd in wait_reading_process_output (time_limit=0, nsecs=0,
      read_kbd=-1, do_display=true, wait_for_cell=55961626, wait_proc=0x0,
      just_wait_proc=0) at process.c:4552
  #9  0x010e9ef1 in kbd_buffer_get_event (kbp=0x82f0cc, used_mouse_menu=0x0,
      end_time=0x0) at keyboard.c:3879
  #10 0x010e6578 in read_event_from_main_queue (end_time=0x0,
      local_getcjmp=0x82f2c0, used_mouse_menu=0x0) at keyboard.c:2230
  #11 0x010e67af in read_decoded_event_from_main_queue (end_time=0x0,
      local_getcjmp=0x82f2c0, prev_event=55961626, used_mouse_menu=0x0)
      at keyboard.c:2294
  #12 0x010e7b62 in read_char (commandflag=-2, map=55961626,
      prev_event=55961626, used_mouse_menu=0x0, end_time=0x0) at keyboard.c:2881
  #13 0x010d06bd in read_menu_input (sf=0x356f4d0, x=0x82f434, y=0x82f430,
      first_time=0x82f3e3) at term.c:3168
  #14 0x010d0c76 in tty_menu_activate (menu=0x3a482a0, pane=0x82f7dc,
      selidx=0x82f7d8, x0=1, y0=1, txt=0x82f7c4,
      help_callback=0x10d1377 <tty_menu_help_callback>) at term.c:3353
  #15 0x010d1b7e in tty_menu_show (f=0x356f4d0, x=1, y=1, for_click=1,
      keymaps=1, title=19586025, error_name=0x82f8b8) at term.c:3751
  #16 0x01074fad in Fx_popup_menu (position=60067158, menu=58308814)
      at menu.c:1358
  #17 0x010f230c in read_char_x_menu_prompt (map=58308814, prev_event=60067158,
      used_mouse_menu=0x82fb6b) at keyboard.c:8381
  #18 0x010e7587 in read_char (commandflag=1, map=58308814,
      prev_event=60067158, used_mouse_menu=0x82fb6b, end_time=0x0)
      at keyboard.c:2754
  #19 0x010f3843 in read_key_sequence (keybuf=0x82fc60, bufsize=30,
      prompt=55961626, dont_downcase_last=false, can_return_switch_frame=true,
      fix_current_buffer=true) at keyboard.c:9069
  #20 0x010e498c in command_loop_1 () at keyboard.c:1436

And here are the teaser images:


[-- Attachment #2: TTY_menus_menubar1.png --]
[-- Type: image/png, Size: 23948 bytes --]

[-- Attachment #3: TTY_menus_menubar2.png --]
[-- Type: image/png, Size: 24000 bytes --]

[-- Attachment #4: TTY_menus_C-mode.png --]
[-- Type: image/png, Size: 44220 bytes --]

[-- Attachment #5: TTY_menus_modeline.png --]
[-- Type: image/png, Size: 19456 bytes --]

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

end of thread, other threads:[~2013-10-20  9:32 UTC | newest]

Thread overview: 40+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-19 13:38 Input for TTY menus Eli Zaretskii
2013-09-19 13:52 ` Masatake YAMATO
2013-09-19 14:33 ` Stefan Monnier
2013-09-19 15:47   ` Eli Zaretskii
2013-09-19 19:21     ` Stefan Monnier
2013-09-23 13:18       ` Eli Zaretskii
2013-09-23 14:43         ` Stefan Monnier
2013-09-21 14:56   ` Eli Zaretskii
2013-10-17  5:34 ` Darren Hoo
2013-10-17 15:49   ` Eli Zaretskii
2013-10-18  4:55     ` Darren Hoo
2013-10-18  6:49       ` Eli Zaretskii
2013-10-18  7:37         ` Darren Hoo
2013-10-18  9:13           ` Eli Zaretskii
2013-10-18 10:39             ` Darren Hoo
2013-10-18 13:38               ` Eli Zaretskii
2013-10-18 13:40               ` Eli Zaretskii
2013-10-19 18:38                 ` Darren Hoo
2013-10-19 18:58                 ` Darren Hoo
2013-10-19 19:07                   ` Darren Hoo
2013-10-20  9:32                     ` Jan Djärv
2013-10-18 14:11         ` Eli Zaretskii
2013-10-18 15:12           ` Stefan Monnier
2013-10-18 15:28             ` Eli Zaretskii
2013-10-18 18:17               ` Stefan Monnier
2013-10-19  8:40             ` Eli Zaretskii
2013-10-19 13:45               ` Stefan Monnier
2013-10-18 17:41         ` chad
2013-10-18 17:43           ` chad
2013-10-18 18:14           ` Eli Zaretskii
2013-10-18 19:26             ` Jan Djärv
2013-10-18 20:04             ` Stefan Monnier
2013-10-19  7:35               ` Eli Zaretskii
2013-10-19  9:43                 ` Eli Zaretskii
2013-10-19 13:40                   ` Stefan Monnier
2013-10-19 14:45                     ` Eli Zaretskii
2013-10-19 15:25                       ` Stefan Monnier
2013-10-19 16:32                         ` Eli Zaretskii
2013-10-19  8:58             ` Jan Djärv
2013-10-19  9:01               ` Eli Zaretskii

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

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

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