simple icon tray

Window managers, icon programs, widgets, etc.
Post Reply
Message
Author
jamesbond
Posts: 3433
Joined: Mon 26 Feb 2007, 05:02
Location: The Blue Marble

#16 Post by jamesbond »

This is good stuff, archived for future use ...
Fatdog64 forum links: [url=http://murga-linux.com/puppy/viewtopic.php?t=117546]Latest version[/url] | [url=https://cutt.ly/ke8sn5H]Contributed packages[/url] | [url=https://cutt.ly/se8scrb]ISO builder[/url]

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

#17 Post by seaside »

technosaurus wrote:@seaside - cool - the stripped down svgs I posted worked in an older wary with gtk 2.20 so it seemed safe - glad to see it being used
technosaurus,

Probably not too useful with sit being killed each time before a new icon was shown. So I changed the stock-ticker to update by copying over the new icon instead and added a right-click stop.

Regards,
s

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

#18 Post by technosaurus »

OK, I think I have inotify figured out - pretty simple really and would eliminate the need for update times. Can any C coders check this before I try and merge it into a callback? I am thinking it may be more straight forward to do this per file instead of per directory though.

usage:
myinotifyd /monitor/this/directory

Code: Select all

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/inotify.h>

#define EVENT_SIZE  ( sizeof (struct inotify_event) )
#define EVENT_BUF_LEN     ( 1024 * ( EVENT_SIZE + 16 ) )

int main(int argc, char** argv)
{
  int length, i, fd, watch;
  char buffer[EVENT_BUF_LEN];

fd = inotify_init();

if ( fd < 0 ) perror( "inotify init failed" );

/* check if argv[1] is a directory */

watch = inotify_add_watch( fd, argv[1], IN_CREATE | IN_DELETE | IN_MODIFY | IN_MOVED_FROM | IN_MOVED_TO | IN_ATTRIB );

while (1){
i=0;
length = read( fd, buffer, EVENT_BUF_LEN ); 
if ( length < 0 ) perror( "reading inotify fd" );

  while ( i < length ) {
	struct inotify_event *event = ( struct inotify_event * ) &buffer[ i ];
	  if ( event->len ) {
      if (event->mask & IN_ATTRIB)printf("%s Metadata changed\n",event->name);
      if (event->mask & IN_CREATE)printf("%s created in watched directory\n",event->name);
      if (event->mask & IN_DELETE)printf("%s deleted from watched directory\n",event->name);
      if (event->mask & IN_MODIFY)printf("%s was modified\n",event->name);
      if (event->mask & IN_MOVED_FROM)printf("%s moved out of watched directory\n",event->name);
      if (event->mask & IN_MOVED_TO)printf("%s moved into watched directory\n",event->name);
    }
    i += EVENT_SIZE + event->len;
  }
}

inotify_rm_watch( fd, watch );
close( fd );

}
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].

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

#19 Post by technosaurus »

so here it is - figured out how to make it update only when a file changes using some pretty hacky inotify and builtin gdk ops. I am going to call this one sit2 since it is significantly different in that it no longer uses a refresh time at all and now executes the right and left click commands directly (no need to keep a shell open to pipe the output through)

Code: Select all

#include <sys/inotify.h>
#include <gtk/gtk.h>
#define EVENT_SIZE  ( sizeof (struct inotify_event) )
#define EVENT_BUF_LEN     ( 1024 * ( EVENT_SIZE + 16 ) )
void leftclick(GtkStatusIcon *si, gpointer s){popen(s,"r");} /* exec s */
void rightclick(GtkStatusIcon *si, guint b,guint a_t, gpointer s){popen(s,"r");}
void refresh(gpointer si, gint fd, GdkInputCondition c){	char buffer[EVENT_BUF_LEN];
	read( fd, buffer, EVENT_BUF_LEN ); /* we are just clearing it & don't care what event type */
	gtk_status_icon_set_from_file(si,gtk_status_icon_get_title(si));} /* redraws */
