File Coverage

consoles/vnc_base.pm
Criterion Covered Total %
statement 111 114 97.3
total 111 114 97.3


line stmt code
1   # Copyright 2009-2013 Bernhard M. Wiedemann
2   # Copyright 2012-2021 SUSE LLC
3   # SPDX-License-Identifier: GPL-2.0-or-later
4    
5    
6   use Mojo::Base 'consoles::video_base', -signatures;
7 30 use consoles::VNC;
  30  
  30  
8 30 use Time::HiRes qw(usleep);
  30  
  30  
9 30  
  30  
  30  
10   use bmwqemu ();
11 30  
  30  
  30  
12   # speed limit: 30 keys per second
13   use constant VNC_TYPING_LIMIT_DEFAULT => consoles::video_base::TYPING_LIMIT_DEFAULT;
14 30  
  30  
  30  
15    
16 4 close($self->{vnc}->socket) if ($self->{vnc} && $self->{vnc}->socket);
  4  
  4  
  4  
17   $self->{vnc} = undef;
18 6 }
  6  
  6  
19 6  
20 6  
21   return unless $self->{vnc};
22   $self->{vnc}->check_vnc_stalls(0);
23 1 return 0;
  1  
  1  
  1  
  1  
24   }
25 2  
  2  
  2  
26 2 $self->{mouse} = {x => -1, y => -1};
27 1  
28 1 die "Need parameters 'hostname' and 'port'" unless $args->{hostname} && $args->{port};
29   bmwqemu::diag "Establishing VNC connection to $args->{hostname}:$args->{port}";
30   $self->{vnc} = consoles::VNC->new($args);
31 7 $self->{vnc}->login($args->{connect_timeout});
  7  
  7  
  7  
32 7 return $self->{vnc};
33   }
34 7  
35 6 return unless $self->{vnc};
36 6 # drain the VNC socket before polling for a new update
37 6 $self->{vnc}->update_framebuffer();
38 4 $self->{vnc}->send_update_request($args ? $args->{incremental} : undef);
39   return;
40   }
41 653  
  653  
  653  
  653  
42 653 return unless $self->{vnc};
43    
44 653 unless ($self->{vnc}->_framebuffer) {
45 653 # No _framebuffer yet. First connect? Tickle vnc server to
46 653 # get it filled.
47   $self->request_screen_update();
48   # wait long enough, new Xvnc on tumbleweed choked on shorter
49 324 # waits after first login
  324  
  324  
50 324  
51   # As an alternative to sleeping we could potentially try to instead
52 324 # loop update_framebuffer until _framebuffer in connect_remote
53   usleep(50_000);
54   }
55 4  
56   $self->{vnc}->update_framebuffer();
57   return unless $self->{vnc}->_framebuffer;
58   return $self->{vnc}->_framebuffer;
59   }
60    
61 4  
62   $self->{vnc}->map_and_send_key($key, undef, $press_release_delay);
63   }
64 324  
65 324 $self->{vnc}->map_and_send_key($args->{key}, 1, 1 / VNC_TYPING_LIMIT_DEFAULT);
66 322 $self->backend->run_capture_loop(.2);
67   return {};
68   }
69 0  
  0  
  0  
70   $self->{vnc}->map_and_send_key($args->{key}, 0, 1 / VNC_TYPING_LIMIT_DEFAULT);
71 2793 $self->backend->run_capture_loop(.2);
  2793  
  2793  
  2793  
  2793  
72 2793 return {};
73   }
74    
75 1  
  1  
  1  
  1  
76 1 $self->{vnc}->mouse_move_to($x, $y);
77 1 }
78 1  
79   $self->{vnc}->absolute;
80   }
81 1  
  1  
  1  
  1  
82 1 my $button = $args->{button};
83 1 my $bstate = $args->{bstate};
84 1 my $mask = {left => $bstate, right => $bstate << 2, middle => $bstate << 1}->{$button} // 0;
85   bmwqemu::diag "pointer_event $mask $self->{mouse}->{x}, $self->{mouse}->{y}";
86   $self->{vnc}->send_pointer_event($mask, $self->{mouse}->{x}, $self->{mouse}->{y});
87 2 return {};
  2  
  2  
  2  
88 1 }
  1  
  1  
  1  
89    
90 4 1;
  4  
  4  
  4  
  4