Skip to content
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
5 changes: 5 additions & 0 deletions assets/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1988,6 +1988,11 @@
"description": "Launches applications in separate systemd services so they don't share Noctalia's cgroup",
"label": "Launch Apps as systemd Services"
},
"launch-apps-custom-command": {
"description": "Custom command used by the app launcher, it substitutes $CMD with the original command.",
"label": "Custom Launcher Command",
"placeholder": "$CMD"
},
"middle-click-opens-widget-settings": {
"description": "Open a bar widget's settings from the bar with middle click",
"label": "Middle Click Opens Widget Settings"
Expand Down
1 change: 1 addition & 0 deletions src/config/config_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -805,6 +805,7 @@ struct ShellConfig {
bool appIconColorize = false;
std::optional<ColorSpec> appIconColor;
bool launchAppsAsSystemdServices = false;
std::string launchAppsCustomCommand;
/// When false, disables Wayland clipboard integration (history panel, data-control binding, Input paste/copy hooks).
bool clipboardEnabled = true;
/// Maximum unpinned clipboard history entries retained (pinned entries are exempt).
Expand Down
1 change: 1 addition & 0 deletions src/config/schema/config_schema.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1112,6 +1112,7 @@ namespace noctalia::config::schema {
field(&ShellConfig::appIconColorize, "app_icon_colorize"),
colorSpecField(&ShellConfig::appIconColor, "app_icon_color", /*alwaysEmit=*/false),
field(&ShellConfig::launchAppsAsSystemdServices, "launch_apps_as_systemd_services"),
field(&ShellConfig::launchAppsCustomCommand, "launch_apps_custom_command"),
field(&ShellConfig::clipboardEnabled, "clipboard_enabled"),
field(
&ShellConfig::clipboardHistoryMaxEntries, "clipboard_history_max_entries", kClipboardHistoryMaxEntriesRange
Expand Down
1 change: 1 addition & 0 deletions src/launcher/app_provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ bool AppProvider::activate(const LauncherResult& result) {
desktop_entry_launch::LaunchOptions launchOptions{
.activationToken = std::move(token),
.runAsSystemdService = m_config->config().shell.launchAppsAsSystemdServices,
.customCommand = m_config->config().shell.launchAppsCustomCommand,
};

if (chosen != nullptr) {
Expand Down
1 change: 1 addition & 0 deletions src/shell/bar/widgets/taskbar_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1857,6 +1857,7 @@ void TaskbarWidget::openTaskContextMenu(const TaskModel& task, InputArea& area)
desktop_entry_launch::LaunchOptions{
.activationToken = std::move(token),
.runAsSystemdService = configService.config().shell.launchAppsAsSystemdServices,
.customCommand = configService.config().shell.launchAppsCustomCommand,
}
);
});
Expand Down
1 change: 1 addition & 0 deletions src/shell/dock/dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ namespace {
return desktop_entry_launch::LaunchOptions{
.activationToken = std::move(token),
.runAsSystemdService = config.config().shell.launchAppsAsSystemdServices,
.customCommand = config.config().shell.launchAppsCustomCommand,
};
}

Expand Down
11 changes: 11 additions & 0 deletions src/shell/settings/settings_registry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1217,6 +1217,17 @@ namespace settings {
{"shell", "launch_apps_as_systemd_services"}, ToggleSetting{cfg.shell.launchAppsAsSystemdServices}
));
}
entries.push_back(makeEntry(
SettingsSection::Shell, "general", tr("settings.schema.shell.launch-apps-custom-command.label"),
tr("settings.schema.shell.launch-apps-custom-command.description"), {"shell", "launch_apps_custom_command"},
TextSetting{
.value = cfg.shell.launchAppsCustomCommand,
.placeholder = tr("settings.schema.shell.launch-apps-custom-command.placeholder"),
.width = 320.0f,
.browseFileExtensions = {},
},
"app command custom launcher"
));
const SettingVisibility clipboardOn{{"shell", "clipboard_enabled"}, {"true"}};
entries.push_back(makeEntry(
SettingsSection::Shell, "clipboard", tr("settings.schema.shell.clipboard-enabled.label"),
Expand Down
22 changes: 20 additions & 2 deletions src/system/desktop_entry_launch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,25 @@ namespace desktop_entry_launch {
return PreparedCommand{std::move(args)};
}

std::string parseCustomCommand(const std::string& exec, const std::string& customCommand) {
std::string command;
if (!customCommand.empty()) {
command = customCommand;
size_t pos = 0;
while ((pos = command.find("$CMD", pos)) != std::string::npos) {
command.replace(pos, 4, exec);
pos += exec.length();
}
} else {
command = exec;
}
return command;
}

bool launchEntry(const DesktopEntry& entry, const LaunchOptions& options) {
auto prepared = prepareCommand(entry.exec, entry.terminal);
const std::string command = parseCustomCommand(entry.exec, options.customCommand);
auto prepared = prepareCommand(command, entry.terminal);

if (!prepared.has_value()) {
kLog.warn("Failed to prepare launch command for desktop entry '{}'", entry.id.empty() ? entry.name : entry.id);
return false;
Expand All @@ -142,7 +159,8 @@ namespace desktop_entry_launch {
const DesktopAction& action, std::string_view appName, std::string_view workingDir, bool terminal,
const LaunchOptions& options
) {
auto prepared = prepareCommand(action.exec, terminal);
const std::string command = parseCustomCommand(action.exec, options.customCommand);
auto prepared = prepareCommand(command, terminal);
if (!prepared.has_value()) {
kLog.warn(
"Failed to prepare launch command for desktop action '{}'", action.id.empty() ? action.name : action.id
Expand Down
1 change: 1 addition & 0 deletions src/system/desktop_entry_launch.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace desktop_entry_launch {
struct LaunchOptions {
std::string activationToken;
bool runAsSystemdService = false;
std::string customCommand;
};

struct PrepareOptions {
Expand Down