C and libappindicator - Creating multiple indicators - c

I'm programming a simple indicator that is supposed to show an icon for each CPU Core in the Unity panel, that will change color depending on the temperature range.
That would require me to have more than one AppIndicator on the same program, since I think there's no way to have one AppIndicator with multiple icons or use a gtk_container to hold those and append it to the AppIndicator. I'm actually trying to use 1 AppIndicator for the menu (with the "Quit" option) and 1 AppIndicator for each CPU Core.
The program had no Gtk warnings with just one AppIndicator (the main one), but after I added the code for creating the other 2 AppIndicators for each CPU Core (both with different unique id's) Gtk started throwing some warnings and critical messages. The indicators show up in the panel just like they are supposed to, but I don't want to simply ignore those messages, as they could be hiding some real issues under the curtains.
Checking the code, the only thing I think could be triggering those warnings and critical messages is app_indicator_new() being called more than once, I actually removed all the menu and menu_item's creation routines for those extra indicators, leaving only the app_indicator_new() call and I still get those messages (one for each extra app_indicator_new() call after the first):
(process:8040): Gtk-CRITICAL **: IA__gtk_icon_theme_get_for_screen: assertion 'GDK_IS_SCREEN (screen)' failed
(process:8040): GLib-GObject-WARNING **: invalid (NULL) pointer instance
(process:8040): GLib-GObject-CRITICAL **: g_signal_connect_data: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed
When I add the code with the menu being created and associated with the extra AppIndicator's some extra errors show up:
(process:8681): GLib-GObject-WARNING **: invalid (NULL) pointer instance
(process:8681): GLib-GObject-CRITICAL **: g_signal_connect_data: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed
(process:8681): Gtk-CRITICAL **: IA__gtk_icon_theme_get_for_screen: assertion 'GDK_IS_SCREEN (screen)' failed
(process:8681): GLib-GObject-WARNING **: invalid (NULL) pointer instance
(process:8681): GLib-GObject-CRITICAL **: g_signal_connect_data: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed
(process:8681): Gtk-CRITICAL **: IA__gtk_settings_get_for_screen: assertion 'GDK_IS_SCREEN (screen)' failed
(process:8681): GLib-GObject-CRITICAL **: g_object_ref: assertion 'G_IS_OBJECT (object)' failed
(process:8681): GLib-GObject-WARNING **: invalid (NULL) pointer instance
(process:8681): GLib-GObject-CRITICAL **: g_signal_connect_data: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed
(process:8681): Gtk-CRITICAL **: IA__gtk_settings_get_for_screen: assertion 'GDK_IS_SCREEN (screen)' failed
(process:8681): GLib-GObject-WARNING **: invalid (NULL) pointer instance
(process:8681): GLib-GObject-CRITICAL **: g_signal_connect_data: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed
(process:8681): Gtk-CRITICAL **: IA__gtk_icon_theme_get_for_screen: assertion 'GDK_IS_SCREEN (screen)' failed
(process:8681): GLib-GObject-WARNING **: invalid (NULL) pointer instance
(process:8681): GLib-GObject-CRITICAL **: g_signal_connect_data: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed
(process:8681): Gtk-CRITICAL **: IA__gtk_settings_get_for_screen: assertion 'GDK_IS_SCREEN (screen)' failed
(process:8681): GLib-GObject-CRITICAL **: g_object_ref: assertion 'G_IS_OBJECT (object)' failed
(process:8681): GLib-GObject-WARNING **: invalid (NULL) pointer instance
(process:8681): GLib-GObject-CRITICAL **: g_signal_connect_data: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed
(process:8681): Gtk-CRITICAL **: IA__gtk_settings_get_for_screen: assertion 'GDK_IS_SCREEN (screen)' failed
(TempI:8681): Gtk-WARNING **: Screen for GtkWindow not set; you must always set
a screen for a GtkWindow before using the window
(TempI:8681): Gdk-CRITICAL **: IA__gdk_screen_get_display: assertion 'GDK_IS_SCREEN (screen)' failed
(TempI:8681): Gdk-CRITICAL **: IA__gdk_keymap_get_for_display: assertion 'GDK_IS_DISPLAY (display)' failed
(TempI:8681): GLib-GObject-WARNING **: invalid (NULL) pointer instance
(TempI:8681): GLib-GObject-CRITICAL **: g_signal_connect_data: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed
(TempI:8681): Gtk-WARNING **: Screen for GtkWindow not set; you must always set
a screen for a GtkWindow before using the window
(TempI:8681): Gdk-CRITICAL **: IA__gdk_screen_get_display: assertion 'GDK_IS_SCREEN (screen)' failed
(TempI:8681): Gdk-CRITICAL **: IA__gdk_keymap_get_for_display: assertion 'GDK_IS_DISPLAY (display)' failed
(TempI:8681): GLib-GObject-WARNING **: invalid (NULL) pointer instance
(TempI:8681): GLib-GObject-CRITICAL **: g_signal_connect_data: assertion 'G_TYPE_CHECK_INSTANCE (instance)' failed
I can post the code of the program if necessary, just didn't do it because it would make the question even larger. That's the block where I'm creating the extra AppIndicators though:
for(int i=0; i<TempI_Main.Cores_Counter; i++){
TempI_Main.Core[i].Gtk_Menu_Root=gtk_menu_new();
//The core name ("Core " + number)
char IndicatorName[TEMPI_MAX_CHARS];
snprintf(IndicatorName, TEMPI_MAX_CHARS,"TempI_Core %u",i);
TempI_Main.Core[i].Gtk_Menu_Root_Description=gtk_menu_item_new_with_label(IndicatorName);
gtk_menu_append(GTK_MENU(TempI_Main.Core[i].Gtk_Menu_Root),TempI_Main.Core[i].Gtk_Menu_Root_Description);
gtk_widget_set_sensitive(GTK_WIDGET(TempI_Main.Core[i].Gtk_Menu_Root_Description),FALSE);
gtk_widget_show(TempI_Main.Core[i].Gtk_Menu_Root_Description);
TempI_Main.Core[i].Gtk_Indicator=app_indicator_new(IndicatorName,"indicator-messages",APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
app_indicator_set_status(TempI_Main.Core[i].Gtk_Indicator, APP_INDICATOR_STATUS_ACTIVE);
//Need to set icon
//Need to set attention icon
app_indicator_set_menu(TempI_Main.Core[i].Gtk_Indicator,GTK_MENU(TempI_Main.Core[i].Gtk_Menu_Root));
}
Any clues what could be the cause? Are multiple AppIndicators per program not supported?
EDIT:
Corrected code after #Jean-François Fabre answer.
for(int i=0; i<TempI_Main.Cores_Counter; i++){
TempI_Main.Core[i].Gtk_Menu_Root=gtk_menu_new();
//The core name ("Core " + number)
char IndicatorName[TEMPI_MAX_CHARS];
//MAX_CHARS - 6 ("Core "+'\0') is the limit for appending
snprintf(IndicatorName, TEMPI_MAX_CHARS,"TempI_Core %u",i);
TempI_Main.Core[i].Gtk_Indicator_Name=strdup(IndicatorName);
TempI_Main.Core[i].Gtk_Menu_Root_Description=gtk_menu_item_new_with_label(TempI_Main.Core[i].Gtk_Indicator_Name);
gtk_menu_append(GTK_MENU(TempI_Main.Core[i].Gtk_Menu_Root),TempI_Main.Core[i].Gtk_Menu_Root_Description);
gtk_widget_set_sensitive(GTK_WIDGET(TempI_Main.Core[i].Gtk_Menu_Root_Description),FALSE);
gtk_widget_show(TempI_Main.Core[i].Gtk_Menu_Root_Description);
TempI_Main.Core[i].Gtk_Indicator=app_indicator_new(TempI_Main.Core[i].Gtk_Indicator_Name,"indicator-messages",APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
app_indicator_set_status(TempI_Main.Core[i].Gtk_Indicator, APP_INDICATOR_STATUS_ACTIVE);
//Need to set icon
//Need to set attention icon
app_indicator_set_menu(TempI_Main.Core[i].Gtk_Indicator,GTK_MENU(TempI_Main.Core[i].Gtk_Menu_Root));
}
EDIT2:
Code for creating a single Core indicator explicitely. Still throwing warnings and critical messages:
TempI_Main.Core[0].Gtk_Menu_Root=gtk_menu_new();
TempI_Main.Core[0].Gtk_Menu_Root_Description=gtk_menu_item_new_with_label("Core1");
gtk_menu_append(GTK_MENU(TempI_Main.Core[0].Gtk_Menu_Root),TempI_Main.Core[0].Gtk_Menu_Root_Description);
gtk_widget_set_sensitive(GTK_WIDGET(TempI_Main.Core[0].Gtk_Menu_Root_Description),FALSE);
gtk_widget_show(TempI_Main.Core[0].Gtk_Menu_Root_Description);
TempI_Main.Core[0].Gtk_Indicator=app_indicator_new("Core1","indicator-messages",APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
app_indicator_set_status(TempI_Main.Core[0].Gtk_Indicator, APP_INDICATOR_STATUS_ACTIVE);
//Need to set icon
//Need to set attention icon
app_indicator_set_menu(TempI_Main.Core[0].Gtk_Indicator,GTK_MENU(TempI_Main.Core[0].Gtk_Menu_Root));

That in a loop is just bad:
char IndicatorName[TEMPI_MAX_CHARS];
snprintf(IndicatorName, TEMPI_MAX_CHARS,"TempI_Core %u",i);
TempI_Main.Core[i].Gtk_Menu_Root_Description=gtk_menu_item_new_with_label(IndicatorName);
...
TempI_Main.Core[i].Gtk_Indicator=app_indicator_new(IndicatorName, ...
You are declaring IndicatorName as an auto variable in the loop but pass it to gtk_menu_item_new_with_label which expects a const char *, means: it will just store the address of the string.
Not only the memory will be reused for further iterations and all menus will have the same indicator name within the loop, but exiting the loop the memory will be allocated to some other variable and the names will be trashed => undefined behaviour
You should make a copy of the string like this:
TempI_Main.Core[i].Gtk_Menu_Root_Description=gtk_menu_item_new_with_label(strdup(IndicatorName));
(of course a better way would be to store the copied string to be able to deallocate them if needed)

I found the root of the issue and it's embarassing to say, but I just misplaced the function that created the AppIndicator. It was being called before gtk_init() so that's where all those errors were coming from. First I had:
TempI_Set_Core_Indicator();
//Starts gtk
gtk_init(&argc,&argv);
TempI_Set_Main_Indicator();
and simply replacing it by:
//Starts gtk
gtk_init(&argc,&argv);
TempI_Set_Main_Indicator();
TempI_Set_Core_Indicator();
was enough to solve the problem. I was focusing so much on the function itself that I didn't stop to look where it was being called.

Related

Error when running print dialog from GTK 3.0

I have a small GTK 3.0 project that throws an error when displaying the print dialog. The offending statement is the following:
gint res = gtk_print_operation_run(operation, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, GTK_WINDOW(data_passer->application_window), &error);
The error is
** (deposit_slip:16703): WARNING **: 18:16:42.872: failed to get find a colord device: The name org.freedesktop.ColorManager was not provided by any .service files
I'm running the program on the Xfce desktop.
What causes this error?

Assertion failed: (0), function uv_close, file ../deps/uv/src/unix/core.c, line 174 warning

I'm running a npm run start, and I get an Assertion warning. What is the problem?

How to clone GtkWindow with its content?

I am using C and Glade with GTK 3. I want to create a simple programming language. I created the basics: code editor, output window etc. But when the user closes the output window, and tries to re-open, this message shows:
(ltc:3443): GLib-GObject-WARNING **: invalid unclassed pointer in cast to 'GObject'
(ltc:3443): GLib-GObject-CRITICAL **: g_object_class_list_properties: assertion 'G_IS_OBJECT_CLASS (class)' failed
I think the problem is caused by that when the user closes the window, its structure also gets destroyed on the memory.
How do I clone the window? I tried the simple GObject cloning algorithm, but it doesn't clone window content.
Is it possible to make the window not get destroyed when closing or clone it?
Probably what you want, instead of cloning the window, is to make sure that it is not destroyed when closed, and instead hidden.
Try connecting to the delete-event signal and using gtk_widget_hide_on_delete() as the signal handler, or calling it in your signal handler.

FAILURE: Execution failed for task ':card.io:buildNative'

I downloaded cardio source and config follow First build guide. But when i run './gradlew build', i got message like:
FAILURE: Build failed with an exception.
Where:
Build file '/media/hungnguyendata/eProtea/Projects/temp/card.io-Android-source/card.io/build.gradle' line: 163
What went wrong:
A problem occurred configuring project ':SampleApp'.
A problem occurred configuring project ':card.io'.
No such property: sonatypeUsername for class: org.gradle.api.publication.maven.internal.ant.DefaultGroovyMavenDeployer
After that, i create gradle.properties file for define property sonatypeUsername. Like this: "sonatypeUsername=sonatypeUsername
sonatypePassword=sonatypePassword". I got this message:
:card.io:buildNative
make: Entering directory /Projects/temp/card.io-Android-source/card.io/src/main/jni'
make: *** No rule to make target/Projects/temp/card.io-Android-source/card.io/src/main/jni/card.io-dmz/processor_support.cpp', needed by /Projects/temp/card.io-Android-source/card.io/src/main/obj/local/arm64-v8a/objs/cardioDecider/card.io-dmz/processor_support.o'. Stop.
make: *** Waiting for unfinished jobs....
make: Leaving directory/Projects/temp/card.io-Android-source/card.io/src/main/jni'
:card.io:buildNative FAILED
FAILURE: Build failed with an exception.
What went wrong:
Execution failed for task ':card.io:buildNative'.
Process 'command '/home/hungnguyen/applications/android-ndk-r10d/ndk-build'' finished with non-zero exit value 2
what should i do to build project. Thanks so much!

it is prossible to run qtmobility on arm platform

i was compiled qtmobility modules multimedia to arm(using QtE4.8.1 arm-linux-gcc),also i put the lib files and plugin files in my arm linux file system。when i run a demo videoplayer (run well in desktop)there get a error like :
no service found for - "com.nokia.qt.mediaplayer" is it possible to run qtmobility multimediakit on
so i put gstreamer libs in /lib directory which compiled by arm-linux-gcc.also error occured
(:267): GStreamer-CRITICAL **: gst_object_ref: assertion object != NULL' failed
(<unknown>:267): GLib-GObject-CRITICAL **: g_object_set: assertionG_IS_OBJECT (object)' failed
(:267): GStreamer-CRITICAL **: gst_object_ref: assertion object != NULL' failed
(<unknown>:267): GStreamer-CRITICAL **: gst_element_link_pads_full: assertionGST_IS_ELEMENT (dest)' failed
(:267): GStreamer-CRITICAL **: gst_element_set_state: assertion GST_IS_ELEMENT (element)' failed
(<unknown>:267): GStreamer-CRITICAL **: gst_element_set_state: assertionGST_IS_ELEMENT (element)' failed
(:267): GStreamer-CRITICAL **: gst_element_unlink: assertion GST_IS_ELEMENT (dest)' failed
(<unknown>:267): GStreamer-CRITICAL **: gst_bin_remove: assertionGST_IS_ELEMENT (element)' failed
(:267): GStreamer-CRITICAL **: gst_obje
any help ?
thanks
You seemed to have something messed up. Do you know that GStreamer has native qt bindings?

Resources