Have libdecor-gtk implement the "GTK Shell" protocol

This commit is contained in:
ManoloFLTK 2023-11-09 11:25:39 +01:00
parent 768dcf2c11
commit 888dc5f5c5
7 changed files with 250 additions and 5 deletions

View File

@ -18,7 +18,7 @@ include ../../makeinclude
OBJECTS = fl_libdecor.o libdecor-cairo-blur.o fl_libdecor-plugins.o \
../../src/xdg-decoration-protocol.o ../../src/xdg-shell-protocol.o \
../../src/text-input-protocol.o cursor-settings.o os-compatibility.o
../../src/text-input-protocol.o ../../src/gtk-shell-protocol.o cursor-settings.o os-compatibility.o
PROTOCOLS = `pkg-config --variable=pkgdatadir wayland-protocols`
@ -38,7 +38,7 @@ all : $(OBJECTS)
depend:
: echo "libdecor/build: make depend..."
fl_libdecor.o : fl_libdecor.c ../src/libdecor.c ../../src/xdg-shell-protocol.c ../../src/xdg-decoration-protocol.c ../../src/text-input-protocol.c
fl_libdecor.o : fl_libdecor.c ../src/libdecor.c ../../src/xdg-shell-protocol.c ../../src/xdg-decoration-protocol.c ../../src/text-input-protocol.c ../../src/gtk-shell-protocol.c
$(CC) $(CFLAGS) $(CFLAGS_DECOR) -c fl_libdecor.c -DLIBDECOR_PLUGIN_API_VERSION=1 -DLIBDECOR_PLUGIN_DIR=\"\"
fl_libdecor-plugins.o : fl_libdecor-plugins.c ../src/plugins/cairo/libdecor-cairo.c
@ -75,10 +75,16 @@ cursor-settings.o : ../src/cursor-settings.c
$(PROTOCOLS)/unstable/text-input/text-input-unstable-v3.xml \
../../src/text-input-client-protocol.h
../../src/gtk-shell-protocol.c :
wayland-scanner private-code \
gtk-shell.xml ../../src/gtk-shell-protocol.c
wayland-scanner client-header \
gtk-shell.xml ../../src/gtk-shell-client-protocol.h
install:
echo "Nothing to install"
uninstall:
clean:
$(RM) *.o ../../src/xdg-*.c ../../src/xdg-*.h ../../src/xdg-*.o ../../src/text-input-*
$(RM) *.o ../../src/xdg-*.c ../../src/xdg-*.h ../../src/xdg-*.o ../../src/text-input-* ../../src/gtk-shell-*

View File

