From f29e0464561e7cc3b033daaf5ccb7c64e0de55e8 Mon Sep 17 00:00:00 2001 From: rurigk Date: Sun, 28 Jan 2024 06:51:53 -0600 Subject: [PATCH] picker: Allow dialog resizing (#173) * picker: Allow dialog resizing * picker: Smaller dialog and remember size changes * picker: Save size in temp files --- hyprland-share-picker/main.cpp | 61 +++-- hyprland-share-picker/mainpicker.ui | 383 ++++++++++++++++++---------- 2 files changed, 288 insertions(+), 156 deletions(-) diff --git a/hyprland-share-picker/main.cpp b/hyprland-share-picker/main.cpp index d102165..31d3c19 100644 --- a/hyprland-share-picker/main.cpp +++ b/hyprland-share-picker/main.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -84,21 +85,24 @@ int main(int argc, char* argv[]) { MainPicker w; mainPickerPtr = &w; + QSettings* settings = new QSettings("/tmp/hypr/hyprland-share-picker.conf", QSettings::IniFormat); + w.setGeometry(0, 0, settings->value("width").toInt(), settings->value("height").toInt()); + // get the tabwidget - const auto TABWIDGET = (QTabWidget*)w.children()[1]->children()[0]; - const auto ALLOWTOKENBUTTON = (QCheckBox*)w.children()[1]->children()[1]; + const auto TABWIDGET = w.findChild("tabWidget"); + const auto ALLOWTOKENBUTTON = w.findChild("checkBox"); const auto TAB1 = (QWidget*)TABWIDGET->children()[0]; const auto SCREENS_SCROLL_AREA_CONTENTS = (QWidget*)TAB1->findChild("screens")->findChild("scrollArea")->findChild("scrollAreaWidgetContents"); + const auto SCREENS_SCROLL_AREA_CONTENTS_LAYOUT = SCREENS_SCROLL_AREA_CONTENTS->layout(); + // add all screens const auto SCREENS = picker.screens(); - constexpr int BUTTON_WIDTH = 441; constexpr int BUTTON_HEIGHT = 41; - constexpr int BUTTON_PAD = 4; for (int i = 0; i < SCREENS.size(); ++i) { const auto GEOMETRY = SCREENS[i]->geometry(); @@ -106,9 +110,9 @@ int main(int argc, char* argv[]) { 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() + ")"); - QPushButton* button = new QPushButton(text, (QWidget*)SCREENS_SCROLL_AREA_CONTENTS); - button->move(9, 5 + (BUTTON_HEIGHT + BUTTON_PAD) * i); - button->resize(BUTTON_WIDTH, BUTTON_HEIGHT); + QPushButton* button = new QPushButton(text); + SCREENS_SCROLL_AREA_CONTENTS_LAYOUT->addWidget(button); + button->setMinimumSize(0, BUTTON_HEIGHT); QObject::connect(button, &QPushButton::clicked, [=]() { std::string ID = button->text().toStdString(); ID = ID.substr(ID.find_last_of('(') + 1); @@ -119,25 +123,33 @@ int main(int argc, char* argv[]) { std::cout << "/"; std::cout << "screen:" << ID << "\n"; + + settings->setValue("width", mainPickerPtr->width()); + settings->setValue("height", mainPickerPtr->height()); + settings->sync(); + pickerPtr->quit(); return 0; }); } - SCREENS_SCROLL_AREA_CONTENTS->resize(SCREENS_SCROLL_AREA_CONTENTS->size().width(), 5 + (BUTTON_HEIGHT + BUTTON_PAD) * SCREENS.size()); + QSpacerItem * SCREENS_SPACER = new QSpacerItem(0,10000, QSizePolicy::Expanding, QSizePolicy::Expanding); + SCREENS_SCROLL_AREA_CONTENTS_LAYOUT->addItem(SCREENS_SPACER); // windows const auto WINDOWS_SCROLL_AREA_CONTENTS = (QWidget*)TAB1->findChild("windows")->findChild("scrollArea_2")->findChild("scrollAreaWidgetContents_2"); + const auto WINDOWS_SCROLL_AREA_CONTENTS_LAYOUT = WINDOWS_SCROLL_AREA_CONTENTS->layout(); + // loop over them int windowIterator = 0; for (auto& window : WINDOWLIST) { QString text = QString::fromStdString(window.clazz + ": " + window.name); - QPushButton* button = new QPushButton(text, (QWidget*)WINDOWS_SCROLL_AREA_CONTENTS); - button->move(9, 5 + (BUTTON_HEIGHT + BUTTON_PAD) * windowIterator); - button->resize(BUTTON_WIDTH, BUTTON_HEIGHT); + QPushButton* button = new QPushButton(text); + WINDOWS_SCROLL_AREA_CONTENTS_LAYOUT->addWidget(button); + button->setMinimumSize(0, BUTTON_HEIGHT); mainPickerPtr->windowIDs[button] = window.id; @@ -147,6 +159,11 @@ int main(int argc, char* argv[]) { std::cout << "/"; std::cout << "window:" << mainPickerPtr->windowIDs[button] << "\n"; + + settings->setValue("width", mainPickerPtr->width()); + settings->setValue("height", mainPickerPtr->height()); + settings->sync(); + pickerPtr->quit(); return 0; }); @@ -154,16 +171,25 @@ int main(int argc, char* argv[]) { windowIterator++; } - WINDOWS_SCROLL_AREA_CONTENTS->resize(WINDOWS_SCROLL_AREA_CONTENTS->size().width(), 5 + (BUTTON_HEIGHT + BUTTON_PAD) * windowIterator); + 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("region"); + const auto REGION_LAYOUT = REGION_OBJECT->layout(); QString text = "Select region..."; - QPushButton* button = new QPushButton(text, (QWidget*)REGION_OBJECT); - button->move(79, 80); - button->resize(321, 41); + QSpacerItem * REGION_L_SPACER = new QSpacerItem(10000,0, QSizePolicy::Expanding, QSizePolicy::Expanding); + QSpacerItem * REGION_R_SPACER = new QSpacerItem(10000,0, QSizePolicy::Expanding, QSizePolicy::Expanding); + + REGION_LAYOUT->addItem(REGION_L_SPACER); + + QPushButton* button = new QPushButton(text); + REGION_LAYOUT->addWidget(button); + + REGION_LAYOUT->addItem(REGION_R_SPACER); + QObject::connect(button, &QPushButton::clicked, [=]() { auto REGION = execAndGet("slurp -f \"%o %x %y %w %h\""); REGION = REGION.substr(0, REGION.length()); @@ -206,6 +232,11 @@ int main(int argc, char* argv[]) { std::cout << "/"; std::cout << "region:" << SCREEN_NAME << "@" << X - pScreen->geometry().x() << "," << Y - pScreen->geometry().y() << "," << W << "," << H << "\n"; + + settings->setValue("width", mainPickerPtr->width()); + settings->setValue("height", mainPickerPtr->height()); + settings->sync(); + pickerPtr->quit(); return 0; } catch (...) { diff --git a/hyprland-share-picker/mainpicker.ui b/hyprland-share-picker/mainpicker.ui index 95a3c65..f6093d2 100644 --- a/hyprland-share-picker/mainpicker.ui +++ b/hyprland-share-picker/mainpicker.ui @@ -7,9 +7,15 @@ 0 0 500 - 290 + 300 + + + 0 + 0 + + 500 @@ -18,163 +24,258 @@ - 500 - 290 + 1280 + 800 MainPicker + + + 0 + 0 + + - 500 - 290 + 0 + 0 - 500 - 290 + 1280 + 800 - - - - 0 - 0 - 500 - 290 - - - - - 500 - 290 - - - - - 500 - 290 - - - - - - - QTabWidget::North - - - 0 - - - - Screen - - - - - 9 - 9 - 461 - 201 - - - - Qt::ScrollBarAlwaysOff - - - false - - - - - 0 - 0 - 459 - 239 - - - - - 459 - 239 - - - - Qt::WheelFocus - - - - - - - Window - - - - - 9 - 9 - 461 - 201 - - - - Qt::ScrollBarAlwaysOff - - - false - - - - - 0 - 0 - 459 - 239 - - - - - 459 - 239 - - - - Qt::WheelFocus - - - - - - - Region - - - - - - - 340 - 256 - 140 - 21 - - - - By selecting this, the application will be given a restore token that it can use to skip prompting you next time. Only select if you trust the application. - - - Allow a restore token - - + + + + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + Qt::StrongFocus + + + + + + QTabWidget::North + + + 0 + + + + + 0 + 0 + + + + Qt::LeftToRight + + + Screen + + + + + + + 0 + 0 + + + + Qt::NoFocus + + + Qt::ScrollBarAlwaysOff + + + QAbstractScrollArea::AdjustIgnored + + + true + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + true + + + + 0 + 0 + 410 + 18 + + + + + 0 + 0 + + + + + 0 + 0 + + + + + 16777215 + 16777215 + + + + Qt::NoFocus + + + + 6 + + + QLayout::SetDefaultConstraint + + + + + + + + + + + 0 + 0 + + + + Window + + + + + + Qt::NoFocus + + + Qt::ScrollBarAlwaysOff + + + true + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + 0 + 0 + 410 + 18 + + + + + 0 + 0 + + + + + 0 + 0 + + + + Qt::NoFocus + + + + + + + + + + + 0 + 0 + + + + + 730 + 224 + + + + Qt::LeftToRight + + + false + + + Region + + + + QLayout::SetDefaultConstraint + + + + + + + + + Qt::ClickFocus + + + By selecting this, the application will be given a restore token that it can use to skip prompting you next time. +Only select if you trust the application. + + + Qt::LeftToRight + + + Allow a restore token + + + + + + - scrollArea - scrollArea_2 tabWidget