From 4bb8104c204399f8f93b912fecb30fad848743d6 Mon Sep 17 00:00:00 2001 From: crertel Date: Mon, 24 Jun 2024 00:18:51 -0500 Subject: [PATCH 01/12] Update development flake. --- flake.nix | 54 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/flake.nix b/flake.nix index ec2fc83..62e11bb 100644 --- a/flake.nix +++ b/flake.nix @@ -7,27 +7,47 @@ }; outputs = { self, nixpkgs, flake-utils }: flake-utils.lib.eachDefaultSystem (system: - let - inherit (pkgs.lib) optional optionals; - pkgs = import nixpkgs { inherit system; }; + let + inherit (pkgs.lib) optional optionals; + pkgs = import nixpkgs { inherit system; }; - elixir = pkgs.beam.packages.erlang.elixir; - in - with pkgs; - { - devShell = pkgs.mkShell { - buildInputs = [ - elixir_1_16 - elixir_ls - glibcLocales - glew glfw pkg-config - xorg.libX11 xorg.libXau xorg.libXdmcp - ] ++ optional stdenv.isLinux inotify-tools + elixir = pkgs.beam.packages.erlang.elixir; + in + with pkgs; + { + devShell = pkgs.mkShell { + buildInputs = [ + util-linux + libselinux + libthai + libdatrie + libsepol + libxkbcommon + libepoxy + pcre + pcre2 + xorg.libXtst + cairo + gtk3 + freeglut + elixir_1_16 + elixir_ls + glibcLocales + glew + glfw + pkg-config + xorg.libX11 + xorg.libXau + xorg.libXdmcp + xorg.libX11 + xorg.libXau + xorg.libXdmcp + ] ++ optional stdenv.isLinux inotify-tools ++ optional stdenv.isDarwin terminal-notifier ++ optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ CoreFoundation CoreServices ]); - }; - }); + }; + }); } From 00a6e1cb0104c93aec95ede6f4ba1e7cc510e627 Mon Sep 17 00:00:00 2001 From: crertel Date: Mon, 24 Jun 2024 02:35:58 -0500 Subject: [PATCH 02/12] Add Elixir 1.16, Erlang 26.2 as CI targets. --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a701a70..c82d97f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -20,6 +20,8 @@ jobs: include: - elixir: '1.12.3' otp: '24.2' + - elixir: '1.16.0' + otp: '26.2' steps: - uses: actions/checkout@v3 From c9bb168bbbea57d232bb48867ba8498add616136 Mon Sep 17 00:00:00 2001 From: crertel Date: Mon, 24 Jun 2024 02:36:22 -0500 Subject: [PATCH 03/12] Version 0.12.0-rc.0 --- mix.exs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mix.exs b/mix.exs index 93c9c0f..16484e0 100644 --- a/mix.exs +++ b/mix.exs @@ -2,7 +2,7 @@ defmodule Scenic.Driver.Local.MixProject do use Mix.Project @app_name :scenic_driver_local - @version "0.11.0" + @version "0.12.0-rc.0" @github "https://github.com/ScenicFramework/scenic_driver_local" def project do @@ -49,7 +49,7 @@ defmodule Scenic.Driver.Local.MixProject do defp deps do [ {:input_event, "~> 1.0 or ~> 0.4"}, - {:scenic, "~> 0.11.0"}, + {:scenic, "~> 0.12"}, # Tools {:credo, ">= 0.0.0", only: [:dev, :test], runtime: false}, From 95c75fba8eaa7b654bf57fa1d64a2cacf7a841fe Mon Sep 17 00:00:00 2001 From: crertel Date: Mon, 24 Jun 2024 02:36:40 -0500 Subject: [PATCH 04/12] Update README, CHANGELOG --- CHANGELOG.md | 36 ++++++++++++++++++++++++++++++++++-- README.md | 18 ++++++++++++------ 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ccd22ee..884ada4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,38 @@ -## Unreleased -* Added Cairo support - @ringlej +## 0.12.0-rc.0 +This is a major update that adds support for Cairo and makes Cairo the default renderer: + +* Add Cairo support - @ringlej * Restructure C code - @ringlej +* Add CI - @axelson +* Updat README for 0.12 - @axelson +* Improve text handling - @JediLuke +* Better control of scene element opacity wiht `:clear` background - @seb3s +* Add `input_blacklist` options to remove `InputEvent` streams - @ringlej +* Fix `script_opts_draw_line` to handle stroke properly - @ringlej +* Add arc script command - @GPrimola +* Fix `LINE_CAP_ROUND -> LINE_JOIN_ROUND` in nanovg backend - @ringlej +* Fix extra `free` in image code - @ringlej +* Fix hidden cursor on refocus and repaint for nanovg backend - @mneumann +* Fix readme typo - @seb3s +* Add FPS and debug logging - @ringlej +* Add alpha channel support for sprites - @seb3s +* Add support for rounded rectangles - @GPrimola +* Add configurable framebuffer device for cairo - @jimsynz +* Assorted updates for deprecations and warnings + + + + + +Note: for Nerves setups you may need additional configuration for your display +to work as expected. If you're using an RPI3 you may want to add an `erlinit` +configuration so that your IEx output isn't displayed on the screen. To do so in your `config/target.exs` add: +``` +# From: https://hexdocs.pm/nerves/1.10.5/connecting-to-a-nerves-target.html#hdmi-cable +`config :nerves, :erlinit, ctty: "ttyAMA0"` +``` + + ## 0.11.0 Very minor fixes diff --git a/README.md b/README.md index 060a67e..d8db446 100644 --- a/README.md +++ b/README.md @@ -9,13 +9,13 @@ This driver replaces both `:scenic_driver_glfw` and `:scenic_driver_nerves_rpi` ## Installation -If [available in Hex](https://hex.pm/docs/publish), the package can be installed -by adding `scenic_driver_local` to your list of dependencies in `mix.exs`: +scenic_driver_local can be installed by adding `scenic_driver_local` to your +list of dependencies in `mix.exs`: ```elixir def deps do [ - {:scenic_driver_local, "~> 0.11.0"} + {:scenic_driver_local, "~> 0.12.0"} ] end ``` @@ -35,9 +35,9 @@ Example: There are quite a few new options as well. It uses `NimbleOptions` to confirm them, so look at the `Scenic.Driver.Local` module for details. -## Targets +## Targets (Nerves) -This driver figures out what underlying graphics technology to use depending on what your MIX_TARGET is set to. +This driver figures out what underlying graphics technology to use depending on what your `MIX_TARGET` environment variable is set to. For example, for apps running on a Mac/PC/Linux, it is usually set to `host`, which causes the driver to use `cairo-gtk` as the underlying tech. @@ -49,7 +49,10 @@ Previous versions of `scenic_driver_local` would use `bcm` (Broadcom Manager) fo You can explicitly use these by setting `SCENIC_LOCAL_TARGET=bcm` or `SCENIC_LOCAL_TARGET=drm`, **but these options are being deprecated**. Please try the default of `SCENIC_LOCAL_TARGET=cairo-fb` as this should work universally on any Nerves target. -`cairo-fb` will require that your `nerves_system_*` has the `cairo` library selected. +`cairo-fb` will require that your `nerves_system_*` has the `cairo` library +selected via the `BR2_PACKAGE_CAIRO=y` buildroot configuration. If you're using +one of the official nerves systems then `BR2_PACKAGE_CAIRO=y` is configured by +default if you're using 1.25.0 or greater. ## Prerequisites @@ -108,6 +111,9 @@ Lastly, install the GLEW package. Find the packaged `include` folder and extract Once these components have been installed, you should be able to build the `scenic_driver_local` driver. +### Installing on Nerves + +See the "Targets" section above ## Documentation From 9678a335a90e06373804729a8d1b8fdc3c321b67 Mon Sep 17 00:00:00 2001 From: crertel Date: Tue, 25 Jun 2024 00:35:41 -0500 Subject: [PATCH 05/12] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 884ada4..999c0e3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ This is a major update that adds support for Cairo and makes Cairo the default r * Add CI - @axelson * Updat README for 0.12 - @axelson * Improve text handling - @JediLuke -* Better control of scene element opacity wiht `:clear` background - @seb3s +* Better control of scene element opacity with `:clear` background - @seb3s * Add `input_blacklist` options to remove `InputEvent` streams - @ringlej * Fix `script_opts_draw_line` to handle stroke properly - @ringlej * Add arc script command - @GPrimola From 717c75a3cedcb92adc9cbaf9e2233dcb3556a0c3 Mon Sep 17 00:00:00 2001 From: crertel Date: Tue, 25 Jun 2024 01:38:48 -0500 Subject: [PATCH 06/12] Require Elixir 1.16 --- .github/workflows/ci.yml | 4 +--- CHANGELOG.md | 3 +++ mix.exs | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c82d97f..043333d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,9 +17,7 @@ jobs: strategy: fail-fast: false matrix: - include: - - elixir: '1.12.3' - otp: '24.2' + include: - elixir: '1.16.0' otp: '26.2' diff --git a/CHANGELOG.md b/CHANGELOG.md index 999c0e3..6afe5b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ ## 0.12.0-rc.0 + +**Note: as of v0.12.0 we'll be requiring at least Elixir 1.16** + This is a major update that adds support for Cairo and makes Cairo the default renderer: * Add Cairo support - @ringlej diff --git a/mix.exs b/mix.exs index 16484e0..6e52c5e 100644 --- a/mix.exs +++ b/mix.exs @@ -9,7 +9,7 @@ defmodule Scenic.Driver.Local.MixProject do [ app: @app_name, version: @version, - elixir: "~> 1.12", + elixir: "~> 1.16", start_permanent: Mix.env() == :prod, description: description(), build_embedded: true, From 86d688daa4fb69bafccdc523ff1cfc0480f85aad Mon Sep 17 00:00:00 2001 From: crertel Date: Tue, 25 Jun 2024 01:45:12 -0500 Subject: [PATCH 07/12] Depend on Scenic 0.12.0-rc.0 --- mix.exs | 2 +- mix.lock | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mix.exs b/mix.exs index 6e52c5e..427d90d 100644 --- a/mix.exs +++ b/mix.exs @@ -49,7 +49,7 @@ defmodule Scenic.Driver.Local.MixProject do defp deps do [ {:input_event, "~> 1.0 or ~> 0.4"}, - {:scenic, "~> 0.12"}, + {:scenic, "~> 0.12.0-rc.0"}, # Tools {:credo, ">= 0.0.0", only: [:dev, :test], runtime: false}, diff --git a/mix.lock b/mix.lock index 542e87e..f560cfd 100644 --- a/mix.lock +++ b/mix.lock @@ -3,7 +3,7 @@ "credo": {:hex, :credo, "1.7.2", "fdee3a7cb553d8f2e773569181f0a4a2bb7d192e27e325404cc31b354f59d68c", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "dd15d6fbc280f6cf9b269f41df4e4992dee6615939653b164ef951f60afcb68e"}, "dialyxir": {:hex, :dialyxir, "1.4.3", "edd0124f358f0b9e95bfe53a9fcf806d615d8f838e2202a9f430d59566b6b53b", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "bf2cfb75cd5c5006bec30141b131663299c661a864ec7fbbc72dfa557487a986"}, "earmark_parser": {:hex, :earmark_parser, "1.4.39", "424642f8335b05bb9eb611aa1564c148a8ee35c9c8a8bba6e129d51a3e3c6769", [:mix], [], "hexpm", "06553a88d1f1846da9ef066b87b57c6f605552cfbe40d20bd8d59cc6bde41944"}, - "elixir_make": {:hex, :elixir_make, "0.6.3", "bc07d53221216838d79e03a8019d0839786703129599e9619f4ab74c8c096eac", [:mix], [], "hexpm", "f5cbd651c5678bcaabdbb7857658ee106b12509cd976c2c2fca99688e1daf716"}, + "elixir_make": {:hex, :elixir_make, "0.8.4", "4960a03ce79081dee8fe119d80ad372c4e7badb84c493cc75983f9d3bc8bde0f", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:certifi, "~> 2.0", [hex: :certifi, repo: "hexpm", optional: true]}], "hexpm", "6e7f1d619b5f61dfabd0a20aa268e575572b542ac31723293a4c1a567d5ef040"}, "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, "ex_doc": {:hex, :ex_doc, "0.31.0", "06eb1dfd787445d9cab9a45088405593dd3bb7fe99e097eaa71f37ba80c7a676", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.1", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "5350cafa6b7f77bdd107aa2199fe277acf29d739aba5aee7e865fc680c62a110"}, "ex_image_info": {:hex, :ex_image_info, "0.2.4", "610002acba43520a9b1cf1421d55812bde5b8a8aeaf1fe7b1f8823e84e762adb", [:mix], [], "hexpm", "fd1a7e02664e3b14dfd3b231d22fdd48bd3dd694c4773e6272b3a6228f1106bc"}, @@ -14,8 +14,8 @@ "makeup": {:hex, :makeup, "1.1.1", "fa0bc768698053b2b3869fa8a62616501ff9d11a562f3ce39580d60860c3a55e", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "5dc62fbdd0de44de194898b6710692490be74baa02d9d108bc29f007783b0b48"}, "makeup_elixir": {:hex, :makeup_elixir, "0.16.1", "cc9e3ca312f1cfeccc572b37a09980287e243648108384b97ff2b76e505c3555", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e127a341ad1b209bd80f7bd1620a15693a9908ed780c3b763bccf7d200c767c6"}, "makeup_erlang": {:hex, :makeup_erlang, "0.1.3", "d684f4bac8690e70b06eb52dad65d26de2eefa44cd19d64a8095e1417df7c8fd", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "b78dc853d2e670ff6390b605d807263bf606da3c82be37f9d7f68635bd886fc9"}, - "nimble_options": {:hex, :nimble_options, "0.4.0", "c89babbab52221a24b8d1ff9e7d838be70f0d871be823165c94dd3418eea728f", [:mix], [], "hexpm", "e6701c1af326a11eea9634a3b1c62b475339ace9456c1a23ec3bc9a847bca02d"}, + "nimble_options": {:hex, :nimble_options, "0.5.2", "42703307b924880f8c08d97719da7472673391905f528259915782bb346e0a1b", [:mix], [], "hexpm", "4da7f904b915fd71db549bcdc25f8d56f378ef7ae07dc1d372cbe72ba950dce0"}, "nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"}, - "scenic": {:hex, :scenic, "0.11.1", "9cabc40a1362de76b25c9b243503251c9e9287816fab88b539c55e8debdb6513", [:make, :mix], [{:elixir_make, "~> 0.6.2", [hex: :elixir_make, repo: "hexpm", optional: false]}, {:ex_image_info, "~> 0.2.4", [hex: :ex_image_info, repo: "hexpm", optional: false]}, {:font_metrics, "~> 0.5.0", [hex: :font_metrics, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.3.4 or ~> 0.4.0", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:truetype_metrics, "~> 0.6", [hex: :truetype_metrics, repo: "hexpm", optional: false]}], "hexpm", "86845290002bb61ac34ab24573dfd0f15f1d17bb24fa68767af65601eaae5153"}, + "scenic": {:hex, :scenic, "0.12.0-rc.0", "e26ad0f70b401631487cae7f2f65d90d5cbe797c64db60e1dc73b8c50a9b3f5d", [:make, :mix], [{:elixir_make, "~> 0.8.4", [hex: :elixir_make, repo: "hexpm", optional: false]}, {:ex_image_info, "~> 0.2.4", [hex: :ex_image_info, repo: "hexpm", optional: false]}, {:font_metrics, "~> 0.5.0", [hex: :font_metrics, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.3.4 or ~> 0.4.0 or ~> 0.5.0 or ~> 1.1", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:truetype_metrics, "~> 0.6", [hex: :truetype_metrics, repo: "hexpm", optional: false]}], "hexpm", "7d341ab4276f376c772180f261de1a13fd1c6df0dd1334c0418d41510ab751a1"}, "truetype_metrics": {:hex, :truetype_metrics, "0.6.1", "9119a04dc269dd8f63e85e12e4098f711cb7c5204a420f4896f40667b9e064f6", [:mix], [{:font_metrics, "~> 0.5", [hex: :font_metrics, repo: "hexpm", optional: false]}], "hexpm", "5711d4a3e4fc92eb073326fbe54208925d35168dc9b288c331ee666a8a84759b"}, } From 984bde83754664d10d32eecadb3c4544630c485e Mon Sep 17 00:00:00 2001 From: crertel Date: Tue, 25 Jun 2024 01:46:32 -0500 Subject: [PATCH 08/12] credo: with -> case --- lib/input.ex | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/input.ex b/lib/input.ex index 3fb8d75..2e9f526 100644 --- a/lib/input.ex +++ b/lib/input.ex @@ -100,7 +100,8 @@ defmodule Scenic.Driver.Local.Input do # Logger.warn( "INPUT #{source}: #{inspect(events)}" ) driver = - with {:ok, device} <- Map.fetch(input_state, source) do + case Map.fetch(input_state, source) do + {:ok, device} -> # record the old pos and key state %{abs_pos: old_abs_pos} = device @@ -199,7 +200,7 @@ defmodule Scenic.Driver.Local.Input do # save the completed device state in the input state input_state = Map.put(input_state, source, device) assign(driver, input_state: input_state) - else + _ -> driver end From 9adf69a8dfb09060217bd9555bd6fc6ab503ef18 Mon Sep 17 00:00:00 2001 From: crertel Date: Tue, 25 Jun 2024 01:47:24 -0500 Subject: [PATCH 09/12] credo: with -> case --- lib/callbacks.ex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/callbacks.ex b/lib/callbacks.ex index aeb7d2f..37efaf9 100644 --- a/lib/callbacks.ex +++ b/lib/callbacks.ex @@ -189,7 +189,8 @@ defmodule Scenic.Driver.Local.Callbacks do # -------------------------------------------------------- defp do_put_scripts(%{assigns: %{port: port}, viewport: vp} = driver, ids) do Enum.reduce(ids, driver, fn id, driver -> - with {:ok, script} <- ViewPort.get_script(vp, id) do + case ViewPort.get_script(vp, id) do + {:ok, script} -> driver = ensure_media(script, driver) script @@ -197,7 +198,6 @@ defmodule Scenic.Driver.Local.Callbacks do |> ToPort.put_script(id, port) driver - else _ -> driver end end) From e2760b87d4187d0a3bf9e3f90e6b65e9ad6cac0e Mon Sep 17 00:00:00 2001 From: crertel Date: Tue, 25 Jun 2024 01:49:18 -0500 Subject: [PATCH 10/12] credo: cond -> if --- lib/to_port.ex | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/to_port.ex b/lib/to_port.ex index ff41e18..52d0545 100644 --- a/lib/to_port.ex +++ b/lib/to_port.ex @@ -191,17 +191,18 @@ defmodule Scenic.Driver.Local.ToPort do @doc false def reshape(width, height, port) when is_integer(width) and is_integer(height) do # enforce a minimum size... - w = - cond do - width < @min_window_width -> @min_window_width - true -> width - end - - h = - cond do - height < @min_window_height -> @min_window_height - true -> height - end + w = if width < @min_window_width do + @min_window_width + else + width + end + + + h = if height < @min_window_height do + @min_window_height + else + height + end msg = << @cmd_reshape::unsigned-integer-size(32)-native, From acf1b330af7b908854298f942b73ed9526b083dc Mon Sep 17 00:00:00 2001 From: crertel Date: Tue, 25 Jun 2024 01:49:32 -0500 Subject: [PATCH 11/12] mix format --- lib/callbacks.ex | 16 ++-- lib/input.ex | 184 ++++++++++++++++++++++--------------------- lib/to_port.ex | 25 +++--- test/driver_test.exs | 2 +- 4 files changed, 117 insertions(+), 110 deletions(-) diff --git a/lib/callbacks.ex b/lib/callbacks.ex index 37efaf9..0143b14 100644 --- a/lib/callbacks.ex +++ b/lib/callbacks.ex @@ -190,15 +190,17 @@ defmodule Scenic.Driver.Local.Callbacks do defp do_put_scripts(%{assigns: %{port: port}, viewport: vp} = driver, ids) do Enum.reduce(ids, driver, fn id, driver -> case ViewPort.get_script(vp, id) do - {:ok, script} -> - driver = ensure_media(script, driver) + {:ok, script} -> + driver = ensure_media(script, driver) - script - |> Script.serialize() - |> ToPort.put_script(id, port) + script + |> Script.serialize() + |> ToPort.put_script(id, port) - driver - _ -> driver + driver + + _ -> + driver end end) end diff --git a/lib/input.ex b/lib/input.ex index 2e9f526..63d0213 100644 --- a/lib/input.ex +++ b/lib/input.ex @@ -102,106 +102,110 @@ defmodule Scenic.Driver.Local.Input do driver = case Map.fetch(input_state, source) do {:ok, device} -> - # record the old pos and key state - %{abs_pos: old_abs_pos} = device - - # add some zero'd out relative values to the device state - device = - device - |> Map.put(:rel_pos_dx, 0) - |> Map.put(:rel_pos_dy, 0) - |> Map.put(:rel_wheel_dx, 0) - |> Map.put(:rel_wheel_dy, 0) - - # process the events - {device, driver} = - Enum.reduce(events, {device, driver}, fn event, {%{debounce: db}, _} = acc -> - case Enum.member?(db, event) do - true -> acc - false -> do_input_event(event, source, acc) + # record the old pos and key state + %{abs_pos: old_abs_pos} = device + + # add some zero'd out relative values to the device state + device = + device + |> Map.put(:rel_pos_dx, 0) + |> Map.put(:rel_pos_dy, 0) + |> Map.put(:rel_wheel_dx, 0) + |> Map.put(:rel_wheel_dy, 0) + + # process the events + {device, driver} = + Enum.reduce(events, {device, driver}, fn event, {%{debounce: db}, _} = acc -> + case Enum.member?(db, event) do + true -> acc + false -> do_input_event(event, source, acc) + end + end) + + # if the absolute position changed (example: by a touchscreen), then calculate the + # normal (not transformed) screen coordinates and move that into the cursor_pos + new_abs_pos = device[:abs_pos] + + driver = + case new_abs_pos != old_abs_pos do + true -> assign(driver, :cursor_pos, new_abs_pos) + false -> driver end - end) - - # if the absolute position changed (example: by a touchscreen), then calculate the - # normal (not transformed) screen coordinates and move that into the cursor_pos - new_abs_pos = device[:abs_pos] - driver = - case new_abs_pos != old_abs_pos do - true -> assign(driver, :cursor_pos, new_abs_pos) - false -> driver + # parse rest if the state + %{ + rel_wheel_dx: rel_wheel_dx, + rel_wheel_dy: rel_wheel_dy + } = device + + %{ + assigns: %{ + cursor_pos: new_cursor_pos, + keys: new_keys + } + } = driver + + # calculate the cursor position in scene coordinates + scene_pos = scene_coords(new_cursor_pos, device, driver) + + # the regular cursor_scroll event + if rel_wheel_dx != 0 || rel_wheel_dy != 0 do + # vector = scene_rel({rel_wheel_dx, rel_wheel_dy}, device, driver) + vector = {rel_wheel_dx, rel_wheel_dy} + send_input(driver, {:cursor_scroll, {vector, scene_pos}}) end - # parse rest if the state - %{ - rel_wheel_dx: rel_wheel_dx, - rel_wheel_dy: rel_wheel_dy - } = device - - %{ - assigns: %{ - cursor_pos: new_cursor_pos, - keys: new_keys - } - } = driver + # The cursor itself would have changed if absolute position devices were in use + driver = + with true <- auto_cursor, + true <- new_cursor_pos != old_cursor_pos do + send_input(driver, {:cursor_pos, scene_pos}) - # calculate the cursor position in scene coordinates - scene_pos = scene_coords(new_cursor_pos, device, driver) - - # the regular cursor_scroll event - if rel_wheel_dx != 0 || rel_wheel_dy != 0 do - # vector = scene_rel({rel_wheel_dx, rel_wheel_dy}, device, driver) - vector = {rel_wheel_dx, rel_wheel_dy} - send_input(driver, {:cursor_scroll, {vector, scene_pos}}) - end - - # The cursor itself would have changed if absolute position devices were in use - driver = - with true <- auto_cursor, - true <- new_cursor_pos != old_cursor_pos do - send_input(driver, {:cursor_pos, scene_pos}) - - driver - |> Cursor.hide() - |> Cursor.set_position(new_cursor_pos) - else - _ -> driver - end - - # generate the cursor button events - # we didn't generate them at the time the button was pressed because the x/y position - # changes are often after them in the event list. So... process the event first then - # rescan the events looking for any button events that would trigger an input - Enum.each(events, fn - {:ev_key, key, value} -> - with "btn_" <> _ <- to_string(key) do - # special case btn_touch to be a left mouse button press - {btn, driver} = - case key do - :btn_touch -> {:btn_left, Cursor.hide(driver)} - btn -> {btn, driver} - end - - send_input(driver, {:cursor_button, {btn, value, KeyMap.mods(new_keys), scene_pos}}) + driver + |> Cursor.hide() + |> Cursor.set_position(new_cursor_pos) + else + _ -> driver end - _ -> - :ok - end) + # generate the cursor button events + # we didn't generate them at the time the button was pressed because the x/y position + # changes are often after them in the event list. So... process the event first then + # rescan the events looking for any button events that would trigger an input + Enum.each(events, fn + {:ev_key, key, value} -> + with "btn_" <> _ <- to_string(key) do + # special case btn_touch to be a left mouse button press + {btn, driver} = + case key do + :btn_touch -> {:btn_left, Cursor.hide(driver)} + btn -> {btn, driver} + end + + send_input( + driver, + {:cursor_button, {btn, value, KeyMap.mods(new_keys), scene_pos}} + ) + end + + _ -> + :ok + end) - # clean up the temporary relative device state - device = - device - |> Map.delete(:rel_pos_dx) - |> Map.delete(:rel_pos_dy) - |> Map.delete(:rel_wheel_dx) - |> Map.delete(:rel_wheel_dy) + # clean up the temporary relative device state + device = + device + |> Map.delete(:rel_pos_dx) + |> Map.delete(:rel_pos_dy) + |> Map.delete(:rel_wheel_dx) + |> Map.delete(:rel_wheel_dy) - # save the completed device state in the input state - input_state = Map.put(input_state, source, device) - assign(driver, input_state: input_state) + # save the completed device state in the input state + input_state = Map.put(input_state, source, device) + assign(driver, input_state: input_state) - _ -> driver + _ -> + driver end {:noreply, driver} diff --git a/lib/to_port.ex b/lib/to_port.ex index 52d0545..50e584e 100644 --- a/lib/to_port.ex +++ b/lib/to_port.ex @@ -191,18 +191,19 @@ defmodule Scenic.Driver.Local.ToPort do @doc false def reshape(width, height, port) when is_integer(width) and is_integer(height) do # enforce a minimum size... - w = if width < @min_window_width do - @min_window_width - else - width - end - - - h = if height < @min_window_height do - @min_window_height - else - height - end + w = + if width < @min_window_width do + @min_window_width + else + width + end + + h = + if height < @min_window_height do + @min_window_height + else + height + end msg = << @cmd_reshape::unsigned-integer-size(32)-native, diff --git a/test/driver_test.exs b/test/driver_test.exs index ad9dc55..565a82c 100644 --- a/test/driver_test.exs +++ b/test/driver_test.exs @@ -31,7 +31,7 @@ defmodule Scenic.Driver.LocalTest do end test "validate_opts/1 with invalid opts" do - assert {:error, validation_error} = Scenic.Driver.Local.validate_opts(name: 'Bob') + assert {:error, validation_error} = Scenic.Driver.Local.validate_opts(name: ~c"Bob") assert validation_error.message =~ "expected :name" end From bc54c8198752f7482d8143aa0120adbc6fc564bb Mon Sep 17 00:00:00 2001 From: crertel Date: Tue, 25 Jun 2024 01:53:40 -0500 Subject: [PATCH 12/12] bump deps --- mix.exs | 10 +++++----- mix.lock | 12 ++++++------ 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/mix.exs b/mix.exs index 427d90d..b6c83ee 100644 --- a/mix.exs +++ b/mix.exs @@ -48,14 +48,14 @@ defmodule Scenic.Driver.Local.MixProject do # Run "mix help deps" to learn about dependencies. defp deps do [ - {:input_event, "~> 1.0 or ~> 0.4"}, + {:input_event, "~> 1.4"}, {:scenic, "~> 0.12.0-rc.0"}, # Tools - {:credo, ">= 0.0.0", only: [:dev, :test], runtime: false}, - {:elixir_make, "~> 0.6 or ~> 0.7", runtime: false}, - {:ex_doc, ">= 0.0.0", only: :dev, runtime: false}, - {:dialyxir, "~> 1.1", only: :dev, runtime: false} + {:credo, ">= 1.7.7", only: [:dev, :test], runtime: false}, + {:elixir_make, "~> 0.8", runtime: false}, + {:ex_doc, ">= 0.34.1", only: :dev, runtime: false}, + {:dialyxir, "~> 1.4", only: :dev, runtime: false} ] end diff --git a/mix.lock b/mix.lock index f560cfd..1a5c3e4 100644 --- a/mix.lock +++ b/mix.lock @@ -1,19 +1,19 @@ %{ "bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"}, - "credo": {:hex, :credo, "1.7.2", "fdee3a7cb553d8f2e773569181f0a4a2bb7d192e27e325404cc31b354f59d68c", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "dd15d6fbc280f6cf9b269f41df4e4992dee6615939653b164ef951f60afcb68e"}, + "credo": {:hex, :credo, "1.7.7", "771445037228f763f9b2afd612b6aa2fd8e28432a95dbbc60d8e03ce71ba4446", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "8bc87496c9aaacdc3f90f01b7b0582467b69b4bd2441fe8aae3109d843cc2f2e"}, "dialyxir": {:hex, :dialyxir, "1.4.3", "edd0124f358f0b9e95bfe53a9fcf806d615d8f838e2202a9f430d59566b6b53b", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "bf2cfb75cd5c5006bec30141b131663299c661a864ec7fbbc72dfa557487a986"}, "earmark_parser": {:hex, :earmark_parser, "1.4.39", "424642f8335b05bb9eb611aa1564c148a8ee35c9c8a8bba6e129d51a3e3c6769", [:mix], [], "hexpm", "06553a88d1f1846da9ef066b87b57c6f605552cfbe40d20bd8d59cc6bde41944"}, "elixir_make": {:hex, :elixir_make, "0.8.4", "4960a03ce79081dee8fe119d80ad372c4e7badb84c493cc75983f9d3bc8bde0f", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:certifi, "~> 2.0", [hex: :certifi, repo: "hexpm", optional: true]}], "hexpm", "6e7f1d619b5f61dfabd0a20aa268e575572b542ac31723293a4c1a567d5ef040"}, "erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"}, - "ex_doc": {:hex, :ex_doc, "0.31.0", "06eb1dfd787445d9cab9a45088405593dd3bb7fe99e097eaa71f37ba80c7a676", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.1", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "5350cafa6b7f77bdd107aa2199fe277acf29d739aba5aee7e865fc680c62a110"}, + "ex_doc": {:hex, :ex_doc, "0.34.1", "9751a0419bc15bc7580c73fde506b17b07f6402a1e5243be9e0f05a68c723368", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "d441f1a86a235f59088978eff870de2e815e290e44a8bd976fe5d64470a4c9d2"}, "ex_image_info": {:hex, :ex_image_info, "0.2.4", "610002acba43520a9b1cf1421d55812bde5b8a8aeaf1fe7b1f8823e84e762adb", [:mix], [], "hexpm", "fd1a7e02664e3b14dfd3b231d22fdd48bd3dd694c4773e6272b3a6228f1106bc"}, "file_system": {:hex, :file_system, "1.0.0", "b689cc7dcee665f774de94b5a832e578bd7963c8e637ef940cd44327db7de2cd", [:mix], [], "hexpm", "6752092d66aec5a10e662aefeed8ddb9531d79db0bc145bb8c40325ca1d8536d"}, "font_metrics": {:hex, :font_metrics, "0.5.1", "10ce0b8b1bf092a2d3d307e05a7c433787ae8ca7cd1f3cf959995a628809a994", [:mix], [{:nimble_options, "~> 0.3", [hex: :nimble_options, repo: "hexpm", optional: false]}], "hexpm", "192e4288772839ae4dadccb0f5b1d5c89b73a0c3961ccea14b6181fdcd535e54"}, - "input_event": {:hex, :input_event, "1.0.0", "061f5524a746d067f50b1e1620857a3e0f815e0508c5331340cd164b06a723b1", [:make, :mix], [{:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "0470eb939199a5ec49bd626a220ed7074da8f3febb82046edd786b10a90588fc"}, + "input_event": {:hex, :input_event, "1.4.2", "8ad280387595110cf4ac4d92cfcfd2f5d61f7285084f35adc5feec077df23058", [:make, :mix], [{:elixir_make, "~> 0.6", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "eb12e3a5d83f2c570d965ad0a5de7bea7c9f387b425ae882c00f3a2a00971e3f"}, "jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"}, - "makeup": {:hex, :makeup, "1.1.1", "fa0bc768698053b2b3869fa8a62616501ff9d11a562f3ce39580d60860c3a55e", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "5dc62fbdd0de44de194898b6710692490be74baa02d9d108bc29f007783b0b48"}, - "makeup_elixir": {:hex, :makeup_elixir, "0.16.1", "cc9e3ca312f1cfeccc572b37a09980287e243648108384b97ff2b76e505c3555", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e127a341ad1b209bd80f7bd1620a15693a9908ed780c3b763bccf7d200c767c6"}, - "makeup_erlang": {:hex, :makeup_erlang, "0.1.3", "d684f4bac8690e70b06eb52dad65d26de2eefa44cd19d64a8095e1417df7c8fd", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "b78dc853d2e670ff6390b605d807263bf606da3c82be37f9d7f68635bd886fc9"}, + "makeup": {:hex, :makeup, "1.1.2", "9ba8837913bdf757787e71c1581c21f9d2455f4dd04cfca785c70bbfff1a76a3", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cce1566b81fbcbd21eca8ffe808f33b221f9eee2cbc7a1706fc3da9ff18e6cac"}, + "makeup_elixir": {:hex, :makeup_elixir, "0.16.2", "627e84b8e8bf22e60a2579dad15067c755531fea049ae26ef1020cad58fe9578", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "41193978704763f6bbe6cc2758b84909e62984c7752b3784bd3c218bb341706b"}, + "makeup_erlang": {:hex, :makeup_erlang, "1.0.0", "6f0eff9c9c489f26b69b61440bf1b238d95badae49adac77973cbacae87e3c2e", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "ea7a9307de9d1548d2a72d299058d1fd2339e3d398560a0e46c27dab4891e4d2"}, "nimble_options": {:hex, :nimble_options, "0.5.2", "42703307b924880f8c08d97719da7472673391905f528259915782bb346e0a1b", [:mix], [], "hexpm", "4da7f904b915fd71db549bcdc25f8d56f378ef7ae07dc1d372cbe72ba950dce0"}, "nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"}, "scenic": {:hex, :scenic, "0.12.0-rc.0", "e26ad0f70b401631487cae7f2f65d90d5cbe797c64db60e1dc73b8c50a9b3f5d", [:make, :mix], [{:elixir_make, "~> 0.8.4", [hex: :elixir_make, repo: "hexpm", optional: false]}, {:ex_image_info, "~> 0.2.4", [hex: :ex_image_info, repo: "hexpm", optional: false]}, {:font_metrics, "~> 0.5.0", [hex: :font_metrics, repo: "hexpm", optional: false]}, {:nimble_options, "~> 0.3.4 or ~> 0.4.0 or ~> 0.5.0 or ~> 1.1", [hex: :nimble_options, repo: "hexpm", optional: false]}, {:truetype_metrics, "~> 0.6", [hex: :truetype_metrics, repo: "hexpm", optional: false]}], "hexpm", "7d341ab4276f376c772180f261de1a13fd1c6df0dd1334c0418d41510ab751a1"},