Bottle patch

Joshua Crawford <mortarn_lists-/[email protected]> Sat, 15 Jan 2005 22:41:35 +1100
Newsgroups gmane.comp.gnome.apps.bubblemon
Message-ID <[email protected]>
--===============1410772288==
Content-Type: multipart/signed; micalg=pgp-sha1;
	protocol="application/pgp-signature"; boundary="Yylu36WmvOXNoKYn"
Content-Disposition: inline


--Yylu36WmvOXNoKYn
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

(I sent this a moment ago from the wrong address. My apologies to anyone who
sees it twice)

G'day,

The patch below (for 2.0.3) modifies the behaviour of the message bottle:

o When fresh new mail arrives, or the applet is started while mail is
  already present (new or not), drop a bottle.
o An unopened (mtime > atime) mailbox keeps the bottle floating, as before.
o An opened mailbox (atime >=3D mtime) makes the bottle sink to the bottom =
(and
  stay there).
o Only when the mailbox is actually empty (size =3D=3D 0) or unreadable is =
no
  bottle shown.


I just started using bubblemon after the Freshmeat announcement a few days
ago and I think it's great (it even got a "Wow, that's cool!" from my
non-geek girlfriend). There's just a couple of things I'd like to see added,
which are a little beyond my knowledge: play a sound (plop) when new email
arrives, and run an application when the applet is clicked. If bubblemon did
these, I could remove Inbox Monitor from my panel.


