[digseting_libdecor] put plugin_gtk into global context, eliminate plugin_gtk as parameter in wl_registry_listener helper init functions
parent
cdedd70a3b
commit
30ece62d04
|
|
@ -133,22 +133,20 @@ registry_handle_global(void *user_data,
|
||||||
const char *interface,
|
const char *interface,
|
||||||
uint32_t version)
|
uint32_t version)
|
||||||
{
|
{
|
||||||
struct libdecor_plugin_gtk *plugin_gtk = user_data;
|
|
||||||
|
|
||||||
if (strcmp(interface, "wl_compositor") == 0){
|
if (strcmp(interface, "wl_compositor") == 0){
|
||||||
init_wl_compositor(plugin_gtk, id, version);
|
init_wl_compositor(id, version);
|
||||||
}
|
}
|
||||||
else if (strcmp(interface, "wl_subcompositor") == 0){
|
else if (strcmp(interface, "wl_subcompositor") == 0){
|
||||||
init_wl_subcompositor(plugin_gtk, id, version);
|
init_wl_subcompositor(id, version);
|
||||||
}
|
}
|
||||||
else if (strcmp(interface, "wl_shm") == 0){
|
else if (strcmp(interface, "wl_shm") == 0){
|
||||||
init_wl_shm(plugin_gtk, id, version);
|
init_wl_shm(id, version);
|
||||||
}
|
}
|
||||||
else if (strcmp(interface, "wl_seat") == 0){
|
else if (strcmp(interface, "wl_seat") == 0){
|
||||||
init_wl_seat(plugin_gtk, id, version);
|
init_wl_seat(id, version);
|
||||||
}
|
}
|
||||||
else if (strcmp(interface, "wl_output") == 0){
|
else if (strcmp(interface, "wl_output") == 0){
|
||||||
init_wl_output(plugin_gtk, id, version);
|
init_wl_output(id, version);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -162,7 +160,7 @@ registry_handle_global_remove(void *user_data,
|
||||||
|
|
||||||
wl_list_for_each(output, &plugin_gtk->output_list, link) {
|
wl_list_for_each(output, &plugin_gtk->output_list, link) {
|
||||||
if (output->id == name) {
|
if (output->id == name) {
|
||||||
output_removed(plugin_gtk, output);
|
output_removed(output);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -250,61 +248,15 @@ libdecorevent__frame_bounds(struct libdecor_frame *frame,
|
||||||
|
|
||||||
int main(){
|
int main(){
|
||||||
/* get desktop settings */
|
/* get desktop settings */
|
||||||
{
|
|
||||||
ctx.color_scheme = libdecor_get_color_scheme();
|
ctx.color_scheme = libdecor_get_color_scheme();
|
||||||
if (libdecor_get_cursor_settings(&ctx.cursor_theme_name, &ctx.cursor_size)){
|
if (libdecor_get_cursor_settings(&ctx.cursor_theme_name, &ctx.cursor_size)){
|
||||||
ctx.cursor_theme_name = 0;
|
ctx.cursor_theme_name = 0;
|
||||||
ctx.cursor_size = 24;
|
ctx.cursor_size = 24;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/*~ NOTE:
|
|
||||||
**~ initialize Wayland, Libdecor, & EGL
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* (1) Appendix B: wl_display_connect
|
|
||||||
** " Connect to a Wayland display. "
|
|
||||||
*/
|
|
||||||
ctx.wl_display = wl_display_connect(0);
|
|
||||||
if (ctx.wl_display == 0){
|
|
||||||
printf("wl_display_connect failed\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (1) Appendix A: wl_display::get_registry
|
|
||||||
** " creates a registry object that allows the client to list
|
|
||||||
** and bind the global objects available from the compositor "
|
|
||||||
*/
|
|
||||||
if (ctx.wl_display != 0){
|
|
||||||
ctx.wl_registry = wl_display_get_registry(ctx.wl_display);
|
|
||||||
if (ctx.wl_registry == 0){
|
|
||||||
printf("wl_display_get_registry failed\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ctx.wl_registry != 0){
|
|
||||||
/* [1] */
|
|
||||||
wl_registry_add_listener(ctx.wl_registry, &wl_registry_listener, 0);
|
|
||||||
|
|
||||||
/* (1) Appendix B: wl_display::dispatch
|
|
||||||
** " Dispatch events on the default event queue. If the default
|
|
||||||
** event queue is empty, this function blocks until there are
|
|
||||||
** events to be read from the display fd. "
|
|
||||||
*/
|
|
||||||
wl_display_dispatch(ctx.wl_display);
|
|
||||||
|
|
||||||
/* (1) Appendix B: wl_display_roundtrip
|
|
||||||
** " Block until all pending request are processed by the server "
|
|
||||||
*/
|
|
||||||
wl_display_roundtrip(ctx.wl_display);
|
|
||||||
|
|
||||||
if (ctx.wl_compositor == 0){
|
|
||||||
printf("failed to get wl_compositor\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* setup GTK context */
|
/* setup GTK context */
|
||||||
int gtk_init_success = 0;
|
int gtk_init_success = 0;
|
||||||
if (ctx.wl_display != 0 && ctx.wl_compositor != 0){
|
{
|
||||||
gdk_set_allowed_backends("wayland");
|
gdk_set_allowed_backends("wayland");
|
||||||
gtk_disable_setlocale();
|
gtk_disable_setlocale();
|
||||||
if (gtk_init_check(0, 0)){
|
if (gtk_init_check(0, 0)){
|
||||||
|
|
@ -320,39 +272,65 @@ int main(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*~ NOTE:
|
||||||
|
**~ initialize Wayland, Libdecor, & EGL
|
||||||
|
*/
|
||||||
|
|
||||||
|
{
|
||||||
|
ctx.plugin_gtk = calloc(1, sizeof *ctx.plugin_gtk);
|
||||||
|
libdecor_plugin_init(&ctx.plugin_gtk->plugin, >k_plugin_iface);
|
||||||
|
|
||||||
|
wl_list_init(&ctx.frames);
|
||||||
|
|
||||||
|
wl_list_init(&ctx.plugin_gtk->visible_frame_list);
|
||||||
|
wl_list_init(&ctx.plugin_gtk->seat_list);
|
||||||
|
wl_list_init(&ctx.plugin_gtk->output_list);
|
||||||
|
}
|
||||||
|
|
||||||
if (gtk_init_success){
|
if (gtk_init_success){
|
||||||
|
ctx.wl_display = wl_display_connect(0);
|
||||||
|
if (ctx.wl_display == 0){
|
||||||
|
printf("wl_display_connect failed\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ctx.wl_display != 0){
|
||||||
|
ctx.wl_registry = wl_display_get_registry(ctx.wl_display);
|
||||||
|
if (ctx.wl_registry == 0){
|
||||||
|
printf("wl_display_get_registry failed\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ctx.wl_registry != 0){
|
||||||
|
wl_registry_add_listener(ctx.wl_registry, &wl_registry_listener, 0);
|
||||||
|
wl_display_dispatch(ctx.wl_display);
|
||||||
|
wl_display_roundtrip(ctx.wl_display);
|
||||||
|
|
||||||
|
if (ctx.wl_compositor == 0){
|
||||||
|
printf("failed to get wl_compositor\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ctx.wl_compositor != 0){
|
||||||
ctx.wl_callback = wl_display_sync(ctx.wl_display);
|
ctx.wl_callback = wl_display_sync(ctx.wl_display);
|
||||||
wl_callback_add_listener(ctx.wl_callback,
|
wl_callback_add_listener(ctx.wl_callback,
|
||||||
&init_wl_display_callback_listener,
|
&init_wl_display_callback_listener,
|
||||||
0);
|
0);
|
||||||
|
|
||||||
wl_list_init(&ctx.frames);
|
ctx.plugin_gtk->wl_registry = wl_display_get_registry(ctx.wl_display);
|
||||||
|
wl_registry_add_listener(ctx.plugin_gtk->wl_registry,
|
||||||
|
®istry_listener, ctx.plugin_gtk);
|
||||||
|
|
||||||
{
|
ctx.plugin_gtk->globals_callback = wl_display_sync(ctx.wl_display);
|
||||||
struct libdecor_plugin_gtk *plugin_gtk;
|
wl_callback_add_listener(ctx.plugin_gtk->globals_callback,
|
||||||
|
|
||||||
plugin_gtk = calloc(1, sizeof *plugin_gtk);
|
|
||||||
libdecor_plugin_init(&plugin_gtk->plugin, >k_plugin_iface);
|
|
||||||
|
|
||||||
wl_list_init(&plugin_gtk->visible_frame_list);
|
|
||||||
wl_list_init(&plugin_gtk->seat_list);
|
|
||||||
wl_list_init(&plugin_gtk->output_list);
|
|
||||||
|
|
||||||
plugin_gtk->wl_registry = wl_display_get_registry(ctx.wl_display);
|
|
||||||
wl_registry_add_listener(plugin_gtk->wl_registry,
|
|
||||||
®istry_listener, plugin_gtk);
|
|
||||||
|
|
||||||
plugin_gtk->globals_callback = wl_display_sync(ctx.wl_display);
|
|
||||||
wl_callback_add_listener(plugin_gtk->globals_callback,
|
|
||||||
&globals_callback_listener,
|
&globals_callback_listener,
|
||||||
plugin_gtk);
|
ctx.plugin_gtk);
|
||||||
wl_display_roundtrip(ctx.wl_display);
|
wl_display_roundtrip(ctx.wl_display);
|
||||||
|
|
||||||
if (plugin_gtk->wl_compositor != 0 &&
|
if (ctx.plugin_gtk->wl_compositor != 0 &&
|
||||||
plugin_gtk->wl_subcompositor != 0 &&
|
ctx.plugin_gtk->wl_subcompositor != 0 &&
|
||||||
plugin_gtk->wl_shm != 0){
|
ctx.plugin_gtk->wl_shm != 0){
|
||||||
ctx.plugin = &plugin_gtk->plugin;
|
ctx.plugin = &ctx.plugin_gtk->plugin;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ctx.plugin == 0){
|
if (ctx.plugin == 0){
|
||||||
|
|
@ -4060,31 +4038,22 @@ struct libdecor_plugin_interface gtk_plugin_iface = {
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
init_wl_compositor(struct libdecor_plugin_gtk *plugin_gtk,
|
init_wl_compositor(uint32_t id, uint32_t version){
|
||||||
uint32_t id,
|
ctx.plugin_gtk->wl_compositor =
|
||||||
uint32_t version)
|
wl_registry_bind(ctx.plugin_gtk->wl_registry,
|
||||||
{
|
|
||||||
plugin_gtk->wl_compositor =
|
|
||||||
wl_registry_bind(plugin_gtk->wl_registry,
|
|
||||||
id, &wl_compositor_interface,
|
id, &wl_compositor_interface,
|
||||||
MIN(version, 4));
|
MIN(version, 4));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
init_wl_subcompositor(struct libdecor_plugin_gtk *plugin_gtk,
|
init_wl_subcompositor(uint32_t id, uint32_t version){
|
||||||
uint32_t id,
|
ctx.plugin_gtk->wl_subcompositor =
|
||||||
uint32_t version)
|
wl_registry_bind(ctx.plugin_gtk->wl_registry,
|
||||||
{
|
|
||||||
plugin_gtk->wl_subcompositor =
|
|
||||||
wl_registry_bind(plugin_gtk->wl_registry,
|
|
||||||
id, &wl_subcompositor_interface, 1);
|
id, &wl_subcompositor_interface, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
shm_format(void *user_data,
|
shm_format(void *user_data, struct wl_shm *wl_shm, uint32_t format){
|
||||||
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)
|
||||||
|
|
@ -4116,21 +4085,18 @@ const struct wl_callback_listener shm_callback_listener = {
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
init_wl_shm(struct libdecor_plugin_gtk *plugin_gtk,
|
init_wl_shm(uint32_t id, uint32_t version){
|
||||||
uint32_t id,
|
|
||||||
uint32_t version)
|
|
||||||
{
|
|
||||||
struct wl_display *wl_display = ctx.wl_display;
|
struct wl_display *wl_display = ctx.wl_display;
|
||||||
|
|
||||||
plugin_gtk->wl_shm =
|
ctx.plugin_gtk->wl_shm =
|
||||||
wl_registry_bind(plugin_gtk->wl_registry,
|
wl_registry_bind(ctx.plugin_gtk->wl_registry,
|
||||||
id, &wl_shm_interface, 1);
|
id, &wl_shm_interface, 1);
|
||||||
wl_shm_add_listener(plugin_gtk->wl_shm, &shm_listener, plugin_gtk);
|
wl_shm_add_listener(ctx.plugin_gtk->wl_shm, &shm_listener, ctx.plugin_gtk);
|
||||||
|
|
||||||
plugin_gtk->globals_callback_shm = wl_display_sync(wl_display);
|
ctx.plugin_gtk->globals_callback_shm = wl_display_sync(wl_display);
|
||||||
wl_callback_add_listener(plugin_gtk->globals_callback_shm,
|
wl_callback_add_listener(ctx.plugin_gtk->globals_callback_shm,
|
||||||
&shm_callback_listener,
|
&shm_callback_listener,
|
||||||
plugin_gtk);
|
ctx.plugin_gtk);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -4937,10 +4903,7 @@ static struct wl_seat_listener seat_listener = {
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
init_wl_seat(struct libdecor_plugin_gtk *plugin_gtk,
|
init_wl_seat(uint32_t id, uint32_t version){
|
||||||
uint32_t id,
|
|
||||||
uint32_t version)
|
|
||||||
{
|
|
||||||
struct seat *seat;
|
struct seat *seat;
|
||||||
|
|
||||||
if (version < 3) {
|
if (version < 3) {
|
||||||
|
|
@ -4952,11 +4915,11 @@ init_wl_seat(struct libdecor_plugin_gtk *plugin_gtk,
|
||||||
|
|
||||||
seat = calloc(1, sizeof *seat);
|
seat = calloc(1, sizeof *seat);
|
||||||
seat->cursor_scale = 1;
|
seat->cursor_scale = 1;
|
||||||
seat->plugin_gtk = plugin_gtk;
|
seat->plugin_gtk = ctx.plugin_gtk;
|
||||||
wl_list_init(&seat->cursor_outputs);
|
wl_list_init(&seat->cursor_outputs);
|
||||||
wl_list_insert(&plugin_gtk->seat_list, &seat->link);
|
wl_list_insert(&ctx.plugin_gtk->seat_list, &seat->link);
|
||||||
seat->wl_seat =
|
seat->wl_seat =
|
||||||
wl_registry_bind(plugin_gtk->wl_registry,
|
wl_registry_bind(ctx.plugin_gtk->wl_registry,
|
||||||
id, &wl_seat_interface, 3);
|
id, &wl_seat_interface, 3);
|
||||||
wl_seat_add_listener(seat->wl_seat, &seat_listener, seat);
|
wl_seat_add_listener(seat->wl_seat, &seat_listener, seat);
|
||||||
}
|
}
|
||||||
|
|
@ -5024,10 +4987,7 @@ static struct wl_output_listener output_listener = {
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
init_wl_output(struct libdecor_plugin_gtk *plugin_gtk,
|
init_wl_output(uint32_t id, uint32_t version){
|
||||||
uint32_t id,
|
|
||||||
uint32_t version)
|
|
||||||
{
|
|
||||||
struct output *output;
|
struct output *output;
|
||||||
|
|
||||||
if (version < 2) {
|
if (version < 2) {
|
||||||
|
|
@ -5038,11 +4998,11 @@ init_wl_output(struct libdecor_plugin_gtk *plugin_gtk,
|
||||||
}
|
}
|
||||||
|
|
||||||
output = calloc(1, sizeof *output);
|
output = calloc(1, sizeof *output);
|
||||||
output->plugin_gtk = plugin_gtk;
|
output->plugin_gtk = ctx.plugin_gtk;
|
||||||
wl_list_insert(&plugin_gtk->output_list, &output->link);
|
wl_list_insert(&ctx.plugin_gtk->output_list, &output->link);
|
||||||
output->id = id;
|
output->id = id;
|
||||||
output->wl_output =
|
output->wl_output =
|
||||||
wl_registry_bind(plugin_gtk->wl_registry,
|
wl_registry_bind(ctx.plugin_gtk->wl_registry,
|
||||||
id, &wl_output_interface,
|
id, &wl_output_interface,
|
||||||
MIN (version, 3));
|
MIN (version, 3));
|
||||||
wl_proxy_set_tag((struct wl_proxy *) output->wl_output,
|
wl_proxy_set_tag((struct wl_proxy *) output->wl_output,
|
||||||
|
|
@ -5064,16 +5024,15 @@ remove_surface_outputs(struct border_component *cmpnt, const struct output *outp
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
output_removed(struct libdecor_plugin_gtk *plugin_gtk,
|
output_removed(struct output *output)
|
||||||
struct output *output)
|
|
||||||
{
|
{
|
||||||
struct libdecor_frame_gtk *frame_gtk;
|
struct libdecor_frame_gtk *frame_gtk;
|
||||||
struct seat *seat;
|
struct seat *seat;
|
||||||
|
|
||||||
wl_list_for_each(frame_gtk, &plugin_gtk->visible_frame_list, link) {
|
wl_list_for_each(frame_gtk, &ctx.plugin_gtk->visible_frame_list, link) {
|
||||||
remove_surface_outputs(&frame_gtk->shadow, output);
|
remove_surface_outputs(&frame_gtk->shadow, output);
|
||||||
}
|
}
|
||||||
wl_list_for_each(seat, &plugin_gtk->seat_list, link) {
|
wl_list_for_each(seat, &ctx.plugin_gtk->seat_list, link) {
|
||||||
struct cursor_output *cursor_output;
|
struct cursor_output *cursor_output;
|
||||||
wl_list_for_each(cursor_output, &seat->cursor_outputs, link) {
|
wl_list_for_each(cursor_output, &seat->cursor_outputs, link) {
|
||||||
if (cursor_output->output == output) {
|
if (cursor_output->output == output) {
|
||||||
|
|
|
||||||
|
|
@ -607,14 +607,14 @@ static void init_xdg_wm_base(uint32_t id, uint32_t version);
|
||||||
|
|
||||||
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(struct libdecor_plugin_gtk *plugin_gtk, uint32_t id, uint32_t version);
|
static void init_wl_compositor(uint32_t id, uint32_t version);
|
||||||
static void init_wl_subcompositor(struct libdecor_plugin_gtk *plugin_gtk, uint32_t id, uint32_t version);
|
static void init_wl_subcompositor(uint32_t id, uint32_t version);
|
||||||
static void init_wl_shm(struct libdecor_plugin_gtk *plugin_gtk, uint32_t id, uint32_t version);
|
static void init_wl_shm(uint32_t id, uint32_t version);
|
||||||
static void init_wl_seat(struct libdecor_plugin_gtk *plugin_gtk,
|
static void init_wl_seat(uint32_t id, uint32_t version);
|
||||||
uint32_t id, uint32_t version);
|
static void init_wl_output( uint32_t id, uint32_t version);
|
||||||
static void init_wl_output(struct libdecor_plugin_gtk *plugin_gtk, uint32_t id, uint32_t version);
|
|
||||||
|
static void output_removed(struct output *output);
|
||||||
|
|
||||||
static void output_removed(struct libdecor_plugin_gtk *plugin_gtk, struct output *output);
|
|
||||||
// digesting_libdecor
|
// digesting_libdecor
|
||||||
|
|
||||||
typedef struct Ctx{
|
typedef struct Ctx{
|
||||||
|
|
@ -632,6 +632,7 @@ typedef struct Ctx{
|
||||||
|
|
||||||
struct wl_list frames;
|
struct wl_list frames;
|
||||||
struct wl_callback *wl_callback;
|
struct wl_callback *wl_callback;
|
||||||
|
struct libdecor_plugin_gtk *plugin_gtk;
|
||||||
struct libdecor_plugin *plugin;
|
struct libdecor_plugin *plugin;
|
||||||
bool plugin_ready;
|
bool plugin_ready;
|
||||||
bool init_done;
|
bool init_done;
|
||||||
|
|
@ -645,9 +646,6 @@ typedef struct Ctx{
|
||||||
int w;
|
int w;
|
||||||
int h;
|
int h;
|
||||||
int close_signal;
|
int close_signal;
|
||||||
//struct xdg_surface *xdg_surface;
|
|
||||||
//struct xdg_toplevel *xdg_toplevel;
|
|
||||||
//struct wl_region *wl_region;
|
|
||||||
EGLDisplay egl_display;
|
EGLDisplay egl_display;
|
||||||
EGLContext egl_context;
|
EGLContext egl_context;
|
||||||
EGLSurface egl_surface;
|
EGLSurface egl_surface;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue