Compare commits
12 commits
da592cc15e
...
495e591dc6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
495e591dc6 | ||
|
|
17cf4485a9 | ||
|
|
673e4c949b | ||
|
|
a77aaa1904 | ||
|
|
56f0115952 | ||
|
|
9a55864e81 | ||
|
|
02a4c58c3d | ||
|
|
af9aaf9c1a | ||
|
|
59b48b5b3b | ||
|
|
618624bcc0 | ||
|
|
a823516ebd | ||
|
|
42752142e3 |
10 changed files with 687 additions and 993 deletions
15
.zed/settings.json
Normal file
15
.zed/settings.json
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
{
|
||||
"format_on_save": "on",
|
||||
"lsp": {
|
||||
"rust-analyzer": {
|
||||
"initialization_options": {
|
||||
"check": {
|
||||
"command": "clippy",
|
||||
},
|
||||
"rustfmt": {
|
||||
"extraArgs": ["+nightly"],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
1461
Cargo.lock
generated
1461
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
17
Cargo.toml
17
Cargo.toml
|
|
@ -4,25 +4,21 @@ description = "The session manager for the COSMIC desktop environment"
|
|||
version = "1.0.0"
|
||||
license = "GPL-3.0-only"
|
||||
edition = "2024"
|
||||
rust-version = "1.85"
|
||||
rust-version = "1.93"
|
||||
authors = ["Lucy <lucy@system76.com>"]
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
async-signals = "0.5"
|
||||
color-eyre = "0.6"
|
||||
futures-util = "0.3"
|
||||
cosmic-dbus-a11y = { git = "https://github.com/pop-os/dbus-settings-bindings" }
|
||||
freedesktop-desktop-entry = { version = "0.7.14", optional = true }
|
||||
shell-words = { version = "1.1.0", optional = true }
|
||||
freedesktop-desktop-entry = { version = "0.8", optional = true }
|
||||
shell-words = { version = "1.1.1", optional = true }
|
||||
dirs = { version = "6.0.0", optional = true }
|
||||
itertools = "0.14"
|
||||
launch-pad = { git = "https://github.com/pop-os/launch-pad" }
|
||||
libc = "0.2"
|
||||
log-panics = { version = "2", features = ["with-backtrace"] }
|
||||
rustix = "1.0"
|
||||
rustix = "1.1"
|
||||
scopeguard = "1"
|
||||
sendfd = { version = "0.4", features = ["tokio"] }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = "1"
|
||||
tokio = { version = "1", features = [
|
||||
|
|
@ -38,15 +34,14 @@ tokio = { version = "1", features = [
|
|||
"sync",
|
||||
"time",
|
||||
] }
|
||||
zbus_systemd = { version = "0.25701.0", optional = true, features = [
|
||||
zbus_systemd = { version = "0.26000.0", optional = true, features = [
|
||||
"systemd1",
|
||||
] }
|
||||
tokio-util = "0.7"
|
||||
tracing = "0.1"
|
||||
tracing-journald = { version = "0.3", optional = true }
|
||||
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
|
||||
zbus = { version = "5.10.0", default-features = false, features = ["tokio"] }
|
||||
cosmic-notifications-util = { git = "https://github.com/pop-os/cosmic-notifications" }
|
||||
zbus = { version = "5.14.0", default-features = false, features = ["tokio"] }
|
||||
logind-zbus = { version = "5.3.2", optional = true }
|
||||
|
||||
[features]
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ if [ -n "${SHELL}" ]; then
|
|||
fi
|
||||
|
||||
export XDG_CURRENT_DESKTOP="${XDG_CURRENT_DESKTOP:=COSMIC}"
|
||||
export XDG_SESSION_DESKTOP="${XDG_SESSION_DESKTOP:=COSMIC}"
|
||||
export XDG_SESSION_TYPE="${XDG_SESSION_TYPE:=wayland}"
|
||||
export _JAVA_AWT_WM_NONREPARENTING=1
|
||||
export GDK_BACKEND=wayland,x11
|
||||
|
|
@ -38,6 +39,22 @@ export QT_AUTO_SCREEN_SCALE_FACTOR=1
|
|||
export QT_ENABLE_HIGHDPI_SCALING=1
|
||||
export DCONF_PROFILE=cosmic
|
||||
|
||||
# Set the QT platform theme to CuteCosmic. Fallback to qt6ct if CuteCosmic is not installed.
|
||||
if [ -z "$QT_QPA_PLATFORMTHEME" ]; then
|
||||
export QT_QPA_PLATFORMTHEME=cosmic
|
||||
for QT_PLUGIN_PATH in /usr/lib{*,/*}/qt6/plugins; do
|
||||
if [ -f "${QT_PLUGIN_PATH}/platformthemes/libcutecosmictheme.so" ]; then
|
||||
# CuteCosmic found, no need for a fallback.
|
||||
export QT_QPA_PLATFORMTHEME=cosmic
|
||||
break
|
||||
elif [ -f "${QT_PLUGIN_PATH}/platformthemes/libqt6ct.so" ] || [ -f "${QT_PLUGIN_PATH}/platformthemes/libqt5ct.so" ]; then
|
||||
# Fallback to qt6ct, but keep looking for CuteCosmic.
|
||||
# Note that "qt5ct" is compatible with both qt5ct and qt6ct.
|
||||
export QT_QPA_PLATFORMTHEME=qt5ct
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
# Start gnome keyring components if the daemon is active
|
||||
# -> check if /run/user/$UID/keyring exists
|
||||
if [ -d "/run/user/$(id -u)/keyring" ]; then
|
||||
|
|
@ -69,16 +86,23 @@ if command -v systemctl >/dev/null; then
|
|||
# environment, update it.
|
||||
mapfile -t existing_env_vars < <(systemctl --user show-environment)
|
||||
for env_var in "${existing_env_vars[@]}"; do
|
||||
env_var_name="$(echo "${env_var}" | awk -F '=' '{print $1}')"
|
||||
env_var_val_str_to_compare="${env_var_name}=${!env_var_name:-}"
|
||||
env_var_name="${env_var%%=*}"
|
||||
env_var_value=${!env_var_name:-}
|
||||
|
||||
if [[ "${env_var}" != "${env_var_val_str_to_compare}" ]]; then
|
||||
# Update only if the value in current environment is non-empty
|
||||
env_var_unassigned_str="${env_var_name}="
|
||||
if [[ "${env_var_val_str_to_compare}" != "${env_var_unassigned_str}" ]]; then
|
||||
systemctl --user import-environment "${env_var_name}" ||:
|
||||
fi
|
||||
# Skip current iteration if the environment variable's value
|
||||
# in the current envionment is unset.
|
||||
if [[ -z "${env_var_value}" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
env_var_val_str_to_compare="${env_var_name}=${env_var_value}"
|
||||
env_var_val_str_to_compare_ansi_c_quoted="${env_var_name}=\$'$(printf '%q' "${env_var_value}")'"
|
||||
if [[ "${env_var}" == "${env_var_val_str_to_compare}" ]]; then
|
||||
continue
|
||||
elif [[ "${env_var}" == "${env_var_val_str_to_compare_ansi_c_quoted}" ]]; then
|
||||
continue
|
||||
fi
|
||||
systemctl --user import-environment "${env_var_name}" ||:
|
||||
done
|
||||
fi
|
||||
|
||||
|
|
|
|||
1
debian/control
vendored
1
debian/control
vendored
|
|
@ -12,6 +12,7 @@ Homepage: https://github.com/pop-os/cosmic-session
|
|||
|
||||
Package: cosmic-session
|
||||
Architecture: amd64 arm64
|
||||
Conflicts: seatd
|
||||
Depends:
|
||||
${misc:Depends},
|
||||
${shlibs:Depends},
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use_field_init_shorthand = true
|
|||
# Unstable formatting options below; remove if you REALLY don't wanna use `cargo +nightly fmt`
|
||||
format_code_in_doc_comments = true
|
||||
format_strings = true
|
||||
imports_granularity = "Crate"
|
||||
imports_granularity = "Module"
|
||||
normalize_comments = true
|
||||
reorder_impl_items = true
|
||||
wrap_comments = true
|
||||
20
src/comp.rs
20
src/comp.rs
|
|
@ -1,17 +1,19 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
use color_eyre::eyre::{Result, WrapErr};
|
||||
use launch_pad::{ProcessManager, process::Process};
|
||||
use launch_pad::ProcessManager;
|
||||
use launch_pad::process::Process;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{collections::HashMap, os::unix::prelude::*};
|
||||
use tokio::{
|
||||
io::AsyncReadExt,
|
||||
net::{UnixStream, unix::OwnedReadHalf},
|
||||
sync::{mpsc, oneshot},
|
||||
task::JoinHandle,
|
||||
};
|
||||
use std::collections::HashMap;
|
||||
use std::os::unix::prelude::*;
|
||||
use tokio::io::AsyncReadExt;
|
||||
use tokio::net::UnixStream;
|
||||
use tokio::net::unix::OwnedReadHalf;
|
||||
use tokio::sync::{mpsc, oneshot};
|
||||
use tokio::task::JoinHandle;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
|
||||
use crate::{process::mark_as_not_cloexec, service::SessionRequest};
|
||||
use crate::process::mark_as_not_cloexec;
|
||||
use crate::service::SessionRequest;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
#[serde(rename_all = "snake_case", tag = "message")]
|
||||
|
|
|
|||
84
src/main.rs
84
src/main.rs
|
|
@ -9,36 +9,36 @@ mod process;
|
|||
mod service;
|
||||
mod systemd;
|
||||
|
||||
use async_signals::Signals;
|
||||
use color_eyre::{Result, eyre::WrapErr};
|
||||
use cosmic_notifications_util::{DAEMON_NOTIFICATIONS_FD, PANEL_NOTIFICATIONS_FD};
|
||||
use futures_util::StreamExt;
|
||||
#[cfg(feature = "autostart")]
|
||||
use itertools::Itertools;
|
||||
use launch_pad::{ProcessManager, process::Process};
|
||||
use color_eyre::Result;
|
||||
use color_eyre::eyre::WrapErr;
|
||||
use launch_pad::ProcessManager;
|
||||
use launch_pad::process::Process;
|
||||
use service::SessionRequest;
|
||||
use std::borrow::Cow;
|
||||
#[cfg(feature = "autostart")]
|
||||
use std::collections::HashSet;
|
||||
use std::env;
|
||||
use std::os::fd::AsRawFd;
|
||||
#[cfg(feature = "autostart")]
|
||||
use std::path::PathBuf;
|
||||
#[cfg(feature = "autostart")]
|
||||
use std::process::{Command, Stdio};
|
||||
use std::{borrow::Cow, env, os::fd::AsRawFd, sync::Arc};
|
||||
use std::sync::Arc;
|
||||
#[cfg(feature = "systemd")]
|
||||
use systemd::{get_systemd_env, is_systemd_used, spawn_scope};
|
||||
use tokio::{
|
||||
sync::{
|
||||
Mutex,
|
||||
mpsc::{Receiver, Sender},
|
||||
oneshot,
|
||||
},
|
||||
time::Duration,
|
||||
};
|
||||
use tokio::signal::unix::{SignalKind, signal};
|
||||
use tokio::sync::mpsc::{Receiver, Sender};
|
||||
use tokio::sync::{Mutex, oneshot};
|
||||
use tokio::time::Duration;
|
||||
use tokio_util::sync::CancellationToken;
|
||||
use tracing::{Instrument, metadata::LevelFilter};
|
||||
use tracing_subscriber::{EnvFilter, fmt, prelude::*};
|
||||
use tracing::Instrument;
|
||||
use tracing::metadata::LevelFilter;
|
||||
use tracing_subscriber::prelude::*;
|
||||
use tracing_subscriber::{EnvFilter, fmt};
|
||||
|
||||
use crate::notifications::notifications_process;
|
||||
use crate::notifications::{
|
||||
DAEMON_NOTIFICATIONS_FD, PANEL_NOTIFICATIONS_FD, notifications_process,
|
||||
};
|
||||
#[cfg(feature = "autostart")]
|
||||
const AUTOSTART_DIR: &'static str = "autostart";
|
||||
#[cfg(feature = "autostart")]
|
||||
|
|
@ -165,7 +165,7 @@ async fn start(
|
|||
Ok(env) => {
|
||||
for systemd_env in env {
|
||||
// Only update the envvar if unset
|
||||
if std::env::var_os(&systemd_env.key) == None {
|
||||
if std::env::var_os(&systemd_env.key).is_none() {
|
||||
// Blacklist of envvars that we shouldn't touch (taken from KDE)
|
||||
if (!systemd_env.key.starts_with("XDG_")
|
||||
|| systemd_env.key == "XDG_DATA_DIRS"
|
||||
|
|
@ -244,10 +244,8 @@ async fn start(
|
|||
.instrument(stderr_span)
|
||||
})
|
||||
.with_on_exit(move |_, _, _, will_restart| {
|
||||
if !will_restart {
|
||||
if let Some(tx) = settings_exit_tx.lock().unwrap().take() {
|
||||
_ = tx.send(());
|
||||
}
|
||||
if !will_restart && let Some(tx) = settings_exit_tx.lock().unwrap().take() {
|
||||
_ = tx.send(());
|
||||
}
|
||||
async {}
|
||||
}),
|
||||
|
|
@ -415,7 +413,9 @@ async fn start(
|
|||
|
||||
if let Some(program_name) = exec_words.next() {
|
||||
// filter out any placeholder args, since we might not be able to deal with them
|
||||
let filtered_args = exec_words.filter(|s| !s.starts_with("%")).collect_vec();
|
||||
let filtered_args = exec_words
|
||||
.filter(|s| !s.starts_with("%"))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// escape them
|
||||
let escaped_args = shell_words::split(&*filtered_args.join(" "));
|
||||
|
|
@ -457,7 +457,8 @@ async fn start(
|
|||
info!("started {} programs", dedupe.len());
|
||||
}
|
||||
|
||||
let mut signals = Signals::new(vec![libc::SIGTERM, libc::SIGINT]).unwrap();
|
||||
let mut sigterm = signal(SignalKind::terminate()).expect("Failed to bind SIGTERM handler");
|
||||
let mut sigint = signal(SignalKind::interrupt()).expect("Failed to bind SIGINT handler");
|
||||
let mut status = Status::Exited;
|
||||
let session_dbus_rx_next = session_rx.recv();
|
||||
tokio::select! {
|
||||
|
|
@ -475,12 +476,11 @@ async fn start(
|
|||
}
|
||||
}
|
||||
},
|
||||
signal = signals.next() => match signal {
|
||||
Some(libc::SIGTERM | libc::SIGINT) => {
|
||||
info!("EXITING: received request to terminate");
|
||||
}
|
||||
Some(signal) => unreachable!("EXITING: received unhandled signal {}", signal),
|
||||
None => {},
|
||||
_ = sigterm.recv() => {
|
||||
info!("EXITING: received SIGTERM request to terminate");
|
||||
},
|
||||
_ = sigint.recv() => {
|
||||
info!("EXITING: received SIGINT request to terminate");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -534,17 +534,15 @@ async fn start_component(
|
|||
})
|
||||
.with_on_start(move |pman, pkey, _will_restart| async move {
|
||||
#[cfg(feature = "systemd")]
|
||||
if *is_systemd_used() {
|
||||
if let Ok((innr_cmd, Some(pid))) = pman.get_exe_and_pid(pkey).await {
|
||||
if let Err(err) = spawn_scope(innr_cmd.clone(), vec![pid]).await {
|
||||
warn!(
|
||||
"Failed to spawn scope for {}. Creating transient unit failed \
|
||||
with {}",
|
||||
innr_cmd, err
|
||||
);
|
||||
};
|
||||
}
|
||||
}
|
||||
if *is_systemd_used()
|
||||
&& let Ok((innr_cmd, Some(pid))) = pman.get_exe_and_pid(pkey).await
|
||||
&& let Err(err) = spawn_scope(innr_cmd.clone(), vec![pid]).await
|
||||
{
|
||||
warn!(
|
||||
"Failed to spawn scope for {}. Creating transient unit failed with {}",
|
||||
innr_cmd, err
|
||||
);
|
||||
};
|
||||
})
|
||||
.with_on_exit(move |mut _pman, _key, err_code, _will_restart| {
|
||||
if let Some(err) = err_code {
|
||||
|
|
|
|||
|
|
@ -1,14 +1,17 @@
|
|||
use color_eyre::{Result, eyre::Context};
|
||||
use cosmic_notifications_util::{DAEMON_NOTIFICATIONS_FD, PANEL_NOTIFICATIONS_FD};
|
||||
use launch_pad::{ProcessKey, process::Process};
|
||||
use color_eyre::Result;
|
||||
use color_eyre::eyre::Context;
|
||||
use launch_pad::ProcessKey;
|
||||
use launch_pad::process::Process;
|
||||
use rustix::fd::AsRawFd;
|
||||
use std::{
|
||||
os::{fd::OwnedFd, unix::net::UnixStream},
|
||||
sync::Arc,
|
||||
};
|
||||
use std::os::fd::OwnedFd;
|
||||
use std::os::unix::net::UnixStream;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::Mutex;
|
||||
use tracing::Instrument;
|
||||
|
||||
pub const PANEL_NOTIFICATIONS_FD: &str = "PANEL_NOTIFICATIONS_FD";
|
||||
pub const DAEMON_NOTIFICATIONS_FD: &str = "DAEMON_NOTIFICATIONS_FD";
|
||||
|
||||
pub fn create_socket() -> Result<(OwnedFd, OwnedFd)> {
|
||||
// Create a new pair of unnamed Unix sockets
|
||||
let (sock_1, sock_2) = UnixStream::pair().wrap_err("failed to create socket pair")?;
|
||||
|
|
@ -26,6 +29,7 @@ pub fn create_socket() -> Result<(OwnedFd, OwnedFd)> {
|
|||
Ok((OwnedFd::from(sock_1), OwnedFd::from(sock_2)))
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn notifications_process(
|
||||
span: tracing::Span,
|
||||
cmd: &'static str,
|
||||
|
|
|
|||
|
|
@ -1,15 +1,11 @@
|
|||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
|
||||
use std::{
|
||||
path::Path,
|
||||
process::{Command, Stdio},
|
||||
sync::OnceLock,
|
||||
};
|
||||
use std::path::Path;
|
||||
use std::process::{Command, Stdio};
|
||||
use std::sync::OnceLock;
|
||||
|
||||
use zbus::{
|
||||
Connection,
|
||||
zvariant::{Array, OwnedValue},
|
||||
};
|
||||
use zbus::Connection;
|
||||
use zbus::zvariant::{Array, OwnedValue};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct EnvVar {
|
||||
|
|
@ -17,11 +13,11 @@ pub struct EnvVar {
|
|||
pub value: String,
|
||||
}
|
||||
|
||||
impl Into<EnvVar> for (&str, &str) {
|
||||
fn into(self) -> EnvVar {
|
||||
impl From<(&str, &str)> for EnvVar {
|
||||
fn from(val: (&str, &str)) -> Self {
|
||||
EnvVar {
|
||||
key: self.0.to_owned(),
|
||||
value: self.1.to_owned(),
|
||||
key: val.0.to_owned(),
|
||||
value: val.1.to_owned(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue