-
Notifications
You must be signed in to change notification settings - Fork 2
feature: implement wl_init and wl_finish #3
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
Open
glenv1ew
wants to merge
2
commits into
podomy:main
Choose a base branch
from
glenv1ew:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+126
−0
Open
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,3 +6,5 @@ current.log | |
| *.o | ||
| .cache/ | ||
| /.vs | ||
| .idea | ||
| .git | ||
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,124 @@ | ||
| #include "wl.h" | ||
|
|
||
| #include <stdio.h> | ||
| #include <string.h> | ||
|
|
||
| #include "xdg-shell-client-protocol.h" | ||
|
|
||
| // registry_global fires once for every global | ||
| // object the compositor advertises. Flint only | ||
| // needs the compositor and the xdg_wm_base | ||
| // shell, so every other interface is ignored. | ||
| static void registry_global(void* data, | ||
| struct wl_registry* registry, | ||
| uint32_t name, | ||
| const char* interface, | ||
| uint32_t version) { | ||
| (void)version; | ||
| struct Wl* wl = data; | ||
|
|
||
| if (strcmp(interface, wl_compositor_interface.name) == | ||
| 0) { | ||
| wl->compositor = wl_registry_bind( | ||
| registry, name, &wl_compositor_interface, 4); | ||
| } else if (strcmp(interface, | ||
| xdg_wm_base_interface.name) == 0) { | ||
| wl->wm_base = wl_registry_bind( | ||
| registry, name, &xdg_wm_base_interface, 1); | ||
| } | ||
| } | ||
|
|
||
| // registry_global_remove fires when a global | ||
| // goes away. Nothing in Flint reacts to that | ||
| // yet, but the listener struct requires it. | ||
| static void registry_global_remove( | ||
| void* data, struct wl_registry* registry, | ||
| uint32_t name) { | ||
| (void)data; | ||
| (void)registry; | ||
| (void)name; | ||
| } | ||
|
|
||
| static const struct wl_registry_listener | ||
| registry_listener = { | ||
| .global = registry_global, | ||
| .global_remove = registry_global_remove, | ||
| }; | ||
|
|
||
| bool wl_init(struct Wl* wl) { | ||
| memset(wl, 0, sizeof(*wl)); | ||
|
|
||
| // Connect to the compositor named by | ||
| // WAYLAND_DISPLAY, or the default socket | ||
| // when unset. | ||
| wl->display = wl_display_connect(NULL); | ||
| if (!wl->display) { | ||
| fprintf(stderr, "wl_display_connect failed\n"); | ||
| return false; | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a print statement that prints if a connection is established |
||
| wl->registry = wl_display_get_registry(wl->display); | ||
| if (!wl->registry) { | ||
| fprintf(stderr, | ||
| "wl_display_get_registry failed\n"); | ||
| return false; | ||
| } | ||
|
|
||
| wl_registry_add_listener(wl->registry, | ||
| ®istry_listener, wl); | ||
|
|
||
| // Round-trip so the global announcements | ||
| // handled above are dispatched before we | ||
| // check what got bound. | ||
| if (wl_display_roundtrip(wl->display) < 0) { | ||
| fprintf(stderr, "wl_display_roundtrip failed\n"); | ||
| return false; | ||
| } | ||
|
|
||
| if (!wl->compositor) { | ||
| fprintf(stderr, | ||
| "wl_compositor global not found\n"); | ||
| return false; | ||
| } | ||
| if (!wl->wm_base) { | ||
| fprintf(stderr, | ||
| "xdg_wm_base global not found\n"); | ||
| return false; | ||
| } | ||
|
|
||
| wl->surface = | ||
| wl_compositor_create_surface(wl->compositor); | ||
| if (!wl->surface) { | ||
| fprintf(stderr, | ||
| "wl_compositor_create_surface failed\n"); | ||
| return false; | ||
| } | ||
|
|
||
| return true; | ||
| } | ||
|
|
||
| void wl_finish(struct Wl* wl) { | ||
| // Reverse order of creation: surface, then | ||
| // the two bound globals, then the registry, | ||
| // then the connection itself. | ||
| if (wl->surface) { | ||
| wl_surface_destroy(wl->surface); | ||
| wl->surface = NULL; | ||
| } | ||
| if (wl->wm_base) { | ||
| xdg_wm_base_destroy(wl->wm_base); | ||
| wl->wm_base = NULL; | ||
| } | ||
| if (wl->compositor) { | ||
| wl_compositor_destroy(wl->compositor); | ||
| wl->compositor = NULL; | ||
| } | ||
| if (wl->registry) { | ||
| wl_registry_destroy(wl->registry); | ||
| wl->registry = NULL; | ||
| } | ||
| if (wl->display) { | ||
| wl_display_disconnect(wl->display); | ||
| wl->display = NULL; | ||
| } | ||
| } | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add a comment explaining why these parameters are (void)