Start tying into UI
This commit is contained in:
parent
33ab4308d1
commit
bee1586af9
@ -27,9 +27,10 @@ qt_standard_project_setup()
|
|||||||
qt_add_executable(waycast)
|
qt_add_executable(waycast)
|
||||||
|
|
||||||
include_directories("${CMAKE_SOURCE_DIR}/lib")
|
include_directories("${CMAKE_SOURCE_DIR}/lib")
|
||||||
include_directories("${CMAKE_SOURCE_DIR}/lib")
|
include_directories("${CMAKE_SOURCE_DIR}/lib/ui")
|
||||||
file(GLOB_RECURSE SRC_FILES CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/src/*.cpp")
|
file(GLOB_RECURSE SRC_FILES CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/src/*.cpp")
|
||||||
target_sources(waycast PRIVATE ${SRC_FILES} src/main.cpp)
|
file(GLOB_RECURSE LIB_UI_FILES CONFIGURE_DEPENDS "${CMAKE_SOURCE_DIR}/lib/ui/*.cpp")
|
||||||
|
target_sources(waycast PRIVATE ${SRC_FILES} ${LIB_UI_FILES} src/main.cpp)
|
||||||
target_include_directories(waycast PRIVATE ${CMAKE_SOURCE_DIR}/lib)
|
target_include_directories(waycast PRIVATE ${CMAKE_SOURCE_DIR}/lib)
|
||||||
# target_include_directories(waycast PRIVATE ${CMAKE_SOURCE_DIR}/lib ${CMAKE_CURRENT_BINARY_DIR})
|
# target_include_directories(waycast PRIVATE ${CMAKE_SOURCE_DIR}/lib ${CMAKE_CURRENT_BINARY_DIR})
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ namespace dmenu
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<std::string> split(std::string s, char delimiter)
|
inline std::vector<std::string> split(std::string s, char delimiter)
|
||||||
{
|
{
|
||||||
std::vector<std::string> items;
|
std::vector<std::string> items;
|
||||||
std::string line;
|
std::string line;
|
||||||
@ -77,7 +77,7 @@ namespace dmenu
|
|||||||
}
|
}
|
||||||
|
|
||||||
using DEVec = std::unique_ptr<std::vector<DesktopEntry>>;
|
using DEVec = std::unique_ptr<std::vector<DesktopEntry>>;
|
||||||
DEVec get_dmenu_app_data()
|
inline DEVec get_dmenu_app_data()
|
||||||
{
|
{
|
||||||
DEVec out = std::make_unique<std::vector<DesktopEntry>>();
|
DEVec out = std::make_unique<std::vector<DesktopEntry>>();
|
||||||
const char* env_dirs = std::getenv("XDG_DATA_DIRS");
|
const char* env_dirs = std::getenv("XDG_DATA_DIRS");
|
||||||
@ -96,7 +96,10 @@ namespace dmenu
|
|||||||
|
|
||||||
for (const auto &dfile : desktopFiles)
|
for (const auto &dfile : desktopFiles)
|
||||||
{
|
{
|
||||||
out->emplace_back(dfile.string());
|
DesktopEntry entry(dfile.string());
|
||||||
|
if (entry.display) {
|
||||||
|
out->push_back(std::move(entry));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ namespace files
|
|||||||
{
|
{
|
||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
std::vector<fs::path> findFilesWithExtension(const std::string path, const std::string ext)
|
inline std::vector<fs::path> findFilesWithExtension(const std::string path, const std::string ext)
|
||||||
{
|
{
|
||||||
std::vector<fs::path> out;
|
std::vector<fs::path> out;
|
||||||
std::unordered_set<std::string> seen; // canonicalized paths to dedupe
|
std::unordered_set<std::string> seen; // canonicalized paths to dedupe
|
||||||
@ -40,7 +40,7 @@ namespace files
|
|||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string readFile(const std::string &filename)
|
inline std::string readFile(const std::string &filename)
|
||||||
{
|
{
|
||||||
std::ifstream in(filename);
|
std::ifstream in(filename);
|
||||||
if (!in)
|
if (!in)
|
||||||
|
49
lib/ui/AppListModel.cpp
Normal file
49
lib/ui/AppListModel.cpp
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
#include "AppListModel.hpp"
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
AppListModel::AppListModel(QObject *parent)
|
||||||
|
: QAbstractListModel(parent)
|
||||||
|
{
|
||||||
|
loadApps();
|
||||||
|
}
|
||||||
|
|
||||||
|
int AppListModel::rowCount(const QModelIndex &parent) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(parent);
|
||||||
|
return m_apps ? static_cast<int>(m_apps->size()) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant AppListModel::data(const QModelIndex &index, int role) const
|
||||||
|
{
|
||||||
|
if (!index.isValid() || !m_apps || index.row() >= static_cast<int>(m_apps->size()))
|
||||||
|
return QVariant();
|
||||||
|
|
||||||
|
const dmenu::DesktopEntry &app = (*m_apps)[index.row()];
|
||||||
|
|
||||||
|
switch (role) {
|
||||||
|
case NameRole:
|
||||||
|
return QString::fromStdString(app.name);
|
||||||
|
case ExecRole:
|
||||||
|
return QString::fromStdString(app.exec);
|
||||||
|
case IdRole:
|
||||||
|
return QString::fromStdString(app.id);
|
||||||
|
default:
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QHash<int, QByteArray> AppListModel::roleNames() const
|
||||||
|
{
|
||||||
|
QHash<int, QByteArray> roles;
|
||||||
|
roles[NameRole] = "name";
|
||||||
|
roles[ExecRole] = "exec";
|
||||||
|
roles[IdRole] = "id";
|
||||||
|
return roles;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppListModel::loadApps()
|
||||||
|
{
|
||||||
|
beginResetModel();
|
||||||
|
m_apps = dmenu::get_dmenu_app_data();
|
||||||
|
endResetModel();
|
||||||
|
}
|
31
lib/ui/AppListModel.hpp
Normal file
31
lib/ui/AppListModel.hpp
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QAbstractListModel>
|
||||||
|
#include <QQmlEngine>
|
||||||
|
|
||||||
|
#undef signals
|
||||||
|
#include "../dmenu.hpp"
|
||||||
|
#define signals public
|
||||||
|
|
||||||
|
class AppListModel : public QAbstractListModel
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
enum AppRoles {
|
||||||
|
NameRole = Qt::UserRole + 1,
|
||||||
|
ExecRole,
|
||||||
|
IdRole
|
||||||
|
};
|
||||||
|
|
||||||
|
explicit AppListModel(QObject *parent = nullptr);
|
||||||
|
|
||||||
|
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
|
||||||
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
QHash<int, QByteArray> roleNames() const override;
|
||||||
|
|
||||||
|
Q_INVOKABLE void loadApps();
|
||||||
|
|
||||||
|
private:
|
||||||
|
dmenu::DEVec m_apps;
|
||||||
|
};
|
10
src/main.cpp
10
src/main.cpp
@ -1,10 +1,11 @@
|
|||||||
#include "dmenu.hpp"
|
|
||||||
#include "files.hpp"
|
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
#include <QQmlApplicationEngine>
|
#include <QQmlApplicationEngine>
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
#include <QWindow>
|
#include <QWindow>
|
||||||
#include <LayerShellQt/window.h>
|
#include <LayerShellQt/window.h>
|
||||||
|
#include "ui/AppListModel.hpp"
|
||||||
|
#include "dmenu.hpp"
|
||||||
|
#include "files.hpp"
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -37,12 +38,15 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
QGuiApplication app(argc, argv);
|
QGuiApplication app(argc, argv);
|
||||||
QCoreApplication::setApplicationName("waycast");
|
QCoreApplication::setApplicationName("waycast");
|
||||||
|
|
||||||
// Enable system theme support
|
// Enable system theme support
|
||||||
app.setDesktopSettingsAware(true);
|
app.setDesktopSettingsAware(true);
|
||||||
|
|
||||||
QQmlApplicationEngine engine;
|
QQmlApplicationEngine engine;
|
||||||
|
|
||||||
|
// Register the AppListModel type with QML
|
||||||
|
qmlRegisterType<AppListModel>("WayCast", 1, 0, "AppListModel");
|
||||||
|
|
||||||
// Set up layer shell before creating any windows
|
// Set up layer shell before creating any windows
|
||||||
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed, &app, []()
|
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed, &app, []()
|
||||||
{ QCoreApplication::exit(-1); });
|
{ QCoreApplication::exit(-1); });
|
||||||
|
14
ui/Main.qml
14
ui/Main.qml
@ -3,6 +3,7 @@ import QtQuick.Controls
|
|||||||
import QtQuick.Window
|
import QtQuick.Window
|
||||||
import QtQuick.Controls.Material
|
import QtQuick.Controls.Material
|
||||||
import QtQuick.Controls.Universal
|
import QtQuick.Controls.Universal
|
||||||
|
import WayCast
|
||||||
|
|
||||||
ApplicationWindow {
|
ApplicationWindow {
|
||||||
id: win
|
id: win
|
||||||
@ -44,7 +45,7 @@ ApplicationWindow {
|
|||||||
Keys.onUpPressed: listView.decrementCurrentIndex()
|
Keys.onUpPressed: listView.decrementCurrentIndex()
|
||||||
Keys.onReturnPressed: {
|
Keys.onReturnPressed: {
|
||||||
if (listView.currentItem) {
|
if (listView.currentItem) {
|
||||||
console.log("Selected:", listModel.get(listView.currentIndex).name)
|
console.log("Selected:", appModel.data(appModel.index(listView.currentIndex, 0), Qt.UserRole + 1))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -56,7 +57,7 @@ ApplicationWindow {
|
|||||||
|
|
||||||
ListView {
|
ListView {
|
||||||
id: listView
|
id: listView
|
||||||
model: listModel
|
model: appModel
|
||||||
currentIndex: 0
|
currentIndex: 0
|
||||||
highlightFollowsCurrentItem: true
|
highlightFollowsCurrentItem: true
|
||||||
|
|
||||||
@ -112,12 +113,7 @@ ApplicationWindow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ListModel {
|
AppListModel {
|
||||||
id: listModel
|
id: appModel
|
||||||
ListElement { name: "Firefox"; exec: "firefox" }
|
|
||||||
ListElement { name: "Terminal"; exec: "gnome-terminal" }
|
|
||||||
ListElement { name: "File Manager"; exec: "nautilus" }
|
|
||||||
ListElement { name: "Text Editor"; exec: "gedit" }
|
|
||||||
ListElement { name: "Calculator"; exec: "gnome-calculator" }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user