-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
211 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
## Install | ||
|
||
```sh | ||
$ sudo apt-get install gjs libkeybinder-3.0-0 gir1.2-keybinder | ||
``` | ||
|
||
## Usage | ||
|
||
```sh | ||
$ yarn build | ||
$ gjs ./dist/main.js | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "record-desktop-gtk", | ||
"version": "0.5.9", | ||
"description": "Record gifs and take screenshots on Linux", | ||
"main": "dist/lib.js", | ||
"scripts": { | ||
"build": "../../node_modules/.bin/webpack --config webpack.config.js" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict'; | ||
|
||
const GLib = require('gi/GLib'); | ||
|
||
module.exports = { | ||
shell, | ||
stdout | ||
}; | ||
|
||
// @TODO: change to async | ||
// http://devdocs.baznga.org/glib20~2.50.0/glib.spawn_command_line_sync | ||
// http://devdocs.baznga.org/glib20~2.50.0/glib.spawn_command_line_async | ||
async function shell(cmd) { | ||
const [, out] = GLib.spawn_command_line_sync(`bash -c "${cmd}"`); | ||
return Promise.resolve(out.toString()); | ||
} | ||
|
||
// @TODO: change to async | ||
// http://devdocs.baznga.org/glib20~2.50.0/glib.spawn_sync | ||
// http://devdocs.baznga.org/glib20~2.50.0/glib.spawn_async | ||
async function stdout(cmd, args = [],) { | ||
const [, out] = GLib.spawn_sync(null, [cmd, ...args], null, GLib.SpawnFlags.SEARCH_PATH, null); | ||
return Promise.resolve(out.toString()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use strict'; | ||
|
||
require('gi').versions.Keybinder = '3.0'; | ||
|
||
const GObject = require('gi/GObject'); | ||
const Gtk = require('gi/Gtk'); | ||
const Keybinder = require('gi/Keybinder'); | ||
|
||
const { selectRegion, takeScreenshot } = require('record-desktop'); | ||
|
||
const Keyboard = GObject.registerClass( | ||
{}, | ||
class Keyboard extends Gtk.ApplicationWindow { | ||
_init(params) { | ||
super._init(params); | ||
|
||
const hotkey = '<Super>X'; | ||
Keybinder.init(); | ||
|
||
const res = Keybinder.bind(hotkey, async () => { | ||
print(`${hotkey} start`); | ||
const outputFile = '/tmp/1.png'; | ||
|
||
const { width, height, x, y } = await selectRegion(); | ||
await takeScreenshot({ width, height, x, y, outputFile }); | ||
|
||
print(`${hotkey} click`, outputFile); | ||
}); | ||
|
||
print(hotkey, res); | ||
} | ||
} | ||
); | ||
|
||
const RecordDesktopGtkApplication = GObject.registerClass( | ||
{}, | ||
class RecordDesktopGtkApplication extends Gtk.Application { | ||
vfunc_activate() { | ||
this.keyboard = new Keyboard({ application: this }); | ||
} | ||
} | ||
); | ||
|
||
new RecordDesktopGtkApplication().run([]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
const path = require('path'); | ||
|
||
module.exports = { | ||
entry: { | ||
main: `${__dirname}/src/index.js`, | ||
}, | ||
output: { | ||
filename: '[name].js', | ||
path: `${__dirname}/dist`, | ||
libraryTarget: 'var', | ||
library: '[name]' | ||
}, | ||
resolve: { | ||
alias: { | ||
'execa': `${__dirname}/src/execa-mock.js` | ||
}, | ||
modules: [ | ||
'node_modules' | ||
] | ||
}, | ||
externals: { | ||
'gi': 'imports.gi', | ||
'gi/GLib': 'imports.gi.GLib', | ||
'gi/GObject': 'imports.gi.GObject', | ||
'gi/Gtk': 'imports.gi.Gtk', | ||
'gi/Keybinder': 'imports.gi.Keybinder' | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
{ | ||
"name": "record-desktop", | ||
"version": "0.5.9", | ||
"main": "src/index.js" | ||
"main": "src/index.js", | ||
"dependencies": { | ||
"execa": "^0.10.0", | ||
"p-cancelable": "^0.4.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,42 @@ | ||
'use strict'; | ||
|
||
/* | ||
inspiration: https://github.com/wulkano/aperture | ||
https://github.com/wulkano/aperture/pull/5/files | ||
https://github.com/wulkano/aperture/pull/32 | ||
*/ | ||
import execa from 'execa'; | ||
const devConsole = console; | ||
|
||
const execa = require('execa'); | ||
const PCancelable = require('p-cancelable'); | ||
|
||
export function ffmpeg({ outputFile, fps = 30, x, y, width, height, offset = 0, showCursor }) { | ||
const args = ['-f', 'x11grab']; | ||
|
||
if (typeof width !== 'undefined') { | ||
if (offset > 0) { | ||
devConsole.log(x, y, width, height); | ||
devConsole.log(offset); | ||
x = x - offset; | ||
y = y - offset; | ||
width = width + offset * 2; | ||
height = height + offset * 2; | ||
devConsole.log(x, y, width, height); | ||
return new PCancelable((resolve, reject, onCancel) => { | ||
const args = ['-f', 'x11grab']; | ||
|
||
if (typeof width !== 'undefined') { | ||
if (offset > 0) { | ||
x = x - offset; | ||
y = y - offset; | ||
width = width + offset * 2; | ||
height = height + offset * 2; | ||
} | ||
|
||
args.push('-video_size', `${width}x${height}`); | ||
args.push('-i', `:0+${x},${y}`) | ||
} else { | ||
args.push('-i', ':0'); | ||
} | ||
|
||
args.push('-video_size', `${width}x${height}`); | ||
args.push('-i', `:0+${x},${y}`) | ||
} else { | ||
args.push('-i', ':0'); | ||
} | ||
|
||
args.push('-y') // force overwrite existing file | ||
args.push('-framerate', fps, '-draw_mouse', +(showCursor === true), outputFile); | ||
args.push('-y') // force overwrite existing file | ||
args.push('-framerate', fps, '-draw_mouse', +(showCursor === true), outputFile); | ||
|
||
const proc = execa('ffmpeg', args); | ||
const proc = execa('ffmpeg', args); | ||
|
||
// proc.stderr.setEncoding('utf8'); | ||
// proc.stderr.on('data', str => { | ||
// devConsole.log(str) | ||
// }) | ||
|
||
const finish = () => new Promise(resolve => { | ||
proc.stdin.setEncoding('utf8'); | ||
proc.stdin.write('q'); | ||
resolve(); | ||
}) | ||
|
||
return { | ||
proc, | ||
finish | ||
}; | ||
proc.then(resolve, reject); | ||
onCancel(() => { | ||
proc.stdin.setEncoding('utf8'); | ||
proc.stdin.write('q'); | ||
}); | ||
}); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters