38
38
#include "rfb/keysym.h"
39
39
40
40
#include "touch.h"
41
+ #include "mouse.h"
41
42
#include "keyboard.h"
42
43
#include "logging.h"
43
44
52
53
static char fb_device [256 ] = "/dev/fb0" ;
53
54
static char touch_device [256 ] = "" ;
54
55
static char kbd_device [256 ] = "" ;
56
+ static char mouse_device [256 ] = "" ;
55
57
56
58
static struct fb_var_screeninfo var_scrinfo ;
57
59
static struct fb_fix_screeninfo fix_scrinfo ;
@@ -165,7 +167,8 @@ static void keyevent(rfbBool down, rfbKeySym key, rfbClientPtr cl)
165
167
injectKeyEvent (scancode , down );
166
168
}
167
169
}
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 )
169
172
{
170
173
UNUSED (cl );
171
174
/* 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.
202
205
}
203
206
}
204
207
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
+
205
225
/*****************************************************************************/
206
226
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 )
208
228
{
209
229
info_print ("Initializing server...\n" );
210
230
@@ -234,8 +254,14 @@ static void init_fb_server(int argc, char **argv, rfbBool enable_touch)
234
254
server -> kbdAddEvent = keyevent ;
235
255
if (enable_touch )
236
256
{
237
- server -> ptrAddEvent = ptrevent ;
257
+ server -> ptrAddEvent = ptrevent_touch ;
258
+ }
259
+
260
+ if (enable_mouse )
261
+ {
262
+ server -> ptrAddEvent = ptrevent_mouse ;
238
263
}
264
+
239
265
240
266
rfbInitServer (server );
241
267
@@ -570,11 +596,12 @@ static void update_screen(void)
570
596
571
597
void print_usage (char * * argv )
572
598
{
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"
574
600
"-p port: VNC port, default is 5900\n"
575
601
"-f device: framebuffer device node, default is /dev/fb0\n"
576
602
"-k device: keyboard device node (example: /dev/input/event0)\n"
577
603
"-t device: touchscreen device node (example:/dev/input/event2)\n"
604
+ "-m device: mouse device node (example:/dev/input/event2)\n"
578
605
"-r degrees: framebuffer rotation, default is 0\n"
579
606
"-R degrees: touchscreen rotation, default is same as framebuffer rotation\n"
580
607
"-F FPS: Maximum target FPS, default is 10\n"
@@ -608,6 +635,11 @@ int main(int argc, char **argv)
608
635
if (argv [i ])
609
636
strcpy (touch_device , argv [i ]);
610
637
break ;
638
+ case 'm' :
639
+ i ++ ;
640
+ if (argv [i ])
641
+ strcpy (mouse_device , argv [i ]);
642
+ break ;
611
643
case 'k' :
612
644
i ++ ;
613
645
strcpy (kbd_device , argv [i ]);
@@ -658,15 +690,27 @@ int main(int argc, char **argv)
658
690
}
659
691
660
692
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 )
662
700
{
663
701
// init touch only if there is a touch device defined
664
702
int ret = init_touch (touch_device , touch_rotate );
665
703
enable_touch = (ret > 0 );
666
704
}
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
+ }
667
711
else
668
712
{
669
- info_print ("No touch device\n" );
713
+ info_print ("No touch or mouse device\n" );
670
714
}
671
715
672
716
info_print ("Initializing VNC server:\n" );
@@ -675,9 +719,9 @@ int main(int argc, char **argv)
675
719
info_print (" bpp: %d\n" , (int )var_scrinfo .bits_per_pixel );
676
720
info_print (" port: %d\n" , (int )vnc_port );
677
721
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 );
679
723
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 );
681
725
682
726
/* Implement our own event loop to detect changes in the framebuffer. */
683
727
while (1 )
0 commit comments