Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .github/workflows/linux-desktop-reliability.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Linux desktop reliability

Check failure on line 1 in .github/workflows/linux-desktop-reliability.yml

View workflow job for this annotation

GitHub Actions / Lint (Biome)

format

File content differs from formatting output

# The built GPUI app on real Linux desktops: Ubuntu 26.04 with GNOME 50 and
# Arch with Hyprland, each with its real portals and tray host, in systemd
Expand Down Expand Up @@ -281,6 +281,19 @@
grep -qx "$line" "$RUNNER_TEMP/out/gnome-screenshot/result.txt"
done

- name: GNOME 50 screenshot from a terminal launch (Cap names itself so.cap.Cap)
env:
DEV_BIN: ${{ github.workspace }}/apps/desktop-gpui/target/debug/cap-gpui
DEV_LIBS: ${{ github.workspace }}/target/native-deps/lib
SCENARIO: screenshot
run: |
sudo -E bash scripts/linux-desktop-harness/run-desktop.sh gnome "$RUNNER_TEMP/cap.deb" \
"$RUNNER_TEMP/out/gnome-screenshot-terminal" LAUNCH=terminal PRELAUNCH=1 GNOME_UNSAFE=1
cat "$RUNNER_TEMP/out/gnome-screenshot-terminal/result.txt" "$RUNNER_TEMP/out/gnome-screenshot-terminal/actions.log"
for line in screenshot_taken=yes screenshot_size=yes capture_failed=0 cap_alive=yes panics=0; do
grep -qx "$line" "$RUNNER_TEMP/out/gnome-screenshot-terminal/result.txt"
done