int main(int argc, char *argv[]){	GtkStatusIcon *si; int i=1, watch, fd;
gtk_init (&argc, &argv); /* loop through icon, tooltip, click messages */
while (i<argc) {	fd = inotify_init(); /* get file descriptor to write on if image changes */
	si = gtk_status_icon_new_from_file(argv[i]); /* get a status icon widget */
	gtk_status_icon_set_title(si,argv[i]); /* hack to store the image path */
	watch = inotify_add_watch( fd, argv[i++], IN_CREATE | IN_MODIFY | IN_MOVED_FROM );
	gdk_input_add( fd, GDK_INPUT_READ, refresh, si ); /* inotify fd is ready for reading, refresh */
	gtk_status_icon_set_tooltip_text(si,argv[i++]);
	g_signal_connect(G_OBJECT(si), "activate", G_CALLBACK(leftclick),(gpointer) argv[i++]);
	g_signal_connect(G_OBJECT(si), "popup-menu", G_CALLBACK(rightclick), (gpointer) argv[i++]);}
gtk_main ();}
Attachments
sit2.tar.gz
(2.18 KiB) Downloaded 1107 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

#20 Post by seaside »

technosaurus,

jJust tried it out and everything works nicely. Thanks.

I was wondering if it were possible to extend the inotify aspect to include monitoring for usb drive additions and removals.

Regards,
s

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

#21 Post by technosaurus »

It really wouldn't go with this project, but monitoring the /sys/block directory for IN_CREATE events would be a good place to start if you wanted to use this as a starting point, but it would be possible to just kill and restart sit for the added drive. There is already a program called inotifyd that does the monitoring and launching part. I would start there.
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

#22 Post by seaside »

Technosaurus,

Thanks for the tip -

Code: Select all

Usage: inotifyd PROG FILE1[:MASK].
That seems much easier than inotifywait with pipes and loops.

Regards,
s

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

#23 Post by technosaurus »

btw it inotifyd is available as busybox applet now too
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].

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

#24 Post by technosaurus »

I have these 217 MIT Licensed icons roughly adapted for use in shell scripts:
http://raphaeljs.com/icons/

... just the icons themselves for now, custom options (foregrounds, backgrounds, colors, text, etc..) can be added later.

my script itself is TPL
Attachments
svgdraw.bz2
usage:
svgdraw iconname
(output is iconname.svg in current working directory)
(73.62 KiB) Downloaded 981 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].

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#25 Post by zigbert »

Wrong thread, sorry

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

#26 Post by vovchik »

Dear technosaurus,

That is a great little script with the icons. I modded it a bit to add a usage bit and made it possible to change colours from the command line. Also, run without parameters, the program spits out a somewhat formatted and sorted list of available icons. Those bits can be improved, but this is what a few minutes of hacking yielded :)

With thanks and kind regards,
vovchik
Attachments
svgdraw-col.tar.gz
(84.63 KiB) Downloaded 1059 times

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

#27 Post by seaside »

technosaurus,

What a clever use of that javascript internet material. Well done.
Now possible to have a nice collection of icons at the ready on demand or easily pre-made with matching color schemes.

Thanks and regards,
s
(If Vovchik also works on it, you know it has to be good) :D
This line was really great-

Code: Select all

icons=`printf "%-20.20s %-20.20s %-20.20s\n" $(sed -n -e '/START/,/END/p' "$PROGDIR/$PROGNAME" | grep "=\"M" | cut -d'=' -f1 | sort)`

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

#28 Post by vovchik »

@ seaside: thanks :)

Dear guys and gals,

I have really improved the input checking and other bits of this script. The icon list is now formatted nicely, and there is also a list for svg 'named colors'. I also changed a bit of the svg generation - modifying the viewBox and scaling so that it generates nominal 128px boxes and 128px objects. You cannot now try to use a non-existent icon or color - the program will tell you. There are two parameters (-i and -c) that will display icons and colors respectively. Have fun. I think technosaurus also deserves at least a few cold beers for his work.

