mirror of
https://github.com/fltk/fltk.git
synced 2026-05-27 19:10:24 +08:00
Wayland: simpler implementation of "GTK Shell" protocol
This commit is contained in:
@@ -301,52 +301,11 @@ unsigned char *fl_libdecor_titlebar_buffer(struct libdecor_frame *frame,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct libdecor { // copied from libdecor.c, for libdecor versions > 0.2.2
|
/* Returns whether surface is the libdecor-created GTK-titlebar of frame */
|
||||||
int ref_count;
|
bool fl_is_surface_from_GTK_titlebar (struct wl_surface *surface, struct libdecor_frame *frame,
|
||||||
const struct libdecor_interface *iface;
|
bool *using_GTK) {
|
||||||
void *user_data; // added after libdecor version 0.2.2
|
*using_GTK = (get_plugin_kind(NULL) == GTK3);
|
||||||
struct libdecor_plugin *plugin;
|
if (!*using_GTK) return false;
|
||||||
bool plugin_ready;
|
struct libdecor_frame_gtk *frame_gtk = (struct libdecor_frame_gtk*)frame;
|
||||||
struct wl_display *wl_display;
|
return (frame_gtk->headerbar.wl_surface == surface);
|
||||||
struct wl_registry *wl_registry;
|
|
||||||
struct xdg_wm_base *xdg_wm_base;
|
|
||||||
struct zxdg_decoration_manager_v1 *decoration_manager;
|
|
||||||
struct wl_callback *init_callback;
|
|
||||||
bool init_done;
|
|
||||||
bool has_error;
|
|
||||||
struct wl_list frames;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct libdecor_022 { // for libdecor versions ≤ 0.2.2
|
|
||||||
int ref_count;
|
|
||||||
const struct libdecor_interface *iface;
|
|
||||||
struct libdecor_plugin *plugin;
|
|
||||||
bool plugin_ready;
|
|
||||||
struct wl_display *wl_display;
|
|
||||||
struct wl_registry *wl_registry;
|
|
||||||
struct xdg_wm_base *xdg_wm_base;
|
|
||||||
struct zxdg_decoration_manager_v1 *decoration_manager;
|
|
||||||
struct wl_callback *init_callback;
|
|
||||||
bool init_done;
|
|
||||||
bool has_error;
|
|
||||||
struct wl_list frames;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* Returns whether surface is a GTK-titlebar created by libdecor-gtk */
|
|
||||||
bool fl_is_surface_gtk_titlebar(struct wl_surface *surface, struct libdecor *context,
|
|
||||||
struct wl_display *wl_display) {
|
|
||||||
if (!context || get_plugin_kind(NULL) != GTK3) return false;
|
|
||||||
// loop over all decorations created by libdecor-gtk
|
|
||||||
struct libdecor_frame *frame;
|
|
||||||
struct wl_list *frames;
|
|
||||||
if (context->wl_display == wl_display) frames = &context->frames;
|
|
||||||
else if (((struct libdecor_022*)context)->wl_display == wl_display)
|
|
||||||
frames = &(((struct libdecor_022*)context)->frames);
|
|
||||||
else return false;
|
|
||||||
wl_list_for_each(frame, frames, link) {
|
|
||||||
struct libdecor_frame_gtk *frame_gtk = (struct libdecor_frame_gtk*)frame;
|
|
||||||
if (frame_gtk->headerbar.wl_surface == surface) return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,8 @@
|
|||||||
#include <string.h> // for strerror()
|
#include <string.h> // for strerror()
|
||||||
extern "C" {
|
extern "C" {
|
||||||
bool libdecor_get_cursor_settings(char **theme, int *size);
|
bool libdecor_get_cursor_settings(char **theme, int *size);
|
||||||
bool fl_is_surface_gtk_titlebar(struct wl_surface *, struct libdecor *, struct wl_display *);
|
bool fl_is_surface_from_GTK_titlebar (struct wl_surface *surface, struct libdecor_frame *frame,
|
||||||
|
bool *using_GTK);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set this to 1 for keyboard debug output, 0 for no debug output
|
// set this to 1 for keyboard debug output, 0 for no debug output
|
||||||
@@ -204,11 +205,21 @@ static Fl_Window *event_coords_from_surface(struct wl_surface *surface,
|
|||||||
static void pointer_enter(void *data, struct wl_pointer *wl_pointer, uint32_t serial,
|
static void pointer_enter(void *data, struct wl_pointer *wl_pointer, uint32_t serial,
|
||||||
struct wl_surface *surface, wl_fixed_t surface_x, wl_fixed_t surface_y) {
|
struct wl_surface *surface, wl_fixed_t surface_x, wl_fixed_t surface_y) {
|
||||||
Fl_Window *win = event_coords_from_surface(surface, surface_x, surface_y);
|
Fl_Window *win = event_coords_from_surface(surface, surface_x, surface_y);
|
||||||
if (!win && gtk_shell) { // check that surface is the headerbar of a GTK-decorated window
|
if (!win && gtk_shell) { // check whether surface is the headerbar of a GTK-decorated window
|
||||||
Fl_Wayland_Screen_Driver *scr_driver = (Fl_Wayland_Screen_Driver*)Fl::screen_driver();
|
Fl_X *xp = Fl_X::first;
|
||||||
if (fl_is_surface_gtk_titlebar(surface, scr_driver->libdecor_context,
|
bool using_GTK = true;
|
||||||
Fl_Wayland_Screen_Driver::wl_display)) {
|
while (xp && using_GTK) { // all mapped windows
|
||||||
gtk_shell_surface = surface;
|
struct wld_window *xid = (struct wld_window*)xp->xid;
|
||||||
|
if (xid->kind == Fl_Wayland_Window_Driver::DECORATED &&
|
||||||
|
fl_is_surface_from_GTK_titlebar(surface, xid->frame, &using_GTK)) {
|
||||||
|
gtk_shell_surface = surface;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
xp = xp->next;
|
||||||
|
}
|
||||||
|
if (!using_GTK) {
|
||||||
|
gtk_shell1_destroy(gtk_shell);
|
||||||
|
gtk_shell = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!win) return;
|
if (!win) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user