feat: project init

This commit is contained in:
2026-02-11 19:33:42 +01:00
parent 98cb519f22
commit 40f6b874cf
7 changed files with 3312 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@@ -0,0 +1 @@
build/

5
Makefile Normal file
View File

@@ -0,0 +1,5 @@
LIBS = $(shell pkg-config --libs wayland-client wayland-egl egl glesv2)
main: main.c
gcc -Wall -Wextra -o main main.c -I./include/ $(LIBS) xdg-shell-protocol.c -g

View File

@@ -0,0 +1,295 @@
/* Generated by wayland-scanner 1.24.0 */
#ifndef HYPRLAND_SURFACE_V1_CLIENT_PROTOCOL_H
#define HYPRLAND_SURFACE_V1_CLIENT_PROTOCOL_H
#include <stdint.h>
#include <stddef.h>
#include "wayland-client.h"
#ifdef __cplusplus
extern "C" {
#endif
/**
* @page page_hyprland_surface_v1 The hyprland_surface_v1 protocol
* hyprland-specific wl_surface extensions
*
* @section page_desc_hyprland_surface_v1 Description
*
* This protocol exposes hyprland-specific wl_surface properties.
*
* @section page_ifaces_hyprland_surface_v1 Interfaces
* - @subpage page_iface_hyprland_surface_manager_v1 - manager for hyprland surface objects
* - @subpage page_iface_hyprland_surface_v1 - hyprland-specific wl_surface properties
* @section page_copyright_hyprland_surface_v1 Copyright
* <pre>
*
* Copyright © 2025 outfoxxed
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* </pre>
*/
struct hyprland_surface_manager_v1;
struct hyprland_surface_v1;
struct wl_region;
struct wl_surface;
#ifndef HYPRLAND_SURFACE_MANAGER_V1_INTERFACE
#define HYPRLAND_SURFACE_MANAGER_V1_INTERFACE
/**
* @page page_iface_hyprland_surface_manager_v1 hyprland_surface_manager_v1
* @section page_iface_hyprland_surface_manager_v1_desc Description
*
* This interface allows a client to create hyprland surface objects.
* @section page_iface_hyprland_surface_manager_v1_api API
* See @ref iface_hyprland_surface_manager_v1.
*/
/**
* @defgroup iface_hyprland_surface_manager_v1 The hyprland_surface_manager_v1 interface
*
* This interface allows a client to create hyprland surface objects.
*/
extern const struct wl_interface hyprland_surface_manager_v1_interface;
#endif
#ifndef HYPRLAND_SURFACE_V1_INTERFACE
#define HYPRLAND_SURFACE_V1_INTERFACE
/**
* @page page_iface_hyprland_surface_v1 hyprland_surface_v1
* @section page_iface_hyprland_surface_v1_desc Description
*
* This interface allows access to hyprland-specific properties of a wl_surface.
*
* Once the wl_surface has been destroyed, the hyprland surface object must be
* destroyed as well. All other operations are a protocol error.
* @section page_iface_hyprland_surface_v1_api API
* See @ref iface_hyprland_surface_v1.
*/
/**
* @defgroup iface_hyprland_surface_v1 The hyprland_surface_v1 interface
*
* This interface allows access to hyprland-specific properties of a wl_surface.
*
* Once the wl_surface has been destroyed, the hyprland surface object must be
* destroyed as well. All other operations are a protocol error.
*/
extern const struct wl_interface hyprland_surface_v1_interface;
#endif
#ifndef HYPRLAND_SURFACE_MANAGER_V1_ERROR_ENUM
#define HYPRLAND_SURFACE_MANAGER_V1_ERROR_ENUM
enum hyprland_surface_manager_v1_error {
/**
* wl_surface already has a hyprland surface object
*/
HYPRLAND_SURFACE_MANAGER_V1_ERROR_ALREADY_CONSTRUCTED = 0,
};
#endif /* HYPRLAND_SURFACE_MANAGER_V1_ERROR_ENUM */
#define HYPRLAND_SURFACE_MANAGER_V1_GET_HYPRLAND_SURFACE 0
#define HYPRLAND_SURFACE_MANAGER_V1_DESTROY 1
/**
* @ingroup iface_hyprland_surface_manager_v1
*/
#define HYPRLAND_SURFACE_MANAGER_V1_GET_HYPRLAND_SURFACE_SINCE_VERSION 1
/**
* @ingroup iface_hyprland_surface_manager_v1
*/
#define HYPRLAND_SURFACE_MANAGER_V1_DESTROY_SINCE_VERSION 1
/** @ingroup iface_hyprland_surface_manager_v1 */
static inline void
hyprland_surface_manager_v1_set_user_data(struct hyprland_surface_manager_v1 *hyprland_surface_manager_v1, void *user_data)
{
wl_proxy_set_user_data((struct wl_proxy *) hyprland_surface_manager_v1, user_data);
}
/** @ingroup iface_hyprland_surface_manager_v1 */
static inline void *
hyprland_surface_manager_v1_get_user_data(struct hyprland_surface_manager_v1 *hyprland_surface_manager_v1)
{
return wl_proxy_get_user_data((struct wl_proxy *) hyprland_surface_manager_v1);
}
static inline uint32_t
hyprland_surface_manager_v1_get_version(struct hyprland_surface_manager_v1 *hyprland_surface_manager_v1)
{
return wl_proxy_get_version((struct wl_proxy *) hyprland_surface_manager_v1);
}
/**
* @ingroup iface_hyprland_surface_manager_v1
*
* Create a hyprland surface object for the given wayland surface.
*
* If the wl_surface already has an associated hyprland_surface_v1 object,
* even from a different manager, creation is a protocol error.
*/
static inline struct hyprland_surface_v1 *
hyprland_surface_manager_v1_get_hyprland_surface(struct hyprland_surface_manager_v1 *hyprland_surface_manager_v1, struct wl_surface *surface)
{
struct wl_proxy *id;
id = wl_proxy_marshal_flags((struct wl_proxy *) hyprland_surface_manager_v1,
HYPRLAND_SURFACE_MANAGER_V1_GET_HYPRLAND_SURFACE, &hyprland_surface_v1_interface, wl_proxy_get_version((struct wl_proxy *) hyprland_surface_manager_v1), 0, NULL, surface);
return (struct hyprland_surface_v1 *) id;
}
/**
* @ingroup iface_hyprland_surface_manager_v1
*
* Destroy the surface manager.
* This does not destroy existing surface objects.
*/
static inline void
hyprland_surface_manager_v1_destroy(struct hyprland_surface_manager_v1 *hyprland_surface_manager_v1)
{
wl_proxy_marshal_flags((struct wl_proxy *) hyprland_surface_manager_v1,
HYPRLAND_SURFACE_MANAGER_V1_DESTROY, NULL, wl_proxy_get_version((struct wl_proxy *) hyprland_surface_manager_v1), WL_MARSHAL_FLAG_DESTROY);
}
#ifndef HYPRLAND_SURFACE_V1_ERROR_ENUM
#define HYPRLAND_SURFACE_V1_ERROR_ENUM
enum hyprland_surface_v1_error {
/**
* wl_surface was destroyed
*/
HYPRLAND_SURFACE_V1_ERROR_NO_SURFACE = 0,
/**
* given opacity was not in the range 0.0 - 1.0 (inclusive)
*/
HYPRLAND_SURFACE_V1_ERROR_OUT_OF_RANGE = 1,
};
#endif /* HYPRLAND_SURFACE_V1_ERROR_ENUM */
#define HYPRLAND_SURFACE_V1_SET_OPACITY 0
#define HYPRLAND_SURFACE_V1_DESTROY 1
#define HYPRLAND_SURFACE_V1_SET_VISIBLE_REGION 2
/**
* @ingroup iface_hyprland_surface_v1
*/
#define HYPRLAND_SURFACE_V1_SET_OPACITY_SINCE_VERSION 1
/**
* @ingroup iface_hyprland_surface_v1
*/
#define HYPRLAND_SURFACE_V1_DESTROY_SINCE_VERSION 1
/**
* @ingroup iface_hyprland_surface_v1
*/
#define HYPRLAND_SURFACE_V1_SET_VISIBLE_REGION_SINCE_VERSION 2
/** @ingroup iface_hyprland_surface_v1 */
static inline void
hyprland_surface_v1_set_user_data(struct hyprland_surface_v1 *hyprland_surface_v1, void *user_data)
{
wl_proxy_set_user_data((struct wl_proxy *) hyprland_surface_v1, user_data);
}
/** @ingroup iface_hyprland_surface_v1 */
static inline void *
hyprland_surface_v1_get_user_data(struct hyprland_surface_v1 *hyprland_surface_v1)
{
return wl_proxy_get_user_data((struct wl_proxy *) hyprland_surface_v1);
}
static inline uint32_t
hyprland_surface_v1_get_version(struct hyprland_surface_v1 *hyprland_surface_v1)
{
return wl_proxy_get_version((struct wl_proxy *) hyprland_surface_v1);
}
/**
* @ingroup iface_hyprland_surface_v1
*
* Sets a multiplier for the overall opacity of the surface.
* This multiplier applies to visual effects such as blur behind the surface
* in addition to the surface's content.
*
* The default value is 1.0.
* Setting a value outside of the range 0.0 - 1.0 (inclusive) is a protocol error.
* Does not take effect until wl_surface.commit is called.
*/
static inline void
hyprland_surface_v1_set_opacity(struct hyprland_surface_v1 *hyprland_surface_v1, wl_fixed_t opacity)
{
wl_proxy_marshal_flags((struct wl_proxy *) hyprland_surface_v1,
HYPRLAND_SURFACE_V1_SET_OPACITY, NULL, wl_proxy_get_version((struct wl_proxy *) hyprland_surface_v1), 0, opacity);
}
/**
* @ingroup iface_hyprland_surface_v1
*
* Destroy the hyprland surface object, resetting properties provided
* by this interface to their default values on the next wl_surface.commit.
*/
static inline void
hyprland_surface_v1_destroy(struct hyprland_surface_v1 *hyprland_surface_v1)
{
wl_proxy_marshal_flags((struct wl_proxy *) hyprland_surface_v1,
HYPRLAND_SURFACE_V1_DESTROY, NULL, wl_proxy_get_version((struct wl_proxy *) hyprland_surface_v1), WL_MARSHAL_FLAG_DESTROY);
}
/**
* @ingroup iface_hyprland_surface_v1
*
* This request sets the region of the surface that contains visible content.
* Visible content refers to content that has an alpha value greater than zero.
*
* The visible region is an optimization hint for the compositor that lets it
* avoid drawing parts of the surface that are not visible. Setting a visible region
* that does not contain all content in the surface may result in missing content
* not being drawn.
*
* The visible region is specified in buffer-local coordinates.
*
* The compositor ignores the parts of the visible region that fall outside of the surface.
* When all parts of the region fall outside of the buffer geometry, the compositor may
* avoid rendering the surface entirely.
*
* The initial value for the visible region is empty. Setting the
* visible region has copy semantics, and the wl_region object can be destroyed immediately.
* A NULL wl_region causes the visible region to be set to empty.
*
* Does not take effect until wl_surface.commit is called.
*/
static inline void
hyprland_surface_v1_set_visible_region(struct hyprland_surface_v1 *hyprland_surface_v1, struct wl_region *region)
{
wl_proxy_marshal_flags((struct wl_proxy *) hyprland_surface_v1,
HYPRLAND_SURFACE_V1_SET_VISIBLE_REGION, NULL, wl_proxy_get_version((struct wl_proxy *) hyprland_surface_v1), 0, region);
}
#ifdef __cplusplus
}
#endif
#endif

View File

File diff suppressed because it is too large Load Diff

81
src/hyprland-surface-v1.c Normal file
View File

@@ -0,0 +1,81 @@
/* Generated by wayland-scanner 1.24.0 */
/*
* Copyright © 2025 outfoxxed
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include <stdbool.h>
#include <stdlib.h>
#include <stdint.h>
#include "wayland-util.h"
#ifndef __has_attribute
# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */
#endif
#if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4)
#define WL_PRIVATE __attribute__ ((visibility("hidden")))
#else
#define WL_PRIVATE
#endif
extern const struct wl_interface hyprland_surface_v1_interface;
extern const struct wl_interface wl_region_interface;
extern const struct wl_interface wl_surface_interface;
static const struct wl_interface *hyprland_surface_v1_types[] = {
NULL,
&hyprland_surface_v1_interface,
&wl_surface_interface,
&wl_region_interface,
};
static const struct wl_message hyprland_surface_manager_v1_requests[] = {
{ "get_hyprland_surface", "no", hyprland_surface_v1_types + 1 },
{ "destroy", "", hyprland_surface_v1_types + 0 },
};
WL_PRIVATE const struct wl_interface hyprland_surface_manager_v1_interface = {
"hyprland_surface_manager_v1", 2,
2, hyprland_surface_manager_v1_requests,
0, NULL,
};
static const struct wl_message hyprland_surface_v1_requests[] = {
{ "set_opacity", "f", hyprland_surface_v1_types + 0 },
{ "destroy", "", hyprland_surface_v1_types + 0 },
{ "set_visible_region", "2?o", hyprland_surface_v1_types + 3 },
};
WL_PRIVATE const struct wl_interface hyprland_surface_v1_interface = {
"hyprland_surface_v1", 2,
3, hyprland_surface_v1_requests,
0, NULL,
};

