2026-03-19 11:03:29 -06:00
|
|
|
/* ZoiteChat
|
|
|
|
|
* Copyright (C) 1998-2010 Peter Zelezny.
|
|
|
|
|
* Copyright (C) 2009-2013 Berke Viktor.
|
|
|
|
|
* Copyright (C) 2026 deepend-tildeclub.
|
|
|
|
|
*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
|
*/
|
|
|
|
|
|
2026-03-02 19:42:48 -07:00
|
|
|
#include "theme-application.h"
|
|
|
|
|
|
|
|
|
|
#include "../../common/fe.h"
|
|
|
|
|
#include "../../common/zoitechatc.h"
|
|
|
|
|
#include "theme-css.h"
|
|
|
|
|
#include "theme-runtime.h"
|
2026-03-04 23:28:01 -07:00
|
|
|
#include "theme-gtk3.h"
|
2026-03-02 19:42:48 -07:00
|
|
|
#include "../maingui.h"
|
|
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
|
2026-03-22 10:00:27 -06:00
|
|
|
#if defined(__GNUC__) || defined(__clang__)
|
|
|
|
|
extern char *theme_css_build_toplevel_classes (void) __attribute__ ((weak));
|
|
|
|
|
#else
|
|
|
|
|
extern char *theme_css_build_toplevel_classes (void);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
static char *
|
|
|
|
|
theme_application_build_toplevel_css (void)
|
|
|
|
|
{
|
|
|
|
|
if (theme_css_build_toplevel_classes)
|
|
|
|
|
return theme_css_build_toplevel_classes ();
|
|
|
|
|
|
|
|
|
|
return g_strdup ("");
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-02 19:42:48 -07:00
|
|
|
static void
|
2026-03-22 10:00:27 -06:00
|
|
|
theme_application_apply_toplevel_theme (gboolean dark)
|
2026-03-02 19:42:48 -07:00
|
|
|
{
|
|
|
|
|
GtkSettings *settings = gtk_settings_get_default ();
|
2026-03-22 10:00:27 -06:00
|
|
|
static GtkCssProvider *theme_provider = NULL;
|
|
|
|
|
static gboolean theme_provider_installed = FALSE;
|
2026-03-04 23:28:01 -07:00
|
|
|
GdkScreen *screen;
|
|
|
|
|
gboolean prefer_dark = dark;
|
|
|
|
|
char *css;
|
|
|
|
|
|
|
|
|
|
if (theme_gtk3_is_active ())
|
|
|
|
|
{
|
|
|
|
|
if (prefs.hex_gui_gtk3_variant == THEME_GTK3_VARIANT_PREFER_DARK)
|
|
|
|
|
prefer_dark = TRUE;
|
|
|
|
|
else if (prefs.hex_gui_gtk3_variant == THEME_GTK3_VARIANT_PREFER_LIGHT)
|
|
|
|
|
prefer_dark = FALSE;
|
|
|
|
|
}
|
2026-03-02 19:42:48 -07:00
|
|
|
|
|
|
|
|
if (settings && g_object_class_find_property (G_OBJECT_GET_CLASS (settings),
|
|
|
|
|
"gtk-application-prefer-dark-theme"))
|
2026-03-04 23:28:01 -07:00
|
|
|
g_object_set (settings, "gtk-application-prefer-dark-theme", prefer_dark, NULL);
|
|
|
|
|
|
|
|
|
|
screen = gdk_screen_get_default ();
|
|
|
|
|
if (!screen)
|
|
|
|
|
return;
|
|
|
|
|
|
2026-03-22 10:00:27 -06:00
|
|
|
if (!theme_provider)
|
|
|
|
|
theme_provider = gtk_css_provider_new ();
|
2026-03-02 19:42:48 -07:00
|
|
|
|
2026-03-22 10:00:27 -06:00
|
|
|
css = theme_application_build_toplevel_css ();
|
|
|
|
|
gtk_css_provider_load_from_data (theme_provider, css, -1, NULL);
|
2026-03-04 23:28:01 -07:00
|
|
|
g_free (css);
|
2026-03-02 19:42:48 -07:00
|
|
|
|
2026-03-22 10:00:27 -06:00
|
|
|
if (!theme_provider_installed)
|
2026-03-04 23:28:01 -07:00
|
|
|
{
|
|
|
|
|
gtk_style_context_add_provider_for_screen (screen,
|
2026-03-22 10:00:27 -06:00
|
|
|
GTK_STYLE_PROVIDER (theme_provider),
|
2026-03-04 23:28:01 -07:00
|
|
|
GTK_STYLE_PROVIDER_PRIORITY_APPLICATION + 1);
|
2026-03-22 10:00:27 -06:00
|
|
|
theme_provider_installed = TRUE;
|
2026-03-02 19:42:48 -07:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
|
theme_application_apply_mode (unsigned int mode, gboolean *palette_changed)
|
|
|
|
|
{
|
|
|
|
|
gboolean dark;
|
|
|
|
|
|
|
|
|
|
theme_runtime_load ();
|
|
|
|
|
dark = theme_runtime_apply_mode (mode, palette_changed);
|
2026-03-22 10:00:27 -06:00
|
|
|
theme_application_apply_toplevel_theme (dark);
|
2026-03-02 19:42:48 -07:00
|
|
|
|
|
|
|
|
theme_application_reload_input_style ();
|
|
|
|
|
|
|
|
|
|
return dark;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
theme_application_reload_input_style (void)
|
|
|
|
|
{
|
|
|
|
|
input_style = theme_application_update_input_style (input_style);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
InputStyle *
|
|
|
|
|
theme_application_update_input_style (InputStyle *style)
|
|
|
|
|
{
|
|
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
|
|
if (!style)
|
|
|
|
|
style = g_new0 (InputStyle, 1);
|
|
|
|
|
|
|
|
|
|
if (style->font_desc)
|
|
|
|
|
pango_font_description_free (style->font_desc);
|
|
|
|
|
style->font_desc = pango_font_description_from_string (prefs.hex_text_font);
|
|
|
|
|
|
|
|
|
|
if (pango_font_description_get_size (style->font_desc) == 0)
|
|
|
|
|
{
|
|
|
|
|
g_snprintf (buf, sizeof (buf), _("Failed to open font:\n\n%s"), prefs.hex_text_font);
|
|
|
|
|
fe_message (buf, FE_MSG_ERROR);
|
|
|
|
|
pango_font_description_free (style->font_desc);
|
|
|
|
|
style->font_desc = pango_font_description_from_string ("sans 11");
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-04 23:28:01 -07:00
|
|
|
theme_css_reload_input_style (FALSE, style->font_desc);
|
2026-03-02 19:42:48 -07:00
|
|
|
|
|
|
|
|
return style;
|
|
|
|
|
}
|