diff --git a/.gitignore b/.gitignore index 2f7896d..a272990 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -target/ +**/target/ +**/.vscode diff --git a/Cargo.lock b/Cargo.lock index 19baf59..686c98e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "aho-corasick" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea5d730647d4fadd988536d06fecce94b7b4f2a7efdae548f1cf4b63205518ab" +dependencies = [ + "memchr", +] + [[package]] name = "anyhow" version = "1.0.75" @@ -20,6 +29,12 @@ version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b4682ae6287fcf752ecaabbfcc7b6f9b72aa33933dc23a554d853aea8eea8635" +[[package]] +name = "block" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" + [[package]] name = "cairo-rs" version = "0.18.2" @@ -45,6 +60,15 @@ dependencies = [ "system-deps", ] +[[package]] +name = "cc" +version = "1.0.83" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0" +dependencies = [ + "libc", +] + [[package]] name = "cfg-expr" version = "0.15.5" @@ -56,13 +80,10 @@ dependencies = [ ] [[package]] -name = "demo" -version = "0.1.0" -dependencies = [ - "gtk4", - "libadwaita", - "origami", -] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "equivalent" @@ -201,6 +222,26 @@ dependencies = [ "system-deps", ] +[[package]] +name = "gettext-rs" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e49ea8a8fad198aaa1f9655a2524b64b70eb06b2f3ff37da407566c93054f364" +dependencies = [ + "gettext-sys", + "locale_config", +] + +[[package]] +name = "gettext-sys" +version = "0.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c63ce2e00f56a206778276704bbe38564c8695249fdc8f354b4ef71c57c3839d" +dependencies = [ + "cc", + "temp-dir", +] + [[package]] name = "gio" version = "0.18.2" @@ -421,6 +462,12 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "lazy_static" +version = "1.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" + [[package]] name = "libadwaita" version = "0.5.3" @@ -459,17 +506,39 @@ version = "0.2.148" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9cdc71e17332e86d2e1d38c1f99edcb6288ee11b815fb1a4b049eaa2114d369b" +[[package]] +name = "locale_config" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d2c35b16f4483f6c26f0e4e9550717a2f6575bcd6f12a53ff0c490a94a6934" +dependencies = [ + "lazy_static", + "objc", + "objc-foundation", + "regex", + "winapi", +] + [[package]] name = "log" version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +[[package]] +name = "malloc_buf" +version = "0.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62bb907fe88d54d8d9ce32a3cceab4218ed2f6b7d35617cafe9adf84e43919cb" +dependencies = [ + "libc", +] + [[package]] name = "memchr" -version = "2.6.3" +version = "2.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f232d6ef707e1956a43342693d2a31e72989554d58299d7a88738cc95b0d35c" +checksum = "f665ee40bc4a3c5590afb1e9677db74a508659dfd71e126420da8274909a0167" [[package]] name = "memoffset" @@ -480,6 +549,45 @@ dependencies = [ "autocfg", ] +[[package]] +name = "nu-ansi-term" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a8165726e8236064dbb45459242600304b42a5ea24ee2948e18e023bf7ba84" +dependencies = [ + "overload", + "winapi", +] + +[[package]] +name = "objc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1" +dependencies = [ + "malloc_buf", +] + +[[package]] +name = "objc-foundation" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9" +dependencies = [ + "block", + "objc", + "objc_id", +] + +[[package]] +name = "objc_id" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b" +dependencies = [ + "objc", +] + [[package]] name = "once_cell" version = "1.18.0" @@ -495,6 +603,24 @@ dependencies = [ "log", ] +[[package]] +name = "origami-demo" +version = "0.1.0" +dependencies = [ + "gettext-rs", + "gtk4", + "libadwaita", + "origami", + "tracing", + "tracing-subscriber", +] + +[[package]] +name = "overload" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15813163c1d831bf4a13c3610c05c0d03b39feb07f7e09fa234dac9b15aaf39" + [[package]] name = "pango" version = "0.18.0" @@ -590,6 +716,35 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "regex" +version = "1.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebee201405406dbf528b8b672104ae6d6d63e6d118cb10e4d51abbc7b58044ff" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59b23e92ee4318893fa3fe3e6fb365258efbfe6ac6ab30f090cdcbb7aa37efa9" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dbb5fb1acd8a1a18b3dd5be62d25485eb770e05afb408a9627d14d451bae12da" + [[package]] name = "rustc_version" version = "0.4.0" @@ -634,6 +789,15 @@ dependencies = [ "serde", ] +[[package]] +name = "sharded-slab" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1b21f559e07218024e7e9f90f96f601825397de0e25420135f7f952453fed0b" +dependencies = [ + "lazy_static", +] + [[package]] name = "slab" version = "0.4.9" @@ -690,6 +854,12 @@ version = "0.12.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d0e916b1148c8e263850e1ebcbd046f333e0683c724876bb0da63ea4373dc8a" +[[package]] +name = "temp-dir" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af547b166dd1ea4b472165569fc456cfb6818116f854690b0ff205e636523dab" + [[package]] name = "thiserror" version = "1.0.49" @@ -710,6 +880,16 @@ dependencies = [ "syn 2.0.37", ] +[[package]] +name = "thread_local" +version = "1.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" +dependencies = [ + "cfg-if", + "once_cell", +] + [[package]] name = "toml" version = "0.7.8" @@ -744,12 +924,76 @@ dependencies = [ "winnow", ] +[[package]] +name = "tracing" +version = "0.1.37" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +dependencies = [ + "cfg-if", + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.26" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f4f31f56159e98206da9efd823404b79b6ef3143b4a7ab76e67b1751b25a4ab" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.37", +] + +[[package]] +name = "tracing-core" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0955b8137a1df6f1a2e9a37d8a6656291ff0297c1a97c24e0d8425fe2312f79a" +dependencies = [ + "once_cell", + "valuable", +] + +[[package]] +name = "tracing-log" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922" +dependencies = [ + "lazy_static", + "log", + "tracing-core", +] + +[[package]] +name = "tracing-subscriber" +version = "0.3.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30a651bc37f915e81f087d86e62a18eec5f79550c7faff886f7090b4ea757c77" +dependencies = [ + "nu-ansi-term", + "sharded-slab", + "smallvec", + "thread_local", + "tracing-core", + "tracing-log", +] + [[package]] name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "valuable" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" + [[package]] name = "version-compare" version = "0.1.1" diff --git a/Cargo.toml b/Cargo.toml index f6c0b41..7672d6a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] members = [ - "demo", - "origami" -] \ No newline at end of file + "origami", + "origami-demo", +] diff --git a/demo/.gitignore b/demo/.gitignore deleted file mode 100644 index ea8c4bf..0000000 --- a/demo/.gitignore +++ /dev/null @@ -1 +0,0 @@ -/target diff --git a/demo/Cargo.toml b/demo/Cargo.toml deleted file mode 100644 index 7ebf593..0000000 --- a/demo/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "demo" -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -adw = { version = "0.5", package = "libadwaita" } -gtk = { version = "0.7", package = "gtk4", features = ["v4_10", "blueprint"] } -ori = { path = "../origami", package = "origami" } \ No newline at end of file diff --git a/demo/src/main.rs b/demo/src/main.rs deleted file mode 100644 index a1b4ae9..0000000 --- a/demo/src/main.rs +++ /dev/null @@ -1,25 +0,0 @@ -mod window; -use window::SpoilerWindow; - -use adw::prelude::*; - -fn main() { - ori::init(); - - let mut args = std::env::args(); - let name = args.next(); - let page = args.next(); - - if args.next().is_some() { - eprintln!("Too many arguments"); - std::process::exit(1); - } - - let app = adw::Application::builder() - .application_id("com.github.paper-plane-developers.OriDemo") - .build(); - - app.connect_activate(move |app| SpoilerWindow::new(app, page.clone()).present()); - - app.run_with_args(&[name.unwrap_or_default()]); -} diff --git a/origami-demo/.gitignore b/origami-demo/.gitignore new file mode 100644 index 0000000..1981755 --- /dev/null +++ b/origami-demo/.gitignore @@ -0,0 +1,9 @@ +/build/ +/_build/ +/builddir/ +/build-aux/app +/build-aux/.flatpak-builder/ +*.ui.in~ +*.ui~ +/.flatpak/ +/vendor diff --git a/origami-demo/Cargo.toml b/origami-demo/Cargo.toml new file mode 100644 index 0000000..5d151c7 --- /dev/null +++ b/origami-demo/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "origami-demo" +version = "0.1.0" +edition = "2021" + +[profile.release] +lto = true + +[dependencies] +adw = { version = "0.5", package = "libadwaita" } +gettext-rs = { version = "0.7", features = ["gettext-system"] } +gtk = { version = "0.7", package = "gtk4", features = ["blueprint", "v4_10"] } +ori = { path = "../origami", package = "origami" } +tracing = "0.1.37" +tracing-subscriber = "0.3" diff --git a/origami-demo/build-aux/com.github.paper_plane_developers.OrigamiDemo.Devel.json b/origami-demo/build-aux/com.github.paper_plane_developers.OrigamiDemo.Devel.json new file mode 100644 index 0000000..be6cabc --- /dev/null +++ b/origami-demo/build-aux/com.github.paper_plane_developers.OrigamiDemo.Devel.json @@ -0,0 +1,64 @@ +{ + "id": "com.github.paper_plane_developers.OrigamiDemo.Devel", + "runtime": "org.gnome.Platform", + "runtime-version": "45", + "sdk": "org.gnome.Sdk", + "sdk-extensions": [ + "org.freedesktop.Sdk.Extension.rust-stable", + "org.freedesktop.Sdk.Extension.llvm16" + ], + "command": "origami-demo", + "finish-args": [ + "--share=ipc", + "--socket=fallback-x11", + "--socket=wayland", + "--device=dri", + "--env=RUST_LOG=origami_demo=debug", + "--env=G_MESSAGES_DEBUG=none", + "--env=RUST_BACKTRACE=1" + ], + "build-options": { + "append-path": "/usr/lib/sdk/rust-stable/bin:/usr/lib/sdk/llvm16/bin", + "build-args": [ + "--share=network" + ], + "env": { + "CARGO_REGISTRIES_CRATES_IO_PROTOCOL": "sparse", + "CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER": "clang", + "CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_RUSTFLAGS": "-C link-arg=-fuse-ld=/usr/lib/sdk/rust-stable/bin/mold", + "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER": "clang", + "CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUSTFLAGS": "-C link-arg=-fuse-ld=/usr/lib/sdk/rust-stable/bin/mold" + }, + "test-args": [ + "--socket=x11", + "--share=network" + ] + }, + "modules": [ + { + "name": "blueprint-compiler", + "buildsystem": "meson", + "sources": [ + { + "type": "archive", + "url": "https://gitlab.gnome.org/jwestman/blueprint-compiler/-/archive/v0.8.1/blueprint-compiler-v0.8.1.tar.gz", + "sha256": "9207697cfac6e87a3c0ccf463be1a95c3bd06aa017c966a7e352ad5bc486cf3c" + } + ] + }, + { + "name": "origami-demo", + "buildsystem": "meson", + "run-tests": true, + "config-opts": [ + "-Dprofile=development" + ], + "sources": [ + { + "type": "dir", + "path": "../" + } + ] + } + ] +} diff --git a/origami-demo/build-aux/dist-vendor.sh b/origami-demo/build-aux/dist-vendor.sh new file mode 100644 index 0000000..ad6a6f0 --- /dev/null +++ b/origami-demo/build-aux/dist-vendor.sh @@ -0,0 +1,16 @@ +#!/bin/sh +# Since Meson invokes this script as +# "/bin/sh .../dist-vendor.sh DIST SOURCE_ROOT" we can't rely on bash features +set -eu +export DIST="$1" +export SOURCE_ROOT="$2" + +cd "$SOURCE_ROOT" +mkdir "$DIST"/.cargo +cargo vendor > "$DIST/.cargo/config" +# Don't combine the previous and this line with a pipe because we can't catch +# errors with "set -o pipefail" +sed -i 's/^directory = ".*"/directory = "vendor"/g' "$DIST/.cargo/config" +# Move vendor into dist tarball directory +mv vendor "$DIST" + diff --git a/origami-demo/data/com.github.paper_plane_developers.OrigamiDemo.desktop.in.in b/origami-demo/data/com.github.paper_plane_developers.OrigamiDemo.desktop.in.in new file mode 100644 index 0000000..bbfcc3b --- /dev/null +++ b/origami-demo/data/com.github.paper_plane_developers.OrigamiDemo.desktop.in.in @@ -0,0 +1,12 @@ +[Desktop Entry] +Name=Origami Demo +Comment=Write a GTK + Rust application +Type=Application +Exec=origami-demo +Terminal=false +Categories=GNOME;GTK; +# Translators: Search terms to find this application. Do NOT translate or localize the semicolons! The list MUST also end with a semicolon! +Keywords=Gnome;GTK; +# Translators: Do NOT translate or transliterate this text (this is an icon file name)! +Icon=@icon@ +StartupNotify=true diff --git a/origami-demo/data/com.github.paper_plane_developers.OrigamiDemo.gschema.xml.in b/origami-demo/data/com.github.paper_plane_developers.OrigamiDemo.gschema.xml.in new file mode 100644 index 0000000..692268f --- /dev/null +++ b/origami-demo/data/com.github.paper_plane_developers.OrigamiDemo.gschema.xml.in @@ -0,0 +1,17 @@ + + + + + 600 + Window width + + + 400 + Window height + + + false + Window maximized state + + + diff --git a/origami-demo/data/com.github.paper_plane_developers.OrigamiDemo.metainfo.xml.in.in b/origami-demo/data/com.github.paper_plane_developers.OrigamiDemo.metainfo.xml.in.in new file mode 100644 index 0000000..5e8a450 --- /dev/null +++ b/origami-demo/data/com.github.paper_plane_developers.OrigamiDemo.metainfo.xml.in.in @@ -0,0 +1,37 @@ + + + + @app-id@ + CC0 + + + Origami Demo + Write a GTK + Rust application + +

