Skip to content

Commit

Permalink
Merge pull request #60 from luleyleo/gtk-help-overlay
Browse files Browse the repository at this point in the history
Replace custom shortcuts overlay with GTKs built-in help overlay.
luleyleo authored Jan 25, 2025
2 parents 6f5b75d + fceffcb commit 28b7485
Showing 15 changed files with 74 additions and 75 deletions.
17 changes: 0 additions & 17 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,22 +1,5 @@
.cargo/
*.pdb
**/*.rs.bk
debug/
target/
vendor/
vendor.tar
debian/*
!debian/changelog
!debian/control
!debian/copyright
!debian/install
!debian/rules
!debian/source

build/
repo/
flatpak/
flatpak-build/
.flatpak-builder/

assets/locale/
1 change: 1 addition & 0 deletions .lazy.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vim.env.APP_ID = "de.leopoldluley.Clapgrep.Devel"
vim.env.GRESOURCES_BUNDLE = vim.fn.getcwd() .. "/build/resources/resources.gresource"

return {}
25 changes: 12 additions & 13 deletions assets/meson.build
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
install_data(
'icons'/ 'hicolor' / 'scalable' / 'apps' / '@[email protected]'.format(application_id),
install_dir: iconsdir / 'hicolor' / 'scalable' / 'apps'
'icons' / 'hicolor' / 'scalable' / 'apps' / '@[email protected]'.format(application_id),
install_dir: iconsdir / 'hicolor' / 'scalable' / 'apps',
)

subdir('resources')

# Desktop file
desktop_conf = configuration_data()
desktop_conf.set('icon', application_id)
@@ -11,22 +13,20 @@ desktop_file = i18n.merge_file(
input: configure_file(
input: '@[email protected]'.format(base_id),
output: '@BASENAME@',
configuration: desktop_conf
configuration: desktop_conf,
),
output: '@[email protected]'.format(application_id),
po_dir: podir,
install: true,
install_dir: datadir / 'applications'
install_dir: datadir / 'applications',
)

# Validate Desktop file
if desktop_file_validate.found()
test(
'validate-desktop',
desktop_file_validate,
args: [
desktop_file.full_path()
],
args: [desktop_file.full_path()],
depends: desktop_file,
)
endif
@@ -39,21 +39,20 @@ appdata_file = i18n.merge_file(
input: configure_file(
input: '@[email protected]'.format(base_id),
output: '@BASENAME@',
configuration: appdata_conf
configuration: appdata_conf,
),
output: '@[email protected]'.format(application_id),
po_dir: podir,
install: true,
install_dir: datadir / 'metainfo'
install_dir: datadir / 'metainfo',
)

# Validate Appdata
if appstream_util.found()
test(
'validate-appdata', appstream_util,
args: [
'validate', '--nonet', appdata_file.full_path()
],
'validate-appdata',
appstream_util,
args: ['validate', '--nonet', appdata_file.full_path()],
depends: appdata_file,
)
endif
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Gtk 4.0;

ShortcutsWindow help-overlay {
ShortcutsWindow help_overlay {
modal: true;
title: _("Clapgrep Shortcuts");

@@ -10,13 +10,11 @@ ShortcutsWindow help-overlay {

ShortcutsShortcut {
title: _("Quit");
accelerator: "<ctrl>q";
action-name: "app.quit";
}

ShortcutsShortcut {
title: _("Shortcuts");
accelerator: "<ctrl>h";
action-name: "app.shortcuts";
}
}
@@ -26,13 +24,11 @@ ShortcutsWindow help-overlay {

ShortcutsShortcut {
title: _("Start Search");
accelerator: "<ctrl>Return";
action-name: "win.start-search";
}

ShortcutsShortcut {
title: _("Stop Search");
accelerator: "<ctrl>s";
action-name: "win.stop-search";
}
}
19 changes: 19 additions & 0 deletions assets/resources/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
help_overlay = custom_target(
'help-overlay',
input: ['help-overlay.blp'],
output: ['help-overlay.ui'],
command: [
blueprint_compiler,
'compile',
'--output', 'assets/resources/help-overlay.ui',
'@INPUT@',
],
)

clapgrep_resources = gnome.compile_resources(
'resources',
'resources.xml',
gresource_bundle: true,
source_dir: meson.current_build_dir(),
dependencies: [help_overlay],
)[0]
6 changes: 6 additions & 0 deletions assets/resources/resources.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<gresources>
<gresource prefix="/de/leopoldluley/Clapgrep/">
<file compressed="true" preprocess="xml-stripblanks" alias="gtk/help-overlay.ui">help-overlay.ui</file>
</gresource>
</gresources>
2 changes: 1 addition & 1 deletion build-aux/fun.sh
Original file line number Diff line number Diff line change
@@ -3,4 +3,4 @@
flatpak-builder --run \
$(dirname $0)/../flatpak \
$(dirname $0)/de.leopoldluley.Clapgrep.Devel.json \
env CARGO_HOME=/run/build/clapgrep/cargo APP_ID=$APP_ID "$@"
env CARGO_HOME=/run/build/clapgrep/cargo "$@"
25 changes: 20 additions & 5 deletions gnome/meson.build
Original file line number Diff line number Diff line change
@@ -3,13 +3,14 @@ if not get_option('extern_cargo_env')
cargo_env.set('CARGO_HOME', meson.project_build_root() / 'cargo-home')
endif
cargo_env.set('APP_ID', application_id)
cargo_env.set('GRESOURCES_BUNDLE', clapgrep_resources.full_path())

cargo_options = []
cargo_options += ['--manifest-path', meson.project_source_root() / 'Cargo.toml']
cargo_options += ['--target-dir', meson.project_build_root()]

if get_option('profile') == 'default'
cargo_options += [ '--release' ]
cargo_options += ['--release']
rust_target = 'release'
message('Building in release mode')
else
@@ -26,18 +27,32 @@ custom_target(
install: true,
install_dir: bindir,
env: cargo_env,
depends: [clapgrep_resources],
command: [
cargo, 'build',
cargo,
'build',
cargo_options,
'&&',
'cp', rust_target / 'clapgrep-gnome', '@OUTPUT@',
]
'cp',
rust_target / 'clapgrep-gnome',
'@OUTPUT@',
],
)

run_target(
'cargo-clippy',
env: cargo_env,
command: [cargo, 'clippy', cargo_options, '--workspace']
depends: [clapgrep_resources],
command: [
cargo,
'clippy',
cargo_options,
'--workspace',
'--all-targets',
'--all-features',
'--',
'-D', 'warnings',
],
)

test(
12 changes: 1 addition & 11 deletions gnome/src/app.rs
Original file line number Diff line number Diff line change
@@ -36,16 +36,6 @@ pub fn start(app: &adw::Application, files: &[gio::File]) {
));
app.add_action(&about_action);

let shortcuts_action = SimpleAction::new("shortcuts", None);
shortcuts_action.connect_activate(clone!(
#[weak]
window,
move |_, _| {
ui::show_shortcuts(&window);
}
));
app.add_action(&shortcuts_action);

let quit_action = SimpleAction::new("quit", None);
quit_action.connect_activate(clone!(
#[weak]
@@ -59,7 +49,7 @@ pub fn start(app: &adw::Application, files: &[gio::File]) {
app.set_accels_for_action("app.quit", &["<ctrl>q"]);
app.set_accels_for_action("app.shortcuts", &["<ctrl>h"]);
app.set_accels_for_action("win.start-search", &["<ctrl>Return"]);
app.set_accels_for_action("app.stop-search", &["<ctrl>s"]);
app.set_accels_for_action("win.stop-search", &["<ctrl>c"]);

window.present();
}
10 changes: 9 additions & 1 deletion gnome/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use adw::prelude::*;
use gtk::gio::ApplicationFlags;
use gtk::{
gio::{self, ApplicationFlags},
glib,
};

mod app;
mod config;
@@ -16,6 +19,11 @@ fn main() {
let _ = adw::init();
sourceview5::init();

let resource_bytes = include_bytes!(env!("GRESOURCES_BUNDLE"));
gio::resources_register(
&gio::Resource::from_data(&glib::Bytes::from_static(resource_bytes)).unwrap(),
);

let application = adw::Application::builder()
.application_id(APP_ID)
.flags(ApplicationFlags::HANDLES_OPEN)
3 changes: 0 additions & 3 deletions gnome/src/ui/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
mod about;
pub use about::about_dialog;

mod shortcuts;
pub use shortcuts::show_shortcuts;

mod error_window;
pub use error_window::ErrorWindow;

2 changes: 1 addition & 1 deletion gnome/src/ui/search_window/search_window.blp
Original file line number Diff line number Diff line change
@@ -282,7 +282,7 @@ menu menu_app {
section {
item {
label: _("Keyboard Shortcuts");
action: "app.shortcuts";
action: "win.show-help-overlay";
}

item {
15 changes: 0 additions & 15 deletions gnome/src/ui/shortcuts/mod.rs

This file was deleted.

5 changes: 2 additions & 3 deletions justfile
Original file line number Diff line number Diff line change
@@ -29,10 +29,9 @@ ci: setup-flatpak-repos
flatpak-builder --keep-build-dirs --install-deps-from=flathub --user --build-only --ccache --force-clean flatpak build-aux/{{appid}}.json
echo Check formatting:
./build-aux/fun.sh cargo fmt --all -- --check --verbose
echo Check code:
./build-aux/fun.sh cargo check
echo Check code with Clippy:
./build-aux/fun.sh cargo clippy --workspace --all-targets --all-features -- -D warnings
./build-aux/fun.sh meson setup -Dprofile=development /run/build/clapgrep/build-ci
./build-aux/fun.sh meson compile -C /run/build/clapgrep/build-ci cargo-clippy

install-flatpak: setup-flatpak-repos
flatpak-builder flatpak-build build-aux/{{appid}}.json --force-clean --install --install-deps-from=flathub --user
1 change: 1 addition & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ dependency('gtk4', version: '>= 4.0.0')
desktop_file_validate = find_program('desktop-file-validate', required: false)
appstream_util = find_program('appstream-util', required: false)
cargo = find_program('cargo', required: true)
blueprint_compiler = find_program('blueprint-compiler', version: '>= 0.14.0', required: true)

version = meson.project_version()

0 comments on commit 28b7485

Please sign in to comment.