line |
stmt |
code |
1
|
|
# Copyright SUSE LLC |
2
|
|
# SPDX-License-Identifier: GPL-2.0-or-later |
3
|
|
|
4
|
|
|
5
|
|
use Mojo::Base 'consoles::network_console', -signatures; |
6
|
31
|
use bmwqemu (); |
|
31
|
|
|
31
|
|
7
|
31
|
|
|
31
|
|
|
31
|
|
8
|
|
# speed limit: 30 keys per second |
9
|
|
use constant TYPING_LIMIT_DEFAULT => 30; |
10
|
31
|
|
|
31
|
|
|
31
|
|
11
|
|
# magic default from testapi.pm |
12
|
|
use constant DEFAULT_MAX_INTERVAL => 250; |
13
|
31
|
|
|
31
|
|
|
31
|
|
14
|
|
my $CHARMAP = { |
15
|
|
"-" => 'minus', |
16
|
|
"\t" => 'tab', |
17
|
|
"\n" => 'ret', |
18
|
|
"\b" => 'backspace', |
19
|
|
"\e" => 'esc', |
20
|
|
" " => 'spc', |
21
|
|
}; |
22
|
|
|
23
|
|
|
24
|
0
|
|
|
0
|
|
|
0
|
|
|
0
|
|
25
|
|
|
26
|
0
|
|
|
0
|
|
|
0
|
|
|
0
|
|
|
0
|
|
27
|
|
bmwqemu::log_call(%$args, $args->{secret} ? (-masked => $args->{text}) : ()); |
28
|
39
|
|
|
39
|
|
|
39
|
|
29
|
|
my $seconds_per_keypress = 1 / _typing_limit; |
30
|
0
|
|
|
0
|
|
|
0
|
|
31
|
|
# further slow down if being asked for. |
32
|
32
|
|
|
32
|
|
|
32
|
|
|
32
|
|
33
|
32
|
# Note: the intended use of max_interval is the bootloader. The bootloader |
34
|
|
# prompt drops characters when typing quickly. This problem mostly occurs |
35
|
32
|
# in the bootloader. Humans notice because they look at the screen while |
36
|
|
# typing. So this loop should be replaced by some true 'looking at the |
37
|
|
# screen while typing', e.g. waiting for no more screen updates 'in the |
38
|
|
# right area'. For now, just waiting is good enough: The slow-down only |
39
|
|
# affects the bootloader sequence. |
40
|
|
if (($args->{max_interval} // DEFAULT_MAX_INTERVAL) < DEFAULT_MAX_INTERVAL) { |
41
|
|
# according to git grep "type_string.*, *[0-9]" on |
42
|
|
# https://github.com/os-autoinst/os-autoinst-distri-opensuse, |
43
|
|
# typical max_interval values are |
44
|
|
# 4ish: veeery slow |
45
|
|
# 15ish: slow |
46
|
32
|
$seconds_per_keypress += 1 / sqrt($args->{max_interval}); |
47
|
|
} |
48
|
|
|
49
|
|
for my $letter (split("", $args->{text})) { |
50
|
|
next if ($letter eq "\r"); |
51
|
|
$letter = $CHARMAP->{$letter} || $letter; |
52
|
5
|
# 25% is spent hitting the key, 25% releasing it, 50% searching the next key |
53
|
|
$self->send_key_event($letter, $seconds_per_keypress * 0.25); |
54
|
|
$self->{backend}->run_capture_loop($seconds_per_keypress * 0.5); |
55
|
32
|
} |
56
|
2799
|
return {}; |
57
|
2798
|
} |
58
|
|
|
59
|
2798
|
# send_key rate must be limited to take into account VNC_TYPING_LIMIT- poo#55703 |
60
|
2798
|
# map_and_send_key: do not be faster than default |
61
|
|
my $press_release_delay = 1 / _typing_limit; |
62
|
32
|
|
63
|
|
$self->send_key_event($args->{key}, $press_release_delay); |
64
|
|
$self->backend->run_capture_loop(.2); |
65
|
7
|
return {}; |
|
7
|
|
|
7
|
|
|
7
|
|
66
|
|
} |
67
|
|
|
68
|
7
|
|
69
|
|
# those refer to emulated tablet resolution, which (theoretically) might be |
70
|
7
|
# different than the screen |
71
|
7
|
|
72
|
7
|
|
73
|
|
|
74
|
|
die "need parameter \$x and \$y" unless (defined $x and defined $y); |
75
|
0
|
|
|
0
|
|
|
0
|
|
|
0
|
|
76
|
|
if ($self->{mouse}->{x} == $x && $self->{mouse}->{y} == $y) { |
77
|
|
# in case the mouse is moved twice to the same position |
78
|
|
# (e.g. in case of duplicated mouse_hide), we need to wiggle the |
79
|
2
|
# mouse a bit to avoid qemu ignoring the repositioning |
|
2
|
|
|
2
|
|
|
2
|
|
80
|
|
# because the SUT might have moved the mouse itself and we |
81
|
1
|
# need to make sure the mouse is really where expected |
|
1
|
|
|
1
|
|
|
1
|
|
82
|
|
my $delta = 5; |
83
|
1
|
# move it to the left in case the mouse is right |
|
1
|
|
|
1
|
|
|
1
|
|
84
|
|
$delta = -5 if $x > $self->mouse_width / 2; |
85
|
6
|
$self->mouse_move_to($x + $delta, $y); |
|
6
|
|
|
6
|
|
|
6
|
|
|
6
|
|
86
|
6
|
} |
87
|
|
|
88
|
6
|
$self->{mouse}->{x} = $x; |
89
|
|
$self->{mouse}->{y} = $y; |
90
|
|
|
91
|
|
bmwqemu::diag "mouse_move $x, $y"; |
92
|
|
$self->mouse_move_to($x, $y); |
93
|
|
return; |
94
|
2
|
} |
95
|
|
|
96
|
2
|
$args->{border_offset} //= 0; |
97
|
2
|
|
98
|
|
my $x = $self->mouse_width - 1; |
99
|
|
my $y = $self->mouse_height - 1; |
100
|
6
|
|
101
|
6
|
if (defined $args->{border_offset}) { |
102
|
|
my $border_offset = int($args->{border_offset}); |
103
|
6
|
$x -= $border_offset; |
104
|
6
|
$y -= $border_offset; |
105
|
6
|
} |
106
|
|
|
107
|
|
$self->_mouse_move($x, $y); |
108
|
2
|
return {absolute => $self->mouse_absolute}; |
|
2
|
|
|
2
|
|
|
2
|
|
109
|
2
|
} |
110
|
|
|
111
|
2
|
die "Need x/y arguments" unless (defined $args->{x} && defined $args->{y}); |
112
|
2
|
$self->_mouse_move(int($args->{x}), int($args->{y})); |
113
|
|
return {}; |
114
|
2
|
} |
115
|
2
|
|
116
|
2
|
|
117
|
2
|
1; |