@ -27,6 +27,10 @@
#include "../src/libdecor.h"
#include <pango/pangocairo.h>
#ifndef HAVE_GTK
# define HAVE_GTK 0
#endif
#if USE_SYSTEM_LIBDECOR
#include "../src/libdecor-plugin.h"
enum zxdg_toplevel_decoration_v1_mode {
@ -55,7 +59,7 @@ struct buffer { // identical in libdecor-cairo.c and libdecor-gtk.c
const struct libdecor_plugin_description *fl_libdecor_plugin_description = NULL;
# ifdef HAVE_GTK
# if HAVE_GTK
# include <gtk/gtk.h>
# include "../src/plugins/gtk/libdecor-gtk.c"
# else
@ -316,3 +320,112 @@ unsigned char *fl_libdecor_titlebar_buffer(struct libdecor_frame *frame,
}
return NULL;
}
/* === Beginning of code to add support of GTK Shell to libdecor-gtk === */
#if HAVE_GTK && !USE_SYSTEM_LIBDECOR
# include "gtk-shell-client-protocol.h"
static struct gtk_shell1 *gtk_shell = NULL;
// libdecor's button member of wl_pointer_listener objects
static void (*decor_pointer_button)(void*, struct wl_pointer *,
uint32_t ,
uint32_t ,
uint32_t ,
uint32_t);
// FLTK's replacement for button member of wl_pointer_listener objects
static void fltk_pointer_button(void *data,
struct wl_pointer *wl_pointer,
uint32_t serial,
uint32_t time,
uint32_t button,
uint32_t state) {
struct seat *seat = data;
struct libdecor_frame_gtk *frame_gtk;
if (!seat->pointer_focus || !own_surface(seat->pointer_focus))
return;
frame_gtk = wl_surface_get_user_data(seat->pointer_focus);
if (!frame_gtk)
return;
if (button == BTN_MIDDLE && state == WL_POINTER_BUTTON_STATE_PRESSED) {
struct gtk_surface1 *gtk_surface = gtk_shell1_get_gtk_surface(gtk_shell,
frame_gtk->headerbar.wl_surface);
gtk_surface1_titlebar_gesture(gtk_surface, serial,
seat->wl_seat, GTK_SURFACE1_GESTURE_MIDDLE_CLICK);
gtk_surface1_release(gtk_surface);
return;
} else if (button == BTN_RIGHT && state == WL_POINTER_BUTTON_STATE_PRESSED) {
struct gtk_surface1 *gtk_surface = gtk_shell1_get_gtk_surface(gtk_shell,
frame_gtk->headerbar.wl_surface);
gtk_surface1_titlebar_gesture(gtk_surface, serial,
seat->wl_seat, GTK_SURFACE1_GESTURE_RIGHT_CLICK);
gtk_surface1_release(gtk_surface);
return;
} else if (button == BTN_LEFT && state == WL_POINTER_BUTTON_STATE_PRESSED) {
static uint32_t previous_click = 0;
if (previous_click && time - previous_click < 250) { // < 0.25 sec for dble clicks
previous_click = 0;
struct gtk_surface1 *gtk_surface = gtk_shell1_get_gtk_surface(gtk_shell,
frame_gtk->headerbar.wl_surface);
gtk_surface1_titlebar_gesture(gtk_surface, serial,
seat->wl_seat, GTK_SURFACE1_GESTURE_DOUBLE_CLICK);
gtk_surface1_release(gtk_surface);
return;
}
previous_click = time;
}
decor_pointer_button(data, wl_pointer, serial, time, button, state);
}
struct wl_object { // copied from wayland-private.h
const struct wl_interface *interface;
const void *implementation;
uint32_t id;
};
#endif // HAVE_GTK && !USE_SYSTEM_LIBDECOR
// replace libdecor's pointer_button by FLTK's
void use_FLTK_pointer_button(struct libdecor_frame *frame) {
#if HAVE_GTK && !USE_SYSTEM_LIBDECOR
static struct wl_pointer_listener *fltk_listener = NULL;
if (!gtk_shell || fltk_listener) return;
struct libdecor_frame_gtk *lfg = (struct libdecor_frame_gtk *)frame;
if (wl_list_empty(&lfg->plugin_gtk->seat_list)) return;
struct seat *seat;
wl_list_for_each(seat, &lfg->plugin_gtk->seat_list, link) {
break;
}
struct wl_object *object = (struct wl_object *)seat->wl_pointer;
if (!object) return;
struct wl_pointer_listener *decor_listener =
(struct wl_pointer_listener*)object->implementation;
fltk_listener =
(struct wl_pointer_listener*)malloc(sizeof(struct wl_pointer_listener));
// initialize FLTK's listener with libdecor's values
*fltk_listener = *decor_listener;
// memorize libdecor's button cb
decor_pointer_button = decor_listener->button;
// replace libdecor's button by FLTK's
fltk_listener->button = fltk_pointer_button;
// replace the pointer listener by a copy whose button member is FLTK's
object->implementation = fltk_listener;
#endif // HAVE_GTK && !USE_SYSTEM_LIBDECOR
}
void bind_to_gtk_shell(struct wl_registry *wl_registry, uint32_t id) {
#if HAVE_GTK && !USE_SYSTEM_LIBDECOR
gtk_shell = (struct gtk_shell1*)wl_registry_bind(wl_registry, id,
&gtk_shell1_interface, 5);
#endif // HAVE_GTK && !USE_SYSTEM_LIBDECOR
}
/* === End of code to add support of GTK Shell to libdecor-gtk === */

View File

@ -0,0 +1,109 @@
<!-- found at: https://gitlab.gnome.org/GNOME/gtk/-/blob/main/gdk/wayland/protocol/gtk-shell.xml -->
<protocol name="gtk">
<interface name="gtk_shell1" version="5">
<description summary="gtk specific extensions">
gtk_shell is a protocol extension providing additional features for
clients implementing it.
</description>
<enum name="capability">
<entry name="global_app_menu" value="1"/>
<entry name="global_menu_bar" value="2"/>
<entry name="desktop_icons" value="3"/>
</enum>
<event name="capabilities">
<arg name="capabilities" type="uint"/>
</event>
<request name="get_gtk_surface">
<arg name="gtk_surface" type="new_id" interface="gtk_surface1"/>
<arg name="surface" type="object" interface="wl_surface"/>
</request>
<request name="set_startup_id">
<arg name="startup_id" type="string" allow-null="true"/>
</request>
<request name="system_bell">
<arg name="surface" type="object" interface="gtk_surface1" allow-null="true"/>
</request>
<!-- Version 3 additions -->
<request name="notify_launch" since="3">
<arg name="startup_id" type="string"/>
</request>
</interface>
<interface name="gtk_surface1" version="5">
<request name="set_dbus_properties">
<arg name="application_id" type="string" allow-null="true"/>
<arg name="app_menu_path" type="string" allow-null="true"/>
<arg name="menubar_path" type="string" allow-null="true"/>
<arg name="window_object_path" type="string" allow-null="true"/>
<arg name="application_object_path" type="string" allow-null="true"/>
<arg name="unique_bus_name" type="string" allow-null="true"/>
</request>
<request name="set_modal"/>
<request name="unset_modal"/>
<request name="present">
<arg name="time" type="uint"/>
</request>
<!-- Version 2 additions -->
<enum name="state">
<entry name="tiled" value="1"/>
<entry name="tiled_top" value="2" since="2" />
<entry name="tiled_right" value="3" since="2" />
<entry name="tiled_bottom" value="4" since="2" />
<entry name="tiled_left" value="5" since="2" />
</enum>
<enum name="edge_constraint" since="2">
<entry name="resizable_top" value="1"/>
<entry name="resizable_right" value="2"/>
<entry name="resizable_bottom" value="3"/>
<entry name="resizable_left" value="4"/>
</enum>
<event name="configure">
<arg name="states" type="array"/>
</event>
<event name="configure_edges" since="2">
<arg name="constraints" type="array"/>
</event>
<!-- Version 3 additions -->
<request name="request_focus" since="3">
<arg name="startup_id" type="string" allow-null="true"/>
</request>
<!-- Version 4 additions -->
<request name="release" type="destructor" since="4"/>
<!-- Version 5 additions -->
<enum name="gesture" since="5">
<entry name="double_click" value="1"/>
<entry name="right_click" value="2"/>
<entry name="middle_click" value="3"/>
</enum>
<enum name="error" since="5">
<entry name="invalid_gesture" value="0"/>
</enum>
<request name="titlebar_gesture" since="5">
<arg name="serial" type="uint"/>
<arg name="seat" type="object" interface="wl_seat"/>
<arg name="gesture" type="uint" enum="gesture"/>
</request>
</interface>
</protocol>

View File

@ -688,6 +688,17 @@ if (UNIX AND OPTION_USE_WAYLAND)
)
list (APPEND STATIC_FILES "xdg-decoration-protocol.c")
list (APPEND SHARED_FILES "xdg-decoration-protocol.c")
if (GTK_FOUND AND OPTION_ALLOW_GTK_PLUGIN)
add_custom_command(
OUTPUT gtk-shell-protocol.c gtk-shell-client-protocol.h
COMMAND wayland-scanner private-code ${CMAKE_CURRENT_SOURCE_DIR}/../libdecor/build/gtk-shell.xml gtk-shell-protocol.c
COMMAND wayland-scanner client-header ${CMAKE_CURRENT_SOURCE_DIR}/../libdecor/build/gtk-shell.xml gtk-shell-client-protocol.h
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/../libdecor/build/gtk-shell.xml
VERBATIM
)
list (APPEND STATIC_FILES "gtk-shell-protocol.c")
list (APPEND SHARED_FILES "gtk-shell-protocol.c")
endif (GTK_FOUND AND OPTION_ALLOW_GTK_PLUGIN)
endif (NOT OPTION_USE_SYSTEM_LIBDECOR)
add_custom_command(
OUTPUT text-input-protocol.c text-input-client-protocol.h

View File

@ -424,6 +424,7 @@ CFILES_WAYLANDX11 = $(WLCFILES)
EXTRA_OBJECTS_WAYLAND = ../libdecor/build/fl_libdecor.o ../libdecor/build/libdecor-cairo-blur.o \
../libdecor/build/fl_libdecor-plugins.o \
xdg-decoration-protocol.o xdg-shell-protocol.o text-input-protocol.o \
gtk-shell-protocol.o \
../libdecor/build/cursor-settings.o ../libdecor/build/os-compatibility.o
EXTRA_OBJECTS_WAYLANDX11 = $(EXTRA_OBJECTS_WAYLAND)
EXTRA_CXXFLAGS_WAYLAND = -I.

View File

@ -46,6 +46,7 @@
#include <string.h> // for strerror()
extern "C" {
bool libdecor_get_cursor_settings(char **theme, int *size);
void bind_to_gtk_shell(struct wl_registry *, uint32_t);
}
@ -1146,6 +1147,9 @@ static void registry_handle_global(void *user_data, struct wl_registry *wl_regis
} else if (strcmp(interface, "gtk_shell1") == 0) {
Fl_Wayland_Screen_Driver::compositor = Fl_Wayland_Screen_Driver::MUTTER;
//fprintf(stderr, "Running the Mutter compositor\n");
if ( version >= 5) {
bind_to_gtk_shell(wl_registry, id);
}
} else if (strcmp(interface, "weston_desktop_shell") == 0) {
Fl_Wayland_Screen_Driver::compositor = Fl_Wayland_Screen_Driver::WESTON;
//fprintf(stderr, "Running the Weston compositor\n");

View File

@ -45,6 +45,7 @@ struct cursor_image { // as in wayland-cursor.c of the Wayland project source co
extern "C" {
# include "../../../libdecor/src/libdecor-plugin.h"
uchar *fl_libdecor_titlebar_buffer(struct libdecor_frame *frame, int *w, int *h, int *stride);
void use_FLTK_pointer_button(struct libdecor_frame *);
}
#define fl_max(a,b) ((a) > (b) ? (a) : (b))
@ -853,7 +854,7 @@ static void handle_configure(struct libdecor_frame *frame,
#ifdef LIBDECOR_MR131
if (is_1st_run) use_FLTK_toplevel_configure_cb(frame);
#endif
use_FLTK_pointer_button(frame);
struct wl_output *wl_output = NULL;
if (window->fl_win->fullscreen_active()) {
if (!(window->state & LIBDECOR_WINDOW_STATE_FULLSCREEN)) {