7 Commits

Author SHA1 Message Date
deepend-tildeclub
8a1e82986a Merge pull request #197 from ZoiteChat/pevents_import_from_hct
Import pevents from .hct too, show clearer result dialog
2026-04-09 13:23:17 -06:00
deepend-tildeclub
e8d421b3df Merge pull request #196 from ZoiteChat/topic_bar_height
Auto-size topic bar to wrapped text
2026-04-09 13:23:03 -06:00
cb2c09b2ba Import pevents from .hct too, show clearer result dialog 2026-04-09 12:30:23 -06:00
a14026f0d1 Add vertical padding to topic text view 2026-04-09 10:56:39 -06:00
e237df31f4 Auto-size topic bar to wrapped text 2026-04-09 10:03:59 -06:00
deepend-tildeclub
a9421c63a9 Merge pull request #195 from ZoiteChat/hct_import_support
Add .hct support to colors.conf import
2026-04-09 08:55:48 -06:00
4f2938d957 Add .hct support to colors.conf import 2026-04-08 17:47:51 -06:00
5 changed files with 308 additions and 33 deletions

View File

@@ -1221,6 +1221,94 @@ extract_archive (const char *source, GError **error)
#endif #endif
} }
static char *
path_find_first_file_recursive (const char *root, const char *name, int depth)
{
GDir *dir;
const char *entry;
if (!root || !name || depth < 0 || !g_file_test (root, G_FILE_TEST_IS_DIR))
return NULL;
{
char *candidate = g_build_filename (root, name, NULL);
if (g_file_test (candidate, G_FILE_TEST_IS_REGULAR))
return candidate;
g_free (candidate);
}
if (depth == 0)
return NULL;
dir = g_dir_open (root, 0, NULL);
if (!dir)
return NULL;
while ((entry = g_dir_read_name (dir)) != NULL)
{
char *child = g_build_filename (root, entry, NULL);
char *found = NULL;
if (g_file_test (child, G_FILE_TEST_IS_DIR))
found = path_find_first_file_recursive (child, name, depth - 1);
g_free (child);
if (found)
{
g_dir_close (dir);
return found;
}
}
g_dir_close (dir);
return NULL;
}
gboolean
zoitechat_gtk3_theme_service_read_archive_text_file (const char *archive_path, const char *name, char **contents, GError **error)
{
char *root;
char *path;
gboolean ok;
GError *local_error = NULL;
if (contents)
*contents = NULL;
if (!archive_path || !*archive_path)
return g_set_error_literal (error, G_FILE_ERROR, G_FILE_ERROR_INVAL, "No archive path provided."), FALSE;
if (!name || !*name)
return g_set_error_literal (error, G_FILE_ERROR, G_FILE_ERROR_INVAL, "No file name provided."), FALSE;
if (!contents)
return g_set_error_literal (error, G_FILE_ERROR, G_FILE_ERROR_INVAL, "No output buffer provided."), FALSE;
root = extract_archive (archive_path, error);
if (!root)
return FALSE;
path = path_find_first_file_recursive (root, name, 8);
if (!path)
{
remove_tree (root);
g_free (root);
return g_set_error_literal (error, G_FILE_ERROR, G_FILE_ERROR_NOENT, "Requested file was not found in archive."), FALSE;
}
ok = g_file_get_contents (path, contents, NULL, &local_error);
g_free (path);
remove_tree (root);
g_free (root);
if (!ok)
{
if (error)
*error = local_error;
else
g_clear_error (&local_error);
return FALSE;
}
return TRUE;
}
gboolean gboolean
zoitechat_gtk3_theme_service_import (const char *source_path, char **imported_id, GError **error) zoitechat_gtk3_theme_service_import (const char *source_path, char **imported_id, GError **error)
{ {

View File

@@ -48,5 +48,6 @@ gboolean zoitechat_gtk3_theme_service_remove_user_theme (const char *theme_id, G
char *zoitechat_gtk3_theme_pick_css_dir_for_minor (const char *theme_root, int preferred_minor); char *zoitechat_gtk3_theme_pick_css_dir_for_minor (const char *theme_root, int preferred_minor);
char *zoitechat_gtk3_theme_pick_css_dir (const char *theme_root); char *zoitechat_gtk3_theme_pick_css_dir (const char *theme_root);
GPtrArray *zoitechat_gtk3_theme_build_inheritance_chain (const char *theme_root); GPtrArray *zoitechat_gtk3_theme_build_inheritance_chain (const char *theme_root);
gboolean zoitechat_gtk3_theme_service_read_archive_text_file (const char *archive_path, const char *name, char **contents, GError **error);
#endif #endif

View File

@@ -862,12 +862,34 @@ fe_set_title (session *sess)
gtk_window_set_title (GTK_WINDOW (sess->gui->window), tbuf); gtk_window_set_title (GTK_WINDOW (sess->gui->window), tbuf);
} }
static void
mg_topicbar_update_height (GtkWidget *topic);
static session *
mg_session_from_window (GtkWidget *wid)
{
GSList *list;
session *sess;
list = sess_list;
while (list)
{
sess = list->data;
if (sess && sess->gui && sess->gui->window == wid)
return sess;
list = list->next;
}
return current_sess;
}
static gboolean static gboolean
mg_windowstate_cb (GtkWindow *wid, GdkEventWindowState *event, gpointer userdata) mg_windowstate_cb (GtkWindow *wid, GdkEventWindowState *event, gpointer userdata)
{ {
guint win_state; guint win_state;
guint win_fullscreen; guint win_fullscreen;
gboolean changed = FALSE; gboolean changed = FALSE;
session *sess;
if ((event->changed_mask & GDK_WINDOW_STATE_ICONIFIED) && if ((event->changed_mask & GDK_WINDOW_STATE_ICONIFIED) &&
(event->new_window_state & GDK_WINDOW_STATE_ICONIFIED) && (event->new_window_state & GDK_WINDOW_STATE_ICONIFIED) &&
@@ -903,6 +925,20 @@ mg_windowstate_cb (GtkWindow *wid, GdkEventWindowState *event, gpointer userdata
mg_schedule_config_save (); mg_schedule_config_save ();
} }
sess = mg_session_from_window (GTK_WIDGET (wid));
if (sess && sess->gui && GTK_IS_WIDGET (sess->gui->topic_entry))
{
mg_topicbar_update_height (sess->gui->topic_entry);
gtk_widget_queue_draw (sess->gui->topic_entry);
}
if (sess && sess->gui && GTK_IS_XTEXT (sess->gui->xtext))
{
gtk_xtext_refresh (GTK_XTEXT (sess->gui->xtext));
gtk_widget_queue_draw (sess->gui->xtext);
}
if (sess && sess->gui && GTK_IS_WIDGET (sess->gui->window))
gtk_widget_queue_draw (sess->gui->window);
menu_set_fullscreen (current_sess->gui, prefs.hex_gui_win_fullscreen); menu_set_fullscreen (current_sess->gui, prefs.hex_gui_win_fullscreen);
#ifdef G_OS_WIN32 #ifdef G_OS_WIN32
@@ -916,6 +952,7 @@ static gboolean
mg_configure_cb (GtkWidget *wid, GdkEventConfigure *event, session *sess) mg_configure_cb (GtkWidget *wid, GdkEventConfigure *event, session *sess)
{ {
gboolean changed = FALSE; gboolean changed = FALSE;
session *target_sess;
if (sess == NULL) if (sess == NULL)
{ {
@@ -998,6 +1035,23 @@ mg_configure_cb (GtkWidget *wid, GdkEventConfigure *event, session *sess)
mg_schedule_config_save (); mg_schedule_config_save ();
} }
target_sess = mg_session_from_window (wid);
if (target_sess && target_sess->gui)
{
if (GTK_IS_WIDGET (target_sess->gui->topic_entry))
{
mg_topicbar_update_height (target_sess->gui->topic_entry);
gtk_widget_queue_draw (target_sess->gui->topic_entry);
}
if (GTK_IS_XTEXT (target_sess->gui->xtext))
{
gtk_xtext_refresh (GTK_XTEXT (target_sess->gui->xtext));
gtk_widget_queue_draw (target_sess->gui->xtext);
}
if (GTK_IS_WIDGET (target_sess->gui->window))
gtk_widget_queue_draw (target_sess->gui->window);
}
return FALSE; return FALSE;
} }
@@ -2969,13 +3023,36 @@ mg_create_dialogbuttons (GtkWidget *box)
} }
static void static void
mg_configure_topic_scroller (GtkWidget *scroller, GtkWidget *topic) mg_topicbar_update_height (GtkWidget *topic)
{ {
GtkWidget *scroller;
GtkTextBuffer *buffer;
GtkTextIter start;
GtkTextIter end;
PangoLayout *layout;
char *text;
int width;
int line_height;
int line_count;
int target_height;
PangoContext *context; PangoContext *context;
PangoFontMetrics *metrics; PangoFontMetrics *metrics;
int line_height;
int min_height; if (!topic || !GTK_IS_TEXT_VIEW (topic))
int max_height; return;
scroller = gtk_widget_get_parent (topic);
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (topic));
gtk_text_buffer_get_bounds (buffer, &start, &end);
text = gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
layout = gtk_widget_create_pango_layout (topic, text && text[0] ? text : " ");
g_free (text);
width = gtk_widget_get_allocated_width (topic) - 8;
if (width > 0)
pango_layout_set_width (layout, width * PANGO_SCALE);
pango_layout_set_wrap (layout, PANGO_WRAP_WORD_CHAR);
context = gtk_widget_get_pango_context (topic); context = gtk_widget_get_pango_context (topic);
metrics = pango_context_get_metrics (context, metrics = pango_context_get_metrics (context,
@@ -2984,26 +3061,52 @@ mg_configure_topic_scroller (GtkWidget *scroller, GtkWidget *topic)
line_height = PANGO_PIXELS (pango_font_metrics_get_ascent (metrics) + line_height = PANGO_PIXELS (pango_font_metrics_get_ascent (metrics) +
pango_font_metrics_get_descent (metrics)); pango_font_metrics_get_descent (metrics));
pango_font_metrics_unref (metrics); pango_font_metrics_unref (metrics);
if (line_height <= 0) if (line_height <= 0)
line_height = 16; line_height = 16;
line_count = pango_layout_get_line_count (layout);
if (line_count <= 0)
line_count = 1;
target_height = line_height * line_count;
if (target_height < line_height)
target_height = line_height;
min_height = line_height + 8; gtk_widget_set_size_request (topic, -1, target_height);
max_height = line_height * 4 + 8; if (scroller && GTK_IS_SCROLLED_WINDOW (scroller))
{
gtk_scrolled_window_set_max_content_height (GTK_SCROLLED_WINDOW (scroller), -1);
gtk_scrolled_window_set_min_content_height (GTK_SCROLLED_WINDOW (scroller), -1);
gtk_scrolled_window_set_max_content_height (GTK_SCROLLED_WINDOW (scroller), target_height);
gtk_scrolled_window_set_min_content_height (GTK_SCROLLED_WINDOW (scroller), target_height);
gtk_widget_set_size_request (scroller, -1, target_height);
gtk_widget_queue_resize (scroller);
}
else
{
gtk_widget_queue_resize (topic);
}
gtk_widget_queue_draw (topic);
g_object_unref (layout);
}
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroller), static void
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); mg_topicbar_buffer_changed_cb (GtkTextBuffer *buffer, gpointer userdata)
gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scroller), GTK_SHADOW_NONE); {
gtk_scrolled_window_set_propagate_natural_height (GTK_SCROLLED_WINDOW (scroller), TRUE); (void) buffer;
gtk_scrolled_window_set_min_content_height (GTK_SCROLLED_WINDOW (scroller), min_height); mg_topicbar_update_height (GTK_WIDGET (userdata));
gtk_scrolled_window_set_max_content_height (GTK_SCROLLED_WINDOW (scroller), max_height); }
static void
mg_topicbar_size_allocate_cb (GtkWidget *widget, GtkAllocation *allocation, gpointer userdata)
{
(void) allocation;
(void) userdata;
mg_topicbar_update_height (widget);
} }
void void
mg_apply_session_font_prefs (session_gui *gui) mg_apply_session_font_prefs (session_gui *gui)
{ {
const PangoFontDescription *font = NULL; const PangoFontDescription *font = NULL;
GtkWidget *topic_scroller;
if (!gui) if (!gui)
return; return;
@@ -3014,9 +3117,7 @@ mg_apply_session_font_prefs (session_gui *gui)
if (gui->topic_entry) if (gui->topic_entry)
{ {
theme_manager_apply_entry_palette (gui->topic_entry, font); theme_manager_apply_entry_palette (gui->topic_entry, font);
topic_scroller = gtk_widget_get_parent (gui->topic_entry); mg_topicbar_update_height (gui->topic_entry);
if (topic_scroller && GTK_IS_SCROLLED_WINDOW (topic_scroller))
mg_configure_topic_scroller (topic_scroller, gui->topic_entry);
} }
if (gui->input_box && prefs.hex_gui_input_style) if (gui->input_box && prefs.hex_gui_input_style)
@@ -3034,7 +3135,7 @@ mg_apply_session_font_prefs (session_gui *gui)
static void static void
mg_create_topicbar (session *sess, GtkWidget *box) mg_create_topicbar (session *sess, GtkWidget *box)
{ {
GtkWidget *vbox, *hbox, *mode_hbox, *topic, *bbox, *topic_scroller; GtkWidget *vbox, *hbox, *mode_hbox, *topic, *bbox;
session_gui *gui = sess->gui; session_gui *gui = sess->gui;
gui->topic_bar = vbox = mg_box_new (GTK_ORIENTATION_VERTICAL, FALSE, 0); gui->topic_bar = vbox = mg_box_new (GTK_ORIENTATION_VERTICAL, FALSE, 0);
@@ -3048,14 +3149,21 @@ mg_create_topicbar (session *sess, GtkWidget *box)
gui->topic_entry = topic = gtk_text_view_new (); gui->topic_entry = topic = gtk_text_view_new ();
gtk_widget_set_name (topic, "zoitechat-topicbox"); gtk_widget_set_name (topic, "zoitechat-topicbox");
gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (topic), GTK_WRAP_WORD); gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (topic), GTK_WRAP_WORD_CHAR);
gtk_text_view_set_left_margin (GTK_TEXT_VIEW (topic), 4); gtk_text_view_set_left_margin (GTK_TEXT_VIEW (topic), 4);
gtk_text_view_set_right_margin (GTK_TEXT_VIEW (topic), 4); gtk_text_view_set_right_margin (GTK_TEXT_VIEW (topic), 4);
topic_scroller = gtk_scrolled_window_new (NULL, NULL); gtk_text_view_set_top_margin (GTK_TEXT_VIEW (topic), 4);
gtk_container_add (GTK_CONTAINER (topic_scroller), topic); gtk_text_view_set_bottom_margin (GTK_TEXT_VIEW (topic), 4);
gtk_text_view_set_pixels_above_lines (GTK_TEXT_VIEW (topic), 0);
gtk_text_view_set_pixels_below_lines (GTK_TEXT_VIEW (topic), 0);
gtk_text_view_set_pixels_inside_wrap (GTK_TEXT_VIEW (topic), 0);
theme_manager_apply_entry_palette (topic, input_style ? input_style->font_desc : NULL); theme_manager_apply_entry_palette (topic, input_style ? input_style->font_desc : NULL);
mg_configure_topic_scroller (topic_scroller, topic); g_signal_connect (gtk_text_view_get_buffer (GTK_TEXT_VIEW (topic)), "changed",
gtk_box_pack_start (GTK_BOX (hbox), topic_scroller, TRUE, TRUE, 0); G_CALLBACK (mg_topicbar_buffer_changed_cb), topic);
g_signal_connect (G_OBJECT (topic), "size-allocate",
G_CALLBACK (mg_topicbar_size_allocate_cb), NULL);
mg_topicbar_update_height (topic);
gtk_box_pack_start (GTK_BOX (hbox), topic, TRUE, TRUE, 0);
gtk_widget_add_events (topic, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | gtk_widget_add_events (topic, GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
GDK_POINTER_MOTION_MASK | GDK_LEAVE_NOTIFY_MASK); GDK_POINTER_MOTION_MASK | GDK_LEAVE_NOTIFY_MASK);
g_signal_connect (G_OBJECT (topic), "key-press-event", g_signal_connect (G_OBJECT (topic), "key-press-event",

View File

@@ -188,6 +188,16 @@ zoitechat_gtk3_theme_service_import (const char *source_path, char **imported_id
return FALSE; return FALSE;
} }
gboolean
zoitechat_gtk3_theme_service_read_archive_text_file (const char *archive_path, const char *name, char **contents, GError **error)
{
(void)archive_path;
(void)name;
(void)contents;
(void)error;
return FALSE;
}
gboolean gboolean
zoitechat_gtk3_theme_service_remove_user_theme (const char *theme_id, GError **error) zoitechat_gtk3_theme_service_remove_user_theme (const char *theme_id, GError **error)
{ {

View File

@@ -29,12 +29,15 @@
#include "../gtkutil.h" #include "../gtkutil.h"
#include "../../common/fe.h" #include "../../common/fe.h"
#include "../../common/cfgfiles.h"
#include "../../common/util.h" #include "../../common/util.h"
#include "../../common/gtk3-theme-service.h" #include "../../common/gtk3-theme-service.h"
#include "theme-gtk3.h" #include "theme-gtk3.h"
#include "theme-manager.h" #include "theme-manager.h"
#include "theme-preferences.h" #include "theme-preferences.h"
extern void load_text_events (void);
typedef struct typedef struct
{ {
GtkWindow *parent; GtkWindow *parent;
@@ -932,6 +935,21 @@ theme_preferences_show_import_error (GtkWidget *button, const char *message)
gtk_widget_destroy (dialog); gtk_widget_destroy (dialog);
} }
static void
theme_preferences_show_import_info (GtkWidget *button, const char *message)
{
GtkWidget *dialog;
dialog = gtk_message_dialog_new (GTK_WINDOW (gtk_widget_get_toplevel (button)),
GTK_DIALOG_MODAL,
GTK_MESSAGE_INFO,
GTK_BUTTONS_CLOSE,
"%s",
message);
gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
}
static gboolean static gboolean
theme_preferences_parse_cfg_color (const char *cfg, theme_preferences_parse_cfg_color (const char *cfg,
const char *key, const char *key,
@@ -1038,40 +1056,77 @@ static void
theme_preferences_import_colors_conf_cb (GtkWidget *button, gpointer user_data) theme_preferences_import_colors_conf_cb (GtkWidget *button, gpointer user_data)
{ {
gboolean *color_change_flag = user_data; gboolean *color_change_flag = user_data;
GtkWidget *dialog; GtkFileChooserNative *dialog;
char *path; char *path;
char *lower_path;
char *cfg; char *cfg;
char *pevents_cfg = NULL;
GError *error = NULL; GError *error = NULL;
gboolean any_imported = FALSE; gboolean any_imported = FALSE;
gboolean imported_from_hct = FALSE;
gboolean imported_pevents = FALSE;
ThemeSemanticToken token; ThemeSemanticToken token;
GtkFileFilter *filter;
dialog = gtk_file_chooser_dialog_new (_("Import colors.conf colors"), dialog = gtk_file_chooser_native_new (_("Import colors.conf colors"),
GTK_WINDOW (gtk_widget_get_toplevel (button)), GTK_WINDOW (gtk_widget_get_toplevel (button)),
GTK_FILE_CHOOSER_ACTION_OPEN, GTK_FILE_CHOOSER_ACTION_OPEN,
_("_Cancel"), GTK_RESPONSE_CANCEL, _("_Import"),
_("_Import"), GTK_RESPONSE_ACCEPT, _("_Cancel"));
NULL);
gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog), TRUE);
gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), FALSE); gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (dialog), FALSE);
filter = gtk_file_filter_new ();
gtk_file_filter_set_name (filter, _("Theme colors (*.conf, *.hct)"));
gtk_file_filter_add_pattern (filter, "*.conf");
gtk_file_filter_add_pattern (filter, "*.hct");
gtk_file_filter_add_pattern (filter, "*.HCT");
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_ACCEPT) if (gtk_native_dialog_run (GTK_NATIVE_DIALOG (dialog)) != GTK_RESPONSE_ACCEPT)
{ {
gtk_widget_destroy (dialog); g_object_unref (dialog);
return; return;
} }
path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); path = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
gtk_widget_destroy (dialog); g_object_unref (dialog);
if (!path) if (!path)
return; return;
if (!g_file_get_contents (path, &cfg, NULL, &error)) lower_path = g_ascii_strdown (path, -1);
if (g_str_has_suffix (lower_path, ".hct"))
{ {
theme_preferences_show_import_error (button, _("Failed to read colors.conf file.")); imported_from_hct = TRUE;
if (!zoitechat_gtk3_theme_service_read_archive_text_file (path, "colors.conf", &cfg, &error))
{
theme_preferences_show_import_error (button, _("Failed to read colors.conf from .hct file."));
g_clear_error (&error); g_clear_error (&error);
g_free (lower_path);
g_free (path); g_free (path);
return; return;
} }
if (zoitechat_gtk3_theme_service_read_archive_text_file (path, "pevents.conf", &pevents_cfg, &error))
{
char *pevents_path = g_build_filename (get_xdir (), "pevents.conf", NULL);
if (g_file_set_contents (pevents_path, pevents_cfg, -1, &error))
{
load_text_events ();
imported_pevents = TRUE;
}
g_free (pevents_path);
g_clear_error (&error);
}
else
g_clear_error (&error);
}
else if (!g_file_get_contents (path, &cfg, NULL, &error))
{
theme_preferences_show_import_error (button, _("Failed to read colors.conf file."));
g_clear_error (&error);
g_free (lower_path);
g_free (path);
return;
}
g_free (lower_path);
for (token = THEME_TOKEN_MIRC_0; token < THEME_TOKEN_COUNT; token++) for (token = THEME_TOKEN_MIRC_0; token < THEME_TOKEN_COUNT; token++)
{ {
@@ -1086,9 +1141,22 @@ theme_preferences_import_colors_conf_cb (GtkWidget *button, gpointer user_data)
if (!any_imported) if (!any_imported)
theme_preferences_show_import_error (button, _("No importable colors were found in that colors.conf file.")); theme_preferences_show_import_error (button, _("No importable colors were found in that colors.conf file."));
else if (imported_from_hct)
{
char *message = g_strdup_printf (imported_pevents ?
_("Imported colors.conf and pevents.conf from %s.") :
_("Imported colors.conf from %s."),
path);
theme_preferences_show_import_info (button, message);
g_free (message);
}
else if (color_change_flag) else if (color_change_flag)
*color_change_flag = theme_preferences_stage.active ? theme_preferences_stage.changed : *color_change_flag; *color_change_flag = theme_preferences_stage.active ? theme_preferences_stage.changed : *color_change_flag;
if (any_imported && color_change_flag)
*color_change_flag = theme_preferences_stage.active ? theme_preferences_stage.changed : *color_change_flag;
g_free (pevents_cfg);
g_free (cfg); g_free (cfg);
g_free (path); g_free (path);
} }