Skip to content

Commit

Permalink
Clean includes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Q1CHENL committed Aug 30, 2023
1 parent 0c273f1 commit ff26516
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 93 deletions.
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,4 @@ target_link_libraries(lumid
Qt5::Widgets
${QTX_CORE_LIB}
${QTX_WIDGETS_LIB}
)

)
24 changes: 6 additions & 18 deletions Main.cpp
Original file line number Diff line number Diff line change
@@ -1,27 +1,16 @@
#include <QApplication>
#include <QBitmap>
#include <QCloseEvent>
#include <QDebug>
#include <QDialog>
#include <QFlags>
#include <QMenu>
#include <QMenuBar>
#include <QObject>
#include <QPainter>
#include <QScreen>
#include <QTimer>
#include <QxtGlobalShortcut>
#include <QDialog>
#include <QSystemTrayIcon>

#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);
Expand All @@ -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();
Expand All @@ -52,7 +41,6 @@ int main(int argc, char* argv[]) {
}
});


QObject::connect(preferencesWindow.applyButton, &QPushButton::clicked, &preferencesWindow, [&]() {
mainWindow.setStride(preferencesWindow.spinbox->value());

Expand Down
53 changes: 23 additions & 30 deletions MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,11 @@

#include "MainWindow.hpp"

#include <QBitmap>
#include <QCloseEvent>
#include <QDebug>
#include <QDialog>
#include <QMenu>
#include <QMenuBar>
#include <QPainter>
#include <QGuiApplication>
#include <QProcess>
#include <QScreen>
#include <QTimer>
#include <QxtGlobalShortcut>
#include <algorithm>
#include <iostream>
#include <regex>

#include "PreferencesWindow.hpp"
Expand Down Expand Up @@ -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);

Expand All @@ -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) {
Expand Down Expand Up @@ -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<SliderWithLabelsLayout>());
initLayout(subLayoutsVex.at(0).get(), info, 0, true);
subLayoutsVex.at(0)->m_DisplayNameLabel.setText("General");
sliderLayouts.emplace_back(std::make_unique<SliderWithLabelsLayout>());
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<QTimer>();
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<SliderWithLabelsLayout>());
sliderLayouts.emplace_back(std::make_unique<SliderWithLabelsLayout>());
}

// 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);
Expand Down Expand Up @@ -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));
});
}
Expand Down Expand Up @@ -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(
Expand All @@ -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());
}
}
Expand Down
16 changes: 3 additions & 13 deletions MainWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,8 @@
#ifndef LUMID_MAINWINDOW_H
#define LUMID_MAINWINDOW_H

#include <QApplication>
#include <QLabel>
#include <QMenu>
#include <QProcess>
#include <QPushButton>
#include <QScreen>
#include <QSlider>
#include <QSystemTrayIcon>
#include <QTimer>
#include <QVBoxLayout>
#include <QWidget>
#include <QxtGlobalShortcut>

Expand All @@ -34,7 +26,7 @@ using namespace Wrappers;
class MainWindow : public QWidget {
public:
MainWindow();

QTimer m_Timer;

PreferencesWindow *m_PreferencesWindow;
Expand All @@ -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<QxtGlobalShortcut> increaseShortcut = std::make_unique<QxtGlobalShortcut>(Qt::Key_F6);
std::unique_ptr<QxtGlobalShortcut> decreaseShortcut = std::make_unique<QxtGlobalShortcut>(Qt::Key_F5);
Expand All @@ -71,7 +61,7 @@ class MainWindow : public QWidget {

BrightnessSlider *generalSlider();

std::vector<std::unique_ptr<SliderWithLabelsLayout>> subLayoutsVex;
std::vector<std::unique_ptr<SliderWithLabelsLayout>> sliderLayouts;

std::unique_ptr<QTimer> generalSliderTimer;

Expand All @@ -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);

Expand Down
1 change: 0 additions & 1 deletion PreferencesWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ void PreferencesWindow::closeEvent(QCloseEvent* event) {
hide();
}


void PreferencesWindow::showEvent(QShowEvent* event) {
QDialog::showEvent(event);

Expand Down
2 changes: 0 additions & 2 deletions PreferencesWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#ifndef LUMID_PREFERENCESWINDOW_HPP
#define LUMID_PREFERENCESWINDOW_HPP

#include <QAction>
#include <QDialog>
#include <QHBoxLayout>
#include <QKeySequenceEdit>
Expand All @@ -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.
Expand Down
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
# Lumid

A simple Qt GUI that adjusts the display brightness for Linux desktop using [ddcutil](https://github.com/rockowitz/ddcutil).<br />

## Screenshots

![UI](assets/focus.png) &nbsp; &nbsp; ![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:<br />
`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.
8 changes: 2 additions & 6 deletions TrayMenu.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
#include "TrayMenu.hpp"

#include <QAction>
#include <QMenu>
#include <QPushButton>
#include <QSystemTrayIcon>
#include <QTimer>
#include <QProcess>

#include "MainWindow.hpp"
#include "PreferencesWindow.hpp"
Expand All @@ -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();
Expand Down
6 changes: 2 additions & 4 deletions TrayMenu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@

#include <QAction>
#include <QMenu>
#include <QSpinBox>
#include <QSystemTrayIcon>

#include "PreferencesWindow.hpp"
#include "MainWindow.hpp"
#include "PreferencesWindow.hpp"

class TrayMenu : public QMenu {
public:
Expand All @@ -21,7 +19,7 @@ class TrayMenu : public QMenu {

std::unique_ptr<QAction> m_Exit;

void connectSignals(MainWindow *mainWindow, PreferencesWindow* prefsWindow);
void connectSignals(MainWindow* mainWindow, PreferencesWindow* prefsWindow);
};

#endif
8 changes: 0 additions & 8 deletions Wrappers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@

#include "Wrappers.hpp"

#include <QApplication>
#include <QCloseEvent>
#include <QDesktopWidget>
#include <QDialog>
#include <QGuiApplication>
#include <QScreen>
#include <QSystemTrayIcon>

#include "MainWindow.hpp"
#include "PreferencesWindow.hpp"

Expand Down
6 changes: 0 additions & 6 deletions Wrappers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,10 @@
#ifndef LUMID_WRAPPERS_HPP
#define LUMID_WRAPPERS_HPP

#include <QAction>
#include <QDialog>
#include <QHBoxLayout>
#include <QKeySequenceEdit>
#include <QLabel>
#include <QMenu>
#include <QPushButton>
#include <QSlider>
#include <QSpinBox>
#include <QSystemTrayIcon>
#include <QTimer>

#include "PreferencesWindow.hpp"
Expand Down

0 comments on commit ff26516

Please sign in to comment.