simple icon tray

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

simple icon tray

#1 Post by technosaurus »

Code: Select all

/* gcc `pkg-config gtk+-x11-2.0 --cflags` -Os -o sit sit.c -lgtk-x11-2.0 -s */
#include <gtk/gtk.h>
int main(int argc, char *argv[]){
	GtkStatusIcon *widget; int i=1;
gtk_init (&argc, &argv);
while (i<argc) {
	widget = gtk_status_icon_new_from_file(argv[i++]);
	gtk_status_icon_set_tooltip(widget,argv[i++]);
	gtk_status_icon_set_visible(widget,TRUE);}
gtk_main ();
return 0;}
fine print
This is not a full featured implementation by any means, only an easy way to show multiple status icons
I intentionally used deprecated widgets so as to be compatible with gtk+-2.10
(to use in gtk3 change gtk_status_icon_set_tooltip to gtk_status_icon_set_tooltip_text)

usage
sit /full/icon/path/icon.png "tooltip text" /path/to/another/icon.svg "another tooltip" ...

it draws extremely fast so it can be used in a shell daemon process thusly

Code: Select all

kill $SITPID
sit $ICON1 $TOOLTIP1 $ICON2 $TOOLTIP2 &
SITPID=$!
(for instance, if you need to change the tooltip or icon based on an event)
Attachments
sit.tar.gz
(1.63 KiB) Downloaded 319 times
sit.png
(5.77 KiB) Downloaded 634 times
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#2 Post by seaside »

technosaurus,

Simple and elegant way to populate a tray with notifier icons.

Thanks,
s
(I see there's no limit to the number of icons- so you could make a kind of dashboard out of a tray :D )

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#3 Post by technosaurus »

I wanted something to complement my xpm percent bar generator and to test out an svg generator that I started. The whole idea was to allow a single daemon process to control all tray applets. I may make another version with callbacks that does stuff when you click on the icon... Possibly even monitor icons to refresh when changed.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

disciple
Posts: 6984
Joined: Sun 21 May 2006, 01:46
Location: Auckland, New Zealand

#4 Post by disciple »

What would be the idea of this?
Something like a music player controlled by several buttons in the tray?
Do you know a good gtkdialog program? Please post a link here

Classic Puppy quotes

ROOT FOREVER
GTK2 FOREVER

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

#5 Post by vovchik »

Dear technosaurus,

Both the idea and implementation are great. A system call parameter on the command line - or a .sitrc file listing icons tooltips and progs-to-exec - would make a nice and tiny utility.

Thanks.

With kind regards,
vovchik

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#6 Post by technosaurus »

updated to icon tooltip action

build script with test/example implementation

Code: Select all

#!/bin/sh
#compile
gcc `pkg-config gtk+-x11-2.0 --cflags` -DGTK_NO_CHECK_CASTS -DG_DISABLE_CAST_CHECKS \
-Os -finline-small-functions -ffunction-sections -fdata-sections -fmerge-all-constants \
-mno-accumulate-outgoing-args -march=i486 -mtune=i686 \
-Wl,-O2,--gc-sections,--as-needed,--sort-common,-s \
sit.c -o sit -lgtk-x11-2.0 && strip --strip-all -R .note -R .comment sit

#run a test
./sit /usr/share/mini-icons/mini-dog.xpm "sit test" "TAG" 2>/dev/null | \
while read LINE; do
case "$LINE" in
 TAG)Xdialog --under-mouse --infobox "sit working" 0 0 &
 ;; 
esac
done
and the code

Code: Select all

#include <gtk/gtk.h>
#include <string.h>
#define write1(s) write(1, s, strlen(s))

void activate(GtkStatusIcon *b, gpointer s){write1(s);write1("\n");}

int main(int argc, char *argv[]){
	GtkStatusIcon *widget; int i=1;
gtk_init (&argc, &argv);
while (i<argc) {
	widget = gtk_status_icon_new_from_file(argv[i++]);
	gtk_status_icon_set_tooltip(widget,argv[i++]);
	g_signal_connect(GTK_OBJECT (widget), "activate", GTK_SIGNAL_FUNC(activate),(gpointer) argv[i++]);
	gtk_status_icon_set_visible(widget,TRUE);}
gtk_main ();
return 0;}
Attachments
sit-0.1.tar.gz
(2.45 KiB) Downloaded 310 times
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#7 Post by seaside »

technosaurus,

Thanks for the added function.

I did run into something which puzzled me - if an svg is made with text only-

Code: Select all

echo '<svg>
   <rect width="64" height="64" x="0.5" y="0.5"
     style="fill:#90EE90"/>
   <text x="0.79569316" y="22"
     style="font-size:22px"
     >Text</text>
   <text x="1" y="48"
     style="font-size:22px;font-weight:bold"
     >Here</text>
 </svg> ' >/tmp/infoicon.svg
and then exec "sit /tmp/infoicon.svg" , it Segmentation faults.

Regards,
s

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#8 Post by technosaurus »

That is a gtk/librsvg "feature" I think the school requires the header info in the svg tag.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#9 Post by seaside »

technosaurus,

I tried -

Code: Select all

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN"
"http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd">
<!-- Created with Inkscape ("http://www.inkscape.org/") -->
<svg
   xmlns="http://www.w3.org/2000/svg"
   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
   xmlns:xlink="http://www.w3.org/1999/xlink"
   id="svg1"
   sodipodi:version="0.32"
   inkscape:version="0.36"
   width="210mm"
   height="297mm"
   sodipodi:docname="/root/infoicon.svg"
   sodipodi:docbase="/root">
  <defs
     id="defs8" />
  <sodipodi:namedview
     id="base" />
  <rect
     width="64"
     height="64"
     x="0.5"
     y="0.5"
     style="fill:#90EE90"
     id="rect2" />
  <text
     x="0.79569316"
     y="22"
     style="font-size:22px"
     id="text3">Text</text>
  <text
     x="1"
     y="48"
     style="font-size:22px;font-weight:bold"
     id="text5">Here</text>
</svg>
And it didn't "segfault", but it did not render in the tray either - just an empty space.

Regards,
s

seaside
Posts: 934
Joined: Thu 12 Apr 2007, 00:19

#10 Post by seaside »

UPDATE:

It apparently is a gtk version issue because I was trying it on Racy 522. I switched to Pup431 and it worked perfectly without the headers.

Regards,
s

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#11 Post by technosaurus »

Now you see why I recommend gtk+-2.16.6 (and its glib version, which I think is the actual problem - that's where all the gobjects originate) with pango-1.24.5. When the gtk devs started prepping for gtk3, they broke a _lot_ of stuff.
It is soooo easy to patch programs that require newer gtk2 libs, because most things are just a rename to work with the g_* vs gtk_ namespace and things like *_set_tooltip was deprecated in favor of *set_tooltip_text (note that they didn't do something cool and allow some kind of _other_ tooltip to necessitate this) ... most of them can be fixed with a quick application of sed or a macro.
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

Post Reply