Page 1 of 1

Program and Swallow problem (Solved)

Posted: Wed 14 Jul 2010, 14:19
by tasmod
I've written my first tray applet in C and gtk which works fine in cli.

However, although it works fine and is Swallowed in the tray, if I restart JWM from menu it starts a second instance and so on for each restart.

What am I missing to stop the multiple instances?

Posted: Wed 14 Jul 2010, 23:22
by technosaurus
are you killing the applet in main? ... probably right at the end ... something like gtk main quit as in this Vala tutorial http://www.vimeo.com/9617309

Posted: Wed 14 Jul 2010, 23:58
by tasmod
This is my 'main' code, all the code is heavily based on Barry's and others works. The only way to learn really I suppose.
I'm a real beginner with C, in my first week at moment.

Firestate is the function that does comparing at intervals to check a firewall state.

Code: Select all

int main(int argc, char **argv) {

        GtkStatusIcon *tray_icon;

        gtk_init(&argc, &argv);

        tray_icon = create_tray_icon();
        
        gtk_timeout_add(interval, Firestate, NULL);

        Firestate(NULL);

        gtk_main();

        return 0;

}

Posted: Thu 15 Jul 2010, 01:01
by technosaurus
I'm not sure the C equivalent, but in vala its

app.destroy.connect (Gtk.main_quit)

