diff --git a/CMakeLists.txt b/CMakeLists.txt index 4f63f75..62fe184 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,6 +49,7 @@ set(PROJECT_SOURCES src/appearance.cpp src/appearance.h src/appearance.ui src/behaviour.cpp src/behaviour.h src/behaviour.ui src/mouse.cpp src/mouse.h src/mouse.ui + src/language.cpp src/language.h src/language.ui ) set(PROJECT_OTHER_FILES .github/workflows/build.yml diff --git a/src/gen-layout-list b/bin/gen-layout-list similarity index 97% rename from src/gen-layout-list rename to bin/gen-layout-list index 2aea9e9..c5810b4 100755 --- a/src/gen-layout-list +++ b/bin/gen-layout-list @@ -2,14 +2,15 @@ from enum import Enum HEADER="""#pragma once +#include #include // Auto-generated based on "/usr/share/X11/xkb/rules/evdev.lst" struct layout { - const char *code; - const char *description; + QString code; + QString description; }; static std::vector evdev_lst_layouts = {""" diff --git a/src/evdev-lst-layouts.h b/src/evdev-lst-layouts.h index 7bbc275..3a6a952 100644 --- a/src/evdev-lst-layouts.h +++ b/src/evdev-lst-layouts.h @@ -1,12 +1,13 @@ #pragma once +#include #include // Auto-generated based on "/usr/share/X11/xkb/rules/evdev.lst" struct layout { - const char *code; - const char *description; + QString code; + QString description; }; static std::vector evdev_lst_layouts = { diff --git a/src/language.cpp b/src/language.cpp new file mode 100644 index 0000000..40a112e --- /dev/null +++ b/src/language.cpp @@ -0,0 +1,63 @@ +#include "language.h" +#include "evdev-lst-layouts.h" +#include "environment.h" +#include "find-themes.h" +#include "layoutmodel.h" +#include "macros.h" +#include "settings.h" +#include "./ui_language.h" + +Language::Language(QWidget *parent) : QWidget(parent), ui(new Ui::pageLanguage) +{ + ui->setupUi(this); + + m_model = new LayoutModel(this); + ui->layoutView->setModel(m_model); + connect(ui->layoutAdd, &QPushButton::pressed, this, &Language::addSelectedLayout); + connect(ui->layoutRemove, &QPushButton::pressed, this, &Language::deleteSelectedLayout); +} + +Language::~Language() +{ + delete ui; +} + +void Language::activate() +{ + /* Keyboard Layout */ + ui->layoutCombo->addItem(tr("Select layout to add...")); + for (auto layout : evdev_lst_layouts) { + ui->layoutCombo->addItem(layout.description); + } +} + +void Language::onApply() +{ + /* + * We include variants in XKB_DEFAULT_LAYOUT, for example + * "latam(deadtilde),ru(phonetic),gr", so XKB_DEFAULT_VARIANT is set to + * empty. + */ + QString layout = m_model->getXkbDefaultLayout(); + if (!layout.isEmpty()) { + environmentSet("XKB_DEFAULT_LAYOUT", layout); + environmentSet("XKB_DEFAULT_VARIANT", ""); + } +} + +void Language::addSelectedLayout(void) +{ + QString description = ui->layoutCombo->currentText(); + + for (auto layout : evdev_lst_layouts) { + if (description == layout.description) { + m_model->addLayout(layout.code, layout.description); + } + } +} + +void Language::deleteSelectedLayout(void) +{ + m_model->deleteLayout(ui->layoutView->currentIndex().row()); +} + diff --git a/src/language.h b/src/language.h new file mode 100644 index 0000000..91cb741 --- /dev/null +++ b/src/language.h @@ -0,0 +1,31 @@ +#ifndef LANGUAGE_H +#define LANGUAGE_H +#include +#include "layoutmodel.h" + +QT_BEGIN_NAMESPACE +namespace Ui { +class pageLanguage; +} +QT_END_NAMESPACE + +class Language : public QWidget +{ + Q_OBJECT + +public: + Language(QWidget *parent = nullptr); + ~Language(); + + void activate(); + void onApply(); + +private slots: + void addSelectedLayout(void); + void deleteSelectedLayout(void); + +private: + Ui::pageLanguage *ui; + LayoutModel *m_model; +}; +#endif // LANGUAGE_H diff --git a/src/language.ui b/src/language.ui new file mode 100644 index 0000000..7d42789 --- /dev/null +++ b/src/language.ui @@ -0,0 +1,85 @@ + + + pageLanguage + + + + 0 + 0 + 251 + 153 + + + + + 6 + + + 6 + + + 6 + + + 6 + + + + + Keyboard Layout + + + + + + + + + + 16777215 + 72 + + + + + + + + + + + + + Add + + + + + + + Remove + + + + + + + + + Qt::Orientation::Vertical + + + + 20 + 40 + + + + + + + + + + + diff --git a/src/maindialog.cpp b/src/maindialog.cpp index 2992694..3edf6e5 100644 --- a/src/maindialog.cpp +++ b/src/maindialog.cpp @@ -7,9 +7,7 @@ #include #include #include "environment.h" -#include "evdev-lst-layouts.h" #include "find-themes.h" -#include "layoutmodel.h" #include "log.h" #include "macros.h" #include "maindialog.h" @@ -19,21 +17,12 @@ MainDialog::MainDialog(QWidget *parent) : QDialog(parent), ui(new Ui::MainDialog) { ui->setupUi(this); - ui->list->setFixedWidth(ui->list->sizeHintForColumn(0) + 2 * ui->list->frameWidth()); - - m_model = new LayoutModel(this); - ui->layoutView->setModel(m_model); - QObject::connect(ui->buttonBox, &QDialogButtonBox::clicked, [&](QAbstractButton *button) { if (ui->buttonBox->standardButton(button) == QDialogButtonBox::Apply) { onApply(); } }); - - connect(ui->layoutAdd, &QPushButton::pressed, this, &MainDialog::addSelectedLayout); - connect(ui->layoutRemove, &QPushButton::pressed, this, &MainDialog::deleteSelectedLayout); - activate(); } @@ -43,34 +32,12 @@ MainDialog::~MainDialog() xml_finish(); } -void MainDialog::addSelectedLayout(void) -{ - const char *description = ui->layoutCombo->currentText().toLatin1().data(); - for (auto layout : evdev_lst_layouts) { - if (!strcmp(description, layout.description)) { - m_model->addLayout(QString(layout.code), QString(layout.description)); - } - } -} - -void MainDialog::deleteSelectedLayout(void) -{ - m_model->deleteLayout(ui->layoutView->currentIndex().row()); -} - void MainDialog::activate() { ui->pageAppearance->activate(); ui->pageBehaviour->activate(); ui->pageMouse->activate(); - - /* # LANGUAGE */ - - /* Keyboard Layout */ - ui->layoutCombo->addItem(tr("Select layout to add...")); - for (auto layout : evdev_lst_layouts) { - ui->layoutCombo->addItem(QString(layout.description)); - } + ui->pageLanguage->activate(); } void MainDialog::onApply() @@ -78,16 +45,7 @@ void MainDialog::onApply() ui->pageAppearance->onApply(); ui->pageBehaviour->onApply(); ui->pageMouse->onApply(); - - /* - * We include variants in XKB_DEFAULT_LAYOUT, for example "latam(deadtilde),ru(phonetic),gr", - * so XKB_DEFAULT_VARIANT is set to empty. - */ - QString layout = m_model->getXkbDefaultLayout(); - if (!layout.isEmpty()) { - environmentSet("XKB_DEFAULT_LAYOUT", layout); - environmentSet("XKB_DEFAULT_VARIANT", ""); - } + ui->pageLanguage->onApply(); // TODO: Get filename in a more consistent way - share common code with main.cpp std::string config_home = std::getenv("HOME") + std::string("/.config/labwc"); diff --git a/src/maindialog.h b/src/maindialog.h index 367ad1f..471f24e 100644 --- a/src/maindialog.h +++ b/src/maindialog.h @@ -1,7 +1,6 @@ #ifndef MAINDIALOG_H #define MAINDIALOG_H #include -#include "layoutmodel.h" #include "settings.h" QT_BEGIN_NAMESPACE @@ -19,14 +18,8 @@ class MainDialog : public QDialog ~MainDialog(); void activate(); -private slots: - void addSelectedLayout(void); - void deleteSelectedLayout(void); - private: - LayoutModel *m_model; void onApply(); - Ui::MainDialog *ui; }; #endif // MAINDIALOG_H diff --git a/src/maindialog.ui b/src/maindialog.ui index 442f3da..a3a2625 100644 --- a/src/maindialog.ui +++ b/src/maindialog.ui @@ -91,77 +91,7 @@ - - - - 6 - - - 6 - - - 6 - - - 6 - - - - - Keyboard Layout - - - - - - - - - - 16777215 - 72 - - - - - - - - - - - - - Add - - - - - - - Remove - - - - - - - - - Qt::Orientation::Vertical - - - - 20 - 40 - - - - - - - - +