362
src/main.c Normal file
View File

@@ -0,0 +1,362 @@
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <wayland-client-core.h>
#include <wayland-client-protocol.h>
#include <wayland-client.h>
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <GLES2/gl2.h>
#include <wayland-egl-core.h>
#include <wayland-egl.h>
#include <fcntl.h> /* For O_* constants */
#include <sys/mman.h>
#include <sys/stat.h> /* For mode constants */
#include <unistd.h>
#include "./include/xdg-shell-client-protocol.h"
#define UNUSED(x) (void)(x)
#define WIDTH 780
#define HEIGHT 420
typedef struct {
struct wl_display *display;
EGLDisplay egl_display;
struct wl_egl_window *egl_window;
EGLSurface egl_surface;
bool ready;
struct wl_compositor *compositor;
struct xdg_wm_base *wm_base;
struct wl_surface *w_surface;
struct xdg_surface *x_surface;
struct xdg_toplevel *toplevel;
struct wl_shm *shm;
// int shm_fd;
// struct wl_shm_pool *pool;
// uint8_t *pool_data;
// struct wl_buffer *buffer;
struct wl_callback *frame_callback;
GLuint program;
} State;
static GLuint compile_shader(GLenum type, const char *src) {
GLuint shader = glCreateShader(type);
glShaderSource(shader, 1, &src, NULL);
glCompileShader(shader);
GLint ok;
glGetShaderiv(shader, GL_COMPILE_STATUS, &ok);
if (!ok) {
char log[512];
glGetShaderInfoLog(shader, sizeof(log), NULL, log);
fprintf(stderr, "shader compile error: %s\n", log);
exit(1);
}
return shader;
}
static GLuint create_program(const char *vs_src, const char *fs_src) {
GLuint vs = compile_shader(GL_VERTEX_SHADER, vs_src);
GLuint fs = compile_shader(GL_FRAGMENT_SHADER, fs_src);
GLuint prog = glCreateProgram();
glAttachShader(prog, vs);
glAttachShader(prog, fs);
glLinkProgram(prog);
GLint ok;
glGetProgramiv(prog, GL_LINK_STATUS, &ok);
if (!ok) {
char log[512];
glGetProgramInfoLog(prog, sizeof(log), NULL, log);
fprintf(stderr, "program link error: %s\n", log);
exit(1);
}
glDeleteShader(vs);
glDeleteShader(fs);
return prog;
}
const char *vs_src =
"attribute vec2 pos;\n"
"uniform float angle;\n"
"void main() {\n"
" float c = cos(angle);\n"
" float s = sin(angle);\n"
" mat2 rot = mat2(c, -s, s, c);\n"
" gl_Position = vec4(rot * pos, 0.0, 1.0);\n"
"}\n";
const char *fs_src =
"precision mediump float;\n"
"void main() {\n"
" gl_FragColor = vec4(1.0, 0.3, 0.2, 1.0);\n"
"}\n";
void wm_base_handle_ping(void *data, struct xdg_wm_base *wm_base,
uint32_t serial) {
UNUSED(data);
printf("INFO: ping method fired! sending pong...\n");
xdg_wm_base_pong(wm_base, serial);
}
static struct xdg_wm_base_listener wm_base_listener = {
.ping = wm_base_handle_ping,
};
void registry_handle_global(void *data, struct wl_registry *registry,
uint32_t name, const char *interface,
uint32_t version) {
State *app_state = data;
printf("HANDLE_GLOBAL: new interface '%s', name = %d, version = %d\n",
interface, name, version);
if (strcmp(interface, "wl_compositor") == 0) {
app_state->compositor =
wl_registry_bind(registry, name, &wl_compositor_interface, version);
printf("%p compositor binding\n", app_state->compositor);
}
if (strcmp(interface, "xdg_wm_base") == 0) {
app_state->wm_base =
wl_registry_bind(registry, name, &xdg_wm_base_interface, version);
if (app_state->wm_base == NULL) {
fprintf(stderr, "ERROR: could not bind to xdg_wm_base\n");
}
int res = xdg_wm_base_add_listener(app_state->wm_base, &wm_base_listener,
app_state);
printf("bound to wm_base: %d\n", res);
}
if (strcmp(interface, "wl_shm") == 0) {
app_state->shm =
wl_registry_bind(registry, name, &wl_shm_interface, version);
if (app_state->shm == NULL) {
fprintf(stderr, "ERROR: could not bind to wl_shm\n");
}
}
}
void registry_handle_global_remove(void *data, struct wl_registry *registry,
uint32_t name) {
UNUSED(data);
UNUSED(registry);
UNUSED(name);
}
static struct wl_registry_listener listener = {
.global = registry_handle_global,
.global_remove = registry_handle_global_remove,
};
static struct wl_callback_listener frame_listener;
static void frame_done(void *data,
struct wl_callback *cb,
uint32_t time)
{
UNUSED(time);
printf("INFO: frame callback\n");
State *state = data;
printf("state ptr = %p\n", state->w_surface);
wl_callback_destroy(cb);
state->frame_callback =
wl_surface_frame(state->w_surface);
wl_callback_add_listener(state->frame_callback,
&frame_listener,
state);
GLint angle_loc = glGetUniformLocation(state->program, "angle");
static float angle = 0.0f;
angle += 0.02f;
glClear(GL_COLOR_BUFFER_BIT);
glUniform1f(angle_loc, angle);
glDrawArrays(GL_TRIANGLES, 0, 3);
eglSwapBuffers(state->egl_display, state->egl_surface);
}
static struct wl_callback_listener frame_listener = {
.done = frame_done,
};
static void xsurface_handle_configure(void *data,
struct xdg_surface *surface,
uint32_t serial) {
State *app_state = data;
xdg_surface_ack_configure(surface, serial);
app_state->frame_callback =
wl_surface_frame(app_state->w_surface);
printf("frame cb: %p\n", app_state->frame_callback);
int cb_res = wl_callback_add_listener(app_state->frame_callback,
&frame_listener,
app_state);
printf("mount callback listener: %d\n", cb_res);
glClear(GL_COLOR_BUFFER_BIT);
eglSwapBuffers(app_state->egl_display, app_state->egl_surface);
}
static const struct xdg_surface_listener xsurface_listener = {
.configure = xsurface_handle_configure,
};
int main(int argc, char **argv) {
UNUSED(argc);
UNUSED(argv);
State *app_state = (void*)malloc(sizeof(State));
app_state->display = wl_display_connect(NULL);
if (app_state->display == NULL) {
fprintf(stderr, "ERROR: could not connect to wl display\n");
return 1;
}
struct wl_registry *registry = wl_display_get_registry(app_state->display);
if (registry == NULL) {
fprintf(stderr, "ERROR: could not connect to wl registry\n");
return 1;
}
int handle = wl_registry_add_listener(registry, &listener, app_state);
printf("registry listener bound: %d\n", handle);
wl_display_roundtrip(app_state->display);
app_state->w_surface = wl_compositor_create_surface(app_state->compositor);
if (app_state->w_surface == NULL) {
fprintf(stderr, "ERROR: could not connect create a surface\n");
return 1;
}
PFNEGLGETPLATFORMDISPLAYEXTPROC getPlatformDisplay =
(PFNEGLGETPLATFORMDISPLAYEXTPROC)eglGetProcAddress(
"eglGetPlatformDisplayEXT");
PFNEGLCREATEPLATFORMWINDOWSURFACEEXTPROC createPlatformWindowSurface =
(void *)eglGetProcAddress("eglCreatePlatformWindowSurfaceEXT");
app_state->egl_display =
getPlatformDisplay(EGL_PLATFORM_WAYLAND_KHR, app_state->display, NULL);
if (app_state->egl_display == NULL) {
fprintf(stderr, "ERROR: could not get platform display\n");
fprintf(stderr, "EGL error: 0x%x\n", eglGetError());
exit(1);
}
if (!eglInitialize(app_state->egl_display, NULL, NULL)) {
fprintf(stderr, "ERROR: could not initialize EGL\n");
fprintf(stderr, "EGL error: 0x%x\n", eglGetError());
exit(1);
}
EGLint config_attribs[] = {
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_RED_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_BLUE_SIZE, 8,
EGL_ALPHA_SIZE, 8,
EGL_NONE
};
EGLConfig config;
EGLint num_configs;
if (!eglChooseConfig(app_state->egl_display, config_attribs,
&config, 1, &num_configs)) {
fprintf(stderr, "ERROR: could not choose EGL config\n");
fprintf(stderr, "EGL error: 0x%x\n", eglGetError());
exit(1);
}
EGLint ctx_attribs[] = {
EGL_CONTEXT_CLIENT_VERSION, 2,
EGL_NONE
};
EGLContext context =
eglCreateContext(app_state->egl_display,
config,
EGL_NO_CONTEXT,
ctx_attribs);
if (context == NULL) {
fprintf(stderr, "ERROR: could not create EGL context\n");
fprintf(stderr, "EGL error: 0x%x\n", eglGetError());
exit(1);
}
app_state->egl_window = wl_egl_window_create(app_state->w_surface, WIDTH, HEIGHT);
if (app_state->egl_window == NULL) {
fprintf(stderr, "ERROR: could not create wl_egl_window\n");
exit(1);
}
app_state->egl_surface = createPlatformWindowSurface(app_state->egl_display, config, app_state->egl_window, NULL);
if (app_state->egl_surface == NULL) {
fprintf(stderr, "ERROR: could not create EGL window surface\n");
fprintf(stderr, "EGL error: 0x%x\n", eglGetError());
exit(1);
}
if (!eglMakeCurrent(app_state->egl_display, app_state->egl_surface, app_state->egl_surface, context)) {
fprintf(stderr, "ERROR: could not change current EGL context\n");
fprintf(stderr, "EGL error: 0x%x\n", eglGetError());
exit(1);
}
app_state->program = create_program(vs_src, fs_src);
glUseProgram(app_state->program);
GLint pos_loc = glGetAttribLocation(app_state->program, "pos");
// GLint angle_loc = glGetUniformLocation(app_state->program, "angle");
float vertices[] = {
0.0f, 0.6f,
-0.6f, -0.6f,
0.6f, -0.6f
};
glEnableVertexAttribArray(pos_loc);
glVertexAttribPointer(pos_loc, 2, GL_FLOAT, GL_FALSE, 0, vertices);
glViewport(0, 0, WIDTH, HEIGHT);
glClearColor(0.2f, 0.4f, 0.8f, 1.0f);
app_state->x_surface =
xdg_wm_base_get_xdg_surface(app_state->wm_base, app_state->w_surface);
if (app_state->x_surface == NULL) {
fprintf(stderr, "ERROR: could not get an xdg surface\n");
return 1;
}
app_state->toplevel = xdg_surface_get_toplevel(app_state->x_surface);
if (app_state->toplevel == NULL) {
fprintf(stderr, "ERROR: could not get an xdg toplevel\n");
return 1;
}
xdg_surface_add_listener(app_state->x_surface, &xsurface_listener, app_state);
app_state->ready = true;
wl_surface_commit(app_state->w_surface);
while (wl_display_dispatch(app_state->display)) {}
return 0;
}

