Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mouse input from PDCurses application not working #7594

Closed
thomthom opened this issue Sep 10, 2020 · 10 comments
Closed

Mouse input from PDCurses application not working #7594

thomthom opened this issue Sep 10, 2020 · 10 comments
Labels
Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing.

Comments

@thomthom
Copy link

thomthom commented Sep 10, 2020

Environment

Windows build number: Microsoft Windows [Version 10.0.19041.450]
Windows Terminal version (if applicable): 1.2.2381.0

Any other software?
PDCurses: https://github.com/wmcbrine/PDCurses @ 618e0aa

Steps to reproduce

# CMakeLists.txt
cmake_minimum_required(VERSION 3.17)

project(CursesTest VERSION 0.1.0 LANGUAGES CXX C)

find_package(Curses REQUIRED)

set(MOUSECURSE_SOURCES
  mousecurse.cpp
)

add_executable(mousecurse ${MOUSECURSE_SOURCES})
target_link_libraries(mousecurse
  curses
)
target_compile_definitions(mousecurse PRIVATE PDC_NCMOUSE)
// mousecurse.cpp
#include <iomanip>
#include <iostream>

#include <curses.h>

void print_input(int input);

int main()
{
  initscr();
  raw();
  keypad(stdscr, TRUE);
  noecho();

  mousemask(BUTTON1_CLICKED, nullptr);

  move(1, 1);
  attron(A_BOLD);
  printw("PDCurses Mouse Test");
  attroff(A_BOLD);

  bool run = true;
  while(run) {
    refresh();
    int input = getch();

    switch(input) {
    case 'q':
      run = false;
      break;
    default:
      print_input(input);
    }
  }

  endwin();
  return 0;
}

void print_input(int input)
{
  move(3, 1);
  clrtoeol();
  printw("The pressed key is ");
  attron(A_BOLD);
  if (input & KEY_CODE_YES) {
    const char* name = keyname(input);
    printw("%i (%s)", input, name);

  } else if (input == KEY_MOUSE) {
    MEVENT event{};
    if(getmouse(&event) == OK) {
      const char* name = keyname(input);
      printw("%i (%s) [x: %i, y: %i, state: %lu]",
          input, name, event.x, event.y, event.bstate);
    }

  } else {
    printw("%i (%c)", input, input);
  }
  attroff(A_BOLD);
}

Expected behavior

I'm expecting the receive mouse input to the application. This works in normal cmd.exe:

mousecurse-cmd

Actual behavior

In Windows Terminal the mouse events doesn't reach the application, instead a text selection is made:

mousecurse-winterm

@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Sep 10, 2020
@jdebp
Copy link

jdebp commented Sep 10, 2020

If it helps in diagnosis, PDCurses uses ReadConsoleInput() to read mouse input events. https://github.com/wmcbrine/PDCurses/blob/48b0c1297529758a10a68aca0f904f90893f165d/wincon/pdckbd.c#L575

@DHowett
Copy link
Member

DHowett commented Sep 10, 2020

So, this is a /duplicate of #376! PDCurses applications are Windows applications using the Win32 console APIs to read mouse events, and we don't currently have support in the translation layer (which is also used by ssh and other terminal emulators on Windows) for translating Win32 mouse events from VT mouse events.

@ghost
Copy link

ghost commented Sep 10, 2020

Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!

@ghost ghost closed this as completed Sep 10, 2020
@ghost ghost added Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing. and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Sep 10, 2020
@thomthom
Copy link
Author

Ok, I'm subscribing to the other issue. Thanks for confirming.

Are there other libraries that are currently able to achieve this in Windows Terminal? (PDCurses was the main library I found that has a working Windows implementation. ncurses seems to not support Windows.)

@DHowett
Copy link
Member

DHowett commented Sep 10, 2020

That's a good question. I'm not sure of that off the top of my head...
In general, anything that wants to use VT is going to be a little easier to wrangle, and be a bit more cross-platform, but was likely not originally developed for Windows. 😄

@thomthom
Copy link
Author

What does "VT" stand for?

@DHowett
Copy link
Member

DHowett commented Sep 10, 2020

Ah, sorry. "Virtual Terminal". I typically call the in-band signalling sequences that terminals use to communicate (and applications use to communicate with terminals) "VT", though I can't determine why I do that. They do things like set color, request input mode changes ("encode these keys differently", "i want mouse input", etc.), and a whole heap of other things.

Broadly and loosely, they're the cross-platform alternative to the Win32 console APIs. Where somebody might say SetConsoleTextAttribute(FOREGROUND_RED) on Windows, they might print out the string \e[31m everywhere else.

@DHowett
Copy link
Member

DHowett commented Sep 10, 2020

(This is very broad, and very loose, but it serves to illustrate the point. jdebp could almost certainly furnish a better explanation than the one that I spent 50 seconds on 😄)

@thomthom
Copy link
Author

So, I could use this "Virtual Terminal" from my app to get mouse events in Windows Terminal, as a workaround until WT supports it?

If so, what APIs would I be looking at?

@jdebp
Copy link

jdebp commented Sep 15, 2020

"VT" in this context usually comes from the product names of the DEC VT range of computer terminals, the VT05 to the VT525. It stands for "video terminal", in opposition to a paper or a hardcopy terminal.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing.
Projects
None yet
Development

No branches or pull requests

3 participants