diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..8b22154d --- /dev/null +++ b/Makefile @@ -0,0 +1,58 @@ +export prefix ?= /usr +sysconfdir ?= /etc +bindir = $(prefix)/bin +libdir = $(prefix)/lib +sharedir = $(prefix)/share + +BINARY = cosmic-comp +ID = com.pop-os.Compositor +TARGET = debug +DEBUG ?= 0 + +.PHONY = all clean install uninstall vendor + +ifeq ($(DEBUG),0) + TARGET = release + ARGS += --release +endif + +VENDOR ?= 0 +ifneq ($(VENDOR),0) + ARGS += --frozen +endif + +TARGET_BIN="$(DESTDIR)$(bindir)/$(BINARY)" + +all: extract-vendor + cargo build $(ARGS) + +clean: + cargo clean + +distclean: + rm -rf .cargo vendor vendor.tar target + +vendor: + mkdir -p .cargo + cargo vendor | head -n -1 > .cargo/config + echo 'directory = "vendor"' >> .cargo/config + tar pcf vendor.tar vendor + rm -rf vendor + +extract-vendor: +ifeq ($(VENDOR),1) + rm -rf vendor; tar pxf vendor.tar +endif + +install: + install -Dm0644 "data/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 -Dm04755 "data/cosmic-service" "$(DESTDIR)/$(bindir)/cosmic-service" + install -Dm04755 "target/$(TARGET)/$(BINARY)" "$(TARGET_BIN)" + + +uninstall: + rm "$(DESTDIR)$(sharedir)/wayland-sessions/cosmic.desktop" + rm "$(TARGET_BIN)" \ No newline at end of file diff --git a/data/cosmic-comp.service b/data/cosmic-comp.service new file mode 100644 index 00000000..85a90663 --- /dev/null +++ b/data/cosmic-comp.service @@ -0,0 +1,12 @@ +[Unit] +Description=Cosmic wayland compositor +BindsTo=cosmic-session.target +Wants=cosmic-session-pre.target +After=cosmic-session-pre.target +Before=cosmic-session.target + +[Service] +Type=simple +ExecStart=/usr/bin/cosmic-comp +Restart=never +ExecStopPost=/usr/bin/systemctl --user unset-environment DISPLAY WAYLAND_DISPLAY \ No newline at end of file diff --git a/data/cosmic-service b/data/cosmic-service new file mode 100644 index 00000000..badf7425 --- /dev/null +++ b/data/cosmic-service @@ -0,0 +1,32 @@ +#!/bin/bash + +# From: https://people.debian.org/~mpitt/systemd.conf-2016-graphical-session.pdf + +# 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 + +# /etc/profile contains a lot of important environment variables +source /etc/profile + +export XDG_CURRENT_DESKTOP=cosmic + +# save environment variables that will be added to systemd +new_env=$(systemctl --user show-environment | cut -d'=' -f 1 | sort | comm -13 - <(env | cut -d'=' -f 1 | sort)) + +# import environment variables from the login manager +systemctl --user import-environment + +# then start the service +systemctl --wait --user start cosmic-comp.service + +# cleanup environment +systemctl --user unset-environment $new_env \ No newline at end of file diff --git a/data/cosmic-session-pre.target b/data/cosmic-session-pre.target new file mode 100644 index 00000000..c9c6a5f4 --- /dev/null +++ b/data/cosmic-session-pre.target @@ -0,0 +1,8 @@ +[Unit] +Description=Cosmic session early services +Documentation=man:systemd.special(7) +RefuseManualStart=yes +StopWhenUnneeded=yes +BindsTo=graphical-session-pre.target +Before=graphical-session-pre.target +Before=cosmic-session.target \ No newline at end of file diff --git a/data/cosmic-session.target b/data/cosmic-session.target new file mode 100644 index 00000000..bf3997d9 --- /dev/null +++ b/data/cosmic-session.target @@ -0,0 +1,7 @@ +[Unit] +Description=Cosmic session +Documentation=man:systemd.special(7) +RefuseManualStart=yes +StopWhenUnneeded=yes +BindsTo=graphical-session.target +Before=graphical-session.target \ No newline at end of file diff --git a/data/cosmic.desktop b/data/cosmic.desktop new file mode 100644 index 00000000..3d288c5a --- /dev/null +++ b/data/cosmic.desktop @@ -0,0 +1,7 @@ +[Desktop Entry] +Name=Cosmic +Commment=This session logs you into Cosmic +Exec=/usr/bin/cosmic-service +Type=Application +DesktopNames=pop:COSMIC +X-GDM-SessionRegisters=false \ No newline at end of file