184
src/xdg-shell-protocol.c Normal file
View File

@@ -0,0 +1,184 @@
/* Generated by wayland-scanner 1.24.0 */
/*
* Copyright © 2008-2013 Kristian Høgsberg
* Copyright © 2013 Rafael Antognolli
* Copyright © 2013 Jasper St. Pierre
* Copyright © 2010-2013 Intel Corporation
* Copyright © 2015-2017 Samsung Electronics Co., Ltd
* Copyright © 2015-2017 Red Hat Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
#include <stdbool.h>
#include <stdlib.h>
#include <stdint.h>
#include "wayland-util.h"
#ifndef __has_attribute
# define __has_attribute(x) 0 /* Compatibility with non-clang compilers. */
#endif
#if (__has_attribute(visibility) || defined(__GNUC__) && __GNUC__ >= 4)
#define WL_PRIVATE __attribute__ ((visibility("hidden")))
#else
#define WL_PRIVATE
#endif
extern const struct wl_interface wl_output_interface;
extern const struct wl_interface wl_seat_interface;
extern const struct wl_interface wl_surface_interface;
extern const struct wl_interface xdg_popup_interface;
extern const struct wl_interface xdg_positioner_interface;
extern const struct wl_interface xdg_surface_interface;
extern const struct wl_interface xdg_toplevel_interface;
static const struct wl_interface *xdg_shell_types[] = {
NULL,
NULL,
NULL,
NULL,
&xdg_positioner_interface,
&xdg_surface_interface,
&wl_surface_interface,
&xdg_toplevel_interface,
&xdg_popup_interface,
&xdg_surface_interface,
&xdg_positioner_interface,
&xdg_toplevel_interface,
&wl_seat_interface,
NULL,
NULL,
NULL,
&wl_seat_interface,
NULL,
&wl_seat_interface,
NULL,
NULL,
&wl_output_interface,
&wl_seat_interface,
NULL,
&xdg_positioner_interface,
NULL,
};
static const struct wl_message xdg_wm_base_requests[] = {
{ "destroy", "", xdg_shell_types + 0 },
{ "create_positioner", "n", xdg_shell_types + 4 },
{ "get_xdg_surface", "no", xdg_shell_types + 5 },
{ "pong", "u", xdg_shell_types + 0 },
};
static const struct wl_message xdg_wm_base_events[] = {
{ "ping", "u", xdg_shell_types + 0 },
};
WL_PRIVATE const struct wl_interface xdg_wm_base_interface = {
"xdg_wm_base", 7,
4, xdg_wm_base_requests,
1, xdg_wm_base_events,
};
static const struct wl_message xdg_positioner_requests[] = {
{ "destroy", "", xdg_shell_types + 0 },
{ "set_size", "ii", xdg_shell_types + 0 },
{ "set_anchor_rect", "iiii", xdg_shell_types + 0 },
{ "set_anchor", "u", xdg_shell_types + 0 },
{ "set_gravity", "u", xdg_shell_types + 0 },
{ "set_constraint_adjustment", "u", xdg_shell_types + 0 },
{ "set_offset", "ii", xdg_shell_types + 0 },
{ "set_reactive", "3", xdg_shell_types + 0 },
{ "set_parent_size", "3ii", xdg_shell_types + 0 },
{ "set_parent_configure", "3u", xdg_shell_types + 0 },
};
WL_PRIVATE const struct wl_interface xdg_positioner_interface = {
"xdg_positioner", 7,
10, xdg_positioner_requests,
0, NULL,
};
static const struct wl_message xdg_surface_requests[] = {
{ "destroy", "", xdg_shell_types + 0 },
{ "get_toplevel", "n", xdg_shell_types + 7 },
{ "get_popup", "n?oo", xdg_shell_types + 8 },
{ "set_window_geometry", "iiii", xdg_shell_types + 0 },
{ "ack_configure", "u", xdg_shell_types + 0 },
};
static const struct wl_message xdg_surface_events[] = {
{ "configure", "u", xdg_shell_types + 0 },
};
WL_PRIVATE const struct wl_interface xdg_surface_interface = {
"xdg_surface", 7,
5, xdg_surface_requests,
1, xdg_surface_events,
};
static const struct wl_message xdg_toplevel_requests[] = {
{ "destroy", "", xdg_shell_types + 0 },
{ "set_parent", "?o", xdg_shell_types + 11 },
{ "set_title", "s", xdg_shell_types + 0 },
{ "set_app_id", "s", xdg_shell_types + 0 },
{ "show_window_menu", "ouii", xdg_shell_types + 12 },
{ "move", "ou", xdg_shell_types + 16 },
{ "resize", "ouu", xdg_shell_types + 18 },
{ "set_max_size", "ii", xdg_shell_types + 0 },
{ "set_min_size", "ii", xdg_shell_types + 0 },
{ "set_maximized", "", xdg_shell_types + 0 },
{ "unset_maximized", "", xdg_shell_types + 0 },
{ "set_fullscreen", "?o", xdg_shell_types + 21 },
{ "unset_fullscreen", "", xdg_shell_types + 0 },
{ "set_minimized", "", xdg_shell_types + 0 },
};
static const struct wl_message xdg_toplevel_events[] = {
{ "configure", "iia", xdg_shell_types + 0 },
{ "close", "", xdg_shell_types + 0 },
{ "configure_bounds", "4ii", xdg_shell_types + 0 },
{ "wm_capabilities", "5a", xdg_shell_types + 0 },
};
WL_PRIVATE const struct wl_interface xdg_toplevel_interface = {
"xdg_toplevel", 7,
14, xdg_toplevel_requests,
4, xdg_toplevel_events,
};
static const struct wl_message xdg_popup_requests[] = {
{ "destroy", "", xdg_shell_types + 0 },
{ "grab", "ou", xdg_shell_types + 22 },
{ "reposition", "3ou", xdg_shell_types + 24 },
};
static const struct wl_message xdg_popup_events[] = {
{ "configure", "iiii", xdg_shell_types + 0 },
{ "popup_done", "", xdg_shell_types + 0 },
{ "repositioned", "3u", xdg_shell_types + 0 },
};
WL_PRIVATE const struct wl_interface xdg_popup_interface = {
"xdg_popup", 7,
3, xdg_popup_requests,
3, xdg_popup_events,
};