-
Notifications
You must be signed in to change notification settings - Fork 53
feat: Support TTY switching with DDM #489
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| find_package(TreelandProtocols REQUIRED) | ||
|
|
||
| ws_generate_local(server ${TREELAND_PROTOCOLS_DATA_DIR}/treeland-ddm-v1.xml treeland-ddm-v1-protocol) | ||
|
|
||
| impl_treeland( | ||
| NAME | ||
| module_ddm | ||
| SOURCE | ||
| ${CMAKE_SOURCE_DIR}/src/modules/ddm/ddminterfacev1.h | ||
| ${CMAKE_SOURCE_DIR}/src/modules/ddm/ddminterfacev1.cpp | ||
| ${WAYLAND_PROTOCOLS_OUTPUTDIR}/treeland-ddm-v1-protocol.c | ||
| INCLUDE | ||
| $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}> | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| // Copyright (C) 2025 April Lu <apr3vau@outlook.com>. | ||
| // SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only | ||
|
|
||
| #include "ddminterfacev1.h" | ||
| #include "treeland-ddm-v1-protocol.h" | ||
| #include "common/treelandlogging.h" | ||
| #include "helper.h" | ||
| #include "usermodel.h" | ||
|
|
||
| #include <wayland-server-core.h> | ||
| #include <wayland-server.h> | ||
| #include <wayland-util.h> | ||
| #include <QDebug> | ||
|
|
||
| struct treeland_ddm { | ||
| wl_resource *resource; | ||
| }; | ||
|
|
||
| // request implementation | ||
|
|
||
| static void switchToGreeter([[maybe_unused]] struct wl_client *client, [[maybe_unused]] struct wl_resource *resource) { | ||
| Helper::instance()->showLockScreen(false); | ||
| } | ||
|
|
||
| static void switchToUser([[maybe_unused]] struct wl_client *client, [[maybe_unused]] struct wl_resource *resource, const char *username) { | ||
| if (strcmp(username, "ddm") != 0) { | ||
| Helper::instance()->userModel()->setCurrentUserName(QString(username)); | ||
| } | ||
| } | ||
|
|
||
| static void activateSession([[maybe_unused]] struct wl_client *client, [[maybe_unused]] struct wl_resource *resource) { | ||
| Helper::instance()->activateSession(); | ||
| } | ||
|
|
||
| static void deactivateSession([[maybe_unused]] struct wl_client *client, [[maybe_unused]] struct wl_resource *resource) { | ||
| Helper::instance()->deactivateSession(); | ||
| } | ||
|
|
||
| static const struct treeland_ddm_interface treeland_ddm_impl { | ||
| .switch_to_greeter = switchToGreeter, | ||
| .switch_to_user = switchToUser, | ||
| .activate_session = activateSession, | ||
| .deactivate_session = deactivateSession, | ||
| }; | ||
|
|
||
| // wayland object binding | ||
|
|
||
| static void handleResourceDestroy(struct wl_resource *resource) { | ||
| qCWarning(treelandCore) << "DDM connection lost"; | ||
| auto ddm = static_cast<struct treeland_ddm *>(wl_resource_get_user_data(resource)); | ||
| ddm->resource = nullptr; | ||
| } | ||
|
|
||
| void handleBindingGlobal(struct wl_client *client, void *data, uint32_t version, uint32_t id) { | ||
| auto ddm = static_cast<struct treeland_ddm *>(data); | ||
| auto *resource = wl_resource_create(client, &treeland_ddm_interface, version, id); | ||
| wl_resource_set_implementation(resource, &treeland_ddm_impl, ddm, handleResourceDestroy); | ||
| ddm->resource = resource; | ||
| qCDebug(treelandCore) << "DDM connection established"; | ||
|
|
||
| treeland_ddm_send_acquire_vt(resource, 0); | ||
| } | ||
|
|
||
| // DDMInterfaceV1 | ||
|
|
||
| DDMInterfaceV1::DDMInterfaceV1() { | ||
|
|
||
| } | ||
|
|
||
| DDMInterfaceV1::~DDMInterfaceV1() { | ||
| } | ||
|
|
||
| QByteArrayView DDMInterfaceV1::interfaceName() const { | ||
| QByteArray arr(treeland_ddm_interface.name); | ||
| return QByteArrayView(arr); | ||
| } | ||
|
|
||
| bool DDMInterfaceV1::isConnected() const { | ||
| auto ddm = static_cast<struct treeland_ddm *>(m_handle); | ||
| return ddm && ddm->resource; | ||
| } | ||
|
|
||
| void DDMInterfaceV1::create(WServer *server) { | ||
| auto ddm = new treeland_ddm { .resource = nullptr }; | ||
| m_handle = ddm; | ||
| m_global = wl_global_create(server->handle()->handle(), &treeland_ddm_interface, | ||
| treeland_ddm_interface.version, ddm, handleBindingGlobal); | ||
| } | ||
|
|
||
| void DDMInterfaceV1::destroy([[maybe_unused]] WServer *server) { | ||
| wl_global_destroy(m_global); | ||
| auto ddm = static_cast<struct treeland_ddm *>(m_handle); | ||
| delete ddm; | ||
| m_handle = nullptr; | ||
| } | ||
|
|
||
| wl_global *DDMInterfaceV1::global() const { | ||
| return m_global; | ||
| } | ||
|
|
||
| // Event wrapper | ||
|
|
||
| void DDMInterfaceV1::switchToVt(int vtnr) { | ||
| auto ddm = static_cast<struct treeland_ddm *>(m_handle); | ||
| if (isConnected()) | ||
| treeland_ddm_send_switch_to_vt(ddm->resource, vtnr); | ||
| else | ||
| qCWarning(treelandCore) << "DDM is not conected when trying to call switchToVt"; | ||
| } | ||
|
|
||
| void DDMInterfaceV1::acquireVt(int vtnr) { | ||
| auto ddm = static_cast<struct treeland_ddm *>(m_handle); | ||
| if (isConnected()) | ||
| treeland_ddm_send_acquire_vt(ddm->resource, vtnr); | ||
| else | ||
| qCWarning(treelandCore) << "DDM is not connected when trying to call acquireVt"; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // Copyright (C) 2025 April Lu <apr3vau@outlook.com>. | ||
| // SPDX-License-Identifier: Apache-2.0 OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only | ||
|
|
||
| #include "wserver.h" | ||
|
|
||
| /** | ||
| * The server-side wrapper for treeland private protocol. | ||
| */ | ||
| class DDMInterfaceV1 : public Waylib::Server::WServerInterface { | ||
| public: | ||
| DDMInterfaceV1(); | ||
| ~DDMInterfaceV1() override; | ||
| QByteArrayView interfaceName() const override; | ||
| bool isConnected() const; | ||
| void switchToVt(int vtnr); | ||
| void acquireVt(int vtnr); | ||
| protected: | ||
| void create(Waylib::Server::WServer *server) override; | ||
| void destroy(Waylib::Server::WServer *server) override; | ||
| wl_global *global() const override; | ||
| private: | ||
| struct wl_global *m_global { nullptr }; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.