~ubuntu-branches/debian/jessie/italc/jessie

« back to all changes in this revision

Viewing changes to ica/x11/x11vnc/pointer.c

  • Committer: Bazaar Package Importer
  • Author(s): Patrick Winnertz
  • Date: 2011-02-11 14:50:22 UTC
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20110211145022-sn173siax6lywjus
Tags: upstream-1.0.13
ImportĀ upstreamĀ versionĀ 1.0.13

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
   Copyright (C) 2002-2010 Karl J. Runge <runge@karlrunge.com> 
 
3
   All rights reserved.
 
4
 
 
5
This file is part of x11vnc.
 
6
 
 
7
x11vnc is free software; you can redistribute it and/or modify
 
8
it under the terms of the GNU General Public License as published by
 
9
the Free Software Foundation; either version 2 of the License, or (at
 
10
your option) any later version.
 
11
 
 
12
x11vnc is distributed in the hope that it will be useful,
 
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
GNU General Public License for more details.
 
16
 
 
17
You should have received a copy of the GNU General Public License
 
18
along with x11vnc; if not, write to the Free Software
 
19
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA
 
20
or see <http://www.gnu.org/licenses/>.
 
21
 
 
22
In addition, as a special exception, Karl J. Runge
 
23
gives permission to link the code of its release of x11vnc with the
 
24
OpenSSL project's "OpenSSL" library (or with modified versions of it
 
25
that use the same license as the "OpenSSL" library), and distribute
 
26
the linked executables.  You must obey the GNU General Public License
 
27
in all respects for all of the code used other than "OpenSSL".  If you
 
28
modify this file, you may extend this exception to your version of the
 
29
file, but you are not obligated to do so.  If you do not wish to do
 
30
so, delete this exception statement from your version.
 
31
*/
 
32
 
1
33
/* -- pointer.c -- */
2
34
 
3
35
#include "x11vnc.h"
22
54
 
23
55
void initialize_pointer_map(char *pointer_remap);
24
56
void do_button_mask_change(int mask, int button);
25
 
void pointer(int mask, int x, int y, rfbClientPtr client);
 
57
void pointer_event(int mask, int x, int y, rfbClientPtr client);
26
58
void initialize_pipeinput(void);
27
59
int check_pipeinput(void);
28
60
void update_x11_pointer_position(int x, int y);
44
76
        int up;
45
77
} prtremap_t;
46
78
 
47
 
#ifdef LIBVNCSERVER_HAVE_LIBPTHREAD
48
 
MUTEX(pointerMutex);
49
 
#endif
50
79
#define MAX_BUTTON_EVENTS 50
51
80
static prtremap_t pointer_map[MAX_BUTTONS+1][MAX_BUTTON_EVENTS];
52
81
 
54
83
 * For parsing the -buttonmap sections, e.g. "4" or ":Up+Up+Up:"
55
84
 */
56
85
static void buttonparse(int from, char **s) {
57
 
#if NO_X11
 
86
#if (0 && NO_X11)
58
87
        if (!from || !s) {}
59
88
        return;
60
89
#else
130
159
                                 */
131
160
                                char *str;
132
161
                                X_LOCK;
 
162
#if NO_X11
 
163
                                kcode = NoSymbol;
 
164
#else
133
165
                                kcode = XKeysymToKeycode(dpy, ksym);
 
166
#endif
134
167
 
135
168
                                pointer_map[from][n].keysym  = ksym;
136
169
                                pointer_map[from][n].keycode = kcode;
216
249
 * process the -buttonmap string
217
250
 */
218
251
void initialize_pointer_map(char *pointer_remap) {
219
 
#if NO_X11
220
 
        if (!pointer_remap) {}
221
 
        return;
222
 
#else
223
252
        unsigned char map[MAX_BUTTONS];
224
253
        int i, k;
225
254
        /*
230
259
         */
231
260
        
232
261
        if (!raw_fb_str) {
 
262
#if NO_X11
 
263
                num_buttons = 5;
 
264
#else
233
265
                X_LOCK;
234
266
                num_buttons = XGetPointerMapping(dpy, map, MAX_BUTTONS);
235
267
                X_UNLOCK;
 
268
                rfbLog("The X server says there are %d mouse buttons.\n", num_buttons);
 
269
#endif
236
270
        } else {
237
271
                num_buttons = 5;
 
272
                rfbLog("Manually set num_buttons to: %d\n", num_buttons);
238
273
        }
239
274
 
240
275
        if (num_buttons < 0) {
295
330
                }
296
331
                free(remap);
297
332
        }
298
 
#endif  /* NO_X11 */
299
333
}
300
334
 
301
335
/*
312
346
        RAWFB_RET_VOID
313
347
 
314
348
        X_LOCK;
315
 
        if (use_xwarppointer) {
 
349
        if (!always_inject && cursor_x == x && cursor_y == y) {
 
350
                ;
 
351
        } else if (use_xwarppointer) {
316
352
                /*
317
353
                 * off_x and off_y not needed with XWarpPointer since
318
354
                 * window is used:
559
595
                uinput_pointer_command(mask, x, y, client);
560
596
        } else if (pipeinput_int == PIPEINPUT_MACOSX) {
561
597
                macosx_pointer_command(mask, x, y, client);
562
 
/*      } else if (pipeinput_int == PIPEINPUT_VNC) {
563
 
                vnc_reflect_send_pointer(x, y, mask);*/
 
