picker: Allow dialog resizing (#173)

* picker: Allow dialog resizing

* picker: Smaller dialog and remember size changes

* picker: Save size in temp files
This commit is contained in:
rurigk 2024-01-28 06:51:53 -06:00 committed by GitHub
parent 5a59264758
commit f29e046456
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 288 additions and 156 deletions

View file

@ -7,6 +7,7 @@
#include <QWidget> #include <QWidget>
#include <QtDebug> #include <QtDebug>
#include <QtWidgets> #include <QtWidgets>
#include <QSettings>
#include <array> #include <array>
#include <cstdio> #include <cstdio>
#include <iostream> #include <iostream>
@ -84,21 +85,24 @@ int main(int argc, char* argv[]) {
MainPicker w; MainPicker w;
mainPickerPtr = &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 // get the tabwidget
const auto TABWIDGET = (QTabWidget*)w.children()[1]->children()[0]; const auto TABWIDGET = w.findChild<QTabWidget *>("tabWidget");
const auto ALLOWTOKENBUTTON = (QCheckBox*)w.children()[1]->children()[1]; const auto ALLOWTOKENBUTTON = w.findChild<QCheckBox *>("checkBox");
const auto TAB1 = (QWidget*)TABWIDGET->children()[0]; const auto TAB1 = (QWidget*)TABWIDGET->children()[0];
const auto SCREENS_SCROLL_AREA_CONTENTS = const auto SCREENS_SCROLL_AREA_CONTENTS =
(QWidget*)TAB1->findChild<QWidget*>("screens")->findChild<QScrollArea*>("scrollArea")->findChild<QWidget*>("scrollAreaWidgetContents"); (QWidget*)TAB1->findChild<QWidget*>("screens")->findChild<QScrollArea*>("scrollArea")->findChild<QWidget*>("scrollAreaWidgetContents");
const auto SCREENS_SCROLL_AREA_CONTENTS_LAYOUT = SCREENS_SCROLL_AREA_CONTENTS->layout();
// add all screens // add all screens
const auto SCREENS = picker.screens(); const auto SCREENS = picker.screens();
constexpr int BUTTON_WIDTH = 441;
constexpr int BUTTON_HEIGHT = 41; constexpr int BUTTON_HEIGHT = 41;
constexpr int BUTTON_PAD = 4;
for (int i = 0; i < SCREENS.size(); ++i) { for (int i = 0; i < SCREENS.size(); ++i) {
const auto GEOMETRY = SCREENS[i]->geometry(); 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()) + " (" + 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()) + ") (") + std::to_string(GEOMETRY.width()) + "x" + std::to_string(GEOMETRY.height()) + ") (") +
SCREENS[i]->name().toStdString() + ")"); SCREENS[i]->name().toStdString() + ")");
QPushButton* button = new QPushButton(text, (QWidget*)SCREENS_SCROLL_AREA_CONTENTS); QPushButton* button = new QPushButton(text);
button->move(9, 5 + (BUTTON_HEIGHT + BUTTON_PAD) * i); SCREENS_SCROLL_AREA_CONTENTS_LAYOUT->addWidget(button);
button->resize(BUTTON_WIDTH, BUTTON_HEIGHT); button->setMinimumSize(0, BUTTON_HEIGHT);
QObject::connect(button, &QPushButton::clicked, [=]() { QObject::connect(button, &QPushButton::clicked, [=]() {
std::string ID = button->text().toStdString(); std::string ID = button->text().toStdString();
ID = ID.substr(ID.find_last_of('(') + 1); ID = ID.substr(ID.find_last_of('(') + 1);
@ -119,25 +123,33 @@ int main(int argc, char* argv[]) {
std::cout << "/"; std::cout << "/";
std::cout << "screen:" << ID << "\n"; std::cout << "screen:" << ID << "\n";
settings->setValue("width", mainPickerPtr->width());
settings->setValue("height", mainPickerPtr->height());
settings->sync();
pickerPtr->quit(); pickerPtr->quit();
return 0; 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 // windows
const auto WINDOWS_SCROLL_AREA_CONTENTS = const auto WINDOWS_SCROLL_AREA_CONTENTS =
(QWidget*)TAB1->findChild<QWidget*>("windows")->findChild<QScrollArea*>("scrollArea_2")->findChild<QWidget*>("scrollAreaWidgetContents_2"); (QWidget*)TAB1->findChild<QWidget*>("windows")->findChild<QScrollArea*>("scrollArea_2")->findChild<QWidget*>("scrollAreaWidgetContents_2");
const auto WINDOWS_SCROLL_AREA_CONTENTS_LAYOUT = WINDOWS_SCROLL_AREA_CONTENTS->layout();
// loop over them // loop over them
int windowIterator = 0; int windowIterator = 0;
for (auto& window : WINDOWLIST) { for (auto& window : WINDOWLIST) {
QString text = QString::fromStdString(window.clazz + ": " + window.name); QString text = QString::fromStdString(window.clazz + ": " + window.name);
QPushButton* button = new QPushButton(text, (QWidget*)WINDOWS_SCROLL_AREA_CONTENTS); QPushButton* button = new QPushButton(text);
button->move(9, 5 + (BUTTON_HEIGHT + BUTTON_PAD) * windowIterator); WINDOWS_SCROLL_AREA_CONTENTS_LAYOUT->addWidget(button);
button->resize(BUTTON_WIDTH, BUTTON_HEIGHT); button->setMinimumSize(0, BUTTON_HEIGHT);
mainPickerPtr->windowIDs[button] = window.id; mainPickerPtr->windowIDs[button] = window.id;
@ -147,6 +159,11 @@ int main(int argc, char* argv[]) {
std::cout << "/"; std::cout << "/";
std::cout << "window:" << mainPickerPtr->windowIDs[button] << "\n"; std::cout << "window:" << mainPickerPtr->windowIDs[button] << "\n";
settings->setValue("width", mainPickerPtr->width());
settings->setValue("height", mainPickerPtr->height());
settings->sync();
pickerPtr->quit(); pickerPtr->quit();
return 0; return 0;
}); });
@ -154,16 +171,25 @@ int main(int argc, char* argv[]) {
windowIterator++; 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 // lastly, region
const auto REGION_OBJECT = (QWidget*)TAB1->findChild<QWidget*>("region"); const auto REGION_OBJECT = (QWidget*)TAB1->findChild<QWidget*>("region");
const auto REGION_LAYOUT = REGION_OBJECT->layout();
QString text = "Select region..."; QString text = "Select region...";
QPushButton* button = new QPushButton(text, (QWidget*)REGION_OBJECT); QSpacerItem * REGION_L_SPACER = new QSpacerItem(10000,0, QSizePolicy::Expanding, QSizePolicy::Expanding);
button->move(79, 80); QSpacerItem * REGION_R_SPACER = new QSpacerItem(10000,0, QSizePolicy::Expanding, QSizePolicy::Expanding);
button->resize(321, 41);
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, [=]() { 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());
@ -206,6 +232,11 @@ int main(int argc, char* argv[]) {
std::cout << "/"; std::cout << "/";
std::cout << "region:" << SCREEN_NAME << "@" << X - pScreen->geometry().x() << "," << Y - pScreen->geometry().y() << "," << W << "," << H << "\n"; 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(); pickerPtr->quit();
return 0; return 0;
} catch (...) { } catch (...) {

View file

@ -7,9 +7,15 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>500</width> <width>500</width>
<height>290</height> <height>300</height>
</rect> </rect>
</property> </property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>500</width> <width>500</width>
@ -18,163 +24,258 @@
</property> </property>
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
<width>500</width> <width>1280</width>
<height>290</height> <height>800</height>
</size> </size>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>MainPicker</string> <string>MainPicker</string>
</property> </property>
<widget class="QWidget" name="centralwidget"> <widget class="QWidget" name="centralwidget">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize"> <property name="minimumSize">
<size> <size>
<width>500</width> <width>0</width>
<height>290</height> <height>0</height>
</size> </size>
</property> </property>
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
<width>500</width> <width>1280</width>
<height>290</height> <height>800</height>
</size> </size>
</property> </property>
<widget class="QTabWidget" name="tabWidget"> <layout class="QVBoxLayout" name="verticalLayout_2">
<property name="geometry"> <item>
<rect> <layout class="QVBoxLayout" name="verticalLayout">
<x>0</x> <item>
<y>0</y> <widget class="QTabWidget" name="tabWidget">
<width>500</width> <property name="sizePolicy">
<height>290</height> <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
</rect> <horstretch>0</horstretch>
</property> <verstretch>0</verstretch>
<property name="minimumSize"> </sizepolicy>
<size> </property>
<width>500</width> <property name="minimumSize">
<height>290</height> <size>
</size> <width>0</width>
</property> <height>0</height>
<property name="maximumSize"> </size>
<size> </property>
<width>500</width> <property name="maximumSize">
<height>290</height> <size>
</size> <width>16777215</width>
</property> <height>16777215</height>
<property name="toolTip"> </size>
<string/> </property>
</property> <property name="focusPolicy">
<property name="tabPosition"> <enum>Qt::StrongFocus</enum>
<enum>QTabWidget::North</enum> </property>
</property> <property name="toolTip">
<property name="currentIndex"> <string/>
<number>0</number> </property>
</property> <property name="tabPosition">
<widget class="QWidget" name="screens"> <enum>QTabWidget::North</enum>
<attribute name="title"> </property>
<string>Screen</string> <property name="currentIndex">
</attribute> <number>0</number>
<widget class="QScrollArea" name="scrollArea"> </property>
<property name="geometry"> <widget class="QWidget" name="screens">
<rect> <property name="sizePolicy">
<x>9</x> <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<y>9</y> <horstretch>0</horstretch>
<width>461</width> <verstretch>0</verstretch>
<height>201</height> </sizepolicy>
</rect> </property>
</property> <property name="layoutDirection">
<property name="horizontalScrollBarPolicy"> <enum>Qt::LeftToRight</enum>
<enum>Qt::ScrollBarAlwaysOff</enum> </property>
</property> <attribute name="title">
<property name="widgetResizable"> <string>Screen</string>
<bool>false</bool> </attribute>
</property> <layout class="QGridLayout" name="gridLayout_2">
<widget class="QWidget" name="scrollAreaWidgetContents"> <item row="0" column="0">
<property name="geometry"> <widget class="QScrollArea" name="scrollArea">
<rect> <property name="sizePolicy">
<x>0</x> <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<y>0</y> <horstretch>0</horstretch>
<width>459</width> <verstretch>0</verstretch>
<height>239</height> </sizepolicy>
</rect> </property>
</property> <property name="focusPolicy">
<property name="minimumSize"> <enum>Qt::NoFocus</enum>
<size> </property>
<width>459</width> <property name="horizontalScrollBarPolicy">
<height>239</height> <enum>Qt::ScrollBarAlwaysOff</enum>
</size> </property>
</property> <property name="sizeAdjustPolicy">
<property name="focusPolicy"> <enum>QAbstractScrollArea::AdjustIgnored</enum>
<enum>Qt::WheelFocus</enum> </property>
</property> <property name="widgetResizable">
</widget> <bool>true</bool>
</widget> </property>
</widget> <property name="alignment">
<widget class="QWidget" name="windows"> <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
<attribute name="title"> </property>
<string>Window</string> <widget class="QWidget" name="scrollAreaWidgetContents">
</attribute> <property name="enabled">
<widget class="QScrollArea" name="scrollArea_2"> <bool>true</bool>
<property name="geometry"> </property>
<rect> <property name="geometry">
<x>9</x> <rect>
<y>9</y> <x>0</x>
<width>461</width> <y>0</y>
<height>201</height> <width>410</width>
</rect> <height>18</height>
</property> </rect>
<property name="horizontalScrollBarPolicy"> </property>
<enum>Qt::ScrollBarAlwaysOff</enum> <property name="sizePolicy">
</property> <sizepolicy hsizetype="Ignored" vsizetype="Maximum">
<property name="widgetResizable"> <horstretch>0</horstretch>
<bool>false</bool> <verstretch>0</verstretch>
</property> </sizepolicy>
<widget class="QWidget" name="scrollAreaWidgetContents_2"> </property>
<property name="geometry"> <property name="minimumSize">
<rect> <size>
<x>0</x> <width>0</width>
<y>0</y> <height>0</height>
<width>459</width> </size>
<height>239</height> </property>
</rect> <property name="maximumSize">
</property> <size>
<property name="minimumSize"> <width>16777215</width>
<size> <height>16777215</height>
<width>459</width> </size>
<height>239</height> </property>
</size> <property name="focusPolicy">
</property> <enum>Qt::NoFocus</enum>
<property name="focusPolicy"> </property>
<enum>Qt::WheelFocus</enum> <layout class="QVBoxLayout" name="screensScrollAreaLayout">
</property> <property name="spacing">
</widget> <number>6</number>
</widget> </property>
</widget> <property name="sizeConstraint">
<widget class="QWidget" name="region"> <enum>QLayout::SetDefaultConstraint</enum>
<attribute name="title"> </property>
<string>Region</string> </layout>
</attribute> </widget>
</widget> </widget>
</widget> </item>
<widget class="QCheckBox" name="checkBox"> </layout>
<property name="geometry"> </widget>
<rect> <widget class="QWidget" name="windows">
<x>340</x> <property name="sizePolicy">
<y>256</y> <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<width>140</width> <horstretch>0</horstretch>
<height>21</height> <verstretch>0</verstretch>
</rect> </sizepolicy>
</property> </property>
<property name="toolTip"> <attribute name="title">
<string>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.</string> <string>Window</string>
</property> </attribute>
<property name="text"> <layout class="QGridLayout" name="gridLayout_3">
<string>Allow a restore token</string> <item row="0" column="0">
</property> <widget class="QScrollArea" name="scrollArea_2">
</widget> <property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="horizontalScrollBarPolicy">
<enum>Qt::ScrollBarAlwaysOff</enum>
</property>
<property name="widgetResizable">
<bool>true</bool>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents_2">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>410</width>
<height>18</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Ignored" vsizetype="Maximum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<layout class="QVBoxLayout" name="windowsScrollAreaLayout"/>
</widget>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="region">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>730</width>
<height>224</height>
</size>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<attribute name="title">
<string>Region</string>
</attribute>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
</layout>
</widget>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox">
<property name="focusPolicy">
<enum>Qt::ClickFocus</enum>
</property>
<property name="toolTip">
<string>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.</string>
</property>
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>Allow a restore token</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget> </widget>
</widget> </widget>
<tabstops> <tabstops>
<tabstop>scrollArea</tabstop>
<tabstop>scrollArea_2</tabstop>
<tabstop>tabWidget</tabstop> <tabstop>tabWidget</tabstop>
</tabstops> </tabstops>
<resources/> <resources/>