Skip to content

Commit

Permalink
core: use qt libraries and follow qml module conventions (#8)
Browse files Browse the repository at this point in the history
* core: use qt libraries and follow qml module conventions

Uses a qml module instead of a context property.
Replaces usages of std and hyprutils with qtbase where applicable.
Removes dependencies: hyprutils, wl-copy, whoami, uname.
Rolls c++ version back to 20, as 23 isn't currently required for anything.

* core: use hyprutils and std again
  • Loading branch information
outfoxxed authored Oct 15, 2024
1 parent 9b50bb2 commit 00beba9
Show file tree
Hide file tree
Showing 14 changed files with 390 additions and 395 deletions.
26 changes: 3 additions & 23 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,22 @@ string(STRIP ${VER_RAW} VER)

project(hsi VERSION ${VER} LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 23)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

find_package(Qt6 6.5 REQUIRED COMPONENTS Widgets Quick QuickControls2)
find_package(PkgConfig REQUIRED)
set(CMAKE_CXX_STANDARD 23)

pkg_check_modules(
deps
REQUIRED
IMPORTED_TARGET
hyprutils)
pkg_check_modules(hyprutils REQUIRED IMPORTED_TARGET hyprutils)

qt_standard_project_setup(REQUIRES 6.5)

qt_add_executable(hyprsysteminfo
src/main.cpp src/util/Utils.cpp src/util/Utils.hpp
)

qt_add_qml_module(hyprsysteminfo
URI hsi
VERSION 1.0
QML_FILES
qml/main.qml
SOURCES
qmlSources/SystemInternals.hpp qmlSources/SystemInternals.cpp qmlSources/SystemIconProvider.hpp
)
add_subdirectory(src)

qt_add_resources(hyprsysteminfo "resource"
PREFIX "/"
FILES
resource/hyprlandlogo.svg
resource/hyprlandlogo.png
)

target_link_libraries(hyprsysteminfo
PRIVATE Qt6::Widgets Qt6::Quick Qt6::Gui Qt6::QuickControls2 PkgConfig::deps
)

include(GNUInstallDirs)
Expand Down
6 changes: 3 additions & 3 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
lib,
stdenv,
cmake,
pkg-config,
hyprutils,
kdePackages,
pciutils,
qt6,
pkg-config,
hyprutils,
version ? "0",
}: let
inherit (lib.sources) cleanSource cleanSourceWith;
Expand All @@ -31,11 +31,11 @@ in
];

buildInputs = [
hyprutils
kdePackages.kirigami-addons
qt6.qtbase
qt6.qtsvg
qt6.qtwayland
hyprutils
];

preFixup = ''
Expand Down
11 changes: 0 additions & 11 deletions qmlSources/SystemInternals.cpp

This file was deleted.

102 changes: 0 additions & 102 deletions qmlSources/SystemInternals.hpp

This file was deleted.

Binary file removed resource/hyprlandlogo.png
Binary file not shown.
14 changes: 14 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
qt_add_executable(hyprsysteminfo
main.cpp
util/Utils.cpp
SystemInfo.cpp
SystemIconProvider.cpp
)

qt_add_qml_module(hyprsysteminfo
URI org.hyprland.systeminfo
VERSION 1.0
QML_FILES main.qml
)

target_link_libraries(hyprsysteminfo PRIVATE Qt6::Widgets Qt6::QuickControls2 PkgConfig::hyprutils)
25 changes: 25 additions & 0 deletions src/SystemIconProvider.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "SystemIconProvider.hpp"
#include <qicon.h>
#include <qlogging.h>
#include <qpixmap.h>

QPixmap CSystemIconProvider::requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) {
auto icon = QIcon::fromTheme(id);

if (!requestedSize.isValid()) {
qCritical() << "Icon requests without an explicit size are not allowed.";
return QPixmap();
}

auto pixmap = icon.pixmap(requestedSize.width(), requestedSize.height());

if (pixmap.isNull()) {
qWarning() << "Could not load icon" << id;
return QPixmap();
}

if (size != nullptr)
*size = pixmap.size();

return pixmap;
}
10 changes: 2 additions & 8 deletions qmlSources/SystemIconProvider.hpp → src/SystemIconProvider.hpp
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
#ifndef SYSTEMICONPROVIDER_H
#define SYSTEMICONPROVIDER_H
#pragma once

#include <QIcon>
#include <QObject>
#include <QPixmap>
#include <QQmlApplicationEngine>
#include <QQuickImageProvider>
#include <iostream>

class CSystemIconProvider : public QQuickImageProvider {
public:
CSystemIconProvider() : QQuickImageProvider(QQuickImageProvider::Pixmap) {}

QPixmap requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) override {
return QIcon::fromTheme(id).pixmap({512, 512});
}
QPixmap requestPixmap(const QString& id, QSize* size, const QSize& requestedSize) override;
};

#endif // SYSTEMICONPROVIDER_H
Loading

0 comments on commit 00beba9

Please sign in to comment.