aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/release.yml112
-rw-r--r--Cargo.lock401
-rw-r--r--Cargo.toml7
-rw-r--r--src/bin/sctd.rs10
-rw-r--r--src/lib.rs48
-rw-r--r--src/platform.rs5
-rw-r--r--src/platform/linux.rs34
-rw-r--r--src/platform/macos.rs44
8 files changed, 460 insertions, 201 deletions
diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml
index a887f70..f63fdf0 100644
--- a/.github/workflows/release.yml
+++ b/.github/workflows/release.yml
@@ -4,50 +4,58 @@ on:
tags:
- '[0-9]+.[0-9]+.[0-9]+'
+permissions:
+ contents: write
+
jobs:
create-release:
name: create-release
- runs-on: ubuntu-18.04
+ runs-on: ubuntu-latest
+ outputs:
+ sctd_version: ${{ env.SCTD_VERSION }}
steps:
- - name: Create artifacts directory
- run: mkdir artifacts
-
+ - uses: actions/checkout@v4
- name: Get the release version from the tag
- if: env.SCTD_VERSION == ''
+ shell: bash
+ run: echo "SCTD_VERSION=${{ github.ref_name }}" >> $GITHUB_ENV
+ - name: Show the version
run: |
- echo "::set-env name=SCTD_VERSION::${GITHUB_REF#refs/tags/}"
- echo "version is: ${{ env.SCTD_VERSION }}"
-
+ echo "version is: $SCTD_VERSION"
+ - name: Check that tag version and Cargo.toml version are the same
+ shell: bash
+ run: |
+ if ! grep -q "version = \"$SCTD_VERSION\"" Cargo.toml; then
+ echo "version does not match Cargo.toml" >&2
+ exit 1
+ fi
- name: Create GitHub release
- id: release
- uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- with:
- tag_name: ${{ env.SCTD_VERSION }}
- release_name: ${{ env.SCTD_VERSION }}
-
- - name: Save release upload URL to artifact
- run: echo "${{ steps.release.outputs.upload_url }}" > artifacts/release-upload-url
-
- - name: Save version number to artifact
- run: echo "${{ env.SCTD_VERSION }}" > artifacts/release-version
-
- - name: Upload artifacts
- uses: actions/upload-artifact@v1
- with:
- name: artifacts
- path: artifacts
+ run: gh release create ${{ env.SCTD_VERSION }} --draft --verify-tag --title ${{ env.SCTD_VERSION }}
build-release:
name: build-release
needs: ['create-release']
- runs-on: ubuntu-18.04
+ runs-on: ${{ matrix.os }}
+ strategy:
+ matrix:
+ build: [linux, macos]
+ include:
+ - build: linux
+ os: ubuntu-latest
+ rust: stable
+ target: x86_64-unknown-linux-gnu
+ - build: macos
+ os: macos-latest
+ rust: stable
+ target: x86_64-apple-darwin
+
steps:
- name: Checkout repository
- uses: actions/checkout@v2
+ uses: actions/checkout@v4
- - name: Install packages
+ - name: Install packages (Linux)
+ if: matrix.build == 'linux'
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends \
@@ -55,47 +63,33 @@ jobs:
libxrandr-dev
- name: Install Rust
- uses: actions-rs/toolchain@v1
- with:
- toolchain: stable
- profile: minimal
- override: true
-
- - name: Get release upload URL
- uses: actions/download-artifact@v1
+ uses: dtolnay/rust-toolchain@master
with:
- name: artifacts
- path: artifacts
-
- - name: Set release upload URL and release version
- shell: bash
- run: |
- release_upload_url="$(cat artifacts/release-upload-url)"
- echo "::set-env name=RELEASE_UPLOAD_URL::$release_upload_url"
- echo "release upload url: $RELEASE_UPLOAD_URL"
- release_version="$(cat artifacts/release-version)"
- echo "::set-env name=RELEASE_VERSION::$release_version"
- echo "release version: $RELEASE_VERSION"
+ toolchain: ${{ matrix.rust }}
+ target: ${{ matrix.target }}
- name: Build release binary
- run: cargo build --verbose --release
+ run: cargo build --verbose --release --target ${{ matrix.target }}
+
+ - name: Strip release binary (linux and macos)
+ if: matrix.build == 'linux' || matrix.build == 'macos'
+ run: strip "target/${{ matrix.target }}/release/sctd"
- name: Build archive
shell: bash
run: |
- staging="sctd-${{ env.RELEASE_VERSION }}"
+ staging="sctd-${{ needs.create-release.outputs.sctd_version }}-${{ matrix.target }}"
mkdir -p "$staging"
- cp target/release/sctd "$staging"
- cp LICENSE "$staging"
+
+ cp "target/${{ matrix.target }}/release/sctd" "$staging/"
+ cp README.md LICENSE "$staging/"
+
tar czf "$staging.tar.gz" "$staging"
- echo "::set-env name=ASSET::$staging.tar.gz"
+ shasum -a 256 "$staging.tar.gz" > "$staging.tar.gz.sha256"
+ echo "ASSET=$staging.tar.gz" >> $GITHUB_ENV
+ echo "ASSET_SUM=$staging.tar.gz.sha256" >> $GITHUB_ENV
- name: Upload release archive
- uses: actions/upload-release-asset@v1.0.1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- with:
- upload_url: ${{ env.RELEASE_UPLOAD_URL }}
- asset_path: ${{ env.ASSET }}
- asset_name: ${{ env.ASSET }}
- asset_content_type: application/octet-stream
+ run: gh release upload ${{ needs.create-release.outputs.sctd_version }} ${{ env.ASSET }} ${{ env.ASSET_SUM }}
diff --git a/Cargo.lock b/Cargo.lock
index 2c025f4..886a546 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1,6 +1,12 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
-version = 3
+version = 4
+
+[[package]]
+name = "android-tzdata"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0"
[[package]]
name = "android_system_properties"
@@ -24,9 +30,9 @@ dependencies = [
[[package]]
name = "autocfg"
-version = "1.1.0"
+version = "1.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
+checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
[[package]]
name = "bitflags"
@@ -36,9 +42,18 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bumpalo"
-version = "3.11.0"
+version = "3.17.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf"
+
+[[package]]
+name = "cc"
+version = "1.2.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c1ad822118d20d2c234f427000d5acc36eabe1e29a348c89b63dd60b13f28e5d"
+checksum = "16595d3be041c03b09d08d0858631facccee9221e579704070e6e9e4915d3bc7"
+dependencies = [
+ "shlex",
+]
[[package]]
name = "cfg-if"
@@ -48,24 +63,23 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chrono"
-version = "0.4.22"
+version = "0.4.41"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bfd4d1b31faaa3a89d7934dbded3111da0d2ef28e3ebccdb4f0179f5929d1ef1"
+checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d"
dependencies = [
+ "android-tzdata",
"iana-time-zone",
"js-sys",
- "num-integer",
"num-traits",
- "time",
"wasm-bindgen",
- "winapi",
+ "windows-link",
]
[[package]]
name = "clap"
-version = "3.2.22"
+version = "3.2.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "86447ad904c7fb335a790c9d7fe3d0d971dc523b8ccd1561a520de9a85302750"
+checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123"
dependencies = [
"atty",
"bitflags",
@@ -86,22 +100,83 @@ dependencies = [
]
[[package]]
+name = "core-foundation"
+version = "0.9.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f"
+dependencies = [
+ "core-foundation-sys",
+ "libc",
+]
+
+[[package]]
name = "core-foundation-sys"
-version = "0.8.3"
+version = "0.8.7"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
+
+[[package]]
+name = "core-graphics"
+version = "0.23.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c07782be35f9e1140080c6b96f0d44b739e2278479f64e02fdab4e32dfd8b081"
+dependencies = [
+ "bitflags",
+ "core-foundation",
+ "core-graphics-types",
+ "foreign-types",
+ "libc",
+]
+
+[[package]]
+name = "core-graphics-types"
+version = "0.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5827cebf4670468b8772dd191856768aedcb1b0278a04f989f7766351917b9dc"
+checksum = "45390e6114f68f718cc7a830514a96f903cccd70d02a8f6d9f643ac4ba45afaf"
+dependencies = [
+ "bitflags",
+ "core-foundation",
+ "libc",
+]
[[package]]
name = "env_logger"
-version = "0.9.1"
+version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c90bf5f19754d10198ccb95b70664fc925bd1fc090a0fd9a6ebc54acc8cd6272"
+checksum = "a12e6657c4c97ebab115a42dcee77225f7f482cdd841cf7088c657a42e9e00e7"
dependencies = [
"humantime",
"log",
]
[[package]]
+name = "foreign-types"
+version = "0.5.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965"
+dependencies = [
+ "foreign-types-macros",
+ "foreign-types-shared",
+]
+
+[[package]]
+name = "foreign-types-macros"
+version = "0.2.3"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1a5c6c585bc94aaf2c7b51dd4c2ba22680844aba4c687be581871a6f518c5742"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "foreign-types-shared"
+version = "0.3.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b"
+
+[[package]]
name = "hashbrown"
version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -118,29 +193,39 @@ dependencies = [
[[package]]
name = "humantime"
-version = "2.1.0"
+version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
+checksum = "9b112acc8b3adf4b107a8ec20977da0273a8c386765a3ec0229bd500a1443f9f"
[[package]]
name = "iana-time-zone"
-version = "0.1.48"
+version = "0.1.63"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "237a0714f28b1ee39ccec0770ccb544eb02c9ef2c82bb096230eefcffa6468b0"
+checksum = "b0c919e5debc312ad217002b8048a17b7d83f80703865bbfcfebb0458b0b27d8"
dependencies = [
"android_system_properties",
"core-foundation-sys",
+ "iana-time-zone-haiku",
"js-sys",
- "once_cell",
+ "log",
"wasm-bindgen",
- "winapi",
+ "windows-core",
+]
+
+[[package]]
+name = "iana-time-zone-haiku"
+version = "0.1.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
+dependencies = [
+ "cc",
]
[[package]]
name = "indexmap"
-version = "1.9.1"
+version = "1.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e"
+checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99"
dependencies = [
"autocfg",
"hashbrown",
@@ -148,89 +233,84 @@ dependencies = [
[[package]]
name = "js-sys"
-version = "0.3.60"
+version = "0.3.77"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "49409df3e3bf0856b916e2ceaca09ee28e6871cf7d9ce97a692cacfdb2a25a47"
+checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f"
dependencies = [
+ "once_cell",
"wasm-bindgen",
]
[[package]]
name = "libc"
-version = "0.2.133"
+version = "0.2.172"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c0f80d65747a3e43d1596c7c5492d95d5edddaabd45a7fcdb02b95f644164966"
+checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa"
[[package]]
name = "log"
-version = "0.4.17"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e"
-dependencies = [
- "cfg-if",
-]
-
-[[package]]
-name = "num-integer"
-version = "0.1.45"
+version = "0.4.27"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9"
-dependencies = [
- "autocfg",
- "num-traits",
-]
+checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
[[package]]
name = "num-traits"
-version = "0.2.15"
+version = "0.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd"
+checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
dependencies = [
"autocfg",
]
[[package]]
name = "once_cell"
-version = "1.14.0"
+version = "1.21.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "2f7254b99e31cad77da24b08ebf628882739a608578bb1bcdfc1f9c21260d7c0"
+checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
[[package]]
name = "os_str_bytes"
-version = "6.3.0"
+version = "6.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "9ff7415e9ae3fff1225851df9e0d9e4e5479f947619774677a63572e55e80eff"
+checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1"
[[package]]
name = "pkg-config"
-version = "0.3.25"
+version = "0.3.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1df8c4ec4b0627e53bdf214615ad287367e482558cf84b109250b37464dc03ae"
+checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c"
[[package]]
name = "proc-macro2"
-version = "1.0.43"
+version = "1.0.95"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0a2ca2c61bc9f3d74d2886294ab7b9853abd9c1ad903a3ac7815c58989bb7bab"
+checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
-version = "1.0.21"
+version = "1.0.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179"
+checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
dependencies = [
"proc-macro2",
]
[[package]]
+name = "rustversion"
+version = "1.0.21"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8a0d197bd2c9dc6e53b84da9556a69ba4cdfab8619eb41a8bd1cc2027a0f6b1d"
+
+[[package]]
name = "sctd"
version = "0.3.0"
dependencies = [
"chrono",
"clap",
+ "core-graphics",
"env_logger",
"log",
"spa",
@@ -238,10 +318,16 @@ dependencies = [
]
[[package]]
+name = "shlex"
+version = "1.3.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
+
+[[package]]
name = "spa"
-version = "0.3.0"
+version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "188e0376df998cb9f953a6d4ceb8556fe9223d1f3386e5c0cdb69aab31d62f1b"
+checksum = "ab074195b3f78a133cd7b7998142cf39dfaac71f6e990eaeecd14f5524db009a"
dependencies = [
"chrono",
]
@@ -254,9 +340,9 @@ checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "syn"
-version = "1.0.100"
+version = "2.0.101"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "52205623b1b0f064a4e71182c3b18ae902267282930c6d5462c91b859668426e"
+checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf"
dependencies = [
"proc-macro2",
"quote",
@@ -265,61 +351,45 @@ dependencies = [
[[package]]
name = "termcolor"
-version = "1.1.3"
+version = "1.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
+checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755"
dependencies = [
"winapi-util",
]
[[package]]
name = "textwrap"
-version = "0.15.1"
+version = "0.16.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "949517c0cf1bf4ee812e2e07e08ab448e3ae0d23472aee8a06c985f0c8815b16"
-
-[[package]]
-name = "time"
-version = "0.1.44"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6db9e6914ab8b1ae1c260a4ae7a49b6c5611b40328a735b21862567685e73255"
-dependencies = [
- "libc",
- "wasi",
- "winapi",
-]
+checksum = "c13547615a44dc9c452a8a534638acdf07120d4b6847c8178705da06306a3057"
[[package]]
name = "unicode-ident"
-version = "1.0.4"
+version = "1.0.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "dcc811dc4066ac62f84f11307873c4850cb653bfa9b1719cee2bd2204a4bc5dd"
-
-[[package]]
-name = "wasi"
-version = "0.10.0+wasi-snapshot-preview1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f"
+checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
[[package]]
name = "wasm-bindgen"
-version = "0.2.83"
+version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "eaf9f5aceeec8be17c128b2e93e031fb8a4d469bb9c4ae2d7dc1888b26887268"
+checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5"
dependencies = [
"cfg-if",
+ "once_cell",
+ "rustversion",
"wasm-bindgen-macro",
]
[[package]]
name = "wasm-bindgen-backend"
-version = "0.2.83"
+version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "4c8ffb332579b0557b52d268b91feab8df3615f265d5270fec2a8c95b17c1142"
+checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6"
dependencies = [
"bumpalo",
"log",
- "once_cell",
"proc-macro2",
"quote",
"syn",
@@ -328,9 +398,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro"
-version = "0.2.83"
+version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "052be0f94026e6cbc75cdefc9bae13fd6052cdcaf532fa6c45e7ae33a1e6c810"
+checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407"
dependencies = [
"quote",
"wasm-bindgen-macro-support",
@@ -338,9 +408,9 @@ dependencies = [
[[package]]
name = "wasm-bindgen-macro-support"
-version = "0.2.83"
+version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "07bc0c051dc5f23e307b13285f9d75df86bfdf816c5721e573dec1f9b8aa193c"
+checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de"
dependencies = [
"proc-macro2",
"quote",
@@ -351,9 +421,12 @@ dependencies = [
[[package]]
name = "wasm-bindgen-shared"
-version = "0.2.83"
+version = "0.2.100"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "1c38c045535d93ec4f0b4defec448e4291638ee608530863b1e2ba115d4fff7f"
+checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d"
+dependencies = [
+ "unicode-ident",
+]
[[package]]
name = "winapi"
@@ -373,11 +446,11 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-util"
-version = "0.1.5"
+version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
+checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb"
dependencies = [
- "winapi",
+ "windows-sys",
]
[[package]]
@@ -387,10 +460,142 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
+name = "windows-core"
+version = "0.61.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3"
+dependencies = [
+ "windows-implement",
+ "windows-interface",
+ "windows-link",
+ "windows-result",
+ "windows-strings",
+]
+
+[[package]]
+name = "windows-implement"
+version = "0.60.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "windows-interface"
+version = "0.59.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8"
+dependencies = [
+ "proc-macro2",
+ "quote",
+ "syn",
+]
+
+[[package]]
+name = "windows-link"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38"
+
+[[package]]
+name = "windows-result"
+version = "0.3.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6"
+dependencies = [
+ "windows-link",
+]
+
+[[package]]
+name = "windows-strings"
+version = "0.4.2"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57"
+dependencies = [
+ "windows-link",
+]
+
+[[package]]
+name = "windows-sys"
+version = "0.59.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b"
+dependencies = [
+ "windows-targets",
+]
+
+[[package]]
+name = "windows-targets"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973"
+dependencies = [
+ "windows_aarch64_gnullvm",
+ "windows_aarch64_msvc",
+ "windows_i686_gnu",
+ "windows_i686_gnullvm",
+ "windows_i686_msvc",
+ "windows_x86_64_gnu",
+ "windows_x86_64_gnullvm",
+ "windows_x86_64_msvc",
+]
+
+[[package]]
+name = "windows_aarch64_gnullvm"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3"
+
+[[package]]
+name = "windows_aarch64_msvc"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469"
+
+[[package]]
+name = "windows_i686_gnu"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b"
+
+[[package]]
+name = "windows_i686_gnullvm"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66"
+
+[[package]]
+name = "windows_i686_msvc"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66"
+
+[[package]]
+name = "windows_x86_64_gnu"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78"
+
+[[package]]
+name = "windows_x86_64_gnullvm"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d"
+
+[[package]]
+name = "windows_x86_64_msvc"
+version = "0.52.6"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec"
+
+[[package]]
name = "x11"
-version = "2.20.0"
+version = "2.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f7ae97874a928d821b061fce3d1fc52f08071dd53c89a6102bc06efcac3b2908"
+checksum = "502da5464ccd04011667b11c435cb992822c2c0dbde1770c988480d312a0db2e"
dependencies = [
"libc",
"pkg-config",
diff --git a/Cargo.toml b/Cargo.toml
index 5868b4a..2491717 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,9 +13,12 @@ log = "0.4"
[dependencies.env_logger]
version = "0.9"
-default_features = false
+default-features = false
features = ["humantime"]
-[dependencies.x11]
+[target.'cfg(target_os = "linux")'.dependencies.x11]
version = "2.20"
features = ["xlib", "xrandr"]
+
+[target.'cfg(target_os = "macos")'.dependencies]
+core-graphics = "0.23"
diff --git a/src/bin/sctd.rs b/src/bin/sctd.rs
index 81e65e5..9e648c3 100644
--- a/src/bin/sctd.rs
+++ b/src/bin/sctd.rs
@@ -48,19 +48,15 @@ fn main() {
let new_temp = sctd::get_temp(utc, &ss, latitude, longitude) as u32;
if new_temp != temp {
temp = new_temp;
- info!("setting temperature to {}", temp);
+ info!("setting temperature to {temp}");
sctd::set_temp(temp);
} else {
- debug!(
- "skipping temperature change as it hasn't changed ({})",
- temp
- );
+ debug!("skipping temperature change as it hasn't changed ({temp})");
}
}
Err(e) => {
error!(
- "error calculating sunrise and sunset for {}, {}: {:?}",
- latitude, longitude, e
+ "error calculating sunrise and sunset for {latitude}, {longitude}: {e:?}"
);
}
}
diff --git a/src/lib.rs b/src/lib.rs
index dfe872a..ccb2b52 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -3,14 +3,16 @@ extern crate log;
extern crate spa;
+mod platform;
+
use chrono::prelude::*;
use spa::{calc_solar_position, SunriseAndSet};
-use std::os::raw::{c_ushort, c_void};
-use std::ptr;
-use x11::xlib::{XCloseDisplay, XDefaultScreen, XFree, XOpenDisplay, XRootWindow};
-use x11::xrandr::{
- XRRAllocGamma, XRRCrtcGamma, XRRGetCrtcGammaSize, XRRGetScreenResourcesCurrent, XRRSetCrtcGamma,
-};
+
+#[cfg(target_os = "linux")]
+use platform::linux as os;
+
+#[cfg(target_os = "macos")]
+use platform::macos as os;
const LOW_TEMP: f64 = 3500f64;
const HIGH_TEMP: f64 = 5500f64;
@@ -26,44 +28,20 @@ pub struct WhitePoint {
}
pub fn set_temp(temp: u32) {
- let ratio: f64 = (temp % 500) as f64 / 500f64;
- unsafe {
- let display = XOpenDisplay(ptr::null_mut());
- let screen = XDefaultScreen(display);
- let root = XRootWindow(display, screen);
- let resource = XRRGetScreenResourcesCurrent(display, root);
-
- for x in 0..(*resource).ncrtc {
- let crtcxid = (*resource).crtcs.offset(x as isize);
- let size = XRRGetCrtcGammaSize(display, *crtcxid);
- let crtc_gamma: *mut XRRCrtcGamma = XRRAllocGamma(size);
- let gamma = avg(temp, ratio);
-
- for i in 0..size {
- let g = (65535f64 * i as f64) / size as f64;
- *((*crtc_gamma).red as *mut c_ushort).offset(i as isize) = (g * gamma.red) as u16;
- *((*crtc_gamma).green as *mut c_ushort).offset(i as isize) =
- (g * gamma.green) as u16;
- *((*crtc_gamma).blue as *mut c_ushort).offset(i as isize) = (g * gamma.blue) as u16;
- }
- XRRSetCrtcGamma(display, *crtcxid, crtc_gamma);
- XFree(crtc_gamma as *mut c_void);
- }
- XCloseDisplay(display);
- }
+ os::set_temp(temp);
}
pub fn reset_temp() {
- set_temp(HIGH_TEMP as u32);
+ os::set_temp(HIGH_TEMP as u32);
}
fn get_transition_progress_from_elevation(elevation: f64) -> f64 {
if elevation < TRANSITION_LOW {
- return 0.0;
+ 0.0
} else if elevation < TRANSITION_HIGH {
(TRANSITION_LOW - elevation) / (TRANSITION_LOW - TRANSITION_HIGH)
} else {
- return 1.0;
+ 1.0
}
}
@@ -71,7 +49,7 @@ pub fn get_temp(utc: DateTime<Utc>, ss: &SunriseAndSet, lat: f64, lon: f64) -> f
match *ss {
SunriseAndSet::Daylight(_, _) => {
let elevation = 90f64 - calc_solar_position(utc, lat, lon).unwrap().zenith_angle;
- debug!("elevation: {}", elevation);
+ debug!("elevation: {elevation}");
let progress = get_transition_progress_from_elevation(elevation);
LOW_TEMP + (progress * (HIGH_TEMP - LOW_TEMP))
}
diff --git a/src/platform.rs b/src/platform.rs
new file mode 100644
index 0000000..204fd43
--- /dev/null
+++ b/src/platform.rs
@@ -0,0 +1,5 @@
+#[cfg(target_os = "linux")]
+pub mod linux;
+
+#[cfg(target_os = "macos")]
+pub mod macos;
diff --git a/src/platform/linux.rs b/src/platform/linux.rs
new file mode 100644
index 0000000..351bcb6
--- /dev/null
+++ b/src/platform/linux.rs
@@ -0,0 +1,34 @@
+use std::os::raw::{c_ushort, c_void};
+use std::ptr;
+use x11::xlib::{XCloseDisplay, XDefaultScreen, XFree, XOpenDisplay, XRootWindow};
+use x11::xrandr::{
+ XRRAllocGamma, XRRCrtcGamma, XRRGetCrtcGammaSize, XRRGetScreenResourcesCurrent, XRRSetCrtcGamma,
+};
+
+pub fn set_temp(temp: u32) {
+ let ratio: f64 = (temp % 500) as f64 / 500f64;
+ unsafe {
+ let display = XOpenDisplay(ptr::null_mut());
+ let screen = XDefaultScreen(display);
+ let root = XRootWindow(display, screen);
+ let resource = XRRGetScreenResourcesCurrent(display, root);
+
+ for x in 0..(*resource).ncrtc {
+ let crtcxid = (*resource).crtcs.offset(x as isize);
+ let size = XRRGetCrtcGammaSize(display, *crtcxid);
+ let crtc_gamma: *mut XRRCrtcGamma = XRRAllocGamma(size);
+ let gamma = avg(temp, ratio);
+
+ for i in 0..size {
+ let g = (65535f64 * i as f64) / size as f64;
+ *((*crtc_gamma).red as *mut c_ushort).offset(i as isize) = (g * gamma.red) as u16;
+ *((*crtc_gamma).green as *mut c_ushort).offset(i as isize) =
+ (g * gamma.green) as u16;
+ *((*crtc_gamma).blue as *mut c_ushort).offset(i as isize) = (g * gamma.blue) as u16;
+ }
+ XRRSetCrtcGamma(display, *crtcxid, crtc_gamma);
+ XFree(crtc_gamma as *mut c_void);
+ }
+ XCloseDisplay(display);
+ }
+}
diff --git a/src/platform/macos.rs b/src/platform/macos.rs
new file mode 100644
index 0000000..0292250
--- /dev/null
+++ b/src/platform/macos.rs
@@ -0,0 +1,44 @@
+use core_graphics::display::CGDisplay;
+
+pub fn set_temp(temp: u32) {
+ use std::os::raw::c_int;
+
+ let ratio: f64 = (temp % 500) as f64 / 500f64;
+ let gamma = crate::avg(temp, ratio);
+
+ let main_display = CGDisplay::main();
+
+ extern "C" {
+ fn CGSetDisplayTransferByTable(
+ display: u32,
+ table_size: u32,
+ red_table: *const f32,
+ green_table: *const f32,
+ blue_table: *const f32,
+ ) -> c_int;
+ fn CGDisplayGammaTableCapacity(display: u32) -> u32;
+ }
+
+ let table_size = unsafe { CGDisplayGammaTableCapacity(main_display.id) } as usize;
+
+ let mut red_table = vec![0.0; table_size];
+ let mut green_table = vec![0.0; table_size];
+ let mut blue_table = vec![0.0; table_size];
+
+ for i in 0..table_size {
+ let value = (i as f32) / (table_size as f32 - 1.0);
+ red_table[i] = (value * gamma.red as f32).min(1.0);
+ green_table[i] = (value * gamma.green as f32).min(1.0);
+ blue_table[i] = (value * gamma.blue as f32).min(1.0);
+ }
+
+ unsafe {
+ CGSetDisplayTransferByTable(
+ main_display.id,
+ table_size as u32,
+ red_table.as_ptr(),
+ green_table.as_ptr(),
+ blue_table.as_ptr(),
+ );
+ }
+}