Skip to content

Commit 3182220

Browse files
committed
Use the new findIconThemes() for cursors too
1 parent 0554fcc commit 3182220

File tree

2 files changed

+32
-22
lines changed

2 files changed

+32
-22
lines changed

src/maindialog.cpp

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ void MainDialog::activate()
8181
ui->dropShadows->setCurrentIndex(xml_get_bool_text("/labwc_config/theme/dropShadows"));
8282

8383
/* Icon Theme */
84-
QStringList themes = findIconThemes();
84+
QStringList themes = findIconThemes(LAB_ICON_THEME_TYPE_ICON);
8585
ui->iconTheme->addItems(themes);
8686
ui->iconTheme->setCurrentIndex(themes.indexOf(xml_get("/labwc_config/theme/icon")));
8787

@@ -104,22 +104,9 @@ void MainDialog::activate()
104104
/* # MOUSE & TOUCHPAD */
105105

106106
/* Cursor Theme */
107-
struct themes cursor_themes = { 0 };
108-
theme_find(&cursor_themes, "icons", "cursors");
109-
110-
active_id = getenv("XCURSOR_THEME") ?: (char *)"";
111-
active = -1;
112-
for (int i = 0; i < cursor_themes.nr; ++i) {
113-
struct theme *theme = cursor_themes.data + i;
114-
if (!strcmp(theme->name, active_id)) {
115-
active = i;
116-
}
117-
ui->cursorTheme->addItem(theme->name);
118-
}
119-
if (active != -1) {
120-
ui->cursorTheme->setCurrentIndex(active);
121-
}
122-
theme_free_vector(&cursor_themes);
107+
QStringList cursorThemes = findIconThemes(LAB_ICON_THEME_TYPE_CURSOR);
108+
ui->cursorTheme->addItems(cursorThemes);
109+
ui->cursorTheme->setCurrentIndex(cursorThemes.indexOf(getenv("XCURSOR_THEME") ?: (char *)""));
123110

124111
/* Cursor Size */
125112
ui->cursorSize->setValue(atoi(getenv("XCURSOR_SIZE") ?: "24"));
@@ -263,7 +250,13 @@ bool hasOnlyCursorSubdir(QString path)
263250
return entries.contains("cursors") && entries.length() == 1;
264251
}
265252

266-
QStringList MainDialog::findIconThemes(void)
253+
bool hasCursorSubdir(QString path)
254+
{
255+
QStringList entries = QDir(path).entryList(QDir::Dirs | QDir::NoDotAndDotDot);
256+
return entries.contains("cursors");
257+
}
258+
259+
QStringList MainDialog::findIconThemes(enum lab_icon_theme_type type)
267260
{
268261
QStringList paths;
269262

@@ -286,10 +279,21 @@ QStringList MainDialog::findIconThemes(void)
286279
QDir dir(path);
287280
QStringList entries = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
288281
for (const QString &entry : std::as_const(entries)) {
289-
if (hasOnlyCursorSubdir(QString(path + "/" + entry))) {
290-
continue;
282+
switch (type) {
283+
case LAB_ICON_THEME_TYPE_ICON:
284+
if (hasOnlyCursorSubdir(QString(path + "/" + entry))) {
285+
continue;
286+
}
287+
themes.push_back(entry);
288+
break;
289+
case LAB_ICON_THEME_TYPE_CURSOR:
290+
if (hasCursorSubdir(QString(path + "/" + entry))) {
291+
themes.push_back(entry);
292+
}
293+
break;
294+
default:
295+
break;
291296
}
292-
themes.push_back(entry);
293297
}
294298
}
295299
themes.removeDuplicates();

src/maindialog.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ class MainDialog;
1010
}
1111
QT_END_NAMESPACE
1212

13+
enum lab_icon_theme_type {
14+
LAB_ICON_THEME_TYPE_NONE = 0,
15+
LAB_ICON_THEME_TYPE_ICON,
16+
LAB_ICON_THEME_TYPE_CURSOR,
17+
};
18+
1319
class MainDialog : public QDialog
1420
{
1521
Q_OBJECT
@@ -18,7 +24,7 @@ class MainDialog : public QDialog
1824
MainDialog(std::vector<std::shared_ptr<Setting>> &settings, QWidget *parent = nullptr);
1925
~MainDialog();
2026
void activate();
21-
QStringList findIconThemes();
27+
QStringList findIconThemes(enum lab_icon_theme_type type);
2228
QStringList findLabwcThemes();
2329

2430
private slots:

0 commit comments

Comments
 (0)