From 5365aefc6e8e244c7fa8dd8be5c9b035c45ef7af Mon Sep 17 00:00:00 2001 From: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> Date: Sat, 1 Jun 2024 07:56:48 +0200 Subject: libdecor: update to upstream commit c2bd8ad6 (31-may-2024) --- libdecor/build/Makefile | 6 +- libdecor/src/cursor-settings.c | 173 ---------------------- libdecor/src/cursor-settings.h | 31 ---- libdecor/src/desktop-settings.c | 213 ++++++++++++++++++++++++++++ libdecor/src/desktop-settings.h | 41 ++++++ libdecor/src/plugins/cairo/libdecor-cairo.c | 2 +- libdecor/src/plugins/gtk/libdecor-gtk.c | 33 +++-- 7 files changed, 279 insertions(+), 220 deletions(-) delete mode 100644 libdecor/src/cursor-settings.c delete mode 100644 libdecor/src/cursor-settings.h create mode 100644 libdecor/src/desktop-settings.c create mode 100644 libdecor/src/desktop-settings.h (limited to 'libdecor') diff --git a/libdecor/build/Makefile b/libdecor/build/Makefile index 19cdbb8da..65952ca06 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 ../../src/gtk-shell-protocol.o cursor-settings.o os-compatibility.o + ../../src/text-input-protocol.o ../../src/gtk-shell-protocol.o desktop-settings.o os-compatibility.o PROTOCOLS = `pkg-config --variable=pkgdatadir wayland-protocols` @@ -46,8 +46,8 @@ libdecor-cairo-blur.o : ../src/plugins/common/libdecor-cairo-blur.c os-compatibility.o : ../src/os-compatibility.c $(CC) $(CFLAGS_DECOR) -c ../src/os-compatibility.c -cursor-settings.o : ../src/cursor-settings.c - $(CC) $(CFLAGS_DECOR) -c ../src/cursor-settings.c $(LIBDECORDBUS) +desktop-settings.o : ../src/desktop-settings.c + $(CC) $(CFLAGS_DECOR) -c ../src/desktop-settings.c $(LIBDECORDBUS) ../../src/xdg-shell-protocol.c : wayland-scanner private-code $(PROTOCOLS)/stable/xdg-shell/xdg-shell.xml \ diff --git a/libdecor/src/cursor-settings.c b/libdecor/src/cursor-settings.c deleted file mode 100644 index 75c42d194..000000000 --- a/libdecor/src/cursor-settings.c +++ /dev/null @@ -1,173 +0,0 @@ -/* - * Copyright © 2019 Christian Rauch - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#include "cursor-settings.h" -#include -#include -#include -#include "config.h" - -static bool -get_cursor_settings_from_env(char **theme, int *size) -{ - char *env_xtheme; - char *env_xsize; - - env_xtheme = getenv("XCURSOR_THEME"); - if (env_xtheme != NULL) - *theme = strdup(env_xtheme); - - env_xsize = getenv("XCURSOR_SIZE"); - if (env_xsize != NULL) - *size = atoi(env_xsize); - - return env_xtheme != NULL && env_xsize != NULL; -} - -#ifdef HAS_DBUS -#include - -static DBusMessage * -get_setting_sync(DBusConnection *const connection, - const char *key, - const char *value) -{ - DBusError error; - dbus_bool_t success; - DBusMessage *message; - DBusMessage *reply; - - message = dbus_message_new_method_call( - "org.freedesktop.portal.Desktop", - "/org/freedesktop/portal/desktop", - "org.freedesktop.portal.Settings", - "Read"); - - success = dbus_message_append_args(message, - DBUS_TYPE_STRING, &key, - DBUS_TYPE_STRING, &value, - DBUS_TYPE_INVALID); - - if (!success) - return NULL; - - dbus_error_init(&error); - - reply = dbus_connection_send_with_reply_and_block( - connection, - message, - DBUS_TIMEOUT_USE_DEFAULT, - &error); - - dbus_message_unref(message); - - if (dbus_error_is_set(&error)) { - dbus_error_free(&error); - return NULL; - } - - dbus_error_free(&error); - return reply; -} - -static bool -parse_type(DBusMessage *const reply, - const int type, - void *value) -{ - DBusMessageIter iter[3]; - - dbus_message_iter_init(reply, &iter[0]); - if (dbus_message_iter_get_arg_type(&iter[0]) != DBUS_TYPE_VARIANT) - return false; - - dbus_message_iter_recurse(&iter[0], &iter[1]); - if (dbus_message_iter_get_arg_type(&iter[1]) != DBUS_TYPE_VARIANT) - return false; - - dbus_message_iter_recurse(&iter[1], &iter[2]); - if (dbus_message_iter_get_arg_type(&iter[2]) != type) - return false; - - dbus_message_iter_get_basic(&iter[2], value); - - return true; -} - -bool -libdecor_get_cursor_settings(char **theme, int *size) -{ - static const char name[] = "org.gnome.desktop.interface"; - static const char key_theme[] = "cursor-theme"; - static const char key_size[] = "cursor-size"; - - DBusError error; - DBusConnection *connection; - DBusMessage *reply; - const char *value_theme = NULL; - - dbus_error_init(&error); - - connection = dbus_bus_get(DBUS_BUS_SESSION, &error); - - if (dbus_error_is_set(&error)) - goto fallback; - - reply = get_setting_sync(connection, name, key_theme); - if (!reply) - goto fallback; - - if (!parse_type(reply, DBUS_TYPE_STRING, &value_theme)) { - dbus_message_unref(reply); - goto fallback; - } - - *theme = strdup(value_theme); - - dbus_message_unref(reply); - - reply = get_setting_sync(connection, name, key_size); - if (!reply) - goto fallback; - - if (!parse_type(reply, DBUS_TYPE_INT32, size)) { - dbus_message_unref(reply); - goto fallback; - } - - dbus_message_unref(reply); - - return true; - -fallback: - return get_cursor_settings_from_env(theme, size); -} -#else -bool -libdecor_get_cursor_settings(char **theme, int *size) -{ - return get_cursor_settings_from_env(theme, size); -} -#endif diff --git a/libdecor/src/cursor-settings.h b/libdecor/src/cursor-settings.h deleted file mode 100644 index 0cc1cb6bf..000000000 --- a/libdecor/src/cursor-settings.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright © 2019 Christian Rauch - * - * Permission is hereby granted, free of charge, to any person obtaining - * a copy of this software and associated documentation files (the - * "Software"), to deal in the Software without restriction, including - * without limitation the rights to use, copy, modify, merge, publish, - * distribute, sublicense, and/or sell copies of the Software, and to - * permit persons to whom the Software is furnished to do so, subject to - * the following conditions: - * - * The above copyright notice and this permission notice (including the - * next paragraph) shall be included in all copies or substantial - * portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS - * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN - * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN - * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -#pragma once - -#include - -bool -libdecor_get_cursor_settings(char **theme, int *size); diff --git a/libdecor/src/desktop-settings.c b/libdecor/src/desktop-settings.c new file mode 100644 index 000000000..28067ac3e --- /dev/null +++ b/libdecor/src/desktop-settings.c @@ -0,0 +1,213 @@ +/* + * Copyright © 2019 Christian Rauch + * Copyright © 2024 Colin Kinloch + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "desktop-settings.h" +#include +#include +#include +#include +#include "config.h" + +static bool +get_cursor_settings_from_env(char **theme, int *size) +{ + char *env_xtheme; + char *env_xsize; + + env_xtheme = getenv("XCURSOR_THEME"); + if (env_xtheme != NULL) + *theme = strdup(env_xtheme); + + env_xsize = getenv("XCURSOR_SIZE"); + if (env_xsize != NULL) + *size = atoi(env_xsize); + + return env_xtheme != NULL && env_xsize != NULL; +} + +#ifdef HAS_DBUS +#include + +static DBusMessage * +get_setting_sync(DBusConnection *const connection, + const char *key, + const char *value) +{ + DBusError error; + dbus_bool_t success; + DBusMessage *message; + DBusMessage *reply; + + message = dbus_message_new_method_call( + "org.freedesktop.portal.Desktop", + "/org/freedesktop/portal/desktop", + "org.freedesktop.portal.Settings", + "Read"); + + success = dbus_message_append_args(message, + DBUS_TYPE_STRING, &key, + DBUS_TYPE_STRING, &value, + DBUS_TYPE_INVALID); + + if (!success) + return NULL; + + dbus_error_init(&error); + + reply = dbus_connection_send_with_reply_and_block( + connection, + message, + DBUS_TIMEOUT_USE_DEFAULT, + &error); + + dbus_message_unref(message); + + if (dbus_error_is_set(&error)) { + dbus_error_free(&error); + return NULL; + } + + dbus_error_free(&error); + return reply; +} + +static bool +parse_type(DBusMessage *const reply, + const int type, + void *value) +{ + DBusMessageIter iter[3]; + + dbus_message_iter_init(reply, &iter[0]); + if (dbus_message_iter_get_arg_type(&iter[0]) != DBUS_TYPE_VARIANT) + return false; + + dbus_message_iter_recurse(&iter[0], &iter[1]); + if (dbus_message_iter_get_arg_type(&iter[1]) != DBUS_TYPE_VARIANT) + return false; + + dbus_message_iter_recurse(&iter[1], &iter[2]); + if (dbus_message_iter_get_arg_type(&iter[2]) != type) + return false; + + dbus_message_iter_get_basic(&iter[2], value); + + return true; +} + +bool +libdecor_get_cursor_settings(char **theme, int *size) +{ + static const char name[] = "org.gnome.desktop.interface"; + static const char key_theme[] = "cursor-theme"; + static const char key_size[] = "cursor-size"; + + DBusError error; + DBusConnection *connection; + DBusMessage *reply; + const char *value_theme = NULL; + + dbus_error_init(&error); + + connection = dbus_bus_get(DBUS_BUS_SESSION, &error); + + if (dbus_error_is_set(&error)) + goto fallback; + + reply = get_setting_sync(connection, name, key_theme); + if (!reply) + goto fallback; + + if (!parse_type(reply, DBUS_TYPE_STRING, &value_theme)) { + dbus_message_unref(reply); + goto fallback; + } + + *theme = strdup(value_theme); + + dbus_message_unref(reply); + + reply = get_setting_sync(connection, name, key_size); + if (!reply) + goto fallback; + + if (!parse_type(reply, DBUS_TYPE_INT32, size)) { + dbus_message_unref(reply); + goto fallback; + } + + dbus_message_unref(reply); + + return true; + +fallback: + return get_cursor_settings_from_env(theme, size); +} + +enum libdecor_color_scheme +libdecor_get_color_scheme() +{ + static const char name[] = "org.freedesktop.appearance"; + static const char key_color_scheme[] = "color-scheme"; + uint32_t color = 0; + + DBusError error; + DBusConnection *connection; + DBusMessage *reply; + + dbus_error_init(&error); + + connection = dbus_bus_get(DBUS_BUS_SESSION, &error); + + if (dbus_error_is_set(&error)) + return 0; + + reply = get_setting_sync(connection, name, key_color_scheme); + if (!reply) + return 0; + + if (!parse_type(reply, DBUS_TYPE_UINT32, &color)) { + dbus_message_unref(reply); + return 0; + } + + dbus_message_unref(reply); + + return color; +} +#else +bool +libdecor_get_cursor_settings(char **theme, int *size) +{ + return get_cursor_settings_from_env(theme, size); +} + +uint32_t +libdecor_get_color_scheme() +{ + return LIBDECOR_COLOR_SCHEME_DEFAULT; +} +#endif diff --git a/libdecor/src/desktop-settings.h b/libdecor/src/desktop-settings.h new file mode 100644 index 000000000..5747d3168 --- /dev/null +++ b/libdecor/src/desktop-settings.h @@ -0,0 +1,41 @@ +/* + * Copyright © 2019 Christian Rauch + * Copyright © 2024 Colin Kinloch + * + * Permission is hereby granted, free of charge, to any person obtaining + * a copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sublicense, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial + * portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#pragma once + +#include + +enum libdecor_color_scheme { + LIBDECOR_COLOR_SCHEME_DEFAULT, + LIBDECOR_COLOR_SCHEME_PREFER_DARK, + LIBDECOR_COLOR_SCHEME_PREFER_LIGHT, +}; + +bool +libdecor_get_cursor_settings(char **theme, int *size); + +enum libdecor_color_scheme +libdecor_get_color_scheme(); diff --git a/libdecor/src/plugins/cairo/libdecor-cairo.c b/libdecor/src/plugins/cairo/libdecor-cairo.c index 30f6f8720..5978d431d 100644 --- a/libdecor/src/plugins/cairo/libdecor-cairo.c +++ b/libdecor/src/plugins/cairo/libdecor-cairo.c @@ -39,7 +39,7 @@ #include "libdecor-plugin.h" #include "utils.h" -#include "cursor-settings.h" +#include "desktop-settings.h" #include "os-compatibility.h" #include diff --git a/libdecor/src/plugins/gtk/libdecor-gtk.c b/libdecor/src/plugins/gtk/libdecor-gtk.c index de6ec90c6..7ce38ddc6 100644 --- a/libdecor/src/plugins/gtk/libdecor-gtk.c +++ b/libdecor/src/plugins/gtk/libdecor-gtk.c @@ -38,7 +38,7 @@ #include "libdecor-plugin.h" #include "utils.h" -#include "cursor-settings.h" +#include "desktop-settings.h" #include "os-compatibility.h" #include @@ -338,6 +338,8 @@ struct libdecor_plugin_gtk { char *cursor_theme_name; int cursor_size; + uint32_t color_scheme_setting; + int double_click_time_ms; int drag_threshold; }; @@ -2246,16 +2248,16 @@ handle_titlebar_gesture(struct libdecor_frame_gtk *frame_gtk, break; case TITLEBAR_GESTURE_MIDDLE_CLICK: break; - case TITLEBAR_GESTURE_RIGHT_CLICK: { /* FLTK */ - const int title_height = gtk_widget_get_allocated_height(frame_gtk->header); - - libdecor_frame_show_window_menu(&frame_gtk->frame, - seat->wl_seat, - serial, - seat->pointer_x, - seat->pointer_y - -title_height); - } /* FLTK */ + case TITLEBAR_GESTURE_RIGHT_CLICK: + { + const int title_height = gtk_widget_get_allocated_height(frame_gtk->header); + libdecor_frame_show_window_menu(&frame_gtk->frame, + seat->wl_seat, + serial, + seat->pointer_x, + seat->pointer_y + -title_height); + } break; } } @@ -2410,7 +2412,7 @@ pointer_button(void *data, handle_button_on_header (frame_gtk, seat, serial, time, button, state); break; default: - break; /* FLTK */ + break; } } @@ -2930,6 +2932,8 @@ libdecor_plugin_new(struct libdecor *context) plugin_gtk->cursor_size = 24; } + plugin_gtk->color_scheme_setting = libdecor_get_color_scheme(); + wl_display = libdecor_get_wl_display(context); plugin_gtk->wl_registry = wl_display_get_registry(wl_display); wl_registry_add_listener(plugin_gtk->wl_registry, @@ -2958,6 +2962,11 @@ libdecor_plugin_new(struct libdecor *context) return NULL; } + g_object_set(gtk_settings_get_default(), + "gtk-application-prefer-dark-theme", + plugin_gtk->color_scheme_setting == LIBDECOR_COLOR_SCHEME_PREFER_DARK, + NULL); + return &plugin_gtk->plugin; } -- cgit v1.2.3