Skip to content

Commit b285c1a

Browse files
author
ponty
committed
Merge branch 'workgroupengineering-features/mouse'
2 parents 764af49 + 36cd428 commit b285c1a

File tree

4 files changed

+332
-8
lines changed

4 files changed

+332
-8
lines changed

framebuffer-vncserver.pro

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ CONFIG -= qt
66
SOURCES += src/framebuffer-vncserver.c
77
SOURCES += src/keyboard.c
88
SOURCES += src/touch.c
9+
SOURCES += src/mouse.c
910

1011
include(deployment.pri)
1112
qtcAddDeployment()

src/framebuffer-vncserver.c

+52-8
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include "rfb/keysym.h"
3939

4040
#include "touch.h"
41+
#include "mouse.h"
4142
#include "keyboard.h"
4243
#include "logging.h"
4344

@@ -52,6 +53,7 @@
5253
static char fb_device[256] = "/dev/fb0";
5354
static char touch_device[256] = "";
5455
static char kbd_device[256] = "";
56+
static char mouse_device[256] = "";
5557

5658
static struct fb_var_screeninfo var_scrinfo;
5759
static struct fb_fix_screeninfo fix_scrinfo;
@@ -165,7 +167,8 @@ static void keyevent(rfbBool down, rfbKeySym key, rfbClientPtr cl)
165167
injectKeyEvent(scancode, down);
166168
}
167169
}
168-
static void ptrevent(int buttonMask, int x, int y, rfbClientPtr cl)
170+
171+
static void ptrevent_touch(int buttonMask, int x, int y, rfbClientPtr cl)
169172
{
170173
UNUSED(cl);
171174
/* Indicates either pointer movement or a pointer button press or release. The pointer is
@@ -202,9 +205,26 @@ a press and release of button 5.
202205
}
203206
}
204207

208+
static void ptrevent_mouse(int buttonMask, int x, int y, rfbClientPtr cl)
209+
{
210+
UNUSED(cl);
211+
/* Indicates either pointer movement or a pointer button press or release. The pointer is
212+
now at (x-position, y-position), and the current state of buttons 1 to 8 are represented
213+
by bits 0 to 7 of button-mask respectively, 0 meaning up, 1 meaning down (pressed).
214+
On a conventional mouse, buttons 1, 2 and 3 correspond to the left, middle and right
215+
buttons on the mouse. On a wheel mouse, each step of the wheel upwards is represented
216+
by a press and release of button 4, and each step downwards is represented by
217+
a press and release of button 5.
218+
From: http://www.vislab.usyd.edu.au/blogs/index.php/2009/05/22/an-headerless-indexed-protocol-for-input-1?blog=61 */
219+
220+
debug_print("Got mouse: %04x (x=%d, y=%d)\n", buttonMask, x, y);
221+
// Simulate left mouse event as touch event
222+
injectMouseEvent(&var_scrinfo, buttonMask, x, y);
223+
}
224+
205225
/*****************************************************************************/
206226

207-
static void init_fb_server(int argc, char **argv, rfbBool enable_touch)
227+
static void init_fb_server(int argc, char **argv, rfbBool enable_touch, rfbBool enable_mouse)
208228
{
209229
info_print("Initializing server...\n");
210230

@@ -234,8 +254,14 @@ static void init_fb_server(int argc, char **argv, rfbBool enable_touch)
234254
server->kbdAddEvent = keyevent;
235255
if (enable_touch)
236256
{
237-
server->ptrAddEvent = ptrevent;
257+
server->ptrAddEvent = ptrevent_touch;
258+
}
259+
260+
if (enable_mouse)
261+
{
262+
server->ptrAddEvent = ptrevent_mouse;
238263
}
264+
239265

240266
rfbInitServer(server);
241267

@@ -570,11 +596,12 @@ static void update_screen(void)
570596

571597
void print_usage(char **argv)
572598
{
573-
info_print("%s [-f device] [-p port] [-t touchscreen] [-k keyboard] [-r rotation] [-R touchscreen rotation] [-F FPS] [-v] [-h]\n"
599+
info_print("%s [-f device] [-p port] [-t touchscreen] [-m touchscreen] [-k keyboard] [-r rotation] [-R touchscreen rotation] [-F FPS] [-v] [-h]\n"
574600
"-p port: VNC port, default is 5900\n"
575601
"-f device: framebuffer device node, default is /dev/fb0\n"
576602
"-k device: keyboard device node (example: /dev/input/event0)\n"
577603
"-t device: touchscreen device node (example:/dev/input/event2)\n"
604+
"-m device: mouse device node (example:/dev/input/event2)\n"
578605
"-r degrees: framebuffer rotation, default is 0\n"
579606
"-R degrees: touchscreen rotation, default is same as framebuffer rotation\n"
580607
"-F FPS: Maximum target FPS, default is 10\n"
@@ -608,6 +635,11 @@ int main(int argc, char **argv)
608635
if (argv[i])
609636
strcpy(touch_device, argv[i]);
610637
break;
638+
case 'm':
639+
i++;
640+
if (argv[i])
641+
strcpy(mouse_device, argv[i]);
642+
break;
611643
case 'k':
612644
i++;
613645
strcpy(kbd_device, argv[i]);
@@ -658,15 +690,27 @@ int main(int argc, char **argv)
658690
}
659691

660692
rfbBool enable_touch = FALSE;
661-
if (strlen(touch_device) > 0)
693+
rfbBool enable_mouse = FALSE;
694+
if(strlen(touch_device) > 0 && strlen(mouse_device) > 0)
695+
{
696+
error_print("It can't using both mouse and touch device.\n");
697+
exit(EXIT_FAILURE);
698+
}
699+
else if (strlen(touch_device) > 0)
662700
{
663701
// init touch only if there is a touch device defined
664702
int ret = init_touch(touch_device, touch_rotate);
665703
enable_touch = (ret > 0);
666704
}
705+
else if(strlen(mouse_device) > 0)
706+
{
707+
// init touch only if there is a mouse device defined
708+
int ret = init_mouse(mouse_device, touch_rotate);
709+
enable_mouse = (ret > 0);
710+
}
667711
else
668712
{
669-
info_print("No touch device\n");
713+
info_print("No touch or mouse device\n");
670714
}
671715

672716
info_print("Initializing VNC server:\n");
@@ -675,9 +719,9 @@ int main(int argc, char **argv)
675719
info_print(" bpp: %d\n", (int)var_scrinfo.bits_per_pixel);
676720
info_print(" port: %d\n", (int)vnc_port);
677721
info_print(" rotate: %d\n", (int)vnc_rotate);
678-
info_print(" touch rotate: %d\n", (int)touch_rotate);
722+
info_print(" mouse/touch rotate: %d\n", (int)touch_rotate);
679723
info_print(" target FPS: %d\n", (int)target_fps);
680-
init_fb_server(argc, argv, enable_touch);
724+
init_fb_server(argc, argv, enable_touch, enable_mouse);
681725

682726
/* Implement our own event loop to detect changes in the framebuffer. */
683727
while (1)

0 commit comments

Comments
 (0)