project for a (works on my devices) demo
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
#include "wl_output_listener.h"
|
||||
|
||||
// Callback for wl_output::mode events (resolutions)
|
||||
void output_mode(void *data, struct wl_output *output,
|
||||
uint32_t flags, int32_t width, int32_t height,
|
||||
int32_t refresh) {
|
||||
const char *mode_type = "";
|
||||
if (flags & WL_OUTPUT_MODE_CURRENT) mode_type = " (current)";
|
||||
if (flags & WL_OUTPUT_MODE_PREFERRED) mode_type = " (preferred)";
|
||||
|
||||
printf("Mode: %dx%d @ %.2f Hz%s\n",
|
||||
width, height, refresh / 1000.0, mode_type);
|
||||
}
|
||||
|
||||
// Callback for wl_output::geometry events (physical display info)
|
||||
void output_geometry(void *data, struct wl_output *output,
|
||||
int32_t x, int32_t y, int32_t physical_width,
|
||||
int32_t physical_height, int32_t subpixel,
|
||||
const char *make, const char *model,
|
||||
int32_t transform) {
|
||||
printf("Output: %s %s (physical size: %dx%d mm)\n", make, model,
|
||||
physical_width, physical_height);
|
||||
}
|
||||
|
||||
// Callback for wl_output::done events (end of output info)
|
||||
void output_done(void *data, struct wl_output *output) {}
|
||||
|
||||
// Callback for wl_output::scale events (HiDPI scaling)
|
||||
void output_scale(void *data, struct wl_output *output, int32_t scale) {}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
#pragma once
|
||||
|
||||
#include <wayland-client.h>
|
||||
#include <stdio.h>
|
||||
|
||||
// Callback for wl_output::mode events (resolutions)
|
||||
void output_mode(
|
||||
void *data,
|
||||
struct wl_output *output,
|
||||
uint32_t flags,
|
||||
int32_t width,
|
||||
int32_t height,
|
||||
int32_t refresh
|
||||
);
|
||||
|
||||
// Callback for wl_output::geometry events (physical display info)
|
||||
void output_geometry(
|
||||
void *data,
|
||||
struct wl_output *output,
|
||||
int32_t x,
|
||||
int32_t y,
|
||||
int32_t physical_width,
|
||||
int32_t physical_height,
|
||||
int32_t subpixel,
|
||||
const char *make,
|
||||
const char *model,
|
||||
int32_t transform
|
||||
);
|
||||
|
||||
// Callback for wl_output::done events (end of output info)
|
||||
void output_done(
|
||||
void *data,
|
||||
struct wl_output *output
|
||||
);
|
||||
|
||||
// Callback for wl_output::scale events (HiDPI scaling)
|
||||
void output_scale(
|
||||
void *data,
|
||||
struct wl_output *output,
|
||||
int32_t scale
|
||||
);
|
||||
@@ -0,0 +1,14 @@
|
||||
#include "xdg_wm_base_listener.h"
|
||||
|
||||
/*
|
||||
listener on the XDG wm_base "ping" event
|
||||
the client must respond fairly soon to the event with a "pong" request or the client may be deemed unresponsive
|
||||
*/
|
||||
void wm_ping(
|
||||
void *data,
|
||||
struct xdg_wm_base *xdg_wm_base,
|
||||
uint32_t serial
|
||||
) {
|
||||
(void) data;
|
||||
xdg_wm_base_pong(xdg_wm_base, serial);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
#include "../xdg-shell.h"
|
||||
|
||||
void wm_ping(
|
||||
void *data,
|
||||
struct xdg_wm_base *xdg_wm_base,
|
||||
uint32_t serial
|
||||
);
|
||||
139
SOURCES/graphics/os/WAYLAND/wl_context.c
Normal file
139
SOURCES/graphics/os/WAYLAND/wl_context.c
Normal file
@@ -0,0 +1,139 @@
|
||||
#include "wl_context.h"
|
||||
|
||||
#include "registry_listeners/wl_output_listener.h"
|
||||
#include "registry_listeners/xdg_wm_base_listener.h"
|
||||
|
||||
#include <wayland-client.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
static const struct wl_output_listener output_listener = {
|
||||
.geometry = output_geometry,
|
||||
.mode = output_mode,
|
||||
.done = output_done,
|
||||
.scale = output_scale,
|
||||
};
|
||||
|
||||
static const struct xdg_wm_base_listener wm_base_listener = {
|
||||
wm_ping
|
||||
};
|
||||
|
||||
/***************************************/
|
||||
/***************************************/
|
||||
/**********REGISTRY CALLBACKS***********/
|
||||
/***************************************/
|
||||
/***************************************/
|
||||
|
||||
/*
|
||||
listener on the registry object's add events
|
||||
used for picking the singletons to COMPOSITOR, SUBCOMPOSITOR and XDG_WM_BASE
|
||||
*/
|
||||
void global_registry(
|
||||
void *data,
|
||||
struct wl_registry *wl_registry,
|
||||
uint32_t name,
|
||||
const char *interface,
|
||||
uint32_t version
|
||||
) {
|
||||
surface_builders *builders = data;
|
||||
|
||||
printf("REGISTRY EVENT\nname: %s\nversion: %d\n", interface, version);
|
||||
|
||||
/*
|
||||
printf("%s\n%s\n%s\n\n", wl_compositor_interface.name, wl_subcompositor_interface.name, xdg_wm_base_interface.name);
|
||||
*/
|
||||
|
||||
if(!strcmp(interface, wl_compositor_interface.name)) {
|
||||
printf("FOUND COMP\n");
|
||||
builders->compositor = wl_registry_bind(
|
||||
wl_registry,
|
||||
name,
|
||||
&wl_compositor_interface,
|
||||
version
|
||||
);
|
||||
}
|
||||
else if(!strcmp(interface, wl_subcompositor_interface.name)){
|
||||
printf("FOUND SUBCOMP\n");
|
||||
builders->subcompositor = wl_registry_bind(
|
||||
wl_registry,
|
||||
name,
|
||||
&wl_subcompositor_interface,
|
||||
version
|
||||
);
|
||||
}
|
||||
else if(!strcmp(interface, xdg_wm_base_interface.name)) {
|
||||
printf("FOUND XDG\n");
|
||||
builders->xdg_wm_base = wl_registry_bind(
|
||||
wl_registry,
|
||||
name,
|
||||
&xdg_wm_base_interface,
|
||||
version
|
||||
);
|
||||
}
|
||||
|
||||
if (strcmp(interface, "wl_output") == 0) {
|
||||
printf("FOUND OUTPUT\n");
|
||||
builders->output = wl_registry_bind(
|
||||
wl_registry,
|
||||
name,
|
||||
&wl_output_interface,
|
||||
1
|
||||
);
|
||||
wl_output_add_listener( builders->output, &output_listener, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
listener on the registry object's remove events
|
||||
it is an error the body being unimplemented ( when an interface becomes unavailable it could mean that the physical device has been disconnected )
|
||||
*/
|
||||
void global_remove(void *data, struct wl_registry *wl_registry,
|
||||
uint32_t name) {
|
||||
(void) data;
|
||||
(void) wl_registry;
|
||||
(void) name;
|
||||
}
|
||||
|
||||
static const struct wl_registry_listener registry_listener = {
|
||||
global_registry,
|
||||
global_remove
|
||||
};
|
||||
|
||||
wl_context* wl_context_new() {
|
||||
wl_context *w = malloc( sizeof( wl_context));
|
||||
w->display = wl_display_connect(NULL);
|
||||
if(! w->display) {
|
||||
fprintf(stderr, "Couldn't connect to wayland display\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
w->builders = malloc( sizeof( surface_builders));
|
||||
w->registry = wl_display_get_registry( w->display);
|
||||
wl_registry_add_listener( w->registry, ®istry_listener, w->builders);
|
||||
wl_display_roundtrip( w->display);
|
||||
if( ! w->builders->compositor || ! w->builders->subcompositor || ! w->builders->xdg_wm_base) {
|
||||
fprintf(stderr, "Couldn't find compositor or xdg shell\n");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
xdg_wm_base_add_listener(w->builders->xdg_wm_base, &wm_base_listener, NULL);
|
||||
|
||||
return w;
|
||||
}
|
||||
|
||||
|
||||
/* ALLOWS FOR QUERYING OF SOME ENVIRONMENT VARIABLE */
|
||||
int wl_context_get(int query){
|
||||
switch( query) {
|
||||
case GLUT_SCREEN_WIDTH :
|
||||
return 192;
|
||||
break;
|
||||
case GLUT_SCREEN_HEIGHT :
|
||||
return 108; /* 1156 */
|
||||
break;
|
||||
default:
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
55
SOURCES/graphics/os/WAYLAND/wl_context.h
Normal file
55
SOURCES/graphics/os/WAYLAND/wl_context.h
Normal file
@@ -0,0 +1,55 @@
|
||||
#pragma once
|
||||
|
||||
#include <wayland-client.h>
|
||||
#include "../WAYLAND/xdg-shell.h"
|
||||
|
||||
typedef struct {
|
||||
struct wl_compositor *compositor;
|
||||
struct wl_subcompositor *subcompositor;
|
||||
struct xdg_wm_base *xdg_wm_base;
|
||||
struct wl_output *output;
|
||||
} surface_builders;
|
||||
|
||||
typedef struct {
|
||||
struct wl_display *display;
|
||||
struct wl_registry *registry;
|
||||
surface_builders *builders;
|
||||
} wl_context;
|
||||
|
||||
#define GLUT_SCREEN_WIDTH 0
|
||||
#define GLUT_SCREEN_HEIGHT 1
|
||||
|
||||
void global_registry(
|
||||
void *data,
|
||||
struct wl_registry *wl_registry,
|
||||
uint32_t name,
|
||||
const char *interface,
|
||||
uint32_t version
|
||||
);
|
||||
|
||||
void global_remove(
|
||||
void *data,
|
||||
struct wl_registry *wl_registry,
|
||||
uint32_t name
|
||||
);
|
||||
|
||||
|
||||
/*
|
||||
the only event dispatched by the WM is the "ping" one
|
||||
emitted periodically to check if clients are still alive
|
||||
|
||||
calls
|
||||
xdg_wm_base_pong
|
||||
to inform the server that the client is alive and responsive
|
||||
*/
|
||||
void wm_ping(
|
||||
void *data,
|
||||
struct xdg_wm_base *xdg_wm_base,
|
||||
uint32_t serial);
|
||||
|
||||
|
||||
|
||||
/* connects to the default display and initializes basic wayland resources */
|
||||
wl_context* wl_context_new();
|
||||
|
||||
int wl_context_get( int query);
|
||||
183
SOURCES/graphics/os/WAYLAND/xdg-shell.c
Normal file
183
SOURCES/graphics/os/WAYLAND/xdg-shell.c
Normal file
@@ -0,0 +1,183 @@
|
||||
/* Generated by wayland-scanner 1.22.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 <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", 5,
|
||||
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", 5,
|
||||
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", 5,
|
||||
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", 5,
|
||||
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", 5,
|
||||
3, xdg_popup_requests,
|
||||
3, xdg_popup_events,
|
||||
};
|
||||
|
||||
2280
SOURCES/graphics/os/WAYLAND/xdg-shell.h
Normal file
2280
SOURCES/graphics/os/WAYLAND/xdg-shell.h
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user