Skip to content

Commit 4dc9129

Browse files
session-picker: add onclick and onhover
1 parent 3e01dc4 commit 4dc9129

File tree

7 files changed

+55
-15
lines changed

7 files changed

+55
-15
lines changed

src/config/LoginSessionManager.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static bool parseDesktopFile(SLoginSessionConfig& sessionConfig) {
4242
return true;
4343
}
4444

45-
static std::vector<SLoginSessionConfig> gatherSessions(const std::vector<std::string>& searchPaths) {
45+
static std::vector<SLoginSessionConfig> gatherSessionsInPaths(const std::vector<std::string>& searchPaths) {
4646
std::vector<SLoginSessionConfig> sessions;
4747

4848
for (const auto& DIR : searchPaths) {
@@ -66,16 +66,19 @@ static std::vector<SLoginSessionConfig> gatherSessions(const std::vector<std::st
6666
return sessions;
6767
}
6868

69-
CLoginSessionManager::CLoginSessionManager(const std::string& sessionDirs) {
69+
void CLoginSessionManager::gather(const std::string& sessionDirs) {
7070
const auto LOGINDEFAULTSESSION = g_pConfigManager->getValue<Hyprlang::STRING>("login:default_session");
7171

7272
Debug::log(LOG, "LoginSessions: Default session: {}, Search directories: {}", std::string{*LOGINDEFAULTSESSION}, sessionDirs);
7373

7474
Hyprutils::String::CVarList sessionDirPaths{sessionDirs, 0, ':', true};
75-
m_loginSessions = gatherSessions(std::vector<std::string>{sessionDirPaths.begin(), sessionDirPaths.end()});
75+
m_loginSessions = gatherSessionsInPaths(std::vector<std::string>{sessionDirPaths.begin(), sessionDirPaths.end()});
76+
7677
const auto CONFIGUEDSESSIONS = g_pConfigManager->getLoginSessionConfigs();
7778
m_loginSessions.insert(m_loginSessions.end(), CONFIGUEDSESSIONS.begin(), CONFIGUEDSESSIONS.end());
7879

80+
// Handle different possiblites for the default_session option.
81+
// It can either be a path to a .desktop file, or the display name.
7982
if (const std::string DEFAULTSESSIONSTRING{*LOGINDEFAULTSESSION}; !DEFAULTSESSIONSTRING.empty()) {
8083
bool found = false;
8184
const auto ABSPATH = absolutePath(DEFAULTSESSIONSTRING, "/");
@@ -156,6 +159,11 @@ void CLoginSessionManager::handleKeyDown() {
156159
}
157160
}
158161

162+
void CLoginSessionManager::selectSession(size_t index) {
163+
if (index < m_loginSessions.size())
164+
m_selectedLoginSession = index;
165+
}
166+
159167
void CLoginSessionManager::onGotLoginSessionAssetCallback() {
160168
m_renderedSessionNames++;
161169
if (m_renderedSessionNames == m_loginSessionResourceIds.size())

src/config/LoginSessionManager.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,17 @@
77

88
class CLoginSessionManager {
99
public:
10-
CLoginSessionManager(const std::string& sessionDirs);
10+
CLoginSessionManager() = default;
1111
~CLoginSessionManager() = default;
1212

1313
CLoginSessionManager(const CLoginSessionManager&) = delete;
1414
CLoginSessionManager& operator=(const CLoginSessionManager&) = delete;
1515
CLoginSessionManager(CLoginSessionManager&&) noexcept = delete;
1616

17+
void gather(const std::string& sessionDirs);
1718
void handleKeyUp();
1819
void handleKeyDown();
20+
void selectSession(size_t index);
1921
void onGotLoginSessionAssetCallback();
2022

2123
const SLoginSessionConfig& getSelectedLoginSession() const;

src/core/hyprlock.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ static void setMallocThreshold() {
3939
}
4040

4141
CHyprlock::CHyprlock(const std::string& wlDisplay, const bool immediateRender, const int graceSeconds, const bool greetdLogin, const std::string& sessionDirs) :
42-
m_bGreetdLogin(greetdLogin), m_greetdSessionDirs(sessionDirs) {
42+
m_greetdLogin(greetdLogin), m_greetdSessionDirs(sessionDirs) {
4343
setMallocThreshold();
4444

4545
m_sWaylandState.display = wl_display_connect(wlDisplay.empty() ? nullptr : wlDisplay.c_str());
@@ -314,10 +314,13 @@ void CHyprlock::run() {
314314
wl_display_roundtrip(m_sWaylandState.display);
315315

316316
g_pRenderer = makeUnique<CRenderer>();
317-
g_pLoginSessionManager = makeUnique<CLoginSessionManager>(m_greetdSessionDirs);
318-
g_pAuth = makeUnique<CAuth>(m_bGreetdLogin);
317+
g_pLoginSessionManager = makeUnique<CLoginSessionManager>();
318+
g_pAuth = makeUnique<CAuth>(m_greetdLogin);
319319
g_pAuth->start();
320320

321+
if (m_greetdLogin)
322+
g_pLoginSessionManager->gather(m_greetdSessionDirs);
323+
321324
Debug::log(LOG, "Running on {}", m_currentDesktop);
322325

323326
if (!g_pHyprlock->m_bImmediateRender) {
@@ -697,9 +700,9 @@ void CHyprlock::handleKeySym(xkb_keysym_t sym, bool composed) {
697700
m_bCapsLock = !m_bCapsLock;
698701
else if (SYM == XKB_KEY_Num_Lock)
699702
m_bNumLock = !m_bNumLock;
700-
else if (SYM == XKB_KEY_Up)
703+
else if (SYM == XKB_KEY_Up && m_greetdLogin)
701704
g_pLoginSessionManager->handleKeyUp();
702-
else if (SYM == XKB_KEY_Down)
705+
else if (SYM == XKB_KEY_Down && m_greetdLogin)
703706
g_pLoginSessionManager->handleKeyDown();
704707
else {
705708
char buf[16] = {0};

src/core/hyprlock.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class CHyprlock {
8989

9090
bool m_bImmediateRender = false;
9191

92-
bool m_bGreetdLogin = false;
92+
bool m_greetdLogin = false;
9393

9494
//
9595
std::chrono::system_clock::time_point m_tGraceEnds;

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ int main(int argc, char** argv, char** envp) {
4545
std::string wlDisplay;
4646
bool immediateRender = false;
4747
bool noFadeIn = false;
48-
int graceSeconds = 0;
4948
bool greetdLogin = false;
49+
int graceSeconds = 0;
5050

5151
std::vector<std::string> args(argv, argv + argc);
5252

src/renderer/widgets/SessionPicker.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include "../../helpers/Color.hpp"
55
#include "../../config/ConfigDataValues.hpp"
66
#include "../../config/LoginSessionManager.hpp"
7+
#include "../../core/Seat.hpp"
8+
#include "../../core/hyprlock.hpp"
79
#include <algorithm>
810
#include <hyprlang.hpp>
911
#include <hyprutils/math/Vector2D.hpp>
@@ -44,21 +46,21 @@ bool CSessionPicker::draw(const SRenderData& data) {
4446

4547
const double PAD = std::abs((m_size.y - m_biggestEntryAssetSize.y) / 2);
4648
const Vector2D SIZE{std::max(m_size.x, m_biggestEntryAssetSize.x + PAD), m_size.y};
47-
const CBox RECTBOX{
49+
m_box = CBox{
4850
posFromHVAlign(m_viewport, SIZE, m_configPos, m_halign, m_valign),
4951
SIZE,
5052
};
5153

52-
const auto ENTRYHEIGHT = RECTBOX.h / (m_loginSessions.size() + 1);
53-
const auto TOPLEFT = RECTBOX.pos() + Vector2D{0.0, RECTBOX.h};
54+
const auto ENTRYHEIGHT = m_box.h / (m_loginSessions.size() + 1);
55+
const auto TOPLEFT = m_box.pos() + Vector2D{0.0, m_box.h};
5456

5557
for (size_t i = 0; i < m_loginSessions.size(); ++i) {
5658
auto& sessionEntry = m_loginSessions[i];
5759

5860
const CBox ENTRYBOX{
5961
TOPLEFT.x,
6062
TOPLEFT.y - ENTRYHEIGHT - (i * (ENTRYHEIGHT + m_entrySpacing)),
61-
RECTBOX.w,
63+
m_box.w,
6264
ENTRYHEIGHT,
6365
};
6466

@@ -121,3 +123,23 @@ void CSessionPicker::setupSessionEntryTexts() {
121123
};
122124
};
123125
}
126+
127+
CBox CSessionPicker::getBoundingBoxWl() const {
128+
return {
129+
Vector2D{m_box.pos().x, m_viewport.y - m_box.pos().y - m_box.size().y},
130+
m_box.size(),
131+
};
132+
}
133+
134+
void CSessionPicker::onClick(uint32_t button, bool down, const Vector2D& pos) {
135+
const auto DIFFERENTIAL = pos.y - (m_viewport.y - m_box.pos().y - m_box.size().y);
136+
const auto HEIGHTPERENTRY = m_box.size().y / m_loginSessions.size();
137+
const size_t SELECTEDENTRY = std::floor(DIFFERENTIAL / HEIGHTPERENTRY);
138+
g_pLoginSessionManager->selectSession(SELECTEDENTRY);
139+
Debug::log(LOG, "clicked on entry: DIFF {} H/E {} SEL {}", DIFFERENTIAL, HEIGHTPERENTRY, SELECTEDENTRY);
140+
g_pHyprlock->renderAllOutputs();
141+
}
142+
143+
void CSessionPicker::onHover(const Vector2D& pos) {
144+
g_pSeatManager->m_pCursorShape->setShape(WP_CURSOR_SHAPE_DEVICE_V1_SHAPE_TEXT);
145+
}

src/renderer/widgets/SessionPicker.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ class CSessionPicker : public IWidget {
2727

2828
virtual void configure(const std::unordered_map<std::string, std::any>& props, const SP<COutput>& pOutput);
2929
virtual bool draw(const SRenderData& data);
30+
virtual CBox getBoundingBoxWl() const;
31+
virtual void onClick(uint32_t button, bool down, const Vector2D& pos);
32+
virtual void onHover(const Vector2D& pos);
3033

3134
void onGotSessionEntryAsset(const std::string& sessionName);
3235

@@ -48,6 +51,8 @@ class CSessionPicker : public IWidget {
4851

4952
Vector2D m_biggestEntryAssetSize;
5053

54+
CBox m_box;
55+
5156
struct {
5257
CHyprColor inner;
5358
CHyprColor selected;

0 commit comments

Comments
 (0)