Fixed VNC mouse, but the correct scale factor for X and Y has to be figured out.
This commit is contained in:
@@ -88,6 +88,7 @@ static const device_t *mouse_curr;
|
|||||||
static void *mouse_priv;
|
static void *mouse_priv;
|
||||||
static int mouse_nbut;
|
static int mouse_nbut;
|
||||||
static int (*mouse_dev_poll)(int x, int y, int z, int b, void *priv);
|
static int (*mouse_dev_poll)(int x, int y, int z, int b, void *priv);
|
||||||
|
static void (*mouse_poll_ex)(void) = NULL;
|
||||||
|
|
||||||
#ifdef ENABLE_MOUSE_LOG
|
#ifdef ENABLE_MOUSE_LOG
|
||||||
int mouse_do_log = ENABLE_MOUSE_LOG;
|
int mouse_do_log = ENABLE_MOUSE_LOG;
|
||||||
@@ -164,13 +165,22 @@ mouse_set_buttons(int buttons)
|
|||||||
mouse_nbut = buttons;
|
mouse_nbut = buttons;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
mouse_set_poll_ex(void (*poll_ex)(void))
|
||||||
|
{
|
||||||
|
mouse_poll_ex = poll_ex;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
mouse_process(void)
|
mouse_process(void)
|
||||||
{
|
{
|
||||||
if (mouse_curr == NULL)
|
if (mouse_curr == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
mouse_poll();
|
if (mouse_poll_ex)
|
||||||
|
mouse_poll_ex();
|
||||||
|
else
|
||||||
|
mouse_poll();
|
||||||
|
|
||||||
if ((mouse_dev_poll != NULL) || (mouse_curr->poll != NULL)) {
|
if ((mouse_dev_poll != NULL) || (mouse_curr->poll != NULL)) {
|
||||||
if (mouse_curr->poll != NULL)
|
if (mouse_curr->poll != NULL)
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ extern void mouse_init(void);
|
|||||||
extern void mouse_close(void);
|
extern void mouse_close(void);
|
||||||
extern void mouse_reset(void);
|
extern void mouse_reset(void);
|
||||||
extern void mouse_set_buttons(int buttons);
|
extern void mouse_set_buttons(int buttons);
|
||||||
|
extern void mouse_set_poll_ex(void (*poll_ex)(void));
|
||||||
extern void mouse_process(void);
|
extern void mouse_process(void);
|
||||||
extern void mouse_set_poll(int (*f)(int, int, int, int, void *), void *);
|
extern void mouse_set_poll(int (*f)(int, int, int, int, void *), void *);
|
||||||
extern void mouse_poll(void);
|
extern void mouse_poll(void);
|
||||||
|
|||||||
72
src/vnc.c
72
src/vnc.c
@@ -44,6 +44,15 @@ static int allowedX,
|
|||||||
allowedY;
|
allowedY;
|
||||||
static int ptr_x, ptr_y, ptr_but;
|
static int ptr_x, ptr_y, ptr_but;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int buttons;
|
||||||
|
int dx;
|
||||||
|
int dy;
|
||||||
|
int dwheel;
|
||||||
|
} MOUSESTATE;
|
||||||
|
|
||||||
|
static MOUSESTATE ms;
|
||||||
|
|
||||||
#ifdef ENABLE_VNC_LOG
|
#ifdef ENABLE_VNC_LOG
|
||||||
int vnc_do_log = ENABLE_VNC_LOG;
|
int vnc_do_log = ENABLE_VNC_LOG;
|
||||||
|
|
||||||
@@ -71,29 +80,43 @@ vnc_kbdevent(rfbBool down, rfbKeySym k, rfbClientPtr cl)
|
|||||||
vnc_kbinput(down ? 1 : 0, (int) k);
|
vnc_kbinput(down ? 1 : 0, (int) k);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
vnc_mouse_poll(void)
|
||||||
|
{
|
||||||
|
static int b = 0;
|
||||||
|
if (ms.dx != 0 || ms.dy != 0) {
|
||||||
|
mouse_x += ms.dx;
|
||||||
|
mouse_y += ms.dy;
|
||||||
|
|
||||||
|
ms.dx = 0;
|
||||||
|
ms.dy = 0;
|
||||||
|
|
||||||
|
// pclog("dx=%d, dy=%d, dwheel=%d\n", mouse_x, mouse_y, mouse_z);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (b != ms.buttons) {
|
||||||
|
mouse_buttons = ms.buttons;
|
||||||
|
b = ms.buttons;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
vnc_ptrevent(int but, int x, int y, rfbClientPtr cl)
|
vnc_ptrevent(int but, int x, int y, rfbClientPtr cl)
|
||||||
{
|
{
|
||||||
if (x >= 0 && x < allowedX && y >= 0 && y < allowedY) {
|
ms.buttons = 0;
|
||||||
/* VNC uses absolute positions within the window, no deltas. */
|
if (but & 0x01)
|
||||||
if (x != ptr_x || y != ptr_y) {
|
ms.buttons |= 0x01;
|
||||||
mouse_x += (x - ptr_x) / 100;
|
if (but & 0x02)
|
||||||
mouse_y += (y - ptr_y) / 100;
|
ms.buttons |= 0x04;
|
||||||
ptr_x = x;
|
if (but & 0x04)
|
||||||
ptr_y = y;
|
ms.buttons |= 0x02;
|
||||||
}
|
ptr_but = but;
|
||||||
|
|
||||||
if (but != ptr_but) {
|
/* VNC uses absolute positions within the window, no deltas. */
|
||||||
mouse_buttons = 0;
|
ms.dx += (x - ptr_x) / 0.96; /* TODO: Figure out the correct scale factor for X and Y. */
|
||||||
if (but & 0x01)
|
ms.dy += (y - ptr_y) / 0.96;
|
||||||
mouse_buttons |= 0x01;
|
ptr_x = x;
|
||||||
if (but & 0x02)
|
ptr_y = y;
|
||||||
mouse_buttons |= 0x04;
|
|
||||||
if (but & 0x04)
|
|
||||||
mouse_buttons |= 0x02;
|
|
||||||
ptr_but = but;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
rfbDefaultPtrAddEvent(but, x, y, cl);
|
rfbDefaultPtrAddEvent(but, x, y, cl);
|
||||||
}
|
}
|
||||||
@@ -110,7 +133,8 @@ vnc_clientgone(rfbClientPtr cl)
|
|||||||
vnc_log("VNC: no clients, pausing..\n");
|
vnc_log("VNC: no clients, pausing..\n");
|
||||||
|
|
||||||
/* Disable the mouse. */
|
/* Disable the mouse. */
|
||||||
plat_mouse_capture(0);
|
// plat_mouse_capture(0);
|
||||||
|
mouse_set_poll_ex(NULL);
|
||||||
|
|
||||||
plat_pause(1);
|
plat_pause(1);
|
||||||
}
|
}
|
||||||
@@ -129,12 +153,14 @@ vnc_newclient(rfbClientPtr cl)
|
|||||||
ptr_y = allowedY / 2;
|
ptr_y = allowedY / 2;
|
||||||
mouse_x = mouse_y = mouse_z = 0;
|
mouse_x = mouse_y = mouse_z = 0;
|
||||||
mouse_buttons = 0x00;
|
mouse_buttons = 0x00;
|
||||||
|
memset(&ms, 0, sizeof(MOUSESTATE));
|
||||||
|
|
||||||
/* We now have clients, un-pause the emulator if needed. */
|
/* We now have clients, un-pause the emulator if needed. */
|
||||||
vnc_log("VNC: unpausing..\n");
|
vnc_log("VNC: unpausing..\n");
|
||||||
|
|
||||||
/* Enable the mouse. */
|
/* Enable the mouse. */
|
||||||
plat_mouse_capture(1);
|
// plat_mouse_capture(1);
|
||||||
|
mouse_set_poll_ex(vnc_mouse_poll);
|
||||||
|
|
||||||
plat_pause(0);
|
plat_pause(0);
|
||||||
}
|
}
|
||||||
@@ -162,7 +188,7 @@ vnc_blit(int x, int y, int w, int h, int monitor_index)
|
|||||||
{
|
{
|
||||||
int row;
|
int row;
|
||||||
|
|
||||||
if (monitor_index || (x < 0) || (y < 0) || (w <= 0) || (h <= 0) || (w > 2048) || (h > 2048) || (buffer32 == NULL)) {
|
if (monitor_index || (x < 0) || (y < 0) || (w < VNC_MIN_X) || (h < VNC_MIN_Y) || (w > VNC_MAX_X) || (h > VNC_MAX_Y) || (buffer32 == NULL)) {
|
||||||
video_blit_complete_monitor(monitor_index);
|
video_blit_complete_monitor(monitor_index);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -260,7 +286,7 @@ vnc_resize(int x, int y)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
/* TightVNC doesn't like certain sizes.. */
|
/* TightVNC doesn't like certain sizes.. */
|
||||||
if (x < VNC_MIN_X || x > VNC_MAX_X || y < VNC_MIN_Y || y > VNC_MAX_Y) {
|
if ((x < VNC_MIN_X) || (x > VNC_MAX_X) || (y < VNC_MIN_Y) || (y > VNC_MAX_Y)) {
|
||||||
vnc_log("VNC: invalid resoltion %dx%d requested!\n", x, y);
|
vnc_log("VNC: invalid resoltion %dx%d requested!\n", x, y);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user