Skip to content

Commit

Permalink
core: use qt libraries and follow qml module conventions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
outfoxxed committed Oct 14, 2024
1 parent 9b50bb2 commit 6738e7d
Show file tree
Hide file tree
Showing 17 changed files with 420 additions and 428 deletions.
27 changes: 2 additions & 25 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,16 @@ project(hsi VERSION ${VER} LANGUAGES CXX)
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)
set(CMAKE_CXX_STANDARD 20)

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
24 changes: 0 additions & 24 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
systems.url = "github:nix-systems/default-linux";

hyprutils = {
url = "github:hyprwm/hyprutils";
inputs.nixpkgs.follows = "nixpkgs";
inputs.systems.follows = "systems";
};
};

outputs = {
Expand Down
4 changes: 0 additions & 4 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
lib,
stdenv,
cmake,
pkg-config,
hyprutils,
kdePackages,
pciutils,
qt6,
Expand All @@ -26,12 +24,10 @@ in

nativeBuildInputs = [
cmake
pkg-config
qt6.wrapQtAppsHook
];

buildInputs = [
hyprutils
kdePackages.kirigami-addons
qt6.qtbase
qt6.qtsvg
Expand Down
1 change: 0 additions & 1 deletion nix/overlays.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ in {
default = self.overlays.hyprsysteminfo;

hyprsysteminfo = lib.composeManyExtensions [
inputs.hyprutils.overlays.default
(final: prev: {
hyprsysteminfo = final.callPackage ./. {
version = "${version}+date=${date}_${self.shortRev or "dirty"}";
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)
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 6738e7d

Please sign in to comment.