| 1 | #[macro_use] |
| 2 | extern crate tracing; |
| 3 | |
| 4 | use std::env; |
| 5 | |
| 6 | use adw::prelude::{AdwApplicationWindowExt, NavigationPageExt}; |
| 7 | use cases::Args; |
| 8 | use gtk::prelude::{ApplicationExt, ApplicationExtManual, BoxExt, GtkWindowExt, WidgetExt}; |
| 9 | use gtk::{gdk, gio, glib}; |
| 10 | use smithay_view::SmithayView; |
| 11 | use tracing_subscriber::EnvFilter; |
| 12 | |
| 13 | use crate::cases::gradient_angle::GradientAngle; |
| 14 | use crate::cases::gradient_area::GradientArea; |
| 15 | use crate::cases::gradient_oklab::GradientOklab; |
| 16 | use crate::cases::gradient_oklab_alpha::GradientOklabAlpha; |
| 17 | use crate::cases::gradient_oklch_alpha::GradientOklchAlpha; |
| 18 | use crate::cases::gradient_oklch_decreasing::GradientOklchDecreasing; |
| 19 | use crate::cases::gradient_oklch_increasing::GradientOklchIncreasing; |
| 20 | use crate::cases::gradient_oklch_longer::GradientOklchLonger; |
| 21 | use crate::cases::gradient_oklch_shorter::GradientOklchShorter; |
| 22 | use crate::cases::gradient_srgb::GradientSrgb; |
| 23 | use crate::cases::gradient_srgb_alpha::GradientSrgbAlpha; |
| 24 | use crate::cases::gradient_srgblinear::GradientSrgbLinear; |
| 25 | use crate::cases::gradient_srgblinear_alpha::GradientSrgbLinearAlpha; |
| 26 | use crate::cases::layout::Layout; |
| 27 | use crate::cases::tile::Tile; |
| 28 | use crate::cases::window::Window; |
| 29 | use crate::cases::TestCase; |
| 30 | |
| 31 | mod cases; |
| 32 | mod smithay_view; |
| 33 | mod test_window; |
| 34 | |
| 35 | fn main() -> glib::ExitCode { |
| 36 | let directives = |
| 37 | env::var("RUST_LOG").unwrap_or_else(|_| "niri-visual-tests=debug,niri=debug".to_owned()); |
| 38 | let env_filter = EnvFilter::builder().parse_lossy(directives); |
| 39 | tracing_subscriber::fmt() |
| 40 | .compact() |
| 41 | .with_env_filter(env_filter) |
| 42 | .init(); |
| 43 | |
| 44 | let app = adw::Application::new(None::<&str>, gio::ApplicationFlags::NON_UNIQUE); |
| 45 | app.connect_startup(on_startup); |
| 46 | app.connect_activate(build_ui); |
| 47 | app.run() |
| 48 | } |
| 49 | |
| 50 | fn on_startup(_app: &adw::Application) { |
| 51 | |
| 52 | let provider = gtk::CssProvider::new(); |
| 53 | provider.load_from_string(include_str!("../resources/style.css")); |
| 54 | if let Some(display) = gdk::Display::default() { |
| 55 | gtk::style_context_add_provider_for_display( |
| 56 | &display, |
| 57 | &provider, |
| 58 | gtk::STYLE_PROVIDER_PRIORITY_APPLICATION, |
| 59 | ); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | fn build_ui(app: &adw::Application) { |
| 64 | let stack = gtk::Stack::new(); |
| 65 | let anim_adjustment = gtk::Adjustment::new(1., 0., 10., 0.1, 0.5, 0.); |
| 66 | |
| 67 | struct S { |
| 68 | stack: gtk::Stack, |
| 69 | anim_adjustment: gtk::Adjustment, |
| 70 | } |
| 71 | |
| 72 | impl S { |
| 73 | fn add<T: TestCase + 'static>(&self, make: impl Fn(Args) -> T + 'static, title: &str) { |
| 74 | let view = SmithayView::new(make, &self.anim_adjustment); |
| 75 | self.stack.add_titled(&view, None, title); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | let s = S { |
| 80 | stack: stack.clone(), |
| 81 | anim_adjustment: anim_adjustment.clone(), |
| 82 | }; |
| 83 | |
| 84 | s.add(Window::freeform, "Freeform Window"); |
| 85 | s.add(Window::fixed_size, "Fixed Size Window"); |
| 86 | s.add( |
| 87 | Window::fixed_size_with_csd_shadow, |
| 88 | "Fixed Size Window - CSD Shadow", |
| 89 | ); |
| 90 | |
| 91 | s.add(Tile::freeform, "Freeform Tile"); |
| 92 | s.add(Tile::fixed_size, "Fixed Size Tile"); |
| 93 | s.add( |
| 94 | Tile::fixed_size_with_csd_shadow, |
| 95 | "Fixed Size Tile - CSD Shadow", |
| 96 | ); |
| 97 | s.add(Tile::freeform_open, "Freeform Tile - Open"); |
| 98 | s.add(Tile::fixed_size_open, "Fixed Size Tile - Open"); |
| 99 | s.add( |
| 100 | Tile::fixed_size_with_csd_shadow_open, |
| 101 | "Fixed Size Tile - CSD Shadow - Open", |
| 102 | ); |
| 103 | |
| 104 | s.add(Layout::open_in_between, "Layout - Open In-Between"); |
| 105 | s.add( |
| 106 | Layout::open_multiple_quickly, |
| 107 | "Layout - Open Multiple Quickly", |
| 108 | ); |
| 109 | s.add( |
| 110 | Layout::open_multiple_quickly_big, |
| 111 | "Layout - Open Multiple Quickly - Big", |
| 112 | ); |
| 113 | s.add(Layout::open_to_the_left, "Layout - Open To The Left"); |
| 114 | s.add( |
| 115 | Layout::open_to_the_left_big, |
| 116 | "Layout - Open To The Left - Big", |
| 117 | ); |
| 118 | |
| 119 | s.add(GradientAngle::new, "Gradient - Angle"); |
| 120 | s.add(GradientArea::new, "Gradient - Area"); |
| 121 | s.add(GradientSrgb::new, "Gradient - Srgb"); |
| 122 | s.add(GradientSrgbLinear::new, "Gradient - SrgbLinear"); |
| 123 | s.add(GradientOklab::new, "Gradient - Oklab"); |
| 124 | s.add(GradientOklchShorter::new, "Gradient - Oklch Shorter"); |
| 125 | s.add(GradientOklchLonger::new, "Gradient - Oklch Longer"); |
| 126 | s.add(GradientOklchIncreasing::new, "Gradient - Oklch Increasing"); |
| 127 | s.add(GradientOklchDecreasing::new, "Gradient - Oklch Decreasing"); |
| 128 | s.add(GradientSrgbAlpha::new, "Gradient - Srgb Alpha"); |
| 129 | s.add(GradientSrgbLinearAlpha::new, "Gradient - SrgbLinear Alpha"); |
| 130 | s.add(GradientOklabAlpha::new, "Gradient - Oklab Alpha"); |
| 131 | s.add(GradientOklchAlpha::new, "Gradient - Oklch Alpha"); |
| 132 | |
| 133 | let content_headerbar = adw::HeaderBar::new(); |
| 134 | |
| 135 | let anim_scale = gtk::Scale::new(gtk::Orientation::Horizontal, Some(&anim_adjustment)); |
| 136 | anim_scale.set_hexpand(true); |
| 137 | |
| 138 | let anim_control_bar = gtk::Box::new(gtk::Orientation::Horizontal, 6); |
| 139 | anim_control_bar.add_css_class("anim-control-bar"); |
| 140 | anim_control_bar.append(>k::Label::new(Some("Slowdown"))); |
| 141 | anim_control_bar.append(&anim_scale); |
| 142 | |
| 143 | let content_view = adw::ToolbarView::new(); |
| 144 | content_view.set_top_bar_style(adw::ToolbarStyle::RaisedBorder); |
| 145 | content_view.set_bottom_bar_style(adw::ToolbarStyle::RaisedBorder); |
| 146 | content_view.add_top_bar(&content_headerbar); |
| 147 | content_view.add_bottom_bar(&anim_control_bar); |
| 148 | content_view.set_content(Some(&stack)); |
| 149 | let content = adw::NavigationPage::new( |
| 150 | &content_view, |
| 151 | stack |
| 152 | .page(&stack.visible_child().unwrap()) |
| 153 | .title() |
| 154 | .as_deref() |
| 155 | .unwrap(), |
| 156 | ); |
| 157 | |
| 158 | let sidebar_header = adw::HeaderBar::new(); |
| 159 | let stack_sidebar = gtk::StackSidebar::new(); |
| 160 | stack_sidebar.set_stack(&stack); |
| 161 | let sidebar_view = adw::ToolbarView::new(); |
| 162 | sidebar_view.add_top_bar(&sidebar_header); |
| 163 | sidebar_view.set_content(Some(&stack_sidebar)); |
| 164 | let sidebar = adw::NavigationPage::new(&sidebar_view, "Tests"); |
| 165 | |
| 166 | let split_view = adw::NavigationSplitView::new(); |
| 167 | split_view.set_content(Some(&content)); |
| 168 | split_view.set_sidebar(Some(&sidebar)); |
| 169 | |
| 170 | stack.connect_visible_child_notify(move |stack| { |
| 171 | content.set_title( |
| 172 | stack |
| 173 | .visible_child() |
| 174 | .and_then(|c| stack.page(&c).title()) |
| 175 | .as_deref() |
| 176 | .unwrap_or_default(), |
| 177 | ) |
| 178 | }); |
| 179 | |
| 180 | let window = adw::ApplicationWindow::new(app); |
| 181 | window.set_title(Some("niri visual tests")); |
| 182 | window.set_content(Some(&split_view)); |
| 183 | window.present(); |
| 184 | } |