140 lines
3.4 KiB
C
140 lines
3.4 KiB
C
#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);
|
|
}
|
|
}
|