Skip to content

Commit 0b06f6e

Browse files
remove CBackend::attempt
1 parent 5fac7c0 commit 0b06f6e

File tree

3 files changed

+22
-32
lines changed

3 files changed

+22
-32
lines changed

include/hyprtoolkit/core/Backend.hpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,6 @@ namespace Hyprtoolkit {
3333
*/
3434
static Hyprutils::Memory::CSharedPointer<CBackend> create();
3535

36-
/*
37-
Attempt to initialize the platform.
38-
Optional. Can be used in case the outputAdded event is used to create new windows.
39-
In such a szenario the platform must be initialized before opening a window.
40-
*/
41-
bool attempt();
42-
4336
/*
4437
Destroy the backend.
4538
Backend will be destroyed once:

src/core/Backend.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,16 @@ SP<CBackend> CBackend::create() {
6969
g_logger->log(HT_LOG_ERROR, "couldn't start aq backend");
7070
return nullptr;
7171
}
72-
73-
return g_backend;
74-
};
75-
76-
bool CBackend::attempt() {
7772
g_waylandPlatform = makeUnique<CWaylandPlatform>();
7873
if (!g_waylandPlatform->attempt()) {
7974
g_waylandPlatform = nullptr;
80-
return false;
75+
return nullptr;
8176
}
8277
g_openGL = makeShared<COpenGLRenderer>(g_waylandPlatform->m_drmState.fd);
8378
g_renderer = g_openGL;
84-
return true;
85-
}
79+
80+
return g_backend;
81+
};
8682

8783
void CBackend::destroy() {
8884
terminate();
@@ -111,7 +107,7 @@ std::vector<SP<IOutput>> CBackend::getOutputs() {
111107
}
112108

113109
SP<IWindow> CBackend::openWindow(const SWindowCreationData& data) {
114-
if (!g_waylandPlatform && !attempt())
110+
if (!g_waylandPlatform)
115111
return nullptr;
116112

117113
if (data.type == HT_WINDOW_LAYER) {

tests/SimpleSessionLock.cpp

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static void layout(const SP<IWindow>& window) {
5151

5252
auto rect4 = CRectangleBuilder::begin() //
5353
->color([] { return CHyprColor{0.4F, 0.2F, 0.4F}; })
54-
->rounding(10)
54+
->rounding(0)
5555
->size({CDynamicSize::HT_SIZE_ABSOLUTE, CDynamicSize::HT_SIZE_ABSOLUTE, {50, 50}})
5656
->commence();
5757

@@ -62,12 +62,12 @@ static void layout(const SP<IWindow>& window) {
6262
->size({CDynamicSize::HT_SIZE_ABSOLUTE, CDynamicSize::HT_SIZE_ABSOLUTE, {447, 447}})
6363
->commence();
6464

65-
auto text = CTextBuilder::begin()->text("world is a fuck")->color([] { return CHyprColor{0.4F, 0.4F, 0.4F}; })->commence();
65+
auto text = CTextBuilder::begin()->text("never give up")->color([] { return CHyprColor{0.4F, 0.4F, 0.4F}; })->commence();
6666

6767
auto button = CButtonBuilder::begin()
68-
->label("Click me bitch")
69-
->onMainClick([](SP<CButtonElement> el) { el->rebuild()->label(std::format("Clicked {} times bitch", buttonClicks++))->commence(); })
70-
->onRightClick([](SP<CButtonElement> el) { el->rebuild()->label("Reset bitch")->commence(); })
68+
->label("Click me kind person")
69+
->onMainClick([](SP<CButtonElement> el) { el->rebuild()->label(std::format("Clicked {} times", buttonClicks++))->commence(); })
70+
->onRightClick([](SP<CButtonElement> el) { el->rebuild()->label("Reset")->commence(); })
7171
->size({CDynamicSize::HT_SIZE_AUTO, CDynamicSize::HT_SIZE_AUTO, {1, 1}})
7272
->commence();
7373

@@ -100,6 +100,15 @@ static void onWindowClose(WP<IWindow> window) {
100100
}
101101
}
102102

103+
static void createLockSurface(SP<IOutput> output) {
104+
windows.emplace_back(CWindowBuilder::begin()->type(HT_WINDOW_LOCK_SURFACE)->prefferedOutput(output)->commence());
105+
std::println("New surface {}!", (uintptr_t)windows.back().get());
106+
WP<IWindow> weakWindow = windows.back();
107+
weakWindow->m_events.closeRequest.listenStatic([weakWindow]() { onWindowClose(weakWindow); });
108+
109+
layout(weakWindow.lock());
110+
}
111+
103112
int main(int argc, char** argv, char** envp) {
104113
int unlockSecs = 1;
105114
if (argc == 2)
@@ -111,18 +120,10 @@ int main(int argc, char** argv, char** envp) {
111120
return -1;
112121
}
113122

114-
backend->m_events.outputAdded.listenStatic([](SP<IOutput> output) {
115-
windows.emplace_back(CWindowBuilder::begin()->type(HT_WINDOW_LOCK_SURFACE)->prefferedOutput(output)->commence());
116-
std::println("New surface {}!", (uintptr_t)windows.back().get());
117-
WP<IWindow> window = windows.back();
118-
window->m_events.closeRequest.listenStatic([window]() { onWindowClose(window); });
119-
120-
layout(window.lock());
121-
});
123+
backend->m_events.outputAdded.listenStatic(createLockSurface);
122124

123-
if (!backend->attempt()) {
124-
std::println("Backend attempt failed!");
125-
return -1;
125+
for (const auto& o: backend->getOutputs()) {
126+
createLockSurface(o);
126127
}
127128

128129
backend->addTimer(std::chrono::seconds(unlockSecs), [](auto, auto) { backend->unlockSession(); }, nullptr);

0 commit comments

Comments
 (0)