With kind regards,
vovchik
Attachments
svgdraw-col.tar.gz
(86.28 KiB) Downloaded 1034 times

User avatar
01micko
Posts: 8741
Joined: Sat 11 Oct 2008, 13:39
Location: qld
Contact:

#29 Post by 01micko »

Made a start with the temperature script.

http://murga-linux.com/puppy/viewtopic. ... 030#635030
Puppy Linux Blog - contact me for access

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

#30 Post by vovchik »

Dear puppians,

I can't seem to get enough of a good thing. Here is a BaCon port I just did of the SVG generating script discussed above. It takes forever to compile (several minutes), but it runs circles around bash (gets compiled by gcc). I compiled in Lucid, so that it should work on all recent puppies. I also UPX'd the binary, so that it is much smaller than the bash version (100k v. 241k), apart from being inherently faster. Have fun....

With kind regards,
vovchik

PS. Just unarchive and copy the binary to /usr/local/bin, for example. The source is also included. You need BaCon to compile, and don't think that the compiler is stuck in a loop. It will finish eventually.

PPS: UPDATED src and binary. 01micko picked up a little bug in my FIND routine. Kudos:)
Attachments
bsvg-0.1a.tar.gz
(188.62 KiB) Downloaded 1040 times
Last edited by vovchik on Tue 19 Jun 2012, 14:23, edited 1 time in total.

User avatar
01micko
Posts: 8741
Joined: Sat 11 Oct 2008, 13:39
Location: qld
Contact:

#31 Post by 01micko »

Hello vovchik,

So far it all works nice except that if I try to use lock as a parameter I get the clock! Curiously, I tried "ock".. got a clock!

Thanks for your work, oh, if it makes a difference I'm using fatdog with 32 bit compat and your binary (no bacon in fatdog as yet).
Puppy Linux Blog - contact me for access

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

#32 Post by vovchik »

Thanks 01micko!

There was a little bug in my FIND routine. It has now been fixed. It really pays to have people test. Thanks again.

With kind regards,
vovchik

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

#33 Post by technosaurus »

I wouldn't say the bacon version is inherently faster or smaller considering that it will likely be called from a script and ops can be done using only builtins (typically faster than sourcing and executing an external program)... Then considering that it will be on a compressed squashfs, the script will get compressed without the additional overhead. It's still good to have alternative though, for native bacon apps. A C only version is pretty easy to do, as it would basically only need strcmp and (f)printf. The things that I left stubbed out that would really improve the look, need some input from graphically oriented designers. Backgrounds that can help tie them together with a unified look and feel that also complement foregrounds that can be informative while being graphically appealing and unified. If I had written it in C I was afraid I would lose input due to inaccessibility.
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].

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

#34 Post by vovchik »

Dear technosaurus,

The BaCon is certainly faster at coming up with the icon and color lists at the moment, but those bits could be optimized in bash. What I am interested in most is collecting more of these simple icons for inclusion and including a few more arguments (scaling and gradients come to mind), as well as text generation (with a few effects). It would really be possible to code a little SVG Factory. And it might just be useful to implement object overlays/compositing. Just food for thought :)

With kind regards,
vovchik

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

#35 Post by technosaurus »

I made a quick mod of the code to incorporate the ICON= into a case statement which both speeds it up and reduces memory usage. Also added color support based solely on positional parameters $2, $3... I need to find one of my old examples to incorporate text. For colors, I assume svg can use anything in rgb.txt.. or hex values of course. The backgrounds I am thinking could be an exported VAR so they can unify across the platform. I saw that vovchick had upscaled the image, I guess I should add a parameter to allow that to be adjustable (gtk doesn't do a great job scaling)
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