Skip to content

Commit 8280829

Browse files
core: correct $LAYOUT replacement (#755)
* core: remove fake declaration in header * widgets: fix layout rendering * core: remove CSeatManager::getActiveKbLayoutName --------- Co-authored-by: Heorhi Valakhanovich <[email protected]>
1 parent eb28a71 commit 8280829

File tree

4 files changed

+11
-28
lines changed

4 files changed

+11
-28
lines changed

src/core/Seat.cpp

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -134,25 +134,6 @@ void CSeatManager::registerCursorShape(SP<CCWpCursorShapeManagerV1> shape) {
134134
m_pCursorShape = makeUnique<CCursorShape>(shape);
135135
}
136136

137-
std::string CSeatManager::getActiveKbLayoutName() {
138-
if (!m_pXKBState || !m_pXKBKeymap)
139-
return "error";
140-
141-
const auto LAYOUTSNUM = xkb_keymap_num_layouts(m_pXKBKeymap);
142-
143-
for (uint32_t i = 0; i < LAYOUTSNUM; ++i) {
144-
if (xkb_state_layout_index_is_active(m_pXKBState, i, XKB_STATE_LAYOUT_EFFECTIVE) == 1) {
145-
const auto LAYOUTNAME = xkb_keymap_layout_get_name(m_pXKBKeymap, i);
146-
147-
if (LAYOUTNAME)
148-
return std::string{LAYOUTNAME};
149-
return "error";
150-
}
151-
}
152-
153-
return "none";
154-
}
155-
156137
bool CSeatManager::registered() {
157138
return m_pSeat;
158139
}

src/core/Seat.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class CSeatManager {
1414
void registerSeat(SP<CCWlSeat> seat);
1515
void registerCursorShape(SP<CCWpCursorShapeManagerV1> shape);
1616
bool registered();
17-
std::string getActiveKbLayoutName();
1817

1918
SP<CCWlKeyboard> m_pKeeb;
2019
SP<CCWlPointer> m_pPointer;

src/core/hyprlock.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ class CHyprlock {
6565
size_t getPasswordBufferLen();
6666
size_t getPasswordBufferDisplayLen();
6767

68-
std::string getActiveKeyboardLayout();
69-
7068
SP<CCExtSessionLockManagerV1> getSessionLockMgr();
7169
SP<CCExtSessionLockV1> getSessionLock();
7270
SP<CCWlCompositor> getCompositor();

src/renderer/widgets/IWidget.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,16 @@ static void replaceAllAttempts(std::string& str) {
100100
}
101101

102102
static void replaceAllLayout(std::string& str) {
103+
std::string layoutName = "error";
104+
const auto LAYOUTIDX = g_pHyprlock->m_uiActiveLayout;
103105

104-
const auto LAYOUTIDX = g_pHyprlock->m_uiActiveLayout;
105-
const auto LAYOUTNAME = g_pSeatManager->getActiveKbLayoutName();
106-
size_t pos = 0;
106+
if (g_pSeatManager->m_pXKBKeymap) {
107+
const auto PNAME = xkb_keymap_layout_get_name(g_pSeatManager->m_pXKBKeymap, LAYOUTIDX);
108+
if (PNAME)
109+
layoutName = PNAME;
110+
}
107111

112+
size_t pos = 0;
108113
while ((pos = str.find("$LAYOUT", pos)) != std::string::npos) {
109114
if (str.substr(pos, 8).ends_with('[') && str.substr(pos).contains(']')) {
110115
const std::string REPL = str.substr(pos + 8, str.find_first_of(']', pos) - 8 - pos);
@@ -114,12 +119,12 @@ static void replaceAllLayout(std::string& str) {
114119
continue;
115120
}
116121

117-
const std::string LANG = LANGS[LAYOUTIDX].empty() ? LAYOUTNAME : LANGS[LAYOUTIDX] == "!" ? "" : LANGS[LAYOUTIDX];
122+
const std::string LANG = LANGS[LAYOUTIDX].empty() ? layoutName : LANGS[LAYOUTIDX] == "!" ? "" : LANGS[LAYOUTIDX];
118123
str.replace(pos, 9 + REPL.length(), LANG);
119124
pos += LANG.length();
120125
} else {
121-
str.replace(pos, 7, LAYOUTNAME);
122-
pos += LAYOUTNAME.length();
126+
str.replace(pos, 7, layoutName);
127+
pos += layoutName.length();
123128
}
124129
}
125130
}

0 commit comments

Comments
 (0)