[digesting_libdecor] eliminate the init_wl* helper functions for setting up global object bindings
parent
10b6246ba4
commit
71be40cf51
|
|
@ -76,6 +76,10 @@ struct libdecor_plugin_interface gtk_plugin_iface;
|
||||||
struct libdecor_plugin_interface fallback_plugin_iface;
|
struct libdecor_plugin_interface fallback_plugin_iface;
|
||||||
|
|
||||||
const struct wl_shm_listener shm_listener;
|
const struct wl_shm_listener shm_listener;
|
||||||
|
const struct wl_seat_listener seat_listener;
|
||||||
|
const struct wl_pointer_listener pointer_listener;
|
||||||
|
const struct wl_touch_listener touch_listener;
|
||||||
|
const struct wl_output_listener output_listener;
|
||||||
|
|
||||||
// X(N:name,R:return,P:params)
|
// X(N:name,R:return,P:params)
|
||||||
#define GL_FUNCS_XLIST(X)\
|
#define GL_FUNCS_XLIST(X)\
|
||||||
|
|
@ -100,18 +104,15 @@ wlevent__wl_registry_global(void *data, struct wl_registry *wl_registry,
|
||||||
MIN(version, 4));
|
MIN(version, 4));
|
||||||
}
|
}
|
||||||
else if (!strcmp(interface, xdg_wm_base_interface.name)){
|
else if (!strcmp(interface, xdg_wm_base_interface.name)){
|
||||||
init_xdg_wm_base(name, version);
|
ctx.xdg_wm_base = wl_registry_bind(ctx.wl_registry, name, &xdg_wm_base_interface, MIN(version, 2));
|
||||||
|
xdg_wm_base_add_listener(ctx.xdg_wm_base, &xdg_wm_base_listener, 0);
|
||||||
}
|
}
|
||||||
else if (!strcmp(interface, zxdg_decoration_manager_v1_interface.name)){
|
else if (!strcmp(interface, zxdg_decoration_manager_v1_interface.name)){
|
||||||
const char *force_csd = getenv("LIBDECOR_FORCE_CSD");
|
ctx.decoration_manager = wl_registry_bind(wl_registry, name, &zxdg_decoration_manager_v1_interface, MIN(version,2));
|
||||||
if (!(force_csd && atoi(force_csd))){
|
|
||||||
ctx.decoration_manager = wl_registry_bind(wl_registry, name,
|
|
||||||
&zxdg_decoration_manager_v1_interface,
|
|
||||||
MIN(version,2));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (strcmp(interface, "wl_subcompositor") == 0){
|
else if (strcmp(interface, "wl_subcompositor") == 0){
|
||||||
init_wl_subcompositor(name, version);
|
ctx.plugin_gtk->wl_subcompositor =
|
||||||
|
wl_registry_bind(ctx.wl_registry, name, &wl_subcompositor_interface, 1);
|
||||||
}
|
}
|
||||||
else if (strcmp(interface, "wl_shm") == 0){
|
else if (strcmp(interface, "wl_shm") == 0){
|
||||||
ctx.plugin_gtk->wl_shm =
|
ctx.plugin_gtk->wl_shm =
|
||||||
|
|
@ -119,10 +120,35 @@ wlevent__wl_registry_global(void *data, struct wl_registry *wl_registry,
|
||||||
wl_shm_add_listener(ctx.plugin_gtk->wl_shm, &shm_listener, ctx.plugin_gtk);
|
wl_shm_add_listener(ctx.plugin_gtk->wl_shm, &shm_listener, ctx.plugin_gtk);
|
||||||
}
|
}
|
||||||
else if (strcmp(interface, "wl_seat") == 0){
|
else if (strcmp(interface, "wl_seat") == 0){
|
||||||
init_wl_seat(name, version);
|
struct seat *seat;
|
||||||
|
if (version < 3){
|
||||||
|
libdecor_notify_plugin_error(LIBDECOR_ERROR_COMPOSITOR_INCOMPATIBLE,
|
||||||
|
"%s version 3 required but only version %i is available\n", interface, version);
|
||||||
|
}
|
||||||
|
|
||||||
|
seat = calloc(1, sizeof *seat);
|
||||||
|
seat->cursor_scale = 1;
|
||||||
|
seat->plugin_gtk = ctx.plugin_gtk;
|
||||||
|
wl_list_init(&seat->cursor_outputs);
|
||||||
|
wl_list_insert(&ctx.plugin_gtk->seat_list, &seat->link);
|
||||||
|
seat->wl_seat = wl_registry_bind(ctx.wl_registry, name, &wl_seat_interface, 3);
|
||||||
|
wl_seat_add_listener(seat->wl_seat, &seat_listener, seat);
|
||||||
}
|
}
|
||||||
else if (strcmp(interface, "wl_output") == 0){
|
else if (strcmp(interface, "wl_output") == 0){
|
||||||
init_wl_output(name, version);
|
struct output *output;
|
||||||
|
if (version < 2){
|
||||||
|
libdecor_notify_plugin_error(LIBDECOR_ERROR_COMPOSITOR_INCOMPATIBLE,
|
||||||
|
"%s version 2 required but only version %i is available\n", interface, version);
|
||||||
|
}
|
||||||
|
|
||||||
|
output = calloc(1, sizeof *output);
|
||||||
|
output->plugin_gtk = ctx.plugin_gtk;
|
||||||
|
wl_list_insert(&ctx.plugin_gtk->output_list, &output->link);
|
||||||
|
output->id = name;
|
||||||
|
output->wl_output = wl_registry_bind(ctx.wl_registry, name, &wl_output_interface, MIN(version, 3));
|
||||||
|
wl_proxy_set_tag((struct wl_proxy *)output->wl_output,
|
||||||
|
&libdecor_gtk_proxy_tag);
|
||||||
|
wl_output_add_listener(output->wl_output, &output_listener, output);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -188,7 +214,6 @@ libdecorevent__frame_bounds(struct libdecor_frame *frame,
|
||||||
static void
|
static void
|
||||||
shm_format(void *user_data, struct wl_shm *wl_shm, uint32_t format){
|
shm_format(void *user_data, struct wl_shm *wl_shm, uint32_t format){
|
||||||
struct libdecor_plugin_gtk *plugin_gtk = user_data;
|
struct libdecor_plugin_gtk *plugin_gtk = user_data;
|
||||||
|
|
||||||
if (format == WL_SHM_FORMAT_ARGB8888){
|
if (format == WL_SHM_FORMAT_ARGB8888){
|
||||||
plugin_gtk->has_argb = true;
|
plugin_gtk->has_argb = true;
|
||||||
}
|
}
|
||||||
|
|
@ -223,6 +248,46 @@ const struct wl_callback_listener init_wl_display_callback_listener = {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
seat_capabilities(void *data, struct wl_seat *wl_seat, uint32_t capabilities){
|
||||||
|
struct seat *seat = data;
|
||||||
|
|
||||||
|
if ((capabilities & WL_SEAT_CAPABILITY_POINTER) &&
|
||||||
|
!seat->wl_pointer) {
|
||||||
|
seat->wl_pointer = wl_seat_get_pointer(wl_seat);
|
||||||
|
wl_pointer_add_listener(seat->wl_pointer,
|
||||||
|
&pointer_listener, seat);
|
||||||
|
} else if (!(capabilities & WL_SEAT_CAPABILITY_POINTER) &&
|
||||||
|
seat->wl_pointer) {
|
||||||
|
wl_pointer_release(seat->wl_pointer);
|
||||||
|
seat->wl_pointer = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((capabilities & WL_SEAT_CAPABILITY_TOUCH) &&
|
||||||
|
!seat->wl_touch) {
|
||||||
|
seat->wl_touch = wl_seat_get_touch(wl_seat);
|
||||||
|
wl_touch_add_listener(seat->wl_touch,
|
||||||
|
&touch_listener, seat);
|
||||||
|
} else if (!(capabilities & WL_SEAT_CAPABILITY_TOUCH) &&
|
||||||
|
seat->wl_touch) {
|
||||||
|
wl_touch_release(seat->wl_touch);
|
||||||
|
seat->wl_touch = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
seat_name(void *data, struct wl_seat *wl_seat, const char *name)
|
||||||
|
{
|
||||||
|
/* avoid warning messages when opening/closing popup window */
|
||||||
|
struct seat *seat = (struct seat*)data;
|
||||||
|
seat->name = strdup(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
const struct wl_seat_listener seat_listener = {
|
||||||
|
seat_capabilities,
|
||||||
|
seat_name
|
||||||
|
};
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
/* get desktop settings */
|
/* get desktop settings */
|
||||||
ctx.color_scheme = libdecor_get_color_scheme();
|
ctx.color_scheme = libdecor_get_color_scheme();
|
||||||
|
|
@ -1788,34 +1853,6 @@ const struct xdg_wm_base_listener xdg_wm_base_listener = {
|
||||||
xdg_wm_base_ping,
|
xdg_wm_base_ping,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
|
||||||
init_xdg_wm_base(uint32_t id, uint32_t version)
|
|
||||||
{
|
|
||||||
uint32_t desired_version = 2;
|
|
||||||
|
|
||||||
/* Find the required version for the available features. */
|
|
||||||
#ifdef XDG_TOPLEVEL_STATE_CONSTRAINED_LEFT_SINCE_VERSION
|
|
||||||
desired_version = MAX(desired_version, XDG_TOPLEVEL_STATE_CONSTRAINED_LEFT_SINCE_VERSION);
|
|
||||||
#endif
|
|
||||||
#ifdef XDG_TOPLEVEL_STATE_SUSPENDED_SINCE_VERSION
|
|
||||||
desired_version = MAX(desired_version, XDG_TOPLEVEL_STATE_SUSPENDED_SINCE_VERSION);
|
|
||||||
#endif
|
|
||||||
#ifdef XDG_TOPLEVEL_WM_CAPABILITIES_SINCE_VERSION
|
|
||||||
desired_version = MAX(desired_version, XDG_TOPLEVEL_WM_CAPABILITIES_SINCE_VERSION);
|
|
||||||
#endif
|
|
||||||
#ifdef XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION
|
|
||||||
desired_version = MAX(desired_version, XDG_TOPLEVEL_CONFIGURE_BOUNDS_SINCE_VERSION);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
ctx.xdg_wm_base = wl_registry_bind(ctx.wl_registry,
|
|
||||||
id,
|
|
||||||
&xdg_wm_base_interface,
|
|
||||||
MIN(version, desired_version));
|
|
||||||
xdg_wm_base_add_listener(ctx.xdg_wm_base,
|
|
||||||
&xdg_wm_base_listener,
|
|
||||||
0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
notify_error(enum libdecor_error error, const char *message)
|
notify_error(enum libdecor_error error, const char *message)
|
||||||
{
|
{
|
||||||
|
|
@ -2510,8 +2547,6 @@ streq(const char *str1,
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *libdecor_gtk_proxy_tag = "libdecor-gtk";
|
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
own_proxy(struct wl_proxy *proxy)
|
own_proxy(struct wl_proxy *proxy)
|
||||||
{
|
{
|
||||||
|
|
@ -3973,12 +4008,6 @@ struct libdecor_plugin_interface gtk_plugin_iface = {
|
||||||
.frame_get_border_size = libdecor_plugin_gtk_frame_get_border_size,
|
.frame_get_border_size = libdecor_plugin_gtk_frame_get_border_size,
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
|
||||||
init_wl_subcompositor(uint32_t id, uint32_t version){
|
|
||||||
ctx.plugin_gtk->wl_subcompositor =
|
|
||||||
wl_registry_bind(ctx.wl_registry, id, &wl_subcompositor_interface, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
cursor_surface_enter(void *data,
|
cursor_surface_enter(void *data,
|
||||||
struct wl_surface *wl_surface,
|
struct wl_surface *wl_surface,
|
||||||
|
|
@ -4524,7 +4553,7 @@ pointer_axis(void *data,
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct wl_pointer_listener pointer_listener = {
|
const struct wl_pointer_listener pointer_listener = {
|
||||||
pointer_enter,
|
pointer_enter,
|
||||||
pointer_leave,
|
pointer_leave,
|
||||||
pointer_motion,
|
pointer_motion,
|
||||||
|
|
@ -4729,7 +4758,7 @@ touch_cancel(void *data,
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct wl_touch_listener touch_listener = {
|
const struct wl_touch_listener touch_listener = {
|
||||||
touch_down,
|
touch_down,
|
||||||
touch_up,
|
touch_up,
|
||||||
touch_motion,
|
touch_motion,
|
||||||
|
|
@ -4737,71 +4766,6 @@ static struct wl_touch_listener touch_listener = {
|
||||||
touch_cancel
|
touch_cancel
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
|
||||||
seat_capabilities(void *data,
|
|
||||||
struct wl_seat *wl_seat,
|
|
||||||
uint32_t capabilities)
|
|
||||||
{
|
|
||||||
struct seat *seat = data;
|
|
||||||
|
|
||||||
if ((capabilities & WL_SEAT_CAPABILITY_POINTER) &&
|
|
||||||
!seat->wl_pointer) {
|
|
||||||
seat->wl_pointer = wl_seat_get_pointer(wl_seat);
|
|
||||||
wl_pointer_add_listener(seat->wl_pointer,
|
|
||||||
&pointer_listener, seat);
|
|
||||||
} else if (!(capabilities & WL_SEAT_CAPABILITY_POINTER) &&
|
|
||||||
seat->wl_pointer) {
|
|
||||||
wl_pointer_release(seat->wl_pointer);
|
|
||||||
seat->wl_pointer = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((capabilities & WL_SEAT_CAPABILITY_TOUCH) &&
|
|
||||||
!seat->wl_touch) {
|
|
||||||
seat->wl_touch = wl_seat_get_touch(wl_seat);
|
|
||||||
wl_touch_add_listener(seat->wl_touch,
|
|
||||||
&touch_listener, seat);
|
|
||||||
} else if (!(capabilities & WL_SEAT_CAPABILITY_TOUCH) &&
|
|
||||||
seat->wl_touch) {
|
|
||||||
wl_touch_release(seat->wl_touch);
|
|
||||||
seat->wl_touch = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
seat_name(void *data,
|
|
||||||
struct wl_seat *wl_seat,
|
|
||||||
const char *name)
|
|
||||||
{
|
|
||||||
/* avoid warning messages when opening/closing popup window */
|
|
||||||
struct seat *seat = (struct seat*)data;
|
|
||||||
seat->name = strdup(name);
|
|
||||||
}
|
|
||||||
|
|
||||||
static struct wl_seat_listener seat_listener = {
|
|
||||||
seat_capabilities,
|
|
||||||
seat_name
|
|
||||||
};
|
|
||||||
|
|
||||||
static void
|
|
||||||
init_wl_seat(uint32_t id, uint32_t version){
|
|
||||||
struct seat *seat;
|
|
||||||
|
|
||||||
if (version < 3) {
|
|
||||||
libdecor_notify_plugin_error(LIBDECOR_ERROR_COMPOSITOR_INCOMPATIBLE,
|
|
||||||
"%s version 3 required but only version %i is available\n",
|
|
||||||
wl_seat_interface.name,
|
|
||||||
version);
|
|
||||||
}
|
|
||||||
|
|
||||||
seat = calloc(1, sizeof *seat);
|
|
||||||
seat->cursor_scale = 1;
|
|
||||||
seat->plugin_gtk = ctx.plugin_gtk;
|
|
||||||
wl_list_init(&seat->cursor_outputs);
|
|
||||||
wl_list_insert(&ctx.plugin_gtk->seat_list, &seat->link);
|
|
||||||
seat->wl_seat = wl_registry_bind(ctx.wl_registry, id, &wl_seat_interface, 3);
|
|
||||||
wl_seat_add_listener(seat->wl_seat, &seat_listener, seat);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
output_geometry(void *data,
|
output_geometry(void *data,
|
||||||
struct wl_output *wl_output,
|
struct wl_output *wl_output,
|
||||||
|
|
@ -4857,37 +4821,13 @@ output_scale(void *data,
|
||||||
output->scale = factor;
|
output->scale = factor;
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct wl_output_listener output_listener = {
|
const struct wl_output_listener output_listener = {
|
||||||
output_geometry,
|
output_geometry,
|
||||||
output_mode,
|
output_mode,
|
||||||
output_done,
|
output_done,
|
||||||
output_scale
|
output_scale
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
|
||||||
init_wl_output(uint32_t id, uint32_t version){
|
|
||||||
struct output *output;
|
|
||||||
|
|
||||||
if (version < 2) {
|
|
||||||
libdecor_notify_plugin_error(LIBDECOR_ERROR_COMPOSITOR_INCOMPATIBLE,
|
|
||||||
"%s version 2 required but only version %i is available\n",
|
|
||||||
wl_output_interface.name,
|
|
||||||
version);
|
|
||||||
}
|
|
||||||
|
|
||||||
output = calloc(1, sizeof *output);
|
|
||||||
output->plugin_gtk = ctx.plugin_gtk;
|
|
||||||
wl_list_insert(&ctx.plugin_gtk->output_list, &output->link);
|
|
||||||
output->id = id;
|
|
||||||
output->wl_output =
|
|
||||||
wl_registry_bind(ctx.wl_registry,
|
|
||||||
id, &wl_output_interface,
|
|
||||||
MIN (version, 3));
|
|
||||||
wl_proxy_set_tag((struct wl_proxy *) output->wl_output,
|
|
||||||
&libdecor_gtk_proxy_tag);
|
|
||||||
wl_output_add_listener(output->wl_output, &output_listener, output);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
remove_surface_outputs(struct border_component *cmpnt, const struct output *output)
|
remove_surface_outputs(struct border_component *cmpnt, const struct output *output)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -593,7 +593,6 @@ int libdecor_os_create_anonymous_file(off_t size);
|
||||||
|
|
||||||
// #include "libdecor.c"
|
// #include "libdecor.c"
|
||||||
|
|
||||||
static void init_xdg_wm_base(uint32_t id, uint32_t version);
|
|
||||||
static void notify_error(enum libdecor_error error, const char *message);
|
static void notify_error(enum libdecor_error error, const char *message);
|
||||||
static void finish_init(void);
|
static void finish_init(void);
|
||||||
|
|
||||||
|
|
@ -601,13 +600,12 @@ static void finish_init(void);
|
||||||
|
|
||||||
static void libdecor_plugin_gtk_destroy(struct libdecor_plugin *plugin);
|
static void libdecor_plugin_gtk_destroy(struct libdecor_plugin *plugin);
|
||||||
|
|
||||||
static void init_wl_compositor(uint32_t id, uint32_t version);
|
|
||||||
static void init_wl_subcompositor(uint32_t id, uint32_t version);
|
|
||||||
static void init_wl_seat(uint32_t id, uint32_t version);
|
|
||||||
static void init_wl_output( uint32_t id, uint32_t version);
|
static void init_wl_output( uint32_t id, uint32_t version);
|
||||||
|
|
||||||
static void output_removed(struct output *output);
|
static void output_removed(struct output *output);
|
||||||
|
|
||||||
|
static const char *libdecor_gtk_proxy_tag = "libdecor-gtk";
|
||||||
|
|
||||||
// digesting_libdecor
|
// digesting_libdecor
|
||||||
|
|
||||||
typedef struct Ctx{
|
typedef struct Ctx{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue