Last active
April 19, 2018 21:11
-
-
Save emersion/4b5aa6df269daf8e53b900eef0c11be9 to your computer and use it in GitHub Desktop.
Creates a client that sends a fullscreen request while unmapped
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
#include <GLES2/gl2.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <wayland-client.h> | |
#include <wayland-egl.h> | |
#include <wlr/render/egl.h> | |
#include "xdg-shell-unstable-v6-client-protocol.h" | |
#include "idle-inhibit-unstable-v1-client-protocol.h" | |
#include <linux/input-event-codes.h> | |
#define DEFAULT_WIDTH 500 | |
#define DEFAULT_HEIGHT 300 | |
static int width = DEFAULT_WIDTH, height = DEFAULT_HEIGHT; | |
static struct wl_compositor *compositor = NULL; | |
static struct wl_seat *seat = NULL; | |
static struct zxdg_shell_v6 *xdg_shell = NULL; | |
struct wlr_egl egl; | |
struct wl_egl_window *egl_window; | |
struct wlr_egl_surface *egl_surface; | |
static void draw(void) { | |
eglMakeCurrent(egl.display, egl_surface, egl_surface, egl.context); | |
float color[] = {1.0, 1.0, 0.0, 1.0}; | |
glViewport(0, 0, width, height); | |
glClearColor(color[0], color[1], color[2], color[3]); | |
glClear(GL_COLOR_BUFFER_BIT); | |
eglSwapBuffers(egl.display, egl_surface); | |
} | |
static void pointer_handle_button(void *data, struct wl_pointer *pointer, uint32_t serial, | |
uint32_t time, uint32_t button, uint32_t state) { | |
//struct wl_surface *surface = data; | |
if (state == WL_POINTER_BUTTON_STATE_PRESSED) { | |
// TODO: do something | |
} | |
draw(); | |
} | |
static void pointer_handle_enter(void *data, struct wl_pointer *wl_pointer, | |
uint32_t serial, struct wl_surface *surface, | |
wl_fixed_t surface_x, wl_fixed_t surface_y) { | |
// This space intentionally left blank | |
} | |
static void pointer_handle_leave(void *data, struct wl_pointer *wl_pointer, | |
uint32_t serial, struct wl_surface *surface) { | |
// This space intentionally left blank | |
} | |
static void pointer_handle_motion(void *data, struct wl_pointer *wl_pointer, | |
uint32_t time, wl_fixed_t surface_x, wl_fixed_t surface_y) { | |
// This space intentionally left blank | |
} | |
static void pointer_handle_axis(void *data, struct wl_pointer *wl_pointer, | |
uint32_t time, uint32_t axis, wl_fixed_t value) { | |
// This space intentionally left blank | |
} | |
static void pointer_handle_frame(void *data, struct wl_pointer *wl_pointer) { | |
// This space intentionally left blank | |
} | |
static void pointer_handle_axis_source(void *data, | |
struct wl_pointer *wl_pointer, uint32_t axis_source) { | |
// This space intentionally left blank | |
} | |
static void pointer_handle_axis_stop(void *data, | |
struct wl_pointer *wl_pointer, uint32_t time, uint32_t axis) { | |
// This space intentionally left blank | |
} | |
static void pointer_handle_axis_discrete(void *data, | |
struct wl_pointer *wl_pointer, uint32_t axis, int32_t discrete) { | |
// This space intentionally left blank | |
} | |
static const struct wl_pointer_listener pointer_listener = { | |
.enter = pointer_handle_enter, | |
.leave = pointer_handle_leave, | |
.motion = pointer_handle_motion, | |
.button = pointer_handle_button, | |
.axis = pointer_handle_axis, | |
.frame = pointer_handle_frame, | |
.axis_source = pointer_handle_axis_source, | |
.axis_stop = pointer_handle_axis_stop, | |
.axis_discrete = pointer_handle_axis_discrete, | |
}; | |
static void zxdg_surface_v6_handle_configure(void *data, | |
struct zxdg_surface_v6 *zxdg_surface_v6, uint32_t serial) { | |
zxdg_surface_v6_ack_configure(zxdg_surface_v6, serial); | |
wl_egl_window_resize(egl_window, width, height, 0, 0); | |
draw(); | |
} | |
static const struct zxdg_surface_v6_listener zxdg_surface_v6_listener = { | |
.configure = zxdg_surface_v6_handle_configure, | |
}; | |
static void zxdg_toplevel_v6_handle_configure(void *data, | |
struct zxdg_toplevel_v6 *zxdg_toplevel_v6, int32_t w, int32_t h, | |
struct wl_array *states) { | |
if (w == 0 || h == 0) { | |
width = DEFAULT_WIDTH; | |
height = DEFAULT_HEIGHT; | |
} else { | |
width = w; | |
height = h; | |
} | |
} | |
static void zxdg_toplevel_v6_handle_close(void *data, | |
struct zxdg_toplevel_v6 *zxdg_toplevel_v6) { | |
exit(EXIT_SUCCESS); | |
} | |
static const struct zxdg_toplevel_v6_listener zxdg_toplevel_v6_listener = { | |
.configure = zxdg_toplevel_v6_handle_configure, | |
.close = zxdg_toplevel_v6_handle_close, | |
}; | |
static void handle_global(void *data, struct wl_registry *registry, | |
uint32_t name, const char *interface, uint32_t version) { | |
if (strcmp(interface, "wl_compositor") == 0) { | |
compositor = wl_registry_bind(registry, name, | |
&wl_compositor_interface, 1); | |
} else if (strcmp(interface, zxdg_shell_v6_interface.name) == 0) { | |
xdg_shell = wl_registry_bind(registry, name, &zxdg_shell_v6_interface, 1); | |
} else if (strcmp(interface, wl_seat_interface.name) == 0) { | |
seat = wl_registry_bind(registry, name, &wl_seat_interface, version); | |
} | |
} | |
static void handle_global_remove(void *data, struct wl_registry *registry, | |
uint32_t name) { | |
// who cares | |
} | |
static const struct wl_registry_listener registry_listener = { | |
.global = handle_global, | |
.global_remove = handle_global_remove, | |
}; | |
int main(int argc, char **argv) { | |
struct wl_display *display = wl_display_connect(NULL); | |
if (display == NULL) { | |
fprintf(stderr, "Failed to create display\n"); | |
return EXIT_FAILURE; | |
} | |
struct wl_registry *registry = wl_display_get_registry(display); | |
wl_registry_add_listener(registry, ®istry_listener, NULL); | |
wl_display_dispatch(display); | |
wl_display_roundtrip(display); | |
if (compositor == NULL) { | |
fprintf(stderr, "wl-compositor not available\n"); | |
return EXIT_FAILURE; | |
} | |
if (xdg_shell == NULL) { | |
fprintf(stderr, "xdg-shell not available\n"); | |
return EXIT_FAILURE; | |
} | |
wlr_egl_init(&egl, EGL_PLATFORM_WAYLAND_EXT, display, NULL, | |
WL_SHM_FORMAT_ARGB8888); | |
struct wl_surface *surface = wl_compositor_create_surface(compositor); | |
struct zxdg_surface_v6 *zxdg_surface_v6 = | |
zxdg_shell_v6_get_xdg_surface(xdg_shell, surface); | |
struct zxdg_toplevel_v6 *zxdg_toplevel_v6 = zxdg_surface_v6_get_toplevel(zxdg_surface_v6); | |
struct wl_pointer *pointer = wl_seat_get_pointer(seat); | |
wl_pointer_add_listener(pointer, &pointer_listener, surface); | |
zxdg_surface_v6_add_listener(zxdg_surface_v6, &zxdg_surface_v6_listener, NULL); | |
zxdg_toplevel_v6_add_listener(zxdg_toplevel_v6, &zxdg_toplevel_v6_listener, NULL); | |
//zxdg_toplevel_v6_set_maximized(zxdg_toplevel_v6); | |
wl_surface_commit(surface); | |
zxdg_toplevel_v6_set_fullscreen(zxdg_toplevel_v6, NULL); | |
wl_surface_commit(surface); | |
egl_window = wl_egl_window_create(surface, width, height); | |
egl_surface = wlr_egl_create_surface(&egl, egl_window); | |
wl_display_roundtrip(display); | |
draw(); | |
while (wl_display_dispatch(display) != -1) { | |
// This space intentionally left blank | |
} | |
return EXIT_SUCCESS; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment