diff --git a/digesting_libdecor.c b/digesting_libdecor.c index 9dae06f..e14dc17 100755 --- a/digesting_libdecor.c +++ b/digesting_libdecor.c @@ -76,6 +76,10 @@ struct libdecor_plugin_interface gtk_plugin_iface; struct libdecor_plugin_interface fallback_plugin_iface; 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) #define GL_FUNCS_XLIST(X)\ @@ -100,18 +104,15 @@ wlevent__wl_registry_global(void *data, struct wl_registry *wl_registry, MIN(version, 4)); } 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)){ - const char *force_csd = getenv("LIBDECOR_FORCE_CSD"); - if (!(force_csd && atoi(force_csd))){ - ctx.decoration_manager = wl_registry_bind(wl_registry, name, - &zxdg_decoration_manager_v1_interface, - MIN(version,2)); - } + ctx.decoration_manager = wl_registry_bind(wl_registry, name, &zxdg_decoration_manager_v1_interface, MIN(version,2)); } 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){ 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); } 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){ - 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); } } @@ -130,8 +156,8 @@ static void wlevent__wl_registry_global_remove(void *data, struct wl_registry *registry, uint32_t name){ struct output *output; - wl_list_for_each(output, &ctx.plugin_gtk->output_list, link) { - if (output->id == name) { + wl_list_for_each(output, &ctx.plugin_gtk->output_list, link){ + if (output->id == name){ output_removed(output); break; } @@ -188,7 +214,6 @@ libdecorevent__frame_bounds(struct libdecor_frame *frame, static void shm_format(void *user_data, struct wl_shm *wl_shm, uint32_t format){ struct libdecor_plugin_gtk *plugin_gtk = user_data; - if (format == WL_SHM_FORMAT_ARGB8888){ plugin_gtk->has_argb = true; } @@ -209,11 +234,11 @@ init_wl_display_callback(void *user_data, wl_callback_destroy(callback); ctx.wl_callback = 0; - if (ctx.plugin_ready) { + if (ctx.plugin_ready){ finish_init(); } - if (ctx.plugin_gtk->has_argb) { + if (ctx.plugin_gtk->has_argb){ libdecor_notify_plugin_ready(); } } @@ -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(){ /* get desktop settings */ 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, }; -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 notify_error(enum libdecor_error error, const char *message) { @@ -2510,8 +2547,6 @@ streq(const char *str1, return false; } -static const char *libdecor_gtk_proxy_tag = "libdecor-gtk"; - static bool 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, }; -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 cursor_surface_enter(void *data, 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_leave, 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_up, touch_motion, @@ -4737,71 +4766,6 @@ static struct wl_touch_listener touch_listener = { 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 output_geometry(void *data, struct wl_output *wl_output, @@ -4857,37 +4821,13 @@ output_scale(void *data, output->scale = factor; } -static struct wl_output_listener output_listener = { +const struct wl_output_listener output_listener = { output_geometry, output_mode, output_done, 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 remove_surface_outputs(struct border_component *cmpnt, const struct output *output) { diff --git a/digesting_libdecor.h b/digesting_libdecor.h index 15c55f0..22306a5 100644 --- a/digesting_libdecor.h +++ b/digesting_libdecor.h @@ -593,7 +593,6 @@ int libdecor_os_create_anonymous_file(off_t size); // #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 finish_init(void); @@ -601,13 +600,12 @@ static void finish_init(void); 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 output_removed(struct output *output); +static const char *libdecor_gtk_proxy_tag = "libdecor-gtk"; + // digesting_libdecor typedef struct Ctx{