diff -upPr bubblemon-2.0.3.old/src/bubblemon.c bubblemon-2.0.3/src/bubblemo=
n.c
--- bubblemon-2.0.3.old/src/bubblemon.c	2005-01-09 20:58:06.000000000 +1100
+++ bubblemon-2.0.3/src/bubblemon.c	2005-01-15 18:10:20.000000000 +1100
@@ -456,17 +456,20 @@ static void bubblemon_updateBottle(int m
     physics.bottle_y < MIN(physics.waterLevels[bubblePic.width / 2].y,
 			   bubblePic.height - msgInBottle.height / 2);
=20
-  if (youveGotMail) {
-    if (physics.bottle_state =3D=3D GONE) {
-      // Drop a new bottle
-      physics.bottle_y =3D bubblePic.height + msgInBottle.height;
-      physics.bottle_dy =3D 0.0;
-      physics.bottle_state =3D FALLING;
-    } else if (physics.bottle_state =3D=3D SINKING) {
-      physics.bottle_state =3D FLOATING;
-    }
+  if ((physics.bottle_state =3D=3D GONE) && (youveGotMail !=3D 0)) {
+    /* Either the applet's just been started and mail is already present
+       or new mail has arrived. Drop a new bottle */
+    physics.bottle_y =3D bubblePic.height + msgInBottle.height;
+    physics.bottle_dy =3D 0.0;
+    physics.bottle_state =3D FALLING;
+  } else if (youveGotMail =3D=3D 2) {
+    /* Keep the bottle floating until the mailbox is opened */
+    physics.bottle_state =3D FLOATING;
+  } else if ((youveGotMail =3D=3D 0) && (physics.bottle_state =3D=3D SUNK)=
) {
+    /* Mail has been deleted. Remove the bottle */
+    physics.bottle_state =3D SINKING;
   } else {
-    /* No unread mail */
+    /* No new mail */
     if ((physics.bottle_state =3D=3D FALLING) ||
 	(physics.bottle_state =3D=3D FLOATING))
     {
@@ -479,7 +482,9 @@ static void bubblemon_updateBottle(int m
   }
=20
   /* Accelerate the bottle */
-  if ((physics.bottle_state =3D=3D FALLING) ||
+  if (physics.bottle_state =3D=3D SUNK) {
+    gravityDdy =3D 0;
+  } else if ((physics.bottle_state =3D=3D FALLING) ||
       (physics.bottle_state =3D=3D SINKING) ||
       !isInWater)
   {
@@ -514,9 +519,17 @@ static void bubblemon_updateBottle(int m
     physics.bottle_state =3D FLOATING;
   }
  =20
-  /* Did we lose it? */
-  if ((physics.bottle_state =3D=3D SINKING) && (physics.bottle_y + msgInBo=
ttle.height < 0.0)) {
-    physics.bottle_state =3D GONE;
+  /* Did it hit bottom? */
+  if (physics.bottle_state =3D=3D SINKING) {
+    if ((youveGotMail !=3D 0) && (physics.bottle_y <=3D msgInBottle.height=
 / 4.0)) {
+      /* Keep it there */
+      physics.bottle_y =3D msgInBottle.height / 4.0;
+      physics.bottle_state =3D SUNK;
+      physics.bottle_dy =3D 0.0;
+    } else if (physics.bottle_y + (msgInBottle.height / 2.0) < 0.0) {
+      /* Remove it */
+      physics.bottle_state =3D GONE;
+    }
   }
 }
=20
diff -upPr bubblemon-2.0.3.old/src/bubblemon.h bubblemon-2.0.3/src/bubblemo=
n.h
--- bubblemon-2.0.3.old/src/bubblemon.h	2005-01-09 20:59:08.000000000 +1100
+++ bubblemon-2.0.3/src/bubblemon.h	2005-01-15 17:55:07.000000000 +1100
@@ -85,7 +85,7 @@ static const unsigned int WEEDCOLOR1   =20
 typedef enum { WATER, ANTIALIAS, AIR } bubblemon_colorcode_t;
=20
 /* Bottle behaviour */
-typedef enum { GONE, FLOATING, SINKING, FALLING } bubblemon_bottlestate_t;
+typedef enum { GONE, FLOATING, SINKING, FALLING, SUNK } bubblemon_bottlest=
ate_t;
=20
 /* Bubble layers */
 typedef enum { BACKGROUND, FOREGROUND } bubblemon_layer_t;
diff -upPr bubblemon-2.0.3.old/src/unix-mail.c bubblemon-2.0.3/src/unix-mai=
l.c
--- bubblemon-2.0.3.old/src/unix-mail.c	2004-08-21 04:27:35.000000000 +1000
+++ bubblemon-2.0.3/src/unix-mail.c	2005-01-15 18:09:50.000000000 +1100
@@ -29,6 +29,7 @@
 /* Check $MAIL for new mail on every N calls to mail_hasUnreadMail. */
 static const int CHECKEVERYNTH =3D 100;
=20
+/* Returns 2 if new (unseen) mail is present, 1 if any other mail, 0 other=
wise. */
 int mail_hasUnreadMail(void)
 {
   static int countdown =3D 0;
@@ -60,10 +61,15 @@ int mail_hasUnreadMail(void)
     // Checking the file dates on the spool file failed
     return 0;
   }
-
-  // New mail has arrived if the mail file has been updated after it
-  // was last read from
-  cachedMailState =3D mailStat.st_mtime > mailStat.st_atime;
+ =20
+  if (mailStat.st_size =3D=3D 0) {
+    /* No mail */
+    cachedMailState =3D 0;
+  } else {
+    /* New mail has arrived if the mail file has been updated after it
+       was last read from */
+    cachedMailState =3D ((mailStat.st_mtime > mailStat.st_atime) ? 2 : 1);
+  }
=20
   return cachedMailState;
 }

--=20
Joshua 'bruce' Crawford ... http://www.geocities.com/mortarn

A seminar on Time Travel will be held two weeks ago.

--Yylu36WmvOXNoKYn
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFB6QFufNeFlNwRVjIRAhAPAJ4317DAXt9+sB6Rqrl5ubhe6p9q+QCg2S5H
7ajB/CJ56NttcM6xSv5gQrI=
=TwIY
-----END PGP SIGNATURE-----

--Yylu36WmvOXNoKYn--



--===============1410772288==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Bubblemon-list mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/bubblemon-list

--===============1410772288==--