Re: a patch for at-poke



Bolian:

Why not include the blink interval in the BlinkData struct?

It seems that would be better than hard-coding a value in the g_timeout
call.

- Bill

On Tue, 2003-05-27 at 11:45, Bolian Yin wrote:
> Hi Michael,
> 
> This version remove all the global vars.  It looks better now.  Please 
> review again.
> 
> Bill, please not commit the previous one for me.  Sorry for that.
> 
> --Bolian
> 
> 
> Michael Meeks wrote:
> 
> >Hi Bolian,
> >
> >On Tue, 2003-05-27 at 03:59, Bolian Yin wrote:
> >  
> >
> >>I found the way to do that all in gdk abstraction.  The new patch is 
> >>attached. I think it is better now. If no other comments, I will ask 
> >>Bill to help me commit it.
> >>    
> >>
> >
> >	So, now I'm not distracted by the X bits ;-) I notice this:
> >
> >  
> >
> >>+/* the stuff to blink */
> >>+static int blink_count = 4;
> >>+static int blink_interval = 200;  /* 0.2 s */
> >>+static int blink_x = 0, blink_y = 0, blink_w = 0, blink_h = 0;
> >>+static GtkWidget *blink_widget = NULL;
> >>    
> >>
> >
> >	If any baby programmers saw this they just might think that global
> >variables were an acceptable way to program - so if only for their sake
> >we should do:
> >
> >typedef struct {
> >	...
> >} BlinkData;
> >
> >	Allocate that in component_blink_extens, pass it in as the user 'data'
> >member of draw_root_subwin (last arg to g_timeout_add), and free it as
> >we return false.
> >
> >	Apart from that; perfect,
> >
> >	Regards,
> >
> >		Michael.
> >
> >  
> >
> ----
> 

> Index: poke.c
> ===================================================================
> RCS file: /cvs/gnome/at-poke/src/poke.c,v
> retrieving revision 1.31
> diff -u -r1.31 poke.c
> --- poke.c	4 Feb 2003 11:45:31 -0000	1.31
> +++ poke.c	27 May 2003 10:39:42 -0000
> @@ -29,6 +29,8 @@
>  #include <glade/glade-xml.h>
>  #include <libgnomeui/gnome-ui-init.h>
>  
> +#include <gdk/gdk.h>
> +
>  #include "graphics.h"
>  #include "child-listener.h"
>  #include "accessible-listener.h"
> @@ -94,6 +96,14 @@
>  	gboolean      poker_died;
>  } Poker;
>  
> +typedef struct {
> +	gint count;
> +	gint x;
> +	gint y;
> +	gint w;
> +	gint h;
> +}BlinkData;
> +
>  enum {
>  	POKER_SELECTION_ICON,
>  	POKER_SELECTION_NAME,
> @@ -312,6 +322,63 @@
>  	AccessibleComponent_unref (component);
>  }
>  
> +static gboolean
> +blink_draw_rectangle(gpointer data)
> +{
> +	static GtkWidget *blink_widget = NULL;
> +	BlinkData *blink_data = (BlinkData *)data;
> +
> +	GdkDisplay *display = gdk_display_get_default();
> +	GdkScreen *screen = gdk_display_get_default_screen(display);
> +	GdkWindow *root_window = gdk_screen_get_root_window(screen);
> + 
> +	GdkGC *gc = gdk_gc_new(root_window);
> +
> +	/* grab mouse for the invisible widget when we are blinking */
> +	if (!blink_widget) {
> +		blink_widget = gtk_invisible_new_for_screen(screen);
> +		gtk_widget_show(blink_widget);
> +		gtk_grab_add(blink_widget);
> +	}
> +
> +	/* set subwindow mode, function and line attributes for our GC */
> +	gdk_gc_set_subwindow(gc, GDK_INCLUDE_INFERIORS);
> +	gdk_gc_set_function(gc, GDK_INVERT);
> +	gdk_gc_set_line_attributes(gc, 3, GDK_LINE_SOLID,
> +				   GDK_CAP_BUTT, GDK_JOIN_MITER);
> +	gdk_draw_rectangle(root_window, gc, FALSE,
> +			   blink_data->x, blink_data->y,
> +			   blink_data->w, blink_data->h);
> +	g_object_unref(gc);
> +
> +	--(blink_data->count);
> +
> +	/* return FALSE will destroy the timer. */
> +	if (blink_data->count <= 0) {
> +		gtk_grab_remove(blink_widget);
> +		gtk_widget_destroy(blink_widget);
> +		blink_widget = NULL;
> +		g_free(blink_data);
> +		return FALSE;
> +	}
> +	return TRUE;
> +}
> +
> +static void
> +component_blink_extents(long int x, long int y, long int w, long int h)
> +{
> +	BlinkData *blink_data = g_new0(BlinkData, 1);
> +
> +	blink_data->count = 4;  /* should be an even number */
> +	blink_data->x = x;
> +	blink_data->y = y;
> +	blink_data->w = w;
> +	blink_data->h = h;
> +
> +	/* interval is 200ms */
> +	g_timeout_add(200, blink_draw_rectangle, (gpointer)blink_data);
> +}
> +
>  static void
>  update_if_component (Poker *poker, AccessibleComponent *component)
>  {
> @@ -335,8 +402,14 @@
>  		{ 0, NULL }
>  	};
>  
> -	AccessibleComponent_getExtents (
> -		component, &x, &y, &w, &h, poker->ctype);
> +	/* make our blinks */
> +	AccessibleComponent_getExtents (component, &x, &y, &w, &h,
> +					SPI_COORD_TYPE_SCREEN);
> +	component_blink_extents(x, y, w, h);
> +
> +	if (poker->ctype != SPI_COORD_TYPE_SCREEN)
> +		AccessibleComponent_getExtents (component, &x, &y, &w, &h,
> +						poker->ctype);
>  
>  	widget = glade_xml_get_widget (poker->xml, "component_if_position");
>  	txt = g_strdup_printf ("%ld, %ld", x, y);





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]