gtk4: missbehavior of the Gtk::Label tooltip
Steps to reproduce
There are two examples for gtk3 and gtk4. They do the same thing. Rises a window and in separate thread is refreshing right label. Left label is not touched. In GTK4 tooltip of the left label is blinking and periodically disappearing due to the right label changes it markup tooltip text each 2 seconds. IN GTK3 such tooltip focus stealing doesn't happens
- gtk3 code
#include <gtk/gtk.h>
#include <thread>
#include <iomanip>
void setTlpMarkup(GtkWidget *wg, char* markUp) {
if (wg) {
while(true) {
auto t = std::time(nullptr);
auto tm = *std::localtime(&t);
std::ostringstream oss;
oss << std::put_time(&tm, "%d-%m-%Y %H-%M-%S");
auto str = std::string(markUp) + ' ' + oss.str();
gtk_widget_set_tooltip_markup(wg, str.c_str());
std::this_thread::sleep_for(std::chrono::seconds(2));
}
}
}
static GtkWidget *lLabel, *rLabel;
std::thread lT, rT;
static void
activate (GtkApplication *app,
gpointer user_data)
{
GtkWidget *window;
GtkWidget *mainBox, *lBox, *rBox;
mainBox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
lBox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
rBox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
gtk_box_pack_start(GTK_BOX(mainBox), lBox, true, true, 0);
gtk_box_pack_end(GTK_BOX(mainBox), rBox, true, true, 0);
// Labels
lLabel = gtk_label_new("Left Label");
rLabel = gtk_label_new("Right Label");
gtk_box_pack_start(GTK_BOX(lBox), lLabel, true, true, 0);
gtk_box_pack_start(GTK_BOX(rBox), rLabel, true, true, 0);
window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "Hello");
gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
gtk_container_add (GTK_CONTAINER (window), mainBox);
gtk_window_present (GTK_WINDOW (window));
gtk_widget_set_tooltip_markup(lLabel, (char*)"Left tooltip");
// lT = std::thread(setTlpMarkup, lLabel, (char*)"Left tooltip");
rT = std::thread(setTlpMarkup, rLabel, (char*)"Right tooltip");
gtk_widget_show_all (window);
}
int main(int argc, char* argv[]) {
GtkApplication *app;
int status{0};
app = gtk_application_new ("org.gtk.example", G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}
- gtk4 code
#include <gtk/gtk.h>
#include <thread>
#include <iomanip>
void setTlpMarkup(GtkWidget *wg, char* markUp) {
if (wg) {
while(true) {
auto t = std::time(nullptr);
auto tm = *std::localtime(&t);
std::ostringstream oss;
oss << std::put_time(&tm, "%d-%m-%Y %H-%M-%S");
auto str = std::string(markUp) + ' ' + oss.str();
gtk_widget_set_tooltip_markup(wg, str.c_str());
std::this_thread::sleep_for(std::chrono::seconds(2));
}
}
}
static GtkWidget *lLabel, *rLabel;
std::thread lT, rT;
static void
activate (GtkApplication *app,
gpointer user_data)
{
GtkWidget *window;
GtkWidget *mainBox, *lBox, *rBox;
mainBox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
lBox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
rBox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5);
gtk_box_pack_start(GTK_BOX(mainBox), lBox, true, true, 0);
gtk_box_pack_end(GTK_BOX(mainBox), rBox, true, true, 0);
// Labels
lLabel = gtk_label_new("Left Label");
rLabel = gtk_label_new("Right Label");
gtk_box_pack_start(GTK_BOX(lBox), lLabel, true, true, 0);
gtk_box_pack_start(GTK_BOX(rBox), rLabel, true, true, 0);
window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "Hello");
gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
gtk_container_add (GTK_CONTAINER (window), mainBox);
gtk_window_present (GTK_WINDOW (window));
gtk_widget_set_tooltip_markup(lLabel, (char*)"Left tooltip");
// lT = std::thread(setTlpMarkup, lLabel, (char*)"Left tooltip");
rT = std::thread(setTlpMarkup, rLabel, (char*)"Right tooltip");
gtk_widget_show_all (window);
}
int main(int argc, char* argv[]) {
GtkApplication *app;
int status{0};
app = gtk_application_new ("org.gtk.example", G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}
Current behavior
When there are at least two or more Labels are presented in the container Widget and application changes tooltip markup for any Label, focused tooltip for any Label is interrupted and even disappeared till next refresh time. In the same time it works fine when just Label markup is changed.
Expected outcome
When application changes tooltip markup for the label it should not prevent of the tooltip showing of the another label
Version information
gtk4 4.12.5