Commit graph

82 commits

Author SHA1 Message Date
Romain Vimont
88ee6bc928 Swap MENU and APP_SWITCH shortcuts
Ctrl+s was mapped to MENU, while Ctrl+m was mapped to APP_SWITCH.

To avoid confusion, swap the shortcuts:
 - Ctrl+m like _M_enu
 - Ctrl+s like _S_witch
2018-03-23 10:10:24 +01:00
Andy Rich
301c52b603 Add support for CTRL+S to send hardware "shake" to device w/readme 2018-03-22 16:15:24 -07:00
Romain Vimont
3b3803da0d Remove useless blocks in switch/case
Remove unnecessary additional blocks.
2018-03-21 11:14:15 +01:00
Romain Vimont
f7bc0bd5b5 Merge branch 'dev' into release 2018-03-14 09:33:53 +01:00
Romain Vimont
e69f6f710d Disable stdout/stderr buffering on Windows
In MSYS2 on Windows, the output is buffered by default. Disable
buffering to print output immediately.

Note that in cmd.exe, it still prints nothing.
2018-03-13 10:20:09 +01:00
Romain Vimont
b858204786 Remove black borders on double-click
Resize the window to fit the device screen on click on black borders
(same as Ctrl+x).

Suggested-by: Guillaume Roche <groche@genymobile.com>
2018-03-13 08:37:46 +01:00
Romain Vimont
c87d94ee27 Map middle-click to HOME
Middle-click is useless in practice. Use it for HOME.
2018-03-10 00:44:19 +01:00
Romain Vimont
e2a7abcd53 Implement clipboard paste
Paste computer clipboard to the device on Ctrl+v.

The other direction (pasting the device clipboard to the computer) is
not implemented. It would require a communication channel from the
device to the computer, other than the socket used by the video stream.
2018-03-07 18:07:02 +01:00
Romain Vimont
9b056f5091 Replace SDL_net by custom implementation
SDL_net is not very suitable for scrcpy.

For example, SDLNet_TCP_Accept() is non-blocking, so we have to wrap it
by calling many SDL_Net-specific functions to make it blocking.

But above all, SDLNet_TCP_Open() is a server socket only when no IP is
provided; otherwise, it's a client socket. Therefore, it is not possible
to create a server socket bound to localhost, so it accepts connections
from anywhere.

This is a problem for scrcpy, because on start, the application listens
for nearly 1 second until it accepts the first connection, supposedly
from the device. If someone on the local network manages to connect to
the server socket first, then they can stream arbitrary H.264 video.
This may be troublesome, for example during a public presentation ;-)

Provide our own simplified API (net.h) instead, implemented for the
different platforms.
2018-02-16 00:56:58 +01:00
Romain Vimont
e8cad790a4 Reword Ctrl+x description
Pressing Ctrl+x resizes the window to remove black borders, "optimal" is
not well-defined.
2018-02-15 14:04:48 +01:00
Romain Vimont
d977202224 Add Ctrl+i shortcut to enable/disable FPS counter
Disable FPS counter on start, and use Ctrl+i to enable/disable it.
2018-02-15 12:24:16 +01:00
Romain Vimont
c6c17af840 Do not print usage on command error
On error, a message is printed. If we print usage afterwards, it's easy
to miss it.
2018-02-14 19:01:26 +01:00
Romain Vimont
8697659890 Expose device serial as an optional argument
The device serial was provided as a positional argument:

    scrcpy 0123456789abcdef

Instead, expose it as an optional argument, -s or --serial:

    scrcpy -s 0123456789abcdef

This avoids inconsistency between platforms when the positional
argument is passed before the options (which is undefined).
2018-02-14 18:57:29 +01:00
Romain Vimont
23d92a95b6 Extract argument parsing to specific functions
To avoid a big switch/case, implement the argument parsing logic in
separate static functions.
2018-02-14 18:53:16 +01:00
Romain Vimont
111068d733 Use SDL_bool return to indicate success
For clarity and consistency across the application, return SDL_TRUE
(instead of 0) on success and SDL_FALSE on failure (instead of
non-zero).
2018-02-14 18:44:28 +01:00
Romain Vimont
d3c76c004e Sort parameters by letter
For readability, sort the command-line arguments parsing by letter.
2018-02-14 18:39:46 +01:00
Romain Vimont
3ed80a1fac Define macros wrappers for logs
Use macros to wrap SDL_Log* functions with the "application" category.
2018-02-13 10:10:18 +01:00
Romain Vimont
4dbc450d01 Enable debug logs only for debug builds
In release mode, use the default log priorities.
2018-02-12 14:17:29 +01:00
Romain Vimont
7fe11033cb Include dependencies version
On --version, also print the dependencies version scrcpy has been
compiled against.
2018-02-07 15:41:59 +01:00
Romain Vimont
9f6464acff Expose application version
Expose scrcpy version via -v or --version.
2018-02-07 15:41:59 +01:00
Romain Vimont
53ff1aa410 Use meson to configure default values
Make meson generate config.h with configured values.
2018-02-07 12:09:10 +01:00
Romain Vimont
5eb91a4ca7 Fix scrcpy() return value
The scrcpy() function returns a SDL_bool to indicate its success, but
was initialized to 0 (SDL_FALSE) instead of SDL_TRUE.
2018-02-04 12:39:17 +01:00
Romain Vimont
0a70e24e80 Add new shortcuts description in help
Document the new shortcuts in the help (scrcpy --help).
2018-02-02 15:10:44 +01:00
Romain Vimont
6b546a87ab Add bit-rate command-line option
Add a command-line option (-b/--bit-rate) to customize the video
bit-rate.
2018-02-01 17:11:40 +01:00
Romain Vimont
7fe7bbf58c Check empty string before strtol()
There is no need to call strtol() if the input string is empty.
2018-02-01 17:11:40 +01:00
Romain Vimont
3bc63708b4 Remove useless newlines in SDL_Log*
Trailing new line is not necessary in SDL_Log* methods.
2018-02-01 17:11:40 +01:00
Romain Vimont
35a111d56e Add --help
Provide command-line help, with -h/--help option.
2018-02-01 17:11:40 +01:00
Romain Vimont
ee93f3f23a Rename maximum_size to max_size
The long option is --max-size, so for consistency, adapt the code
accordingly.
2018-02-01 17:11:40 +01:00
Romain Vimont
213b721ff9 Use long command-line options
In addition to the short form (e.g. "-p"), add the long form ("--port").
2018-02-01 15:35:20 +01:00
Romain Vimont
60b2f2ca64 Indent switch blocks content
For readability, indent "case" in switch blocks.

Replace:

    switch (x) {
    case 1:
        // ...
    case 2:
        // ...
    case 3: { // a local scope block
        int i = 42;
        // ...
    }
    }

By:

    switch (x) {
        case 1:
            // ...
        case 2:
            // ...
        case 3: { // a local scope block
            int i = 42;
            // ...
        }
    }
2018-02-01 11:44:20 +01:00
Romain Vimont
89f6a3cfe7 Handle resized video stream
Accept a parameter to limit the video size.

For instance, with "-m 960", the great side of the video will be scaled
down to 960 (if necessary), while the other side will be scaled down so
that the aspect ratio is preserved. Both dimensions must be a multiple
of 8, so black bands might be added, and the mouse positions must be
computed accordingly.
2018-01-29 15:40:33 +01:00
Romain Vimont
2c35220618 Rename screen -> scrcpy -> main
Rename scrcpy.c to main.c (this file handles the command line parsing),
and screen.c to scrcpy.c (it exposes the entry point scrcpy()).
2018-01-23 16:44:59 +01:00