From 5288e10cab0776686fa25bbeb4adfaf93b734d4f Mon Sep 17 00:00:00 2001 From: MoonlightWave-12 <135532-MoonlightWave-12@users.noreply.gitlab.gnome.org> Date: Fri, 20 Sep 2024 12:06:30 +0200 Subject: [PATCH] scaling: Add GSettings for adjusting the height of the panel Part-of: --- README.md | 14 +++++++ cargo.sh | 3 ++ data/meson.build | 32 ++++++++++++++++ data/sm.puri.Squeekboard.gschema.xml | 32 ++++++++++++++++ debian/squeekboard.install | 1 + meson.build | 5 +++ src/state.rs | 57 ++++++++++++++++++++++++---- 7 files changed, 136 insertions(+), 8 deletions(-) create mode 100644 data/sm.puri.Squeekboard.gschema.xml diff --git a/README.md b/README.md index 2b6e67a7..8c113373 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,7 @@ Running $ cd ../build/ $ src/squeekboard ``` + If no compatible Wayland compositor is running yet, you can use Phoc (after installing it): ```sh @@ -82,6 +83,7 @@ Alternatively, force panel visibility manually with: ```sh $ busctl call --user sm.puri.OSK0 /sm/puri/OSK0 sm.puri.OSK0 SetVisible b true ``` + or by using the environment-variable `SQUEEKBOARD_DEBUG=force_show`. ### What the compositor has to support @@ -95,6 +97,18 @@ It's strongly recommended to support: - input-method-v2 +Settings +-------- + +To see a list of available settings, use the following command: + +```sh +$ gsettings list-keys sm.puri.Squeekboard +``` + +Note: If the keyboard is open when the settings for the panel-height are changed, the height of the keyboard will not change until it is opened again, or the layout is changed. +While using Phosh, one can long-click/long-tap the home-bar at the bottom, to open and close the keyboard. + Developing ---------- diff --git a/cargo.sh b/cargo.sh index c4be97b4..2a4cc881 100755 --- a/cargo.sh +++ b/cargo.sh @@ -12,6 +12,9 @@ SOURCE_DIR="$(dirname "$SCRIPT_PATH")" CARGO_TARGET_DIR="$(pwd)" export CARGO_TARGET_DIR +GSETTINGS_SCHEMA_DIR="${CARGO_TARGET_DIR}/data:${GSETTINGS_SCHEMA_DIR}" +export GSETTINGS_SCHEMA_DIR + cd "$SOURCE_DIR" # the 'run" command takes arguments at the end, diff --git a/data/meson.build b/data/meson.build index d2ec986a..5d0a0879 100644 --- a/data/meson.build +++ b/data/meson.build @@ -1,5 +1,37 @@ gnome = import('gnome') +#workaround due to https://github.com/mesonbuild/meson/issues/1687 +copy_schema = custom_target('copy-gschema-to-builddir', + input: 'sm.puri.Squeekboard.gschema.xml', + output: 'sm.puri.Squeekboard.gschema.xml', + command: ['cp', '@INPUT@', '@OUTPUT@'] +) +schemas = ['sm.puri.Squeekboard.gschema.xml'] +compile_schemas = custom_target('glib-compile-schemas', + build_by_default: true, + output: 'gschemas.compiled', + install: false, + command: [find_program('glib-compile-schemas'), + meson.current_build_dir() + ], + depends: [copy_schema] +) +install_data( + schemas, + install_dir: schemasdir +) + +compile_schemas = find_program('glib-compile-schemas', required: false) +if compile_schemas.found() + test('Validate schema file', compile_schemas, + args: ['--strict', '--dry-run', meson.current_source_dir()]) +endif + +install_data( + schemas, + install_dir: 'share/glib-2.0/schemas' +) + squeekboard_resources = gnome.compile_resources( 'squeekboard-resources', 'squeekboard.gresources.xml', diff --git a/data/sm.puri.Squeekboard.gschema.xml b/data/sm.puri.Squeekboard.gschema.xml new file mode 100644 index 00000000..73f752cd --- /dev/null +++ b/data/sm.puri.Squeekboard.gschema.xml @@ -0,0 +1,32 @@ + + + + + 1.00 + The multiplier for the height of the panel while the screen is in landscape-orientation + + The height of the panel for the layout is multiplied by this value, + while the screen is in landscape-orientation. + Changing this is currently mostly useful for custom layouts, + or to work around scaling-issues, because the layout-aspect-ratio is fixed. + There is an upper limit of 2/3 of the screen. + For square screens, the setting for screens in landscape-orientation is used. + + + + + 1.00 + The multiplier for the height of the panel while the screen is in portrait-orientation + + The height of the panel for the layout is multiplied by this value, + while the screen is in portrait-orientation. + Changing this is currently mostly useful for custom layouts, + or to work around scaling-issues, because the layout-aspect-ratio is fixed. + There is an upper limit of 2/3 of the screen. + For square screens, the setting for screens in landscape-orientation is used. + + + + + diff --git a/debian/squeekboard.install b/debian/squeekboard.install index eeca73ed..569b15a6 100644 --- a/debian/squeekboard.install +++ b/debian/squeekboard.install @@ -1,4 +1,5 @@ tools/squeekboard-restyled usr/bin usr/bin/squeekboard /usr/bin usr/share/applications/*.desktop usr/share/squeekboard/ +usr/share/glib-2.0/schemas/ usr/share/locale/ diff --git a/meson.build b/meson.build index 534428b3..fc187ea8 100644 --- a/meson.build +++ b/meson.build @@ -70,6 +70,7 @@ else depdatadir = get_option('depdatadir') endif dbusdir = join_paths(depdatadir, 'dbus-1/interfaces') +schemasdir = datadir / 'glib-2.0' / 'schemas' conf_data = configuration_data() conf_data.set_quoted('GETTEXT_PACKAGE', 'squeekboard') @@ -111,3 +112,7 @@ subdir('protocols') subdir('src') subdir('tools') subdir('tests') + +gnome.post_install( + glib_compile_schemas: true, +) \ No newline at end of file diff --git a/src/state.rs b/src/state.rs index f78b9861..494f4dbe 100644 --- a/src/state.rs +++ b/src/state.rs @@ -19,6 +19,8 @@ use crate::panel; use crate::panel::PixelSize; use crate::popover; use crate::util::Rational; +use gio::Settings; +use gdk::prelude::SettingsExt; use std::cmp; use std::collections::HashMap; use std::time::Instant; @@ -390,6 +392,10 @@ Outcome: let screen_aspect_ratio = {px_size.height as f64 / px_size.width as f64}; + let gsettings = Settings::new("sm.puri.Squeekboard"); + let scale_setting_horizontal = gsettings.double("scale-in-horizontal-screen-orientation"); + let scale_setting_vertical = gsettings.double("scale-in-vertical-screen-orientation"); + // Reduce height, to match what the layout can fill. // For this, we need to guess if normal or wide will be picked. // This must match `eek_gtk_keyboard.c::get_type`. @@ -417,17 +423,28 @@ Outcome: (layout_aspect_ratio * px_size.width as i32).ceil() as u32, ); - ( - PixelSize { - scale_factor: output.scale as u32, - // Set the height of the panel for the layout. - pixels: if arrangement == ArrangementKind::Base && screen_width < screen_height { + let panel_height = { + if arrangement == ArrangementKind::Base && screen_width < screen_height { cmp::min((px_size.height as f64 / (screen_aspect_ratio / (7.0 / 12.0))) as u32, px_size.height / 2)} else if arrangement == ArrangementKind::Wide && screen_width < screen_height { cmp::min((px_size.height as f64 / (screen_aspect_ratio / (5.0 / 16.0))) as u32, px_size.height / 2)} else if arrangement == ArrangementKind::Wide { cmp::min(cmp::max(px_size.height / 3 as u32, recommended_panel_height), px_size.height / 2)} - else {px_size.height / 2}, + else {px_size.height / 2} + }; + + ( + PixelSize { + scale_factor: output.scale as u32, + // Set the height of the panel for the layout. + pixels: if screen_width < screen_height { + cmp::min((panel_height as f64 * scale_setting_vertical) as u32, + (px_size.height as f64 * (2.0 / 3.0)) as u32) + } + else { + cmp::min((panel_height as f64 * scale_setting_horizontal) as u32, + (px_size.height as f64 * (2.0 / 3.0)) as u32) + }, }, arrangement, ) @@ -737,6 +754,11 @@ pub mod test { // scaling-tests fn scaling_test_base(pixel_width: i32, pixel_height: i32, physical_width: i32, physical_height: i32, scale: i32, expected_pixel_height: u32) { use crate::outputs::{Mode, Geometry, c, Size}; + + let gsettings = Settings::new("sm.puri.Squeekboard"); + let scale_setting_horizontal = gsettings.double("scale-in-horizontal-orientation"); + let scale_setting_vertical = gsettings.double("scale-in-vertical-orientation"); + assert_eq!( Application::get_preferred_height_and_arrangement(&OutputState { current_mode: Some(Mode { @@ -755,7 +777,14 @@ pub mod test { Some(( PixelSize { scale_factor: scale as u32, - pixels: expected_pixel_height, + pixels: if pixel_width < pixel_height { + cmp::min((expected_pixel_height as f64 * scale_setting_vertical) as u32, + (pixel_height as f64 * (2.0 / 3.0)) as u32) + } + else { + cmp::min((expected_pixel_height as f64 * scale_setting_horizontal) as u32, + (pixel_height as f64 * (2.0 / 3.0)) as u32) + }, }, ArrangementKind::Base, )), @@ -764,6 +793,11 @@ pub mod test { fn scaling_test_wide(pixel_width: i32, pixel_height: i32, physical_width: i32, physical_height: i32, scale: i32, expected_pixel_height: u32) { use crate::outputs::{Mode, Geometry, c, Size}; + + let gsettings = Settings::new("sm.puri.Squeekboard"); + let scale_setting_horizontal = gsettings.double("scale-in-horizontal-orientation"); + let scale_setting_vertical = gsettings.double("scale-in-vertical-orientation"); + assert_eq!( Application::get_preferred_height_and_arrangement(&OutputState { current_mode: Some(Mode { @@ -782,7 +816,14 @@ pub mod test { Some(( PixelSize { scale_factor: scale as u32, - pixels: expected_pixel_height, + pixels: if pixel_width < pixel_height { + cmp::min((expected_pixel_height as f64 * scale_setting_vertical) as u32, + (pixel_height as f64 * (2.0 / 3.0)) as u32) + } + else { + cmp::min((expected_pixel_height as f64 * scale_setting_horizontal) as u32, + (pixel_height as f64 * (2.0 / 3.0)) as u32) + }, }, ArrangementKind::Wide, )),