Author: stippi Date: 2010-05-14 17:53:09 +0200 (Fri, 14 May 2010) New Revision: 36811 Changeset: http://dev.haiku-os.org/changeset/36811/haiku Modified: haiku/trunk/headers/os/interface/InterfaceDefs.h haiku/trunk/headers/private/app/ServerProtocol.h haiku/trunk/src/kits/interface/InterfaceDefs.cpp haiku/trunk/src/servers/app/ProfileMessageSupport.cpp haiku/trunk/src/servers/app/ServerApp.cpp Log: Patch by Wim van der Meer: Implemented global Interface Kit function to retrieve the current mouse position and pressed buttons. I've changed the return code to status_t and added anal error checking, most of the rest of the file is not doing it, though... :-) Thanks, Wim! Modified: haiku/trunk/headers/os/interface/InterfaceDefs.h =================================================================== --- haiku/trunk/headers/os/interface/InterfaceDefs.h 2010-05-14 09:36:26 UTC (rev 36810) +++ haiku/trunk/headers/os/interface/InterfaceDefs.h 2010-05-14 15:53:09 UTC (rev 36811) @@ -10,6 +10,7 @@ #include <OS.h> class BRect; +class BPoint; // some handy UTF-8 characters @@ -380,6 +381,8 @@ void set_focus_follows_mouse_mode(mode_focus_follows_mouse mode); mode_focus_follows_mouse focus_follows_mouse_mode(); +status_t get_mouse(BPoint* screenWhere, uint32* buttons); + void set_accept_first_click(bool acceptFirstClick); bool accept_first_click(); Modified: haiku/trunk/headers/private/app/ServerProtocol.h =================================================================== --- haiku/trunk/headers/private/app/ServerProtocol.h 2010-05-14 09:36:26 UTC (rev 36810) +++ haiku/trunk/headers/private/app/ServerProtocol.h 2010-05-14 15:53:09 UTC (rev 36811) @@ -81,6 +81,8 @@ AS_BEGIN_RECT_TRACKING, AS_END_RECT_TRACKING, + + AS_GET_CURSOR_POSITION, // Window definitions AS_SHOW_WINDOW, Modified: haiku/trunk/src/kits/interface/InterfaceDefs.cpp =================================================================== --- haiku/trunk/src/kits/interface/InterfaceDefs.cpp 2010-05-14 09:36:26 UTC (rev 36810) +++ haiku/trunk/src/kits/interface/InterfaceDefs.cpp 2010-05-14 15:53:09 UTC (rev 36811) @@ -7,6 +7,7 @@ * Caz <turok2@xxxxxxxxxxxxxx> * Axel Dörfler, axeld@xxxxxxxxxxxxxxxx * Michael Lotz <mmlr@xxxxxxxx> + * Wim van der Meer <WPJvanderMeer@xxxxxxxxx> */ @@ -23,9 +24,10 @@ #include <ControlLook.h> #include <Font.h> #include <Menu.h> +#include <Point.h> #include <Roster.h> +#include <Screen.h> #include <ScrollBar.h> -#include <Screen.h> #include <String.h> #include <TextView.h> @@ -925,6 +927,42 @@ } +status_t +get_mouse(BPoint* screenWhere, uint32* buttons) +{ + if (screenWhere == NULL && buttons == NULL) + return B_BAD_VALUE; + + BPrivate::AppServerLink link; + link.StartMessage(AS_GET_CURSOR_POSITION); + + int32 code; + status_t ret = link.FlushWithReply(code); + if (ret != B_OK) + return ret; + if (code != B_OK) + return code; + + if (screenWhere != NULL) + ret = link.Read<BPoint>(screenWhere); + else { + BPoint dummy; + ret = link.Read<BPoint>(&dummy); + } + if (ret != B_OK) + return ret; + + if (buttons != NULL) + ret = link.Read<uint32>(buttons); + else { + uint32 dummy; + ret = link.Read<uint32>(&dummy); + } + + return ret; +} + + void set_accept_first_click(bool acceptFirstClick) { Modified: haiku/trunk/src/servers/app/ProfileMessageSupport.cpp =================================================================== --- haiku/trunk/src/servers/app/ProfileMessageSupport.cpp 2010-05-14 09:36:26 UTC (rev 36810) +++ haiku/trunk/src/servers/app/ProfileMessageSupport.cpp 2010-05-14 15:53:09 UTC (rev 36811) @@ -61,6 +61,8 @@ CODE(AS_BEGIN_RECT_TRACKING); CODE(AS_END_RECT_TRACKING); + + CODE(AS_GET_CURSOR_POSITION); // Window definitions CODE(AS_SHOW_WINDOW); Modified: haiku/trunk/src/servers/app/ServerApp.cpp =================================================================== --- haiku/trunk/src/servers/app/ServerApp.cpp 2010-05-14 09:36:26 UTC (rev 36810) +++ haiku/trunk/src/servers/app/ServerApp.cpp 2010-05-14 15:53:09 UTC (rev 36811) @@ -11,6 +11,7 @@ * Jérôme Duval, jerome.duval@xxxxxxx * Andrej Spielmann, <andrej.spielmann@xxxxxxxxxxxx> * Philippe Saint-Pierre, stpere@xxxxxxxxx + * Wim van der Meer, <WPJvanderMeer@xxxxxxxxx> */ @@ -1165,7 +1166,21 @@ break; } - + case AS_GET_CURSOR_POSITION: + { + STRACE(("ServerApp %s: Get Cursor position\n", Signature())); + // Returns + // 1) BPoint mouse location + // 2) int32 button state + BPoint where; + int32 buttons; + fDesktop->GetLastMouseState(&where, &buttons); + fLink.StartMessage(B_OK); + fLink.Attach<BPoint>(where); + fLink.Attach<int32>(buttons); + fLink.Flush(); + break; + } case AS_GET_SCROLLBAR_INFO: { STRACE(("ServerApp %s: Get ScrollBar info\n", Signature()));