diff --git a/source/libublsettings-gtk3-status.c b/source/libublsettings-gtk3-status.c index 9a2b6d0..254abef 100644 --- a/source/libublsettings-gtk3-status.c +++ b/source/libublsettings-gtk3-status.c @@ -1,6 +1,6 @@ #include "libublsettings-gtk3.h" -static render_data render; +static render_data render = {}; void _yon_ubl_header_setup(GtkWidget *Overlay, GtkWidget *Head, GtkWidget *Image, char *image_path) { @@ -24,6 +24,30 @@ int yon_ubl_status_box_setup(GtkWidget *icon, GtkWidget *box, GtkWidget *label) } else return 0; } +int yon_status_box_is_set(){ + if (render.box){ + return 1; + } + return 0; +} + +GMutex _render_block_mutex; +gboolean _render_blocked=0; + +void *_yon_ubl_status_box_block_input(int*seconds){ + g_mutex_lock(&_render_block_mutex); + _render_blocked = 1; + g_mutex_unlock(&_render_block_mutex); + sleep(*seconds); + g_mutex_lock(&_render_block_mutex); + _render_blocked = 0; + g_mutex_unlock(&_render_block_mutex); +} + +void yon_ubl_status_box_block_input(int seconds){ + g_thread_new("block_thread",(GThreadFunc)_yon_ubl_status_box_block_input,&seconds); +} + void yon_ubl_status_box_set(BACKGROUND_IMAGE_TYPE type, GtkWidget *box, GtkImage *icon){ GtkIconTheme *ictheme = gtk_icon_theme_get_default(); @@ -61,6 +85,10 @@ void _yon_ubl_status_box_render(char *text, BACKGROUND_IMAGE_TYPE type) } void yon_ubl_status_box_render(char *text, BACKGROUND_IMAGE_TYPE type){ + g_mutex_lock(&_render_block_mutex); + int blocked = _render_blocked; + g_mutex_unlock(&_render_block_mutex); + if (blocked) return; _yon_ubl_status_box_render(text,type); } @@ -81,6 +109,10 @@ gboolean _yon_ubl_status_box_render_thread(struct __yon_ubl_status_box_render_th } void yon_ubl_status_box_render_thread(char *text, BACKGROUND_IMAGE_TYPE type){ + g_mutex_lock(&_render_block_mutex); + int blocked = _render_blocked; + g_mutex_unlock(&_render_block_mutex); + if (blocked) return; struct __yon_ubl_status_box_render_thread_struct *data = malloc(sizeof(struct __yon_ubl_status_box_render_thread_struct)); data->text=yon_char_new(text); data->type=type; @@ -199,6 +231,10 @@ void yon_status_box_destroyed(){ } int yon_ubl_status_box_spawn_infinite(GtkContainer *container, char *status_id, char *display_text, BACKGROUND_IMAGE_TYPE type){ + g_mutex_lock(&_render_block_mutex); + int blocked = _render_blocked; + g_mutex_unlock(&_render_block_mutex); + if (blocked) return 0; // if (!gtk_container_get_children(container)){ if (yon_status_thread_id){ if (!strcmp(yon_status_thread_id,status_id)){ @@ -286,6 +322,10 @@ int yon_ubl_status_box_despawn_infinite(GtkContainer *container){ } void yon_ubl_status_box_spawn(GtkContainer *container,char *display_text, int timeout,BACKGROUND_IMAGE_TYPE type){ + g_mutex_lock(&_render_block_mutex); + int blocked = _render_blocked; + g_mutex_unlock(&_render_block_mutex); + if (blocked) return; if (!gtk_container_get_children(container)){ GtkWidget *box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,5); GtkWidget *revealer = gtk_revealer_new(); diff --git a/source/libublsettings-gtk3.h b/source/libublsettings-gtk3.h index 49b0a59..41d8533 100644 --- a/source/libublsettings-gtk3.h +++ b/source/libublsettings-gtk3.h @@ -359,6 +359,8 @@ typedef struct { */ int yon_ubl_status_box_setup(GtkWidget *icon, GtkWidget *box, GtkWidget *label); +int yon_status_box_is_set(); + /**yon_ubl_status_box_render(render,text,type) * [EN] * Renders message in status box; @@ -376,6 +378,8 @@ int yon_ubl_status_box_setup(GtkWidget *icon, GtkWidget *box, GtkWidget *label); */ void yon_ubl_status_box_render(char *text, BACKGROUND_IMAGE_TYPE type); +void yon_ubl_status_box_block_input(int seconds); + /**yon_ubl_status_box_render_thread(render,text,type) * [EN] * Renders message in status box. It is safe to use outside of interface thread.