Commit graph

1383 commits

Author SHA1 Message Date
Romain Vimont
9f6464acff Expose application version
Expose scrcpy version via -v or --version.
2018-02-07 15:41:59 +01:00
Romain Vimont
8d30d40b79 Make SKIP_FRAMES a compilation flag
The skip_frames flag was a non-configurable runtime flag. Since it is
not exposed to the user, there is no need for a (possible) runtime cost.

For testing purpose, we still want it to be configurable, so make it a
compilation flag.
2018-02-07 15:40:24 +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
cb7e29180f Change the window icon color in debug mode
To highlight the debug/release mode of the running application, use a
different window icon color in debug mode.
2018-02-07 11:48:25 +01:00
Romain Vimont
33062ffb8c Add Makefile recipe for debug build
Expose commands to build the application in debug mode.
2018-02-07 11:47:10 +01:00
Romain Vimont
71c2bfdd22 Parse XPM without SDL_image
We encounter some problems with SDL2_image on MSYS2 (Windows), so
implement our own XPM parsing which does not depend on SDL_image.

The input XPM is considered safe (it's in our source repo), so do not
check XPM format errors. This implies that read_xpm() is not safe to
call on any unsafe input.

Although less straightforward, use SDL_CreateRGBSurfaceFrom() instead of
SDL_CreateRGBSurfaceWithFormatFrom() because it is available with SDL
versions older than 2.0.5.
2018-02-05 19:24:33 +01:00
Romain Vimont
920bafce73 Revert "Fix Makefile for Windows"
In MSYS2 on Windows, the behavior is the same as on Linux.

On systems where the behavior is not the same, just customize the GRADLE
variable:

    GRADLE=gradlew make release

This reverts commit de192cab1b.
2018-02-05 19:24:00 +01:00
Romain Vimont
f22d4decca Enable mouse focus clickthrough only if available
The hint SDL_HINT_MOUSE_FOCUS_CLICKTHROUGH appeared in SDL 2.0.5. Ignore
it if the SDL version is older.
2018-02-05 16:15:52 +01:00
Romain Vimont
de192cab1b Fix Makefile for Windows
The default value of GRADLE is "./gradlew", which is the correct value
on Linux.

On Windows, it should use gradlew.bat (by calling "gradlew") instead.
2018-02-05 14:52:19 +01:00
Romain Vimont
52c89c7afb Add window icon
Add a bugdroid icon loaded from an XPM.
2018-02-05 14:46:00 +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
82ee55845c Add "make run"
To run the app during development, add a recipe "run" to the Makefile.
2018-02-04 12:17:34 +01:00
Romain Vimont
1ac37c4291 Hide services in Device
Expose useful methods directly in Device, without exposing the service
managers.
2018-02-02 17:06:57 +01:00
Romain Vimont
06333e1e08 Cache managers in ServiceManager
To guarantee that we instantiate services only one, cache the value the
first time.
2018-02-02 16:25:37 +01:00
Romain Vimont
69a359c7f4 Refactor actions calls
The purpose of handle_shortcut() was to group all actions together,
whether they are initiated from a text input event or a keycode event.

However, it did not handle the case where it was initiated from a mouse
event (a right-click must turn the screen on), since the action was
identified by the shortcut char.

Instead, expose one function per action, to be called directly from
where the event is handled.
2018-02-02 15:23:04 +01:00
Romain Vimont
d73dee9833 fixup! Handle all shortcuts in the same function 2018-02-02 15:17:03 +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
3365460658 Turn screen on on start
When starting scrcpy, immediately turn the screen on.
2018-02-02 14:57:33 +01:00
Romain Vimont
a139509f11 Turn screen on on right-click
The right-click is almost useless on Android, so use it to turn the
screen on.

Add a new control event type (command) to request the server to turn the
screen on.
2018-02-02 14:56:03 +01:00
Romain Vimont
228545cefd Reformat EventController
Reformated by Android Studio.
2018-02-02 14:52:00 +01:00
Romain Vimont
deba69d022 Handle all shortcuts in the same function
Shortcuts are sometimes initiated from a keycode event, and sometimes
from a text input event.

Move the handling to a unique function.
2018-02-02 12:01:38 +01:00
Romain Vimont
7f6a565401 Extract shortcut actions to separate functions
To simplify event handling code, move all actions to separate functions.
2018-02-02 11:52:19 +01:00
Romain Vimont
f8ad007a28 Move switch fullscreen logs
Logs were printed by the caller of switch_fullscreen(). Move them inside
the function to simplify event handling code.
2018-02-02 11:48:05 +01:00
Romain Vimont
6fe7b84629 Add shortcuts for physical keys
Add shortcuts for HOME, BACK, APPS, POWER, VOLUME_UP and VOLUME_DOWN.
2018-02-02 11:39:25 +01:00
Romain Vimont
1faf6cfd9d Rename the server scrcpy-server.jar
The server is built as an APK to simplify the build, but in fact this is
a simple jar (it is not even signed).

In order to avoid confusion, rename it to .jar, so that users do not try
to "adb install" it.

Also rename it from "scrcpy" to "scrcpy-server" to distinguish from the
client-side.
2018-02-02 09:37:10 +01:00
Romain Vimont
2172c53b7b Force the server target filename
The server path may be customized using SCRCPY_APK. If its basename is
different from "scrcpy.apk", it will be pushed with a different name,
so the execution would fail.

Therefore, force the push target filename.
2018-02-02 09:34:52 +01:00
Romain Vimont
ca44585f96 Do not send simple mouse move events
Moving the mouse without any button pressed has no effect on Android.
Therefore, do not even send these very frequent events.
2018-02-02 09:26:25 +01:00
Romain Vimont
79b28eb68f Enable mouse focus clickthrough
Consider a click to gain focus as a click on the device.
2018-02-01 20:52: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
2683fa20ed Add debug log for shortcuts
Add a debug log for every succeeded shortcut action.
2018-02-01 17:11:40 +01:00
Romain Vimont
274e1ac9ec Fix rotation bug in fullscreen mode on X11
On rotation, scrcpy resize the window to match the new rotation.
However, in fullscreen mode, setting the window size does not change the
windowed size on X11, so the behavior is incorrect.

To avoid the problem, apply the resize only after fullscreen is
disabled.
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
628f88ab89 Use ADB environment variable
Use the ADB environment variable to provide a custom adb path.
2018-01-31 19:51:43 +01:00
Romain Vimont
865ebb3862 Encode video using MediaCodec API
Replace screenrecord execution by manual screen encoding using the
MediaCodec API.

The "screenrecord" solution had several drawbacks:
 - screenrecord output is buffered, so tiny frames may not be accessible
   immediately;
 - it did not output a frame until the surface changed, leading to a
   black screen on start;
 - it is limited to 3 minutes recording, so it needed to be restarted;
 - screenrecord added black borders in the video when the requested
   dimensions did not preserve aspect-ratio exactly (sometimes
   unavoidable since video dimensions must be multiple of 8);
 - rotation handling was hacky (killing the process and starting a new
   one).

Handling the encoding manually allows to solve all these problems.
2018-01-31 19:51:43 +01:00
Romain Vimont
7ed334915e Register uncaught exception handler
Never miss an exception by using an uncaught exception handler.
2018-01-31 19:50:45 +01:00
Romain Vimont
8c4a454d68 Extract argument parsing
Move argument parsing to a separate method.
2018-01-31 19:49:49 +01:00
Romain Vimont
73831a0837 Use the Point class from the framework
Replace our custom Point class by android.graphics.Point.
2018-01-31 19:42:08 +01:00
Romain Vimont
b67907e24e Convert server to an Android project
To simplify the device server-side build, use gradle to create an APK,
even if we use it as a simple jar, by running its main() method.
2018-01-30 12:01:36 +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
2c4ea6869e Do not use device as a singleton
The device instance should be able to store a state (e.g. the maximum
size requested by the user), so it should not be a singleton.
2018-01-29 15:00:15 +01:00
Romain Vimont
879941355d Swap position/point names
A point is a 2D vector. A position represent a point relative to the
screen size.
2018-01-29 14:52:22 +01:00
Romain Vimont
f70359f14f Inject mouse events as touchscreen
As a mouse, some clicks on close prositions are sometimes not generated
on some devices.
2018-01-25 17:17:21 +01:00
Romain Vimont
1930c81062 Add toString() methods to java point classes
Useful for debugging.
2018-01-25 17:16:32 +01:00
Romain Vimont
dca53ff931 Add missing source files in server Makefile
All classes were still built, but make was not able to detect changes on
missing files.
2018-01-25 17:15:40 +01:00
Romain Vimont
2aa15db210 Add shortcut to resize to ratio 1:1
Make Ctrl+g resize the window to the size of the video (pixel-perfect).
2018-01-24 09:56:42 +01:00