From df7d26ff5b89ce9852813abd370d1357aab1501b Mon Sep 17 00:00:00 2001 From: hurikhan Date: Thu, 12 Feb 2015 15:58:00 +0100 Subject: [PATCH] cleanup + MouseGrab --- demos/misc/window_management/control.gd | 2 + .../window_management/window_management.scn | Bin 4744 -> 4850 bytes platform/x11/os_x11.cpp | 79 +++++++----------- platform/x11/os_x11.h | 1 + 4 files changed, 35 insertions(+), 47 deletions(-) diff --git a/demos/misc/window_management/control.gd b/demos/misc/window_management/control.gd index d329237aed..50fc3a3765 100644 --- a/demos/misc/window_management/control.gd +++ b/demos/misc/window_management/control.gd @@ -28,6 +28,8 @@ func _fixed_process(delta): get_node("Label_Size").set_text(str("Size:\n", OS.get_window_size() ) ) + get_node("Label_MousePosition").set_text(str("Mouse Position:\n", Input.get_mouse_pos() ) ) + get_node("Label_Screen_Count").set_text( str("Screen_Count:\n", OS.get_screen_count() ) ) get_node("Label_Screen_Current").set_text( str("Screen:\n", OS.get_screen() ) ) diff --git a/demos/misc/window_management/window_management.scn b/demos/misc/window_management/window_management.scn index bf7a0871e7c6ad7c8ab50d4335408fc8eb7f8867..14d0da04151608996f142d02c9c55befed508601 100644 GIT binary patch delta 2672 zcmeBB{iG@v6zuHG00IIG4EGHg7!I>DFx+EfV0g>Kz~I0*QSKlML!tun#>W}V^>Gb+ ziNOyT)SUJ-h&LKC#ycxaW++Lve84KkR9aM|P?*&BfLVgUz_FSsKc_UI*jeQPtIPw2 zbf;qvn57sD9|)T>7(QS$cRs}GnOl&PnyXOj^qDcwMRf{eetPmhCdcGtl@AL9T>r5Y zjQq- zX2AyxvTnB?Fj+UgW-xdlD#u{>fI-gD)R9kR3PZ7CBO?Q|BA*ARgShKd6;YP}5l{^?zi!}lsFl%_6RTR_AOb~PM zcCdH&#*n<|w?nW)`~mUKtquDR=sRpzH5b%$Q4~4Z?_l8A*dXzevsrV~T z=kVM?UTYmoMt*vJo_gct>ujdd-Ykb@J107K9op?6tK7_-SejF^dWqAl1G4T9C#$n- zDBOL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ed|;B%C8-r&IC{KA3z@D~SZ2kr;V3=W|RUJ23;@(%hA38`47lD zXg^?Pa0+x_b|_~MP>^`QZtalm;O@%k;O;!%f!~GC!Q9o}f#0>qfj!h|zk{~xZU=UU zUC$v6nGq%9cDYoADDe$GK08+yhFV!hXcE7 zkHcb@4-V|!G7i%jWE9jLrZdPYusf)GJ4}AXYvtuw?Qq|L!C|oj1A~?V3xlQtv%_JB z`47YoJ8X88cG&E|?y%WW*)X{gWPu<#vX6jaz3b+O%)+kHATsztg&hw+low|5 zVqkb^Bg`PB;Qo+Vn88?q|6#E(gNZ`@Lw#WeZv|_H{|XEa`yUyr9~C}q&0wk!4l?9X zwz^0ALw#W;AFyUe?nlh(9_9~=h21ZMwD~@?6FwI1UhSIfHveIe)TR9T*tIK(Xh%m?2bwU11Z$f5+wr%$q&GKj7Z%eBNQR!(#_y&&dv(J=z~g zZ*~ZOz`ohn-%;9mv6s2Cy8B^gc?WT)set_mouse_pos(center); + } } void OS_X11::warp_mouse_pos(const Point2& p_to) { @@ -724,44 +727,10 @@ void OS_X11::set_window_size(const Size2 p_size) { } void OS_X11::set_fullscreen(bool p_enabled) { - -#if 0 - if(p_enabled && current_videomode.fullscreen) - return; - - if(!current_videomode.resizable) - set_resizable(true); - - if(p_enabled) { - window_data.size = get_window_size(); - window_data.position = get_window_position(); - - int screen = get_screen(); - Size2i size = get_screen_size(screen); - Point2i position = get_screen_position(screen); - - set_wm_border(false); - set_wm_fullscreen(true); - XMoveResizeWindow(x11_display, x11_window, position.x, position.y, size.x, size.y); - - current_videomode.fullscreen = True; - } else { - set_wm_fullscreen(false); - set_wm_border(true); - XMoveResizeWindow(x11_display, x11_window, - window_data.position.x, - window_data.position.y, - window_data.size.width, - window_data.size.height); - - current_videomode.fullscreen = False; - } -#endif set_wm_fullscreen(p_enabled); current_videomode.fullscreen = p_enabled; visual_server->init(); - } bool OS_X11::is_fullscreen() const { @@ -1209,7 +1178,7 @@ void OS_X11::process_xevents() { event.xbutton.x=last_mouse_pos.x; event.xbutton.y=last_mouse_pos.y; } - + InputEvent mouse_event; mouse_event.ID=++event_id; mouse_event.type = InputEvent::MOUSE_BUTTON; @@ -1244,7 +1213,7 @@ void OS_X11::process_xevents() { last_click_ms+=diff; last_click_pos = Point2(event.xbutton.x,event.xbutton.y); } - } + } input->parse_input_event( mouse_event); @@ -1254,11 +1223,10 @@ void OS_X11::process_xevents() { last_timestamp=event.xmotion.time; - + // Motion is also simple. // A little hack is in order // to be able to send relative motion events. - Point2i pos( event.xmotion.x, event.xmotion.y ); if (mouse_mode==MOUSE_MODE_CAPTURED) { @@ -1273,7 +1241,7 @@ void OS_X11::process_xevents() { } Point2i new_center = pos; - pos = last_mouse_pos + ( pos-center ); + pos = last_mouse_pos + ( pos - center ); center=new_center; do_mouse_warp=true; #else @@ -1287,9 +1255,7 @@ void OS_X11::process_xevents() { XWarpPointer(x11_display, None, x11_window, 0,0,0,0, (int)center.x, (int)center.y); #endif - } - if (!last_mouse_pos_valid) { @@ -1298,7 +1264,14 @@ void OS_X11::process_xevents() { } Point2i rel = pos - last_mouse_pos; - + +#ifdef EXPERIMENTAL_WM_API + if (mouse_mode==MOUSE_MODE_CAPTURED) { + pos.x = current_videomode.width / 2; + pos.y = current_videomode.height / 2; + } +#endif + InputEvent motion_event; motion_event.ID=++event_id; motion_event.type=InputEvent::MOUSE_MOTION; @@ -1309,7 +1282,7 @@ void OS_X11::process_xevents() { motion_event.mouse_motion.x=pos.x; motion_event.mouse_motion.y=pos.y; input->set_mouse_pos(pos); - motion_event.mouse_motion.global_x=pos.x; + motion_event.mouse_motion.global_x=pos.y; motion_event.mouse_motion.global_y=pos.y; motion_event.mouse_motion.speed_x=input->get_mouse_speed().x; motion_event.mouse_motion.speed_y=input->get_mouse_speed().y; @@ -1318,6 +1291,8 @@ void OS_X11::process_xevents() { motion_event.mouse_motion.relative_y=rel.y; last_mouse_pos=pos; + + // printf("rel: %d,%d\n", rel.x, rel.y ); input->parse_input_event( motion_event); @@ -1392,8 +1367,18 @@ void OS_X11::process_xevents() { if (do_mouse_warp) { XWarpPointer(x11_display, None, x11_window, - 0,0,0,0, (int)current_videomode.width/2, (int)current_videomode.height/2); + 0,0,0,0, (int)current_videomode.width/2, (int)current_videomode.height/2); + /* + Window root, child; + int root_x, root_y; + int win_x, win_y; + unsigned int mask; + XQueryPointer( x11_display, x11_window, &root, &child, &root_x, &root_y, &win_x, &win_y, &mask ); + + printf("Root: %d,%d\n", root_x, root_y); + printf("Win: %d,%d\n", win_x, win_y); + */ } } diff --git a/platform/x11/os_x11.h b/platform/x11/os_x11.h index b47c5db069..7518c93562 100644 --- a/platform/x11/os_x11.h +++ b/platform/x11/os_x11.h @@ -160,6 +160,7 @@ class OS_X11 : public OS_Unix { Joystick joysticks[JOYSTICKS_MAX]; #ifdef EXPERIMENTAL_WM_API + unsigned int capture_idle; bool maximized; //void set_wm_border(bool p_enabled); void set_wm_fullscreen(bool p_enabled);