diff --git a/CMakeLists.txt b/CMakeLists.txt index bc103cd..d47af23 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,5 +28,4 @@ target_link_libraries(lumid Qt5::Widgets ${QTX_CORE_LIB} ${QTX_WIDGETS_LIB} - ) - +) diff --git a/Main.cpp b/Main.cpp index b5fee9d..96de75c 100644 --- a/Main.cpp +++ b/Main.cpp @@ -1,27 +1,16 @@ #include -#include -#include -#include -#include -#include -#include -#include #include -#include -#include -#include -#include -#include +#include #include "MainWindow.hpp" #include "PreferencesWindow.hpp" #include "TrayMenu.hpp" /** - * @brief - * Here we initilize our program and handle all external - * couplings between MainWindow, TrayIcon, TrayMenu and - * PreferencesWindow Objects. + * @brief + * Here we initilize our program and handle all external + * couplings between MainWindow, TrayIcon, TrayMenu and + * PreferencesWindow Objects. */ int main(int argc, char* argv[]) { QApplication app(argc, argv); @@ -37,7 +26,7 @@ int main(int argc, char* argv[]) { preferencesWindow.setWindowFlags(preferencesWindow.windowFlags() | Qt::WindowStaysOnTopHint); // set up tray icon - // trayIcon.setIcon(QIcon("/usr/share/icons/lumid.png")); + // trayIcon.setIcon(QIcon("/usr/share/icons/lumid.png")); trayIcon.setIcon(QIcon("../assets/icon-2nd-version.png")); trayIcon.setContextMenu(&trayMenu); trayIcon.show(); @@ -52,7 +41,6 @@ int main(int argc, char* argv[]) { } }); - QObject::connect(preferencesWindow.applyButton, &QPushButton::clicked, &preferencesWindow, [&]() { mainWindow.setStride(preferencesWindow.spinbox->value()); diff --git a/MainWindow.cpp b/MainWindow.cpp index 432b4b5..b086df0 100644 --- a/MainWindow.cpp +++ b/MainWindow.cpp @@ -4,18 +4,11 @@ #include "MainWindow.hpp" -#include -#include -#include -#include -#include -#include -#include +#include +#include #include -#include #include #include -#include #include #include "PreferencesWindow.hpp" @@ -72,7 +65,7 @@ MainWindow::MainWindow() { connect(&hideButton, &QPushButton::clicked, this, [=]() { MainWindow::hideOtherSliders(); }); - subLayoutsVex.at(0)->addWidget(&hideButton); + sliderLayouts.at(0)->addWidget(&hideButton); installEventFilter(this); @@ -85,11 +78,11 @@ MainWindow::MainWindow() { decreaseShortcut.get()); this->setWindowFlags( - Qt::Window | // make the widget a window - Qt::FramelessWindowHint | // disable title bar and buttons on it - Qt::Tool | // prevent showing in dock + Qt::Window | // make the widget a window + Qt::FramelessWindowHint | // disable title bar and buttons on it + Qt::Tool | // prevent showing in dock // Qt::WindowDoesNotAcceptFocus | // prevent dock showing up but the window is not on top - Qt::WindowStaysOnTopHint); // make the window on top layer + Qt::WindowStaysOnTopHint); // make the window on top layer } void MainWindow::shortCutsKeyPressed(BrightnessSlider *slider, int stride) { @@ -161,40 +154,40 @@ void MainWindow::initAllLayouts() { // init main layout // make unique directly, don't use std::unique_ptr ptr = make_unique... // that it will be deleted out of scope - subLayoutsVex.emplace_back(std::make_unique()); - initLayout(subLayoutsVex.at(0).get(), info, 0, true); - subLayoutsVex.at(0)->m_DisplayNameLabel.setText("General"); + sliderLayouts.emplace_back(std::make_unique()); + initLayout(sliderLayouts.at(0).get(), info, 0, true); + sliderLayouts.at(0)->m_DisplayNameLabel.setText("General"); // init the timer for main slider generalSliderTimer = std::make_unique(); generalSliderTimer->setSingleShot(true); connect(generalSliderTimer.get(), &QTimer::timeout, this, [&]() { - int value = subLayoutsVex.at(0)->m_Slider.value(); + int value = sliderLayouts.at(0)->m_Slider.value(); for (int i = 0; i < displayCount; ++i) { - subLayoutsVex.at(i + 1)->m_Slider.setValue(value); + sliderLayouts.at(i + 1)->m_Slider.setValue(value); } - subLayoutsVex.at(0)->m_BrightnessLabel.setText(QString::number(value)); + sliderLayouts.at(0)->m_BrightnessLabel.setText(QString::number(value)); }); - connect(&(subLayoutsVex.at(0)->m_Slider), &QSlider::valueChanged, this, + connect(&(sliderLayouts.at(0)->m_Slider), &QSlider::valueChanged, this, [=](int value) { generalSliderTimer->start(300); - subLayoutsVex.at(0)->m_BrightnessLabel.setText( + sliderLayouts.at(0)->m_BrightnessLabel.setText( QString::number(value)); }); // init the unique ptrs for (int i = 0; i < info.size(); ++i) { - subLayoutsVex.emplace_back(std::make_unique()); + sliderLayouts.emplace_back(std::make_unique()); } // init except for main layout int j = 0; for (int i = 1; i < info.size() + 1; ++i, ++j) { - initLayout(subLayoutsVex.at(i).get(), info, j, false); + initLayout(sliderLayouts.at(i).get(), info, j, false); - connect(&(subLayoutsVex.at(i)->m_Slider), &QSlider::valueChanged, this, + connect(&(sliderLayouts.at(i)->m_Slider), &QSlider::valueChanged, this, [=](int value) { QStringList args; QString newValue = QString::number(value); @@ -224,7 +217,7 @@ void MainWindow::initAllLayouts() { << "ddcutil" << "setvcp" << "10" << arguments); - subLayoutsVex.at(i)->m_BrightnessLabel.setText( + sliderLayouts.at(i)->m_BrightnessLabel.setText( QString::number(value)); }); } @@ -273,11 +266,11 @@ void MainWindow::hideOtherSliders() { if (other_sliders_hidden) { performHideAndChangeButtonText("Focus", "Lumid", other_sliders_hidden, &hideButton, &m_MainLayout, - &subLayoutsVex); + &sliderLayouts); return; } performHideAndChangeButtonText("Show All", " ", other_sliders_hidden, - &hideButton, &m_MainLayout, &subLayoutsVex); + &hideButton, &m_MainLayout, &sliderLayouts); } void MainWindow::performHideAndChangeButtonText( @@ -301,11 +294,11 @@ void MainWindow::switchVisibility(SliderWithLabelsLayout *layout, } BrightnessSlider *MainWindow::generalSlider() { - return &subLayoutsVex.at(0).get()->m_Slider; + return &sliderLayouts.at(0).get()->m_Slider; } void MainWindow::addLayouts() { - for (const auto &i : subLayoutsVex) { + for (const auto &i : sliderLayouts) { m_MainLayout.addLayout(i.get()); } } diff --git a/MainWindow.hpp b/MainWindow.hpp index d054c93..ae8a728 100644 --- a/MainWindow.hpp +++ b/MainWindow.hpp @@ -5,16 +5,8 @@ #ifndef LUMID_MAINWINDOW_H #define LUMID_MAINWINDOW_H -#include -#include -#include -#include #include -#include -#include -#include #include -#include #include #include @@ -34,7 +26,7 @@ using namespace Wrappers; class MainWindow : public QWidget { public: MainWindow(); - + QTimer m_Timer; PreferencesWindow *m_PreferencesWindow; @@ -57,12 +49,10 @@ class MainWindow : public QWidget { int posY; bool other_sliders_hidden = true; int stride = 10; - // QSystemTrayIcon trayIcon; SlidersHBoxLayout m_MainLayout; ShowAllAndFocusButton hideButton; QTimer click_tmr; - // TrayMenu m_TrayMenu; std::unique_ptr increaseShortcut = std::make_unique(Qt::Key_F6); std::unique_ptr decreaseShortcut = std::make_unique(Qt::Key_F5); @@ -71,7 +61,7 @@ class MainWindow : public QWidget { BrightnessSlider *generalSlider(); - std::vector> subLayoutsVex; + std::vector> sliderLayouts; std::unique_ptr generalSliderTimer; @@ -83,7 +73,7 @@ class MainWindow : public QWidget { void addLayouts(); - // void closeEvent(QCloseEvent *event) override; + // void closeEvent(QCloseEvent *event) override; static void switchVisibility(SliderWithLabelsLayout *layout, bool visible); diff --git a/PreferencesWindow.cpp b/PreferencesWindow.cpp index ec92a00..9935074 100644 --- a/PreferencesWindow.cpp +++ b/PreferencesWindow.cpp @@ -65,7 +65,6 @@ void PreferencesWindow::closeEvent(QCloseEvent* event) { hide(); } - void PreferencesWindow::showEvent(QShowEvent* event) { QDialog::showEvent(event); diff --git a/PreferencesWindow.hpp b/PreferencesWindow.hpp index 38006f9..244edf4 100644 --- a/PreferencesWindow.hpp +++ b/PreferencesWindow.hpp @@ -14,7 +14,6 @@ #ifndef LUMID_PREFERENCESWINDOW_HPP #define LUMID_PREFERENCESWINDOW_HPP -#include #include #include #include @@ -24,7 +23,6 @@ class PreferencesWindow : public QDialog { public: - // In C++, you generally only provide default values // for arguments in the function declaration, not in // the function definition. diff --git a/README.md b/README.md index f052919..763f657 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,25 @@ # Lumid + A simple Qt GUI that adjusts the display brightness for Linux desktop using [ddcutil](https://github.com/rockowitz/ddcutil).
+ ## Screenshots + ![UI](assets/focus.png)     ![UI](assets/showAll.png) ## Build + 1. Install ddcutil: `dnf install ddcutil` 2. You may need to change the Qt version in CMakeLists.txt to the one you are using. -3. ddcutil requires sudo. You may need to adjust your system settings to avoid entering password. One method could be: +3. ddcutil requires sudo. You may need to adjust your system settings to avoid entering password. One method could be: `sudo visudo` in terminal, comment out `%wheel ALL=(ALL) ALL` and comment in `%wheel ALL=(ALL) NOPASSWD: ALL`. 4. Global shortcuts requires Qxt Libraries. You can install them using your package manager. For example on Fedora:
`sudo dnf install libqxt-qt5-devel.x86_64` ## Use + This app has only been tested on my own Fedora 37 desktop with GNOME 43.7. I wrote this because the other extensions/apps did not meet my personal requirement of simplicity and less lagging when adjusting the brightness. >**Note: The default keyboard shortcuts for increasing and decreasing brightness are F6 and F5, respectively.** ## Known Issues -Title bar color does not change along with system theme. - +Title bar color does not change along with system theme. diff --git a/TrayMenu.cpp b/TrayMenu.cpp index bdc567d..b106691 100644 --- a/TrayMenu.cpp +++ b/TrayMenu.cpp @@ -1,10 +1,7 @@ #include "TrayMenu.hpp" #include -#include -#include -#include -#include +#include #include "MainWindow.hpp" #include "PreferencesWindow.hpp" @@ -24,8 +21,7 @@ TrayMenu::TrayMenu() { void TrayMenu::connectSignals(MainWindow* mainWindow, PreferencesWindow* prefsWindow) { // use "=" to capture ptr to ensure to have a copy connect(m_Open.get(), &QAction::triggered, this, [=]() { mainWindow->showOnTopLeft(); }); - connect(m_OpenDisplaySetting.get(), &QAction::triggered, this, []() { - QProcess::startDetached("gnome-control-center", QStringList() << "display"); }); + connect(m_OpenDisplaySetting.get(), &QAction::triggered, this, []() { QProcess::startDetached("gnome-control-center", QStringList() << "display"); }); connect(m_Preferences.get(), &QAction::triggered, this, [=]() { // catch pointer by value! prefsWindow->show(); prefsWindow->raise(); diff --git a/TrayMenu.hpp b/TrayMenu.hpp index 29ec76a..eaf859e 100644 --- a/TrayMenu.hpp +++ b/TrayMenu.hpp @@ -3,11 +3,9 @@ #include #include -#include -#include -#include "PreferencesWindow.hpp" #include "MainWindow.hpp" +#include "PreferencesWindow.hpp" class TrayMenu : public QMenu { public: @@ -21,7 +19,7 @@ class TrayMenu : public QMenu { std::unique_ptr m_Exit; - void connectSignals(MainWindow *mainWindow, PreferencesWindow* prefsWindow); + void connectSignals(MainWindow* mainWindow, PreferencesWindow* prefsWindow); }; #endif \ No newline at end of file diff --git a/Wrappers.cpp b/Wrappers.cpp index b677486..adadf8d 100644 --- a/Wrappers.cpp +++ b/Wrappers.cpp @@ -4,14 +4,6 @@ #include "Wrappers.hpp" -#include -#include -#include -#include -#include -#include -#include - #include "MainWindow.hpp" #include "PreferencesWindow.hpp" diff --git a/Wrappers.hpp b/Wrappers.hpp index 6605f5f..802a0b0 100644 --- a/Wrappers.hpp +++ b/Wrappers.hpp @@ -5,16 +5,10 @@ #ifndef LUMID_WRAPPERS_HPP #define LUMID_WRAPPERS_HPP -#include -#include #include -#include #include -#include #include #include -#include -#include #include #include "PreferencesWindow.hpp"