diff options
| author | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2023-11-09 11:25:39 +0100 |
|---|---|---|
| committer | ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> | 2023-11-12 19:13:35 +0100 |
| commit | 888dc5f5c5456d2721f87f01dd1b10d47c6f439e (patch) | |
| tree | 95078c6b836c201eb4c525ea6c6da66fcc1ae0f1 /libdecor/build | |
| parent | 768dcf2c11146d47f8a79a3d020e2cc0aa91c05b (diff) | |
Have libdecor-gtk implement the "GTK Shell" protocol
Diffstat (limited to 'libdecor/build')
| -rw-r--r-- | libdecor/build/Makefile | 12 | ||||
| -rw-r--r-- | libdecor/build/fl_libdecor-plugins.c | 115 | ||||
| -rw-r--r-- | libdecor/build/gtk-shell.xml | 109 |
3 files changed, 232 insertions, 4 deletions
diff --git a/libdecor/build/Makefile b/libdecor/build/Makefile index 25116f4c0..946ec6318 100644 --- a/libdecor/build/Makefile +++ b/libdecor/build/Makefile @@ -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-* diff --git a/libdecor/build/fl_libdecor-plugins.c b/libdecor/build/fl_libdecor-plugins.c index 701ba7abb..e25f79285 100644 --- a/libdecor/build/fl_libdecor-plugins.c +++ b/libdecor/build/fl_libdecor-plugins.c @@ -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, + >k_shell1_interface, 5); +#endif // HAVE_GTK && !USE_SYSTEM_LIBDECOR +} + +/* === End of code to add support of GTK Shell to libdecor-gtk === */ diff --git a/libdecor/build/gtk-shell.xml b/libdecor/build/gtk-shell.xml new file mode 100644 index 000000000..f00684679 --- /dev/null +++ b/libdecor/build/gtk-shell.xml @@ -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> + |
