Program and Swallow problem (Solved)

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
tasmod
Posts: 1460
Joined: Thu 04 Dec 2008, 13:53
Location: North Lincolnshire. UK
Contact:

Program and Swallow problem (Solved)

#1 Post 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?
Last edited by tasmod on Thu 15 Jul 2010, 18:01, edited 1 time in total.
Rob
-
The moment after you press "Post" is the moment you actually see the typso 8)

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

#2 Post 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
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
tasmod
Posts: 1460
Joined: Thu 04 Dec 2008, 13:53
Location: North Lincolnshire. UK
Contact:

#3 Post 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;

}
Rob
-
The moment after you press "Post" is the moment you actually see the typso 8)

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

#4 Post 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)
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
Patriot
Posts: 733
Joined: Thu 15 Jan 2009, 19:04

Re: Program and Swallow problem

#5 Post 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

User avatar
tasmod
Posts: 1460
Joined: Thu 04 Dec 2008, 13:53
Location: North Lincolnshire. UK
Contact:

#6 Post 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.
Rob
-
The moment after you press "Post" is the moment you actually see the typso 8)

User avatar
tasmod
Posts: 1460
Joined: Thu 04 Dec 2008, 13:53
Location: North Lincolnshire. UK
Contact:

#7 Post 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 ?
Rob
-
The moment after you press "Post" is the moment you actually see the typso 8)

User avatar
tasmod
Posts: 1460
Joined: Thu 04 Dec 2008, 13:53
Location: North Lincolnshire. UK
Contact:

#8 Post 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.
Attachments
mini-firewall1.xpm
Firewall on icon
(63.17 KiB) Downloaded 423 times
firewall-off.xpm
Firewall off icon.
(21.84 KiB) Downloaded 395 times
Last edited by tasmod on Thu 15 Jul 2010, 15:02, edited 1 time in total.
Rob
-
The moment after you press "Post" is the moment you actually see the typso 8)

User avatar
tasmod
Posts: 1460
Joined: Thu 04 Dec 2008, 13:53
Location: North Lincolnshire. UK
Contact:

#9 Post 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 ??
Attachments
firewallstatus.png
Running in tray
(6.3 KiB) Downloaded 894 times
Last edited by tasmod on Fri 16 Jul 2010, 08:45, edited 2 times in total.
Rob
-
The moment after you press "Post" is the moment you actually see the typso 8)

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

#10 Post 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
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
tasmod
Posts: 1460
Joined: Thu 04 Dec 2008, 13:53
Location: North Lincolnshire. UK
Contact:

#11 Post 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
Last edited by tasmod on Fri 16 Jul 2010, 10:03, edited 1 time in total.
Rob
-
The moment after you press "Post" is the moment you actually see the typso 8)

User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

#12 Post 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
Puppy Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D

User avatar
tasmod
Posts: 1460
Joined: Thu 04 Dec 2008, 13:53
Location: North Lincolnshire. UK
Contact:

#13 Post 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.
Rob
-
The moment after you press "Post" is the moment you actually see the typso 8)

big_bass
Posts: 1740
Joined: Mon 13 Aug 2007, 12:21

#14 Post 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

User avatar
tasmod
Posts: 1460
Joined: Thu 04 Dec 2008, 13:53
Location: North Lincolnshire. UK
Contact:

#15 Post 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.
Rob
-
The moment after you press "Post" is the moment you actually see the typso 8)

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

#16 Post by vovchik »

Dear tasmod,

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

With kind regards,
vovchik

User avatar
tasmod
Posts: 1460
Joined: Thu 04 Dec 2008, 13:53
Location: North Lincolnshire. UK
Contact:

#17 Post 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)
Rob
-
The moment after you press "Post" is the moment you actually see the typso 8)

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

#18 Post 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

User avatar
Lobster
Official Crustacean
Posts: 15522
Joined: Wed 04 May 2005, 06:06
Location: Paradox Realm
Contact:

#19 Post 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 :)
Puppy Raspup 8.2Final 8)
Puppy Links Page http://www.smokey01.com/bruceb/puppy.html :D

User avatar
tasmod
Posts: 1460
Joined: Thu 04 Dec 2008, 13:53
Location: North Lincolnshire. UK
Contact:

#20 Post by tasmod »

OK Lobster, done. Pet for Luci is in the Luci thread.
Rob
-
The moment after you press "Post" is the moment you actually see the typso 8)

Post Reply