[digesting_libdecor] merge plugin_gtk's two sync callbacks with the main one
parent
54039259ad
commit
10b6246ba4
|
|
@ -71,11 +71,12 @@ const struct xdg_wm_base_listener xdg_wm_base_listener;
|
|||
const struct wl_callback_listener init_wl_display_callback_listener;
|
||||
const struct wl_buffer_listener buffer_listener;
|
||||
const struct wl_callback_listener shm_callback_listener;
|
||||
const struct wl_callback_listener globals_callback_listener;
|
||||
|
||||
struct libdecor_plugin_interface gtk_plugin_iface;
|
||||
struct libdecor_plugin_interface fallback_plugin_iface;
|
||||
|
||||
const struct wl_shm_listener shm_listener;
|
||||
|
||||
// X(N:name,R:return,P:params)
|
||||
#define GL_FUNCS_XLIST(X)\
|
||||
X(glDrawBuffer, void, (GLenum buf)) \
|
||||
|
|
@ -93,10 +94,6 @@ static void
|
|||
wlevent__wl_registry_global(void *data, struct wl_registry *wl_registry,
|
||||
uint32_t name, const char *interface,
|
||||
uint32_t version){
|
||||
/* (1) Appendix A: wl_registry::bind
|
||||
** " Binds a new, client-created object to the server "
|
||||
*/
|
||||
|
||||
if (strcmp(interface, "wl_compositor") == 0){
|
||||
ctx.wl_compositor = (struct wl_compositor*)
|
||||
wl_registry_bind(wl_registry, name, &wl_compositor_interface,
|
||||
|
|
@ -117,7 +114,9 @@ wlevent__wl_registry_global(void *data, struct wl_registry *wl_registry,
|
|||
init_wl_subcompositor(name, version);
|
||||
}
|
||||
else if (strcmp(interface, "wl_shm") == 0){
|
||||
init_wl_shm(name, version);
|
||||
ctx.plugin_gtk->wl_shm =
|
||||
wl_registry_bind(ctx.wl_registry, name, &wl_shm_interface, 1);
|
||||
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);
|
||||
|
|
@ -127,7 +126,6 @@ wlevent__wl_registry_global(void *data, struct wl_registry *wl_registry,
|
|||
}
|
||||
}
|
||||
|
||||
/* (1) Appendix A: wl_registry::global_remove */
|
||||
static void
|
||||
wlevent__wl_registry_global_remove(void *data, struct wl_registry *registry,
|
||||
uint32_t name){
|
||||
|
|
@ -145,39 +143,18 @@ const struct wl_registry_listener wl_registry_listener = {
|
|||
wlevent__wl_registry_global_remove,
|
||||
};
|
||||
|
||||
/* (libdecor.h) libdecor_interface::error " An error event " */
|
||||
static void
|
||||
libdecorevent__error(enum libdecor_error error, const char *msg){}
|
||||
|
||||
|
||||
/* (libdecor.h) libdecor_frame_interface::configure
|
||||
** " A new configuration was received. An application should respond to
|
||||
** this by creating a suitable libdecor_state, and apply it using
|
||||
** libdecor_frame_commit. "
|
||||
*/
|
||||
static void
|
||||
libdecorevent__frame_configure(struct libdecor_frame *frame,
|
||||
struct libdecor_configuration *config,
|
||||
void *udata){
|
||||
int w = ctx.w;
|
||||
int h = ctx.h;
|
||||
/* (libdecor.h)
|
||||
** " Get the expected size of the content for this configuration. "
|
||||
*/
|
||||
if (libdecor_configuration_get_content_size(config, frame, &w, &h)){
|
||||
|
||||
/* (libdecor.h) " Create a new content surface state. " */
|
||||
struct libdecor_state *state = libdecor_state_new(w, h);
|
||||
|
||||
/* (libdecor.h) libdecor_frame_commit
|
||||
** " Commit a new window state. This can be called on application
|
||||
** driven resizes when the window is floating, or in response to
|
||||
** received configurations, i.e. from e.g. interactive resizes
|
||||
** or state changes. "
|
||||
*/
|
||||
libdecor_frame_commit(frame, state, config);
|
||||
|
||||
/* (libdecor.h) " Free a content surface state. " */
|
||||
libdecor_state_free(state);
|
||||
}
|
||||
ctx.configured = 1;
|
||||
|
|
@ -185,32 +162,20 @@ libdecorevent__frame_configure(struct libdecor_frame *frame,
|
|||
ctx.h = h;
|
||||
}
|
||||
|
||||
/* (libdecor.h) libdecor_frame_interface::close
|
||||
** " The window was requested to be closed by the compositor. "
|
||||
*/
|
||||
static void
|
||||
libdecorevent__frame_close(struct libdecor_frame *frame, void *udata){
|
||||
ctx.close_signal = 1;
|
||||
}
|
||||
|
||||
/* (libdecor.h) libdecor_frame_interface::commit
|
||||
** " The window decoration asked to have the main surface to be
|
||||
** committed. This is required when the decoration is implemented
|
||||
** using synchronous subsurfaces. "
|
||||
*/
|
||||
static void
|
||||
libdecorevent__frame_commit(struct libdecor_frame *frame, void *udata){
|
||||
wl_surface_commit(ctx.wl_surface);
|
||||
}
|
||||
|
||||
/* (libdecor.h) libdecor_frame_interface::dismiss_popup
|
||||
** " Any mapped popup that has a grab on the given seat should be dismissed. "
|
||||
*/
|
||||
static void
|
||||
libdecorevent__frame_dismiss_popup(struct libdecor_frame *frame,
|
||||
const char *seat_name,
|
||||
void *user_data){
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -220,6 +185,44 @@ libdecorevent__frame_bounds(struct libdecor_frame *frame,
|
|||
void *user_data){
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
const struct wl_shm_listener shm_listener = {
|
||||
shm_format
|
||||
};
|
||||
|
||||
static void
|
||||
init_wl_display_callback(void *user_data,
|
||||
struct wl_callback *callback,
|
||||
uint32_t time){
|
||||
struct libdecor *context = user_data;
|
||||
|
||||
ctx.init_done = true;
|
||||
|
||||
wl_callback_destroy(callback);
|
||||
ctx.wl_callback = 0;
|
||||
|
||||
if (ctx.plugin_ready) {
|
||||
finish_init();
|
||||
}
|
||||
|
||||
if (ctx.plugin_gtk->has_argb) {
|
||||
libdecor_notify_plugin_ready();
|
||||
}
|
||||
}
|
||||
|
||||
const struct wl_callback_listener init_wl_display_callback_listener = {
|
||||
init_wl_display_callback
|
||||
};
|
||||
|
||||
|
||||
int main(){
|
||||
/* get desktop settings */
|
||||
ctx.color_scheme = libdecor_get_color_scheme();
|
||||
|
|
@ -283,24 +286,24 @@ int main(){
|
|||
if (ctx.wl_compositor == 0){
|
||||
printf("failed to get wl_compositor\n");
|
||||
}
|
||||
if (ctx.plugin_gtk->wl_subcompositor == 0){
|
||||
printf("failed to get wl_subcompositor\n");
|
||||
}
|
||||
if (ctx.plugin_gtk->wl_shm == 0){
|
||||
printf("failed to get wl_shm\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (ctx.wl_compositor != 0){
|
||||
if (ctx.wl_compositor != 0 &&
|
||||
ctx.plugin_gtk->wl_subcompositor != 0 &&
|
||||
ctx.plugin_gtk->wl_shm != 0){
|
||||
ctx.wl_callback = wl_display_sync(ctx.wl_display);
|
||||
wl_callback_add_listener(ctx.wl_callback,
|
||||
&init_wl_display_callback_listener,
|
||||
0);
|
||||
|
||||
ctx.plugin_gtk->globals_callback = wl_display_sync(ctx.wl_display);
|
||||
wl_callback_add_listener(ctx.plugin_gtk->globals_callback,
|
||||
&globals_callback_listener,
|
||||
ctx.plugin_gtk);
|
||||
wl_display_roundtrip(ctx.wl_display);
|
||||
|
||||
if (ctx.plugin_gtk->wl_subcompositor != 0 &&
|
||||
ctx.plugin_gtk->wl_shm != 0){
|
||||
ctx.plugin = &ctx.plugin_gtk->plugin;
|
||||
}
|
||||
ctx.plugin = &ctx.plugin_gtk->plugin;
|
||||
|
||||
if (ctx.plugin == 0){
|
||||
fprintf(stderr, "Failed to load static plugin: failed to init\n");
|
||||
|
|
@ -1829,32 +1832,6 @@ finish_init(void){
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
init_wl_display_callback(void *user_data,
|
||||
struct wl_callback *callback,
|
||||
uint32_t time)
|
||||
{
|
||||
struct libdecor *context = user_data;
|
||||
|
||||
ctx.init_done = true;
|
||||
|
||||
wl_callback_destroy(callback);
|
||||
ctx.wl_callback = 0;
|
||||
|
||||
if (ctx.xdg_wm_base == 0){
|
||||
notify_error(LIBDECOR_ERROR_COMPOSITOR_INCOMPATIBLE,
|
||||
"Compositor is missing required interfaces");
|
||||
}
|
||||
|
||||
if (ctx.plugin_ready) {
|
||||
finish_init();
|
||||
}
|
||||
}
|
||||
|
||||
const struct wl_callback_listener init_wl_display_callback_listener = {
|
||||
init_wl_display_callback
|
||||
};
|
||||
|
||||
int
|
||||
libdecor_dispatch(int timeout)
|
||||
{
|
||||
|
|
@ -2603,13 +2580,6 @@ libdecor_plugin_gtk_destroy(struct libdecor_plugin *plugin)
|
|||
struct output *output, *output_tmp;
|
||||
struct libdecor_frame_gtk *frame, *frame_tmp;
|
||||
|
||||
if (plugin_gtk->globals_callback)
|
||||
wl_callback_destroy(plugin_gtk->globals_callback);
|
||||
if (plugin_gtk->globals_callback_shm)
|
||||
wl_callback_destroy(plugin_gtk->globals_callback_shm);
|
||||
if (plugin_gtk->shm_callback)
|
||||
wl_callback_destroy(plugin_gtk->shm_callback);
|
||||
|
||||
wl_list_for_each_safe(seat, seat_tmp, &plugin_gtk->seat_list, link) {
|
||||
struct cursor_output *cursor_output, *tmp;
|
||||
|
||||
|
|
@ -4009,52 +3979,6 @@ init_wl_subcompositor(uint32_t id, uint32_t version){
|
|||
wl_registry_bind(ctx.wl_registry, id, &wl_subcompositor_interface, 1);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
struct wl_shm_listener shm_listener = {
|
||||
shm_format
|
||||
};
|
||||
|
||||
static void
|
||||
shm_callback(void *user_data, struct wl_callback *callback, uint32_t time){
|
||||
struct libdecor_plugin_gtk *plugin_gtk = user_data;
|
||||
|
||||
wl_callback_destroy(callback);
|
||||
plugin_gtk->globals_callback_shm = NULL;
|
||||
|
||||
if (!plugin_gtk->has_argb) {
|
||||
libdecor_notify_plugin_error(LIBDECOR_ERROR_COMPOSITOR_INCOMPATIBLE,
|
||||
"Compositor is missing required shm format");
|
||||
return;
|
||||
}
|
||||
|
||||
libdecor_notify_plugin_ready();
|
||||
}
|
||||
|
||||
const struct wl_callback_listener shm_callback_listener = {
|
||||
shm_callback
|
||||
};
|
||||
|
||||
static void
|
||||
init_wl_shm(uint32_t id, uint32_t version){
|
||||
struct wl_display *wl_display = ctx.wl_display;
|
||||
|
||||
ctx.plugin_gtk->wl_shm =
|
||||
wl_registry_bind(ctx.wl_registry, id, &wl_shm_interface, 1);
|
||||
wl_shm_add_listener(ctx.plugin_gtk->wl_shm, &shm_listener, ctx.plugin_gtk);
|
||||
|
||||
ctx.plugin_gtk->globals_callback_shm = wl_display_sync(wl_display);
|
||||
wl_callback_add_listener(ctx.plugin_gtk->globals_callback_shm,
|
||||
&shm_callback_listener,
|
||||
ctx.plugin_gtk);
|
||||
}
|
||||
|
||||
static void
|
||||
cursor_surface_enter(void *data,
|
||||
struct wl_surface *wl_surface,
|
||||
|
|
@ -5001,21 +4925,6 @@ output_removed(struct output *output)
|
|||
free(output);
|
||||
}
|
||||
|
||||
static void
|
||||
globals_callback(void *user_data,
|
||||
struct wl_callback *callback,
|
||||
uint32_t time)
|
||||
{
|
||||
struct libdecor_plugin_gtk *plugin_gtk = user_data;
|
||||
|
||||
wl_callback_destroy(callback);
|
||||
plugin_gtk->globals_callback = NULL;
|
||||
}
|
||||
|
||||
const struct wl_callback_listener globals_callback_listener = {
|
||||
globals_callback
|
||||
};
|
||||
|
||||
static struct libdecor_plugin_priority priorities[] = {
|
||||
{ NULL, LIBDECOR_PLUGIN_PRIORITY_HIGH }
|
||||
};
|
||||
|
|
|
|||
|
|
@ -435,13 +435,9 @@ struct libdecor_frame_gtk {
|
|||
struct libdecor_plugin_gtk {
|
||||
struct libdecor_plugin plugin;
|
||||
|
||||
struct wl_callback *globals_callback;
|
||||
struct wl_callback *globals_callback_shm;
|
||||
|
||||
struct wl_subcompositor *wl_subcompositor;
|
||||
|
||||
struct wl_shm *wl_shm;
|
||||
struct wl_callback *shm_callback;
|
||||
bool has_argb;
|
||||
|
||||
struct wl_list visible_frame_list;
|
||||
|
|
@ -494,10 +490,8 @@ void libdecor_frame_popup_grab(struct libdecor_frame *frame,
|
|||
void libdecor_frame_popup_ungrab(struct libdecor_frame *frame,
|
||||
const char *seat_name);
|
||||
void libdecor_frame_translate_coordinate(struct libdecor_frame *frame,
|
||||
int surface_x,
|
||||
int surface_y,
|
||||
int *frame_x,
|
||||
int *frame_y);
|
||||
int surface_x, int surface_y,
|
||||
int *frame_x, int *frame_y);
|
||||
void libdecor_frame_set_min_content_size(struct libdecor_frame *frame,
|
||||
int content_width,
|
||||
int content_height);
|
||||
|
|
@ -600,6 +594,8 @@ 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);
|
||||
|
||||
//#include "plugins/gtk/libdecor-gtk.c"
|
||||
|
||||
|
|
@ -607,7 +603,6 @@ 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_shm(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);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue