dwl/session.pl

89 lines
3.0 KiB
Perl
Executable File

#!/usr/bin/env perl
use strict;
use warnings FATAL => qw(uninitialized);
use English;
use Cwd qw(abs_path);
use File::Basename qw(dirname basename);
use File::Path qw(remove_tree make_path);
# Set up environment.
$ENV{XDG_CURRENT_DESKTOP} = "sway";
$ENV{XDG_CURRENT_SESSION} = "sway";
$ENV{SDL_VIDEODRIVER} = "wayland,x11";
$ENV{QT_QPA_PLATFORM} = "wayland";
$ENV{CLUTTER_BACKEND} = "wayland";
$ENV{MOZ_ENABLE_WAYLAND} = "1";
$ENV{GUAKE_ENABLE_WAYLAND} = "1";
$ENV{SSH_ASKPASS} = "/usr/lib64/seahorse/seahorse-ssh-askpass";
my $XDG_RUNTIME_DIR = $ENV{XDG_RUNTIME_DIR} // die("Cannot find XDG_RUNTIME_DIR variable.\n");
my $HOME = $ENV{HOME} // die("Cannot find HOME variable.\n");
# Directory that the session.pl script itself is in.
my $scriptDir = dirname(abs_path($PROGRAM_NAME));
# Clean up some files
unlink("$XDG_RUNTIME_DIR/dwl-bar-0");
remove_tree("${XDG_RUNTIME_DIR}/cdwl");
# Create correct XDG Portals configuration.
my $xdgPortalsConfig = "[preferred]
default=kde
org.freedesktop.impl.portal.FileChooser=gtk
org.freedesktop.impl.portal.Screenshot=wlr
org.freedesktop.impl.portal.ScreenCast=wlr
org.freedesktop.impl.portal.Settings=kde;gtk;wlr;
";
my $xdgPortalsConfigError;
make_path("${HOME}/.config/xdg-desktop-portal", { mode => 0700, error => \$xdgPortalsConfigError }) or sub {
if(@$xdgPortalsConfigError) {
die(@$xdgPortalsConfigError);
}
print("\nDid it.\n");
};
open(my $xdgPortalsConfigFile, ">", "${HOME}/.config/xdg-desktop-portal/portals.conf") or die($ERRNO);
print $xdgPortalsConfigFile ($xdgPortalsConfig);
close($xdgPortalsConfigFile);
# Create temporary binary path and symlink binaries from subprojects.
make_path("${XDG_RUNTIME_DIR}/cdwl/bin", { mode => 0700 }) or die($ERRNO);
# Populate binary path.
my $binPath = "${XDG_RUNTIME_DIR}/cdwl/bin";
my $subPath = "${scriptDir}/builddir/subprojects";
sub link_sub_binary {
my $project = $ARG[0];
symlink("${subPath}/${project}/${project}", "${binPath}/${project}");
}
sub link_built_binary {
my $exe = $ARG[0];
symlink("${subPath}/$exe", "${binPath}/". basename($exe));
}
sub link_script {
my $file = $ARG[0];
symlink("${scriptDir}/runtime-scripts/${file}", "${binPath}/${file}");
}
link_sub_binary("swayidle");
link_sub_binary("wtype");
link_sub_binary("dwl-bar");
link_sub_binary("wofi");
link_sub_binary("dwlmsg");
link_sub_binary("wev");
link_sub_binary("pamixer");
link_sub_binary("hyprpicker");
link_sub_binary("xdg-desktop-portal-wlr");
link_built_binary("shortcuts/net.iotib.Shortcuts");
link_script("playerctl-toggle.pl");
link_script("status.pl");
link_script("update-flatpak.pl");
# Create empty current_mode file.
open(my $fh, ">", "${XDG_RUNTIME_DIR}/cdwl/current_mode");
print $fh ("Normal");
close($fh);
# Set path to include temporary binary path.
$ENV{PATH} = "${XDG_RUNTIME_DIR}/cdwl/bin:" . $ENV{PATH};
# Run window manager.
system("meson setup $scriptDir/builddir $scriptDir && ninja -C $scriptDir/builddir && dbus-run-session ssh-agent $scriptDir/builddir/dwl -d 2>err.log");