This repository has been archived by the owner on Nov 1, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
80 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,80 @@ | ||
#include <wayland-client.h> | ||
#include "wlr-layer-shell-unstable-v1-client-protocol.h" | ||
|
||
struct wl_compositor *compositor; | ||
struct wl_pointer *pointer; | ||
struct wl_seat *seat; | ||
struct wl_shell *shell; | ||
struct zwp_pointer_constraints_v1 *pointer_constraints; | ||
|
||
static void registry_global(void *data, | ||
struct wl_registry *registry, uint32_t name, | ||
const char *interface, uint32_t version) { | ||
if (strcmp(interface, wl_compositor_interface.name) == 0) { | ||
compositor = wl_registry_bind(registry, name, | ||
&wl_compositor_interface, min(version, 4)); | ||
} else if (strcmp(interface, wl_shell_interface.name) == 0) { | ||
shell = wl_registry_bind(registry, name, | ||
&wl_shell_interface, min(version, 1)); | ||
} else if (strcmp(interface, wl_seat_interface.name) == 0) { | ||
seat = wl_registry_bind(registry, name, | ||
&wl_seat_interface, min(version, 2)); | ||
pointer = wl_seat_get_pointer(seat); | ||
wl_pointer_add_listener(pointer, &pointer_listener, | ||
NULL); | ||
} else if (strcmp(interface, zwp_pointer_constraints_v1_interface.name) == 0) { | ||
pointer_constraints = wl_registry_bind(registry, name, | ||
&zwp_pointer_constraints_v1_interface, min(version, 1)); | ||
} | ||
} | ||
|
||
static void registry_global_remove(void *a, | ||
struct wl_registry *b, uint32_t c) {} | ||
|
||
static const struct wl_registry_listener registry_listener = { | ||
.global = registry_global, | ||
.global_remove = registry_global_remove | ||
}; | ||
|
||
int main() { | ||
struct wl_buffer *buffer; | ||
struct wl_shm_pool *pool; | ||
struct wl_shell_surface *surface; | ||
|
||
struct wl_registry *registry; | ||
|
||
struct wl_display *display = wl_display_connect(NULL); | ||
|
||
registry = wl_display_get_registry(display); | ||
wl_registry_add_listener(registry, ®istry_listener, | ||
NULL); | ||
wl_display_roundtrip(display); | ||
wl_registry_destroy(registry); | ||
|
||
struct wl_surface* surface = wl_compositor_create_surface(compositor); | ||
struct wl_shell_surface* shell_surface = wl_shell_get_shell_surface(shell, surface); | ||
|
||
struct wl_region *region = wl_compositor_create_region(compositor); | ||
wl_region_add(region, 64, 64, 64, 64); | ||
|
||
struct zwp_confined_pointer_v1 *confined_pointer = zwp_pointer_constraints_v1_confine_pointer(pointer_constraints, | ||
wl_shell_surface_get_user_data(surface), | ||
pointer, | ||
region, | ||
ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT | ||
); | ||
|
||
struct wl_region *region2 = wl_compositor_create_region(compositor); | ||
wl_region_add(region2, 128, 64, 64, 64); | ||
zwp_confined_pointer_v1_set_region(confined_pointer, region2); | ||
|
||
wl_surface_commit(wl_shell_surface_get_user_data(surface)); | ||
|
||
while (true) { | ||
if (wl_display_dispatch(display) < 0) { | ||
return 1; | ||
} | ||
} | ||
|
||
return 0; | ||
} |