145 lines
4.5 KiB
C
145 lines
4.5 KiB
C
#include <wayland-client-protocol.h>
|
|
#include <gdk/wayland/gdkwayland.h>
|
|
#include <assert.h>
|
|
#include "wayland.h"
|
|
#include "foreign.h"
|
|
#include "session.h"
|
|
|
|
|
|
struct _DiyaWayland
|
|
{
|
|
DiyaObject parent;
|
|
struct wl_compositor * compositor;
|
|
struct wl_shm * shm;
|
|
};
|
|
G_DEFINE_FINAL_TYPE(DiyaWayland, diya_wayland, DIYA_TYPE_SHELL_OBJECT)
|
|
|
|
static void diya_wayland_dispose(GObject* object)
|
|
{
|
|
(void) object;
|
|
//DiyaWayland * self = DIYA_WAYLAND(object);
|
|
g_debug("diya_wayland_dispose");
|
|
G_OBJECT_CLASS(diya_wayland_parent_class)->dispose(object);
|
|
}
|
|
|
|
static void diya_wayland_init(DiyaWayland * self)
|
|
{
|
|
self->compositor = NULL;
|
|
self->shm = NULL;
|
|
}
|
|
|
|
static void diya_wayland_class_init(DiyaWaylandClass *class)
|
|
{
|
|
GObjectClass *gobject_class = G_OBJECT_CLASS(class);
|
|
//DiyaObjectClass *base_class = DIYA_OBJECT_CLASS(class);
|
|
|
|
gobject_class->dispose = diya_wayland_dispose;
|
|
//gobject_class->set_property = diya_lock_session_set_property;
|
|
//gobject_class->get_property = diya_lock_session_get_property;
|
|
//base_class->to_string = diya_lock_session_to_string;
|
|
}
|
|
|
|
|
|
static void handle_global(void *data, struct wl_registry *registry, uint32_t name, const gchar *interface, uint32_t version)
|
|
{
|
|
/*if (!g_strcmp0(interface, zxdg_output_manager_v1_interface.name))
|
|
xdg_output_register(registry, name);
|
|
else if (!g_strcmp0(interface, wl_shm_interface.name))
|
|
shm_register(registry, name);
|
|
else if (!g_strcmp0(interface, zwlr_layer_shell_v1_interface.name))
|
|
layer_shell_register(registry, name, version);
|
|
if (!g_strcmp0(interface,zwlr_foreign_toplevel_manager_v1_interface.name))
|
|
foreign_toplevel_register(registry,name);
|
|
*/
|
|
(void) version;
|
|
DiyaShell * shell = data;
|
|
DiyaWayland * wayland;
|
|
g_object_get(shell, "wayland", &wayland, NULL);
|
|
assert(DIYA_IS_WAYLAND(wayland));
|
|
g_debug("WAYLAND GLOBAL: %s", interface);
|
|
if (!g_strcmp0(interface, zwlr_foreign_toplevel_manager_v1_interface.name))
|
|
{
|
|
diya_shell_foreign_toplevel_register(registry, name, data);
|
|
}
|
|
else if(!g_strcmp0(interface, ext_session_lock_manager_v1_interface.name))
|
|
{
|
|
diya_shell_session_lock_register(registry, name);
|
|
}
|
|
else if (strcmp(interface, wl_compositor_interface.name) == 0)
|
|
{
|
|
wayland->compositor = wl_registry_bind(registry, name, &wl_compositor_interface, 4);
|
|
}
|
|
else if (strcmp(interface, wl_shm_interface.name) == 0)
|
|
{
|
|
wayland->shm = wl_registry_bind(registry, name, &wl_shm_interface, 1);
|
|
}
|
|
}
|
|
|
|
static void handle_global_remove(void *data, struct wl_registry *registry,
|
|
uint32_t name)
|
|
{
|
|
(void) data;
|
|
(void) registry;
|
|
(void) name;
|
|
}
|
|
|
|
static const struct wl_registry_listener registry_listener =
|
|
{
|
|
.global = handle_global,
|
|
.global_remove = handle_global_remove
|
|
};
|
|
|
|
void diya_shell_wayland_init(DiyaShell *shell)
|
|
{
|
|
struct wl_display *display;
|
|
struct wl_registry *registry;
|
|
display = gdk_wayland_display_get_wl_display(gdk_display_get_default());
|
|
if (!display)
|
|
{
|
|
g_error("Can't get wayland display");
|
|
return;
|
|
}
|
|
DiyaWayland * wayland = g_object_new(DIYA_TYPE_WAYLAND, "shell", shell, NULL);
|
|
g_object_set(shell, "wayland", wayland, NULL);
|
|
//g_object_set(wayland, "shell", shell, NULL);
|
|
registry = wl_display_get_registry(display);
|
|
wl_registry_add_listener(registry, ®istry_listener, (void*)shell);
|
|
wl_display_roundtrip(display);
|
|
// wayland_monitor_probe();
|
|
// GdkMonitor *mon = wayland_monitor_get_default();
|
|
// g_info("default output: %s", (gchar *)g_object_get_data(G_OBJECT(mon), "xdg_name"));
|
|
|
|
// wl_display_roundtrip(display);
|
|
// wl_display_roundtrip(display);
|
|
}
|
|
|
|
struct wl_surface* diya_wayland_create_surface(DiyaWayland * self)
|
|
{
|
|
assert(self->compositor);
|
|
struct wl_surface* surface = wl_compositor_create_surface(self->compositor);
|
|
assert(surface);
|
|
return surface;
|
|
}
|
|
|
|
struct wl_output* diya_wayland_get_output(DiyaWayland * self, int index)
|
|
{
|
|
(void) self;
|
|
/**
|
|
* TODO: listen to wl_ouput interface instead of using gdk
|
|
*/
|
|
GListModel * list = gdk_display_get_monitors(gdk_display_get_default());
|
|
GdkMonitor * monitor = g_list_model_get_item(list,index);
|
|
if(! monitor)
|
|
{
|
|
return NULL;
|
|
}
|
|
struct wl_output * output = gdk_wayland_monitor_get_wl_output(monitor);
|
|
assert(output);
|
|
return output;
|
|
}
|
|
struct wl_shm_pool * diya_wayland_create_shm_pool(DiyaWayland * self, int fd, guint size)
|
|
{
|
|
assert(self->shm);
|
|
return wl_shm_create_pool(self->shm, fd, size);
|
|
}
|