update screenshots

This commit is contained in:
Simon Vieille 2022-04-11 22:25:50 +02:00
parent 61eb6666e3
commit 6c6cce1d26
Signed by: deblan
GPG key ID: 03383D15A1D31745
3 changed files with 21 additions and 8 deletions

View file

@ -187,20 +187,29 @@ var pointerTouchMoveHandler = function(e) {
ws.send(msg);
}
var liveClickHandler = function(e) {
var liveHqClickHandler = function(e) {
return liveClickHandler(e, 'hq')
}
var liveLqClickHandler = function(e) {
return liveClickHandler(e, 'lq')
}
var liveClickHandler = function(e, quality) {
if (isLive) {
isLive = false;
$(this).text('Live');
$('#live-hq').text(`Live HQ`);
$('#live-lq').text(`Live LQ`);
return;
}
isLive = true;
$(this).text('Stop live');
$(e.target).text('Stop live');
var doScreenshot = function() {
if (isLive) {
ws.send('{"type":"screenshot"}');
ws.send(`{"type":"screenshot","quality":"${quality}"}`);
window.setTimeout(doScreenshot, 100);
}
@ -272,7 +281,8 @@ var addListeners = function() {
.on('touchstart', pointerTouchStartHandler)
.on('touchmove', pointerTouchMoveHandler);
$('#live').click(liveClickHandler);
$('#live-hq').click(liveHqClickHandler);
$('#live-lq').click(liveLqClickHandler);
$('.btn-fullscreen').click(fullscreenHandler)
}

View file

@ -213,8 +213,10 @@
<p class="legend">Desktop</p>
</div>
<div class="col-12">
<button type="button" data-msg='{"type":"screenshot"}' class="btn btn-secondary">Screenshot</button>
<button type="button" id="live" class="btn btn-secondary">Live</button>
<button type="button" data-msg='{"type":"screenshot","quality":"hq"}' class="btn btn-secondary">Screenshot HQ</button>
<button type="button" data-msg='{"type":"screenshot","quality":"lq"}' class="btn btn-secondary">Screenshot LQ</button>
<button type="button" id="live-hq" class="btn btn-secondary">Live HQ</button>
<button type="button" id="live-lq" class="btn btn-secondary">Live LQ</button>
<div id="screenshot"><img class="btn-fullscreen" data-target="#screenshot img" src="data:image/png; base64, iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAIAAACQd1PeAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH4gIJDjc3srQk8gAAAB1pVFh0Q29tbWVudAAAAAAAQ3JlYXRlZCB3aXRoIEdJTVBkLmUHAAAADElEQVQI12P48+cPAAXsAvVTWDc6AAAAAElFTkSuQmCC"></div>
</div>
<div class="col-12">

View file

@ -169,6 +169,7 @@ $server->addMessageHandler('text', function (ConnectionInterface $from, array $d
$server->addMessageHandler('screenshot', function (ConnectionInterface $from, array $data) use ($shell, $messageOutput) {
$tmpFilename = sprintf('%s/remote_i3wm_ws_screenshot.lock', sys_get_temp_dir());
$qualities = ['hq' => 95, 'lq' => 5];
if (file_exists($tmpFilename) && time() - filemtime($tmpFilename) < 10) {
return;
@ -176,7 +177,7 @@ $server->addMessageHandler('screenshot', function (ConnectionInterface $from, ar
touch($tmpFilename);
$content = $shell->exec('import -window root -quality 10 -display :0 jpeg:-');
$content = $shell->exec(sprintf('import -window root -quality %d -display :0 jpeg:-', $qualities[$data['quality'] ?? 'hq']));
if (!empty($content)) {
$base64 = base64_encode($content);