gnome-edu r21 - in trunk/garfunkel: . src
- From: brunobol svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-edu r21 - in trunk/garfunkel: . src
- Date: Wed, 24 Dec 2008 14:54:15 +0000 (UTC)
Author: brunobol
Date: Wed Dec 24 14:54:15 2008
New Revision: 21
URL: http://svn.gnome.org/viewvc/gnome-edu?rev=21&view=rev
Log:
2008-12-24 Bruno Boaventura <brunobol gnome org>
* garfunkel/garfunkel.c:
Add initial keyboard support (use GConf in future).
Fix some thread related problems.
Adding a new functions called garfunkel_blink_once and
garfunkel_blink_once_thread, which are used to blink just one
light.
Based on patch from FrabrÃcio Godoy <skarllot gmail com>.
Modified:
trunk/garfunkel/ChangeLog
trunk/garfunkel/src/garfunkel.c
Modified: trunk/garfunkel/src/garfunkel.c
==============================================================================
--- trunk/garfunkel/src/garfunkel.c (original)
+++ trunk/garfunkel/src/garfunkel.c Wed Dec 24 14:54:15 2008
@@ -26,7 +26,6 @@
#include "config.h"
#endif
-#include <math.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <librsvg/rsvg.h>
@@ -34,8 +33,7 @@
#include "garfunkel.h"
-#define GFK_BLINK_SPEED_FAST 200000
-#define GFK_BLINK_SPEED_NORMAL 500000
+#define GFK_BLINK_TIME 500000
#define THEME_FILENAME "garfunkel.svg"
G_DEFINE_TYPE (Garfunkel, garfunkel, GTK_TYPE_DRAWING_AREA);
@@ -53,7 +51,8 @@
RsvgHandle *svg_handle;
GarfunkelLights lights;
-
+ GarfunkelLights blink_once;
+
GSList *sequence;
GSList *user_sequence;
@@ -62,12 +61,15 @@
static gboolean garfunkel_expose (GtkWidget *widget, GdkEventExpose *event);
static void garfunkel_redraw (Garfunkel *garfunkel);
-static void garfunkel_blink (Garfunkel *garfunkel, GarfunkelLights light, gulong time);
+static void garfunkel_blink (Garfunkel *garfunkel, GarfunkelLights light);
static gboolean garfunkel_key_press (GtkWidget *widget, GdkEventKey *event);
static gboolean garfunkel_button_press (GtkWidget *widget, GdkEventButton *event);
static void garfunkel_sequence_increment (Garfunkel *garfunkel);
static void garfunkel_sequence_drop (Garfunkel *garfunkel);
-static void garfunkel_sequence_blink (gpointer data);
+static void garfunkel_sequence_blink (Garfunkel *garfunkel);
+static void garfunkel_sequence_blink_thread (gpointer data);
+static void garfunkel_blink_once (Garfunkel *garfunkel, GarfunkelLights light);
+static void garfunkel_blink_once_thread (gpointer data);
static void
@@ -83,6 +85,7 @@
garfunkel->priv = g_new0 (GarfunkelPrivate, 1);
garfunkel->priv->lights = 0;
+ garfunkel->priv->blink_once = 0;
garfunkel->priv->sequence = NULL;
garfunkel->priv->user_sequence = NULL;
@@ -240,7 +243,7 @@
static void
-garfunkel_blink (Garfunkel *garfunkel, GarfunkelLights light, gulong time)
+garfunkel_blink (Garfunkel *garfunkel, GarfunkelLights light)
{
GarfunkelPrivate * gp= NULL;
@@ -250,42 +253,42 @@
garfunkel_redraw (garfunkel);
- g_usleep (time / 2);
+ g_usleep (GFK_BLINK_TIME);
gp->lights = 0;
garfunkel_redraw (garfunkel);
-
- g_usleep (time);
}
-static gboolean
-garfunkel_key_press (GtkWidget *widget, GdkEventKey *event)
+static void
+garfunkel_blink_once (Garfunkel *garfunkel, GarfunkelLights light)
{
- g_print ("teste\n");
+ GarfunkelPrivate * gp= NULL;
- garfunkel_sequence_drop ((Garfunkel *) widget);
+ gp = garfunkel->priv;
+
+ if (!g_mutex_trylock (garfunkel->priv->thread_mutex))
+ return;
- return FALSE;
+ gp->lights = garfunkel->priv->blink_once | light;
+
+ g_thread_create (garfunkel_blink_once_thread, (gpointer) garfunkel, FALSE, NULL);
}
-static gboolean
-garfunkel_button_press (GtkWidget *widget, GdkEventButton *event)
+static void
+garfunkel_blink_once_thread (gpointer data)
{
- Garfunkel *garfunkel;
+ Garfunkel *garfunkel = (Garfunkel *) data;
- garfunkel = (Garfunkel *) widget;
-
- if (!g_mutex_trylock (garfunkel->priv->thread_mutex))
- return;
+ GarfunkelPrivate * gp= NULL;
- garfunkel_sequence_increment (garfunkel);
-
- g_thread_create(garfunkel_sequence_blink, (gpointer) garfunkel, FALSE, NULL);
+ gp = garfunkel->priv;
- return FALSE;
+ garfunkel_blink (garfunkel, gp->blink_once);
+
+ g_mutex_unlock (gp->thread_mutex);
}
@@ -307,18 +310,30 @@
static void
garfunkel_sequence_drop (Garfunkel *garfunkel)
{
-/* GarfunkelPrivate * gp= NULL;*/
+ GarfunkelPrivate * gp= NULL;
+
+ gp = garfunkel->priv;
-/* gp = garfunkel->priv;*/
+ g_slist_free (gp->sequence);
-/* g_list_free (gp->sequence);*/
+ gp->sequence = NULL;
+}
+
+
+static void
+garfunkel_sequence_blink (Garfunkel *garfunkel)
+{
+ if (!g_mutex_trylock (garfunkel->priv->thread_mutex))
+ return;
-/* gp->sequence = NULL;*/
+ garfunkel_sequence_increment (garfunkel);
+
+ g_thread_create (garfunkel_sequence_blink_thread, (gpointer) garfunkel, FALSE, NULL);
}
static void
-garfunkel_sequence_blink (gpointer data)
+garfunkel_sequence_blink_thread (gpointer data)
{
Garfunkel *garfunkel = (Garfunkel *) data;
@@ -333,7 +348,9 @@
while (tmplist)
{
- garfunkel_blink (garfunkel, (gint) (tmplist->data), GFK_BLINK_SPEED_NORMAL);
+ garfunkel_blink (garfunkel, (gint) (tmplist->data));
+
+ g_usleep (GFK_BLINK_TIME);
tmplist = g_slist_next (tmplist);
}
@@ -343,3 +360,33 @@
g_mutex_unlock (gp->thread_mutex);
}
+
+static gboolean
+garfunkel_key_press (GtkWidget *widget, GdkEventKey *event)
+{
+ switch (event->keyval)
+ {
+ case GDK_a:
+ garfunkel_blink_once ((Garfunkel *) widget, GFK_GREEN);
+ case GDK_s:
+ garfunkel_blink_once ((Garfunkel *) widget, GFK_RED);
+ case GDK_z:
+ garfunkel_blink_once ((Garfunkel *) widget, GFK_YELLOW);
+ case GDK_x:
+ garfunkel_blink_once ((Garfunkel *) widget, GFK_BLUE);
+ }
+}
+
+
+static gboolean
+garfunkel_button_press (GtkWidget *widget, GdkEventButton *event)
+{
+ Garfunkel *garfunkel;
+
+ garfunkel = (Garfunkel *) widget;
+
+ garfunkel_sequence_blink (garfunkel);
+
+ return FALSE;
+}
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]