Init
This commit is contained in:
86
server.c
Normal file
86
server.c
Normal file
@@ -0,0 +1,86 @@
|
||||
#include <stdio.h>
|
||||
#include <wayland/wayland-server.h>
|
||||
#include <wayland/wayland-util.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
typedef struct my_state_t {
|
||||
int x;
|
||||
struct wl_list client_outputs;
|
||||
} my_state;
|
||||
|
||||
typedef struct my_output_t {
|
||||
my_state *state;
|
||||
struct wl_resource *resource;
|
||||
} my_output;
|
||||
|
||||
static void
|
||||
wl_output_handle_resource_destroy(struct wl_resource *resource)
|
||||
{
|
||||
my_output *client_output = wl_resource_get_user_data(resource);
|
||||
|
||||
// TODO: Clean up resource
|
||||
|
||||
// remove_to_list(client_output->state->client_outputs, client_output);
|
||||
}
|
||||
|
||||
static void
|
||||
wl_output_handle_release(struct wl_client *client, struct wl_resource *resource)
|
||||
{
|
||||
wl_resource_destroy(resource);
|
||||
}
|
||||
|
||||
static const struct wl_output_interface
|
||||
wl_output_implementation = {
|
||||
.release = wl_output_handle_release,
|
||||
};
|
||||
|
||||
static void wl_output_handle_bind(struct wl_client *client, void *data, uint32_t version, uint32_t id)
|
||||
{
|
||||
my_state *state = data;
|
||||
printf("wl_output_handle_bind: State Variable: %d", state->x);
|
||||
|
||||
my_output *client_output = malloc(sizeof *client_output);
|
||||
|
||||
struct wl_resource *resource = wl_resource_create(
|
||||
client, &wl_output_implementation, wl_output_interface.version, id);
|
||||
|
||||
wl_resource_set_implementation(resource, &wl_output_implementation,
|
||||
client_output, wl_output_handle_resource_destroy);
|
||||
|
||||
client_output->resource = resource;
|
||||
client_output->state = state;
|
||||
|
||||
// Send geometry event, et al
|
||||
wl_output_send_geometry(resource, 0, 0, 1920, 1080,
|
||||
WL_OUTPUT_SUBPIXEL_UNKNOWN, "Foobar, Inc",
|
||||
"Fancy Monitor 9001 4K HD 120 FPS Noscope",
|
||||
WL_OUTPUT_TRANSFORM_NORMAL);
|
||||
|
||||
// add_to_list(state->client_outputs, client_output);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
struct wl_display *display = wl_display_create();
|
||||
if (!display) {
|
||||
fprintf(stderr, "Unable to create Wayland display.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
const char *socket = wl_display_add_socket_auto(display);
|
||||
if (!socket) {
|
||||
fprintf(stderr, "Unable to add socket to Wayland display.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
fprintf(stderr, "Running Wayland display on %s\n", socket);
|
||||
|
||||
my_state state = { 0 };
|
||||
|
||||
wl_global_create(display, &wl_output_interface, 1, &state, wl_output_handle_bind);
|
||||
|
||||
wl_display_run(display);
|
||||
|
||||
wl_display_destroy(display);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user