Skip to content

add cmdline option for specifying physical screen dimensions #76

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## 📰 NEWS
- the physical dimensions of the screen can now be specified via cmdline, using the `--dimensions` option.
- the layout of the engine-binaries branch has changed again. The symbolic link from `libflutter_engine.so` to the fitting `libflutter_engine.so.release` or `libflutter_engine.so.debug` is no longer needed, flutter-pi will now dynamically load the engine fitting the the runtime mode that was specified via cmdline. (if `--release` is given, flutter-pi will load `libflutter_engine.so.release`, else `libflutter_engine.so.debug`)
- flutter-pi now requires `libsystemd-dev`, `libinput-dev` and `libudev-dev` at compile-time. (`libudev-dev` is actually optional. To build without udev support, use cmake.)
- flutter-pi and the engine binaries updated for flutter 1.20.
Expand Down Expand Up @@ -120,9 +121,11 @@ OPTIONS:
pattern you use as a parameter so it isn't
implicitly expanded by your shell.

--aot Run the app in AOT mode. The AOT snapshot
--release Run the app in release mode. The AOT snapshot
of the app ("app.so") must be located inside the
asset bundle directory.
This also requires a libflutter_engine.so that was
built with --runtime-mode=release.

-o, --orientation <orientation> Start the app in this orientation. Valid
for <orientation> are: portrait_up, landscape_left,
Expand All @@ -139,6 +142,13 @@ OPTIONS:
clock-wise.
Valid values are 0, 90, 180 and 270.

-d, --dimensions "width_mm,height_mm" The width & height of your display in
millimeters. Useful if your GPU doesn't provide
valid physical dimensions for your display.
The physical dimensions of your display are used
to calculate the flutter device-pixel-ratio, which
in turn basically "scales" the UI.

--no-text-input Disable text input from the console.
This means flutter-pi won't configure the console
to raw/non-canonical mode.
Expand All @@ -150,7 +160,18 @@ EXAMPLES:
flutter-pi -i "/dev/input/mouse*" /home/pi/helloworld_flutterassets
flutter-pi -o portrait_up ./flutter_assets
flutter-pi -r 90 ./flutter_assets
flutter-pi -d "155, 86" ./flutter_assets
flutter-pi /home/pi/helloworld_flutterassets

SEE ALSO:
Author: Hannes Winkler, a.k.a ardera
Source: https://github.com/ardera/flutter-pi
License: MIT

For instructions on how to build an asset bundle or an AOT snapshot
of your app, please see the linked git repository.
For a list of options you can pass to the flutter engine, look here:
https://github.com/flutter/engine/blob/master/shell/common/switches.h
```

`<asset bundle path>` is the path of the flutter asset bundle directory (i.e. the directory containing `kernel_blob.bin`)
Expand Down
58 changes: 41 additions & 17 deletions src/flutter-pi.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ OPTIONS:\n\
clock-wise.\n\
Valid values are 0, 90, 180 and 270.\n\
\n\
-d, --dimensions \"width_mm,height_mm\" The width & height of your display in\n\
millimeters. Useful if your GPU doesn't provide\n\
valid physical dimensions for your display.\n\
The physical dimensions of your display are used\n\
to calculate the flutter device-pixel-ratio, which\n\
in turn basically \"scales\" the UI.\n\
\n\
--no-text-input Disable text input from the console.\n\
This means flutter-pi won't configure the console\n\
to raw/non-canonical mode.\n\
Expand All @@ -109,6 +116,7 @@ EXAMPLES:\n\
flutter-pi -i \"/dev/input/mouse*\" /home/pi/helloworld_flutterassets\n\
flutter-pi -o portrait_up ./flutter_assets\n\
flutter-pi -r 90 ./flutter_assets\n\
flutter-pi -d \"155, 86\" ./flutter_assets\n\
flutter-pi /home/pi/helloworld_flutterassets\n\
\n\
SEE ALSO:\n\
Expand Down Expand Up @@ -1189,26 +1197,26 @@ static int init_display(void) {
}

// find a connected connector
flutterpi.display.width_mm = 0;
flutterpi.display.height_mm = 0;
for_each_connector_in_drmdev(flutterpi.drm.drmdev, connector) {
if (connector->connector->connection == DRM_MODE_CONNECTED) {
// only update the physical size of the display if the values
// are not yet initialized / not set with a commandline option
if ((connector->connector->connector_type == DRM_MODE_CONNECTOR_DSI) &&
(connector->connector->mmWidth == 0) &&
(connector->connector->mmHeight == 0))
{
// if it's connected via DSI, and the width & height are 0,
// it's probably the official 7 inch touchscreen.
flutterpi.display.width_mm = 155;
flutterpi.display.height_mm = 86;
} else if ((connector->connector->mmHeight % 10 == 0) &&
(connector->connector->mmWidth % 10 == 0)) {
// don't change anything.
} else {
flutterpi.display.width_mm = connector->connector->mmWidth;
flutterpi.display.height_mm = connector->connector->mmHeight;
if ((flutterpi.display.width_mm == 0) || (flutterpi.display.height_mm == 0)) {
if ((connector->connector->connector_type == DRM_MODE_CONNECTOR_DSI) &&
(connector->connector->mmWidth == 0) &&
(connector->connector->mmHeight == 0))
{
// if it's connected via DSI, and the width & height are 0,
// it's probably the official 7 inch touchscreen.
flutterpi.display.width_mm = 155;
flutterpi.display.height_mm = 86;
} else if ((connector->connector->mmHeight % 10 == 0) &&
(connector->connector->mmWidth % 10 == 0)) {
// don't change anything.
} else {
flutterpi.display.width_mm = connector->connector->mmWidth;
flutterpi.display.height_mm = connector->connector->mmHeight;
}
}

break;
Expand Down Expand Up @@ -2394,21 +2402,23 @@ static bool parse_cmd_args(int argc, char **argv) {
int longopt_index = 0;
int runtime_mode_int = kDebug;
int disable_text_input_int = false;
int ok;

struct option long_options[] = {
{"release", no_argument, &runtime_mode_int, kRelease},
{"input", required_argument, NULL, 'i'},
{"orientation", required_argument, NULL, 'o'},
{"rotation", required_argument, NULL, 'r'},
{"no-text-input", no_argument, &disable_text_input_int, true},
{"dimensions", required_argument, NULL, 'd'},
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};

bool finished_parsing_options = false;
while (!finished_parsing_options) {
longopt_index = 0;
opt = getopt_long(argc, argv, "+i:o:r:h", long_options, &longopt_index);
opt = getopt_long(argc, argv, "+i:o:r:d:h", long_options, &longopt_index);

switch (opt) {
case 0:
Expand Down Expand Up @@ -2461,6 +2471,20 @@ static bool parse_cmd_args(int argc, char **argv) {
flutterpi.view.rotation = rotation;
break;

case 'd': ;
unsigned int width_mm, height_mm;

ok = sscanf(optarg, "%u,%u", &width_mm, &height_mm);
if ((ok == 0) || (ok == EOF)) {
fprintf(stderr, "ERROR: Invalid argument for --dimensions passed.\n%s", usage);
return false;
}

flutterpi.display.width_mm = width_mm;
flutterpi.display.height_mm = height_mm;

break;

case 'h':
printf("%s", usage);
return false;
Expand Down