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

onClick triggers on mouse release, not on press #38

Closed
end-4 opened this issue Aug 11, 2023 · 3 comments
Closed

onClick triggers on mouse release, not on press #38

end-4 opened this issue Aug 11, 2023 · 3 comments

Comments

@end-4
Copy link
Contributor

end-4 commented Aug 11, 2023

  • The function assigned to onClick runs when the mouse button is released, not pressed
  • This makes interaction feel slower
  • Can we have onClick for mouse press and onClickRelease for release?
@Aylur
Copy link
Owner

Aylur commented Aug 11, 2023

I was actually thinking of removing that property altogether with onSecondaryClick and onMiddleClick props too, and just mention in the wiki how to use the Gtk native signal, but that is a better idea, for better DX.

in the meantime this how you can achieve this

const { Gdk } = imports.gi;

const button = {
    type: 'button',
    // 'button-release-event' for the release event
    connections: [['button-press-event', (widget, event) => {
        const button = event.get_button()[1]; // event is a Gdk.Event

        if (button === Gdk.BUTTON_SECONDARY)
            print('right click'); // assuming right handed mouse

        if (button === Gdk.BUTTON_MIDDLE)
            print('middle click');

        if (button === Gdk.BUTTON_PRIMARY)
            print('left click');
    }]],
};

Aylur added a commit that referenced this issue Aug 11, 2023
@end-4
Copy link
Contributor Author

end-4 commented Aug 11, 2023

that worked, thanks

@Aylur
Copy link
Owner

Aylur commented Aug 11, 2023

I have implemented your suggestion for button and eventbox, also updated the wiki

@Aylur Aylur closed this as completed Aug 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants