|
1 | 1 | use anyhow::Result; |
2 | 2 | use log::{info, warn}; |
3 | 3 | use smithay_client_toolkit::globals::ProvidesBoundGlobal; |
| 4 | +use std::env; |
4 | 5 |
|
5 | 6 | use super::super::state::{WaylandState, WaylandStateInit}; |
6 | 7 | use super::WaylandBackend; |
7 | 8 | use super::setup::WaylandSetup; |
8 | 9 | use super::tray::process_tray_action; |
| 10 | +use crate::backend::wayland::portal_capture::screenshot_portal_available; |
9 | 11 | use crate::{ |
10 | 12 | capture::CaptureManager, |
11 | 13 | config::Config, |
12 | | - input::{InputState, state::CompositorCapabilities}, |
| 14 | + input::InputState, |
| 15 | + input::state::{CompositorCapabilities, DesktopEnvironment, ShellMode}, |
13 | 16 | onboarding::{DEFERRED_HINT_REPEAT_MAX, OnboardingStore}, |
14 | 17 | }; |
15 | 18 |
|
@@ -43,16 +46,29 @@ pub(super) fn init_state(backend: &WaylandBackend, setup: WaylandSetup) -> Resul |
43 | 46 |
|
44 | 47 | let mut input_state = input_state::build_input_state(&config); |
45 | 48 | input_state.set_session_preflight_options(session_options.clone()); |
| 49 | + let screencopy_supported = setup.screencopy_manager.is_some(); |
| 50 | + let portal_freeze_supported = screenshot_portal_available(&backend.tokio_runtime); |
| 51 | + let frozen_supported = screencopy_supported || portal_freeze_supported; |
| 52 | + let tokio_handle = backend.tokio_runtime.handle().clone(); |
46 | 53 |
|
47 | 54 | // Set compositor capabilities based on detected Wayland protocols |
48 | 55 | input_state.compositor_capabilities = CompositorCapabilities { |
49 | 56 | layer_shell: setup.layer_shell_available, |
50 | | - screencopy: setup.screencopy_manager.is_some(), |
| 57 | + screencopy: screencopy_supported, |
| 58 | + freeze_capture: frozen_supported, |
51 | 59 | pointer_constraints: setup |
52 | 60 | .state_globals |
53 | 61 | .pointer_constraints_state |
54 | 62 | .bound_global() |
55 | 63 | .is_ok(), |
| 64 | + desktop_environment: desktop_environment_from_env(), |
| 65 | + shell_mode: if setup.layer_shell_available { |
| 66 | + ShellMode::LayerShell |
| 67 | + } else if setup.state_globals.xdg_shell.is_some() { |
| 68 | + ShellMode::XdgFallback |
| 69 | + } else { |
| 70 | + ShellMode::Unknown |
| 71 | + }, |
56 | 72 | }; |
57 | 73 |
|
58 | 74 | let mut onboarding = OnboardingStore::load(); |
@@ -91,11 +107,10 @@ pub(super) fn init_state(backend: &WaylandBackend, setup: WaylandSetup) -> Resul |
91 | 107 | let capture_manager = CaptureManager::new(backend.tokio_runtime.handle()); |
92 | 108 | info!("Capture manager initialized"); |
93 | 109 |
|
94 | | - let tokio_handle = backend.tokio_runtime.handle().clone(); |
95 | | - |
96 | | - let frozen_supported = setup.layer_shell_available; |
97 | 110 | let freeze_on_start = if backend.freeze_on_start && !frozen_supported { |
98 | | - warn!("Frozen mode is not supported on GNOME xdg fallback; ignoring --freeze"); |
| 111 | + warn!( |
| 112 | + "Frozen mode unavailable: no screencopy backend and no screenshot portal backend; ignoring --freeze" |
| 113 | + ); |
99 | 114 | false |
100 | 115 | } else { |
101 | 116 | backend.freeze_on_start |
@@ -144,3 +159,19 @@ fn apply_initial_mode(backend: &WaylandBackend, _config: &Config, input_state: & |
144 | 159 | } |
145 | 160 | } |
146 | 161 | } |
| 162 | + |
| 163 | +fn desktop_environment_from_env() -> DesktopEnvironment { |
| 164 | + let values = [ |
| 165 | + env::var("XDG_CURRENT_DESKTOP").unwrap_or_default(), |
| 166 | + env::var("XDG_SESSION_DESKTOP").unwrap_or_default(), |
| 167 | + env::var("DESKTOP_SESSION").unwrap_or_default(), |
| 168 | + ]; |
| 169 | + if values |
| 170 | + .iter() |
| 171 | + .any(|value| value.to_ascii_uppercase().contains("GNOME")) |
| 172 | + { |
| 173 | + DesktopEnvironment::Gnome |
| 174 | + } else { |
| 175 | + DesktopEnvironment::Unknown |
| 176 | + } |
| 177 | +} |
0 commit comments