598
        } else if (pipeinput_int == PIPEINPUT_VNC) {
 
599
                vnc_reflect_send_pointer(x, y, mask);
564
600
        }
565
601
        if (pipeinput_fh == NULL) {
566
602
                return;
623
659
 * This may queue pointer events rather than sending them immediately
624
660
 * to the X server. (see update_x11_pointer*())
625
661
 */
626
 
void pointer(int mask, int x, int y, rfbClientPtr client) {
 
662
void pointer_event(int mask, int x, int y, rfbClientPtr client) {
627
663
        allowed_input_t input;
628
664
        int sent = 0, buffer_it = 0;
629
665
        double now;
630
666
 
 
667
        if (threads_drop_input) {
 
668
                return;
 
669
        }
 
670
 
631
671
        if (mask >= 0) {
632
672
                got_pointer_calls++;
633
673
        }
675
715
                y = nfix(y, dpy_y);
676
716
        }
677
717
 
 
718
        INPUT_LOCK;
 
719
 
678
720
        if ((pipeinput_fh != NULL || pipeinput_int) && mask >= 0) {
679
721
                pipe_pointer(mask, x, y, client);       /* MACOSX here. */
680
722
                if (! pipeinput_tee) {
690
732
                                button_mask_prev = button_mask;
691
733
                                button_mask = mask;
692
734
                        }
 
735
                        if (!view_only && (input.motion || input.button)) {
 
736
                                last_rfb_ptr_injected = dnow();
 
737
                        }
 
738
                        INPUT_UNLOCK;
693
739
                        return;
694
740
                }
695
741
        }
696
742
 
697
743
        if (view_only) {
 
744
                INPUT_UNLOCK;
698
745
                return;
699
746
        }
700
747
 
706
753
                 * to flush the event queue; there is no real pointer event.
707
754
                 */
708
755
                if (! input.motion && ! input.button) {
 
756
                        INPUT_UNLOCK;
709
757
                        return;
710
758
                }
711
759
 
714
762
                last_pointer_client = client;
715
763
 
716
764
                last_pointer_time = now;
 
765
                last_rfb_ptr_injected = dnow();
717
766
 
718
767
                if (blackout_ptr && blackouts) {
719
768
                        int b, ok = 1;
736
785
                                        blackr[b].x1, blackr[b].y1,
737
786
                                        blackr[b].x2, blackr[b].y2);
738
787
                                }
 
788
                                INPUT_UNLOCK;
739
789
                                return;
740
790
                        }
741
791
                }
750
800
        if ((use_threads && pointer_mode != 1) || pointer_flush_delay > 0.0) {
751
801
#               define NEV 32
752
802
                /* storage for the event queue */
753
 
                static int mutex_init = 0;
754
803
                static int nevents = 0;
755
804
                static int ev[NEV][3];
756
805
                int i;
757
806
                /* timer things */
758
807
                static double dt = 0.0, tmr = 0.0, maxwait = 0.4;
759
808
 
760
 
                if (! mutex_init) {
761
 
                        INIT_MUTEX(pointerMutex);
762
 
                        mutex_init = 1;
763
 
                }
764
 
 
765
809
                if (pointer_flush_delay > 0.0) {
766
810
                        maxwait = pointer_flush_delay;
767
811
                }
771
815
                        }
772
816
                }
773
817
 
774
 
                LOCK(pointerMutex);
 
818
                POINTER_LOCK;
775
819
 
776
820
                /* 
777
821
                 * If the framebuffer is being copied in another thread
806
850
                                        ev[i][1] = -1;
807
851
                                        ev[i][2] = -1;
808
852
                                }
809
 
                                UNLOCK(pointerMutex);
810
853
                                if (debug_pointer) {
811
854
                                        rfbLog("pointer(): deferring event %d"
812
855
                                            " %.4f\n", i, tmr - x11vnc_start);
813
856
                                }
 
857
                                POINTER_UNLOCK;
 
858
                                INPUT_UNLOCK;
814
859
                                return;
815
860
                        }
816
861
                }
862
907
                dt = 0.0;
863
908
                dtime0(&tmr);
864
909
 
865
 
                UNLOCK(pointerMutex);
 
910
                POINTER_UNLOCK;
866
911
        }
867
912
        if (mask < 0) {         /* -1 just means flush the event queue */
868
913
                if (debug_pointer) {
869
914
                        rfbLog("pointer(): flush only.  %.4f\n",
870
915
                            dnowx());
871
916
                }
 
917
                INPUT_UNLOCK;
872
918
                return;
873
919
        }
874
920
 
905
951
                XFlush_wr(dpy); 
906
952
                X_UNLOCK;
907
953
        }
 
954
        INPUT_UNLOCK;
908
955
}
909
956
 
910
957
void initialize_pipeinput(void) {
986
1033
                } else {
987
1034
                        rfbLog("pipeinput: could not open: %s\n", dev);
988
1035
                        rfbLogPerror("open");
 
1036
                        rfbLog("You may need to be root to open %s.\n", dev);
 
1037
                        rfbLog("\n");
989
1038
                }
990
1039
                return;
991
1040
        } else if (strstr(p, "UINPUT") == p) {