mirror of
https://git.outfoxxed.me/quickshell/quickshell.git
synced 2026-04-10 06:11:54 +10:00
core/command: filter instance selection by current display
This commit is contained in:
parent
1e8cc2e78d
commit
00858812f2
9 changed files with 50 additions and 9 deletions
|
|
@ -13,6 +13,7 @@
|
|||
#include <qdebug.h>
|
||||
#include <qdir.h>
|
||||
#include <qfileinfo.h>
|
||||
#include <qguiapplication.h>
|
||||
#include <qjsonarray.h>
|
||||
#include <qjsondocument.h>
|
||||
#include <qjsonobject.h>
|
||||
|
|
@ -178,7 +179,8 @@ int selectInstance(CommandState& cmd, InstanceLockInfo* instance, bool deadFallb
|
|||
}
|
||||
} else if (!cmd.instance.id->isEmpty()) {
|
||||
path = basePath->filePath("by-pid");
|
||||
auto [liveInstances, deadInstances] = QsPaths::collectInstances(path);
|
||||
auto [liveInstances, deadInstances] =
|
||||
QsPaths::collectInstances(path, cmd.config.anyDisplay ? "" : getDisplayConnection());
|
||||
|
||||
liveInstances.removeIf([&](const InstanceLockInfo& info) {
|
||||
return !info.instance.instanceId.startsWith(*cmd.instance.id);
|
||||
|
|
@ -228,7 +230,8 @@ int selectInstance(CommandState& cmd, InstanceLockInfo* instance, bool deadFallb
|
|||
|
||||
path = QDir(basePath->filePath("by-path")).filePath(pathId);
|
||||
|
||||
auto [liveInstances, deadInstances] = QsPaths::collectInstances(path);
|
||||
auto [liveInstances, deadInstances] =
|
||||
QsPaths::collectInstances(path, cmd.config.anyDisplay ? "" : getDisplayConnection());
|
||||
|
||||
auto instances = liveInstances;
|
||||
if (instances.isEmpty() && deadFallback) {
|
||||
|
|
@ -311,7 +314,10 @@ int listInstances(CommandState& cmd) {
|
|||
path = QDir(basePath->filePath("by-path")).filePath(pathId);
|
||||
}
|
||||
|
||||
auto [liveInstances, deadInstances] = QsPaths::collectInstances(path);
|
||||
auto [liveInstances, deadInstances] = QsPaths::collectInstances(
|
||||
path,
|
||||
cmd.config.anyDisplay || cmd.instance.all ? "" : getDisplayConnection()
|
||||
);
|
||||
|
||||
sortInstances(liveInstances, cmd.config.newest);
|
||||
|
||||
|
|
@ -373,6 +379,7 @@ int listInstances(CommandState& cmd) {
|
|||
<< " Process ID: " << instance.instance.pid << '\n'
|
||||
<< " Shell ID: " << instance.instance.shellId << '\n'
|
||||
<< " Config path: " << instance.instance.configPath << '\n'
|
||||
<< " Display connection: " << instance.instance.display << '\n'
|
||||
<< " Launch time: " << launchTimeStr
|
||||
<< (isDead ? "" : " (running for " + runtimeStr + ")") << '\n'
|
||||
<< (gray ? "\033[0m" : "");
|
||||
|
|
@ -545,4 +552,18 @@ int runCommand(int argc, char** argv, QCoreApplication* coreApplication) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
QString getDisplayConnection() {
|
||||
auto platform = qEnvironmentVariable("QT_QPA_PLATFORM");
|
||||
auto wlDisplay = qEnvironmentVariable("WAYLAND_DISPLAY");
|
||||
auto xDisplay = qEnvironmentVariable("DISPLAY");
|
||||
|
||||
if (platform == "wayland" || (platform.isEmpty() && !wlDisplay.isEmpty())) {
|
||||
return "wayland," + wlDisplay;
|
||||
} else if (platform == "xcb" || (platform.isEmpty() && !xDisplay.isEmpty())) {
|
||||
return "x11," + xDisplay;
|
||||
} else {
|
||||
return "unk," + QGuiApplication::platformName();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace qs::launch
|
||||
|
|
|
|||
|
|
@ -134,6 +134,7 @@ int launch(const LaunchArgs& args, char** argv, QCoreApplication* coreApplicatio
|
|||
.shellId = shellId,
|
||||
.launchTime = qs::Common::LAUNCH_TIME,
|
||||
.pid = getpid(),
|
||||
.display = getDisplayConnection(),
|
||||
};
|
||||
|
||||
#if CRASH_REPORTER
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ struct CommandState {
|
|||
QStringOption manifest;
|
||||
QStringOption name;
|
||||
bool newest = false;
|
||||
bool anyDisplay = false;
|
||||
} config;
|
||||
|
||||
struct {
|
||||
|
|
@ -106,6 +107,8 @@ void exitDaemon(int code);
|
|||
int parseCommand(int argc, char** argv, CommandState& state);
|
||||
int runCommand(int argc, char** argv, QCoreApplication* coreApplication);
|
||||
|
||||
QString getDisplayConnection();
|
||||
|
||||
int launch(const LaunchArgs& args, char** argv, QCoreApplication* coreApplication);
|
||||
|
||||
} // namespace qs::launch
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ int parseCommand(int argc, char** argv, CommandState& state) {
|
|||
.argv = argv,
|
||||
};
|
||||
|
||||
auto addConfigSelection = [&](CLI::App* cmd, bool withNewestOption = false) {
|
||||
auto addConfigSelection = [&](CLI::App* cmd, bool filtering = false) {
|
||||
auto* group =
|
||||
cmd->add_option_group("Config Selection")
|
||||
->description(
|
||||
|
|
@ -49,9 +49,13 @@ int parseCommand(int argc, char** argv, CommandState& state) {
|
|||
->envname("QS_MANIFEST")
|
||||
->excludes(path);
|
||||
|
||||
if (withNewestOption) {
|
||||
if (filtering) {
|
||||
group->add_flag("-n,--newest", state.config.newest)
|
||||
->description("Operate on the most recently launched instance instead of the oldest");
|
||||
|
||||
group->add_flag("--any-display", state.config.anyDisplay)
|
||||
->description("If passed, instances will not be filtered by the display connection they "
|
||||
"were launched on.");
|
||||
}
|
||||
|
||||
return group;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue