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,9 +77,14 @@ std::vector<SWindowEntry> getWindows(const char* env) {
int main(int argc, char* argv[]) {
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 auto WINDOWLIST = getWindows(WINDOWLISTSTR);
const char* WINDOWLISTSTR = getenv("XDPH_WINDOW_SHARING_LIST");
const auto WINDOWLIST = getWindows(WINDOWLISTSTR);
QApplication picker(argc, argv);
pickerPtr = &picker;
@ -90,8 +95,11 @@ int main(int argc, char* argv[]) {
w.setGeometry(0, 0, settings->value("width").toInt(), settings->value("height").toInt());
// get the tabwidget
const auto TABWIDGET = w.findChild<QTabWidget *>("tabWidget");
const auto ALLOWTOKENBUTTON = w.findChild<QCheckBox *>("checkBox");
const auto TABWIDGET = w.findChild<QTabWidget*>("tabWidget");
const auto ALLOWTOKENBUTTON = w.findChild<QCheckBox*>("checkBox");
if (allowTokenByDefault)
ALLOWTOKENBUTTON->setCheckState(Qt::CheckState::Checked);
const auto TAB1 = (QWidget*)TABWIDGET->children()[0];
@ -106,13 +114,13 @@ int main(int argc, char* argv[]) {
constexpr int BUTTON_HEIGHT = 41;
for (int i = 0; i < SCREENS.size(); ++i) {
const auto GEOMETRY = SCREENS[i]->geometry();
const auto GEOMETRY = SCREENS[i]->geometry();
QString text = QString::fromStdString(std::string("Screen " + std::to_string(i) + " at " + std::to_string(GEOMETRY.x()) + ", " + std::to_string(GEOMETRY.y()) + " (" +
std::to_string(GEOMETRY.width()) + "x" + std::to_string(GEOMETRY.height()) + ") (") +
SCREENS[i]->name().toStdString() + ")");
QString outputName = SCREENS[i]->name();
ElidedButton* button = new ElidedButton(text);
QString text = QString::fromStdString(std::string("Screen " + std::to_string(i) + " at " + std::to_string(GEOMETRY.x()) + ", " + std::to_string(GEOMETRY.y()) + " (" +
std::to_string(GEOMETRY.width()) + "x" + std::to_string(GEOMETRY.height()) + ") (") +
SCREENS[i]->name().toStdString() + ")");
QString outputName = SCREENS[i]->name();
ElidedButton* button = new ElidedButton(text);
button->setMinimumSize(0, BUTTON_HEIGHT);
SCREENS_SCROLL_AREA_CONTENTS_LAYOUT->addWidget(button);
@ -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);
// windows
@ -144,7 +152,7 @@ int main(int argc, char* argv[]) {
// loop over them
int windowIterator = 0;
for (auto& window : WINDOWLIST) {
QString text = QString::fromStdString(window.clazz + ": " + window.name);
QString text = QString::fromStdString(window.clazz + ": " + window.name);
ElidedButton* button = new ElidedButton(text);
button->setMinimumSize(0, BUTTON_HEIGHT);
@ -170,20 +178,19 @@ int main(int argc, char* argv[]) {
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);
// lastly, region
const auto REGION_OBJECT = (QWidget*)TAB1->findChild<QWidget*>("region");
const auto REGION_LAYOUT = REGION_OBJECT->layout();
const auto REGION_OBJECT = (QWidget*)TAB1->findChild<QWidget*>("region");
const auto REGION_LAYOUT = REGION_OBJECT->layout();
QString text = "Select region...";
QString text = "Select region...";
ElidedButton* button = new ElidedButton(text);
button->setMaximumSize(400, BUTTON_HEIGHT);
REGION_LAYOUT->addWidget(button);
QObject::connect(button, &QPushButton::clicked, [=]() {
auto REGION = execAndGet("slurp -f \"%o %x %y %w %h\"");
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("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->parse();

View file

@ -36,17 +36,21 @@ std::string buildWindowList() {
}
SSelectionData promptForScreencopySelection() {
SSelectionData data;
SSelectionData data;
const char* WAYLAND_DISPLAY = getenv("WAYLAND_DISPLAY");
const char* XCURSOR_SIZE = getenv("XCURSOR_SIZE");
const char* HYPRLAND_INSTANCE_SIGNATURE = getenv("HYPRLAND_INSTANCE_SIGNATURE");
const char* WAYLAND_DISPLAY = getenv("WAYLAND_DISPLAY");
const char* XCURSOR_SIZE = getenv("XCURSOR_SIZE");
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 /)
// TODO: this is dumb, use a pipe or something.
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",
WAYLAND_DISPLAY ? WAYLAND_DISPLAY : "", XCURSOR_SIZE ? XCURSOR_SIZE : "24", HYPRLAND_INSTANCE_SIGNATURE ? HYPRLAND_INSTANCE_SIGNATURE : "0", buildWindowList());
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(),
(**PALLOWTOKENBYDEFAULT ? " --allow-token" : ""));
const auto RETVAL = execAndGet(cmd.c_str());