Skip to content

[Bug]: context menu on Ubuntu/x11 in the top left of the screen on 29.0.0-beta.3 #41143

Closed

Description

@Kilian

Preflight Checklist

Electron Version

29.0.0-beta.3

What operating system are you using?

Ubuntu

Operating System Version

Ubuntu 23.04

What arch are you using?

x64

Last Known Working Electron version

29.0.0-beta.2

Expected Behavior

The context menu is located next to the pointer cursor, screenshot from 29.0.0-beta.2

Screenshot from 2024-01-26 16-12-40

Actual Behavior

The context menu appears in the top left of the screen when using 29.0.0-beta.3
Screenshot from 2024-01-26 16-13-01

Testcase Gist URL

https://gist.github.com/ad3013a440b58351f3c496923a0ea2d6

Additional Information

This is using X11

Activity

  1. moved this to 👀 Unsorted Items in 29-x-yon Jan 26, 2024
  2. added
    bug/regression ↩️
    on Jan 26, 2024
  3. self-assigned this
    on Jan 31, 2024
  4. moved this from 👀 Unsorted Items to 🛑 Blocks Stable in 29-x-yon Jan 31, 2024
  5. Kilian commented on Feb 1, 2024

    @Kilian
    MemberAuthor

    Still present in beta.4 and beta.5 as well.

  6. ckerr commented on Feb 7, 2024

    @ckerr
    Member
  7. ckerr commented on Feb 7, 2024

    @ckerr
    Member

    Haven't tracked down the root cause, but here's a breadcrumb:

    In MenuViews::PopupAt(),

      // (-1, -1) means showing on mouse location.
      gfx::Point location;
      if (x == -1 || y == -1) {
        location = display::Screen::GetScreen()->GetCursorScreenPoint();
      } else {
        gfx::Point origin = native_window->GetContentBounds().origin();
        location = gfx::Point(origin.x() + x, origin.y() + y);
      }

    display::Screen::GetScreen()->GetCursorScreenPoint() is returning meaningful values in 29.0.0-beta.2, but 0, 0 in beta.3.

  8. ckerr commented on Feb 7, 2024

    @ckerr
    Member

    X11ScreenOzone::GetCursorScreenPoint() is returning 0,0 (which it gets from ui::X11EventSource::GetInstance()->last_cursor_location()) after for us after https://chromium-review.googlesource.com/c/chromium/src/+/5214873 .

    Though the function does work in its invocations up until the moment we create a popup, so it may be that we need to change the order of our actions when creating a popup 🤔

  9. ckerr commented on Feb 7, 2024

    @ckerr
    Member

    Just leaving more breadcrumbs: I noticed there had been some followup changes to the upstream ui/gfx/ code so I tested out the gist Electron main -- expecting it to work, so that I could find the right commit to cherry-pick back to e29 -- but it's still broken in v30.0.0-nightly.20240207

  10. ckerr commented on Feb 8, 2024

    @ckerr
    Member

    One workaround is to pass in the same x, y that came from the context-menu props:

      mainWindow.webContents.on('context-menu', (event, props) => {
        const { x, y } = props;
        const template = [ 
          { label: 'Edit', }, 
          { label: 'Hello From Electron!' }
        ]
        Menu.buildFromTemplate(template).popup({ window: mainWindow, x, y });
      });

    That avoids the broken lookup.

  11. ckerr commented on Feb 8, 2024

    @ckerr
    Member

    Every 0,0 that I'm seeing is coming from GetRootCursorLocationFromEvent() in ui/events/platform/x11/x11_event_source.cc returning 0,0 whenever it receives an x11::Input::CrossingEvent.

        } else if (crossing &&
                   (crossing->opcode == x11::Input::CrossingEvent::Enter ||
                    crossing->opcode == x11::Input::CrossingEvent::Leave)) {
          is_valid_event = touch_factory->ShouldProcessCrossingEvent(*crossing);
          std::cerr << __FILE__ << ':' << __LINE__ << " is valid" << std::endl;
        }

    It gets the value from EventSystemLocationFromXEvent() which returns root_x, root_y for CrossingEvents:

      gfx::Point EventSystemLocationFromXEvent(const x11::Event& xev) {
        if (auto* crossing = xev.As<x11::CrossingEvent>())
          return gfx::Point(crossing->root_x, crossing->root_y);
        if (auto* button = xev.As<x11::ButtonEvent>())
          return gfx::Point(button->root_x, button->root_y);
        if (auto* motion = xev.As<x11::MotionNotifyEvent>())
          return gfx::Point(motion->root_x, motion->root_y);
        if (auto* xievent = xev.As<x11::Input::DeviceEvent>()) {
          return gfx::Point(Fp1616ToDouble(xievent->root_x),
                            Fp1616ToDouble(xievent->root_y));
        }
        return gfx::Point();
      }

    And this seems pretty reasonable. https://tronche.com/gui/x/xlib/events/window-entry-exit/ describes those fields:

    The x_root and y_root members are set to the pointer's coordinates relative to the root window's origin at the time of the event.

  12. ckerr commented on Feb 8, 2024

    @ckerr
    Member

    OK I found it. It's an upstream bug.

    There are two different CrossingEvent classes: x11::Input::CrossingEvent and x11::CrossingEvent.

    In ui/events/platform/x11/x11_event_source.cc , GetRootCursorLocationFromEvent() calls ui::EventSystemLocationFromXEvent() on an event if it's the former. But EventLocationFromXEvent() igores that type and looks for the latter.

    IDK why there are two types but this mismatch is the root of the problem & it can be resolved by checking for x11::Input::CrossingEvent in EventTimeFromXEvent(). We can add a patches/chromium/ patch to fix this for e29 and submit a fix upstream.

  13. moved this from 🛑 Blocks Stable to 🛠️ Fixed for Next Release in 29-x-yon Feb 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions