예제 #1
0
static gboolean
geyes_applet_fill (PanelApplet *applet)
{
	EyesApplet *eyes_applet;
	GSimpleActionGroup *action_group;
	GAction *action;
	gchar *ui_path;

	panel_applet_set_flags (applet, PANEL_APPLET_EXPAND_MINOR);
	
        eyes_applet = create_eyes (applet);

	eyes_applet->settings = panel_applet_settings_new (applet, GEYES_PREFS_SCHEMA);

        eyes_applet->timeout_id = g_timeout_add (
		UPDATE_TIMEOUT, (GSourceFunc) timer_cb, eyes_applet);

	action_group = g_simple_action_group_new ();
	g_action_map_add_action_entries (G_ACTION_MAP (action_group),
	                                 geyes_applet_menu_actions,
	                                 G_N_ELEMENTS (geyes_applet_menu_actions),
	                                 eyes_applet);
	ui_path = g_build_filename (GEYES_MENU_UI_DIR, "geyes-applet-menu.xml", NULL);
	panel_applet_setup_menu_from_file (eyes_applet->applet,
					   ui_path, action_group,
					   GETTEXT_PACKAGE);
	g_free (ui_path);

	gtk_widget_insert_action_group (GTK_WIDGET (applet), "geyes",
	                                G_ACTION_GROUP (action_group));

	action = g_action_map_lookup_action (G_ACTION_MAP (action_group), "preferences");
	g_object_bind_property (applet, "locked-down",
	                        action, "enabled",
	                        G_BINDING_DEFAULT|G_BINDING_INVERT_BOOLEAN|G_BINDING_SYNC_CREATE);

	g_object_unref (action_group);

	gtk_widget_set_tooltip_text (GTK_WIDGET (eyes_applet->applet), _("Eyes"));

	set_atk_name_description (GTK_WIDGET (eyes_applet->applet), _("Eyes"), 
			_("The eyes look in the direction of the mouse pointer"));

	g_signal_connect (eyes_applet->vbox,
			  "destroy",
			  G_CALLBACK (destroy_cb),
			  eyes_applet);

	gtk_widget_show_all (GTK_WIDGET (eyes_applet->applet));

	/* setup here and not in create eyes so the destroy signal is set so 
	 * that when there is an error within loading the theme
	 * we can emit this signal */
        if (properties_load (eyes_applet) == FALSE)
		return FALSE;

	setup_eyes (eyes_applet);

	return TRUE;
}
예제 #2
0
static gboolean
geyes_applet_fill (MatePanelApplet *applet)
{
	EyesApplet *eyes_applet;
	GtkActionGroup *action_group;
	gchar *ui_path;

	g_set_application_name (_("Eyes"));
	
	gtk_window_set_default_icon_name ("mate-eyes-applet");
	mate_panel_applet_set_flags (applet, MATE_PANEL_APPLET_EXPAND_MINOR);
	mate_panel_applet_set_background_widget (applet, GTK_WIDGET (applet));
	
        eyes_applet = create_eyes (applet);

        eyes_applet->timeout_id = g_timeout_add (
		UPDATE_TIMEOUT, (GSourceFunc) timer_cb, eyes_applet);

	action_group = gtk_action_group_new ("Geyes Applet Actions");
	gtk_action_group_set_translation_domain (action_group, GETTEXT_PACKAGE);
	gtk_action_group_add_actions (action_group,
				      geyes_applet_menu_actions,
				      G_N_ELEMENTS (geyes_applet_menu_actions),
				      eyes_applet);
	ui_path = g_build_filename (GEYES_MENU_UI_DIR, "geyes-applet-menu.xml", NULL);
	mate_panel_applet_setup_menu_from_file (eyes_applet->applet,
					   ui_path, action_group);
	g_free (ui_path);

	if (mate_panel_applet_get_locked_down (eyes_applet->applet)) {
		GtkAction *action;

		action = gtk_action_group_get_action (action_group, "Props");
		gtk_action_set_visible (action, FALSE);
	}
	g_object_unref (action_group);

	gtk_widget_set_tooltip_text (GTK_WIDGET (eyes_applet->applet), _("Eyes"));

	set_atk_name_description (GTK_WIDGET (eyes_applet->applet), _("Eyes"), 
			_("The eyes look in the direction of the mouse pointer"));

	g_signal_connect (eyes_applet->vbox,
			  "dispose",
			  G_CALLBACK (dispose_cb),
			  eyes_applet);

	gtk_widget_show_all (GTK_WIDGET (eyes_applet->applet));

	/* setup here and not in create eyes so the destroy signal is set so 
	 * that when there is an error within loading the theme
	 * we can emit this signal */
        if (properties_load (eyes_applet) == FALSE)
		return FALSE;

	setup_eyes (eyes_applet);

	return TRUE;
}
예제 #3
0
void
init_eyes(ModeInfo * mi)
{
	Display    *display = MI_DISPLAY(mi);
	Window      window = MI_WINDOW(mi);
	EyeScrInfo *ep;
	int         i;

        /*-
         *    Initialization that only needs to be done once.  If the
         *      release hook is called, this stuff may be freed and this
         *      function will have to allocate it again next time the
         *      init hook is called.
         */
	if (eye_info == NULL) {
		if ((eye_info = (EyeScrInfo *) calloc(MI_NUM_SCREENS(mi),
					       sizeof (EyeScrInfo))) == NULL)
			return;
	}
	ep = &eye_info[MI_SCREEN(mi)];

	if (ep->flypix == None) {
		getPixmap(mi, window, FLY_WIDTH, FLY_HEIGHT, FLY_BITS,
			  &(ep->flywidth), &(ep->flyheight), &(ep->flypix),
			  &(ep->graphics_format));
		if (ep->flypix == None) {
			free_eyes(display, ep);
			return;
		}
#ifdef XBM_GRELB
		if (ep->graphics_format == IS_XBM) {
			ep->graphics_format =0;
			getPixmap(mi, window,
			  FLY2_WIDTH, FLY2_HEIGHT, FLY2_BITS,
			  &(ep->fly2width), &(ep->fly2height), &(ep->fly2pix),
			  &(ep->graphics_format));
			if (ep->fly2pix == None) {
				free_eyes(display, ep);
				return;
			}
		}
#endif
	}
	if (ep->flyGC == None) {
		XGCValues   gcv;

		gcv.foreground = MI_BLACK_PIXEL(mi);
		gcv.background = MI_BLACK_PIXEL(mi);
		if ((ep->flyGC = XCreateGC(display, window,
				 GCForeground | GCBackground, &gcv)) == None) {
			free_eyes(display, ep);
			return;
		}
	}
	if (ep->eyeGC == None) {
		if ((ep->eyeGC = XCreateGC(display, window,
			   (unsigned long) 0, (XGCValues *) NULL)) == None) {
			free_eyes(display, ep);
			return;
		}
	}
	ep->time = 0;
	/* don't want any exposure events from XCopyArea */
	XSetGraphicsExposures(display, ep->eyeGC, False);

	freePairsOfEyes(display, ep);
	if (MI_IS_ICONIC(mi))
		ep->num_eyes = 1;
	else {
		ep->num_eyes = MI_COUNT(mi);
		/* MAX_EYES is used or one may quickly run out of memory */
		if (ep->num_eyes > MAX_EYES)
			ep->num_eyes = MAX_EYES;
		if (ep->num_eyes < 0) {
			if (ep->num_eyes < -MAX_EYES)
				ep->num_eyes = NRAND(MAX_EYES) + 1;
			else
				ep->num_eyes = NRAND(-ep->num_eyes) + 1;	/* Add 1 so its not too boring */
		}
	}
	if (!ep->eyes) {
		if ((ep->eyes = (Eyes *) calloc(ep->num_eyes, sizeof (Eyes))) == NULL) {
			free_eyes(display, ep);
			return;
		}
	}

	for (i = 0; i < ep->num_eyes; i++) {	/* place each eye pair */
		/* don't assume None == 0 */
		ep->eyes[i].pixmap = None;
		create_eyes(mi, &(ep->eyes[i]), ep->eyes, ep->num_eyes);
	}

	init_fly(mi, &(ep->fly));	/* init the bouncer */

	if (trackmouse && !ep->cursor) {	/* Create an invisible cursor */
		Pixmap      bit;
		XColor      black;

		black.red = 0;
		black.green = 0;
		black.blue = 0;
		black.flags = DoRed | DoGreen | DoBlue;
		if ((bit = XCreatePixmapFromBitmapData(display, window,
				(char *) "\000", 1, 1, MI_BLACK_PIXEL(mi),
				MI_BLACK_PIXEL(mi), 1)) == None) {
			free_eyes(display, ep);
			return;
		}
		if ((ep->cursor = XCreatePixmapCursor(display, bit, bit,
				&black, &black, 0, 0)) == None) {
			free_eyes(display, ep);
			return;
		}
		XFreePixmap(display, bit);
	}
	XDefineCursor(display, window, ep->cursor);

	MI_CLEARWINDOW(mi);
}
예제 #4
0
static void
paint_eyes(ModeInfo * mi, Eyes * e, Fly * f, Eyes * eyes, int num_eyes)
{
	EyeScrInfo *ep = &eye_info[MI_SCREEN(mi)];
	Display    *display = MI_DISPLAY(mi);
	Window      window = MI_WINDOW(mi);
	GC          gc = ep->eyeGC;
	Bool        iconic = MI_IS_ICONIC(mi);
	int         focusx = (f->x + (f->width / 2)) - e->x;
	int         focusy = (f->y + (f->height / 2)) - e->y;
	Pixmap      pix = e->pixmap;
	TPoint      point;
	int         i;

	if (pix == None) {
		e->time_to_die = 0;	/* "should not happen" */
	}
	if (ep->time >= e->time_to_die) {
		/* Sorry Bud, your time is up */
		if (e->painted) {
			/* only unpaint it if previously painted */
			XSetForeground(display, gc, MI_BLACK_PIXEL(mi));
			XFillRectangle(display, window, gc, e->x, e->y, e->width, e->height);
		}
		/* randomly place the eyes elsewhere */
		create_eyes(mi, e, eyes, num_eyes);
		pix = e->pixmap;	/* pixmap may have changed */
	}
	/* If the bouncer would intersect this pair of eyes, force the
	 * eyes to move.  This simplifies the code, because we do not
	 * have to deal with drawing the bouncer on top of the eyes.
	 * When trying to do so, there was too much annoying flashing
	 * and ghost images from the undraw.  I decided to observe the
	 * KISS principle and keep it simple.  I think the effect is
	 * better also.
	 * We must draw the flyer on the eyes when iconic, but that is
	 * easy because the eyes repaint the whole box each time.
	 */
	if ((!iconic) && (fly_touches_eye(f, e))) {
		e->time_to_die = 0;
	}
	if (e->time_to_die == 0) {
		return;		/* collides with something */
	}
	/* set the point to look at and compute the pupil position  */
	point.x = Tx(focusx, focusy, &e->transform);
	point.y = Ty(focusx, focusy, &e->transform);
	computePupil(0, point, &(e->pupil[0]));
	computePupil(1, point, &(e->pupil[1]));

	if (e->painted) {
		/* if still looking at the same point, do nothing further */
		if (TPointEqual(e->pupil[0], e->last_pupil[0]) &&
		    TPointEqual(e->pupil[1], e->last_pupil[1])) {
			return;
		}
	}
	for (i = 0; i < 2; i++) {
		/* update the eye, calculates the changed rectangle */
		make_eye(mi, pix, e, i, False);

		/* Only blit the change if the full image has been painted */
		if (e->painted) {
			/* copy the changed rectangle out to the screen */
			XCopyArea(display, pix, window, gc,
				  e->bbox.x, e->bbox.y,
				  (int) e->bbox.width, (int) e->bbox.height,
				  e->x + e->bbox.x, e->y + e->bbox.y);
		}
		/* remember where we're looking, for the next time around */
		e->last_pupil[i] = e->pupil[i];
	}

	/* always do full paint when iconic, eliminates need to track fly */
	if (iconic || (!e->painted)) {
		XCopyArea(display, pix, window, gc, 0, 0,
			  e->width, e->height, e->x, e->y);
	}
	/* when iconic, pretend to never paint, causes full paint each time */
	if (!iconic) {
		e->painted++;	/* note that a paint has been done */
	}
}