summaryrefslogtreecommitdiffstats
path: root/src/VBox/Additions/haiku/VBoxMouse
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-11 08:17:27 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-11 08:17:27 +0000
commitf215e02bf85f68d3a6106c2a1f4f7f063f819064 (patch)
tree6bb5b92c046312c4e95ac2620b10ddf482d3fa8b /src/VBox/Additions/haiku/VBoxMouse
parentInitial commit. (diff)
downloadvirtualbox-c31cb7e733ae8e33d73383e04db264d4293f0b1a.tar.xz
virtualbox-c31cb7e733ae8e33d73383e04db264d4293f0b1a.zip
Adding upstream version 7.0.14-dfsg.upstream/7.0.14-dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/VBox/Additions/haiku/VBoxMouse')
-rw-r--r--src/VBox/Additions/haiku/VBoxMouse/Makefile.kmk90
-rw-r--r--src/VBox/Additions/haiku/VBoxMouse/VBoxMouse.cpp318
-rw-r--r--src/VBox/Additions/haiku/VBoxMouse/VBoxMouse.h91
-rw-r--r--src/VBox/Additions/haiku/VBoxMouse/VBoxMouseFilter.cpp117
-rw-r--r--src/VBox/Additions/haiku/VBoxMouse/VBoxMouseFilter.h87
5 files changed, 703 insertions, 0 deletions
diff --git a/src/VBox/Additions/haiku/VBoxMouse/Makefile.kmk b/src/VBox/Additions/haiku/VBoxMouse/Makefile.kmk
new file mode 100644
index 00000000..f8089e11
--- /dev/null
+++ b/src/VBox/Additions/haiku/VBoxMouse/Makefile.kmk
@@ -0,0 +1,90 @@
+# $Id: Makefile.kmk $
+## @file
+# Sub-Makefile for VBoxMouse, Haiku Additions.
+#
+
+#
+# Copyright (C) 2012-2023 Oracle and/or its affiliates.
+#
+# This file is part of VirtualBox base platform packages, as
+# available from https://www.virtualbox.org.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation, in version 3 of the
+# License.
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, see <https://www.gnu.org/licenses>.
+#
+# SPDX-License-Identifier: GPL-3.0-only
+#
+
+#
+# This code is based on:
+#
+# VirtualBox Guest Additions for Haiku.
+# Copyright (c) 2011 Mike Smith <mike@scgtrp.net>
+# François Revol <revol@free.fr>
+#
+# Permission is hereby granted, free of charge, to any person
+# obtaining a copy of this software and associated documentation
+# files (the "Software"), to deal in the Software without
+# restriction, including without limitation the rights to use,
+# copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the
+# Software is furnished to do so, subject to the following
+# conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+# OTHER DEALINGS IN THE SOFTWARE.
+#
+
+SUB_DEPTH = ../../../../..
+include $(KBUILD_PATH)/subheader.kmk
+
+# @todo split the mouse code to communicate with VBoxMouse/VBoxService
+# to allow building with gcc2.
+# R1 will need gcc2-built input_server add-ons.
+
+PROGRAMS += VBoxMouse
+VBoxMouse_TEMPLATE = VBoxGuestR3Exe
+VBoxMouse_DEFS = VBOX_WITH_HGCM LOG_TO_BACKDOOR
+VBoxMouse_DEFS += LOG_ENABLED
+VBoxMouse_INCS = ../include
+VBoxMouse_SOURCES = \
+ VBoxMouse.cpp
+
+VBoxMouse_LIBS = \
+ be \
+ device \
+ $(VBOX_LIB_IPRT_GUEST_R3) \
+ $(VBOX_LIB_VBGL_R3) \
+ /system/servers/input_server
+
+PROGRAMS += VBoxMouseFilter
+VBoxMouseFilter_TEMPLATE = VBoxGuestR3Exe
+VBoxMouseFilter_DEFS = VBOX_WITH_HGCM LOG_TO_BACKDOOR
+VBoxMouseFilter_DEFS += LOG_ENABLED
+VBoxMouseFilter_INCS = ../include
+VBoxMouseFilter_SOURCES = \
+ VBoxMouseFilter.cpp
+
+VBoxMouseFilter_LIBS = $(VBoxMouse_LIBS)
+
+include $(KBUILD_PATH)/subfooter.kmk
+
diff --git a/src/VBox/Additions/haiku/VBoxMouse/VBoxMouse.cpp b/src/VBox/Additions/haiku/VBoxMouse/VBoxMouse.cpp
new file mode 100644
index 00000000..50261a45
--- /dev/null
+++ b/src/VBox/Additions/haiku/VBoxMouse/VBoxMouse.cpp
@@ -0,0 +1,318 @@
+/* $Id: VBoxMouse.cpp $ */
+/** @file
+ * VBoxMouse; input_server add-on - Haiku Guest Additions, implementation.
+ */
+
+/*
+ * Copyright (C) 2012-2023 Oracle and/or its affiliates.
+ *
+ * This file is part of VirtualBox base platform packages, as
+ * available from https://www.virtualbox.org.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, in version 3 of the
+ * License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <https://www.gnu.org/licenses>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+/*
+ * This code is based on:
+ *
+ * VirtualBox Guest Additions for Haiku.
+ * Copyright (c) 2011 Mike Smith <mike@scgtrp.net>
+ * François Revol <revol@free.fr>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <Clipboard.h>
+#include <Debug.h>
+#include <Message.h>
+#include <String.h>
+
+#include "VBoxMouse.h"
+#include <VBox/VBoxGuest.h> /** @todo use the VbglR3 interface! */
+#include <VBox/VBoxGuestLib.h>
+#include <VBoxGuestInternal.h>
+#include <VBox/VMMDev.h>
+#include <VBox/log.h>
+#include <iprt/errcore.h>
+
+/* Export as global symbol with C linkage, RTDECL is necessary. */
+RTDECL(BInputServerDevice *)
+instantiate_input_device()
+{
+ return new VBoxMouse();
+}
+
+
+static inline int vboxMouseAcquire()
+{
+ uint32_t fFeatures = 0;
+ int rc = VbglR3GetMouseStatus(&fFeatures, NULL, NULL);
+ if (RT_SUCCESS(rc))
+ {
+ rc = VbglR3SetMouseStatus(fFeatures | VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE | VMMDEV_MOUSE_NEW_PROTOCOL);
+ if (RT_FAILURE(rc))
+ LogRel(("VbglR3SetMouseStatus failed. rc=%d\n", rc));
+ }
+ else
+ LogRel(("VbglR3GetMouseStatus failed. rc=%d\n", rc));
+ return rc;
+}
+
+
+static inline int vboxMouseRelease()
+{
+ uint32_t fFeatures = 0;
+ int rc = VbglR3GetMouseStatus(&fFeatures, NULL, NULL);
+ if (RT_SUCCESS(rc))
+ {
+ rc = VbglR3SetMouseStatus(fFeatures & ~VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE & ~VMMDEV_MOUSE_NEW_PROTOCOL);
+ if (RT_FAILURE(rc))
+ LogRel(("VbglR3SetMouseStatus failed. rc=%d\n", rc));
+ }
+ else
+ LogRel(("VbglR3GetMouseStatus failed. rc=%d\n", rc));
+ return rc;
+}
+
+
+VBoxMouse::VBoxMouse()
+ : BInputServerDevice(),
+ fDriverFD(-1),
+ fServiceThreadID(-1),
+ fExiting(false)
+{
+}
+
+
+VBoxMouse::~VBoxMouse()
+{
+}
+
+
+status_t VBoxMouse::InitCheck()
+{
+ int rc = VbglR3Init();
+ if (!RT_SUCCESS(rc))
+ return ENXIO;
+
+ input_device_ref device = { (char *)"VBoxMouse", B_POINTING_DEVICE, (void *)this };
+ input_device_ref *deviceList[2] = { &device, NULL };
+ RegisterDevices(deviceList);
+
+ return B_OK;
+}
+
+
+status_t VBoxMouse::SystemShuttingDown()
+{
+ VbglR3Term();
+
+ return B_OK;
+}
+
+
+status_t VBoxMouse::Start(const char *device, void *cookie)
+{
+#if 0
+ status_t err;
+ int rc;
+ uint32_t fFeatures = 0;
+ Log(("VBoxMouse::%s()\n", __FUNCTION__));
+
+ rc = VbglR3GetMouseStatus(&fFeatures, NULL, NULL);
+ if (RT_SUCCESS(rc))
+ rc = VbglR3SetMouseStatus(fFeatures
+ | VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE
+ | VMMDEV_MOUSE_NEW_PROTOCOL);
+ if (!RT_SUCCESS(rc))
+ {
+ LogRel(("VBoxMouse: Error switching guest mouse into absolute mode: %d\n", rc));
+ return B_DEVICE_NOT_FOUND;
+ }
+
+ err = fServiceThreadID = spawn_thread(_ServiceThreadNub,
+ "VBoxMouse", B_NORMAL_PRIORITY, this);
+ if (err >= B_OK)
+ {
+ resume_thread(fServiceThreadID);
+ return B_OK;
+ }
+ else
+ LogRel(("VBoxMouse: Error starting service thread: 0x%08lx\n",
+ err));
+
+ // release the mouse
+ rc = VbglR3GetMouseStatus(&fFeatures, NULL, NULL);
+ if (RT_SUCCESS(rc))
+ rc = VbglR3SetMouseStatus(fFeatures
+ & ~VMMDEV_MOUSE_GUEST_CAN_ABSOLUTE
+ & ~VMMDEV_MOUSE_NEW_PROTOCOL);
+
+ return B_ERROR;
+#endif
+
+ status_t err = B_OK;
+ int rc;
+ uint32_t fFeatures = 0;
+ LogFlowFunc(("device=%s cookie=%p\n", device, cookie));
+
+ rc = vboxMouseAcquire();
+ if (RT_SUCCESS(rc))
+ {
+ err = fServiceThreadID = spawn_thread(_ServiceThreadNub, "VBoxMouse", B_NORMAL_PRIORITY, this);
+ if (err >= B_OK)
+ {
+ resume_thread(fServiceThreadID);
+ return B_OK;
+ }
+ else
+ LogRel(("VBoxMouse::Start Error starting service thread: 0x%08lx\n", err));
+
+ vboxMouseRelease();
+ err = B_ERROR;
+ }
+ else
+ {
+ LogRel(("VBoxMouse::Start vboxMouseAcquire failed. rc=%d\n", rc));
+ err = B_DEVICE_NOT_FOUND;
+ }
+
+ return err;
+}
+
+
+status_t VBoxMouse::Stop(const char *device, void *cookie)
+{
+ status_t status;
+ int rc;
+ uint32_t fFeatures = 0;
+ Log(("VBoxMouse::%s()\n", __FUNCTION__));
+
+ fExiting = true;
+
+ vboxMouseRelease();
+
+ close(fDriverFD);
+ fDriverFD = -1;
+ //XXX WTF ?
+ suspend_thread(fServiceThreadID);
+ resume_thread(fServiceThreadID);
+ wait_for_thread(fServiceThreadID, &status);
+ fServiceThreadID = -1;
+ fExiting = false;
+ return B_OK;
+}
+
+
+status_t VBoxMouse::Control(const char *device, void *cookie, uint32 code, BMessage *message)
+{
+ switch (code)
+ {
+ case B_MOUSE_SPEED_CHANGED:
+ case B_CLICK_SPEED_CHANGED:
+ case B_MOUSE_ACCELERATION_CHANGED:
+ default:
+ return BInputServerDevice::Control(device, cookie, code, message);
+ }
+ return B_OK;
+}
+
+
+status_t VBoxMouse::_ServiceThreadNub(void *_this)
+{
+ VBoxMouse *service = (VBoxMouse *)_this;
+ return service->_ServiceThread();
+}
+
+
+status_t VBoxMouse::_ServiceThread()
+{
+ Log(("VBoxMouse::%s()\n", __FUNCTION__));
+
+ fDriverFD = open(VBOXGUEST_DEVICE_NAME, O_RDWR);
+ if (fDriverFD < 0)
+ return ENXIO;
+
+ /* The thread waits for incoming messages from the host. */
+ while (!fExiting)
+ {
+ uint32_t cx, cy, fFeatures;
+ int rc;
+
+ fd_set readSet, writeSet, errorSet;
+ FD_ZERO(&readSet);
+ FD_ZERO(&writeSet);
+ FD_ZERO(&errorSet);
+ FD_SET(fDriverFD, &readSet);
+ if (fDriverFD < 0)
+ break;
+ rc = select(fDriverFD + 1, &readSet, &writeSet, &errorSet, NULL);
+ if (rc < 0)
+ {
+ if (errno == EINTR || errno == EAGAIN)
+ continue;
+ break;
+ }
+
+ rc = VbglR3GetMouseStatus(&fFeatures, &cx, &cy);
+ if ( RT_SUCCESS(rc)
+ && (fFeatures & VMMDEV_MOUSE_HOST_WANTS_ABSOLUTE))
+ {
+ float x = cx * 1.0 / 65535;
+ float y = cy * 1.0 / 65535;
+
+ _debugPrintf("VBoxMouse: at %d,%d %f,%f\n", cx, cy, x, y);
+
+ /* Send absolute movement */
+ bigtime_t now = system_time();
+ BMessage *event = new BMessage(B_MOUSE_MOVED);
+ event->AddInt64("when", now);
+ event->AddFloat("x", x);
+ event->AddFloat("y", y);
+ event->AddFloat("be:tablet_x", x);
+ event->AddFloat("be:tablet_y", y);
+ //event->PrintToStream();
+ EnqueueMessage(event);
+
+ //LogRelFlow(("processed host event rc = %d\n", rc));
+ }
+ }
+ return 0;
+}
+
diff --git a/src/VBox/Additions/haiku/VBoxMouse/VBoxMouse.h b/src/VBox/Additions/haiku/VBoxMouse/VBoxMouse.h
new file mode 100644
index 00000000..69a62b8a
--- /dev/null
+++ b/src/VBox/Additions/haiku/VBoxMouse/VBoxMouse.h
@@ -0,0 +1,91 @@
+/* $Id: VBoxMouse.h $ */
+/** @file
+ * VBoxMouse; input_server add-on - Haiku Guest Additions, header.
+ */
+
+/*
+ * Copyright (C) 2012-2023 Oracle and/or its affiliates.
+ *
+ * This file is part of VirtualBox base platform packages, as
+ * available from https://www.virtualbox.org.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, in version 3 of the
+ * License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <https://www.gnu.org/licenses>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+/*
+ * This code is based on:
+ *
+ * VirtualBox Guest Additions for Haiku.
+ * Copyright (c) 2011 Mike Smith <mike@scgtrp.net>
+ * François Revol <revol@free.fr>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef GA_INCLUDED_SRC_haiku_VBoxMouse_VBoxMouse_h
+#define GA_INCLUDED_SRC_haiku_VBoxMouse_VBoxMouse_h
+#ifndef RT_WITHOUT_PRAGMA_ONCE
+# pragma once
+#endif
+
+#include <InputServerDevice.h>
+
+extern "C" _EXPORT BInputServerDevice* instantiate_input_device();
+
+class VBoxMouse : public BInputServerDevice
+{
+ public:
+ VBoxMouse();
+ virtual ~VBoxMouse();
+
+ virtual status_t InitCheck();
+ virtual status_t SystemShuttingDown();
+
+ virtual status_t Start(const char *device, void *cookie);
+ virtual status_t Stop(const char *device, void *cookie);
+ virtual status_t Control(const char *device, void *cookie, uint32 code, BMessage *message);
+
+ private:
+
+ static status_t _ServiceThreadNub(void *_this);
+ status_t _ServiceThread();
+
+ int fDriverFD;
+ thread_id fServiceThreadID;
+ bool fExiting;
+};
+
+#endif /* !GA_INCLUDED_SRC_haiku_VBoxMouse_VBoxMouse_h */
+
diff --git a/src/VBox/Additions/haiku/VBoxMouse/VBoxMouseFilter.cpp b/src/VBox/Additions/haiku/VBoxMouse/VBoxMouseFilter.cpp
new file mode 100644
index 00000000..5f0158ba
--- /dev/null
+++ b/src/VBox/Additions/haiku/VBoxMouse/VBoxMouseFilter.cpp
@@ -0,0 +1,117 @@
+/* $Id: VBoxMouseFilter.cpp $ */
+/** @file
+ * VBoxMouse; input_server filter - Haiku Guest Additions, implementation.
+ */
+
+/*
+ * Copyright (C) 2012-2023 Oracle and/or its affiliates.
+ *
+ * This file is part of VirtualBox base platform packages, as
+ * available from https://www.virtualbox.org.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, in version 3 of the
+ * License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <https://www.gnu.org/licenses>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+/*
+ * This code is based on:
+ *
+ * VirtualBox Guest Additions for Haiku.
+ * Copyright (c) 2011 Mike Smith <mike@scgtrp.net>
+ * François Revol <revol@free.fr>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <Clipboard.h>
+#include <Debug.h>
+#include <Message.h>
+#include <String.h>
+
+#include "VBoxMouseFilter.h"
+#include <VBox/VBoxGuestLib.h>
+#include <VBoxGuestInternal.h>
+#include <VBox/log.h>
+#include <iprt/errcore.h>
+
+/** @todo can this be merged with VBoxMouse? */
+
+RTDECL(BInputServerFilter *)
+instantiate_input_filter()
+{
+ return new VBoxMouseFilter();
+}
+
+VBoxMouseFilter::VBoxMouseFilter()
+ : BInputServerFilter(),
+ fDriverFD(-1),
+ fServiceThreadID(-1),
+ fExiting(false),
+ fCurrentButtons(0)
+{
+}
+
+
+VBoxMouseFilter::~VBoxMouseFilter()
+{
+}
+
+
+filter_result VBoxMouseFilter::Filter(BMessage *message, BList *outList)
+{
+ switch (message->what)
+ {
+ case B_MOUSE_UP:
+ case B_MOUSE_DOWN:
+ {
+ printf("click|release\n");
+ message->FindInt32("buttons", &fCurrentButtons);
+ /** @todo r=ramshankar this looks wrong, no 'break' here? */
+ }
+
+ case B_MOUSE_MOVED:
+ {
+ printf("mouse moved\n");
+ message->ReplaceInt32("buttons", fCurrentButtons);
+ /** @todo r=ramshankar: 'break' or explicit comment please. */
+ }
+ }
+
+ return B_DISPATCH_MESSAGE;
+}
+
diff --git a/src/VBox/Additions/haiku/VBoxMouse/VBoxMouseFilter.h b/src/VBox/Additions/haiku/VBoxMouse/VBoxMouseFilter.h
new file mode 100644
index 00000000..64996a2f
--- /dev/null
+++ b/src/VBox/Additions/haiku/VBoxMouse/VBoxMouseFilter.h
@@ -0,0 +1,87 @@
+/* $Id: VBoxMouseFilter.h $ */
+/** @file
+ * VBoxMouse; input_server filter - Haiku Guest Additions, header.
+ */
+
+/*
+ * Copyright (C) 2012-2023 Oracle and/or its affiliates.
+ *
+ * This file is part of VirtualBox base platform packages, as
+ * available from https://www.virtualbox.org.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, in version 3 of the
+ * License.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see <https://www.gnu.org/licenses>.
+ *
+ * SPDX-License-Identifier: GPL-3.0-only
+ */
+
+/*
+ * This code is based on:
+ *
+ * VirtualBox Guest Additions for Haiku.
+ * Copyright (c) 2011 Mike Smith <mike@scgtrp.net>
+ * François Revol <revol@free.fr>
+ *
+ * Permission is hereby granted, free of charge, to any person
+ * obtaining a copy of this software and associated documentation
+ * files (the "Software"), to deal in the Software without
+ * restriction, including without limitation the rights to use,
+ * copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following
+ * conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+ * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+ * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#ifndef GA_INCLUDED_SRC_haiku_VBoxMouse_VBoxMouseFilter_h
+#define GA_INCLUDED_SRC_haiku_VBoxMouse_VBoxMouseFilter_h
+#ifndef RT_WITHOUT_PRAGMA_ONCE
+# pragma once
+#endif
+
+#include <InputServerFilter.h>
+
+extern "C" _EXPORT BInputServerFilter* instantiate_input_filter();
+
+class VBoxMouseFilter : public BInputServerFilter
+{
+ public:
+ VBoxMouseFilter();
+ virtual ~VBoxMouseFilter();
+
+ virtual filter_result Filter(BMessage* message, BList* outList);
+
+ private:
+ static status_t _ServiceThreadNub(void *_this);
+ status_t _ServiceThread();
+
+ int fDriverFD;
+ thread_id fServiceThreadID;
+ bool fExiting;
+ bool fEnabled;
+ int32 fCurrentButtons;
+};
+
+#endif /* !GA_INCLUDED_SRC_haiku_VBoxMouse_VBoxMouseFilter_h */
+