Exemplo n.º 1
0
int create_filters(const char *pProgram, int eExecute, int uUp, int dDown, pid_t *pProcess1, 
pid_t *pProcess2)
{
	if (!pProcess1 || !pProcess2)
	{
	fprintf(stderr, "%s: internal error\n", pProgram);
	return -1;
	}

	int far_incoming    = -1;
	int far_outgoing    = -1;
	int client_incoming = -1;
	int client_outgoing = -1;

	int filter_type = check_type(eExecute);

	if (filter_type == FILTER_ERROR)
	{
	fprintf(stderr, "%s: filter must be associated with an active server or forwarder\n", pProgram);
	return -1;
	}


	else if (filter_type == FILTER_NORMAL)
	{
	if (normal_setup(pProgram, uUp, dDown, &client_incoming, &client_outgoing,
	     &far_incoming, &far_outgoing ) < 0)
	return -1;

	return fork_normal(pProgram, uUp, dDown, pProcess1, pProcess2, client_incoming,
	  client_outgoing, far_incoming, far_outgoing);
	}


	else if (filter_type == FILTER_REMOTE)
	{
	if (remote_setup(pProgram, eExecute, &client_incoming, &client_outgoing,
	      &far_incoming, &far_outgoing) < 0)
	return -1;

	return fork_remote(pProgram, eExecute, uUp, dDown, pProcess1, pProcess2,
	  client_incoming, client_outgoing, far_incoming, far_outgoing);
	}


	else
	{
	fprintf(stderr, "%s: internal error\n", pProgram);
	return -1;
	}
}
Exemplo n.º 2
0
void display_cow(bool debug, const char *text, bool run_main, cowmode_t mode)
{
   GdkScreen *screen = gdk_screen_get_default();

   gint n_monitors = gdk_screen_get_n_monitors(screen);

   gint pick = get_int_option("monitor");
   if (pick < 0 || pick >= n_monitors)
      pick = random() % n_monitors;
   
   GdkRectangle geom;
   gdk_screen_get_monitor_geometry(screen, pick, &geom);

   xcowsay.screen_width = geom.width;
   xcowsay.screen_height = geom.height;

   g_assert(xcowsay.cow_pixbuf);
   xcowsay.cow = make_shape_from_pixbuf(xcowsay.cow_pixbuf);

   switch (mode) {
   case COWMODE_NORMAL:
   case COWMODE_THINK:
      normal_setup(text, debug, mode);
      break;
   case COWMODE_DREAM:
      dream_setup(text, debug);
      break;
   default:
      fprintf(stderr, "Error: Unsupported cow mode %d\n", mode);
      exit(1);
   }
   
   xcowsay.bubble = make_shape_from_pixbuf(xcowsay.bubble_pixbuf);   
   
   int total_width = shape_width(xcowsay.cow)
      + get_int_option("bubble_x")
      + xcowsay.bubble_width;
   int total_height = max(shape_height(xcowsay.cow), xcowsay.bubble_height);

   int bubble_off = max((xcowsay.bubble_height - shape_height(xcowsay.cow))/2, 0);

   int area_w = xcowsay.screen_width - total_width;
   int area_h = xcowsay.screen_height - total_height;

   // Fit the cow on the screen as best as we can
   // The area can't be be zero or we'd get an FPE
   if (area_w < 1)
      area_w = 1;
   if (area_h < 1)
      area_h = 1;

   int cow_x = get_int_option("at_x");
   if (cow_x < 0)
      cow_x = random() % area_w;
   else if (cow_x >= area_w)
      cow_x = area_w - 1;
   
   int cow_y = get_int_option("at_y");
   if (cow_y < 0)
      cow_y = random() % area_h;
   else if (cow_y >= area_h)
      cow_y = area_h - 1;

   if (get_bool_option("left")) {
      move_shape(xcowsay.cow,
                 geom.x + cow_x + xcowsay.bubble_width,
                 geom.y + bubble_off + cow_y);
      show_shape(xcowsay.cow);
      
      int bx = shape_x(xcowsay.cow) - xcowsay.bubble_width
         + get_int_option("bubble_x");
      int by = shape_y(xcowsay.cow)
         + (shape_height(xcowsay.cow) - shape_height(xcowsay.bubble))/2
         + get_int_option("bubble_y");
      move_shape(xcowsay.bubble, bx, by);
   }
   else {
      move_shape(xcowsay.cow,
                 geom.x + cow_x,
                 geom.y + bubble_off + cow_y);
      show_shape(xcowsay.cow);
      
      int bx = shape_x(xcowsay.cow) + shape_width(xcowsay.cow)
         + get_int_option("bubble_x");
      int by = shape_y(xcowsay.cow)
         + (shape_height(xcowsay.cow) - shape_height(xcowsay.bubble))/2
         + get_int_option("bubble_y");
      move_shape(xcowsay.bubble, bx, by);
   }
      
   xcowsay.state = csLeadIn;
   xcowsay.transition_timeout = get_int_option("lead_in_time");
   g_timeout_add(TICK_TIMEOUT, tick, NULL);

   close_when_clicked(xcowsay.cow);
   
   if (run_main)
      gtk_main();

   g_object_unref(xcowsay.bubble_pixbuf);
   xcowsay.bubble_pixbuf = NULL;
}