@ -1,28 +1,64 @@
# include "libublsettings-gtk3.h"
# include "libublsettings-gtk3.h"
static render_data render = { } ;
// static render_data render = {};
struct status_struct {
GtkWidget * box ;
GtkWidget * revealer ;
GtkWidget * label ;
GtkWidget * icon ;
guint thread ;
GMutex mutex ;
int sleep_timer ;
int window_height ;
} ;
void _yon_ubl_header_setup ( GtkWidget * Overlay , GtkWidget * Head , GtkWidget * Image , char * image_path )
void _ _yon_ubl_status_box_destroyed( GtkWidget * self , struct status_struct * statusstruct ) ;
{
void yon_ubl_status_box_despawn ( GtkContainer * status_container ) ;
gtk_overlay_add_overlay ( GTK_OVERLAY ( Overlay ) , Head ) ;
gboolean yon_ubl_status_destroy_status ( struct status_struct * statusstruct ) ;
gtk_image_set_from_file ( GTK_IMAGE ( Image ) , image_path ) ;
gboolean _yon_ubl_status_box_timed_remove ( struct status_struct * statusstruct ) ;
}
gboolean yon_status_shrink_window ( struct status_struct * statusstruct ) ;
int yon_ubl_status_box_setup ( GtkWidget * icon , GtkWidget * box , GtkWidget * label )
{
if ( icon & & box & & label ) {
render . icon = icon ;
render . box = box ;
render . label = label ;
return 1 ;
} else return 0 ;
}
int yon_status_box_is_set ( ) {
struct status_struct * render = NULL ;
if ( render . box ) {
return 1 ;
struct status_struct * yon_status_struct_new ( ) {
}
struct status_struct * status = malloc ( sizeof ( struct status_struct ) ) ;
return 0 ;
memset ( status , 0 , sizeof ( struct status_struct ) ) ;
status - > box = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 5 ) ;
status - > revealer = gtk_revealer_new ( ) ;
status - > label = gtk_label_new ( " " ) ;
status - > icon = gtk_image_new ( ) ;
gtk_label_set_line_wrap ( GTK_LABEL ( status - > label ) , 1 ) ;
gtk_label_set_line_wrap_mode ( GTK_LABEL ( status - > label ) , PANGO_WRAP_WORD ) ;
gtk_container_add ( GTK_CONTAINER ( status - > revealer ) , status - > box ) ;
gtk_box_pack_start ( GTK_BOX ( status - > box ) , status - > icon , 0 , 0 , 5 ) ;
gtk_box_pack_start ( GTK_BOX ( status - > box ) , status - > label , 0 , 0 , 5 ) ;
gtk_widget_set_margin_bottom ( status - > label , 9 ) ;
gtk_widget_set_margin_top ( status - > label , 9 ) ;
gtk_label_set_xalign ( GTK_LABEL ( status - > label ) , 0.0 ) ;
PangoAttrList * attributes = pango_attr_list_new ( ) ;
PangoAttribute * boldAttr = pango_attr_weight_new ( PANGO_WEIGHT_BOLD ) ;
pango_attr_list_insert ( attributes , boldAttr ) ;
gtk_label_set_attributes ( GTK_LABEL ( status - > label ) , attributes ) ;
GdkRGBA textColor ;
gdk_rgba_parse ( & textColor , " #4d4d4d4d4d4d " ) ;
PangoAttribute * colorAttr = pango_attr_foreground_new (
( int ) ( textColor . red * 65535 ) ,
( int ) ( textColor . green * 65535 ) ,
( int ) ( textColor . blue * 65535 )
) ;
pango_attr_list_insert ( attributes , colorAttr ) ;
gtk_revealer_set_transition_duration ( GTK_REVEALER ( status - > revealer ) , 200 ) ;
g_signal_connect ( G_OBJECT ( status - > revealer ) , " destroy " , G_CALLBACK ( __yon_ubl_status_box_destroyed ) , status ) ;
g_object_set_data ( G_OBJECT ( status - > revealer ) , " status_struct " , status ) ;
gtk_widget_show_all ( status - > revealer ) ;
return status ;
}
}
GMutex _render_block_mutex ;
GMutex _render_block_mutex ;
@ -42,96 +78,37 @@ void yon_ubl_status_box_block_input(int seconds){
g_thread_new ( " block_thread " , ( GThreadFunc ) _yon_ubl_status_box_block_input , & 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 ) {
void yon_ubl_status_box_set ( BACKGROUND_IMAGE_TYPE type , GtkRevealer * root ) {
struct status_struct * status = g_object_get_data ( G_OBJECT ( root ) , " status_struct " ) ;
if ( ! status ) {
status = g_object_get_data ( G_OBJECT ( root ) , " status_def_struct " ) ;
}
GtkIconTheme * ictheme = gtk_icon_theme_get_default ( ) ;
GtkIconTheme * ictheme = gtk_icon_theme_get_default ( ) ;
switch ( type ) {
switch ( type ) {
case BACKGROUND_IMAGE_SUCCESS_TYPE :
case BACKGROUND_IMAGE_SUCCESS_TYPE : {
{
gtk_style_context_remove_class ( gtk_widget_get_style_context ( status - > box ) , " boxInfoMessError " ) ;
gtk_style_context_ remove _class( gtk_widget_get_style_context ( box) , " boxInfoMess Error " ) ;
gtk_style_context_ add _class( gtk_widget_get_style_context ( status- > box) , " boxInfoMess OK " ) ;
gtk_ style_context_add_class( gtk_widget_get_style_context ( box ) , " boxInfoMessOK " ) ;
gtk_ image_set_from_icon_name( GTK_IMAGE ( status - > icon ) , " com.ublinux.libublsettingsui-gtk3.checked " , GTK_ICON_SIZE_BUTTON ) ;
gtk_image_set_ from_pixbuf( GTK_IMAGE ( icon ) , gtk_icon_theme_load_icon_for_scale ( ictheme , " com.ublinux.libublsettingsui-gtk3.checked " , 25 , 1 , GTK_ICON_LOOKUP_FORCE_SIZE , NULL ) ) ;
gtk_image_set_ pixel_size( GTK_IMAGE ( status - > icon ) , 25 ) ;
}
}
break ;
break ;
case BACKGROUND_IMAGE_FAIL_TYPE :
case BACKGROUND_IMAGE_FAIL_TYPE : {
{
gtk_style_context_remove_class ( gtk_widget_get_style_context ( status - > box ) , " boxInfoMessOK " ) ;
gtk_style_context_ remove _class( gtk_widget_get_style_context ( box) , " boxInfoMess OK " ) ;
gtk_style_context_ add _class( gtk_widget_get_style_context ( status- > box) , " boxInfoMess Error " ) ;
gtk_ style_context_add_class( gtk_widget_get_style_context ( box ) , " boxInfoMessError " ) ;
gtk_ image_set_from_icon_name( GTK_IMAGE ( status - > icon ) , " com.ublinux.libublsettingsui-gtk3.warning " , GTK_ICON_SIZE_BUTTON ) ;
gtk_image_set_ from_pixbuf( GTK_IMAGE ( icon ) , gtk_icon_theme_load_icon_for_scale ( ictheme , " com.ublinux.libublsettingsui-gtk3.warning " , 25 , 1 , GTK_ICON_LOOKUP_FORCE_SIZE , NULL ) ) ;
gtk_image_set_ pixel_size( GTK_IMAGE ( status - > icon ) , 25 ) ;
}
}
break ;
break ;
case BACKGROUND_IMAGE_INFO_TYPE :
case BACKGROUND_IMAGE_INFO_TYPE : {
{
gtk_style_context_remove_class ( gtk_widget_get_style_context ( status - > box ) , " boxInfoMessError " ) ;
gtk_style_context_ remove _class( gtk_widget_get_style_context ( box) , " boxInfoMess Error " ) ;
gtk_style_context_ add _class( gtk_widget_get_style_context ( status- > box) , " boxInfoMess OK " ) ;
gtk_ style_context_add_class( gtk_widget_get_style_context ( box ) , " boxInfoMessOK " ) ;
gtk_ image_set_from_icon_name( GTK_IMAGE ( status - > icon ) , " com.ublinux.libublsettingsui-gtk3.important-symbolic " , GTK_ICON_SIZE_BUTTON ) ;
gtk_image_set_ from_pixbuf( GTK_IMAGE ( icon ) , gtk_icon_theme_load_icon_for_scale ( ictheme , " com.ublinux.libublsettingsui-gtk3.important-symbolic " , 25 , 1 , GTK_ICON_LOOKUP_FORCE_SIZE , NULL ) ) ;
gtk_image_set_ pixel_size( GTK_IMAGE ( status - > icon ) , 25 ) ;
}
}
break ;
break ;
}
}
}
}
void _yon_ubl_status_box_render ( char * text , BACKGROUND_IMAGE_TYPE type )
{
render_data data = render ;
yon_ubl_status_box_set ( type , data . box , GTK_IMAGE ( data . icon ) ) ;
if ( text )
gtk_label_set_text ( GTK_LABEL ( data . label ) , text ) ;
}
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 ) ;
}
struct __yon_ubl_status_box_render_thread_struct {
char * text ;
BACKGROUND_IMAGE_TYPE type ;
} ;
gboolean _yon_ubl_status_box_render_thread ( struct __yon_ubl_status_box_render_thread_struct * data ) {
render_data statusbox = render ;
yon_ubl_status_box_set ( data - > type , statusbox . box , GTK_IMAGE ( statusbox . icon ) ) ;
if ( data - > text ) {
gtk_label_set_text ( GTK_LABEL ( statusbox . label ) , data - > text ) ;
free ( data - > text ) ;
}
free ( data ) ;
return G_SOURCE_REMOVE ;
}
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 ;
g_idle_add ( ( GSourceFunc ) _yon_ubl_status_box_render_thread , data ) ;
}
gboolean _yon_ubl_status_highlight_incorrect_start ( GtkWidget * widget ) {
gtk_style_context_add_class ( gtk_widget_get_style_context ( widget ) , " errorBox " ) ;
return G_SOURCE_REMOVE ;
}
gboolean _yon_ubl_status_highlight_incorrect_stop ( GtkWidget * widget ) {
gtk_style_context_remove_class ( gtk_widget_get_style_context ( widget ) , " errorBox " ) ;
return G_SOURCE_REMOVE ;
}
gboolean _yon_ubl_status_highlight_incorrect ( GtkWidget * widget ) {
g_idle_add ( ( GSourceFunc ) _yon_ubl_status_highlight_incorrect_start , widget ) ;
sleep ( 5 ) ;
g_idle_add ( ( GSourceFunc ) _yon_ubl_status_highlight_incorrect_stop , widget ) ;
}
void yon_ubl_status_highlight_incorrect ( GtkWidget * widget ) {
g_thread_new ( " error_highlight " , ( GThreadFunc ) _yon_ubl_status_highlight_incorrect , widget ) ;
}
gboolean _yon_ubl_status_list_store_highlight_incorrect_start ( GtkWidget * * widget_pack ) {
gboolean _yon_ubl_status_list_store_highlight_incorrect_start ( GtkWidget * * widget_pack ) {
GtkListStore * list = ( GtkListStore * ) widget_pack [ 0 ] ;
GtkListStore * list = ( GtkListStore * ) widget_pack [ 0 ] ;
@ -157,9 +134,9 @@ gboolean _yon_ubl_status_list_store_highlight_incorrect_stop(GtkWidget **widget_
}
}
void _yon_ubl_status_list_store_highlight_incorrect ( GtkWidget * * widget_pack ) {
void _yon_ubl_status_list_store_highlight_incorrect ( GtkWidget * * widget_pack ) {
g_idle_add ( ( GSourceFunc ) _yon_ubl_status_ highlight_incorrect_stop , widget_pack ) ;
g_idle_add ( ( GSourceFunc ) _yon_ubl_status_ list_store_highlight_incorrect_start , widget_pack ) ;
sleep ( 5 ) ;
sleep ( 5 ) ;
g_idle_add ( ( GSourceFunc ) _yon_ubl_status_ highlight_incorrect_stop, widget_pack ) ;
g_idle_add ( ( GSourceFunc ) _yon_ubl_status_ list_store_ highlight_incorrect_stop, widget_pack ) ;
}
}
void yon_ubl_status_list_store_highlight_incorrect ( GtkListStore * list , GtkTreeIter * iter ) {
void yon_ubl_status_list_store_highlight_incorrect ( GtkListStore * list , GtkTreeIter * iter ) {
@ -175,224 +152,218 @@ struct temp_statusbox {
int window_height ;
int window_height ;
} ;
} ;
static char * yon_status_thread_id = NULL ;
gboolean yon_ubl_status_hide_revealer ( struct temp_statusbox * statusstruct ) {
gtk_revealer_set_reveal_child ( GTK_REVEALER ( statusstruct - > revealer ) , 0 ) ;
// Standard status box functions
void _yon_ubl_header_setup ( GtkWidget * Overlay , GtkWidget * Head , GtkWidget * Image , char * image_path ) {
gtk_overlay_add_overlay ( GTK_OVERLAY ( Overlay ) , Head ) ;
gtk_image_set_from_file ( GTK_IMAGE ( Image ) , image_path ) ;
}
}
gboolean yon_status_shrink_window ( struct temp_statusbox * statusstruct ) {
int yon_ubl_status_box_setup ( GtkWidget * icon , GtkWidget * box , GtkWidget * label ) {
if ( statusstruct - > revealer ) {
if ( icon & & box & & label ) {
GtkWidget * window = gtk_widget_get_toplevel ( statusstruct - > revealer ) ;
render = malloc ( sizeof ( struct status_struct ) ) ;
memset ( render , 0 , sizeof ( struct status_struct ) ) ;
int width , height ;
render - > box = box ;
gtk_window_get_size ( GTK_WINDOW ( window ) , & width , NULL ) ;
render - > label = label ;
gtk_window_resize ( GTK_WINDOW ( window ) , width , statusstruct - > window_height ) ;
render - > icon = icon ;
return G_SOURCE_CONTINUE ;
g_object_set_data ( G_OBJECT ( render - > box ) , " status_def_struct " , render ) ;
} else return G_SOURCE_REMOVE ;
return 1 ;
} else return 0 ;
}
int yon_status_box_is_set ( ) {
if ( render ) {
return 1 ;
}
return 0 ;
}
}
gboolean yon_ubl_status_destroy_status ( struct temp_statusbox * statusstruct ) {
void _yon_ubl_status_box_render ( char * text , BACKGROUND_IMAGE_TYPE type ) {
GtkWidget * window = gtk_widget_get_toplevel ( statusstruct - > revealer ) ;
struct status_struct * data = render ;
GtkWidget * revealer = statusstruct - > revealer ;
yon_ubl_status_box_set ( type , ( GtkRevealer * ) data - > box ) ;
gtk_widget_destroy ( statusstruct - > revealer ) ;
if ( text )
statusstruct - > revealer = NULL ;
gtk_label_set_text ( GTK_LABEL ( data - > label ) , text ) ;
int width , height ;
gtk_window_get_size ( GTK_WINDOW ( window ) , & width , NULL ) ;
gtk_window_resize ( GTK_WINDOW ( window ) , width , statusstruct - > window_height ) ;
return G_SOURCE_REMOVE ;
}
}
void _yon_ubl_status_box_timed_remove ( struct temp_statusbox * statusstruct ) {
void yon_ubl_status_box_render ( char * text , BACKGROUND_IMAGE_TYPE type ) {
sleep ( statusstruct - > times ) ;
g_mutex_lock ( & _render_block_mutex ) ;
if ( statusstruct - > revealer ) {
int blocked = _render_blocked ;
g_idle_add ( ( GSourceFunc ) yon_ubl_status_hide_revealer , statusstruct ) ;
g_mutex_unlock ( & _render_block_mutex ) ;
g_idle_add ( ( GSourceFunc ) yon_status_shrink_window , statusstruct ) ;
if ( blocked ) return ;
sleep ( 1 ) ;
_yon_ubl_status_box_render ( text , type ) ;
g_idle_add ( ( GSourceFunc ) yon_ubl_status_destroy_status , statusstruct ) ;
}
struct __yon_ubl_status_box_render_thread_struct {
char * text ;
BACKGROUND_IMAGE_TYPE type ;
} ;
void _yon_ubl_status_box_render_thread ( struct __yon_ubl_status_box_render_thread_struct * data ) {
struct status_struct * statusbox = render ;
yon_ubl_status_box_set ( data - > type , GTK_REVEALER ( statusbox - > revealer ) ) ;
if ( data - > text ) {
gtk_label_set_text ( GTK_LABEL ( statusbox - > label ) , data - > text ) ;
free ( data - > text ) ;
}
}
free ( data ) ;
}
}
void __yon_ubl_status_box_destroyed ( GtkWidget * self , struct temp_statusbox * statusstruct ) {
void yon_ubl_status_box_render_thread ( char * text , BACKGROUND_IMAGE_TYPE type ) {
statusstruct - > revealer = NULL ;
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 ;
g_idle_add_once ( ( GSourceOnceFunc ) _yon_ubl_status_box_render_thread , data ) ;
}
}
void yon_status_box_destroyed ( ) {
if ( yon_status_thread_id ) {
free ( yon_status_thread_id ) ;
yon_status_thread_id = NULL ;
// Status spawn functions
void __yon_ubl_status_box_destroyed ( GtkWidget * self , struct status_struct * statusstruct ) {
g_mutex_lock ( & statusstruct - > mutex ) ;
if ( statusstruct - > thread > - 1 ) {
g_source_remove ( statusstruct - > thread ) ;
}
}
g_mutex_unlock ( & statusstruct - > mutex ) ;
}
}
int yon_ubl_status_box_spawn_infinite ( GtkContainer * container , char * status_id , char * display_text , BACKGROUND_IMAGE_TYPE type ) {
void yon_ubl_status_box_spawn ( GtkContainer * container , char * display_text , int timeout , BACKGROUND_IMAGE_TYPE type ) {
g_mutex_lock ( & _render_block_mutex ) ;
g_mutex_lock ( & _render_block_mutex ) ;
int blocked = _render_blocked ;
int blocked = _render_blocked ;
g_mutex_unlock ( & _render_block_mutex ) ;
g_mutex_unlock ( & _render_block_mutex ) ;
if ( blocked ) return 0 ;
if ( blocked ) return ;
// if (!gtk_container_get_children(container)){
// if (gtk_container_get_children(container))return;
if ( yon_status_thread_id ) {
if ( ! strcmp ( yon_status_thread_id , status_id ) ) {
return 0 ;
}
free ( yon_status_thread_id ) ;
yon_status_thread_id = NULL ;
GList * list = gtk_container_get_children ( container ) ;
for ( int i = 0 ; i < g_list_length ( list ) ; i + + ) {
gtk_widget_destroy ( ( GtkWidget * ) g_list_nth_data ( list , i ) ) ;
}
}
yon_status_thread_id = yon_char_new ( status_id ) ;
GtkWidget * box = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 5 ) ;
GtkWidget * revealer = gtk_revealer_new ( ) ;
GtkWidget * label = gtk_label_new ( " " ) ;
GtkWidget * icon = gtk_image_new ( ) ;
g_signal_connect ( G_OBJECT ( box ) , " destroy " , G_CALLBACK ( yon_status_box_destroyed ) , NULL ) ;
gtk_label_set_line_wrap ( GTK_LABEL ( label ) , 1 ) ;
gtk_label_set_line_wrap_mode ( GTK_LABEL ( label ) , PANGO_WRAP_WORD ) ;
gtk_container_add ( GTK_CONTAINER ( revealer ) , box ) ;
gtk_box_pack_start ( GTK_BOX ( box ) , icon , 0 , 0 , 5 ) ;
gtk_box_pack_start ( GTK_BOX ( box ) , label , 0 , 0 , 0 ) ;
gtk_container_add ( container , revealer ) ;
gtk_widget_show_all ( revealer ) ;
gtk_revealer_set_reveal_child ( GTK_REVEALER ( revealer ) , 1 ) ;
gtk_widget_set_margin_bottom ( label , 9 ) ;
gtk_widget_set_margin_top ( label , 9 ) ;
gtk_label_set_xalign ( GTK_LABEL ( label ) , 0.0 ) ;
PangoAttrList * attributes = pango_attr_list_new ( ) ;
PangoAttribute * boldAttr = pango_attr_weight_new ( PANGO_WEIGHT_BOLD ) ;
pango_attr_list_insert ( attributes , boldAttr ) ;
gtk_label_set_attributes ( GTK_LABEL ( label ) , attributes ) ;
GdkRGBA textColor ;
gdk_rgba_parse ( & textColor , " #4d4d4d4d4d4d " ) ;
PangoAttribute * colorAttr = pango_attr_foreground_new (
( int ) ( textColor . red * 65535 ) ,
( int ) ( textColor . green * 65535 ) ,
( int ) ( textColor . blue * 65535 )
) ;
pango_attr_list_insert ( attributes , colorAttr ) ;
yon_ubl_status_box_set ( type , box , GTK_IMAGE ( icon ) ) ;
if ( display_text )
gtk_label_set_text ( GTK_LABEL ( label ) , display_text ) ;
struct temp_statusbox * statusstruct = malloc ( sizeof ( struct temp_statusbox ) ) ;
g_signal_connect ( G_OBJECT ( revealer ) , " destroy " , G_CALLBACK ( __yon_ubl_status_box_destroyed ) , statusstruct ) ;
statusstruct - > revealer = revealer ;
gtk_window_get_size ( GTK_WINDOW ( gtk_widget_get_toplevel ( revealer ) ) , NULL , & statusstruct - > window_height ) ;
// }
}
int delete_busy = 0 ;
struct status_struct * status = yon_status_struct_new ( ) ;
int _yon_ubl_status_box_despawn_infinite ( GtkContainer * container ) {
if ( ! delete_busy ) {
status - > sleep_timer = timeout ;
delete_busy = 1 ;
if ( yon_status_thread_id ) {
gtk_container_add ( container , status - > revealer ) ;
free ( yon_status_thread_id ) ;
gtk_revealer_set_reveal_child ( GTK_REVEALER ( status - > revealer ) , 1 ) ;
yon_status_thread_id = NULL ;
}
yon_ubl_status_box_set ( type , GTK_REVEALER ( status - > revealer ) ) ;
GList * list = gtk_container_get_children ( container ) ;
if ( display_text ) {
for ( int i = 0 ; i < g_list_length ( list ) ; i + + ) {
gtk_label_set_text ( GTK_LABEL ( status - > label ) , display_text ) ;
GtkWidget * revealer = g_list_nth_data ( list , i ) ;
}
g_list_free ( list ) ;
if ( GTK_IS_REVEALER ( revealer ) ) {
gtk_window_get_size ( GTK_WINDOW ( gtk_widget_get_toplevel ( status - > revealer ) ) , NULL , & status - > window_height ) ;
gtk_revealer_set_reveal_child ( GTK_REVEALER ( revealer ) , 0 ) ;
if ( status - > sleep_timer > 0 ) {
usleep ( 200000 ) ;
g_mutex_lock ( & status - > mutex ) ;
list = gtk_container_get_children ( container ) ;
status - > thread = g_timeout_add ( status - > sleep_timer * 1000 , ( GSourceFunc ) _yon_ubl_status_box_timed_remove , status ) ;
if ( g_list_length > 0 ) {
g_mutex_unlock ( & status - > mutex ) ;
if ( GTK_IS_REVEALER ( revealer ) ) {
gtk_widget_destroy ( revealer ) ;
}
}
}
}
delete_busy = 0 ;
}
}
}
}
int yon_ubl_status_box_despawn_infinite ( GtkContainer * container ) {
GThread * thread = g_thread_new ( " StatusThread " , ( GThreadFunc ) _yon_ubl_status_box_despawn_infinite , container ) ;
// Status despawn functions
void yon_ubl_status_hide_revealer ( struct status_struct * status ) {
gtk_revealer_set_transition_type ( GTK_REVEALER ( status - > revealer ) , GTK_REVEALER_TRANSITION_TYPE_SLIDE_UP ) ;
gtk_revealer_set_reveal_child ( GTK_REVEALER ( status - > revealer ) , 0 ) ;
}
}
void * __yon_ubl_status_box_despawn ( GtkContainer * status_container ) {
gboolean __yon_ubl_status_box_despawn ( struct status_struct * status ) {
GList * list = gtk_container_get_children ( status_container ) ;
gtk_widget_destroy ( status - > revealer ) ;
GtkWidget * revealer = g_list_nth_data ( list , 0 ) ;
free ( status ) ;
struct temp_statusbox * statusstruct = malloc ( sizeof ( struct temp_statusbox ) ) ;
return G_SOURCE_REMOVE ;
statusstruct - > revealer = revealer ;
statusstruct - > times = 0 ;
g_idle_add ( ( GSourceFunc ) yon_ubl_status_hide_revealer , statusstruct ) ;
sleep ( 1 ) ;
gtk_widget_destroy ( statusstruct - > revealer ) ;
g_list_free ( list ) ;
return NULL ;
}
}
void yon_ubl_status_box_despawn ( GtkContainer * status_container ) {
void yon_ubl_status_box_despawn ( GtkContainer * status_container ) {
GList * list = gtk_container_get_children ( status_container ) ;
GList * list = gtk_container_get_children ( status_container ) ;
if ( ! list ) return ;
if ( ! list ) return ;
GList * iter ;
for ( iter = list ; iter ; iter = iter - > next ) {
struct status_struct * status = g_object_get_data ( G_OBJECT ( status_container ) , " status_struct " ) ;
if ( status - > thread > ( guint ) - 1 ) {
g_mutex_lock ( & status - > mutex ) ;
g_source_remove ( status - > thread ) ;
g_mutex_unlock ( & status - > mutex ) ;
}
g_idle_add_once ( ( GSourceOnceFunc ) yon_ubl_status_hide_revealer , status ) ;
g_timeout_add ( 1000 , ( GSourceFunc ) __yon_ubl_status_box_despawn , status ) ;
}
g_list_free ( list ) ;
g_list_free ( list ) ;
g_thread_new ( " status_despawn " , ( GThreadFunc ) __yon_ubl_status_box_despawn , status_container ) ;
return ;
}
}
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 ) ) return ;
GtkWidget * box = gtk_box_new ( GTK_ORIENTATION_HORIZONTAL , 5 ) ;
GtkWidget * revealer = gtk_revealer_new ( ) ;
GtkWidget * label = gtk_label_new ( " " ) ;
GtkWidget * icon = gtk_image_new ( ) ;
gtk_label_set_line_wrap ( GTK_LABEL ( label ) , 1 ) ;
gtk_label_set_line_wrap_mode ( GTK_LABEL ( label ) , PANGO_WRAP_WORD ) ;
gtk_container_add ( GTK_CONTAINER ( revealer ) , box ) ;
gtk_box_pack_start ( GTK_BOX ( box ) , icon , 0 , 0 , 5 ) ;
gtk_box_pack_start ( GTK_BOX ( box ) , label , 0 , 0 , 5 ) ;
gtk_container_add ( container , revealer ) ;
gtk_widget_show_all ( revealer ) ;
gtk_revealer_set_reveal_child ( GTK_REVEALER ( revealer ) , 1 ) ;
gtk_widget_set_margin_bottom ( label , 9 ) ;
gtk_widget_set_margin_top ( label , 9 ) ;
gtk_label_set_xalign ( GTK_LABEL ( label ) , 0.0 ) ;
PangoAttrList * attributes = pango_attr_list_new ( ) ;
PangoAttribute * boldAttr = pango_attr_weight_new ( PANGO_WEIGHT_BOLD ) ;
pango_attr_list_insert ( attributes , boldAttr ) ;
gtk_label_set_attributes ( GTK_LABEL ( label ) , attributes ) ;
GdkRGBA textColor ;
gboolean _yon_ubl_status_box_timed_remove ( struct status_struct * statusstruct ) {
gdk_rgba_parse ( & textColor , " #4d4d4d4d4d4d " ) ;
if ( statusstruct - > revealer ) {
PangoAttribute * colorAttr = pango_attr_foreground_new (
yon_ubl_status_hide_revealer ( statusstruct ) ;
( int ) ( textColor . red * 65535 ) ,
g_idle_add ( ( GSourceFunc ) yon_status_shrink_window , statusstruct ) ;
( int ) ( textColor . green * 65535 ) ,
g_timeout_add ( 10000 , ( GSourceFunc ) yon_ubl_status_destroy_status , statusstruct ) ;
( int ) ( textColor . blue * 65535 )
}
) ;
return G_SOURCE_REMOVE ;
pango_attr_list_insert ( attributes , colorAttr ) ;
yon_ubl_status_box_set ( type , box , GTK_IMAGE ( icon ) ) ;
if ( display_text )
gtk_label_set_text ( GTK_LABEL ( label ) , display_text ) ;
struct temp_statusbox * statusstruct = malloc ( sizeof ( struct temp_statusbox ) ) ;
statusstruct - > revealer = revealer ;
statusstruct - > times = timeout ;
g_object_add_weak_pointer ( G_OBJECT ( revealer ) , ( gpointer * ) & statusstruct - > revealer ) ;
gtk_window_get_size ( GTK_WINDOW ( gtk_widget_get_toplevel ( revealer ) ) , NULL , & statusstruct - > window_height ) ;
g_signal_connect ( G_OBJECT ( revealer ) , " destroy " , G_CALLBACK ( __yon_ubl_status_box_destroyed ) , statusstruct ) ;
GThread * thread = g_thread_new ( " StatusThread " , ( GThreadFunc ) _yon_ubl_status_box_timed_remove , statusstruct ) ;
}
}
int yon_ubl_status_set_text ( GtkContainer * status_placeholder , char * text ) {
gboolean yon_ubl_status_destroy_status ( struct status_struct * statusstruct ) {
GList * placeholder_children = gtk_container_get_children ( status_placeholder ) ;
if ( statusstruct - > window_height < = 0 ) return G_SOURCE_REMOVE ;
if ( placeholder_children ) {
GtkWidget * window = gtk_widget_get_toplevel ( statusstruct - > revealer ) ;
GList * status_children = gtk_container_get_children ( GTK_CONTAINER ( placeholder_children - > data ) ) ;
gtk_widget_destroy ( statusstruct - > revealer ) ;
if ( status_children ) {
statusstruct - > revealer = NULL ;
gtk_label_set_text ( GTK_LABEL ( g_list_nth_data ( status_children , 1 ) ) , text ) ;
int width , height ;
g_list_free ( status_children ) ;
gtk_window_get_size ( GTK_WINDOW ( window ) , & width , NULL ) ;
}
gtk_window_resize ( GTK_WINDOW ( window ) , width , statusstruct - > window_height ) ;
g_list_free ( placeholder_children ) ;
return G_SOURCE_REMOVE ;
}
gboolean yon_status_shrink_window ( struct status_struct * statusstruct ) {
if ( statusstruct - > revealer ) {
GtkWidget * window = gtk_widget_get_toplevel ( statusstruct - > revealer ) ;
int width , height ;
gtk_window_get_size ( GTK_WINDOW ( window ) , & width , NULL ) ;
gtk_window_resize ( GTK_WINDOW ( window ) , width , statusstruct - > window_height ) ;
return G_SOURCE_CONTINUE ;
} else return G_SOURCE_REMOVE ;
}
// Widget highlight functions
gboolean _yon_ubl_status_highlight_incorrect_start ( GtkWidget * widget ) {
gtk_style_context_add_class ( gtk_widget_get_style_context ( widget ) , " errorBox " ) ;
return G_SOURCE_REMOVE ;
}
gboolean _yon_ubl_status_highlight_incorrect_stop ( GtkWidget * widget ) {
gtk_style_context_remove_class ( gtk_widget_get_style_context ( widget ) , " errorBox " ) ;
return G_SOURCE_REMOVE ;
}
gboolean _yon_ubl_status_highlight_incorrect ( GtkWidget * widget ) {
g_idle_add ( ( GSourceFunc ) _yon_ubl_status_highlight_incorrect_stop , widget ) ;
return G_SOURCE_REMOVE ;
}
void yon_ubl_status_highlight_incorrect ( GtkWidget * widget ) {
guint * thread = NULL ;
thread = g_object_get_data ( G_OBJECT ( widget ) , " highlight_thread " ) ;
if ( ( * thread ) > ( guint ) - 1 ) {
g_source_remove ( ( * thread ) ) ;
free ( thread ) ;
}
}
return 0 ;
thread = malloc ( sizeof ( guint ) ) ;
_yon_ubl_status_highlight_incorrect_start ( widget ) ;
( * thread ) = g_timeout_add ( 5000 , ( GSourceFunc ) _yon_ubl_status_highlight_incorrect , widget ) ;
g_object_set_data ( G_OBJECT ( widget ) , " highlight_thread " , thread ) ;
}
}