diff --git a/.cargo/config b/.cargo/config index 96178ba..35049cb 100644 --- a/.cargo/config +++ b/.cargo/config @@ -1,4 +1,2 @@ -paths = ['../gtk4-rs/gtk4'] - [alias] xtask = "run --package xtask --" diff --git a/.gitmodules b/.gitmodules index 3847aaf..416e64b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ [submodule "keycodemapdb"] - path = keycodemapdb - url = https://gitlab.com/keycodemap/keycodemapdb.git + path = keycodemapdb + url = https://gitlab.com/keycodemap/keycodemapdb.git diff --git a/Cargo.toml b/Cargo.toml index 9df75a6..5c7ee6d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,6 @@ members = [ "keycodemap", "qemu-display-listener", - "qemu-gtk4", "qemu-vnc", "xtask", ] diff --git a/qemu-gtk4/.editorconfig b/qemu-gtk4/.editorconfig deleted file mode 100644 index e23188f..0000000 --- a/qemu-gtk4/.editorconfig +++ /dev/null @@ -1,13 +0,0 @@ -root = true -[*] -indent_style = space -trim_trailing_whitespace = true -insert_final_newline = true -charset = utf-8 - -[*.{build,yml,ui,yaml}] -indent_size = 2 - -[*.{json,py}] -indent_size = 4 - diff --git a/qemu-gtk4/.github/workflows/ci.yml b/qemu-gtk4/.github/workflows/ci.yml deleted file mode 100644 index 677efed..0000000 --- a/qemu-gtk4/.github/workflows/ci.yml +++ /dev/null @@ -1,19 +0,0 @@ -on: - push: - branches: [master] - pull_request: -name: CI -jobs: - flatpak: - name: "Flatpak" - runs-on: ubuntu-20.04 - container: - image: bilelmoussaoui/flatpak-github-actions:gnome-3.38 - options: --privileged - steps: - - uses: actions/checkout@v2 - - uses: bilelmoussaoui/flatpak-github-actions@v2 - with: - bundle: "qemu-gtk4.flatpak" - manifest-path: "build-aux/org.qemu.gtk4.Devel.json" - run-tests: "true" diff --git a/qemu-gtk4/.gitignore b/qemu-gtk4/.gitignore deleted file mode 100644 index ab60d21..0000000 --- a/qemu-gtk4/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -target/ -build/ -_build/ -builddir/ -build-aux/app -build-aux/.flatpak-builder/ -src/config.rs -*.ui.in~ -*.ui~ -.flatpak/ diff --git a/qemu-gtk4/.gitlab-ci.yml b/qemu-gtk4/.gitlab-ci.yml deleted file mode 100644 index 6f59d57..0000000 --- a/qemu-gtk4/.gitlab-ci.yml +++ /dev/null @@ -1,39 +0,0 @@ -stages: - - check - - test - -flatpak: - image: 'registry.gitlab.gnome.org/gnome/gnome-runtime-images/rust_bundle:3.38' - stage: test - tags: - - flatpak - variables: - BUNDLE: "qemu-gtk4-nightly.flatpak" - MANIFEST_PATH: "build-aux/org.qemu.gtk4.Devel.json" - FLATPAK_MODULE: "qemu-gtk4" - APP_ID: "org.qemu.gtk4.Devel" - RUNTIME_REPO: "https://nightly.gnome.org/gnome-nightly.flatpakrepo" - script: - - > - xvfb-run -a -s "-screen 0 1024x768x24" - flatpak-builder --keep-build-dirs --user --disable-rofiles-fuse flatpak_app --repo=repo ${BRANCH:+--default-branch=$BRANCH} ${MANIFEST_PATH} - - flatpak build-bundle repo ${BUNDLE} --runtime-repo=${RUNTIME_REPO} ${APP_ID} ${BRANCH} - artifacts: - name: 'Flatpak artifacts' - expose_as: 'Get Flatpak bundle here' - when: 'always' - paths: - - "${BUNDLE}" - - '.flatpak-builder/build/${FLATPAK_MODULE}/_flatpak_build/meson-logs/meson-log.txt' - - '.flatpak-builder/build/${FLATPAK_MODULE}/_flatpak_build/meson-logs/testlog.txt' - expire_in: 14 days - -# Configure and run rustfmt -# Exits and builds fails if on bad format -rustfmt: - image: "rust:slim" - script: - - rustup component add rustfmt - - rustc -Vv && cargo -Vv - - cargo fmt --version - - cargo fmt --all -- --color=always --check diff --git a/qemu-gtk4/Cargo.toml b/qemu-gtk4/Cargo.toml deleted file mode 100644 index a541001..0000000 --- a/qemu-gtk4/Cargo.toml +++ /dev/null @@ -1,37 +0,0 @@ -[package] -name = "qemu-gtk4" -version = "0.1.0" -authors = ["QEMU developpers "] -edition = "2018" - -[dependencies] -qemu-display-listener = { path = "../qemu-display-listener", features = ["glib"] } -keycodemap = { path = "../keycodemap" } -zbus = { version = "2.0.0-beta" } -log = "0.4" -pretty_env_logger = "0.4" -gettext-rs = { version = "0.5", features = ["gettext-system"] } -gtk-macros = "0.2" -once_cell = "1.5" -khronos-egl = { version = "3.0.0", features = ["dynamic"] } -libloading = "0.6" -gl = "0.14.0" -glib = { git = "https://github.com/gtk-rs/gtk-rs", optional = true } -derivative = "2.2.0" -gst = { package = "gstreamer", version = "0.16.7" } -gst-app = { package = "gstreamer-app", version = "0.16.5" } -gst-audio = { package = "gstreamer-audio", version = "0.16.5" } -wayland-protocols = { version = "0.28.5", features = ["unstable_protocols", "client"] } -wayland-client = "0.28.5" - -[dependencies.gtk] -package = "gtk4" -git = "https://github.com/gtk-rs/gtk4-rs" - -[dependencies.gdk-wl] -package = "gdk4-wayland" -git = "https://github.com/gtk-rs/gtk4-rs" - -[dependencies.gdk-x11] -package = "gdk4-x11" -git = "https://github.com/gtk-rs/gtk4-rs" diff --git a/qemu-gtk4/LICENSE.md b/qemu-gtk4/LICENSE.md deleted file mode 100644 index 3844e57..0000000 --- a/qemu-gtk4/LICENSE.md +++ /dev/null @@ -1,7 +0,0 @@ -Copyright © 2019, QEMU developpers -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -The Software is provided “as is”, without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. In no event shall the authors or copyright holders X be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the Software. -Except as contained in this notice, the name of the QEMU developpers shall not be used in advertising or otherwise to promote the sale, use or other dealings in this Software without prior written authorization from the QEMU developpers. \ No newline at end of file diff --git a/qemu-gtk4/README.md b/qemu-gtk4/README.md deleted file mode 100644 index 514499d..0000000 --- a/qemu-gtk4/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# QEMU Gtk4 - -## Credits - -Based on [GTK Rust template](https://gitlab.gnome.org/bilelmoussaoui/gtk-rust-template) diff --git a/qemu-gtk4/build-aux/cargo.sh b/qemu-gtk4/build-aux/cargo.sh deleted file mode 100644 index 42bfb1e..0000000 --- a/qemu-gtk4/build-aux/cargo.sh +++ /dev/null @@ -1,20 +0,0 @@ -#!/bin/sh - -export MESON_BUILD_ROOT="$1" -export MESON_SOURCE_ROOT="$2" -export CARGO_TARGET_DIR="$MESON_BUILD_ROOT"/target -export CARGO_HOME="$CARGO_TARGET_DIR"/cargo-home - -if [[ $4 = "Devel" ]] -then - echo "DEBUG MODE" - cargo build --manifest-path \ - "$MESON_SOURCE_ROOT"/Cargo.toml && \ - cp "$CARGO_TARGET_DIR"/debug/$5 $3 -else - echo "RELEASE MODE" - cargo build --manifest-path \ - "$MESON_SOURCE_ROOT"/Cargo.toml --release && \ - cp "$CARGO_TARGET_DIR"/release/$5 $3 -fi - diff --git a/qemu-gtk4/build-aux/dist-vendor.sh b/qemu-gtk4/build-aux/dist-vendor.sh deleted file mode 100644 index be73278..0000000 --- a/qemu-gtk4/build-aux/dist-vendor.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -export DIST="$1" -export SOURCE_ROOT="$2" - -cd "$SOURCE_ROOT" -mkdir "$DIST"/.cargo -cargo vendor | sed 's/^directory = ".*"/directory = "vendor"/g' > $DIST/.cargo/config -# Move vendor into dist tarball directory -mv vendor "$DIST" - diff --git a/qemu-gtk4/build-aux/meson_post_install.py b/qemu-gtk4/build-aux/meson_post_install.py deleted file mode 100755 index 9028aec..0000000 --- a/qemu-gtk4/build-aux/meson_post_install.py +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env python3 - -from os import environ, path -from subprocess import call - -if not environ.get('DESTDIR', ''): - PREFIX = environ.get('MESON_INSTALL_PREFIX', '/usr/local') - DATA_DIR = path.join(PREFIX, 'share') - print('Updating icon cache...') - call(['gtk-update-icon-cache', '-qtf', path.join(DATA_DIR, 'icons/hicolor')]) - print("Compiling new schemas...") - call(["glib-compile-schemas", path.join(DATA_DIR, 'glib-2.0/schemas')]) - print("Updating desktop database...") - call(["update-desktop-database", path.join(DATA_DIR, 'applications')]) diff --git a/qemu-gtk4/build-aux/org.qemu.gtk4.Devel.json b/qemu-gtk4/build-aux/org.qemu.gtk4.Devel.json deleted file mode 100644 index d68ab26..0000000 --- a/qemu-gtk4/build-aux/org.qemu.gtk4.Devel.json +++ /dev/null @@ -1,104 +0,0 @@ -{ - "app-id": "org.qemu.gtk4.Devel", - "runtime": "org.gnome.Platform", - "runtime-version": "3.38", - "sdk": "org.gnome.Sdk", - "sdk-extensions": ["org.freedesktop.Sdk.Extension.rust-stable"], - "command": "qemu-gtk4", - "finish-args" : [ - "--socket=fallback-x11", - "--socket=wayland", - "--device=dri", - "--talk-name=org.a11y.Bus", - "--env=RUST_LOG=qemu-gtk4=debug", - "--env=G_MESSAGES_DEBUG=none" - ], - "build-options" : { - "append-path" : "/usr/lib/sdk/rust-stable/bin", - "build-args" : [ - "--share=network" - ], - "test-args": [ - "--socket=x11", - "--share=network" - ], - "env" : { - "CARGO_HOME" : "/run/build/qemu-gtk4/cargo", - "RUST_BACKTRACE": "1", - "RUSTFLAGS": "-L=/app/lib" - } - }, - "modules": [ - { - "name": "gtk4", - "buildsystem": "meson", - "config-opts": [ - "-Ddemos=false", - "-Dbuild-examples=false", - "-Dbuild-tests=false" - ], - "sources": [ - { - "type": "archive", - "url": "https://download.gnome.org/sources/gtk/4.0/gtk-4.0.3.tar.xz", - "sha256": "d7c9893725790b50bd9a3bb278856d9d543b44b6b9b951d7b60e7bdecc131890" - } - ], - "modules": [ - { - "name": "pango", - "buildsystem": "meson", - "sources": [ - { - "type": "archive", - "url": "https://download.gnome.org/sources/pango/1.48/pango-1.48.1.tar.xz", - "sha256": "08c2d550a96559f15fb317d7167b96df57ef743fef946f4e274bd8b6f2918058" - } - ] - }, - { - "name": "libsass", - "sources": [ - { - "type": "archive", - "url": "https://github.com/sass/libsass/archive/3.6.4.tar.gz", - "sha256": "f9484d9a6df60576e791566eab2f757a97fd414fce01dd41fc0a693ea5db2889" - }, - { - "type": "script", - "dest-filename": "autogen.sh", - "commands": ["autoreconf -si"] - } - ] - }, - { - "name": "sassc", - "sources": [ - { - "type": "archive", - "url": "https://github.com/sass/sassc/archive/3.6.1.tar.gz", - "sha256": "8cee391c49a102b4464f86fc40c4ceac3a2ada52a89c4c933d8348e3e4542a60" - }, - { - "type": "script", - "dest-filename": "autogen.sh", - "commands": ["autoreconf -si"] - } - ] - } - ] - }, - { - "name": "qemu-gtk4", - "buildsystem": "meson", - "run-tests": true, - "config-opts": ["-Dprofile=development"], - "sources": [ - { - "type": "dir", - "path": "../" - } - ] - } - ] -} diff --git a/qemu-gtk4/data/icons/meson.build b/qemu-gtk4/data/icons/meson.build deleted file mode 100644 index 2ab86e9..0000000 --- a/qemu-gtk4/data/icons/meson.build +++ /dev/null @@ -1,10 +0,0 @@ -install_data( - '@0@.svg'.format(application_id), - install_dir: iconsdir / 'hicolor' / 'scalable' / 'apps' -) - -install_data( - '@0@-symbolic.svg'.format(base_id), - install_dir: iconsdir / 'hicolor' / 'symbolic' / 'apps', - rename: '@0@-symbolic.svg'.format(application_id) -) diff --git a/qemu-gtk4/data/icons/org.qemu.gtk4-symbolic.svg b/qemu-gtk4/data/icons/org.qemu.gtk4-symbolic.svg deleted file mode 100644 index fc4d934..0000000 --- a/qemu-gtk4/data/icons/org.qemu.gtk4-symbolic.svg +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/qemu-gtk4/data/icons/org.qemu.gtk4.Devel.svg b/qemu-gtk4/data/icons/org.qemu.gtk4.Devel.svg deleted file mode 100644 index 92533ae..0000000 --- a/qemu-gtk4/data/icons/org.qemu.gtk4.Devel.svg +++ /dev/null @@ -1,147 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/qemu-gtk4/data/icons/org.qemu.gtk4.svg b/qemu-gtk4/data/icons/org.qemu.gtk4.svg deleted file mode 100644 index c2bd5b1..0000000 --- a/qemu-gtk4/data/icons/org.qemu.gtk4.svg +++ /dev/null @@ -1,60 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/qemu-gtk4/data/meson.build b/qemu-gtk4/data/meson.build deleted file mode 100644 index cc26f98..0000000 --- a/qemu-gtk4/data/meson.build +++ /dev/null @@ -1,83 +0,0 @@ -subdir('icons') -# Desktop file -desktop_conf = configuration_data() -desktop_conf.set('icon', application_id) -desktop_file = i18n.merge_file( - type: 'desktop', - input: configure_file( - input: '@0@.desktop.in.in'.format(base_id), - output: '@BASENAME@', - configuration: desktop_conf - ), - output: '@0@.desktop'.format(application_id), - po_dir: podir, - install: true, - install_dir: datadir / 'applications' -) -# Validate Desktop file -if desktop_file_validate.found() - test( - 'validate-desktop', - desktop_file_validate, - args: [ - desktop_file.full_path() - ] - ) -endif - -# Appdata -appdata_conf = configuration_data() -appdata_conf.set('app-id', application_id) -appdata_conf.set('gettext-package', gettext_package) -appdata_file = i18n.merge_file( - input: configure_file( - input: '@0@.metainfo.xml.in.in'.format(base_id), - output: '@BASENAME@', - configuration: appdata_conf - ), - output: '@0@.metainfo.xml'.format(application_id), - po_dir: podir, - install: true, - install_dir: datadir / 'metainfo' -) -# Validate Appdata -if appstream_util.found() - test( - 'validate-appdata', appstream_util, - args: [ - 'validate', '--nonet', appdata_file.full_path() - ] - ) -endif - -# GSchema -gschema_conf = configuration_data() -gschema_conf.set('app-id', application_id) -gschema_conf.set('gettext-package', gettext_package) -configure_file( - input: '@0@.gschema.xml.in'.format(base_id), - output: '@0@.gschema.xml'.format(application_id), - configuration: gschema_conf, - install: true, - install_dir: datadir / 'glib-2.0' / 'schemas' -) - -# Validata GSchema -if glib_compile_schemas.found() - test( - 'validate-gschema', glib_compile_schemas, - args: [ - '--strict', '--dry-run', meson.current_source_dir() - ] - ) -endif - -# Resources -resources = gnome.compile_resources( - 'resources', - 'resources.gresource.xml', - gresource_bundle: true, - source_dir: meson.current_build_dir(), - install: true, - install_dir: pkgdatadir, -) diff --git a/qemu-gtk4/data/org.qemu.gtk4.desktop.in.in b/qemu-gtk4/data/org.qemu.gtk4.desktop.in.in deleted file mode 100644 index b17ae0b..0000000 --- a/qemu-gtk4/data/org.qemu.gtk4.desktop.in.in +++ /dev/null @@ -1,11 +0,0 @@ -[Desktop Entry] -Name=QEMU Gtk -Comment=A GTK + Rust application boilerplate template -Type=Application -Exec=qemu-gtk4 -Terminal=false -Categories=GNOME;GTK; -Keywords=Gnome;GTK; -# Translators: Do NOT translate or transliterate this text (this is an icon file name)! -Icon=@icon@ -StartupNotify=true diff --git a/qemu-gtk4/data/org.qemu.gtk4.gschema.xml.in b/qemu-gtk4/data/org.qemu.gtk4.gschema.xml.in deleted file mode 100644 index a1fbd27..0000000 --- a/qemu-gtk4/data/org.qemu.gtk4.gschema.xml.in +++ /dev/null @@ -1,20 +0,0 @@ - - - - - -1 - Default window width - Default window width - - - -1 - Default window height - Default window height - - - false - Default window maximized behaviour - - - - diff --git a/qemu-gtk4/data/org.qemu.gtk4.metainfo.xml.in.in b/qemu-gtk4/data/org.qemu.gtk4.metainfo.xml.in.in deleted file mode 100644 index c53c4f8..0000000 --- a/qemu-gtk4/data/org.qemu.gtk4.metainfo.xml.in.in +++ /dev/null @@ -1,30 +0,0 @@ - - - - @app-id@ - CC0 - GPL-3.0+ - QEMU Gtk - A GTK QEMU display. - -

GTK application to interact with QEMU display.

-
- https://gitlab.com/qemu-project/qemu - https://gitlab.com/qemu-project/qemu/issues - - - - - - - ModernToolkit - HiDpiIcon - - QEMU developpers - qemu-devel@nongnu.org - @gettext-package@ - @app-id@.desktop -
diff --git a/qemu-gtk4/data/resources.gresource.xml b/qemu-gtk4/data/resources.gresource.xml deleted file mode 100644 index 2d1b48c..0000000 --- a/qemu-gtk4/data/resources.gresource.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - resources/ui/shortcuts.ui - resources/ui/console.ui - resources/ui/window.ui - - resources/style.css - - diff --git a/qemu-gtk4/data/resources/style.css b/qemu-gtk4/data/resources/style.css deleted file mode 100644 index 3c4bd47..0000000 --- a/qemu-gtk4/data/resources/style.css +++ /dev/null @@ -1,4 +0,0 @@ -.title-header{ - font-size: 36px; - font-weight: bold; -} diff --git a/qemu-gtk4/data/resources/ui/console.ui b/qemu-gtk4/data/resources/ui/console.ui deleted file mode 100644 index 665218c..0000000 --- a/qemu-gtk4/data/resources/ui/console.ui +++ /dev/null @@ -1,31 +0,0 @@ - - - - diff --git a/qemu-gtk4/data/resources/ui/shortcuts.ui b/qemu-gtk4/data/resources/ui/shortcuts.ui deleted file mode 100644 index d5dff5e..0000000 --- a/qemu-gtk4/data/resources/ui/shortcuts.ui +++ /dev/null @@ -1,30 +0,0 @@ - - - - True - - - shortcuts - 10 - - - General - - - Show Shortcuts - <Primary>question - - - - - Quit - <Primary>Q - - - - - - - - - diff --git a/qemu-gtk4/data/resources/ui/window.ui b/qemu-gtk4/data/resources/ui/window.ui deleted file mode 100644 index fc67b39..0000000 --- a/qemu-gtk4/data/resources/ui/window.ui +++ /dev/null @@ -1,37 +0,0 @@ - - - -
- - _Preferences - app.preferences - - - _Keyboard Shortcuts - win.show-help-overlay - - - _About GTK QEMU - app.about - -
-
- -
diff --git a/qemu-gtk4/hooks/pre-commit.hook b/qemu-gtk4/hooks/pre-commit.hook deleted file mode 100755 index 363b8d5..0000000 --- a/qemu-gtk4/hooks/pre-commit.hook +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/sh -# Source: https://gitlab.gnome.org/GNOME/fractal/blob/master/hooks/pre-commit.hook - -install_rustfmt() { - if ! which rustup &> /dev/null; then - curl https://sh.rustup.rs -sSf | sh -s -- -y - export PATH=$PATH:$HOME/.cargo/bin - if ! which rustup &> /dev/null; then - echo "Failed to install rustup. Performing the commit without style checking." - exit 0 - fi - fi - - if ! rustup component list|grep rustfmt &> /dev/null; then - echo "Installing rustfmt…" - rustup component add rustfmt - fi -} - -if ! which cargo &> /dev/null || ! cargo fmt --help &> /dev/null; then - echo "Unable to check Fractal’s code style, because rustfmt could not be run." - - if [ ! -t 1 ]; then - # No input is possible - echo "Performing commit." - exit 0 - fi - - echo "" - echo "y: Install rustfmt via rustup" - echo "n: Don't install rustfmt and perform the commit" - echo "Q: Don't install rustfmt and abort the commit" - - while true; do - read -p "Install rustfmt via rustup? [y/n/Q]: " yn - case $yn in - [Yy]* ) install_rustfmt; break;; - [Nn]* ) echo "Performing commit."; exit 0;; - [Qq]* | "" ) echo "Aborting commit."; exit -1;; - * ) echo "Invalid input";; - esac - done -fi - -echo "--Checking style--" -cargo fmt --all -- --check -if test $? != 0; then - echo "--Checking style fail--" - echo "Please fix the above issues, either manually or by running: cargo fmt --all" - - exit -1 -else - echo "--Checking style pass--" -fi diff --git a/qemu-gtk4/meson.build b/qemu-gtk4/meson.build deleted file mode 100644 index 0474896..0000000 --- a/qemu-gtk4/meson.build +++ /dev/null @@ -1,70 +0,0 @@ -project('qemu-gtk4', - 'rust', - version: '0.0.1', - license: 'MIT', - meson_version: '>= 0.50') - -i18n = import('i18n') -gnome = import('gnome') - -base_id = 'org.qemu.gtk4' - -dependency('glib-2.0', version: '>= 2.66') -dependency('gio-2.0', version: '>= 2.66') -dependency('gtk4', version: '>= 4.0.0') - -glib_compile_resources = find_program('glib-compile-resources', required: true) -glib_compile_schemas = find_program('glib-compile-schemas', required: true) -desktop_file_validate = find_program('desktop-file-validate', required: false) -appstream_util = find_program('appstream-util', required: false) -cargo = find_program('cargo', required: true) -cargo_script = find_program('build-aux/cargo.sh') - -version = meson.project_version() -version_array = version.split('.') -major_version = version_array[0].to_int() -minor_version = version_array[1].to_int() -version_micro = version_array[2].to_int() - -prefix = get_option('prefix') -bindir = prefix / get_option('bindir') -localedir = prefix / get_option('localedir') - -datadir = prefix / get_option('datadir') -pkgdatadir = datadir / meson.project_name() -iconsdir = datadir / 'icons' -podir = meson.source_root() / 'po' -gettext_package = meson.project_name() - -if get_option('profile') == 'development' - profile = 'Devel' - vcs_tag = run_command('git', 'rev-parse', '--short', 'HEAD').stdout().strip() - if vcs_tag == '' - version_suffix = '-devel' - else - version_suffix = '-@0@'.format(vcs_tag) - endif - application_id = '@0@.@1@'.format(base_id, profile) -else - profile = '' - version_suffix = '' - application_id = base_id -endif - -meson.add_dist_script( - 'build-aux/dist-vendor.sh', - meson.build_root() / 'meson-dist' / meson.project_name() + '-' + version, - meson.source_root() -) - -if get_option('profile') == 'development' - # Setup pre-commit hook for ensuring coding style is always consistent - message('Setting up git pre-commit hook..') - run_command('cp', '-f', 'hooks/pre-commit.hook', '.git/hooks/pre-commit') -endif - -subdir('data') -subdir('po') -subdir('src') - -meson.add_install_script('build-aux/meson_post_install.py') diff --git a/qemu-gtk4/meson_options.txt b/qemu-gtk4/meson_options.txt deleted file mode 100644 index abf708f..0000000 --- a/qemu-gtk4/meson_options.txt +++ /dev/null @@ -1,10 +0,0 @@ -option( - 'profile', - type: 'combo', - choices: [ - 'default', - 'development' - ], - value: 'default', - description: 'The build profile for QEMU Gtk. One of "default" or "development".' -) diff --git a/qemu-gtk4/po/LINGUAS b/qemu-gtk4/po/LINGUAS deleted file mode 100644 index e69de29..0000000 diff --git a/qemu-gtk4/po/POTFILES.in b/qemu-gtk4/po/POTFILES.in deleted file mode 100644 index b85657c..0000000 --- a/qemu-gtk4/po/POTFILES.in +++ /dev/null @@ -1,6 +0,0 @@ -data/resources/ui/shortcuts.ui -data/resources/ui/console.ui.in -data/resources/ui/window.ui.in -data/org.qemu.gtk4.desktop.in.in -data/org.qemu.gtk4.gschema.xml.in -data/org.qemu.gtk4.metainfo.xml.in.in diff --git a/qemu-gtk4/po/meson.build b/qemu-gtk4/po/meson.build deleted file mode 100644 index 57d1266..0000000 --- a/qemu-gtk4/po/meson.build +++ /dev/null @@ -1 +0,0 @@ -i18n.gettext(gettext_package, preset: 'glib') diff --git a/qemu-gtk4/src/application.rs b/qemu-gtk4/src/application.rs deleted file mode 100644 index ac0a0a2..0000000 --- a/qemu-gtk4/src/application.rs +++ /dev/null @@ -1,212 +0,0 @@ -use crate::config; -use crate::window::QemuApplicationWindow; -use gio::ApplicationFlags; -use glib::clone; -use glib::WeakRef; -use gtk::prelude::*; -use gtk::subclass::prelude::*; -use gtk::{gdk, gio, glib}; -use gtk_macros::action; -use log::{debug, info}; -use once_cell::sync::OnceCell; -use std::env; - -use crate::gstaudio::GstAudio; -use qemu_display_listener::{Audio, Console}; -use zbus::Connection; - -mod imp { - use super::*; - - #[derive(Debug, Default)] - pub struct QemuApplication { - pub window: OnceCell>, - pub conn: OnceCell, - pub addr: OnceCell, - pub audio: OnceCell, - } - - #[glib::object_subclass] - impl ObjectSubclass for QemuApplication { - const NAME: &'static str = "QemuApplication"; - type Type = super::QemuApplication; - type ParentType = gtk::Application; - } - - impl ObjectImpl for QemuApplication {} - - impl gio::subclass::prelude::ApplicationImpl for QemuApplication { - fn handle_local_options( - &self, - application: &Self::Type, - options: &glib::VariantDict, - ) -> i32 { - if options.lookup_value("version", None).is_some() { - println!("Version: {} ({})", config::VERSION, config::PROFILE); - return 0; - } - - self.parent_handle_local_options(application, options) - } - - fn command_line( - &self, - application: &Self::Type, - command_line: &gio::ApplicationCommandLine, - ) -> i32 { - let mut opt = command_line.get_arguments().into_iter().skip(1); - if let Some(arg) = opt.next() { - self.addr.set(arg.into_string().unwrap()).unwrap(); - } - application.activate(); - self.parent_command_line(application, command_line) - } - - fn activate(&self, app: &Self::Type) { - debug!("GtkApplication::activate"); - - if let Some(window) = self.window.get() { - let window = window.upgrade().unwrap(); - window.show(); - window.present(); - return; - } - - app.set_resource_base_path(Some("/org/qemu/gtk4/")); - app.setup_css(); - - let conn = if let Some(addr) = self.addr.get() { - Connection::new_for_address(&addr, true) - } else { - Connection::new_session() - } - .expect("Failed to connect to DBus"); - - if Audio::available(&conn) { - if let Ok(audio) = Audio::new(&conn) { - self.audio - .set(GstAudio::new(audio).expect("Failed to setup audio")) - .unwrap(); - } - } - - let console = Console::new(&conn, 0).expect("Failed to get the console"); - self.conn.set(conn).expect("Connection already set."); - - let window = QemuApplicationWindow::new(app, console); - self.window - .set(window.downgrade()) - .expect("Window already set."); - - app.setup_gactions(); - app.setup_accels(); - - app.get_main_window().present(); - } - - fn startup(&self, app: &Self::Type) { - debug!("GtkApplication::startup"); - self.parent_startup(app); - } - } - - impl GtkApplicationImpl for QemuApplication {} -} - -glib::wrapper! { - pub struct QemuApplication(ObjectSubclass) - @extends gio::Application, gtk::Application, @implements gio::ActionMap, gio::ActionGroup; -} - -impl QemuApplication { - pub fn new() -> Self { - let app = glib::Object::new::(&[ - ("application-id", &Some(config::APP_ID)), - ( - "flags", - &(ApplicationFlags::NON_UNIQUE | ApplicationFlags::HANDLES_COMMAND_LINE), - ), - ]) - .expect("Application initialization failed..."); - app.add_main_option( - "version", - glib::Char(0), - glib::OptionFlags::NONE, - glib::OptionArg::None, - "Show program version", - None, - ); - app - } - - fn get_main_window(&self) -> QemuApplicationWindow { - let priv_ = imp::QemuApplication::from_instance(self); - priv_.window.get().unwrap().upgrade().unwrap() - } - - fn setup_gactions(&self) { - // Quit - action!( - self, - "quit", - clone!(@weak self as app => move |_, _| { - // This is needed to trigger the delete event - // and saving the window state - app.get_main_window().close(); - app.quit(); - }) - ); - - // About - action!( - self, - "about", - clone!(@weak self as app => move |_, _| { - app.show_about_dialog(); - }) - ); - } - - // Sets up keyboard shortcuts - fn setup_accels(&self) { - self.set_accels_for_action("app.quit", &["q"]); - self.set_accels_for_action("win.show-help-overlay", &["question"]); - } - - fn setup_css(&self) { - let provider = gtk::CssProvider::new(); - provider.load_from_resource("/org/qemu/gtk4/style.css"); - if let Some(display) = gdk::Display::get_default() { - gtk::StyleContext::add_provider_for_display( - &display, - &provider, - gtk::STYLE_PROVIDER_PRIORITY_APPLICATION, - ); - } - } - - fn show_about_dialog(&self) { - let dialog = gtk::AboutDialogBuilder::new() - .program_name("QEMU Gtk") - .logo_icon_name(config::APP_ID) - .license_type(gtk::License::MitX11) - .website("https://gitlab.com/qemu-project/qemu/") - .version(config::VERSION) - .transient_for(&self.get_main_window()) - .modal(true) - .authors(vec!["QEMU developpers".into()]) - .artists(vec!["QEMU developpers".into()]) - .build(); - - dialog.show(); - } - - pub fn run(&self) { - info!("QEMU Gtk ({})", config::APP_ID); - info!("Version: {} ({})", config::VERSION, config::PROFILE); - info!("Datadir: {}", config::PKGDATADIR); - - let args: Vec = env::args().collect(); - ApplicationExtManual::run(self, &args); - } -} diff --git a/qemu-gtk4/src/config.rs.in b/qemu-gtk4/src/config.rs.in deleted file mode 100644 index 699897f..0000000 --- a/qemu-gtk4/src/config.rs.in +++ /dev/null @@ -1,7 +0,0 @@ -pub const APP_ID: &str = @APP_ID@; -pub const GETTEXT_PACKAGE: &str = @GETTEXT_PACKAGE@; -pub const LOCALEDIR: &str = @LOCALEDIR@; -pub const PKGDATADIR: &str = @PKGDATADIR@; -pub const PROFILE: &str = @PROFILE@; -pub const RESOURCES_FILE: &str = concat!(@PKGDATADIR@, "/resources.gresource"); -pub const VERSION: &str = @VERSION@; diff --git a/qemu-gtk4/src/console.rs b/qemu-gtk4/src/console.rs deleted file mode 100644 index 274b3d8..0000000 --- a/qemu-gtk4/src/console.rs +++ /dev/null @@ -1,427 +0,0 @@ -use glib::clone; -use glib::subclass::prelude::*; -use gtk::glib::translate::FromGlibPtrBorrow; -use gtk::prelude::*; -use gtk::{gdk, glib, CompositeTemplate}; -use log::debug; -use once_cell::sync::OnceCell; -use std::cell::{Cell, RefCell}; - -use wayland_client::{Display, GlobalManager}; -use wayland_protocols::unstable::pointer_constraints::v1::client::zwp_locked_pointer_v1::ZwpLockedPointerV1; -use wayland_protocols::unstable::pointer_constraints::v1::client::zwp_pointer_constraints_v1::{ - Lifetime, ZwpPointerConstraintsV1, -}; -use wayland_protocols::unstable::relative_pointer::v1::client::zwp_relative_pointer_manager_v1::ZwpRelativePointerManagerV1; -use wayland_protocols::unstable::relative_pointer::v1::client::zwp_relative_pointer_v1::{ - Event as RelEvent, ZwpRelativePointerV1, -}; - -use keycodemap::*; -use qemu_display_listener::{Console, ConsoleEvent as Event, MouseButton}; - -mod imp { - use super::*; - use gtk::subclass::prelude::*; - - #[derive(CompositeTemplate, Default)] - #[template(resource = "/org/qemu/gtk4/console.ui")] - pub struct QemuConsole { - #[template_child] - pub area: TemplateChild, - #[template_child] - pub label: TemplateChild, - pub console: OnceCell, - pub wait_rendering: Cell, - pub shortcuts_inhibited_id: Cell>, - pub ungrab_shortcut: OnceCell, - pub key_controller: OnceCell, - pub event_queue: OnceCell, - pub rel_manager: OnceCell>, - pub rel_pointer: RefCell>>, - pub pointer_constraints: OnceCell>, - pub lock_pointer: RefCell>>, - pub has_grab: Cell, - } - - #[glib::object_subclass] - impl ObjectSubclass for QemuConsole { - const NAME: &'static str = "QemuConsole"; - type Type = super::QemuConsole; - type ParentType = gtk::Widget; - - fn class_init(klass: &mut Self::Class) { - Self::bind_template(klass); - } - - fn instance_init(obj: &glib::subclass::InitializingObject) { - obj.init_template(); - } - } - - impl ObjectImpl for QemuConsole { - fn constructed(&self, obj: &Self::Type) { - self.parent_constructed(obj); - - // TODO: implement a custom trigger with only modifiers, ala spice-gtk? - let ungrab = gtk::ShortcutTrigger::parse_string("g").unwrap(); - self.ungrab_shortcut.set(ungrab).unwrap(); - - let ec = gtk::EventControllerKey::new(); - ec.set_propagation_phase(gtk::PropagationPhase::Capture); - self.area.add_controller(&ec); - ec.connect_key_pressed( - clone!(@weak obj => @default-panic, move |_, _keyval, keycode, _state| { - let c = obj.qemu_console(); - if let Some(qnum) = KEYMAP_XORGEVDEV2QNUM.get(keycode as usize) { - let _ = c.keyboard.press(*qnum as u32); - } - glib::signal::Inhibit(true) - }), - ); - ec.connect_key_released(clone!(@weak obj => move |_, _keyval, keycode, _state| { - let c = obj.qemu_console(); - if let Some(qnum) = KEYMAP_XORGEVDEV2QNUM.get(keycode as usize) { - let _ = c.keyboard.release(*qnum as u32); - } - })); - self.key_controller.set(ec).unwrap(); - - let ec = gtk::EventControllerMotion::new(); - self.area.add_controller(&ec); - ec.connect_motion(clone!(@weak obj => move |_, x, y| { - let priv_ = imp::QemuConsole::from_instance(&obj); - let c = obj.qemu_console(); - if c.mouse.is_absolute().unwrap_or(true) { - priv_.motion(x, y); - }; - })); - - let ec = gtk::GestureClick::new(); - ec.set_button(0); - self.area.add_controller(&ec); - ec.connect_pressed(clone!(@weak obj => @default-panic, move |gesture, _n_press, x, y| { - let priv_ = imp::QemuConsole::from_instance(&obj); - let c = obj.qemu_console(); - let button = from_gdk_button(gesture.get_current_button()); - priv_.motion(x, y); - let _ = c.mouse.press(button); - - if !c.mouse.is_absolute().unwrap_or(true) { - priv_.area.set_cursor_abs(false); - if let Some(device) = gesture.get_device() { - if let Ok(device) = device.downcast::() { - let pointer = device.get_wl_pointer(); - if priv_.lock_pointer.borrow().is_none() { - if let Some(constraints) = priv_.pointer_constraints.get() { - if let Some(surf) = priv_.area.get_native() - .and_then(|n| n.get_surface()) - .and_then(|s| s.downcast::().ok()) - .map(|w| w.get_wl_surface()) { - let lock = constraints.lock_pointer(&surf, &pointer, None, Lifetime::Persistent as _); - lock.quick_assign(move |_, event, _| { - debug!("{:?}", event); - }); - priv_.lock_pointer.replace(Some(lock)); - } - } - } - if priv_.rel_pointer.borrow().is_none() { - if let Some(rel_manager) = priv_.rel_manager.get() { - let rel_pointer = rel_manager.get_relative_pointer(&pointer); - rel_pointer.quick_assign(clone!(@weak obj => @default-panic, move |_, event, _| { - if let RelEvent::RelativeMotion { dx_unaccel, dy_unaccel, .. } = event { - let priv_ = imp::QemuConsole::from_instance(&obj); - let c = obj.qemu_console(); - let scale = priv_.area.get_scale_factor(); - let _ = c.mouse.rel_motion(dx_unaccel as i32 / scale, dy_unaccel as i32 / scale); - } - })); - priv_.rel_pointer.replace(Some(rel_pointer)); - } - } - } - } - } - - if let Some(toplevel) = priv_.get_toplevel() { - if !toplevel.get_property_shortcuts_inhibited() { - toplevel.inhibit_system_shortcuts::(None); - - let ec = gtk::EventControllerKey::new(); - ec.set_propagation_phase(gtk::PropagationPhase::Capture); - ec.connect_key_pressed(clone!(@weak obj, @weak toplevel => @default-panic, move |ec, keyval, keycode, state| { - let priv_ = imp::QemuConsole::from_instance(&obj); - if let Some(ref e) = ec.get_current_event() { - if priv_.ungrab_shortcut.get().unwrap().trigger(e, false) == gdk::KeyMatch::Exact { - //widget.remove_controller(ec); here crashes badly - glib::idle_add_local(clone!(@weak ec, @weak toplevel, @weak obj => @default-panic, move || { - let priv_ = imp::QemuConsole::from_instance(&obj); - if let Some(widget) = ec.get_widget() { - widget.remove_controller(&ec); - } - toplevel.restore_system_shortcuts(); - if let Some(lock) = priv_.lock_pointer.take() { - lock.destroy(); - } - if let Some(rel_pointer) = priv_.rel_pointer.take() { - rel_pointer.destroy(); - } - priv_.area.set_cursor_abs(true); - priv_.has_grab.set(false); - glib::Continue(false) - })); - } else { - priv_.key_controller.get().unwrap().emit_by_name("key-pressed", &[&*keyval, &keycode, &state]).unwrap(); - } - } - - glib::signal::Inhibit(true) - })); - ec.connect_key_released(clone!(@weak obj => @default-panic, move |_ec, keyval, keycode, state| { - let priv_ = imp::QemuConsole::from_instance(&obj); - priv_.key_controller.get().unwrap().emit_by_name("key-released", &[&*keyval, &keycode, &state]).unwrap(); - })); - if let Some(root) = priv_.area.get_root() { - root.add_controller(&ec); - } - - let id = toplevel.connect_property_shortcuts_inhibited_notify(clone!(@weak obj => @default-panic, move |toplevel| { - let inhibited = toplevel.get_property_shortcuts_inhibited(); - debug!("shortcuts-inhibited: {}", inhibited); - if !inhibited { - let priv_ = imp::QemuConsole::from_instance(&obj); - let id = priv_.shortcuts_inhibited_id.take(); - toplevel.disconnect(id.unwrap()); - } - })); - priv_.shortcuts_inhibited_id.set(Some(id)); - } - } - - priv_.has_grab.set(true); - priv_.area.grab_focus(); - })); - ec.connect_released(clone!(@weak obj => move |gesture, _n_press, x, y| { - let priv_ = imp::QemuConsole::from_instance(&obj); - let c = obj.qemu_console(); - let button = from_gdk_button(gesture.get_current_button()); - - priv_.motion(x, y); - let _ = c.mouse.release(button); - })); - - let ec = gtk::EventControllerScroll::new(gtk::EventControllerScrollFlags::BOTH_AXES); - self.area.add_controller(&ec); - ec.connect_scroll(clone!(@weak obj => @default-panic, move |_, _dx, dy| { - let c = obj.qemu_console(); - - let button = if dy >= 1.0 { - Some(MouseButton::WheelDown) - } else if dy <= -1.0 { - Some(MouseButton::WheelUp) - } else { - None - }; - if let Some(button) = button { - let _ = c.mouse.press(button); - let _ = c.mouse.release(button); - } - glib::signal::Inhibit(true) - })); - - self.area.set_sensitive(true); - self.area.set_focusable(true); - self.area.set_focus_on_click(true); - - self.area - .connect_create_context(clone!(@weak obj => @default-panic, move |_| { - // can't connect-after create-context yet, so idle it - glib::idle_add_local(clone!(@weak ec => @default-panic, move || { - let priv_ = imp::QemuConsole::from_instance(&obj); - priv_.attach_qemu_console(&obj); - glib::Continue(false) - })); - None - })); - - unsafe { - self.area.connect_notify_unsafe( - Some("resize-hack"), - clone!(@weak obj => move |_, _| { - let priv_ = imp::QemuConsole::from_instance(&obj); - let alloc = priv_.area.get_allocation(); - if let Err(e) = obj.qemu_console().proxy.set_ui_info(0, 0, 0, 0, alloc.width as u32, alloc.height as u32) { - eprintln!("Failed to SetUIInfo: {}", e); - } - }), - ); - } - } - - // Needed for direct subclasses of GtkWidget; - // Here you need to unparent all direct children - // of your template. - fn dispose(&self, obj: &Self::Type) { - while let Some(child) = obj.get_first_child() { - child.unparent(); - } - } - } - - impl WidgetImpl for QemuConsole { - fn realize(&self, widget: &Self::Type) { - self.parent_realize(widget); - - if let Ok(dpy) = widget.get_display().downcast::() { - let display = unsafe { - Display::from_external_display(dpy.get_wl_display().as_ref().c_ptr() as *mut _) - }; - let mut event_queue = display.create_event_queue(); - let attached_display = display.attach(event_queue.token()); - let globals = GlobalManager::new(&attached_display); - event_queue - .sync_roundtrip(&mut (), |_, _, _| unreachable!()) - .unwrap(); - let rel_manager = globals - .instantiate_exact::(1) - .unwrap(); - self.rel_manager.set(rel_manager).unwrap(); - let pointer_constraints = globals - .instantiate_exact::(1) - .unwrap(); - self.pointer_constraints.set(pointer_constraints).unwrap(); - let fd = display.get_connection_fd(); - let _ = glib::unix_fd_add_local(fd, glib::IOCondition::IN, move |_, _| { - event_queue - .sync_roundtrip(&mut (), |_, _, _| unreachable!()) - .unwrap(); - glib::Continue(true) - }); - } - } - } - - impl QemuConsole { - fn get_toplevel(&self) -> Option { - self.area - .get_root() - .and_then(|r| r.get_native()) - .and_then(|n| n.get_surface()) - .and_then(|s| s.downcast::().ok()) - } - - fn motion(&self, x: f64, y: f64) { - if let Some((x, y)) = self.area.transform_input(x, y) { - let c = self.console.get().unwrap(); - let _ = c.mouse.set_abs_position(x, y); - } - } - - pub(crate) fn attach_qemu_console(&self, obj: &super::QemuConsole) { - let console = match self.console.get() { - Some(console) => console, - None => return, - }; - if !obj.get_realized() { - return; - } - - let (rx, wait_tx) = console - .glib_listen() - .expect("Failed to listen to the console"); - self.area - .connect_render(clone!(@weak obj => @default-panic, move |_, _| { - let priv_ = imp::QemuConsole::from_instance(&obj); - let wait_rendering = priv_.wait_rendering.get(); - if wait_rendering > 0 { - if let Err(e) = wait_tx.send(()) { - eprintln!("Failed to ack rendering: {}", e); - } - priv_.wait_rendering.set(wait_rendering - 1); - } - glib::signal::Inhibit(false) - })); - rx.attach( - None, - clone!(@weak obj => @default-panic, move |t| { - let priv_ = imp::QemuConsole::from_instance(&obj); - debug!("Console event: {:?}", t); - match t { - Event::Scanout(s) => { - priv_.area.set_scanout(s); - priv_.area.queue_render(); - } - Event::Update(u) => { - priv_.area.update(u); - priv_.area.queue_render(); - } - Event::ScanoutDMABUF(s) => { - priv_.label.set_label(&format!("{:?}", s)); - priv_.area.set_scanout_dmabuf(s); - } - Event::UpdateDMABUF { .. } => { - priv_.wait_rendering.set(priv_.wait_rendering.get() + 1); - // we don't simply queue_render, as we want a copy immediately - priv_.area.make_current(); - priv_.area.attach_buffers(); - let _ = unsafe { - glib::Object::from_glib_borrow(priv_.area.as_ptr() as *mut glib::gobject_ffi::GObject) - .emit_by_name("render", &[&priv_.area.get_context().as_ref()]) - .unwrap() - }; - priv_.area.queue_draw(); - } - Event::Disconnected => { - priv_.label.set_label("Console disconnected!"); - } - Event::CursorDefine { width, height, hot_x, hot_y, data }=> { - let scale = priv_.area.get_scale_factor(); - let pb = gdk::gdk_pixbuf::Pixbuf::from_mut_slice(data, gdk::gdk_pixbuf::Colorspace::Rgb, true, 8, width, height, width * 4); - let pb = pb.scale_simple(width * scale, height * scale, gdk::gdk_pixbuf::InterpType::Bilinear).unwrap(); - let tex = gdk::Texture::new_for_pixbuf(&pb); - let cur = gdk::Cursor::from_texture(&tex, hot_x * scale, hot_y * scale, None); - priv_.area.cursor_define(cur); - } - Event::MouseSet(m) => { - priv_.area.mouse_set(m); - let c = obj.qemu_console(); - let abs = c.mouse.is_absolute().unwrap_or(true); - if priv_.has_grab.get() { - priv_.area.set_cursor_abs(abs); - } - priv_.area.queue_render(); - } - } - Continue(true) - }), - ); - } - } -} - -glib::wrapper! { - pub struct QemuConsole(ObjectSubclass) @extends gtk::Widget; -} - -impl QemuConsole { - pub fn set_qemu_console(&self, console: Console) { - let priv_ = imp::QemuConsole::from_instance(self); - priv_.console.set(console).unwrap(); - priv_.attach_qemu_console(self); - } - - fn qemu_console(&self) -> &Console { - let priv_ = imp::QemuConsole::from_instance(self); - priv_.console.get().expect("Console is not yet set!") - } -} - -fn from_gdk_button(button: u32) -> MouseButton { - match button { - 1 => MouseButton::Left, - 2 => MouseButton::Middle, - 3 => MouseButton::Right, - _ => MouseButton::Extra, - } -} diff --git a/qemu-gtk4/src/console_area.rs b/qemu-gtk4/src/console_area.rs deleted file mode 100644 index fa01386..0000000 --- a/qemu-gtk4/src/console_area.rs +++ /dev/null @@ -1,479 +0,0 @@ -use glib::subclass::prelude::*; -use glib::translate::*; -use gtk::prelude::*; -use gtk::subclass::widget::WidgetImplExt; -use gtk::{gdk, glib, graphene}; -use std::cell::{Cell, RefCell}; -use std::ffi::{CStr, CString}; - -use crate::egl; -use crate::error::*; -use gl::{self, types::*}; -use qemu_display_listener::{MouseSet, Scanout, ScanoutDMABUF, Update}; - -mod imp { - use super::*; - use gtk::subclass::prelude::*; - - #[derive(Default)] - pub struct QemuConsoleArea { - pub tex_id: Cell, - pub texture_blit_vao: Cell, - pub texture_blit_prog: Cell, - pub texture_blit_flip_prog: Cell, - pub scanout: Cell>, - pub scanout_size: Cell<(u32, u32)>, - pub cursor_abs: Cell, - pub cursor: RefCell>, - pub mouse: Cell>, - } - - #[glib::object_subclass] - impl ObjectSubclass for QemuConsoleArea { - const NAME: &'static str = "QemuConsoleArea"; - type Type = super::QemuConsoleArea; - type ParentType = gtk::GLArea; - - fn class_init(_klass: &mut Self::Class) { - // GL loading could be done earlier? - let egl = egl::egl(); - - gl::load_with(|s| { - egl.get_proc_address(s) - .map(|f| f as _) - .unwrap_or(std::ptr::null()) - }); - } - } - - impl ObjectImpl for QemuConsoleArea { - fn constructed(&self, obj: &Self::Type) { - self.parent_constructed(obj); - } - - fn properties() -> &'static [glib::ParamSpec] { - use once_cell::sync::Lazy; - static PROPERTIES: Lazy> = Lazy::new(|| { - vec![glib::ParamSpec::boolean( - "resize-hack", - "resize-hack", - "Resize hack to notify parent", - false, - glib::ParamFlags::READWRITE | glib::ParamFlags::CONSTRUCT, - )] - }); - PROPERTIES.as_ref() - } - - fn set_property( - &self, - _obj: &Self::Type, - _id: usize, - _value: &glib::Value, - _pspec: &glib::ParamSpec, - ) { - } - } - - impl WidgetImpl for QemuConsoleArea { - fn realize(&self, widget: &Self::Type) { - widget.set_has_depth_buffer(false); - widget.set_has_stencil_buffer(false); - widget.set_auto_render(false); - widget.set_required_version(3, 2); - self.parent_realize(widget); - widget.make_current(); - - if let Err(e) = unsafe { self.realize_gl() } { - let e = glib::Error::new(QemuGtkError::GL, &e); - widget.set_error(Some(&e)); - } - } - - fn size_allocate(&self, widget: &Self::Type, width: i32, height: i32, baseline: i32) { - self.parent_size_allocate(widget, width, height, baseline); - widget.notify("resize-hack"); - } - - fn snapshot(&self, widget: &Self::Type, snapshot: >k::Snapshot) { - self.parent_snapshot(widget, snapshot); - - if !self.cursor_abs.get() { - if let Some(mouse) = self.mouse.get() { - if mouse.on != 0 { - if let Some(cursor) = &*self.cursor.borrow() { - if let Some(texture) = cursor.get_texture() { - let sf = widget.get_scale_factor(); - snapshot.append_texture( - &texture, - &graphene::Rect::new( - (mouse.x - cursor.get_hotspot_x() / sf) as f32, - (mouse.y - cursor.get_hotspot_y() / sf) as f32, - (texture.get_width() / sf) as f32, - (texture.get_height() / sf) as f32, - ), - ) - } - } - } - } - } - } - } - - impl GLAreaImpl for QemuConsoleArea { - fn render(&self, gl_area: &Self::Type, _context: &gdk::GLContext) -> bool { - unsafe { - gl::ClearColor(0.1, 0.1, 0.1, 1.0); - gl::Clear(gl::COLOR_BUFFER_BIT); - gl::Disable(gl::BLEND); - - let vp = self.viewport(gl_area); - gl::Viewport(vp.x, vp.y, vp.width, vp.height); - self.texture_blit(false); - } - - // parent will return to update call - false - } - } - - impl QemuConsoleArea { - pub fn borders(&self, gl_area: &super::QemuConsoleArea) -> (u32, u32) { - let sf = gl_area.get_scale_factor(); - let (w, h) = (gl_area.get_width() * sf, gl_area.get_height() * sf); - let (gw, gh) = gl_area.scanout_size(); - let (sw, sh) = (w as f32 / gw as f32, h as f32 / gh as f32); - - if sw < sh { - let bh = h - (h as f32 * sw / sh) as i32; - (0, bh as u32 / 2) - } else { - let bw = w - (w as f32 * sh / sw) as i32; - (bw as u32 / 2, 0) - } - } - - pub fn viewport(&self, gl_area: &super::QemuConsoleArea) -> gdk::Rectangle { - let sf = gl_area.get_scale_factor(); - let (w, h) = (gl_area.get_width() * sf, gl_area.get_height() * sf); - let (borderw, borderh) = self.borders(gl_area); - let (borderw, borderh) = (borderw as i32, borderh as i32); - gdk::Rectangle { - x: borderw, - y: borderh, - width: w - borderw * 2, - height: h - borderh * 2, - } - } - - unsafe fn realize_gl(&self) -> Result<(), String> { - let texture_blit_vs = CString::new(include_str!("texture-blit.vert")).unwrap(); - let texture_blit_flip_vs = - CString::new(include_str!("texture-blit-flip.vert")).unwrap(); - let texture_blit_fs = CString::new(include_str!("texture-blit.frag")).unwrap(); - - let texture_blit_prg = - compile_prog(texture_blit_vs.as_c_str(), texture_blit_fs.as_c_str())?; - self.texture_blit_prog.set(texture_blit_prg); - let texture_blit_flip_prg = - compile_prog(texture_blit_flip_vs.as_c_str(), texture_blit_fs.as_c_str())?; - self.texture_blit_flip_prog.set(texture_blit_flip_prg); - - let mut vao = 0; - gl::GenVertexArrays(1, &mut vao); - gl::BindVertexArray(vao); - let mut vb = 0; - gl::GenBuffers(1, &mut vb); - gl::BindBuffer(gl::ARRAY_BUFFER, vb); - static POS: [f32; 8] = [-1.0, -1.0, 1.0, -1.0, -1.0, 1.0, 1.0, 1.0]; - gl::BufferData( - gl::ARRAY_BUFFER, - std::mem::size_of::<[f32; 8]>() as _, - POS.as_ptr() as _, - gl::STATIC_DRAW, - ); - let in_pos = gl::GetAttribLocation( - texture_blit_prg, - CString::new("in_position").unwrap().as_c_str().as_ptr(), - ) as u32; - gl::VertexAttribPointer(in_pos, 2, gl::FLOAT, gl::FALSE, 0, std::ptr::null()); - gl::EnableVertexAttribArray(in_pos); - gl::BindBuffer(gl::ARRAY_BUFFER, 0); - gl::BindVertexArray(0); - self.texture_blit_vao.set(vao); - - let tex_unit = gl::GetUniformLocation( - texture_blit_prg, - CString::new("tex_unit").unwrap().as_c_str().as_ptr(), - ); - gl::ProgramUniform1i(texture_blit_prg, tex_unit, 0); - - let mut tex_id = 0; - gl::GenTextures(1, &mut tex_id); - self.tex_id.set(tex_id); - - Ok(()) - } - - unsafe fn texture_blit(&self, flip: bool) { - gl::UseProgram(if flip { - todo!(); - //self.texture_blit_flip_prog.get() - } else { - self.texture_blit_prog.get() - }); - gl::ActiveTexture(gl::TEXTURE0); - gl::BindTexture(gl::TEXTURE_2D, self.tex_id()); - gl::BindVertexArray(self.texture_blit_vao.get()); - gl::DrawArrays(gl::TRIANGLE_STRIP, 0, 4); - } - - pub fn tex_id(&self) -> GLuint { - self.tex_id.get() - } - - pub fn save_to_png(&self, widget: &super::QemuConsoleArea, filename: &str) { - let (gw, gh) = self.scanout_size.get(); - let ctxt = widget.get_context().unwrap(); - let tex = unsafe { gdk::GLTexture::new(&ctxt, self.tex_id(), gw as _, gh as _) }; - tex.save_to_png(filename); - } - - pub fn set_scanout(&self, widget: &super::QemuConsoleArea, s: Scanout) { - widget.make_current(); - - if s.format != 0x20020888 { - todo!(); - } - unsafe { - gl::BindTexture(gl::TEXTURE_2D, self.tex_id()); - gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MIN_FILTER, gl::NEAREST as _); - gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MAG_FILTER, gl::LINEAR as _); - gl::PixelStorei(gl::UNPACK_ROW_LENGTH, s.stride as i32 / 4); - gl::TexImage2D( - gl::TEXTURE_2D, - 0, - gl::RGB as _, - s.width as _, - s.height as _, - 0, - gl::BGRA, - gl::UNSIGNED_BYTE, - s.data.as_ptr() as _, - ); - } - - self.scanout_size.set((s.width, s.height)); - } - - pub fn update(&self, widget: &super::QemuConsoleArea, u: Update) { - widget.make_current(); - - if u.format != 0x20020888 { - todo!(); - } - unsafe { - gl::BindTexture(gl::TEXTURE_2D, self.tex_id()); - gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MIN_FILTER, gl::NEAREST as _); - gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MAG_FILTER, gl::LINEAR as _); - gl::PixelStorei(gl::UNPACK_ROW_LENGTH, u.stride as i32 / 4); - gl::TexSubImage2D( - gl::TEXTURE_2D, - 0, - u.x, - u.y, - u.w, - u.h, - gl::BGRA, - gl::UNSIGNED_BYTE, - u.data.as_ptr() as _, - ); - } - } - - pub fn set_scanout_dmabuf(&self, widget: &super::QemuConsoleArea, s: ScanoutDMABUF) { - widget.make_current(); - let egl = egl::egl(); - - let egl_dpy = if let Ok(dpy) = widget.get_display().downcast::() - { - let wl_dpy = dpy.get_wl_display(); - egl.get_display(wl_dpy.as_ref().c_ptr() as _) - .expect("Failed to get EGL display") - } else if let Ok(dpy) = widget.get_display().downcast::() { - let _dpy = - unsafe { gdk_x11::ffi::gdk_x11_display_get_xdisplay(dpy.to_glib_none().0) }; - eprintln!("X11: unsupported display kind, todo: EGL"); - return; - } else { - eprintln!("Unsupported display kind"); - return; - }; - - let attribs = vec![ - egl::WIDTH as usize, - s.width as usize, - egl::HEIGHT as usize, - s.height as usize, - egl::LINUX_DRM_FOURCC_EXT as usize, - s.fourcc as usize, - egl::DMA_BUF_PLANE0_FD_EXT as usize, - s.fd as usize, - egl::DMA_BUF_PLANE0_PITCH_EXT as usize, - s.stride as usize, - egl::DMA_BUF_PLANE0_OFFSET_EXT as usize, - 0, - egl::DMA_BUF_PLANE0_MODIFIER_LO_EXT as usize, - (s.modifier & 0xffffffff) as usize, - egl::DMA_BUF_PLANE0_MODIFIER_HI_EXT as usize, - (s.modifier >> 32 & 0xffffffff) as usize, - egl::NONE as usize, - ]; - - let img = egl - .create_image( - egl_dpy, - unsafe { egl::Context::from_ptr(egl::NO_CONTEXT) }, - egl::LINUX_DMA_BUF_EXT, - unsafe { egl::ClientBuffer::from_ptr(std::ptr::null_mut()) }, - &attribs, - ) - .expect("Failed to eglCreateImage"); - - unsafe { - gl::BindTexture(gl::TEXTURE_2D, self.tex_id()); - gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MIN_FILTER, gl::NEAREST as _); - gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_MAG_FILTER, gl::LINEAR as _); - } - if let Some(image_target) = egl::image_target_texture_2d_oes() { - image_target(gl::TEXTURE_2D, img.as_ptr() as gl::types::GLeglImageOES); - } else { - eprintln!("Failed to set texture image"); - } - - self.scanout_size.set((s.width, s.height)); - self.scanout.set(Some(s)); - - if let Err(e) = egl.destroy_image(egl_dpy, img) { - eprintln!("Destroy image failed: {}", e); - } - } - } -} - -glib::wrapper! { - pub struct QemuConsoleArea(ObjectSubclass) - @extends gtk::Widget, gtk::GLArea; -} - -impl QemuConsoleArea { - pub fn scanout_size(&self) -> (u32, u32) { - let priv_ = imp::QemuConsoleArea::from_instance(self); - - priv_.scanout_size.get() - } - - pub fn set_scanout(&self, s: Scanout) { - let priv_ = imp::QemuConsoleArea::from_instance(self); - - priv_.set_scanout(self, s); - } - - pub fn update(&self, u: Update) { - let priv_ = imp::QemuConsoleArea::from_instance(self); - - priv_.update(self, u); - } - - pub fn set_scanout_dmabuf(&self, s: ScanoutDMABUF) { - let priv_ = imp::QemuConsoleArea::from_instance(self); - - priv_.set_scanout_dmabuf(self, s); - } - - pub fn save_to_png(&self, filename: &str) { - let priv_ = imp::QemuConsoleArea::from_instance(self); - - priv_.save_to_png(self, filename); - } - - pub fn transform_input(&self, x: f64, y: f64) -> Option<(u32, u32)> { - let priv_ = imp::QemuConsoleArea::from_instance(self); - - let vp = priv_.viewport(self); - let x = x as i32 * self.get_scale_factor(); - let y = y as i32 * self.get_scale_factor(); - if !vp.contains_point(x, y) { - return None; - } - let (sw, sh) = priv_.scanout_size.get(); - let x = (x - vp.x) as f64 * (sw as f64 / vp.width as f64); - let y = (y - vp.y) as f64 * (sh as f64 / vp.height as f64); - Some((x as u32, y as u32)) - } - - pub fn set_cursor_abs(&self, abs: bool) { - let priv_ = imp::QemuConsoleArea::from_instance(self); - - priv_.cursor_abs.set(abs); - if abs { - if let Some(cursor) = priv_.cursor.borrow().clone() { - self.set_cursor(Some(&cursor)); - } - } else { - self.set_cursor_from_name(Some("none")) - } - self.queue_render(); - } - - pub fn cursor_define(&self, cursor: gdk::Cursor) { - let priv_ = imp::QemuConsoleArea::from_instance(self); - priv_.cursor.replace(Some(cursor)); - } - - pub fn mouse_set(&self, mouse: MouseSet) { - let priv_ = imp::QemuConsoleArea::from_instance(self); - priv_.mouse.set(Some(mouse)); - } -} - -unsafe fn compile_shader(type_: GLenum, src: &CStr) -> GLuint { - let shader = gl::CreateShader(type_); - gl::ShaderSource(shader, 1, &src.as_ptr(), std::ptr::null()); - gl::CompileShader(shader); - shader -} - -fn cstring_new_len(len: usize) -> CString { - let buffer: Vec = Vec::with_capacity(len + 1); - unsafe { CString::from_vec_unchecked(buffer) } -} - -unsafe fn compile_prog(vs: &CStr, fs: &CStr) -> Result { - let vs = compile_shader(gl::VERTEX_SHADER, vs); - let fs = compile_shader(gl::FRAGMENT_SHADER, fs); - let prog = gl::CreateProgram(); - - gl::AttachShader(prog, vs); - gl::AttachShader(prog, fs); - gl::LinkProgram(prog); - - let mut status: i32 = 0; - gl::GetProgramiv(prog, gl::LINK_STATUS, &mut status); - if status == 0 { - let mut len: GLint = 0; - gl::GetProgramiv(prog, gl::INFO_LOG_LENGTH, &mut len); - let error = cstring_new_len(len as usize); - gl::GetProgramInfoLog( - prog, - len, - std::ptr::null_mut(), - error.as_ptr() as *mut gl::types::GLchar, - ); - return Err(error.to_string_lossy().into_owned()); - } - gl::DeleteShader(vs); - gl::DeleteShader(fs); - Ok(prog) -} diff --git a/qemu-gtk4/src/egl.rs b/qemu-gtk4/src/egl.rs deleted file mode 100644 index e2e5437..0000000 --- a/qemu-gtk4/src/egl.rs +++ /dev/null @@ -1,35 +0,0 @@ -pub use khronos_egl::*; -use once_cell::sync::OnceCell; - -type EglInstance = Instance>; - -pub(crate) fn egl() -> &'static EglInstance { - static INSTANCE: OnceCell = OnceCell::new(); - INSTANCE.get_or_init(|| { - let lib = libloading::Library::new("libEGL.so").expect("unable to find libEGL.so"); - unsafe { - khronos_egl::DynamicInstance::::load_required_from(lib) - .expect("unable to load libEGL.so") - } - }) -} - -pub const LINUX_DMA_BUF_EXT: Enum = 0x3270; -pub const LINUX_DRM_FOURCC_EXT: Int = 0x3271; -pub const DMA_BUF_PLANE0_FD_EXT: Int = 0x3272; -pub const DMA_BUF_PLANE0_OFFSET_EXT: Int = 0x3273; -pub const DMA_BUF_PLANE0_PITCH_EXT: Int = 0x3274; -pub const DMA_BUF_PLANE0_MODIFIER_LO_EXT: Int = 0x3443; -pub const DMA_BUF_PLANE0_MODIFIER_HI_EXT: Int = 0x3444; - -// GLAPI void APIENTRY glEGLImageTargetTexture2DOES (GLenum target, GLeglImageOES image); - -pub type ImageTargetTexture2DOesFn = extern "C" fn(gl::types::GLenum, gl::types::GLeglImageOES); - -pub fn image_target_texture_2d_oes() -> Option { - unsafe { - egl() - .get_proc_address("glEGLImageTargetTexture2DOES") - .map(|f| std::mem::transmute::<_, ImageTargetTexture2DOesFn>(f)) - } -} diff --git a/qemu-gtk4/src/error.rs b/qemu-gtk4/src/error.rs deleted file mode 100644 index 1190d8d..0000000 --- a/qemu-gtk4/src/error.rs +++ /dev/null @@ -1,8 +0,0 @@ -use gtk::glib; - -#[derive(Clone, Copy, Debug, PartialEq, Eq, glib::GErrorDomain)] -#[gerror_domain(name = "QemuGtk")] -pub enum QemuGtkError { - GL, - Failed, -} diff --git a/qemu-gtk4/src/gstaudio.rs b/qemu-gtk4/src/gstaudio.rs deleted file mode 100644 index 51252ff..0000000 --- a/qemu-gtk4/src/gstaudio.rs +++ /dev/null @@ -1,140 +0,0 @@ -use gst::prelude::*; -use gst_audio::StreamVolumeExt; -use std::thread::{self, JoinHandle}; -use std::{collections::HashMap, error::Error}; - -use qemu_display_listener::{Audio, PCMInfo}; - -#[derive(Debug)] -struct OutStream { - pipeline: gst::Pipeline, - src: gst_app::AppSrc, - sink: gst::Element, -} - -fn pcminfo_as_caps(info: &PCMInfo) -> String { - let format = format!( - "{}{}{}", - if info.is_float { - "F" - } else if info.is_signed { - "S" - } else { - "U" - }, - info.bits, - if info.be { "BE" } else { "LE" } - ); - format!( - "audio/x-raw,format={format},channels={channels},rate={rate},layout=interleaved", - format = format, - channels = info.nchannels, - rate = info.freq, - ) -} - -impl OutStream { - fn new(info: &PCMInfo) -> Result> { - let caps = pcminfo_as_caps(info); - let pipeline = &format!("appsrc name=src is-live=1 do-timestamp=0 format=time caps=\"{}\" ! queue ! audioconvert ! audioresample ! autoaudiosink name=sink", caps); - let pipeline = gst::parse_launch(pipeline)?; - let pipeline = pipeline.dynamic_cast::().unwrap(); - let src = pipeline - .get_by_name("src") - .unwrap() - .dynamic_cast::() - .unwrap(); - let sink = pipeline.get_by_name("sink").unwrap(); - Ok(Self { - pipeline, - src, - sink, - }) - } -} - -#[derive(Debug)] -pub struct GstAudio { - out_thread: JoinHandle<()>, -} - -impl GstAudio { - pub fn new(audio: Audio) -> Result> { - gst::init()?; - - // TODO audio.listen_in() for capture. - let rx = audio.listen_out()?; - let mut out = HashMap::new(); - let out_thread = thread::spawn(move || loop { - match rx.recv() { - Ok(event) => { - use qemu_display_listener::AudioOutEvent::*; - match event { - Init { id, info } => { - if out.contains_key(&id) { - eprintln!("Invalid Init, id {} is already setup", id); - continue; - } - match OutStream::new(&info) { - Ok(s) => { - out.insert(id, s); - } - Err(e) => { - eprintln!("Failed to create stream: {}", e); - } - } - } - Fini { id } => { - out.remove(&id); - } - SetEnabled { id, enabled } => { - if let Some(s) = out.get(&id) { - if let Err(e) = s.pipeline.set_state(if enabled { - gst::State::Playing - } else { - gst::State::Ready - }) { - eprintln!("Failed to change state: {}", e); - } - } else { - eprintln!("Stream was not setup yet: {}", id); - } - } - SetVolume { id, volume } => { - if let Some(s) = out.get(&id) { - if let Some(stream_vol) = s - .pipeline - .get_by_interface(gst_audio::StreamVolume::static_type()) - { - let stream_vol = stream_vol - .dynamic_cast::() - .unwrap(); - stream_vol.set_mute(volume.mute); - if let Some(vol) = volume.volume.first() { - let vol = *vol as f64 / 255f64; - stream_vol - .set_volume(gst_audio::StreamVolumeFormat::Cubic, vol); - } - } else { - eprintln!("Volume not implemented for this pipeline"); - } - } else { - eprintln!("Stream was not setup yet: {}", id); - } - } - Write { id, data } => { - if let Some(s) = out.get(&id) { - let b = gst::Buffer::from_slice(data); - let _ = s.src.push_buffer(b); - } else { - eprintln!("Stream was not setup yet: {}", id); - } - } - } - } - Err(e) => eprintln!("Audio thread error: {}", e), - } - }); - Ok(Self { out_thread }) - } -} diff --git a/qemu-gtk4/src/main.rs b/qemu-gtk4/src/main.rs deleted file mode 100644 index f113417..0000000 --- a/qemu-gtk4/src/main.rs +++ /dev/null @@ -1,36 +0,0 @@ -#[allow(clippy::new_without_default)] -mod application; -#[rustfmt::skip] -mod config; -mod console; -mod console_area; -mod egl; -mod error; -mod gstaudio; -mod window; - -use application::QemuApplication; -use config::{GETTEXT_PACKAGE, LOCALEDIR, RESOURCES_FILE}; -use gettextrs::*; -use gtk::gio; - -fn main() { - // Initialize logger, debug is carried out via debug!, info!, and warn!. - pretty_env_logger::init(); - - // Prepare i18n - setlocale(LocaleCategory::LcAll, ""); - bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR); - textdomain(GETTEXT_PACKAGE); - - gtk::glib::set_application_name("QEMU Gtk"); - gtk::glib::set_prgname(Some("qemu-gtk4")); - - gtk::init().expect("Unable to start GTK4"); - - let res = gio::Resource::load(RESOURCES_FILE).expect("Could not load gresource file"); - gio::resources_register(&res); - - let app = QemuApplication::new(); - app.run(); -} diff --git a/qemu-gtk4/src/meson.build b/qemu-gtk4/src/meson.build deleted file mode 100644 index d885b6b..0000000 --- a/qemu-gtk4/src/meson.build +++ /dev/null @@ -1,48 +0,0 @@ -global_conf = configuration_data() -global_conf.set_quoted('APP_ID', application_id) -global_conf.set_quoted('PKGDATADIR', pkgdatadir) -global_conf.set_quoted('PROFILE', profile) -global_conf.set_quoted('VERSION', version + version_suffix) -global_conf.set_quoted('GETTEXT_PACKAGE', gettext_package) -global_conf.set_quoted('LOCALEDIR', localedir) -config = configure_file( - input: 'config.rs.in', - output: 'config.rs', - configuration: global_conf -) -# Copy the config.rs output to the source directory. -run_command( - 'cp', - meson.build_root() / 'src' / 'config.rs', - meson.source_root() / 'src' / 'config.rs', - check: true -) - -sources = files( - 'application.rs', - 'config.rs', - 'console.rs', - 'console_area.rs', - 'egl.rs', - 'main.rs', - 'window.rs', -) - -custom_target( - 'cargo-build', - build_by_default: true, - input: sources, - output: meson.project_name(), - console: true, - install: true, - install_dir: bindir, - depends: resources, - command: [ - cargo_script, - meson.build_root(), - meson.source_root(), - '@OUTPUT@', - profile, - meson.project_name(), - ] -) diff --git a/qemu-gtk4/src/texture-blit-flip.vert b/qemu-gtk4/src/texture-blit-flip.vert deleted file mode 100644 index f9b93d9..0000000 --- a/qemu-gtk4/src/texture-blit-flip.vert +++ /dev/null @@ -1,10 +0,0 @@ - -#version 130 - -in vec2 in_position; -out vec2 ex_tex_coord; - -void main(void) { - gl_Position = vec4(in_position, 0.0, 1.0); - ex_tex_coord = vec2(1.0 + in_position.x, 1.0 + in_position.y) * 0.5; -} diff --git a/qemu-gtk4/src/texture-blit.frag b/qemu-gtk4/src/texture-blit.frag deleted file mode 100644 index c916ec6..0000000 --- a/qemu-gtk4/src/texture-blit.frag +++ /dev/null @@ -1,10 +0,0 @@ - -#version 130 - -uniform sampler2D tex_unit; -in mediump vec2 ex_tex_coord; -out mediump vec4 out_frag_color; - -void main(void) { - out_frag_color = texture(tex_unit, ex_tex_coord); -} diff --git a/qemu-gtk4/src/texture-blit.vert b/qemu-gtk4/src/texture-blit.vert deleted file mode 100644 index c688865..0000000 --- a/qemu-gtk4/src/texture-blit.vert +++ /dev/null @@ -1,10 +0,0 @@ - -#version 130 - -in vec2 in_position; -out vec2 ex_tex_coord; - -void main(void) { - gl_Position = vec4(in_position, 0.0, 1.0); - ex_tex_coord = vec2(1.0 + in_position.x, 1.0 - in_position.y) * 0.5; -} diff --git a/qemu-gtk4/src/window.rs b/qemu-gtk4/src/window.rs deleted file mode 100644 index b736e98..0000000 --- a/qemu-gtk4/src/window.rs +++ /dev/null @@ -1,125 +0,0 @@ -use crate::application::QemuApplication; -use crate::config::{APP_ID, PROFILE}; -use crate::console::QemuConsole; -use glib::signal::Inhibit; -use gtk::subclass::prelude::*; -use gtk::{self, prelude::*}; -use gtk::{gio, glib, CompositeTemplate}; -use log::warn; - -use qemu_display_listener::Console; - -mod imp { - use super::*; - - #[derive(Debug, CompositeTemplate)] - #[template(resource = "/org/qemu/gtk4/window.ui")] - pub struct QemuApplicationWindow { - #[template_child] - pub headerbar: TemplateChild, - #[template_child] - pub console: TemplateChild, - pub settings: gio::Settings, - } - - #[glib::object_subclass] - impl ObjectSubclass for QemuApplicationWindow { - const NAME: &'static str = "QemuApplicationWindow"; - type Type = super::QemuApplicationWindow; - type ParentType = gtk::ApplicationWindow; - - fn new() -> Self { - Self { - headerbar: TemplateChild::default(), - console: TemplateChild::default(), - settings: gio::Settings::new(APP_ID), - } - } - - fn class_init(klass: &mut Self::Class) { - Self::bind_template(klass); - } - - // You must call `Widget`'s `init_template()` within `instance_init()`. - fn instance_init(obj: &glib::subclass::InitializingObject) { - obj.init_template(); - } - } - - impl ObjectImpl for QemuApplicationWindow { - fn constructed(&self, obj: &Self::Type) { - self.parent_constructed(obj); - - let builder = gtk::Builder::from_resource("/org/qemu/gtk4/shortcuts.ui"); - let shortcuts = builder.get_object("shortcuts").unwrap(); - obj.set_help_overlay(Some(&shortcuts)); - - // Devel Profile - if PROFILE == "Devel" { - obj.get_style_context().add_class("devel"); - } - - // load latest window state - obj.load_window_size(); - } - } - - impl WindowImpl for QemuApplicationWindow { - // save window state on delete event - fn close_request(&self, obj: &Self::Type) -> Inhibit { - if let Err(err) = obj.save_window_size() { - warn!("Failed to save window state, {}", &err); - } - Inhibit(false) - } - } - - impl WidgetImpl for QemuApplicationWindow {} - impl ApplicationWindowImpl for QemuApplicationWindow {} -} - -glib::wrapper! { - pub struct QemuApplicationWindow(ObjectSubclass) - @extends gtk::Widget, gtk::Window, gtk::ApplicationWindow, @implements gio::ActionMap, gio::ActionGroup; -} - -impl QemuApplicationWindow { - pub fn new(app: &QemuApplication, console: Console) -> Self { - let window: Self = glib::Object::new(&[]).expect("Failed to create QemuApplicationWindow"); - window.set_application(Some(app)); - - let win = &imp::QemuApplicationWindow::from_instance(&window); - win.console.set_qemu_console(console); - // Set icons for shell - gtk::Window::set_default_icon_name(APP_ID); - - window - } - - pub fn save_window_size(&self) -> Result<(), glib::BoolError> { - let settings = &imp::QemuApplicationWindow::from_instance(self).settings; - - let size = self.get_default_size(); - - settings.set_int("window-width", size.0)?; - settings.set_int("window-height", size.1)?; - - settings.set_boolean("is-maximized", self.is_maximized())?; - - Ok(()) - } - - fn load_window_size(&self) { - let settings = &imp::QemuApplicationWindow::from_instance(self).settings; - - let width = settings.get_int("window-width"); - let height = settings.get_int("window-height"); - let is_maximized = settings.get_boolean("is-maximized"); - - self.set_default_size(width, height); - - if is_maximized { - self.maximize(); - } - } -}