screencopy/picker: add an option to allow restore token by default

fixes #258

screencopy:allow_token_by_default -> bool
This commit is contained in:
Vaxry 2024-09-21 16:07:33 +01:00
parent 5e40936fa0
commit bab430b3cc
3 changed files with 36 additions and 24 deletions

View file

@ -77,8 +77,13 @@ std::vector<SWindowEntry> getWindows(const char* env) {
int main(int argc, char* argv[]) { int main(int argc, char* argv[]) {
qputenv("QT_LOGGING_RULES", "qml=false"); qputenv("QT_LOGGING_RULES", "qml=false");
const char* WINDOWLISTSTR = getenv("XDPH_WINDOW_SHARING_LIST"); bool allowTokenByDefault = false;
for (int i = 1; i < argc; ++i) {
if (argv[i] == std::string{"--allow-token"})
allowTokenByDefault = true;
}
const char* WINDOWLISTSTR = getenv("XDPH_WINDOW_SHARING_LIST");
const auto WINDOWLIST = getWindows(WINDOWLISTSTR); const auto WINDOWLIST = getWindows(WINDOWLISTSTR);
QApplication picker(argc, argv); QApplication picker(argc, argv);
@ -90,8 +95,11 @@ int main(int argc, char* argv[]) {
w.setGeometry(0, 0, settings->value("width").toInt(), settings->value("height").toInt()); w.setGeometry(0, 0, settings->value("width").toInt(), settings->value("height").toInt());
// get the tabwidget // get the tabwidget
const auto TABWIDGET = w.findChild<QTabWidget *>("tabWidget"); const auto TABWIDGET = w.findChild<QTabWidget*>("tabWidget");
const auto ALLOWTOKENBUTTON = w.findChild<QCheckBox *>("checkBox"); const auto ALLOWTOKENBUTTON = w.findChild<QCheckBox*>("checkBox");
if (allowTokenByDefault)
ALLOWTOKENBUTTON->setCheckState(Qt::CheckState::Checked);
const auto TAB1 = (QWidget*)TABWIDGET->children()[0]; const auto TAB1 = (QWidget*)TABWIDGET->children()[0];
@ -132,7 +140,7 @@ int main(int argc, char* argv[]) {
}); });
} }
QSpacerItem * SCREENS_SPACER = new QSpacerItem(0,10000, QSizePolicy::Expanding, QSizePolicy::Expanding); QSpacerItem* SCREENS_SPACER = new QSpacerItem(0, 10000, QSizePolicy::Expanding, QSizePolicy::Expanding);
SCREENS_SCROLL_AREA_CONTENTS_LAYOUT->addItem(SCREENS_SPACER); SCREENS_SCROLL_AREA_CONTENTS_LAYOUT->addItem(SCREENS_SPACER);
// windows // windows
@ -170,7 +178,7 @@ int main(int argc, char* argv[]) {
windowIterator++; windowIterator++;
} }
QSpacerItem * WINDOWS_SPACER = new QSpacerItem(0,10000, QSizePolicy::Expanding, QSizePolicy::Expanding); QSpacerItem* WINDOWS_SPACER = new QSpacerItem(0, 10000, QSizePolicy::Expanding, QSizePolicy::Expanding);
WINDOWS_SCROLL_AREA_CONTENTS_LAYOUT->addItem(WINDOWS_SPACER); WINDOWS_SCROLL_AREA_CONTENTS_LAYOUT->addItem(WINDOWS_SPACER);
// lastly, region // lastly, region
@ -183,7 +191,6 @@ int main(int argc, char* argv[]) {
button->setMaximumSize(400, BUTTON_HEIGHT); button->setMaximumSize(400, BUTTON_HEIGHT);
REGION_LAYOUT->addWidget(button); REGION_LAYOUT->addWidget(button);
QObject::connect(button, &QPushButton::clicked, [=]() { QObject::connect(button, &QPushButton::clicked, [=]() {
auto REGION = execAndGet("slurp -f \"%o %x %y %w %h\""); auto REGION = execAndGet("slurp -f \"%o %x %y %w %h\"");
REGION = REGION.substr(0, REGION.length()); REGION = REGION.substr(0, REGION.length());

View file

@ -42,6 +42,7 @@ CPortalManager::CPortalManager() {
m_sConfig.config->addConfigValue("general:toplevel_dynamic_bind", Hyprlang::INT{0L}); m_sConfig.config->addConfigValue("general:toplevel_dynamic_bind", Hyprlang::INT{0L});
m_sConfig.config->addConfigValue("screencopy:max_fps", Hyprlang::INT{120L}); m_sConfig.config->addConfigValue("screencopy:max_fps", Hyprlang::INT{120L});
m_sConfig.config->addConfigValue("screencopy:allow_token_by_default", Hyprlang::INT{0L});
m_sConfig.config->commence(); m_sConfig.config->commence();
m_sConfig.config->parse(); m_sConfig.config->parse();

View file

@ -42,11 +42,15 @@ SSelectionData promptForScreencopySelection() {
const char* XCURSOR_SIZE = getenv("XCURSOR_SIZE"); const char* XCURSOR_SIZE = getenv("XCURSOR_SIZE");
const char* HYPRLAND_INSTANCE_SIGNATURE = getenv("HYPRLAND_INSTANCE_SIGNATURE"); const char* HYPRLAND_INSTANCE_SIGNATURE = getenv("HYPRLAND_INSTANCE_SIGNATURE");
static auto* const* PALLOWTOKENBYDEFAULT =
(Hyprlang::INT* const*)g_pPortalManager->m_sConfig.config->getConfigValuePtr("screencopy:allow_token_by_default")->getDataStaticPtr();
// DANGEROUS: we are sending a list of app IDs and titles via env. Make sure it's in 'singlequotes' to avoid something like $(rm -rf /) // DANGEROUS: we are sending a list of app IDs and titles via env. Make sure it's in 'singlequotes' to avoid something like $(rm -rf /)
// TODO: this is dumb, use a pipe or something. // TODO: this is dumb, use a pipe or something.
std::string cmd = std::string cmd =
std::format("WAYLAND_DISPLAY='{}' QT_QPA_PLATFORM='wayland' XCURSOR_SIZE='{}' HYPRLAND_INSTANCE_SIGNATURE='{}' XDPH_WINDOW_SHARING_LIST='{}' hyprland-share-picker 2>&1", std::format("WAYLAND_DISPLAY='{}' QT_QPA_PLATFORM='wayland' XCURSOR_SIZE='{}' HYPRLAND_INSTANCE_SIGNATURE='{}' XDPH_WINDOW_SHARING_LIST='{}' hyprland-share-picker{} 2>&1",
WAYLAND_DISPLAY ? WAYLAND_DISPLAY : "", XCURSOR_SIZE ? XCURSOR_SIZE : "24", HYPRLAND_INSTANCE_SIGNATURE ? HYPRLAND_INSTANCE_SIGNATURE : "0", buildWindowList()); WAYLAND_DISPLAY ? WAYLAND_DISPLAY : "", XCURSOR_SIZE ? XCURSOR_SIZE : "24", HYPRLAND_INSTANCE_SIGNATURE ? HYPRLAND_INSTANCE_SIGNATURE : "0", buildWindowList(),
(**PALLOWTOKENBYDEFAULT ? " --allow-token" : ""));
const auto RETVAL = execAndGet(cmd.c_str()); const auto RETVAL = execAndGet(cmd.c_str());