A boilerplate template for GTK + Rust. It uses Meson as a build system and has flatpak support by default.

+
+ + + https://gitlab.gnome.org/bilelmoussaoui/origami-demo/raw/master/data/resources/screenshots/screenshot1.png + Main window + + + https://gitlab.gnome.org/bilelmoussaoui/origami-demo + https://gitlab.gnome.org/bilelmoussaoui/origami-demo/issues + + + + + + + ModernToolkit + HiDpiIcon + + Paper Plane Developers + + @gettext-package@ + @app-id@.desktop +
diff --git a/origami-demo/data/icons/com.github.paper_plane_developers.OrigamiDemo-symbolic.svg b/origami-demo/data/icons/com.github.paper_plane_developers.OrigamiDemo-symbolic.svg new file mode 100644 index 0000000..fc4d934 --- /dev/null +++ b/origami-demo/data/icons/com.github.paper_plane_developers.OrigamiDemo-symbolic.svg @@ -0,0 +1,59 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/origami-demo/data/icons/com.github.paper_plane_developers.OrigamiDemo.Devel.svg b/origami-demo/data/icons/com.github.paper_plane_developers.OrigamiDemo.Devel.svg new file mode 100644 index 0000000..92533ae --- /dev/null +++ b/origami-demo/data/icons/com.github.paper_plane_developers.OrigamiDemo.Devel.svg @@ -0,0 +1,147 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/origami-demo/data/icons/com.github.paper_plane_developers.OrigamiDemo.svg b/origami-demo/data/icons/com.github.paper_plane_developers.OrigamiDemo.svg new file mode 100644 index 0000000..c2bd5b1 --- /dev/null +++ b/origami-demo/data/icons/com.github.paper_plane_developers.OrigamiDemo.svg @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/origami-demo/data/icons/meson.build b/origami-demo/data/icons/meson.build new file mode 100644 index 0000000..2ab86e9 --- /dev/null +++ b/origami-demo/data/icons/meson.build @@ -0,0 +1,10 @@ +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/origami-demo/data/meson.build b/origami-demo/data/meson.build new file mode 100644 index 0000000..5643b60 --- /dev/null +++ b/origami-demo/data/meson.build @@ -0,0 +1,76 @@ +subdir('icons') +subdir('resources') +# 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() + ], + depends: desktop_file, + ) +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() + ], + depends: appdata_file, + ) +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_build_dir() + ], + ) +endif diff --git a/origami-demo/data/resources/meson.build b/origami-demo/data/resources/meson.build new file mode 100644 index 0000000..604e1b2 --- /dev/null +++ b/origami-demo/data/resources/meson.build @@ -0,0 +1,9 @@ +# 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/origami-demo/data/resources/resources.gresource.xml b/origami-demo/data/resources/resources.gresource.xml new file mode 100644 index 0000000..3e00c03 --- /dev/null +++ b/origami-demo/data/resources/resources.gresource.xml @@ -0,0 +1,8 @@ + + + + + ui/shortcuts.ui + style.css + + diff --git a/origami-demo/data/resources/screenshots/screenshot1.png b/origami-demo/data/resources/screenshots/screenshot1.png new file mode 100644 index 0000000..173b6be Binary files /dev/null and b/origami-demo/data/resources/screenshots/screenshot1.png differ diff --git a/origami-demo/data/resources/style.css b/origami-demo/data/resources/style.css new file mode 100644 index 0000000..3c4bd47 --- /dev/null +++ b/origami-demo/data/resources/style.css @@ -0,0 +1,4 @@ +.title-header{ + font-size: 36px; + font-weight: bold; +} diff --git a/origami-demo/data/resources/ui/shortcuts.ui b/origami-demo/data/resources/ui/shortcuts.ui new file mode 100644 index 0000000..ef12f02 --- /dev/null +++ b/origami-demo/data/resources/ui/shortcuts.ui @@ -0,0 +1,29 @@ + + + + True + + + shortcuts + 10 + + + General + + + Show Shortcuts + win.show-help-overlay + + + + + Quit + app.quit + + + + + + + + diff --git a/origami-demo/hooks/pre-commit.hook b/origami-demo/hooks/pre-commit.hook new file mode 100755 index 0000000..464590e --- /dev/null +++ b/origami-demo/hooks/pre-commit.hook @@ -0,0 +1,57 @@ +#!/bin/sh +# Source: https://gitlab.gnome.org/GNOME/fractal/blob/master/hooks/pre-commit.hook + +install_rustfmt() { + if ! which rustup >/dev/null 2>&1; then + curl https://sh.rustup.rs -sSf | sh -s -- -y + export PATH=$PATH:$HOME/.cargo/bin + if ! which rustup >/dev/null 2>&1; then + echo "Failed to install rustup. Performing the commit without style checking." + exit 0 + fi + fi + + if ! rustup component list|grep rustfmt >/dev/null 2>&1; then + echo "Installing rustfmt…" + rustup component add rustfmt + fi +} + +if ! which cargo >/dev/null 2>&1 || ! cargo fmt --help >/dev/null 2>&1; then + echo "Unable to check the project’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" + + echo "" + while true + do + printf "%s" "Install rustfmt via rustup? [y/n/Q]: "; read yn < /dev/tty + case $yn in + [Yy]* ) install_rustfmt; break;; + [Nn]* ) echo "Performing commit."; exit 0;; + [Qq]* | "" ) echo "Aborting commit."; exit 1 >/dev/null 2>&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/origami-demo/meson.build b/origami-demo/meson.build new file mode 100644 index 0000000..1580ac8 --- /dev/null +++ b/origami-demo/meson.build @@ -0,0 +1,71 @@ +project( + 'origami-demo', + 'rust', + version: '0.1.0', + meson_version: '>= 0.59', + # license: 'MIT', +) + +i18n = import('i18n') +gnome = import('gnome') + +base_id = 'com.github.paper_plane_developers.OrigamiDemo' + +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) + +version = meson.project_version() + +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.project_source_root() / 'po' +gettext_package = meson.project_name() + +if get_option('profile') == 'development' + profile = 'Devel' + vcs_tag = run_command('git', 'rev-parse', '--short', 'HEAD', check: false).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.project_build_root() / 'meson-dist' / meson.project_name() + '-' + version, + meson.project_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', check: false) +endif + +subdir('data') +subdir('po') +subdir('src') + +gnome.post_install( + gtk_update_icon_cache: true, + glib_compile_schemas: true, + update_desktop_database: true, +) diff --git a/origami-demo/meson_options.txt b/origami-demo/meson_options.txt new file mode 100644 index 0000000..bde6282 --- /dev/null +++ b/origami-demo/meson_options.txt @@ -0,0 +1,10 @@ +option( + 'profile', + type: 'combo', + choices: [ + 'default', + 'development' + ], + value: 'default', + description: 'The build profile for Origami Demo. One of "default" or "development".' +) diff --git a/origami-demo/po/LINGUAS b/origami-demo/po/LINGUAS new file mode 100644 index 0000000..e69de29 diff --git a/origami-demo/po/POTFILES.in b/origami-demo/po/POTFILES.in new file mode 100644 index 0000000..d0e616f --- /dev/null +++ b/origami-demo/po/POTFILES.in @@ -0,0 +1,6 @@ +data/com.github.paper_plane_developers.OrigamiDemo.desktop.in.in +data/com.github.paper_plane_developers.OrigamiDemo.gschema.xml.in +data/com.github.paper_plane_developers.OrigamiDemo.metainfo.xml.in.in +data/resources/ui/shortcuts.ui +data/resources/ui/window.ui +src/application.rs diff --git a/origami-demo/po/meson.build b/origami-demo/po/meson.build new file mode 100644 index 0000000..57d1266 --- /dev/null +++ b/origami-demo/po/meson.build @@ -0,0 +1 @@ +i18n.gettext(gettext_package, preset: 'glib') diff --git a/origami-demo/src/application.rs b/origami-demo/src/application.rs new file mode 100644 index 0000000..6928cad --- /dev/null +++ b/origami-demo/src/application.rs @@ -0,0 +1,149 @@ +use gettextrs::gettext; +use tracing::{debug, info}; + +use gtk::prelude::*; +use gtk::subclass::prelude::*; +use gtk::{gdk, gio, glib}; + +use crate::config::{APP_ID, PKGDATADIR, PROFILE, VERSION}; +use crate::window::SpoilerWindow; + +mod imp { + use super::*; + use glib::WeakRef; + use std::cell::OnceCell; + + #[derive(Debug, Default)] + pub struct ExampleApplication { + pub window: OnceCell>, + } + + #[glib::object_subclass] + impl ObjectSubclass for ExampleApplication { + const NAME: &'static str = "ExampleApplication"; + type Type = super::ExampleApplication; + type ParentType = gtk::Application; + } + + impl ObjectImpl for ExampleApplication {} + + impl ApplicationImpl for ExampleApplication { + fn activate(&self) { + debug!("GtkApplication::activate"); + self.parent_activate(); + let app = self.obj(); + + if let Some(window) = self.window.get() { + let window = window.upgrade().unwrap(); + window.present(); + return; + } + + let window = SpoilerWindow::new(&*app, None); + self.window + .set(window.downgrade()) + .expect("Window already set."); + + app.main_window().present(); + } + + fn startup(&self) { + debug!("GtkApplication::startup"); + self.parent_startup(); + let app = self.obj(); + + // Set icons for shell + gtk::Window::set_default_icon_name(APP_ID); + + app.setup_css(); + app.setup_gactions(); + app.setup_accels(); + } + } + + impl GtkApplicationImpl for ExampleApplication {} +} + +glib::wrapper! { + pub struct ExampleApplication(ObjectSubclass) + @extends gio::Application, gtk::Application, + @implements gio::ActionMap, gio::ActionGroup; +} + +impl ExampleApplication { + fn main_window(&self) -> SpoilerWindow { + self.imp().window.get().unwrap().upgrade().unwrap() + } + + fn setup_gactions(&self) { + // Quit + let action_quit = gio::ActionEntry::builder("quit") + .activate(move |app: &Self, _, _| { + // This is needed to trigger the delete event and saving the window state + app.main_window().close(); + app.quit(); + }) + .build(); + + // About + let action_about = gio::ActionEntry::builder("about") + .activate(|app: &Self, _, _| { + app.show_about_dialog(); + }) + .build(); + self.add_action_entries([action_quit, action_about]); + } + + // Sets up keyboard shortcuts + fn setup_accels(&self) { + self.set_accels_for_action("app.quit", &["q"]); + self.set_accels_for_action("window.close", &["w"]); + } + + fn setup_css(&self) { + let provider = gtk::CssProvider::new(); + provider.load_from_resource("/com/github/paper_plane_developers/OrigamiDemo/style.css"); + if let Some(display) = gdk::Display::default() { + gtk::style_context_add_provider_for_display( + &display, + &provider, + gtk::STYLE_PROVIDER_PRIORITY_APPLICATION, + ); + } + } + + fn show_about_dialog(&self) { + let dialog = gtk::AboutDialog::builder() + .logo_icon_name(APP_ID) + // Insert your license of choice here + // .license_type(gtk::License::MitX11) + // Insert your website here + // .website("https://gitlab.gnome.org/bilelmoussaoui/origami-demo/") + .version(VERSION) + .transient_for(&self.main_window()) + .translator_credits(gettext("translator-credits")) + .modal(true) + .authors(vec!["Paper Plane Developers"]) + .artists(vec!["Paper Plane Developers"]) + .build(); + + dialog.present(); + } + + pub fn run(&self) -> glib::ExitCode { + info!("Origami Demo ({})", APP_ID); + info!("Version: {} ({})", VERSION, PROFILE); + info!("Datadir: {}", PKGDATADIR); + + ApplicationExtManual::run(self) + } +} + +impl Default for ExampleApplication { + fn default() -> Self { + glib::Object::builder() + .property("application-id", APP_ID) + .property("resource-base-path", "/com/github/paper_plane_developers/OrigamiDemo/") + .build() + } +} diff --git a/origami-demo/src/config.rs.in b/origami-demo/src/config.rs.in new file mode 100644 index 0000000..699897f --- /dev/null +++ b/origami-demo/src/config.rs.in @@ -0,0 +1,7 @@ +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/origami-demo/src/main.rs b/origami-demo/src/main.rs new file mode 100644 index 0000000..071e72c --- /dev/null +++ b/origami-demo/src/main.rs @@ -0,0 +1,35 @@ +mod config { + #![allow(dead_code)] + + include!(concat!(env!("CODEGEN_BUILD_DIR"), "/config.rs")); +} + +mod application; +mod window; + +use gettextrs::{gettext, LocaleCategory}; +use gtk::{gio, glib}; + +use self::application::ExampleApplication; +use self::config::{GETTEXT_PACKAGE, LOCALEDIR, RESOURCES_FILE}; + +fn main() -> glib::ExitCode { + adw::init().unwrap(); + ori::init(); + + // Initialize logger + tracing_subscriber::fmt::init(); + + // Prepare i18n + gettextrs::setlocale(LocaleCategory::LcAll, ""); + gettextrs::bindtextdomain(GETTEXT_PACKAGE, LOCALEDIR).expect("Unable to bind the text domain"); + gettextrs::textdomain(GETTEXT_PACKAGE).expect("Unable to switch to the text domain"); + + glib::set_application_name(&gettext("Origami Demo")); + + let res = gio::Resource::load(RESOURCES_FILE).expect("Could not load gresource file"); + gio::resources_register(&res); + + let app = ExampleApplication::default(); + app.run() +} diff --git a/origami-demo/src/meson.build b/origami-demo/src/meson.build new file mode 100644 index 0000000..75c7a75 --- /dev/null +++ b/origami-demo/src/meson.build @@ -0,0 +1,48 @@ +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 +) + +cargo_options = [ '--manifest-path', meson.project_source_root() / 'Cargo.toml' ] +cargo_options += [ '--target-dir', meson.project_build_root() / 'src' ] + +if get_option('profile') == 'default' + cargo_options += [ '--release' ] + rust_target = 'release' + message('Building in release mode') +else + rust_target = 'debug' + message('Building in debug mode') +endif + +cargo_env = [ + 'CARGO_HOME=' + meson.project_build_root() / 'cargo-home', + 'CODEGEN_BUILD_DIR=' + meson.current_build_dir() +] + +cargo_build = custom_target( + 'cargo-build', + build_by_default: true, + build_always_stale: true, + output: meson.project_name(), + console: true, + install: true, + install_dir: bindir, + depends: resources, + command: [ + 'env', + cargo_env, + cargo, 'build', + cargo_options, + '&&', + 'cp', 'src' / rust_target / meson.project_name(), '@OUTPUT@', + ] +) diff --git a/demo/src/window/loading_indicator/loading_indicator.blp b/origami-demo/src/window/loading_indicator/loading_indicator.blp similarity index 100% rename from demo/src/window/loading_indicator/loading_indicator.blp rename to origami-demo/src/window/loading_indicator/loading_indicator.blp diff --git a/demo/src/window/loading_indicator/mod.rs b/origami-demo/src/window/loading_indicator/mod.rs similarity index 100% rename from demo/src/window/loading_indicator/mod.rs rename to origami-demo/src/window/loading_indicator/mod.rs diff --git a/demo/src/window/mod.rs b/origami-demo/src/window/mod.rs similarity index 98% rename from demo/src/window/mod.rs rename to origami-demo/src/window/mod.rs index 3df0835..45c1150 100644 --- a/demo/src/window/mod.rs +++ b/origami-demo/src/window/mod.rs @@ -1,13 +1,13 @@ -mod loading_indicator; -mod shimmer_effect; -mod spoiler; - +use gtk::prelude::StaticType; use adw::prelude::*; use adw::subclass::prelude::*; use gtk::{gio, glib}; -mod imp { +mod loading_indicator; +mod shimmer_effect; +mod spoiler; +mod imp { use super::*; #[derive(Debug, Default, gtk::CompositeTemplate)] @@ -24,11 +24,11 @@ mod imp { type ParentType = adw::ApplicationWindow; fn class_init(klass: &mut Self::Class) { + klass.bind_template(); + + spoiler::SpoilerPage::static_type(); loading_indicator::LoadingIndicatorPage::static_type(); shimmer_effect::ShimmerEffectPage::static_type(); - spoiler::SpoilerPage::static_type(); - - klass.bind_template(); } fn instance_init(obj: &glib::subclass::InitializingObject) { diff --git a/demo/src/window/shimmer_effect/mod.rs b/origami-demo/src/window/shimmer_effect/mod.rs similarity index 100% rename from demo/src/window/shimmer_effect/mod.rs rename to origami-demo/src/window/shimmer_effect/mod.rs diff --git a/demo/src/window/shimmer_effect/shimmer_effect.blp b/origami-demo/src/window/shimmer_effect/shimmer_effect.blp similarity index 100% rename from demo/src/window/shimmer_effect/shimmer_effect.blp rename to origami-demo/src/window/shimmer_effect/shimmer_effect.blp diff --git a/demo/src/window/spoiler/mod.rs b/origami-demo/src/window/spoiler/mod.rs similarity index 100% rename from demo/src/window/spoiler/mod.rs rename to origami-demo/src/window/spoiler/mod.rs diff --git a/demo/src/window/spoiler/spoiler.blp b/origami-demo/src/window/spoiler/spoiler.blp similarity index 90% rename from demo/src/window/spoiler/spoiler.blp rename to origami-demo/src/window/spoiler/spoiler.blp index 53e75e1..043c690 100644 --- a/demo/src/window/spoiler/spoiler.blp +++ b/origami-demo/src/window/spoiler/spoiler.blp @@ -7,7 +7,7 @@ template $OriDemoSpoilerPage : Adw.Bin { actions: copy; formats: "GdkFileList"; } - + orientation: vertical; vexpand: true; @@ -32,14 +32,14 @@ template $OriDemoSpoilerPage : Adw.Bin { vexpand: true; // the most important property - hidden: bind revealer.reveal-child inverted bidirectional; + hidden: bind-property revealer.reveal-child inverted bidirectional; child: Adw.StatusPage { title: "Drop any pictures here"; description: "To see how will they look under the spoiler"; - }; + }; } } } }; -} \ No newline at end of file +} diff --git a/demo/src/window/window.blp b/origami-demo/src/window/window.blp similarity index 100% rename from demo/src/window/window.blp rename to origami-demo/src/window/window.blp