Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add debug session for debugging with existing cosmic install #1108

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ vendor.tar
.vscode
*.log
/result
build/*
33 changes: 30 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ ifneq ($(VENDOR),0)
endif

TARGET_BIN="$(DESTDIR)$(bindir)/$(BINARY)"
DEBUG_TARGET_BIN="$(DESTDIR)$(bindir)/debug-$(BINARY)"

KEYBINDINGS_CONF="$(DESTDIR)$(sharedir)/cosmic/com.system76.CosmicSettings.Shortcuts/v1/defaults"
TILING_EXCEPTIONS_CONF="$(DESTDIR)$(sharedir)/cosmic/com.system76.CosmicSettings.WindowRules/v1/tiling_exception_defaults"
Expand Down Expand Up @@ -52,15 +53,41 @@ install:
install -Dm0644 "data/keybindings.ron" "$(KEYBINDINGS_CONF)"
install -Dm0644 "data/tiling-exceptions.ron" "$(TILING_EXCEPTIONS_CONF)"

install-bare-session: install
install -Dm0644 "data/cosmic.desktop" "$(DESTDIR)$(sharedir)/wayland-sessions/cosmic.desktop"
gen-template:
mkdir build || true
sed -f data/replace.sed data/cosmic-comp.service > build/cosmic-comp.service
sed -f data/replace.sed data/cosmic.desktop > build/cosmic.desktop

install-bare-session: install gen-template
install -Dm0644 "build/cosmic.desktop" "$(DESTDIR)$(sharedir)/wayland-sessions/cosmic.desktop"
install -Dm0644 "data/cosmic-session.target" "$(DESTDIR)$(libdir)/systemd/user/cosmic-session.target"
install -Dm0644 "data/cosmic-session-pre.target" "$(DESTDIR)$(libdir)/systemd/user/cosmic-session-pre.target"
install -Dm0644 "data/cosmic-comp.service" "$(DESTDIR)$(libdir)/systemd/user/cosmic-comp.service"
install -Dm0644 "build/cosmic-comp.service" "$(DESTDIR)$(libdir)/systemd/user/cosmic-comp.service"
install -Dm0755 "data/cosmic-service" "$(DESTDIR)/$(bindir)/cosmic-service"

install-debug:
install -Dm0755 "$(CARGO_TARGET_DIR)/$(TARGET)/$(BINARY)" "$(DEBUG_TARGET_BIN)"

gen-debug-template:
mkdir build || true
sed -f debug-data/replace.sed data/cosmic-comp.service > build/debug-cosmic-comp.service
sed -f debug-data/replace.sed data/cosmic.desktop > build/debug-cosmic.desktop

install-debug-session: install-debug gen-debug-template
install -Dm0644 "build/debug-cosmic.desktop" "$(DESTDIR)$(sharedir)/wayland-sessions/debug-cosmic.desktop"
install -Dm0644 "build/debug-cosmic-comp.service" "$(DESTDIR)$(libdir)/systemd/user/debug-cosmic-comp.service"
install -Dm0755 "debug-data/debug-cosmic-service" "$(DESTDIR)/$(bindir)/debug-cosmic-service"

uninstall:
rm "$(TARGET_BIN)" "$(KEYBINDINGS_CONF)"

uninstall-bare-session:
rm "$(DESTDIR)$(sharedir)/wayland-sessions/cosmic.desktop"

uninstall-debug:
rm "$(DEBUG_TARGET_BIN)"

uninstall-debug-session:
rm "$(DESTDIR)$(sharedir)/wayland-sessions/cosmic.desktop"
rm "$(DESTDIR)$(libdir)/systemd/user/debug-cosmic-comp.service"
rm "$(DESTDIR)/$(bindir)/debug-cosmic-service"
4 changes: 2 additions & 2 deletions data/cosmic-comp.service
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[Unit]
Description=Cosmic wayland compositor
Description=${DEBUG_STR}Cosmic wayland compositor
BindsTo=cosmic-session.target
Wants=cosmic-session-pre.target
After=cosmic-session-pre.target
Before=cosmic-session.target

[Service]
Type=notify
ExecStart=/usr/bin/cosmic-comp
ExecStart=/usr/bin/${DEBUG_BIN}cosmic-comp
Restart=never
ExecStopPost=/usr/bin/systemctl --user unset-environment DISPLAY WAYLAND_DISPLAY
4 changes: 2 additions & 2 deletions data/cosmic.desktop
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[Desktop Entry]
Name=Cosmic
Name=${DEBUG_STR}Cosmic
Commment=This session logs you into Cosmic
Exec=/usr/bin/cosmic-service
Exec=/usr/bin/${DEBUG_BIN}cosmic-service
Type=Application
DesktopNames=pop:COSMIC
X-GDM-SessionRegisters=false
2 changes: 2 additions & 0 deletions data/replace.sed
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
s/${DEBUG_STR}//g
s/${DEBUG_BIN}//g
52 changes: 52 additions & 0 deletions debug-data/debug-cosmic-service
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/bin/bash

set -e

# From: https://people.debian.org/~mpitt/systemd.conf-2016-graphical-session.pdf

if command -v systemctl >/dev/null; then
# robustness: if the previous graphical session left some failed units,
# reset them so that they don't break this startup
for unit in $(systemctl --user --no-legend --state=failed --plain list-units | cut -f1 -d' '); do
partof="$(systemctl --user show -p PartOf --value "$unit")"
for target in cosmic-session.target graphical-session.target; do
if [ "$partof" = "$target" ]; then
systemctl --user reset-failed "$unit"
break
fi
done
done
fi

# use the user's preferred shell to acquire environment variables
# see: https://github.com/pop-os/cosmic-session/issues/23
if [ -n "${SHELL}" ]; then
# --in-login-shell: our flag to indicate that we don't need to recurse any further
if [ "${1}" != "--in-login-shell" ]; then
# `exec -l`: like `login`, prefixes $SHELL with a hyphen to start a login shell
exec bash -c "exec -l '${SHELL}' -c '${0} --in-login-shell'"
fi
fi

export XDG_CURRENT_DESKTOP="${XDG_CURRENT_DESKTOP:=COSMIC}"
export XDG_SESSION_TYPE="${XDG_SESSION_TYPE:=wayland}"
export XCURSOR_THEME="${XCURSOR_THEME:=Cosmic}"
export _JAVA_AWT_WM_NONREPARENTING=1
export GDK_BACKEND=wayland,x11
export MOZ_ENABLE_WAYLAND=1
export QT_QPA_PLATFORM="wayland;xcb"
export QT_AUTO_SCREEN_SCALE_FACTOR=1
export QT_ENABLE_HIGHDPI_SCALING=1
export DCONF_PROFILE=cosmic
export RUST_LOG=debug

if command -v systemctl >/dev/null; then
# set environment variables for new units started by user service manager
systemctl --user import-environment XDG_SESSION_TYPE XDG_CURRENT_DESKTOP
fi
# Run cosmic-session
if [[ -z "${DBUS_SESSION_BUS_ADDRESS}" ]]; then
exec /usr/bin/dbus-run-session -- /usr/bin/cosmic-session /usr/bin/debug-cosmic-comp
else
exec /usr/bin/cosmic-session /usr/bin/debug-cosmic-comp
fi
2 changes: 2 additions & 0 deletions debug-data/replace.sed
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
s/${DEBUG_STR}/Debug /g
s/${DEBUG_BIN}/debug-/g
Loading