LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-10-2008, 12:43 AM   #1
phuna
LQ Newbie
 
Registered: Jul 2005
Posts: 13

Rep: Reputation: 0
Gtk StatusIcon does not refresh


Hi all,

I have written a program in Gtk that has an icon in system tray.
This icon's image will be changed every 1s by a thread.
The problem is, icon's image in system tray does not change as thread update it.
Any help would be great appreciated.

-----
The source code is as below:

Code:
#include <gtk/gtk.h>
#include <stdlib.h>

int image = 0;
GtkStatusIcon *tray_icon = NULL;

static GtkStatusIcon *create_tray_icon() {

  GError *error = NULL;
  tray_icon = gtk_status_icon_new_from_file ("/usr/share/pixmaps/gnome-laptop.png");
  gtk_status_icon_set_tooltip(tray_icon,
                              "Example Tray Icon");
  gtk_status_icon_set_visible(tray_icon, TRUE);
  return tray_icon;
}

void *update_icon_thread (void *tid)
{
  while (1) {
  if (1 == image) {
    gtk_status_icon_set_from_file (tray_icon, "/usr/share/pixmaps/gnome-laptop.png");
    image = 0;
  } else {
    gtk_status_icon_set_from_file (tray_icon, "/usr/share/pixmaps/apple-red.png");
    image = 1;
  }
    sleep(1);
  }
}

int main(int argc, char **argv) {
  GtkStatusIcon *tray_icon;

  pthread_t thread;
  int rc;

  gtk_init(&argc, &argv);
  tray_icon = create_tray_icon();

  rc = pthread_create(&thread, NULL, update_icon_thread, (void *)NULL);
  if (rc) {
    printf("ERROR; return code from pthread_create() is %d\n", rc);
    exit(-1);
  }
  gtk_main();

  return 0;
}
 
Old 10-10-2008, 06:41 PM   #2
raconteur
Member
 
Registered: Dec 2007
Location: Slightly left of center
Distribution: slackware
Posts: 276
Blog Entries: 2

Rep: Reputation: 44
iirc, gtk caches icon images, and I'm not quite familiar enough with the SDK to know if there is a way to refresh the cache programatically.
It can be forced from the command line with gtk-update-icon-cache (1).
 
Old 10-11-2008, 09:39 PM   #3
phuna
LQ Newbie
 
Registered: Jul 2005
Posts: 13

Original Poster
Rep: Reputation: 0
Thank you for your reply.
I tried gtk-update-icon-cache but the icon still the same.
Code:
$ gtk-update-icon-cache
$ gtk-update-icon-cache -f --ignore-theme-index
gtk-update-icon-cache: Failed to open file  : No such file or directory
BTW, I'm not using GNOME, I use fluxbox.

Best regards
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Folder refresh. Where can I change how often the refresh occurs? glore2002 Slackware 2 08-12-2008 12:37 AM
gtk-qt-engine causes white border on gtk tray icons tdtooke Linux - Desktop 0 08-08-2008 12:25 PM
Freerock uninstall stole GTK looking for up-to-date pango, atk, gtk, glib and xft tgz Oholiab Slackware 8 09-18-2005 11:57 AM
GTK source install doesn't give gtk-config Feebles Linux - Software 4 06-15-2005 12:51 PM
cant find gtk-config file or gtk-devel to install happychappy Linux - Software 2 02-16-2005 12:46 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration