Merge pull request #20385 from moiman100/unify-double-clicking
Added double clicking to all buttons on Linux and Javascript
This commit is contained in:
commit
5f32fc8208
|
@ -295,6 +295,30 @@ EM_BOOL OS_JavaScript::mouse_button_callback(int p_event_type, const EmscriptenM
|
|||
default: return false;
|
||||
}
|
||||
|
||||
if (ev->is_pressed()) {
|
||||
|
||||
uint64_t diff = p_event->timestamp - os->last_click_ms;
|
||||
|
||||
if (ev->get_button_index() == os->last_click_button_index) {
|
||||
|
||||
if (diff < 400 && Point2(os->last_click_pos).distance_to(ev->get_position()) < 5) {
|
||||
|
||||
os->last_click_ms = 0;
|
||||
os->last_click_pos = Point2(-100, -100);
|
||||
os->last_click_button_index = -1;
|
||||
ev->set_doubleclick(true);
|
||||
}
|
||||
|
||||
} else {
|
||||
os->last_click_button_index = ev->get_button_index();
|
||||
}
|
||||
|
||||
if (!ev->is_doubleclick()) {
|
||||
os->last_click_ms += diff;
|
||||
os->last_click_pos = ev->get_position();
|
||||
}
|
||||
}
|
||||
|
||||
int mask = os->input->get_mouse_button_mask();
|
||||
int button_flag = 1 << (ev->get_button_index() - 1);
|
||||
if (ev->is_pressed()) {
|
||||
|
@ -1070,6 +1094,10 @@ OS_JavaScript::OS_JavaScript(int p_argc, char *p_argv[]) {
|
|||
}
|
||||
set_cmdline(p_argv[0], arguments);
|
||||
|
||||
last_click_button_index = -1;
|
||||
last_click_ms = 0;
|
||||
last_click_pos = Point2(-100, -100);
|
||||
|
||||
window_maximized = false;
|
||||
entering_fullscreen = false;
|
||||
just_exited_fullscreen = false;
|
||||
|
|
|
@ -52,6 +52,10 @@ class OS_JavaScript : public OS_Unix {
|
|||
CursorShape cursor_shape;
|
||||
Point2 touches[32];
|
||||
|
||||
Point2i last_click_pos;
|
||||
uint64_t last_click_ms;
|
||||
int last_click_button_index;
|
||||
|
||||
MainLoop *main_loop;
|
||||
AudioDriverJavaScript audio_driver_javascript;
|
||||
|
||||
|
|
|
@ -96,6 +96,8 @@ Error OS_X11::initialize(const VideoMode &p_desired, int p_video_driver, int p_a
|
|||
xmbstring = NULL;
|
||||
x11_window = 0;
|
||||
last_click_ms = 0;
|
||||
last_click_button_index = -1;
|
||||
last_click_pos = Point2(-100, -100);
|
||||
args = OS::get_singleton()->get_cmdline_args();
|
||||
current_videomode = p_desired;
|
||||
main_loop = NULL;
|
||||
|
@ -1958,17 +1960,25 @@ void OS_X11::process_xevents() {
|
|||
|
||||
mb->set_pressed((event.type == ButtonPress));
|
||||
|
||||
if (event.type == ButtonPress && event.xbutton.button == 1) {
|
||||
if (event.type == ButtonPress) {
|
||||
|
||||
uint64_t diff = get_ticks_usec() / 1000 - last_click_ms;
|
||||
|
||||
if (diff < 400 && Point2(last_click_pos).distance_to(Point2(event.xbutton.x, event.xbutton.y)) < 5) {
|
||||
if (mb->get_button_index() == last_click_button_index) {
|
||||
|
||||
last_click_ms = 0;
|
||||
last_click_pos = Point2(-100, -100);
|
||||
mb->set_doubleclick(true);
|
||||
if (diff < 400 && Point2(last_click_pos).distance_to(Point2(event.xbutton.x, event.xbutton.y)) < 5) {
|
||||
|
||||
} else {
|
||||
last_click_ms = 0;
|
||||
last_click_pos = Point2(-100, -100);
|
||||
last_click_button_index = -1;
|
||||
mb->set_doubleclick(true);
|
||||
}
|
||||
|
||||
} else if (mb->get_button_index() < 4 || mb->get_button_index() > 7) {
|
||||
last_click_button_index = mb->get_button_index();
|
||||
}
|
||||
|
||||
if (!mb->is_doubleclick()) {
|
||||
last_click_ms += diff;
|
||||
last_click_pos = Point2(event.xbutton.x, event.xbutton.y);
|
||||
}
|
||||
|
|
|
@ -125,6 +125,7 @@ class OS_X11 : public OS_Unix {
|
|||
bool last_mouse_pos_valid;
|
||||
Point2i last_click_pos;
|
||||
uint64_t last_click_ms;
|
||||
int last_click_button_index;
|
||||
uint32_t last_button_state;
|
||||
#ifdef TOUCH_ENABLED
|
||||
struct {
|
||||
|
|
Loading…
Reference in New Issue