-
-
Notifications
You must be signed in to change notification settings - Fork 139
/
userinput.c
10197 lines (9007 loc) · 230 KB
/
userinput.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright (C) 2002-2010 Karl J. Runge <runge@karlrunge.com>
All rights reserved.
This file is part of x11vnc.
x11vnc 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; either version 2 of the License, or (at
your option) any later version.
x11vnc 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 x11vnc; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA
or see <http://www.gnu.org/licenses/>.
In addition, as a special exception, Karl J. Runge
gives permission to link the code of its release of x11vnc with the
OpenSSL project's "OpenSSL" library (or with modified versions of it
that use the same license as the "OpenSSL" library), and distribute
the linked executables. You must obey the GNU General Public License
in all respects for all of the code used other than "OpenSSL". If you
modify this file, you may extend this exception to your version of the
file, but you are not obligated to do so. If you do not wish to do
so, delete this exception statement from your version.
*/
/* -- userinput.c -- */
#include "x11vnc.h"
#include "xwrappers.h"
#include "xdamage.h"
#include "xrecord.h"
#include "xinerama.h"
#include "win_utils.h"
#include "xevents.h"
#include "user.h"
#include "scan.h"
#include "cleanup.h"
#include "pointer.h"
#include "rates.h"
#include "keyboard.h"
#include "solid.h"
#include "xrandr.h"
#include "8to24.h"
#include "unixpw.h"
#include "macosx.h"
#include "macosxCGS.h"
#include "cursor.h"
#include "screen.h"
#include "connections.h"
/*
* user input handling heuristics
*/
int defer_update_nofb = 4; /* defer a shorter time under -nofb */
int last_scroll_type = SCR_NONE;
int get_wm_frame_pos(int *px, int *py, int *x, int *y, int *w, int *h,
Window *frame, Window *win);
void parse_scroll_copyrect(void);
void parse_fixscreen(void);
void parse_wireframe(void);
void set_wirecopyrect_mode(char *str);
void set_scrollcopyrect_mode(char *str);
void initialize_scroll_keys(void);
void initialize_scroll_matches(void);
void initialize_scroll_term(void);
void initialize_max_keyrepeat(void);
int direct_fb_copy(int x1, int y1, int x2, int y2, int mark);
void fb_push(void);
int fb_push_wait(double max_wait, int flags);
void eat_viewonly_input(int max_eat, int keep);
void mark_for_xdamage(int x, int y, int w, int h);
void mark_region_for_xdamage(sraRegionPtr region);
void set_xdamage_mark(int x, int y, int w, int h);
int near_wm_edge(int x, int y, int w, int h, int px, int py);
int near_scrollbar_edge(int x, int y, int w, int h, int px, int py);
void check_fixscreen(void);
int check_xrecord(void);
int check_wireframe(void);
int fb_update_sent(int *count);
int check_user_input(double dt, double dtr, int tile_diffs, int *cnt);
void do_copyregion(sraRegionPtr region, int dx, int dy, int mode);
int check_ncache(int reset, int mode);
int find_rect(int idx, int x, int y, int w, int h);
int bs_restore(int idx, int *nbatch, sraRegionPtr rmask, XWindowAttributes *attr, int clip, int nopad, int *valid, int verb);
int try_to_fix_su(Window win, int idx, Window above, int *nbatch, char *mode);
int try_to_fix_resize_su(Window orig_frame, int orig_x, int orig_y, int orig_w, int orig_h,
int x, int y, int w, int h, int try_batch);
int lookup_win_index(Window);
void set_ncache_xrootpmap(void);
static void get_client_regions(int *req, int *mod, int *cpy, int *num) ;
static void parse_scroll_copyrect_str(char *scr);
static void parse_wireframe_str(char *wf);
static void destroy_str_list(char **list);
static void draw_box(int x, int y, int w, int h, int restore);
static int do_bdpush(Window wm_win, int x0, int y0, int w0, int h0, int bdx,
int bdy, int bdskinny);
static int set_ypad(void);
static void scale_mark(int x1, int y1, int x2, int y2, int mark);
static int push_scr_ev(double *age, int type, int bdpush, int bdx, int bdy,
int bdskinny, int first_push);
static int crfix(int x, int dx, int Lx);
static int scrollability(Window win, int set);
static int eat_pointer(int max_ptr_eat, int keep);
static void set_bdpush(int type, double *last_bdpush, int *pushit);
static int repeat_check(double last_key_scroll);
static int check_xrecord_keys(void);
static int check_xrecord_mouse(void);
static int try_copyrect(Window orig_frame, Window frame, int x, int y, int w, int h,
int dx, int dy, int *obscured, sraRegionPtr extra_clip, double max_wait, int *nbatch);
static int wireframe_mod_state();
static void check_user_input2(double dt);
static void check_user_input3(double dt, double dtr, int tile_diffs);
static void check_user_input4(double dt, double dtr, int tile_diffs);
winattr_t *cache_list;
/*
* For -wireframe: find the direct child of rootwin that has the
* pointer, assume that is the WM frame that contains the application
* (i.e. wm reparents the app toplevel) return frame position and size
* if successful.
*/
int get_wm_frame_pos(int *px, int *py, int *x, int *y, int *w, int *h,
Window *frame, Window *win) {
#if !NO_X11
Window r, c;
XWindowAttributes attr;
Bool ret;
int rootx, rooty, wx, wy;
unsigned int mask;
#endif
#ifdef MACOSX
if (macosx_console) {
return macosx_get_wm_frame_pos(px, py, x, y, w, h, frame, win);
}
#endif
RAWFB_RET(0)
#if NO_X11
if (!px || !py || !x || !y || !w || !h || !frame || !win) {}
return 0;
#else
ret = XQueryPointer_wr(dpy, rootwin, &r, &c, &rootx, &rooty, &wx, &wy,
&mask);
*frame = c;
/* current pointer position is returned too */
*px = rootx;
*py = rooty;
if (!ret || ! c || c == rootwin) {
/* no immediate child */
return 0;
}
/* child window position and size */
if (! valid_window(c, &attr, 1)) {
return 0;
}
*x = attr.x;
*y = attr.y;
*w = attr.width;
*h = attr.height;
#if 0
/* more accurate, but the animation is bogus anyway */
if (attr.border_width > 0) {
*w += 2 * attr.border_width;
*h += 2 * attr.border_width;
}
#endif
if (win != NULL) {
*win = descend_pointer(5, c, NULL, 0);
}
return 1;
#endif /* NO_X11 */
}
static int scrollcopyrect_top, scrollcopyrect_bot;
static int scrollcopyrect_left, scrollcopyrect_right;
static double scr_key_time, scr_key_persist;
static double scr_mouse_time, scr_mouse_persist, scr_mouse_maxtime;
static double scr_mouse_pointer_delay;
static double scr_key_bdpush_time, scr_mouse_bdpush_time;
static void parse_scroll_copyrect_str(char *scr) {
char *p, *str;
int i;
char *part[16];
for (i=0; i<16; i++) {
part[i] = NULL;
}
if (scr == NULL || *scr == '\0') {
return;
}
str = strdup(scr);
p = strtok(str, ",");
i = 0;
while (p) {
part[i++] = strdup(p);
p = strtok(NULL, ",");
if (i >= 16) break;
}
free(str);
/*
* Top, Bottom, Left, Right tolerances for scrollbar locations.
*/
if ((str = part[0]) != NULL) {
int t, b, l, r;
if (sscanf(str, "%d+%d+%d+%d", &t, &b, &l, &r) == 4) {
scrollcopyrect_top = t;
scrollcopyrect_bot = b;
scrollcopyrect_left = l;
scrollcopyrect_right = r;
}
}
/* key scrolling timing heuristics. */
if ((str = part[1]) != NULL) {
double t1, t2, t3;
if (sscanf(str, "%lf+%lf+%lf", &t1, &t2, &t3) == 3) {
scr_key_time = t1;
scr_key_persist = t2;
scr_key_bdpush_time = t3;
}
}
/* mouse scrolling timing heuristics. */
if ((str = part[2]) != NULL) {
double t1, t2, t3, t4, t5;
if (sscanf(str, "%lf+%lf+%lf+%lf+%lf", &t1, &t2, &t3, &t4,
&t5) == 5) {
scr_mouse_time = t1;
scr_mouse_persist = t2;
scr_mouse_bdpush_time = t3;
scr_mouse_pointer_delay = t4;
scr_mouse_maxtime = t5;
}
}
for (i = 0; i < 16; i++)
free(part[i]);
}
void parse_scroll_copyrect(void) {
parse_scroll_copyrect_str(SCROLL_COPYRECT_PARMS);
if (! scroll_copyrect_str) {
scroll_copyrect_str = strdup(SCROLL_COPYRECT_PARMS);
}
parse_scroll_copyrect_str(scroll_copyrect_str);
}
void parse_fixscreen(void) {
char *str, *p;
screen_fixup_V = 0.0;
screen_fixup_C = 0.0;
screen_fixup_X = 0.0;
screen_fixup_8 = 0.0;
if (! screen_fixup_str) {
return;
}
str = strdup(screen_fixup_str);
p = strtok(str, ",");
while (p) {
double t;
if (*p == 'V' && sscanf(p, "V=%lf", &t) == 1) {
screen_fixup_V = t;
} else if (*p == 'C' && sscanf(p, "C=%lf", &t) == 1) {
screen_fixup_C = t;
} else if (*p == 'X' && sscanf(p, "X=%lf", &t) == 1) {
screen_fixup_X = t;
} else if (*p == 'X' && sscanf(p, "8=%lf", &t) == 1) {
screen_fixup_8 = t;
}
p = strtok(NULL, ",");
}
free(str);
if (screen_fixup_V < 0.0) screen_fixup_V = 0.0;
if (screen_fixup_C < 0.0) screen_fixup_C = 0.0;
if (screen_fixup_X < 0.0) screen_fixup_X = 0.0;
if (screen_fixup_8 < 0.0) screen_fixup_8 = 0.0;
}
/*
WIREFRAME_PARMS "0xff,2,0,30+6+6+6,Alt,0.05+0.3+2.0,8"
0xff,2,0,32+8+8+8,all,0.15+0.30+5.0+0.125
shade,linewidth,percent,T+B+L+R,mods,t1+t2+t3+t4
*/
#define LW_MAX 8
static unsigned long wireframe_shade = 0xff;
static int wireframe_lw;
static double wireframe_frac;
static int wireframe_top, wireframe_bot, wireframe_left, wireframe_right;
static double wireframe_t1, wireframe_t2, wireframe_t3, wireframe_t4;
static char *wireframe_mods = NULL;
/*
* Parse the gory -wireframe string for parameters.
*/
static void parse_wireframe_str(char *wf) {
char *p, *str;
int i;
char *part[16];
for (i=0; i<16; i++) {
part[i] = NULL;
}
if (wf == NULL || *wf == '\0') {
return;
}
str = strdup(wf);
/* leading ",", make it start with ignorable string "z" */
if (*str == ',') {
char *tmp = (char *) malloc(strlen(str)+2);
strcpy(tmp, "z");
strcat(tmp, str);
free(str);
str = tmp;
}
p = strtok(str, ",");
i = 0;
while (p) {
part[i++] = strdup(p);
p = strtok(NULL, ",");
if (i >= 16) break;
}
free(str);
/* Wireframe shade, color, RGB: */
if ((str = part[0]) != NULL) {
unsigned long n;
int r, g, b, ok = 0;
XColor cdef;
Colormap cmap;
if (dpy && (bpp == 32 || bpp == 16)) {
#if !NO_X11
X_LOCK;
cmap = DefaultColormap (dpy, scr);
if (XParseColor(dpy, cmap, str, &cdef) &&
XAllocColor(dpy, cmap, &cdef)) {
r = cdef.red >> 8;
g = cdef.green >> 8;
b = cdef.blue >> 8;
if (r == 0 && g == 0) {
g = 1; /* need to be > 255 */
}
n = 0;
n |= (r << main_red_shift);
n |= (g << main_green_shift);
n |= (b << main_blue_shift);
wireframe_shade = n;
ok = 1;
}
X_UNLOCK;
#else
r = g = b = 0;
cmap = 0;
cdef.pixel = 0;
#endif
}
if (ok) {
;
} else if (sscanf(str, "0x%lx", &n) == 1) {
wireframe_shade = n;
} else if (sscanf(str, "%lu", &n) == 1) {
wireframe_shade = n;
} else if (sscanf(str, "%lx", &n) == 1) {
wireframe_shade = n;
}
}
/* linewidth: # of pixels wide for the wireframe lines */
if ((str = part[1]) != NULL) {
int n;
if (sscanf(str, "%d", &n) == 1) {
wireframe_lw = n;
if (wireframe_lw < 1) {
wireframe_lw = 1;
}
if (wireframe_lw > LW_MAX) {
wireframe_lw = LW_MAX;
}
}
}
/* percentage cutoff for opaque move/resize (like WM's) */
if ((str = part[2]) != NULL) {
if (*str == '\0') {
;
} else if (strchr(str, '.')) {
wireframe_frac = atof(str);
} else {
wireframe_frac = ((double) atoi(str))/100.0;
}
}
/*
* Top, Bottom, Left, Right tolerances to guess the wm frame is
* being grabbed (Top is traditionally bigger, i.e. titlebar):
*/
if ((str = part[3]) != NULL) {
int t, b, l, r;
if (sscanf(str, "%d+%d+%d+%d", &t, &b, &l, &r) == 4) {
wireframe_top = t;
wireframe_bot = b;
wireframe_left = l;
wireframe_right = r;
}
}
/*
* wireframe in interior with Modifier down.
* 0 => no mods
* 1 => all mods
* Shift,Alt,Control,Meta,Super,Hyper
*/
if (wireframe_mods) {
free(wireframe_mods);
}
wireframe_mods = NULL;
if ((str = part[4]) != NULL) {
if (*str == '0' || !strcmp(str, "none")) {
;
} else if (*str == '1' || !strcmp(str, "all")) {
wireframe_mods = strdup("all");
} else if (!strcmp(str, "Alt") || !strcmp(str, "Shift")
|| !strcmp(str, "Control") || !strcmp(str, "Meta")
|| !strcmp(str, "Super") || !strcmp(str, "Hyper")) {
wireframe_mods = strdup(str);
}
}
/* check_wireframe() timing heuristics. */
if ((str = part[5]) != NULL) {
double t1, t2, t3, t4;
if (sscanf(str, "%lf+%lf+%lf+%lf", &t1, &t2, &t3, &t4) == 4) {
wireframe_t1 = t1;
wireframe_t2 = t2;
wireframe_t3 = t3;
wireframe_t4 = t4;
}
}
for (i = 0; i < 16; i++)
free(part[i]);
}
/*
* First parse the defaults and apply any user supplied ones (may be a subset)
*/
void parse_wireframe(void) {
parse_wireframe_str(WIREFRAME_PARMS);
if (! wireframe_str) {
wireframe_str = strdup(WIREFRAME_PARMS);
}
parse_wireframe_str(wireframe_str);
}
/*
* Set wireframe_copyrect based on desired mode.
*/
void set_wirecopyrect_mode(char *str) {
char *orig = wireframe_copyrect;
if (str == NULL || *str == '\0') {
wireframe_copyrect = strdup(wireframe_copyrect_default);
} else if (!strcmp(str, "always") || !strcmp(str, "all")) {
wireframe_copyrect = strdup("always");
} else if (!strcmp(str, "top")) {
wireframe_copyrect = strdup("top");
} else if (!strcmp(str, "never") || !strcmp(str, "none")) {
wireframe_copyrect = strdup("never");
} else {
if (! wireframe_copyrect) {
wireframe_copyrect = strdup(wireframe_copyrect_default);
} else {
orig = NULL;
}
rfbLog("unknown -wirecopyrect mode: %s, using: %s\n", str,
wireframe_copyrect);
}
if (orig) {
free(orig);
}
}
/*
* Set scroll_copyrect based on desired mode.
*/
void set_scrollcopyrect_mode(char *str) {
char *orig = scroll_copyrect;
if (str == NULL || *str == '\0') {
scroll_copyrect = strdup(scroll_copyrect_default);
} else if (!strcmp(str, "always") || !strcmp(str, "all") ||
!strcmp(str, "both")) {
scroll_copyrect = strdup("always");
} else if (!strcmp(str, "keys") || !strcmp(str, "keyboard")) {
scroll_copyrect = strdup("keys");
} else if (!strcmp(str, "mouse") || !strcmp(str, "pointer")) {
scroll_copyrect = strdup("mouse");
} else if (!strcmp(str, "never") || !strcmp(str, "none")) {
scroll_copyrect = strdup("never");
} else {
if (! scroll_copyrect) {
scroll_copyrect = strdup(scroll_copyrect_default);
} else {
orig = NULL;
}
rfbLog("unknown -scrollcopyrect mode: %s, using: %s\n", str,
scroll_copyrect);
}
if (orig) {
free(orig);
}
}
void initialize_scroll_keys(void) {
char *str, *p;
int i, nkeys = 0, saw_builtin = 0;
int ks_max = 2 * 0xFFFF;
if (scroll_key_list) {
free(scroll_key_list);
scroll_key_list = NULL;
}
if (! scroll_key_list_str || *scroll_key_list_str == '\0') {
return;
}
if (strstr(scroll_key_list_str, "builtin")) {
int k;
/* add in number of keysyms builtin gives */
for (k=1; k<ks_max; k++) {
if (xrecord_scroll_keysym((rfbKeySym) k)) {
nkeys++;
}
}
}
nkeys++; /* first key, i.e. no commas. */
p = str = strdup(scroll_key_list_str);
while(*p) {
if (*p == ',') {
nkeys++; /* additional key. */
}
p++;
}
nkeys++; /* exclude/include 0 element */
nkeys++; /* trailing NoSymbol */
scroll_key_list = (KeySym *) malloc((size_t)nkeys*sizeof(KeySym));
for (i=0; i<nkeys; i++) {
scroll_key_list[i] = NoSymbol;
}
if (*str == '-') {
scroll_key_list[0] = 1;
p = strtok(str+1, ",");
} else {
p = strtok(str, ",");
}
i = 1;
while (p) {
if (!strcmp(p, "builtin")) {
int k;
if (saw_builtin) {
p = strtok(NULL, ",");
continue;
}
saw_builtin = 1;
for (k=1; k<ks_max; k++) {
if (xrecord_scroll_keysym((rfbKeySym) k)) {
scroll_key_list[i++] = (rfbKeySym) k;
}
}
} else {
unsigned int in;
if (sscanf(p, "%u", &in) == 1) {
scroll_key_list[i++] = (rfbKeySym) in;
} else if (sscanf(p, "0x%x", &in) == 1) {
scroll_key_list[i++] = (rfbKeySym) in;
} else if (XStringToKeysym(p) != NoSymbol) {
scroll_key_list[i++] = XStringToKeysym(p);
} else {
rfbLog("initialize_scroll_keys: skip unknown "
"keysym: %s\n", p);
}
}
p = strtok(NULL, ",");
}
free(str);
}
static void destroy_str_list(char **list) {
int i = 0;
if (! list) {
return;
}
while (list[i] != NULL) {
free(list[i++]);
}
free(list);
}
void initialize_scroll_matches(void) {
char *str, *imp = "__IMPOSSIBLE_STR__";
int i, n, nkey, nmouse;
destroy_str_list(scroll_good_all);
scroll_good_all = NULL;
destroy_str_list(scroll_good_key);
scroll_good_key = NULL;
destroy_str_list(scroll_good_mouse);
scroll_good_mouse = NULL;
destroy_str_list(scroll_skip_all);
scroll_skip_all = NULL;
destroy_str_list(scroll_skip_key);
scroll_skip_key = NULL;
destroy_str_list(scroll_skip_mouse);
scroll_skip_mouse = NULL;
/* scroll_good: */
if (scroll_good_str != NULL && *scroll_good_str != '\0') {
str = scroll_good_str;
} else {
str = scroll_good_str0;
}
scroll_good_all = create_str_list(str);
nkey = 0;
nmouse = 0;
n = 0;
while (scroll_good_all[n] != NULL) {
char *s = scroll_good_all[n++];
if (strstr(s, "KEY:") == s) nkey++;
if (strstr(s, "MOUSE:") == s) nmouse++;
}
if (nkey++) {
scroll_good_key = (char **) malloc(nkey*sizeof(char *));
for (i=0; i<nkey; i++) scroll_good_key[i] = NULL;
}
if (nmouse++) {
scroll_good_mouse = (char **) malloc(nmouse*sizeof(char *));
for (i=0; i<nmouse; i++) scroll_good_mouse[i] = NULL;
}
nkey = 0;
nmouse = 0;
for (i=0; i<n; i++) {
char *s = scroll_good_all[i];
if (strstr(s, "KEY:") == s) {
scroll_good_key[nkey++] = strdup(s+strlen("KEY:"));
free(s);
scroll_good_all[i] = strdup(imp);
} else if (strstr(s, "MOUSE:") == s) {
scroll_good_mouse[nmouse++]=strdup(s+strlen("MOUSE:"));
free(s);
scroll_good_all[i] = strdup(imp);
}
}
/* scroll_skip: */
if (scroll_skip_str != NULL && *scroll_skip_str != '\0') {
str = scroll_skip_str;
} else {
str = scroll_skip_str0;
}
scroll_skip_all = create_str_list(str);
nkey = 0;
nmouse = 0;
n = 0;
while (scroll_skip_all[n] != NULL) {
char *s = scroll_skip_all[n++];
if (strstr(s, "KEY:") == s) nkey++;
if (strstr(s, "MOUSE:") == s) nmouse++;
}
if (nkey++) {
scroll_skip_key = (char **) malloc(nkey*sizeof(char *));
for (i=0; i<nkey; i++) scroll_skip_key[i] = NULL;
}
if (nmouse++) {
scroll_skip_mouse = (char **) malloc(nmouse*sizeof(char *));
for (i=0; i<nmouse; i++) scroll_skip_mouse[i] = NULL;
}
nkey = 0;
nmouse = 0;
for (i=0; i<n; i++) {
char *s = scroll_skip_all[i];
if (strstr(s, "KEY:") == s) {
scroll_skip_key[nkey++] = strdup(s+strlen("KEY:"));
free(s);
scroll_skip_all[i] = strdup(imp);
} else if (strstr(s, "MOUSE:") == s) {
scroll_skip_mouse[nmouse++]=strdup(s+strlen("MOUSE:"));
free(s);
scroll_skip_all[i] = strdup(imp);
}
}
}
void initialize_scroll_term(void) {
char *str;
int n;
destroy_str_list(scroll_term);
scroll_term = NULL;
if (scroll_term_str != NULL && *scroll_term_str != '\0') {
str = scroll_term_str;
} else {
str = scroll_term_str0;
}
if (!strcmp(str, "none")) {
return;
}
scroll_term = create_str_list(str);
n = 0;
while (scroll_term[n] != NULL) {
char *s = scroll_good_all[n++];
/* pull parameters out at some point */
s = NULL;
}
}
void initialize_max_keyrepeat(void) {
char *str;
int lo, hi;
if (max_keyrepeat_str != NULL && *max_keyrepeat_str != '\0') {
str = max_keyrepeat_str;
} else {
str = max_keyrepeat_str0;
}
if (sscanf(str, "%d-%d", &lo, &hi) != 2) {
rfbLog("skipping invalid -scr_keyrepeat string: %s\n", str);
sscanf(max_keyrepeat_str0, "%d-%d", &lo, &hi);
}
max_keyrepeat_lo = lo;
max_keyrepeat_hi = hi;
if (max_keyrepeat_lo < 1) {
max_keyrepeat_lo = 1;
}
if (max_keyrepeat_hi > 40) {
max_keyrepeat_hi = 40;
}
}
typedef struct saveline {
int x0, y0, x1, y1;
int shift;
int vert;
int saved;
char *data;
} saveline_t;
/*
* Draw the wireframe box onto the framebuffer. Saves the real
* framebuffer data to some storage lines. Restores previous lines.
* use restore = 1 to clean up (done with animation).
* This works with -scale.
*/
static void draw_box(int x, int y, int w, int h, int restore) {
int x0, y0, x1, y1, i, pixelsize = bpp/8;
char *dst, *src, *use_fb;
static saveline_t *save[4];
static int first = 1, len = 0;
int max = dpy_x > dpy_y ? dpy_x : dpy_y;
int use_Bpl, lw = wireframe_lw;
unsigned long shade = wireframe_shade;
int color = 0;
unsigned short us = 0;
unsigned long ul = 0;
if (clipshift) {
x -= coff_x;
y -= coff_y;
}
/* handle -8to24 mode: use 2nd fb only */
use_fb = main_fb;
use_Bpl = main_bytes_per_line;
if (cmap8to24 && cmap8to24_fb) {
use_fb = cmap8to24_fb;
pixelsize = 4;
if (depth <= 8) {
use_Bpl *= 4;
} else if (depth <= 16) {
use_Bpl *= 2;
}
}
if (max > len) {
/* create/resize storage lines: */
for (i=0; i<4; i++) {
len = max;
if (! first && save[i]) {
if (save[i]->data) {
free(save[i]->data);
save[i]->data = NULL;
}
free(save[i]);
}
save[i] = (saveline_t *) malloc(sizeof(saveline_t));
save[i]->saved = 0;
save[i]->data = (char *) malloc( (LW_MAX+1)*len*4 );
/*
* Four types of lines:
* 0) top horizontal
* 1) bottom horizontal
* 2) left vertical
* 3) right vertical
*
* shift means shifted by width or height.
*/
if (i == 0) {
save[i]->vert = 0;
save[i]->shift = 0;
} else if (i == 1) {
save[i]->vert = 0;
save[i]->shift = 1;
} else if (i == 2) {
save[i]->vert = 1;
save[i]->shift = 0;
} else if (i == 3) {
save[i]->vert = 1;
save[i]->shift = 1;
}
}
}
first = 0;
/*
* restore any saved lines. see below for algorithm and
* how x0, etc. are used. we just reverse those steps.
*/
for (i=0; i<4; i++) {
int s = save[i]->shift;
int yu, y_min = -1, y_max = -1;
int y_start, y_stop, y_step;
if (! save[i]->saved) {
continue;
}
x0 = save[i]->x0;
y0 = save[i]->y0;
x1 = save[i]->x1;
y1 = save[i]->y1;
if (save[i]->vert) {
y_start = y0+lw;
y_stop = y1-lw;
y_step = lw*pixelsize;
} else {
y_start = y0 - s*lw;
y_stop = y_start + lw;
y_step = max*pixelsize;
}
for (yu = y_start; yu < y_stop; yu++) {
if (x0 == x1) {
continue;
}
if (yu < 0 || yu >= dpy_y) {
continue;
}
if (y_min < 0 || yu < y_min) {
y_min = yu;
}
if (y_max < 0 || yu > y_max) {
y_max = yu;
}
src = save[i]->data + (yu-y_start)*y_step;
dst = use_fb + yu*use_Bpl + x0*pixelsize;
memcpy(dst, src, (size_t)(x1-x0)*pixelsize);
}
if (y_min >= 0) {
if (0) fprintf(stderr, "Mark-1 %d %d %d %d\n", x0, y_min, x1, y_max+1);
mark_rect_as_modified(x0, y_min, x1, y_max+1, 0);
}
save[i]->saved = 0;
}
if (0) fprintf(stderr, " DrawBox: %04dx%04d+%04d+%04d B=%d rest=%d lw=%d %.4f\n", w, h, x, y, 2*(w+h)*(2-restore)*pixelsize*lw, restore, lw, dnowx());
if (restore) {
return;
}
/*
* work out shade/color for the wireframe line, could be a color
* for 16bpp or 24bpp.
*/
if (shade > 255) {
if (pixelsize == 2) {
us = (unsigned short) (shade & 0xffff);
color = 1;
} else if (pixelsize == 4) {
ul = (unsigned long) shade;
color = 1;
} else {
shade = shade % 256;
}
}
for (i=0; i<4; i++) {
int s = save[i]->shift;
int yu, y_min = -1, y_max = -1;
int yblack = -1, xblack1 = -1, xblack2 = -1;
int y_start, y_stop, y_step;
if (save[i]->vert) {
/*
* make the narrow x's be on the screen, let
* the y's hang off (not drawn).
*/
save[i]->x0 = x0 = nfix(x + s*w - s*lw, dpy_x);
save[i]->y0 = y0 = y;
save[i]->x1 = x1 = nfix(x + s*w - s*lw + lw, dpy_x);
save[i]->y1 = y1 = y + h;
/*
* start and stop a linewidth away from true edge,
* to avoid interfering with horizontal lines.
*/
y_start = y0+lw;
y_stop = y1-lw;
y_step = lw*pixelsize;
/* draw a black pixel for the border if lw > 1 */
if (s) {
xblack1 = x1-1;
} else {
xblack1 = x0;
}
} else {
/*
* make the wide x's be on the screen, let the y's
* hang off (not drawn).
*/
save[i]->x0 = x0 = nfix(x, dpy_x);
save[i]->y0 = y0 = y + s*h;
save[i]->x1 = x1 = nfix(x + w, dpy_x);
save[i]->y1 = y1 = y0 + lw;
y_start = y0 - s*lw;
y_stop = y_start + lw;
y_step = max*pixelsize;
/* draw a black pixels for the border if lw > 1 */
if (s) {
yblack = y_stop - 1;
} else {
yblack = y_start;
}
xblack1 = x0;
xblack2 = x1-1;
}
/* now loop over the allowed y's for either case */