diff --git a/linux/ARCHITECTURE.md b/linux/ARCHITECTURE.md index e687edd48e..510d4cda8e 100644 --- a/linux/ARCHITECTURE.md +++ b/linux/ARCHITECTURE.md @@ -87,7 +87,7 @@ Each window is a `SessionWindow` (`crates/app/src/ui/session_window/`) for its c - When a run, a save or an export ends in a tab the user is not looking at, the window's `WorkNotifier` sends a desktop notification through `GApplication`: one per tab, with no time threshold, as GNOME Console does. A tab counts as looked at while the window is active and the tab is in front. The notification names the tab and the connection only, since it can show on the lock screen, so an editor tab goes by its number rather than its script. Clicking it runs `app.focus-tab`, which brings the tab forward in its window. It is withdrawn once the tab is in front of an active window, when the tab closes, and when the session goes. A save that settles while a close prompt covering its tab decides is not notified: the prompt waited for it in front of the user, and then closes the tab or asks about it again. - The window's content is the page itself, never a wrapper, and is at least 360 by 294 pixels. Each page has its own header bars and its own `AdwToastOverlay`, and the window's toasts go to the page on screen. The menus come from `data/resources/gtk/menus.ui`, which `GtkApplication` loads at startup. Main Menu above the sidebar holds app and connection-library commands. Session Menu in the content header holds commands for the session in front, including Safe Mode. -The `WorkspaceShell` (`crates/app/src/ui/workspace/workspace_shell.rs`) is what a window has once: the connection tree in the sidebar, the one tab view every session's tabs share, the header bars, the assistant's column and the toasts. Its `front` property is the session of the tab in front, or with no tab the newest session or the one last shown, and the session in front speaks for the window: the header bars, the window title, its banners, its assistant pane and the window's actions read it through bindings. The `Workspace` (`crates/app/src/ui/workspace/`) is one session: its sidebar model, which the tree shows as one list per schema and a search as one flat list of what it found, its tabs, its banners and its assistant pane, and the `title`, `subtitle`, `window-title` and `icon-name` properties the shell binds. The shell's template puts the `AdwTabOverview` at the root, as libadwaita expects, around an `AdwBreakpointBin` with an `AdwOverlaySplitView`: the sidebar and the tabs each have their own header bar. Below 600sp the sidebar collapses into an overlay, and below 450sp an `AdwTabButton` takes the tab bar's place. The `show-sidebar` window action and F9 show and hide the sidebar. Below the tree, a bar holds the Add menu the session in front builds from what its engine makes and whether it may write; the Favorites scope hides it. The shell adds the window's workspace actions once, each sent to the session in front, and removes them when it shuts down. A workspace follows its session's health and object list through `WatchForwarder`s and tells the window what it holds through its `dirty-changed`, `saves-in-flight-changed`, `work-completed` and `tabs-changed` signals. Its `WorkspaceHandle` runs the saves and tells the close prompts what closing any part of it would lose. Its `ExportLedger` writes exports off the GTK thread: the rows are encoded on the runtime and GIO writes them. An export takes the rows a grid holds, or every row of a table or an editor statement, streamed through `Connection::stream_read` on a read-only connection of its own with no deadline. `ReplaceFileWriter` removes a file the export made when it stops or fails. An existing regular file gets a temporary file beside it, renamed over it at the end, so a stopped export leaves it as it was. GLib truncates a symbolic link's target, a hard-linked file or a file in a folder that refuses the temporary file when the export opens it, and a stopped export then says that file is incomplete. [Workspace tab system](#workspace-tab-system) covers its tabs, and `../core/ARCHITECTURE.md`, Sessions and health, the `Session` itself. +The `WorkspaceShell` (`crates/app/src/ui/workspace/workspace_shell.rs`) is what a window has once: the connection tree in the sidebar, the one tab view every session's tabs share, the header bars, the assistant's column and the toasts. Its `front` property is the session of the tab in front, or with no tab the newest session or the one last shown, and the session in front speaks for the window: the header bars, the window title, its banners, its assistant pane and the window's actions read it through bindings. The `Workspace` (`crates/app/src/ui/workspace/`) is one session: its sidebar model, which the tree shows as one list per schema and a search as one flat list of what it found, its tabs, its banners and its assistant pane, and the `title`, `subtitle`, `window-title` and `icon-name` properties the shell binds. The shell's template puts the `AdwTabOverview` at the root, as libadwaita expects, around an `AdwBreakpointBin` with an `AdwOverlaySplitView`: the sidebar and the tabs each have their own header bar. Below 600sp the sidebar collapses into an overlay, and below 450sp an `AdwTabButton` takes the tab bar's place. The `show-sidebar` window action and F9 show and hide the sidebar. Below the tree, a bar holds the Add menu the session in front builds from what its engine makes and whether it may write; the Favorites scope hides it. A handle on the sidebar's edge sets the most it takes ([toolkit-workarounds.md](docs/toolkit-workarounds.md#a-sidebar-the-user-can-widen)). The shell adds the window's workspace actions once, each sent to the session in front, and removes them when it shuts down. A workspace follows its session's health and object list through `WatchForwarder`s and tells the window what it holds through its `dirty-changed`, `saves-in-flight-changed`, `work-completed` and `tabs-changed` signals. Its `WorkspaceHandle` runs the saves and tells the close prompts what closing any part of it would lose. Its `ExportLedger` writes exports off the GTK thread: the rows are encoded on the runtime and GIO writes them. An export takes the rows a grid holds, or every row of a table or an editor statement, streamed through `Connection::stream_read` on a read-only connection of its own with no deadline. `ReplaceFileWriter` removes a file the export made when it stops or fails. An existing regular file gets a temporary file beside it, renamed over it at the end, so a stopped export leaves it as it was. GLib truncates a symbolic link's target, a hard-linked file or a file in a folder that refuses the temporary file when the export opens it, and a stopped export then says that file is incomplete. [Workspace tab system](#workspace-tab-system) covers its tabs, and `../core/ARCHITECTURE.md`, Sessions and health, the `Session` itself. ## UI architecture diff --git a/linux/changelog.d/4155.added.md b/linux/changelog.d/4155.added.md new file mode 100644 index 0000000000..c3b5c02fee --- /dev/null +++ b/linux/changelog.d/4155.added.md @@ -0,0 +1 @@ +The sidebar can be widened by dragging its edge or with the arrow keys, and every window keeps that width. diff --git a/linux/crates/app/src/ui/workspace/mod.rs b/linux/crates/app/src/ui/workspace/mod.rs index 98dc26594a..19eecb0954 100644 --- a/linux/crates/app/src/ui/workspace/mod.rs +++ b/linux/crates/app/src/ui/workspace/mod.rs @@ -26,6 +26,7 @@ mod schema_chooser; mod schema_filter; mod session_watches; mod sidebar; +mod sidebar_width; mod status_pages; mod structure; mod structure_target; diff --git a/linux/crates/app/src/ui/workspace/sidebar_width.rs b/linux/crates/app/src/ui/workspace/sidebar_width.rs new file mode 100644 index 0000000000..b89fcb8575 --- /dev/null +++ b/linux/crates/app/src/ui/workspace/sidebar_width.rs @@ -0,0 +1,124 @@ +use gtk4 as gtk; +use gtk4::prelude::*; +use gtk4::{gdk, gio, glib, graphene}; +use libadwaita as adw; +use tablepro_linux_platform::settings::keys::SIDEBAR_WIDTH; + +// The schema's range, which refuses a write outside it. +const NARROWEST: f64 = 220.0; +const WIDEST: f64 = 1200.0; +const STEP: f64 = 16.0; + +// The setting is the most the sidebar takes, which the split view's fraction +// lowers in a narrow window, so every window reads it and a drag writes it +// once it ends. +pub(super) fn follow(split: &adw::OverlaySplitView, handle: >k::Box, settings: &gio::Settings) { + settings.bind(SIDEBAR_WIDTH, split, "max-sidebar-width").get().build(); + // Collapsed, the sidebar lies over the content at its widest. + handle.set_visible(!split.is_collapsed()); + split.connect_collapsed_notify(glib::clone!( + #[weak] + handle, + move |split| handle.set_visible(!split.is_collapsed()) + )); + + let drag = gtk::GestureDrag::new(); + drag.connect_drag_update(glib::clone!( + #[weak] + split, + #[weak] + handle, + move |drag, _, _| { + if let Some(width) = pointer_width(&split, &handle, drag) { + split.set_max_sidebar_width(width.clamp(NARROWEST, WIDEST)); + } + } + )); + drag.connect_drag_end(glib::clone!( + #[weak] + split, + #[strong] + settings, + move |_, _, _| keep(&settings, split.max_sidebar_width()) + )); + handle.add_controller(drag); + + let keys = gtk::EventControllerKey::new(); + keys.connect_key_pressed(glib::clone!( + #[weak] + split, + #[strong] + settings, + #[upgrade_or] + glib::Propagation::Proceed, + move |_, key, _, _| match step(key, split.direction() == gtk::TextDirection::Rtl) { + Some(step) => { + keep(&settings, stepped(shown_width(&split), split.max_sidebar_width(), step)); + glib::Propagation::Stop + } + None => glib::Propagation::Proceed, + } + )); + handle.add_controller(keys); +} + +// Towards the content widens the sidebar, whichever side it is on. +fn step(key: gdk::Key, rtl: bool) -> Option { + match (key, rtl) { + (gdk::Key::Right, false) | (gdk::Key::Left, true) => Some(STEP), + (gdk::Key::Left, false) | (gdk::Key::Right, true) => Some(-STEP), + _ => None, + } +} + +// A window under twice the width kept shows the sidebar at half its width, which +// a wider window still gives it, so widening there keeps that width. +fn stepped(shown: f64, kept: f64, step: f64) -> f64 { + let width = shown + step; + if step > 0.0 { width.max(kept) } else { width } +} + +fn keep(settings: &gio::Settings, width: f64) { + if let Err(error) = settings.set_double(SIDEBAR_WIDTH, width.round().clamp(NARROWEST, WIDEST)) { + tracing::warn!(%error, "the sidebar's width was not kept"); + } +} + +fn shown_width(split: &adw::OverlaySplitView) -> f64 { + let pixels = split.sidebar().map_or(0, |sidebar| sidebar.width()); + split + .sidebar_width_unit() + .from_px(f64::from(pixels), Some(&split.settings())) +} + +// Measured in the split view, which stays put while the handle moves with the edge. +fn pointer_width(split: &adw::OverlaySplitView, handle: >k::Box, drag: >k::GestureDrag) -> Option { + // A touch has its own sequence; only a pointer's is none. + let (x, y) = drag.point(drag.current_sequence().as_ref())?; + let point = handle.compute_point(split, &graphene::Point::new(x as f32, y as f32))?; + let pixels = match split.direction() { + gtk::TextDirection::Rtl => f64::from(split.width()) - f64::from(point.x()), + _ => f64::from(point.x()), + }; + Some(split.sidebar_width_unit().from_px(pixels, Some(&split.settings()))) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn the_arrow_towards_the_content_widens_the_sidebar() { + assert_eq!(step(gdk::Key::Right, false), Some(STEP)); + assert_eq!(step(gdk::Key::Left, false), Some(-STEP)); + assert_eq!(step(gdk::Key::Left, true), Some(STEP), "the sidebar is on the right"); + assert_eq!(step(gdk::Key::Up, false), None); + } + + #[test] + fn widening_a_sidebar_the_window_holds_at_half_keeps_the_width_kept() { + assert_eq!(stepped(280.0, 280.0, STEP), 296.0); + assert_eq!(stepped(500.0, 600.0, STEP), 600.0, "the window is 1000 wide"); + assert_eq!(stepped(500.0, 600.0, -STEP), 484.0); + } +} diff --git a/linux/crates/app/src/ui/workspace/tests/shell.rs b/linux/crates/app/src/ui/workspace/tests/shell.rs index 92d0a0085e..a7e724aacb 100644 --- a/linux/crates/app/src/ui/workspace/tests/shell.rs +++ b/linux/crates/app/src/ui/workspace/tests/shell.rs @@ -946,3 +946,26 @@ fn the_schemas_button_chooses_what_the_sidebar_lists_and_keeps_it() { wait_until(WAIT, || !banner.is_revealed()).expect("Show All"); assert!(filters.sidebar_schemas(id, &database).is_empty()); } + +#[gtk4::test] +fn the_sidebar_takes_the_width_kept_in_settings_and_has_a_handle_to_set_it() { + use tablepro_linux_platform::settings::keys::SIDEBAR_WIDTH; + + let test = TestWindow::connected("SidebarWidth"); + let shell = shell_of(&test.workspace()); + let (split, handle) = (shell.imp().split_view.get(), shell.imp().sidebar_handle.get()); + let settings = test.services.settings.gio().clone(); + assert_eq!(split.max_sidebar_width(), 280.0, "the schema's default"); + + settings.set_double(SIDEBAR_WIDTH, 440.0).expect("a width in range"); + wait_until(WAIT, || split.max_sidebar_width() == 440.0).expect("the window follows the setting"); + assert!(settings.set_double(SIDEBAR_WIDTH, 100.0).is_err(), "under the floor"); + + assert!(handle.is_visible() && handle.is_focusable()); + assert_eq!(handle.accessible_role(), gtk::AccessibleRole::Separator); + crate::test_support::assert_labelled(&handle).expect("the handle is named"); + split.set_collapsed(true); + assert!(!handle.is_visible(), "a collapsed sidebar lies over the content"); + split.set_collapsed(false); + assert!(handle.is_visible()); +} diff --git a/linux/crates/app/src/ui/workspace/workspace_shell.rs b/linux/crates/app/src/ui/workspace/workspace_shell.rs index 1122d2022a..def3ec0b5c 100644 --- a/linux/crates/app/src/ui/workspace/workspace_shell.rs +++ b/linux/crates/app/src/ui/workspace/workspace_shell.rs @@ -175,6 +175,7 @@ impl WorkspaceShell { &imp.split_view.get(), "show-sidebar", )); + super::sidebar_width::follow(&imp.split_view, &imp.sidebar_handle, services.settings.gio()); window.add_action(&assistant_action(&shell)); imp.walk_hooks.replace(Some(shell.hook_recent_walk(window))); diff --git a/linux/crates/app/src/ui/workspace/workspace_shell_imp.rs b/linux/crates/app/src/ui/workspace/workspace_shell_imp.rs index f8c88f1a72..abfc10506c 100644 --- a/linux/crates/app/src/ui/workspace/workspace_shell_imp.rs +++ b/linux/crates/app/src/ui/workspace/workspace_shell_imp.rs @@ -69,6 +69,8 @@ pub struct WorkspaceShell { #[template_child] pub schema_filter_button: TemplateChild, #[template_child] + pub sidebar_handle: TemplateChild, + #[template_child] pub sidebar_slot: TemplateChild, #[template_child] pub scope_toggle: TemplateChild, diff --git a/linux/crates/platform/src/settings/keys.rs b/linux/crates/platform/src/settings/keys.rs index e4c21ca8a6..36d9b8e7a7 100644 --- a/linux/crates/platform/src/settings/keys.rs +++ b/linux/crates/platform/src/settings/keys.rs @@ -1,3 +1,4 @@ +pub const SIDEBAR_WIDTH: &str = "sidebar-width"; pub const DEFAULT_PAGE_SIZE: &str = "default-page-size"; pub const CONFIRM_BULK_DELETE: &str = "confirm-bulk-delete"; pub const SHOW_ALTERNATE_ROWS: &str = "show-alternate-rows"; diff --git a/linux/crates/platform/tests/settings.rs b/linux/crates/platform/tests/settings.rs index 6939de58a3..ad95e06c84 100644 --- a/linux/crates/platform/tests/settings.rs +++ b/linux/crates/platform/tests/settings.rs @@ -62,6 +62,21 @@ async fn defaults_match_schema() -> TestResult { Ok(()) } +#[glib::async_test] +async fn the_sidebar_width_stays_between_its_floor_and_its_cap() -> TestResult { + use gio::prelude::SettingsExt; + + let fixture = Fixture::new()?; + let settings = fixture.settings.gio(); + + assert!((settings.double(keys::SIDEBAR_WIDTH) - 280.0).abs() < f64::EPSILON); + assert!(settings.set_double(keys::SIDEBAR_WIDTH, 219.0).is_err()); + assert!(settings.set_double(keys::SIDEBAR_WIDTH, 1201.0).is_err()); + settings.set_double(keys::SIDEBAR_WIDTH, 440.0)?; + assert!((settings.double(keys::SIDEBAR_WIDTH) - 440.0).abs() < f64::EPSILON); + Ok(()) +} + #[glib::async_test] async fn usage_data_turns_off_and_on_again() -> TestResult { let fixture = Fixture::new()?; diff --git a/linux/data/app.tablepro.TablePro.gschema.xml.in b/linux/data/app.tablepro.TablePro.gschema.xml.in index af9c9f021a..53d0504ee4 100644 --- a/linux/data/app.tablepro.TablePro.gschema.xml.in +++ b/linux/data/app.tablepro.TablePro.gschema.xml.in @@ -52,6 +52,13 @@ Whether the main window was maximized when it last closed. + + 280.0 + + Sidebar width + The most the sidebar takes, in scale-independent pixels; the content always keeps half the window. + + 1000 diff --git a/linux/data/resources/ui/workspace-shell.ui b/linux/data/resources/ui/workspace-shell.ui index 787e883a84..74fcee18d4 100644 --- a/linux/data/resources/ui/workspace-shell.ui +++ b/linux/data/resources/ui/workspace-shell.ui @@ -57,96 +57,121 @@ 220 280 + + 0.5 - - - - - false - - - system-search-symbolic - - - - - view-refresh-symbolic - win.refresh-tables - - - - - - - - - - Search connections and tables… - true - - Search connections and tables - + + + + + end + 4 + true + separator + + + col-resize + + Sidebar Width + - - - tables - true - 12 - 12 - 6 - 6 - - - tables - Tables + + + + + + false + + + system-search-symbolic + + + + + view-refresh-symbolic + win.refresh-tables + + - - - favorites - Favorites + + + + + + Search connections and tables… + true + + Search connections and tables + + + - - - - - - false - false - - - - - false - - - list-add-symbolic - up - false + + + tables + true + 12 + 12 + 6 + 6 + + + tables + Tables + + + + + favorites + Favorites + + - - - - Schemas - true - up - false + + + + false + false - - - - - - true + + + false + + + list-add-symbolic + up + false + + + + + + Schemas + true + up + false + + + + + + + + true + + diff --git a/linux/docs/storage.md b/linux/docs/storage.md index dc4cf8b719..65028590fc 100644 --- a/linux/docs/storage.md +++ b/linux/docs/storage.md @@ -340,6 +340,7 @@ The schema id is the application id and the path follows it: `app.tablepro.Table | `window-width` | `i` | `1200` | 360 to 32767 | | `window-height` | `i` | `760` | 294 to 32767 | | `is-maximized` | `b` | `false` | | +| `sidebar-width` | `d` | `280` | 220 to 1200, in sp: the most the sidebar takes | | `default-page-size` | `u` | `1000` | 100 to 100000 | | `show-alternate-rows` | `b` | `true` | | | `show-row-numbers` | `b` | `true` | | diff --git a/linux/docs/toolkit-workarounds.md b/linux/docs/toolkit-workarounds.md index 2bbbf0685a..2746a62f73 100644 --- a/linux/docs/toolkit-workarounds.md +++ b/linux/docs/toolkit-workarounds.md @@ -10,6 +10,14 @@ The places the app steps around a GTK, libadwaita, GtkSourceView, IBus or gtk-rs - **Test.** `a_tab_dropped_outside_every_window_stays_where_it_was` in `crates/app/src/ui/session_window/tests/sessions.rs`. - **Remove when** the floor's libadwaita offers a way to decline a detach, or tab groups: use it, and drop the position restore for this case. +## A sidebar the user can widen + +- **What libadwaita does.** `AdwOverlaySplitView` sizes its sidebar as a fraction of its own width between `min-sidebar-width` and `max-sidebar-width`, and has no divider to drag. `GtkPaned` has one, but has no collapsed overlay, no breakpoints and no header bar integration. This is the documented design, not a defect. +- **Seen in.** libadwaita 1.9 (the floor) and 1.10. +- **Workaround.** A focusable handle with the separator role lies over the sidebar's trailing edge (`data/resources/ui/workspace-shell.ui`, `crates/app/src/ui/workspace/sidebar_width.rs`). A drag or the arrow keys set `max-sidebar-width` through the `sidebar-width` setting, which every window follows; `sidebar-width-fraction` of 0.5 keeps half the window for the content, and the handle hides while the sidebar is collapsed. The handle covers the edge of the tree's scrollbar. +- **Test.** `the_sidebar_takes_the_width_kept_in_settings_and_has_a_handle_to_set_it` in `crates/app/src/ui/workspace/tests/shell.rs`, `the_sidebar_width_stays_between_its_floor_and_its_cap` in `crates/platform/tests/settings.rs`. +- **Remove when** the floor's libadwaita offers a resizable split view: use it. + ## IBus keeps every text view - **Defect.** From GTK 4.24 a `GtkTextView` or `GtkText` makes itself its input method's client widget at construction and clears it only in its own dispose (GTK commit 3df992599b). ibus-gtk4 holds the client with a strong reference (`ibus_im_context_set_client_widget`), so the view is never disposed, nor anything it holds. [ibus/ibus#2968](https://github.com/ibus/ibus/issues/2968), open. diff --git a/linux/po/POTFILES.in b/linux/po/POTFILES.in index b1c1b1a903..5bfce6ead8 100644 --- a/linux/po/POTFILES.in +++ b/linux/po/POTFILES.in @@ -681,6 +681,7 @@ crates/app/src/ui/workspace/sidebar/tests.rs crates/app/src/ui/workspace/sidebar/tree_menu.rs crates/app/src/ui/workspace/sidebar/tree_node.rs crates/app/src/ui/workspace/sidebar/tree_row.rs +crates/app/src/ui/workspace/sidebar_width.rs crates/app/src/ui/workspace/status_pages.rs crates/app/src/ui/workspace/structure.rs crates/app/src/ui/workspace/structure_target.rs