- name: GNOME 50 area recording (portal stream cropped to the area)
env:
DEV_BIN: ${{ github.workspace }}/apps/desktop-gpui/target/debug/cap-gpui
Expand Down
30 changes: 21 additions & 9 deletions apps/desktop-gpui/src/app_windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1234,7 +1234,7 @@ pub fn open_settings(page: Page, cx: &mut App) {
let handle = cx.open_window(
WindowOptions {
#[cfg(target_os = "linux")]
app_id: Some(crate::app_windows::APP_ID.into()),
app_id: Some(crate::app_windows::app_id().into()),
window_bounds: Some(WindowBounds::Windowed(bounds)),
display_id,
// A real titlebar this time, transparent with the buttons moved
Expand Down Expand Up @@ -1415,7 +1415,7 @@ pub fn open_onboarding(cx: &mut App) {
let handle = cx.open_window(
WindowOptions {
#[cfg(target_os = "linux")]
app_id: Some(crate::app_windows::APP_ID.into()),
app_id: Some(crate::app_windows::app_id().into()),
window_bounds: Some(WindowBounds::Windowed(bounds)),
display_id,
titlebar: None,
Expand Down Expand Up @@ -1568,7 +1568,7 @@ pub fn open_mode_select(cx: &mut App) -> bool {
let handle = cx.open_window(
WindowOptions {
#[cfg(target_os = "linux")]
app_id: Some(crate::app_windows::APP_ID.into()),
app_id: Some(crate::app_windows::app_id().into()),
window_bounds: Some(WindowBounds::Windowed(bounds)),
display_id,
// `traffic_lights_position` has no ModeSelect arm, so it takes the
Expand Down Expand Up @@ -1690,7 +1690,7 @@ pub fn open_teleprompter(cx: &mut App) {
let handle = cx.open_window(
WindowOptions {
#[cfg(target_os = "linux")]
app_id: Some(crate::app_windows::APP_ID.into()),
app_id: Some(crate::app_windows::app_id().into()),
window_bounds: Some(WindowBounds::Windowed(bounds)),
display_id,
// `decorations: true`, `titleBarStyle: "overlay"`, `hiddenTitle:
Expand Down Expand Up @@ -2521,7 +2521,7 @@ fn open_overlay(
let handle = cx.open_window(
WindowOptions {
#[cfg(target_os = "linux")]
app_id: Some(crate::app_windows::APP_ID.into()),
app_id: Some(crate::app_windows::app_id().into()),
// The origin is corrected right after opening -- gpui's own
// window-origin math cannot express "cover this display" (see
// `platform::set_window_frame_cg`). The size is honoured, and it is
Expand Down Expand Up @@ -2975,6 +2975,18 @@ pub fn restore_content_protection(cx: &mut App) {
#[cfg(target_os = "linux")]
pub(crate) const APP_ID: &str = "Cap";

/// The app id Cap's windows carry. GNOME Shell asks the portals' questions
/// (screenshot access) only for the focused app, matched as the window's app
/// id against the id Cap gave the portals, so a launch that named itself
/// `so.cap.Cap` there names its windows the same.
#[cfg(target_os = "linux")]
pub(crate) fn app_id() -> &'static str {
Comment thread
richiemcilroy marked this conversation as resolved.
Resolved
if crate::linux_portal_id::windows_use_portal_app_id() {
return crate::linux_portal_id::PORTAL_APP_ID;
}
APP_ID
}

#[cfg(target_os = "linux")]
fn clean_capture_supported(
mode: RecordingMode,
Expand Down Expand Up @@ -4047,7 +4059,7 @@ pub fn open_camera_window(cx: &mut App) {
..Default::default()
}),
#[cfg(target_os = "linux")]
app_id: Some(crate::app_windows::APP_ID.into()),
app_id: Some(crate::app_windows::app_id().into()),
#[cfg(target_os = "linux")]
window_decorations: Some(gpui::WindowDecorations::Client),
// Non-activating panel, same as the bar: the bubble is clickable
Expand Down Expand Up @@ -4907,7 +4919,7 @@ fn open_editor_window(
let handle = cx.open_window(
WindowOptions {
#[cfg(target_os = "linux")]
app_id: Some(crate::app_windows::APP_ID.into()),
app_id: Some(crate::app_windows::app_id().into()),
window_bounds: Some(WindowBounds::Windowed(bounds)),
display_id,
// Native traffic lights, inset to (20, 32):
Expand Down Expand Up @@ -6709,7 +6721,7 @@ fn open_controls(
let handle = cx.open_window(
WindowOptions {
#[cfg(target_os = "linux")]
app_id: Some(crate::app_windows::APP_ID.into()),
app_id: Some(crate::app_windows::app_id().into()),
window_bounds: Some(WindowBounds::Windowed(bounds)),
display_id,
// No titlebar at all: with one, the panel still draws standard
Expand Down Expand Up @@ -6890,7 +6902,7 @@ pub fn open_screenshot_editor(path: PathBuf, cx: &mut App) {
let handle = cx.open_window(
WindowOptions {
#[cfg(target_os = "linux")]
app_id: Some(crate::app_windows::APP_ID.into()),
app_id: Some(crate::app_windows::app_id().into()),
window_bounds: Some(WindowBounds::Windowed(bounds)),
display_id,
titlebar: Some(gpui::TitlebarOptions {
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop-gpui/src/linux_dialog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ fn open(request: Request, cx: &mut App) {
title: Some(title.into()),
..Default::default()
}),
app_id: Some(crate::app_windows::APP_ID.into()),
app_id: Some(crate::app_windows::app_id().into()),
focus: true,
show: true,
is_resizable: false,
Expand Down
28 changes: 28 additions & 0 deletions apps/desktop-gpui/src/linux_portal_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ use std::{
};

pub const PORTAL_APP_ID: &str = "so.cap.Cap";

static REGISTERED: std::sync::atomic::AtomicBool = std::sync::atomic::AtomicBool::new(false);

/// Whether Cap's windows take [`PORTAL_APP_ID`]: only after this launch
/// registered it, and only on GNOME, the one desktop that matches windows to
/// it. Elsewhere the windows keep their usual id, which window rules may name.
pub fn windows_use_portal_app_id() -> bool {
REGISTERED.load(std::sync::atomic::Ordering::Acquire)
&& is_gnome(&std::env::var("XDG_CURRENT_DESKTOP").unwrap_or_default())
}

fn is_gnome(current_desktop: &str) -> bool {
current_desktop
.split(':')
.any(|desktop| desktop.eq_ignore_ascii_case("gnome"))
}
const PACKAGED_APP_ID: &str = "Cap";

/// The app id xdg-desktop-portal reads from a launcher's systemd unit:
Expand Down Expand Up @@ -172,6 +188,7 @@ pub async fn register() {
.await
{
Ok(Ok(())) => {
REGISTERED.store(true, std::sync::atomic::Ordering::Release);
tracing::info!(
app_id = PORTAL_APP_ID,
attempt,
Expand Down Expand Up @@ -269,6 +286,17 @@ mod tests {
assert!(application_dirs(Some("relative".into()), None, None).is_none());
}

#[test]
fn windows_follow_the_portal_id_only_on_gnome() {
assert!(is_gnome("ubuntu:GNOME"));
assert!(is_gnome("GNOME"));
assert!(is_gnome("GNOME-Classic:GNOME"));
assert!(!is_gnome("KDE"));
assert!(!is_gnome("Hyprland"));
assert!(!is_gnome("niri"));
assert!(!is_gnome(""));
}

#[test]
fn only_a_missing_entry_is_retried() {
assert!(app_info_not_found(
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop-gpui/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ fn main() {
..Default::default()
}),
#[cfg(target_os = "linux")]
app_id: Some(crate::app_windows::APP_ID.into()),
app_id: Some(crate::app_windows::app_id().into()),
#[cfg(target_os = "linux")]
window_min_size: Some(size(px(MAIN_WINDOW_WIDTH), px(MAIN_WINDOW_HEIGHT))),
#[cfg(target_os = "linux")]
Expand Down
2 changes: 1 addition & 1 deletion apps/desktop-gpui/src/permission_guide.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub fn start(permission: OSPermission, cx: &mut App) {
let opened = cx.open_window(
WindowOptions {
#[cfg(target_os = "linux")]
app_id: Some(crate::app_windows::APP_ID.into()),
app_id: Some(crate::app_windows::app_id().into()),
window_bounds: Some(WindowBounds::Windowed(Bounds {
origin: point(px(0.), px(0.)),
size: size(px(PANEL_W), px(PANEL_H)),
Expand Down
2 changes: 2 additions & 0 deletions scripts/linux-desktop-harness/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ screenshot mode does, with Cap focused as after a click, and allows it when
the portal asks (GNOME Shell's question is answered from the Shell, so it needs
`GNOME_UNSAFE=1`; elsewhere the permission is granted up front because the GTK
portal's dialog aborts in the container). It checks a PNG of the display's size (`SCREEN`, 1920x1080) was saved.
`PRELAUNCH=1` runs Cap once before, so a `LAUNCH=terminal` run finds the
`so.cap.Cap.desktop` entry GNOME matches Cap's windows to.
`SCENARIO=wallpaper` records a clip, opens it in the editor and imports the
desktop's wallpaper as its background (`CAP_GPUI_AUTO_DESKTOP_BACKGROUND=1`).
GNOME keeps its default JPEG XL wallpaper; `WALLPAPER=swaybg` starts swaybg
Expand Down
11 changes: 10 additions & 1 deletion scripts/linux-desktop-harness/scenario-screenshot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ if [[ $XDG_CURRENT_DESKTOP != *GNOME* ]]; then
done
fi

# PRELAUNCH=1 runs Cap once first, as on a system Cap has run on: a shell
# launch writes so.cap.Cap.desktop, which GNOME reads a few seconds later.
if [[ ${PRELAUNCH:-} == 1 ]]; then
first=$(bash "$here/launch-cap.sh" first)
sleep 8
kill "$first" 2>/dev/null
sleep 3
fi

# LAUNCH=dock starts Cap in the unit GNOME's app grid gives it, as
# scenario-start-stop.sh does; LAUNCH=terminal from a shell.
if [[ ${LAUNCH:-dock} == dock ]]; then
Expand All @@ -32,7 +41,7 @@ pid=$(bash "$here/launch-cap.sh" cap CAP_GPUI_AUTO_RECORD=screenshot CAP_GPUI_AU
focus_cap() {
if [[ $XDG_CURRENT_DESKTOP == *GNOME* ]]; then
gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell --method org.gnome.Shell.Eval \
"global.display.list_all_windows().filter(w => w.get_wm_class() === 'Cap' && w.showing_on_its_workspace()).forEach(w => w.activate(global.display.get_current_time_roundtrip()))" \
"global.display.list_all_windows().filter(w => /^(Cap|so\.cap\.Cap)$/.test(w.get_wm_class() || '') && w.showing_on_its_workspace()).forEach(w => w.activate(global.display.get_current_time_roundtrip()))" \
>/dev/null 2>&1
elif [[ -n ${HYPRLAND_INSTANCE_SIGNATURE:-} ]]; then
hyprctl dispatch focuswindow class:Cap >/dev/null 2>&1
Expand Down
2 changes: 1 addition & 1 deletion scripts/linux-desktop-harness/scenario-start-stop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ use_control() {
--method org.gnome.Shell.Eval 'Main.overview.hide()' >/dev/null 2>&1
sleep 1
rect=$(gdbus call --session --dest org.gnome.Shell --object-path /org/gnome/Shell \
--method org.gnome.Shell.Eval "(() => { const w = global.display.list_all_windows().find(w => w.get_wm_class() === 'Cap' && w.showing_on_its_workspace() && w.get_frame_rect().width === 320 && w.get_frame_rect().height === 150); if (!w) return ''; const r = w.get_frame_rect(); return [r.x, r.y, r.width, r.height].join(' '); })()" \
--method org.gnome.Shell.Eval "(() => { const w = global.display.list_all_windows().find(w => /^(Cap|so\.cap\.Cap)$/.test(w.get_wm_class() || '') && w.showing_on_its_workspace() && w.get_frame_rect().width === 320 && w.get_frame_rect().height === 150); if (!w) return ''; const r = w.get_frame_rect(); return [r.x, r.y, r.width, r.height].join(' '); })()" \
2>/dev/null | sed -n "s/^(true, '\\(.*\\)')$/\\1/p" | tr -d '"')
echo "controls window: ${rect:-not shown}" >>"$out/actions.log"
result visible_controls_shown "$([[ -n "$rect" ]] && echo yes || echo no)"
Expand Down
Loading