by the way i put some sample code for making a tray applet in vala in the vala/genie thread (based on nic's status icon example)

Re: Program and Swallow problem

Posted: Thu 15 Jul 2010, 13:49
by Patriot
Hmmm .....
tasmod wrote:..... However, although it works fine and is Swallowed in the tray, if I restart JWM from menu it starts a second instance and so on for each restart.

What am I missing to stop the multiple instances?
I'm wild guessing that you're starting your app from jwmrc-tray as a swallow item ... Starting any gtk trayicon app as a swallow will not get into JWM swallow list and it won't be killed on restart. The swallow option is for normal windowed apps that you want to force into tray area (the swallow function relies on window name ID). Any apps that is written as a gtk trayicon should be started either in .xinitrc or the Startup folder.


Rgds

Posted: Thu 15 Jul 2010, 13:52
by tasmod
I'm just going through my code just now in conjunction with the Gtk reference Barry posted.

I think I'll stick with C as it is more universal than Vala and i don't want my poor aching brain to start again with new syntax. I have enough syntax problems already. :lol:

I'm closer now to getting my applet as I want it to work. The right click menu comes up and selecting the about generates the Gtk box but it is Swallowed. Need to find what I've changed to cause that, originally it worked OK but on exit it errored. It only showed error in cli but had no effect on applet operation. I knew it was the 'exit' that was unclean as I didn't know how to close and return from Gtk window. I used 'gtk_quit' which caused the error message.

Unfortunately I was so engrossed in the program I didn't have a backup of the 'nearly' working model. :cry: So now I'm looking for the change I must have made.

I'm not using anything special to code. I use Geany for the code and syntax highlighting features. Then I run a compile command in a cli.
Sometimes it is too easy in Geany to delete a word or section of code when in fact I intended to copy.

Probably could do with an IDE to use.

Posted: Thu 15 Jul 2010, 13:55
by tasmod
Ahhh friend Patriot,

Many thanks for that. Yes I was swallowing in .jwm-tray. Now I know I can see what I can do to move it.

I'm puzzled slightly as to BKs freemem applet. Mine is based on that and Blinky as inspiration. They appear in .jwm-tray ?

Posted: Thu 15 Jul 2010, 14:01
by tasmod
I would post what code I have here, but as it is probably very 'ugly' to a true C programmer then I'm very reluctant. More of a hack job really. 8)


Edit
Removed code as app actually works :D

Will pet it up.

Posted: Thu 15 Jul 2010, 14:42
by tasmod
Oh joy, joy, joy !! :D :D

Removed it as a swallowed app in jwm-tray and it works spot on in system tray once it is added to Startup folder.

Even better that way. I can now write a simple remove from folder command to accompany it.

It was intended as a first run reminder for the new iso's. It would sit in tray as 'Firewall Off' with a left click run now or right click menu option to run the firewall setup program.

Once firewall is running, the tray icon menu could offer the option to remove it from tray.

Anyone care to improve the icon sizes ?? Or try the app if I post it ??

Posted: Thu 15 Jul 2010, 22:18
by technosaurus
This is how glipper does it in .xinitrc (but it would work in any startup script)

Code: Select all

[ -f /root/.glipper_on ] && glipper &
if you want glipper to turn on just

Code: Select all

echo >/root/.glipper_on
if you want glipper to turn off just

Code: Select all

rm /root/.glipper_on

Posted: Fri 16 Jul 2010, 08:06
by tasmod
OK, I changed code slightly and have done away with external script.

It is now just the binary and icons.

EDIT

Now removed duplicate pet.

The latest version is now in Additional Software/Network

HERE

Posted: Fri 16 Jul 2010, 09:52
by Lobster
Seems to be working very nicely for me - I am in 2.11 or 2.12 of Lucid
. . . in fact that would be a useful icon - telling which version of Puppy I am using. There is a version file kept somewhere but can not remember where . . .
What is your plan? Perhaps change to user spot as an option?

Anyway well done :D

Posted: Fri 16 Jul 2010, 10:01
by tasmod
Hi Lobster,

Yes, I created and compiled it on Luci , now 212 with me.

It's basic operation is simple, when firewall wizard is run it appends lines to the rc.local file. I just check for the state of those lines. If 'start' is in the line, firewall is on, if 'stop' firewall is off, if no lines firewall also off.

Now up to version 0.3.

I've added the Network Setup wizard to menu and IP Information to menu.

Hmm, version info. OK will look at it but no promises, it requires parsing the info returned.

Maybe add to tooltip so when you hover over, it shows version as well as firewall status.

Posted: Fri 16 Jul 2010, 15:44
by big_bass
Hey tasmond
swallowed app in jwm-tray
thanks
you reminded me of trios fix for freememapplet

*a small delay script was required also in /usr/sbin

Code: Select all


#!/bin/sh
killall freememapplet
sleep 1
exec freememapplet


===========================
added to the /root/.jwmrc-tray

Code: Select all

<Swallow name="freememapplet" width="34">
			freememappletdelayed
		</Swallow>
I had to modify it for the jwm in 4.12
but it was an easy fix to an annoying problem

Joe

Posted: Fri 16 Jul 2010, 16:00
by tasmod
Hi Joe,

Yes when I first 'Swallowed' the app in .jwm-tray I made a script firewallstateshell with just the small sleep value. That was before Patriot told me it wouldn't be swallowed anyway.

Now it's standalone.

Glad my antics jogged memory.

Posted: Fri 16 Jul 2010, 20:27
by vovchik
Dear tasmod,

It works, so many thanks.....and congrats.

With kind regards,
vovchik

Posted: Fri 16 Jul 2010, 21:39
by tasmod
Glad you like it vovchik,

v0.4 is out with version information as a choice in the menu. This returns the Puppy version it is running in. (Lobsters idea)

Posted: Sat 17 Jul 2010, 12:56
by vovchik
Dear tasmod,

I just got an idea. You could use your firewall app and make it thoroughly universal - like alltray - by allowing the user to set the app to be launched and toggle icons on the command line.

With kind regards,
vovchik

Posted: Mon 19 Jul 2010, 09:14
by Lobster
tasmod - your firewall check should make it into 214 o9f Lucid (I Hope)
Is it possible you can look at the time and date (bottom right) and make it run
the date and time wizard on right click?

Good that you are learning and doing useful stuff simultaneously :)

Posted: Mon 19 Jul 2010, 19:38
by tasmod
OK Lobster, done. Pet for Luci is in the Luci thread.