fix: Meson libperl parse cleanup; tighten topic URL hit-testing so only actual links click

This commit is contained in:
2026-03-16 19:10:49 -06:00
parent 81dcdbe648
commit 0ab7eb7207
2 changed files with 46 additions and 7 deletions

View File

@@ -45,6 +45,22 @@ endif
perl_ldflags = [] perl_ldflags = []
perl_rpath = '' perl_rpath = ''
foreach flag : ret.stdout().strip().split(' ') foreach flag : ret.stdout().strip().split(' ')
if flag.startswith('/') and '/libperl.' in flag
split = flag.split('/')
libperl_dir = ''
foreach part : split
if part != '' and not part.startswith('libperl.')
if libperl_dir == ''
libperl_dir = '/' + part
else
libperl_dir += '/' + part
endif
endif
endforeach
perl_ldflags += '-L' + libperl_dir
perl_ldflags += '-lperl'
continue
endif
if flag.startswith('-L') or flag.startswith('-l') if flag.startswith('-L') or flag.startswith('-l')
perl_ldflags += flag perl_ldflags += flag
endif endif

View File

@@ -2184,12 +2184,13 @@ mg_topic_key_press_cb (GtkWidget *entry, GdkEventKey *event, gpointer userdata)
} }
static char * static char *
mg_topic_get_word_at_pos (GtkWidget *entry, gdouble event_x, gdouble event_y) mg_topic_get_word_at_pos (GtkWidget *entry, gdouble event_x, gdouble event_y, int *word_pos)
{ {
GtkTextBuffer *buffer; GtkTextBuffer *buffer;
GtkTextIter iter; GtkTextIter iter;
GtkTextIter start; GtkTextIter start;
GtkTextIter end; GtkTextIter end;
GtkTextIter cursor;
int x; int x;
int y; int y;
@@ -2199,6 +2200,7 @@ mg_topic_get_word_at_pos (GtkWidget *entry, gdouble event_x, gdouble event_y)
x, y, &x, &y); x, y, &x, &y);
gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (entry), &iter, x, y); gtk_text_view_get_iter_at_location (GTK_TEXT_VIEW (entry), &iter, x, y);
cursor = iter;
start = iter; start = iter;
while (!gtk_text_iter_starts_line (&start)) while (!gtk_text_iter_starts_line (&start))
{ {
@@ -2226,6 +2228,16 @@ mg_topic_get_word_at_pos (GtkWidget *entry, gdouble event_x, gdouble event_y)
if (gtk_text_iter_equal (&start, &end)) if (gtk_text_iter_equal (&start, &end))
return NULL; return NULL;
if (word_pos)
{
char *prefix;
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (entry));
prefix = gtk_text_buffer_get_text (buffer, &start, &cursor, FALSE);
*word_pos = (int)strlen (prefix);
g_free (prefix);
}
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (entry)); buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (entry));
return gtk_text_buffer_get_text (buffer, &start, &end, FALSE); return gtk_text_buffer_get_text (buffer, &start, &end, FALSE);
} }
@@ -2248,25 +2260,34 @@ mg_topic_set_cursor (GtkWidget *entry, GdkCursorType cursor_type)
} }
static gboolean static gboolean
mg_topic_word_is_clickable (const char *word) mg_topic_word_is_clickable (const char *word, int word_pos)
{ {
int start;
int end;
if (!word || word[0] == 0) if (!word || word[0] == 0)
return FALSE; return FALSE;
if (strcmp (word, "/") == 0) if (strcmp (word, "/") == 0)
return FALSE; return FALSE;
return url_check_word (word) != 0; if (url_check_word (word) == 0)
return FALSE;
url_last (&start, &end);
return word_pos >= start && word_pos < end;
} }
static gboolean static gboolean
mg_topic_motion_cb (GtkWidget *entry, GdkEventMotion *event, gpointer userdata) mg_topic_motion_cb (GtkWidget *entry, GdkEventMotion *event, gpointer userdata)
{ {
char *word; char *word;
int word_pos;
gboolean word_is_clickable; gboolean word_is_clickable;
word = mg_topic_get_word_at_pos (entry, event->x, event->y); word_pos = 0;
word_is_clickable = mg_topic_word_is_clickable (word); word = mg_topic_get_word_at_pos (entry, event->x, event->y, &word_pos);
word_is_clickable = mg_topic_word_is_clickable (word, word_pos);
if (word_is_clickable) if (word_is_clickable)
mg_topic_set_cursor (entry, GDK_HAND2); mg_topic_set_cursor (entry, GDK_HAND2);
else else
@@ -2287,17 +2308,19 @@ static gboolean
mg_topic_button_release_cb (GtkWidget *entry, GdkEventButton *event, gpointer userdata) mg_topic_button_release_cb (GtkWidget *entry, GdkEventButton *event, gpointer userdata)
{ {
char *word; char *word;
int word_pos;
int start; int start;
int end; int end;
if (event->button != 1) if (event->button != 1)
return FALSE; return FALSE;
word = mg_topic_get_word_at_pos (entry, event->x, event->y); word_pos = 0;
word = mg_topic_get_word_at_pos (entry, event->x, event->y, &word_pos);
if (!word) if (!word)
return FALSE; return FALSE;
if (mg_topic_word_is_clickable (word)) if (mg_topic_word_is_clickable (word, word_pos))
{ {
url_last (&start, &end); url_last (&start, &end);
word[end] = 0; word[end] = 0;