enable gtk frontend in windows (#58)

The gtk frontend can now be built in windows!
The github workflow is updated to build GTK and add it to the releases section.
This commit is contained in:
Ferdinand Schober
2023-12-24 18:00:59 +01:00
committed by GitHub
parent cdd3a3b818
commit d3fed1b769
11 changed files with 208 additions and 20 deletions

View File

@@ -30,14 +30,50 @@ jobs:
windows-release-build: windows-release-build:
runs-on: windows-latest runs-on: windows-latest
steps: steps:
- uses: actions/setup-python@v5
with:
python-version: '3.11'
# needed for cache restore
- name: create gtk dir
run: mkdir C:\gtk-build\gtk\x64\release
- uses: actions/cache@v3
id: cache
with:
path: c:/gtk-build/gtk/x64/release/**
key: gtk-windows-build
restore-keys: gtk-windows-build
- name: Update path
run: |
echo "PKG_CONFIG=C:\gtk-build\gtk\x64\release\bin\pkgconf.exe" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "C:\pkg-config-lite-0.28-1\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
echo "C:\gtk-build\gtk\x64\release\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
echo $env:GITHUB_PATH
echo $env:PATH
- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
# choco install msys2
# choco install visualstudio2022-workload-vctools
# choco install pkgconfiglite
pipx install gvsbuild
# see https://github.com/wingtk/gvsbuild/pull/1004
Move-Item "C:\Program Files\Git\usr\bin" "C:\Program Files\Git\usr\notbin"
Move-Item "C:\Program Files\Git\bin" "C:\Program Files\Git\notbin"
gvsbuild build --msys-dir=C:\msys64 gtk4 libadwaita librsvg
Move-Item "C:\Program Files\Git\usr\notbin" "C:\Program Files\Git\usr\bin"
Move-Item "C:\Program Files\Git\notbin" "C:\Program Files\Git\bin"
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Release Build - name: Release Build
run: cargo build --release run: cargo build --release
- name: Copy Gtk Dlls
run: Get-Childitem -Path "C:\\gtk-build\\gtk\\x64\\release\\bin\\*.dll" -File -Recurse | Copy-Item -Destination "target\\release"
- name: Upload build artifact - name: Upload build artifact
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: lan-mouse-windows name: lan-mouse-windows
path: target/release/lan-mouse.exe path: |
target/release/lan-mouse.exe
target/release/*.dll
macos-release-build: macos-release-build:
runs-on: macos-latest runs-on: macos-latest

View File

@@ -41,6 +41,38 @@ jobs:
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: actions/setup-python@v5
with:
python-version: '3.11'
# needed for cache restore
- name: create gtk dir
run: mkdir C:\gtk-build\gtk\x64\release
- uses: actions/cache@v3
id: cache
with:
path: c:/gtk-build/gtk/x64/release/**
key: gtk-windows-build
restore-keys: gtk-windows-build
- name: Update path
run: |
echo "PKG_CONFIG=C:\gtk-build\gtk\x64\release\bin\pkgconf.exe" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "C:\pkg-config-lite-0.28-1\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
echo "C:\gtk-build\gtk\x64\release\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
echo $env:GITHUB_PATH
echo $env:PATH
- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
# choco install msys2
# choco install visualstudio2022-workload-vctools
# choco install pkgconfiglite
pipx install gvsbuild
# see https://github.com/wingtk/gvsbuild/pull/1004
Move-Item "C:\Program Files\Git\usr\bin" "C:\Program Files\Git\usr\notbin"
Move-Item "C:\Program Files\Git\bin" "C:\Program Files\Git\notbin"
gvsbuild build --msys-dir=C:\msys64 gtk4 libadwaita librsvg
Move-Item "C:\Program Files\Git\usr\notbin" "C:\Program Files\Git\usr\bin"
Move-Item "C:\Program Files\Git\notbin" "C:\Program Files\Git\bin"
- name: Build - name: Build
run: cargo build --verbose run: cargo build --verbose
- name: Run tests - name: Run tests
@@ -49,11 +81,15 @@ jobs:
run: cargo fmt --check run: cargo fmt --check
- name: Clippy - name: Clippy
run: cargo clippy --all-features --all-targets -- --deny warnings run: cargo clippy --all-features --all-targets -- --deny warnings
- name: Copy Gtk Dlls
run: Get-Childitem -Path "C:\\gtk-build\\gtk\\x64\\release\\bin\\*.dll" -File -Recurse | Copy-Item -Destination "target\\debug"
- name: Upload build artifact - name: Upload build artifact
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: lan-mouse-windows name: lan-mouse-windows
path: target/debug/lan-mouse.exe path: |
target/debug/lan-mouse.exe
target/debug/*.dll
build-macos: build-macos:
runs-on: macos-latest runs-on: macos-latest

View File

@@ -26,14 +26,50 @@ jobs:
windows-release-build: windows-release-build:
runs-on: windows-latest runs-on: windows-latest
steps: steps:
- uses: actions/setup-python@v5
with:
python-version: '3.11'
# needed for cache restore
- name: create gtk dir
run: mkdir C:\gtk-build\gtk\x64\release
- uses: actions/cache@v3
id: cache
with:
path: c:/gtk-build/gtk/x64/release/**
key: gtk-windows-build
restore-keys: gtk-windows-build
- name: Update path
run: |
echo "PKG_CONFIG=C:\gtk-build\gtk\x64\release\bin\pkgconf.exe" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
echo "C:\pkg-config-lite-0.28-1\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
echo "C:\gtk-build\gtk\x64\release\bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append
echo $env:GITHUB_PATH
echo $env:PATH
- name: Install dependencies
if: steps.cache.outputs.cache-hit != 'true'
run: |
# choco install msys2
# choco install visualstudio2022-workload-vctools
# choco install pkgconfiglite
pipx install gvsbuild
# see https://github.com/wingtk/gvsbuild/pull/1004
Move-Item "C:\Program Files\Git\usr\bin" "C:\Program Files\Git\usr\notbin"
Move-Item "C:\Program Files\Git\bin" "C:\Program Files\Git\notbin"
gvsbuild build --msys-dir=C:\msys64 gtk4 libadwaita librsvg
Move-Item "C:\Program Files\Git\usr\notbin" "C:\Program Files\Git\usr\bin"
Move-Item "C:\Program Files\Git\notbin" "C:\Program Files\Git\bin"
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Release Build - name: Release Build
run: cargo build --release run: cargo build --release
- name: Copy Gtk Dlls
run: Get-Childitem -Path "C:\\gtk-build\\gtk\\x64\\release\\bin\\*.dll" -File -Recurse | Copy-Item -Destination "target\\release"
- name: Upload build artifact - name: Upload build artifact
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with:
name: lan-mouse-windows name: lan-mouse-windows
path: target/release/lan-mouse.exe path: |
target/release/lan-mouse.exe
target/release/*.dll
macos-release-build: macos-release-build:
runs-on: macos-latest runs-on: macos-latest

View File

@@ -27,6 +27,9 @@ async-trait = "0.1.73"
futures-core = "0.3.28" futures-core = "0.3.28"
futures = "0.3.28" futures = "0.3.28"
clap = { version="4.4.11", features = ["derive"] } clap = { version="4.4.11", features = ["derive"] }
gtk = { package = "gtk4", version = "0.7.2", features = ["v4_2"], optional = true }
adw = { package = "libadwaita", version = "0.5.2", features = ["v1_1"], optional = true }
async-channel = { version = "2.1.1", optional = true }
[target.'cfg(all(unix, not(target_os="macos")))'.dependencies] [target.'cfg(all(unix, not(target_os="macos")))'.dependencies]
wayland-client = { version="0.31.1", optional = true } wayland-client = { version="0.31.1", optional = true }
@@ -38,18 +41,13 @@ ashpd = { version = "0.6.2", default-features = false, features = ["tokio"], opt
reis = { git = "https://github.com/ids1024/reis", features = [ "tokio" ], optional = true } reis = { git = "https://github.com/ids1024/reis", features = [ "tokio" ], optional = true }
libc = { version="0.2.148", optional = true } libc = { version="0.2.148", optional = true }
[target.'cfg(unix)'.dependencies]
gtk = { package = "gtk4", version = "0.7.2", features = ["v4_6"], optional = true }
adw = { package = "libadwaita", version = "0.5.2", features = ["v1_1"], optional = true }
async-channel = { version = "2.1.1", optional = true }
[target.'cfg(target_os="macos")'.dependencies] [target.'cfg(target_os="macos")'.dependencies]
core-graphics = { version = "0.23", features = ["highsierra"] } core-graphics = { version = "0.23", features = ["highsierra"] }
[target.'cfg(windows)'.dependencies] [target.'cfg(windows)'.dependencies]
winapi = { version = "0.3.9", features = ["winuser"] } winapi = { version = "0.3.9", features = ["winuser"] }
[target.'cfg(unix)'.build-dependencies] [build-dependencies]
glib-build-tools = "0.18.0" glib-build-tools = "0.18.0"
[features] [features]

View File

@@ -39,6 +39,72 @@ input capture (to send events *to* other clients) on different operating systems
Keycode translation is not yet implemented so on MacOS only mouse emulation works as of right now. Keycode translation is not yet implemented so on MacOS only mouse emulation works as of right now.
## Build and Run ## Build and Run
### Install Dependencies
#### Macos
```sh
brew install libadwaita
```
#### Ubuntu and derivatives
```sh
sudo apt install libadwaita-1-dev libgtk-4-dev libx11-dev libxtst-dev
```
#### Arch and derivatives
```sh
sudo pacman -S libadwaita gtk libx11 libxtst
```
#### Fedora and derivatives
```sh
sudo dnf install libadwaita-devel libXtst-devel libX11-devel
```
#### Windows
Follow the instructions at [gtk-rs.org](https://gtk-rs.org/gtk4-rs/stable/latest/book/installation_windows.html)
*TLDR:*
Build gtk from source
- The following commands should be run in an admin power shell instance:
```sh
# install chocolatey
Set-ExecutionPolicy Bypass -Scope Process -Force; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))
# install python 3.11 (Version is important, as 3.12 does not work currently)
choco install python --version=3.11.0
# install git
choco install git
# install msys2
choco install msys2
# install Visual Studio 2022
choco install visualstudio2022-workload-vctools
```
- The following commands should be run in a regular power shell instance:
```sh
# install gvsbuild with python
python -m pip install --user pipx
python -m pipx ensurepath
pipx install gvsbuild
# build gtk + libadwaita
gvsbuild build gtk4 libadwaita librsvg
```
Make sure to add the directory `C:\gtk-build\gtk\x64\release\bin`
[to the `PATH` environment variable]((https://learn.microsoft.com/en-us/previous-versions/office/developer/sharepoint-2010/ee537574(v=office.14))). Otherwise the project will fail to build.
To avoid building GTK from source, it is possible to disable
the gtk frontend (see conditional compilation below).
### Build and run
Build in release mode: Build in release mode:
```sh ```sh
cargo build --release cargo build --release

View File

@@ -1,6 +1,5 @@
fn main() { fn main() {
// composite_templates // composite_templates
#[cfg(unix)]
glib_build_tools::compile_resources( glib_build_tools::compile_resources(
&["resources"], &["resources"],
"resources/resources.gresource.xml", "resources/resources.gresource.xml",

View File

@@ -109,9 +109,9 @@ impl Config {
}; };
let frontend = match frontend { let frontend = match frontend {
#[cfg(all(unix, feature = "gtk"))] #[cfg(feature = "gtk")]
None => Frontend::Gtk, None => Frontend::Gtk,
#[cfg(any(not(feature = "gtk"), not(unix)))] #[cfg(not(feature = "gtk"))]
None => Frontend::Cli, None => Frontend::Cli,
Some(s) => match s.as_str() { Some(s) => match s.as_str() {
"cli" => Frontend::Cli, "cli" => Frontend::Cli,

View File

@@ -31,16 +31,16 @@ use crate::{
pub mod cli; pub mod cli;
/// gtk frontend /// gtk frontend
#[cfg(all(unix, feature = "gtk"))] #[cfg(feature = "gtk")]
pub mod gtk; pub mod gtk;
pub fn run_frontend(config: &Config) -> Result<()> { pub fn run_frontend(config: &Config) -> Result<()> {
match config.frontend { match config.frontend {
#[cfg(all(unix, feature = "gtk"))] #[cfg(feature = "gtk")]
Frontend::Gtk => { Frontend::Gtk => {
gtk::run(); gtk::run();
} }
#[cfg(any(not(feature = "gtk"), not(unix)))] #[cfg(not(feature = "gtk"))]
Frontend::Gtk => panic!("gtk frontend requested but feature not enabled!"), Frontend::Gtk => panic!("gtk frontend requested but feature not enabled!"),
Frontend::Cli => { Frontend::Cli => {
cli::run()?; cli::run()?;

View File

@@ -27,7 +27,17 @@ use super::FrontendNotify;
pub fn run() -> glib::ExitCode { pub fn run() -> glib::ExitCode {
log::debug!("running gtk frontend"); log::debug!("running gtk frontend");
#[cfg(windows)]
let ret = std::thread::Builder::new()
.stack_size(8 * 1024 * 1024) // https://gitlab.gnome.org/GNOME/gtk/-/commit/52dbb3f372b2c3ea339e879689c1de535ba2c2c3 -> caused crash on windows
.name("gtk".into())
.spawn(gtk_main)
.unwrap()
.join()
.unwrap();
#[cfg(not(windows))]
let ret = gtk_main(); let ret = gtk_main();
log::debug!("frontend exited"); log::debug!("frontend exited");
ret ret
} }

View File

@@ -1,7 +1,9 @@
use std::{ use std::cell::{Cell, RefCell};
cell::{Cell, RefCell},
os::unix::net::UnixStream, #[cfg(windows)]
}; use std::net::TcpStream;
#[cfg(unix)]
use std::os::unix::net::UnixStream;
use adw::subclass::prelude::*; use adw::subclass::prelude::*;
use adw::{ use adw::{
@@ -29,7 +31,10 @@ pub struct Window {
#[template_child] #[template_child]
pub toast_overlay: TemplateChild<ToastOverlay>, pub toast_overlay: TemplateChild<ToastOverlay>,
pub clients: RefCell<Option<gio::ListStore>>, pub clients: RefCell<Option<gio::ListStore>>,
#[cfg(unix)]
pub stream: RefCell<Option<UnixStream>>, pub stream: RefCell<Option<UnixStream>>,
#[cfg(windows)]
pub stream: RefCell<Option<TcpStream>>,
pub port: Cell<u16>, pub port: Cell<u16>,
} }

View File

@@ -36,8 +36,10 @@ pub fn run() -> Result<()> {
} else { } else {
// otherwise start the service as a child process and // otherwise start the service as a child process and
// run a frontend // run a frontend
start_service()?; let mut service = start_service()?;
frontend::run_frontend(&config)?; frontend::run_frontend(&config)?;
log::info!("terminating service");
service.kill()?;
} }
anyhow::Ok(()) anyhow::Ok(())